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

« back to all changes in this revision

Viewing changes to src/sd/gd/gddiagram.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 1995, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.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
#include "gdgraph.h"
 
23
#include "genericedge.h"
 
24
#include "genericnode.h"
 
25
#include "emptynode.h"
 
26
#include "miniellipse.h"
 
27
#include "blackdot.h"
 
28
#include "box.h"
 
29
#include "bullseye.h"
 
30
#include "circle.h"
 
31
#include "square.h"
 
32
#include "notebox.h"
 
33
#include "roundedbox.h"
 
34
#include "ellipsedbox.h"
 
35
#include "triangle.h"
 
36
#include "hexagon.h"
 
37
#include "horizontalbar.h"
 
38
#include "verticalbar.h"
 
39
#include "solidhorizontalbar.h"
 
40
#include "solidverticalbar.h"
 
41
#include "diamond.h"
 
42
#include "line.h"
 
43
#include "textbox.h"
 
44
#include "comment.h"
 
45
#include "stickman.h"
 
46
#include "folder.h"
 
47
#include "disk.h"
 
48
#include "buildingblock.h"
 
49
#include "cube.h"
 
50
#include "subfolder.h"
 
51
#include "gddiagram.h"
 
52
#include "gdviewer.h"
 
53
#include "gdwindow.h"
 
54
 
 
55
#include "gdboundaryshape.h"
 
56
#include "gdcontrollershape.h"
 
57
#include "gdentityshape.h"
 
58
 
 
59
const int GDDiagram::DOT_WIDTH = 8;
 
60
 
 
61
GDDiagram::GDDiagram(Config *c, GDWindow *d, GDViewer *v, GDGraph *g): 
 
62
                Diagram(c,d,v,g) {
 
63
        UpdateNodeType(1);
 
64
        UpdateEdgeType(1);
 
65
}
 
