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