19 #include <QGraphicsScene>
21 #include <QTextStream>
30 const double PI = 3.1415926535;
39 m_modelCoords (modelCoords),
47 const QList<Point> &pointsToIsolate,
50 m_pointRadius (pointRadius),
51 m_pointsToIsolate (pointsToIsolate),
52 m_modelCoords (modelCoords),
56 <<
" pointRadius=" << pointRadius
57 <<
" pointsToIsolate=" << pointsToIsolate.count();
60 void GridLineFactory::bindItemToScene(QGraphicsItem *item)
const
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);
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))) {
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);
270 <<
" radiusLinearCartesian=" << radiusLinearCartesian
271 <<
" posXRadiusY0Screen=" <<
QPointFToString (posXRadiusY0Screen).toLatin1().data()
272 <<
" posX0YRadiusScreen=" <<
QPointFToString (posX0YRadiusScreen).toLatin1().data()
273 <<
" ellipseXAxis=" << ellipseXAxis
274 <<
" ellipseYAxis=" << ellipseYAxis
275 <<
" posXRadiusY0AlignedScreen=" <<
QPointFToString (posXRadiusY0AlignedScreen).toLatin1().data()
276 <<
" posX0YRadiusAlignedScreen=" <<
QPointFToString (posX0YRadiusAlignedScreen).toLatin1().data()
280 QGraphicsItem *GridLineFactory::ellipseItem (
const Transformation &transformation,
281 double radiusLinearCartesian,
282 const QPointF &posStartScreen,
283 const QPointF &posEndScreen)
const
287 QPointF posStartGraph, posEndGraph;
297 if (angleEnd < angleStart) {
300 double angleSpan = angleEnd - angleStart;
303 QPointF posOriginGraph (0, 0), posOriginScreen;
308 <<
" radiusLinearCartesian=" << radiusLinearCartesian
309 <<
" posStartScreen=" <<
QPointFToString (posStartScreen).toLatin1().data()
310 <<
" posEndScreen=" <<
QPointFToString (posEndScreen).toLatin1().data()
311 <<
" posOriginScreen=" <<
QPointFToString (posOriginScreen).toLatin1().data()
314 <<
" transformation=" << transformation;
319 double ellipseXAxis, ellipseYAxis;
320 QTransform transformAlign;
321 createTransformAlign (transformation,
322 radiusLinearCartesian,
329 QRectF boundingRect (-1.0 * ellipseXAxis + posOriginScreen.x(),
330 -1.0 * ellipseYAxis + posOriginScreen.y(),
337 item->setTransform (transformAlign.transposed ().inverted ());
342 void GridLineFactory::finishActiveGridLine (
const QPointF &posStartScreen,
343 const QPointF &posEndScreen,
350 <<
" posStartScreen=" <<
QPointFToString (posStartScreen).toLatin1().data()
351 <<
" posEndScreen=" <<
QPointFToString (posEndScreen).toLatin1().data()
352 <<
" yFrom=" << yFrom
360 double radiusLinearCartesian = yFrom;
369 item = ellipseItem (transformation,
370 radiusLinearCartesian,
377 item = lineItem (posStartScreen,
382 bindItemToScene (item);
385 QGraphicsItem *GridLineFactory::lineItem (
const QPointF &posStartScreen,
386 const QPointF &posEndScreen)
const
389 <<
" posStartScreen=" <<
QPointFToString (posStartScreen).toLatin1().data()
390 <<
" posEndScreen=" <<
QPointFToString (posEndScreen).toLatin1().data();
392 return new QGraphicsLineItem (QLineF (posStartScreen,
396 double GridLineFactory::minScreenDistanceFromPoints (
const QPointF &posScreen)
398 double minDistance = 0;
399 for (
int i = 0; i < m_pointsToIsolate.count (); i++) {
400 const Point &pointCenter = m_pointsToIsolate.at (i);
402 double dx = posScreen.x() - pointCenter.
posScreen().x();
403 double dy = posScreen.y() - pointCenter.
posScreen().y();
405 double distance = qSqrt (dx * dx + dy * dy);
406 if (i == 0 || distance < minDistance) {
407 minDistance = distance;