Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Centipede
CentipedeSegmentConstantXLine.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
7
#include "
CentipedeEndpointsCartesian.h
"
8
#include "
CentipedeSegmentConstantXLine.h
"
9
#include "
EnumsToQt.h
"
10
#include "
GraphicsLineItemRelay.h
"
11
#include "
GraphicsScene.h
"
12
#include "
mmsubs.h
"
13
#include <qmath.h>
14
#include <QGraphicsLineItem>
15
#include <QPen>
16
17
CentipedeSegmentConstantXLine::CentipedeSegmentConstantXLine
(
GraphicsScene
&scene,
18
const
DocumentModelGuideline
&
modelGuideline
,
19
const
Transformation
&
transformation
,
20
const
QPointF &
posClickScreen
) :
21
CentipedeSegmentAbstract
(
modelGuideline
,
22
transformation
,
23
posClickScreen
)
24
{
25
CentipedeEndpointsCartesian
endpoints (
modelGuideline
,
26
transformation
,
27
posClickScreen
);
28
29
m_posLow = endpoints.
posScreenConstantXForLowY
(
modelGuideline
.creationCircleRadius ());
30
31
m_posHigh = endpoints.
posScreenConstantXForHighY
(
modelGuideline
.creationCircleRadius ());
32
33
// Create graphics item and its relay
34
m_graphicsItem =
new
QGraphicsLineItem (QLineF (m_posLow,
35
m_posHigh));
36
m_graphicsItemRelay =
new
GraphicsLineItemRelay
(
this
,
37
m_graphicsItem);
38
39
QColor color (
ColorPaletteToQColor
(
modelGuideline
.lineColor()));
40
41
m_graphicsItem->setPen (QPen (color,
42
modelGuideline
.lineWidthActive ()));
43
44
scene.addItem (m_graphicsItem);
45
}
46
47
CentipedeSegmentConstantXLine::~CentipedeSegmentConstantXLine
()
48
{
49
delete
m_graphicsItem;
50
delete
m_graphicsItemRelay;
51
}
52
53
double
CentipedeSegmentConstantXLine::distanceToClosestEndpoint
(
const
QPointF &posScreen)
const
54
{
55
double
distanceLow =
magnitude
(posScreen - m_posLow);
56
double
distanceHigh =
magnitude
(posScreen - m_posHigh);
57
58
return
qMin (distanceLow, distanceHigh);
59
}
60
61
void
CentipedeSegmentConstantXLine::updateRadius
(
double
radius)
62
{
63
// Scale up/down the line segment length, keeping it centered on the same center point
64
QPointF posCenter = (m_posHigh + m_posLow) / 2.0;
65
QPointF delta = m_posHigh - m_posLow;
66
double
radiusInitial =
magnitude
(delta) / 2.0;
// Convert from diameter to radius
67
double
scaling = radius / radiusInitial;
68
QPointF posLow = posCenter - scaling / 2.0 * delta;
69
QPointF posHigh = posCenter + scaling / 2.0 * delta;
70
71
// Update geometry but only after the event handler currently on the stack has disappeared.
72
// This means sending a signal instead of calling QGraphicsLineItem::setLine directly
73
emit
signalUpdateEndpoints
(posLow,
74
posHigh);
75
}
CentipedeEndpointsCartesian.h
CentipedeSegmentConstantXLine.h
ColorPaletteToQColor
QColor ColorPaletteToQColor(ColorPalette color)
Definition
EnumsToQt.cpp:16
EnumsToQt.h
GraphicsLineItemRelay.h
GraphicsScene.h
CentipedeEndpointsCartesian
Compute endpoints for cartesian centipedes.
Definition
CentipedeEndpointsCartesian.h:18
CentipedeEndpointsCartesian::posScreenConstantXForLowY
QPointF posScreenConstantXForLowY(double radius) const
Screen point for X value of circle/coordinate intersection in the decreasing Y direction.
Definition
CentipedeEndpointsCartesian.cpp:111
CentipedeEndpointsCartesian::posScreenConstantXForHighY
QPointF posScreenConstantXForHighY(double radius) const
Screen point for X value of circle/coordinate intersection in the increasing Y direction.
Definition
CentipedeEndpointsCartesian.cpp:105
CentipedeSegmentAbstract::posClickScreen
QPointF posClickScreen() const
Center of circle in screen coordinates.
Definition
CentipedeSegmentAbstract.cpp:48
CentipedeSegmentAbstract::CentipedeSegmentAbstract
CentipedeSegmentAbstract(const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
Definition
CentipedeSegmentAbstract.cpp:14
CentipedeSegmentAbstract::modelGuideline
const DocumentModelGuideline & modelGuideline() const
Settings.
Definition
CentipedeSegmentAbstract.cpp:43
CentipedeSegmentAbstract::transformation
Transformation transformation() const
Transformation which is static through the entire lifetime of the Centipede class instances.
Definition
CentipedeSegmentAbstract.cpp:53
CentipedeSegmentConstantXLine::distanceToClosestEndpoint
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const
Return distance to closest endpoint.
Definition
CentipedeSegmentConstantXLine.cpp:53
CentipedeSegmentConstantXLine::CentipedeSegmentConstantXLine
CentipedeSegmentConstantXLine(GraphicsScene &scene, const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
Definition
CentipedeSegmentConstantXLine.cpp:17
CentipedeSegmentConstantXLine::updateRadius
virtual void updateRadius(double radius)
Update geometry to reflect cursor movement.
Definition
CentipedeSegmentConstantXLine.cpp:61
CentipedeSegmentConstantXLine::~CentipedeSegmentConstantXLine
virtual ~CentipedeSegmentConstantXLine()
Definition
CentipedeSegmentConstantXLine.cpp:47
CentipedeSegmentConstantXLine::signalUpdateEndpoints
void signalUpdateEndpoints(QPointF start, QPointF end)
Send new geometry for later updating.
DocumentModelGuideline
Model for managing the coordinate values corresponding Guidelines.
Definition
DocumentModelGuideline.h:22
GraphicsLineItemRelay
Enable postponed geometry changes for QGraphicsLineItem, using a signal to trigger this class to upda...
Definition
GraphicsLineItemRelay.h:22
GraphicsScene
Add point and line handling to generic QGraphicsScene.
Definition
GraphicsScene.h:37
Transformation
Affine transformation between screen and graph coordinates, based on digitized axis points.
Definition
Transformation.h:32
magnitude
double magnitude(const QPointF &vec)
Norm of vector.
Definition
mmsubs.cpp:193
mmsubs.h
Generated on
for Engauge Digitizer by
1.17.0