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