kivio_point.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2000-2001 theKompany.com & Dave Marotti
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "kivio_point.h"
20#include "kivio_common.h"
21
22#include <kdebug.h>
23
24
25/*
26 * Names for the different point types. invalid
27 * and last are not used for any real point type,
28 * and only serve as bounds checking devices.
29 */
30static const char *KivioPointTypeNames[]={
31 "invalid", "normal", "bezier", "arc", "last"
32};
33
34
40KivioPoint::KivioPoint()
41{
42 m_x = 0.0f;
43 m_y = 0.0f;
44 m_pointType = kptNormal;
45}
46
47
55KivioPoint::KivioPoint( const KivioPoint &copy )
56{
57 m_x = copy.m_x;
58 m_y = copy.m_y;
59 m_pointType = copy.m_pointType;
60}
61
62
72KivioPoint::KivioPoint( double newX, double newY, KivioPointType pt )
73{
74 m_x = newX;
75 m_y = newY;
76 m_pointType = pt;
77}
78
79
83KivioPoint::~KivioPoint()
84{
85}
86
87
93void KivioPoint::copyInto( KivioPoint *pTarget ) const
94{
95 if( !pTarget )
96 return;
97
98 pTarget->m_x = m_x;
99 pTarget->m_y = m_y;
100 pTarget->m_pointType = m_pointType;
101}
102
103
112KivioPoint::KivioPointType KivioPoint::pointTypeFromString( const TQString &str )
113{
114 int i;
115
116 // Iterate through all the possible enums
117 for( i=(int)kptNone+1; i<(int)kptLast; i++ )
118 {
119 // If we find it, return it
120 if( str.compare( KivioPointTypeNames[i] )==0 )
121 {
122 return (KivioPointType)i;
123 }
124 }
125
126 // Otherwise return an invalid type
127 return kptNone;
128}
129
130
131
138bool KivioPoint::loadXML( const TQDomElement &e )
139{
140 if( e.tagName().compare( "KivioPoint" ) != 0 )
141 {
142 kdDebug(43000) << "Attempted to load KivioPoint from non-KivioPoint element" << endl;
143 return false;
144 }
145
146 m_x = XmlReadFloat( e, "x", 1.0f );
147 m_y = XmlReadFloat( e, "y", 1.0f );
148 m_pointType = (KivioPointType)pointTypeFromString( XmlReadString( e, "type", "normal" ) );
149
150
151 return true;
152}
153
154
155
162TQDomElement KivioPoint::saveXML( TQDomDocument &doc )
163{
164 TQDomElement e = doc.createElement("KivioPoint");
165
166
167 XmlWriteFloat( e, TQString("x"), m_x );
168 XmlWriteFloat( e, TQString("y"), m_y );
169 XmlWriteString( e, TQString("type"), TQString(KivioPointTypeNames[m_pointType]) );
170 return e;
171}