66
 
 
67
Thing *GDDiagram::CreateThing(int classNr) {
 
68
        Grafport *g = GetDiagramViewer()->GetGrafport();
 
69
        ShapeView *v = GetDiagramViewer()->GetCurView();
 
70
        Thing *thing = 0;
 
71
 
 
72
        switch ( classNr ) {
 
73
        case Code::BOX:
 
74
                thing = new Box(v, g, 0, 0); 
 
75
                break;
 
76
        case Code::SQUARE:
 
77
                thing = new Square(v, g, 0, 0); 
 
78
                break;
 
79
        case Code::CIRCLE:
 
80
                thing = new Circle(v, g, 0, 0); 
 
81
                break;
 
82
        case Code::ELLIPSE:
 
83
                thing = new Ellipse(v, g, 0, 0); 
 
84
                break;
 
85
        case Code::STICKMAN:
 
86
                thing = new StickMan(v, g, 0, 0); 
 
87
                break;
 
88
        case Code::TRIANGLE:
 
89
                thing = new Triangle(v, g, 0, 0); 
 
90
                break;
 
91
        case Code::HEXAGON:
 
92
                thing = new Hexagon(v, g, 0, 0); 
 
93
                break;
 
94
        case Code::HORIZONTAL_BAR:
 
95
                thing = new HorizontalBar(v, g, 0, 0); 
 
96
                break;
 
97
        case Code::VERTICAL_BAR:
 
98
                thing = new VerticalBar(v, g, 0, 0); 
 
99
                break;
 
100
        case Code::ROUNDED_BOX:
 
101
                thing = new RoundedBox(v, g, 0, 0); 
 
102
                break;
 
103
        case Code::ELLIPSED_BOX:
 
104
                thing = new EllipsedBox(v, g, 0, 0); 
 
105
                break;
 
106
        case Code::DIAMOND:
 
107
                thing = new Diamond(v, g, 0, 0); 
 
108
                break;
 
109
        case Code::TEXT_BOX:
 
110
                thing = new TextBox(v, g, 0, 0); 
 
111
                break;
 
112
        case Code::BLACK_DOT:
 
113
                thing = new BlackDot(v, g, 0, 0); 
 
114
                break;
 
115
        case Code::BULLS_EYE:
 
116
                thing = new BullsEye(v, g, 0, 0); 
 
117
                break;
 
118
        case Code::SOLID_HORIZONTAL_BAR:
 
119
                thing = new SolidHorizontalBar(v, g, 0, 0);
 
120
                break;
 
121
        case Code::SOLID_VERTICAL_BAR:
 
122
                thing = new SolidVerticalBar(v, g, 0, 0);
 
123
                break;
 
124
        case Code::NOTE_BOX:
 
125
                thing = new NoteBox(v, g, 0, 0);
 
126
                break;
 
127
        case Code::BUILDING_BLOCK:
 
128
                 thing = new BuildingBlock(v, g, 0, 0);
 
129
                break;
 
130
        case Code::CUBE:
 
131
                 thing = new Cube(v, g, 0, 0);
 
132
                break;
 
133
        case Code::FOLDER:
 
134
                 thing = new Folder(v, g, 0, 0);
 
135
                break;
 
136
        case Code::SUB_FOLDER:
 
137
                 thing = new SubFolder(v, g, 0, 0);
 
138
                break;
 
139
        case Code::DISK:
 
140
                 thing = new Disk(v, g, 0, 0);
 
141
                break;
 
142
        case Code::GD_BOUNDARY_SHAPE:
 
143
                thing = new GDBoundaryShape(v, g, 0, 0);
 
144
                break;
 
145
        case Code::GD_CONTROLLER_SHAPE:
 
146
                thing = new GDControllerShape(v, g, 0, 0);
 
147
                break;
 
148
        case Code::GD_ENTITY_SHAPE:
 
149
                thing = new GDEntityShape(v, g, 0, 0);
 
150
                break;
 
151
 
 
152
        case Code::VIEW:
 
153
                thing = new ShapeView(GetDiagramViewer()); 
 
154
                break;
 
155
 
 
156
        case Code::LINE:
 
157
                thing = new Line(v, g, 0, 0, 0);
 
158
                break;
 
159
        // old line (arrow) types...
 
160
        case Code::ARROW:
 
161
                {
 
162
                        Line *line = new Line(v, g, 0, 0, 0);
 
163
                        line->SetEnd2(LineEnd::FILLED_ARROW);
 
164
                        thing = line;
 
165
                }
 
166
                break;
 
167
        case Code::DOUBLE_ARROW:
 
168
                {
 
169
                        Line *line = new Line(v, g, 0, 0, 0);
 
170
                        line->SetEnd1(LineEnd::FILLED_ARROW);
 
171
                        line->SetEnd2(LineEnd::FILLED_ARROW);
 
172
                        thing = line;
 
173
                }
 
174
                break;
 
175
        case Code::DOUBLE_HEADED_ARROW:
 
176
                {
 
177
                        Line *line = new Line(v, g, 0, 0, 0);
 
178
                        line->SetEnd2(LineEnd::DOUBLE_FILLED_ARROW);
 
179
                        thing = line;
 
180
                }
 
181
                break;
 
182
 
 
183
        case Code::GENERIC_NODE:
 
184
                thing = new GenericNode(GetGraph());
 
185
                break;
 
186
        case Code::EMPTY_NODE:
 
187
                thing = new EmptyNode(GetGraph());
 
188
                break;
 
189
        case Code::COMMENT:
 
190
                thing = new Comment(GetGraph());
 
191
                break;
 
192
 
 
193
        case Code::GENERIC_EDGE:
 
194
                thing = new GenericEdge(GetGraph(), 0, 0);
 
195
                break;
 
196
        default:
 
197
                error("%s, line %d: impl error: " "wrong class number %d\n", 
 
198
                        __FILE__, __LINE__, classNr);
 
199
                return 0;
 
200
        }
 
201
        if (thing != 0 && HasIndexShape(thing->GetClassType()))
 
202
                ((NodeShape *)thing)->SetFixedIndexLabel(False);
 
203
 
 
204
        return thing;
 
205
}
 
206
 
 
207
Node *GDDiagram::CreateNode(){
 
208
        Node *node = 0;
 
209
        switch ( GetNodeType() ) {
 
210
        case Code::GENERIC_NODE:
 
211
                node = new GenericNode(GetGraph());
 
212
                break;
 
213
        case Code::EMPTY_NODE:
 
214
                node = new EmptyNode(GetGraph());
 
215
                break;
 
216
        case Code::COMMENT:
 
217
                node = new Comment(GetGraph());
 
218
                break;
 
219
        default:
 
220
                error("%s, line %d: impl error: "
 
221
                        "unknown node type\n", __FILE__, __LINE__);
 
222
        }
 
223
        return node;
 
224
}
 
