Salome HOME
Bug #1170: wrong object names in Main objects field Partition
[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, const std::string& theName, const int theTag = 1);
63
64
65   /// Records the shape newShape which is a modification of the shape oldShape.
66   /// As an example, consider the case of a face split or merged in a Boolean operation.
67   MODEL_EXPORT virtual void modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
68     const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName, const int theTag = 1);
69
70   /// Records the shape oldShape which was deleted from the current label.
71   /// As an example, consider the case of a face removed by a Boolean operation.
72   MODEL_EXPORT virtual void deleted(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
73     const int theTag = 1);
74
75   /// load deleted shapes
76   MODEL_EXPORT virtual void loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
77                                                std::shared_ptr<GeomAPI_Shape>  theShapeIn,
78                                                const int  theKindOfShape,
79                                                const int  theTag);
80   /// load and orient modified shapes
81   MODEL_EXPORT virtual void loadAndOrientModifiedShapes (
82                                                    GeomAlgoAPI_MakeShape* theMS,
83                                                std::shared_ptr<GeomAPI_Shape>  theShapeIn,
84                                                const int  theKindOfShape,
85                                                const int  theTag,
86                                                                                            const std::string& theName,
87                                                GeomAPI_DataMapOfShapeShape& theSubShapes,
88                                                const bool theIsStoreSeparate = false);
89    /// load and orient generated shapes
90   MODEL_EXPORT virtual void loadAndOrientGeneratedShapes (
91                                                    GeomAlgoAPI_MakeShape* theMS,
92                                                std::shared_ptr<GeomAPI_Shape>  theShapeIn,
93                                                const int  theKindOfShape,
94                                                const int  theTag,
95                                                                                            const std::string& theName,
96                                                GeomAPI_DataMapOfShapeShape& theSubShapes);
97   
98   /// Loads shapes of the first level (to be used during shape import)
99   MODEL_EXPORT virtual void loadFirstLevel(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int&  theTag);
100   
101   /// Loads disconnected edges
102   MODEL_EXPORT virtual void loadDisconnectedEdges(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int&  theTag);
103
104   /// Loads disconnected vetexes
105   MODEL_EXPORT virtual void loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int&  theTag);
106
107   /// Removes the stored builders
108   MODEL_EXPORT virtual ~Model_BodyBuilder();
109
110   /// Converts evolution of sub-shapes stored in naming structure to selection 
111   /// (theFlag = true) and back (theFlag = false)
112   MODEL_EXPORT virtual void evolutionToSelection(const bool theFlag);
113
114   /// Returns true if the latest modification of this body in the naming history
115   // is equal to the given shape
116   MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape);
117
118 protected:
119   /// Default constructor accessible only by Model_Objects
120   Model_BodyBuilder(ModelAPI_Object* theOwner);
121
122   /// Removes the stored builders
123   void clean();
124
125   /// Returns (creates if necessary) the builder created on the needed tag of sub-label
126   TNaming_Builder* builder(const int theTag);
127
128 private:
129   /// Loads shapes of the next level (to be used during shape import)
130   void loadNextLevels(std::shared_ptr<GeomAPI_Shape> theShape, const std::string& theName, int&  theTag);
131
132   /// builds name for the shape kept at the specified tag 
133   void buildName(const int theTag, const std::string& theName);
134
135   friend class Model_ResultBody;
136   friend class Model_ResultCompSolid;
137 };
138
139 #endif