Salome HOME
b00fb22d205e7eb56e9798d7ab7b9edcc9884099
[modules/shaper.git] / src / Model / Model_ResultBody.h
1 // Copyright (C) 2014-2023  CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef Model_ResultBody_H_
21 #define Model_ResultBody_H_
22
23 #include "Model.h"
24 #include <ModelAPI_ResultBody.h>
25 #include <vector>
26 #include <map>
27
28 #include <TopTools_DataMapOfShapeListOfShape.hxx>
29
30 /**\class Model_ResultBody
31 * \ingroup DataModel
32 * \brief The body (shape) result of a feature.
33 *
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.
38 */
39 class Model_ResultBody : public ModelAPI_ResultBody
40 {
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.
46   bool myLastConcealed;
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
52   bool myIsGenerated;
53   /// Map from old shape to list of new shapes, cash for computeOldForSub method
54   TopTools_DataMapOfShapeListOfShape myHistoryCash;
55
56 public:
57
58   /// Removes the stored builders
59   MODEL_EXPORT virtual ~Model_ResultBody();
60
61   /// Request for initialization of data model of the result body: adding all attributes
62   virtual void initAttributes();
63
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;
68
69   /// load generated shapes
70   MODEL_EXPORT
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;
76
77   /// load modified shapes for sub-objects
78   MODEL_EXPORT
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;
83
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);
86
87   /// Returns the number of sub-elements
88   MODEL_EXPORT virtual int numberOfSubs(bool forTree = false) const;
89
90   /// Returns the sub-result by zero-base index
91   MODEL_EXPORT virtual ResultBodyPtr subResult(const int theIndex,
92     bool forTree = false) const;
93
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;
97
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);
101
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,
105     const bool theFlag);
106
107   /// The compsolid is concealed if at least one of the sub is concealed
108   MODEL_EXPORT virtual bool isConcealed();
109
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);
112
113   /// Returns true is the topology is connected.
114   MODEL_EXPORT virtual bool isConnectedTopology();
115
116   /// Cleans cash related to the already stored elements
117   MODEL_EXPORT virtual void cleanCash() override;
118
119   /// sets the texture file
120   MODEL_EXPORT virtual bool hasTexture() override;
121
122   /// Find the imported color by the construction name of a shape.
123   /// Returns empty vector if not found.
124   MODEL_EXPORT virtual const std::vector<int>& findShapeColor(const std::wstring& theShapeName);
125
126 protected:
127   /// Makes a body on the given feature
128   Model_ResultBody();
129
130   /// Updates the sub-bodies if shape of this object is composite-solid
131   void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape,
132                   const bool theShapeChanged = true);
133
134   /// Updates the sub-bodies in accordance to the algorithm history information
135   void updateSubs(
136     const GeomShapePtr& theThisShape, const std::list<GeomShapePtr>& theOlds,
137     const std::shared_ptr<GeomAlgoAPI_MakeShape> theMakeShape, const bool isGenerated);
138
139   /// Checks the state of children and parents to send events of creation/erase when needed
140   void updateConcealment();
141
142   /// Adds to theOldForSub only old shapes that where used for theSub creation
143   void computeOldForSub(const GeomShapePtr& theSub,
144     const std::list<GeomShapePtr>& theAllOlds, std::list<GeomShapePtr>& theOldForSub);
145
146   friend class Model_Objects;
147
148   /// Add shape Name for read shape in step file
149   std::wstring addShapeName(std::shared_ptr<GeomAPI_Shape>,const std::wstring& theName) override;
150
151   /// Add color for shape Name read shape in step file
152   void addShapeColor( const std::wstring& theName,std::vector<int>& color) override;
153
154   /// Set the map of name and color read shape in step file
155   void setShapeName(std::map< std::wstring,
156                               std::shared_ptr<GeomAPI_Shape>>& theShapeName,
157                               std::map< std::wstring,
158                               std::vector<int>>& theColorsShape) override;
159
160   /// Find the name of shape read in step file
161   std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theShape) override;
162
163   /// Clear the map of name and color read shape in step file
164   void clearShapeNameAndColor() override;
165
166   /// map with the name read in step file and shape
167   std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > myNamesShape;
168
169   /// map from the construction name to the imported color
170   std::map< std::wstring, std::vector<int>> myColorsShape;
171
172 };
173
174 #endif