1 // Created on: 2002-01-16
2 // Created by: Michael PONIKAROV
3 // Copyright (c) 2002-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_ExtStringArray.hxx>
18 #include <Standard_Dump.hxx>
19 #include <Standard_GUID.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_ExtendedString.hxx>
22 #include <TDataStd_DeltaOnModificationOfExtStringArray.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TDF_DefaultDeltaOnModification.hxx>
25 #include <TDF_DeltaOnModification.hxx>
26 #include <TDF_Label.hxx>
27 #include <TDF_RelocationTable.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_ExtStringArray,TDF_Attribute)
31 //=======================================================================
34 //=======================================================================
35 const Standard_GUID& TDataStd_ExtStringArray::GetID()
37 static Standard_GUID anExtStringArrayID ("2a96b624-ec8b-11d0-bee7-080009dc3333");
38 return anExtStringArrayID;
41 //=======================================================================
43 //purpose : Implements Set functionality
44 //=======================================================================
45 Handle(TDataStd_ExtStringArray) SetAttr(const TDF_Label& label,
46 const Standard_Integer lower,
47 const Standard_Integer upper,
48 const Standard_Boolean isDelta,
49 const Standard_GUID& theGuid)
51 Handle(TDataStd_ExtStringArray) A;
52 if (!label.FindAttribute (theGuid, A))
54 A = new TDataStd_ExtStringArray;
56 A->Init (lower, upper);
58 label.AddAttribute(A);
60 else if (lower != A->Lower() || upper != A->Upper())
62 A->Init(lower, upper);
66 //=======================================================================
67 //function : TDataStd_ExtStringArray::TDataStd_ExtStringArray
69 //=======================================================================
71 TDataStd_ExtStringArray::TDataStd_ExtStringArray()
72 : myIsDelta(Standard_False), myID(GetID())
75 //=======================================================================
78 //=======================================================================
80 void TDataStd_ExtStringArray::Init(const Standard_Integer lower,
81 const Standard_Integer upper)
83 Standard_RangeError_Raise_if(upper < lower,"TDataStd_ExtStringArray::Init");
85 myValue = new TColStd_HArray1OfExtendedString(lower, upper, "");
88 //=======================================================================
91 //=======================================================================
93 Handle(TDataStd_ExtStringArray) TDataStd_ExtStringArray::Set (
94 const TDF_Label& label,
95 const Standard_Integer lower,
96 const Standard_Integer upper,
97 const Standard_Boolean isDelta)
100 return SetAttr(label, lower, upper, isDelta, GetID());
103 //=======================================================================
105 //purpose : Set user defined attribute with specific ID
106 //=======================================================================
108 Handle(TDataStd_ExtStringArray) TDataStd_ExtStringArray::Set (
109 const TDF_Label& label,
110 const Standard_GUID& theGuid,
111 const Standard_Integer lower,
112 const Standard_Integer upper,
113 const Standard_Boolean isDelta)
116 return SetAttr(label, lower, upper, isDelta, theGuid);
118 //=======================================================================
119 //function : SetValue
121 //=======================================================================
123 void TDataStd_ExtStringArray::SetValue(const Standard_Integer index, const TCollection_ExtendedString& value)
125 if(myValue.IsNull()) return;
126 if( myValue->Value(index) == value)
130 myValue->SetValue(index, value);
134 //=======================================================================
137 //=======================================================================
139 const TCollection_ExtendedString& TDataStd_ExtStringArray::Value (const Standard_Integer index) const
141 if (myValue.IsNull())
143 static TCollection_ExtendedString staticEmptyValue;
144 return staticEmptyValue;
146 return myValue->Value(index);
149 //=======================================================================
152 //=======================================================================
153 Standard_Integer TDataStd_ExtStringArray::Lower (void) const
155 if(myValue.IsNull()) return 0;
156 return myValue->Lower();
160 //=======================================================================
163 //=======================================================================
164 Standard_Integer TDataStd_ExtStringArray::Upper (void) const
166 if(myValue.IsNull()) return 0;
167 return myValue->Upper();
171 //=======================================================================
174 //=======================================================================
175 Standard_Integer TDataStd_ExtStringArray::Length (void) const
177 if(myValue.IsNull()) return 0;
178 return myValue->Length();
183 //=======================================================================
184 //function : ChangeArray
185 //purpose : If value of <newArray> differs from <myValue>, Backup
186 // : performed and myValue refers to new instance of HArray1OfExtendedString
187 // : that holds <newArray>
188 //=======================================================================
190 void TDataStd_ExtStringArray::ChangeArray(const Handle(TColStd_HArray1OfExtendedString)& newArray,
191 const Standard_Boolean isCheckItems)
193 Standard_Integer aLower = newArray->Lower();
194 Standard_Integer anUpper = newArray->Upper();
195 Standard_Boolean aDimEqual = Standard_False;
198 if (Lower() == aLower && Upper() == anUpper ) {
199 aDimEqual = Standard_True;
200 Standard_Boolean isEqual = Standard_True;
202 for(i = aLower; i <= anUpper; i++) {
203 if(myValue->Value(i) != newArray->Value(i)) {
204 isEqual = Standard_False;
215 // Handles of myValue of current and backuped attributes will be different!!!
216 if(myValue.IsNull() || !aDimEqual)
217 myValue = new TColStd_HArray1OfExtendedString(aLower, anUpper);
219 for(i = aLower; i <= anUpper; i++)
220 myValue->SetValue(i, newArray->Value(i));
223 //=======================================================================
226 //=======================================================================
228 const Standard_GUID& TDataStd_ExtStringArray::ID () const { return myID; }
230 //=======================================================================
233 //=======================================================================
235 void TDataStd_ExtStringArray::SetID( const Standard_GUID& theGuid)
237 if(myID == theGuid) return;
242 //=======================================================================
244 //purpose : sets default ID
245 //=======================================================================
247 void TDataStd_ExtStringArray::SetID()
253 //=======================================================================
254 //function : NewEmpty
256 //=======================================================================
258 Handle(TDF_Attribute) TDataStd_ExtStringArray::NewEmpty () const
260 return new TDataStd_ExtStringArray();
263 //=======================================================================
266 //=======================================================================
268 void TDataStd_ExtStringArray::Restore(const Handle(TDF_Attribute)& With)
270 Standard_Integer i, lower, upper;
271 Handle(TDataStd_ExtStringArray) anArray = Handle(TDataStd_ExtStringArray)::DownCast(With);
272 if(!anArray->myValue.IsNull()) {
273 lower = anArray->Lower();
274 upper = anArray->Upper();
275 myValue = new TColStd_HArray1OfExtendedString(lower, upper);
276 for(i = lower; i<=upper; i++)
277 myValue->SetValue(i, anArray->Value(i));
278 myIsDelta = anArray->myIsDelta;
279 myID = anArray->ID();
285 //=======================================================================
288 //=======================================================================
290 void TDataStd_ExtStringArray::Paste (const Handle(TDF_Attribute)& Into,
291 const Handle(TDF_RelocationTable)& ) const
293 if(!myValue.IsNull()) {
294 Handle(TDataStd_ExtStringArray) anAtt = Handle(TDataStd_ExtStringArray)::DownCast(Into);
295 if(!anAtt.IsNull()) {
296 anAtt->ChangeArray( myValue, Standard_False );
297 anAtt->SetDelta(myIsDelta);
303 //=======================================================================
306 //=======================================================================
308 Standard_OStream& TDataStd_ExtStringArray::Dump (Standard_OStream& anOS) const
310 anOS << "\nExtStringArray :";
311 if(!myValue.IsNull()) {
312 Standard_Integer i, lower, upper;
313 lower = myValue->Lower();
314 upper = myValue->Upper();
315 for(i = lower; i<=upper; i++)
316 anOS << "\t" <<myValue->Value(i)<<std::endl;
318 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
319 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
320 myID.ToCString(sguid);
326 //=======================================================================
327 //function : DeltaOnModification
329 //=======================================================================
331 Handle(TDF_DeltaOnModification) TDataStd_ExtStringArray::DeltaOnModification
332 (const Handle(TDF_Attribute)& OldAttribute) const
335 return new TDataStd_DeltaOnModificationOfExtStringArray(Handle(TDataStd_ExtStringArray)::DownCast (OldAttribute));
336 else return new TDF_DefaultDeltaOnModification(OldAttribute);
339 //=======================================================================
340 //function : DumpJson
342 //=======================================================================
343 void TDataStd_ExtStringArray::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
345 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
347 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
349 if (!myValue.IsNull())
351 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myValue->Lower())
352 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myValue->Upper())
354 for (TColStd_Array1OfExtendedString::Iterator aValueIt (myValue->Array1()); aValueIt.More(); aValueIt.Next())
356 const TCollection_ExtendedString& aValue = aValueIt.Value();
357 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aValue)
361 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsDelta)