diff --git a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp index 48a01cb7d24a..8c9f24eea25e 100644 --- a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp @@ -305,7 +305,6 @@ void TaskHelixParameters::updateUI() void TaskHelixParameters::onSelectionChanged(const Gui::SelectionChanges& msg) { if (msg.Type == Gui::SelectionChanges::AddSelection) { - exitSelectionMode(); std::vector axis; App::DocumentObject* selObj; @@ -363,12 +362,15 @@ void TaskHelixParameters::onAxisChanged(int num) if (lnk.getValue() == 0) { // enter reference selection mode TaskSketchBasedParameters::onSelectReference(true, true, false, true); + return; } else { if (!pcHelix->getDocument()->isIn(lnk.getValue())){ Base::Console().Error("Object was deleted\n"); return; } propReferenceAxis->Paste(lnk); + + // in case user is in selection mode, but changed his mind before selecting anything. exitSelectionMode(); } @@ -477,6 +479,32 @@ void TaskHelixParameters::getReferenceAxis(App::DocumentObject*& obj, std::vecto } } +void TaskHelixParameters::startReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) +{ + PartDesign::ProfileBased* pcHelix = dynamic_cast(vp->getObject()); + if (pcHelix->getAddSubType() == PartDesign::FeatureAddSub::Subtractive) { + Gui::Document* doc = vp->getDocument(); + if (doc) { + doc->setHide(profile->getNameInDocument()); + } + } else { + TaskSketchBasedParameters::startReferenceSelection(profile, base); + } +} + +void TaskHelixParameters::finishReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) +{ + PartDesign::ProfileBased* pcHelix = dynamic_cast(vp->getObject()); + if (pcHelix->getAddSubType() == PartDesign::FeatureAddSub::Subtractive) { + Gui::Document* doc = vp->getDocument(); + if (doc) { + doc->setShow(profile->getNameInDocument()); + } + } else { + TaskSketchBasedParameters::finishReferenceSelection(profile, base); + } +} + // this is used for logging the command fully when recording macros void TaskHelixParameters::apply() { diff --git a/src/Mod/PartDesign/Gui/TaskHelixParameters.h b/src/Mod/PartDesign/Gui/TaskHelixParameters.h index aaa1c7ed7b6a..6e5d3e6614bf 100644 --- a/src/Mod/PartDesign/Gui/TaskHelixParameters.h +++ b/src/Mod/PartDesign/Gui/TaskHelixParameters.h @@ -82,7 +82,8 @@ private Q_SLOTS: void changeEvent(QEvent *e) override; bool updateView() const; void getReferenceAxis(App::DocumentObject *&obj, std::vector &sub) const; - + void startReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) override; + void finishReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) override; //mirrors of helixes's properties App::PropertyLength* propPitch; diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index 8512743b2a24..07980efdf6d8 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -92,6 +92,27 @@ const QString TaskSketchBasedParameters::onAddSelection(const Gui::SelectionChan return refStr; } + +void TaskSketchBasedParameters::startReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) +{ + Gui::Document* doc = vp->getDocument(); + if (doc) { + doc->setHide(profile->getNameInDocument()); + if (base) + doc->setShow(base->getNameInDocument()); + } +} + +void TaskSketchBasedParameters::finishReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) +{ + Gui::Document* doc = vp->getDocument(); + if (doc) { + doc->setShow(profile->getNameInDocument()); + if (base) + doc->setHide(base->getNameInDocument()); + } +} + void TaskSketchBasedParameters::onSelectReference(const bool pressed, const bool edge, const bool face, const bool planar) { // Note: Even if there is no solid, App::Plane and Part::Datum can still be selected @@ -101,27 +122,18 @@ void TaskSketchBasedParameters::onSelectReference(const bool pressed, const bool App::DocumentObject* prevSolid = pcSketchBased->getBaseObject( /* silent =*/ true ); if (pressed) { - Gui::Document* doc = vp->getDocument(); - if (doc) { - doc->setHide(pcSketchBased->getNameInDocument()); - if (prevSolid) - doc->setShow(prevSolid->getNameInDocument()); - } + startReferenceSelection(pcSketchBased, prevSolid); Gui::Selection().clearSelection(); Gui::Selection().addSelectionGate (new ReferenceSelection(prevSolid, edge, face, planar)); } else { Gui::Selection().rmvSelectionGate(); - Gui::Document* doc = vp->getDocument(); - if (doc) { - doc->setShow(pcSketchBased->getNameInDocument()); - if (prevSolid) - doc->setHide(prevSolid->getNameInDocument()); - } + finishReferenceSelection(pcSketchBased, prevSolid); } } } + void TaskSketchBasedParameters::exitSelectionMode() { onSelectReference(false, false, false, false); diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h index 4ff02b477d99..351e485230bc 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h @@ -51,6 +51,8 @@ class TaskSketchBasedParameters : public PartDesignGui::TaskFeatureParameters, protected: void onSelectionChanged(const Gui::SelectionChanges& msg)=0; const QString onAddSelection(const Gui::SelectionChanges& msg); + virtual void startReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base); + virtual void finishReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base); void onSelectReference(const bool pressed, const bool edge, const bool face, const bool planar); void exitSelectionMode(); QVariant setUpToFace(const QString& text);