Salome HOME
ad5f1c53136a25ca5a985f834ea5e400823a229f
[modules/shaper.git] / src / Model / Model_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 Model_ResultBody_H_
22 #define Model_ResultBody_H_
23
24 #include "Model.h"
25 #include <ModelAPI_ResultBody.h>
26 #include <vector>
27 #include <map>
28
29 /**\class Model_ResultBody
30 * \ingroup DataModel
31 * \brief The body (shape) result of a feature.
32 *
33 * Provides a shape that may be displayed in the viewer.
34 * May provide really huge results, so, working with this kind
35 * of result must be optimized.
36 * Also provides a conainer of sub-body result in case it is compound or compsolid.
37 */
38 class Model_ResultBody : public ModelAPI_ResultBody
39 {
40   /// Sub-bodies if this is compsolid or compound: zero-based index to subs
41   std::vector<ResultBodyPtr> mySubs;
42   /// Also keep map of result to index in mySubs to facilitate speed of access from OB
43   std::map<ObjectPtr, int> mySubsMap;
44   /// Keeps the last state of the concealment flag in order to update it when needed.
45   bool myLastConcealed;
46
47 public:
48
49   /// Removes the stored builders
50   MODEL_EXPORT virtual ~Model_ResultBody();
51
52   /// load and orient modified shapes for sub-objects
53   MODEL_EXPORT virtual void loadAndOrientModifiedShapes (GeomAlgoAPI_MakeShape* theMS,
54     std::shared_ptr<GeomAPI_Shape>  theShapeIn, const int  theKindOfShape, const int  theTag,
55     const std::string& theName, GeomAPI_DataMapOfShapeShape& theSubShapes,
56     const bool theIsStoreSeparate = false, const bool theIsStoreAsGenerated = false,
57     const bool theSplitInSubs = false);
58
59
60   /// Returns the number of sub-elements
61   MODEL_EXPORT virtual int numberOfSubs(bool forTree = false) const;
62
63   /// Returns the sub-result by zero-base index
64   MODEL_EXPORT virtual ResultBodyPtr subResult(const int theIndex,
65     bool forTree = false) const;
66
67   /// Returns true if feature or reuslt belong to this composite feature as subs
68   /// Returns theIndex - zero based index of sub if found
69   MODEL_EXPORT virtual bool isSub(ObjectPtr theObject, int& theIndex) const;
70
71   /// Returns the parameters of color definition in the resources config manager
72   MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName,
73                                             std::string& theDefault);
74
75   /// Disables the result body: keeps the resulting shape as selection, but erases the underlaying
76   /// naming data structure if theFlag if false. Or restores every  thing on theFlag is true.
77   MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
78     const bool theFlag);
79
80   /// The compsolid is concealed if at least one of the sub is concealed
81   MODEL_EXPORT virtual bool isConcealed();
82
83   /// Sets all subs as concealed in the data tree (referenced by other objects)
84   MODEL_EXPORT virtual void setIsConcealed(const bool theValue);
85
86   /// Returns true if the latest modification of this body in the naming history
87   // is equal to the given shape
88   MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr<GeomAPI_Shape>& theShape);
89
90 protected:
91   /// Makes a body on the given feature
92   Model_ResultBody();
93
94   /// Updates the sub-bodies if shape of this object is composite-solid
95   void updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisShape);
96
97   // Checks the state of children and partents to send events of creation/erase when needed
98   void updateConcealment();
99
100   friend class Model_Objects;
101 };
102
103 #endif