1 #include <HYDROData_Object.h>
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>
11 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
12 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
14 // is equal function for unique object mapping
15 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
17 return (theObj1->ID() == theObj2->ID());
20 QString HYDROData_Object::GetName() const
22 Handle(TDataStd_Name) aName;
23 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
24 TCollection_AsciiString aStr(aName->Get());
25 return QString(aStr.ToCString());
30 void HYDROData_Object::SetName(const QString& theName)
32 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
35 bool HYDROData_Object::IsVisible( const int theViewId ) const
37 ViewId2VisualStateMap aMap;
38 GetViewId2VisualStateMap( aMap );
39 if( aMap.find( theViewId ) != aMap.end() )
41 const VisualState& aVisualState = aMap[ theViewId ];
42 return aVisualState.Visibility;
47 void HYDROData_Object::SetVisible( const int theViewId,
53 ViewId2VisualStateMap aMap;
54 GetViewId2VisualStateMap( aMap );
56 VisualState& aVisualState = aMap[ theViewId ];
57 aVisualState.Visibility = theVal;
59 SetViewId2VisualStateMap( aMap );
62 bool HYDROData_Object::IsRemoved() const
64 return !myLab.HasAttribute();
67 void HYDROData_Object::Remove()
69 return myLab.ForgetAllAttributes(Standard_True);
72 HYDROData_Object::HYDROData_Object()
76 HYDROData_Object::~HYDROData_Object()
80 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
82 TDF_CopyLabel aCopy(myLab, theDestination->Label());
86 void HYDROData_Object::SetLabel(TDF_Label theLabel)
91 void HYDROData_Object::SaveByteArray(const int theTag,
92 const char* theData, const int theLen)
94 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
95 // array is empty, remove the attribute
97 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
100 // store data of image in byte array
101 Handle(TDataStd_ByteArray) aData;
102 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
103 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
105 // copy bytes one by one
106 if (aData->Length() != theLen) {
107 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
108 for(int a = 0; a < theLen; a++)
109 aNewData->SetValue(a + 1, theData[a]);
110 aData->ChangeArray(aNewData);
112 for(int a = 0; a < theLen; a++)
113 aData->SetValue(a + 1, theData[a]);
117 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen)
119 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
120 Handle(TDataStd_ByteArray) aData;
121 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
122 return NULL; // return empty image if there is no array
123 theLen = aData->Length();
125 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
129 void HYDROData_Object::GetViewId2VisualStateMap( ViewId2VisualStateMap& theMap ) const
133 TDF_Label aViewIdLab = myLab.FindChild( DataTag_ViewId );
134 TDF_Label aVisibilityLab = myLab.FindChild( DataTag_Visibility );
135 TDF_Label aTransparencyLab = myLab.FindChild( DataTag_Transparency );
136 TDF_Label aZValueLab = myLab.FindChild( DataTag_ZValue );
138 Handle(TDataStd_IntegerArray) aViewIdArray;
139 Handle(TDataStd_BooleanArray) aVisibilityArray;
140 Handle(TDataStd_RealArray) aTransparencyArray;
141 Handle(TDataStd_RealArray) aZValueArray;
143 if( !aViewIdLab.FindAttribute( TDataStd_IntegerArray::GetID(), aViewIdArray ) ||
144 !aVisibilityLab.FindAttribute( TDataStd_BooleanArray::GetID(), aVisibilityArray ) ||
145 !aTransparencyLab.FindAttribute( TDataStd_RealArray::GetID(), aTransparencyArray ) ||
146 !aZValueLab.FindAttribute( TDataStd_RealArray::GetID(), aZValueArray ) )
149 int aSize = qMin( qMin( aViewIdArray->Length(), aVisibilityArray->Length() ),
150 qMin( aTransparencyArray->Length(), aZValueArray->Length() ) );
151 for( int anIndex = 0; anIndex < aSize; anIndex++ )
153 int aViewId = aViewIdArray->Value( anIndex );
154 VisualState aVisualState;
155 aVisualState.Visibility = aVisibilityArray->Value( anIndex );
156 aVisualState.Transparency = aTransparencyArray->Value( anIndex );
157 aVisualState.ZValue = aZValueArray->Value( anIndex );
158 theMap[ aViewId ] = aVisualState;
162 void HYDROData_Object::SetViewId2VisualStateMap( const ViewId2VisualStateMap& theMap )
164 TDF_Label aViewIdLab = myLab.FindChild( DataTag_ViewId );
165 TDF_Label aVisibilityLab = myLab.FindChild( DataTag_Visibility );
166 TDF_Label aTransparencyLab = myLab.FindChild( DataTag_Transparency );
167 TDF_Label aZValueLab = myLab.FindChild( DataTag_ZValue );
169 aViewIdLab.ForgetAllAttributes();
170 aVisibilityLab.ForgetAllAttributes();
171 aTransparencyLab.ForgetAllAttributes();
172 aZValueLab.ForgetAllAttributes();
174 int aSize = theMap.size();
176 Handle(TDataStd_IntegerArray) aViewIdArray =
177 TDataStd_IntegerArray::Set( aViewIdLab, 0, aSize-1 );
178 Handle(TDataStd_BooleanArray) aVisibilityArray =
179 TDataStd_BooleanArray::Set( aVisibilityLab, 0, aSize-1 );
180 Handle(TDataStd_RealArray) aTransparencyArray =
181 TDataStd_RealArray::Set( aTransparencyLab, 0, aSize-1 );
182 Handle(TDataStd_RealArray) aZValueArray =
183 TDataStd_RealArray::Set( aZValueLab, 0, aSize-1 );
186 ViewId2VisualStateMapIterator anIter( theMap );
187 while( anIter.hasNext() )
189 int aViewId = anIter.next().key();
190 const VisualState& aVisualState = anIter.value();
191 aViewIdArray->SetValue( anIndex, aViewId );
192 aVisibilityArray->SetValue( anIndex, aVisualState.Visibility );
193 aTransparencyArray->SetValue( anIndex, aVisualState.Transparency );
194 aZValueArray->SetValue( anIndex, aVisualState.ZValue );