summaryrefslogtreecommitdiffstats
path: root/kivio/kiviopart/kiviosdk/kivio_point.cpp
blob: b3afae70966d899ac372e15a398f7ddf9fad5da1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 * 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_point.h"
#include "kivio_common.h"

#include <kdebug.h>


/*
 * Names for the different point types. invalid
 * and last are not used for any real point type, 
 * and only serve as bounds checking devices.
 */
static const char *KivioPointTypeNames[]={
    "invalid", "normal", "bezier", "arc", "last"
};


/**
 * Constructor
 *
 * Sets this point to (0,0) and of type normal.
 */
KivioPoint::KivioPoint()
{
    m_x = 0.0f;
    m_y = 0.0f;
    m_pointType = kptNormal;
}


/**
 * Copy constructor
 *
 * @param copy The KivioPoint to make a copy of.
 *
 * Copies copy into this object.
 */
KivioPoint::KivioPoint( const KivioPoint &copy )
{
    m_x = copy.m_x;
    m_y = copy.m_y;
    m_pointType = copy.m_pointType;
}


/**
 * Alternate constructor.
 *
 * @param newX The x value of the point
 * @param newY The y value of the point
 * @param pt The point type
 *
 * Creates a new point with values.
 */
KivioPoint::KivioPoint( double newX, double newY, KivioPointType pt )
{
    m_x = newX;
    m_y = newY;
    m_pointType = pt;
}


/**
 * Destructor
 */
KivioPoint::~KivioPoint()
{
}


/**
 * Copies this object's data into pTarget
 *
 * @param pTarget The destination of the copy
 */
void KivioPoint::copyInto( KivioPoint *pTarget ) const
{
    if( !pTarget )
        return;

    pTarget->m_x = m_x;
    pTarget->m_y = m_y;
    pTarget->m_pointType = m_pointType;
}


/**
 * Figure out the KivioPointType from a string
 *
 * @param str The string to search with
 *
 * This will figure out the KivioPointType from a string.  For example,
 * "normal" will return kptNormal.
 */
KivioPoint::KivioPointType KivioPoint::pointTypeFromString( const TQString &str )
{
    int i;
    
    // Iterate through all the possible enums
    for( i=(int)kptNone+1; i<(int)kptLast; i++ )
    {
        // If we find it, return it
        if( str.compare( KivioPointTypeNames[i] )==0 )
        {
            return (KivioPointType)i;
        }
    }
    
    // Otherwise return an invalid type
    return kptNone;
}



/**
 * Load this object from an XML element
 *
 * @param e The element to load from
 * @returns true on success, false on failure.
 */
bool KivioPoint::loadXML( const TQDomElement &e )
{
    if( e.tagName().compare( "KivioPoint" ) != 0 )
    {
       kdDebug(43000) << "Attempted to load KivioPoint from non-KivioPoint element" << endl;
        return false;
    }

    m_x = XmlReadFloat( e, "x", 1.0f );
    m_y = XmlReadFloat( e, "y", 1.0f );
    m_pointType = (KivioPointType)pointTypeFromString( XmlReadString( e, "type", "normal" ) );
    

    return true;
}



/**
 * Save this object to an XML element
 *
 * @param doc The document we are saving to
 * @returns TQDomElement
 */
TQDomElement KivioPoint::saveXML( TQDomDocument &doc )
{
    TQDomElement e = doc.createElement("KivioPoint");
    

    XmlWriteFloat( e, TQString("x"), m_x );
    XmlWriteFloat( e, TQString("y"), m_y );
    XmlWriteString( e, TQString("type"), TQString(KivioPointTypeNames[m_pointType]) );
    return e;
}