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
36#include <ogdf/basic/SList.h>
37
38namespace ogdf {
39
41public:
42 // construction
43
44 // Creates a UML graph for no associated graph (default constructor).
45 UMLGraph() : GraphAttributes(), m_pG(nullptr), m_hiddenEdges(nullptr) { }
46
47 // Creates a UML graph associated with graph \p G.
51 explicit UMLGraph(Graph& G, long initAttributes = 0);
52
54 virtual ~UMLGraph();
55
56 // Initializes the UML graph for graph \p G.
64 virtual void init(Graph& G, long initAttr) {
65 m_pG = &G;
66 GraphAttributes::init(G, initAttr);
67 m_hierarchyParent.init(constGraph(), nullptr);
68 m_upwardEdge.init(constGraph(), false);
69
70 delete m_hiddenEdges;
71 m_hiddenEdges = new Graph::HiddenEdgeSet(G);
72 }
73
74 virtual void init(const Graph& G, long initAttr) override {
75 init(const_cast<Graph&>(G), initAttr);
76 }
77
80
86
90
96
98 void undoStars();
100 void undoStar(node center, bool restoreAllEdges);
101
103 DRect cliqueRect(node v) { return m_cliqueCircleSize[v]; }
104
105 DPoint cliquePos(node v) { return m_cliqueCirclePos[v]; }
106
107#if 0
108 //compute circle positions for all nodes around center
109 //using the ordering given in this UMLGraph, calls
110 //ccP(List...)
111 //rectMin is a temporary solution until compaction with constraints allows stretching
112 //of rect to clique size, it gives the min(w,h) of the given fixed size rect around the clique
113 void computeCliquePosition(node center, double rectMin);
114 void computeCliquePosition(node center, double rectMin, const adjEntry &startAdj);
115#endif
116
123 void computeCliquePosition(List<node>& adjNodes, node center, double rectMin = -1.0);
124
125 const SListPure<node>& centerNodes() { return m_centerNodes; }
126
128 void setDefaultCliqueCenterSize(double i) { m_cliqueCenterSize = max(i, 1.0); }
129
130 double getDefaultCliqueCenterSize() { return m_cliqueCenterSize; }
131
134 // TODO: check here how to guarantee that value is defined,
135 // edgearray is only valid if there are cliques replaced
136 return m_replacementEdge[e];
137 }
138
140
141#if 0
143 Graph& pureGraph() const {return *m_pG;}
144
146 void setAlign(edge e, bool b) {m_alignEdge[e] = b;}
147#endif
148
150 void setUpwards(adjEntry a, bool b) { m_upwardEdge[a] = b; }
151
152 bool upwards(adjEntry a) const { return m_upwardEdge[a]; }
153
155 void writeGML(const char* fileName);
156
158 void writeGML(std::ostream& os);
159
164
165#if 0
169 void sortEdgesFromLayout();
170#endif
171
174 public:
175 explicit AssociationClass(edge e, double width = 1.0, double height = 1.0, double x = 0.0,
176 double y = 0.0)
177 : m_width(width), m_height(height), m_x(x), m_y(y), m_edge(e), m_node(nullptr) { }
178
179 double m_width;
180 double m_height;
181 double m_x;
182 double m_y;
185 };
186
187 const SListPure<AssociationClass*>& assClassList() const { return m_assClassList; }
188
189 const AssociationClass* assClass(edge e) const { return m_assClass[e]; }
190
192 node createAssociationClass(edge e, double width = 1.0, double height = 1.0) {
193 AssociationClass* ac = new AssociationClass(e, width, height);
194 m_assClass[e] = ac;
195 m_assClassList.pushBack(ac);
196 //we already insert the node here, but not the edge
197 //when we always insert this node here, we can remove the associationclass
198 //class and information later on
199 node v = m_pG->newNode();
200 m_height[v] = ac->m_height;
201 m_width[v] = ac->m_width;
202 m_associationClassModel[ac->m_edge] = v;
203 ac->m_node = v;
204 //guarantee correct angle at edge to edge connection
205 if (m_attributes & GraphAttributes::nodeType) {
206 m_vType[v] = Graph::NodeType::associationClass;
207 }
208 return v;
209 }
210
211 //this modelling should only take place in the preprocessing steps
212 //of the drawing algorithms?
215 SListIterator<UMLGraph::AssociationClass*> it = m_assClassList.begin();
216 while (it.valid()) {
217 modelAssociationClass((*it));
218 ++it;
219 }
220 }
221
223 node dummy = m_pG->split(ac->m_edge)->source();
224
225 m_height[dummy] = 1; //just a dummy size
226 m_width[dummy] = 1;
227 OGDF_ASSERT(ac->m_node);
228 m_pG->newEdge(ac->m_node, dummy);
229
230 return dummy;
231 }
232
234 SListIterator<UMLGraph::AssociationClass*> it = m_assClassList.begin();
235 while (it.valid()) {
236 undoAssociationClass((*it));
237 ++it;
238 }
239 }
240
243 node v = m_associationClassModel[ac->m_edge];
244 OGDF_ASSERT(v);
245 OGDF_ASSERT(v->degree() == 1);
246 if (v->degree() != 1) {
247 throw AlgorithmFailureException(AlgorithmFailureCode::Label);
248 }
249 //save layout information
250 ac->m_x = x(v);
251 ac->m_y = y(v);
252
253 //remove node and unsplit edge
254
255 //run around the dummy node connected to v
256 adjEntry outAdj = v->firstAdj();
258
259 node dummy = dummyAdj->theNode();
260 OGDF_ASSERT(dummy->degree() == 3);
261
262 //we do not delete the node if we already inserted it in create...
263 //because it is a part of the graph now (in contrast to the split node)
264 m_pG->delEdge(v->firstAdj()->theEdge());
265 OGDF_ASSERT(v->degree() == 0);
266
267 m_pG->unsplit(dummy);
268 }
269
270protected:
273
276
278
279private:
281
284
285 //information about edges that are deleted in clique processing
286#if 0
287 class CliqueInfo {
288 public:
289 CliqueInfo(node v, int i) : m_target(v), m_edgeIndex(i) {}
290 node m_target; //target node of deleted edge
291 int m_edgeIndex; //index of deleted edge, has to be restored
292 };
293#endif
294
297
299 EdgeArray<bool> m_replacementEdge; // XXX: maybe we can join this with edge type
304
306
308 //structures for association classes
309 //may be replaced later by generic structures for different types
313
316
319
324
326
328};
329
330}
Declaration and implementation of AdjEntryArray class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declaration of singly linked lists and iterators.
Class for adjacency list elements.
Definition Graph_d.h:79
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition Graph_d.h:109
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:97
Dynamic arrays indexed with adjacency entries.
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition exceptions.h:241
Rectangles with real coordinates.
Definition geometry.h:790
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
Functionality for temporarily hiding edges in constant time.
Definition Graph_d.h:821
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition Graph_d.h:220
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Graph_d.h:223
Singly linked lists (maintaining the length of the list).
Definition SList.h:833
Encapsulates a pointer to an ogdf::SList element.
Definition SList.h:92
bool valid() const
Returns true iff the iterator points to an element.
Definition SList.h:122
Singly linked lists.
Definition SList.h:179
Modelling of association classes.
Definition UMLGraph.h:173
AssociationClass(edge e, double width=1.0, double height=1.0, double x=0.0, double y=0.0)
Definition UMLGraph.h:175
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:301
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:150
EdgeArray< node > m_associationClassModel
modelled classes are stored
Definition UMLGraph.h:312
SListPure< edge > m_mergeEdges
Definition UMLGraph.h:307
EdgeArray< AssociationClass * > m_assClass
association class for list
Definition UMLGraph.h:311
virtual void init(const Graph &G, long initAttr) override
Initializes the graph attributes for graph G.
Definition UMLGraph.h:74
void modelAssociationClasses()
Inserts representation for association class in underlying graph.
Definition UMLGraph.h:214
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:133
NodeArray< DPoint > m_cliqueCirclePos
save the position of the node in the circular drawing of the clique
Definition UMLGraph.h:303
SListPure< AssociationClass * > m_assClassList
saves all accociation classes
Definition UMLGraph.h:310
virtual void init(Graph &G, long initAttr)
Definition UMLGraph.h:64
AdjEntryArray< bool > m_upwardEdge
used to classify edges for embedding with alignment
Definition UMLGraph.h:318
double getDefaultCliqueCenterSize()
Definition UMLGraph.h:130
node createAssociationClass(edge e, double width=1.0, double height=1.0)
Adds association class to edge e.
Definition UMLGraph.h:192
void undoAssociationClasses()
Definition UMLGraph.h:233
double m_cliqueCenterSize
default size of inserted clique replacement center nodes
Definition UMLGraph.h:295
void undoAssociationClass(AssociationClass *ac)
Removes the modeling of the association class without removing the information.
Definition UMLGraph.h:242
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:323
DPoint cliquePos(node v)
Definition UMLGraph.h:105
SListPure< node > m_centerNodes
center nodes introduced at clique replacement
Definition UMLGraph.h:296
node doInsertMergers(node v, SList< edge > &inGens)
Inserts mergers per node with given edges.
bool upwards(adjEntry a) const
Definition UMLGraph.h:152
const SListPure< AssociationClass * > & assClassList() const
Definition UMLGraph.h:187
DRect cliqueRect(node v)
Returns the size of a circular drawing for a clique around center v.
Definition UMLGraph.h:103
void undoStar(node center, bool restoreAllEdges)
Boolean switches restore of all hidden edges in single clique call.
Graph * m_pG
Definition UMLGraph.h:280
EdgeArray< bool > m_replacementEdge
used to mark clique replacement edges
Definition UMLGraph.h:299
UMLGraph(Graph &G, long initAttributes=0)
By default, all edges are associations.
node modelAssociationClass(AssociationClass *ac)
Definition UMLGraph.h:222
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:125
Graph::HiddenEdgeSet * m_hiddenEdges
Definition UMLGraph.h:327
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:128
const AssociationClass * assClass(edge e) const
Definition UMLGraph.h:189
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.