~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/dg/polypoint.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
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).
 
6
//
 
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.
 
11
//
 
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.
 
16
//
 
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
 
20
// 02111-1307, USA.
 
21
///////////////////////////////////////////////////////////////////////////////
 
22
 
 
23
#include "polypoint.h"
 
24
 
 
25
#include "grafport.h"
 
26
 
 
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);
 
35
 
 
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);
 
44
 
 
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);
 
50
 
 
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);
 
55
 
 
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);
 
59
 
 
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);
 
64
 
 
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);
 
69
 
 
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);
 
74
 
 
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);
 
83
 
 
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);
 
87
 
 
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);
 
92
 
 
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);
 
97
 
 
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);
 
102
 
 
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);
 
111
 
 
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);
 
120
 
 
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);
 
125
 
 
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);
 
129
 
 
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 */):
 
133
XUnscaled(xu),
 
134
XHorizScaled(xhs),
 
135
XVertScaled(xvs),
 
136
XNameScaled(xns),
 
137
YUnscaled(yu),
 
138
YHorizScaled(yhs),
 
139
YVertScaled(yvs),
 
140
YNameScaled(yns),
 
141
edgeVisible(ev),
 
142
edgeIsArc(ea)
 
143
{
 
144
}
 
145
 
 
146
void PolyPoint::Write(Grafport *g, double x, double y, double hs, double vs,
 
147
        TextShape *text) const
 
148
{
 
149
        Point p(int(0.5 + x + XUnscaled +
 
150
                XHorizScaled * hs +
 
151
                XVertScaled * vs +
 
152
                XNameScaled * text->GetStringWidth()),
 
153
                int(0.5 + y + YUnscaled +
 
154
                YHorizScaled * hs +
 
155
                YVertScaled * vs +
 
156
                YNameScaled * text->GetStringHeight()));
 
157
        text->SetPosition(&p);
 
158
        text->SetGrafport(g);
 
159
        text->Draw();
 
160
}
 
161
 
 
162
 
 
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)
 
166
{
 
167
        double xx = p->x - x - XUnscaled - tw * XNameScaled;
 
168
        double yy = p->y - y - YUnscaled - th * YNameScaled;
 
169
        if ( constrainX ) {
 
170
                // ignore x coordinates. If possible, only change vs
 
171
                if ( YHorizScaled ) {
 
172
                        double tempy = *hs * YHorizScaled + *vs * YVertScaled;
 
173
                        if ( 0.0 == tempy )
 
174
                                return;
 
175
                        double factor = yy / tempy;
 
176
                        *hs *= factor;
 
177
                        *vs *= factor;
 
178
                } else if ( YVertScaled )
 
179
                        *vs = yy / YVertScaled;
 
180
                return;
 
181
        }
 
182
        if ( constrainY ) {
 
183
                // ignore y coordinates. If possible, only change hs
 
184
                if ( XVertScaled ) {
 
185
                        double tempx = *hs * XHorizScaled + *vs * XVertScaled;
 
186
                        if ( 0.0 == tempx )
 
187
                                return;
 
188
                        double factor = xx / tempx;
 
189
                        *hs *= factor;
 
190
                        *vs *= factor;
 
191
                } else if ( XHorizScaled )
 
192
                        *hs = xx / XHorizScaled;
 
193
                return;
 
194
        }
 
195
        // Ax = b
 
196
        // ( a11   a12 )   ( x1 )   ( b1 )
 
197
        // (           ) * (    ) = (    )
 
198
        // ( a21   a22 )   ( x2 )   ( b2 )
 
199
        // double a11 = XHorizScaled, a12 = XVertScaled;
 
200
        // double a21 = YHorizScaled, a22 = YVertScaled;
 
201
        double det = XHorizScaled * YVertScaled - XVertScaled * YHorizScaled;
 
202
        if ( det ) {
 
203
                // double b1 = xx;
 
204
                // double b2 = yy;
 
205
                *hs = (xx * YVertScaled  - yy * XVertScaled ) / det;
 
206
                *vs = (yy * XHorizScaled - xx * YHorizScaled) / det;
 
207
                return;
 
208
        }
 
209
        // handle degenerate case: there may be a constraint, but a
 
210
        // non-unique one.
 
211
        double factor;
 
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 )
 
217
                factor = xx / tempx;
 
218
        else if ( 0.0 != tempy )
 
219
                factor = yy / tempy;
 
220
        else
 
221
                return;
 
222
        *hs *= factor;
 
223
        *vs *= factor;
 
224
        return;
 
225
}