1
////////////////////////////////////////////////////////////////////////////////
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).
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.
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.
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
22
////////////////////////////////////////////////////////////////////////////////
25
#include "inputfile.h"
26
#include "outputfile.h"
27
#include "t4tlistline.h"
31
#include "diagramviewer.h"
32
#include "shapeview.h"
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) {
42
T4TListLine::T4TListLine(ShapeView *v, Grafport *g, GShape *n1, GShape *n2,
43
bool Curved): T4Line(v, g, n1, n2, Curved) {
47
T4TListLine::T4TListLine(const T4TListLine &aline): T4Line(aline) {
50
void T4TListLine::InitTextShapes() {
51
tlist = new List<TextShape *>;
54
T4TListLine::~T4TListLine() {
58
void T4TListLine::DrawTextShapes() {
59
T4Line::DrawTextShapes();
63
void T4TListLine::DrawShape() {
67
void T4TListLine::CalcPositionTextShapes() {
68
T4Line::CalcPositionTextShapes();
69
CalcPositionTextShapeList();
72
void T4TListLine::UpdateTListTextShape(const string *s, unsigned n) {
75
tlist->elem(n)->SetString(s);
80
void T4TListLine::SetSelect(bool s) {
84
bool T4TListLine::InTextArea(int x, int y) {
85
if (T4Line::InTextArea(x, y))
88
for (tlist->first(); !tlist->done(); tlist->next())
89
if (tlist->cur()->InTextArea(x, y))
94
TextShape *T4TListLine::HitTextShape(int x, int y) {
95
TextShape *textShape = T4Line::HitTextShape(x, y);
99
for (tlist->first(); !tlist->done(); tlist->next()) {
100
if (tlist->cur()->ContainsPt(x, y))
106
TextShape *T4TListLine::ChooseTextShape(int x, int y) {
107
return T4Line::ChooseTextShape(x, y);
110
bool T4TListLine::HasTextShape(TextShape *t) const {
111
if (T4Line::HasTextShape(t))
113
for (tlist->first(); !tlist->done(); tlist->next())
114
if (tlist->cur() == t)
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());
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());
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());
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());
153
void T4TListLine::WriteMembers(OutputFile *ofile) {
154
T4Line::WriteMembers(ofile);
157
ReadDirection::Type2String(GetNameDirection(), &s);
158
(*ofile) << "\t{ NameDirection " << s << " }\n";
160
(*ofile) << "\t{ Messages " << tlist->count() <<" }\n";
162
// Write message positions
163
for (tlist->first(); !tlist->done(); tlist->next()) {
164
(*ofile) << "\t{ TnPosition " << *(tlist->cur()->GetPosition()) << " }\n";
171
bool T4TListLine::ReadMembers(InputFile *ifile, double format) {
173
if (!T4Line::ReadMembers(ifile, format))
178
void T4TListLine::SetTextShape() {
179
T4Line::SetTextShape();
184
void T4TListLine::SetFont(XFont *ft) {
188
void T4TListLine::SetTextColor(const string *c) {
189
T4Line::SetTextColor(c);
192
void T4TListLine::SetAlignment(TextAlign::Type al) {
193
T4Line::SetAlignment(al);
194
for (tlist->first(); !tlist->done(); tlist->next())
195
tlist->cur()->SetAlignment(al);
198
void T4TListLine::SetGrafport(Grafport *g) {
199
T4Line::SetGrafport(g);
200
for (tlist->first(); !tlist->done(); tlist->next())
201
tlist->cur()->SetGrafport(g);
204
void T4TListLine::SetView(ShapeView *v) {
206
for (tlist->first(); !tlist->done(); tlist->next())
207
tlist->cur()->SetView(v);
210
bool T4TListLine::HasString(const string *s, bool sens, bool sub) const {
211
if (T4Line::HasString(s, sens, sub))
217
bool T4TListLine::HasString(const string *s, bool sens, bool sub,
218
List<TextShape *> *list) {
219
bool b = T4Line::HasString(s, sens, sub, list);
223
void T4TListLine::MoveRaw(const Point *delta) {
224
T4Line::MoveRaw(delta);
227
void T4TListLine::CalcPositionTextShapeList() {
228
Point *from, *to, *save;
229
save = from = to = (*GetLine())[0];
230
for (unsigned i = 1; i<=GetLineNumber(); i++) {
232
to = (*GetLine())[i];
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;
242
SetPosition(&pos, False);
246
// keep the position of the name at fixed distance of the line.
249
alpha = atan((double)ht/(double)wd);
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);
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();