From 1230f493d5fd389e9763191ac7d51d4682995516 Mon Sep 17 00:00:00 2001 From: AjinkyaDahale Date: Tue, 20 Dec 2016 03:07:49 +0530 Subject: [PATCH] Lock constraint can be applied with better selection Can't yet start without selection: the button on toolbar is not active without a selection yet --- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 98 +++++++++++++++++++-- src/Mod/Sketcher/Gui/CommandCreateGeo.cpp | 3 +- src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 11 +-- 3 files changed, 93 insertions(+), 19 deletions(-) diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index acbd0cb4d..f6bbd90d2 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -932,6 +933,29 @@ bool CmdSketcherConstrainVertical::isActive(void) // ====================================================================================== +namespace SketcherGui { + class LockSelection : public Gui::SelectionFilterGate + { + App::DocumentObject* object; + public: + LockSelection(App::DocumentObject* obj) + : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), object(obj) + {} + + bool allow(App::Document *pDoc, App::DocumentObject *pObj, const char *sSubName) + { + if (pObj != this->object) + return false; + if (!sSubName || sSubName[0] == '\0') + return false; + std::string element(sSubName); + if (element.substr(0,6) == "Vertex") + return true; + return false; + } + }; +} + /* XPM */ static const char *cursor_createlock[]={ "32 32 3 1", @@ -974,44 +998,102 @@ static const char *cursor_createlock[]={ /** * @brief The DrawSketchHandlerLock class * - * Hacking on the lines of the functions in CommandCreateGeo.cpp to make lock + * Hacking along the lines of the functions in CommandCreateGeo.cpp to make lock * constraints on the fly. */ class DrawSketchHandlerLock: public DrawSketchHandler { public: DrawSketchHandlerLock() : selectionDone(false) {} - virtual ~DrawSketchHandlerLock() {} + virtual ~DrawSketchHandlerLock() + { + Gui::Selection().rmvSelectionGate(); + } virtual void activated(ViewProviderSketch *) { + Gui::Selection().rmvSelectionGate(); + Gui::Selection().addSelectionGate(new LockSelection(sketchgui->getObject())); setCursor(QPixmap(cursor_createlock),7,7); } virtual void mouseMove(Base::Vector2d onSketchPos) { - setPositionText(onSketchPos); - if (seekAutoConstraint(sugConstr, onSketchPos, Base::Vector2d(0.f,0.f))) { - renderSuggestConstraintsCursor(sugConstr); + // If preselection Point + //int preSelPnt = sketchgui->getPreselectPoint(); + if (sketchgui->getPreselectPoint() != -1) { + setPositionText(onSketchPos); return; } + resetPositionText(); applyCursor(); } virtual bool pressButton(Base::Vector2d onSketchPos) { - EditPoint = onSketchPos; - selectionDone = true; + Q_UNUSED(onSketchPos); + // Get Preselection Point + int preSelPnt = sketchgui->getPreselectPoint(); + if (preSelPnt != -1) { + pointGeoId = Constraint::GeoUndef; + pointPosId = Sketcher::none; + sketchgui->getSketchObject()->getGeoVertexIndex(preSelPnt, pointGeoId, pointPosId); + selectionDone = true; + return true; + } return true; } virtual bool releaseButton(Base::Vector2d onSketchPos) { + Q_UNUSED(onSketchPos); + if (selectionDone) { + unsetCursor(); + resetPositionText(); + + Sketcher::SketchObject* Obj = static_cast(sketchgui->getObject()); + + Base::Vector3d pnt = Obj->getPoint(pointGeoId,pointPosId); + + // undo command open + Gui::Command::openCommand("add fixed constraint"); + Gui::Command::doCommand( + Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceX',%d,%d,%f)) ", + sketchgui->getObject()->getNameInDocument(),pointGeoId,pointPosId,pnt.x); + Gui::Command::doCommand( + Gui::Command::Doc,"App.ActiveDocument.%s.addConstraint(Sketcher.Constraint('DistanceY',%d,%d,%f)) ", + sketchgui->getObject()->getNameInDocument(),pointGeoId,pointPosId,pnt.y); + + if (pointGeoId <= Sketcher::GeoEnum::RefExt || constraintCreationMode==Reference) { + // it is a constraint on a external line, make it non-driving + const std::vector &ConStr = Obj->Constraints.getValues(); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", + sketchgui->getObject()->getNameInDocument(),ConStr.size()-2,"False"); + + Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.setDriving(%i,%s)", + sketchgui->getObject()->getNameInDocument(),ConStr.size()-1,"False"); + } + + // finish the transaction and update + Gui::Command::commitCommand(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); + bool autoRecompute = hGrp->GetBool("AutoRecompute",false); + + if(autoRecompute) + Gui::Command::updateActive(); + + // clear the selection (convenience) + Gui::Selection().clearSelection(); + + } return true; } protected: bool selectionDone; - Base::Vector2d EditPoint; + int pointGeoId; + Sketcher::PointPos pointPosId; std::vector sugConstr; }; diff --git a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp index dd8c5bb32..18cf11d54 100644 --- a/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp +++ b/src/Mod/Sketcher/Gui/CommandCreateGeo.cpp @@ -4729,7 +4729,6 @@ public: else static_cast(sketchgui->getObject())->solve(); - //ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher"); bool continuousMode = hGrp->GetBool("ContinuousCreationMode",true); if(continuousMode){ @@ -4878,7 +4877,7 @@ namespace SketcherGui { return false; } }; -}; +} /* XPM */ diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 4bc10b60d..fb4554e7a 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -61,16 +61,9 @@ using namespace Sketcher; //************************************************************************** // Construction/Destruction -DrawSketchHandler::DrawSketchHandler() - : sketchgui(0) -{ +DrawSketchHandler::DrawSketchHandler() : sketchgui(0) {} -} - -DrawSketchHandler::~DrawSketchHandler() -{ - -} +DrawSketchHandler::~DrawSketchHandler() {} void DrawSketchHandler::quit(void) {