MorphoGraphX  2.0-1-227
ScaleBar.hpp
Go to the documentation of this file.
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  {
33  public:
35  enum Position { Top, Bottom, Left, Right, TopLeft, BottomLeft, TopRight, BottomRight, Center };
36 
37  enum Direction { Horizontal, Vertical };
38 
39  enum TextPosition { In, Out };
40 
41  ScaleBar();
42 
43  void setWantedSize(double ws)
44  {
45  if(ws > 0)
46  wantedSize = ws;
47  }
48 
49  void setScale(double s)
50  {
51  if(s > 0)
52  scale = s;
53  }
54 
55  void setUnit(QString u)
56  {
57  unit = u;
58  displayUnit = !u.isEmpty();
59  }
60 
61  // Specified the screen coordinate only for user defined
62  // sp is in normalized screen coordinates (i.e. between (0,0) and (1,1))
63  void setPosition(Position p) //, Point2d sp = Point2d())
64  {
65  pos = p;
66  }
67 
68  void setThickness(int th)
69  {
70  if(th < 1)
71  thickness = 1;
72  else
73  thickness = th;
74  }
75 
76  void setShiftBorder(const Point2u& pt) {
77  shiftBorder = pt;
78  }
79 
80  void setFont(const QFont& fnt) {
81  unit_font = fnt;
82  }
83 
84  void setFontSize(int size) {
85  fontSize = (size > 0) ? size : 0;
86  }
87 
88  void init(QGLViewer* viewer);
89  void draw(QGLViewer* viewer, QPaintDevice* device = 0);
90 
91  void readParms(Parms& parms, QString section);
92  void writeParms(QTextStream& pout, QString section);
93 
94  void scaleDrawing(double s);
95  void restoreScale();
96 
97  protected:
98  void findScale(double unit_size);
99  double wantedSize;
100  double scale;
101  QString unit;
105  QFont unit_font;
106  double thickness;
109  int fontSize;
110  bool autoScale, autoUnit;
111  double minSize, maxSize;
112 
113  double globalScale;
114 
115  // Saved positions
116  /*
117  * double savedWantedSize;
118  * double savedThickness;
119  * Point2u savedShiftBorder;
120  * int savedFontSize;
121  * double savedMinSize;
122  * double savedMaxSize;
123  */
124  };
125 }
126 #endif
mgx::ScaleBar::autoUnit
bool autoUnit
Definition: ScaleBar.hpp:110
mgx::ScaleBar::Position
Position
Definition: ScaleBar.hpp:35
mgx::ScaleBar::wantedSize
double wantedSize
Definition: ScaleBar.hpp:99
mgx::ScaleBar::globalScale
double globalScale
Definition: ScaleBar.hpp:113
mgx::ScaleBar::displayUnit
bool displayUnit
Definition: ScaleBar.hpp:102
mgx::ScaleBar::setShiftBorder
void setShiftBorder(const Point2u &pt)
Definition: ScaleBar.hpp:76
GL.hpp
mgx::ScaleBar::pos
Position pos
Definition: ScaleBar.hpp:103
mgx::ScaleBar::setFontSize
void setFontSize(int size)
Definition: ScaleBar.hpp:84
mgx::ScaleBar
Definition: ScaleBar.hpp:31
mgx::ScaleBar::setPosition
void setPosition(Position p)
Definition: ScaleBar.hpp:63
mgx::ScaleBar::dir
Direction dir
Definition: ScaleBar.hpp:104
mgx::ScaleBar::Point2u
Vector< 2, size_t > Point2u
Definition: ScaleBar.hpp:34
mgx::ScaleBar::scale
double scale
Definition: ScaleBar.hpp:100
mgx::ScaleBar::setScale
void setScale(double s)
Definition: ScaleBar.hpp:49
mgx::ScaleBar::TextPosition
TextPosition
Definition: ScaleBar.hpp:39
mgx::ScaleBar::unit
QString unit
Definition: ScaleBar.hpp:101
Geometry.hpp
mgx::Information::init
mgx_EXPORT void init(QMainWindow *wnd)
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::ScaleBar::setThickness
void setThickness(int th)
Definition: ScaleBar.hpp:68
mgx::ScaleBar::setUnit
void setUnit(QString u)
Definition: ScaleBar.hpp:55
mgx::ScaleBar::unit_font
QFont unit_font
Definition: ScaleBar.hpp:105
mgx::ScaleBar::shiftBorder
Point2u shiftBorder
Definition: ScaleBar.hpp:107
QGLViewer
Parms.hpp
mgx::ScaleBar::TopRight
@ TopRight
Definition: ScaleBar.hpp:35
mgx::ScaleBar::setFont
void setFont(const QFont &fnt)
Definition: ScaleBar.hpp:80
mgx::ScaleBar::Direction
Direction
Definition: ScaleBar.hpp:37
mgx::ScaleBar::minSize
double minSize
Definition: ScaleBar.hpp:111
mgx::ScaleBar::fontSize
int fontSize
Definition: ScaleBar.hpp:109
mgx::ScaleBar::thickness
double thickness
Definition: ScaleBar.hpp:106
mgx::Vector< 2, size_t >
mgx::ScaleBar::textPosition
TextPosition textPosition
Definition: ScaleBar.hpp:108
mgx::ScaleBar::setWantedSize
void setWantedSize(double ws)
Definition: ScaleBar.hpp:43
mgx::Parms
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:116