Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[modules/shaper.git] / src / Model / Model_AttributeSelection.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_AttributeSelection.h
4 // Created:     8 May 2014
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef Model_AttributeSelection_H_
8 #define Model_AttributeSelection_H_
9
10 #include "Model.h"
11 #include "Model_AttributeReference.h"
12 #include <ModelAPI_AttributeSelection.h>
13 #include <TDF_LabelMap.hxx>
14 #include <TopoDS_Shape.hxx>
15
16 class Model_AttributeSelectionList;
17
18 /**\class Model_AttributeSelection
19  * \ingroup DataModel
20  * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
21  */
22 class Model_AttributeSelection : public ModelAPI_AttributeSelection
23 {
24   Model_AttributeReference myRef;  ///< The reference functionality reusage
25   TDF_LabelMap myScope; ///< the map of valid labels for naming selection solving
26   /// temporarily storages to avoid keeping in the data structure if not needed
27   ResultPtr myTmpContext;
28   /// temporarily storages to avoid keeping in the data structure if not needed
29   std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
30   /// Reference to the partent attribute, if any (to split selection compounds in issue 1799)
31   Model_AttributeSelectionList* myParent;
32 public:
33   /// Defines the result and its selected sub-shape
34   /// \param theContext object where the sub-shape was selected
35   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
36   /// \param theTemporarily if it is true, do not store and name the added in the data framework
37   ///           (used to remove immideately, without the following updates)
38   MODEL_EXPORT virtual void setValue(
39     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
40     const bool theTemporarily = false);
41
42   /// Reset temporary stored values
43   virtual void removeTemporaryValues();
44
45   /// Returns the selected subshape
46   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
47
48   /// Returns the context of the selection (the whole shape owner)
49   MODEL_EXPORT virtual ResultPtr context();
50
51   /// Sets the feature object
52   MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
53
54   /// Updates the underlied selection due to the changes in the referenced objects
55   /// \returns false if update is failed
56   MODEL_EXPORT virtual bool update();
57
58   /// Returns a textual string of the selection
59   /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
60   MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
61
62   /// Returns an Id of the selection
63   /// NOTE: This method has been added for temporary export of groups towards old GEOM
64   /// It should then be removed when a direct use of objects from SHAPER
65   /// will be possible from SMESH module of SALOME.
66   MODEL_EXPORT virtual int Id();
67
68   /// Defines the sub-shape by Id
69   /// NOTE: This method is opposite to Id() method.
70   MODEL_EXPORT virtual void setId(int theID);
71
72   /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
73   MODEL_EXPORT virtual void selectSubShape(const std::string& theType,
74                                            const std::string& theSubShapeName);
75
76   /// Returns true if attribute was  initialized by some value
77   MODEL_EXPORT virtual bool isInitialized();
78
79   /// Returns true if recomute of selection become impossible
80   MODEL_EXPORT virtual bool isInvalid();
81
82   /// Updates the arguments of selection if something was affected by creation
83   /// or reorder of features upper in the history line (issue #1757)
84   MODEL_EXPORT virtual void updateInHistory();
85
86 protected:
87   /// Objects are created for features automatically
88   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
89
90   /// Performs the selection for the body result (TNaming Selection)
91
92   /// Performs the selection for the body result (TNaming selection)
93   virtual void selectBody(
94     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
95
96   /// Performs the selection for the part result (selection by name of body result inside of part)
97   /// \param theContext the result - owner of the selection
98   /// \param theSubShape selected shape
99   /// \param theUpdate flag that shows that it must be just update, theShape is null
100   /// \returns true if eveything is selected correctly
101   virtual bool selectPart(
102     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
103     const bool theUpdate = false);
104
105   /// Returns the label where TNaming_Selection results are stored
106   /// Note: there must be no attributes stored at the same label because Selector clears this lab
107   TDF_Label selectionLabel();
108
109   /// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
110   TDF_LabelMap& scope();
111
112   /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
113   MODEL_EXPORT virtual void setID(const std::string theID);
114
115   /// Returns the name by context. Adds the part name if the context is located in other document
116   std::string contextName(const ResultPtr& theContext) const;
117
118   /// Sets the parent attribute
119   void setParent(Model_AttributeSelectionList* theParent);
120
121   /// Splits theNewShape into sub-shapes of theType type (for the list parent of this attribute)
122   void split(ResultPtr theContext, TopoDS_Shape theNewShape, TopAbs_ShapeEnum theType);
123
124   friend class Model_Data;
125   friend class Model_AttributeSelectionList;
126 };
127
128 #endif