MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ScaleBar.hpp
1 #ifndef SCALEBAR_HPP
2 #define SCALEBAR_HPP
3 
4 #include <Config.hpp>
5 #include <GL.hpp>
6 
7 #include <Geometry.hpp>
8 #include <MGXViewer/qglviewer.h>
9 #include <Parms.hpp>
10 
11 #include <cmath>
12 #include <QColor>
13 #include <QFont>
14 #include <QString>
15 #include <string>
16 
17 class QTextStream;
18 
19 namespace mgx {
20 
21 class mgx_EXPORT ScaleBar {
22 public:
24  enum Position { Top, Bottom, Left, Right, TopLeft, BottomLeft, TopRight, BottomRight, Center };
25 
26  enum Direction { Horizontal, Vertical };
27 
28  enum TextPosition { In, Out };
29 
30  ScaleBar();
31 
32  void setWantedSize(double ws)
33  {
34  if(ws > 0)
35  wantedSize = ws;
36  }
37 
38  void setScale(double s)
39  {
40  if(s > 0)
41  scale = s;
42  }
43 
44  void setUnit(QString u)
45  {
46  unit = u;
47  displayUnit = !u.isEmpty();
48  }
49 
50  // Specified the screen coordinate only for user defined
51  // sp is in normalized screen coordinates (i.e. between (0,0) and (1,1))
52  void setPosition(Position p) //, Point2d sp = Point2d())
53  {
54  pos = p;
55  }
56 
57  void setThickness(int th)
58  {
59  if(th < 1)
60  thickness = 1;
61  else
62  thickness = th;
63  }
64 
65  void setShiftBorder(const Point2u& pt) {
66  shiftBorder = pt;
67  }
68 
69  void setFont(const QFont& fnt) {
70  unit_font = fnt;
71  }
72 
73  void setFontSize(int size) {
74  fontSize = (size > 0) ? size : 0;
75  }
76 
77  void init(QGLViewer* viewer);
78  void draw(QGLViewer* viewer, QPaintDevice* device = 0);
79 
80  void readParms(util::Parms& parms, QString section);
81  void writeParms(QTextStream& pout, QString section);
82 
83  void scaleDrawing(double s);
84  void restoreScale();
85 
86 protected:
87  void findScale(double unit_size);
88  double wantedSize;
89  double scale;
90  QString unit;
91  bool displayUnit;
92  Position pos;
93  Direction dir;
94  QFont unit_font;
95  double thickness;
96  Point2u shiftBorder;
97  TextPosition textPosition;
98  int fontSize;
99  bool autoScale, autoUnit;
100  double minSize, maxSize;
101 
102  double globalScale;
103 
104  // Saved positions
105  /*
106  * double savedWantedSize;
107  * double savedThickness;
108  * Point2u savedShiftBorder;
109  * int savedFontSize;
110  * double savedMinSize;
111  * double savedMaxSize;
112  */
113 };
114 } // namespace mgx
115 #endif // SCALEBAR_HPP
Defines the util::Parms class.
Common definitions and utilities for all geometry algorithms This file is shared by cuda...
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:105
Definition: ScaleBar.hpp:21