1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <TDataStd_ReferenceArray.ixx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& TDataStd_ReferenceArray::GetID()
29 static Standard_GUID TDataStd_ReferenceArrayID ("7EE745A6-BB50-446c-BB0B-C195B23AB5CA");
30 return TDataStd_ReferenceArrayID;
33 //=======================================================================
34 //function : TDataStd_ReferenceArray
35 //purpose : Empty Constructor
36 //=======================================================================
37 TDataStd_ReferenceArray::TDataStd_ReferenceArray()
42 //=======================================================================
45 //=======================================================================
46 void TDataStd_ReferenceArray::Init(const Standard_Integer lower,
47 const Standard_Integer upper)
49 Standard_RangeError_Raise_if(upper < lower,"TDataStd_ReferenceArray::Init");
51 myArray = new TDataStd_HLabelArray1(lower, upper);
54 //=======================================================================
57 //=======================================================================
58 Handle(TDataStd_ReferenceArray) TDataStd_ReferenceArray::Set(const TDF_Label& label,
59 const Standard_Integer lower,
60 const Standard_Integer upper)
62 Handle(TDataStd_ReferenceArray) A;
63 if (!label.FindAttribute (TDataStd_ReferenceArray::GetID(), A))
65 A = new TDataStd_ReferenceArray;
66 A->Init (lower, upper);
67 label.AddAttribute(A);
69 else if (lower != A->Lower() || upper != A->Upper())
71 A->Init(lower, upper);
76 //=======================================================================
79 //=======================================================================
80 void TDataStd_ReferenceArray::SetValue (const Standard_Integer index,
81 const TDF_Label& value)
83 if (value == myArray->Value(index))
88 myArray->SetValue(index, value);
91 //=======================================================================
94 //=======================================================================
95 TDF_Label TDataStd_ReferenceArray::Value (const Standard_Integer index) const
97 return myArray->Value(index);
100 //=======================================================================
103 //=======================================================================
104 Standard_Integer TDataStd_ReferenceArray::Lower () const
106 if (myArray.IsNull())
108 return myArray->Lower();
111 //=======================================================================
114 //=======================================================================
115 Standard_Integer TDataStd_ReferenceArray::Upper () const
117 if (myArray.IsNull())
119 return myArray->Upper();
122 //=======================================================================
125 //=======================================================================
126 Standard_Integer TDataStd_ReferenceArray::Length () const
128 if (myArray.IsNull())
130 return myArray->Length();
133 //=======================================================================
134 //function : InternalArray
136 //=======================================================================
137 const Handle(TDataStd_HLabelArray1)& TDataStd_ReferenceArray::InternalArray () const
142 //=======================================================================
143 //function : SetInternalArray
145 //=======================================================================
146 void TDataStd_ReferenceArray::SetInternalArray (const Handle(TDataStd_HLabelArray1)& values,
147 const Standard_Boolean isCheckItem)
150 Standard_Integer aLower = values->Lower();
151 Standard_Integer anUpper = values->Upper();
152 Standard_Boolean aDimEqual = Standard_False;
156 if (Lower() == aLower && Upper() == anUpper ) {
157 aDimEqual = Standard_True;
158 Standard_Boolean isEqual = Standard_True;
160 for(i = aLower; i <= anUpper; i++) {
161 if(myArray->Value(i) != values->Value(i)) {
162 isEqual = Standard_False;
174 if(myArray.IsNull() || !aDimEqual)
175 myArray = new TDataStd_HLabelArray1(aLower, anUpper);
177 for(i = aLower; i <= anUpper; i++)
178 myArray->SetValue(i, values->Value(i));
181 //=======================================================================
184 //=======================================================================
185 const Standard_GUID& TDataStd_ReferenceArray::ID () const
190 //=======================================================================
191 //function : NewEmpty
193 //=======================================================================
194 Handle(TDF_Attribute) TDataStd_ReferenceArray::NewEmpty () const
196 return new TDataStd_ReferenceArray();
199 //=======================================================================
202 //=======================================================================
203 void TDataStd_ReferenceArray::Restore(const Handle(TDF_Attribute)& With)
205 Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(With);
206 if (!anArray->myArray.IsNull())
208 const TDataStd_LabelArray1& arr = anArray->myArray->Array1();
209 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
211 for (; i <= upper; i++)
213 myArray->SetValue(i, arr.Value(i));
222 //=======================================================================
225 //=======================================================================
226 void TDataStd_ReferenceArray::Paste (const Handle(TDF_Attribute)& Into,
227 const Handle(TDF_RelocationTable)& RT) const
229 Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(Into);
230 if (myArray.IsNull())
232 anArray->myArray.Nullify();
235 const TDataStd_LabelArray1& arr = myArray->Array1();
236 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
237 if (lower != anArray->Lower() || upper != anArray->Upper())
238 anArray->Init(lower, upper);
239 for (; i <= upper; i++)
241 TDF_Label L = arr.Value(i), rL;
244 if (!RT->HasRelocation(L, rL))
246 anArray->myArray->SetValue(i, rL);
251 //=======================================================================
252 //function : References
253 //purpose : Adds the referenced attributes or labels.
254 //=======================================================================
255 void TDataStd_ReferenceArray::References(const Handle(TDF_DataSet)& aDataSet) const
257 if (!Label().IsImported() && !myArray.IsNull())
259 const TDataStd_LabelArray1& arr = myArray->Array1();
260 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
261 for (; i <= upper; i++)
263 if (!arr.Value(i).IsNull())
264 aDataSet->AddLabel(arr.Value(i));
269 //=======================================================================
272 //=======================================================================
273 Standard_OStream& TDataStd_ReferenceArray::Dump (Standard_OStream& anOS) const
275 anOS << "ReferenceArray";