0030520: VIS - IVtkTools_ShapePicker::GetPickPosition() returns incorrect point
[occt.git] / src / TObj / TObj_TIntSparseArray.hxx
1 // Created on: 2007-03-16
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // The original implementation Copyright: (C) RINA S.p.A
17
18 #ifndef TObj_TIntSparseArray_HeaderFile
19 #define TObj_TIntSparseArray_HeaderFile
20
21 #include <TObj_Common.hxx>
22
23 #include <NCollection_SparseArray.hxx>
24 #include <TDF_Attribute.hxx>
25 #include <TDF_Label.hxx>
26
27 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_VecOfData;
28 typedef NCollection_SparseArray<Standard_Integer> TObj_TIntSparseArray_MapOfData;
29
30 class Standard_GUID;
31
32 /**
33  * OCAF Attribute to store a set of positive integer values in the OCAF tree.
34  * Each value is identified by ID (positive integer).
35  * The supporting underlying data structure is NCollection_SparseArray of integers.
36  */
37
38 class TObj_TIntSparseArray : public TDF_Attribute
39 {
40  public:
41
42   //! Empty constructor
43   Standard_EXPORT TObj_TIntSparseArray();
44
45   //! This method is used in implementation of ID()
46   static Standard_EXPORT const Standard_GUID& GetID();
47
48   //! Returns the ID of this attribute.
49   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
50
51   //! Creates TObj_TIntSparseArray attribute on given label.
52   static Standard_EXPORT Handle(TObj_TIntSparseArray) Set
53                             (const TDF_Label& theLabel);
54
55  public:
56   //! Methods for access to data
57
58   //! Returns the number of stored values in the set
59   Standard_Size Size() const
60   { return myVector.Size(); }
61
62   typedef TObj_TIntSparseArray_VecOfData::ConstIterator Iterator;
63
64   //! Returns iterator on objects contained in the set
65   Iterator GetIterator() const { return Iterator(myVector); }
66
67   //! Returns true if the value with the given ID is present.
68   Standard_Boolean HasValue (const Standard_Size theId) const
69   { return myVector.HasValue(theId); }
70
71   //! Returns the value by its ID.
72   //! Raises an exception if no value is stored with this ID
73   Standard_Integer Value (const Standard_Size theId) const
74   { return myVector.Value(theId); }
75
76   //! Sets the value with the given ID.
77   //! Raises an exception if theId is not positive
78   Standard_EXPORT void SetValue (const Standard_Size theId,
79                                  const Standard_Integer theValue);
80
81   //! Unsets the value with the given ID.
82   //! Raises an exception if theId is not positive
83   Standard_EXPORT void UnsetValue(const Standard_Size theId);
84
85   //! Clears the set
86   Standard_EXPORT void Clear ();
87
88  public:
89   //! Redefined OCAF abstract methods
90
91   //! Returns an new empty TObj_TIntSparseArray attribute. It is used by the
92   //! copy algorithm.
93   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
94
95   //! Moves this delta into a new other attribute.
96   Standard_EXPORT Handle(TDF_Attribute) BackupCopy() const Standard_OVERRIDE;
97
98   //! Restores the set using info saved in backup attribute theDelta.
99   Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theDelta) Standard_OVERRIDE;
100
101   //! This method is used when copying an attribute from a source structure
102   //! into a target structure.
103   Standard_EXPORT void Paste(const Handle(TDF_Attribute)&       theInto,
104                              const Handle(TDF_RelocationTable)& theRT) const Standard_OVERRIDE;
105
106   //! It is called just before Commit or Abort transaction
107   //! and does Backup() to create a delta
108   Standard_EXPORT void BeforeCommitTransaction() Standard_OVERRIDE;
109
110   //! Applies theDelta to this.
111   Standard_EXPORT void DeltaOnModification
112                         (const Handle(TDF_DeltaOnModification)& theDelta) Standard_OVERRIDE;
113
114   //! Clears my modification delta; called after application of theDelta
115   Standard_EXPORT Standard_Boolean AfterUndo
116                         (const Handle(TDF_AttributeDelta)& theDelta,
117                          const Standard_Boolean toForce) Standard_OVERRIDE;
118
119  public:
120   //! Methods to handle the modification delta
121
122   //! Sets the flag pointing to the necessity to maintain a modification delta.
123   //! It is called by the retrieval driver
124   void SetDoBackup (const Standard_Boolean toDo)
125   { myDoBackup = toDo; }
126
127   void ClearDelta ()
128   { myOldMap.Clear(); }
129
130  private:
131   //! Internal constant to recognize items in the backup array
132   //! correspondent to absent values
133   enum
134   {
135     AbsentValue = -1
136   };
137
138   //! backup one value
139   void backupValue (const Standard_Size theId,
140                     const Standard_Integer theCurrValue,
141                     const Standard_Integer theNewValue);
142
143   TObj_TIntSparseArray_VecOfData myVector;
144   TObj_TIntSparseArray_MapOfData myOldMap;
145   Standard_Boolean               myDoBackup;
146
147  public:
148   //! CASCADE RTTI
149   DEFINE_STANDARD_RTTIEXT(TObj_TIntSparseArray,TDF_Attribute)
150 };
151
152 //! Define handle class for TObj_TIntSparseArray
153 DEFINE_STANDARD_HANDLE(TObj_TIntSparseArray,TDF_Attribute)
154
155 #endif
156
157 #ifdef _MSC_VER
158 #pragma once
159 #endif