Salome HOME
Prepare version 1.2.1: quick fix for iteration 2 release
[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 public:
25   /// Defines the result and its selected sub-shape
26   MODEL_EXPORT virtual void setValue(
27     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
28
29   /// Returns the selected subshape
30   MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> value();
31
32   /// Returns the context of the selection (the whole shape owner)
33   MODEL_EXPORT virtual ResultPtr context();
34
35   /// Sets the feature object
36   MODEL_EXPORT virtual void setObject(const std::shared_ptr<ModelAPI_Object>& theObject);
37
38   /// Updates the underlied selection due to the changes in the referenced objects
39   /// \returns false if update is failed
40   MODEL_EXPORT virtual bool update();
41
42   /// Returns a textual string of the selection
43   /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
44   MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
45   
46   /// Returns an Id of the selection
47   /// NOTE: This method has been added for temporary export of groups towards old GEOM
48   /// It should then be removed when a direct use of objects from NewGeom
49   /// will be possible from SMESH module of SALOME.
50   MODEL_EXPORT virtual int Id();
51
52   /// Selects (i.e. creates Naming data structure) of sub-shape specifed by textual name
53   MODEL_EXPORT virtual void selectSubShape(const std::string& theType, const std::string& theSubShapeName);
54
55   /// Returns true if attribute was  initialized by some value
56   MODEL_EXPORT virtual bool isInitialized();
57
58 protected:
59   /// Objects are created for features automatically
60   MODEL_EXPORT Model_AttributeSelection(TDF_Label& theLabel);
61     /// Performs the selection for the body result (TNaming Selection)
62
63   /// Performs the selection for the body result (TNaming selection)
64   virtual void selectBody(
65     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
66
67   /// Performs the selection for the construction result (selection by index)
68   virtual void selectConstruction(
69     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& theSubShape);
70
71   /// Returns the label where TNaming_Selection results are stored
72   /// Note: there must be no attributes stored at the same label because Selector clears this lab
73   TDF_Label selectionLabel();
74
75   /// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
76   TDF_LabelMap& scope();
77
78   /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
79   MODEL_EXPORT virtual void setID(const std::string theID);
80
81   friend class Model_Data;
82   friend class Model_AttributeSelectionList;
83 };
84
85 #endif