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