Tulip  5.2.0
Large graphs analysis and drawing
Glyph.h
1 /*
2  *
3  * This file is part of Tulip (http://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 GLYPH_H
22 #define GLYPH_H
23 
24 #ifndef DOXYGEN_NOTFOR_DEVEL
25 
26 #include <tulip/Plugin.h>
27 #include <tulip/Size.h>
28 #include <tulip/Coord.h>
29 #include <tulip/BoundingBox.h>
30 #include <tulip/PluginContext.h>
31 
32 namespace tlp {
33 
34 static const std::string GLYPH_CATEGORY = "Node shape";
35 
36 class Graph;
37 struct node;
38 class GlGraphInputData;
39 class GlRect;
40 
41 class GlyphContext : public PluginContext {
42 public:
43  GlGraphInputData *glGraphInputData;
44  ///
45  GlyphContext(Graph ** = nullptr, GlGraphInputData *glGraphInputData = nullptr, int = 5, int = 5)
46  : glGraphInputData(glGraphInputData) {}
47  ///
48  ~GlyphContext() override {}
49 };
50 //==========================================================
51 class TLP_GL_SCOPE Glyph : public tlp::Plugin {
52 public:
53  std::string category() const override {
54  return GLYPH_CATEGORY;
55  }
56  std::string icon() const override {
57  return ":/tulip/gui/icons/32/plugin_glyph.png";
58  }
59 
60  Glyph(const tlp::PluginContext *context);
61  ~Glyph() override;
62 
63  virtual std::string getGroup() const {
64  return "";
65  }
66 
67  virtual void getIncludeBoundingBox(BoundingBox &boundingBox, node) {
68  boundingBox[0] = Coord(-0.5, -0.5, -0.5);
69  boundingBox[1] = Coord(0.5, 0.5, 0.5);
70  }
71 
72  virtual void getTextBoundingBox(BoundingBox &boundingBox, node n) {
73  getIncludeBoundingBox(boundingBox, n);
74  }
75 
76  virtual void draw(node, float) = 0;
77  /*
78  * return a point where an edge coming from "from" can be attached
79  * by default, the point will be on the surface of the largest sphere contained
80  * inside the unit cube (before scaling).
81  */
82  virtual Coord getAnchor(const Coord &nodeCenter, const Coord &from, const Size &scale,
83  const double zRotation) const;
84 
85  /**
86  * Return if the Glyph render its label (return true) or if GlNode have to render label (return
87  * false)
88  */
89  virtual bool renderLabel() {
90  return false;
91  }
92 
93  /**
94  * Return if the Glyph supports shader rendering optimization (see GlNode.cpp)
95  */
96  virtual bool shaderSupported() const {
97  return true;
98  }
99 
100  /**
101  * draw a preconfigured GlRect in the screen plane
102  */
103  static void drawRectInScreenPlane(GlRect &rect, const Size &size, bool disableMasks);
104 
105  GlGraphInputData *glGraphInputData;
106 
107 protected:
108  /*
109  * called by public method getAnchor to actually compute the anchor point
110  * vector is coordinate of the point to anchor to, relative to nodecenter
111  * glyph size is (1,1,1)
112  * this is the method to redefine for each glyph where the default 'getAnchor' method
113  * is inapropriated
114  * Returned value is a vector to be applied to 'nodeCenter' in the public method
115  */
116  virtual Coord getAnchor(const Coord &vector) const;
117 };
118 //==========================================================
119 class TLP_GL_SCOPE NoShaderGlyph : public Glyph {
120 public:
121  NoShaderGlyph(const tlp::PluginContext *context = nullptr) : Glyph(context) {}
122  bool shaderSupported() const override {
123  return false;
124  }
125 };
126 }
127 
128 #define GLYPHINFORMATION(NAME, AUTHOR, DATE, INFO, RELEASE, ID) \
129  PLUGININFORMATION(NAME, AUTHOR, DATE, INFO, RELEASE, "") \
130  int id() const override { \
131  return ID; \
132  }
133 
134 #endif // DOXYGEN_NOTFOR_DEVEL
135 
136 #endif // GLYPH_H
137 ///@endcond
Contains runtime parameters for a plugin.
Definition: PluginContext.h:42
Top-level interface for plug-ins.
Definition: Plugin.h:85