Engauge Digitizer  2
Transformation.h
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #ifndef TRANSFORMATION_H
8 #define TRANSFORMATION_H
9 
10 #include "CmdMediator.h"
11 #include "DocumentModelCoords.h"
12 #include "DocumentModelGeneral.h"
13 #include "MainWindowModel.h"
14 #include <QPointF>
15 #include <QString>
16 #include <QTransform>
17 
32 {
33  // For unit testing
34  friend class TestExport;
35  friend class TestTransformation;
36 
37 public:
40 
42  Transformation (const Transformation &other);
43 
46 
48  void identity();
49 
51  bool operator!=(const Transformation &other);
52 
59  static QTransform calculateTransformFromLinearCartesianPoints (const QPointF &posFrom0,
60  const QPointF &posFrom1,
61  const QPointF &posFrom2,
62  const QPointF &posTo0,
63  const QPointF &posTo1,
64  const QPointF &posTo2);
65 
68  const QPointF &posGraphIn);
69 
71  static QPointF cartesianOrPolarFromCartesian (const DocumentModelCoords &modelCoords,
72  const QPointF &posGraphIn);
73 
75  void coordTextForStatusBar (QPointF cursorScreen,
76  QString &coordsScreen,
77  QString &coordsGraph,
78  QString &resolutionGraph,
79  const QString &needMoreText);
80 
82  static double logToLinearCartesian (double xy);
83 
85  static double logToLinearRadius (double r,
86  double rCenter);
87 
90 
93 
96 
98  void printStream (QString indentation,
99  QTextStream &str) const;
100 
102  void resetOnLoad();
103 
105  bool transformIsDefined() const;
106 
108  void transformLinearCartesianGraphToRawGraph (const QPointF &coordGraph,
109  QPointF &coordScreen) const;
110 
112  void transformLinearCartesianGraphToScreen (const QPointF &coordGraph,
113  QPointF &coordScreen) const;
114 
116  QTransform transformMatrix () const;
117 
119  void transformRawGraphToLinearCartesianGraph (const QPointF &pointRaw,
120  QPointF &pointLinearCartesian) const;
121 
123  void transformRawGraphToScreen (const QPointF &pointRaw,
124  QPointF &pointScreen) const;
125 
127  void transformScreenToLinearCartesianGraph (const QPointF &pointScreen,
128  QPointF &pointLinearCartesian) const;
129 
131  void transformScreenToRawGraph (const QPointF &coordScreen,
132  QPointF &coordGraph) const;
133 
135  void update (bool fileIsLoaded,
136  const CmdMediator &cmdMediator,
137  const MainWindowModel &modelMainWindow);
138 
139 private:
140 
141  // No need to display values like 1E-17 when it is insignificant relative to the range
142  double roundOffSmallValues (double value, double range);
143 
144  // Model coords are set upon entry from CmdMediator
145  void setModelCoords (const DocumentModelCoords &modelCoords,
146  const DocumentModelGeneral &modelGeneral,
147  const MainWindowModel &modelMainWindow);
148 
149  // Compute transform from screen and graph points. The 3x3 matrices are handled as QTransform since QMatrix is deprecated
150  void updateTransformFromMatrices (const QTransform &matrixScreen,
151  const QTransform &matrixGraph);
152 
153  // State variable
154  bool m_transformIsDefined;
155 
156  // Transform between cartesian screen coordinates and cartesian graph coordinates
157  QTransform m_transform;
158 
159  // Coordinates information from last time the transform was updated. Only defined if m_transformIsDefined is true
160  DocumentModelCoords m_modelCoords;
161 
162  // General settings
163  DocumentModelGeneral m_modelGeneral;
164 
165  // Formatting information
166  MainWindowModel m_modelMainWindow;
167 };
168 
170 std::ostringstream &operator<< (std::ostringstream &str,
171  const Transformation &transformation);
172 
173 #endif // TRANSFORMATION_H
Model for DlgSettingsGeneral and CmdSettingsGeneral.
static QPointF cartesianFromCartesianOrPolar(const DocumentModelCoords &modelCoords, const QPointF &posGraphIn)
Output cartesian coordinates from input cartesian or polar coordinates. This is static for easier use...
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded...
static QTransform calculateTransformFromLinearCartesianPoints(const QPointF &posFrom0, const QPointF &posFrom1, const QPointF &posFrom2, const QPointF &posTo0, const QPointF &posTo1, const QPointF &posTo2)
Calculate QTransform using from/to points that have already been adjusted for, when applicable...
MainWindowModel modelMainWindow() const
Get method for MainWindowModel.
bool operator!=(const Transformation &other)
Inequality operator. This is marked as defined.
static QPointF cartesianOrPolarFromCartesian(const DocumentModelCoords &modelCoords, const QPointF &posGraphIn)
Output cartesian or polar coordinates from input cartesian coordinates. This is static for easier use...
static double logToLinearRadius(double r, double rCenter)
Convert radius scaling from log to linear. Calling code is responsible for determining if this is nec...
Transformation()
Default constructor. This is marked as undefined until the proper number of axis points are added...
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Unit test of Export classes.
Definition: TestExport.h:15
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
static double logToLinearCartesian(double xy)
Convert cartesian scaling from log to linear. Calling code is responsible for determining if this is ...
void transformLinearCartesianGraphToScreen(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian pixel screen coordinates.
Unit test of transformation class. Checking mostly involves verifying forward/reverse are inverses of...
Transformation & operator=(const Transformation &other)
Assignment operator.
Affine transformation between screen and graph coordinates, based on digitized axis points...
void coordTextForStatusBar(QPointF cursorScreen, QString &coordsScreen, QString &coordsGraph, QString &resolutionGraph, const QString &needMoreText)
Return string descriptions of cursor coordinates for status bar.
void transformLinearCartesianGraphToRawGraph(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian, polar, linear, log coordinates...
Model for DlgSettingsMainWindow.
Model for DlgSettingsCoords and CmdSettingsCoords.
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
Command queue stack.
Definition: CmdMediator.h:23
void identity()
Identity transformation.
void update(bool fileIsLoaded, const CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow)
Update transform by iterating through the axis points.
void transformScreenToLinearCartesianGraph(const QPointF &pointScreen, QPointF &pointLinearCartesian) const
Transform screen coordinates to linear cartesian coordinates.
void transformRawGraphToLinearCartesianGraph(const QPointF &pointRaw, QPointF &pointLinearCartesian) const
Convert graph coordinates (linear or log, cartesian or polar) to linear cartesian coordinates...
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
QTransform transformMatrix() const
Get method for copying only, for the transform matrix.