1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <TDataStd_ReferenceArray.ixx>
18 //=======================================================================
21 //=======================================================================
22 const Standard_GUID& TDataStd_ReferenceArray::GetID()
24 static Standard_GUID TDataStd_ReferenceArrayID ("7EE745A6-BB50-446c-BB0B-C195B23AB5CA");
25 return TDataStd_ReferenceArrayID;
28 //=======================================================================
29 //function : TDataStd_ReferenceArray
30 //purpose : Empty Constructor
31 //=======================================================================
32 TDataStd_ReferenceArray::TDataStd_ReferenceArray()
37 //=======================================================================
40 //=======================================================================
41 void TDataStd_ReferenceArray::Init(const Standard_Integer lower,
42 const Standard_Integer upper)
44 Standard_RangeError_Raise_if(upper < lower,"TDataStd_ReferenceArray::Init");
46 myArray = new TDataStd_HLabelArray1(lower, upper);
49 //=======================================================================
52 //=======================================================================
53 Handle(TDataStd_ReferenceArray) TDataStd_ReferenceArray::Set(const TDF_Label& label,
54 const Standard_Integer lower,
55 const Standard_Integer upper)
57 Handle(TDataStd_ReferenceArray) A;
58 if (!label.FindAttribute (TDataStd_ReferenceArray::GetID(), A))
60 A = new TDataStd_ReferenceArray;
61 A->Init (lower, upper);
62 label.AddAttribute(A);
64 else if (lower != A->Lower() || upper != A->Upper())
66 A->Init(lower, upper);
71 //=======================================================================
74 //=======================================================================
75 void TDataStd_ReferenceArray::SetValue (const Standard_Integer index,
76 const TDF_Label& value)
78 if(myArray.IsNull()) return;
79 if (value == myArray->Value(index))
83 myArray->SetValue(index, value);
86 //=======================================================================
89 //=======================================================================
90 TDF_Label TDataStd_ReferenceArray::Value (const Standard_Integer index) const
92 return myArray->Value(index);
95 //=======================================================================
98 //=======================================================================
99 Standard_Integer TDataStd_ReferenceArray::Lower () const
101 if (myArray.IsNull())
103 return myArray->Lower();
106 //=======================================================================
109 //=======================================================================
110 Standard_Integer TDataStd_ReferenceArray::Upper () const
112 if (myArray.IsNull())
114 return myArray->Upper();
117 //=======================================================================
120 //=======================================================================
121 Standard_Integer TDataStd_ReferenceArray::Length () const
123 if (myArray.IsNull())
125 return myArray->Length();
128 //=======================================================================
129 //function : InternalArray
131 //=======================================================================
132 const Handle(TDataStd_HLabelArray1)& TDataStd_ReferenceArray::InternalArray () const
137 //=======================================================================
138 //function : SetInternalArray
140 //=======================================================================
141 void TDataStd_ReferenceArray::SetInternalArray (const Handle(TDataStd_HLabelArray1)& values,
142 const Standard_Boolean)
145 Standard_Integer aLower = values->Lower();
146 Standard_Integer anUpper = values->Upper();
147 Standard_Boolean aDimEqual = Standard_False;
151 if (Lower() == aLower && Upper() == anUpper ) {
152 aDimEqual = Standard_True;
153 Standard_Boolean isEqual = Standard_True;
155 for(i = aLower; i <= anUpper; i++) {
156 if(myArray->Value(i) != values->Value(i)) {
157 isEqual = Standard_False;
169 if(myArray.IsNull() || !aDimEqual)
170 myArray = new TDataStd_HLabelArray1(aLower, anUpper);
172 for(i = aLower; i <= anUpper; i++)
173 myArray->SetValue(i, values->Value(i));
176 //=======================================================================
179 //=======================================================================
180 const Standard_GUID& TDataStd_ReferenceArray::ID () const
185 //=======================================================================
186 //function : NewEmpty
188 //=======================================================================
189 Handle(TDF_Attribute) TDataStd_ReferenceArray::NewEmpty () const
191 return new TDataStd_ReferenceArray();
194 //=======================================================================
197 //=======================================================================
198 void TDataStd_ReferenceArray::Restore(const Handle(TDF_Attribute)& With)
200 Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(With);
201 if (!anArray->myArray.IsNull())
203 const TDataStd_LabelArray1& arr = anArray->myArray->Array1();
204 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
206 for (; i <= upper; i++)
208 myArray->SetValue(i, arr.Value(i));
217 //=======================================================================
220 //=======================================================================
221 void TDataStd_ReferenceArray::Paste (const Handle(TDF_Attribute)& Into,
222 const Handle(TDF_RelocationTable)& RT) const
224 Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(Into);
225 if (myArray.IsNull())
227 anArray->myArray.Nullify();
230 const TDataStd_LabelArray1& arr = myArray->Array1();
231 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
232 if (lower != anArray->Lower() || upper != anArray->Upper())
233 anArray->Init(lower, upper);
234 for (; i <= upper; i++)
236 TDF_Label L = arr.Value(i), rL;
239 if (!RT->HasRelocation(L, rL))
241 anArray->myArray->SetValue(i, rL);
246 //=======================================================================
247 //function : References
248 //purpose : Adds the referenced attributes or labels.
249 //=======================================================================
250 void TDataStd_ReferenceArray::References(const Handle(TDF_DataSet)& aDataSet) const
252 if (!Label().IsImported() && !myArray.IsNull())
254 const TDataStd_LabelArray1& arr = myArray->Array1();
255 Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper();
256 for (; i <= upper; i++)
258 if (!arr.Value(i).IsNull())
259 aDataSet->AddLabel(arr.Value(i));
264 //=======================================================================
267 //=======================================================================
268 Standard_OStream& TDataStd_ReferenceArray::Dump (Standard_OStream& anOS) const
270 anOS << "ReferenceArray";