Salome HOME
Improve coverage for ModelAPI and Config packages
[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
41   Handle_TDataStd_ReferenceList myRef;  ///< references to the features labels
42   /// pairs of doc ID and entries if reference is to external object, appends some in this list if
43   /// something in myRef is empty
44   Handle_TDataStd_ExtStringList myExtDocRef;
45   bool myHashUsed; ///< true if the hash stored is valid
46   std::set<ObjectPtr> myHashObjects; ///< hashed information: objects existing in the list
47   std::map<int, ObjectPtr> myHashIndex; ///< index to object in the list
48   std::map<int, ObjectPtr> myHashIndexNoEmpty; ///< index to not empty object in the list
49 public:
50   /// Appends the feature to the end of a list
51   MODEL_EXPORT virtual void append(ObjectPtr theObject);
52
53   /// Erases the first meet of the feature in the list
54   MODEL_EXPORT virtual void remove(ObjectPtr theObject);
55
56   /// Returns number of features in the list
57   ///\param theWithEmpty if it is false, returns the number of not-empty referenced objects
58   MODEL_EXPORT virtual int size(const bool theWithEmpty = true) const;
59
60   /// Removes all references from the list
61   MODEL_EXPORT virtual void clear();
62
63   /// Returns the list of features
64   MODEL_EXPORT virtual std::list<ObjectPtr> list();
65
66   /// Returns true if the object is in list
67   MODEL_EXPORT virtual bool isInList(const ObjectPtr& theObj);
68
69   /// Returns the list of features
70   ///\param theIndex zero-based index in the list
71   ///\param theWithEmpty if it is false, counts the not-empty referenced objects only
72   MODEL_EXPORT virtual ObjectPtr object(const int theIndex, const bool theWithEmpty = true);
73
74   /// Substitutes the feature by another one. Does nothing if such object is not found.
75   /// Does not support the external documents objects yet.
76   MODEL_EXPORT virtual void substitute(const ObjectPtr& theCurrent, const ObjectPtr& theNew);
77
78   /// Removes the last element in the list.
79   /// Does not support the external documents objects yet.
80   MODEL_EXPORT virtual void removeLast();
81
82   /// Removes the elements from the list.
83   /// Does not support the external documents objects yet.
84   /// \param theIndices a list of indices of elements to be removed
85   MODEL_EXPORT virtual void remove(const std::set<int>& theIndices);
86
87   /// Returns true if attribute was  initialized by some value
88   MODEL_EXPORT virtual bool isInitialized();
89  protected:
90   /// Objects are created for features automatically
91   MODEL_EXPORT Model_AttributeRefList(TDF_Label& theLabel);
92   /// Reinitializes the internal state of the attribute (may be needed on undo/redo, abort, etc)
93   virtual void reinit();
94   /// Returns the object by iterators (theExtIter is iterated if necessary)
95   ObjectPtr iteratedObject(TDF_ListIteratorOfLabelList& theLIter,
96     TDataStd_ListIteratorOfListOfExtendedString& theExtIter,
97     std::shared_ptr<Model_Document> theDoc) const;
98   /// Creates the hash-objects containers (does nothing if hash is already correct)
99   void createHash();
100   /// Erases the hashed objects caused by complicated modifications in the list
101   void eraseHash();
102
103   friend class Model_Data;
104 };
105
106 #endif