Go to the documentation of this file.
23 #include <QApplication>
25 #include <QGraphicsEllipseItem>
26 #include <QGraphicsScene>
29 #include <QMessageBox>
39 m_candidatePoint (nullptr)
62 m_outline =
new QGraphicsEllipseItem ();
64 m_outline->setPen (QPen (Qt::black));
65 m_outline->setVisible (
true);
70 const QSize &viewSize)
const
76 void DigitizeStatePointMatch::createPermanentPoint (
CmdMediator *cmdMediator,
77 const QPointF &posScreen)
85 context ().mainWindow().selectedGraphCurve(),
96 void DigitizeStatePointMatch::createTemporaryPoint (
CmdMediator *cmdMediator,
97 const QPoint &posScreen)
114 NULL_GEOMETRY_WINDOW);
120 m_posCandidatePoint = posScreen;
127 return QCursor (Qt::ArrowCursor);
143 QList<PointMatchPixel> DigitizeStatePointMatch::extractSamplePointPixels (
const QImage &img,
145 const QPointF &posScreen)
const
152 QList<PointMatchPixel> samplePointPixels;
154 int radiusMax = qFloor (modelPointMatch.
maxPointSize() / 2);
157 for (
int xOffset = -radiusMax; xOffset <= radiusMax; xOffset++) {
158 for (
int yOffset = -radiusMax; yOffset <= radiusMax; yOffset++) {
160 int x = qFloor (posScreen.x() + xOffset);
161 int y = qFloor (posScreen.y() + yOffset);
162 int radius = qFloor (qSqrt (xOffset * xOffset + yOffset * yOffset));
164 if (radius <= radiusMax) {
166 bool pixelIsOn = colorFilter.pixelFilteredIsOn (img,
174 samplePointPixels.push_back (point);
179 return samplePointPixels;
183 const QString &pointIdentifier)
186 <<
" point=" << pointIdentifier.toLatin1 ().data ();
190 const QStringList &pointIdentifiers)
193 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
206 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
209 if (key == Qt::Key_Right) {
211 promoteCandidatePointToPermanentPoint (cmdMediator);
213 popCandidatePoint(cmdMediator);
225 m_outline->setRect (posScreen.x() - modelPointMatch.
maxPointSize() / 2.0,
232 bool pixelShouldBeOn = pixelIsOnInImage (img,
233 qFloor (posScreen.x()),
234 qFloor (posScreen.y()),
237 QColor penColorIs = m_outline->pen().color();
238 bool pixelIsOn = (penColorIs.red () != penColorIs.green());
239 if (pixelShouldBeOn != pixelIsOn) {
240 QColor penColorShouldBe (pixelShouldBeOn ? Qt::green : Qt::black);
241 m_outline->setPen (QPen (penColorShouldBe));
256 createPermanentPoint (cmdMediator,
259 findPointsAndShowFirstCandidate (cmdMediator,
263 void DigitizeStatePointMatch::findPointsAndShowFirstCandidate (
CmdMediator *cmdMediator,
264 const QPointF &posScreen)
271 QList<PointMatchPixel> samplePointPixels = extractSamplePointPixels (img,
280 QApplication::setOverrideCursor(Qt::WaitCursor);
283 m_candidatePoints = pointMatchAlgorithm.findPoints (samplePointPixels,
288 QApplication::restoreOverrideCursor();
291 popCandidatePoint (cmdMediator);
294 bool DigitizeStatePointMatch::pixelIsOnInImage (
const QImage &img,
297 int radiusLimit)
const
302 bool pixelShouldBeOn =
false;
303 for (
int xOffset = -radiusLimit; xOffset <= radiusLimit; xOffset++) {
304 for (
int yOffset = -radiusLimit; yOffset <= radiusLimit; yOffset++) {
306 int radius = qFloor (qSqrt (xOffset * xOffset + yOffset * yOffset));
308 if (radius <= radiusLimit) {
310 int xNearby = x + xOffset;
311 int yNearby = y + yOffset;
313 if ((0 <= xNearby) &&
315 (xNearby < img.width()) &&
316 (yNearby < img.height())) {
322 pixelShouldBeOn =
true;
330 return pixelShouldBeOn;
333 void DigitizeStatePointMatch::popCandidatePoint (
CmdMediator *cmdMediator)
337 if (m_candidatePoints.count() > 0) {
340 QPoint posScreen = m_candidatePoints.first();
341 m_candidatePoints.pop_front ();
343 createTemporaryPoint(cmdMediator,
349 QMessageBox::information (
nullptr,
350 QObject::tr (
"Point Match"),
351 QObject::tr (
"There are no more matching points"));
356 void DigitizeStatePointMatch::promoteCandidatePointToPermanentPoint(
CmdMediator *cmdMediator)
358 createPermanentPoint (cmdMediator,
359 m_posCandidatePoint);
364 return "DigitizeStatePointMatch";
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
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...
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses,...
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
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...
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...
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity.
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
MainWindow & mainWindow()
Reference to the MainWindow, without const.
virtual void handleMousePress(CmdMediator *cmdMediator, 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.
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
Storage of one imported image and the data attached to that image.
void addTemporaryPoint(const QString &identifier, GraphicsPoint *point)
Add one temporary point to m_graphicsLinesForCurves. Non-temporary points are handled by the updateLi...
int cursorSize() const
Get method for effective cursor size.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
const Points points() const
Return a shallow copy of the Points.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
Container for one set of digitized Points.
Command for adding one graph point.
Single on or off pixel out of the pixels that define the point match mode's candidate point.
double maxPointSize() const
Get method for max point size.
void setPaletteColor(ColorPalette paletteColor)
Set method for point color.
QImage imageFiltered() const
Background image that has been filtered for the current curve. This asserts if a curve-specific image...
Class for filtering image to remove unimportant information.
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
bool pixelFilteredIsOn(const QImage &image, int x, int y) const
Return true if specified filtered pixel is on.
#define ENGAUGE_CHECK_PTR(ptr)
#endif
DigitizeState
Set of possible states of Digitize toolbar.
#define LOG4CPP_INFO_S(logger)
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.
Transformation transformation() const
Return read-only copy of transformation.
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 updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
Model for DlgSettingsSegments and CmdSettingsSegments.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
log4cpp::Category * mainCat
bool canPasteProtected(const Transformation &transformation, const QSize &viewSize) const
Protected version of canPaste method. Some, but not all, leaf classes use this method.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
DigitizeStatePointMatch(DigitizeStateContext &context)
Single constructor.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
Algorithm returning a list of points that match the specified point.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
Details for a specific Point.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
virtual QString state() const
State name for debugging.
Graphics item for drawing a circular or polygonal Point.
#define LOG4CPP_DEBUG_S(logger)
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
Window that displays the geometry information, as a table, for the current curve.
void showTemporaryMessage(const QString &temporaryMessage)
Show temporary message in status bar.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Utility class for generating ordinal numbers.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
virtual ~DigitizeStatePointMatch()
ColorPalette paletteColorCandidate() const
Get method for candidate color.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...