8 #include "DocumentModelCoords.h" 9 #include "DocumentModelGridDisplay.h" 10 #include "EngaugeAssert.h" 11 #include "EnumsToQt.h" 12 #include "GraphicsArcItem.h" 13 #include "GridLineFactory.h" 14 #include "GridLineLimiter.h" 15 #include "GridLines.h" 16 #include "GridLineStyle.h" 18 #include "MainWindowModel.h" 19 #include <QGraphicsScene> 21 #include <QTextStream> 22 #include "QtToString.h" 23 #include "Transformation.h" 25 const int Z_VALUE_IN_FRONT = 100;
28 const double CHECKER_OPACITY = 0.6;
30 const double PI = 3.1415926535;
31 const double TWO_PI = 2.0 * PI;
32 const double DEGREES_TO_RADIANS = PI / 180.0;
33 const double RADIANS_TO_TICS = 5760 / TWO_PI;
39 m_modelCoords (modelCoords),
42 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::GridLineFactory";
47 const QList<Point> &pointsToIsolate,
50 m_pointRadius (pointRadius),
51 m_pointsToIsolate (pointsToIsolate),
52 m_modelCoords (modelCoords),
55 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::GridLineFactory" 56 <<
" pointRadius=" << pointRadius
57 <<
" pointsToIsolate=" << pointsToIsolate.count();
60 void GridLineFactory::bindItemToScene(QGraphicsItem *item)
const 62 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::bindItemToScene";
64 item->setOpacity (CHECKER_OPACITY);
65 item->setZValue (Z_VALUE_IN_FRONT);
67 item->setToolTip (QObject::tr (
"Axes checker. If this does not align with the axes, then the axes points should be checked"));
70 m_scene.addItem (item);
79 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::createGridLine" 96 const int NUM_STEPS = 1000;
98 bool stateSegmentIsActive =
false;
99 QPointF posStartScreen (0, 0);
102 for (
int i = 0; i <= NUM_STEPS; i++) {
104 double s = (double) i / (
double) NUM_STEPS;
107 double xGraph = (1.0 - s) * xFrom + s * xTo;
108 double yGraph = (1.0 - s) * yFrom + s * yTo;
112 xGraph = qExp ((1.0 - s) * qLn (xFrom) + s * qLn (xTo));
115 yGraph = qExp ((1.0 - s) * qLn (yFrom) + s * qLn (yTo));
122 double distanceToNearestPoint = minScreenDistanceFromPoints (pointScreen);
123 if ((distanceToNearestPoint < m_pointRadius) ||
127 if (stateSegmentIsActive) {
130 finishActiveGridLine (posStartScreen,
136 stateSegmentIsActive =
false;
142 if (!stateSegmentIsActive) {
145 stateSegmentIsActive =
true;
146 posStartScreen = pointScreen;
165 modelGridDisplay.
stable()) {
167 double startX = modelGridDisplay.
startX ();
168 double startY = modelGridDisplay.
startY ();
169 double stepX = modelGridDisplay.
stepX ();
170 double stepY = modelGridDisplay.
stepY ();
171 double stopX = modelGridDisplay.
stopX ();
172 double stopY = modelGridDisplay.
stopY ();
196 if (stepX > (isLinearX ? 0 : 1) &&
197 stepY > (isLinearY ? 0 : 1) &&
198 (isLinearX || (startX > 0)) &&
199 (isLinearY || (startY > 0))) {
201 QColor color (ColorPaletteToQColor (modelGridDisplay.
paletteColor()));
202 QPen pen (QPen (color,
206 for (
double x = startX; x <= stopX; (isLinearX ? x += stepX : x *= stepX)) {
210 gridLines.
add (gridLine);
213 for (
double y = startY; y <= stopY; (isLinearY ? y += stepY : y *= stepY)) {
217 gridLines.
add (gridLine);
223 void GridLineFactory::createTransformAlign (
const Transformation &transformation,
224 double radiusLinearCartesian,
225 const QPointF &posOriginScreen,
226 QTransform &transformAlign,
227 double &ellipseXAxis,
228 double &ellipseYAxis)
const 241 QPointF posXRadiusY0Graph (radiusLinearCartesian, 0), posX0YRadiusGraph (0, radiusLinearCartesian);
242 QPointF posXRadiusY0Screen, posX0YRadiusScreen;
249 QPointF deltaXRadiusY0 = posXRadiusY0Screen - posOriginScreen;
250 QPointF deltaX0YRadius = posX0YRadiusScreen - posOriginScreen;
251 ellipseXAxis = qSqrt (deltaXRadiusY0.x () * deltaXRadiusY0.x () +
252 deltaXRadiusY0.y () * deltaXRadiusY0.y ());
253 ellipseYAxis = qSqrt (deltaX0YRadius.x () * deltaX0YRadius.x () +
254 deltaX0YRadius.y () * deltaX0YRadius.y ());
257 QPointF posXRadiusY0AlignedScreen (posOriginScreen.x() + ellipseXAxis, posOriginScreen.y());
258 QPointF posX0YRadiusAlignedScreen (posOriginScreen.x(), posOriginScreen.y() - ellipseYAxis);
264 posXRadiusY0AlignedScreen,
265 posX0YRadiusAlignedScreen);
267 LOG4CPP_INFO_S ((*mainCat)) <<
"GridLineFactory::createTransformAlign" 268 <<
" transformation=" << QTransformToString (transformation.
transformMatrix()).toLatin1().data() << endl
269 <<
" radiusLinearCartesian=" << radiusLinearCartesian
270 <<
" posXRadiusY0Screen=" << QPointFToString (posXRadiusY0Screen).toLatin1().data()
271 <<
" posX0YRadiusScreen=" << QPointFToString (posX0YRadiusScreen).toLatin1().data()
272 <<
" ellipseXAxis=" << ellipseXAxis
273 <<
" ellipseYAxis=" << ellipseYAxis
274 <<
" posXRadiusY0AlignedScreen=" << QPointFToString (posXRadiusY0AlignedScreen).toLatin1().data()
275 <<
" posX0YRadiusAlignedScreen=" << QPointFToString (posX0YRadiusAlignedScreen).toLatin1().data()
276 <<
" transformAlign=" << QTransformToString (transformAlign).toLatin1().data();
279 QGraphicsItem *GridLineFactory::ellipseItem (
const Transformation &transformation,
280 double radiusLinearCartesian,
281 const QPointF &posStartScreen,
282 const QPointF &posEndScreen)
const 286 QPointF posStartGraph, posEndGraph;
294 double angleStart = posStartGraph.x() * DEGREES_TO_RADIANS;
295 double angleEnd = posEndGraph.x() * DEGREES_TO_RADIANS;
296 if (angleEnd < angleStart) {
299 double angleSpan = angleEnd - angleStart;
302 QPointF posOriginGraph (0, 0), posOriginScreen;
306 LOG4CPP_INFO_S ((*mainCat)) <<
"GridLineFactory::ellipseItem" 307 <<
" radiusLinearCartesian=" << radiusLinearCartesian
308 <<
" posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
309 <<
" posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
310 <<
" posOriginScreen=" << QPointFToString (posOriginScreen).toLatin1().data()
311 <<
" angleStart=" << angleStart / DEGREES_TO_RADIANS
312 <<
" angleEnd=" << angleEnd / DEGREES_TO_RADIANS
313 <<
" transformation=" << transformation;
318 double ellipseXAxis, ellipseYAxis;
319 QTransform transformAlign;
320 createTransformAlign (transformation,
321 radiusLinearCartesian,
328 QRectF boundingRect (-1.0 * ellipseXAxis + posOriginScreen.x(),
329 -1.0 * ellipseYAxis + posOriginScreen.y(),
333 item->setStartAngle (angleStart * RADIANS_TO_TICS);
334 item->setSpanAngle (angleSpan * RADIANS_TO_TICS);
336 item->setTransform (transformAlign.transposed ().inverted ());
341 void GridLineFactory::finishActiveGridLine (
const QPointF &posStartScreen,
342 const QPointF &posEndScreen,
348 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::finishActiveGridLine" 349 <<
" posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
350 <<
" posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
351 <<
" yFrom=" << yFrom
355 if ((m_modelCoords.
coordsType() == COORDS_TYPE_POLAR) &&
359 double radiusLinearCartesian = yFrom;
368 item = ellipseItem (transformation,
369 radiusLinearCartesian,
376 item = lineItem (posStartScreen,
381 bindItemToScene (item);
384 QGraphicsItem *GridLineFactory::lineItem (
const QPointF &posStartScreen,
385 const QPointF &posEndScreen)
const 387 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GridLineFactory::lineItem" 388 <<
" posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
389 <<
" posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data();
391 return new QGraphicsLineItem (QLineF (posStartScreen,
395 double GridLineFactory::minScreenDistanceFromPoints (
const QPointF &posScreen)
397 double minDistance = 0;
398 for (
int i = 0; i < m_pointsToIsolate.count (); i++) {
399 const Point &pointCenter = m_pointsToIsolate.at (i);
401 double dx = posScreen.x() - pointCenter.
posScreen().x();
402 double dy = posScreen.y() - pointCenter.
posScreen().y();
404 double distance = qSqrt (dx * dx + dy * dy);
405 if (i == 0 || distance < minDistance) {
406 minDistance = distance;
void limitForXTheta(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startX, double &stepX, double &stopX) const
Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowM...
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void createGridLinesForEvenlySpacedGrid(const DocumentModelGridDisplay &modelGridDisplay, const Document &document, const MainWindowModel &modelMainWindow, const Transformation &transformation, GridLines &gridLines)
Create a rectangular (cartesian) or annular (polar) grid of evenly spaced grid lines.
Draw an arc as an ellipse but without lines from the center to the start and end points.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
QPointF posScreen() const
Accessor for screen position.
bool stable() const
Get method for stable flag.
Model for DlgSettingsMainWindow.
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, double &stepY, double &stopY) const
Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowM...
Container class for GridLine objects.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
double stopY() const
Get method for y grid line upper bound (inclusive).
double stopX() const
Get method for x grid line upper bound (inclusive).
ColorPalette paletteColor() const
Get method for color.
Model for DlgSettingsCoords and CmdSettingsCoords.
Storage of one imported image and the data attached to that image.
double startY() const
Get method for y grid line lower bound (inclusive).
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
GridLineFactory(QGraphicsScene &scene, const DocumentModelCoords &modelCoords)
Simple constructor for general use (i.e. not by Checker)
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...
double stepY() const
Get method for y grid line increment.
double startX() const
Get method for x grid line lower bound (inclusive).
void setPen(const QPen &pen)
Set the pen style.
double originRadius() const
Get method for origin radius in polar mode.
Single grid line drawn a straight or curved line.
Limit the number of grid lines so a bad combination of start/step/stop value will not lead to extreme...
double stepX() const
Get method for x grid line increment.
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.
void add(QGraphicsItem *item)
Add graphics item which represents one segment of the line.