Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Centipede
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
7
#include "
CentipedeEndpointsPolar.h
"
8
#include "
CentipedeSegmentConstantTRadial.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 <QGraphicsRectItem>
16
#include <QPen>
17
18
CentipedeSegmentConstantTRadial::CentipedeSegmentConstantTRadial
(
GraphicsScene
&scene,
19
const
DocumentModelCoords
&modelCoords,
20
const
DocumentModelGuideline
&
modelGuideline
,
21
const
Transformation
&
transformation
,
22
const
QPointF &
posClickScreen
) :
23
CentipedeSegmentAbstract
(
modelGuideline
,
24
transformation
,
25
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,
38
modelGuideline
,
39
transformation
,
40
posClickScreen
,
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
60
CentipedeSegmentConstantTRadial::~CentipedeSegmentConstantTRadial
()
61
{
62
delete
m_graphicsItem;
63
delete
m_graphicsItemRelay;
64
}
65
66
double
CentipedeSegmentConstantTRadial::distanceToClosestEndpoint
(
const
QPointF &posScreen)
const
67
{
68
double
distanceLow =
magnitude
(posScreen - m_posLow);
69
double
distanceHigh =
magnitude
(posScreen - m_posHigh);
70
71
return
qMin (distanceLow, distanceHigh);
72
}
73
74
void
CentipedeSegmentConstantTRadial::updateRadius
(
double
radius)
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
}
CentipedeEndpointsPolar.h
CentipedeSegmentConstantTRadial.h
COORD_SCALE_LOG
@ COORD_SCALE_LOG
Definition
CoordScale.h:14
ColorPaletteToQColor
QColor ColorPaletteToQColor(ColorPalette color)
Definition
EnumsToQt.cpp:16
EnumsToQt.h
GraphicsLineItemRelay.h
GraphicsScene.h
CentipedeEndpointsPolar
Compute endpoints for polar centipedes.
Definition
CentipedeEndpointsPolar.h:21
CentipedeEndpointsPolar::posScreenConstantTForRHighLow
void posScreenConstantTForRHighLow(double radius, QPointF &posLow, QPointF &posHigh) const
Endpoints for radial line segmentin polar coordinates.
Definition
CentipedeEndpointsPolar.cpp:287
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
CentipedeSegmentConstantTRadial::signalUpdateEndpoints
void signalUpdateEndpoints(QPointF start, QPointF end)
Send new geometry for later updating.
CentipedeSegmentConstantTRadial::CentipedeSegmentConstantTRadial
CentipedeSegmentConstantTRadial(GraphicsScene &scene, const DocumentModelCoords &modelCoords, const DocumentModelGuideline &modelGuideline, const Transformation &transformation, const QPointF &posClickScreen)
Constructor with individual coordinates.
Definition
CentipedeSegmentConstantTRadial.cpp:18
CentipedeSegmentConstantTRadial::~CentipedeSegmentConstantTRadial
virtual ~CentipedeSegmentConstantTRadial()
Definition
CentipedeSegmentConstantTRadial.cpp:60
CentipedeSegmentConstantTRadial::distanceToClosestEndpoint
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const
Return distance to closest endpoint.
Definition
CentipedeSegmentConstantTRadial.cpp:66
CentipedeSegmentConstantTRadial::updateRadius
virtual void updateRadius(double radius)
Update geometry to reflect cursor movement.
Definition
CentipedeSegmentConstantTRadial.cpp:74
DocumentModelCoords
Model for DlgSettingsCoords and CmdSettingsCoords.
Definition
DocumentModelCoords.h:21
DocumentModelCoords::coordScaleYRadius
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.
Definition
DocumentModelCoords.cpp:88
DocumentModelCoords::originRadius
double originRadius() const
Get method for origin radius in polar mode.
Definition
DocumentModelCoords.cpp:174
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