Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 00020 00021 #ifndef GLAXIS_H_ 00022 #define GLAXIS_H_ 00023 00024 #include <tulip/GlComposite.h> 00025 #include <tulip/Color.h> 00026 00027 const float DEFAULT_GRAD_WIDTH = 6.; 00028 00029 const float MAGIG_FACTOR = (1.f / (1.3f)); 00030 00031 namespace tlp { 00032 00033 class GlLabel; 00034 00035 /** 00036 * @ingroup OpenGL 00037 * @brief A base class to draw an axis with graduations 00038 * 00039 * This class allow to render an axis with graduations. This class is there for code factorisation 00040 * and should not be used directly. Use derivated classes instead : GlQuantitativeAxis for a numerical 00041 * graduated axis and GlNominativeAxis for a string graduated axis 00042 */ 00043 class TLP_GL_SCOPE GlAxis : public GlComposite { 00044 00045 public : 00046 00047 enum AxisOrientation {HORIZONTAL_AXIS, VERTICAL_AXIS}; 00048 00049 enum LabelPosition {LEFT_OR_BELOW, RIGHT_OR_ABOVE}; 00050 enum CaptionLabelPosition {LEFT, RIGHT, BELOW, ABOVE}; 00051 00052 /** 00053 * @brief GlAxis constructor 00054 * 00055 * @param axisName the name of the axis 00056 * @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) 00057 * @param axisLength the length of the axis 00058 * @param axisOrientation the orientation of the axis, 2 possible values (HORIZONTAL_AXIS or VERTICAL_AXIS) 00059 * @param axisColor the color of the axis 00060 */ 00061 GlAxis(const std::string &axisName, const Coord &axisBaseCoord, const float axisLength, 00062 const AxisOrientation &axisOrientation, const Color &axisColor); 00063 00064 /** 00065 * @brief GlAxis destructor 00066 */ 00067 virtual ~GlAxis(); 00068 00069 /** 00070 * @brief Method which returns the base coordinates of the axis 00071 */ 00072 Coord getAxisBaseCoord() const { 00073 return axisBaseCoord; 00074 } 00075 /** 00076 * @brief Method which returns the length of the axis 00077 */ 00078 float getAxisLength() const { 00079 return axisLength; 00080 } 00081 /** 00082 * @brief Method which returns the name of the axis 00083 */ 00084 std::string getAxisName() const { 00085 return axisName; 00086 } 00087 /** 00088 * @brief Method which returns the orientation of the axis 00089 */ 00090 AxisOrientation getAxisOrientation() const { 00091 return axisOrientation; 00092 } 00093 /** 00094 * @brief Method which returns the width of the axis graduations 00095 */ 00096 float getAxisGradsWidth() const { 00097 return axisGradsWidth; 00098 } 00099 /** 00100 * @brief Method which returns the distance between the axis graduations 00101 */ 00102 float getSpaceBetweenAxisGrads() const { 00103 return spaceBetweenAxisGrads; 00104 } 00105 /** 00106 * @brief Method which returns the axis graduations labels height 00107 */ 00108 float getLabelHeight() const { 00109 return labelHeight; 00110 } 00111 00112 /** 00113 * @brief Method which returns the max axis graduations labels width 00114 */ 00115 float getMaxLabelWidth() const { 00116 return maxGraduationLabelWidth; 00117 } 00118 00119 /** 00120 * @brief Method which returns the color of the axis 00121 */ 00122 Color getAxisColor() const { 00123 return axisColor; 00124 } 00125 00126 /** 00127 * @brief Method to set the axis name 00128 */ 00129 void setAxisName(const std::string &axisName) { 00130 this->axisName = axisName; 00131 } 00132 /** 00133 * @brief Method to set the axis length 00134 */ 00135 void setAxisLength(const float axisLength) { 00136 this->axisLength = axisLength; 00137 } 00138 /** 00139 * @brief Method to set the axis color 00140 */ 00141 void setAxisColor(const Color &axisColor) { 00142 this->axisColor = axisColor; 00143 } 00144 /** 00145 * @brief Methods to set the axis graduations Width 00146 */ 00147 void setAxisGradsWidth(const float axisGradsWidth) { 00148 this->axisGradsWidth = axisGradsWidth; 00149 } 00150 00151 /** 00152 * @brief Methods to set the max caption width 00153 */ 00154 void setMaxCaptionWidth(const float maxCaptionWidth) { 00155 this->maxCaptionWidth = maxCaptionWidth; 00156 } 00157 00158 /** 00159 * @brief Method to update the axis drawing. 00160 * 00161 * It has to be called when one (ore more) of the setters methods above has been used 00162 * This method erase the whole axis drawing and redraw the axis line and the caption (if any) 00163 * The axis graduations have to be reset by calling setAxisGraduations 00164 */ 00165 virtual void updateAxis(); 00166 00167 /** 00168 * @brief Method to set the axis graduations. No need to call updateAxis after calling this method. 00169 * 00170 * @param axisGradsLabels the labels of the graduations, they will be equally spaced on the axis 00171 * @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 00172 * 00173 */ 00174 void setAxisGraduations(const std::vector<std::string> &axisGradsLabels, 00175 const LabelPosition &axisGradsLabelsPosition = LEFT_OR_BELOW); 00176 00177 00178 void setAxisGraduationsMaxLabelWidth(const float maxWidth) { 00179 maxGraduationLabelWidth = maxWidth; 00180 } 00181 00182 /** 00183 * @brief Method which adds a caption to the axis. No need to call updateAxis after calling this method. 00184 * 00185 * @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 00186 * @param captionHeight the caption text height 00187 * @param captionFrame if true the caption will be framed 00188 * @param maxCaptionWidth fill this parameter if you want to restrain the caption width 00189 * @param captionOffset fill this parameter if you want to fix the offset between the axis and the caption 00190 * @param caption if this parameter is filled, use this value as caption text, otherwise the caption text will be the axis name 00191 */ 00192 void addCaption(const CaptionLabelPosition &captionPos, const float captionHeight, const bool captionFrame = false, 00193 const float maxCaptionWidth = 0, const float captionOffset = 0, const std::string caption = ""); 00194 00195 /** 00196 * @brief Method to set the axis graduations labels size. 00197 * 00198 * This method can be used if you want axis with same labels size 00199 * 00200 * @param height the height for labels 00201 * 00202 */ 00203 void setGradsLabelsHeight(float height); 00204 00205 void translate(const Coord &c); 00206 00207 float getCaptionHeight() const; 00208 00209 void setCaptionHeight(float height, bool frame); 00210 00211 private : 00212 00213 void buildAxisLine(); 00214 00215 00216 protected : 00217 00218 void computeBoundingBox(); 00219 virtual Coord computeCaptionCenter(const bool captionFrame); 00220 virtual void computeCaptionSize(float height); 00221 void addAxisCaption(const Coord &captionLabelCenter, const bool captionFrame); 00222 00223 std::string axisName; 00224 Coord axisBaseCoord; 00225 float axisLength; 00226 AxisOrientation axisOrientation; 00227 LabelPosition axisGradsPosition; 00228 Color axisColor; 00229 float axisGradsWidth; 00230 float spaceBetweenAxisGrads; 00231 float captionWidth; 00232 float captionHeight; 00233 float baseCaptionHeight; 00234 bool captionFrame; 00235 std::string captionText; 00236 GlLabel *captionLabel; 00237 float labelHeight; 00238 float captionOffset; 00239 GlComposite *axisLinesComposite; 00240 GlComposite *captionComposite; 00241 GlComposite *gradsComposite; 00242 std::vector<GlLabel*> gradsLabelsVector; 00243 bool captionSet; 00244 CaptionLabelPosition captionPosition; 00245 float maxCaptionWidth; 00246 float maxGraduationLabelWidth; 00247 }; 00248 00249 } 00250 00251 #endif /* GLAXIS_H_ */