Tulip  5.2.0
Large graphs analysis and drawing
GlAxis.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 
20 #ifndef GLAXIS_H_
21 #define GLAXIS_H_
22 
23 #include <tulip/GlComposite.h>
24 #include <tulip/Color.h>
25 
26 const float DEFAULT_GRAD_WIDTH = 6.;
27 
28 const float MAGIG_FACTOR = (1.f / (1.3f));
29 
30 namespace tlp {
31 
32 class GlLabel;
33 
34 /**
35  * @ingroup OpenGL
36  * @brief A base class to draw an axis with graduations
37  *
38  * This class allow to render an axis with graduations. This class is there for code factorisation
39  * and should not be used directly. Use derivated classes instead : GlQuantitativeAxis for a
40  * numerical
41  * graduated axis and GlNominativeAxis for a string graduated axis
42  */
43 class TLP_GL_SCOPE GlAxis : public GlComposite {
44 
45 public:
46  enum AxisOrientation { HORIZONTAL_AXIS, VERTICAL_AXIS };
47 
48  enum LabelPosition { LEFT_OR_BELOW, RIGHT_OR_ABOVE };
49  enum CaptionLabelPosition { LEFT, RIGHT, BELOW, ABOVE };
50 
51  /**
52  * @brief GlAxis constructor
53  *
54  * @param axisName the name of the axis
55  * @param axisBaseCoord the base coord of the axis (if the axis is horizontal, it is the the left
56  * end, if vertical it is the down end)
57  * @param axisLength the length of the axis
58  * @param axisOrientation the orientation of the axis, 2 possible values (HORIZONTAL_AXIS or
59  * VERTICAL_AXIS)
60  * @param axisColor the color of the axis
61  */
62  GlAxis(const std::string &axisName, const Coord &axisBaseCoord, const float axisLength,
63  const AxisOrientation &axisOrientation, const Color &axisColor);
64 
65  /**
66  * @brief GlAxis destructor
67  */
68  ~GlAxis() override;
69 
70  /**
71  * @brief Method which returns the base coordinates of the axis
72  */
73  Coord getAxisBaseCoord() const {
74  return axisBaseCoord;
75  }
76  /**
77  * @brief Method which returns the length of the axis
78  */
79  float getAxisLength() const {
80  return axisLength;
81  }
82  /**
83  * @brief Method which returns the name of the axis
84  */
85  std::string getAxisName() const {
86  return axisName;
87  }
88  /**
89  * @brief Method which returns the orientation of the axis
90  */
91  AxisOrientation getAxisOrientation() const {
92  return axisOrientation;
93  }
94  /**
95  * @brief Method which returns the width of the axis graduations
96  */
97  float getAxisGradsWidth() const {
98  return axisGradsWidth;
99  }
100  /**
101  * @brief Method which returns the distance between the axis graduations
102  */
103  float getSpaceBetweenAxisGrads() const {
104  return spaceBetweenAxisGrads;
105  }
106  /**
107  * @brief Method which returns the axis graduations labels height
108  */
109  float getLabelHeight() const {
110  return labelHeight;
111  }
112 
113  /**
114  * @brief Method which returns the max axis graduations labels width
115  */
116  float getMaxLabelWidth() const {
117  return maxGraduationLabelWidth;
118  }
119 
120  /**
121  * @brief Method which returns the color of the axis
122  */
123  Color getAxisColor() const {
124  return axisColor;
125  }
126 
127  /**
128  * @brief Method to set the axis name
129  */
130  void setAxisName(const std::string &axisName) {
131  this->axisName = axisName;
132  }
133  /**
134  * @brief Method to set the axis length
135  */
136  void setAxisLength(const float axisLength) {
137  this->axisLength = axisLength;
138  }
139  /**
140  * @brief Method to set the axis color
141  */
142  void setAxisColor(const Color &axisColor) {
143  this->axisColor = axisColor;
144  }
145  /**
146  * @brief Methods to set the axis graduations Width
147  */
148  void setAxisGradsWidth(const float axisGradsWidth) {
149  this->axisGradsWidth = axisGradsWidth;
150  }
151 
152  /**
153  * @brief Methods to set the max caption width
154  */
155  void setMaxCaptionWidth(const float maxCaptionWidth) {
156  this->maxCaptionWidth = maxCaptionWidth;
157  }
158 
159  /**
160  * @brief Method to update the axis drawing.
161  *
162  * It has to be called when one (ore more) of the setters methods above has been used
163  * This method erase the whole axis drawing and redraw the axis line and the caption (if any)
164  * The axis graduations have to be reset by calling setAxisGraduations
165  */
166  virtual void updateAxis();
167 
168  /**
169  * @brief Method to set the axis graduations. No need to call updateAxis after calling this
170  * method.
171  *
172  * @param axisGradsLabels the labels of the graduations, they will be equally spaced on the axis
173  * @param axisGradsLabelsPosition the relative position of the axis graduations label. Two
174  * possible values : LEFT_OR_BELOW (if the axis is horizontal, labels will be on the left of the
175  * axis, otherwise below) or RIGHT_OR_ABOVE
176  *
177  */
178  void setAxisGraduations(const std::vector<std::string> &axisGradsLabels,
179  const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW);
180 
181  void setAxisGraduationsMaxLabelWidth(const float maxWidth) {
182  maxGraduationLabelWidth = maxWidth;
183  }
184 
185  /**
186  * @brief Method which adds a caption to the axis. No need to call updateAxis after calling this
187  * method.
188  *
189  * @param captionPos the relative position of the caption. Two possible values : LEFT_OR_BELOW (if
190  * the axis is vertical, caption will be below of the axis, otherwise on the left) or
191  * RIGHT_OR_ABOVE
192  * @param captionHeight the caption text height
193  * @param captionFrame if true the caption will be framed
194  * @param maxCaptionWidth fill this parameter if you want to restrain the caption width
195  * @param captionOffset fill this parameter if you want to fix the offset between the axis and the
196  * caption
197  * @param caption if this parameter is filled, use this value as caption text, otherwise the
198  * caption text will be the axis name
199  */
200  void addCaption(const CaptionLabelPosition &captionPos, const float captionHeight,
201  const bool captionFrame = false, const float maxCaptionWidth = 0,
202  const float captionOffset = 0, const std::string caption = "");
203 
204  /**
205  * @brief Method to set the axis graduations labels size.
206  *
207  * This method can be used if you want axis with same labels size
208  *
209  * @param height the height for labels
210  *
211  */
212  void setGradsLabelsHeight(float height);
213 
214  void translate(const Coord &c) override;
215 
216  float getCaptionHeight() const;
217 
218  void setCaptionHeight(float height, bool frame);
219 
220 private:
221  void buildAxisLine();
222 
223 protected:
224  void computeBoundingBox();
225  virtual Coord computeCaptionCenter(const bool captionFrame);
226  virtual void computeCaptionSize(float height);
227  void addAxisCaption(const Coord &captionLabelCenter, const bool captionFrame);
228 
229  std::string axisName;
230  Coord axisBaseCoord;
231  float axisLength;
232  AxisOrientation axisOrientation;
233  LabelPosition axisGradsPosition;
234  Color axisColor;
235  float axisGradsWidth;
236  float spaceBetweenAxisGrads;
237  float captionWidth;
238  float captionHeight;
239  float baseCaptionHeight;
240  bool captionFrame;
241  std::string captionText;
242  GlLabel *captionLabel;
243  float labelHeight;
244  float captionOffset;
245  GlComposite *axisLinesComposite;
246  GlComposite *captionComposite;
247  GlComposite *gradsComposite;
248  std::vector<GlLabel *> gradsLabelsVector;
249  bool captionSet;
250  CaptionLabelPosition captionPosition;
251  float maxCaptionWidth;
252  float maxGraduationLabelWidth;
253 };
254 }
255 
256 #endif /* GLAXIS_H_ */
void setAxisName(const std::string &axisName)
Method to set the axis name.
Definition: GlAxis.h:130
float getSpaceBetweenAxisGrads() const
Method which returns the distance between the axis graduations.
Definition: GlAxis.h:103
void setAxisLength(const float axisLength)
Method to set the axis length.
Definition: GlAxis.h:136
std::string getAxisName() const
Method which returns the name of the axis.
Definition: GlAxis.h:85
void setAxisGradsWidth(const float axisGradsWidth)
Methods to set the axis graduations Width.
Definition: GlAxis.h:148
Create a label into Tulip 3D engine.
Definition: GlLabel.h:46
Color getAxisColor() const
Method which returns the color of the axis.
Definition: GlAxis.h:123
A base class to draw an axis with graduations.
Definition: GlAxis.h:43
float getAxisGradsWidth() const
Method which returns the width of the axis graduations.
Definition: GlAxis.h:97
float getAxisLength() const
Method which returns the length of the axis.
Definition: GlAxis.h:79
void setMaxCaptionWidth(const float maxCaptionWidth)
Methods to set the max caption width.
Definition: GlAxis.h:155
Coord getAxisBaseCoord() const
Method which returns the base coordinates of the axis.
Definition: GlAxis.h:73
GlSimpleEntity used to agregate other GlEntity.
Definition: GlComposite.h:39
AxisOrientation getAxisOrientation() const
Method which returns the orientation of the axis.
Definition: GlAxis.h:91
float getMaxLabelWidth() const
Method which returns the max axis graduations labels width.
Definition: GlAxis.h:116
float getLabelHeight() const
Method which returns the axis graduations labels height.
Definition: GlAxis.h:109
void setAxisColor(const Color &axisColor)
Method to set the axis color.
Definition: GlAxis.h:142