Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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>
38 #include <ogdf/basic/exceptions.h>
39 #include <ogdf/basic/geometry.h>
40 
41 #include <algorithm>
42 #include <iosfwd>
43 
44 namespace ogdf {
45 template<class E>
46 class List;
47 
49 public:
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 
90  void insertGenMergers();
92  node doInsertMergers(node v, SList<edge>& inGens);
93  void undoGenMergers();
94 
98 
103  void replaceByStar(List<List<node>>& cliques);
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 
141  bool isReplacement(edge e) {
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
150  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 
171  void adjustHierarchyParents();
172 
173 #if 0
174  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) {
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) {
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 
278 protected:
281 
282  node replaceByStar(List<node>& clique, NodeArray<int>& cliqueNum);
283  DRect circularBound(node center);
284 
286 
287 private:
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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
ogdf::UMLGraph::centerNodes
const SListPure< node > & centerNodes()
Definition: UMLGraph.h:133
Graph.h
Includes declaration of graph class.
ogdf::GenericPoint< double >
ogdf::UMLGraph::undoAssociationClasses
void undoAssociationClasses()
Definition: UMLGraph.h:241
ogdf::UMLGraph::AssociationClass::AssociationClass
AssociationClass(edge e, double width=1.0, double height=1.0, double x=0.0, double y=0.0)
Definition: UMLGraph.h:183
ogdf::UMLGraph::isReplacement
bool isReplacement(edge e)
Returns true if edge was inserted during clique replacement.
Definition: UMLGraph.h:141
exceptions.h
Definition of exception classes.
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::UMLGraph::m_hiddenEdges
Graph::HiddenEdgeSet * m_hiddenEdges
Definition: UMLGraph.h:335
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::Graph::NodeType::associationClass
@ associationClass
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:166
ogdf::UMLGraph::m_mergeEdges
SListPure< edge > m_mergeEdges
Definition: UMLGraph.h:315
ogdf::Graph::HiddenEdgeSet
Functionality for temporarily hiding edges in constant time.
Definition: Graph_d.h:1224
ogdf::AlgorithmFailureCode::Label
@ Label
labelling failed
ogdf::SListIteratorBase
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:50
ogdf::GraphAttributes::init
virtual void init(const Graph &G, long attr)
Initializes the graph attributes for graph G.
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:845
ogdf::UMLGraph::m_centerNodes
SListPure< node > m_centerNodes
center nodes introduced at clique replacement
Definition: UMLGraph.h:304
ogdf::UMLGraph::cliqueRect
DRect cliqueRect(node v)
Returns the size of a circular drawing for a clique around center v.
Definition: UMLGraph.h:111
ogdf::UMLGraph::m_assClassList
SListPure< AssociationClass * > m_assClassList
saves all accociation classes
Definition: UMLGraph.h:318
ogdf::UMLGraph::modelAssociationClasses
void modelAssociationClasses()
Inserts representation for association class in underlying graph.
Definition: UMLGraph.h:222
ogdf::SListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: SList.h:134
ogdf::AdjElement::twin
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:172
ogdf::UMLGraph::AssociationClass
Modelling of association classes.
Definition: UMLGraph.h:181
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::UMLGraph::AssociationClass::m_node
node m_node
Definition: UMLGraph.h:192
ogdf::AlgorithmFailureException
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition: exceptions.h:247
ogdf::edge
EdgeElement * edge
The type of edges.
Definition: Graph_d.h:74
ogdf::UMLGraph::m_upwardEdge
AdjEntryArray< bool > m_upwardEdge
used to classify edges for embedding with alignment
Definition: UMLGraph.h:326
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
ogdf::UMLGraph::m_associationClassModel
EdgeArray< node > m_associationClassModel
modelled classes are stored
Definition: UMLGraph.h:320
ogdf::NodeElement::degree
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:283
ogdf::UMLGraph::undoAssociationClass
void undoAssociationClass(AssociationClass *ac)
Removes the modeling of the association class without removing the information.
Definition: UMLGraph.h:250
SList.h
Declaration of singly linked lists and iterators.
ogdf::DRect
Rectangles with real coordinates.
Definition: geometry.h:798
ogdf::UMLGraph::cliquePos
DPoint cliquePos(node v)
Definition: UMLGraph.h:113
ogdf::UMLGraph::m_hierarchyParent
NodeArray< node > m_hierarchyParent
used to derive edge types for alignment in PlanRepUML (same hierarchyparent => edge connects (half)br...
Definition: UMLGraph.h:331
ogdf::SListPure
Singly linked lists.
Definition: SList.h:52
ogdf::UMLGraph::m_cliqueCirclePos
NodeArray< DPoint > m_cliqueCirclePos
save the position of the node in the circular drawing of the clique
Definition: UMLGraph.h:311
ogdf::UMLGraph::m_replacementEdge
EdgeArray< bool > m_replacementEdge
used to mark clique replacement edges
Definition: UMLGraph.h:307
ogdf::UMLGraph::assClass
const AssociationClass * assClass(edge e) const
Definition: UMLGraph.h:197
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: DfsMakeBiconnected.h:40
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::UMLGraph::init
virtual void init(const Graph &G, long initAttr) override
Initializes the graph attributes for graph G.
Definition: UMLGraph.h:82
ogdf::UMLGraph::setDefaultCliqueCenterSize
void setDefaultCliqueCenterSize(double i)
Default size of inserted clique replacement center nodes.
Definition: UMLGraph.h:136
ogdf::UMLGraph
Definition: UMLGraph.h:48
ogdf::UMLGraph::AssociationClass::m_width
double m_width
Definition: UMLGraph.h:187
ogdf::UMLGraph::setUpwards
void setUpwards(adjEntry a, bool b)
Sets status of edges to be specially embedded (if alignment)
Definition: UMLGraph.h:158
ogdf::graphics::init
void init()
Definition: graphics.h:450
ogdf::UMLGraph::modelAssociationClass
node modelAssociationClass(AssociationClass *ac)
Definition: UMLGraph.h:230
ogdf::UMLGraph::m_pG
Graph * m_pG
Definition: UMLGraph.h:288
ogdf::UMLGraph::assClassList
const SListPure< AssociationClass * > & assClassList() const
Definition: UMLGraph.h:195
ogdf::UMLGraph::m_assClass
EdgeArray< AssociationClass * > m_assClass
association class for list
Definition: UMLGraph.h:319
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::NodeElement::firstAdj
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:286
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::UMLGraph::upwards
bool upwards(adjEntry a) const
Definition: UMLGraph.h:160
ogdf::UMLGraph::AssociationClass::m_height
double m_height
Definition: UMLGraph.h:188
ogdf::UMLGraph::AssociationClass::m_y
double m_y
Definition: UMLGraph.h:190
ogdf::GraphAttributes::nodeType
static const long nodeType
Corresponds to node attribute type(node).
Definition: GraphAttributes.h:140
ogdf::UMLGraph::createAssociationClass
node createAssociationClass(edge e, double width=1.0, double height=1.0)
Adds association class to edge e.
Definition: UMLGraph.h:200
ogdf::UMLGraph::m_cliqueCenterSize
double m_cliqueCenterSize
default size of inserted clique replacement center nodes
Definition: UMLGraph.h:303
ogdf::UMLGraph::getDefaultCliqueCenterSize
double getDefaultCliqueCenterSize()
Definition: UMLGraph.h:138
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::UMLGraph::AssociationClass::m_x
double m_x
Definition: UMLGraph.h:189
ogdf::UMLGraph::m_cliqueCircleSize
NodeArray< DRect > m_cliqueCircleSize
save the bounding box size of the circular drawing of the clique at center
Definition: UMLGraph.h:309
ogdf::UMLGraph::init
virtual void init(Graph &G, long initAttr)
Definition: UMLGraph.h:72
ogdf::UMLGraph::AssociationClass::m_edge
edge m_edge
Definition: UMLGraph.h:191
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::UMLGraph::UMLGraph
UMLGraph()
Definition: UMLGraph.h:53