1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "FeaturesPlugin_BooleanCut.h"
22 #include "FeaturesPlugin_Tools.h"
24 #include <ModelAPI_ResultBody.h>
25 #include <ModelAPI_AttributeSelectionList.h>
26 #include <ModelAPI_Tools.h>
28 #include <GeomAlgoAPI_Boolean.h>
29 #include <GeomAlgoAPI_CompoundBuilder.h>
30 #include <GeomAlgoAPI_MakeShapeList.h>
31 #include <GeomAlgoAPI_PaveFiller.h>
32 #include <GeomAlgoAPI_ShapeTools.h>
33 #include <GeomAlgoAPI_Tools.h>
35 #include <GeomAPI_ShapeExplorer.h>
36 #include <GeomAPI_ShapeIterator.h>
38 //==================================================================================================
39 FeaturesPlugin_BooleanCut::FeaturesPlugin_BooleanCut()
40 : FeaturesPlugin_Boolean(FeaturesPlugin_Boolean::BOOL_CUT)
44 //==================================================================================================
45 void FeaturesPlugin_BooleanCut::initAttributes()
47 FeaturesPlugin_Boolean::initAttributes();
48 initVersion(THE_VERSION_1, selectionList(OBJECT_LIST_ID()), selectionList(TOOL_LIST_ID()));
51 //==================================================================================================
52 void FeaturesPlugin_BooleanCut::execute()
54 ObjectHierarchy anObjects, aTools;
57 // Getting objects and tools
58 if (!processAttribute(OBJECT_LIST_ID(), anObjects, aPlanes) ||
59 !processAttribute(TOOL_LIST_ID(), aTools, aPlanes))
64 if(anObjects.IsEmpty() || aTools.IsEmpty()) {
65 std::string aFeatureError = "Error: Not enough objects for boolean operation.";
66 setError(aFeatureError);
70 // version of CUT feature
71 int aCutVersion = version();
73 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo> aResultBaseAlgoList;
74 ListOfShape aResultShapesList;
77 std::shared_ptr<GeomAlgoAPI_MakeShapeList> aMakeShapeList(new GeomAlgoAPI_MakeShapeList());
79 GeomShapePtr aResultCompound;
80 if (aCutVersion == THE_VERSION_1) {
81 // merge hierarchies of compounds containing objects and tools
83 keepUnusedSubsOfCompound(GeomShapePtr(), anObjects, aTools, aMakeShapeList);
86 // For solids cut each object with all tools.
88 for (ObjectHierarchy::Iterator anObjectsIt = anObjects.Begin();
89 anObjectsIt != anObjects.End() && isOk;
91 GeomShapePtr anObject = *anObjectsIt;
92 GeomShapePtr aParent = anObjects.Parent(anObject);
95 GeomAPI_Shape::ShapeType aShapeType = aParent->shapeType();
96 if (aShapeType == GeomAPI_Shape::COMPOUND) {
98 isOk = processCompound(GeomAlgoAPI_Tools::BOOL_CUT,
99 anObjects, aParent, aTools.Objects(),
100 aResultIndex, aResultBaseAlgoList, aResultShapesList,
103 else if (aShapeType == GeomAPI_Shape::COMPSOLID) {
104 // Compsolid handling
105 isOk = processCompsolid(GeomAlgoAPI_Tools::BOOL_CUT,
106 anObjects, aParent, aTools.Objects(), ListOfShape(),
107 aResultIndex, aResultBaseAlgoList, aResultShapesList,
111 // process object as is
112 isOk = processObject(GeomAlgoAPI_Tools::BOOL_CUT,
113 anObject, aTools.Objects(), aPlanes,
114 aResultIndex, aResultBaseAlgoList, aResultShapesList,
119 storeResult(anObjects.Objects(), aTools.Objects(), aResultCompound, aResultIndex,
120 aMakeShapeList, aResultBaseAlgoList);
122 // Store deleted shapes after all results has been proceeded. This is to avoid issue when in one
123 // result shape has been deleted, but in another it was modified or stayed.
124 if (!aResultCompound)
125 aResultCompound = GeomAlgoAPI_CompoundBuilder::compound(aResultShapesList);
126 FeaturesPlugin_Tools::loadDeletedShapes(aResultBaseAlgoList,
130 // remove the rest results if there were produced in the previous pass
131 removeResults(aResultIndex);