Salome HOME
5c19f711ccd2c2f7ec8c8e7f163cec4aa87b8ab9
[modules/shaper.git] / src / ModelAPI / ModelAPI_ResultBody.h
1 // Copyright (C) 2014-2021  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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef ModelAPI_ResultBody_H_
21 #define ModelAPI_ResultBody_H_
22
23 #include "ModelAPI_Result.h"
24 #include <GeomAPI_Shape.h>
25 #include <GeomAPI_DataMapOfShapeShape.h>
26 #include <string>
27 #include <map>
28 #include <vector>
29
30 class ModelAPI_BodyBuilder;
31 class GeomAlgoAPI_MakeShape;
32
33 /**\class ModelAPI_ResultBody
34 * \ingroup DataModel
35 * \brief The body (shape) result of a feature.
36 *
37 * Provides a shape that may be displayed in the viewer.
38 * May provide really huge results, so, working with this kind
39 * of result must be optimized.
40 * Also provides a container of sub-body result in case it is compound or compsolid.
41 */
42 class ModelAPI_ResultBody : public ModelAPI_Result
43 {
44 public:
45   /// Internal enumeration for storage the information of connected topology flag
46   enum ConnectedTopologyFlag {
47     ConnectionNotComputed, ///< not yet computed
48     IsConnected,           ///< the topology is connected
49     IsNotConnected         ///< the topology is connected
50   };
51
52 protected:
53   /// Keeps (not persistently) the connected topology flag
54   ConnectedTopologyFlag myConnect;
55
56   ModelAPI_BodyBuilder* myBuilder; ///< provides the body processing in naming shape
57
58 public:
59   MODELAPI_EXPORT virtual ~ModelAPI_ResultBody();
60
61   /// Returns the group identifier of this result
62   MODELAPI_EXPORT virtual std::string groupName();
63
64   /// Returns the group identifier of this result
65   inline static std::string group()
66   {
67     static std::string MY_GROUP = "Bodies";
68     return MY_GROUP;
69   }
70
71   /// default color for a result body
72   inline static const std::string& DEFAULT_COLOR()
73   {
74     static const std::string RESULT_BODY_COLOR("200,200,230");
75     return RESULT_BODY_COLOR;
76   }
77
78   /// default deflection for a result body
79   inline static const std::string DEFAULT_DEFLECTION()
80   {
81     return "0.0001";
82   }
83
84   /// Returns the number of sub-elements
85   MODELAPI_EXPORT virtual int numberOfSubs(bool forTree = false) const = 0;
86
87   /// Returns the sub-result by zero-base index
88   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_ResultBody> subResult(
89     const int theIndex, bool forTree = false) const = 0;
90
91   /// Returns true if theResult belong to this composite result as sub.
92   /// Returns theIndex - zero based index of sub if found
93   MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0;
94
95   /// \brief Stores the shape (called by the execution method).
96   /// param[in] theShape shape to store.
97   /// param[in] theIsStoreSameShapes if false stores reference to the same shape
98   ///                                if it is already in document.
99   MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape,
100                                      const bool theIsStoreSameShapes = true);
101
102   /// Stores the generated shape (called by the execution method).
103   MODELAPI_EXPORT virtual void storeGenerated(const GeomShapePtr& theFromShape,
104                                               const GeomShapePtr& theToShape);
105
106   /// Stores the root modified shapes (called by the execution method).
107   MODELAPI_EXPORT virtual void storeGenerated(
108     const std::list<GeomShapePtr>& theFromShapes, const GeomShapePtr& theToShape,
109     const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape);
110
111   /// Stores the modified shape (called by the execution method).
112   MODELAPI_EXPORT virtual void storeModified(const GeomShapePtr& theOldShape,
113                                              const GeomShapePtr& theNewShape,
114                                              const bool theIsCleanStored = true);
115
116   /// Stores the root modified shapes (called by the execution method).
117   MODELAPI_EXPORT virtual void storeModified(
118     const std::list<GeomShapePtr>& theOldShapes, const GeomShapePtr& theNewShape,
119     const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape);
120
121   /// Returns the shape-result produced by this feature
122   MODELAPI_EXPORT virtual GeomShapePtr shape();
123
124   /// Records the subshape newShape which was generated during a topological construction.
125   /// As an example, consider the case of a face generated in construction of a box.
126   /// Returns true if it is stored correctly (the final shape contains this new sub-shape)
127   MODELAPI_EXPORT virtual bool generated(const GeomShapePtr& theNewShape,
128     const std::string& theName, const bool theCheckIsInResult = true) = 0;
129
130   /// Records the shape newShape which was generated from the shape oldShape during a topological
131   /// construction. As an example, consider the case of a face generated from an edge in
132   /// construction of a prism.
133   MODELAPI_EXPORT virtual void generated(const GeomShapePtr& theOldShape,
134                                          const GeomShapePtr& theNewShape,
135                                          const std::string& theName = "");
136
137   /// Records the shape newShape which is a modification of the shape oldShape.
138   /// As an example, consider the case of a face split or merged in a Boolean operation.
139   MODELAPI_EXPORT virtual void modified(const GeomShapePtr& theOldShape,
140                                         const GeomShapePtr& theNewShape,
141                                         const std::string& theName = "");
142
143   /// load deleted shapes
144   MODELAPI_EXPORT
145   virtual void loadDeletedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
146                                  const GeomShapePtr& theOldShape,
147                                  const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
148                                  const GeomShapePtr& theShapesToExclude = GeomShapePtr());
149
150   /// load and orient modified shapes
151   MODELAPI_EXPORT
152   virtual void loadModifiedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
153                                   const GeomShapePtr& theOldShape,
154                                   const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
155                                   const std::string& theName = "") = 0;
156
157   /// load and orient generated shapes
158   MODELAPI_EXPORT
159   virtual void loadGeneratedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
160                                    const GeomShapePtr& theOldShape,
161                                    const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
162                                    const std::string& theName = "",
163                                    const bool theSaveOldIfNotInTree = false) = 0;
164
165   /// load shapes of the first level (to be used during shape import)
166   MODELAPI_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape,
167                                               const std::string& theName) = 0;
168
169   /// Returns true is the topology is connected.
170   MODELAPI_EXPORT virtual bool isConnectedTopology() = 0;
171
172   /// Set displayed flag to the result and all sub results
173   /// \param theDisplay a boolean value
174   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
175
176   /// Updates the sub-bodies if shape of this object is compsolid or compound
177   MODELAPI_EXPORT virtual void updateSubs(const GeomShapePtr& theThisShape,
178     const bool theShapeChanged = true) = 0;
179
180   /// Updates the sub-bodies in accordance to the algorithm history information
181   MODELAPI_EXPORT virtual void updateSubs(
182     const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
183     const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated) = 0;
184
185   /// Cleans cash related to the already stored elements
186   MODELAPI_EXPORT virtual void cleanCash() = 0;
187
188   /// Add shape Name for read shape in step file
189   MODELAPI_EXPORT virtual std::wstring addShapeName
190                               (std::shared_ptr<GeomAPI_Shape>,const std::wstring& theName) = 0;
191
192   /// Add color for shape Name read shape in step file
193   MODELAPI_EXPORT virtual void addShapeColor
194                               (const std::wstring& theName,std::vector<int>& theColor) = 0;
195
196   /// Set the map of name and color read shape in step file
197   MODELAPI_EXPORT virtual void setShapeName
198                           (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > &theShapeName,
199                            std::map< std::wstring, std::vector<int>> & theColorsShape) = 0;
200
201   /// Clear the map of name and color read shape in step file
202   MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0;
203
204   /// find the name of shapp read in step file
205   MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theShape) = 0;
206
207
208 protected:
209   /// Default constructor accessible only from Model_Objects
210   MODELAPI_EXPORT ModelAPI_ResultBody();
211
212 };
213
214 //! Pointer on feature object
215 typedef std::shared_ptr<ModelAPI_ResultBody> ResultBodyPtr;
216
217 #endif