1 #include <HYDROData_Object.h>
3 #include <TDataStd_Name.hxx>
4 #include <TDataStd_ByteArray.hxx>
5 #include <TDF_CopyLabel.hxx>
7 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
8 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
10 // is equal function for unique object mapping
11 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
13 return (theObj1->ID() == theObj2->ID());
16 QString HYDROData_Object::GetName() const
18 Handle(TDataStd_Name) aName;
19 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
20 TCollection_AsciiString aStr(aName->Get());
21 return QString(aStr.ToCString());
26 void HYDROData_Object::SetName(const QString& theName)
28 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
31 bool HYDROData_Object::IsRemoved() const
33 return !myLab.HasAttribute();
36 void HYDROData_Object::Remove()
38 return myLab.ForgetAllAttributes(Standard_True);
41 HYDROData_Object::HYDROData_Object()
45 HYDROData_Object::~HYDROData_Object()
49 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
51 TDF_CopyLabel aCopy(myLab, theDestination->Label());
55 void HYDROData_Object::SetLabel(TDF_Label theLabel)
60 void HYDROData_Object::SaveByteArray(const int theTag,
61 const char* theData, const int theLen)
63 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
64 // array is empty, remove the attribute
66 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
69 // store data of image in byte array
70 Handle(TDataStd_ByteArray) aData;
71 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
72 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
74 // copy bytes one by one
75 if (aData->Length() != theLen) {
76 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
77 for(int a = 0; a < theLen; a++)
78 aNewData->SetValue(a + 1, theData[a]);
79 aData->ChangeArray(aNewData);
81 for(int a = 0; a < theLen; a++)
82 aData->SetValue(a + 1, theData[a]);
86 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen)
88 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
89 Handle(TDataStd_ByteArray) aData;
90 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
91 return NULL; // return empty image if there is no array
92 theLen = aData->Length();
94 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));