1 // Copyright (C) 2014-2020 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 /// Records the subshape newShape which was generated during a topological construction.
62 /// As an example, consider the case of a face generated in construction of a box.
63 MODEL_EXPORT virtual bool generated(const GeomShapePtr& theNewShape,
64 const std::string& theName, const bool theCheckIsInResult = true) override;
66 /// load generated shapes
68 virtual void loadGeneratedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
69 const GeomShapePtr& theOldShape,
70 const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
71 const std::string& theName = "",
72 const bool theSaveOldIfNotInTree = false) override;
74 /// load modified shapes for sub-objects
76 virtual void loadModifiedShapes(const std::shared_ptr<GeomAlgoAPI_MakeShape>& theAlgo,
77 const GeomShapePtr& theOldShape,
78 const GeomAPI_Shape::ShapeType theShapeTypeToExplore,
79 const std::string& theName = "") override;
81 /// load shapes of the first level (to be used during shape import)
82 MODEL_EXPORT virtual void loadFirstLevel(GeomShapePtr theShape, const std::string& theName);
84 /// Returns the number of sub-elements
85 MODEL_EXPORT virtual int numberOfSubs(bool forTree = false) const;
87 /// Returns the sub-result by zero-base index
88 MODEL_EXPORT virtual ResultBodyPtr subResult(const int theIndex,
89 bool forTree = false) const;
91 /// Returns true if feature or result belong to this composite feature as subs
92 /// Returns theIndex - zero based index of sub if found
93 MODEL_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const;
95 /// Returns the parameters of color definition in the resources configuration manager
96 MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
97 std::string& theDefault);
99 /// Disables the result body: keeps the resulting shape as selection, but erases the underlaying
100 /// naming data structure if theFlag if false. Or restores every thing on theFlag is true.
101 MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
104 /// The compsolid is concealed if at least one of the sub is concealed
105 MODEL_EXPORT virtual bool isConcealed();
107 /// Sets all subs as concealed in the data tree (referenced by other objects)
108 MODEL_EXPORT virtual void setIsConcealed(const bool theValue, const bool theForced = false);
110 /// Returns true is the topology is connected.
111 MODEL_EXPORT virtual bool isConnectedTopology();
113 /// Cleans cash related to the already stored elements
114 MODEL_EXPORT virtual void cleanCash() override;
117 /// Makes a body on the given feature
120 /// Updates the sub-bodies if shape of this object is composite-solid
121 void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
122 const bool theShapeChanged = true);
124 /// Updates the sub-bodies in accordance to the algorithm history information
126 const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
127 const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated);
129 // Checks the state of children and parents to send events of creation/erase when needed
130 void updateConcealment();
132 /// Adds to theOldForSub only old shapes that where used for theSub creation
133 void computeOldForSub(const GeomShapePtr& theSub,
134 const std::list<GeomShapePtr>& theAllOlds, std::list<GeomShapePtr>& theOldForSub);
136 friend class Model_Objects;