225
 
 
226
Edge *GDDiagram::CreateEdge(Subject *node1, Subject *node2){
 
227
        // Check possible connections (node-node-edge matrix).
 
228
        if (!CheckConnection(node1, node2))
 
229
                return 0; 
 
230
        Edge *edge = 0;
 
231
        if (GetEdgeType() == Code::GENERIC_EDGE)
 
232
                edge = new GenericEdge(GetGraph(), node1, node2);
 
233
        else 
 
234
                error( "%s, line %d: impl error: "
 
235
                        " unknown edge type\n", __FILE__, __LINE__);
 
236
        return edge;
 
237
}
 
238
 
 
239
NodeShape *GDDiagram::CreateNodeShape(Node *node, int x, int y) {
 
240
        NodeShape *shape = 0;
 
241
        Grafport *g = GetDiagramViewer()->GetGrafport();
 
242
        ShapeView *v = GetDiagramViewer()->GetCurView();
 
243
        int t = GetNodeShapeType();
 
244
        switch ( t ) {
 
245
        case Code::BOX:
 
246
                shape = new Box(v, g, x, y);
 
247
                break;
 
248
        case Code::SQUARE:
 
249
                shape = new Square(v, g, x, y);
 
250
                break;
 
251
        case Code::CIRCLE:
 
252
                shape = new Circle(v, g, x, y);
 
253
                break;
 
254
        case Code::ELLIPSE:
 
255
                shape = new Ellipse(v, g, x, y);
 
256
                break;
 
257
        case Code::STICKMAN:
 
258
                shape = new StickMan(v, g, x, y);
 
259
                break;
 
260
        case Code::HEXAGON:
 
261
                shape = new Hexagon(v, g, x, y);
 
262
                break;
 
263
        case Code::HORIZONTAL_BAR:
 
264
                shape = new HorizontalBar(v, g, x, y);
 
265
                break;
 
266
        case Code::VERTICAL_BAR:
 
267
                shape = new VerticalBar(v, g, x, y);
 
268
                break;
 
269
        case Code::TRIANGLE:
 
270
                shape = new Triangle(v, g, x, y);
 
271
                break;
 
272
        case Code::ROUNDED_BOX:
 
273
                shape = new RoundedBox(v, g, x, y);
 
274
                break;
 
275
        case Code::ELLIPSED_BOX:
 
276
                shape = new EllipsedBox(v, g, x, y);
 
277
                break;
 
278
        case Code::DIAMOND:
 
279
                shape = new Diamond(v, g, x, y);
 
280
                break;
 
281
        case Code::NOTE_BOX:
 
282
                shape = new NoteBox(v, g, x, y);
 
283
                break;
 
284
        case Code::BLACK_DOT:
 
285
                shape = new BlackDot(v, g, x, y);
 
286
                break;
 
287
        case Code::BULLS_EYE:
 
288
                shape = new BullsEye(v, g, x, y);
 
289
                break;
 
290
        case Code::TEXT_BOX:
 
291
                shape = new TextBox(v, g, x, y);
 
292
                break;
 
293
        case Code::SOLID_HORIZONTAL_BAR:
 
294
                shape = new SolidHorizontalBar(v, g, x, y);
 
295
                break;
 
296
        case Code::SOLID_VERTICAL_BAR:
 
297
                shape = new SolidVerticalBar(v, g, x, y);
 
298
                break;
 
299
        case Code::BUILDING_BLOCK:
 
300
                shape = new BuildingBlock(v, g, x, y);
 
301
                break;
 
302
        case Code::CUBE:
 
303
                shape = new Cube(v, g, x, y);
 
304
                break;
 
305
        case Code::FOLDER:
 
306
                shape = new Folder(v, g, x, y);
 
307
                break;
 
308
        case Code::SUB_FOLDER:
 
309
                shape = new SubFolder(v, g, x, y);
 
310
                break;
 
311
        case Code::DISK:
 
312
                shape = new Disk(v, g, x, y);
 
313
                break;
 
314
        case Code::GD_BOUNDARY_SHAPE:
 
315
                shape = new GDBoundaryShape(v, g, x, y);
 
316
                break;
 
317
        case Code::GD_CONTROLLER_SHAPE:
 
318
                shape = new GDControllerShape(v, g, x, y);
 
319
                break;
 
320
        case Code::GD_ENTITY_SHAPE:
 
321
                shape = new GDEntityShape(v, g, x, y);
 
322
                break;
 
323
        default:
 
324
                error( "%s, line %d: impl error: "
 
325
                        "node shape type does not exist\n", __FILE__, __LINE__);
 
326
        }
 
327
        if (check(shape)) {
 
328
                if (HasIndexShape(t))
 
329
                        shape->SetFixedIndexLabel(False);
 
330
                shape->SetSubject(node);
 
331
                shape->SetTextShape();
 
332
        }
 
333
        return shape;
 
334
}
 
