Salome HOME
1b423738e5c9e4efda760ecc79292509db6f29d9
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_MakeShape.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_MakeShape.h
4 // Created:     17 Oct 2014
5 // Author:      Sergey ZARITCHNY
6 //
7 // Modified by Clarisse Genrault (CEA) : 17 Mar 2016
8
9 #ifndef GeomAlgoAPI_MakeShape_H_
10 #define GeomAlgoAPI_MakeShape_H_
11
12 #include <GeomAlgoAPI.h>
13 #include <GeomAPI_DataMapOfShapeShape.h>
14
15 #include <list>
16 #include <memory>
17 #include <map>
18
19 /// \class GeomAlgoAPI_MakeShape
20 /// \ingroup DataAlgo
21 /// \brief Interface to the root class of all topological shapes constructions
22 class GeomAlgoAPI_MakeShape : public GeomAPI_Interface
23 {
24 public:
25   /// Builder type enum
26   enum BuilderType {
27     Unknown,
28     OCCT_BRepBuilderAPI_MakeShape,
29     OCCT_BOPAlgo_Builder
30   };
31
32 public:
33   /// \brief Empty constructor.
34   GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape();
35
36   /// \brief Constructor by builder and builder type.
37   /// \param[in] theBuilder pointer to the builder.
38   /// \param[in] theBuilderType builder type.
39   template<class T> explicit GeomAlgoAPI_MakeShape(T* theBuilder, const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
40   : GeomAPI_Interface(theBuilder),
41     myBuilderType(theBuilderType)
42   {
43     initialize();
44   }
45
46   /// \brief Initializes internals.
47   /// \param[in] theBuilder pointer to the builder.
48   /// \param[in] theBuilderType builder type.
49   template<class T> void initialize(T* theBuilder, const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
50   {
51     setImpl(theBuilder);
52     myBuilderType = theBuilderType;
53     initialize();
54   }
55
56   /// \return status of builder.
57   GEOMALGOAPI_EXPORT bool isDone() const;
58
59   /// \return a shape built by the shape construction algorithm.
60   GEOMALGOAPI_EXPORT virtual const std::shared_ptr<GeomAPI_Shape> shape() const;
61
62   /// \return true if resulting shape is valid.
63   GEOMALGOAPI_EXPORT bool isValid() const;
64
65   /// \return true if resulting shape has volume.
66   GEOMALGOAPI_EXPORT bool hasVolume() const;
67
68   /// \return map of sub-shapes of the result. To be used for History keeping.
69   GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfSubShapes() const;
70
71   /// \return the list of shapes generated from the shape \a theShape.
72   /// \param[in] theShape base shape.
73   /// \param[out] theHistory generated shapes.
74   GEOMALGOAPI_EXPORT virtual void generated(const std::shared_ptr<GeomAPI_Shape> theShape,
75                                             ListOfShape& theHistory);
76
77   /// \return the list of shapes modified from the shape \a theShape.
78   /// \param[in] theShape base shape.
79   /// \param[out] theHistory modified shapes.
80   GEOMALGOAPI_EXPORT virtual void modified(const std::shared_ptr<GeomAPI_Shape> theShape,
81                                            ListOfShape& theHistory);
82
83   /// \return true if theShape was deleted.
84   /// \param[in] theShape base shape.
85   GEOMALGOAPI_EXPORT virtual bool isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape);
86
87   /// \return true if the data were correct.
88   GEOMALGOAPI_EXPORT virtual bool check() { return true; };
89
90   ///  \return the list of created faces.
91   GEOMALGOAPI_EXPORT std::map< std::string, std::shared_ptr<GeomAPI_Shape> > getCreatedFaces() {return myCreatedFaces;}
92
93   /// \return the error.
94   GEOMALGOAPI_EXPORT std::string getError() { return myError; }
95
96   /// \brief Prepare the naming of faces.
97   GEOMALGOAPI_EXPORT virtual void prepareNamingFaces();
98
99   /// \brief Check the validity of the produced shape.
100   GEOMALGOAPI_EXPORT bool checkValid(std::string theMessage);
101
102 protected:
103   /// \brief Sets builder type.
104   /// \param[in] theBuilderType new builder type.
105   void setBuilderType(const BuilderType theBuilderType);
106
107   /// \brief Sets status of builder.
108   /// \param[in] theFlag new status.
109   void setDone(const bool theFlag);
110
111   /// \brief Sets result shape.
112   /// \param[in] theShape new shape.
113   void setShape(const std::shared_ptr<GeomAPI_Shape> theShape);
114
115 protected:
116   std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap; ///< Data map to keep correct orientation of sub-shapes.
117   std::string myError; /// Error occurred during the execution of an algorithm.
118   std::map< std::string, std::shared_ptr<GeomAPI_Shape> > myCreatedFaces; /// Map of created faces with their name for naming.
119   
120 private:
121   /// \brief Initializes internals.
122   void initialize();
123
124 private:
125   GeomAlgoAPI_MakeShape::BuilderType myBuilderType; ///< Type of make shape builder.
126   bool myDone; ///< Builder status.
127   std::shared_ptr<GeomAPI_Shape> myShape; ///< Resulting shape.
128 };
129
130 typedef std::list<std::shared_ptr<GeomAlgoAPI_MakeShape> > ListOfMakeShape;
131
132 #endif