1 // Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModelAPI_ResultBody_H_
21 #define ModelAPI_ResultBody_H_
23 #include "ModelAPI_Result.h"
24 #include <GeomAPI_Shape.h>
25 #include <GeomAPI_DataMapOfShapeShape.h>
30 class ModelAPI_BodyBuilder;
31 class GeomAlgoAPI_MakeShape;
33 /**\class ModelAPI_ResultBody
35 * \brief The body (shape) result of a feature.
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.
42 class ModelAPI_ResultBody : public ModelAPI_Result
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
53 /// Keeps (not persistently) the connected topology flag
54 ConnectedTopologyFlag myConnect;
56 ModelAPI_BodyBuilder* myBuilder; ///< provides the body processing in naming shape
59 MODELAPI_EXPORT virtual ~ModelAPI_ResultBody();
61 /// Reference to the image attribute of the result body.
62 inline static const std::string& IMAGE_ID()
64 static const std::string MY_IMAGE_ID("Image");
68 /// Returns the group identifier of this result
69 MODELAPI_EXPORT virtual std::string groupName();
71 /// Returns the group identifier of this result
72 inline static std::string group()
74 static std::string MY_GROUP = "Bodies";
78 /// default color for a result body
79 inline static const std::string& DEFAULT_COLOR()
81 static const std::string RESULT_BODY_COLOR("200,200,230");
82 return RESULT_BODY_COLOR;
85 /// default deflection for a result body
86 inline static const std::string DEFAULT_DEFLECTION()
91 /// Returns the number of sub-elements
92 MODELAPI_EXPORT virtual int numberOfSubs(bool forTree = false) const = 0;
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;
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;
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);
109 /// Stores the generated shape (called by the execution method).
110 MODELAPI_EXPORT virtual void storeGenerated(const GeomShapePtr& theFromShape,
111 const GeomShapePtr& theToShape);
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);
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);
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);
128 /// Returns the shape-result produced by this feature
129 MODELAPI_EXPORT virtual GeomShapePtr shape();
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;
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 = "");
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 = "");
150 /// load deleted shapes
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());
157 /// load and orient modified shapes
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;
164 /// load and orient generated shapes
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;
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;
176 /// Returns true is the topology is connected.
177 MODELAPI_EXPORT virtual bool isConnectedTopology() = 0;
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);
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;
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;
192 /// Cleans cash related to the already stored elements
193 MODELAPI_EXPORT virtual void cleanCash() = 0;
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;
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;
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;
208 /// Clear the map of name and color read shape in step file
209 MODELAPI_EXPORT virtual void clearShapeNameAndColor() = 0;
211 /// Find the name of shape read in step file
212 MODELAPI_EXPORT virtual std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theShape) = 0;
214 /// Find the imported color by the construction name of a shape.
215 /// Returns empty vector if not found.
216 MODELAPI_EXPORT virtual const std::vector<int>& findShapeColor(
217 const std::wstring& theShapeName) = 0;
221 /// Default constructor accessible only from Model_Objects
222 MODELAPI_EXPORT ModelAPI_ResultBody();
226 //! Pointer on feature object
227 typedef std::shared_ptr<ModelAPI_ResultBody> ResultBodyPtr;