8 #include "DocumentModelCoords.h" 9 #include "EngaugeAssert.h" 10 #include "EnumsToQt.h" 11 #include "GridLineFactory.h" 15 #include <QGraphicsItem> 16 #include <QGraphicsScene> 19 #include <QTextStream> 20 #include "QtToString.h" 21 #include "Transformation.h" 23 const int NUM_AXES_POINTS_2 = 2;
24 const int NUM_AXES_POINTS_3 = 3;
25 const int NUM_AXES_POINTS_4 = 4;
27 extern const QString DUMMY_CURVE_NAME;
32 const int CHECKER_POINTS_WIDTH = 5;
41 const QList<Point> &points,
46 LOG4CPP_INFO_S ((*mainCat)) <<
"Checker::adjustPolarAngleRanges transformation=" << transformation;
48 const double UNIT_LENGTH = 1.0;
51 if (modelCoords.
coordsType() == COORDS_TYPE_POLAR) {
56 path = QString (
"yMin=%1 ").arg (yMin);
60 double angle0 = points.at(0).posGraph().x();
61 double angle1 = points.at(1).posGraph().x();
62 double angle2 = points.at(2).posGraph().x();
64 QPointF (angle0, UNIT_LENGTH));
66 QPointF (angle1, UNIT_LENGTH));
68 QPointF (angle2, UNIT_LENGTH));
72 double sumAngle0 = angleBetweenVectors(pos0, pos1) + angleBetweenVectors(pos0, pos2);
73 double sumAngle1 = angleBetweenVectors(pos1, pos0) + angleBetweenVectors(pos1, pos2);
74 double sumAngle2 = angleBetweenVectors(pos2, pos0) + angleBetweenVectors(pos2, pos1);
75 if ((sumAngle0 <= sumAngle1) && (sumAngle0 <= sumAngle2)) {
78 if ((angleFromVectorToVector (pos0, pos1) < 0) ||
79 (angleFromVectorToVector (pos0, pos2) > 0)) {
80 path += QString (
"from 1=%1 through 0 to 2=%2").arg (angle1).arg (angle2);
84 path += QString (
"from 2=%1 through 0 to 1=%2").arg (angle2).arg (angle1);
88 }
else if ((sumAngle1 <= sumAngle0) && (sumAngle1 <= sumAngle2)) {
91 if ((angleFromVectorToVector (pos1, pos0) < 0) ||
92 (angleFromVectorToVector (pos1, pos2) > 0)) {
93 path += QString (
"from 0=%1 through 1 to 2=%2").arg (angle0).arg (angle2);
97 path += QString (
"from 2=%1 through 1 to 0=%2").arg (angle2).arg (angle0);
104 if ((angleFromVectorToVector (pos2, pos0) < 0) ||
105 (angleFromVectorToVector (pos2, pos1) > 0)) {
106 path += QString (
"from 0=%1 through 2 to 1=%2").arg (angle0).arg (angle1);
110 path += QString (
"from 1=%1 through 2 to 0=%2").arg (angle1).arg (angle0);
117 while (xMax < xMin) {
121 path += QString (
" xMax+=%1").arg (thetaPeriod);
127 LOG4CPP_INFO_S ((*mainCat)) <<
"Checker::adjustPolarAngleRanges path=(" << path.toLatin1().data() <<
")";
134 DocumentAxesPointsRequired documentAxesPointsRequired)
136 LOG4CPP_INFO_S ((*mainCat)) <<
"Checker::prepareForDisplay";
138 ENGAUGE_ASSERT ((polygon.count () == NUM_AXES_POINTS_2) ||
139 (polygon.count () == NUM_AXES_POINTS_3) ||
140 (polygon.count () == NUM_AXES_POINTS_4));
145 QPolygonF::const_iterator itr;
146 for (itr = polygon.begin (); itr != polygon.end (); itr++) {
148 const QPointF &pF = *itr;
150 Point p (DUMMY_CURVE_NAME,
154 points.push_back (p);
165 documentAxesPointsRequired);
173 DocumentAxesPointsRequired documentAxesPointsRequired)
175 LOG4CPP_INFO_S ((*mainCat)) <<
"Checker::prepareForDisplay " 176 <<
" transformation=" << transformation;
178 ENGAUGE_ASSERT ((points.count () == NUM_AXES_POINTS_2) ||
179 (points.count () == NUM_AXES_POINTS_3) ||
180 (points.count () == NUM_AXES_POINTS_4));
183 m_gridLines.
clear ();
185 bool fourPoints = (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_4);
188 double xFrom = 0, xTo = 0, yFrom = 0, yTo = 0;
192 for (i = 0; i < points.count(); i++) {
193 if (!fourPoints || (points.at(i).isXOnly() && fourPoints)) {
197 xFrom = points.at(i).posGraph().x();
198 xTo = points.at(i).posGraph().x();
201 xFrom = qMin (xFrom, points.at(i).posGraph().x());
202 xTo = qMax (xTo , points.at(i).posGraph().x());
206 if (!fourPoints || (!points.at(i).isXOnly() && fourPoints)) {
210 yFrom = points.at(i).posGraph().y();
211 yTo = points.at(i).posGraph().y();
214 yFrom = qMin (yFrom, points.at(i).posGraph().y());
215 yTo = qMax (yTo , points.at(i).posGraph().y());
222 adjustPolarAngleRanges (modelCoords,
234 m_gridLines.
add (factory.
createGridLine (xFrom, yFrom, xFrom, yTo , transformation));
235 m_gridLines.
add (factory.
createGridLine (xFrom, yTo , xTo , yTo , transformation));
236 m_gridLines.
add (factory.
createGridLine (xTo , yTo , xTo , yFrom, transformation));
237 m_gridLines.
add (factory.
createGridLine (xTo , yFrom, xFrom, yFrom, transformation));
249 QColor color = ColorPaletteToQColor (modelAxesChecker.
lineColor());
250 QPen pen (QBrush (color), CHECKER_POINTS_WIDTH);
Factory class for generating the points, composed of QGraphicsItem objects, along a GridLine...
void clear()
Deallocate and remove all grid lines.
void setPen(const QPen &pen)
Set the pen style of each grid line.
virtual void updateModelAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
Apply the new DocumentModelAxesChecker, to the points already associated with this object...
double thetaPeriod() const
Return the period of the theta value for polar coordinates, consistent with CoordThetaUnits.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
void prepareForDisplay(const QPolygonF &polygon, int pointRadius, const DocumentModelAxesChecker &modelAxesChecker, const DocumentModelCoords &modelCoords, DocumentAxesPointsRequired documentAxesPointsRequired)
Create the polygon from current information, including pixel coordinates, just prior to display...
ColorPalette lineColor() const
Get method for line color.
Model for DlgSettingsCoords and CmdSettingsCoords.
void setVisible(bool visible)
Make all grid lines visible or hidden.
Model for DlgSettingsAxesChecker and CmdSettingsAxesChecker.
CoordsType coordsType() const
Get method for coordinates type.
void add(GridLine *gridLine)
Add specified grid line. Ownership of all allocated QGraphicsItems is passed to new GridLine...
Checker(QGraphicsScene &scene)
Single constructor for DlgSettingsAxesChecker, which does not have an explicit transformation. The identity transformation is assumed.
void setVisible(bool visible)
Show/hide this axes checker.
double originRadius() const
Get method for origin radius in polar mode.
GridLine * createGridLine(double xFrom, double yFrom, double xTo, double yTo, const Transformation &transformation)
Create grid line, either along constant X/theta or constant Y/radius side.