Salome HOME
Naming now stores primitives on tags 11+.
[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 conainer of sub-body result in case it is compound or compsolid.
40 */
41 class ModelAPI_ResultBody : public ModelAPI_Result
42 {
43 public:
44   /// Iternal 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 reuslt 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 std::shared_ptr<GeomAPI_Shape>& theShape,
99     const bool theIsStoreSameShapes = true);
100
101   /// Stores the generated shape (called by the execution method).
102   MODELAPI_EXPORT virtual void storeGenerated(const std::shared_ptr<GeomAPI_Shape>& theFromShape,
103     const std::shared_ptr<GeomAPI_Shape>& theToShape);
104
105   /// Stores the modified shape (called by the execution method).
106   MODELAPI_EXPORT virtual void storeModified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
107     const std::shared_ptr<GeomAPI_Shape>& theNewShape, const int theDecomposeSolidsTag = 0);
108
109   /// Stores the shape without naming support
110   MODELAPI_EXPORT virtual void storeWithoutNaming(
111     const std::shared_ptr<GeomAPI_Shape>& theShape);
112
113   /// Returns the shape-result produced by this feature
114   MODELAPI_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
115
116   /// Records the subshape newShape which was generated during a topological construction.
117   /// As an example, consider the case of a face generated in construction of a box.
118   MODELAPI_EXPORT virtual void generated(const std::shared_ptr<GeomAPI_Shape>& theNewShape,
119                                          const std::string& theName);
120
121   /// Records the shape newShape which was generated from the shape oldShape during a topological
122   /// construction. As an example, consider the case of a face generated from an edge in
123   /// construction of a prism.
124   MODELAPI_EXPORT virtual void generated(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
125     const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
126     const int theTag = 1);
127
128   /// Records the shape newShape which is a modification of the shape oldShape.
129   /// As an example, consider the case of a face split or merged in a Boolean operation.
130   MODELAPI_EXPORT virtual void modified(const std::shared_ptr<GeomAPI_Shape>& theOldShape,
131     const std::shared_ptr<GeomAPI_Shape>& theNewShape, const std::string& theName,
132     const int theTag = 1);
133
134   /// Records the shape oldShape which was deleted from the current label.
135   /// As an example, consider the case of a face removed by a Boolean operation.
136   MODELAPI_EXPORT virtual void deleted(
137     const std::shared_ptr<GeomAPI_Shape>& theOldShape, const int theTag = 1);
138
139   /// load deleted shapes
140   MODELAPI_EXPORT virtual void loadDeletedShapes(GeomAlgoAPI_MakeShape* theMS,
141     std::shared_ptr<GeomAPI_Shape>  theShapeIn,
142     const int  theKindOfShape,
143     const int  theTag,
144     const GeomShapePtr theShapes = GeomShapePtr());
145
146   /// load and orient modified shapes
147   MODELAPI_EXPORT virtual void loadAndOrientModifiedShapes(GeomAlgoAPI_MakeShape* theMS,
148     std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
149     const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
150     const bool theIsStoreSeparate = false, const bool theIsStoreAsGenerated = false,
151     const bool theSplitInSubs = false);
152
153   /// load and orient generated shapes
154   MODELAPI_EXPORT virtual void loadAndOrientGeneratedShapes(GeomAlgoAPI_MakeShape* theMS,
155     std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape,
156     const int  theTag, const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes);
157
158   /// load shapes of the first level (to be used during shape import)
159   MODELAPI_EXPORT virtual void loadFirstLevel(std::shared_ptr<GeomAPI_Shape> theShape,
160     const std::string& theName, int&  theTag);
161
162   /// load disconnected edges
163   MODELAPI_EXPORT virtual void loadDisconnectedEdges(std::shared_ptr<GeomAPI_Shape> theShape,
164     const std::string& theName, int&  theTag);
165
166   /// load disconnected vetexes
167   MODELAPI_EXPORT virtual void loadDisconnectedVertexes(std::shared_ptr<GeomAPI_Shape> theShape,
168     const std::string& theName, int&  theTag);
169
170   /// Returns true if the latest modification of this body in the naming history
171   // is equal to the given shape
172   MODELAPI_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape) = 0;
173
174   /// Returns true is the topology is connected.
175   MODELAPI_EXPORT virtual bool isConnectedTopology() = 0;
176
177   /// Set displayed flag to the result and all sub results
178   /// \param theDisplay a boolean value
179   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
180
181   /// Updates the sub-bodies if shape of this object is compsolid or compound
182   MODELAPI_EXPORT virtual void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
183     const bool theShapeChanged = true) = 0;
184
185 protected:
186   /// Default constructor accessible only from Model_Objects
187   MODELAPI_EXPORT ModelAPI_ResultBody();
188
189 };
190
191 //! Pointer on feature object
192 typedef std::shared_ptr<ModelAPI_ResultBody> ResultBodyPtr;
193
194 #endif