2 #include "HYDROData_Object.h"
4 #include "HYDROData_Iterator.h"
6 #include <TDataStd_Name.hxx>
7 #include <TDataStd_ByteArray.hxx>
8 #include <TDataStd_UAttribute.hxx>
9 #include <TDataStd_IntegerArray.hxx>
10 #include <TDataStd_BooleanArray.hxx>
11 #include <TDataStd_RealArray.hxx>
12 #include <TDataStd_ReferenceList.hxx>
14 #include <TDF_CopyLabel.hxx>
15 #include <TDF_ListIteratorOfLabelList.hxx>
18 #include <QStringList>
21 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
22 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
24 // is equal function for unique object mapping
25 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
27 return (theObj1->ID() == theObj2->ID());
30 QString HYDROData_Object::GetName() const
32 Handle(TDataStd_Name) aName;
33 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
34 TCollection_AsciiString aStr(aName->Get());
35 return QString(aStr.ToCString());
40 void HYDROData_Object::SetName(const QString& theName)
42 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
45 QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
47 QStringList anEmptyList;
51 void HYDROData_Object::Update( const bool theIsForce )
55 QVariant HYDROData_Object::GetDataVariant()
60 bool HYDROData_Object::IsRemoved() const
62 return !myLab.HasAttribute();
65 void HYDROData_Object::Remove()
67 return myLab.ForgetAllAttributes(Standard_True);
70 HYDROData_Object::HYDROData_Object()
74 HYDROData_Object::~HYDROData_Object()
78 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
80 TDF_CopyLabel aCopy(myLab, theDestination->Label());
84 void HYDROData_Object::SetLabel(TDF_Label theLabel)
89 void HYDROData_Object::SaveByteArray(const int theTag,
90 const char* theData, const int theLen)
92 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
93 // array is empty, remove the attribute
95 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
98 // store data of image in byte array
99 Handle(TDataStd_ByteArray) aData;
100 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
101 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
103 // copy bytes one by one
104 if (aData->Length() != theLen) {
105 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
106 for(int a = 0; a < theLen; a++)
107 aNewData->SetValue(a + 1, theData[a]);
108 aData->ChangeArray(aNewData);
110 for(int a = 0; a < theLen; a++)
111 aData->SetValue(a + 1, theData[a]);
115 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen) const
117 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
118 Handle(TDataStd_ByteArray) aData;
119 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
120 return NULL; // return empty image if there is no array
121 theLen = aData->Length();
123 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
127 int HYDROData_Object::NbReferenceObjects( const int theTag ) const
129 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
130 return aRefs.IsNull() ? 0 : aRefs->Extent();
133 void HYDROData_Object::AddReferenceObject( const Handle_HYDROData_Object& theObj,
136 if ( theObj.IsNull() )
139 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
140 aRefs->Append( theObj->Label() );
143 void HYDROData_Object::SetReferenceObject( const Handle_HYDROData_Object& theObj,
147 if ( theObj.IsNull() )
150 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
152 if ( theIndex >= aRefs->Extent() )
154 aRefs->Append( theObj->Label() );
156 else if ( theIndex < 0 )
158 aRefs->Prepend( theObj->Label() );
162 RemoveReferenceObject( theTag, theIndex );
164 Handle(HYDROData_Object) aBeforeObj = GetReferenceObject( theTag, theIndex );
166 aRefs = getReferenceList( theTag, true ); // because reference list can be removed
167 if ( !aBeforeObj.IsNull() )
168 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
170 aRefs->Append( theObj->Label() );
174 Handle(HYDROData_Object) HYDROData_Object::GetReferenceObject( const int theTag,
175 const int theIndex ) const
177 Handle(HYDROData_Object) aRes;
179 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
180 if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
183 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
184 for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
186 const TDF_Label& aRefLabel = anIter.Value();
187 aRes = HYDROData_Iterator::Object( aRefLabel );
192 HYDROData_SequenceOfObjects HYDROData_Object::GetReferenceObjects( const int theTag ) const
194 HYDROData_SequenceOfObjects aRes;
196 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
197 if ( aRefs.IsNull() )
200 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
201 for ( ; anIter.More(); anIter.Next() )
203 const TDF_Label& aRefLabel = anIter.Value();
205 Handle(HYDROData_Object) aRefObject = HYDROData_Iterator::Object( aRefLabel );
206 if ( aRefObject.IsNull() )
209 aRes.Append( aRefObject );
215 void HYDROData_Object::RemoveReferenceObject( const int theTag,
218 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
219 if ( aRefs.IsNull() )
222 if ( aRefs->Extent() == 1 && theIndex == 0 )
224 // remove all if only one
225 ClearReferenceObjects( theTag );
229 Handle(HYDROData_Object) aRemovedObj = GetReferenceObject( theTag, theIndex );
230 if ( aRemovedObj.IsNull() )
233 aRefs->Remove( aRemovedObj->Label() );
236 void HYDROData_Object::ClearReferenceObjects( const int theTag )
238 TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
239 aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
242 Handle(TDataStd_ReferenceList) HYDROData_Object::getReferenceList( const int theTag,
243 const bool theIsCreate ) const
245 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
247 Handle(TDataStd_ReferenceList) aRefs;
248 if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
249 aRefs = TDataStd_ReferenceList::Set( aLabel );