1 #include "CmdAddPointGraph.h"
2 #include "CmdMediator.h"
3 #include "ColorFilter.h"
4 #include "CurveStyles.h"
5 #include "DigitizeStateContext.h"
6 #include "DigitizeStatePointMatch.h"
7 #include "EngaugeAssert.h"
9 #include "GraphicsPoint.h"
10 #include "GraphicsScene.h"
11 #include "GraphicsView.h"
13 #include "MainWindow.h"
14 #include "OrdinalGenerator.h"
15 #include "PointMatchAlgorithm.h"
16 #include "PointStyle.h"
17 #include <QApplication>
19 #include <QGraphicsEllipseItem>
20 #include <QGraphicsScene>
23 #include <QMessageBox>
26 const double Z_VALUE = 200.0;
35 DigitizeStatePointMatch::~DigitizeStatePointMatch ()
46 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::begin";
53 m_outline =
new QGraphicsEllipseItem ();
55 m_outline->setPen (QPen (Qt::black));
56 m_outline->setVisible (
true);
57 m_outline->setZValue (Z_VALUE);
60 void DigitizeStatePointMatch::createPermanentPoint (
const QPointF &posScreen)
68 context ().mainWindow().selectedGraphCurve(),
78 void DigitizeStatePointMatch::createTemporaryPoint (
const QPoint &posScreen)
80 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStatePointMatch::createTemporaryPoint";
98 m_posCandidatePoint = posScreen;
103 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStatePointMatch::cursor";
105 return QCursor (Qt::ArrowCursor);
110 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::end";
116 ENGAUGE_CHECK_PTR (m_outline);
121 QList<PointMatchPixel> DigitizeStatePointMatch::extractSamplePointPixels (
const QImage &img,
123 const QPointF &posScreen)
const
125 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::extractSamplePointPixels";
130 QList<PointMatchPixel> samplePointPixels;
135 for (
int xOffset = -radiusMax; xOffset <= radiusMax; xOffset++) {
136 for (
int yOffset = -radiusMax; yOffset <= radiusMax; yOffset++) {
138 int x = posScreen.x() + xOffset;
139 int y = posScreen.y() + yOffset;
140 int radius = qSqrt (xOffset * xOffset + yOffset * yOffset);
142 if (radius <= radiusMax) {
152 samplePointPixels.push_back (point);
157 return samplePointPixels;
162 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleCurveChange";
168 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleKeyPress"
169 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
172 if (key == Qt::Key_Right) {
174 promoteCandidatePointToPermanentPoint ();
187 m_outline->setRect (posScreen.x() - modelPointMatch.
maxPointSize() / 2.0,
194 bool pixelShouldBeOn = pixelIsOnInImage (img,
199 QColor penColorIs = m_outline->pen().color();
200 bool pixelIsOn = (penColorIs.red () != penColorIs.green());
201 if (pixelShouldBeOn != pixelIsOn) {
202 QColor penColorShouldBe (pixelShouldBeOn ? Qt::green : Qt::black);
203 m_outline->setPen (QPen (penColorShouldBe));
209 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleMousePress";
214 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleMouseRelease";
216 createPermanentPoint (posScreen);
218 findPointsAndShowFirstCandidate (posScreen);
221 void DigitizeStatePointMatch::findPointsAndShowFirstCandidate (
const QPointF &posScreen)
223 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::findPointsAndShowFirstCandidate";
228 QList<PointMatchPixel> samplePointPixels = extractSamplePointPixels (img,
237 QApplication::setOverrideCursor(Qt::WaitCursor);
240 m_candidatePoints = pointMatchAlgorithm.findPoints (samplePointPixels,
245 QApplication::restoreOverrideCursor();
248 popCandidatePoint ();
251 bool DigitizeStatePointMatch::pixelIsOnInImage (
const QImage &img,
254 int radiusLimit)
const
259 bool pixelShouldBeOn =
false;
260 for (
int xOffset = -radiusLimit; xOffset <= radiusLimit; xOffset++) {
261 for (
int yOffset = -radiusLimit; yOffset <= radiusLimit; yOffset++) {
263 int radius = qSqrt (xOffset * xOffset + yOffset * yOffset);
265 if (radius <= radiusLimit) {
267 int xNearby = x + xOffset;
268 int yNearby = y + yOffset;
270 if ((0 <= xNearby) &&
272 (xNearby < img.width()) &&
273 (yNearby < img.height())) {
279 pixelShouldBeOn =
true;
287 return pixelShouldBeOn;
290 void DigitizeStatePointMatch::popCandidatePoint ()
292 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStatePointMatch::popCandidatePoint";
294 if (m_candidatePoints.count() > 0) {
297 QPoint posScreen = m_candidatePoints.first();
298 m_candidatePoints.pop_front ();
300 createTemporaryPoint(posScreen);
305 QMessageBox::information (0,
307 "There are no more matching points");
312 void DigitizeStatePointMatch::promoteCandidatePointToPermanentPoint()
314 createPermanentPoint (m_posCandidatePoint);
319 return "DigitizeStatePointMatch";
324 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::updateModelDigitizeCurve";
329 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::updateModelSegments";
DocumentModelCommon modelCommon() const
Get method for DocumentModelCommon.
double maxPointSize() const
Get method for max point size.
const PointStyle pointStyle(const QString &curveName) const
Get method for copying one point style. Cannot return just a reference or else there is a warning abo...
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
virtual void begin(DigitizeState previousState)
Method that is called at the exact moment a state is entered.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
const Points points() const
Return a shallow copy of the Points.
CmdMediator & cmdMediator()
Provide CmdMediator for indirect access to the Document.
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.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
virtual void handleKeyPress(Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
Single on or off pixel out of the pixels that define the point match mode's candidate point...
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.
virtual void handleMouseMove(QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
virtual void updateModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
virtual void handleMouseRelease(QPointF posScreen)
Handle a mouse release that was intercepted earlier.
Class for filtering image to remove unimportant information.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
void showTemporaryMessage(const QString &temporaryMessage)
Show temporary message in status bar.
virtual void handleCurveChange()
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Details for a specific Point.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setCursor()
Update the cursor according to the current state.
int cursorSize() const
Get method for effective cursor size.
DigitizeStatePointMatch(DigitizeStateContext &context)
Single constructor.
Command for adding one graph point.
virtual QString state() const
State name for debugging.
void setPaletteColor(ColorPalette paletteColor)
Set method for point color.
Storage of one imported image and the data attached to that image.
Container for one set of digitized Points.
QImage imageFiltered() const
Background image that has been filtered for the current curve. This asserts if a curve-specific image...
Graphics item for drawing a circular or polygonal Point.
Algorithm returning a list of points that match the specified point.
ColorPalette paletteColorCandidate() const
Get method for candidate color.
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
bool pixelFilteredIsOn(const QImage &image, int x, int y) const
Return true if specified filtered pixel is on.
void appendNewCmd(QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
Utility class for generating ordinal numbers.
virtual void handleMousePress(QPointF posScreen)
Handle a mouse press that was intercepted earlier.
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
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.
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...
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.
virtual QCursor cursor() const
Returns the state-specific cursor shape.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.