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