Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
UMLGraph.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
36#include <ogdf/basic/SList.h>
37#include <ogdf/basic/basic.h>
39#include <ogdf/basic/geometry.h>
40
41#include <algorithm>
42#include <iosfwd>
43
44namespace ogdf {
45template<class E>
46class List;
47
49public:
50 // construction
51
52 // Creates a UML graph for no associated graph (default constructor).
53 UMLGraph() : GraphAttributes(), m_pG(nullptr), m_hiddenEdges(nullptr) { }
54
55 // Creates a UML graph associated with graph \p G.
59 explicit UMLGraph(Graph& G, long initAttributes = 0);
60
62 virtual ~UMLGraph();
63
64 // Initializes the UML graph for graph \p G.
72 virtual void init(Graph& G, long initAttr) {
73 m_pG = &G;
74 GraphAttributes::init(G, initAttr);
75 m_hierarchyParent.init(constGraph(), nullptr);
76 m_upwardEdge.init(constGraph(), false);
77
78 delete m_hiddenEdges;
79 m_hiddenEdges = new Graph::HiddenEdgeSet(G);
80 }
81
82 virtual void init(const Graph& G, long initAttr) override {
83 init(const_cast<Graph&>(G), initAttr);
84 }
85
88
94
98
104
106 void undoStars();
108 void undoStar(node center, bool restoreAllEdges);
109
111 DRect cliqueRect(node v) { return m_cliqueCircleSize[v]; }
112
113 DPoint cliquePos(node v) { return m_cliqueCirclePos[v]; }
114
115#if 0
116 //compute circle positions for all nodes around center
117 //using the ordering given in this UMLGraph, calls
118 //ccP(List...)
119 //rectMin is a temporary solution until compaction with constraints allows stretching
120 //of rect to clique size, it gives the min(w,h) of the given fixed size rect around the clique
121 void computeCliquePosition(node center, double rectMin);
122 void computeCliquePosition(node center, double rectMin, const adjEntry &startAdj);
123#endif
124
131 void computeCliquePosition(List<node>& adjNodes, node center, double rectMin = -1.0);
132
133 const SListPure<node>& centerNodes() { return m_centerNodes; }
134
136 void setDefaultCliqueCenterSize(double i) { m_cliqueCenterSize = max(i, 1.0); }
137
138 double getDefaultCliqueCenterSize() { return m_cliqueCenterSize; }
139
142 // TODO: check here how to guarantee that value is defined,
143 // edgearray is only valid if there are cliques replaced
144 return m_replacementEdge[e];
145 }
146
148
149#if 0
151 Graph& pureGraph() const {return *m_pG;}
152
154 void setAlign(edge e, bool b) {m_alignEdge[e] = b;}
155#endif
156
158 void setUpwards(adjEntry a, bool b) { m_upwardEdge[a] = b; }
159
160 bool upwards(adjEntry a) const { return m_upwardEdge[a]; }
161
163 void writeGML(const char* fileName);
164
166 void writeGML(std::ostream& os);
167
172
173#if 0
177 void sortEdgesFromLayout();
178#endif
179
182 public:
183 explicit AssociationClass(edge e, double width = 1.0, double height = 1.0, double x = 0.0,
184 double y = 0.0)
185 : m_width(width), m_height(height), m_x(x), m_y(y), m_edge(e), m_node(nullptr) { }
186
187 double m_width;
188 double m_height;
189 double m_x;
190 double m_y;
193 };
194
195 const SListPure<AssociationClass*>& assClassList() const { return m_assClassList; }
196
197 const AssociationClass* assClass(edge e) const { return m_assClass[e]; }
198
200 node createAssociationClass(edge e, double width = 1.0, double height = 1.0) {
201 AssociationClass* ac = new AssociationClass(e, width, height);
202 m_assClass[e] = ac;
203 m_assClassList.pushBack(ac);
204 //we already insert the node here, but not the edge
205 //when we always insert this node here, we can remove the associationclass
206 //class and information later on
207 node v = m_pG->newNode();
208 m_height[v] = ac->m_height;
209 m_width[v] = ac->m_width;
210 m_associationClassModel[ac->m_edge] = v;
211 ac->m_node = v;
212 //guarantee correct angle at edge to edge connection
213 if (m_attributes & GraphAttributes::nodeType) {
214 m_vType[v] = Graph::NodeType::associationClass;
215 }
216 return v;
217 }
218
219 //this modelling should only take place in the preprocessing steps
220 //of the drawing algorithms?
223 SListIterator<UMLGraph::AssociationClass*> it = m_assClassList.begin();
224 while (it.valid()) {
225 modelAssociationClass((*it));
226 ++it;
227 }
228 }
229
231 node dummy = m_pG->split(ac->m_edge)->source();
232
233 m_height[dummy] = 1; //just a dummy size
234 m_width[dummy] = 1;
235 OGDF_ASSERT(ac->m_node);
236 m_pG->newEdge(ac->m_node, dummy);
237
238 return dummy;
239 }
240
242 SListIterator<UMLGraph::AssociationClass*> it = m_assClassList.begin();
243 while (it.valid()) {
244 undoAssociationClass((*it));
245 ++it;
246 }
247 }
248
251 node v = m_associationClassModel[ac->m_edge];
252 OGDF_ASSERT(v);
253 OGDF_ASSERT(v->degree() == 1);
254 if (v->degree() != 1) {
255 throw AlgorithmFailureException(AlgorithmFailureCode::Label);
256 }
257 //save layout information
258 ac->m_x = x(v);
259 ac->m_y = y(v);
260
261 //remove node and unsplit edge
262
263 //run around the dummy node connected to v
264 adjEntry outAdj = v->firstAdj();
265 adjEntry dummyAdj = outAdj->twin();
266
267 node dummy = dummyAdj->theNode();
268 OGDF_ASSERT(dummy->degree() == 3);
269
270 //we do not delete the node if we already inserted it in create...
271 //because it is a part of the graph now (in contrast to the split node)
272 m_pG->delEdge(v->firstAdj()->theEdge());
273 OGDF_ASSERT(v->degree() == 0);
274
275 m_pG->unsplit(dummy);
276 }
277
278protected:
281
284
286
287private:
289
292
293 //information about edges that are deleted in clique processing
294#if 0
295 class CliqueInfo {
296 public:
297 CliqueInfo(node v, int i) : m_target(v), m_edgeIndex(i) {}
298 node m_target; //target node of deleted edge
299 int m_edgeIndex; //index of deleted edge, has to be restored
300 };
301#endif
302
305
307 EdgeArray<bool> m_replacementEdge; // XXX: maybe we can join this with edge type
312
314
316 //structures for association classes
317 //may be replaced later by generic structures for different types
321
324
327
332
334
336};
337
338}
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declaration of singly linked lists and iterators.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition Graph_d.h:173
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:161
node theNode() const
Returns the node whose adjacency list contains this element.
Definition Graph_d.h:167
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition exceptions.h:247
Rectangles with real coordinates.
Definition geometry.h:798
Class for the representation of edges.
Definition Graph_d.h:364
Functionality for temporarily hiding edges in constant time.
Definition Graph_d.h:1222
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Class for the representation of nodes.
Definition Graph_d.h:241
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition Graph_d.h:284
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Graph_d.h:287
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
Encapsulates a pointer to an ogdf::SList element.
Definition SList.h:104
bool valid() const
Returns true iff the iterator points to an element.
Definition SList.h:134
Singly linked lists.
Definition SList.h:191
Modelling of association classes.
Definition UMLGraph.h:181
AssociationClass(edge e, double width=1.0, double height=1.0, double x=0.0, double y=0.0)
Definition UMLGraph.h:183
void writeGML(std::ostream &os)
Writes attributed graph in GML format to output stream os.
void undoStars()
Undo clique replacements.
NodeArray< DRect > m_cliqueCircleSize
save the bounding box size of the circular drawing of the clique at center
Definition UMLGraph.h:309
void writeGML(const char *fileName)
Writes attributed graph in GML format to file fileName.
void setUpwards(adjEntry a, bool b)
Sets status of edges to be specially embedded (if alignment)
Definition UMLGraph.h:158
EdgeArray< node > m_associationClassModel
modelled classes are stored
Definition UMLGraph.h:320
SListPure< edge > m_mergeEdges
Definition UMLGraph.h:315
EdgeArray< AssociationClass * > m_assClass
association class for list
Definition UMLGraph.h:319
virtual void init(const Graph &G, long initAttr) override
Initializes the graph attributes for graph G.
Definition UMLGraph.h:82
void modelAssociationClasses()
Inserts representation for association class in underlying graph.
Definition UMLGraph.h:222
void replaceByStar(List< List< node > > &cliques)
Replaces (dense) subgraphs given in list clique by inserting a center node connected to each node (=>...
virtual ~UMLGraph()
Destructor.
node replaceByStar(List< node > &clique, NodeArray< int > &cliqueNum)
bool isReplacement(edge e)
Returns true if edge was inserted during clique replacement.
Definition UMLGraph.h:141
NodeArray< DPoint > m_cliqueCirclePos
save the position of the node in the circular drawing of the clique
Definition UMLGraph.h:311
SListPure< AssociationClass * > m_assClassList
saves all accociation classes
Definition UMLGraph.h:318
virtual void init(Graph &G, long initAttr)
Definition UMLGraph.h:72
AdjEntryArray< bool > m_upwardEdge
used to classify edges for embedding with alignment
Definition UMLGraph.h:326
double getDefaultCliqueCenterSize()
Definition UMLGraph.h:138
node createAssociationClass(edge e, double width=1.0, double height=1.0)
Adds association class to edge e.
Definition UMLGraph.h:200
void undoAssociationClasses()
Definition UMLGraph.h:241
double m_cliqueCenterSize
default size of inserted clique replacement center nodes
Definition UMLGraph.h:303
void undoAssociationClass(AssociationClass *ac)
Removes the modeling of the association class without removing the information.
Definition UMLGraph.h:250
void computeCliquePosition(List< node > &adjNodes, node center, double rectMin=-1.0)
Compute positions for the nodes in adjNodes on a circle.
NodeArray< node > m_hierarchyParent
used to derive edge types for alignment in PlanRepUML (same hierarchyparent => edge connects (half)br...
Definition UMLGraph.h:331
DPoint cliquePos(node v)
Definition UMLGraph.h:113
SListPure< node > m_centerNodes
center nodes introduced at clique replacement
Definition UMLGraph.h:304
node doInsertMergers(node v, SList< edge > &inGens)
Inserts mergers per node with given edges.
bool upwards(adjEntry a) const
Definition UMLGraph.h:160
const SListPure< AssociationClass * > & assClassList() const
Definition UMLGraph.h:195
DRect cliqueRect(node v)
Returns the size of a circular drawing for a clique around center v.
Definition UMLGraph.h:111
void undoStar(node center, bool restoreAllEdges)
Boolean switches restore of all hidden edges in single clique call.
Graph * m_pG
Definition UMLGraph.h:288
EdgeArray< bool > m_replacementEdge
used to mark clique replacement edges
Definition UMLGraph.h:307
UMLGraph(Graph &G, long initAttributes=0)
By default, all edges are associations.
node modelAssociationClass(AssociationClass *ac)
Definition UMLGraph.h:230
DRect circularBound(node center)
void adjustHierarchyParents()
Adjusts the parent field for all nodes after insertion of mergers. If insertion is done per node via ...
const SListPure< node > & centerNodes()
Definition UMLGraph.h:133
Graph::HiddenEdgeSet * m_hiddenEdges
Definition UMLGraph.h:335
void undoGenMergers()
void insertGenMergers()
Merges generalizations at a common superclass.
void setDefaultCliqueCenterSize(double i)
Default size of inserted clique replacement center nodes.
Definition UMLGraph.h:136
const AssociationClass * assClass(edge e) const
Definition UMLGraph.h:197
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
Definition of exception classes.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.