Engauge Digitizer 2
Loading...
Searching...
No Matches
CentipedePairPolar.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
13#include "DocumentModelCoords.h"
15#include "GraphicsScene.h"
16#include "mmsubs.h"
17#include "Transformation.h"
18
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 // Create visible Centipede items
32 m_centipedeXT = new CentipedeSegmentConstantTRadial (scene,
33 modelCoords,
34 modelGuideline,
35 transformation,
36 posScreen);
37 m_centipedeYR = new CentipedeSegmentConstantREllipse (scene,
38 modelCoords,
39 modelGuideline,
40 transformation,
41 posScreen);
42
43 // Save starting graph position
44 transformation.transformScreenToRawGraph(posScreen,
45 m_posGraphStart);
46}
47
49{
50 delete m_centipedeXT;
51 delete m_centipedeYR;
52}
53
54bool CentipedePairPolar::done (const QPointF &posScreen)
55{
56 QPointF delta = posScreen - m_posScreenStart;
57 double distanceFromCenter = magnitude (delta);
58
59 return (distanceFromCenter > m_modelGuideline.creationCircleRadius ());
60}
61
62void CentipedePairPolar::move (const QPointF &posScreen)
63{
64 QPointF delta = posScreen - m_posScreenStart;
65 double distanceFromCenter = magnitude (delta);
66
67 if (updateFinalValues (posScreen)) {
68 m_centipedeXT->updateRadius (m_modelGuideline.creationCircleRadius () + distanceFromCenter);
69 m_centipedeYR->updateRadius (m_modelGuideline.creationCircleRadius () - distanceFromCenter);
70 } else {
71 m_centipedeXT->updateRadius (m_modelGuideline.creationCircleRadius () - distanceFromCenter);
72 m_centipedeYR->updateRadius (m_modelGuideline.creationCircleRadius () + distanceFromCenter);
73 }
74}
75
77{
78 return m_selectedXTFinal;
79}
80
81bool CentipedePairPolar::updateFinalValues (const QPointF &posScreen)
82{
83 // Update selection
84 double distXT = m_centipedeXT->distanceToClosestEndpoint (posScreen);
85 double distYR = m_centipedeYR->distanceToClosestEndpoint (posScreen);
86 m_selectedXTFinal = (distXT < distYR);
87
88 // Update value
89 if (m_selectedXTFinal) {
90 m_valueFinal = m_posGraphStart.x();
91 } else {
92 m_valueFinal = m_posGraphStart.y();
93 }
94
95 return m_selectedXTFinal;
96}
97
99{
100 return m_valueFinal;
101}
void move(const QPointF &posScreen)
Follow cursor move.
CentipedePairPolar(GraphicsScene &scene, const Transformation &transformation, const DocumentModelGuideline &modelGuideline, const DocumentModelCoords &modelCoords, const QPointF &posScreen)
Constructor with individual coordinates.
bool selectedXTFinal() const
True if XT is final selection, otherwise false if YR is final selection.
double valueFinal() const
Final XT or YT (depending on selectedXTFinal) value.
bool done(const QPointF &posScreen)
True if cursor has moved far enough that the CentipedePairPolar has finished and should be removed.
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const =0
Return distance to closest endpoint.
Centipede for constant T radial using QGraphicsLineItem.
Model for DlgSettingsCoords and CmdSettingsCoords.
Model for managing the coordinate values corresponding Guidelines.
Add point and line handling to generic QGraphicsScene.
Affine transformation between screen and graph coordinates, based on digitized axis points.
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
double magnitude(const QPointF &vec)
Norm of vector.
Definition mmsubs.cpp:193