Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ModelAPI / ModelAPI_ResultBody.h
1 // Copyright (C) 2014-2022  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   /// Reference to the image attribute of the result body.
62   inline static const std::string& IMAGE_ID()
63   {
64     static const std::string MY_IMAGE_ID("Image");
65     return MY_IMAGE_ID;
66   }
67
68   /// Returns the group identifier of this result
69   MODELAPI_EXPORT virtual std::string groupName();
70
71   /// Returns the group identifier of this result
72   inline static std::string group()
73   {
74     static std::string MY_GROUP = "Bodies";
75     return MY_GROUP;
76   }
77
78   /// default color for a result body
79   inline static const std::string& DEFAULT_COLOR()
80   {
81     static const std::string RESULT_BODY_COLOR("200,200,230");
82     return RESULT_BODY_COLOR;
83   }
84
85   /// default deflection for a result body
86   inline static const std::string DEFAULT_DEFLECTION()
87   {
88     return "0.0001";
89   }
90
91   /// Returns the number of sub-elements
92   MODELAPI_EXPORT virtual int numberOfSubs(bool forTree = false) const = 0;
93
94   /// Returns the sub-result by zero-base index
95   MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_ResultBody> subResult(
96     const int theIndex, bool forTree = false) const = 0;
97
98   /// Returns true if theResult belong to this composite result as sub.
99   /// Returns theIndex - zero based index of sub if found
100   MODELAPI_EXPORT virtual bool isSub(ObjectPtr theResult, int& theIndex) const = 0;
101
102   /// \brief Stores the shape (called by the execution method).
103   /// param[in] theShape shape to store.
104   /// param[in] theIsStoreSameShapes if false stores reference to the same shape
105   ///                                if it is already in document.
106   MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape,
107                                      const bool theIsStoreSameShapes = true);
108
109   /// Stores the generated shape (called by the execution method).
110   MODELAPI_EXPORT virtual void storeGenerated(const GeomShapePtr& theFromShape,
111                                               const GeomShapePtr& theToShape);
112
113   /// Stores the root modified shapes (called by the execution method).
114   MODELAPI_EXPORT virtual void storeGenerated(
115     const std::list<GeomShapePtr>& theFromShapes, const GeomShapePtr& theToShape,
116     const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape);
117
118   /// Stores the modified shape (called by the execution method).
119   MODELAPI_EXPORT virtual void storeModified(const GeomShapePtr& theOldShape,
120                                              const GeomShapePtr& theNewShape,
121                                              const bool theIsCleanStored = true);
122
123   /// Stores the root modified shapes (called by the execution method).
124   MODELAPI_EXPORT virtual void storeModified(
125     const std::list<GeomShapePtr>& theOldShapes, const GeomShapePtr& theNewShape,
126     const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape);
127
128   /// Returns the shape-result produced by this feature
129   MODELAPI_EXPORT virtual GeomShapePtr shape();
130
131   /// Records the subshape newShape which was generated during a topological construction.
132   /// As an example, consider the case of a face generated in construction of a box.
133   /// Returns true if it is stored correctly (the final shape contains this new sub-shape)
134   MODELAPI_EXPORT virtual bool generated(const GeomShapePtr& theNewShape,
135     const std::string& theName, const bool theCheckIsInResult = true) = 0;
136
137   /// Records the shape newShape which was generated from the shape oldShape during a topological
138   /// construction. As an example, consider the case of a face generated from an edge in
139   /// construction of a prism.
140   MODELAPI_EXPORT virtual void generated(const GeomShapePtr& theOldShape,
141                                          const GeomShapePtr& theNewShape,
142                                          const std::string& theName = "");
143
144   /// Records the shape newShape which is a modification of the shape oldShape.
145   /// As an example, consider the case of a face split or merged in a Boolean operation.
146   MODELAPI_EXPORT virtual void modified(const GeomShapePtr& theOldShape,
147                                         const GeomShapePtr& theNewShape,
148                                         const std::string& theName = "");
149
150   /// load deleted shapes
151   MODELAPI_EXPORT
152   virtual void loadDeletedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
153                                  const GeomShapePtr& theOldShape,
154                                  const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
155                                  const GeomShapePtr& theShapesToExclude = GeomShapePtr());
156
157   /// load and orient modified shapes
158   MODELAPI_EXPORT
159   virtual void loadModifiedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
160                                   const GeomShapePtr& theOldShape,
161                                   const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
162                                   const std::string& theName = "") = 0;
163
164   /// load and orient generated shapes
165   MODELAPI_EXPORT
166   virtual void loadGeneratedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
167                                    const GeomShapePtr& theOldShape,
168                                    const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
169                                    const std::string& theName = "",
170                                    const bool theSaveOldIfNotInTree = false) = 0;
171
172   /// load shapes of the first level (to be used during shape import)
173   MODELAPI_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape,
174                                               const std::string& theName) = 0;
175
176   /// Returns true is the topology is connected.
177   MODELAPI_EXPORT virtual bool isConnectedTopology() = 0;
178
179   /// Set displayed flag to the result and all sub results
180   /// \param theDisplay a boolean value
181   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
182
183   /// Updates the sub-bodies if shape of this object is compsolid or compound
184   MODELAPI_EXPORT virtual void updateSubs(const GeomShapePtr& theThisShape,
185     const bool theShapeChanged = true) = 0;
186
187   /// Updates the sub-bodies in accordance to the algorithm history information
188   MODELAPI_EXPORT virtual void updateSubs(
189     const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
190     const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated) = 0;
191
192   /// Cleans cash related to the already stored elements
193   MODELAPI_EXPORT virtual void cleanCash() = 0;
194
195   /// Add shape Name for read shape in step file
196   MODELAPI_EXPORT virtual std::wstring addShapeName
197                               (std::shared_ptr<GeomAPI_Shape>,const std::wstring& theName) = 0;
198
199   /// Add color for shape Name read shape in step file
200   MODELAPI_EXPORT virtual void addShapeColor
201                               (const std::wstring& theName,std::vector<int>& theColor) = 0;
202
203   /// Set the map of name and color read shape in step file
204   MODELAPI_EXPORT virtual void setShapeName
205                           (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > &theShapeName,
206                            std::map< std::wstring, std::vector<int>> & theColorsShape) = 0;
207
208   /// Clear the map of name and color read shape in step file
209   MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0;
210
211   /// find the name of shapp read in step file
212   MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theShape) = 0;
213
214
215 protected:
216   /// Default constructor accessible only from Model_Objects
217   MODELAPI_EXPORT ModelAPI_ResultBody();
218
219 };
220
221 //! Pointer on feature object
222 typedef std::shared_ptr<ModelAPI_ResultBody> ResultBodyPtr;
223
224 #endif