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