1 // Copyright (C) 2014-2022 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_CompositeBoolean_H_
21 #define FeaturesPlugin_CompositeBoolean_H_
23 #include "FeaturesPlugin.h"
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_ResultBody.h>
27 #include <GeomAlgoAPI_MakeShape.h>
28 #include <GeomAlgoAPI_MakeShapeList.h>
30 /// \class FeaturesPlugin_CompositeBoolean
32 /// \brief Interface for the composite boolean feature.
33 class FeaturesPlugin_CompositeBoolean
43 /// Attribute name of main objects.
44 inline static const std::string& OBJECTS_ID()
46 static const std::string MY_OBJECTS_ID("main_objects");
50 /// Performs the algorithm and stores results it in the data structure.
51 FEATURESPLUGIN_EXPORT virtual void executeCompositeBoolean();
53 const OperationType& operationType() const { return myOperationType; }
56 struct ResultBaseAlgo {
57 ResultBodyPtr resultBody;
58 GeomShapePtr baseShape;
59 std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape;
63 FeaturesPlugin_CompositeBoolean(){};
65 /// Initializes boolean attributes.
66 void initBooleanAttributes();
68 /// This function need to be defined for extrusion/revolution generation.
69 virtual bool makeGeneration(ListOfShape& theBaseShapes,
70 ListOfMakeShape& theMakeShapes) = 0;
72 /// Makes boolean operation.
73 /// \param[in] theTools list of tools.
74 /// \param[out] theObjects list of objects.
75 /// \param[out] theMakeShapes list of according algos.
76 /// \return false if failed.
77 bool makeBoolean(const ListOfShape& theTools,
78 ListOfShape& theObjects,
79 ListOfMakeShape& theMakeShapes);
81 /// Stores generation history.
82 virtual void storeGenerationHistory(ResultBodyPtr theResultBody,
83 const GeomShapePtr theBaseShape,
84 const GeomMakeShapePtr theMakeShape) = 0;
86 /// Stores modification history.
87 void storeModificationHistory(ResultBodyPtr theResultBody,
88 const GeomShapePtr theObject,
89 const ListOfShape& theTools,
90 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape);
92 /// Stores deleted shapes.
93 void storeDeletedShapes(std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
94 const ListOfShape& theTools,
95 const GeomShapePtr theResultShapesCompound);
98 /// Makes cut operation recursively.
99 /// Called from makeBoolean().
100 /// \param[in] theCompound the shape to be cut.
101 /// \param[in] theTools list of tools.
102 /// \param[out] theMakeShapeList list of according algos.
103 /// \param[out] theResult result of cut.
104 /// \return false if failed or no cuts done (this is normal case).
105 bool cutRecursiveCompound (const GeomShapePtr theCompound,
106 const ListOfShape& theTools,
107 std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList,
108 GeomShapePtr& theResult);
110 /// Add subshapes of \a theCompound to \a theSubShapesToAdd list,
111 /// except ones from \a theSubShapesToAvoid.
112 /// Called from makeBoolean().
113 /// \param[in] theCompound the shape to collect sub-shapes of.
114 /// \param[in] theSubShapesToAvoid list of shapes that should not be added to the result.
115 /// \param[out] theSubShapesToAdd list of found sub-shapes.
116 void addSubShapes (const GeomShapePtr theCompound,
117 const ListOfShape& theSubShapesToAvoid,
118 ListOfShape& theSubShapesToAdd);
121 ModelAPI_Feature* myFeature;
122 OperationType myOperationType;