#include <HYDROData_Object.h>
#include <TDataStd_Name.hxx>
+#include <TDataStd_ByteArray.hxx>
#include <TDF_CopyLabel.hxx>
IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
{
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;
+}