Engauge Digitizer  2
DigitizeStateCurve.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 "CmdAddPointGraph.h"
8 #include "CmdMediator.h"
9 #include "CursorFactory.h"
10 #include "DigitizeStateContext.h"
11 #include "DigitizeStateCurve.h"
12 #include "Logger.h"
13 #include "MainWindow.h"
14 #include "OrdinalGenerator.h"
15 #include <QCursor>
16 #include <QGraphicsScene>
17 #include <QImage>
18 #include <QSize>
19 #include "Transformation.h"
20 
23 {
24 }
25 
26 DigitizeStateCurve::~DigitizeStateCurve ()
27 {
28 }
29 
31 {
33 }
34 
36  DigitizeState /* previousState */)
37 {
38  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::begin";
39 
40  setCursor(cmdMediator);
41  context().setDragMode(QGraphicsView::NoDrag);
43 }
44 
45 bool DigitizeStateCurve::canPaste (const Transformation &transformation,
46  const QSize &size) const
47 {
48  return canPasteProtected (transformation,
49  size);
50 }
51 
52 QCursor DigitizeStateCurve::cursor(CmdMediator *cmdMediator) const
53 {
54  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateCurve::cursor";
55 
56  CursorFactory cursorFactory;
57  QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
58 
59  return cursor;
60 }
61 
63 {
64  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::end";
65 }
66 
68  const QString &pointIdentifier)
69 {
70  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleContextMenuEventAxis "
71  << " point=" << pointIdentifier.toLatin1 ().data ();
72 }
73 
75  const QStringList &pointIdentifiers)
76 {
77  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve ::handleContextMenuEventGraph "
78  << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
79 }
80 
82 {
83  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleCurveChange";
84 }
85 
87  Qt::Key key,
88  bool /* atLeastOneSelectedItem */)
89 {
90  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleKeyPress"
91  << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
92 }
93 
95  QPointF /* posScreen */)
96 {
97 // LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateCurve::handleMouseMove";
98 }
99 
101  QPointF /* posScreen */)
102 {
103  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleMousePress";
104 }
105 
107  QPointF posScreen)
108 {
109  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleMouseRelease";
110 
111  // Create command to add point
112  OrdinalGenerator ordinalGenerator;
113  Document &document = cmdMediator->document ();
114  const Transformation &transformation = context ().mainWindow ().transformation();
115  QUndoCommand *cmd = new CmdAddPointGraph (context ().mainWindow(),
116  document,
117  context ().mainWindow().selectedGraphCurve(),
118  posScreen,
119  ordinalGenerator.generateCurvePointOrdinal(document,
120  transformation,
121  posScreen,
122  activeCurve ()));
123  context().appendNewCmd(cmdMediator,
124  cmd);
125 }
126 
128 {
129  return "DigitizeStateCurve";
130 }
131 
133 {
134  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::updateAfterPointAddition";
135 }
136 
138  const DocumentModelDigitizeCurve & /*modelDigitizeCurve */)
139 {
140  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::updateModelDigitizeCurve";
141 
142  setCursor(cmdMediator);
143 }
144 
146 {
147  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::updateModelSegments";
148 }
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
Transformation transformation() const
Return read-only copy of transformation.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
Create standard cross cursor, or custom cursor, according to settings.
Definition: CursorFactory.h:15
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
DigitizeStateCurve(DigitizeStateContext &context)
Single constructor.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
virtual QString state() const
State name for debugging.
bool canPasteProtected(const Transformation &transformation, const QSize &viewSize) const
Protected version of canPaste method. Some, but not all, leaf classes use this method.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
Affine transformation between screen and graph coordinates, based on digitized axis points...
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual bool canPaste(const Transformation &transformation, const QSize &viewSize) const
Return true if there is good data in the clipboard for pasting, and that is compatible with the curre...
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition: Document.cpp:703
Command for adding one graph point.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity...
virtual void handleMouseMove(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
Utility class for generating ordinal numbers.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
Command queue stack.
Definition: CmdMediator.h:23
Model for DlgSettingsSegments and CmdSettingsSegments.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
double generateCurvePointOrdinal(const Document &document, const Transformation &transformation, const QPointF &posScreen, const QString &curveName)
Select ordinal so new point curve passes smoothly through existing points.
QCursor generate(const DocumentModelDigitizeCurve &modelDigitizeCurve) const
Factory method to generate standard or custom cursor.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.