1 // Copyright (C) 2014-2021 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 Model_ResultBody_H_
21 #define Model_ResultBody_H_
24 #include <ModelAPI_ResultBody.h>
28 #include <TopTools_DataMapOfShapeListOfShape.hxx>
30 /**\class Model_ResultBody
32 * \brief The body (shape) result of a feature.
34 * Provides a shape that may be displayed in the viewer.
35 * May provide really huge results, so, working with this kind
36 * of result must be optimized.
37 * Also provides a container of sub-body result in case it is compound or compsolid.
39 class Model_ResultBody : public ModelAPI_ResultBody
41 /// Sub-bodies if this is compsolid or compound: zero-based index to subs
42 std::vector<ResultBodyPtr> mySubs;
43 /// Also keep map of result to index in mySubs to facilitate speed of access from OB
44 std::map<ObjectPtr, int> mySubsMap;
45 /// Keeps the last state of the concealment flag in order to update it when needed.
47 /// History information for update subs
48 std::shared_ptr<GeomAlgoAPI_MakeShape> myAlgo;
49 /// All old shapes used for the root result construction
50 std::list<GeomShapePtr> myOlds;
51 /// Information about the kind of the history information: modified or generated
53 /// Map from old shape to list of new shapes, cash for computeOldForSub method
54 TopTools_DataMapOfShapeListOfShape myHistoryCash;
58 /// Removes the stored builders
59 MODEL_EXPORT virtual ~Model_ResultBody();
61 /// Request for initialization of data model of the result body: adding all attributes
62 virtual void initAttributes();
64 /// Records the subshape newShape which was generated during a topological construction.
65 /// As an example, consider the case of a face generated in construction of a box.
66 MODEL_EXPORT virtual bool generated(const GeomShapePtr& theNewShape,
67 const std::string& theName, const bool theCheckIsInResult = true) override;
69 /// load generated shapes
71 virtual void loadGeneratedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
72 const GeomShapePtr& theOldShape,
73 const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
74 const std::string& theName = "",
75 const bool theSaveOldIfNotInTree = false) override;
77 /// load modified shapes for sub-objects
79 virtual void loadModifiedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
80 const GeomShapePtr& theOldShape,
81 const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
82 const std::string& theName = "") override;
84 /// load shapes of the first level (to be used during shape import)
85 MODEL_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape, const std::string& theName);
87 /// Returns the number of sub-elements
88 MODEL_EXPORT virtual int numberOfSubs(bool forTree = false) const;
90 /// Returns the sub-result by zero-base index
91 MODEL_EXPORT virtual ResultBodyPtr subResult(const int theIndex,
92 bool forTree = false) const;
94 /// Returns true if feature or result belong to this composite feature as subs
95 /// Returns theIndex - zero based index of sub if found
96 MODEL_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const;
98 /// Returns the parameters of color definition in the resources configuration manager
99 MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
100 std::string& theDefault);
102 /// Disables the result body: keeps the resulting shape as selection, but erases the underlaying
103 /// naming data structure if theFlag if false. Or restores every thing on theFlag is true.
104 MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
107 /// The compsolid is concealed if at least one of the sub is concealed
108 MODEL_EXPORT virtual bool isConcealed();
110 /// Sets all subs as concealed in the data tree (referenced by other objects)
111 MODEL_EXPORT virtual void setIsConcealed(const bool theValue, const bool theForced = false);
113 /// Returns true is the topology is connected.
114 MODEL_EXPORT virtual bool isConnectedTopology();
116 /// Cleans cash related to the already stored elements
117 MODEL_EXPORT virtual void cleanCash() override;
119 /// sets the texture file
120 MODEL_EXPORT virtual bool hasTexture() override;
124 /// Makes a body on the given feature
127 /// Updates the sub-bodies if shape of this object is composite-solid
128 void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
129 const bool theShapeChanged = true);
131 /// Updates the sub-bodies in accordance to the algorithm history information
133 const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
134 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated);
136 /// Checks the state of children and parents to send events of creation/erase when needed
137 void updateConcealment();
139 /// Adds to theOldForSub only old shapes that where used for theSub creation
140 void computeOldForSub(const GeomShapePtr& theSub,
141 const std::list<GeomShapePtr>& theAllOlds, std::list<GeomShapePtr>& theOldForSub);
143 friend class Model_Objects;
145 /// Add shape Name for read shape in step file
146 std::wstring addShapeName(std::shared_ptr<GeomAPI_Shape>,const std::wstring& theName) override;
148 /// Add color for shape Name read shape in step file
149 void addShapeColor( const std::wstring& theName,std::vector<int>& color) override;
151 /// Set the map of name and color read shape in step file
152 void setShapeName(std::map< std::wstring,
153 std::shared_ptr<GeomAPI_Shape>>& theShapeName,
154 std::map< std::wstring,
155 std::vector<int>>& theColorsShape) override;
157 /// find the name of shapp read in step file
158 std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theShape) override;
160 /// Clear the map of name and color read shape in step file
161 void clearShapeNameAndColor() override;
163 /// map with the name read in step file and shape
164 std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > myNamesShape;
166 /// map with the name contruct and color read
167 std::map< std::wstring, std::vector<int>> myColorsShape;