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