X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROData%2FHYDROData_Iterator.cxx;h=181bc496e1c6839f0accc7495ce78294d9e44752;hb=e7225e329739e01faed6682de0bc83cf84c28de6;hp=534cbd13c62e6bdb60621dd497bee362a2cc7558;hpb=2728f2367cc657e6a4c900ca221263ee9add26fd;p=modules%2Fhydro.git diff --git a/src/HYDROData/HYDROData_Iterator.cxx b/src/HYDROData/HYDROData_Iterator.cxx index 534cbd13..181bc496 100644 --- a/src/HYDROData/HYDROData_Iterator.cxx +++ b/src/HYDROData/HYDROData_Iterator.cxx @@ -1,8 +1,33 @@ -#include -#include +#include "HYDROData_Iterator.h" + +#include "HYDROData_AltitudeObject.h" +#include "HYDROData_Bathymetry.h" +#include "HYDROData_CalculationCase.h" +#include "HYDROData_Channel.h" +#include "HYDROData_Confluence.h" +#include "HYDROData_DummyObject3D.h" +#include "HYDROData_Digue.h" +#include "HYDROData_ShapesGroup.h" +#include "HYDROData_Image.h" +#include "HYDROData_ImmersibleZone.h" +#include "HYDROData_Obstacle.h" +#include "HYDROData_ObstacleAltitude.h" +#include "HYDROData_Polyline3D.h" +#include "HYDROData_PolylineXY.h" +#include "HYDROData_Profile.h" +#include "HYDROData_ProfileUZ.h" +#include "HYDROData_VisualState.h" +#include "HYDROData_Region.h" +#include "HYDROData_River.h" +#include "HYDROData_SplittedShapesGroup.h" +#include "HYDROData_Stream.h" +#include "HYDROData_StreamAltitude.h" +#include "HYDROData_Zone.h" #include +#include + #include //! Returns label by root objects kind and the kind of the object @@ -12,9 +37,10 @@ static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind) return theRoot.FindChild(theKind); } -HYDROData_Iterator::HYDROData_Iterator(Handle(HYDROData_Document) theDoc, ObjectKind theKind) - : myIter(GetLabelByKind(theDoc->LabelOfObjects(), theKind), - TDataStd_Name::GetID(), theKind == KIND_UNKNOWN) // iterate all sub-objects for unknown kind +HYDROData_Iterator::HYDROData_Iterator( const Handle(HYDROData_Document)& theDoc, + const ObjectKind theKind ) +: myIter( GetLabelByKind( theDoc->LabelOfObjects(), theKind ), + TDataStd_Name::GetID(), theKind == KIND_UNKNOWN ) // iterate all sub-objects for unknown kind { } @@ -22,7 +48,7 @@ void HYDROData_Iterator::Next() { myIter.Next(); // omit the properties iteration in case of UNKNOWN kind filtering - while(myIter.More() && myIter.Value()->Label().Depth() != 4) + while ( myIter.More() && myIter.Value()->Label().Depth() < 4 ) myIter.Next(); } @@ -31,31 +57,86 @@ bool HYDROData_Iterator::More() const return myIter.More(); } -Handle(HYDROData_Object) HYDROData_Iterator::Current() +Handle(HYDROData_Entity) HYDROData_Iterator::Current() { return Object(myIter.Value()->Label()); } -Handle_HYDROData_Object HYDROData_Iterator::CreateObject( - Handle(HYDROData_Document) theDoc, ObjectKind theKind) +Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( + const Handle(HYDROData_Document)& theDoc, + const ObjectKind& theObjectKind ) { - TDF_Label aNewLab = GetLabelByKind(theDoc->LabelOfObjects(), theKind). - FindChild(theDoc->NewID()); - // object exists if there is name attribute - TDataStd_Name::Set(aNewLab, TCollection_ExtendedString("")); - return Object(aNewLab); + TDF_Label aNewLab = + GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() ); + return CreateObject( aNewLab, theObjectKind ); +} + +Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel, + const ObjectKind& theObjectKind ) +{ + // Object exists if there is a name attribute + TDataStd_Name::Set( theNewLabel, "" ); + + // Store the type of object in data label + TDataStd_NamedData::Set( theNewLabel ); + + Handle(TDataStd_NamedData) aNamedData; + theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ); + aNamedData->SetInteger( "ObjectKind", theObjectKind ); + + return Object( theNewLabel ); } -Handle_HYDROData_Object HYDROData_Iterator::Object(const TDF_Label theLabel) +Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel ) { - ObjectKind aKind = theLabel.Father().Tag(); - Handle(HYDROData_Object) aResult; - switch(aKind) { - case KIND_IMAGE: - aResult = new HYDROData_Image(); - break; + Handle(HYDROData_Entity) aResult; + + // If label has no name attribute it mean that this is not object or + // this object has been removed from document + Handle(TDataStd_Name) aNameAtt; + if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) ) + return aResult; + + ObjectKind aKind = KIND_UNKNOWN; + + // Retrieve the type of object from label + Handle(TDataStd_NamedData) aNamedData; + if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) ) + aKind = aNamedData->GetInteger( "ObjectKind" ); + + if ( aKind == KIND_UNKNOWN ) + aKind = theLabel.Father().Tag(); // Try to get type from father label + + switch( aKind ) + { + case KIND_IMAGE: aResult = new HYDROData_Image(); break; + case KIND_POLYLINE: aResult = new HYDROData_Polyline3D(); break; + case KIND_BATHYMETRY: aResult = new HYDROData_Bathymetry(); break; + case KIND_ALTITUDE: aResult = new HYDROData_AltitudeObject(); break; + case KIND_IMMERSIBLE_ZONE: aResult = new HYDROData_ImmersibleZone(); break; + case KIND_RIVER: aResult = new HYDROData_River(); break; + case KIND_STREAM: aResult = new HYDROData_Stream(); break; + case KIND_CONFLUENCE: aResult = new HYDROData_Confluence(); break; + case KIND_CHANNEL: aResult = new HYDROData_Channel(); break; + case KIND_OBSTACLE: aResult = new HYDROData_Obstacle(); break; + case KIND_DIGUE: aResult = new HYDROData_Digue(); break; + case KIND_PROFILE: aResult = new HYDROData_Profile(); break; + case KIND_PROFILEUZ: aResult = new HYDROData_ProfileUZ(); break; + case KIND_POLYLINEXY: aResult = new HYDROData_PolylineXY(); break; + case KIND_CALCULATION: aResult = new HYDROData_CalculationCase(); break; + case KIND_REGION: aResult = new HYDROData_Region(); break; + case KIND_ZONE: aResult = new HYDROData_Zone(); break; + case KIND_VISUAL_STATE: aResult = new HYDROData_VisualState(); break; + case KIND_DUMMY_3D: aResult = new HYDROData_DummyObject3D(); break; + case KIND_SHAPES_GROUP: aResult = new HYDROData_ShapesGroup(); break; + case KIND_SPLITTED_GROUP: aResult = new HYDROData_SplittedShapesGroup(); break; + case KIND_STREAM_ALTITUDE: aResult = new HYDROData_StreamAltitude(); break; + case KIND_OBSTACLE_ALTITUDE: aResult = new HYDROData_ObstacleAltitude(); break; + default: break; } - if (!aResult.IsNull()) - aResult->SetLabel(theLabel); + + if ( !aResult.IsNull() ) + aResult->SetLabel( theLabel ); + return aResult; }