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

« back to all changes in this revision

Viewing changes to src/dg/diagram.h

  • 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
#ifndef _DIAGRAM_H
 
23
#define _DIAGRAM_H
 
24
 
 
25
#include "document.h"
 
26
#include "diagramviewer.h"
 
27
#include "linestyle.h"
 
28
#include "lineend.h"
 
29
#include "sequence.h"
 
30
class Graph;
 
31
class Edge;
 
32
 
 
33
/// (abstract) diagram class.
 
34
class Diagram: public Document {
 
35
/*@Doc: {\large {\bf scope:} diagram} */
 
36
public:
 
37
        ///
 
38
        Diagram(Config *, DiagramWindow *, DiagramViewer *, Graph *);
 
39
        ///
 
40
        virtual ~Diagram();
 
41
        ///
 
42
        void Initialize();
 
43
        ///
 
44
        Graph *GetGraph() const {return graph;}
 
45
        ///
 
46
        AssocList *GetAssocList() const {return assocList;}
 
47
 
 
48
        /// Create a new node subject. Depends on current node type.
 
49
        virtual Node *CreateNode() = 0;
 
50
 
 
51
        /// Create edge, checks if connection is allowed. 
 
52
        virtual Edge *CreateEdge(Subject *n1, Subject *n2) = 0;
 
53
 
 
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;
 
56
 
 
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;
 
60
 
 
61
        /// set/reset current node shape type to/from num.
 
62
        virtual void UpdateNodeType(int num) = 0;
 
63
 
 
64
        /// set/reset current edge shape type to/from num.
 
65
        virtual void UpdateEdgeType(int num) = 0;
 
66
 
 
67
        /// set/reset curved edge shapes.
 
68
        void SetCurve(bool set);
 
69
        ///
 
70
        bool IsCurve() const {return dviewer->IsDefaultCurve();}
 
71
 
 
72
        /// Check if connection between those two nodes is allowed.
 
73
        bool CheckConnection(Subject *n1, Subject *n2);
 
74
 
 
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.
 
80
 
 
81
        /// Add node/edge to graph data structure.
 
82
        virtual void AddSubject(Subject *s); 
 
83
 
 
84
        /// Add nodes and edges to graph data structure.
 
85
        void AddSubjects(List<Subject *> *s); 
 
86
 
 
87
        /// Remove node/edge from graph data structure.
 
88
        virtual void RemoveSubject(Subject *s); 
 
89
 
 
90
        /// Remove nodes and edges from graph data structure.
 
91
        void RemoveSubjects(List<Subject *> *s); 
 
92
 
 
93
        /// add edges to subjects which connect the subjects in subjects.
 
94
        void CompleteSubjects(List<Subject *> *subjects);
 
95
 
 
96
        /// add subjects to subjects which are connected by edges in subjects.
 
97
        void CompleteEdges(List<Subject *> *subjects);
 
98
 
 
99
        /// add to edges all edges of which subject is part.
 
100
        void CompleteSubject(List<Subject *> *edges, Subject *subject);
 
101
 
 
102
        /// Remove all nodes and edges.
 
103
        void RemoveAll(); 
 
104
 
 
105
        /// Annotate subject via pop-up dialog.
 
106
        void AnnotateSubject(Subject *s);
 
107
 
 
108
        /// Annotate annotationSubject
 
109
        void SetSubjectAnnotation(string *s);
 
110
        
 
111
        /// Redirect line from first or last subject that covers point pt.
 
112
        bool RedirectEdge(Line *line, bool first, const Point *pt);
 
113
 
 
114
        /// move diagram in main window.
 
115
        void Move(MoveType);
 
116
 
 
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);
 
121
 
 
122
        /// Update the text of text shape t and the corresponding subject.
 
123
        virtual bool SetText(TextShape *t, const string *s);
 
124
 
 
125
        ///
 
126
        void FindAll(const string *s, bool send, bool substring, bool nameOnly); 
 
127
        ///
 
128
        void FindNext(const string *s, bool send, bool substring, bool nameOnly); 
 
129
        ///
 
130
        void ReplaceAll(const string *s1, const string *s2, 
 
131
                        bool send, bool substring, bool nameOnly); 
 
132
        ///
 
133
        void ReplaceNext(const string *s1, const string *s2, 
 
134
                        bool send, bool substring, bool nameOnly); 
 
135
        ///
 
136
        virtual bool HasIndexNode(int) {return False;}
 
137
        ///
 
