From 3cc032c11e6ead4691e4c56abb18727c4958d7c0 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 21 Sep 2013 09:16:44 +0200 Subject: [PATCH] + Add option to refine solid on sketch-based features --- src/Mod/Part/App/modelRefine.h | 2 +- src/Mod/Part/Gui/DlgSettingsGeneral.cpp | 6 +++-- src/Mod/Part/Gui/DlgSettingsGeneral.ui | 23 +++++++++++++++---- src/Mod/PartDesign/App/FeatureGroove.cpp | 2 ++ src/Mod/PartDesign/App/FeaturePad.cpp | 2 ++ src/Mod/PartDesign/App/FeaturePocket.cpp | 6 ++++- src/Mod/PartDesign/App/FeatureRevolution.cpp | 2 ++ src/Mod/PartDesign/App/FeatureSketchBased.cpp | 16 +++++++++++++ src/Mod/PartDesign/App/FeatureSketchBased.h | 1 + src/Mod/PartDesign/App/FeatureTransformed.cpp | 18 +++++++++++++++ src/Mod/PartDesign/App/FeatureTransformed.h | 1 + 11 files changed, 70 insertions(+), 9 deletions(-) diff --git a/src/Mod/Part/App/modelRefine.h b/src/Mod/Part/App/modelRefine.h index 32c897ff7..928ecfbc2 100644 --- a/src/Mod/Part/App/modelRefine.h +++ b/src/Mod/Part/App/modelRefine.h @@ -180,7 +180,7 @@ GeomAbs_OtherSurface }; */ namespace Part { -class BRepBuilderAPI_RefineModel : public BRepBuilderAPI_MakeShape +class PartExport BRepBuilderAPI_RefineModel : public BRepBuilderAPI_MakeShape { public: BRepBuilderAPI_RefineModel(const TopoDS_Shape&); diff --git a/src/Mod/Part/Gui/DlgSettingsGeneral.cpp b/src/Mod/Part/Gui/DlgSettingsGeneral.cpp index aee0f17a5..f6ed2565d 100644 --- a/src/Mod/Part/Gui/DlgSettingsGeneral.cpp +++ b/src/Mod/Part/Gui/DlgSettingsGeneral.cpp @@ -69,8 +69,9 @@ void DlgSettingsGeneral::saveSettings() Interface_Static::SetCVal("write.step.unit","MM"); break; } - ui->checkBooleanRefine->onSave(); ui->checkBooleanCheck->onSave(); + ui->checkBooleanRefine->onSave(); + ui->checkSketchBaseRefine->onSave(); } void DlgSettingsGeneral::loadSettings() @@ -79,8 +80,9 @@ void DlgSettingsGeneral::loadSettings() .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part"); int unit = hGrp->GetInt("Unit", 0); ui->comboBoxUnits->setCurrentIndex(unit); - ui->checkBooleanRefine->onRestore(); ui->checkBooleanCheck->onRestore(); + ui->checkBooleanRefine->onRestore(); + ui->checkSketchBaseRefine->onRestore(); } /** diff --git a/src/Mod/Part/Gui/DlgSettingsGeneral.ui b/src/Mod/Part/Gui/DlgSettingsGeneral.ui index 66922553a..6336e9ab0 100644 --- a/src/Mod/Part/Gui/DlgSettingsGeneral.ui +++ b/src/Mod/Part/Gui/DlgSettingsGeneral.ui @@ -75,6 +75,19 @@ + + + Automatically check model after boolean operation + + + CheckModel + + + Mod/Part/Boolean + + + + Automatically refine model after boolean operation @@ -87,16 +100,16 @@ - - + + - Automatically check model after boolean operation + Automatically refine model after sketch-based operation - CheckModel + RefineModel - Mod/Part/Boolean + Mod/PartDesign diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index e3344e70a..b2f6cdc3a 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -134,6 +134,7 @@ App::DocumentObjectExecReturn *Groove::execute(void) if (RevolMaker.IsDone()) { TopoDS_Shape result = RevolMaker.Shape(); // set the subtractive shape property for later usage in e.g. pattern + result = refineShapeIfActive(result); this->SubShape.setValue(result); // cut out groove to get one result object @@ -147,6 +148,7 @@ App::DocumentObjectExecReturn *Groove::execute(void) if (solRes.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); + solRes = refineShapeIfActive(solRes); this->Shape.setValue(solRes); } else diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index d50551519..6168d9a9d 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -160,6 +160,7 @@ App::DocumentObjectExecReturn *Pad::execute(void) return new App::DocumentObjectExecReturn("Pad: Resulting shape is empty"); // set the additive shape property for later usage in e.g. pattern + prism = refineShapeIfActive(prism); this->AddShape.setValue(prism); // if the sketch has a support fuse them to get one result object @@ -175,6 +176,7 @@ App::DocumentObjectExecReturn *Pad::execute(void) // lets check if the result is a solid if (solRes.IsNull()) return new App::DocumentObjectExecReturn("Pad: Resulting shape is not a solid"); + solRes = refineShapeIfActive(solRes); this->Shape.setValue(solRes); } else { this->Shape.setValue(prism); diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index 2570edddb..966a407e5 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -143,13 +143,15 @@ App::DocumentObjectExecReturn *Pocket::execute(void) if (!PrismMaker.IsDone()) return new App::DocumentObjectExecReturn("Pocket: Up to face: Could not extrude the sketch!"); TopoDS_Shape prism = PrismMaker.Shape(); + prism = refineShapeIfActive(prism); // And the really expensive way to get the SubShape... BRepAlgoAPI_Cut mkCut(support, prism); if (!mkCut.IsDone()) return new App::DocumentObjectExecReturn("Pocket: Up to face: Could not get SubShape!"); // FIXME: In some cases this affects the Shape property: It is set to the same shape as the SubShape!!!! - this->SubShape.setValue(mkCut.Shape()); + TopoDS_Shape result = refineShapeIfActive(mkCut.Shape()); + this->SubShape.setValue(result); this->Shape.setValue(prism); } else { TopoDS_Shape prism; @@ -159,6 +161,7 @@ App::DocumentObjectExecReturn *Pocket::execute(void) return new App::DocumentObjectExecReturn("Pocket: Resulting shape is empty"); // set the subtractive shape property for later usage in e.g. pattern + prism = refineShapeIfActive(prism); this->SubShape.setValue(prism); // Cut the SubShape out of the support @@ -170,6 +173,7 @@ App::DocumentObjectExecReturn *Pocket::execute(void) TopoDS_Shape solRes = this->getSolid(result); if (solRes.IsNull()) return new App::DocumentObjectExecReturn("Pocket: Resulting shape is not a solid"); + solRes = refineShapeIfActive(solRes); remapSupportShape(solRes); this->Shape.setValue(solRes); } diff --git a/src/Mod/PartDesign/App/FeatureRevolution.cpp b/src/Mod/PartDesign/App/FeatureRevolution.cpp index afb3667f7..df32db4d9 100644 --- a/src/Mod/PartDesign/App/FeatureRevolution.cpp +++ b/src/Mod/PartDesign/App/FeatureRevolution.cpp @@ -139,6 +139,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void) if (RevolMaker.IsDone()) { TopoDS_Shape result = RevolMaker.Shape(); + result = refineShapeIfActive(result); // set the additive shape property for later usage in e.g. pattern this->AddShape.setValue(result); @@ -150,6 +151,7 @@ App::DocumentObjectExecReturn *Revolution::execute(void) if (!mkFuse.IsDone()) throw Base::Exception("Fusion with support failed"); result = mkFuse.Shape(); + result = refineShapeIfActive(result); } this->Shape.setValue(result); diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index e903537a5..8dcaaa885 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -66,6 +66,9 @@ #include #include +#include +#include +#include #include "FeatureSketchBased.h" using namespace PartDesign; @@ -924,3 +927,16 @@ bool SketchBased::isParallelPlane(const TopoDS_Shape& s1, const TopoDS_Shape& s2 return false; } + +TopoDS_Shape SketchBased::refineShapeIfActive(const TopoDS_Shape& oldShape) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign"); + if (hGrp->GetBool("RefineModel", false)) { + Part::BRepBuilderAPI_RefineModel mkRefine(oldShape); + TopoDS_Shape resShape = mkRefine.Shape(); + return resShape; + } + + return oldShape; +} diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.h b/src/Mod/PartDesign/App/FeatureSketchBased.h index 863c382a7..abb034e80 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.h +++ b/src/Mod/PartDesign/App/FeatureSketchBased.h @@ -86,6 +86,7 @@ protected: bool isEqualGeometry(const TopoDS_Shape&, const TopoDS_Shape&) const; bool isQuasiEqual(const TopoDS_Shape&, const TopoDS_Shape&) const; void remapSupportShape(const TopoDS_Shape&); + TopoDS_Shape refineShapeIfActive(const TopoDS_Shape&) const; /// Extract a face from a given LinkSub static void getUpToFaceFromLinkSub(TopoDS_Face& upToFace, diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index b7ecf6638..a17ef4e75 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -43,6 +43,9 @@ #include #include +#include +#include +#include using namespace PartDesign; @@ -262,11 +265,13 @@ App::DocumentObjectExecReturn *Transformed::execute(void) // lets check if the result is a solid if (result.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid", *o); + result = refineShapeIfActive(result); } else { BRepAlgoAPI_Cut mkCut(support, transformedShapes); if (!mkCut.IsDone()) return new App::DocumentObjectExecReturn("Cut out of support failed", *o); result = mkCut.Shape(); + result = refineShapeIfActive(result); } support = result; // Use result of this operation for fuse/cut of next original @@ -292,4 +297,17 @@ App::DocumentObjectExecReturn *Transformed::execute(void) return App::DocumentObject::StdReturn; } +TopoDS_Shape Transformed::refineShapeIfActive(const TopoDS_Shape& oldShape) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign"); + if (hGrp->GetBool("RefineModel", false)) { + Part::BRepBuilderAPI_RefineModel mkRefine(oldShape); + TopoDS_Shape resShape = mkRefine.Shape(); + return resShape; + } + + return oldShape; +} + } diff --git a/src/Mod/PartDesign/App/FeatureTransformed.h b/src/Mod/PartDesign/App/FeatureTransformed.h index 32c212159..96f375c2c 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.h +++ b/src/Mod/PartDesign/App/FeatureTransformed.h @@ -81,6 +81,7 @@ public: protected: virtual void positionBySupport(void); + TopoDS_Shape refineShapeIfActive(const TopoDS_Shape&) const; std::list rejected; };