Salome HOME
Dump Image data to python script (Feature #13).
[modules/hydro.git] / src / HYDROData / HYDROData_Object.cxx
index 488b03ef973faf061417d121b977fce416089cfa..1b6337a0a0d5c410b915fb1aab016409ba24c66f 100644 (file)
@@ -1,8 +1,16 @@
 #include <HYDROData_Object.h>
 
 #include <TDataStd_Name.hxx>
+#include <TDataStd_ByteArray.hxx>
+#include <TDataStd_UAttribute.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <TDataStd_BooleanArray.hxx>
+#include <TDataStd_RealArray.hxx>
 #include <TDF_CopyLabel.hxx>
 
+#include <QString>
+#include <QStringList>
+
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
 
@@ -27,6 +35,12 @@ void HYDROData_Object::SetName(const QString& theName)
   TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
 }
 
+QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+  QStringList anEmptyList;
+  return anEmptyList;
+}
+
 bool HYDROData_Object::IsRemoved() const
 {
   return !myLab.HasAttribute();
@@ -55,3 +69,41 @@ void HYDROData_Object::SetLabel(TDF_Label theLabel)
 {
   myLab = theLabel;
 }
+
+void HYDROData_Object::SaveByteArray(const int theTag, 
+  const char* theData, const int theLen)
+{
+  TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
+  // array is empty, remove the attribute
+  if (theLen <= 0) {
+    aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
+    return;
+  }
+  // store data of image in byte array
+  Handle(TDataStd_ByteArray) aData;
+  if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
+    aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
+  }
+  // copy bytes one by one
+  if (aData->Length() != theLen) {
+    Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
+    for(int a = 0; a < theLen; a++)
+      aNewData->SetValue(a + 1, theData[a]);
+    aData->ChangeArray(aNewData);
+  } else {
+    for(int a = 0; a < theLen; a++)
+      aData->SetValue(a + 1, theData[a]);
+  }
+}
+
+const char* HYDROData_Object::ByteArray(const int theTag, int& theLen) const
+{
+  TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
+  Handle(TDataStd_ByteArray) aData;
+  if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
+    return NULL; // return empty image if there is no array
+  theLen = aData->Length();
+  if (theLen)
+    return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
+  return NULL;
+}