0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / TDataStd / TDataStd_IntegerArray.hxx
1 // Created on: 1999-06-16
2 // Created by: Sergey RUIN
3 // Copyright (c) 1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _TDataStd_IntegerArray_HeaderFile
18 #define _TDataStd_IntegerArray_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <TColStd_HArray1OfInteger.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <TDF_Attribute.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_OStream.hxx>
28 #include <Standard_GUID.hxx>
29
30 class TDataStd_DeltaOnModificationOfIntArray;
31 class Standard_GUID;
32 class TDF_Label;
33 class TDF_Attribute;
34 class TDF_RelocationTable;
35 class TDF_DeltaOnModification;
36
37
38 class TDataStd_IntegerArray;
39 DEFINE_STANDARD_HANDLE(TDataStd_IntegerArray, TDF_Attribute)
40
41 //! Contains an array of integers.
42 class TDataStd_IntegerArray : public TDF_Attribute
43 {
44   friend class TDataStd_DeltaOnModificationOfIntArray;
45   DEFINE_STANDARD_RTTIEXT(TDataStd_IntegerArray, TDF_Attribute)
46 public:
47
48   //! class methods
49   //! =============
50   //! Returns the GUID for arrays of integers.
51   Standard_EXPORT static const Standard_GUID& GetID();
52   
53   //! Finds or creates on the <label> an integer array attribute
54   //! with the specified <lower> and <upper> boundaries.
55   //! If <isDelta> == False, DefaultDeltaOnModification is used.
56   //! If <isDelta> == True, DeltaOnModification of the current attribute is used.
57   //! If attribute is already set, all input parameters are refused and the found
58   //! attribute is returned.
59   Standard_EXPORT static Handle(TDataStd_IntegerArray) Set (const TDF_Label& label, const Standard_Integer lower, 
60                                                             const Standard_Integer upper, 
61                                                             const Standard_Boolean isDelta = Standard_False);
62   
63   //! Finds, or creates, an IntegerArray attribute with explicit user defined <guid>.
64   //! The IntegerArray attribute  is  returned.
65   Standard_EXPORT static Handle(TDataStd_IntegerArray) Set (const TDF_Label& label, const Standard_GUID&   theGuid,
66                                                             const Standard_Integer lower, const Standard_Integer upper, 
67                                                             const Standard_Boolean isDelta = Standard_False);
68
69   //! Initialize the inner array with bounds from <lower> to <upper>
70   Standard_EXPORT void Init (const Standard_Integer lower, const Standard_Integer upper);
71   
72   //! Sets  the   <Index>th  element  of   the  array to <Value>
73   //! OutOfRange exception is raised if <Index> doesn't respect Lower and Upper bounds of the internal  array.
74   Standard_EXPORT void SetValue (const Standard_Integer Index, const Standard_Integer Value);
75   
76   //! Sets the explicit GUID (user defined) for the attribute.
77   Standard_EXPORT void SetID( const Standard_GUID&  theGuid) Standard_OVERRIDE;
78
79   //! Sets default GUID for the attribute.
80   Standard_EXPORT void SetID() Standard_OVERRIDE;
81
82   //! Return the value of  the  <Index>th element of the array
83   Standard_EXPORT Standard_Integer Value (const Standard_Integer Index) const;
84
85   Standard_Integer operator () (const Standard_Integer Index) const 
86   {
87     return Value(Index);
88   }
89   
90   //! Returns the lower boundary of this array of integers.
91   Standard_EXPORT Standard_Integer Lower() const;
92   
93   //! Return the upper boundary of this array of integers.
94   Standard_EXPORT Standard_Integer Upper() const;
95   
96   //! Returns the length of this array of integers in
97   //! terms of the number of elements it contains.
98   Standard_EXPORT Standard_Integer Length() const;
99   
100   //! Sets the inner array <myValue>  of the IntegerArray attribute to
101   //! <newArray>. If value of <newArray> differs from <myValue>, Backup performed
102   //! and myValue refers to new instance of HArray1OfInteger that holds <newArray>
103   //! values
104   //! If <isCheckItems> equal True each item of <newArray> will be checked with each
105   //! item of <myValue> for coincidence (to avoid backup).
106   Standard_EXPORT void ChangeArray (const Handle(TColStd_HArray1OfInteger)& newArray, const Standard_Boolean isCheckItems = Standard_True);
107
108   //! Return the inner array of the IntegerArray attribute
109   const Handle(TColStd_HArray1OfInteger)& Array() const { return myValue; }
110
111   Standard_Boolean GetDelta() const { return myIsDelta; }
112
113   //! for  internal  use  only!
114   void SetDelta (const Standard_Boolean isDelta) { myIsDelta = isDelta; }
115
116   Standard_EXPORT TDataStd_IntegerArray();
117   
118   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
119   
120   Standard_EXPORT void Restore (const Handle(TDF_Attribute)& With) Standard_OVERRIDE;
121   
122   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
123   
124   //! Note. Uses inside ChangeArray() method
125   Standard_EXPORT void Paste (const Handle(TDF_Attribute)& Into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
126   
127   Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
128   
129   //! Makes a DeltaOnModification between <me> and
130   //! <anOldAttribute>.
131   Standard_EXPORT virtual Handle(TDF_DeltaOnModification) DeltaOnModification (const Handle(TDF_Attribute)& anOldAttribute) const Standard_OVERRIDE;
132
133 private:
134
135   void RemoveArray() { myValue.Nullify(); }
136
137 private:
138
139   Handle(TColStd_HArray1OfInteger) myValue;
140   Standard_Boolean myIsDelta;
141   Standard_GUID myID;
142
143
144 };
145
146 #endif // _TDataStd_IntegerArray_HeaderFile