1 #include <HYDROData_Object.h>
3 #include <TDataStd_Name.hxx>
4 #include <TDataStd_ByteArray.hxx>
5 #include <TDataStd_UAttribute.hxx>
6 #include <TDataStd_IntegerArray.hxx>
7 #include <TDataStd_BooleanArray.hxx>
8 #include <TDataStd_RealArray.hxx>
9 #include <TDF_CopyLabel.hxx>
11 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
12 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
14 // is equal function for unique object mapping
15 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
17 return (theObj1->ID() == theObj2->ID());
20 QString HYDROData_Object::GetName() const
22 Handle(TDataStd_Name) aName;
23 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
24 TCollection_AsciiString aStr(aName->Get());
25 return QString(aStr.ToCString());
30 void HYDROData_Object::SetName(const QString& theName)
32 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
35 bool HYDROData_Object::IsRemoved() const
37 return !myLab.HasAttribute();
40 void HYDROData_Object::Remove()
42 return myLab.ForgetAllAttributes(Standard_True);
45 HYDROData_Object::HYDROData_Object()
49 HYDROData_Object::~HYDROData_Object()
53 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
55 TDF_CopyLabel aCopy(myLab, theDestination->Label());
59 void HYDROData_Object::SetLabel(TDF_Label theLabel)
64 void HYDROData_Object::SaveByteArray(const int theTag,
65 const char* theData, const int theLen)
67 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
68 // array is empty, remove the attribute
70 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
73 // store data of image in byte array
74 Handle(TDataStd_ByteArray) aData;
75 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
76 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
78 // copy bytes one by one
79 if (aData->Length() != theLen) {
80 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
81 for(int a = 0; a < theLen; a++)
82 aNewData->SetValue(a + 1, theData[a]);
83 aData->ChangeArray(aNewData);
85 for(int a = 0; a < theLen; a++)
86 aData->SetValue(a + 1, theData[a]);
90 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen)
92 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
93 Handle(TDataStd_ByteArray) aData;
94 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
95 return NULL; // return empty image if there is no array
96 theLen = aData->Length();
98 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));