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