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,
171 const QString &needMoreText)
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 if (cursorScreen.x() < 0 ||
178 cursorScreen.y() < 0) {
183 resolutionsGraph =
"";
187 coordsScreen = QString(
"(%1, %2)")
188 .arg (cursorScreen.x ())
189 .arg (cursorScreen.y ());
191 if (m_transformIsDefined) {
194 QPointF cursorScreenDelta (cursorScreen.x () + X_DELTA_PIXELS,
195 cursorScreen.y () + Y_DELTA_PIXELS);
198 QPointF pointGraph, pointGraphDelta;
205 double resolutionXGraph = qAbs ((pointGraphDelta.x () - pointGraph.x ()) / X_DELTA_PIXELS);
206 double resolutionYGraph = qAbs ((pointGraphDelta.y () - pointGraph.y ()) / Y_DELTA_PIXELS);
210 QString xThetaFormatted, yRadiusFormatted;
220 coordsGraph = QString (
"(%1, %2)")
221 .arg (xThetaFormatted)
222 .arg (yRadiusFormatted);
224 resolutionsGraph = QString (
"(%1, %2)")
225 .arg (resolutionXGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS)
226 .arg (resolutionYGraph, UNCONSTRAINED_FIELD_WIDTH, FORMAT, PRECISION_DIGITS);
230 coordsGraph = QString (
"<font color=\"red\">%1</font>")
232 resolutionsGraph = coordsGraph;
241 m_transformIsDefined =
true;
255 return qLn (r) - qLn (rCenter);
260 return m_modelCoords;
265 return m_modelGeneral;
270 return m_modelMainWindow;
273 ostringstream &operator<<(ostringstream &strOuter,
277 QTextStream strInner (&text);
280 strOuter << text.toLatin1().data ();
286 QTextStream &str)
const 288 str <<
"Transformation\n";
290 indentation += INDENTATION_DELTA;
292 if (m_transformIsDefined) {
294 str << indentation <<
"affine=" << (m_transform.isAffine() ?
"yes" :
"no") <<
" matrix=(" 295 << m_transform.m11() <<
", " << m_transform.m12() <<
", " << m_transform.m13() <<
", " 296 << m_transform.m21() <<
", " << m_transform.m22() <<
", " << m_transform.m23() <<
", " 297 << m_transform.m31() <<
", " << m_transform.m32() <<
", " << m_transform.m33() <<
")";
301 str << indentation <<
"undefined";
308 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::resetOnLoad";
310 m_transformIsDefined =
false;
313 double Transformation::roundOffSmallValues (
double value,
double range)
315 if (qAbs (value) < range / qPow (10.0, PRECISION_DIGITS)) {
333 return m_transformIsDefined;
337 QPointF &pointRawGraph)
const 342 pointRawGraph = pointLinearCartesianGraph;
345 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
351 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
353 pointRawGraph.setY (pointRawGraph.y() + m_modelCoords.
originRadius());
358 pointRawGraph.setX (qExp (pointRawGraph.x()));
363 if (m_modelCoords.
coordsType() == COORDS_TYPE_CARTESIAN) {
365 offset = ZERO_OFFSET_AFTER_LOG;
371 pointRawGraph.setY (qExp (pointRawGraph.y() + qLn (offset)));
376 QPointF &coordScreen)
const 378 ENGAUGE_ASSERT (m_transformIsDefined);
380 coordScreen = m_transform.inverted ().transposed ().map (coordGraph);
389 QPointF &pointLinearCartesian)
const 394 double x = pointRaw.x();
395 double y = pointRaw.y();
398 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
409 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
414 ZERO_OFFSET_AFTER_LOG);
419 if (m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
426 pointLinearCartesian.setX (x);
427 pointLinearCartesian.setY (y);
431 QPointF &pointScreen)
const 433 QPointF pointLinearCartesianGraph;
436 pointLinearCartesianGraph);
442 QPointF &coordGraph)
const 444 ENGAUGE_ASSERT (m_transformIsDefined);
446 coordGraph = m_transform.transposed ().map (coordScreen);
450 QPointF &coordGraph)
const 452 QPointF pointLinearCartesianGraph;
454 pointLinearCartesianGraph);
463 LOG4CPP_DEBUG_S ((*mainCat)) <<
"Transformation::update";
467 m_transformIsDefined =
false;
478 Functor2wRet<const QString &, const Point&, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
482 if (ftor.transformIsDefined ()) {
484 updateTransformFromMatrices (ftor.matrixScreen(),
488 m_transformIsDefined =
false;
494 void Transformation::updateTransformFromMatrices (
const QTransform &matrixScreen,
495 const QTransform &matrixGraph)
499 m_transformIsDefined =
true;
502 QPointF pointGraphRaw0 (matrixGraph.m11(),
504 QPointF pointGraphRaw1 (matrixGraph.m12(),
506 QPointF pointGraphRaw2 (matrixGraph.m13(),
509 QPointF pointGraphLinearCart0, pointGraphLinearCart1, pointGraphLinearCart2;
511 pointGraphLinearCart0);
513 pointGraphLinearCart1);
515 pointGraphLinearCart2);
519 QPointF (matrixScreen.m12(), matrixScreen.m22()),
520 QPointF (matrixScreen.m13(), matrixScreen.m23()),
521 QPointF (pointGraphLinearCart0.x(), pointGraphLinearCart0.y()),
522 QPointF (pointGraphLinearCart1.x(), pointGraphLinearCart1.y()),
523 QPointF (pointGraphLinearCart2.x(), pointGraphLinearCart2.y()));
526 QTransform matrixGraphLinear (pointGraphLinearCart0.x(),
527 pointGraphLinearCart1.x(),
528 pointGraphLinearCart2.x(),
529 pointGraphLinearCart0.y(),
530 pointGraphLinearCart1.y(),
531 pointGraphLinearCart2.y(),
535 QPointF pointScreenRoundTrip0, pointScreenRoundTrip1, pointScreenRoundTrip2;
537 pointScreenRoundTrip0);
539 pointScreenRoundTrip1);
541 pointScreenRoundTrip2);
543 QPointF pointScreen0 (matrixScreen.m11(),
545 QPointF pointScreen1 (matrixScreen.m12(),
547 QPointF pointScreen2 (matrixScreen.m13(),
550 LOG4CPP_INFO_S ((*mainCat)) <<
"Transformation::updateTransformFromMatrices" 551 <<
" matrixScreen=\n" << QTransformToString (matrixScreen).toLatin1().data () <<
" " 552 <<
" matrixGraphRaw=\n" << QTransformToString (matrixGraph).toLatin1().data() <<
" " 553 <<
" matrixGraphLinear=\n" << QTransformToString (matrixGraphLinear).toLatin1().data() <<
"\n" 554 <<
" originalScreen0=" << QPointFToString (pointScreen0).toLatin1().data() <<
"\n" 555 <<
" originalScreen1=" << QPointFToString (pointScreen1).toLatin1().data() <<
"\n" 556 <<
" originalScreen2=" << QPointFToString (pointScreen2).toLatin1().data() <<
"\n" 557 <<
" roundTripScreen0=" << QPointFToString (pointScreenRoundTrip0).toLatin1().data() <<
"\n" 558 <<
" roundTripScreen1=" << QPointFToString (pointScreenRoundTrip1).toLatin1().data() <<
"\n" 559 <<
" 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.