Engauge Digitizer 2
Loading...
Searching...
No Matches
DigitizeStateAxis.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 "CmdAddPointAxis.h"
8#include "CmdMediator.h"
9#include "CursorFactory.h"
10#include "DigitizeStateAxis.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
28
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);
47}
48
49bool DigitizeStateAxis::canPaste (const Transformation & /* transformation */,
50 const QSize & /* size */) const
51{
52 return false;
53}
54
55void DigitizeStateAxis::createTemporaryPoint (CmdMediator *cmdMediator,
56 const QPointF &posScreen)
57{
58 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::createTemporaryPoint";
59
60 GeometryWindow *NULL_GEOMETRY_WINDOW = nullptr;
61
62 // Temporary point that user can see while DlgEditPointAxis is active
63 const Curve &curveAxes = cmdMediator->curveAxes();
64 PointStyle pointStyleAxes = curveAxes.curveStyle().pointStyle();
66 pointStyleAxes,
67 posScreen,
68 NULL_GEOMETRY_WINDOW);
69
71 point);
72}
73
74QCursor DigitizeStateAxis::cursor(CmdMediator *cmdMediator) const
75{
76 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::cursor";
77
78 CursorFactory cursorFactory;
79 QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
80
81 return cursor;
82}
83
85{
86 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::end";
87}
88
90{
91 return false;
92}
93
95 const QString &pointIdentifier)
96{
97 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleContextMenuEventAxis "
98 << " point=" << pointIdentifier.toLatin1 ().data ();
99}
100
102 const QStringList &pointIdentifiers)
103{
104 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleContextMenuEventGraph "
105 << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
106}
107
109{
110 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleCurveChange";
111}
112
114 Qt::Key key,
115 bool /* atLeastOneSelectedItem */)
116{
117 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleKeyPress"
118 << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
119}
120
122 QPointF /* posScreen */)
123{
124// LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::handleMouseMove";
125}
126
128 QPointF /* posScreen */)
129{
130 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMousePress";
131}
132
134 QPointF posScreen)
135{
136 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMouseRelease";
137
138 if (context().mainWindow().transformIsDefined()) {
139
140 QMessageBox::warning (nullptr,
141 QObject::tr ("Engauge Digitizer"),
142 QObject::tr ("Three axis points have been defined, and no more are needed or allowed."));
143
144 } else {
145
146 createTemporaryPoint (cmdMediator,
147 posScreen);
148
149 // Ask user for coordinates
150 DlgEditPointAxis *dlg = new DlgEditPointAxis (context ().mainWindow (),
151 cmdMediator->document().modelCoords(),
152 cmdMediator->document().modelGeneral(),
153 context().mainWindow().modelMainWindow(),
154 context().mainWindow().transformation(),
155 cmdMediator->document().documentAxesPointsRequired());
156 int rtn = dlg->exec ();
157
158 bool isXOnly;
159 QPointF posGraph = dlg->posGraph (isXOnly);
160 delete dlg;
161
162 // Remove temporary point
164
165 if (rtn == QDialog::Accepted) {
166
167 // User wants to add this axis point, but let's perform sanity checks first
168
169 bool isError;
170 QString errorMessage;
171 int nextOrdinal = cmdMediator->document().nextOrdinalForCurve(AXIS_CURVE_NAME);
172
173 cmdMediator->document().checkAddPointAxis(posScreen,
174 posGraph,
175 isError,
176 errorMessage,
177 isXOnly);
178
179 if (isError) {
180
181 QMessageBox::warning (nullptr,
182 QObject::tr ("Engauge Digitizer"),
183 errorMessage);
184
185 } else {
186
187 // Create command to add point
188 Document &document = cmdMediator->document ();
189 QUndoCommand *cmd = new CmdAddPointAxis (context ().mainWindow(),
190 document,
191 posScreen,
192 posGraph,
193 nextOrdinal,
194 isXOnly);
195 context().appendNewCmd(cmdMediator,
196 cmd);
197 }
198 }
199 }
200}
201
203{
204 return "DigitizeStateAxis";
205}
206
208{
209 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateAfterPointAddition";
210}
211
213 const DocumentModelDigitizeCurve & /*modelDigitizeCurve */)
214{
215 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelDigitizeCurve";
216
217 setCursor(cmdMediator);
218}
219
221{
222 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelSegments";
223}
const QString AXIS_CURVE_NAME
DigitizeState
Set of possible states of Digitize toolbar.
log4cpp::Category * mainCat
Definition Logger.cpp:14
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:34
CurveStyle curveStyle() const
Return the curve style.
Definition Curve.cpp:149
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
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 void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, 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.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
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 bool guidelinesAreSelectable() const
Enable/disable guidelines according to state.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
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.
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, in a graph with two axes.
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:44
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Definition Document.cpp:726
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition Document.cpp:712
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition Document.cpp:775
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition Document.cpp:698
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition Document.cpp:366
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:271
Window that displays the geometry information, as a table, for the current curve.
Graphics item for drawing a circular or polygonal Point.
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...
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.
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
void handleGuidelinesActiveChange(bool active)
Handle Guidelines active status toggle.
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:519
Affine transformation between screen and graph coordinates, based on digitized axis points.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20