Engauge Digitizer  2
TransformationStateContext.cpp
Go to the documentation of this file.
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>
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 
29 {
30  qDeleteAll (m_states);
31 }
32 
34 {
35  return m_isGnuplot;
36 }
37 
39 {
40  LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateContext::resetOnLoad";
41 
42  m_currentState = NUM_TRANSFORMATION_STATES;
43 }
44 
46  TransformationState transformationState,
47  CmdMediator &cmdMediator,
48  const Transformation &transformation,
49  const QString &selectedGraphCurve)
50 {
51  LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateContext::triggerStateTransition";
52 
53  // Transition even if we are already at the requested state (transformationState == m_currentState) to
54  // allow self-transitions. Those allow clean refreshing of the axis checker
55 
56  // End the current state if there is one
57  if (m_currentState != NUM_TRANSFORMATION_STATES) {
58  m_states[m_currentState]->end(cmdMediator,
59  transformation);
60  }
61 
62  m_currentState = transformationState;
63 
64  // Start the requested state
65  m_states[m_currentState]->begin(isGnuplot,
66  cmdMediator,
67  transformation,
68  selectedGraphCurve);
69 }
70 
72  const Transformation &transformation)
73 {
74  LOG4CPP_INFO_S ((*mainCat)) << "TransformationStateContext::updateAxesChecker";
75 
76  // Skip if there is no image so the state has not yet been set yet
77  if (m_currentState < NUM_TRANSFORMATION_STATES) {
78 
79  m_states[m_currentState]->updateAxesChecker (cmdMediator,
80  transformation);
81 
82  }
83 }
TransformationStateDefined.h
TransformationStateDefined
Class to show transformation since transformation is defined.
Definition: TransformationStateDefined.h:17
TransformationStateContext::updateAxesChecker
void updateAxesChecker(CmdMediator &cmdMediator, const Transformation &transformation)
Apply the new DocumentModelAxesChecker.
Definition: TransformationStateContext.cpp:71
TransformationStateContext::~TransformationStateContext
virtual ~TransformationStateContext()
Definition: TransformationStateContext.cpp:28
CmdMediator.h
TransformationState
TransformationState
Set of possible states of axes transformation.
Definition: TransformationStateAbstractBase.h:17
Transformation
Affine transformation between screen and graph coordinates, based on digitized axis points.
Definition: Transformation.h:30
EngaugeAssert.h
TRANSFORMATION_STATE_UNDEFINED
Definition: TransformationStateAbstractBase.h:19
TransformationStateAbstractBase.h
NUM_TRANSFORMATION_STATES
Definition: TransformationStateAbstractBase.h:20
TransformationStateContext::TransformationStateContext
TransformationStateContext(QGraphicsScene &scene, bool isGnuplot)
Single constructor.
Definition: TransformationStateContext.cpp:17
Logger.h
LOG4CPP_INFO_S
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
TransformationStateUndefined
Class to not show transformation since transformation is undefined.
Definition: TransformationStateUndefined.h:12
TransformationStateContext::isGnuplot
bool isGnuplot() const
Flag for gnuplot debug files.
Definition: TransformationStateContext.cpp:33
TransformationStateContext::resetOnLoad
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded.
Definition: TransformationStateContext.cpp:38
mainCat
log4cpp::Category * mainCat
Definition: Logger.cpp:14
TRANSFORMATION_STATE_DEFINED
Definition: TransformationStateAbstractBase.h:18
CmdMediator
Command queue stack.
Definition: CmdMediator.h:22
TransformationStateUndefined.h
TransformationStateContext.h
TransformationStateContext::triggerStateTransition
void triggerStateTransition(bool isGnuplot, TransformationState transformationState, CmdMediator &cmdMediator, const Transformation &transformation, const QString &selectedGraphCurve)
Trigger a state transition to be performed immediately.
Definition: TransformationStateContext.cpp:45
ENGAUGE_ASSERT
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:19