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