Salome HOME
Visibility management is improved. Methods SetVisible/IsVisible of HYDROData_Object...
[modules/hydro.git] / src / HYDROData / HYDROData_Object.cxx
index 488b03ef973faf061417d121b977fce416089cfa..23f9038cdd8dbe09584119c54768909e06513413 100644 (file)
@@ -1,6 +1,11 @@
 #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>
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
@@ -55,3 +60,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)
+{
+  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;
+}