2 #include "HYDROData_Iterator.h"
4 #include "HYDROData_AltitudeObject.h"
5 #include "HYDROData_Bathymetry.h"
6 #include "HYDROData_CalculationCase.h"
7 #include "HYDROData_Channel.h"
8 #include "HYDROData_Confluence.h"
9 #include "HYDROData_DummyObject3D.h"
10 #include "HYDROData_Digue.h"
11 #include "HYDROData_EdgesGroup.h"
12 #include "HYDROData_Image.h"
13 #include "HYDROData_ImmersibleZone.h"
14 #include "HYDROData_Obstacle.h"
15 #include "HYDROData_Polyline3D.h"
16 #include "HYDROData_PolylineXY.h"
17 #include "HYDROData_Profile.h"
18 #include "HYDROData_ProfileUZ.h"
19 #include "HYDROData_VisualState.h"
20 #include "HYDROData_Region.h"
21 #include "HYDROData_River.h"
22 #include "HYDROData_SplittedEdgesGroup.h"
23 #include "HYDROData_Stream.h"
24 #include "HYDROData_Zone.h"
26 #include <TDataStd_Name.hxx>
27 #include <TDataStd_NamedData.hxx>
29 #include <NCollection_DataMap.hxx>
31 //! Returns label by root objects kind and the kind of the object
32 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
34 if (theKind == KIND_UNKNOWN) return theRoot;
35 return theRoot.FindChild(theKind);
38 HYDROData_Iterator::HYDROData_Iterator( const Handle(HYDROData_Document)& theDoc,
39 const ObjectKind theKind )
40 : myIter( GetLabelByKind( theDoc->LabelOfObjects(), theKind ),
41 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN ) // iterate all sub-objects for unknown kind
45 void HYDROData_Iterator::Next()
48 // omit the properties iteration in case of UNKNOWN kind filtering
49 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
53 bool HYDROData_Iterator::More() const
58 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
60 return Object(myIter.Value()->Label());
63 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
64 const Handle(HYDROData_Document)& theDoc,
65 const ObjectKind& theObjectKind )
68 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
69 return CreateObject( aNewLab, theObjectKind );
72 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
73 const ObjectKind& theObjectKind )
75 // Object exists if there is a name attribute
76 TDataStd_Name::Set( theNewLabel, "" );
78 // Store the type of object in data label
79 TDataStd_NamedData::Set( theNewLabel );
81 Handle(TDataStd_NamedData) aNamedData;
82 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
83 aNamedData->SetInteger( "ObjectKind", theObjectKind );
85 return Object( theNewLabel );
88 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
90 Handle(HYDROData_Entity) aResult;
92 // If label has no name attribute it mean that this is not object or
93 // this object has been removed from document
94 Handle(TDataStd_Name) aNameAtt;
95 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
98 ObjectKind aKind = KIND_UNKNOWN;
100 // Retrieve the type of object from label
101 Handle(TDataStd_NamedData) aNamedData;
102 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
103 aKind = aNamedData->GetInteger( "ObjectKind" );
105 if ( aKind == KIND_UNKNOWN )
106 aKind = theLabel.Father().Tag(); // Try to get type from father label
110 case KIND_IMAGE: aResult = new HYDROData_Image(); break;
111 case KIND_POLYLINE: aResult = new HYDROData_Polyline3D(); break;
112 case KIND_BATHYMETRY: aResult = new HYDROData_Bathymetry(); break;
113 case KIND_ALTITUDE: aResult = new HYDROData_AltitudeObject(); break;
114 case KIND_IMMERSIBLE_ZONE: aResult = new HYDROData_ImmersibleZone(); break;
115 case KIND_RIVER: aResult = new HYDROData_River(); break;
116 case KIND_STREAM: aResult = new HYDROData_Stream(); break;
117 case KIND_CONFLUENCE: aResult = new HYDROData_Confluence(); break;
118 case KIND_CHANNEL: aResult = new HYDROData_Channel(); break;
119 case KIND_OBSTACLE: aResult = new HYDROData_Obstacle(); break;
120 case KIND_DIGUE: aResult = new HYDROData_Digue(); break;
121 case KIND_PROFILE: aResult = new HYDROData_Profile(); break;
122 case KIND_PROFILEUZ: aResult = new HYDROData_ProfileUZ(); break;
123 case KIND_POLYLINEXY: aResult = new HYDROData_PolylineXY(); break;
124 case KIND_CALCULATION: aResult = new HYDROData_CalculationCase(); break;
125 case KIND_REGION: aResult = new HYDROData_Region(); break;
126 case KIND_ZONE: aResult = new HYDROData_Zone(); break;
127 case KIND_VISUAL_STATE: aResult = new HYDROData_VisualState(); break;
128 case KIND_DUMMY_3D: aResult = new HYDROData_DummyObject3D(); break;
129 case KIND_EDGES_GROUP: aResult = new HYDROData_EdgesGroup(); break;
130 case KIND_SPLITTED_GROUP: aResult = new HYDROData_SplittedEdgesGroup();break;
134 if ( !aResult.IsNull() )
135 aResult->SetLabel( theLabel );