23
#include "PreCompiled.h"
27
# include <BRepAlgoAPI_BooleanOperation.hxx>
28
# include <BRepCheck_Analyzer.hxx>
29
# include <Standard_Failure.hxx>
32
#include <App/Application.h>
33
#include <Base/Parameter.h>
35
#include "FeaturePartBoolean.h"
36
#include "TopoShapeOpCode.h"
37
#include "modelRefine.h"
42
PROPERTY_SOURCE_ABSTRACT(Part::Boolean, Part::Feature)
47
ADD_PROPERTY(Base,(nullptr));
48
ADD_PROPERTY(Tool,(nullptr));
49
ADD_PROPERTY_TYPE(History,(ShapeHistory()), "Boolean", (App::PropertyType)
50
(App::Prop_Output|App::Prop_Transient|App::Prop_Hidden), "Shape history");
53
ADD_PROPERTY_TYPE(Refine,(0),"Boolean",(App::PropertyType)(App::Prop_None),"Refine shape (clean up redundant edges) after this boolean operation");
56
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
57
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part/Boolean");
58
this->Refine.setValue(hGrp->GetBool("RefineModel", false));
61
short Boolean::mustExecute() const
63
if (Base.getValue() && Tool.getValue()) {
64
if (Base.isTouched()) {
67
if (Tool.isTouched()) {
74
const char *Boolean::opCode() const
76
return Part::OpCodes::Boolean;
79
App::DocumentObjectExecReturn* Boolean::execute()
82
#if defined(__GNUC__) && defined(FC_OS_LINUX)
83
Base::SignalException se;
85
auto base = Base.getValue();
86
auto tool = Tool.getValue();
89
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
91
std::vector<TopoShape> shapes;
94
shapes.push_back(Feature::getTopoShape(Base.getValue()));
95
auto BaseShape = shapes[0].getShape();
96
if (BaseShape.IsNull()) {
97
throw NullShapeException("Base shape is null");
99
shapes.push_back(Feature::getTopoShape(Tool.getValue()));
100
auto ToolShape = shapes[1].getShape();
101
if (ToolShape.IsNull()) {
102
throw NullShapeException("Tool shape is null");
105
std::unique_ptr<BRepAlgoAPI_BooleanOperation> mkBool(makeOperation(BaseShape, ToolShape));
106
if (!mkBool->IsDone()) {
107
std::stringstream error;
108
error << "Boolean operation failed";
109
if (BaseShape.ShapeType() != TopAbs_SOLID) {
110
error << std::endl << base->Label.getValue() << " is not a solid";
112
if (ToolShape.ShapeType() != TopAbs_SOLID) {
113
error << std::endl << tool->Label.getValue() << " is not a solid";
115
return new App::DocumentObjectExecReturn(error.str());
117
TopoDS_Shape resShape = mkBool->Shape();
118
if (resShape.IsNull()) {
119
return new App::DocumentObjectExecReturn("Resulting shape is null");
121
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
124
->GetGroup("Preferences")
125
->GetGroup("Mod/Part/Boolean");
127
if (hGrp->GetBool("CheckModel", true)) {
128
BRepCheck_Analyzer aChecker(resShape);
129
if (!aChecker.IsValid()) {
130
return new App::DocumentObjectExecReturn("Resulting shape is invalid");
134
res.makeElementShape(*mkBool, shapes, opCode());
135
if (this->Refine.getValue()) {
136
res = res.makeElementRefine();
138
this->Shape.setValue(res);
139
return Part::Feature::execute();
142
return new App::DocumentObjectExecReturn(
143
"A fatal error occurred when running boolean operation");