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