Salome HOME
Added the system of reinitialization of attributes instead of re-creation of them...
[modules/shaper.git] / src / Model / Model_AttributeRefAttrList.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        Model_AttributeRefAttrList.h
4 // Created:     20 Jan 2016
5 // Author:      Mikhail PONIKAROV
6
7 #ifndef Model_AttributeRefAttrList_H_
8 #define Model_AttributeRefAttrList_H_
9
10 #include "Model.h"
11 #include "ModelAPI_AttributeRefAttrList.h"
12 #include "ModelAPI_Feature.h"
13
14 #include <TDF_Label.hxx>
15 #include <TDataStd_ReferenceList.hxx>
16 #include <TDataStd_ExtStringList.hxx>
17
18 /**\class Model_AttributeRefAttrList
19  * \ingroup DataModel
20  * \brief Attribute that contains list of references to features (located in the same document)
21  * or references to attributes of the features (list of AttributeRefAttr)
22  */
23
24 class Model_AttributeRefAttrList : public ModelAPI_AttributeRefAttrList
25 {
26   TDF_Label myLab; ///< the main label of this attribute
27   Handle_TDataStd_ReferenceList myRef;  ///< references to the features labels
28   Handle_TDataStd_ExtStringList myIDs;  ///< the referenced attributes IDs (empty for just object)
29  public:
30   /// Appends the feature to the end of a list
31   MODEL_EXPORT virtual void append(ObjectPtr theObject);
32   /// Appends the attribute to the end of a list
33   MODEL_EXPORT virtual void append(AttributePtr theAttr);
34
35   /// Erases the first meet of the feature in the list
36   MODEL_EXPORT virtual void remove(ObjectPtr theObject);
37   /// Erases the first meet of the attribute in the list
38   MODEL_EXPORT virtual void remove(AttributePtr theAttr);
39
40   /// Removes all references from the list
41   MODEL_EXPORT virtual void clear();
42
43   /// Returns number of features in the list
44   MODEL_EXPORT virtual int size() const;
45
46   /// Returns the list of features and attributes (if it is reference to the attribute)
47   MODEL_EXPORT virtual std::list<std::pair<ObjectPtr, AttributePtr> > list();
48
49   /// Returns true if the object is in list
50   MODEL_EXPORT virtual bool isInList(const ObjectPtr& theObj);
51   /// Returns true if the attribute is in list
52   MODEL_EXPORT virtual bool isInList(const AttributePtr& theObj);
53
54   /// Returns true if this is reference to an attribute, not just object
55   MODEL_EXPORT virtual bool isAttribute(const int theIndex) const;
56
57   /// Returns the referenced object by the zero-based index
58   ///\param theIndex zero-based index in the list
59   MODEL_EXPORT virtual ObjectPtr object(const int theIndex) const;
60   /// Returns the referenced attribute by the zero-based index
61   ///\param theIndex zero-based index in the list
62   MODEL_EXPORT virtual AttributePtr attribute(const int theIndex) const;
63
64   /// Removes the last element in the list.
65   MODEL_EXPORT virtual void removeLast();
66
67   /// Removes the elements from the list.
68   /// \param theIndices a list of indices of elements to be removed
69   MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
70
71   /// Returns true if attribute was initialized by some value
72   MODEL_EXPORT virtual bool isInitialized();
73  protected:
74   /// Objects are created for features automatically
75   MODEL_EXPORT Model_AttributeRefAttrList(TDF_Label& theLabel);
76   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
77   virtual void reinit();
78
79   friend class Model_Data;
80 };
81
82 #endif