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