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