Salome HOME
Update of documentation in the Model package
[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
15 /**\class Model_AttributeSelection
16  * \ingroup DataModel
17  * \brief Attribute that contains reference to the sub-shape of some result, the selected shape.
18  */
19
20 class Model_AttributeSelection : public ModelAPI_AttributeSelection
21 {
22   Model_AttributeReference myRef;  ///< The reference functionality reusage
23   TDF_LabelMap myScope; ///< the map of valid labels for naming selection solving
24   /// temporarily storages to avoid keeping in the data structure if not needed
25   ResultPtr myTmpContext;
26   /// temporarily storages to avoid keeping in the data structure if not needed
27   std::shared_ptr<GeomAPI_Shape> myTmpSubShape;
28 public:
29   /// Defines the result and its selected sub-shape
30   /// \param theContext object where the sub-shape was selected
31   /// \param theSubShape selected sub-shape (if null, the whole context is selected)
32   /// \param theTemporarily if it is true, do not store and name the added in the data framework
33   ///           (used to remove immideately, without the following updates)
34   MODEL_EXPORT virtual void setValue(
35     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
36     const bool theTemporarily = false);
37
38   /// Returns the selected subshape
39   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
40
41   /// Returns the context of the selection (the whole shape owner)
42   MODEL_EXPORT virtual ResultPtr context();
43
44   /// Sets the feature object
45   MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
46
47   /// Updates the underlied selection due to the changes in the referenced objects
48   /// \returns false if update is failed
49   MODEL_EXPORT virtual bool update();
50
51   /// Returns a textual string of the selection
52   /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
53   MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
54   
55   /// Returns an Id of the selection
56   /// NOTE: This method has been added for temporary export of groups towards old GEOM
57   /// It should then be removed when a direct use of objects from NewGeom
58   /// will be possible from SMESH module of SALOME.
59   MODEL_EXPORT virtual int Id();
60
61   /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
62   MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName);
63
64   /// Returns true if attribute was  initialized by some value
65   MODEL_EXPORT virtual bool isInitialized();
66
67   /// Returns true if recomute of selection become impossible
68   MODEL_EXPORT virtual bool isInvalid();
69
70
71 protected:
72   /// Objects are created for features automatically
73   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
74     /// Performs the selection for the body result (TNaming Selection)
75
76   /// Performs the selection for the body result (TNaming selection)
77   virtual void selectBody(
78     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
79
80   /// Performs the selection for the construction result (selection by index)
81   virtual void selectConstruction(
82     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
83
84   /// Performs the selection for the part result (selection by name of body result inside of part)
85   /// \param theContext the result - owner of the selection
86   /// \param theSubShape selected shape
87   /// \param theUpdate flag that shows that it must be just update, theShape is null
88   /// \returns true if eveything is selected correctly
89   virtual bool selectPart(
90     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape,
91     const bool theUpdate = false);
92
93   /// Returns the label where TNaming_Selection results are stored
94   /// Note: there must be no attributes stored at the same label because Selector clears this lab
95   TDF_Label selectionLabel();
96
97   /// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
98   TDF_LabelMap& scope();
99
100   /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
101   MODEL_EXPORT virtual void setID(const std::string theID);
102
103   friend class Model_Data;
104   friend class Model_AttributeSelectionList;
105 };
106
107 #endif