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