7 #include "CmdAddPointGraph.h"
8 #include "CmdMediator.h"
9 #include "ColorFilter.h"
10 #include "CurveStyles.h"
11 #include "DigitizeStateContext.h"
12 #include "DigitizeStatePointMatch.h"
13 #include "EngaugeAssert.h"
14 #include "EnumsToQt.h"
15 #include "GraphicsPoint.h"
16 #include "GraphicsScene.h"
17 #include "GraphicsView.h"
19 #include "MainWindow.h"
20 #include "OrdinalGenerator.h"
21 #include "PointMatchAlgorithm.h"
22 #include "PointStyle.h"
23 #include <QApplication>
25 #include <QGraphicsEllipseItem>
26 #include <QGraphicsScene>
29 #include <QMessageBox>
32 const double Z_VALUE = 200.0;
41 DigitizeStatePointMatch::~DigitizeStatePointMatch ()
53 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::begin";
60 m_outline =
new QGraphicsEllipseItem ();
62 m_outline->setPen (QPen (Qt::black));
63 m_outline->setVisible (
true);
64 m_outline->setZValue (Z_VALUE);
67 void DigitizeStatePointMatch::createPermanentPoint (
CmdMediator *cmdMediator,
68 const QPointF &posScreen)
76 context ().mainWindow().selectedGraphCurve(),
87 void DigitizeStatePointMatch::createTemporaryPoint (
CmdMediator *cmdMediator,
88 const QPoint &posScreen)
90 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStatePointMatch::createTemporaryPoint";
108 m_posCandidatePoint = posScreen;
113 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStatePointMatch::cursor";
115 return QCursor (Qt::ArrowCursor);
120 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::end";
126 ENGAUGE_CHECK_PTR (m_outline);
131 QList<PointMatchPixel> DigitizeStatePointMatch::extractSamplePointPixels (
const QImage &img,
133 const QPointF &posScreen)
const
135 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::extractSamplePointPixels";
140 QList<PointMatchPixel> samplePointPixels;
145 for (
int xOffset = -radiusMax; xOffset <= radiusMax; xOffset++) {
146 for (
int yOffset = -radiusMax; yOffset <= radiusMax; yOffset++) {
148 int x = posScreen.x() + xOffset;
149 int y = posScreen.y() + yOffset;
150 int radius = qSqrt (xOffset * xOffset + yOffset * yOffset);
152 if (radius <= radiusMax) {
162 samplePointPixels.push_back (point);
167 return samplePointPixels;
172 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleCurveChange";
179 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleKeyPress"
180 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
183 if (key == Qt::Key_Right) {
185 promoteCandidatePointToPermanentPoint (cmdMediator);
187 popCandidatePoint(cmdMediator);
199 m_outline->setRect (posScreen.x() - modelPointMatch.
maxPointSize() / 2.0,
206 bool pixelShouldBeOn = pixelIsOnInImage (img,
211 QColor penColorIs = m_outline->pen().color();
212 bool pixelIsOn = (penColorIs.red () != penColorIs.green());
213 if (pixelShouldBeOn != pixelIsOn) {
214 QColor penColorShouldBe (pixelShouldBeOn ? Qt::green : Qt::black);
215 m_outline->setPen (QPen (penColorShouldBe));
222 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleMousePress";
228 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::handleMouseRelease";
230 createPermanentPoint (cmdMediator,
233 findPointsAndShowFirstCandidate (cmdMediator,
237 void DigitizeStatePointMatch::findPointsAndShowFirstCandidate (
CmdMediator *cmdMediator,
238 const QPointF &posScreen)
240 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::findPointsAndShowFirstCandidate";
245 QList<PointMatchPixel> samplePointPixels = extractSamplePointPixels (img,
254 QApplication::setOverrideCursor(Qt::WaitCursor);
257 m_candidatePoints = pointMatchAlgorithm.findPoints (samplePointPixels,
262 QApplication::restoreOverrideCursor();
265 popCandidatePoint (cmdMediator);
268 bool DigitizeStatePointMatch::pixelIsOnInImage (
const QImage &img,
271 int radiusLimit)
const
276 bool pixelShouldBeOn =
false;
277 for (
int xOffset = -radiusLimit; xOffset <= radiusLimit; xOffset++) {
278 for (
int yOffset = -radiusLimit; yOffset <= radiusLimit; yOffset++) {
280 int radius = qSqrt (xOffset * xOffset + yOffset * yOffset);
282 if (radius <= radiusLimit) {
284 int xNearby = x + xOffset;
285 int yNearby = y + yOffset;
287 if ((0 <= xNearby) &&
289 (xNearby < img.width()) &&
290 (yNearby < img.height())) {
296 pixelShouldBeOn =
true;
304 return pixelShouldBeOn;
307 void DigitizeStatePointMatch::popCandidatePoint (
CmdMediator *cmdMediator)
309 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStatePointMatch::popCandidatePoint";
311 if (m_candidatePoints.count() > 0) {
314 QPoint posScreen = m_candidatePoints.first();
315 m_candidatePoints.pop_front ();
317 createTemporaryPoint(cmdMediator,
323 QMessageBox::information (0,
324 QObject::tr (
"Point Match"),
325 QObject::tr (
"There are no more matching points"));
330 void DigitizeStatePointMatch::promoteCandidatePointToPermanentPoint(
CmdMediator *cmdMediator)
332 createPermanentPoint (cmdMediator,
333 m_posCandidatePoint);
338 return "DigitizeStatePointMatch";
344 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::updateModelDigitizeCurve";
349 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStatePointMatch::updateModelSegments";
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 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.
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.
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.
int cursorSize() const
Get method for effective cursor size.
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.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
void showTemporaryMessage(const QString &temporaryMessage)
Show temporary message in status bar.
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...
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
Details for a specific Point.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
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...
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
DigitizeStatePointMatch(DigitizeStateContext &context)
Single constructor.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
Command for adding one graph point.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
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.
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...
Utility class for generating ordinal numbers.
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.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
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.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.