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 "diagramviewer.h"
27
#include "linestyle.h"
33
/// (abstract) diagram class.
34
class Diagram: public Document {
35
/*@Doc: {\large {\bf scope:} diagram} */
38
Diagram(Config *, DiagramWindow *, DiagramViewer *, Graph *);
44
Graph *GetGraph() const {return graph;}
46
AssocList *GetAssocList() const {return assocList;}
48
/// Create a new node subject. Depends on current node type.
49
virtual Node *CreateNode() = 0;
51
/// Create edge, checks if connection is allowed.
52
virtual Edge *CreateEdge(Subject *n1, Subject *n2) = 0;
54
/// Create a node shape at (x,y), with default size and node as subject.
55
virtual NodeShape *CreateNodeShape(Node *node, int x, int y) = 0;
57
/// Create a line of lineType from fromShape to toShape via points.
58
virtual Line *CreateLine(Edge *edge,
59
GShape *fromShape, GShape *toShape, List<Point *> *line) = 0;
61
/// set/reset current node shape type to/from num.
62
virtual void UpdateNodeType(int num) = 0;
64
/// set/reset current edge shape type to/from num.
65
virtual void UpdateEdgeType(int num) = 0;
67
/// set/reset curved edge shapes.
68
void SetCurve(bool set);
70
bool IsCurve() const {return dviewer->IsDefaultCurve();}
72
/// Check if connection between those two nodes is allowed.
73
bool CheckConnection(Subject *n1, Subject *n2);
75
// when removing shapes from the screen we save them in a
76
// temp. buffer. With undo we add the shapes again, and get
77
// them from the buffer. Therefore, adding means taking from
78
// the temp. buffer. For symmetry, when we create a shape
79
// we also put it first in the buffer.
81
/// Add node/edge to graph data structure.
82
virtual void AddSubject(Subject *s);
84
/// Add nodes and edges to graph data structure.
85
void AddSubjects(List<Subject *> *s);
87
/// Remove node/edge from graph data structure.
88
virtual void RemoveSubject(Subject *s);
90
/// Remove nodes and edges from graph data structure.
91
void RemoveSubjects(List<Subject *> *s);
93
/// add edges to subjects which connect the subjects in subjects.
94
void CompleteSubjects(List<Subject *> *subjects);
96
/// add subjects to subjects which are connected by edges in subjects.
97
void CompleteEdges(List<Subject *> *subjects);
99
/// add to edges all edges of which subject is part.
100
void CompleteSubject(List<Subject *> *edges, Subject *subject);
102
/// Remove all nodes and edges.
105
/// Annotate subject via pop-up dialog.
106
void AnnotateSubject(Subject *s);
108
/// Annotate annotationSubject
109
void SetSubjectAnnotation(string *s);
111
/// Redirect line from first or last subject that covers point pt.
112
bool RedirectEdge(Line *line, bool first, const Point *pt);
114
/// move diagram in main window.
117
/// select all shapes of subject in current view.
118
void SelectSubject(Subject *s);
119
/// select all shapes of subjects in list in current view.
120
void SelectSubjects(List<Subject *> *s);
122
/// Update the text of text shape t and the corresponding subject.
123
virtual bool SetText(TextShape *t, const string *s);
126
void FindAll(const string *s, bool send, bool substring, bool nameOnly);
128
void FindNext(const string *s, bool send, bool substring, bool nameOnly);
130
void ReplaceAll(const string *s1, const string *s2,
131
bool send, bool substring, bool nameOnly);
133
void ReplaceNext(const string *s1, const string *s2,
134
bool send, bool substring, bool nameOnly);
136
virtual bool HasIndexNode(int) {return False;}
138
virtual bool HasIndexShape(int) {return False;}
142
/// Give Node next index nr. and update shapes.
143
void SetNextIndex(Node *n);
146
virtual void SetHierarchic(bool s);
148
virtual bool AllowHierarchic() const;
151
static Sequence sequence;
154
DiagramViewer *GetDiagramViewer() const {return dviewer;}
157
int GetNodeType() const {return dviewer->GetDefaultNodeType();}
159
void SetNodeType(int n) {dviewer->SetDefaultNodeType(n);}
161
int GetEdgeType() const {return dviewer->GetDefaultEdgeType();}
163
void SetEdgeType(int n) {dviewer->SetDefaultEdgeType(n);}
165
int GetNodeShapeType() const {
166
return dviewer->GetDefaultNodeShapeType();}
168
void SetNodeShapeType(int n) {
169
dviewer->SetDefaultNodeShapeType(n);}
171
void SetLineType(int n) {dviewer->SetDefaultLineType(n);}
173
int GetLineType() const {return dviewer->GetDefaultLineType();}
175
LineStyle::Type GetNodeLineStyle() {
176
return dviewer->GetDefaultNodeLineStyle();}
178
LineStyle::Type GetEdgeLineStyle() {
179
return dviewer->GetDefaultEdgeLineStyle();}
181
void SetNodeLineStyle(LineStyle::Type n) {
182
dviewer->SetDefaultNodeLineStyle(n);}
184
void SetEdgeLineStyle(LineStyle::Type e) {
185
dviewer->SetDefaultEdgeLineStyle(e);}
187
LineEnd::Type GetLineEnd1() {
188
return dviewer->GetDefaultLineEnd1(); }
190
LineEnd::Type GetLineEnd2() {
191
return dviewer->GetDefaultLineEnd2(); }
193
void SetLineEnd1(LineEnd::Type t) {
194
dviewer->SetDefaultLineEnd1(t); }
196
void SetLineEnd2(LineEnd::Type t) {
197
dviewer->SetDefaultLineEnd2(t); }
199
/// Sets name of subject to s. Checks if name is allowed.
200
bool SetSubjectName(Subject *subject, const string *s);
202
/// Check and set index of a node.
203
bool SetIndex(Node *n, const string *index);
206
virtual void PlaceShapes();
212
/// Creates a new shape/subject depending on classNr.
213
virtual Thing *CreateThing(int classNr) = 0;
215
/// update all name strings of shapes representing subject.
216
void UpdateNameStrings(Subject *subject);
219
DiagramViewer *dviewer;
223
AssocList *assocList;
226
List<ShapeView *> viewsRead;
232
Subject *annotationSubject;
234
/// fit shapes to drawing area + some extra edit space.
241
void CheckSubjects();
243
void ReadThing(int classNr, unsigned long value, bool dashedShape);
245
void DeleteDiagram();