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