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)
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;
87 if (modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
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;
130 if (modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
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)
172 const int UNCONSTRAINED_FIELD_WIDTH = 0;
173 const double X_DELTA_PIXELS = 1.0, Y_DELTA_PIXELS = 1.0;
174 const char FORMAT =
'g';
176 if (cursorScreen.x() < 0 ||
177 cursorScreen.y() < 0) {
182 resolutionsGraph =
"";
186 coordsScreen = QString(
"(%1, %2)")
187 .arg (cursorScreen.x ())
188 .arg (cursorScreen.y ());
190 if (m_transformIsDefined) {
193 QPointF cursorScreenDelta (cursorScreen.x () + X_DELTA_PIXELS,
194 cursorScreen.y () + Y_DELTA_PIXELS);
197 QPointF pointGraph, pointGraphDelta;
204 double resolutionXGraph = qAbs ((pointGraphDelta.x () - pointGraph.x ()) / X_DELTA_PIXELS);
205 double resolutionYGraph = qAbs ((pointGraphDelta.y () - pointGraph.y ()) / Y_DELTA_PIXELS);
209 QString xThetaFormatted, yRadiusFormatted;
219 coordsGraph = QString (
"(%1, %2)")
220 .arg (xThetaFormatted)
221 .arg (yRadiusFormatted);
223 resolutionsGraph = QString (
"(%1, %2)")
224 .arg (resolutionXGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS)
225 .arg (resolutionYGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS);
229 coordsGraph = QString (
"<font color=\"red\">%1</font>")
230 .arg (QObject::tr (
"Need more axis points"));
231 resolutionsGraph = coordsGraph;
240 m_transformIsDefined =
true;
254 return qLn (r) - qLn (rCenter);
259 return m_modelCoords;
264 return m_modelGeneral;
269 return m_modelMainWindow;
272 ostringstream &operator<<(ostringstream &strOuter,
276 QTextStream strInner (&text);
279 strOuter << text.toLatin1().data ();
285 QTextStream &str)
const 287 str <<
"Transformation\n";
289 indentation += INDENTATION_DELTA;
291 if (m_transformIsDefined) {
293 str << indentation <<
"affine=" << (m_transform.isAffine() ?
"yes" :
"no") <<
" matrix=(" 294 << m_transform.m11() <<
", " << m_transform.m12() <<
", " << m_transform.m13() <<
", " 295 << m_transform.m21() <<
", " << m_transform.m22() <<
", " << m_transform.m23() <<
", " 296 << m_transform.m31() <<
", " << m_transform.m32() <<
", " << m_transform.m33() <<
")";
300 str << indentation <<
"undefined";
307 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::resetOnLoad";
309 m_transformIsDefined =
false;
312 double Transformation::roundOffSmallValues (
double value,
double range)
314 if (qAbs (value) < range / qPow (10.0, PRECISION_DIGITS)) {
332 return m_transformIsDefined;
336 QPointF &pointRawGraph)
const 341 pointRawGraph = pointLinearCartesianGraph;
344 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
350 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
352 pointRawGraph.setY (pointRawGraph.y() + m_modelCoords.
originRadius());
357 pointRawGraph.setX (qExp (pointRawGraph.x()));
362 if (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN) {
364 offset = ZERO_OFFSET_AFTER_LOG;
370 pointRawGraph.setY (qExp (pointRawGraph.y() + qLn (offset)));
375 QPointF &coordScreen)
const 377 ENGAUGE_ASSERT (m_transformIsDefined);
379 coordScreen = m_transform.inverted ().transposed ().map (coordGraph);
388 QPointF &pointLinearCartesian)
const 393 double x = pointRaw.x();
394 double y = pointRaw.y();
397 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
408 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
413 ZERO_OFFSET_AFTER_LOG);
418 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
425 pointLinearCartesian.setX (x);
426 pointLinearCartesian.setY (y);
430 QPointF &pointScreen)
const 432 QPointF pointLinearCartesianGraph;
435 pointLinearCartesianGraph);
441 QPointF &coordGraph)
const 443 ENGAUGE_ASSERT (m_transformIsDefined);
445 coordGraph = m_transform.transposed ().map (coordScreen);
449 QPointF &coordGraph)
const 451 QPointF pointLinearCartesianGraph;
453 pointLinearCartesianGraph);
462 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Transformation::update";
466 m_transformIsDefined =
false;
477 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
481 if (ftor.transformIsDefined ()) {
483 updateTransformFromMatrices (ftor.matrixScreen(),
487 m_transformIsDefined =
false;
493 void Transformation::updateTransformFromMatrices (
const QTransform &matrixScreen,
494 const QTransform &matrixGraph)
498 m_transformIsDefined =
true;
501 QPointF pointGraphRaw0 (matrixGraph.m11(),
503 QPointF pointGraphRaw1 (matrixGraph.m12(),
505 QPointF pointGraphRaw2 (matrixGraph.m13(),
508 QPointF pointGraphLinearCart0, pointGraphLinearCart1, pointGraphLinearCart2;
510 pointGraphLinearCart0);
512 pointGraphLinearCart1);
514 pointGraphLinearCart2);
518 QPointF (matrixScreen.m12(), matrixScreen.m22()),
519 QPointF (matrixScreen.m13(), matrixScreen.m23()),
520 QPointF (pointGraphLinearCart0.x(), pointGraphLinearCart0.y()),
521 QPointF (pointGraphLinearCart1.x(), pointGraphLinearCart1.y()),
522 QPointF (pointGraphLinearCart2.x(), pointGraphLinearCart2.y()));
525 QTransform matrixGraphLinear (pointGraphLinearCart0.x(),
526 pointGraphLinearCart1.x(),
527 pointGraphLinearCart2.x(),
528 pointGraphLinearCart0.y(),
529 pointGraphLinearCart1.y(),
530 pointGraphLinearCart2.y(),
534 QPointF pointScreenRoundTrip0, pointScreenRoundTrip1, pointScreenRoundTrip2;
536 pointScreenRoundTrip0);
538 pointScreenRoundTrip1);
540 pointScreenRoundTrip2);
542 QPointF pointScreen0 (matrixScreen.m11(),
544 QPointF pointScreen1 (matrixScreen.m12(),
546 QPointF pointScreen2 (matrixScreen.m13(),
549 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::updateTransformFromMatrices" 550 <<
" matrixScreen=\n" << QTransformToString (matrixScreen).toLatin1().data () <<
" " 551 <<
" matrixGraphRaw=\n" << QTransformToString (matrixGraph).toLatin1().data() <<
" " 552 <<
" matrixGraphLinear=\n" << QTransformToString (matrixGraphLinear).toLatin1().data() <<
"\n" 553 <<
" originalScreen0=" << QPointFToString (pointScreen0).toLatin1().data() <<
"\n" 554 <<
" originalScreen1=" << QPointFToString (pointScreen1).toLatin1().data() <<
"\n" 555 <<
" originalScreen2=" << QPointFToString (pointScreen2).toLatin1().data() <<
"\n" 556 <<
" roundTripScreen0=" << QPointFToString (pointScreenRoundTrip0).toLatin1().data() <<
"\n" 557 <<
" roundTripScreen1=" << QPointFToString (pointScreenRoundTrip1).toLatin1().data() <<
"\n" 558 <<
" 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.