Engauge Digitizer 2
Loading...
Searching...
No Matches
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 "DlgEditPoint.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
28
29DigitizeStateAxis::~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
48void DigitizeStateAxis::createTemporaryPoint (CmdMediator *cmdMediator,
49 const QPointF &posScreen)
50{
51 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::createTemporaryPoint";
52
53 // Temporary point that user can see while DlgEditPoint is active
54 const Curve &curveAxes = cmdMediator->curveAxes();
55 PointStyle pointStyleAxes = curveAxes.curveStyle().pointStyle();
57 pointStyleAxes,
58 posScreen);
59
61 point);
62}
63
64QCursor DigitizeStateAxis::cursor(CmdMediator *cmdMediator) const
65{
66 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::cursor";
67
68 CursorFactory cursorFactory;
69 QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
70
71 return cursor;
72}
73
75{
76 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::end";
77}
78
80{
81 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleCurveChange";
82}
83
85 Qt::Key key,
86 bool /* atLeastOneSelectedItem */)
87{
88 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleKeyPress"
89 << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
90}
91
93 QPointF /* posScreen */)
94{
95// LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::handleMouseMove";
96}
97
99 QPointF /* posScreen */)
100{
101 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMousePress";
102}
103
105 QPointF posScreen)
106{
107 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMouseRelease";
108
109 if (context().mainWindow().transformIsDefined()) {
110
111 QMessageBox::warning (0,
112 QObject::tr ("Application"),
113 QObject::tr ("Three axis points have been defined, and no more are needed or allowed."));
114
115 } else {
116
117 createTemporaryPoint (cmdMediator,
118 posScreen);
119
120 // Ask user for coordinates
121 DlgEditPoint *dlg = new DlgEditPoint (context ().mainWindow (),
122 *this,
123 cmdMediator->document().modelCoords(),
124 context().mainWindow().modelMainWindow(),
125 cursor (cmdMediator),
126 context().mainWindow().transformation(),
127 cmdMediator->document().documentAxesPointsRequired());
128 int rtn = dlg->exec ();
129
130 bool isXOnly;
131 QPointF posGraph = dlg->posGraph (isXOnly);
132 delete dlg;
133
134 // Remove temporary point
136
137 if (rtn == QDialog::Accepted) {
138
139 // User wants to add this axis point, but let's perform sanity checks first
140
141 bool isError;
142 QString errorMessage;
143 int nextOrdinal = cmdMediator->document().nextOrdinalForCurve(AXIS_CURVE_NAME);
144
145 cmdMediator->document().checkAddPointAxis(posScreen,
146 posGraph,
147 isError,
148 errorMessage,
149 isXOnly);
150
151 if (isError) {
152
153 QMessageBox::warning (0,
154 QObject::tr ("Application"),
155 errorMessage);
156
157 } else {
158
159 // Create command to add point
160 Document &document = cmdMediator->document ();
161 QUndoCommand *cmd = new CmdAddPointAxis (context ().mainWindow(),
162 document,
163 posScreen,
164 posGraph,
165 nextOrdinal,
166 isXOnly);
167 context().appendNewCmd(cmdMediator,
168 cmd);
169 }
170 }
171 }
172}
173
175{
176 return "DigitizeStateAxis";
177}
178
180 const DocumentModelDigitizeCurve & /*modelDigitizeCurve */)
181{
182 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelDigitizeCurve";
183
184 setCursor(cmdMediator);
185}
186
188{
189 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelSegments";
190}
Command for adding one axis point.
Command queue stack.
Definition CmdMediator.h:24
const Curve & curveAxes() const
See Document::curveAxes.
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Create standard cross cursor, or custom cursor, according to settings.
QCursor generate(const DocumentModelDigitizeCurve &modelDigitizeCurve) const
Factory method to generate standard or custom cursor.
PointStyle pointStyle() const
Get method for PointStyle.
Container for one set of digitized Points.
Definition Curve.h:33
CurveStyle curveStyle() const
Return the curve style.
Definition Curve.cpp:138
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses,...
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
DigitizeStateAxis(DigitizeStateContext &context)
Single constructor.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
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 updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual QString state() const
State name for debugging.
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 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.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
Dialog box for editing the information of one axis point.
QPointF posGraph(bool &isXOnly) const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Model for DlgSettingsSegments and CmdSettingsSegments.
Storage of one imported image and the data attached to that image.
Definition Document.h:41
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition Document.cpp:625
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition Document.cpp:674
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition Document.cpp:611
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition Document.cpp:326
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:233
Graphics item for drawing a circular or polygonal Point.
void addTemporaryPoint(const QString &identifier, GraphicsPoint *point)
Add one temporary point to m_graphicsLinesForCurves. Non-temporary points are handled by the updateLi...
void removePoint(const QString &identifier)
Remove specified point. This aborts if the point does not exist.
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
Details for a specific Point.
Definition PointStyle.h:21
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
Definition Point.cpp:501