1 #include <HYDROData_Object.h>
3 #include <TDataStd_Name.hxx>
4 #include <TDataStd_ByteArray.hxx>
5 #include <TDataStd_UAttribute.hxx>
6 #include <TDF_CopyLabel.hxx>
8 static const Standard_GUID GUID_VISIBILITY("d6a715c5-9c86-4adc-8a6c-13188f3ad94b");
10 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
11 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
13 // is equal function for unique object mapping
14 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
16 return (theObj1->ID() == theObj2->ID());
19 QString HYDROData_Object::GetName() const
21 Handle(TDataStd_Name) aName;
22 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
23 TCollection_AsciiString aStr(aName->Get());
24 return QString(aStr.ToCString());
29 void HYDROData_Object::SetName(const QString& theName)
31 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
34 bool HYDROData_Object::GetVisibility() const
36 return myLab.IsAttribute(GUID_VISIBILITY);
39 void HYDROData_Object::SetVisibility(bool theState)
42 TDataStd_UAttribute::Set(myLab, GUID_VISIBILITY);
44 myLab.ForgetAttribute(GUID_VISIBILITY);
48 bool HYDROData_Object::IsRemoved() const
50 return !myLab.HasAttribute();
53 void HYDROData_Object::Remove()
55 return myLab.ForgetAllAttributes(Standard_True);
58 HYDROData_Object::HYDROData_Object()
62 HYDROData_Object::~HYDROData_Object()
66 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
68 TDF_CopyLabel aCopy(myLab, theDestination->Label());
72 void HYDROData_Object::SetLabel(TDF_Label theLabel)
77 void HYDROData_Object::SaveByteArray(const int theTag,
78 const char* theData, const int theLen)
80 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
81 // array is empty, remove the attribute
83 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
86 // store data of image in byte array
87 Handle(TDataStd_ByteArray) aData;
88 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
89 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
91 // copy bytes one by one
92 if (aData->Length() != theLen) {
93 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
94 for(int a = 0; a < theLen; a++)
95 aNewData->SetValue(a + 1, theData[a]);
96 aData->ChangeArray(aNewData);
98 for(int a = 0; a < theLen; a++)
99 aData->SetValue(a + 1, theData[a]);
103 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen)
105 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
106 Handle(TDataStd_ByteArray) aData;
107 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
108 return NULL; // return empty image if there is no array
109 theLen = aData->Length();
111 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));