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