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>
12 #include <QStringList>
14 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
15 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
17 // is equal function for unique object mapping
18 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
20 return (theObj1->ID() == theObj2->ID());
23 QString HYDROData_Object::GetName() const
25 Handle(TDataStd_Name) aName;
26 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
27 TCollection_AsciiString aStr(aName->Get());
28 return QString(aStr.ToCString());
33 void HYDROData_Object::SetName(const QString& theName)
35 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
38 QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
40 QStringList anEmptyList;
44 bool HYDROData_Object::IsRemoved() const
46 return !myLab.HasAttribute();
49 void HYDROData_Object::Remove()
51 return myLab.ForgetAllAttributes(Standard_True);
54 HYDROData_Object::HYDROData_Object()
58 HYDROData_Object::~HYDROData_Object()
62 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
64 TDF_CopyLabel aCopy(myLab, theDestination->Label());
68 void HYDROData_Object::SetLabel(TDF_Label theLabel)
73 void HYDROData_Object::SaveByteArray(const int theTag,
74 const char* theData, const int theLen)
76 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
77 // array is empty, remove the attribute
79 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
82 // store data of image in byte array
83 Handle(TDataStd_ByteArray) aData;
84 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
85 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
87 // copy bytes one by one
88 if (aData->Length() != theLen) {
89 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
90 for(int a = 0; a < theLen; a++)
91 aNewData->SetValue(a + 1, theData[a]);
92 aData->ChangeArray(aNewData);
94 for(int a = 0; a < theLen; a++)
95 aData->SetValue(a + 1, theData[a]);
99 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen)
101 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
102 Handle(TDataStd_ByteArray) aData;
103 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
104 return NULL; // return empty image if there is no array
105 theLen = aData->Length();
107 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));