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