Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

UMLGraph.h
Go to the documentation of this file.
1 
32 #pragma once
33 
36 #include <ogdf/basic/SList.h>
37 
38 namespace ogdf {
39 
41 public:
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 
82  void insertGenMergers();
84  node doInsertMergers(node v, SList<edge>& inGens);
85  void undoGenMergers();
86 
90 
95  void replaceByStar(List<List<node>>& cliques);
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 
133  bool isReplacement(edge e) {
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
142  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 
163  void adjustHierarchyParents();
164 
165 #if 0
166  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) {
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) {
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();
257  adjEntry dummyAdj = outAdj->twin();
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 
270 protected:
273 
274  node replaceByStar(List<node>& clique, NodeArray<int>& cliqueNum);
275  DRect circularBound(node center);
276 
278 
279 private:
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 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:66
GraphAttributes.h
Declaration of class GraphAttributes which extends a Graph by additional attributes.
ogdf::UMLGraph::centerNodes
const SListPure< node > & centerNodes()
Definition: UMLGraph.h:125
ogdf::GenericPoint< double >
ogdf::UMLGraph::undoAssociationClasses
void undoAssociationClasses()
Definition: UMLGraph.h:233
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:175
ogdf::UMLGraph::isReplacement
bool isReplacement(edge e)
Returns true if edge was inserted during clique replacement.
Definition: UMLGraph.h:133
ogdf::UMLGraph::m_hiddenEdges
Graph::HiddenEdgeSet * m_hiddenEdges
Definition: UMLGraph.h:327
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::Graph::NodeType::associationClass
@ associationClass
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:159
ogdf::UMLGraph::m_mergeEdges
SListPure< edge > m_mergeEdges
Definition: UMLGraph.h:307
ogdf::Graph::HiddenEdgeSet
Functionality for temporarily hiding edges in constant time.
Definition: Graph_d.h:1216
ogdf::AlgorithmFailureCode::Label
@ Label
labelling failed
ogdf::SListIteratorBase
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:41
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:833
ogdf::UMLGraph::m_centerNodes
SListPure< node > m_centerNodes
center nodes introduced at clique replacement
Definition: UMLGraph.h:296
ogdf::UMLGraph::cliqueRect
DRect cliqueRect(node v)
Returns the size of a circular drawing for a clique around center v.
Definition: UMLGraph.h:103
ogdf::UMLGraph::m_assClassList
SListPure< AssociationClass * > m_assClassList
saves all accociation classes
Definition: UMLGraph.h:310
ogdf::UMLGraph::modelAssociationClasses
void modelAssociationClasses()
Inserts representation for association class in underlying graph.
Definition: UMLGraph.h:214
ogdf::SListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: SList.h:122
ogdf::AdjElement::twin
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:165
ogdf::UMLGraph::AssociationClass
Modelling of association classes.
Definition: UMLGraph.h:173
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::UMLGraph::AssociationClass::m_node
node m_node
Definition: UMLGraph.h:184
ogdf::AlgorithmFailureException
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition: exceptions.h:243
ogdf::edge
EdgeElement * edge
The type of edges.
Definition: Graph_d.h:67
ogdf::UMLGraph::m_upwardEdge
AdjEntryArray< bool > m_upwardEdge
used to classify edges for embedding with alignment
Definition: UMLGraph.h:318
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:153
ogdf::UMLGraph::m_associationClassModel
EdgeArray< node > m_associationClassModel
modelled classes are stored
Definition: UMLGraph.h:312
ogdf::NodeElement::degree
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:276
ogdf::UMLGraph::undoAssociationClass
void undoAssociationClass(AssociationClass *ac)
Removes the modeling of the association class without removing the information.
Definition: UMLGraph.h:242
SList.h
Declaration of singly linked lists and iterators.
ogdf::DRect
Rectangles with real coordinates.
Definition: geometry.h:791
ogdf::UMLGraph::cliquePos
DPoint cliquePos(node v)
Definition: UMLGraph.h:105
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:323
ogdf::SListPure
Singly linked lists.
Definition: SList.h:39
ogdf::UMLGraph::m_cliqueCirclePos
NodeArray< DPoint > m_cliqueCirclePos
save the position of the node in the circular drawing of the clique
Definition: UMLGraph.h:303
ogdf::UMLGraph::m_replacementEdge
EdgeArray< bool > m_replacementEdge
used to mark clique replacement edges
Definition: UMLGraph.h:299
ogdf::UMLGraph::assClass
const AssociationClass * assClass(edge e) const
Definition: UMLGraph.h:189
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::UMLGraph::init
virtual void init(const Graph &G, long initAttr) override
Initializes the graph attributes for graph G.
Definition: UMLGraph.h:74
ogdf::UMLGraph::setDefaultCliqueCenterSize
void setDefaultCliqueCenterSize(double i)
Default size of inserted clique replacement center nodes.
Definition: UMLGraph.h:128
ogdf::UMLGraph
Definition: UMLGraph.h:40
ogdf::UMLGraph::AssociationClass::m_width
double m_width
Definition: UMLGraph.h:179
ogdf::UMLGraph::setUpwards
void setUpwards(adjEntry a, bool b)
Sets status of edges to be specially embedded (if alignment)
Definition: UMLGraph.h:150
ogdf::graphics::init
void init()
Definition: graphics.h:446
ogdf::UMLGraph::modelAssociationClass
node modelAssociationClass(AssociationClass *ac)
Definition: UMLGraph.h:222
ogdf::UMLGraph::m_pG
Graph * m_pG
Definition: UMLGraph.h:280
ogdf::UMLGraph::assClassList
const SListPure< AssociationClass * > & assClassList() const
Definition: UMLGraph.h:187
ogdf::UMLGraph::m_assClass
EdgeArray< AssociationClass * > m_assClass
association class for list
Definition: UMLGraph.h:311
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:279
AdjEntryArray.h
Declaration and implementation of AdjEntryArray class.
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::UMLGraph::upwards
bool upwards(adjEntry a) const
Definition: UMLGraph.h:152
ogdf::UMLGraph::AssociationClass::m_height
double m_height
Definition: UMLGraph.h:180
ogdf::UMLGraph::AssociationClass::m_y
double m_y
Definition: UMLGraph.h:182
ogdf::GraphAttributes::nodeType
static const long nodeType
Corresponds to node attribute type(node).
Definition: GraphAttributes.h:134
ogdf::UMLGraph::createAssociationClass
node createAssociationClass(edge e, double width=1.0, double height=1.0)
Adds association class to edge e.
Definition: UMLGraph.h:192
ogdf::UMLGraph::m_cliqueCenterSize
double m_cliqueCenterSize
default size of inserted clique replacement center nodes
Definition: UMLGraph.h:295
ogdf::UMLGraph::getDefaultCliqueCenterSize
double getDefaultCliqueCenterSize()
Definition: UMLGraph.h:130
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::UMLGraph::AssociationClass::m_x
double m_x
Definition: UMLGraph.h:181
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:301
ogdf::UMLGraph::init
virtual void init(Graph &G, long initAttr)
Definition: UMLGraph.h:64
ogdf::UMLGraph::AssociationClass::m_edge
edge m_edge
Definition: UMLGraph.h:183
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::UMLGraph::UMLGraph
UMLGraph()
Definition: UMLGraph.h:45