Salome HOME
Dump Bathymetry data to python script (Feature #13).
[modules/hydro.git] / src / HYDROData / HYDROData_Object.cxx
1 #include <HYDROData_Object.h>
2
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>
10
11 #include <QString>
12 #include <QStringList>
13
14 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
15 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
16
17 // is equal function for unique object mapping
18 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
19 {
20   return (theObj1->ID() == theObj2->ID());
21 }
22
23 QString HYDROData_Object::GetName() const
24 {
25   Handle(TDataStd_Name) aName;
26   if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
27     TCollection_AsciiString aStr(aName->Get());
28     return QString(aStr.ToCString());
29   }
30   return QString();
31 }
32
33 void HYDROData_Object::SetName(const QString& theName)
34 {
35   TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
36 }
37
38 QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
39 {
40   QStringList anEmptyList;
41   return anEmptyList;
42 }
43
44 bool HYDROData_Object::IsRemoved() const
45 {
46   return !myLab.HasAttribute();
47 }
48
49 void HYDROData_Object::Remove()
50 {
51   return myLab.ForgetAllAttributes(Standard_True);
52 }
53
54 HYDROData_Object::HYDROData_Object()
55 {
56 }
57
58 HYDROData_Object::~HYDROData_Object()
59 {
60 }
61
62 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
63 {
64   TDF_CopyLabel aCopy(myLab, theDestination->Label());
65   aCopy.Perform();
66 }
67
68 void HYDROData_Object::SetLabel(TDF_Label theLabel)
69 {
70   myLab = theLabel;
71 }
72
73 void HYDROData_Object::SaveByteArray(const int theTag, 
74   const char* theData, const int theLen)
75 {
76   TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
77   // array is empty, remove the attribute
78   if (theLen <= 0) {
79     aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
80     return;
81   }
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);
86   }
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);
93   } else {
94     for(int a = 0; a < theLen; a++)
95       aData->SetValue(a + 1, theData[a]);
96   }
97 }
98
99 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen)
100 {
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();
106   if (theLen)
107     return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
108   return NULL;
109 }