Tulip  5.0.0
Large graphs analysis and drawing
GlGraphInputData.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef Tulip_GLGRAPHINPUTDATA_H
22 #define Tulip_GLGRAPHINPUTDATA_H
23 
24 #include <tulip/tulipconf.h>
25 #include <tulip/Observable.h>
26 #include <tulip/LayoutProperty.h>
27 #include <tulip/DoubleProperty.h>
28 #include <tulip/StringProperty.h>
29 #include <tulip/BooleanProperty.h>
30 #include <tulip/SizeProperty.h>
31 #include <tulip/IntegerProperty.h>
32 #include <tulip/ColorProperty.h>
33 
34 namespace tlp {
35 
36 class PropertyManager;
37 class Graph;
38 class Glyph;
39 class EdgeExtremityGlyph;
40 class GlVertexArrayManager;
41 class GlMetaNodeRenderer;
42 class GlGraphRenderingParameters;
43 class GlGlyphRenderer;
44 
45 /**
46  * Class use to store inputData of the graph
47  */
48 class TLP_GL_SCOPE GlGraphInputData : public Observable {
49 
50 public:
51 
52  /**
53  * GlGraphInputData available properties
54  */
55  enum PropertyName {
56  VIEW_COLOR=0, /**< color of nodes/edges */
57  VIEW_LABELCOLOR, /**< color of labels */
58  VIEW_LABELBORDERCOLOR, /**< border color of labels */
59  VIEW_LABELBORDERWIDTH, /**< border width of labels */
60  VIEW_SIZE, /**< size of nodes/edges */
61  VIEW_LABELPOSITION, /**< position of labels */
62  VIEW_SHAPE, /**< shape of nodes/edges */
63  VIEW_ROTATION, /**< rotation apply on nodes */
64  VIEW_SELECTED, /**< nodes/edges selected */
65  VIEW_FONT, /**< font name of labels */
66  VIEW_FONTSIZE, /**< font size of labels */
67  VIEW_LABEL, /**< text of labels */
68  VIEW_LAYOUT, /**< position of nodes */
69  VIEW_TEXTURE, /**< texture of nodes/edges */
70  VIEW_BORDERCOLOR, /**< border color of nodes/edges */
71  VIEW_BORDERWIDTH, /**< border width of nodes/edges */
72  VIEW_SRCANCHORSHAPE, /**< shape of source arrow edge extremity */
73  VIEW_SRCANCHORSIZE, /**< size of source arrow edge extremity */
74  VIEW_TGTANCHORSHAPE, /**< shape of target arrow edge extremity */
75  VIEW_TGTANCHORSIZE, /**< size of target arrow edge extremity */
76  VIEW_ANIMATIONFRAME, /**< animation frame */
77  VIEW_FONTAWESOMEICON, /**< font awesome icon name for the font awesome icon glyph*/
78  VIEW_ICON, /**< icon name for the icon glyph*/
79  NB_PROPS /** must be the last, give the number of enum props */
80  };
81 
82  /**
83  * Create the inputData with Graph : graph and GlGraphRenderingParameters : parameters
84  */
85  GlGraphInputData(Graph* graph, GlGraphRenderingParameters* parameters,GlMetaNodeRenderer *renderer = NULL);
86 
87  ~GlGraphInputData();
88 
89  /**
90  * Return the graph of this inputData
91  */
92  Graph* getGraph() const {
93  return graph;
94  }
95 
96  void treatEvent(const Event &ev);
97 
98  /**
99  * Set metaNode renderer
100  * If deleteOldMetaNodeRenderer==true : this function delete old meta node renderer
101  */
102  void setMetaNodeRenderer(GlMetaNodeRenderer *renderer,bool deleteOldMetaNodeRenderer=true);
103 
104  /**
105  * Return metaNode renderer
106  */
107  GlMetaNodeRenderer *getMetaNodeRenderer() const {
108  return _metaNodeRenderer;
109  }
110 
111  /**
112  * Return glEdgeDisplayManager
113  */
114  GlVertexArrayManager *getGlVertexArrayManager() const {
115  return _glVertexArrayManager;
116  }
117 
118  GlGlyphRenderer *getGlGlyphRenderer() const {
119  return _glGlyphRenderer;
120  }
121 
122  /**
123  * Set glEdgeDisplayManager
124  */
125  void setGlVertexArrayManager(GlVertexArrayManager * manager) {
126  _glVertexArrayManager=manager;
127  }
128 
129  /**
130  * Function to get the PropertyInterface* corresponding
131  * to a given name
132  */
133  tlp::PropertyInterface* getProperty(const std::string& name) const {
134  std::map<std::string, PropertyName>::iterator it =
135  _propertiesNameMap.find(name);
136 
137  if (it != _propertiesNameMap.end())
138  return _propertiesMap[it->second];
139 
140  return NULL;
141  }
142 
143  /**
144  * Function to get the typed PropertyInterface* for a given propertyName
145  * See PropertyName enum for more details on available properties
146  */
147  template<typename T>
148  T* getProperty(PropertyName propertyName) const {
149  return static_cast<T*>(_propertiesMap[propertyName]);
150  }
151 
152  /**
153  * Function to set the PropertyInterface* for a given propertyName
154  * See PropertyName enum for more details on available properties
155  */
156  void setProperty(PropertyName propertyName, PropertyInterface *property) {
157  _properties.erase(_propertiesMap[propertyName]);
158  _propertiesMap[propertyName]=property;
159  _properties.insert(property);
160  }
161 
162  /**
163  * Function to set the PropertyInterface* for a given name
164  */
165  bool setProperty(const std::string& name, PropertyInterface *property);
166 
167  /**
168  * Function to set a bunch of named PropertyInterface*
169  */
170  bool installProperties(const std::map<std::string, tlp::PropertyInterface*>& propsMap);
171 
172  /**
173  * Return a pointer on the property used to elementColor
174  */
175  ColorProperty * getElementColor() const {
176  return getProperty<ColorProperty>(VIEW_COLOR);
177  }
178  /**
179  * Set the pointer on the property used to elementColor
180  */
181  void setElementColor(ColorProperty *property) {
182  setProperty(VIEW_COLOR,property);
183  }
184  /**
185  * Return a pointer on the property used to elementLabelColor
186  */
187  ColorProperty *getElementLabelColor() const {
188  return getProperty<ColorProperty>(VIEW_LABELCOLOR);
189  }
190  /**
191  * Set the pointer on the property used to elementLabelColor
192  */
193  void setElementLabelColor(ColorProperty *property) {
194  setProperty(VIEW_LABELCOLOR,property);
195  }
196  /**
197  * Return a pointer on the property used to elementLabelBorderColor
198  */
199  ColorProperty *getElementLabelBorderColor() const {
200  return getProperty<ColorProperty>(VIEW_LABELBORDERCOLOR);
201  }
202  /**
203  * Set the pointer on the property used to elementLabelBorderColor
204  */
205  void setElementLabelBorderColor(ColorProperty *property) {
206  setProperty(VIEW_LABELBORDERCOLOR,property);
207  }
208  /**
209  * Return a pointer on the property used to elementLabelBorderWidth
210  */
211  DoubleProperty *getElementLabelBorderWidth() const {
212  return getProperty<DoubleProperty>(VIEW_LABELBORDERWIDTH);
213  }
214  /**
215  * Set the pointer on the property used to elementLabelBorderColor
216  */
217  void setElementLabelBorderWidth(DoubleProperty *property) {
218  setProperty(VIEW_LABELBORDERWIDTH,property);
219  }
220  /**
221  * Return a pointer on the property used to elementSize
222  */
223  SizeProperty *getElementSize() const {
224  return getProperty<SizeProperty>(VIEW_SIZE);
225  }
226  /**
227  * Set the pointer on the property used to elementSize
228  */
229  void setElementSize(SizeProperty *property) {
230  setProperty(VIEW_SIZE,property);
231  }
232  /**
233  * Return a pointer on the property used to elementLabelPosition
234  */
235  IntegerProperty *getElementLabelPosition() const {
236  return getProperty<IntegerProperty>(VIEW_LABELPOSITION);
237  }
238  /**
239  * Set the pointer on the property used to elementLabelPosition
240  */
241  void setElementLabelPosition(IntegerProperty *property) {
242  setProperty(VIEW_LABELPOSITION,property);
243  }
244  /**
245  * Return a pointer on the property used to elementShape
246  */
247  IntegerProperty *getElementShape() const {
248  return getProperty<IntegerProperty>(VIEW_SHAPE);
249  }
250  /**
251  * Set the pointer on the property used to elementShape
252  */
253  void setElementShape(IntegerProperty *property) {
254  setProperty(VIEW_SHAPE,property);
255  }
256  /**
257  * Return a pointer on the property used to elementRotation
258  */
259  DoubleProperty *getElementRotation() const {
260  return getProperty<DoubleProperty>(VIEW_ROTATION);
261  }
262  /**
263  * Set the pointer on the property used to elementRotation
264  */
265  void setElementRotation(DoubleProperty *property) {
266  setProperty(VIEW_ROTATION,property);
267  }
268  /**
269  * Return a pointer on the property used to elementSelected
270  */
271  BooleanProperty *getElementSelected() const {
272  return getProperty<BooleanProperty>(VIEW_SELECTED);
273  }
274  /**
275  * Set the pointer on the property used to elementSelected
276  */
277  void setElementSelected(BooleanProperty *property) {
278  setProperty(VIEW_SELECTED,property);
279  }
280  /**
281  * Return a pointer on the property used to elementFont
282  */
283  StringProperty *getElementFont() const {
284  return getProperty<StringProperty>(VIEW_FONT);
285  }
286  /**
287  * Set the pointer on the property used to elementFont
288  */
289  void setElementFont(StringProperty *property) {
290  setProperty(VIEW_FONT,property);
291  }
292  /**
293  * Return a pointer on the property used to elementFontSize
294  */
295  IntegerProperty *getElementFontSize() const {
296  return getProperty<IntegerProperty>(VIEW_FONTSIZE);
297  }
298  /**
299  * Set the pointer on the property used to elementFontSize
300  */
301  void setElementFontSize(IntegerProperty *property) {
302  setProperty(VIEW_FONTSIZE,property);
303  }
304  /**
305  * Return a pointer on the property used to elementLabel
306  */
307  StringProperty *getElementLabel() const {
308  return getProperty<StringProperty>(VIEW_LABEL);
309  }
310  /**
311  * Set the pointer on the property used to elementLabel
312  */
313  void setElementLabel(StringProperty *property) {
314  setProperty(VIEW_LABEL,property);
315  }
316  /**
317  * Return a pointer on the property used to elementLayout
318  */
319  LayoutProperty *getElementLayout() const {
320  return getProperty<LayoutProperty>(VIEW_LAYOUT);
321  }
322  /**
323  * Set the pointer on the property used to elementLayout
324  */
325  void setElementLayout(LayoutProperty *property) {
326  setProperty(VIEW_LAYOUT,property);
327  }
328  /**
329  * Return a pointer on the property used to elementTexture
330  */
331  StringProperty *getElementTexture() const {
332  return getProperty<StringProperty>(VIEW_TEXTURE);
333  }
334  /**
335  * Set the pointer on the property used to elementTexture
336  */
337  void setElementTexture(StringProperty *property) {
338  setProperty(VIEW_TEXTURE,property);
339  }
340  /**
341  * Return a pointer on the property used to elementBorderColor
342  */
343  ColorProperty *getElementBorderColor() const {
344  return getProperty<ColorProperty>(VIEW_BORDERCOLOR);
345  }
346  /**
347  * Set the pointer on the property used to elementBorderColor
348  */
349  void setElementBorderColor(ColorProperty *property) {
350  setProperty(VIEW_BORDERCOLOR,property);
351  }
352  /**
353  * Return a pointer on the property used to elementBorderWidth
354  */
355  DoubleProperty *getElementBorderWidth() const {
356  return getProperty<DoubleProperty>(VIEW_BORDERWIDTH);
357  }
358  /**
359  * Set the pointer on the property used to elementBorderWidth
360  */
361  void setElementBorderWidth(DoubleProperty *property) {
362  setProperty(VIEW_BORDERWIDTH,property);
363  }
364  /**
365  * Return a pointer on the property used to elementSrcAnchorShape
366  */
367  IntegerProperty *getElementSrcAnchorShape() const {
368  return getProperty<IntegerProperty>(VIEW_SRCANCHORSHAPE);
369  }
370  /**
371  * Set the pointer on the property used to elementSrcAnchorShape
372  */
373  void setElementSrcAnchorShape(IntegerProperty *property) {
374  setProperty(VIEW_SRCANCHORSHAPE,property);
375  }
376  /**
377  * Return a pointer on the property used to elementSrcAnchorSize
378  */
379  SizeProperty *getElementSrcAnchorSize() const {
380  return getProperty<SizeProperty>(VIEW_SRCANCHORSIZE);
381  }
382  /**
383  * Set the pointer on the property used to elementSrcAnchorSize
384  */
385  void setElementSrcAnchorSize(SizeProperty *property) {
386  setProperty(VIEW_SRCANCHORSIZE,property);
387  }
388  /**
389  * Return a pointer on the property used to elementTgtAnchorShape
390  */
391  IntegerProperty *getElementTgtAnchorShape() const {
392  return getProperty<IntegerProperty>(VIEW_TGTANCHORSHAPE);
393  }
394  /**
395  * Set the pointer on the property used to elementTgtAnchorShape
396  */
397  void setElementTgtAnchorShape(IntegerProperty *property) {
398  setProperty(VIEW_TGTANCHORSHAPE,property);
399  }
400  /**
401  * Return a pointer on the property used to elementTgtAnchorSize
402  */
403  SizeProperty *getElementTgtAnchorSize() const {
404  return getProperty<SizeProperty>(VIEW_TGTANCHORSIZE);
405  }
406  /**
407  * Set the property name for elementSourceAnchorSize
408  */
409  void setElementTgtAnchorSize(SizeProperty *property) {
410  setProperty(VIEW_TGTANCHORSIZE,property);
411  }
412  /**
413  * Return a pointer on the property used to elementAnimationFrame
414  */
415  IntegerProperty *getElementAnimationFrame() const {
416  return getProperty<IntegerProperty>(VIEW_ANIMATIONFRAME);
417  }
418  /**
419  * Set the pointer on the property used to elementAnimationFrame
420  */
421  void setElementAnimationFrame(IntegerProperty *property) {
422  setProperty(VIEW_ANIMATIONFRAME,property);
423  }
424 
425  /**
426  * Return a pointer on the property used to elementFontAwesomeIcon
427  *
428  * @deprecated use getElementIcon() instead
429  */
430  _DEPRECATED StringProperty *getElementFontAwesomeIcon() const {
431  return getProperty<StringProperty>(VIEW_FONTAWESOMEICON);
432  }
433  /**
434  * Set the pointer on the property used to elementFontAwesomeIcon
435  *
436  * @deprecated use setElementIcon(StringProperty *property) instead
437  */
438  _DEPRECATED void setElementFontAwesomeIcon(StringProperty *property) {
439  setProperty(VIEW_FONTAWESOMEICON,property);
440  }
441 
442  /**
443  * Return a pointer on the property used to elementIcon
444  *
445  * @since Tulip 5.0
446  */
447  StringProperty *getElementIcon() const {
448  return getProperty<StringProperty>(VIEW_ICON);
449  }
450 
451  /**
452  * Set the pointer on the property used to elementIcon
453  *
454  * @since Tulip 5.0
455  */
456  void setElementIcon(StringProperty *property) {
457  setProperty(VIEW_ICON,property);
458  }
459 
460  std::set<tlp::PropertyInterface*> properties() const {
461  return _properties;
462  }
463 
464  /**
465  * @brief reloadGraphProperties restore the properties of the GlGraphInputData from the the graph.
466  */
467  void reloadGraphProperties();
468 
469  /**
470  * @brief renderingParameters return a pointer on the rendering parameters.
471  * @return
472  */
473  GlGraphRenderingParameters* renderingParameters()const {
474  return parameters;
475  }
476 
477  /**
478  * @brief setRenderingParameters set the pointer on the rendering parameters.
479  * @param newParameters
480  */
481  void setRenderingParameters(GlGraphRenderingParameters* newParameters) {
482  parameters = newParameters;
483  }
484 
485 public :
486 
487  Graph* graph;
488 
489  GlGraphRenderingParameters* parameters;
490 
491  MutableContainer<Glyph *> glyphs;
492  MutableContainer<EdgeExtremityGlyph *> extremityGlyphs;
493 
494 protected:
495 
496  std::set<PropertyInterface*> _properties;
497 
498  PropertyInterface* _propertiesMap[NB_PROPS];
499  static std::map<std::string,PropertyName> _propertiesNameMap;
500 
501  GlMetaNodeRenderer *_metaNodeRenderer;
502  GlVertexArrayManager *_glVertexArrayManager;
503  GlGlyphRenderer *_glGlyphRenderer;
504 
505 
506 };
507 }
508 
509 #endif
510 ///@endcond
PropertyInterface describes the interface of a graph property.
virtual void erase(const node)=0
Erases the value stored for the given node. The new value for the node is the default value...