File: ddRelationshipTerminal.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 (154 lines) | stat: -rw-r--r-- 4,719 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
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ddRelationshipTerminal.cpp - Draw inverse arrows at fk terminal based on kind of relationship.
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

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

// App headers
#include "dd/dditems/figures/ddRelationshipTerminal.h"
#include "hotdraw/utilities/hdPoint.h"
#include "hotdraw/utilities/hdRect.h"
#include "hotdraw/main/hdDrawingView.h"
#include "hotdraw/utilities/hdGeometry.h"

ddRelationshipTerminal::ddRelationshipTerminal(ddRelationshipFigure *owner, bool endFigureTerminal)
{
	ownerFigure = owner;
	endTerminal = endFigureTerminal;
}

ddRelationshipTerminal::~ddRelationshipTerminal()
{
}

hdPoint &ddRelationshipTerminal::draw (wxBufferedDC &context, hdPoint &a, hdPoint &b, hdDrawingView *view)
{
	hdGeometry g;
	hdPoint points[3];

	context.SetPen(terminalLinePen);

	hdPoint aCopy = a, bCopy = b;
	view->CalcScrolledPosition(aCopy.x, aCopy.y, &aCopy.x, &aCopy.y);
	view->CalcScrolledPosition(bCopy.x, bCopy.y, &bCopy.x, &bCopy.y);

	if(endTerminal)
	{
		//Calc a point very far away of center of table to intersect one of the sides lines of the table rectangle figure
		double X = aCopy.x + (bCopy.x - aCopy.x) * 0.9;
		double Y = aCopy.y + (bCopy.y - aCopy.y) * 0.9;

		if(ownerFigure->getEndFigure() && ownerFigure->getOneToMany())
		{
			hdRect r = ownerFigure->getEndFigure()->displayBox().gethdRect(view->getIdx());

			view->CalcScrolledPosition(r.x, r.y, &r.x, &r.y);

			int centerX = r.x + r.width / 2;
			int centerY = r.y + r.height / 2;

			context.SetPen(*wxBLACK_PEN);
			context.SetBrush(*wxBLACK_BRUSH);

			double XX, YY, distance;

			//Calculate a new point to a given distance from the end of the relationship to draw many ( ----<| ) connector
			//first calculate vector from point1 & point2
			double vectorx = aCopy.x - bCopy.x;
			double vectory = aCopy.y - bCopy.y;
			//calculate the length
			double length = sqrt(vectorx * vectorx + vectory * vectory);
			//normalize the vector to unit length
			double normalizevx = vectorx / length;
			double normalizevy = vectory / length;
			distance = -15;
			//calculate point a given distance
			XX = bCopy.x + normalizevx * (length + distance);
			YY = bCopy.y + normalizevy * (length + distance);

			wxPoint intersectionLine1(centerX, centerY);
			wxPoint intersectionLine2(X, Y);

			//TOP
			if(g.intersection(intersectionLine1, intersectionLine2, r.GetTopLeft(), r.GetTopRight()))
			{
				points[0] = wxPoint(XX, YY);
				points[1] = wxPoint(aCopy.x - 7, aCopy.y);
				points[2] = wxPoint(aCopy.x + 7, aCopy.y);
				context.DrawPolygon(3, points);

				if(ownerFigure->getIdentifying())
				{
					context.SetPen(wxPen(*wxBLACK, 2));
					context.DrawLine(wxPoint(XX - 7, YY), wxPoint(XX + 7, YY));
					context.SetPen(*wxBLACK_PEN);
				}

			}	//RIGHT
			else if(g.intersection(intersectionLine1, intersectionLine2, r.GetTopRight(), r.GetBottomRight()))
			{
				points[0] = wxPoint(XX, YY);
				points[1] = wxPoint(aCopy.x, aCopy.y - 7);
				points[2] = wxPoint(aCopy.x, aCopy.y + 7);
				context.DrawPolygon(3, points);

				if(ownerFigure->getIdentifying())
				{
					context.SetPen(wxPen(*wxBLACK, 2));
					context.DrawLine(wxPoint(XX, YY - 7), wxPoint(XX, YY + 7));
					context.SetPen(*wxBLACK_PEN);
				}
			}	//BOTTOM
			else if(g.intersection(intersectionLine1, intersectionLine2, r.GetBottomLeft(), r.GetBottomRight()))
			{
				points[0] = wxPoint(XX, YY);
				points[1] = wxPoint(aCopy.x - 7, aCopy.y);
				points[2] = wxPoint(aCopy.x + 7, aCopy.y);
				context.DrawPolygon(3, points);

				if(ownerFigure->getIdentifying())
				{
					context.SetPen(wxPen(*wxBLACK, 2));
					context.DrawLine(wxPoint(XX - 7, YY), wxPoint(XX + 7, YY));
					context.SetPen(*wxBLACK_PEN);
				}
			}	//LEFT
			else if(g.intersection(intersectionLine1, intersectionLine2, r.GetTopLeft(), r.GetBottomLeft()))
			{
				points[0] = wxPoint(XX, YY);
				points[1] = wxPoint(aCopy.x, aCopy.y - 7);
				points[2] = wxPoint(aCopy.x, aCopy.y + 7);
				context.DrawPolygon(3, points);

				if(ownerFigure->getIdentifying())
				{
					context.SetPen(wxPen(*wxBLACK, 2));
					context.DrawLine(wxPoint(XX, YY - 7), wxPoint(XX, YY + 7));
					context.SetPen(*wxBLACK_PEN);
				}
			}
			else
			{
				//CENTER of star figure or invalid place, do nothing
			}

			value = hdPoint(XX, YY);
			return value;
		}
		value = hdPoint(0, 0);
		return value;
	}
	value = hdPoint(0, 0);
	return value;
}