kivio

kivio_connector_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_common.h"
20#include "kivio_connector_point.h"
21#include "kivio_connector_target.h"
22#include "kivio_stencil.h"
23
24KivioConnectorPoint::KivioConnectorPoint()
25{
26 m_pTarget = 0L;
27 m_pStencil = 0L;
28 m_targetId = -1;
29 m_connectable = true;
30}
31
32KivioConnectorPoint::KivioConnectorPoint( KivioStencil *pParent, bool conn )
33{
34 m_pTarget = 0L;
35 m_pStencil = pParent;
36 m_targetId = -1;
37 m_connectable = conn;
38}
39
40KivioConnectorPoint::~KivioConnectorPoint()
41{
42 if( m_pTarget )
43 {
44 m_pTarget->removeConnectorPointFromList( this );
45 m_pTarget = 0L;
46 }
47
48 m_pStencil = 0L;
49}
50
60void KivioConnectorPoint::setTarget( KivioConnectorTarget *pTarget )
61{
62 if( m_connectable == false )
63 {
64 return;
65 }
66
67 if( m_pTarget )
68 {
69 m_pTarget->removeConnectorPointFromList( this );
70 }
71
72
73 m_pTarget = pTarget;
74
75 m_pos.setX(pTarget->x());
76 m_pos.setY(pTarget->y());
77
78 m_pTarget->addConnectorPointToList( this );
79}
80
81
91void KivioConnectorPoint::setX( double newX, bool updateStencil )
92{
93 double oldX = m_pos.x();
94 m_pos.setX(newX);
95
96 if( updateStencil && m_pStencil )
97 m_pStencil->updateConnectorPoints(this, oldX, m_pos.y());
98}
99
100
110void KivioConnectorPoint::setY( double newY, bool updateStencil )
111{
112 double oldY = m_pos.y();
113 m_pos.setY(newY);
114
115 if( updateStencil && m_pStencil )
116 m_pStencil->updateConnectorPoints(this, m_pos.x(), oldY);
117}
118
119
130 void KivioConnectorPoint::setPosition( double newX, double newY, bool updateStencil )
131{
132 double oldX = m_pos.x();
133 double oldY = m_pos.y();
134
135 m_pos.setCoords(newX, newY);
136
137 if( updateStencil && m_pStencil )
138 m_pStencil->updateConnectorPoints(this, oldX, oldY);
139}
140
141
151void KivioConnectorPoint::disconnect( bool removeFromTargetList )
152{
153 if( m_pTarget )
154 {
155 if( removeFromTargetList == true )
156 m_pTarget->removeConnectorPointFromList(this);
157
158 m_pTarget = 0L;
159 m_targetId = -1;
160 }
161
162}
163
164
172bool KivioConnectorPoint::loadXML( const TQDomElement &e )
173{
174 m_pos.setX(XmlReadFloat( e, "x", 1.0f ));
175 m_pos.setY(XmlReadFloat( e, "y", 1.0f ));
176 m_targetId = XmlReadInt( e, "targetId", -1 );
177 m_connectable = (bool)XmlReadInt( e, "connectable", (int)true );
178
179 return true;
180}
181
182
192TQDomElement KivioConnectorPoint::saveXML( TQDomDocument &doc )
193{
194 TQDomElement e = doc.createElement("KivioConnectorPoint");
195
196 XmlWriteFloat( e, "x", m_pos.x() );
197 XmlWriteFloat( e, "y", m_pos.y() );
198 XmlWriteInt( e, "connectable", (int)m_connectable );
199
200 if( m_targetId != -1 )
201 XmlWriteInt( e, "targetId", m_targetId );
202
203 return e;
204}
205
206void KivioConnectorPoint::moveBy( double _x, double _y, bool updateStencil )
207{
208 m_pos += KoPoint(_x, _y);
209
210 if( updateStencil && m_pStencil )
211 m_pStencil->updateConnectorPoints(this, _x, _y);
212}
213
214bool KivioConnectorPoint::isConnected()
215{
216 return (m_pTarget != 0L);
217}