Engauge Digitizer 2
Loading...
Searching...
No Matches
DigitizeStateSegment.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 "CmdAddPointsGraph.h"
10#include "EngaugeAssert.h"
11#include "GraphicsScene.h"
12#include "Logger.h"
13#include "MainWindow.h"
14#include "OrdinalGenerator.h"
15#include <QGraphicsPixmapItem>
16#include <QGraphicsScene>
17#include <QImage>
18#include <QSize>
19#include "Segment.h"
20#include "SegmentFactory.h"
21#include "Transformation.h"
22
27
31
36
38 DigitizeState /* previousState */)
39{
40 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::begin";
41
42 m_cmdMediator = cmdMediator; // Save for slotMouseClickOnSegment
43
44 setCursor(cmdMediator);
45 context().setDragMode(QGraphicsView::NoDrag);
48
49 handleCurveChange(cmdMediator);
50}
51
53 const QSize &viewSize) const
54{
55 return canPasteProtected (transformation,
56 viewSize);
57}
58
59QCursor DigitizeStateSegment::cursor(CmdMediator * /* cmdMediator */) const
60{
61 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateSegment::cursor";
62
63 return QCursor (Qt::ArrowCursor);
64}
65
67{
68 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::end";
69
71 SegmentFactory segmentFactory (dynamic_cast<QGraphicsScene &> (scene),
72 context().isGnuplot());
73
74 segmentFactory.clearSegments(m_segments);
75}
76
78{
79 return false;
80}
81
83 const QString &pointIdentifier)
84{
85 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::handleContextMenuEventAxis "
86 << " point=" << pointIdentifier.toLatin1 ().data ();
87}
88
90 const QStringList &pointIdentifiers)
91{
92 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment ::handleContextMenuEventGraph "
93 << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
94}
95
97{
98 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::handleCurveChange";
99
100 QImage img = context().mainWindow().imageFiltered();
101
102 GraphicsScene &scene = context().mainWindow().scene();
103 SegmentFactory segmentFactory (dynamic_cast<QGraphicsScene &> (scene),
104 context().isGnuplot());
105
106 segmentFactory.clearSegments (m_segments);
107
108 // Create new segments
109 segmentFactory.makeSegments (img,
110 cmdMediator->document().modelSegments(),
111 m_segments);
112
113 // Connect signals of the new segments
114 QList<Segment*>::iterator itr;
115 for (itr = m_segments.begin(); itr != m_segments.end(); itr++) {
116 Segment *segment = *itr;
117
118 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::handleCurveChange"
119 << " lines=" << segment->lineCount();
120
121 connect (segment, SIGNAL (signalMouseClickOnSegment (QPointF)), this, SLOT (slotMouseClickOnSegment (QPointF)));
122 }
123}
124
126 Qt::Key key,
127 bool /* atLeastOneSelectedItem */)
128{
129 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::handleKeyPress"
130 << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
131}
132
134 QPointF /* posScreen */)
135{
136// LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateSegment::handleMouseMove";
137}
138
140 QPointF /* posScreen */)
141{
142 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::handleMousePress";
143}
144
146 QPointF /* posScreen */)
147{
148 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::handleMouseRelease";
149}
150
151Segment *DigitizeStateSegment::segmentFromSegmentStart (const QPointF &posSegmentStart) const
152{
153 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::segmentFromSegmentStart"
154 << " segments=" << m_segments.count();
155
156 QList<Segment*>::const_iterator itr;
157 for (itr = m_segments.begin(); itr != m_segments.end(); itr++) {
158 Segment *segment = *itr;
159
160 if (segment->firstPoint() == posSegmentStart) {
161
162 return segment;
163 }
164 }
165
166 LOG4CPP_ERROR_S ((*mainCat)) << "DigitizeStateSegment::segmentFromSegmentStart";
167 ENGAUGE_ASSERT (false);
168 return nullptr;
169}
170
172{
173 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::slotMouseClickOnSegment";
174
175 Segment *segment = segmentFromSegmentStart (posSegmentStart);
176
177 // Create single-entry list that is expected by SegmentFactory
178 QList<Segment*> segments;
179 segments.push_back (segment);
180
181 // Generate point coordinates. Nothing is created in the GraphicsScene at this point
182 GraphicsScene &scene = context().mainWindow().scene();
183 SegmentFactory segmentFactory (dynamic_cast<QGraphicsScene &> (scene),
184 context().isGnuplot());
185
186 QList<QPoint> points = segmentFactory.fillPoints (m_cmdMediator->document().modelSegments(),
187 segments);
188
189 // Create one ordinal for each point
190 OrdinalGenerator ordinalGenerator;
191 Document &document = m_cmdMediator->document ();
192 const Transformation &transformation = context ().mainWindow ().transformation();
193 QList<double> ordinals;
194 QList<QPoint>::iterator itr;
195 for (itr = points.begin(); itr != points.end(); itr++) {
196
197 QPoint point = *itr;
198 ordinals << ordinalGenerator.generateCurvePointOrdinal(document,
199 transformation,
200 point,
201 activeCurve ());
202 }
203
204 // Create command to add points
205 QUndoCommand *cmd = new CmdAddPointsGraph (context ().mainWindow(),
206 document,
207 context ().mainWindow().selectedGraphCurve(),
208 points,
209 ordinals);
210 context().appendNewCmd(m_cmdMediator,
211 cmd);
212}
213
215{
216 return "DigitizeStateSegment";
217}
218
220{
221 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::updateAfterPointAddition";
222}
223
225 const DocumentModelDigitizeCurve & /*modelDigitizeCurve */)
226{
227 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::updateModelDigitizeCurve";
228}
229
231{
232 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSegment::updateModelSegments";
233
234 QList<Segment*>::const_iterator itr;
235 for (itr = m_segments.begin(); itr != m_segments.end(); itr++) {
236 Segment *segment = *itr;
237
238 segment->updateModelSegment (modelSegments);
239 }
240}
DigitizeState
Set of possible states of Digitize toolbar.
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Definition Logger.cpp:14
Command for adding one or more graph points. This is for Segment Fill mode.
Command queue stack.
Definition CmdMediator.h:24
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
bool canPasteProtected(const Transformation &transformation, const QSize &viewSize) const
Protected version of canPaste method. Some, but not all, leaf classes use this method.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses,...
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 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.
virtual bool guidelinesAreSelectable() const
Enable/disable guidelines according to state.
virtual QString state() const
State name for debugging.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
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.
void slotMouseClickOnSegment(QPointF)
Receive signal from Segment that has been clicked on. The CmdMediator from the begin method will be u...
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 handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve 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...
DigitizeStateSegment(DigitizeStateContext &context)
Single constructor.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
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 handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
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
DocumentModelSegments modelSegments() const
Get method for DocumentModelSegments.
Definition Document.cpp:761
Add point and line handling to generic QGraphicsScene.
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.
QImage imageFiltered() const
Background image that has been filtered for the current curve. This asserts if a curve-specific image...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
Transformation transformation() const
Return read-only copy of transformation.
Utility class for generating ordinal numbers.
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.
Factory class for Segment objects.
QList< QPoint > fillPoints(const DocumentModelSegments &modelSegments, QList< Segment * > segments)
Return segment fill points for all segments, for previewing.
void clearSegments(QList< Segment * > &segments)
Remove the segments created by makeSegments.
void makeSegments(const QImage &imageFiltered, const DocumentModelSegments &modelSegments, QList< Segment * > &segments, bool useDlg=true)
Main entry point for creating all Segments for the filtered image.
Selectable piecewise-defined line that follows a filtered line in the image.
Definition Segment.h:22
int lineCount() const
Get method for number of lines.
Definition Segment.cpp:380
void updateModelSegment(const DocumentModelSegments &modelSegments)
Update this segment given the new settings.
Definition Segment.cpp:540
QPointF firstPoint() const
Coordinates of first point in Segment.
Definition Segment.cpp:281
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
#define LOG4CPP_ERROR_S(logger)
Definition convenience.h:12