7 #include "CallbackUpdateTransform.h"
9 #include "EngaugeAssert.h"
10 #include "FormatCoordsUnits.h"
15 #include "QtToString.h"
16 #include "Transformation.h"
22 const int PRECISION_DIGITS = 4;
24 const double PI = 3.1415926535;
25 const double ZERO_OFFSET_AFTER_LOG = 1;
28 m_transformIsDefined (false)
33 m_transformIsDefined (other.transformIsDefined()),
34 m_transform (other.transformMatrix())
59 const QPointF &posFrom1,
60 const QPointF &posFrom2,
61 const QPointF &posTo0,
62 const QPointF &posTo1,
63 const QPointF &posTo2)
65 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::calculateTransformFromLinearCartesianPoints";
68 from.setMatrix (posFrom0.x(), posFrom1.x(), posFrom2.x(),
69 posFrom0.y(), posFrom1.y(), posFrom2.y(),
72 to.setMatrix (posTo0.x(), posTo1.x(), posTo2.x(),
73 posTo0.y(), posTo1.y(), posTo2.y(),
75 QTransform fromInv = from.inverted ();
81 const QPointF &posGraphIn)
84 QPointF posGraphCartesian = posGraphIn;
86 if (modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
89 double angleRadians = 0;
92 case COORD_UNITS_POLAR_THETA_DEGREES:
93 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
94 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
95 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
96 angleRadians = posGraphIn.x () * PI / 180.0;
99 case COORD_UNITS_POLAR_THETA_GRADIANS:
100 angleRadians = posGraphIn.x () * PI / 200.0;
103 case COORD_UNITS_POLAR_THETA_RADIANS:
104 angleRadians = posGraphIn.x ();
107 case COORD_UNITS_POLAR_THETA_TURNS:
108 angleRadians = posGraphIn.x () * 2.0 * PI;
112 ENGAUGE_ASSERT (
false);
115 double radius = posGraphIn.y ();
116 posGraphCartesian.setX (radius * cos (angleRadians));
117 posGraphCartesian.setY (radius * sin (angleRadians));
120 return posGraphCartesian;
124 const QPointF &posGraphIn)
127 QPointF posGraphCartesianOrPolar = posGraphIn;
129 if (modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
132 double angleRadians = qAtan2 (posGraphIn.y (),
136 case COORD_UNITS_POLAR_THETA_DEGREES:
137 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
138 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
139 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
140 posGraphCartesianOrPolar.setX (angleRadians * 180.0 / PI);
143 case COORD_UNITS_POLAR_THETA_GRADIANS:
144 posGraphCartesianOrPolar.setX (angleRadians * 200.0 / PI);
147 case COORD_UNITS_POLAR_THETA_RADIANS:
148 posGraphCartesianOrPolar.setX (angleRadians);
151 case COORD_UNITS_POLAR_THETA_TURNS:
152 posGraphCartesianOrPolar.setX (angleRadians / 2.0 / PI);
156 ENGAUGE_ASSERT (
false);
159 double radius = qSqrt (posGraphIn.x () * posGraphIn.x () + posGraphIn.y () * posGraphIn.y ());
160 posGraphCartesianOrPolar.setY (radius);
163 return posGraphCartesianOrPolar;
167 QString &coordsScreen,
168 QString &coordsGraph,
169 QString &resolutionsGraph)
171 const int UNCONSTRAINED_FIELD_WIDTH = 0;
172 const double X_DELTA_PIXELS = 1.0, Y_DELTA_PIXELS = 1.0;
173 const char FORMAT =
'g';
175 if (cursorScreen.x() < 0 ||
176 cursorScreen.y() < 0) {
181 resolutionsGraph =
"";
185 coordsScreen = QString(
"(%1, %2)")
186 .arg (cursorScreen.x ())
187 .arg (cursorScreen.y ());
189 if (m_transformIsDefined) {
192 QPointF cursorScreenDelta (cursorScreen.x () + X_DELTA_PIXELS,
193 cursorScreen.y () + Y_DELTA_PIXELS);
196 QPointF pointGraph, pointGraphDelta;
203 double resolutionXGraph = qAbs ((pointGraphDelta.x () - pointGraph.x ()) / X_DELTA_PIXELS);
204 double resolutionYGraph = qAbs ((pointGraphDelta.y () - pointGraph.y ()) / Y_DELTA_PIXELS);
208 QString xThetaFormatted, yRadiusFormatted;
218 coordsGraph = QString (
"(%1, %2)")
219 .arg (xThetaFormatted)
220 .arg (yRadiusFormatted);
222 resolutionsGraph = QString (
"(%1, %2)")
223 .arg (resolutionXGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS)
224 .arg (resolutionYGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS);
228 coordsGraph =
"<font color=\"red\">Need more axis points</font>";
229 resolutionsGraph = coordsGraph;
238 m_transformIsDefined =
true;
252 return qLn (r) - qLn (rCenter);
257 return m_modelCoords;
262 return m_modelGeneral;
267 return m_modelMainWindow;
270 ostringstream &operator<<(ostringstream &strOuter,
274 QTextStream strInner (&text);
277 strOuter << text.toLatin1().data ();
283 QTextStream &str)
const
285 str <<
"Transformation\n";
287 indentation += INDENTATION_DELTA;
289 if (m_transformIsDefined) {
291 str << indentation <<
"affine=" << (m_transform.isAffine() ?
"yes" :
"no") <<
" matrix=("
292 << m_transform.m11() <<
", " << m_transform.m12() <<
", " << m_transform.m13() <<
", "
293 << m_transform.m21() <<
", " << m_transform.m22() <<
", " << m_transform.m23() <<
", "
294 << m_transform.m31() <<
", " << m_transform.m32() <<
", " << m_transform.m33() <<
")";
298 str << indentation <<
"undefined";
305 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::resetOnLoad";
307 m_transformIsDefined =
false;
310 double Transformation::roundOffSmallValues (
double value,
double range)
312 if (qAbs (value) < range / qPow (10.0, PRECISION_DIGITS)) {
330 return m_transformIsDefined;
334 QPointF &pointRawGraph)
const
339 pointRawGraph = pointLinearCartesianGraph;
342 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
348 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
350 pointRawGraph.setY (pointRawGraph.y() + m_modelCoords.
originRadius());
355 pointRawGraph.setX (qExp (pointRawGraph.x()));
360 if (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN) {
362 offset = ZERO_OFFSET_AFTER_LOG;
368 pointRawGraph.setY (qExp (pointRawGraph.y() + qLn (offset)));
373 QPointF &coordScreen)
const
375 ENGAUGE_ASSERT (m_transformIsDefined);
377 coordScreen = m_transform.inverted ().transposed ().map (coordGraph);
386 QPointF &pointLinearCartesian)
const
391 double x = pointRaw.x();
392 double y = pointRaw.y();
395 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
406 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
411 ZERO_OFFSET_AFTER_LOG);
416 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
423 pointLinearCartesian.setX (x);
424 pointLinearCartesian.setY (y);
428 QPointF &pointScreen)
const
430 QPointF pointLinearCartesianGraph;
433 pointLinearCartesianGraph);
439 QPointF &coordGraph)
const
441 ENGAUGE_ASSERT (m_transformIsDefined);
443 coordGraph = m_transform.transposed ().map (coordScreen);
447 QPointF &coordGraph)
const
449 QPointF pointLinearCartesianGraph;
451 pointLinearCartesianGraph);
460 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Transformation::update";
464 m_transformIsDefined =
false;
475 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
479 if (ftor.transformIsDefined ()) {
481 updateTransformFromMatrices (ftor.matrixScreen(),
485 m_transformIsDefined =
false;
491 void Transformation::updateTransformFromMatrices (
const QTransform &matrixScreen,
492 const QTransform &matrixGraph)
496 m_transformIsDefined =
true;
499 QPointF pointGraphRaw0 (matrixGraph.m11(),
501 QPointF pointGraphRaw1 (matrixGraph.m12(),
503 QPointF pointGraphRaw2 (matrixGraph.m13(),
506 QPointF pointGraphLinearCart0, pointGraphLinearCart1, pointGraphLinearCart2;
508 pointGraphLinearCart0);
510 pointGraphLinearCart1);
512 pointGraphLinearCart2);
516 QPointF (matrixScreen.m12(), matrixScreen.m22()),
517 QPointF (matrixScreen.m13(), matrixScreen.m23()),
518 QPointF (pointGraphLinearCart0.x(), pointGraphLinearCart0.y()),
519 QPointF (pointGraphLinearCart1.x(), pointGraphLinearCart1.y()),
520 QPointF (pointGraphLinearCart2.x(), pointGraphLinearCart2.y()));
523 QTransform matrixGraphLinear (pointGraphLinearCart0.x(),
524 pointGraphLinearCart1.x(),
525 pointGraphLinearCart2.x(),
526 pointGraphLinearCart0.y(),
527 pointGraphLinearCart1.y(),
528 pointGraphLinearCart2.y(),
532 QPointF pointScreenRoundTrip0, pointScreenRoundTrip1, pointScreenRoundTrip2;
534 pointScreenRoundTrip0);
536 pointScreenRoundTrip1);
538 pointScreenRoundTrip2);
540 QPointF pointScreen0 (matrixScreen.m11(),
542 QPointF pointScreen1 (matrixScreen.m12(),
544 QPointF pointScreen2 (matrixScreen.m13(),
547 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::updateTransformFromMatrices"
548 <<
" matrixScreen=\n" << QTransformToString (matrixScreen).toLatin1().data () <<
" "
549 <<
" matrixGraphRaw=\n" << QTransformToString (matrixGraph).toLatin1().data() <<
" "
550 <<
" matrixGraphLinear=\n" << QTransformToString (matrixGraphLinear).toLatin1().data() <<
"\n"
551 <<
" originalScreen0=" << QPointFToString (pointScreen0).toLatin1().data() <<
"\n"
552 <<
" originalScreen1=" << QPointFToString (pointScreen1).toLatin1().data() <<
"\n"
553 <<
" originalScreen2=" << QPointFToString (pointScreen2).toLatin1().data() <<
"\n"
554 <<
" roundTripScreen0=" << QPointFToString (pointScreenRoundTrip0).toLatin1().data() <<
"\n"
555 <<
" roundTripScreen1=" << QPointFToString (pointScreenRoundTrip1).toLatin1().data() <<
"\n"
556 <<
" roundTripScreen2=" << QPointFToString (pointScreenRoundTrip2).toLatin1().data() <<
"\n";
Model for DlgSettingsGeneral and CmdSettingsGeneral.
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double originRadius() const
Get method for origin radius in polar mode.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsMainWindow.
CoordsType coordsType() const
Get method for coordinates type.
Model for DlgSettingsCoords and CmdSettingsCoords.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.