1
//------------------------------------------------------------------------------
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 2001, University of Twente.
5
// Author: Henk van de Zandschulp (henkz@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 Foundation, Inc.,
19
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
//-----------------------------------------------------------------------------
22
#include "messagedialog.h"
23
#include "ssdsingleclassbox.h"
24
#include "cbsingleclassbox.h"
25
#include "ssdsingleobjectbox.h"
26
#include "c2r2mlistline.h"
27
#include "t4tlistline.h"
28
#include "commentlink.h"
29
#include "ssdclassnode.h"
30
#include "cbclassnode.h"
31
#include "cbobjectnode.h"
32
#include "ucdsingleclassbox.h"
36
#include "cbclasslinkedge.h"
37
#include "cbobjectlinkedge.h"
48
#include "cbdiagram.h"
49
#include "cbdmessage.h"
53
CBDiagram::CBDiagram(Config *c, CBWindow *w, CBViewer *v, CBGraph *g):
54
ERDiagram(c, w, v, g) {
57
cbChecks = new CBChecks(this, g);
60
CBDiagram::~CBDiagram() {
64
Thing *CBDiagram::CreateThing(int classNr) {
65
Grafport *g = GetDiagramViewer()->GetGrafport();
66
ShapeView *v = GetDiagramViewer()->GetCurView();
67
CBGraph *cg = (CBGraph *)GetGraph();
69
if (classNr == Code::VIEW)
70
thing = new ShapeView(GetDiagramViewer());
73
else if (classNr==Code::UCD_SINGLE_CLASS_BOX)
74
thing = new UCDSingleClassBox(v, g, 0, 0);
75
else if (classNr==Code::STICKMAN)
76
thing = new StickMan(v, g, 0, 0);
77
else if (classNr==Code::SSD_SINGLE_CLASS_BOX)
78
thing = new SSDSingleClassBox(v, g, 0, 0);
79
else if (classNr==Code::CBD_SINGLE_CLASS_BOX)
80
thing = new CBSingleClassBox(v, g, 0, 0);
81
else if (classNr==Code::SSD_SINGLE_OBJECT_BOX)
82
thing = new SSDSingleObjectBox(v, g, 0, 0);
83
else if (classNr==Code::TEXT_BOX)
84
thing = new TextBox(v, g, 0, 0);
85
else if (classNr==Code::NOTE_BOX)
86
thing = new NoteBox(v, g, 0, 0);
89
else if (classNr==Code::T4_TLIST_LINE)
90
thing = new T4TListLine(v, g, 0, 0, 0);
91
else if (classNr==Code::C2R2_MLIST_LINE)
92
thing = new C2R2MListLine(v, g, 0, 0, 0);
93
else if (classNr==Code::LINE)
94
thing = new Line(v, g, 0, 0, 0);
97
else if (classNr==Code::UCD_ACTOR_NODE) //compatibility
98
thing = new CBActor(cg);
99
else if (classNr==Code::CBD_ACTOR_NODE)
100
thing = new CBActor(cg);
101
else if (classNr==Code::CBD_CLASS_NODE)
102
thing = new CBClassNode(cg);
103
else if (classNr==Code::CBD_OBJECT_NODE)
104
thing = new CBObjectNode(cg);
106
else if (classNr==Code::NOTE)
107
thing = new Note(cg);
108
else if (classNr==Code::COMMENT)
109
thing = new Comment(cg);
112
else if (classNr==Code::CBD_CLASS_LINK_EDGE)
113
thing = new CBClassLinkEdge(cg, 0, 0);
114
else if (classNr==Code::CBD_OBJECT_LINK_EDGE)
115
thing = new CBObjectLinkEdge(cg, 0, 0);
116
else if (classNr==Code::COMMENT_LINK)
117
thing = new CommentLink(cg, 0, 0);
120
error("%s, line %d: impl error: wrong class number %d\n",
121
__FILE__, __LINE__, classNr);
125
Node *CBDiagram::CreateNode(){
127
CBGraph *g = (CBGraph *)GetGraph();
129
if (GetNodeType()==Code::CBD_ACTOR_NODE)
130
node = new CBActor(g);
131
else if (GetNodeType()==Code::CBD_CLASS_NODE)
132
node = new CBClassNode(g);
133
else if (GetNodeType()==Code::CBD_OBJECT_NODE)
134
node = new CBObjectNode(g);
135
else if (GetNodeType()==Code::NOTE)
137
else if (GetNodeType()==Code::COMMENT)
138
node = new Comment(g);
140
error( "%s, line %d: impl error: unknown node type\n",
145
Edge *CBDiagram::CreateEdge(Subject *subj1, Subject* subj2){
146
if (!CheckEdgeConstraints(subj1, subj2))
149
CBGraph *g = (CBGraph *)GetGraph();
150
if (GetEdgeType() == Code::CBD_CLASS_LINK_EDGE)
151
edge = new CBClassLinkEdge(g, subj1, subj2);
152
else if (GetEdgeType() == Code::CBD_OBJECT_LINK_EDGE)
153
edge = new CBObjectLinkEdge(g, subj1, subj2);
154
else if (GetEdgeType()==Code::COMMENT_LINK)
155
edge = new CommentLink(g, subj1, subj2);
157
error( "%s, line %d: impl error: unknown edge type\n",
163
NodeShape *CBDiagram::CreateNodeShape(Node* node, int x, int y) {
164
NodeShape* shape = 0;
165
Grafport *g = GetDiagramViewer()->GetGrafport();
166
ShapeView *v = GetDiagramViewer()->GetCurView();
168
if (GetNodeShapeType() == Code::STICKMAN)
169
shape = new StickMan(v, g, x, y);
171
else if (GetNodeShapeType() == Code::OBJECT_STICKMAN) {
172
SetNodeShapeType(Code::STICKMAN); //reset
173
shape = new StickMan(v, g, x, y);
174
shape->GetName()->SetUnderlined(True);
177
else if (GetNodeShapeType() == Code::ACTOR_OBJECT_BOX) {
178
SetNodeShapeType(Code::UCD_SINGLE_CLASS_BOX); //reset
179
shape = new UCDSingleClassBox(v, g, x, y);
180
shape->GetName()->SetUnderlined(True);
183
else if (GetNodeShapeType() == Code::SSD_SINGLE_OBJECT_BOX)
184
shape = new SSDSingleObjectBox(v, g, x, y);
185
else if (GetNodeShapeType() == Code::CBD_SINGLE_CLASS_BOX)
186
shape = new CBSingleClassBox(v, g, x, y);
187
else if (GetNodeShapeType() == Code::SSD_SINGLE_CLASS_BOX)
188
shape = new SSDSingleClassBox(v, g, x, y);
190
else if (GetNodeShapeType() == Code::UCD_SINGLE_CLASS_BOX)
191
shape = new UCDSingleClassBox(v, g, x, y);
192
else if (GetNodeShapeType() == Code::NOTE_BOX)
193
shape = new NoteBox(v, g, x, y);
194
else if (GetNodeShapeType() == Code::TEXT_BOX)
195
shape = new TextBox(v, g, x, y);
197
error( "%s, line %d: impl error: "
198
"node shape type doesn't exist\n", __FILE__, __LINE__);
201
shape->SetSubject(node);
202
shape->SetTextShape();
207
Line *CBDiagram::CreateLine(Edge* edge, GShape *from, GShape *to, List<Point*> *l) {
208
Grafport *g = GetDiagramViewer()->GetGrafport();
209
ShapeView *v = GetDiagramViewer()->GetCurView();
211
if (GetLineType()== Code::T4_TLIST_LINE)
212
line = new C2R2MListLine(v, g, from, to, l, IsCurve());
213
else if (GetLineType()==Code::C2R2_MLIST_LINE)
214
line = new C2R2MListLine(v, g, from, to, l, IsCurve());
215
else if (GetLineType()== Code::LINE)
216
line = new Line(v, g, from, to, l, IsCurve());
218
error( "%s, line %d: impl error: "
219
"edge shape type does not exist\n", __FILE__, __LINE__);
221
line->SetSubject(edge);
222
if (edge->GetClassType()==Code::CBD_CLASS_LINK_EDGE) {
223
line->GetName()->SetUnderlined(False);
225
line->SetTextShape();
226
line->SetEnd1(GetLineEnd1());
227
line->SetEnd2(GetLineEnd2());
232
void CBDiagram::UpdateNodeType(int num) {
233
((DiagramWindow *)GetMainWindow())->SetNodeName(num);
235
case 1: SetNodeType(Code::CBD_ACTOR_NODE);
236
SetNodeShapeType(Code::STICKMAN);
237
SetNodeLineStyle(LineStyle::SOLID);
239
case 2: SetNodeType(Code::CBD_ACTOR_NODE);
240
SetNodeShapeType(Code::UCD_SINGLE_CLASS_BOX);
241
SetNodeLineStyle(LineStyle::SOLID);
243
case 3: SetNodeType(Code::CBD_CLASS_NODE);
244
SetNodeShapeType(Code::SSD_SINGLE_CLASS_BOX);
245
SetNodeLineStyle(LineStyle::SOLID);
247
case 4: SetNodeType(Code::COMMENT);
248
SetNodeShapeType(Code::TEXT_BOX);
249
SetNodeLineStyle(LineStyle::INVISIBLE);
251
case 5: SetNodeType(Code::CBD_ACTOR_NODE);
252
SetNodeShapeType(Code::OBJECT_STICKMAN);
253
SetNodeLineStyle(LineStyle::SOLID);
255
case 6: SetNodeType(Code::CBD_ACTOR_NODE);
256
SetNodeShapeType(Code::ACTOR_OBJECT_BOX);
257
SetNodeLineStyle(LineStyle::SOLID);
259
case 7: SetNodeType(Code::CBD_OBJECT_NODE);
260
SetNodeShapeType(Code::SSD_SINGLE_OBJECT_BOX);
261
SetNodeLineStyle(LineStyle::SOLID);
263
case 8: SetNodeType(Code::NOTE);
264
SetNodeShapeType(Code::NOTE_BOX);
265
SetNodeLineStyle(LineStyle::SOLID);
268
error("%s, line %d: impl error: "
269
"unknown node type selected\n", __FILE__,__LINE__);
274
void CBDiagram::UpdateEdgeType(int num) {
275
((DiagramWindow *)GetMainWindow())->SetEdgeName(num);
277
case 1: SetEdgeType(Code::CBD_CLASS_LINK_EDGE);
278
SetLineType(Code::T4_TLIST_LINE);
279
SetEdgeLineStyle(LineStyle::SOLID);
280
SetLineEnd1(LineEnd::EMPTY);
281
SetLineEnd2(LineEnd::EMPTY);
283
case 2: SetEdgeType(Code::COMMENT_LINK);
284
SetLineType(Code::LINE);
285
SetEdgeLineStyle(LineStyle::WIDE_DOTTED);
286
SetLineEnd1(LineEnd::EMPTY);
287
SetLineEnd2(LineEnd::EMPTY);
289
case 3: SetEdgeType(Code::CBD_OBJECT_LINK_EDGE);
290
SetLineType(Code::T4_TLIST_LINE);
291
SetEdgeLineStyle(LineStyle::SOLID);
292
SetLineEnd1(LineEnd::EMPTY);
293
SetLineEnd2(LineEnd::EMPTY);
296
error("%s, line %d: impl error: "
297
"unknown edge type selected\n", __FILE__,__LINE__);
302
bool CBDiagram::SetText(TextShape *t, const string *s) {
303
const string *d = t->GetDescription();
304
Subject *subj = t->GetParent()->GetSubject();
305
if (*d == "Stereotype" && subj->GetClassType()==Code::CBD_CLASS_NODE)
306
return SetStereotype((CBClassNode*)subj, s);
307
else if (*d == "Properties" && subj->GetClassType()==Code::CBD_CLASS_NODE)
308
return SetProperties((CBClassNode*)subj, s);
309
else if (*d == "Message")
310
return SetMessage(subj, s, t->GetSequence());
312
return ERDiagram::SetText(t, s);
316
bool CBDiagram::SetStereotype(CBClassNode *object, const string *s) {
317
(void)object->SetStereotype(s);
318
// update all shapes in the viewer.
319
List<GShape *> shapes;
320
GetDiagramViewer()->GetShapes(object, &shapes);
321
for (check(shapes.first()); !shapes.done(); shapes.next()) {
322
const string *str = object->GetStereotype();
323
GShape *shape = shapes.cur();
324
if (check(!shape->IsTextShape())) {
325
if (shape->GetClassType()==Code::SSD_SINGLE_CLASS_BOX) {
326
SSDSingleClassBox *bs = (SSDSingleClassBox *)shape;
327
bs->UpdateStereotypeLabelString(str);
329
if (GetDiagramViewer()->IsAutoResize())
338
bool CBDiagram::SetProperties(CBClassNode *object, const string *s) {
339
(void) object->SetProperties(s);
340
// update all shapes in the viewer.
341
List<GShape *> shapes;
342
GetDiagramViewer()->GetShapes(object, &shapes);
343
for (check(shapes.first()); !shapes.done(); shapes.next()) {
344
const string *str = object->GetProperties();
345
GShape *shape = shapes.cur();
346
if (check(!shape->IsTextShape())) {
347
if (shape->GetClassType()==Code::SSD_SINGLE_CLASS_BOX) {
348
SSDSingleClassBox *bs = (SSDSingleClassBox *)shape;
349
bs->UpdatePropertiesLabelString(str);
351
if (GetDiagramViewer()->IsAutoResize())
359
bool CBDiagram::SetMessage(Subject *subj, const string *s, unsigned nr) {
360
List<GShape *> shapes;
361
GetDiagramViewer()->GetShapes(subj, &shapes);
364
// split string in different one line strings.
366
char *str = (char *)ss.getstr();
368
char *x = strtok(str, "\r");
372
string *ns = new string(x);
374
Subject::NameErrType result;
375
unsigned numItems = ((CBObjectLinkEdge *)subj)->NrOfMessages();
376
bool toggle = False; //default
377
for (check(shapes.first()); !shapes.done(); shapes.next()) {
378
GShape *shape = shapes.cur();
379
if (shape->GetClassType() == Code::C2R2_MLIST_LINE) {
380
Point from = *(((Line *)shape)->GetFromShape()->GetPosition());
381
Point to = *(((Line *)shape)->GetToShape()->GetPosition());
386
if ((m == nr) && (m < numItems)) {
387
result = ((CBObjectLinkEdge *)subj)->SetMessage(ns, m, True, toggle);
390
result = ((CBObjectLinkEdge *)subj)->SetMessage(ns, m, False, toggle);
394
// update and redraw the shapes.
395
if (check(shapes.first())) {
397
Shape *shape = shapes.cur();
398
((C2R2MListLine *)shape)->UpdateTListTextShape(ns,m);
399
} while (shapes.next());
411
bool CBDiagram::SetRoleName(Subject *subject, const string *s, unsigned ) {
412
List<GShape *> shapes;
413
GetDiagramViewer()->GetShapes(subject, &shapes);
416
string txt = "'" + *s + "' is not a possible role name";
417
ShowDialog(MessageDialog::ERROR, "Error", &txt);
424
void CBDiagram::CheckDocument() {
427
// Check that classes are named.
428
total += cbChecks->CheckNamelessNodes(Code::CBD_CLASS_NODE, chkbuf);
429
// Check that object classes are named.
430
total += cbChecks->CheckNamelessNodes(Code::CBD_OBJECT_NODE, chkbuf);
432
ReportCheck(total, &chkbuf);