Engauge Digitizer  2
Transformation.h
1 #ifndef TRANSFORMATION_H
2 #define TRANSFORMATION_H
3 
4 #include "CmdMediator.h"
5 #include "DocumentModelCoords.h"
6 #include "MainWindowModel.h"
7 #include <QPointF>
8 #include <QString>
9 #include <QTransform>
10 
25 {
26  // For unit testing
27  friend class TestTransformation;
28 
29 public:
32 
35 
37  void identity();
38 
40  bool operator!=(const Transformation &other);
41 
48  static QTransform calculateTransformFromLinearCartesianPoints (const QPointF &posFrom0,
49  const QPointF &posFrom1,
50  const QPointF &posFrom2,
51  const QPointF &posTo0,
52  const QPointF &posTo1,
53  const QPointF &posTo2);
54 
57  const QPointF &posGraphIn);
58 
60  static QPointF cartesianOrPolarFromCartesian (const DocumentModelCoords &modelCoords,
61  const QPointF &posGraphIn);
62 
64  void coordTextForStatusBar (QPointF cursorScreen,
65  QString &coordsScreen,
66  QString &coordsGraph,
67  QString &resolutionGraph);
68 
70  static double logToLinearCartesian (double xy);
71 
73  static double logToLinearRadius (double r,
74  double rCenter);
75 
78 
80  void printStream (QString indentation,
81  QTextStream &str) const;
82 
84  void resetOnLoad();
85 
87  bool transformIsDefined() const { return m_transformIsDefined; }
88 
90  void transformLinearCartesianGraphToRawGraph (const QPointF &coordGraph,
91  QPointF &coordScreen) const;
92 
94  void transformLinearCartesianGraphToScreen (const QPointF &coordGraph,
95  QPointF &coordScreen) const;
96 
98  QTransform transformMatrix () const;
99 
101  void transformRawGraphToLinearCartesianGraph (const QPointF &pointRaw,
102  QPointF &pointLinearCartesian) const;
103 
105  void transformRawGraphToScreen (const QPointF &pointRaw,
106  QPointF &pointScreen) const;
107 
109  void transformScreenToLinearCartesianGraph (const QPointF &pointScreen,
110  QPointF &pointLinearCartesian) const;
111 
113  void transformScreenToRawGraph (const QPointF &coordScreen,
114  QPointF &coordGraph) const;
115 
117  void update (bool fileIsLoaded,
118  const CmdMediator &cmdMediator,
119  const MainWindowModel &modelMainWindow);
120 
121 private:
122 
123  // No need to display values like 1E-17 when it is insignificant relative to the range
124  double roundOffSmallValues (double value, double range);
125 
126  // Model coords are set upon entry from CmdMediator
127  void setModelCoords (const DocumentModelCoords &modelCoords,
128  const MainWindowModel &modelMainWindow);
129 
130  // Compute transform from screen and graph points. The 3x3 matrices are handled as QTransform since QMatrix is deprecated
131  void updateTransformFromMatrices (const QTransform &matrixScreen,
132  const QTransform &matrixGraph);
133 
134  // State variable
135  bool m_transformIsDefined;
136 
137  // Transform between cartesian screen coordinates and cartesian graph coordinates
138  QTransform m_transform;
139 
140  // Coordinates information from last time the transform was updated. Only defined if m_transformIsDefined is true
141  DocumentModelCoords m_modelCoords;
142 
143  // Formatting information
144  MainWindowModel m_modelMainWindow;
145 };
146 
148 const Transformation &operator<< (std::ostringstream &str,
149  const Transformation &transformation);
150 
151 #endif // TRANSFORMATION_H
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
void coordTextForStatusBar(QPointF cursorScreen, QString &coordsScreen, QString &coordsGraph, QString &resolutionGraph)
Return string descriptions of cursor coordinates for status bar.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
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...
void transformScreenToLinearCartesianGraph(const QPointF &pointScreen, QPointF &pointLinearCartesian) const
Transform screen coordinates to linear cartesian coordinates.
QTransform transformMatrix() const
Get method for copying only, for the transform matrix.
void transformLinearCartesianGraphToScreen(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian pixel screen coordinates.
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...
static double logToLinearCartesian(double xy)
Convert cartesian scaling from log to linear. Calling code is responsible for determining if this is ...
Unit test of transformation class. Checking mostly involves verifying forward/reverse are inverses of...
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Transformation & operator=(const Transformation &other)
Assignment operator.
Affine transformation between screen and graph coordinates, based on digitized axis points...
Model for DlgSettingsMainWindow and CmdSettingsMainWindow.
Model for DlgSettingsCoords and CmdSettingsCoords.
void transformLinearCartesianGraphToRawGraph(const QPointF &coordGraph, QPointF &coordScreen) const
Transform from linear cartesian graph coordinates to cartesian, polar, linear, log coordinates...
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.
Command queue stack.
Definition: CmdMediator.h:16
void identity()
Identity transformation.
void update(bool fileIsLoaded, const CmdMediator &cmdMediator, const MainWindowModel &modelMainWindow)
Update transform by iterating through the axis points.
void transformRawGraphToLinearCartesianGraph(const QPointF &pointRaw, QPointF &pointLinearCartesian) const
Convert graph coordinates (linear or log, cartesian or polar) to linear cartesian coordinates...
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...