File: hdLineConnection.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (293 lines) | stat: -rw-r--r-- 6,578 bytes parent folder | download
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// hdLineConnection.cpp - Base class for line connection figure
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

// wxWindows headers
#include <wx/wx.h>
#include <wx/dcbuffer.h>

// App headers
#include "hotdraw/figures/hdLineConnection.h"
#include "hotdraw/handles/hdChangeConnectionStartHandle.h"
#include "hotdraw/handles/hdChangeConnectionEndHandle.h"
#include "hotdraw/handles/hdLineConnectionHandle.h"
#include "hotdraw/locators/hdPolyLineLocator.h"
#include "hotdraw/utilities/hdArrayCollection.h"

hdLineConnection::hdLineConnection():
	hdPolyLineFigure()
{
	startConnector = NULL;
	endConnector = NULL;
	changeConnStartHandle = NULL;
	changeConnEndHandle = NULL;
}

hdLineConnection::hdLineConnection(int posIdx, hdIFigure *figure1, hdIFigure *figure2):
	hdPolyLineFigure()
{
	//Check figure available positions for diagrams, add at least needed to allow initialization of the class
	int i, start;
	start = basicDisplayBox.CountPositions();
	for(i = start; i < (posIdx + 1); i++)
	{
		AddPosForNewDiagram();
	}

	startConnector = NULL;
	endConnector = NULL;

	if(figure1)
	{
		connectStart(figure1->connectorAt(posIdx, 0, 0));
	}

	if(figure2)
	{
		connectEnd(figure2->connectorAt(posIdx, 0, 0));
	}
}

hdLineConnection::~hdLineConnection()
{
}

hdIConnector *hdLineConnection::getStartConnector()
{
	return startConnector;
}

hdIConnector *hdLineConnection::getEndConnector()
{
	return endConnector;
}

void hdLineConnection::setStartConnector(hdIConnector *connector)
{
	startConnector = connector;
}

void hdLineConnection::setEndConnector(hdIConnector *connector)
{
	endConnector = connector;
}

void hdLineConnection::connectStart(hdIConnector *start, hdDrawingView *view)
{
	if(startConnector == start)
	{
		return;
	}

	disconnectStart();
	startConnector = start;
	connectFigure(startConnector);
}

void hdLineConnection::connectEnd(hdIConnector *end, hdDrawingView *view)
{
	if(endConnector == end)
	{
		return;
	}

	disconnectEnd();
	endConnector = end;
	connectFigure(endConnector);
}

void hdLineConnection::disconnectStart(hdDrawingView *view)
{
	disconnectFigure (startConnector);
	startConnector = NULL;
}

void hdLineConnection::disconnectEnd(hdDrawingView *view)
{
	disconnectFigure (endConnector);
	endConnector = NULL;
}

bool hdLineConnection::canConnectStart(hdIFigure *figure)
{
	return true;
}

bool hdLineConnection::canConnectEnd(hdIFigure *figure)
{
	return true;
}

hdIFigure *hdLineConnection::getStartFigure()
{
	if(startConnector)
	{
		return startConnector->getOwner();
	}

	return NULL;
}

hdIFigure *hdLineConnection::getEndFigure()
{
	if(endConnector)
	{
		return endConnector->getOwner();
	}

	return NULL;
}

void hdLineConnection::updateConnection(int posIdx)
{
	if(startConnector)
	{
		setStartPoint(posIdx, startConnector->findStart(posIdx, this));
	}
	if(endConnector)
	{
		setEndPoint(posIdx, endConnector->findEnd(posIdx, this));
	}
}

hdIHandle *hdLineConnection::getStartHandle()
{
	if(!changeConnStartHandle)
	{
		changeConnStartHandle =  new hdChangeConnectionStartHandle(this);
	}
	return changeConnStartHandle;
}

hdIHandle *hdLineConnection::getEndHandle()
{
	if(!changeConnEndHandle)
	{
		changeConnEndHandle =  new hdChangeConnectionEndHandle(this);
	}
	return changeConnEndHandle;
}

void hdLineConnection::basicMoveBy(int posIdx, int x, int y)
{
	hdPolyLineFigure::basicMoveBy(posIdx, x, y);
	updateConnection(posIdx);
}

bool hdLineConnection::canConnect()
{
	return false;
}

void hdLineConnection::setPointAt (int posIdx, int index, int x, int y)
{
	hdPolyLineFigure::setPointAt(posIdx, index, x, y);
	updateConnection(posIdx);
}

hdCollection *hdLineConnection::handlesEnumerator()
{
	return handles;
}


void hdLineConnection::connectFigure (hdIConnector *connector)
{
	if(connector)
	{
		connector->getOwner()->addObserver(this);
	}
}

void hdLineConnection::disconnectFigure (hdIConnector *connector)
{
	if(connector)
	{
		connector->getOwner()->removeObserver(this);
	}
}

void hdLineConnection::onFigureChanged(int posIdx, hdIFigure *figure)
{
	updateConnection(posIdx);
}

void hdLineConnection::addPoint (int posIdx, int x, int y)
{
	willChange();
	points[posIdx]->addItem((hdObject *) new hdPoint(x, y) );
	//Update handles
	if(points[posIdx]->count() == 1)
	{
		//first point add start handle
		if(handles->count() == 0)
			handles->addItem(getStartHandle());
	}
	else if(points[posIdx]->count() == 2)
	{
		//second point add end handle
		if(handles->count() == 1)
			handles->addItem(getEndHandle());
	}
	else if(points[posIdx]->count() > 2)
	{
		//Locate maximum index if there is need for one new handle then added it
		if( getMaximunIndex() > handles->count() )
		{
			//third and above point, add a polylinehandle before end handle
			handles->insertAtIndex(new hdPolyLineHandle(this, new hdPolyLineLocator(0), 0), handles->count() - 1);
		}
	}
	updateHandlesIndexes();
	changed(posIdx);
}

void hdLineConnection::insertPointAt (int posIdx, int index, int x, int y)
{
	willChange();
	points[posIdx]->insertAtIndex((hdObject *) new hdPoint(x, y), index);
	//Update handles
	//Is there need of a new handle if is first point
	if(index == 0 && handles->count() == 0 )
	{
		//add a new handle "normal" for a point in next position 0,1 in 1... in 0 startHandle is not moved
		handles->insertAtIndex(new hdPolyLineHandle(this, new hdPolyLineLocator(index), index), 1);
	}
	else if(index == (points[posIdx]->count() - 1) &&  handles->count() < getMaximunIndex() ) //last point
	{
		//add a new handle "normal" for a point in before last item position
		handles->insertAtIndex(new hdPolyLineHandle(this, new hdPolyLineLocator(index), index), (points[posIdx]->count() - 1));
	}
	else if(handles->count() < getMaximunIndex())
	{
		//add handle at index
		handles->insertAtIndex(new hdPolyLineHandle(this, new hdPolyLineLocator(index), index), index);
	}
	updateHandlesIndexes();
	changed(posIdx);
}

//Update points between start and end, because start and end don't have index (is other kind of handle)
void hdLineConnection::updateHandlesIndexes()
{
	hdPolyLineHandle *h = NULL;

	//Get maximun point position in a collection of points
	int maxPosition = getMaximunIndex();

	//Update Handles indexes
	for(int i = 1; i < maxPosition - 1; i++)
	{
		h = (hdPolyLineHandle *) handles->getItemAt(i);
		h->setIndex(i);
	}
}