Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Centipede
CentipedeSegmentConstantYLine.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 "
CentipedeSegmentConstantYLine.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
CentipedeSegmentConstantYLine::CentipedeSegmentConstantYLine
(
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.
posScreenConstantYForLowX
(
modelGuideline
.creationCircleRadius ());
30
m_posHigh = endpoints.
posScreenConstantYForHighX
(
modelGuideline
.creationCircleRadius ());
31
32
// Create graphics item and its relay
33
m_graphicsItem =
new
QGraphicsLineItem (QLineF (m_posLow,
34
m_posHigh));
35
m_graphicsItemRelay =
new
GraphicsLineItemRelay
(
this
,
36
m_graphicsItem);
37
38
QColor color (
ColorPaletteToQColor
(
modelGuideline
.lineColor()));
39
40
m_graphicsItem->setPen (QPen (color,
41
modelGuideline
.lineWidthActive ()));
42
43
scene.addItem (m_graphicsItem);
44
}
45
46
CentipedeSegmentConstantYLine::~CentipedeSegmentConstantYLine
()
47
{
48
delete
m_graphicsItem;
49
delete
m_graphicsItemRelay;
50
}
51
52
double
CentipedeSegmentConstantYLine::distanceToClosestEndpoint
(
const
QPointF &posScreen)
const
53
{
54
double
distanceLow =
magnitude
(posScreen - m_posLow);
55
double
distanceHigh =
magnitude
(posScreen - m_posHigh);
56
57
return
qMin (distanceLow, distanceHigh);
58
}
59
60
void
CentipedeSegmentConstantYLine::updateRadius
(
double
radius)
61
{
62
// Scale up/down the line segment length, keeping it centered on the same center point
63
QPointF posCenter = (m_posHigh + m_posLow) / 2.0;
64
QPointF delta = m_posHigh - m_posLow;
65
double
radiusInitial =
magnitude
(delta) / 2.0;
// Convert from diameter to radius
66
double
scaling = radius / radiusInitial;
67
QPointF posLow = posCenter - scaling / 2.0 * delta;
68
QPointF posHigh = posCenter + scaling / 2.0 * delta;
69
70
// Update geometry but only after the event handler currently on the stack has disappeared.
71
// This means sending a signal instead of calling QGraphicsLineItem::setLine directly
72
emit
signalUpdateEndpoints
(posLow,
73
posHigh);
74
}
CentipedeEndpointsCartesian.h
CentipedeSegmentConstantYLine.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::posScreenConstantYForLowX
QPointF posScreenConstantYForLowX(double radius) const
Screen point for Y value of circle/coordinate intersection in the decreasing X direction.
Definition
CentipedeEndpointsCartesian.cpp:179
CentipedeEndpointsCartesian::posScreenConstantYForHighX
QPointF posScreenConstantYForHighX(double radius) const
Screen point for Y value of circle/coordinate intersection in the increasing X direction.
Definition
CentipedeEndpointsCartesian.cpp:173
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
CentipedeSegmentConstantYLine::updateRadius
virtual void updateRadius(double radius)
Update geometry to reflect cursor movement.
Definition
CentipedeSegmentConstantYLine.cpp:60
CentipedeSegmentConstantYLine::~CentipedeSegmentConstantYLine
virtual ~CentipedeSegmentConstantYLine()
Definition
CentipedeSegmentConstantYLine.cpp:46
CentipedeSegmentConstantYLine::distanceToClosestEndpoint
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const
Return distance to closest endpoint.
Definition
CentipedeSegmentConstantYLine.cpp:52
CentipedeSegmentConstantYLine::CentipedeSegmentConstantYLine
CentipedeSegmentConstantYLine(GraphicsScene &scene, const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
Definition
CentipedeSegmentConstantYLine.cpp:17
CentipedeSegmentConstantYLine::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