Engauge Digitizer 2
Loading...
Searching...
No Matches
CentipedeStateContext.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 "CentipedeState.h"
12#include "CmdGuidelineAddXT.h"
13#include "CmdGuidelineAddYR.h"
15#include "EngaugeAssert.h"
16#include "GraphicsScene.h"
17#include "Logger.h"
18#include "MainWindow.h"
19#include <QObject>
20#include "Transformation.h"
21
23 m_stateGuideline (stateGuideline),
24 m_scene (nullptr),
25 m_transformation (nullptr)
26{
27 // These states follow the same order as the CentipedeState enumeration
29 m_states.insert (CENTIPEDE_STATE_BUILD_POLAR , new CentipedeStateBuildPolar (*this));
30 m_states.insert (CENTIPEDE_STATE_PREBUILD , new CentipedeStatePrebuild (*this));
31 ENGAUGE_ASSERT (m_states.size () == NUM_CENTIPEDE_STATES);
32
33 m_currentState = NUM_CENTIPEDE_STATES; // Value that forces a transition right away
35}
36
38{
39 // Remove states, one of which may have incomplete in-work graphics items
40 QVector<CentipedeStateAbstractBase*>::iterator itr;
41 for (itr = m_states.begin (); itr != m_states.end (); itr++) {
42 CentipedeStateAbstractBase *state = *itr;
43 delete state;
44 }
45
46 m_states.clear();
47
48 delete m_scene;
49 delete m_transformation;
50}
51
52void CentipedeStateContext::completeRequestedStateTransitionIfExists ()
53{
54 if (m_currentState != m_requestedState) {
55
56 // A transition is waiting so perform it
57
58 if (m_currentState != NUM_CENTIPEDE_STATES) {
59
60 // This is not the first state so close the previous state
61 m_states [m_currentState]->end ();
62 }
63
64 // Start the new state
65 m_currentState = m_requestedState;
66 m_states [m_requestedState]->begin ();
67 }
68}
69
71 double selectedValue)
72{
73 m_stateGuideline.createGuidelineCommand (selectedXT,
74 selectedValue);
75}
76
78 bool atLeastOneSelectedItem)
79{
80 m_states [m_currentState]->handleKeyPress (key,
81 atLeastOneSelectedItem);
82
83 completeRequestedStateTransitionIfExists();
84
85}
86
88{
89 m_states [m_currentState]->handleMouseMove (pos);
90
91 completeRequestedStateTransitionIfExists();
92
93}
94
99 QPointF pos,
100 bool clickedOnItem)
101{
102 // If a graphics item can be, or was, selected then do not create a new CentipedePair (by
103 // skipping the state transition
104 if (!clickedOnItem) {
105
106 // Forward context variables
107 m_scene = scene;
108 m_transformation = new Transformation (transformation);
109 m_modelGuideline = modelGuideline;
110 m_modelCoords = modelCoords;
111 m_posClickScreen = pos;
112
113 m_states [m_currentState]->handleMousePress (pos);
114
115 completeRequestedStateTransitionIfExists();
116 }
117}
118
120{
121 m_states [m_currentState]->handleMouseRelease (pos);
122
123 completeRequestedStateTransitionIfExists();
124}
125
127{
128 return m_modelCoords;
129}
130
132{
133 return m_modelGuideline;
134}
135
137{
138 return m_posClickScreen;
139}
140
142{
143 m_requestedState = centipedeState;
144}
145
147{
148 m_requestedState = centipedeState;
149 completeRequestedStateTransitionIfExists();
150}
151
153{
154 return *m_scene;
155}
156
158{
159 return *m_transformation;
160}
CentipedeState
Set of possible states of Centipede construction.
@ NUM_CENTIPEDE_STATES
@ CENTIPEDE_STATE_BUILD_CARTESIAN
@ CENTIPEDE_STATE_PREBUILD
@ CENTIPEDE_STATE_BUILD_POLAR
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
Base class for CentipedePair states.
Class for period while building cartesian centipedes.
Class for period while building polar centipedes.
DocumentModelCoords modelCoords() const
Get method for forwarded DocumentModelCoords.
GraphicsScene & scene() const
Get method for forwarded GraphicsScene.
CentipedeStateContext(DigitizeStateGuideline &stateGuideline)
Single constructor.
virtual void handleMouseMove(QPointF posScreen)
DocumentModelGuideline modelGuideline() const
Get method for forwarded DocumentModelGuideline.
virtual void handleMousePress(GraphicsScene *scene, const Transformation &transformation, const DocumentModelGuideline &modelGuideline, const DocumentModelCoords &modelCoords, QPointF posScreen, bool clickedOnItem)
QPointF posClickScreen() const
Get method for forwarded click point.
Transformation transformation() const
Get method for forwarded Transformation.
virtual void handleMouseRelease(QPointF posScreen)
void requestDelayedStateTransition(CentipedeState centipedeState)
Initiate state transition to be performed later, when CentipedeState is off the stack.
void createGuidelineCommand(bool selectedXTFinal, double valueFinal)
Create a command for creating a Guideline.
void requestImmediateStateTransition(CentipedeState centipedeState)
Perform immediate state transition for immediate action. Called when states are off the stack.
virtual void handleKeyPress(Qt::Key key, bool atLeastOneSelectedItem)
Class for period between build states.
Digitizing state for creating, moving and removing guidelines.
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.