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 #ifndef FeaturesPlugin_Boolean_H_
21 #define FeaturesPlugin_Boolean_H_
23 #include "FeaturesPlugin.h"
24 #include "FeaturesPlugin_Tools.h"
26 #include <GeomAlgoAPI_MakeShape.h>
27 #include <GeomAlgoAPI_Tools.h>
29 #include <ModelAPI_Feature.h>
31 class ModelAPI_Result;
33 /// \class FeaturesPlugin_Boolean
35 /// \brief Feature for applying of Boolean operations on Solids.
36 /// Supports four kinds of Boolean operations: Cut, Fuse, Common and Smash.
37 class FeaturesPlugin_Boolean : public ModelAPI_Feature
48 /// Attribute name of main objects.
49 inline static const std::string& OBJECT_LIST_ID()
51 static const std::string MY_OBJECT_LIST_ID("main_objects");
52 return MY_OBJECT_LIST_ID;
55 /// Attribute name of tool objects.
56 inline static const std::string& TOOL_LIST_ID()
58 static const std::string MY_TOOL_LIST_ID("tool_objects");
59 return MY_TOOL_LIST_ID;
62 /// \return boolean operation type.
63 FEATURESPLUGIN_EXPORT OperationType operationType();
65 /// Request for initialization of data model of the feature: adding all attributes.
66 FEATURESPLUGIN_EXPORT virtual void initAttributes();
70 /// Use plugin manager for features creation.
71 FeaturesPlugin_Boolean(const OperationType theOperationType);
73 /// Load Naming data structure of the feature to the document
74 void loadNamingDS(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
75 const std::shared_ptr<GeomAPI_Shape> theBaseShape,
76 const ListOfShape& theTools,
77 const std::shared_ptr<GeomAPI_Shape> theResultShape,
78 const GeomMakeShapePtr& theMakeShape);
81 /// Auxiliary class to store hierarchy of Boolean operation objects/tools
82 /// and their parent shapes (compounds or compsolids)
83 class ObjectHierarchy {
84 typedef std::map<GeomShapePtr, ListOfShape, GeomAPI_Shape::Comparator> MapShapeToSubshapes;
85 typedef std::map<GeomShapePtr, GeomShapePtr, GeomAPI_Shape::Comparator> MapShapeToParent;
86 typedef std::set<GeomShapePtr, GeomAPI_Shape::Comparator> SetOfShape;
88 ListOfShape myObjects;
89 MapShapeToParent myParent;
90 MapShapeToSubshapes mySubshapes;
92 SetOfShape myProcessedObjects;
95 /// Add object of Boolean opration
96 void AddObject(const GeomShapePtr& theObject);
98 /// Maps shape and its parent
99 void AddParent(const GeomShapePtr& theShape, const GeomShapePtr& theParent);
101 /// Return parent shape for the given, or empty if it is a high-level shape.
102 /// By default, the parent and all its subshapes are marked as processed for further skip.
103 GeomShapePtr Parent(const GeomShapePtr& theShape, bool theMarkProcessed = true);
105 /// Split compound/compsolid shape for subshapes selected for Boolean operation and the other.
106 void SplitCompound(const GeomShapePtr& theCompShape,
107 ListOfShape& theUsed,
108 ListOfShape& theNotUsed) const;
110 /// Return \c true if there is no object in hierarchy
111 bool IsEmpty() const;
113 /// Return list of objects
114 const ListOfShape& Objects() const { return myObjects; }
115 /// Separate objects of the given range of types and all other objects
116 void ObjectsByType(ListOfShape& theShapesByType, ListOfShape& theOtherShapes,
117 const GeomAPI_Shape::ShapeType theMinType = GeomAPI_Shape::COMPOUND,
118 const GeomAPI_Shape::ShapeType theMaxType = GeomAPI_Shape::SHAPE) const;
122 friend class ObjectHierarchy;
124 ObjectHierarchy* myHierarchy;
125 ListOfShape::iterator myObject;
128 Iterator(ObjectHierarchy* theHierarchy, bool isBegin = true);
130 void SkipAlreadyProcessed();
133 bool operator==(const Iterator&) const;
134 bool operator!=(const Iterator&) const;
136 Iterator& operator++();
137 Iterator operator++(int);
139 GeomShapePtr operator*() const;
146 /// Process SelectionList attribute and fill the objects hierarchy.
147 bool processAttribute(const std::string& theAttributeName,
148 ObjectHierarchy& theObjects,
149 ListOfShape& thePlanesList);
151 /// Perform Boolean operation of the object with the tools
152 /// \return \c false if something went wrong
153 bool processObject(const GeomAlgoAPI_Tools::BOPType theBooleanType,
154 const GeomShapePtr& theObject,
155 const ListOfShape& theTools,
156 const ListOfShape& thePlanes,
158 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
159 ListOfShape& theResultShapesList);
161 /// Perform Boolean operation of the Compsolid with the tools
162 /// \return \c false if something went wrong
163 bool processCompsolid(const GeomAlgoAPI_Tools::BOPType theBooleanType,
164 const ObjectHierarchy& theCompsolidHierarchy,
165 const GeomShapePtr& theCompsolid,
166 const ListOfShape& theTools,
167 const ListOfShape& thePlanes,
169 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
170 ListOfShape& theResultShapesList);
172 /// Perform Boolean operation of the Compound with the tools
173 /// \return \c false if something went wrong
174 bool processCompound(const GeomAlgoAPI_Tools::BOPType theBooleanType,
175 const ObjectHierarchy& theCompoundHierarchy,
176 const GeomShapePtr& theCompound,
177 const ListOfShape& theTools,
179 std::vector<FeaturesPlugin_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
180 ListOfShape& theResultShapesList);
183 void parentForShape(const GeomShapePtr& theShape,
184 const std::shared_ptr<ModelAPI_Result>& theContext,
185 ObjectHierarchy& theShapesHierarchy);
188 OperationType myOperationType;