Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_VersionedBoolean.h
1 // Copyright (C) 2014-2023  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_VersionedBoolean_H_
21 #define FeaturesPlugin_VersionedBoolean_H_
22
23 #include "FeaturesPlugin.h"
24 #include "FeaturesPlugin_Tools.h"
25
26 #include <GeomAPI_ShapeHierarchy.h>
27 #include <GeomAlgoAPI_Tools.h>
28
29 #include <ModelAPI_Feature.h>
30 #include <ModelAPI_Tools.h>
31
32 class ModelAPI_Attribute;
33 class ModelAPI_Result;
34 class GeomAlgoAPI_MakeShapeList;
35
36 /// \class FeaturesPlugin_VersionedBoolean
37 /// \ingroup Plugins
38 /// \brief Feature controls a version of Boolean operations.
39 class FeaturesPlugin_VersionedBoolean : public ModelAPI_Feature
40 {
41 protected:
42   static const std::string& BOP_VERSION_9_4()
43   {
44     static const std::string VERSION("v9.4");
45     return VERSION;
46   }
47
48   /// Use plugin manager for features creation.
49   FeaturesPlugin_VersionedBoolean() {}
50
51   /// Initialize version field of the Boolean feature.
52   /// The version is initialized for newly created features,
53   /// not read from previously stored document.
54   void initVersion(const std::string& theVersion,
55                    const std::shared_ptr<ModelAPI_Attribute> theObjectsAttr
56                             = std::shared_ptr<ModelAPI_Attribute>(),
57                    const std::shared_ptr<ModelAPI_Attribute> theToolsAttr
58                             = std::shared_ptr<ModelAPI_Attribute>());
59
60   /// Process SelectionList attribute and fill the objects hierarchy.
61   bool processAttribute(const std::string& theAttributeName,
62                         GeomAPI_ShapeHierarchy& theObjects,
63                         ListOfShape& thePlanesList);
64
65   /// Perform Boolean operation of the object with the tools.
66   /// In case of theResultCompound is not empty, the result of Boolean operation
67   /// is added to this compound, and corresponding ResultBody is not generated.
68   /// \return \c false if something went wrong
69   bool processObject(const GeomAlgoAPI_Tools::BOPType theBooleanType,
70                      const GeomShapePtr& theObject,
71                      const ListOfShape& theTools,
72                      const ListOfShape& thePlanes,
73                      const double theFuzzy,
74                      int& theResultIndex,
75                      std::vector<ModelAPI_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
76                      ListOfShape& theResultShapesList,
77                      GeomShapePtr theResulCompound = GeomShapePtr());
78
79   /// Perform Boolean operation of the Compsolid with the tools
80   /// In case of theResultCompound is not empty, the result of Boolean operation
81   /// is added to this compound, and corresponding ResultBody is not generated.
82   /// \return \c false if something went wrong
83   bool processCompsolid(const GeomAlgoAPI_Tools::BOPType theBooleanType,
84                         GeomAPI_ShapeHierarchy& theCompsolidHierarchy,
85                         const GeomShapePtr& theCompsolid,
86                         const ListOfShape& theTools,
87                         const ListOfShape& thePlanes,
88                         const double theFuzzy,
89                         int& theResultIndex,
90                         std::vector<ModelAPI_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
91                         ListOfShape& theResultShapesList,
92                         GeomShapePtr theResulCompound = GeomShapePtr());
93
94   /// Perform Boolean operation of the Compound with the tools
95   /// In case of theResultCompound is not empty, the result of Boolean operation
96   /// is added to this compound, and corresponding ResultBody is not generated.
97   /// \return \c false if something went wrong
98   bool processCompound(const GeomAlgoAPI_Tools::BOPType theBooleanType,
99                        GeomAPI_ShapeHierarchy& theCompoundHierarchy,
100                        const GeomShapePtr& theCompound,
101                        const ListOfShape& theTools,
102                        const double theFuzzy,
103                        int& theResultIndex,
104                        std::vector<ModelAPI_Tools::ResultBaseAlgo>& theResultBaseAlgoList,
105                        ListOfShape& theResultShapesList,
106                        GeomShapePtr theResulCompound = GeomShapePtr());
107
108   /// Resize planes to fit them to the bounding box of the given lins of objects.
109   static void resizePlanes(const ListOfShape& theObjects,
110                            ListOfShape& thePlanes,
111                            std::shared_ptr<GeomAlgoAPI_MakeShapeList>& theMakeShapeList);
112
113   /// Process unused sub-shapes of compounds.
114   /// Keep the compound hierarchy, but merge top-level compounds
115   /// into a single compound and add the result of the FUSE operation.
116   GeomShapePtr keepUnusedSubsOfCompound(
117       const GeomShapePtr& theResult,
118       const GeomAPI_ShapeHierarchy& theObjectsHierarchy,
119       const GeomAPI_ShapeHierarchy& theToolsHierarchy,
120       std::shared_ptr<GeomAlgoAPI_MakeShapeList> theMakeShapeList);
121 };
122
123 #endif