Salome HOME
Updated generated shapes storing.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_CompositeBoolean.h
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef FeaturesPlugin_CompositeBoolean_H_
22 #define FeaturesPlugin_CompositeBoolean_H_
23
24 #include "FeaturesPlugin.h"
25
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_ResultBody.h>
28 #include <GeomAlgoAPI_MakeShape.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   /// Creates a new part document if needed.
51   FEATURESPLUGIN_EXPORT virtual void executeCompositeBoolean();
52
53 protected:
54   struct ResultBaseAlgo {
55     ResultBodyPtr resultBody;
56     GeomShapePtr baseShape;
57     std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape;
58   };
59
60 protected:
61   FeaturesPlugin_CompositeBoolean(){};
62
63   /// Initializes boolean attributes.
64   void initBooleanAttributes();
65
66   /// This function need to be defined for extrusion/revolution generation.
67   virtual bool makeGeneration(ListOfShape& theBaseShapes,
68                               ListOfMakeShape& theMakeShapes) = 0;
69
70   /// Makes boolean operation.
71   /// \param[in] theTools list of tools.
72   /// \param[out] theObjects list of objects.
73   /// \param[out] theMakeShapes list of according algos.
74   /// \return false in failed.
75   bool makeBoolean(const ListOfShape& theTools,
76                    ListOfShape& theObjects,
77                    ListOfMakeShape& theMakeShapes);
78
79   /// Stores generation history.
80   virtual void storeGenerationHistory(ResultBodyPtr theResultBody,
81                                       const GeomShapePtr theBaseShape,
82                                       const GeomMakeShapePtr theMakeShape) = 0;
83
84   /// Stores modification history.
85   void storeModificationHistory(ResultBodyPtr theResultBody,
86                                 const GeomShapePtr theObject,
87                                 const ListOfShape& theTools,
88                                 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape);
89
90   /// Stores deleted shapes.
91   void storeDeletedShapes(std::vector<ResultBaseAlgo>& theResultBaseAlgoList,
92                           const ListOfShape& theTools,
93                           const GeomShapePtr theResultShapesCompound);
94
95 protected:
96   ModelAPI_Feature* myFeature;
97   OperationType myOperationType;
98 };
99
100 #endif