7 #include "CallbackUpdateTransform.h" 9 #include "EngaugeAssert.h" 10 #include "FormatCoordsUnits.h" 16 #include "QtToString.h" 17 #include "Transformation.h" 23 const int PRECISION_DIGITS = 4;
25 const double PI = 3.1415926535;
26 const double ZERO_OFFSET_AFTER_LOG = 1;
29 m_transformIsDefined (false)
34 m_transformIsDefined (other.transformIsDefined()),
35 m_transform (other.transformMatrix())
60 const QPointF &posFrom1,
61 const QPointF &posFrom2,
62 const QPointF &posTo0,
63 const QPointF &posTo1,
64 const QPointF &posTo2)
66 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::calculateTransformFromLinearCartesianPoints";
69 from.setMatrix (posFrom0.x(), posFrom1.x(), posFrom2.x(),
70 posFrom0.y(), posFrom1.y(), posFrom2.y(),
73 to.setMatrix (posTo0.x(), posTo1.x(), posTo2.x(),
74 posTo0.y(), posTo1.y(), posTo2.y(),
76 QTransform fromInv = from.inverted ();
82 const QPointF &posGraphIn)
85 QPointF posGraphCartesian = posGraphIn;
90 double angleRadians = 0;
93 case COORD_UNITS_POLAR_THETA_DEGREES:
94 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
95 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
96 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
97 angleRadians = posGraphIn.x () * PI / 180.0;
100 case COORD_UNITS_POLAR_THETA_GRADIANS:
101 angleRadians = posGraphIn.x () * PI / 200.0;
104 case COORD_UNITS_POLAR_THETA_RADIANS:
105 angleRadians = posGraphIn.x ();
108 case COORD_UNITS_POLAR_THETA_TURNS:
109 angleRadians = posGraphIn.x () * 2.0 * PI;
113 ENGAUGE_ASSERT (
false);
116 double radius = posGraphIn.y ();
117 posGraphCartesian.setX (radius * cos (angleRadians));
118 posGraphCartesian.setY (radius * sin (angleRadians));
121 return posGraphCartesian;
125 const QPointF &posGraphIn)
128 QPointF posGraphCartesianOrPolar = posGraphIn;
133 double angleRadians = qAtan2 (posGraphIn.y (),
137 case COORD_UNITS_POLAR_THETA_DEGREES:
138 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES:
139 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS:
140 case COORD_UNITS_POLAR_THETA_DEGREES_MINUTES_SECONDS_NSEW:
141 posGraphCartesianOrPolar.setX (angleRadians * 180.0 / PI);
144 case COORD_UNITS_POLAR_THETA_GRADIANS:
145 posGraphCartesianOrPolar.setX (angleRadians * 200.0 / PI);
148 case COORD_UNITS_POLAR_THETA_RADIANS:
149 posGraphCartesianOrPolar.setX (angleRadians);
152 case COORD_UNITS_POLAR_THETA_TURNS:
153 posGraphCartesianOrPolar.setX (angleRadians / 2.0 / PI);
157 ENGAUGE_ASSERT (
false);
160 double radius = qSqrt (posGraphIn.x () * posGraphIn.x () + posGraphIn.y () * posGraphIn.y ());
161 posGraphCartesianOrPolar.setY (radius);
164 return posGraphCartesianOrPolar;
168 QString &coordsScreen,
169 QString &coordsGraph,
170 QString &resolutionsGraph,
173 const int UNCONSTRAINED_FIELD_WIDTH = 0;
174 const double X_DELTA_PIXELS = 1.0, Y_DELTA_PIXELS = 1.0;
175 const char FORMAT =
'g';
177 QString needMoreText = (usingScaleBar ?
178 QObject::tr (
"Need scale bar") :
179 QObject::tr (
"Need more axis points"));
181 if (cursorScreen.x() < 0 ||
182 cursorScreen.y() < 0) {
187 resolutionsGraph =
"";
191 coordsScreen = QString(
"(%1, %2)")
192 .arg (cursorScreen.x ())
193 .arg (cursorScreen.y ());
195 if (m_transformIsDefined) {
198 QPointF cursorScreenDelta (cursorScreen.x () + X_DELTA_PIXELS,
199 cursorScreen.y () + Y_DELTA_PIXELS);
202 QPointF pointGraph, pointGraphDelta;
209 double resolutionXGraph = qAbs ((pointGraphDelta.x () - pointGraph.x ()) / X_DELTA_PIXELS);
210 double resolutionYGraph = qAbs ((pointGraphDelta.y () - pointGraph.y ()) / Y_DELTA_PIXELS);
214 QString xThetaFormatted, yRadiusFormatted;
224 coordsGraph = QString (
"(%1, %2)")
225 .arg (xThetaFormatted)
226 .arg (yRadiusFormatted);
228 resolutionsGraph = QString (
"(%1, %2)")
229 .arg (resolutionXGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS)
230 .arg (resolutionYGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS);
234 coordsGraph = QString (
"<font color=\"red\">%1</font>")
236 resolutionsGraph = coordsGraph;
245 m_transformIsDefined =
true;
259 return qLn (r) - qLn (rCenter);
264 return m_modelCoords;
269 return m_modelGeneral;
274 return m_modelMainWindow;
277 ostringstream &operator<<(ostringstream &strOuter,
281 QTextStream strInner (&text);
284 strOuter << text.toLatin1().data ();
290 QTextStream &str)
const 292 str <<
"Transformation\n";
294 indentation += INDENTATION_DELTA;
296 if (m_transformIsDefined) {
298 str << indentation <<
"affine=" << (m_transform.isAffine() ?
"yes" :
"no") <<
" matrix=(" 299 << m_transform.m11() <<
", " << m_transform.m12() <<
", " << m_transform.m13() <<
", " 300 << m_transform.m21() <<
", " << m_transform.m22() <<
", " << m_transform.m23() <<
", " 301 << m_transform.m31() <<
", " << m_transform.m32() <<
", " << m_transform.m33() <<
")";
305 str << indentation <<
"undefined";
312 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::resetOnLoad";
314 m_transformIsDefined =
false;
317 double Transformation::roundOffSmallValues (
double value,
double range)
319 if (qAbs (value) < range / qPow (10.0, PRECISION_DIGITS)) {
337 return m_transformIsDefined;
341 QPointF &pointRawGraph)
const 346 pointRawGraph = pointLinearCartesianGraph;
349 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
355 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
357 pointRawGraph.setY (pointRawGraph.y() + m_modelCoords.
originRadius());
362 pointRawGraph.setX (qExp (pointRawGraph.x()));
367 if (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN) {
369 offset = ZERO_OFFSET_AFTER_LOG;
375 pointRawGraph.setY (qExp (pointRawGraph.y() + qLn (offset)));
380 QPointF &coordScreen)
const 382 ENGAUGE_ASSERT (m_transformIsDefined);
384 coordScreen = m_transform.inverted ().transposed ().map (coordGraph);
393 QPointF &pointLinearCartesian)
const 398 double x = pointRaw.x();
399 double y = pointRaw.y();
402 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
413 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
418 ZERO_OFFSET_AFTER_LOG);
423 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
430 pointLinearCartesian.setX (x);
431 pointLinearCartesian.setY (y);
435 QPointF &pointScreen)
const 437 QPointF pointLinearCartesianGraph;
440 pointLinearCartesianGraph);
446 QPointF &coordGraph)
const 448 ENGAUGE_ASSERT (m_transformIsDefined);
450 coordGraph = m_transform.transposed ().map (coordScreen);
454 QPointF &coordGraph)
const 456 QPointF pointLinearCartesianGraph;
458 pointLinearCartesianGraph);
467 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Transformation::update";
471 m_transformIsDefined =
false;
482 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
486 if (ftor.transformIsDefined ()) {
488 updateTransformFromMatrices (ftor.matrixScreen(),
493 m_transformIsDefined =
false;
499 void Transformation::updateTransformFromMatrices (
const QTransform &matrixScreen,
500 const QTransform &matrixGraph)
504 m_transformIsDefined =
true;
507 QPointF pointGraphRaw0 (matrixGraph.m11(),
509 QPointF pointGraphRaw1 (matrixGraph.m12(),
511 QPointF pointGraphRaw2 (matrixGraph.m13(),
514 QPointF pointGraphLinearCart0, pointGraphLinearCart1, pointGraphLinearCart2;
516 pointGraphLinearCart0);
518 pointGraphLinearCart1);
520 pointGraphLinearCart2);
524 QPointF (matrixScreen.m12(), matrixScreen.m22()),
525 QPointF (matrixScreen.m13(), matrixScreen.m23()),
526 QPointF (pointGraphLinearCart0.x(), pointGraphLinearCart0.y()),
527 QPointF (pointGraphLinearCart1.x(), pointGraphLinearCart1.y()),
528 QPointF (pointGraphLinearCart2.x(), pointGraphLinearCart2.y()));
531 QTransform matrixGraphLinear (pointGraphLinearCart0.x(),
532 pointGraphLinearCart1.x(),
533 pointGraphLinearCart2.x(),
534 pointGraphLinearCart0.y(),
535 pointGraphLinearCart1.y(),
536 pointGraphLinearCart2.y(),
540 QPointF pointScreenRoundTrip0, pointScreenRoundTrip1, pointScreenRoundTrip2;
542 pointScreenRoundTrip0);
544 pointScreenRoundTrip1);
546 pointScreenRoundTrip2);
548 QPointF pointScreen0 (matrixScreen.m11(),
550 QPointF pointScreen1 (matrixScreen.m12(),
552 QPointF pointScreen2 (matrixScreen.m13(),
555 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::updateTransformFromMatrices" 556 <<
" matrixScreen=\n" << QTransformToString (matrixScreen).toLatin1().data () <<
" " 557 <<
" matrixGraphRaw=\n" << QTransformToString (matrixGraph).toLatin1().data() <<
" " 558 <<
" matrixGraphLinear=\n" << QTransformToString (matrixGraphLinear).toLatin1().data() <<
"\n" 559 <<
" originalScreen0=" << QPointFToString (pointScreen0).toLatin1().data() <<
"\n" 560 <<
" originalScreen1=" << QPointFToString (pointScreen1).toLatin1().data() <<
"\n" 561 <<
" originalScreen2=" << QPointFToString (pointScreen2).toLatin1().data() <<
"\n" 562 <<
" roundTripScreen0=" << QPointFToString (pointScreenRoundTrip0).toLatin1().data() <<
"\n" 563 <<
" roundTripScreen1=" << QPointFToString (pointScreenRoundTrip1).toLatin1().data() <<
"\n" 564 <<
" roundTripScreen2=" << QPointFToString (pointScreenRoundTrip2).toLatin1().data() <<
"\n";
Model for DlgSettingsGeneral and CmdSettingsGeneral.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
CoordUnitsPolarTheta coordUnitsTheta() const
Get method for theta unit.
Model for DlgSettingsMainWindow.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
CoordsType coordsType() const
Get method for coordinates type.
double originRadius() const
Get method for origin radius in polar mode.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.