1
//------------------------------------------------------------------------------
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1999, Vrije Universiteit Amsterdam and University of Twente.
5
// Author: Frank Dehne (frank@cs.vu.nl).
6
// Author: Henk van de Zandschulp (henkz@cs.utwente.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 Foundation, Inc.,
20
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
//-----------------------------------------------------------------------------
23
#include "ssdsingleclassbox.h"
24
#include "ssddoubleclassbox.h"
25
#include "ssdtripleclassbox.h"
26
#include "ssdclassnode.h"
27
#include "diagramviewer.h"
28
#include "inputfile.h"
29
#include "outputfile.h"
32
SSDDoubleClassBox::SSDDoubleClassBox(ShapeView *v, Grafport *g, int x, int y,
33
int w, int h): DoubleClassBox(v, g, x, y, w, h) {
34
stereotypeLabel = new TextShape(v, g, this);
35
stereotypeLabel->SetOneLine(True);
36
stereotypeLabel->SetDescription("Stereotype");
37
string my_stereo = "<<SSDDoubleClassBox>>";
38
stereotypeLabel->SetString(&my_stereo);
39
propertiesLabel = new TextShape(v, g, this);
40
propertiesLabel->SetOneLine(False);
41
propertiesLabel->SetDescription("Properties");
42
string my_props = "{ SSDDoubleClassBox }";
43
propertiesLabel->SetString(&my_props);
44
showStereotype = False;
45
showProperties = False;
46
SetSize(w, RequiredHeight());
49
SSDDoubleClassBox::~SSDDoubleClassBox() {
50
delete stereotypeLabel;
51
delete propertiesLabel;
54
SSDDoubleClassBox::SSDDoubleClassBox(const SSDDoubleClassBox &s): DoubleClassBox(s) {
55
showStereotype = s.showStereotype;
56
showProperties = s.showProperties;
57
stereotypeLabel = new TextShape(*s.stereotypeLabel);
58
propertiesLabel = new TextShape(*s.propertiesLabel);
59
stereotypeLabel->SetParent(this);
60
propertiesLabel->SetParent(this);
61
SetSize(s.GetWidth(), s.GetHeight());
64
SSDDoubleClassBox::SSDDoubleClassBox(const SSDSingleClassBox &s): DoubleClassBox(s) {
65
showStereotype = s.IsShowStereotype();
66
showProperties = s.IsShowProperties();
67
stereotypeLabel = new TextShape(*s.GetStereotypeLabel());
68
propertiesLabel = new TextShape(*s.GetPropertiesLabel());
69
stereotypeLabel->SetParent(this);
70
propertiesLabel->SetParent(this);
72
AdjustSizes(GetName()->GetString());
75
SSDDoubleClassBox::SSDDoubleClassBox(const SSDTripleClassBox &s): DoubleClassBox(s) {
76
showStereotype = s.IsShowStereotype();
77
showProperties = s.IsShowProperties();
78
stereotypeLabel = new TextShape(*s.GetStereotypeLabel());
79
propertiesLabel = new TextShape(*s.GetPropertiesLabel());
80
stereotypeLabel->SetParent(this);
81
propertiesLabel->SetParent(this);
83
AdjustSizes(GetName()->GetString());
86
void SSDDoubleClassBox::SetGrafport(Grafport *g) {
87
DoubleClassBox::SetGrafport(g);
88
stereotypeLabel->SetGrafport(g);
89
propertiesLabel->SetGrafport(g);
92
void SSDDoubleClassBox::SetView(ShapeView *v) {
93
DoubleClassBox::SetView(v);
94
stereotypeLabel->SetView(v);
95
propertiesLabel->SetView(v);
98
bool SSDDoubleClassBox::HasTextShape(TextShape *t) const {
99
if (DoubleClassBox::HasTextShape(t))
101
if (GetStereotypeLabel() == t)
103
if (GetPropertiesLabel() == t)
108
bool SSDDoubleClassBox::HasString(const string *s, bool sens, bool sub) const {
109
if (DoubleClassBox::HasString(s, sens, sub))
111
if (showStereotype && stereotypeLabel->HasString(s, sens, sub))
113
if (showProperties && propertiesLabel->HasString(s, sens, sub))
118
bool SSDDoubleClassBox::HasString(const string *s, bool sens, bool sub,
119
List<TextShape *> *list) {
120
bool b = DoubleClassBox::HasString(s, sens, sub, list);
121
if (showStereotype && stereotypeLabel->HasString(s, sens, sub, list))
123
if (showProperties && propertiesLabel->HasString(s, sens, sub, list))
128
void SSDDoubleClassBox::SetTextShape() {
129
DoubleClassBox::SetTextShape();
130
if (!check(GetSubject() &&
131
GetSubject()->GetClassType()==Code::SSD_CLASS_NODE))
133
GetStereotypeLabel()->SetString(
134
((SSDClassNode *)GetSubject())->GetStereotype());
135
GetStereotypeLabel()->SetParent(this);
136
GetPropertiesLabel()->SetString(
137
((SSDClassNode *)GetSubject())->GetProperties());
138
GetPropertiesLabel()->SetParent(this);
139
// CalcPositionLabels();
142
void SSDDoubleClassBox::SetFont(XFont *ft) {
143
DoubleClassBox::SetFont(ft);
144
stereotypeLabel->SetFont(ft);
145
propertiesLabel->SetFont(ft);
146
// CalcPositionLabels();
149
void SSDDoubleClassBox::SetTextColor(const string *c) {
150
DoubleClassBox::SetTextColor(c);
151
stereotypeLabel->SetColor(c);
152
propertiesLabel->SetColor(c);
155
void SSDDoubleClassBox::UpdateShowStereotype(bool b) {
156
if (b == showStereotype)
161
// CalcPositionLabels();
166
void SSDDoubleClassBox::UpdateShowProperties(bool b) {
167
if (b == showProperties)
172
// CalcPositionLabels();
177
void SSDDoubleClassBox::DrawTextShapes() {
178
string oldBackground;
179
Grafport *g = GetGrafport();
180
if (GetFillStyle() != FillStyle::UNFILLED) {
181
oldBackground = *g->GetBackgroundColor();
182
g->SetBackgroundColor(GetFillColor()->getstr());
184
NodeShape::DrawTextShapes();
185
int textHeight = GetName()->GetFontHeight();
186
int addLines = (showStereotype ? 1 : 0);
187
// min_firstboxlines : 2 when no <<stereotype>> / {props} shown
188
int min_firstboxlines = ((showStereotype || showProperties) ? 1 : 2);
189
int labelLines = max(GetName()->GetString()->lines(),min_firstboxlines);
190
// calculate first_compartmentHeight
192
addLines += GetPropertiesLabelString()->lines();
193
int snpHeight = (addLines+labelLines) * textHeight;
194
if (snpHeight < GetHeight()) {
195
g->SetLineStyle(GetSeparatorLineStyle());
196
g->DrawLine(GetLeftMost()+1, GetTopMost()+snpHeight+1,
198
GetTopMost()+snpHeight+1);
199
g->SetLineStyle(GetLineStyle());
202
for (GetLabels()->first(); !GetLabels()->done(); GetLabels()->next()) {
205
GetLabels()->cur()->Draw();
208
if (GetFillStyle() != FillStyle::UNFILLED)
209
g->SetBackgroundColor(oldBackground.getstr());
211
stereotypeLabel->Draw();
213
propertiesLabel->Draw();
216
void SSDDoubleClassBox::AdjustSize() {
217
int twd = RequiredWidth();
218
int ht = RequiredHeight();
219
if (twd > GetWidth() || ht != GetHeight()) {
220
int wd = max((twd+2*TEXTMARGIN), GetWidth());
222
GetViewer()->ShapePositionUpdate(this);
225
// CalcPositionLabels();
228
void SSDDoubleClassBox::AdjustSizes(const string *) {
229
if (!GetViewer()->IsAutoResize()) {
230
// CalcPositionLabels();
233
int twd = RequiredWidth();
234
int ht = RequiredHeight();
235
if (twd > GetWidth() || GetHeight() != ht) {
236
int wd = max((twd+2*TEXTMARGIN), GetWidth());
238
GetViewer()->ShapePositionUpdate(this);
241
// CalcPositionLabels();
244
void SSDDoubleClassBox::CalcPositionLabels() {
245
DoubleClassBox::CalcPositionLabels();
247
Point pt = *GetPosition();
248
// calculate labelnameHeight first
249
int textHeight = GetName()->GetFontHeight();
250
int addLines = (showStereotype ? 1 : 0);
251
// min_firstboxlines : 2 when no <<stereotype>> / {props} shown
252
int min_firstboxlines = ((showStereotype || showProperties) ? 1 : 2);
253
int labelLines = max(GetName()->GetString()->lines(),min_firstboxlines);
254
int nameHeight = labelLines * textHeight;
255
// calculate first_compartmentHeight
257
addLines += GetPropertiesLabelString()->lines();
258
int snpHeight = (addLines+labelLines) * textHeight;
260
pt.y = GetTopMost() + textHeight + nameHeight/2;
262
pt.y = GetTopMost() + nameHeight/2;
263
GetName()->SetPosition(&pt);
265
pt.y = GetTopMost() + snpHeight;
266
pt.y += (3*textHeight)/4;
267
for (GetLabels()->first(); !GetLabels()->done(); GetLabels()->next()) {
268
TextShape *t = GetLabels()->cur();
269
// position and left adjust textshape
270
int w = t->GetStringWidth();
271
pt.x = GetLeftMost() + w/2 + TEXTMARGIN;
276
// set index label position.
277
pt.x = GetName()->GetPosition()->x + GetWidth()*5/12;
278
pt.y = GetName()->GetPosition()->y - nameHeight/4;
279
GetIndexLabel()->SetPosition(&pt);
282
CalcPositionStereotypeLabel();
284
CalcPositionPropertiesLabel();
288
void SSDDoubleClassBox::CalcPositionStereotypeLabel() {
289
int textHeight = GetName()->GetFontHeight();
291
pt.x = GetPosition()->x;
292
pt.y = GetTopMost() + textHeight/2;
293
stereotypeLabel->SetPosition(&pt);
297
void SSDDoubleClassBox::CalcPositionPropertiesLabel() {
298
// calculate labelnameHeight first
299
int textHeight = GetName()->GetFontHeight();
300
int addLines = (showStereotype ? 1 : 0);
301
// min_firstboxlines : 2 when no <<stereotype>> / {props} shown
302
int min_firstboxlines = ((showStereotype || showProperties) ? 1 : 2);
303
int labelLines = max(GetName()->GetString()->lines(),min_firstboxlines);
304
int snHeight = (addLines+labelLines) * textHeight;
305
int propHeight = (showProperties ?
306
GetPropertiesLabelString()->lines()*textHeight : 0);
308
pt.x = GetPosition()->x;
309
pt.y = GetTopMost() + snHeight + propHeight/2;
310
propertiesLabel->SetPosition(&pt);
314
int SSDDoubleClassBox::RequiredHeight() {
315
int textHeight = GetName()->GetFontHeight();
316
int addLines = (showStereotype ? 1 : 0);
317
// min_firstboxlines : 2 when no <<stereotype>> / {props} shown
318
int min_firstboxlines = ((showStereotype || showProperties) ? 1 : 2);
319
int labelLines = max(GetName()->GetString()->lines(),min_firstboxlines);
320
// calculate first_compartmentHeight
322
addLines += GetPropertiesLabelString()->lines();
323
int snpHeight = (addLines+labelLines) * textHeight;
324
int ht = (snpHeight + textHeight + GetLabels()->count()*textHeight);
325
// return max(ht, GetInitialHeight());
329
int SSDDoubleClassBox::RequiredWidth() {
330
int twidth = GetName()->GetWidth();
332
twidth = max(twidth, GetStereotypeLabel()->GetWidth());
334
twidth = max(twidth, GetPropertiesLabel()->GetWidth());
336
for (GetLabels()->first(); !GetLabels()->done(); GetLabels()->next()) {
337
int wd = GetLabels()->cur()->GetStringWidth();
338
twidth = max(twidth, wd);
344
TextShape *SSDDoubleClassBox::ChooseTextShape(int x, int y) {
345
// in first part (of the class name) ?
346
// calculate #labelnameLines first
347
int textHeight = GetName()->GetFontHeight();
348
int addLines = (showStereotype ? 1 : 0);
349
// min_firstboxlines : 2 when no <<stereotype>> / {props} shown
350
int min_firstboxlines = ((showStereotype || showProperties) ? 1 : 2);
351
int labelLines = max(GetName()->GetString()->lines(),min_firstboxlines);
352
int snHeight = (addLines+labelLines) * textHeight;
353
// calculate first_compartmentHeight
355
addLines += GetPropertiesLabelString()->lines();
356
int snpHeight = (addLines+labelLines) * textHeight;
357
int pos_y = GetTopMost() + snpHeight;
359
if (showStereotype) {
360
if (y <= GetTopMost() + textHeight)
361
return GetStereotypeLabel();
363
if (GetViewer()->IsShowIndexes() && !IsFixedIndexLabel()) {
364
if (y <= GetName()->GetPosition()->y &&
365
x >= GetName()->GetPosition()->x + GetWidth()/3)
366
return GetIndexLabel();
368
if (y > GetTopMost() + snHeight)
369
return GetPropertiesLabel();
374
pos_y += textHeight/2;
375
for (GetLabels()->first(); !GetLabels()->done(); GetLabels()->next()) {
377
if (pos_y >= GetTopMost() + GetHeight())
380
return GetLabels()->cur();
382
if (GetViewer()->IsEditing())
384
// somewhere down the list; create a new label.
385
TextShape *t = new TextShape(GetView(), GetGrafport(), this);
386
t->SetAlignment(TextAlign::LEFT);
387
t->SetSequence(GetLabels()->count());
388
t->SetDescription(&labelDescription);
389
t->SetFont(GetName()->GetFont());
390
t->SetColor(GetName()->GetColor());
393
// CalcPositionLabels();
394
// move text shape to a better position.
395
Point pt = *t->GetPosition();
396
pt.x += GetWidth()/2 - TEXTMARGIN;
402
void SSDDoubleClassBox::UpdateStereotypeLabelString(const string *s) {
405
SetStereotypeLabelString(s);
410
void SSDDoubleClassBox::UpdatePropertiesLabelString(const string *s) {
413
SetPropertiesLabelString(s);
418
bool SSDDoubleClassBox::ReadMembers(InputFile *ifile, double format) {
419
if (!DoubleClassBox::ReadMembers(ifile, format))
421
if (format >= 1.28) {
423
if (!ifile->ReadAttribute("ShowStereotype", &val))
425
showStereotype = (val == "True");
426
if (!ifile->ReadAttribute("ShowProperties", &val))
428
showProperties = (val == "True");
431
showStereotype = False;
432
showProperties = False;
437
void SSDDoubleClassBox::WriteMembers(OutputFile *ofile) {
438
DoubleClassBox::WriteMembers(ofile);
439
(*ofile) << "\t{ ShowStereotype " << (showStereotype?"True":"False") << " }\n";
440
(*ofile) << "\t{ ShowProperties " << (showProperties?"True":"False") << " }\n";