Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / Model / Model_BodyBuilder.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 Model_BodyBuilder_H_
22 #define Model_BodyBuilder_H_
23
24 #include "Model.h"
25 #include <ModelAPI_BodyBuilder.h>
26
27 #include <GeomAlgoAPI_MakeShape.h>
28 #include <GeomAPI_DataMapOfShapeShape.h>
29 #include <vector>
30
31 class TNaming_Builder;
32
33 /**\class Model_BodyBuilder
34  * \ingroup DataModel
35  * \brief Extra API for the ResultBody that allows to work with naming.
36  */
37 class Model_BodyBuilder : public ModelAPI_BodyBuilder
38 {
39   /// builders that store the naming history: one per label to allow store several shapes to one
40   /// label; index in vector corresponds to the label tag
41   std::map<int, TNaming_Builder*> myBuilders;
42 public:
43   /// Stores the shape (called by the execution method).
44   MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape,
45                                   const bool theIsStoreSameShapes = true);
46
47   /// Stores the generated shape (called by the execution method).
48   MODEL_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
49                                                const std::shared_ptr<GeomAPI_Shape>& theToShape);
50
51   /// Stores the modified shape (called by the execution method).
52   /// \param theOldShape shape that produces result
53   /// \param theNewShape resulting shape
54   /// \param theDecomposeSolidsTag tag for starting of solids sub-elements placement in case
55   ///          theNewShape is compound of solids, if zero it is not used
56   MODEL_EXPORT virtual void storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
57                                                 const std::shared_ptr<GeomAPI_Shape>& theNewShape,
58                                           const int theDecomposeSolidsTag = 0);
59
60   /// Stores the shape without naming support
61   /// \param theShape shape to store
62   MODEL_EXPORT virtual void storeWithoutNaming(const std::shared_ptr<GeomAPI_Shape>& theShape);
63
64   /// Returns the shape-result produced by this feature
65   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
66
67   /// Records the subshape newShape which was generated during a topological construction.
68   /// As an example, consider the case of a face generated in construction of a box.
69   MODEL_EXPORT virtual void generated(const std::shared_ptr<GeomAPI_Shape>& theNewShape,
70     const std::string& theName, const int theTag = 1);
71
72   /// Records the shape newShape which was generated from the shape oldShape during a topological
73   /// construction. As an example, consider the case of a face generated from an edge in
74   /// construction of a prism.
75   MODEL_EXPORT virtual void generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
76     const std::shared_ptr<GeomAPI_Shape>& theNewShape,
77     const std::string& theName, const int theTag = 1);
78
79
80   /// Records the shape newShape which is a modification of the shape oldShape.
81   /// As an example, consider the case of a face split or merged in a Boolean operation.
82   MODEL_EXPORT virtual void modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
83     const std::shared_ptr<GeomAPI_Shape>& theNewShape,
84     const std::string& theName, const int theTag = 1);
85
86   /// Records the shape oldShape which was deleted from the current label.
87   /// As an example, consider the case of a face removed by a Boolean operation.
88   MODEL_EXPORT virtual void deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
89     const int theTag = 1);
90
91   /// load deleted shapes
92   MODEL_EXPORT virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
93                                                std::shared_ptr<GeomAPI_Shape>  theShapeIn,
94                                                const int  theKindOfShape,
95                                                const int  theTag);
96   /// load and orient modified shapes
97   MODEL_EXPORT virtual void loadAndOrientModifiedShapes (
98                                                    GeomAlgoAPI_MakeShape* theMS,
99                                                std::shared_ptr<GeomAPI_Shape>  theShapeIn,
100                                                const int  theKindOfShape,
101                                                const int  theTag,
102                                                                                            const std::string& theName,
103                                                GeomAPI_DataMapOfShapeShape& theSubShapes,
104                                                const bool theIsStoreSeparate = false,
105                                                const bool theIsStoreAsGenerated = false);
106    /// load and orient generated shapes
107   MODEL_EXPORT virtual void loadAndOrientGeneratedShapes (
108                                                    GeomAlgoAPI_MakeShape* theMS,
109                                                std::shared_ptr<GeomAPI_Shape>  theShapeIn,
110                                                const int  theKindOfShape,
111                                                const int  theTag,
112                                                                                            const std::string& theName,
113                                                GeomAPI_DataMapOfShapeShape& theSubShapes);
114
115   /// Loads shapes of the first level (to be used during shape import)
116   MODEL_EXPORT virtual void loadFirstLevel(std::shared_ptr<GeomAPI_Shape> theShape,
117                                            const std::string& theName, int&  theTag);
118
119   /// Loads disconnected edges
120   MODEL_EXPORT virtual void loadDisconnectedEdges(std::shared_ptr<GeomAPI_Shape> theShape,
121                                                   const std::string& theName, int&  theTag);
122
123   /// Loads disconnected vetexes
124   MODEL_EXPORT virtual void loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape,
125                                                      const std::string& theName, int&  theTag);
126
127   /// Removes the stored builders
128   MODEL_EXPORT virtual ~Model_BodyBuilder();
129
130   /// Converts evolution of sub-shapes stored in naming structure to selection
131   /// (theFlag = true) and back (theFlag = false)
132   MODEL_EXPORT virtual void evolutionToSelection(const bool theFlag);
133
134   /// Returns true if the latest modification of this body in the naming history
135   // is equal to the given shape
136   MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape);
137
138 protected:
139   /// Default constructor accessible only by Model_Objects
140   Model_BodyBuilder(ModelAPI_Object* theOwner);
141
142   /// Removes the stored builders
143   void clean();
144
145   /// Returns (creates if necessary) the builder created on the needed tag of sub-label
146   TNaming_Builder* builder(const int theTag);
147
148 private:
149   /// Loads shapes of the next level (to be used during shape import)
150   void loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape,
151                       const std::string& theName, int&  theTag);
152
153   /// builds name for the shape kept at the specified tag
154   void buildName(const int theTag, const std::string& theName);
155
156   friend class Model_ResultBody;
157   friend class Model_ResultCompSolid;
158 };
159
160 #endif