Part: move model check to separate function
This is to avoid code duplication.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
#include "FeaturePartBoolean.h"
|
||||
@@ -39,6 +40,26 @@
|
||||
|
||||
using namespace Part;
|
||||
|
||||
namespace Part
|
||||
{
|
||||
void throwIfInvalidIfCheckModel(const TopoDS_Shape& shape)
|
||||
{
|
||||
Base::Reference<ParameterGrp> 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<ParameterGrp> 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");
|
||||
|
||||
@@ -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<ParameterGrp> 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();
|
||||
|
||||
@@ -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<ParameterGrp> 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();
|
||||
|
||||
Reference in New Issue
Block a user