kivio

kivio_point.cpp

00001 /*
00002  * Kivio - Visual Modelling and Flowcharting
00003  * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 #include "kivio_point.h"
00020 #include "kivio_common.h"
00021 
00022 #include <kdebug.h>
00023 
00024 
00025 /*
00026  * Names for the different point types. invalid
00027  * and last are not used for any real point type, 
00028  * and only serve as bounds checking devices.
00029  */
00030 static const char *KivioPointTypeNames[]={
00031     "invalid", "normal", "bezier", "arc", "last"
00032 };
00033 
00034 
00040 KivioPoint::KivioPoint()
00041 {
00042     m_x = 0.0f;
00043     m_y = 0.0f;
00044     m_pointType = kptNormal;
00045 }
00046 
00047 
00055 KivioPoint::KivioPoint( const KivioPoint &copy )
00056 {
00057     m_x = copy.m_x;
00058     m_y = copy.m_y;
00059     m_pointType = copy.m_pointType;
00060 }
00061 
00062 
00072 KivioPoint::KivioPoint( double newX, double newY, KivioPointType pt )
00073 {
00074     m_x = newX;
00075     m_y = newY;
00076     m_pointType = pt;
00077 }
00078 
00079 
00083 KivioPoint::~KivioPoint()
00084 {
00085 }
00086 
00087 
00093 void KivioPoint::copyInto( KivioPoint *pTarget ) const
00094 {
00095     if( !pTarget )
00096         return;
00097 
00098     pTarget->m_x = m_x;
00099     pTarget->m_y = m_y;
00100     pTarget->m_pointType = m_pointType;
00101 }
00102 
00103 
00112 KivioPoint::KivioPointType KivioPoint::pointTypeFromString( const QString &str )
00113 {
00114     int i;
00115     
00116     // Iterate through all the possible enums
00117     for( i=(int)kptNone+1; i<(int)kptLast; i++ )
00118     {
00119         // If we find it, return it
00120         if( str.compare( KivioPointTypeNames[i] )==0 )
00121         {
00122             return (KivioPointType)i;
00123         }
00124     }
00125     
00126     // Otherwise return an invalid type
00127     return kptNone;
00128 }
00129 
00130 
00131 
00138 bool KivioPoint::loadXML( const QDomElement &e )
00139 {
00140     if( e.tagName().compare( "KivioPoint" ) != 0 )
00141     {
00142        kdDebug(43000) << "Attempted to load KivioPoint from non-KivioPoint element" << endl;
00143         return false;
00144     }
00145 
00146     m_x = XmlReadFloat( e, "x", 1.0f );
00147     m_y = XmlReadFloat( e, "y", 1.0f );
00148     m_pointType = (KivioPointType)pointTypeFromString( XmlReadString( e, "type", "normal" ) );
00149     
00150 
00151     return true;
00152 }
00153 
00154 
00155 
00162 QDomElement KivioPoint::saveXML( QDomDocument &doc )
00163 {
00164     QDomElement e = doc.createElement("KivioPoint");
00165     
00166 
00167     XmlWriteFloat( e, QString("x"), m_x );
00168     XmlWriteFloat( e, QString("y"), m_y );
00169     XmlWriteString( e, QString("type"), QString(KivioPointTypeNames[m_pointType]) );
00170     return e;
00171 }
KDE Home | KDE Accessibility Home | Description of Access Keys