1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 2001, Universiteit Twente, Enschede.
5
// Author: David N. Jansen (dnjansen@cs.utwente.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
///////////////////////////////////////////////////////////////////////////////
23
#include "polypoint.h"
27
const PolyPoint PolyPoint::TopLeft ( 0, -0.5, 0, 0, 0, 0, -0.5, 0, true);
28
const PolyPoint PolyPoint::Top ( 0, 0 , 0, 0, 0, 0, -0.5, 0, true);
29
const PolyPoint PolyPoint::TopRight ( 0, 0.5, 0, 0, 0, 0, -0.5, 0, true);
30
const PolyPoint PolyPoint::Right ( 0, 0.5, 0, 0, 0, 0, 0 , 0, true);
31
const PolyPoint PolyPoint::BottomRight ( 0, 0.5, 0, 0, 0, 0, 0.5, 0, true);
32
const PolyPoint PolyPoint::Bottom ( 0, 0 , 0, 0, 0, 0, 0.5, 0, true);
33
const PolyPoint PolyPoint::BottomLeft ( 0, -0.5, 0, 0, 0, 0, 0.5, 0, true);
34
const PolyPoint PolyPoint::Left ( 0, -0.5, 0, 0, 0, 0, 0 , 0, true);
36
const PolyPoint PolyPoint::TopLeft1 ( 1, -0.5, 0, 0, 1, 0, -0.5, 0);
37
const PolyPoint PolyPoint::Top1 ( 0, 0 , 0, 0, 1, 0, -0.5, 0);
38
const PolyPoint PolyPoint::TopRight1 (-1, 0.5, 0, 0, 1, 0, -0.5, 0);
39
const PolyPoint PolyPoint::Right1 (-1, 0.5, 0, 0, 0, 0, 0 , 0);
40
const PolyPoint PolyPoint::BottomRight1(-1, 0.5, 0, 0, -1, 0, 0.5, 0);
41
const PolyPoint PolyPoint::Bottom1 ( 0, 0 , 0, 0, -1, 0, 0.5, 0);
42
const PolyPoint PolyPoint::BottomLeft1 ( 1, -0.5, 0, 0, -1, 0, 0.5, 0);
43
const PolyPoint PolyPoint::Left1 ( 1, -0.5, 0, 0, 0, 0, 0 , 0);
45
#define INV6 (1.0/6.0)
46
const PolyPoint PolyPoint::FolderTR1 ( 0, 0.5, 0, 0, 0, 0,-INV6, 0, true);
47
const PolyPoint PolyPoint::FolderTR2 ( 0,-INV6, 0, 0, 0, 0,-INV6, 0, true);
48
const PolyPoint PolyPoint::FolderTR3 ( 0,-INV6, 0, 0, 0, 0, -0.5, 0, true);
49
const PolyPoint PolyPoint::FolderLeft ( 0, -0.5, 0, 0, 0, 0,-INV6, 0);
51
const PolyPoint PolyPoint::TopLeftInv ( 0, -0.5, 0, 0, 0, 0, -0.5, 0);
52
const PolyPoint PolyPoint::TopRightInv ( 0, 0.5, 0, 0, 0, 0, -0.5, 0);
53
const PolyPoint PolyPoint::BottomRightInv( 0, 0.5, 0, 0, 0, 0, 0.5, 0);
54
const PolyPoint PolyPoint::BottomLeftInv ( 0, -0.5, 0, 0, 0, 0, 0.5, 0);
56
const PolyPoint PolyPoint::Index (0, 0 , 0 ,0, 7, 0 ,-0.5,0);
57
const PolyPoint PolyPoint::Dupli (0,-0.4 , 0 ,0, 7, 0 ,-0.5,0);
58
const PolyPoint PolyPoint::Multi (0, 0.4 , 0 ,0, 7, 0 ,-0.5,0);
60
const PolyPoint PolyPoint::TopArc (0, 0 ,0,0, 0,0,-0.5,0, true, true);
61
const PolyPoint PolyPoint::RightArc (0, 0.5,0,0, 0,0, 0 ,0, true, true);
62
const PolyPoint PolyPoint::BottomArc (0, 0 ,0,0, 0,0, 0.5,0, true, true);
63
const PolyPoint PolyPoint::LeftArc (0,-0.5,0,0, 0,0, 0 ,0, true, true);
65
const PolyPoint PolyPoint::TopArc1 ( 0, 0 ,0,0, 1,0,-0.5,0, false, true);
66
const PolyPoint PolyPoint::RightArc1 (-1, 0.5,0,0, 0,0, 0 ,0, false, true);
67
const PolyPoint PolyPoint::BottomArc1 ( 0, 0 ,0,0, -1,0, 0.5,0, false, true);
68
const PolyPoint PolyPoint::LeftArc1 ( 1,-0.5,0,0, 0,0, 0 ,0, false, true);
70
const PolyPoint PolyPoint::TopAbsArc ( 0, 0, 0, 0, -4, 0, 0, 0, false, true);
71
const PolyPoint PolyPoint::RightAbsArc ( 4, 0, 0, 0, 0, 0, 0, 0, false, true);
72
const PolyPoint PolyPoint::BottomAbsArc( 0, 0, 0, 0, 4, 0, 0, 0, false, true);
73
const PolyPoint PolyPoint::LeftAbsArc (-4, 0, 0, 0, 0, 0, 0, 0, false, true);
75
const PolyPoint PolyPoint::TopLeftSq (0,-0.25,-0.25,0, 0,-0.25,-0.25,0,true);
76
const PolyPoint PolyPoint::TopSq (0, 0 , 0 ,0, 0,-0.25,-0.25,0,true);
77
const PolyPoint PolyPoint::TopRightSq (0, 0.25, 0.25,0, 0,-0.25,-0.25,0,true);
78
const PolyPoint PolyPoint::RightSq (0, 0.25, 0.25,0, 0, 0 , 0 ,0,true);
79
const PolyPoint PolyPoint::BottomRightSq(0, 0.25, 0.25,0, 0, 0.25, 0.25,0,true);
80
const PolyPoint PolyPoint::BottomSq (0, 0 , 0 ,0, 0, 0.25, 0.25,0,true);
81
const PolyPoint PolyPoint::BottomLeftSq (0,-0.25,-0.25,0, 0, 0.25, 0.25,0,true);
82
const PolyPoint PolyPoint::LeftSq (0,-0.25,-0.25,0, 0, 0 , 0 ,0,true);
84
const PolyPoint PolyPoint::IndexSq (0, 0 , 0 ,0, 0,-1.0/6,-1.0/6,0);
85
const PolyPoint PolyPoint::DupliSq (0,-0.2 ,-0.2 ,0, 0,-1.0/6,-1.0/6,0);
86
const PolyPoint PolyPoint::MultiSq (0, 0.2 , 0.2 ,0, 0,-1.0/6,-1.0/6,0);
88
const PolyPoint PolyPoint::TopSqArc (0, 0 , 0 ,0, 0,-0.25,-0.25,0,true, true);
89
const PolyPoint PolyPoint::RightSqArc (0, 0.25, 0.25,0, 0, 0 , 0 ,0,true, true);
90
const PolyPoint PolyPoint::BottomSqArc(0, 0 , 0 ,0, 0, 0.25, 0.25,0,true, true);
91
const PolyPoint PolyPoint::LeftSqArc (0,-0.25,-0.25,0, 0, 0 , 0 ,0,true, true);
93
const PolyPoint PolyPoint::TopLeftTxt ( 0, 0, 0, -0.5, 0, 0, 0, -0.5);
94
const PolyPoint PolyPoint::BottomLeftTxt ( 0, 0, 0, -0.5, 0, 0, 0, 0.5);
95
const PolyPoint PolyPoint::BottomRightTxt ( 0, 0, 0, 0.5, 0, 0, 0, 0.5);
96
const PolyPoint PolyPoint::TopRightTxt ( 0, 0, 0, 0.5, 0, 0, 0, -0.5);
98
const PolyPoint PolyPoint::TopLeftTxt2 (-2, 0, 0, -0.5, -2, 0, 0, -0.5);
99
const PolyPoint PolyPoint::BottomLeftTxt2 (-2, 0, 0, -0.5, 2, 0, 0, 0.5);
100
const PolyPoint PolyPoint::BottomRightTxt2( 2, 0, 0, 0.5, 2, 0, 0, 0.5);
101
const PolyPoint PolyPoint::TopRightTxt2 ( 2, 0, 0, 0.5, -2, 0, 0, -0.5);
103
const PolyPoint PolyPoint::RoundedBoxTTL ( 5,-0.48, 0.02,0, 0, 0 ,-0.5 ,0, true, true);
104
const PolyPoint PolyPoint::RoundedBoxTLL ( 0,-0.5 , 0 ,0, 5, 0.02,-0.48,0, true);
105
const PolyPoint PolyPoint::RoundedBoxBLL ( 0,-0.5 , 0 ,0, -5,-0.02, 0.48,0, true, true);
106
const PolyPoint PolyPoint::RoundedBoxBBL ( 5,-0.48, 0.02,0, 0, 0 , 0.5 ,0, true);
107
const PolyPoint PolyPoint::RoundedBoxBBR (-5, 0.48,-0.02,0, 0, 0 , 0.5 ,0, true, true);
108
const PolyPoint PolyPoint::RoundedBoxBRR ( 0, 0.5 , 0 ,0, -5,-0.02, 0.48,0, true);
109
const PolyPoint PolyPoint::RoundedBoxTRR ( 0, 0.5 , 0 ,0, 5, 0.02,-0.48,0, true, true);
110
const PolyPoint PolyPoint::RoundedBoxTTR (-5, 0.48,-0.02,0, 0, 0 ,-0.5 ,0, true);
112
const PolyPoint PolyPoint::RoundedBoxTTL1( 5,-0.48, 0.02,0, 1, 0 ,-0.5 ,0, false, true);
113
const PolyPoint PolyPoint::RoundedBoxTLL1( 1,-0.5 , 0 ,0, 5, 0.02,-0.48,0);
114
const PolyPoint PolyPoint::RoundedBoxBLL1( 1,-0.5 , 0 ,0, -5,-0.02, 0.48,0, false, true);
115
const PolyPoint PolyPoint::RoundedBoxBBL1( 5,-0.48, 0.02,0, -1, 0 , 0.5 ,0);
116
const PolyPoint PolyPoint::RoundedBoxBBR1(-5, 0.48,-0.02,0, -1, 0 , 0.5 ,0, false, true);
117
const PolyPoint PolyPoint::RoundedBoxBRR1(-1, 0.5 , 0 ,0, -5,-0.02, 0.48,0);
118
const PolyPoint PolyPoint::RoundedBoxTRR1(-1, 0.5 , 0 ,0, 5, 0.02,-0.48,0, false, true);
119
const PolyPoint PolyPoint::RoundedBoxTTR1(-5, 0.48,-0.02,0, 1, 0 ,-0.5 ,0);
121
const PolyPoint PolyPoint::SubtitleTLSq(-3, 0, 0, -0.5, 0, 0.25, 0.25, 0 );
122
const PolyPoint PolyPoint::SubtitleBLSq(-3, 0, 0, -0.5, 6, 0.25, 0.25, 1.0);
123
const PolyPoint PolyPoint::SubtitleTRSq( 3, 0, 0, 0.5, 0, 0.25, 0.25, 0 );
124
const PolyPoint PolyPoint::SubtitleBRSq( 3, 0, 0, 0.5, 6, 0.25, 0.25, 1.0);
126
const PolyPoint PolyPoint::BottomLeftSqInv (0,-0.25,-0.25, 0, 0, 0.25, 0.25, 0);
127
const PolyPoint PolyPoint::BottomSqInv (0, 0 , 0 , 0, 0, 0.25, 0.25, 0);
128
const PolyPoint PolyPoint::BottomRightSqInv(0, 0.25, 0.25, 0, 0, 0.25, 0.25, 0);
130
PolyPoint::PolyPoint(double xu, double xhs, double xvs, double xns, double yu,
131
double yhs, double yvs, double yns, bool ev /* = false */,
132
bool ea /* = false */):
146
void PolyPoint::Write(Grafport *g, double x, double y, double hs, double vs,
147
TextShape *text) const
149
Point p(int(0.5 + x + XUnscaled +
152
XNameScaled * text->GetStringWidth()),
153
int(0.5 + y + YUnscaled +
156
YNameScaled * text->GetStringHeight()));
157
text->SetPosition(&p);
158
text->SetGrafport(g);
163
void PolyPoint::CalcScale(const DPoint *p, double x, double y,
164
double *hs, double *vs, double tw, double th,
165
bool constrainX, bool constrainY)
167
double xx = p->x - x - XUnscaled - tw * XNameScaled;
168
double yy = p->y - y - YUnscaled - th * YNameScaled;
170
// ignore x coordinates. If possible, only change vs
171
if ( YHorizScaled ) {
172
double tempy = *hs * YHorizScaled + *vs * YVertScaled;
175
double factor = yy / tempy;
178
} else if ( YVertScaled )
179
*vs = yy / YVertScaled;
183
// ignore y coordinates. If possible, only change hs
185
double tempx = *hs * XHorizScaled + *vs * XVertScaled;
188
double factor = xx / tempx;
191
} else if ( XHorizScaled )
192
*hs = xx / XHorizScaled;
196
// ( a11 a12 ) ( x1 ) ( b1 )
198
// ( a21 a22 ) ( x2 ) ( b2 )
199
// double a11 = XHorizScaled, a12 = XVertScaled;
200
// double a21 = YHorizScaled, a22 = YVertScaled;
201
double det = XHorizScaled * YVertScaled - XVertScaled * YHorizScaled;
205
*hs = (xx * YVertScaled - yy * XVertScaled ) / det;
206
*vs = (yy * XHorizScaled - xx * YHorizScaled) / det;
209
// handle degenerate case: there may be a constraint, but a
212
double tempx = *hs * XHorizScaled + *vs * XVertScaled;
213
double tempy = *hs * YHorizScaled + *vs * YVertScaled;
214
if ( 0.0 != tempx && 0.0 != tempy )
215
factor = (xx / tempx + yy / tempy) * 0.5;
216
else if ( 0.0 != tempx )
218
else if ( 0.0 != tempy )