2 #include "HYDROData_Object.h"
4 #include "HYDROData_Iterator.h"
6 #include <TDataStd_Name.hxx>
7 #include <TDataStd_ByteArray.hxx>
8 #include <TDataStd_UAttribute.hxx>
9 #include <TDataStd_IntegerArray.hxx>
10 #include <TDataStd_BooleanArray.hxx>
11 #include <TDataStd_RealArray.hxx>
12 #include <TDataStd_ReferenceList.hxx>
14 #include <TDF_CopyLabel.hxx>
15 #include <TDF_ListIteratorOfLabelList.hxx>
19 #include <QStringList>
22 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
23 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
25 // is equal function for unique object mapping
26 bool IsEqual(const Handle_HYDROData_Object& theObj1, const Handle_HYDROData_Object& theObj2)
28 return (theObj1->ID() == theObj2->ID());
31 QString HYDROData_Object::GetName() const
33 Handle(TDataStd_Name) aName;
34 if (myLab.FindAttribute(TDataStd_Name::GetID(), aName)) {
35 TCollection_AsciiString aStr(aName->Get());
36 return QString(aStr.ToCString());
41 void HYDROData_Object::SetName(const QString& theName)
43 TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
46 QStringList HYDROData_Object::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
48 QStringList anEmptyList;
52 void HYDROData_Object::Update( const bool theIsForce )
56 QVariant HYDROData_Object::GetDataVariant()
61 bool HYDROData_Object::IsRemoved() const
63 return !myLab.HasAttribute();
66 void HYDROData_Object::Remove()
68 return myLab.ForgetAllAttributes(Standard_True);
71 HYDROData_Object::HYDROData_Object()
75 HYDROData_Object::~HYDROData_Object()
79 void HYDROData_Object::CopyTo(Handle_HYDROData_Object theDestination) const
81 TDF_CopyLabel aCopy(myLab, theDestination->Label());
85 void HYDROData_Object::SetLabel(TDF_Label theLabel)
90 void HYDROData_Object::SaveByteArray(const int theTag,
91 const char* theData, const int theLen)
93 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
94 // array is empty, remove the attribute
96 aLab.ForgetAttribute(TDataStd_ByteArray::GetID());
99 // store data of image in byte array
100 Handle(TDataStd_ByteArray) aData;
101 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData)) {
102 aData = TDataStd_ByteArray::Set(aLab, 1, theLen);
104 // copy bytes one by one
105 if (aData->Length() != theLen) {
106 Handle(TColStd_HArray1OfByte) aNewData = new TColStd_HArray1OfByte(1, theLen);
107 for(int a = 0; a < theLen; a++)
108 aNewData->SetValue(a + 1, theData[a]);
109 aData->ChangeArray(aNewData);
111 for(int a = 0; a < theLen; a++)
112 aData->SetValue(a + 1, theData[a]);
116 const char* HYDROData_Object::ByteArray(const int theTag, int& theLen) const
118 TDF_Label aLab = theTag == 0 ? myLab : myLab.FindChild(theTag);
119 Handle(TDataStd_ByteArray) aData;
120 if (!aLab.FindAttribute(TDataStd_ByteArray::GetID(), aData))
121 return NULL; // return empty image if there is no array
122 theLen = aData->Length();
124 return (const char*)(&(aData->InternalArray()->ChangeArray1().ChangeValue(1)));
128 int HYDROData_Object::NbReferenceObjects( const int theTag ) const
130 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
131 return aRefs.IsNull() ? 0 : aRefs->Extent();
134 void HYDROData_Object::AddReferenceObject( const Handle_HYDROData_Object& theObj,
137 if ( theObj.IsNull() )
140 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
141 aRefs->Append( theObj->Label() );
144 void HYDROData_Object::SetReferenceObject( const Handle_HYDROData_Object& theObj,
148 if ( theObj.IsNull() )
150 RemoveReferenceObject( theTag, theIndex );
154 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, true );
156 if ( theIndex >= aRefs->Extent() )
158 aRefs->Append( theObj->Label() );
160 else if ( theIndex < 0 )
162 aRefs->Prepend( theObj->Label() );
166 RemoveReferenceObject( theTag, theIndex );
168 Handle(HYDROData_Object) aBeforeObj = GetReferenceObject( theTag, theIndex );
170 aRefs = getReferenceList( theTag, true ); // because reference list can be removed
171 if ( !aBeforeObj.IsNull() )
172 aRefs->InsertBefore( theObj->Label(), aBeforeObj->Label() );
174 aRefs->Append( theObj->Label() );
178 Handle(HYDROData_Object) HYDROData_Object::GetReferenceObject( const int theTag,
179 const int theIndex ) const
181 Handle(HYDROData_Object) aRes;
183 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
184 if ( aRefs.IsNull() || theIndex < 0 || theIndex >= aRefs->Extent() )
187 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
188 for ( int anIndex = 0; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
190 const TDF_Label& aRefLabel = anIter.Value();
191 aRes = HYDROData_Iterator::Object( aRefLabel );
196 HYDROData_SequenceOfObjects HYDROData_Object::GetReferenceObjects( const int theTag ) const
198 HYDROData_SequenceOfObjects aRes;
200 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
201 if ( aRefs.IsNull() )
204 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
205 for ( ; anIter.More(); anIter.Next() )
207 const TDF_Label& aRefLabel = anIter.Value();
209 Handle(HYDROData_Object) aRefObject = HYDROData_Iterator::Object( aRefLabel );
210 if ( aRefObject.IsNull() )
213 aRes.Append( aRefObject );
219 void HYDROData_Object::RemoveReferenceObject( const int theTag,
222 Handle(TDataStd_ReferenceList) aRefs = getReferenceList( theTag, false );
223 if ( aRefs.IsNull() )
226 if ( aRefs->Extent() == 1 && theIndex == 0 )
228 // remove all if only one
229 ClearReferenceObjects( theTag );
234 TDF_ListIteratorOfLabelList anIter( aRefs->List() );
235 for ( ; anIndex != theIndex && anIter.More(); anIter.Next(), ++anIndex );
237 if ( anIndex != theIndex )
240 const TDF_Label& aRefLabel = anIter.Value();
241 aRefs->Remove( aRefLabel );
244 void HYDROData_Object::ClearReferenceObjects( const int theTag )
246 TDF_Label aSetLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
247 aSetLabel.ForgetAttribute( TDataStd_ReferenceList::GetID() );
250 Handle(TDataStd_ReferenceList) HYDROData_Object::getReferenceList( const int theTag,
251 const bool theIsCreate ) const
253 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
255 Handle(TDataStd_ReferenceList) aRefs;
256 if ( !aLabel.FindAttribute( TDataStd_ReferenceList::GetID(), aRefs ) && theIsCreate )
257 aRefs = TDataStd_ReferenceList::Set( aLabel );
262 void HYDROData_Object::SetColor( const QColor& theColor,
265 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
267 Handle(TDataStd_IntegerArray) aColorArray;
268 if ( !aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
269 aColorArray = TDataStd_IntegerArray::Set( aLabel, 1, 4 );
271 aColorArray->SetValue( 1, theColor.red() );
272 aColorArray->SetValue( 2, theColor.green() );
273 aColorArray->SetValue( 3, theColor.blue() );
274 aColorArray->SetValue( 4, theColor.alpha() );
277 QColor HYDROData_Object::GetColor( const QColor& theDefColor,
278 const int theTag ) const
280 QColor aResColor = theDefColor;
282 TDF_Label aLabel = theTag == 0 ? myLab : myLab.FindChild( theTag );
284 Handle(TDataStd_IntegerArray) aColorArray;
285 if ( aLabel.FindAttribute( TDataStd_IntegerArray::GetID(), aColorArray ) )
287 aResColor.setRed( aColorArray->Value( 1 ) );
288 aResColor.setGreen( aColorArray->Value( 2 ) );
289 aResColor.setBlue( aColorArray->Value( 3 ) );
290 aResColor.setAlpha( aColorArray->Value( 4 ) );