20#include <QGraphicsScene>
37 m_modelCoords (modelCoords),
40 qCDebug(ENGAUGE_LOG) <<
"GridLineFactory::GridLineFactory";
45 const QList<Point> &pointsToIsolate,
48 m_pointRadius (pointRadius),
49 m_pointsToIsolate (pointsToIsolate),
50 m_modelCoords (modelCoords),
53 qCDebug(ENGAUGE_LOG) <<
"GridLineFactory::GridLineFactory"
54 <<
" pointRadius=" << pointRadius
55 <<
" pointsToIsolate=" << pointsToIsolate.count();
58void GridLineFactory::bindItemToScene(QGraphicsItem *item)
const
60 qCDebug(ENGAUGE_LOG) <<
"GridLineFactory::bindItemToScene";
65 item->setToolTip (QObject::tr (
"Axes checker. If this does not align with the axes, then the axes points should be checked"));
68 m_scene.addItem (item);
77 qCDebug(ENGAUGE_LOG) <<
"GridLineFactory::createGridLine"
94 const int NUM_STEPS = 1000;
96 bool stateSegmentIsActive =
false;
97 QPointF posStartScreen (0, 0);
100 for (
int i = 0; i <= NUM_STEPS; i++) {
102 double s = double (i) / double (NUM_STEPS);
105 double xGraph = (1.0 - s) * xFrom + s * xTo;
106 double yGraph = (1.0 - s) * yFrom + s * yTo;
110 xGraph = qExp ((1.0 - s) * qLn (xFrom) + s * qLn (xTo));
113 yGraph = qExp ((1.0 - s) * qLn (yFrom) + s * qLn (yTo));
120 double distanceToNearestPoint = minScreenDistanceFromPoints (pointScreen);
121 if ((distanceToNearestPoint < m_pointRadius) ||
125 if (stateSegmentIsActive) {
128 finishActiveGridLine (posStartScreen,
134 stateSegmentIsActive =
false;
140 if (!stateSegmentIsActive) {
143 stateSegmentIsActive =
true;
144 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 ();
171 unsigned int numX = modelGridDisplay.
countX ();
172 unsigned int numY = modelGridDisplay.
countY ();
212 if (stepX > (isLinearX ? 0 : 1) &&
213 stepY > (isLinearY ? 0 : 1) &&
214 (isLinearX || (startX > 0)) &&
215 (isLinearY || (startY > 0))) {
218 QPen pen (QPen (color,
222 for (
double x = startX; x <= stopX; (isLinearX ? x += stepX : x *= stepX)) {
226 gridLines.
add (gridLine);
229 for (
double y = startY; y <= stopY; (isLinearY ? y += stepY : y *= stepY)) {
233 gridLines.
add (gridLine);
239void GridLineFactory::createTransformAlign (
const Transformation &transformation,
240 double radiusLinearCartesian,
241 const QPointF &posOriginScreen,
242 QTransform &transformAlign,
243 double &ellipseXAxis,
244 double &ellipseYAxis)
const
257 QPointF posXRadiusY0Graph (radiusLinearCartesian, 0), posX0YRadiusGraph (0, radiusLinearCartesian);
258 QPointF posXRadiusY0Screen, posX0YRadiusScreen;
265 QPointF deltaXRadiusY0 = posXRadiusY0Screen - posOriginScreen;
266 QPointF deltaX0YRadius = posX0YRadiusScreen - posOriginScreen;
267 ellipseXAxis = qSqrt (deltaXRadiusY0.x () * deltaXRadiusY0.x () +
268 deltaXRadiusY0.y () * deltaXRadiusY0.y ());
269 ellipseYAxis = qSqrt (deltaX0YRadius.x () * deltaX0YRadius.x () +
270 deltaX0YRadius.y () * deltaX0YRadius.y ());
273 QPointF posXRadiusY0AlignedScreen (posOriginScreen.x() + ellipseXAxis, posOriginScreen.y());
274 QPointF posX0YRadiusAlignedScreen (posOriginScreen.x(), posOriginScreen.y() - ellipseYAxis);
280 posXRadiusY0AlignedScreen,
281 posX0YRadiusAlignedScreen);
284 qCInfo(ENGAUGE_LOG) <<
"GridLineFactory::createTransformAlign"
286 <<
" radiusLinearCartesian=" << radiusLinearCartesian
287 <<
" posXRadiusY0Screen=" <<
QPointFToString (posXRadiusY0Screen).toLatin1().data()
288 <<
" posX0YRadiusScreen=" <<
QPointFToString (posX0YRadiusScreen).toLatin1().data()
289 <<
" ellipseXAxis=" << ellipseXAxis
290 <<
" ellipseYAxis=" << ellipseYAxis
291 <<
" posXRadiusY0AlignedScreen=" <<
QPointFToString (posXRadiusY0AlignedScreen).toLatin1().data()
292 <<
" posX0YRadiusAlignedScreen=" <<
QPointFToString (posX0YRadiusAlignedScreen).toLatin1().data()
296QGraphicsItem *GridLineFactory::ellipseItem (
const Transformation &transformation,
297 double radiusLinearCartesian,
298 const QPointF &posStartScreen,
299 const QPointF &posEndScreen)
const
303 QPointF posStartGraph, posEndGraph;
311 double angleStart = qDegreesToRadians (posStartGraph.x());
312 double angleEnd = qDegreesToRadians (posEndGraph.x());
313 if (angleEnd < angleStart) {
314 angleEnd += 2.0 * M_PI;
316 double angleSpan = angleEnd - angleStart;
319 QPointF posOriginGraph (0, 0), posOriginScreen;
323 qCInfo(ENGAUGE_LOG) <<
"GridLineFactory::ellipseItem"
324 <<
" radiusLinearCartesian=" << radiusLinearCartesian
325 <<
" posStartScreen=" <<
QPointFToString (posStartScreen).toLatin1().data()
326 <<
" posEndScreen=" <<
QPointFToString (posEndScreen).toLatin1().data()
327 <<
" posOriginScreen=" <<
QPointFToString (posOriginScreen).toLatin1().data()
328 <<
" angleStart=" << qRadiansToDegrees (angleStart)
329 <<
" angleEnd=" << qRadiansToDegrees (angleEnd)
330 <<
" transformation=" << transformation;
335 double ellipseXAxis, ellipseYAxis;
336 QTransform transformAlign;
337 createTransformAlign (transformation,
338 radiusLinearCartesian,
345 QRectF boundingRect (-1.0 * ellipseXAxis + posOriginScreen.x(),
346 -1.0 * ellipseYAxis + posOriginScreen.y(),
353 item->setTransform (transformAlign.transposed ().inverted ());
358void GridLineFactory::finishActiveGridLine (
const QPointF &posStartScreen,
359 const QPointF &posEndScreen,
365 qCDebug(ENGAUGE_LOG) <<
"GridLineFactory::finishActiveGridLine"
366 <<
" posStartScreen=" <<
QPointFToString (posStartScreen).toLatin1().data()
367 <<
" posEndScreen=" <<
QPointFToString (posEndScreen).toLatin1().data()
368 <<
" yFrom=" << yFrom
376 double radiusLinearCartesian = yFrom;
379 m_modelCoords.originRadius());
381 radiusLinearCartesian -= m_modelCoords.originRadius();
385 item = ellipseItem (transformation,
386 radiusLinearCartesian,
393 item = lineItem (posStartScreen,
398 bindItemToScene (item);
401QGraphicsItem *GridLineFactory::lineItem (
const QPointF &posStartScreen,
402 const QPointF &posEndScreen)
const
404 qCDebug(ENGAUGE_LOG) <<
"GridLineFactory::lineItem"
405 <<
" posStartScreen=" <<
QPointFToString (posStartScreen).toLatin1().data()
406 <<
" posEndScreen=" <<
QPointFToString (posEndScreen).toLatin1().data();
408 return new QGraphicsLineItem (QLineF (posStartScreen,
412double GridLineFactory::minScreenDistanceFromPoints (
const QPointF &posScreen)
414 double minDistance = 0;
415 for (
int i = 0; i < m_pointsToIsolate.count (); i++) {
416 const Point &pointCenter = m_pointsToIsolate.at (i);
418 double dx = posScreen.x() - pointCenter.
posScreen().x();
419 double dy = posScreen.y() - pointCenter.
posScreen().y();
421 double distance = qSqrt (dx * dx + dy * dy);
422 if (i == 0 || distance < minDistance) {
423 minDistance = distance;
const double RADIANS_TO_TICS
QColor ColorPaletteToQColor(ColorPalette color)
const double CHECKER_OPACITY
const int Z_VALUE_IN_FRONT
const Qt::PenStyle GRID_LINE_STYLE
QString QTransformToString(const QTransform &transform)
QString QPointFToString(const QPointF &pos)
Model for DlgSettingsCoords and CmdSettingsCoords.
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
GridCoordDisable disableY() const
Get method for y grid line disabled variable.
unsigned int countX() const
Get method for x grid line count.
double startX() const
Get method for x grid line lower bound (inclusive).
GridCoordDisable disableX() const
Get method for x grid line disabled variable.
unsigned int countY() const
Get method for y grid line count.
double stepX() const
Get method for x grid line increment.
double stopX() const
Get method for x grid line upper bound (inclusive).
double stopY() const
Get method for y grid line upper bound (inclusive).
bool stable() const
Get method for stable flag.
ColorPalette paletteColor() const
Get method for color.
double stepY() const
Get method for y grid line increment.
double startY() const
Get method for y grid line lower bound (inclusive).
unsigned int lineWidth() const
Get method for line width.
Storage of one imported image and the data attached to that image.
GraphicsArcItem()
Default constructor. This needs, at a minimum, a later call to setRect.
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.
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.
GridLineFactory(QGraphicsScene &scene, const DocumentModelCoords &modelCoords)
Simple constructor for general use (i.e. not by Checker).
Limit the number of grid lines so a bad combination of start/step/stop value will not lead to extreme...
void limitForYRadius(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startY, double &stepY, double &stopY, unsigned int numY) const
Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowM...
void limitForXTheta(const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startX, double &stepX, double &stopX, unsigned int numX) const
Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowM...
Normalize the four parameters used to define a grid line for display or removal.
Single grid line drawn a straight or curved line.
void setPen(const QPen &pen)
Set the pen style.
void add(QGraphicsItem *item)
Add graphics item which represents one segment of the line.
GridLine()
Default constructor for storage in containers.
Container class for GridLine objects.
void add(GridLine *gridLine)
Add specified grid line. Ownership of all allocated QGraphicsItems is passed to new GridLine.
Model for DlgSettingsMainWindow.
QPointF posScreen() const
Accessor for screen position.
QPointF normalize(const QPointF &vec)
Return normalized vector.