Salome HOME
bbcd26eb7cfd18c8eb163e5b1da495b7f841dd6d
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_CompositeBoolean.h
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef FeaturesPlugin_CompositeBoolean_H_
21 #define FeaturesPlugin_CompositeBoolean_H_
22
23 #include "FeaturesPlugin.h"
24
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_ResultBody.h>
27 #include <GeomAlgoAPI_MakeShape.h>
28 #include <GeomAlgoAPI_MakeShapeList.h>
29
30 /// \class FeaturesPlugin_CompositeBoolean
31 /// \ingroup Plugins
32 /// \brief Interface for the composite boolean feature.
33 class FeaturesPlugin_CompositeBoolean
34 {
35 public:
36   enum OperationType {
37     BOOL_CUT,
38     BOOL_FUSE,
39     BOOL_COMMON,
40     BOOL_SMASH
41   };
42
43   /// Attribute name of main objects.
44   inline static const std::string& OBJECTS_ID()
45   {
46     static const std::string MY_OBJECTS_ID("main_objects");
47     return MY_OBJECTS_ID;
48   }
49
50   /// Performs the algorithm and stores results it in the data structure.
51   FEATURESPLUGIN_EXPORT virtual void executeCompositeBoolean();
52
53   const OperationType& operationType() const { return myOperationType; }
54
55 protected:
56   struct ResultBaseAlgo {
57     ResultBodyPtr resultBody;
58     GeomShapePtr baseShape;
59     std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape;
60   };
61
62 protected:
63   FeaturesPlugin_CompositeBoolean(){};
64
65   /// Initializes boolean attributes.
66   void initBooleanAttributes();
67
68   /// This function need to be defined for extrusion/revolution generation.
69   virtual bool makeGeneration(ListOfShape& theBaseShapes,
70                               ListOfMakeShape& theMakeShapes) = 0;
71
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);
80
81   /// Stores generation history.
82   virtual void storeGenerationHistory(ResultBodyPtr theResultBody,
83                                       const GeomShapePtr theBaseShape,
84                                       const GeomMakeShapePtr theMakeShape) = 0;
85
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);
91
92   /// Stores deleted shapes.
93   void storeDeletedShapes(std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
94                           const ListOfShape& theTools,
95                           const GeomShapePtr theResultShapesCompound);
96
97 private:
98   /// Makes cut operation recursively. Called from makeBoolean().
99   /// \param[in] theCompound the shape to be cut.
100   /// \param[in] theTools list of tools.
101   /// \param[out] theMakeShapeList list of according algos.
102   /// \param[out] theResult result of cut.
103   /// \return false if failed or no cuts done (this is normal case).
104   bool cutRecursiveCompound (const GeomShapePtr theCompound,
105                              const ListOfShape& theTools,
106                              std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList,
107                              GeomShapePtr& theResult);
108
109 protected:
110   ModelAPI_Feature* myFeature;
111   OperationType myOperationType;
112 };
113
114 #endif