1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef GeomAlgoAPI_MakeShape_H_
21 #define GeomAlgoAPI_MakeShape_H_
23 #include <GeomAlgoAPI.h>
24 #include <GeomAPI_DataMapOfShapeShape.h>
31 /// \class GeomAlgoAPI_MakeShape
33 /// \brief Interface to the root class of all topological shapes constructions
34 class GeomAlgoAPI_MakeShape : public GeomAPI_Interface
40 OCCT_BRepBuilderAPI_MakeShape,
45 /// \brief Empty constructor.
46 GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape();
48 /// Destructor for remove myHist
49 GEOMALGOAPI_EXPORT ~GeomAlgoAPI_MakeShape();
51 /// \brief Constructor by builder and builder type.
52 /// \param[in] theBuilder pointer to the builder.
53 /// \param[in] theBuilderType builder type.
54 template<class T> explicit GeomAlgoAPI_MakeShape(
56 const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
57 : GeomAPI_Interface(theBuilder),
58 myBuilderType(theBuilderType)
63 /// \brief Initializes internals.
64 /// \param[in] theBuilder pointer to the builder.
65 /// \param[in] theBuilderType builder type.
66 template<class T> void initialize(
68 const BuilderType theBuilderType = OCCT_BRepBuilderAPI_MakeShape)
71 myBuilderType = theBuilderType;
75 /// Execute the algorithm.
76 GEOMALGOAPI_EXPORT virtual void build() {}
78 /// \return status of builder.
79 GEOMALGOAPI_EXPORT bool isDone() const;
81 /// \return a shape built by the shape construction algorithm.
82 GEOMALGOAPI_EXPORT virtual const GeomShapePtr shape() const;
84 /// \return true if resulting shape is valid.
85 GEOMALGOAPI_EXPORT bool isValid() const;
87 /// \return map of sub-shapes of the result. To be used for History keeping.
88 GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfSubShapes() const;
90 /// \return the list of shapes generated from the shape \a theShape.
91 /// \param[in] theOldShape base shape.
92 /// \param[out] theNewShapes shapes generated from \a theShape. Does not cleared!
93 GEOMALGOAPI_EXPORT virtual void generated(const GeomShapePtr theOldShape,
94 ListOfShape& theNewShapes);
96 /// \return the list of shapes modified from the shape \a theShape.
97 /// \param[in] theOldShape base shape.
98 /// \param[out] theNewShapes shapes modified from \a theShape. Does not cleared!
99 GEOMALGOAPI_EXPORT virtual void modified(const GeomShapePtr theOldShape,
100 ListOfShape& theNewShapes);
102 /// \return true if theShape was deleted.
103 /// \param[in] theOldShape base shape.
104 GEOMALGOAPI_EXPORT virtual bool isDeleted(const GeomShapePtr theOldShape);
106 /// \return true if the data were correct.
107 GEOMALGOAPI_EXPORT virtual bool check() { return true; };
109 /// \brief Prepare the naming of faces.
110 GEOMALGOAPI_EXPORT virtual void prepareNamingFaces();
112 /// \return the list of created faces.
113 GEOMALGOAPI_EXPORT std::map< std::string, GeomShapePtr > getCreatedFaces() {
114 return myCreatedFaces;
117 /// \return the error.
118 GEOMALGOAPI_EXPORT std::string getError() { return myError; }
120 /// \brief Check the validity of the produced shape.
121 GEOMALGOAPI_EXPORT bool checkValid(std::string theMessage);
123 /// Optimization of access the new shapes by old shapes for the limited set of needed new shapes.
124 /// \param theWholeOld the whole old shape
125 /// \param theShapeType type of the sub-shapes that is used for optimization
126 /// \returns true if optimization containers are already filled
127 GEOMALGOAPI_EXPORT bool isNewShapesCollected(GeomShapePtr theWholeOld,
128 const int theShapeType);
130 /// Optimization of access the new shapes by old shapes for the limited set of needed new shapes.
131 /// \param theWholeOld the whole old shape
132 /// \param theShapeType type of the sub-shapes that is used for optimization
133 /// \returns true if optimization containers are already filled
134 GEOMALGOAPI_EXPORT void collectNewShapes(GeomShapePtr theWholeOld,
135 const int theShapeType);
137 /// Optimization of access the new shapes by old shapes for the limited set of needed new shapes.
138 /// \param theWholeOld the whole old shape
139 /// \param theNewShape the whole new shape
140 /// \param theShapeType type of the old sub-shapes
141 /// \returns compound of all old shapes that were used for creation of the given new
142 GEOMALGOAPI_EXPORT GeomShapePtr oldShapesForNew(GeomShapePtr theWholeOld,
143 GeomShapePtr theNewShape,
144 const int theShapeType);
146 /// Replaces \a theShape with shape from \a myMap.
147 GEOMALGOAPI_EXPORT void fixOrientation(GeomShapePtr& theShape);
150 /// \brief Sets builder type.
151 /// \param[in] theBuilderType new builder type.
152 void setBuilderType(const BuilderType theBuilderType);
154 /// \brief Sets status of builder.
155 /// \param[in] theFlag new status.
156 void setDone(const bool theFlag);
158 /// \brief Sets result shape.
159 /// \param[in] theShape new shape.
160 void setShape(const GeomShapePtr theShape);
162 /// \return true if passed shape is valid for history.
163 bool isValidForHistory(const GeomShapePtr theShape);
166 /// Data map to keep correct orientation of sub-shapes.
167 std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
168 /// Error occurred during the execution of an algorithm.
170 /// Map of created faces with their name for naming.
171 std::map< std::string, GeomShapePtr > myCreatedFaces;
174 /// \brief Initializes internals.
178 GeomAlgoAPI_MakeShape::BuilderType myBuilderType; ///< Type of make shape builder.
179 bool myDone; ///< Builder status.
180 GeomShapePtr myShape; ///< Resulting shape.
182 /// map that is used to keep the optimization structure for access to the history
183 /// kind of sub-shapes -> whole old shape -> new shape -> list of old shapes that create this new
187 typedef std::shared_ptr<GeomAlgoAPI_MakeShape> GeomMakeShapePtr;
188 typedef std::list<GeomMakeShapePtr> ListOfMakeShape;