Salome HOME
Copyright update 2021
[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
29 /// \class FeaturesPlugin_CompositeBoolean
30 /// \ingroup Plugins
31 /// \brief Interface for the composite boolean feature.
32 class FeaturesPlugin_CompositeBoolean
33 {
34 public:
35   enum OperationType {
36     BOOL_CUT,
37     BOOL_FUSE,
38     BOOL_COMMON,
39     BOOL_SMASH
40   };
41
42   /// Attribute name of main objects.
43   inline static const std::string& OBJECTS_ID()
44   {
45     static const std::string MY_OBJECTS_ID("main_objects");
46     return MY_OBJECTS_ID;
47   }
48
49   /// Performs the algorithm and stores results it in the data structure.
50   FEATURESPLUGIN_EXPORT virtual void executeCompositeBoolean();
51
52   const OperationType& operationType() const { return myOperationType; }
53
54 protected:
55   struct ResultBaseAlgo {
56     ResultBodyPtr resultBody;
57     GeomShapePtr baseShape;
58     std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape;
59   };
60
61 protected:
62   FeaturesPlugin_CompositeBoolean(){};
63
64   /// Initializes boolean attributes.
65   void initBooleanAttributes();
66
67   /// This function need to be defined for extrusion/revolution generation.
68   virtual bool makeGeneration(ListOfShape& theBaseShapes,
69                               ListOfMakeShape& theMakeShapes) = 0;
70
71   /// Makes boolean operation.
72   /// \param[in] theTools list of tools.
73   /// \param[out] theObjects list of objects.
74   /// \param[out] theMakeShapes list of according algos.
75   /// \return false in failed.
76   bool makeBoolean(const ListOfShape& theTools,
77                    ListOfShape& theObjects,
78                    ListOfMakeShape& theMakeShapes);
79
80   /// Stores generation history.
81   virtual void storeGenerationHistory(ResultBodyPtr theResultBody,
82                                       const GeomShapePtr theBaseShape,
83                                       const GeomMakeShapePtr theMakeShape) = 0;
84
85   /// Stores modification history.
86   void storeModificationHistory(ResultBodyPtr theResultBody,
87                                 const GeomShapePtr theObject,
88                                 const ListOfShape& theTools,
89                                 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape);
90
91   /// Stores deleted shapes.
92   void storeDeletedShapes(std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
93                           const ListOfShape& theTools,
94                           const GeomShapePtr theResultShapesCompound);
95
96 protected:
97   ModelAPI_Feature* myFeature;
98   OperationType myOperationType;
99 };
100
101 #endif