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;
34 transformation.transformRawGraphToScreen (posOriginGraph,
35 posOriginScreen);
36
37 CentipedeEndpointsPolar endpoints (modelCoords,
41 posOriginScreen);
42
43 endpoints.posScreenConstantTForRHighLow (modelGuideline.creationCircleRadius(),
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
52 QColor color (ColorPaletteToQColor (modelGuideline.lineColor()));
53
54 m_graphicsItem->setPen (QPen (color,
55 modelGuideline.lineWidthActive ()));
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.
Enable postponed geometry changes for QGraphicsLineItem, using a signal to trigger this class to upda...
Add point and line handling to generic QGraphicsScene.
Affine transformation between screen and graph coordinates, based on digitized axis points.
double magnitude(const QPointF &vec)
Norm of vector.
Definition mmsubs.cpp:193