Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Centipede
CentipedePairCartesian.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 "
CentipedePairCartesian.h
"
8
#include "
CentipedeSegmentAbstract.h
"
9
#include "
CentipedeSegmentConstantREllipse.h
"
10
#include "
CentipedeSegmentConstantTRadial.h
"
11
#include "
CentipedeSegmentConstantXLine.h
"
12
#include "
CentipedeSegmentConstantYLine.h
"
13
#include "
DocumentModelCoords.h
"
14
#include "
DocumentModelGuideline.h
"
15
#include "
GraphicsScene.h
"
16
#include "
mmsubs.h
"
17
#include "
Transformation.h
"
18
19
CentipedePairCartesian::CentipedePairCartesian
(
GraphicsScene
&scene,
20
const
Transformation
&transformation,
21
const
DocumentModelGuideline
&modelGuideline,
22
const
DocumentModelCoords
&
/* modelCoords */
,
23
const
QPointF &posScreen) :
24
m_modelGuideline (modelGuideline),
25
m_centipedeXT (nullptr),
26
m_centipedeYR (nullptr),
27
m_posScreenStart (posScreen),
28
m_selectedXTFinal (true),
29
m_valueFinal (0)
30
{
31
m_centipedeXT =
new
CentipedeSegmentConstantXLine
(scene,
32
modelGuideline,
33
transformation,
34
posScreen);
35
m_centipedeYR =
new
CentipedeSegmentConstantYLine
(scene,
36
modelGuideline,
37
transformation,
38
posScreen);
39
40
// Save starting graph position
41
transformation.
transformScreenToRawGraph
(posScreen,
42
m_posGraphStart);
43
}
44
45
CentipedePairCartesian::~CentipedePairCartesian
()
46
{
47
delete
m_centipedeXT;
48
delete
m_centipedeYR;
49
}
50
51
bool
CentipedePairCartesian::done
(
const
QPointF &posScreen)
52
{
53
QPointF delta = posScreen - m_posScreenStart;
54
double
distanceFromCenter =
magnitude
(delta);
55
56
return
(distanceFromCenter > m_modelGuideline.creationCircleRadius ());
57
}
58
59
void
CentipedePairCartesian::move
(
const
QPointF &posScreen)
60
{
61
QPointF delta = posScreen - m_posScreenStart;
62
double
distanceFromCenter =
magnitude
(delta);
63
64
if
(updateFinalValues (posScreen)) {
65
m_centipedeXT->updateRadius (m_modelGuideline.creationCircleRadius () + distanceFromCenter);
66
m_centipedeYR->updateRadius (m_modelGuideline.creationCircleRadius () - distanceFromCenter);
67
}
else
{
68
m_centipedeXT->updateRadius (m_modelGuideline.creationCircleRadius () - distanceFromCenter);
69
m_centipedeYR->updateRadius (m_modelGuideline.creationCircleRadius () + distanceFromCenter);
70
}
71
}
72
73
bool
CentipedePairCartesian::selectedXTFinal
()
const
74
{
75
return
m_selectedXTFinal;
76
}
77
78
bool
CentipedePairCartesian::updateFinalValues (
const
QPointF &posScreen)
79
{
80
// Update selection
81
double
distXT = m_centipedeXT->
distanceToClosestEndpoint
(posScreen);
82
double
distYR = m_centipedeYR->
distanceToClosestEndpoint
(posScreen);
83
m_selectedXTFinal = (distXT < distYR);
84
85
// Update value
86
if
(m_selectedXTFinal) {
87
m_valueFinal = m_posGraphStart.x();
88
}
else
{
89
m_valueFinal = m_posGraphStart.y();
90
}
91
92
return
m_selectedXTFinal;
93
}
94
95
double
CentipedePairCartesian::valueFinal
()
const
96
{
97
return
m_valueFinal;
98
}
CentipedePairCartesian.h
CentipedeSegmentAbstract.h
CentipedeSegmentConstantREllipse.h
CentipedeSegmentConstantTRadial.h
CentipedeSegmentConstantXLine.h
CentipedeSegmentConstantYLine.h
DocumentModelCoords.h
DocumentModelGuideline.h
GraphicsScene.h
Transformation.h
CentipedePairCartesian::move
void move(const QPointF &posScreen)
Follow cursor move.
Definition
CentipedePairCartesian.cpp:59
CentipedePairCartesian::selectedXTFinal
bool selectedXTFinal() const
True if XT is final selection, otherwise false if YR is final selection.
Definition
CentipedePairCartesian.cpp:73
CentipedePairCartesian::~CentipedePairCartesian
virtual ~CentipedePairCartesian()
Definition
CentipedePairCartesian.cpp:45
CentipedePairCartesian::valueFinal
double valueFinal() const
Final XT or YT (depending on selectedXTFinal) value.
Definition
CentipedePairCartesian.cpp:95
CentipedePairCartesian::done
bool done(const QPointF &posScreen)
True if cursor has moved far enough that the CentipedePairCartesian has finished and should be remove...
Definition
CentipedePairCartesian.cpp:51
CentipedePairCartesian::CentipedePairCartesian
CentipedePairCartesian(GraphicsScene &scene, const Transformation &transformation, const DocumentModelGuideline &modelGuideline, const DocumentModelCoords &modelCoords, const QPointF &posScreen)
Constructor with individual coordinates.
Definition
CentipedePairCartesian.cpp:19
CentipedeSegmentAbstract::distanceToClosestEndpoint
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const =0
Return distance to closest endpoint.
CentipedeSegmentConstantXLine
Centipede for constant XT using QGraphicsLineItem.
Definition
CentipedeSegmentConstantXLine.h:18
CentipedeSegmentConstantYLine
Centipede for constant YR using QGraphicsLineItem.
Definition
CentipedeSegmentConstantYLine.h:18
DocumentModelCoords
Model for DlgSettingsCoords and CmdSettingsCoords.
Definition
DocumentModelCoords.h:21
DocumentModelGuideline
Model for managing the coordinate values corresponding Guidelines.
Definition
DocumentModelGuideline.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
Transformation::transformScreenToRawGraph
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
Definition
Transformation.cpp:465
magnitude
double magnitude(const QPointF &vec)
Norm of vector.
Definition
mmsubs.cpp:193
mmsubs.h
Generated on
for Engauge Digitizer by
1.17.0