diff --git a/src/Mod/PartDesign/App/FeatureExtrude.cpp b/src/Mod/PartDesign/App/FeatureExtrude.cpp index 4b281efbad..54a3599328 100644 --- a/src/Mod/PartDesign/App/FeatureExtrude.cpp +++ b/src/Mod/PartDesign/App/FeatureExtrude.cpp @@ -78,3 +78,54 @@ short FeatureExtrude::mustExecute() const return 1; return ProfileBased::mustExecute(); } + +Base::Vector3d FeatureExtrude::computeDirection(const Base::Vector3d& sketchVector) +{ + Base::Vector3d extrudeDirection; + + if (!UseCustomVector.getValue()) { + if (!ReferenceAxis.getValue()) { + // use sketch's normal vector for direction + extrudeDirection = sketchVector; + AlongSketchNormal.setReadOnly(true); + } + else { + // update Direction from ReferenceAxis + App::DocumentObject* pcReferenceAxis = ReferenceAxis.getValue(); + const std::vector& subReferenceAxis = ReferenceAxis.getSubValues(); + Base::Vector3d base; + Base::Vector3d dir; + getAxis(pcReferenceAxis, subReferenceAxis, base, dir, false); + switch (addSubType) { + case Type::Additive: + extrudeDirection = dir; + break; + case Type::Subtractive: + extrudeDirection = -dir; + break; + } + } + } + else { + // use the given vector + // if null vector, use sketchVector + if ((fabs(Direction.getValue().x) < Precision::Confusion()) + && (fabs(Direction.getValue().y) < Precision::Confusion()) + && (fabs(Direction.getValue().z) < Precision::Confusion())) { + Direction.setValue(sketchVector); + } + extrudeDirection = Direction.getValue(); + } + + // disable options of UseCustomVector + Direction.setReadOnly(!UseCustomVector.getValue()); + ReferenceAxis.setReadOnly(UseCustomVector.getValue()); + // UseCustomVector allows AlongSketchNormal but !UseCustomVector does not forbid it + if (UseCustomVector.getValue()) + AlongSketchNormal.setReadOnly(false); + + // explicitly set the Direction so that the dialog shows also the used direction + // if the sketch's normal vector was used + Direction.setValue(extrudeDirection); + return extrudeDirection; +} diff --git a/src/Mod/PartDesign/App/FeatureExtrude.h b/src/Mod/PartDesign/App/FeatureExtrude.h index a2fd9ea2e0..cfa1522de8 100644 --- a/src/Mod/PartDesign/App/FeatureExtrude.h +++ b/src/Mod/PartDesign/App/FeatureExtrude.h @@ -53,6 +53,9 @@ public: //@{ short mustExecute() const; //@} + +protected: + Base::Vector3d computeDirection(const Base::Vector3d& sketchVector); }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index e88fc4eebe..7b3a5f560e 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -58,7 +58,7 @@ using namespace PartDesign; const char* Pad::TypeEnums[]= {"Length", "UpToLast", "UpToFirst", "UpToFace", "TwoLengths", NULL}; -PROPERTY_SOURCE(PartDesign::Pad, PartDesign::ProfileBased) +PROPERTY_SOURCE(PartDesign::Pad, PartDesign::FeatureExtrude) Pad::Pad() { @@ -82,23 +82,7 @@ Pad::Pad() Length2.setConstraints(nullptr); } -short Pad::mustExecute() const -{ - if (Placement.isTouched() || - Type.isTouched() || - Length.isTouched() || - Length2.isTouched() || - UseCustomVector.isTouched() || - Direction.isTouched() || - ReferenceAxis.isTouched() || - AlongSketchNormal.isTouched() || - Offset.isTouched() || - UpToFace.isTouched()) - return 1; - return ProfileBased::mustExecute(); -} - -App::DocumentObjectExecReturn *Pad::execute(void) +App::DocumentObjectExecReturn *Pad::execute() { // Validate parameters double L = Length.getValue(); @@ -133,8 +117,6 @@ App::DocumentObjectExecReturn *Pad::execute(void) base = TopoDS_Shape(); } - // get the Sketch plane - Base::Placement SketchPos = obj->Placement.getValue(); // get the normal vector of the sketch Base::Vector3d SketchVector = getProfileNormal(); @@ -144,53 +126,11 @@ App::DocumentObjectExecReturn *Pad::execute(void) base.Move(invObjLoc); - Base::Vector3d paddingDirection; - - if (!UseCustomVector.getValue()) { - if (!ReferenceAxis.getValue()) { - // use sketch's normal vector for direction - paddingDirection = SketchVector; - AlongSketchNormal.setReadOnly(true); - } - else { - // update Direction from ReferenceAxis - try { - App::DocumentObject* pcReferenceAxis = ReferenceAxis.getValue(); - const std::vector& subReferenceAxis = ReferenceAxis.getSubValues(); - Base::Vector3d base; - Base::Vector3d dir; - getAxis(pcReferenceAxis, subReferenceAxis, base, dir, false); - paddingDirection = dir; - } - catch (const Base::Exception& e) { - return new App::DocumentObjectExecReturn(e.what()); - } - } - } - else { - // use the given vector - // if null vector, use SketchVector - if ( (fabs(Direction.getValue().x) < Precision::Confusion()) - && (fabs(Direction.getValue().y) < Precision::Confusion()) - && (fabs(Direction.getValue().z) < Precision::Confusion()) ) { - Direction.setValue(SketchVector); - } - paddingDirection = Direction.getValue(); - } - - // disable options of UseCustomVector - Direction.setReadOnly(!UseCustomVector.getValue()); - ReferenceAxis.setReadOnly(UseCustomVector.getValue()); - // UseCustomVector allows AlongSketchNormal but !UseCustomVector does not forbid it - if (UseCustomVector.getValue()) - AlongSketchNormal.setReadOnly(false); + Base::Vector3d paddingDirection = computeDirection(SketchVector); // create vector in padding direction with length 1 gp_Dir dir(paddingDirection.x, paddingDirection.y, paddingDirection.z); - // store the finally used direction to display it in the dialog - Direction.setValue(dir.X(), dir.Y(), dir.Z()); - // The length of a gp_Dir is 1 so the resulting pad would have // the length L in the direction of dir. But we want to have its height in the // direction of the normal vector. @@ -212,10 +152,6 @@ App::DocumentObjectExecReturn *Pad::execute(void) L2 = L2 / factor; } - // explicitly set the Direction so that the dialog shows also the used direction - // if the sketch's normal vector was used - Direction.setValue(paddingDirection); - dir.Transform(invObjLoc.Transformation()); if (sketchshape.IsNull()) @@ -394,7 +330,6 @@ App::DocumentObjectExecReturn *Pad::execute(void) return App::DocumentObject::StdReturn; } catch (Standard_Failure& e) { - if (std::string(e.GetMessageString()) == "TopoDS::Face") return new App::DocumentObjectExecReturn("Could not create face from sketch.\n" "Intersecting sketch entities or multiple faces in a sketch are not allowed."); diff --git a/src/Mod/PartDesign/App/FeaturePad.h b/src/Mod/PartDesign/App/FeaturePad.h index 7723ec379a..381571e4f5 100644 --- a/src/Mod/PartDesign/App/FeaturePad.h +++ b/src/Mod/PartDesign/App/FeaturePad.h @@ -29,22 +29,13 @@ namespace PartDesign { -class PartDesignExport Pad : public ProfileBased +class PartDesignExport Pad : public FeatureExtrude { PROPERTY_HEADER(PartDesign::Pad); public: Pad(); - App::PropertyEnumeration Type; - App::PropertyLength Length; - App::PropertyLength Length2; - App::PropertyBool UseCustomVector; - App::PropertyVector Direction; - App::PropertyBool AlongSketchNormal; - App::PropertyLength Offset; - App::PropertyLinkSub ReferenceAxis; - /** @name methods override feature */ //@{ /** Recalculate the feature @@ -60,17 +51,15 @@ public: * If Reversed is true then the direction of revolution will be reversed. * The created material will be fused with the sketch support (if there is one) */ - App::DocumentObjectExecReturn *execute(void); - short mustExecute() const; + App::DocumentObjectExecReturn *execute(); /// returns the type name of the view provider - const char* getViewProviderName(void) const { + const char* getViewProviderName() const { return "PartDesignGui::ViewProviderPad"; } //@} private: static const char* TypeEnums[]; - //static const char* SideEnums[]; }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index d77390069e..6d9a435c6e 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -57,7 +57,7 @@ using namespace PartDesign; const char* Pocket::TypeEnums[]= {"Length","ThroughAll","UpToFirst","UpToFace","TwoLengths",NULL}; -PROPERTY_SOURCE(PartDesign::Pocket, PartDesign::ProfileBased) +PROPERTY_SOURCE(PartDesign::Pocket, PartDesign::FeatureExtrude) Pocket::Pocket() { @@ -81,23 +81,7 @@ Pocket::Pocket() Length2.setConstraints(nullptr); } -short Pocket::mustExecute() const -{ - if (Placement.isTouched() || - Type.isTouched() || - Length.isTouched() || - Length2.isTouched() || - Offset.isTouched() || - UseCustomVector.isTouched() || - Direction.isTouched() || - ReferenceAxis.isTouched() || - AlongSketchNormal.isTouched() || - UpToFace.isTouched()) - return 1; - return ProfileBased::mustExecute(); -} - -App::DocumentObjectExecReturn *Pocket::execute(void) +App::DocumentObjectExecReturn *Pocket::execute() { // Handle legacy features, these typically have Type set to 3 (previously NULL, now UpToFace), // empty FaceName (because it didn't exist) and a value for Length @@ -136,10 +120,8 @@ App::DocumentObjectExecReturn *Pocket::execute(void) return new App::DocumentObjectExecReturn(text); } - // get the Sketch plane - Base::Placement SketchPos = obj->Placement.getValue(); // get the normal vector of the sketch - Base::Vector3d SketchVector = getProfileNormal(); + Base::Vector3d SketchVector = getProfileNormal(); // turn around for pockets SketchVector *= -1; @@ -150,53 +132,11 @@ App::DocumentObjectExecReturn *Pocket::execute(void) base.Move(invObjLoc); - Base::Vector3d pocketDirection; - - if (!UseCustomVector.getValue()) { - if (!ReferenceAxis.getValue()) { - // use sketch's normal vector for direction - pocketDirection = SketchVector; - AlongSketchNormal.setReadOnly(true); - } - else { - // update Direction from ReferenceAxis - try { - App::DocumentObject* pcReferenceAxis = ReferenceAxis.getValue(); - const std::vector& subReferenceAxis = ReferenceAxis.getSubValues(); - Base::Vector3d base; - Base::Vector3d dir; - getAxis(pcReferenceAxis, subReferenceAxis, base, dir, false); - pocketDirection = -dir; - } - catch (const Base::Exception& e) { - return new App::DocumentObjectExecReturn(e.what()); - } - } - } - else { - // use the given vector - // if null vector, use SketchVector - if ((fabs(Direction.getValue().x) < Precision::Confusion()) - && (fabs(Direction.getValue().y) < Precision::Confusion()) - && (fabs(Direction.getValue().z) < Precision::Confusion())) { - Direction.setValue(SketchVector); - } - pocketDirection = Direction.getValue(); - } - - // disable options of UseCustomVector - Direction.setReadOnly(!UseCustomVector.getValue()); - ReferenceAxis.setReadOnly(UseCustomVector.getValue()); - // UseCustomVector allows AlongSketchNormal but !UseCustomVector does not forbid it - if (UseCustomVector.getValue()) - AlongSketchNormal.setReadOnly(false); + Base::Vector3d pocketDirection = computeDirection(SketchVector); // create vector in pocketing direction with length 1 gp_Dir dir(pocketDirection.x, pocketDirection.y, pocketDirection.z); - // store the finally used direction to display it in the dialog - Direction.setValue(dir.X(), dir.Y(), dir.Z()); - // The length of a gp_Dir is 1 so the resulting pocket would have // the length L in the direction of dir. But we want to have its height in the // direction of the normal vector. @@ -218,10 +158,6 @@ App::DocumentObjectExecReturn *Pocket::execute(void) L2 = L2 / factor; } - // explicitly set the Direction so that the dialog shows also the used direction - // if the sketch's normal vector was used - Direction.setValue(pocketDirection); - dir.Transform(invObjLoc.Transformation()); if (profileshape.IsNull()) diff --git a/src/Mod/PartDesign/App/FeaturePocket.h b/src/Mod/PartDesign/App/FeaturePocket.h index 01dba2f70c..3c83e7becf 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.h +++ b/src/Mod/PartDesign/App/FeaturePocket.h @@ -29,22 +29,13 @@ namespace PartDesign { -class PartDesignExport Pocket : public ProfileBased +class PartDesignExport Pocket : public FeatureExtrude { PROPERTY_HEADER(PartDesign::Pocket); public: Pocket(); - App::PropertyEnumeration Type; - App::PropertyLength Length; - App::PropertyLength Length2; - App::PropertyLength Offset; - App::PropertyBool UseCustomVector; - App::PropertyVector Direction; - App::PropertyBool AlongSketchNormal; - App::PropertyLinkSub ReferenceAxis; - /** @name methods override feature */ //@{ /** Recalculate the feature @@ -57,8 +48,7 @@ public: * If Midplane is true, then the extrusion will extend for half of the length on both sides of the sketch plane * The created material will be cut out of the sketch support */ - App::DocumentObjectExecReturn *execute(void); - short mustExecute() const; + App::DocumentObjectExecReturn *execute(); /// returns the type name of the view provider const char* getViewProviderName(void) const { return "PartDesignGui::ViewProviderPocket"; @@ -66,7 +56,6 @@ public: //@} private: static const char* TypeEnums[]; - }; } //namespace PartDesign