Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ELabelInterface.h
Go to the documentation of this file.
1
32#pragma once
33
36#include <ogdf/uml/PlanRepUML.h>
37
38namespace ogdf {
39
40// the available labels
41// the five basic labels are not allowed to be changed,
42// cause they have a special meaning/position, insert
43// other labels between mult1/End2
44
45enum class LabelType {
46 End1 = 0,
47 Mult1,
48 Name,
49 End2,
50 Mult2,
52};
53
54enum class UsedLabels {
55 End1 = (1 << static_cast<int>(LabelType::End1)), // 1
56 Mult1 = (1 << static_cast<int>(LabelType::Mult1)), // 2
57 Name = (1 << static_cast<int>(LabelType::Name)), // 4
58 End2 = (1 << static_cast<int>(LabelType::End2)), // 8
59 Mult2 = (1 << static_cast<int>(LabelType::Mult2)), // 16
60 lAll = (1 << static_cast<int>(LabelType::NumLabels)) - 1, // 31
61};
62
63// the basic single label defining class
64// holds info about all labels for one edge
65template<class coordType>
67public:
68 static const int numberUsedLabels = static_cast<int>(UsedLabels::lAll);
69
70 //construction and destruction
72 m_edge = nullptr;
73 m_usedLabels = 0;
74 }
75
76 //bit pattern 2^labelenumpos bitwise
77 explicit EdgeLabel(edge e, int usedLabels = numberUsedLabels)
78 : m_usedLabels(usedLabels), m_edge(e) {
79 for (int i = 0; i < m_numberLabelTypes; i++) {
80 //zu testzwecken randoms
81 m_xSize[i] = double(randomNumber(5, 13)) / 50.0; //1
82 m_ySize[i] = double(randomNumber(3, 7)) / 50.0; //1
83
84 m_xPos[i] = 0;
85 m_yPos[i] = 0;
86 }
87 }
88
89 // Construction with specification of label sizes in arrays of length labelnum
90 EdgeLabel(edge e, coordType w[], coordType h[], int usedLabels = numberUsedLabels)
91 : m_usedLabels(usedLabels), m_edge(e) {
92 for (int i = 0; i < m_numberLabelTypes; i++) {
93 m_xSize[i] = w[i];
94 m_ySize[i] = h[i];
95 m_xPos[i] = 0;
96 m_yPos[i] = 0;
97 }
98 }
99
101 : m_usedLabels(usedLabels), m_edge(e) {
102 for (int i = 0; i < m_numberLabelTypes; i++) {
103 if (m_usedLabels & (1 << i)) {
104 m_xPos[i] = 0.0;
105 m_yPos[i] = 0.0;
106 m_xSize[i] = w;
107 m_ySize[i] = h;
108 }
109 }
110 }
111
112 //copy constructor
113 EdgeLabel(const EdgeLabel& rhs) : m_usedLabels(rhs.m_usedLabels), m_edge(rhs.m_edge) {
114 for (int i = 0; i < m_numberLabelTypes; i++) {
115 m_xPos[i] = rhs.m_xPos[i];
116 m_yPos[i] = rhs.m_yPos[i];
117 m_xSize[i] = rhs.m_xSize[i];
118 m_ySize[i] = rhs.m_ySize[i];
119 }
120 }
121
123
124 //assignment
126 if (this != &rhs) {
127 m_usedLabels = rhs.m_usedLabels;
128 m_edge = rhs.m_edge;
129 int i;
130 for (i = 0; i < m_numberLabelTypes; i++) {
131 m_xPos[i] = rhs.m_xPos[i];
132 m_yPos[i] = rhs.m_yPos[i];
133 m_xSize[i] = rhs.m_xSize[i];
134 m_ySize[i] = rhs.m_ySize[i];
135 }
136 }
137 return *this;
138 }
139
141 if (m_edge) {
142 OGDF_ASSERT(m_edge == rhs.m_edge);
143 } else {
144 m_edge = rhs.m_edge;
145 }
146 if (this != &rhs) {
147 m_usedLabels |= rhs.m_usedLabels;
148 for (int i = 0; i < m_numberLabelTypes; i++) {
149 if (rhs.m_usedLabels & (1 << i)) {
150 m_xPos[i] = rhs.m_xPos[i];
151 m_yPos[i] = rhs.m_yPos[i];
152 m_xSize[i] = rhs.m_xSize[i];
153 m_ySize[i] = rhs.m_ySize[i];
154 }
155 }
156 }
157 return *this;
158 }
159
160 //set
161 void setX(LabelType elt, coordType x) { m_xPos[static_cast<int>(elt)] = x; }
162
163 void setY(LabelType elt, coordType y) { m_yPos[static_cast<int>(elt)] = y; }
164
165 void setHeight(LabelType elt, coordType h) { m_ySize[static_cast<int>(elt)] = h; }
166
167 void setWidth(LabelType elt, coordType w) { m_xSize[static_cast<int>(elt)] = w; }
168
169 void setEdge(edge e) { m_edge = e; }
170
171 void addType(LabelType elt) { m_usedLabels |= (1 << static_cast<int>(elt)); }
172
173 //get
174 coordType getX(LabelType elt) const { return m_xPos[static_cast<int>(elt)]; }
175
176 coordType getY(LabelType elt) const { return m_yPos[static_cast<int>(elt)]; }
177
178 coordType getWidth(LabelType elt) const { return m_xSize[static_cast<int>(elt)]; }
179
180 coordType getHeight(LabelType elt) const { return m_ySize[static_cast<int>(elt)]; }
181
182 edge theEdge() const { return m_edge; }
183
184 bool usedLabel(LabelType elt) const {
185 return (m_usedLabels & (1 << static_cast<int>(elt))) > 0;
186 }
187
188 int& usedLabel() { return m_usedLabels; }
189
190
191private:
192 static const int m_numberLabelTypes = static_cast<int>(LabelType::NumLabels);
193
194 //the positions of the labels
195 coordType m_xPos[m_numberLabelTypes];
196 coordType m_yPos[m_numberLabelTypes];
197
198 //the input label sizes
199 coordType m_xSize[m_numberLabelTypes];
200 coordType m_ySize[m_numberLabelTypes];
201
202 //which labels have to be placed bit pattern 2^labelenumpos bitwise
203 int m_usedLabels; //1 = only name, 5 = name and end2, ...
204
205 //the edge of heaven
207
208 //the label text
209#if 0
210 string m_string;
211#endif
212};
213
214//Interface to algorithm
215template<class coordType>
217public:
218 //constructor
220 //the PRU should not work with real world data but with
221 //normalized integer values
222 m_distDefault = 2;
223 m_minFeatDist = 1;
224 m_labels.init(pru.original());
225 m_ug = nullptr;
226
227 for (edge e : pru.original().edges) {
229 }
230 }
231
232 //constructor on GraphAttributes
234 //the GraphAttributes should work on real world data,
235 //which can be floats or ints
236 m_distDefault = 0.002;
237 m_minFeatDist = 0.003;
238 m_labels.init(uml.constGraph());
239
240 for (edge e : uml.constGraph().edges) {
242 }
243 }
244
245 GraphAttributes& graph() { return *m_ug; }
246
247 //set new EdgeLabel
248 void setLabel(const edge& e, const EdgeLabel<coordType>& el) { m_labels[e] = el; }
249
250 void addLabel(const edge& e, const EdgeLabel<coordType>& el) { m_labels[e] |= el; }
251
252 //get info about current EdgeLabel
254
255 coordType getWidth(edge e, LabelType elt) { return m_labels[e].getWidth(elt); }
256
257 coordType getHeight(edge e, LabelType elt) { return m_labels[e].getHeight(elt); }
258
259 //get general information
261
263
264private:
265 EdgeArray<EdgeLabel<coordType>> m_labels; //holds all labels for original edges
266 //the base graph
268
269 coordType m_distDefault; //default distance label/edge for positioner
270 coordType m_minFeatDist; //min Distance label/feature in candidate posit.
271};
272
273}
Declaration of class GridLayout.
Declaration of class GridLayoutMapped which extends GridLayout by a grid mapping mechanism.
Declaration of class PlanRepUML.
GraphAttributes * m_ug
void setLabel(const edge &e, const EdgeLabel< coordType > &el)
ELabelInterface(GraphAttributes &uml)
GraphAttributes & graph()
coordType getWidth(edge e, LabelType elt)
coordType getHeight(edge e, LabelType elt)
void addLabel(const edge &e, const EdgeLabel< coordType > &el)
EdgeLabel< coordType > & getLabel(edge e)
EdgeArray< EdgeLabel< coordType > > m_labels
ELabelInterface(PlanRepUML &pru)
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
coordType m_xSize[m_numberLabelTypes]
void addType(LabelType elt)
EdgeLabel(edge e, coordType w, coordType h, int usedLabels)
coordType getWidth(LabelType elt) const
void setX(LabelType elt, coordType x)
coordType getHeight(LabelType elt) const
EdgeLabel & operator=(const EdgeLabel &rhs)
EdgeLabel(edge e, coordType w[], coordType h[], int usedLabels=numberUsedLabels)
void setWidth(LabelType elt, coordType w)
edge theEdge() const
EdgeLabel(const EdgeLabel &rhs)
coordType getY(LabelType elt) const
coordType m_xPos[m_numberLabelTypes]
EdgeLabel & operator|=(const EdgeLabel &rhs)
void setY(LabelType elt, coordType y)
EdgeLabel(edge e, int usedLabels=numberUsedLabels)
void setEdge(edge e)
coordType m_ySize[m_numberLabelTypes]
bool usedLabel(LabelType elt) const
coordType m_yPos[m_numberLabelTypes]
coordType getX(LabelType elt) const
void setHeight(LabelType elt, coordType h)
Stores additional attributes of a graph (like layout information).
virtual void init(const Graph &G, long attr)
Initializes the graph attributes for graph G.
Planarized representation (of a connected component) of a UMLGraph; allows special handling of hierar...
Definition PlanRepUML.h:48
#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
int randomNumber(int low, int high)
Returns random integer between low and high (including).
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
@ NumLabels
the number of available labels at an edge