From b16f03ec0249c2c31d523316a1e0e63e64f7ea1c Mon Sep 17 00:00:00 2001 From: Uwe Date: Sat, 16 Jul 2022 23:17:06 +0200 Subject: [PATCH] [PD] add parameter enabling logic for pad/pocket - currently all parameters are always enabled and thus can lead to errors like the one reported here: https://forum.freecadweb.org/viewtopic.php?f=3&t=70266 --- src/Mod/PartDesign/App/FeatureExtrude.cpp | 54 +++++++++++++++++++++++ src/Mod/PartDesign/App/FeatureExtrude.h | 5 +++ src/Mod/PartDesign/App/FeaturePad.cpp | 4 ++ src/Mod/PartDesign/App/FeaturePocket.cpp | 5 ++- 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/Mod/PartDesign/App/FeatureExtrude.cpp b/src/Mod/PartDesign/App/FeatureExtrude.cpp index 65a8b50b7c..48ffee5da6 100644 --- a/src/Mod/PartDesign/App/FeatureExtrude.cpp +++ b/src/Mod/PartDesign/App/FeatureExtrude.cpp @@ -273,3 +273,57 @@ void FeatureExtrude::generateTaperedPrism(TopoDS_Shape& prism, prism = comp; } } + +void FeatureExtrude::updateProperties(const std::string &method) +{ + // disable settings that are not valid on the current method + // disable everything unless we are sure we don't need it + bool isLengthEnabled = false; + bool isLength2Enabled = false; + bool isOffsetEnabled = false; + bool isMidplaneEnabled = false; + bool isReversedEnabled = false; + bool isUpToFaceEnabled = false; + bool isTaperVisible = false; + bool isTaper2Visible = false; + if (method == "Length") { + isLengthEnabled = true; + isTaperVisible = true; + isMidplaneEnabled = true; + isReversedEnabled = !Midplane.getValue(); + } + else if (method == "UpToLast") { + isOffsetEnabled = true; + isReversedEnabled = true; + } + else if (method == "ThroughAll") { + isMidplaneEnabled = true; + isReversedEnabled = !Midplane.getValue(); + } + else if (method == "UpToFirst") { + isOffsetEnabled = true; + isReversedEnabled = true; + } + else if (method == "UpToFace") { + isOffsetEnabled = true; + isReversedEnabled = true; + isUpToFaceEnabled = true; + } + else if (method == "TwoLengths") { + isLengthEnabled = true; + isLength2Enabled = true; + isTaperVisible = true; + isTaper2Visible = true; + isReversedEnabled = true; + } + + Length.setReadOnly(!isLengthEnabled); + AlongSketchNormal.setReadOnly(!isLengthEnabled); + Length2.setReadOnly(!isLength2Enabled); + Offset.setReadOnly(!isOffsetEnabled); + TaperAngle.setReadOnly(!isTaperVisible); + TaperAngle2.setReadOnly(!isTaper2Visible); + Midplane.setReadOnly(!isMidplaneEnabled); + Reversed.setReadOnly(!isReversedEnabled); + UpToFace.setReadOnly(!isUpToFaceEnabled); +} diff --git a/src/Mod/PartDesign/App/FeatureExtrude.h b/src/Mod/PartDesign/App/FeatureExtrude.h index ba349c11e6..97d9bc76c0 100644 --- a/src/Mod/PartDesign/App/FeatureExtrude.h +++ b/src/Mod/PartDesign/App/FeatureExtrude.h @@ -111,6 +111,11 @@ protected: const double angle, const double angle2, const bool midplane); + + /** + * Disables settings that are not valid for the current method + */ + void updateProperties(const std::string &method); }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index e8cc92f7f5..f801683a51 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -238,6 +238,9 @@ App::DocumentObjectExecReturn *Pad::execute() this->Shape.setValue(getSolid(prism)); } + // eventually disable some settings that are not valid for the current method + updateProperties(method); + return App::DocumentObject::StdReturn; } catch (Standard_Failure& e) { @@ -250,4 +253,5 @@ App::DocumentObjectExecReturn *Pad::execute() catch (Base::Exception& e) { return new App::DocumentObjectExecReturn(e.what()); } + } diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index 2aa3294643..ef209b0e56 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -39,7 +39,7 @@ using namespace PartDesign; /* TRANSLATOR PartDesign::Pocket */ -const char* Pocket::TypeEnums[]= {"Length","ThroughAll","UpToFirst","UpToFace","TwoLengths",nullptr}; +const char* Pocket::TypeEnums[]= {"Length", "ThroughAll", "UpToFirst", "UpToFace", "TwoLengths", nullptr}; PROPERTY_SOURCE(PartDesign::Pocket, PartDesign::FeatureExtrude) @@ -237,6 +237,9 @@ App::DocumentObjectExecReturn *Pocket::execute() this->Shape.setValue(getSolid(solRes)); } + // eventually disable some settings that are not valid for the current method + updateProperties(method); + return App::DocumentObject::StdReturn; } catch (Standard_Failure& e) {