1
////////////////////////////////////////////////////////////////////////////////
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).
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
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
////////////////////////////////////////////////////////////////////////////////
26
#include "trdiagram.h"
27
#include "shapeview.h"
30
TRViewer::TRViewer(Config *c, TRWindow *d): DiagramViewer(c, d) {
34
void TRViewer::Initialize() {
35
TRView *v = new TRView(this);
40
void TRViewer::UpdateTreeMode(bool newMode) {
42
SetStatus("view as forked tree");
44
SetStatus("view as editable graph");
45
if (newMode != treeMode && !IsPasting() && !IsZigZag()) {
49
GetMainWindow()->EnableUndo(False);
50
GetMainWindow()->EnableRedo(False);
53
GetMainWindow()->EnableUndo(True);
54
GetMainWindow()->EnableRedo(True);
60
void TRViewer::Select(int x, int y) {
62
DiagramViewer::Select(x, y);
65
void TRViewer::Adjust(int x, int y) {
67
DiagramViewer::Adjust(x, y);
70
void TRViewer::MovingPointer(int x, int y) {
72
DiagramViewer::MovingPointer(x, y);
75
void TRViewer::KeyTyped(int x, int y, int c) {
77
DiagramViewer::KeyTyped(x, y, c);
80
Command *TRViewer::Drag(int x, int y) {
82
return DiagramViewer::Drag(x, y);
87
Command *TRViewer::Connect(int x, int y) {
89
return DiagramViewer::Connect(x, y);
94
void TRViewer::SelectAll() {
95
treeMode? SetStatus("Aborted: in view mode"):DiagramViewer::SelectAll();
98
void TRViewer::Cut() {
99
treeMode? SetStatus("Aborted: in view mode"):DiagramViewer::Cut();
102
void TRViewer::Copy() {
103
treeMode? SetStatus("Aborted: in view mode"):DiagramViewer::Copy();
106
void TRViewer::UpdateCurve() {
107
treeMode? SetStatus("Aborted: in view mode"):DiagramViewer::UpdateCurve();
110
void TRViewer::Paste() {
111
treeMode? SetStatus("Aborted: in view mode"):DiagramViewer::Paste();
114
void TRViewer::DeleteAll() {
115
treeMode? SetStatus("Aborted: in view mode"):
116
DiagramViewer::DeleteAll();
119
void TRViewer::DeleteSubjects() {
120
treeMode? SetStatus("Aborted: in view mode"):
121
DiagramViewer::DeleteSubjects();
124
void TRViewer::AlignNodes(NodeAlign::Type n) {
125
treeMode? SetStatus("Aborted: in view mode"):
126
DiagramViewer::AlignNodes(n);
129
void TRViewer::SameSize() {
130
treeMode? SetStatus("Aborted: in view mode"):DiagramViewer::SameSize();
133
void TRViewer::MoveAllShapes(Document::MoveType t) {
134
DiagramViewer::MoveAllShapes(t);
136
GetMainWindow()->EnableUndo(False);
137
GetMainWindow()->EnableRedo(False);
141
void TRViewer::Annotate() {
142
treeMode? SetStatus("Aborted: in view mode"):DiagramViewer::Annotate();
145
void TRViewer::FindAll(const string *s, bool b1, bool b2, bool b3) {
146
// treeMode? SetStatus("Aborted: in view mode"):
147
DiagramViewer::FindAll(s, b1, b2, b3);
150
void TRViewer::FindNext(const string *s, bool b1, bool b2, bool b3) {
151
// treeMode? SetStatus("Aborted: in view mode"):
152
DiagramViewer::FindNext(s, b1, b2, b3);
155
void TRViewer::ReplaceNext(const string *s1, const string *s2,
156
bool b1, bool b2, bool b3) {
157
treeMode? SetStatus("Aborted: in view mode"):
158
DiagramViewer::ReplaceNext(s1, s2, b1, b2, b3);
161
void TRViewer::ReplaceAll(const string *s1, const string *s2,
162
bool b1, bool b2, bool b3) {
163
treeMode? SetStatus("Aborted: in view mode"):
164
DiagramViewer::ReplaceAll(s1, s2, b1, b2, b3);
167
void TRViewer::Draw() {
168
treeMode? DrawTreeMode(): DrawNormalMode();
171
void TRViewer::DrawNormalMode() {
172
GetCurView()->Draw();
175
void TRViewer::DrawTreeMode() {
176
GetGrafport()->SetLineStyle(LineStyle::SOLID);
177
((TRDiagram *)GetDiagram())->DrawTreeLayout();
178
GetCurView()->DrawNames();
181
void TRViewer::Undraw() {
185
void TRViewer::DrawTreeFork(Shape *root, List<Shape *> *children) {
186
if (children->count() == 0)
188
List<Shape *> childrenTop;
189
List<Shape *> childrenBottom;
190
List<Shape *> childrenLeft;
191
List<Shape *> childrenRight;
192
// int rootLeftMost = root->GetLeftMost();
193
// int rootRightMost = root->GetRightMost();
194
Point rootPosition = *root->GetPosition();
195
for (children->first(); !children->done(); children->next()) {
196
Shape *child = children->cur();
197
int leftMost = child->GetLeftMost();
198
int rightMost = child->GetRightMost();
199
Point position = *child->GetPosition();
200
// if (rightMost < rootRightMost - 10)
201
if (rightMost <= rootPosition.x)
202
childrenLeft.add(child);
203
// else if (leftMost > rootLeftMost)
204
else if (leftMost >= rootPosition.x)
205
childrenRight.add(child);
206
if (position.y <= rootPosition.y)
207
childrenTop.add(child);
209
childrenBottom.add(child);
211
if (childrenLeft.count() == children->count() ||
212
childrenRight.count() == children->count()) {
213
if (childrenTop.count() == children->count()) {
214
DrawVerticalTreeFork(root, children, UP);
216
else if (childrenBottom.count() == children->count()) {
217
DrawVerticalTreeFork(root, children, DOWN);
220
DrawVerticalTreeFork(root, &childrenTop, UP);
221
DrawVerticalTreeFork(root, &childrenBottom, DOWN);
225
DrawHorizontalTreeFork(root, &childrenTop, UP);
226
DrawHorizontalTreeFork(root, &childrenBottom, DOWN);
230
void TRViewer::DrawHorizontalTreeFork(Shape *root, List<Shape *> *children,
232
if (children->count() == 0)
234
Point rp = *root->GetPosition();
235
// find extreme coordinates of the children.
236
int minx = 0, maxx = 0, maxy = 0, miny = 0;
237
if (children->first()) {
238
Shape *child = children->cur();
239
Point p = *child->GetPosition();
240
miny = child->GetTopMost();
241
maxy = child->GetBottomMost();
245
child = children->cur();
246
Point pt = *child->GetPosition();
247
int top = child->GetTopMost();
248
int bottom = child->GetBottomMost();
257
else if (bottom > maxy)
259
} while (children->next());
261
// find points to attach the root.
262
// and find y coordinate of horizontal bar.
263
Point p1; int hbar_y;
265
p1 = Point(rp.x, root->GetBottomMost());
266
hbar_y = max(p1.y + 5, miny - 20);
269
p1 = Point(rp.x, root->GetTopMost());
270
hbar_y = min(p1.y - 5, maxy + 20);
272
// draw line from root to hbar.
273
Point p2 = Point(rp.x, hbar_y);
274
GetGrafport()->DrawLine(p1.x, p1.y, p2.x, p2.y);
275
// draw horizontal bar.
276
Point p5 = Point(min(minx, rp.x), hbar_y);
277
Point p6 = Point(max(maxx, rp.x), hbar_y);
278
GetGrafport()->DrawLine(p5.x, p5.y, p6.x, p6.y);
279
// draw lines from children to the horizontal bar.
280
for (children->first(); !children->done(); children->next()) {
281
Shape *child = children->cur();
282
Point pt = *child->GetPosition();
285
p3 = Point(pt.x, child->GetTopMost());
287
p3 = Point(pt.x, child->GetBottomMost());
288
Point p4 = Point(p3.x, hbar_y);
289
GetGrafport()->DrawLine(p3.x, p3.y, p4.x, p4.y);
293
void TRViewer::DrawVerticalTreeFork(Shape *root, List<Shape *> *children,
297
p1 = Point(root->GetPosition()->x, root->GetBottomMost());
299
p1 = Point(root->GetPosition()->x, root->GetTopMost());
300
if (children->first()) {
301
int py = children->cur()->GetPosition()->y;
303
Shape *child = children->cur();
304
int cury = child->GetPosition()->y;
305
Point p2 = Point(p1.x, cury);
307
if (child->GetPosition()->x < p1.x)
308
p3.x = child->GetRightMost() + 4;
310
p3.x = child->GetLeftMost() - 4;
311
GetGrafport()->DrawLine(p2.x, p2.y, p3.x, p3.y);
316
} while (children->next());
317
Point p4 = Point(p1.x, py);
318
GetGrafport()->DrawLine(p1.x, p1.y, p4.x, p4.y);