Engauge Digitizer  2
DigitizeStateAxis.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 "CmdAddPointAxis.h"
8 #include "CmdMediator.h"
9 #include "CursorFactory.h"
10 #include "DigitizeStateAxis.h"
11 #include "DigitizeStateContext.h"
12 #include "DlgEditPointAxis.h"
13 #include "Document.h"
14 #include "GraphicsScene.h"
15 #include "GraphicsView.h"
16 #include "Logger.h"
17 #include "MainWindow.h"
18 #include "PointStyle.h"
19 #include <QCursor>
20 #include <QImage>
21 #include <QMessageBox>
22 #include <QTimer>
23 
26 {
27 }
28 
29 DigitizeStateAxis::~DigitizeStateAxis ()
30 {
31 }
32 
34 {
35  return AXIS_CURVE_NAME;
36 }
37 
39  DigitizeState /* previousState */)
40 {
41  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::begin";
42 
43  setCursor(cmdMediator);
44  context().setDragMode(QGraphicsView::NoDrag);
46 }
47 
48 bool DigitizeStateAxis::canPaste (const Transformation & /* transformation */,
49  const QSize & /* size */) const
50 {
51  return false;
52 }
53 
54 void DigitizeStateAxis::createTemporaryPoint (CmdMediator *cmdMediator,
55  const QPointF &posScreen)
56 {
57  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::createTemporaryPoint";
58 
59  GeometryWindow *NULL_GEOMETRY_WINDOW = 0;
60 
61  // Temporary point that user can see while DlgEditPointAxis is active
62  const Curve &curveAxes = cmdMediator->curveAxes();
63  PointStyle pointStyleAxes = curveAxes.curveStyle().pointStyle();
65  pointStyleAxes,
66  posScreen,
67  NULL_GEOMETRY_WINDOW);
68 
70  point);
71 }
72 
73 QCursor DigitizeStateAxis::cursor(CmdMediator *cmdMediator) const
74 {
75  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::cursor";
76 
77  CursorFactory cursorFactory;
78  QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
79 
80  return cursor;
81 }
82 
84 {
85  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::end";
86 }
87 
89  const QString &pointIdentifier)
90 {
91  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleContextMenuEventAxis "
92  << " point=" << pointIdentifier.toLatin1 ().data ();
93 }
94 
96  const QStringList &pointIdentifiers)
97 {
98  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleContextMenuEventGraph "
99  << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
100 }
101 
103 {
104  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleCurveChange";
105 }
106 
108  Qt::Key key,
109  bool /* atLeastOneSelectedItem */)
110 {
111  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleKeyPress"
112  << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
113 }
114 
116  QPointF /* posScreen */)
117 {
118 // LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::handleMouseMove";
119 }
120 
122  QPointF /* posScreen */)
123 {
124  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMousePress";
125 }
126 
128  QPointF posScreen)
129 {
130  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMouseRelease";
131 
132  if (context().mainWindow().transformIsDefined()) {
133 
134  QMessageBox::warning (0,
135  QObject::tr ("Engauge Digitizer"),
136  QObject::tr ("Three axis points have been defined, and no more are needed or allowed."));
137 
138  } else {
139 
140  createTemporaryPoint (cmdMediator,
141  posScreen);
142 
143  // Ask user for coordinates
144  DlgEditPointAxis *dlg = new DlgEditPointAxis (context ().mainWindow (),
145  cmdMediator->document().modelCoords(),
146  cmdMediator->document().modelGeneral(),
149  cmdMediator->document().documentAxesPointsRequired());
150  int rtn = dlg->exec ();
151 
152  bool isXOnly;
153  QPointF posGraph = dlg->posGraph (isXOnly);
154  delete dlg;
155 
156  // Remove temporary point
158 
159  if (rtn == QDialog::Accepted) {
160 
161  // User wants to add this axis point, but let's perform sanity checks first
162 
163  bool isError;
164  QString errorMessage;
165  int nextOrdinal = cmdMediator->document().nextOrdinalForCurve(AXIS_CURVE_NAME);
166 
167  cmdMediator->document().checkAddPointAxis(posScreen,
168  posGraph,
169  isError,
170  errorMessage,
171  isXOnly);
172 
173  if (isError) {
174 
175  QMessageBox::warning (0,
176  QObject::tr ("Engauge Digitizer"),
177  errorMessage);
178 
179  } else {
180 
181  // Create command to add point
182  Document &document = cmdMediator->document ();
183  QUndoCommand *cmd = new CmdAddPointAxis (context ().mainWindow(),
184  document,
185  posScreen,
186  posGraph,
187  nextOrdinal,
188  isXOnly);
189  context().appendNewCmd(cmdMediator,
190  cmd);
191  }
192  }
193  }
194 }
195 
197 {
198  return "DigitizeStateAxis";
199 }
200 
202 {
203  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateAfterPointAddition";
204 }
205 
207  const DocumentModelDigitizeCurve & /*modelDigitizeCurve */)
208 {
209  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelDigitizeCurve";
210 
211  setCursor(cmdMediator);
212 }
213 
215 {
216  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelSegments";
217 }
Dialog box for editing the information of one axis point, in a graph with two axes.
const Curve & curveAxes() const
See Document::curveAxes.
Definition: CmdMediator.cpp:57
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
void removePoint(const QString &identifier)
Remove specified point. This aborts if the point does not exist.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual QString state() const
State name for debugging.
Create standard cross cursor, or custom cursor, according to settings.
Definition: CursorFactory.h:15
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition: Document.cpp:759
PointStyle pointStyle() const
Get method for PointStyle.
Definition: CurveStyle.cpp:75
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Definition: Document.cpp:717
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition: Document.cpp:360
Window that displays the geometry information, as a table, for the current curve. ...
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
void checkAddPointAxis(const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage, bool isXOnly)
Check before calling addPointAxis. Also returns the next available ordinal number (to prevent clashes...
Definition: Document.cpp:265
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
MainWindow & mainWindow()
Reference to the MainWindow, without const.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
Definition: Point.cpp:507
Transformation transformation() const
Return read-only copy of transformation.
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...
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity...
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen, GeometryWindow *geometryWindow)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition: Document.cpp:703
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Affine transformation between screen and graph coordinates, based on digitized axis points...
Details for a specific Point.
Definition: PointStyle.h:20
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
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...
Command for adding one axis point.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
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...
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
Container for one set of digitized Points.
Definition: Curve.h:33
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
MainWindowModel modelMainWindow() const
Get method for main window model.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
Command queue stack.
Definition: CmdMediator.h:23
void addTemporaryPoint(const QString &identifier, GraphicsPoint *point)
Add one temporary point to m_graphicsLinesForCurves. Non-temporary points are handled by the updateLi...
Model for DlgSettingsSegments and CmdSettingsSegments.
CurveStyle curveStyle() const
Return the curve style.
Definition: Curve.cpp:148
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
DigitizeStateAxis(DigitizeStateContext &context)
Single constructor.
QCursor generate(const DocumentModelDigitizeCurve &modelDigitizeCurve) const
Factory method to generate standard or custom cursor.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:689
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...