kivio

kivio_connector_target.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_point.h"
23#include "kivio_stencil.h"
24#include "kivio_intra_stencil_data.h"
25
26#include <kdebug.h>
27
28KivioConnectorTarget::KivioConnectorTarget()
29 : m_pConnectors(NULL)
30{
31 m_position.setX( 0.0f );
32 m_position.setY( 0.0f );
33 m_pConnectors = new TQPtrList<KivioConnectorPoint>;
34 m_pConnectors->setAutoDelete(false);
35 m_id = -1;
36 m_xOffset = m_yOffset = 0;
37}
38
39KivioConnectorTarget::KivioConnectorTarget(double x, double y)
40{
41 m_position.setX( x );
42 m_position.setY( y );
43 m_pConnectors = new TQPtrList<KivioConnectorPoint>;
44 m_pConnectors->setAutoDelete(false);
45
46 m_id = -1;
47 m_xOffset = m_yOffset = 0;
48}
49
50KivioConnectorTarget::KivioConnectorTarget(double x, double y, double xOffset, double yOffset)
51{
52 m_position.setX( x );
53 m_position.setY( y );
54 m_pConnectors = new TQPtrList<KivioConnectorPoint>;
55 m_pConnectors->setAutoDelete(false);
56
57 m_id = -1;
58 setOffsets(xOffset, yOffset);
59}
60
67KivioConnectorTarget *KivioConnectorTarget::duplicate()
68{
69 KivioConnectorTarget *pTarget = new KivioConnectorTarget( m_position.x(), m_position.y(), m_xOffset, m_yOffset );
70
71 return pTarget;
72}
73
74
81KivioConnectorTarget::~KivioConnectorTarget()
82{
83 // Iterate through all connectors diconnecting them from this
84 KivioConnectorPoint *point;
85
86 if( m_pConnectors )
87 {
88 point = m_pConnectors->first();
89 point = m_pConnectors->take();
90
91 while( point )
92 {
93 kdDebug(43000) << "KivioConnectorTarget:: -> diconnecting" << endl;
94
95 // Disconnect the point. But tell the point to not call
96 // KivioConnectorTarget::removeConnectorFromList() because it will cause our
97 // position in the list to be screwed up.
98 point->disconnect( false );
99
100 point = m_pConnectors->take();
101 }
102
103 delete m_pConnectors;
104 m_pConnectors = NULL;
105 }
106}
107
108
112bool KivioConnectorTarget::loadXML( const TQDomElement &e )
113{
114 if( e.tagName().compare( "KivioConnectorTarget" ) != 0 )
115 {
116 kdDebug(43000) << "Attempted to load KivioConnectorTarget from non-KivioConnectorTarget element" << endl;
117 return false;
118 }
119
120 m_position.setX(XmlReadFloat( e, "x", 1.0f ));
121 m_position.setY(XmlReadFloat( e, "y", 1.0f ));
122
123 m_id = XmlReadInt( e, "id", -1 );
124
125 return true;
126}
127
128
132TQDomElement KivioConnectorTarget::saveXML( TQDomDocument &doc )
133{
134 TQDomElement e;
135
136 e = doc.createElement("KivioConnectorTarget");
137
138 XmlWriteFloat( e, "x", m_position.x() );
139 XmlWriteFloat( e, "y", m_position.y() );
140
141 if( m_id != -1 )
142 XmlWriteInt( e, "id", m_id );
143
144 return e;
145}
146
147
151void KivioConnectorTarget::addConnectorPointToList( KivioConnectorPoint *p )
152{
153 if( p )
154 m_pConnectors->append(p);
155}
156
157
166bool KivioConnectorTarget::removeConnectorPointFromList( KivioConnectorPoint *p )
167{
168 if( !p )
169 return false;
170
171
172 return m_pConnectors->remove(p);
173}
174
175
179void KivioConnectorTarget::setX( float _x )
180{
181 m_position.setX(_x);
182
183 KivioConnectorPoint *pPoint = m_pConnectors->first();
184 while( pPoint )
185 {
186 pPoint->setX( _x, true );
187
188 pPoint = m_pConnectors->next();
189 }
190}
191
192
196
197void KivioConnectorTarget::setY( float _y )
198{
199 m_position.setY(_y);
200
201 KivioConnectorPoint *pPoint = m_pConnectors->first();
202 while( pPoint )
203 {
204 pPoint->setY( _y, true );
205
206 pPoint = m_pConnectors->next();
207 }
208}
209
210
214
215void KivioConnectorTarget::setPosition( float _x, float _y )
216{
217 m_position.setX( _x );
218 m_position.setY( _y );
219
220 KivioConnectorPoint *pPoint = m_pConnectors->first();
221 while( pPoint )
222 {
223 pPoint->setPosition( _x, _y, true );
224
225 pPoint = m_pConnectors->next();
226 }
227}
228
229
233void KivioConnectorTarget::paintOutline( KivioIntraStencilData *pData )
234{
235 KivioConnectorPoint *pPoint;
236 KivioStencil *pStencil;
237
238 pPoint = m_pConnectors->first();
239 while( pPoint )
240 {
241 pStencil = pPoint->stencil();
242
243 if( pStencil )
244 pStencil->paintOutline( pData );
245
246 pPoint = m_pConnectors->next();
247 }
248}
249
250
254bool KivioConnectorTarget::hasConnections()
255{
256 KivioConnectorPoint *pPoint = m_pConnectors->first();
257
258 if( pPoint )
259 return true;
260
261 return false;
262}
263
264
268void KivioConnectorTarget::setId( int i )
269{
270 KivioConnectorPoint *pPoint = m_pConnectors->first();
271 m_id= i;
272
273 while( pPoint )
274 {
275 pPoint->setTargetId( i );
276
277 pPoint = m_pConnectors->next();
278 }
279}
280
281void KivioConnectorTarget::setOffsets(double x, double y)
282{
283 m_xOffset = x;
284 m_yOffset = y;
285}