1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // hdLineConnectionHandle.cpp - Base class for Handles that are located at locator position
9 //
10 //////////////////////////////////////////////////////////////////////////
11 
12 #include "pgAdmin3.h"
13 
14 // wxWindows headers
15 #include <wx/wx.h>
16 #include <wx/dcbuffer.h>
17 
18 // App headers
19 #include "hotdraw/handles/hdLineConnectionHandle.h"
20 #include "hotdraw/figures/hdPolyLineFigure.h"
21 #include "hotdraw/utilities/hdPoint.h"
22 #include "hotdraw/utilities/hdGeometry.h"
23 #include "hotdraw/main/hdDrawingView.h"
24 
hdLineConnectionHandle(hdPolyLineFigure * figure,hdILocator * loc,int index)25 hdLineConnectionHandle::hdLineConnectionHandle(hdPolyLineFigure *figure, hdILocator *loc, int index):
26 	hdPolyLineHandle(figure, loc, index)
27 {
28 }
29 
invokeEnd(hdMouseEvent & event,hdDrawingView * view)30 void hdLineConnectionHandle::invokeEnd(hdMouseEvent &event, hdDrawingView *view)
31 {
32 	int x = event.GetPosition().x, y = event.GetPosition().y;
33 	hdPolyLineFigure *figure = (hdPolyLineFigure *) getOwner();
34 	//eliminate all handles in the middle of a straight line
35 
36 	if( figure->pointCount(view->getIdx()) > 2 && getIndex() != 0 && getIndex() != (figure->pointCount(view->getIdx()) - 1) )
37 	{
38 		hdPoint p1 = figure->pointAt(view->getIdx(), getIndex() - 1);
39 		hdPoint p2 = figure->pointAt(view->getIdx(), getIndex() + 1);
40 		hdGeometry g;
41 		if(g.lineContainsPoint(p1.x, p1.y, p2.x, p2.y, x, y))
42 		{
43 			figure->removePointAt(view->getIdx(), getIndex());
44 		}
45 	}
46 }
47