1
/***************************************************************************
2
* Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <BRepAlgoAPI_Common.hxx>
26
# include <BRepCheck_Analyzer.hxx>
27
# include <Standard_Failure.hxx>
29
# include <TopoDS_Iterator.hxx>
30
# include <TopTools_IndexedMapOfShape.hxx>
33
#include <App/Application.h>
34
#include <Base/Parameter.h>
36
#include "FeaturePartCommon.h"
37
#include "TopoShapeOpCode.h"
38
#include "modelRefine.h"
43
PROPERTY_SOURCE(Part::Common, Part::Boolean)
46
Common::Common() = default;
48
const char *Common::opCode() const
50
return Part::OpCodes::Common;
53
BRepAlgoAPI_BooleanOperation* Common::makeOperation(const TopoDS_Shape& base, const TopoDS_Shape& tool) const
55
// Let's call algorithm computing a section operation:
56
return new BRepAlgoAPI_Common(base, tool);
59
// ----------------------------------------------------
61
PROPERTY_SOURCE(Part::MultiCommon, Part::Feature)
64
MultiCommon::MultiCommon()
66
ADD_PROPERTY(Shapes,(nullptr));
68
ADD_PROPERTY_TYPE(History,(ShapeHistory()), "Boolean", (App::PropertyType)
69
(App::Prop_Output|App::Prop_Transient|App::Prop_Hidden), "Shape history");
72
ADD_PROPERTY_TYPE(Refine,(0),"Boolean",(App::PropertyType)(App::Prop_None),"Refine shape (clean up redundant edges) after this boolean operation");
74
//init Refine property
75
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
76
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/Part/Boolean");
77
this->Refine.setValue(hGrp->GetBool("RefineModel", false));
80
short MultiCommon::mustExecute() const
82
if (Shapes.isTouched())
87
App::DocumentObjectExecReturn *MultiCommon::execute()
89
std::vector<TopoShape> shapes;
90
for (auto obj : Shapes.getValues()) {
91
TopoShape sh = Feature::getTopoShape(obj);
93
return new App::DocumentObjectExecReturn("Input shape is null");
99
res.makeElementBoolean(Part::OpCodes::Common, shapes);
101
throw Base::RuntimeError("Resulting shape is null");
104
Base::Reference<ParameterGrp> hGrp = App::GetApplication()
107
->GetGroup("Preferences")
108
->GetGroup("Mod/Part/Boolean");
109
if (hGrp->GetBool("CheckModel", false)) {
110
BRepCheck_Analyzer aChecker(res.getShape());
111
if (!aChecker.IsValid()) {
112
return new App::DocumentObjectExecReturn("Resulting shape is invalid");
116
if (this->Refine.getValue()) {
117
res = res.makeElementRefine();
119
this->Shape.setValue(res);
121
return Part::Feature::execute();