Engauge Digitizer 2
Loading...
Searching...
No Matches
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
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 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
46{
47 delete m_centipedeXT;
48 delete m_centipedeYR;
49}
50
51bool 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
59void 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
74{
75 return m_selectedXTFinal;
76}
77
78bool 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
96{
97 return m_valueFinal;
98}
void move(const QPointF &posScreen)
Follow cursor move.
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 CentipedePairCartesian has finished and should be remove...
CentipedePairCartesian(GraphicsScene &scene, const Transformation &transformation, const DocumentModelGuideline &modelGuideline, const DocumentModelCoords &modelCoords, const QPointF &posScreen)
Constructor with individual coordinates.
virtual double distanceToClosestEndpoint(const QPointF &posScreen) const =0
Return distance to closest endpoint.
Centipede for constant XT using QGraphicsLineItem.
Centipede for constant YR 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