335
 
 
336
Line *GDDiagram::CreateLine(
 
337
                Edge *edge, GShape *from, GShape *to, List<Point *> *l) {
 
338
        Grafport *g = GetDiagramViewer()->GetGrafport();
 
339
        ShapeView *v = GetDiagramViewer()->GetCurView();
 
340
        Line *line = 0;
 
341
        int t = GetLineType();
 
342
        if (t == Code::LINE)
 
343
                line = new Line(v, g, from, to, l, IsCurve());
 
344
        else
 
345
                error( "%s, line %d: impl error: "
 
346
                        "line type does not exist\n", __FILE__, __LINE__);
 
347
        if (check(line)) {
 
348
                line->SetSubject(edge);
 
349
                line->SetTextShape();
 
350
                line->SetEnd1(GetLineEnd1());
 
351
                line->SetEnd2(GetLineEnd2());
 
352
        }
 
353
        return line;
 
354
}
 
355
 
 
356
void GDDiagram::UpdateNodeType(int num) {
 
357
        ((DiagramWindow *)GetMainWindow())->SetNodeName(num);
 
358
        switch (num) {
 
359
        case 1: SetNodeType(Code::GENERIC_NODE);
 
360
                SetNodeShapeType(Code::BOX);
 
361
                break;
 
362
        case 2: SetNodeType(Code::GENERIC_NODE);
 
363
                SetNodeShapeType(Code::CIRCLE);
 
364
                break;
 
365
        case 3: SetNodeType(Code::GENERIC_NODE);
 
366
                SetNodeShapeType(Code::ROUNDED_BOX);
 
367
                break;
 
368
        case 4: SetNodeType(Code::GENERIC_NODE);
 
369
                SetNodeShapeType(Code::TRIANGLE);
 
370
                break;
 
371
        case 5: SetNodeType(Code::EMPTY_NODE);
 
372
                SetNodeShapeType(Code::BULLS_EYE);
 
373
                break;
 
374
        case 6: SetNodeType(Code::GENERIC_NODE);
 
375
                SetNodeShapeType(Code::STICKMAN);
 
376
                break;
 
377
        case 7: SetNodeType(Code::GENERIC_NODE);
 
378
                SetNodeShapeType(Code::CUBE);
 
379
                break;
 
380
        case 8: SetNodeType(Code::GENERIC_NODE);
 
381
                SetNodeShapeType(Code::GD_BOUNDARY_SHAPE);
 
382
                break;
 
383
        case 9: SetNodeType(Code::COMMENT);
 
384
                SetNodeShapeType(Code::TEXT_BOX);
 
385
                break;
 
386
        case 10: SetNodeType(Code::GENERIC_NODE);
 
387
                SetNodeShapeType(Code::DIAMOND);
 
388
                break;
 
389
        case 11: SetNodeType(Code::GENERIC_NODE);
 
390
                SetNodeShapeType(Code::SQUARE);
 
391
                break;
 
392
        case 12: SetNodeType(Code::GENERIC_NODE);
 
393
                SetNodeShapeType(Code::VERTICAL_BAR);
 
394
                break;
 
395
        case 13: SetNodeType(Code::GENERIC_NODE);
 
396
                SetNodeShapeType(Code::HEXAGON);
 
397
                break;
 
398
        case 14: SetNodeType(Code::EMPTY_NODE);
 
399
                SetNodeShapeType(Code::SOLID_VERTICAL_BAR);
 
400
                break;
 
401
        case 15: SetNodeType(Code::GENERIC_NODE);
 
402
                SetNodeShapeType(Code::FOLDER);
 
403
                break;
 
404
        case 16: SetNodeType(Code::GENERIC_NODE);
 
405
                SetNodeShapeType(Code::BUILDING_BLOCK);
 
406
                break;
 
407
        case 17: SetNodeType(Code::GENERIC_NODE);
 
408
                SetNodeShapeType(Code::GD_CONTROLLER_SHAPE);
 
409
                break;
 
410
        case 18: SetNodeType(Code::GENERIC_NODE);
 
411
                SetNodeShapeType(Code::NOTE_BOX);
 
412
                break;
 
413
        case 19: SetNodeType(Code::GENERIC_NODE);
 
414
                SetNodeShapeType(Code::ELLIPSE);
 
415
                break;
 
416
        case 20: SetNodeType(Code::EMPTY_NODE);
 
417
                SetNodeShapeType(Code::BLACK_DOT);
 
418
                break;
 
419
        case 21: SetNodeType(Code::GENERIC_NODE);
 
420
                SetNodeShapeType(Code::HORIZONTAL_BAR);
 
421
                break;
 
422
        case 22: SetNodeType(Code::GENERIC_NODE);
 
423
                SetNodeShapeType(Code::ELLIPSED_BOX);
 
424
                break;
 
425
        case 23: SetNodeType(Code::EMPTY_NODE);
 
426
                SetNodeShapeType(Code::SOLID_HORIZONTAL_BAR);
 
427
                break;
 
428
        case 24: SetNodeType(Code::GENERIC_NODE);
 
429
                SetNodeShapeType(Code::SUB_FOLDER);
 
430
                break;
 
431
        case 25: SetNodeType(Code::GENERIC_NODE);
 
432
                SetNodeShapeType(Code::DISK);
 
433
                break;
 
434
        case 26: SetNodeType(Code::GENERIC_NODE);
 
435
                SetNodeShapeType(Code::GD_ENTITY_SHAPE);
 
436
                break;
 
437
        default:
 
438
                error("%s, line %d: impl error: "
 
439
                "unknown node type selected\n", __FILE__,__LINE__);
 
440
        }
 
441
}
 