138
        virtual bool HasIndexShape(int) {return False;}
 
139
        ///
 
140
        void Reindex();
 
141
 
 
142
        /// Give Node next index nr. and update shapes.
 
143
        void SetNextIndex(Node *n);
 
144
 
 
145
        ///
 
146
        virtual void SetHierarchic(bool s);
 
147
        ///
 
148
        virtual bool AllowHierarchic() const;
 
149
 
 
150
        ///
 
151
        static Sequence sequence;
 
152
protected:
 
153
        ///
 
154
        DiagramViewer *GetDiagramViewer() const {return dviewer;}
 
155
 
 
156
        ///
 
157
        int GetNodeType() const {return dviewer->GetDefaultNodeType();}
 
158
        ///
 
159
        void SetNodeType(int n) {dviewer->SetDefaultNodeType(n);}
 
160
        ///
 
161
        int GetEdgeType() const {return dviewer->GetDefaultEdgeType();}
 
162
        ///
 
163
        void SetEdgeType(int n) {dviewer->SetDefaultEdgeType(n);}
 
164
        ///
 
165
        int GetNodeShapeType() const {
 
166
                return dviewer->GetDefaultNodeShapeType();}
 
167
        ///
 
168
        void SetNodeShapeType(int n) {
 
169
                dviewer->SetDefaultNodeShapeType(n);}
 
170
        ///
 
171
        void SetLineType(int n) {dviewer->SetDefaultLineType(n);}
 
172
        ///
 
173
        int GetLineType() const {return dviewer->GetDefaultLineType();}
 
174
        /// 
 
175
        LineStyle::Type GetNodeLineStyle() {
 
176
                return dviewer->GetDefaultNodeLineStyle();}
 
177
        /// 
 
178
        LineStyle::Type GetEdgeLineStyle() {
 
179
                return dviewer->GetDefaultEdgeLineStyle();}
 
180
        /// 
 
181
        void SetNodeLineStyle(LineStyle::Type n) {
 
182
                dviewer->SetDefaultNodeLineStyle(n);}
 
183
        /// 
 
184
        void SetEdgeLineStyle(LineStyle::Type e) {
 
185
                dviewer->SetDefaultEdgeLineStyle(e);}
 
186
        ///
 
187
        LineEnd::Type GetLineEnd1() {
 
188
                return dviewer->GetDefaultLineEnd1(); }
 
189
        ///
 
190
        LineEnd::Type GetLineEnd2() {
 
191
                return dviewer->GetDefaultLineEnd2(); }
 
192
        ///
 
193
        void SetLineEnd1(LineEnd::Type t) {
 
194
                dviewer->SetDefaultLineEnd1(t); }
 
195
        ///
 
196
        void SetLineEnd2(LineEnd::Type t) {
 
197
                dviewer->SetDefaultLineEnd2(t); }
 
198
        
 
199
        /// Sets name of subject to s. Checks if name is allowed.
 
200
        bool SetSubjectName(Subject *subject, const string *s);
 
201
 
 
202
        /// Check and set index of a node.
 
203
        bool SetIndex(Node *n, const string *index);
 
204
 
 
205
        ///
 
206
        virtual void PlaceShapes();
 
207
        ///
 
208
        void LoadEntries();
 
209
        ///
 
210
        void SaveEntries();
 
211
 
 
212
        /// Creates a new shape/subject depending on classNr.
 
213
        virtual Thing *CreateThing(int classNr) = 0;
 
214
 
 
215
        /// update all name strings of shapes representing subject.
 
216
        void UpdateNameStrings(Subject *subject);
 
217
private:
 
218
        ///
 
219
        DiagramViewer *dviewer;
 
220
        ///
 
221
        Graph *graph;
 
222
        ///
 
223
        AssocList *assocList;
 
224
 
 
225
        ///
 
226
        List<ShapeView *> viewsRead;
 
227
 
 
228
        ///
 
229
        unsigned long maxid;
 
230
 
 
231
        ///
 
232
        Subject *annotationSubject;
 
233
 
 
234
        /// fit shapes to drawing area + some extra edit space.
 
235
        void FitShapes(); 
 
236
        ///
 
237
        void PlaceViews();
 
238
        ///
 
239
        void PurgeViews();
 
240
        ///
 
241
        void CheckSubjects();
 
242
        ///
 
243
        void ReadThing(int classNr, unsigned long value, bool dashedShape);
 
244
        ///
 
245
        void DeleteDiagram();
 
246
};
 
247
#endif