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>
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
18 // is equal function for unique object mapping
19 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
21 return (theObj1->ID() == theObj2->ID());
24 QString HYDROData_Object::GetName() const
26 Handle(TDataStd_Name) aName;
27 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
28 TCollection_AsciiString aStr(aName->Get());
29 return QString(aStr.ToCString());
34 void HYDROData_Object::SetName(const QString& theName)
36 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
39 QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
41 QStringList anEmptyList;
45 void HYDROData_Object::Update()
49 QVariant HYDROData_Object::GetDataVariant()
54 bool HYDROData_Object::IsRemoved() const
56 return !myLab.HasAttribute();
59 void HYDROData_Object::Remove()
61 return myLab.ForgetAllAttributes(Standard_True);
64 HYDROData_Object::HYDROData_Object()
68 HYDROData_Object::~HYDROData_Object()
72 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
74 TDF_CopyLabel aCopy(myLab, theDestination->Label());
78 void HYDROData_Object::SetLabel(TDF_Label theLabel)
83 void HYDROData_Object::SaveByteArray(const int theTag,
84 const char* theData, const int theLen)
86 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
87 // array is empty, remove the attribute
89 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
92 // store data of image in byte array
93 Handle(TDataStd_ByteArray) aData;
94 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
95 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
97 // copy bytes one by one
98 if (aData->Length() != theLen) {
99 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
100 for(int a = 0; a < theLen; a++)
101 aNewData->SetValue(a + 1, theData[a]);
102 aData->ChangeArray(aNewData);
104 for(int a = 0; a < theLen; a++)
105 aData->SetValue(a + 1, theData[a]);
109 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen) const
111 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
112 Handle(TDataStd_ByteArray) aData;
113 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
114 return NULL; // return empty image if there is no array
115 theLen = aData->Length();
117 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));