Salome HOME
Visibility management is improved. Methods SetVisible/IsVisible of HYDROData_Object...
[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 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
12 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
13
14 // is equal function for unique object mapping
15 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
16 {
17   return (theObj1->ID() == theObj2->ID());
18 }
19
20 QString HYDROData_Object::GetName() const
21 {
22   Handle(TDataStd_Name) aName;
23   if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
24     TCollection_AsciiString aStr(aName->Get());
25     return QString(aStr.ToCString());
26   }
27   return QString();
28 }
29
30 void HYDROData_Object::SetName(const QString& theName)
31 {
32   TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
33 }
34
35 bool HYDROData_Object::IsRemoved() const
36 {
37   return !myLab.HasAttribute();
38 }
39
40 void HYDROData_Object::Remove()
41 {
42   return myLab.ForgetAllAttributes(Standard_True);
43 }
44
45 HYDROData_Object::HYDROData_Object()
46 {
47 }
48
49 HYDROData_Object::~HYDROData_Object()
50 {
51 }
52
53 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
54 {
55   TDF_CopyLabel aCopy(myLab, theDestination->Label());
56   aCopy.Perform();
57 }
58
59 void HYDROData_Object::SetLabel(TDF_Label theLabel)
60 {
61   myLab = theLabel;
62 }
63
64 void HYDROData_Object::SaveByteArray(const int theTag, 
65   const char* theData, const int theLen)
66 {
67   TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
68   // array is empty, remove the attribute
69   if (theLen <= 0) {
70     aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
71     return;
72   }
73   // store data of image in byte array
74   Handle(TDataStd_ByteArray) aData;
75   if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
76     aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
77   }
78   // copy bytes one by one
79   if (aData->Length() != theLen) {
80     Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
81     for(int a = 0; a < theLen; a++)
82       aNewData->SetValue(a + 1, theData[a]);
83     aData->ChangeArray(aNewData);
84   } else {
85     for(int a = 0; a < theLen; a++)
86       aData->SetValue(a + 1, theData[a]);
87   }
88 }
89
90 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen)
91 {
92   TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
93   Handle(TDataStd_ByteArray) aData;
94   if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
95     return NULL; // return empty image if there is no array
96   theLen = aData->Length();
97   if (theLen)
98     return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
99   return NULL;
100 }