~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/dg/t4tlistline.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 2000, Vrije Universiteit Amsterdam and University of Twente.
 
5
// Author: Henk van de Zandschulp (henkz@cs.utwente.nl).
 
6
// Author: Frank Dehne (frank@cs.vu.nl).
 
7
//
 
8
// TCM is free software; you can redistribute it and/or modify
 
9
// it under the terms of the GNU General Public License as published by
 
10
// the Free Software Foundation; either version 2 of the License, or 
 
11
// (at your option) any later version.
 
12
//
 
13
// TCM is distributed in the hope that it will be useful,
 
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
// GNU General Public License for more details.
 
17
//
 
18
// You should have received a copy of the GNU General Public License
 
19
// along with TCM; if not, write to the Free Software
 
20
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
21
// 02111-1307, USA.
 
22
////////////////////////////////////////////////////////////////////////////////
 
23
 
 
24
#include "subject.h"
 
25
#include "inputfile.h"
 
26
#include "outputfile.h"
 
27
#include "t4tlistline.h"
 
28
#include <stdlib.h>
 
29
#include <math.h>
 
30
#include "grafport.h"
 
31
#include "diagramviewer.h"
 
32
#include "shapeview.h"
 
33
#include "shape.h"
 
34
#include <limits.h>
 
35
 
 
36
T4TListLine::T4TListLine(ShapeView *v, Grafport *g, GShape *n1, GShape *n2, 
 
37
                List<Point *> *aline, bool Curved): 
 
38
                        T4Line(v, g, n1, n2, aline, Curved) {
 
39
        InitTextShapes();
 
40
}
 
41
 
 
42
T4TListLine::T4TListLine(ShapeView *v, Grafport *g, GShape *n1, GShape *n2, 
 
43
                bool Curved): T4Line(v, g, n1, n2, Curved) {
 
44
        InitTextShapes();
 
45
}
 
46
 
 
47
T4TListLine::T4TListLine(const T4TListLine &aline): T4Line(aline) {
 
48
}
 
49
 
 
50
void T4TListLine::InitTextShapes() {
 
51
        tlist = new List<TextShape *>;
 
52
}
 
53
 
 
54
T4TListLine::~T4TListLine() {
 
55
        delete tlist;
 
56
}
 
57
 
 
58
void T4TListLine::DrawTextShapes() {
 
59
        T4Line::DrawTextShapes();
 
60
}
 
61
 
 
62
 
 
63
void T4TListLine::DrawShape() {
 
64
        T4Line::DrawShape();
 
65
}
 
66
 
 
67
void T4TListLine::CalcPositionTextShapes() {
 
68
        T4Line::CalcPositionTextShapes();
 
69
        CalcPositionTextShapeList();
 
70
}
 
71
 
 
72
void T4TListLine::UpdateTListTextShape(const string *s, unsigned n) {
 
73
        if (IsVisible())
 
74
                Undraw();
 
75
        tlist->elem(n)->SetString(s);
 
76
        if (IsVisible())
 
77
                Draw();
 
78
}
 
79
 
 
80
void T4TListLine::SetSelect(bool s) {
 
81
        T4Line::SetSelect(s);
 
82
}
 
83
 
 
84
bool T4TListLine::InTextArea(int x, int y) {
 
85
        if (T4Line::InTextArea(x, y))
 
86
                return True;
 
87
        else 
 
88
                for (tlist->first(); !tlist->done(); tlist->next())
 
89
                        if (tlist->cur()->InTextArea(x, y))
 
90
                                return True;
 
91
        return False;
 
92
}
 
93
 
 
94
TextShape *T4TListLine::HitTextShape(int x, int y) {
 
95
        TextShape *textShape = T4Line::HitTextShape(x, y);
 
96
        if (textShape)
 
97
                return textShape;
 
98
        else
 
99
                for (tlist->first(); !tlist->done(); tlist->next()) {
 
100
                        if (tlist->cur()->ContainsPt(x, y))
 
101
                                return tlist->cur();
 
102
                }
 
103
        return 0;
 
104
}
 
105
 
 
106
TextShape *T4TListLine::ChooseTextShape(int x, int y) {
 
107
        return T4Line::ChooseTextShape(x, y);
 
108
}
 
109
 
 
110
bool T4TListLine::HasTextShape(TextShape *t) const {
 
111
        if (T4Line::HasTextShape(t))
 
112
                return True;
 
113
        for (tlist->first(); !tlist->done(); tlist->next())
 
114
                if (tlist->cur() == t)
 
115
                        return True;
 
116
        return False;
 
117
}
 
118
 
 
119
int T4TListLine::GetLeftMost() const {
 
120
        int e = T4Line::GetLeftMost();
 
121
        for (tlist->first(); !tlist->done(); tlist->next()) {
 
122
                e = min(e, tlist->cur()->GetLeftMost());
 
123
        }
 
124
        return e;
 
125
}
 
126
 
 
127
int T4TListLine::GetTopMost() const {
 
128
        int e = T4Line::GetTopMost();
 
129
        for (tlist->first(); !tlist->done(); tlist->next()) {
 
130
                e = min(e, tlist->cur()->GetTopMost());
 
131
        }
 
132
        return e;
 
133
}
 
