Sketcher: Snap: initial implementation: - creation of SnapManager class. - Move grid snap to this new class. - Add snap to object. - Add snap at angle.
This commit is contained in:
@@ -65,6 +65,7 @@
|
||||
#include "DrawSketchHandler.h"
|
||||
#include "EditDatumDialog.h"
|
||||
#include "EditModeCoinManager.h"
|
||||
#include "SnapManager.h"
|
||||
#include "TaskDlgEditSketch.h"
|
||||
#include "TaskSketcherValidation.h"
|
||||
#include "Utils.h"
|
||||
@@ -304,6 +305,7 @@ ViewProviderSketch::ViewProviderSketch()
|
||||
Mode(STATUS_NONE),
|
||||
listener(nullptr),
|
||||
editCoinManager(nullptr),
|
||||
snapManager(nullptr),
|
||||
pObserver(std::make_unique<ViewProviderSketch::ParameterObserver>(*this)),
|
||||
sketchHandler(nullptr),
|
||||
viewOrientationFactor(1)
|
||||
@@ -551,36 +553,11 @@ bool ViewProviderSketch::keyPressed(bool pressed, int key)
|
||||
return true; // handle all other key events
|
||||
}
|
||||
|
||||
void ViewProviderSketch::setSnapMode(SnapMode mode)
|
||||
void ViewProviderSketch::setAngleSnapping(bool enable, Base::Vector2d referencePoint)
|
||||
{
|
||||
snapMode = mode; // to be redirected to SnapManager
|
||||
}
|
||||
|
||||
SnapMode ViewProviderSketch::getSnapMode() const
|
||||
{
|
||||
return snapMode; // to be redirected to SnapManager
|
||||
}
|
||||
|
||||
void ViewProviderSketch::snapToGrid(double &x, double &y) // Paddle, when resolving this conflict, make sure to use the function in ViewProviderGridExtension
|
||||
{
|
||||
if (snapMode == SnapMode::SnapToGrid && ShowGrid.getValue()) {
|
||||
// Snap Tolerance in pixels
|
||||
const double snapTol = getGridSize() / 5;
|
||||
|
||||
double tmpX = x, tmpY = y;
|
||||
|
||||
getClosestGridPoint(tmpX, tmpY);
|
||||
|
||||
// Check if x within snap tolerance
|
||||
if (x < tmpX + snapTol && x > tmpX - snapTol) {
|
||||
x = tmpX; // Snap X Mouse Position
|
||||
}
|
||||
|
||||
// Check if y within snap tolerance
|
||||
if (y < tmpY + snapTol && y > tmpY - snapTol) {
|
||||
y = tmpY; // Snap Y Mouse Position
|
||||
}
|
||||
}
|
||||
assert(snapManager);
|
||||
snapManager->angleSnapEnabled = enable;
|
||||
snapManager->referencePoint = referencePoint;
|
||||
}
|
||||
|
||||
void ViewProviderSketch::getProjectingLine(const SbVec2s& pnt, const Gui::View3DInventorViewer *viewer, SbLine& line) const
|
||||
@@ -679,7 +656,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
|
||||
|
||||
try {
|
||||
getCoordsOnSketchPlane(pos,normal,x,y);
|
||||
snapToGrid(x, y);
|
||||
snapManager->snap(x, y);
|
||||
}
|
||||
catch (const Base::ZeroDivisionError&) {
|
||||
return false;
|
||||
@@ -1148,7 +1125,7 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor
|
||||
double x,y;
|
||||
try {
|
||||
getCoordsOnSketchPlane(line.getPosition(),line.getDirection(),x,y);
|
||||
snapToGrid(x, y);
|
||||
snapManager->snap(x, y);
|
||||
}
|
||||
catch (const Base::ZeroDivisionError&) {
|
||||
return false;
|
||||
@@ -1275,7 +1252,7 @@ bool ViewProviderSketch::mouseMove(const SbVec2s &cursorPos, Gui::View3DInventor
|
||||
SbLine line2;
|
||||
getProjectingLine(DoubleClick::prvCursorPos, viewer, line2);
|
||||
getCoordsOnSketchPlane(line2.getPosition(),line2.getDirection(),drag.xInit,drag.yInit);
|
||||
snapToGrid(drag.xInit, drag.yInit);
|
||||
snapManager->snap(drag.xInit, drag.yInit);
|
||||
} else {
|
||||
drag.resetVector();
|
||||
}
|
||||
@@ -2877,6 +2854,7 @@ bool ViewProviderSketch::setEdit(int ModNum)
|
||||
preselection.reset();
|
||||
selection.reset();
|
||||
editCoinManager = std::make_unique<EditModeCoinManager>(*this);
|
||||
snapManager = std::make_unique<SnapManager>(*this);
|
||||
|
||||
auto editDoc = Gui::Application::Instance->editDocument();
|
||||
App::DocumentObject *editObj = getSketchObject();
|
||||
@@ -3123,6 +3101,7 @@ void ViewProviderSketch::unsetEdit(int ModNum)
|
||||
deactivateHandler();
|
||||
|
||||
editCoinManager = nullptr;
|
||||
snapManager = nullptr;
|
||||
preselection.reset();
|
||||
selection.reset();
|
||||
this->detachSelection();
|
||||
|
||||
Reference in New Issue
Block a user