Engauge Digitizer  2
 All Classes Functions Variables Typedefs Enumerations Friends Pages
TransformationStateContext.cpp
1 /******************************************************************************************************
2  * (C) 2014 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 "CmdMediator.h"
8 #include "EngaugeAssert.h"
9 #include "Logger.h"
10 #include <QGraphicsScene>
11 #include <QImage>
12 #include "TransformationStateAbstractBase.h"
13 #include "TransformationStateContext.h"
14 #include "TransformationStateDefined.h"
15 #include "TransformationStateUndefined.h"
16 
18  bool isGnuplot) :
19  m_isGnuplot (isGnuplot)
20 {
21  m_states.insert (TRANSFORMATION_STATE_DEFINED , new TransformationStateDefined (*this, scene));
22  m_states.insert (TRANSFORMATION_STATE_UNDEFINED, new TransformationStateUndefined (*this, scene));
23  ENGAUGE_ASSERT (m_states.size () == NUM_TRANSFORMATION_STATES);
24 
25  m_currentState = NUM_TRANSFORMATION_STATES; // Value that forces a transition right away
26 }
27 
28 TransformationStateContext::~TransformationStateContext()
29 {
30 }
31 
33 {
34  return m_isGnuplot;
35 }
36 
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateContext::resetOnLoad";
40 
41  m_currentState = NUM_TRANSFORMATION_STATES;
42 }
43 
45  TransformationState transformationState,
46  CmdMediator &cmdMediator,
47  const Transformation &transformation,
48  const QString &selectedGraphCurve)
49 {
50  LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateContext::triggerStateTransition";
51 
52  // Transition even if we are already at the requested state (transformationState == m_currentState) to
53  // allow self-transitions. Those allow clean refreshing of the axis checker
54 
55  // End the current state if there is one
56  if (m_currentState != NUM_TRANSFORMATION_STATES) {
57  m_states[m_currentState]->end(cmdMediator,
58  transformation);
59  }
60 
61  m_currentState = transformationState;
62 
63  // Start the requested state
64  m_states[m_currentState]->begin(isGnuplot,
65  cmdMediator,
66  transformation,
67  selectedGraphCurve);
68 }
69 
71  const Transformation &transformation)
72 {
73  LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateContext::updateAxesChecker";
74 
75  // Skip if there is no image so the state has not yet been set yet
76  if (m_currentState < NUM_TRANSFORMATION_STATES) {
77 
78  m_states[m_currentState]->updateAxesChecker (cmdMediator,
79  transformation);
80 
81  }
82 }
Class to show transformation since transformation is defined.
Class to not show transformation since transformation is undefined.
bool isGnuplot() const
Flag for gnuplot debug files.
Affine transformation between screen and graph coordinates, based on digitized axis points...
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded...
Command queue stack.
Definition: CmdMediator.h:23
TransformationStateContext(QGraphicsScene &scene, bool isGnuplot)
Single constructor.
void updateAxesChecker(CmdMediator &cmdMediator, const Transformation &transformation)
Apply the new DocumentModelAxesChecker.
void triggerStateTransition(bool isGnuplot, TransformationState transformationState, CmdMediator &cmdMediator, const Transformation &transformation, const QString &selectedGraphCurve)
Trigger a state transition to be performed immediately.