Skip to content

Commit

Permalink
PartDesign: Helix: fix preview
Browse files Browse the repository at this point in the history
  • Loading branch information
davidosterberg authored and wwmayer committed Feb 17, 2021
1 parent 81267fc commit 8e16225
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
30 changes: 29 additions & 1 deletion src/Mod/PartDesign/Gui/TaskHelixParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ void TaskHelixParameters::updateUI()
void TaskHelixParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
{
if (msg.Type == Gui::SelectionChanges::AddSelection) {

exitSelectionMode();
std::vector<std::string> axis;
App::DocumentObject* selObj;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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<PartDesign::Helix*>(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<PartDesign::Helix*>(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()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/PartDesign/Gui/TaskHelixParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ private Q_SLOTS:
void changeEvent(QEvent *e) override;
bool updateView() const;
void getReferenceAxis(App::DocumentObject *&obj, std::vector<std::string> &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;
Expand Down
36 changes: 24 additions & 12 deletions src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8e16225

Please sign in to comment.