23#include <QApplication>
25#include <QGraphicsEllipseItem>
26#include <QGraphicsScene>
39 m_candidatePoint (nullptr)
63 m_outline =
new QGraphicsEllipseItem ();
65 m_outline->setPen (QPen (Qt::black));
66 m_outline->setVisible (
true);
71 const QSize &viewSize)
const
77void DigitizeStatePointMatch::createPermanentPoint (
CmdMediator *cmdMediator,
78 const QPointF &posScreen)
86 context ().mainWindow().selectedGraphCurve(),
97void DigitizeStatePointMatch::createTemporaryPoint (
CmdMediator *cmdMediator,
98 const QPoint &posScreen)
115 NULL_GEOMETRY_WINDOW);
121 m_posCandidatePoint = posScreen;
128 return QCursor (Qt::ArrowCursor);
144QList<PointMatchPixel> DigitizeStatePointMatch::extractSamplePointPixels (
const QImage &img,
146 const QPointF &posScreen)
const
153 QList<PointMatchPixel> samplePointPixels;
155 int radiusMax = qFloor (modelPointMatch.
maxPointSize() / 2);
158 for (
int xOffset = -radiusMax; xOffset <= radiusMax; xOffset++) {
159 for (
int yOffset = -radiusMax; yOffset <= radiusMax; yOffset++) {
161 int x = qFloor (posScreen.x() + xOffset);
162 int y = qFloor (posScreen.y() + yOffset);
163 int radius = qFloor (qSqrt (xOffset * xOffset + yOffset * yOffset));
165 if (radius <= radiusMax) {
175 samplePointPixels.push_back (point);
180 return samplePointPixels;
189 const QString &pointIdentifier)
192 <<
" point=" << pointIdentifier.toLatin1 ().data ();
196 const QStringList &pointIdentifiers)
199 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
212 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
215 if (key == Qt::Key_Right) {
217 promoteCandidatePointToPermanentPoint (cmdMediator);
219 popCandidatePoint(cmdMediator);
231 m_outline->setRect (posScreen.x() - modelPointMatch.
maxPointSize() / 2.0,
238 bool pixelShouldBeOn = pixelIsOnInImage (img,
239 qFloor (posScreen.x()),
240 qFloor (posScreen.y()),
243 QColor penColorIs = m_outline->pen().color();
244 bool pixelIsOn = (penColorIs.red () != penColorIs.green());
245 if (pixelShouldBeOn != pixelIsOn) {
246 QColor penColorShouldBe (pixelShouldBeOn ? Qt::green : Qt::black);
247 m_outline->setPen (QPen (penColorShouldBe));
262 createPermanentPoint (cmdMediator,
265 findPointsAndShowFirstCandidate (cmdMediator,
269void DigitizeStatePointMatch::findPointsAndShowFirstCandidate (
CmdMediator *cmdMediator,
270 const QPointF &posScreen)
277 QList<PointMatchPixel> samplePointPixels = extractSamplePointPixels (img,
286 QApplication::setOverrideCursor(Qt::WaitCursor);
289 m_candidatePoints = pointMatchAlgorithm.findPoints (samplePointPixels,
294 QApplication::restoreOverrideCursor();
297 popCandidatePoint (cmdMediator);
300bool DigitizeStatePointMatch::pixelIsOnInImage (
const QImage &img,
303 int radiusLimit)
const
308 bool pixelShouldBeOn =
false;
309 for (
int xOffset = -radiusLimit; xOffset <= radiusLimit; xOffset++) {
310 for (
int yOffset = -radiusLimit; yOffset <= radiusLimit; yOffset++) {
312 int radius = qFloor (qSqrt (xOffset * xOffset + yOffset * yOffset));
314 if (radius <= radiusLimit) {
316 int xNearby = x + xOffset;
317 int yNearby = y + yOffset;
319 if ((0 <= xNearby) &&
321 (xNearby < img.width()) &&
322 (yNearby < img.height())) {
328 pixelShouldBeOn =
true;
336 return pixelShouldBeOn;
339void DigitizeStatePointMatch::popCandidatePoint (
CmdMediator *cmdMediator)
343 if (m_candidatePoints.count() > 0) {
346 QPoint posScreen = m_candidatePoints.first();
347 m_candidatePoints.pop_front ();
349 createTemporaryPoint(cmdMediator,
355 QMessageBox::information (
nullptr,
356 QObject::tr (
"Point Match"),
357 QObject::tr (
"There are no more matching points"));
362void DigitizeStatePointMatch::promoteCandidatePointToPermanentPoint(
CmdMediator *cmdMediator)
364 createPermanentPoint (cmdMediator,
365 m_posCandidatePoint);
370 return "DigitizeStatePointMatch";
DigitizeState
Set of possible states of Digitize toolbar.
#define ENGAUGE_CHECK_PTR(ptr)
Drop in replacement for Q_CHECK_PTR.
log4cpp::Category * mainCat
Command for adding one graph point.
Class for filtering image to remove unimportant information.
bool pixelFilteredIsOn(const QImage &image, int x, int y) const
Return true if specified filtered pixel is on.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
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...
Container for one set of digitized Points.
const Points points() const
Return a shallow copy of the Points.
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 QString state() const
State name for debugging.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
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 QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
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 handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
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 handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
virtual ~DigitizeStatePointMatch()
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
virtual bool guidelinesAreSelectable() const
Enable/disable guidelines according to state.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
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.
DigitizeStatePointMatch(DigitizeStateContext &context)
Single constructor.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
int cursorSize() const
Get method for effective cursor size.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
ColorPalette paletteColorCandidate() const
Get method for candidate color.
double maxPointSize() const
Get method for max point size.
Model for DlgSettingsSegments and CmdSettingsSegments.
Storage of one imported image and the data attached to that image.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
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 removeTemporaryPointIfExists()
Remove temporary point if it exists.
void showTemporaryMessage(const QString &temporaryMessage)
Show temporary message in status bar.
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.
Algorithm returning a list of points that match the specified point.
Single on or off pixel out of the pixels that define the point match mode's candidate point.
Details for a specific Point.
void setPaletteColor(ColorPalette paletteColor)
Set method for point color.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)