Salome HOME
a72900d28bbb511be723b37f7ecc97e5680d8ee1
[modules/shaper.git] / src / Model / Model_AttributeRefList.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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef Model_AttributeRefList_H_
21 #define Model_AttributeRefList_H_
22
23 #include "Model.h"
24 #include "ModelAPI_AttributeRefList.h"
25 #include "ModelAPI_Feature.h"
26 #include "Model_Document.h"
27
28 #include <TDataStd_ReferenceList.hxx>
29 #include <TDataStd_ExtStringList.hxx>
30
31 /**\class Model_AttributeRefList
32  * \ingroup DataModel
33  * \brief Attribute that contains list of references to features, may be located in different documents.
34  */
35
36 class Model_AttributeRefList : public ModelAPI_AttributeRefList
37 {
38   TDF_Label myLab; ///< the main label of this attribute
39   Handle_TDataStd_ReferenceList myRef;  ///< references to the features labels
40   /// pairs of doc ID and entries if reference is to external object, appends some in this list if
41   /// something in myRef is empty
42   Handle_TDataStd_ExtStringList myExtDocRef;
43  public:
44   /// Appends the feature to the end of a list
45   MODEL_EXPORT virtual void append(ObjectPtr theObject);
46
47   /// Erases the first meet of the feature in the list
48   MODEL_EXPORT virtual void remove(ObjectPtr theObject);
49
50   /// Returns number of features in the list
51   ///\param theWithEmpty if it is false, returns the number of not-empty referenced objects
52   MODEL_EXPORT virtual int size(const bool theWithEmpty = true) const;
53
54   /// Removes all references from the list
55   MODEL_EXPORT virtual void clear();
56
57   /// Returns the list of features
58   MODEL_EXPORT virtual std::list<ObjectPtr> list();
59
60   /// Returns true if the object is in list
61   MODEL_EXPORT virtual bool isInList(const ObjectPtr& theObj);
62
63   /// Returns the list of features
64   ///\param theIndex zero-based index in the list
65   ///\param theWithEmpty if it is false, counts the not-empty referenced objects only
66   MODEL_EXPORT virtual ObjectPtr object(const int theIndex, const bool theWithEmpty = true) const;
67
68   /// Substitutes the feature by another one. Does nothing if such object is not found.
69   /// Does not support the external documents objects yet.
70   MODEL_EXPORT virtual void substitute(const ObjectPtr& theCurrent, const ObjectPtr& theNew);
71
72   /// Substitutes the object by another one and back. So, features will become exchanged in the list
73   /// Does not support the external documents objects yet.
74   MODEL_EXPORT virtual void exchange(const ObjectPtr& theObject1, const ObjectPtr& theObject2);
75
76   /// Removes the last element in the list.
77   /// Does not support the external documents objects yet.
78   MODEL_EXPORT virtual void removeLast();
79
80   /// Removes the elements from the list.
81   /// Does not support the external documents objects yet.
82   /// \param theIndices a list of indices of elements to be removed
83   MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
84
85   /// Returns true if attribute was  initialized by some value
86   MODEL_EXPORT virtual bool isInitialized();
87  protected:
88   /// Objects are created for features automatically
89   MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
90   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
91   virtual void reinit();
92   /// Returns the object by iterators (theExtIter is iterated if necessary)
93   ObjectPtr iteratedObject(TDF_ListIteratorOfLabelList& theLIter,
94     TDataStd_ListIteratorOfListOfExtendedString& theExtIter,
95     std::shared_ptr<Model_Document> theDoc) const;
96
97   friend class Model_Data;
98 };
99
100 #endif