From 23999464e4ec381bebe4729a896178d45e5bd226 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 2 Jul 2024 08:40:30 +0200 Subject: [PATCH] Part: move model check to separate function This is to avoid code duplication. --- src/Mod/Part/App/FeaturePartBoolean.cpp | 37 +++++++++++++++++-------- src/Mod/Part/App/FeaturePartCommon.cpp | 17 ++++-------- src/Mod/Part/App/FeaturePartFuse.cpp | 18 +++++------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/Mod/Part/App/FeaturePartBoolean.cpp b/src/Mod/Part/App/FeaturePartBoolean.cpp index 96a22f1115..22587b7ace 100644 --- a/src/Mod/Part/App/FeaturePartBoolean.cpp +++ b/src/Mod/Part/App/FeaturePartBoolean.cpp @@ -30,6 +30,7 @@ #endif #include +#include #include #include "FeaturePartBoolean.h" @@ -39,6 +40,26 @@ using namespace Part; +namespace Part +{ +void throwIfInvalidIfCheckModel(const TopoDS_Shape& shape) +{ + Base::Reference hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Mod/Part/Boolean"); + + if (hGrp->GetBool("CheckModel", true)) { + BRepCheck_Analyzer aChecker(shape); + if (!aChecker.IsValid()) { + throw Base::RuntimeError("Resulting shape is invalid"); + } + } +} + +} + PROPERTY_SOURCE_ABSTRACT(Part::Boolean, Part::Feature) @@ -118,18 +139,9 @@ App::DocumentObjectExecReturn* Boolean::execute() if (resShape.IsNull()) { return new App::DocumentObjectExecReturn("Resulting shape is null"); } - Base::Reference hGrp = App::GetApplication() - .GetUserParameter() - .GetGroup("BaseApp") - ->GetGroup("Preferences") - ->GetGroup("Mod/Part/Boolean"); - if (hGrp->GetBool("CheckModel", true)) { - BRepCheck_Analyzer aChecker(resShape); - if (!aChecker.IsValid()) { - return new App::DocumentObjectExecReturn("Resulting shape is invalid"); - } - } + throwIfInvalidIfCheckModel(resShape); + TopoShape res(0); res.makeElementShape(*mkBool, shapes, opCode()); if (this->Refine.getValue()) { @@ -139,6 +151,9 @@ App::DocumentObjectExecReturn* Boolean::execute() copyMaterial(base); return Part::Feature::execute(); } + catch (const Base::Exception& e) { + return new App::DocumentObjectExecReturn(e.what()); + } catch (...) { return new App::DocumentObjectExecReturn( "A fatal error occurred when running boolean operation"); diff --git a/src/Mod/Part/App/FeaturePartCommon.cpp b/src/Mod/Part/App/FeaturePartCommon.cpp index cd72d54b68..008a946f0a 100644 --- a/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/src/Mod/Part/App/FeaturePartCommon.cpp @@ -40,6 +40,11 @@ using namespace Part; +namespace Part +{ + extern void throwIfInvalidIfCheckModel(const TopoDS_Shape& shape); +} + PROPERTY_SOURCE(Part::Common, Part::Boolean) @@ -101,17 +106,7 @@ App::DocumentObjectExecReturn *MultiCommon::execute() throw Base::RuntimeError("Resulting shape is null"); } - Base::Reference hGrp = App::GetApplication() - .GetUserParameter() - .GetGroup("BaseApp") - ->GetGroup("Preferences") - ->GetGroup("Mod/Part/Boolean"); - if (hGrp->GetBool("CheckModel", false)) { - BRepCheck_Analyzer aChecker(res.getShape()); - if (!aChecker.IsValid()) { - return new App::DocumentObjectExecReturn("Resulting shape is invalid"); - } - } + throwIfInvalidIfCheckModel(res.getShape()); if (this->Refine.getValue()) { res = res.makeElementRefine(); diff --git a/src/Mod/Part/App/FeaturePartFuse.cpp b/src/Mod/Part/App/FeaturePartFuse.cpp index 19f3091c4e..3a41e7af12 100644 --- a/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/src/Mod/Part/App/FeaturePartFuse.cpp @@ -43,6 +43,11 @@ FC_LOG_LEVEL_INIT("Part",true,true); using namespace Part; +namespace Part +{ + extern void throwIfInvalidIfCheckModel(const TopoDS_Shape& shape); +} + PROPERTY_SOURCE(Part::Fuse, Part::Boolean) @@ -151,17 +156,8 @@ App::DocumentObjectExecReturn *MultiFuse::execute() throw Base::RuntimeError("Resulting shape is null"); } - Base::Reference hGrp = App::GetApplication() - .GetUserParameter() - .GetGroup("BaseApp") - ->GetGroup("Preferences") - ->GetGroup("Mod/Part/Boolean"); - if (hGrp->GetBool("CheckModel", true)) { - BRepCheck_Analyzer aChecker(res.getShape()); - if (!aChecker.IsValid()) { - return new App::DocumentObjectExecReturn("Resulting shape is invalid"); - } - } + throwIfInvalidIfCheckModel(res.getShape()); + if (this->Refine.getValue()) { try { TopoDS_Shape oldShape = res.getShape();