/* * Kivio - Visual Modelling and Flowcharting * Copyright (C) 2000-2001 theKompany.com & Dave Marotti * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kivio_common.h" #include "kivio_connector_target.h" #include "kivio_shape.h" #include "kivio_shape_data.h" #include "kivio_sml_stencil.h" #include "kivio_sml_stencil_spawner.h" #include "kivio_stencil_spawner_set.h" #include "kivio_stencil_spawner.h" #include "kivio_stencil_spawner_info.h" #include #include #include #include #include #include #include #include #include KivioSMLStencilSpawner::KivioSMLStencilSpawner( KivioStencilSpawnerSet *p ) : KivioStencilSpawner( p ), m_pStencil(NULL) { m_pStencil = new KivioSMLStencil(); m_pTargets = new TQPtrList; m_pTargets->setAutoDelete(true); } KivioSMLStencilSpawner::~KivioSMLStencilSpawner() { if( m_pStencil ) { delete m_pStencil; m_pStencil = NULL; } if( m_pTargets ) { delete m_pTargets; m_pTargets = NULL; } kdDebug(43000) << "* SMLStencilSpawner "<< m_pInfo->id() << " deleted" << endl; } TQDomElement KivioSMLStencilSpawner::saveXML( TQDomDocument &doc ) { TQDomElement spawnE = doc.createElement("KivioSMLStencilSpawner"); XmlWriteString( spawnE, "id", m_pInfo->id() ); return spawnE; } bool KivioSMLStencilSpawner::load( const TQString &file ) { TQDomDocument d("test"); m_filename = TQString(file); TQFile f(file); if( f.open( IO_ReadOnly )==false ) { kdDebug(43000) << "KivioSMLStencilSpawner::load() - Error opening stencil: " << file << endl; return false; } d.setContent(&f); if(loadXML(file, d)) { f.close(); return true; } else { f.close(); return false; } } bool KivioSMLStencilSpawner::loadXML( const TQString &file, TQDomDocument &d ) { KivioConnectorTarget *pTarget; TQDomElement root = d.documentElement(); TQDomElement e; TQDomNode node = root.firstChild(); TQString nodeName; while( !node.isNull() ) { nodeName = node.nodeName(); if( nodeName.compare("KivioSMLStencilSpawnerInfo")==0 ) { m_pInfo->loadXML( (const TQDomElement)node.toElement() ); } else if( nodeName.compare("KivioShape")==0 ) { loadShape( node ); } else if( nodeName.compare("Dimensions")==0 ) { e = node.toElement(); m_defWidth = XmlReadFloat( e, "w", 72.0f ); m_defHeight = XmlReadFloat( e, "h", 72.0f ); } else if( nodeName.compare("KivioConnectorTarget")==0 ) { pTarget = new KivioConnectorTarget(); pTarget->loadXML( (const TQDomElement)node.toElement() ); m_pStencil->m_pConnectorTargets->append( pTarget ); } else { kdDebug(43000) << "KivioSMLStencilSpawner::load() - Unknown node " << nodeName << " while loading " << file << endl; } node = node.nextSibling(); } pTarget = m_pStencil->m_pConnectorTargets->first(); while(pTarget) { pTarget->setOffsets(pTarget->x() / m_defWidth, pTarget->y() / m_defHeight); m_pTargets->append(pTarget->duplicate()); pTarget = m_pStencil->m_pConnectorTargets->next(); } // Now load the xpm TQFileInfo finfo(file); TQString pixFile = finfo.dirPath(true) + "/" + finfo.baseName() + ".xpm"; if(!m_icon.load( pixFile )) { TQString pixFile = finfo.dirPath(true) + "/" + finfo.baseName() + ".png"; m_icon.load( pixFile ); } return true; } /** * Loads a tqshape from an XML node. */ void KivioSMLStencilSpawner::loadShape( TQDomNode &tqshapeNode ) { KivioShapeData::KivioShapeType t; KivioShape *pShape = NULL; TQDomElement tqshapeElement = tqshapeNode.toElement(); t = KivioShapeData::tqshapeTypeFromString( XmlReadString( tqshapeElement, "type", "None" ) ); switch( t ) { case KivioShapeData::kstNone: break; case KivioShapeData::kstArc: pShape = KivioShape::loadShapeArc( tqshapeElement ); break; case KivioShapeData::kstPie: pShape = KivioShape::loadShapePie( tqshapeElement ); break; case KivioShapeData::kstLineArray: pShape = KivioShape::loadShapeLineArray( tqshapeElement ); break; case KivioShapeData::kstPolyline: pShape = KivioShape::loadShapePolyline( tqshapeElement ); break; case KivioShapeData::kstPolygon: pShape = KivioShape::loadShapePolygon( tqshapeElement ); break; case KivioShapeData::kstBezier: pShape = KivioShape::loadShapeBezier( tqshapeElement ); break; case KivioShapeData::kstRectangle: pShape = KivioShape::loadShapeRectangle( tqshapeElement ); break; case KivioShapeData::kstRoundRectangle: pShape = KivioShape::loadShapeRoundRectangle( tqshapeElement ); break; case KivioShapeData::kstEllipse: pShape = KivioShape::loadShapeEllipse( tqshapeElement ); break; case KivioShapeData::kstOpenPath: pShape = KivioShape::loadShapeOpenPath( tqshapeElement ); break; case KivioShapeData::kstClosedPath: pShape = KivioShape::loadShapeClosedPath( tqshapeElement ); break; case KivioShapeData::kstTextBox: pShape = KivioShape::loadShapeTextBox( tqshapeElement ); break; default: break; } if( pShape ) { m_pStencil->m_pShapeList->append( pShape ); } } /** * Returns a new stencil, with default width/height of the spawner settings. */ KivioStencil *KivioSMLStencilSpawner::newStencil() { KivioStencil *pNewStencil = m_pStencil->duplicate(); pNewStencil->setSpawner(this); pNewStencil->setDimensions( m_defWidth, m_defHeight ); return pNewStencil; }