7 #include "DocumentModelCoords.h"
8 #include "DocumentModelGridDisplay.h"
9 #include "EngaugeAssert.h"
10 #include "EnumsToQt.h"
11 #include "GraphicsArcItem.h"
12 #include "GridLineFactory.h"
13 #include "GridLines.h"
14 #include "GridLineStyle.h"
16 #include <QGraphicsScene>
18 #include <QTextStream>
19 #include "QtToString.h"
20 #include "Transformation.h"
22 const int Z_VALUE_IN_FRONT = 100;
25 const double CHECKER_OPACITY = 0.6;
27 const double PI = 3.1415926535;
28 const double TWO_PI = 2.0 * PI;
29 const double DEGREES_TO_RADIANS = PI / 180.0;
30 const double RADIANS_TO_TICS = 5760 / TWO_PI;
37 m_modelCoords (modelCoords),
38 m_transformation (transformation),
41 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::GridLineFactory"
42 <<
" transformation=" << transformation;
47 const QList<Point> &pointsToIsolate,
51 m_pointRadius (pointRadius),
52 m_pointsToIsolate (pointsToIsolate),
53 m_modelCoords (modelCoords),
54 m_transformation (transformation),
57 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::GridLineFactory"
58 <<
" pointRadius=" << pointRadius
59 <<
" pointsToIsolate=" << pointsToIsolate.count()
60 <<
" transformation=" << transformation;
63 void GridLineFactory::bindItemToScene(QGraphicsItem *item)
const
65 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::bindItemToScene";
67 item->setOpacity (CHECKER_OPACITY);
68 item->setZValue (Z_VALUE_IN_FRONT);
70 item->setToolTip (QObject::tr (
"Axes checker. If this does not align with the axes, then the axes points should be checked"));
73 m_scene.addItem (item);
81 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::createGridLine"
98 const int NUM_STEPS = 1000;
100 bool stateSegmentIsActive =
false;
101 QPointF posStartScreen (0, 0);
104 for (
int i = 0; i <= NUM_STEPS; i++) {
106 double s = (double) i / (
double) NUM_STEPS;
109 double xGraph = (1.0 - s) * xFrom + s * xTo;
110 double yGraph = (1.0 - s) * yFrom + s * yTo;
114 xGraph = qExp ((1.0 - s) * qLn (xFrom) + s * qLn (xTo));
117 yGraph = qExp ((1.0 - s) * qLn (yFrom) + s * qLn (yTo));
124 double distanceToNearestPoint = minScreenDistanceFromPoints (pointScreen);
125 if ((distanceToNearestPoint < m_pointRadius) ||
129 if (stateSegmentIsActive) {
132 finishActiveGridLine (posStartScreen,
137 stateSegmentIsActive =
false;
143 if (!stateSegmentIsActive) {
146 stateSegmentIsActive =
true;
147 posStartScreen = pointScreen;
163 modelGridDisplay.
stable()) {
165 double startX = modelGridDisplay.
startX ();
166 double startY = modelGridDisplay.
startY ();
167 double stepX = modelGridDisplay.
stepX ();
168 double stepY = modelGridDisplay.
stepY ();
169 double stopX = modelGridDisplay.
stopX ();
170 double stopY = modelGridDisplay.
stopY ();
175 QColor color (ColorPaletteToQColor (modelGridDisplay.
paletteColor()));
176 QPen pen (QPen (color,
181 for (
double x = startX; x <= stopX; (isLinearX ? x += stepX : x *= stepX)) {
185 gridLines.
add (gridLine);
189 for (
double y = startY; y <= stopY; (isLinearY ? y += stepY : y *= stepY)) {
193 gridLines.
add (gridLine);
199 void GridLineFactory::createTransformAlign (
const Transformation &transformation,
200 double radiusLinearCartesian,
201 const QPointF &posOriginScreen,
202 QTransform &transformAlign,
203 double &ellipseXAxis,
204 double &ellipseYAxis)
const
217 QPointF posXRadiusY0Graph (radiusLinearCartesian, 0), posX0YRadiusGraph (0, radiusLinearCartesian);
218 QPointF posXRadiusY0Screen, posX0YRadiusScreen;
225 QPointF deltaXRadiusY0 = posXRadiusY0Screen - posOriginScreen;
226 QPointF deltaX0YRadius = posX0YRadiusScreen - posOriginScreen;
227 ellipseXAxis = qSqrt (deltaXRadiusY0.x () * deltaXRadiusY0.x () +
228 deltaXRadiusY0.y () * deltaXRadiusY0.y ());
229 ellipseYAxis = qSqrt (deltaX0YRadius.x () * deltaX0YRadius.x () +
230 deltaX0YRadius.y () * deltaX0YRadius.y ());
233 QPointF posXRadiusY0AlignedScreen (posOriginScreen.x() + ellipseXAxis, posOriginScreen.y());
234 QPointF posX0YRadiusAlignedScreen (posOriginScreen.x(), posOriginScreen.y() - ellipseYAxis);
240 posXRadiusY0AlignedScreen,
241 posX0YRadiusAlignedScreen);
243 LOG4CPP_INFO_S ((*mainCat)) <<
"GridLineFactory::createTransformAlign"
244 <<
" transformation=" << QTransformToString (transformation.
transformMatrix()).toLatin1().data() << endl
245 <<
" radiusLinearCartesian=" << radiusLinearCartesian
246 <<
" posXRadiusY0Screen=" << QPointFToString (posXRadiusY0Screen).toLatin1().data()
247 <<
" posX0YRadiusScreen=" << QPointFToString (posX0YRadiusScreen).toLatin1().data()
248 <<
" ellipseXAxis=" << ellipseXAxis
249 <<
" ellipseYAxis=" << ellipseYAxis
250 <<
" posXRadiusY0AlignedScreen=" << QPointFToString (posXRadiusY0AlignedScreen).toLatin1().data()
251 <<
" posX0YRadiusAlignedScreen=" << QPointFToString (posX0YRadiusAlignedScreen).toLatin1().data()
252 <<
" transformAlign=" << QTransformToString (transformAlign).toLatin1().data();
255 QGraphicsItem *GridLineFactory::ellipseItem (
const Transformation &transformation,
256 double radiusLinearCartesian,
257 const QPointF &posStartScreen,
258 const QPointF &posEndScreen)
const
262 QPointF posStartGraph, posEndGraph;
270 double angleStart = posStartGraph.x() * DEGREES_TO_RADIANS;
271 double angleEnd = posEndGraph.x() * DEGREES_TO_RADIANS;
272 if (angleEnd < angleStart) {
275 double angleSpan = angleEnd - angleStart;
278 QPointF posOriginGraph (0, 0), posOriginScreen;
282 LOG4CPP_INFO_S ((*mainCat)) <<
"GridLineFactory::ellipseItem"
283 <<
" radiusLinearCartesian=" << radiusLinearCartesian
284 <<
" posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
285 <<
" posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
286 <<
" posOriginScreen=" << QPointFToString (posOriginScreen).toLatin1().data()
287 <<
" angleStart=" << angleStart / DEGREES_TO_RADIANS
288 <<
" angleEnd=" << angleEnd / DEGREES_TO_RADIANS
289 <<
" transformation=" << transformation;
294 double ellipseXAxis, ellipseYAxis;
295 QTransform transformAlign;
296 createTransformAlign (transformation,
297 radiusLinearCartesian,
304 QRectF boundingRect (-1.0 * ellipseXAxis + posOriginScreen.x(),
305 -1.0 * ellipseYAxis + posOriginScreen.y(),
309 item->setStartAngle (angleStart * RADIANS_TO_TICS);
310 item->setSpanAngle (angleSpan * RADIANS_TO_TICS);
312 item->setTransform (transformAlign.transposed ().inverted ());
317 void GridLineFactory::finishActiveGridLine (
const QPointF &posStartScreen,
318 const QPointF &posEndScreen,
323 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::finishActiveGridLine"
324 <<
" posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
325 <<
" posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
326 <<
" yFrom=" << yFrom
330 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
334 double radiusLinearCartesian = yFrom;
343 item = ellipseItem (m_transformation,
344 radiusLinearCartesian,
351 item = lineItem (posStartScreen,
356 bindItemToScene (item);
359 QGraphicsItem *GridLineFactory::lineItem (
const QPointF &posStartScreen,
360 const QPointF &posEndScreen)
const
362 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::lineItem"
363 <<
" posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
364 <<
" posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data();
366 return new QGraphicsLineItem (QLineF (posStartScreen,
370 double GridLineFactory::minScreenDistanceFromPoints (
const QPointF &posScreen)
372 double minDistance = 0;
373 for (
int i = 0; i < m_pointsToIsolate.count (); i++) {
374 const Point &pointCenter = m_pointsToIsolate.at (i);
376 double dx = posScreen.x() - pointCenter.
posScreen().x();
377 double dy = posScreen.y() - pointCenter.
posScreen().y();
379 double distance = qSqrt (dx * dx + dy * dy);
380 if (i == 0 || distance < minDistance) {
381 minDistance = distance;
double stopX() const
Get method for x grid line upper bound (inclusive).
double stepX() const
Get method for x grid line increment.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
GridLine * createGridLine(double xFrom, double yFrom, double xTo, double yTo)
Create grid line, either along constant X/theta or constant Y/radius side.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double originRadius() const
Get method for origin radius in polar mode.
Draw an arc as an ellipse but without lines from the center to the start and end points.
void createGridLinesForEvenlySpacedGrid(const DocumentModelGridDisplay &modelGridDisplay, GridLines &gridLines)
Create a rectangular (cartesian) or annular (polar) grid of evenly spaced grid lines.
double startX() const
Get method for x grid line lower bound (inclusive).
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
QPointF posScreen() const
Accessor for screen position.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
Container class for GridLine objects.
CoordsType coordsType() const
Get method for coordinates type.
GridLineFactory(QGraphicsScene &scene, const DocumentModelCoords &modelCoords, const Transformation &transformation)
Simple constructor for general use (i.e. not by Checker)
Model for DlgSettingsCoords and CmdSettingsCoords.
ColorPalette paletteColor() const
Get method for color.
double stopY() const
Get method for y grid line upper bound (inclusive).
double startY() const
Get method for y grid line lower bound (inclusive).
double stepY() const
Get method for y grid line increment.
void add(GridLine *gridLine)
Add specified grid line. Ownership of all allocated QGraphicsItems is passed to new GridLine...
bool stable() const
Get method for stable flag.
void setPen(const QPen &pen)
Set the pen style.
Single grid line drawn a straight or curved line.
void add(QGraphicsItem *item)
Add graphics item which represents one segment of the line.