Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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