Salome HOME
cf844349a18d151f14d3b38ce8c3f4a7b5a818f7
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_MakeShape.h
1 // Copyright (C) 2014-2024  CEA, EDF
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 GeomAlgoAPI_MakeShape_H_
21 #define GeomAlgoAPI_MakeShape_H_
22
23 #include <GeomAlgoAPI.h>
24 #include <GeomAPI_DataMapOfShapeShape.h>
25
26 #include <list>
27 #include <memory>
28 #include <map>
29 #include <string>
30
31 /// \class GeomAlgoAPI_MakeShape
32 /// \ingroup DataAlgo
33 /// \brief Interface to the root class of all topological shapes constructions
34 class GeomAlgoAPI_MakeShape : public GeomAPI_Interface
35 {
36 public:
37   /// Builder type enum
38   enum BuilderType {
39     Unknown,
40     OCCT_BRepBuilderAPI_MakeShape,
41     OCCT_BOPAlgo_Builder
42   };
43
44 public:
45   /// \brief Empty constructor.
46   GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape();
47
48   /// Destructor for remove myHist
49   GEOMALGOAPI_EXPORT ~GeomAlgoAPI_MakeShape();
50
51   /// \brief Constructor by builder and builder type.
52   /// \param[in] theBuilder pointer to the builder.
53   /// \param[in] theBuilderType builder type.
54   template<class T> explicit GeomAlgoAPI_MakeShape(
55     T* theBuilder,
56     const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
57   : GeomAPI_Interface(theBuilder),
58     myBuilderType(theBuilderType)
59   {
60     initialize();
61   }
62
63   /// \brief Initializes internals.
64   /// \param[in] theBuilder pointer to the builder.
65   /// \param[in] theBuilderType builder type.
66   template<class T> void initialize(
67     T* theBuilder,
68     const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
69   {
70     setImpl(theBuilder);
71     myBuilderType = theBuilderType;
72     initialize();
73   }
74
75   /// Execute the algorithm.
76   GEOMALGOAPI_EXPORT virtual void build() {}
77
78   /// \return status of builder.
79   GEOMALGOAPI_EXPORT bool isDone() const;
80
81   /// \return a shape built by the shape construction algorithm.
82   GEOMALGOAPI_EXPORT virtual const GeomShapePtr shape() const;
83
84   /// \return true if resulting shape is valid.
85   GEOMALGOAPI_EXPORT bool isValid() const;
86
87   /// \return map of sub-shapes of the result. To be used for History keeping.
88   GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfSubShapes() const;
89
90   /// \return the list of shapes generated from the shape \a theShape.
91   /// \param[in] theOldShape base shape.
92   /// \param[out] theNewShapes shapes generated from \a theShape. Does not cleared!
93   GEOMALGOAPI_EXPORT virtual void generated(const GeomShapePtr theOldShape,
94                                             ListOfShape& theNewShapes);
95
96   /// \return the list of shapes modified from the shape \a theShape.
97   /// \param[in] theOldShape base shape.
98   /// \param[out] theNewShapes shapes modified from \a theShape. Does not cleared!
99   GEOMALGOAPI_EXPORT virtual void modified(const GeomShapePtr theOldShape,
100                                            ListOfShape& theNewShapes);
101
102   /// \return true if theShape was deleted.
103   /// \param[in] theOldShape base shape.
104   GEOMALGOAPI_EXPORT virtual bool isDeleted(const GeomShapePtr theOldShape);
105
106   /// \return true if the data were correct.
107   GEOMALGOAPI_EXPORT virtual bool check() { return true; };
108
109   /// \brief Prepare the naming of faces.
110   GEOMALGOAPI_EXPORT virtual void prepareNamingFaces();
111
112   ///  \return the list of created faces.
113   GEOMALGOAPI_EXPORT std::map< std::string, GeomShapePtr > getCreatedFaces() {
114     return myCreatedFaces;
115   }
116
117   /// \return the error.
118   GEOMALGOAPI_EXPORT std::string getError() { return myError; }
119
120   /// \brief Check the validity of the produced shape.
121   GEOMALGOAPI_EXPORT bool checkValid(std::string theMessage);
122
123   /// Optimization of access the new shapes by old shapes for the limited set of needed new shapes.
124   /// \param theWholeOld the whole old shape
125   /// \param theShapeType type of the sub-shapes that is used for optimization
126   /// \returns true if optimization containers are already filled
127   GEOMALGOAPI_EXPORT bool isNewShapesCollected(GeomShapePtr theWholeOld,
128                                                const int theShapeType);
129
130   /// Optimization of access the new shapes by old shapes for the limited set of needed new shapes.
131   /// \param theWholeOld the whole old shape
132   /// \param theShapeType type of the sub-shapes that is used for optimization
133   /// \returns true if optimization containers are already filled
134   GEOMALGOAPI_EXPORT void collectNewShapes(GeomShapePtr theWholeOld,
135                                            const int theShapeType);
136
137   /// Optimization of access the new shapes by old shapes for the limited set of needed new shapes.
138   /// \param theWholeOld the whole old shape
139   /// \param theNewShape the whole new shape
140   /// \param theShapeType type of the old sub-shapes
141   /// \returns compound of all old shapes that were used for creation of the given new
142   GEOMALGOAPI_EXPORT GeomShapePtr oldShapesForNew(GeomShapePtr theWholeOld,
143                                                   GeomShapePtr theNewShape,
144                                                   const int theShapeType);
145
146   /// Replaces \a theShape with shape from \a myMap.
147   GEOMALGOAPI_EXPORT void fixOrientation(GeomShapePtr& theShape);
148
149 protected:
150   /// \brief Sets builder type.
151   /// \param[in] theBuilderType new builder type.
152   GEOMALGOAPI_EXPORT void setBuilderType(const BuilderType theBuilderType);
153
154   /// \brief Sets status of builder.
155   /// \param[in] theFlag new status.
156   GEOMALGOAPI_EXPORT void setDone(const bool theFlag);
157
158   /// \brief Sets result shape.
159   /// \param[in] theShape new shape.
160   GEOMALGOAPI_EXPORT void setShape(const GeomShapePtr theShape);
161
162   /// \return true if passed shape is valid for history.
163   bool isValidForHistory(const GeomShapePtr theShape);
164
165 protected:
166    /// Data map to keep correct orientation of sub-shapes.
167   std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
168   /// Error occurred during the execution of an algorithm.
169   std::string myError;
170   /// Map of created faces with their name for naming.
171   std::map< std::string, GeomShapePtr > myCreatedFaces;
172
173 private:
174   /// \brief Initializes internals.
175   void initialize();
176
177 private:
178   GeomAlgoAPI_MakeShape::BuilderType myBuilderType; ///< Type of make shape builder.
179   bool myDone; ///< Builder status.
180   GeomShapePtr myShape; ///< Resulting shape.
181
182   /// map that is used to keep the optimization structure for access to the history
183   /// kind of sub-shapes -> whole old shape -> new shape -> list of old shapes that create this new
184   void* myHist;
185 };
186
187 typedef std::shared_ptr<GeomAlgoAPI_MakeShape> GeomMakeShapePtr;
188 typedef std::list<GeomMakeShapePtr> ListOfMakeShape;
189
190 #endif