134
 
 
135
int T4TListLine::GetRightMost() const {
 
136
        int e = T4Line::GetRightMost();
 
137
        for (tlist->first(); !tlist->done(); tlist->next()) {
 
138
                e = max(e, tlist->cur()->GetRightMost());
 
139
        }
 
140
        return e;
 
141
}
 
142
 
 
143
int T4TListLine::GetBottomMost() const {
 
144
        int e = T4Line::GetBottomMost();
 
145
        for (tlist->first(); !tlist->done(); tlist->next()) {
 
146
                e = max(e, tlist->cur()->GetBottomMost());
 
147
        }
 
148
        return e;
 
149
}
 
150
 
 
151
 
 
152
 
 
153
void T4TListLine::WriteMembers(OutputFile *ofile) {
 
154
        T4Line::WriteMembers(ofile);
 
155
 
 
156
        string s;
 
157
        ReadDirection::Type2String(GetNameDirection(), &s);
 
158
        (*ofile) << "\t{ NameDirection " << s << " }\n";
 
159
 
 
160
        (*ofile) << "\t{ Messages " << tlist->count() <<" }\n";
 
161
 
 
162
        // Write message positions
 
163
        for (tlist->first(); !tlist->done(); tlist->next()) {
 
164
                (*ofile) << "\t{ TnPosition " << *(tlist->cur()->GetPosition()) << " }\n";
 
165
 
 
166
        }
 
167
 
 
168
 
 
169
}
 
170
 
 
171
bool T4TListLine::ReadMembers(InputFile *ifile, double format) {
 
172
        string val1, val2;
 
173
        if (!T4Line::ReadMembers(ifile, format))
 
174
                return False;
 
175
        return True;
 
176
}
 
177
 
 
178
void T4TListLine::SetTextShape() {
 
179
        T4Line::SetTextShape();
 
180
        tlist->clear();
 
181
}
 
182
 
 
183
 
 
184
void T4TListLine::SetFont(XFont *ft) {
 
185
        T4Line::SetFont(ft);
 
186
}
 
187
 
 
188
void T4TListLine::SetTextColor(const string *c) {
 
189
        T4Line::SetTextColor(c);
 
190
}
 
191
 
 
192
void T4TListLine::SetAlignment(TextAlign::Type al) {
 
193
        T4Line::SetAlignment(al);
 
194
        for (tlist->first(); !tlist->done(); tlist->next())
 
195
                tlist->cur()->SetAlignment(al);
 
196
}
 
197
 
 
198
void T4TListLine::SetGrafport(Grafport *g) {
 
199
        T4Line::SetGrafport(g);
 
200
        for (tlist->first(); !tlist->done(); tlist->next())
 
201
                tlist->cur()->SetGrafport(g);
 
202
}
 
203
 
 
204
void T4TListLine::SetView(ShapeView *v) {
 
205
        T4Line::SetView(v);
 
206
        for (tlist->first(); !tlist->done(); tlist->next())
 
207
                tlist->cur()->SetView(v);
 
208
}
 
209
 
 
210
bool T4TListLine::HasString(const string *s, bool sens, bool sub) const {
 
211
        if (T4Line::HasString(s, sens, sub))
 
212
                return True;
 
213
        else
 
214
                return False;
 
215
}
 
216
 
 
217
bool T4TListLine::HasString(const string *s, bool sens, bool sub, 
 
218
                        List<TextShape *> *list) {
 
219
        bool b = T4Line::HasString(s, sens, sub, list);
 
220
        return b;
 
221
}
 
222
 
 
223
void T4TListLine::MoveRaw(const Point *delta) {
 
224
        T4Line::MoveRaw(delta);
 
225
}
 
226
 
 
227
void T4TListLine::CalcPositionTextShapeList() {
 
228
        Point *from, *to, *save;
 
229
        save = from = to = (*GetLine())[0];
 
230
        for (unsigned i = 1; i<=GetLineNumber(); i++) {
 
231
                from = save;
 
232
                to = (*GetLine())[i];
 
233
                save = to;
 
234
        }
 
235
        Point pos = *GetPosition();
 
236
        int wd = to->x - from->x;
 
237
        int ht = to->y - from->y;
 
238
        pos.x = min(from->x, to->x) + abs(wd) / 2;
 
239
        pos.y = min(from->y, to->y) + abs(ht) / 2;
 
240
        SetWidth(wd);
 
241
        SetHeight(ht);
 
242
        SetPosition(&pos, False);
 
243
        if (IsCurved()) {               
 
244
                return;
 
245
        }
 
246
        // keep the position of the name at fixed distance of the line.
 
247
        double alpha;
 
248
        if (wd != 0)
 
249
                alpha = atan((double)ht/(double)wd);
 
250
        else
 
251
                alpha = 2*atan(1);
 
252
        double extrax = (CL_DISTX * sin(alpha));
 
253
        double extray = (CL_DISTY * cos(alpha));
 
254
        if (extray <= 0.01 && extray >= -0.01)
 
255
                extrax = -fabs(extrax);
 
256
        Point pt;
 
257
        pt.x = pos.x - (int)extrax;
 
258
        pt.y = pos.y + (int)extray;
 
259
        for (tlist->first(); !tlist->done(); tlist->next()) {
 
260
                tlist->cur()->SetPosition(&pt);
 
261
                pt.y += tlist->cur()->GetFontHeight();
 
262
        }
 
263
        CalcDirection();
 
264
}