Engauge Digitizer 2
Loading...
Searching...
No Matches
CentipedeSegmentConstantTRadial.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2020 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
9#include "EnumsToQt.h"
11#include "GraphicsScene.h"
12#include "mmsubs.h"
13#include <qmath.h>
14#include <QGraphicsLineItem>
15#include <QGraphicsRectItem>
16#include <QPen>
17
19 const DocumentModelCoords &modelCoords,
22 const QPointF &posClickScreen) :
26{
27 // Compute basis vectors that are used here and when by any callback(s)
28 QPointF posOriginGraph (0, 0);
29 if (modelCoords.coordScaleYRadius() == COORD_SCALE_LOG) {
30 posOriginGraph = QPointF (0, modelCoords.originRadius());
31 }
32
33 QPointF posOriginScreen;
35 posOriginScreen);
36
37 CentipedeEndpointsPolar endpoints (modelCoords,
41 posOriginScreen);
42
44 m_posLow,
45 m_posHigh);
46
47 m_graphicsItem = new QGraphicsLineItem (QLineF (m_posLow,
48 m_posHigh));
49 m_graphicsItemRelay = new GraphicsLineItemRelay (this,
50 m_graphicsItem);
51
53
54 m_graphicsItem->setPen (QPen (color,
56
57 scene.addItem (m_graphicsItem);
58}
59
61{
62 delete m_graphicsItem;
63 delete m_graphicsItemRelay;
64}
65
67{
68 double distanceLow = magnitude (posScreen - m_posLow);
69 double distanceHigh = magnitude (posScreen - m_posHigh);
70
71 return qMin (distanceLow, distanceHigh);
72}
73
75{
76 // Scale up/down the line segment length, keeping it centered on the same center point
77 QPointF posCenter = (m_posHigh + m_posLow) / 2.0;
78 QPointF delta = m_posHigh - m_posLow;
79 double radiusInitial = magnitude (delta) / 2.0; // Convert from diameter to radius
80 double scaling = radius / radiusInitial;
81 QPointF posLow = posCenter - scaling / 2.0 * delta;
82 QPointF posHigh = posCenter + scaling / 2.0 * delta;
83
84 // Update geometry but only after the event handler currently on the stack has disappeared.
85 // This means sending a signal instead of calling QGraphicsLineItem::setLine directly
86 emit signalUpdateEndpoints (posLow,
87 posHigh);
88}
@ COORD_SCALE_LOG
Definition CoordScale.h:14
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
Compute endpoints for polar centipedes.
void posScreenConstantTForRHighLow(double radius, QPointF &posLow, QPointF &posHigh) const
Endpoints for radial line segmentin polar coordinates.
QPointF posClickScreen() const
Center of circle in screen coordinates.
CentipedeSegmentAbstract(const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
const DocumentModelGuideline & modelGuideline() const
Settings.
Transformation transformation() const
Transformation which is static through the entire lifetime of the Centipede class instances.
void signalUpdateEndpoints(QPointF start, QPointF end)
Send new geometry for later updating.
CentipedeSegmentConstantTRadial(GraphicsScene &scene, const DocumentModelCoords &modelCoords, const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const
Return distance to closest endpoint.
virtual void updateRadius(double radius)
Update geometry to reflect cursor movement.
Model for DlgSettingsCoords and CmdSettingsCoords.
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
double originRadius() const
Get method for origin radius in polar mode.
Model for managing the coordinate values corresponding Guidelines.
double creationCircleRadius() const
Get method for creation circle radius in pixels.
ColorPalette lineColor() const
Get method for line color.
double lineWidthActive() const
Get method for line width when active.
GraphicsLineItemRelay(QObject *caller, QGraphicsLineItem *graphicsItem)
Single constructor with associated GraphicsArcItem.
Add point and line handling to generic QGraphicsScene.
Affine transformation between screen and graph coordinates, based on digitized axis points.
void transformRawGraphToScreen(const QPointF &pointRaw, QPointF &pointScreen) const
Transform from raw graph coordinates to linear cartesian graph coordinates, then to screen coordinate...
double magnitude(const QPointF &vec)
Norm of vector.
Definition mmsubs.cpp:193