Tulip  4.7.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
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  NB_PROPS /** must be the last, give the number of enum props */
79  };
80 
81  /**
82  * Create the inputData with Graph : graph and GlGraphRenderingParameters : parameters
83  */
84  GlGraphInputData(Graph* graph, GlGraphRenderingParameters* parameters,GlMetaNodeRenderer *renderer = NULL);
85 
86  ~GlGraphInputData();
87 
88  /**
89  * Return the graph of this inputData
90  */
91  Graph* getGraph() const {
92  return graph;
93  }
94 
95  void treatEvent(const Event &ev);
96 
97  /**
98  * Set metaNode renderer
99  * If deleteOldMetaNodeRenderer==true : this function delete old meta node renderer
100  */
101  void setMetaNodeRenderer(GlMetaNodeRenderer *renderer,bool deleteOldMetaNodeRenderer=true);
102 
103  /**
104  * Return metaNode renderer
105  */
106  GlMetaNodeRenderer *getMetaNodeRenderer() const {
107  return _metaNodeRenderer;
108  }
109 
110  /**
111  * Return glEdgeDisplayManager
112  */
113  GlVertexArrayManager *getGlVertexArrayManager() const {
114  return _glVertexArrayManager;
115  }
116 
117  GlGlyphRenderer *getGlGlyphRenderer() const {
118  return _glGlyphRenderer;
119  }
120 
121  /**
122  * Set glEdgeDisplayManager
123  */
124  void setGlVertexArrayManager(GlVertexArrayManager * manager) {
125  _glVertexArrayManager=manager;
126  }
127 
128  /**
129  * Function to get the PropertyInterface* corresponding
130  * to a given name
131  */
132  tlp::PropertyInterface* getProperty(const std::string& name) const {
133  std::map<std::string, PropertyName>::iterator it =
134  _propertiesNameMap.find(name);
135 
136  if (it != _propertiesNameMap.end())
137  return _propertiesMap[it->second];
138 
139  return NULL;
140  }
141 
142  /**
143  * Function to get the typed PropertyInterface* for a given propertyName
144  * See PropertyName enum for more details on available properties
145  */
146  template<typename T>
147  T* getProperty(PropertyName propertyName) const {
148  return static_cast<T*>(_propertiesMap[propertyName]);
149  }
150 
151  /**
152  * Function to set the PropertyInterface* for a given propertyName
153  * See PropertyName enum for more details on available properties
154  */
155  void setProperty(PropertyName propertyName, PropertyInterface *property) {
156  _properties.erase(_propertiesMap[propertyName]);
157  _propertiesMap[propertyName]=property;
158  _properties.insert(property);
159  }
160 
161  /**
162  * Function to set the PropertyInterface* for a given name
163  */
164  bool setProperty(const std::string& name, PropertyInterface *property);
165 
166  /**
167  * Function to set a bunch of named PropertyInterface*
168  */
169  bool installProperties(const std::map<std::string, tlp::PropertyInterface*>& propsMap);
170 
171  /**
172  * Return a pointer on the property used to elementColor
173  */
174  ColorProperty * getElementColor() const {
175  return getProperty<ColorProperty>(VIEW_COLOR);
176  }
177  /**
178  * Set the pointer on the property used to elementColor
179  */
180  void setElementColor(ColorProperty *property) {
181  setProperty(VIEW_COLOR,property);
182  }
183  /**
184  * Return a pointer on the property used to elementLabelColor
185  */
186  ColorProperty *getElementLabelColor() const {
187  return getProperty<ColorProperty>(VIEW_LABELCOLOR);
188  }
189  /**
190  * Set the pointer on the property used to elementLabelColor
191  */
192  void setElementLabelColor(ColorProperty *property) {
193  setProperty(VIEW_LABELCOLOR,property);
194  }
195  /**
196  * Return a pointer on the property used to elementLabelBorderColor
197  */
198  ColorProperty *getElementLabelBorderColor() const {
199  return getProperty<ColorProperty>(VIEW_LABELBORDERCOLOR);
200  }
201  /**
202  * Set the pointer on the property used to elementLabelBorderColor
203  */
204  void setElementLabelBorderColor(ColorProperty *property) {
205  setProperty(VIEW_LABELBORDERCOLOR,property);
206  }
207  /**
208  * Return a pointer on the property used to elementLabelBorderWidth
209  */
210  DoubleProperty *getElementLabelBorderWidth() const {
211  return getProperty<DoubleProperty>(VIEW_LABELBORDERWIDTH);
212  }
213  /**
214  * Set the pointer on the property used to elementLabelBorderColor
215  */
216  void setElementLabelBorderWidth(DoubleProperty *property) {
217  setProperty(VIEW_LABELBORDERWIDTH,property);
218  }
219  /**
220  * Return a pointer on the property used to elementSize
221  */
222  SizeProperty *getElementSize() const {
223  return getProperty<SizeProperty>(VIEW_SIZE);
224  }
225  /**
226  * Set the pointer on the property used to elementSize
227  */
228  void setElementSize(SizeProperty *property) {
229  setProperty(VIEW_SIZE,property);
230  }
231  /**
232  * Return a pointer on the property used to elementLabelPosition
233  */
234  IntegerProperty *getElementLabelPosition() const {
235  return getProperty<IntegerProperty>(VIEW_LABELPOSITION);
236  }
237  /**
238  * Set the pointer on the property used to elementLabelPosition
239  */
240  void setElementLabelPosition(IntegerProperty *property) {
241  setProperty(VIEW_LABELPOSITION,property);
242  }
243  /**
244  * Return a pointer on the property used to elementShape
245  */
246  IntegerProperty *getElementShape() const {
247  return getProperty<IntegerProperty>(VIEW_SHAPE);
248  }
249  /**
250  * Set the pointer on the property used to elementShape
251  */
252  void setElementShape(IntegerProperty *property) {
253  setProperty(VIEW_SHAPE,property);
254  }
255  /**
256  * Return a pointer on the property used to elementRotation
257  */
258  DoubleProperty *getElementRotation() const {
259  return getProperty<DoubleProperty>(VIEW_ROTATION);
260  }
261  /**
262  * Set the pointer on the property used to elementRotation
263  */
264  void setElementRotation(DoubleProperty *property) {
265  setProperty(VIEW_ROTATION,property);
266  }
267  /**
268  * Return a pointer on the property used to elementSelected
269  */
270  BooleanProperty *getElementSelected() const {
271  return getProperty<BooleanProperty>(VIEW_SELECTED);
272  }
273  /**
274  * Set the pointer on the property used to elementSelected
275  */
276  void setElementSelected(BooleanProperty *property) {
277  setProperty(VIEW_SELECTED,property);
278  }
279  /**
280  * Return a pointer on the property used to elementFont
281  */
282  StringProperty *getElementFont() const {
283  return getProperty<StringProperty>(VIEW_FONT);
284  }
285  /**
286  * Set the pointer on the property used to elementFont
287  */
288  void setElementFont(StringProperty *property) {
289  setProperty(VIEW_FONT,property);
290  }
291  /**
292  * Return a pointer on the property used to elementFontSize
293  */
294  IntegerProperty *getElementFontSize() const {
295  return getProperty<IntegerProperty>(VIEW_FONTSIZE);
296  }
297  /**
298  * Set the pointer on the property used to elementFontSize
299  */
300  void setElementFontSize(IntegerProperty *property) {
301  setProperty(VIEW_FONTSIZE,property);
302  }
303  /**
304  * Return a pointer on the property used to elementLabel
305  */
306  StringProperty *getElementLabel() const {
307  return getProperty<StringProperty>(VIEW_LABEL);
308  }
309  /**
310  * Set the pointer on the property used to elementLabel
311  */
312  void setElementLabel(StringProperty *property) {
313  setProperty(VIEW_LABEL,property);
314  }
315  /**
316  * Return a pointer on the property used to elementLayout
317  */
318  LayoutProperty *getElementLayout() const {
319  return getProperty<LayoutProperty>(VIEW_LAYOUT);
320  }
321  /**
322  * Set the pointer on the property used to elementLayout
323  */
324  void setElementLayout(LayoutProperty *property) {
325  setProperty(VIEW_LAYOUT,property);
326  }
327  /**
328  * Return a pointer on the property used to elementTexture
329  */
330  StringProperty *getElementTexture() const {
331  return getProperty<StringProperty>(VIEW_TEXTURE);
332  }
333  /**
334  * Set the pointer on the property used to elementTexture
335  */
336  void setElementTexture(StringProperty *property) {
337  setProperty(VIEW_TEXTURE,property);
338  }
339  /**
340  * Return a pointer on the property used to elementBorderColor
341  */
342  ColorProperty *getElementBorderColor() const {
343  return getProperty<ColorProperty>(VIEW_BORDERCOLOR);
344  }
345  /**
346  * Set the pointer on the property used to elementBorderColor
347  */
348  void setElementBorderColor(ColorProperty *property) {
349  setProperty(VIEW_BORDERCOLOR,property);
350  }
351  /**
352  * Return a pointer on the property used to elementBorderWidth
353  */
354  DoubleProperty *getElementBorderWidth() const {
355  return getProperty<DoubleProperty>(VIEW_BORDERWIDTH);
356  }
357  /**
358  * Set the pointer on the property used to elementBorderWidth
359  */
360  void setElementBorderWidth(DoubleProperty *property) {
361  setProperty(VIEW_BORDERWIDTH,property);
362  }
363  /**
364  * Return a pointer on the property used to elementSrcAnchorShape
365  */
366  IntegerProperty *getElementSrcAnchorShape() const {
367  return getProperty<IntegerProperty>(VIEW_SRCANCHORSHAPE);
368  }
369  /**
370  * Set the pointer on the property used to elementSrcAnchorShape
371  */
372  void setElementSrcAnchorShape(IntegerProperty *property) {
373  setProperty(VIEW_SRCANCHORSHAPE,property);
374  }
375  /**
376  * Return a pointer on the property used to elementSrcAnchorSize
377  */
378  SizeProperty *getElementSrcAnchorSize() const {
379  return getProperty<SizeProperty>(VIEW_SRCANCHORSIZE);
380  }
381  /**
382  * Set the pointer on the property used to elementSrcAnchorSize
383  */
384  void setElementSrcAnchorSize(SizeProperty *property) {
385  setProperty(VIEW_SRCANCHORSIZE,property);
386  }
387  /**
388  * Return a pointer on the property used to elementTgtAnchorShape
389  */
390  IntegerProperty *getElementTgtAnchorShape() const {
391  return getProperty<IntegerProperty>(VIEW_TGTANCHORSHAPE);
392  }
393  /**
394  * Set the pointer on the property used to elementTgtAnchorShape
395  */
396  void setElementTgtAnchorShape(IntegerProperty *property) {
397  setProperty(VIEW_TGTANCHORSHAPE,property);
398  }
399  /**
400  * Return a pointer on the property used to elementTgtAnchorSize
401  */
402  SizeProperty *getElementTgtAnchorSize() const {
403  return getProperty<SizeProperty>(VIEW_TGTANCHORSIZE);
404  }
405  /**
406  * Set the property name for elementSourceAnchorSize
407  */
408  void setElementTgtAnchorSize(SizeProperty *property) {
409  setProperty(VIEW_TGTANCHORSIZE,property);
410  }
411  /**
412  * Return a pointer on the property used to elementAnimationFrame
413  */
414  IntegerProperty *getElementAnimationFrame() const {
415  return getProperty<IntegerProperty>(VIEW_ANIMATIONFRAME);
416  }
417  /**
418  * Set the pointer on the property used to elementAnimationFrame
419  */
420  void setElementAnimationFrame(IntegerProperty *property) {
421  setProperty(VIEW_ANIMATIONFRAME,property);
422  }
423 
424  /**
425  * Return a pointer on the property used to elementFontAwesomeIcon
426  */
427  StringProperty *getElementFontAwesomeIcon() const {
428  return getProperty<StringProperty>(VIEW_FONTAWESOMEICON);
429  }
430  /**
431  * Set the pointer on the property used to elementFontAwesomeIcon
432  */
433  void setElementFontAwesomeIcon(StringProperty *property) {
434  setProperty(VIEW_FONTAWESOMEICON,property);
435  }
436 
437  std::set<tlp::PropertyInterface*> properties() const {
438  return _properties;
439  }
440 
441  /**
442  * @brief reloadGraphProperties restore the properties of the GlGraphInputData from the the graph.
443  */
444  void reloadGraphProperties();
445 
446  /**
447  * @brief renderingParameters return a pointer on the rendering parameters.
448  * @return
449  */
450  GlGraphRenderingParameters* renderingParameters()const {
451  return parameters;
452  }
453 
454  /**
455  * @brief setRenderingParameters set the pointer on the rendering parameters.
456  * @param newParameters
457  */
458  void setRenderingParameters(GlGraphRenderingParameters* newParameters) {
459  parameters = newParameters;
460  }
461 
462 public :
463 
464  Graph* graph;
465 
466  GlGraphRenderingParameters* parameters;
467 
468  MutableContainer<Glyph *> glyphs;
469  MutableContainer<EdgeExtremityGlyph *> extremityGlyphs;
470 
471 protected:
472 
473  std::set<PropertyInterface*> _properties;
474 
475  PropertyInterface* _propertiesMap[NB_PROPS];
476  static std::map<std::string,PropertyName> _propertiesNameMap;
477 
478  GlMetaNodeRenderer *_metaNodeRenderer;
479  GlVertexArrayManager *_glVertexArrayManager;
480  GlGlyphRenderer *_glGlyphRenderer;
481 
482 
483 };
484 }
485 
486 #endif
487 ///@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...