442
 
 
443
void GDDiagram::UpdateEdgeType(int num) {
 
444
        ((DiagramWindow *)GetMainWindow())->SetEdgeName(num);
 
445
        SetEdgeType(Code::GENERIC_EDGE);
 
446
        SetLineType(Code::LINE);
 
447
        switch(num) {
 
448
        case 1: SetLineEnd1(LineEnd::EMPTY);
 
449
                SetLineEnd2(LineEnd::EMPTY);
 
450
                break;
 
451
        case 2: SetLineEnd1(LineEnd::FILLED_ARROW);
 
452
                SetLineEnd2(LineEnd::FILLED_ARROW);
 
453
                break;
 
454
        case 3: SetLineEnd1(LineEnd::EMPTY);
 
455
                SetLineEnd2(LineEnd::FILLED_ARROW);
 
456
                break;
 
457
        case 4: SetLineEnd1(LineEnd::EMPTY);
 
458
                SetLineEnd2(LineEnd::WHITE_TRIANGLE);
 
459
                break;
 
460
        case 5: SetLineEnd1(LineEnd::EMPTY);
 
461
                SetLineEnd2(LineEnd::DOUBLE_FILLED_ARROW);
 
462
                break;
 
463
        case 6: SetLineEnd1(LineEnd::EMPTY);
 
464
                SetLineEnd2(LineEnd::OPEN_ARROW);
 
465
                break;
 
466
        default:
 
467
                error("%s, line %d: impl error: "
 
468
                        "unknown edge type selected\n", __FILE__,__LINE__);
 
469
        }
 
470
}
 
471
 
 
472
bool GDDiagram::HasIndexNode(int code) {
 
473
        return (code == Code::GENERIC_NODE);
 
474
}
 
475
 
 
476
bool GDDiagram::HasIndexShape(int code) {
 
477
        switch ( code ) {
 
478
        case Code::BOX:
 
479
        case Code::SQUARE:
 
480
        case Code::ELLIPSE:
 
481
        case Code::CIRCLE:
 
482
        case Code::ROUNDED_BOX:
 
483
        case Code::DIAMOND:
 
484
        case Code::TRIANGLE:
 
485
        case Code::HORIZONTAL_BAR:
 
486
        case Code::VERTICAL_BAR:
 
487
        case Code::NOTE_BOX:
 
488
        case Code::HEXAGON:
 
489
        case Code::ELLIPSED_BOX:
 
490
        case Code::FOLDER:
 
491
        case Code::SUB_FOLDER:
 
492
        case Code::CUBE:
 
493
        case Code::BUILDING_BLOCK:
 
494
        case Code::STICKMAN:
 
495
        case Code::DISK:
 
496
        case Code::GD_BOUNDARY_SHAPE:
 
497
        case Code::GD_CONTROLLER_SHAPE:
 
498
        case Code::GD_ENTITY_SHAPE:
 
499
                return 1;
 
500
        default:
 
501
                return 0;
 
502
        }
 
503
}