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