]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_MakeShape.h
Salome HOME
dbf15a320f6dc9575fd0c2a3d1d63920c24e1e23
[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 email : webmaster.salome@opencascade.com<mailto: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   /// \brief Constructor by builder and builder type.
49   /// \param[in] theBuilder pointer to the builder.
50   /// \param[in] theBuilderType builder type.
51   template<class T> explicit GeomAlgoAPI_MakeShape(T* theBuilder,
52     const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
53   : GeomAPI_Interface(theBuilder),
54     myBuilderType(theBuilderType)
55   {
56     initialize();
57   }
58
59   /// \brief Initializes internals.
60   /// \param[in] theBuilder pointer to the builder.
61   /// \param[in] theBuilderType builder type.
62   template<class T> void initialize(T* theBuilder,
63     const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
64   {
65     setImpl(theBuilder);
66     myBuilderType = theBuilderType;
67     initialize();
68   }
69
70   /// \return status of builder.
71   GEOMALGOAPI_EXPORT bool isDone() const;
72
73   /// \return a shape built by the shape construction algorithm.
74   GEOMALGOAPI_EXPORT virtual const std::shared_ptr<GeomAPI_Shape> shape() const;
75
76   /// \return true if resulting shape is valid.
77   GEOMALGOAPI_EXPORT bool isValid() const;
78
79   /// \return true if resulting shape has volume.
80   GEOMALGOAPI_EXPORT bool hasVolume() const;
81
82   /// \return map of sub-shapes of the result. To be used for History keeping.
83   GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfSubShapes() const;
84
85   /// \return the list of shapes generated from the shape \a theShape.
86   /// \param[in] theShape base shape.
87   /// \param[out] theHistory generated shapes.
88   GEOMALGOAPI_EXPORT virtual void generated(const std::shared_ptr<GeomAPI_Shape> theShape,
89                                             ListOfShape& theHistory);
90
91   /// \return the list of shapes modified from the shape \a theShape.
92   /// \param[in] theShape base shape.
93   /// \param[out] theHistory modified shapes. Does not cleared!
94   GEOMALGOAPI_EXPORT virtual void modified(const std::shared_ptr<GeomAPI_Shape> theShape,
95                                            ListOfShape& theHistory);
96
97   /// \return true if theShape was deleted.
98   /// \param[in] theShape base shape.
99   GEOMALGOAPI_EXPORT virtual bool isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape);
100
101   /// \return true if the data were correct.
102   GEOMALGOAPI_EXPORT virtual bool check() { return true; };
103
104   ///  \return the list of created faces.
105   GEOMALGOAPI_EXPORT std::map< std::string, std::shared_ptr<GeomAPI_Shape> > getCreatedFaces()
106   {return myCreatedFaces;}
107
108   /// \return the error.
109   GEOMALGOAPI_EXPORT std::string getError() { return myError; }
110
111   /// \brief Prepare the naming of faces.
112   GEOMALGOAPI_EXPORT virtual void prepareNamingFaces();
113
114   /// \brief Check the validity of the produced shape.
115   GEOMALGOAPI_EXPORT bool checkValid(std::string theMessage);
116
117 protected:
118   /// \brief Sets builder type.
119   /// \param[in] theBuilderType new builder type.
120   void setBuilderType(const BuilderType theBuilderType);
121
122   /// \brief Sets status of builder.
123   /// \param[in] theFlag new status.
124   void setDone(const bool theFlag);
125
126   /// \brief Sets result shape.
127   /// \param[in] theShape new shape.
128   void setShape(const std::shared_ptr<GeomAPI_Shape> theShape);
129
130 protected:
131    /// Data map to keep correct orientation of sub-shapes.
132   std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
133   /// Error occurred during the execution of an algorithm.
134   std::string myError;
135   /// Map of created faces with their name for naming.
136   std::map< std::string, std::shared_ptr<GeomAPI_Shape> > myCreatedFaces;
137
138 private:
139   /// \brief Initializes internals.
140   void initialize();
141
142 private:
143   GeomAlgoAPI_MakeShape::BuilderType myBuilderType; ///< Type of make shape builder.
144   bool myDone; ///< Builder status.
145   std::shared_ptr<GeomAPI_Shape> myShape; ///< Resulting shape.
146 };
147
148 typedef std::list<std::shared_ptr<GeomAlgoAPI_MakeShape> > ListOfMakeShape;
149
150 #endif