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_Stream.h"
23 #include "HYDROData_Zone.h"
25 #include <TDataStd_Name.hxx>
26 #include <TDataStd_NamedData.hxx>
28 #include <NCollection_DataMap.hxx>
30 //! Returns label by root objects kind and the kind of the object
31 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
33 if (theKind == KIND_UNKNOWN) return theRoot;
34 return theRoot.FindChild(theKind);
37 HYDROData_Iterator::HYDROData_Iterator( const Handle(HYDROData_Document)& theDoc,
38 const ObjectKind theKind )
39 : myIter( GetLabelByKind( theDoc->LabelOfObjects(), theKind ),
40 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN ) // iterate all sub-objects for unknown kind
44 void HYDROData_Iterator::Next()
47 // omit the properties iteration in case of UNKNOWN kind filtering
48 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
52 bool HYDROData_Iterator::More() const
57 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
59 return Object(myIter.Value()->Label());
62 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
63 const Handle(HYDROData_Document)& theDoc,
64 const ObjectKind& theObjectKind )
67 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
68 return CreateObject( aNewLab, theObjectKind );
71 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
72 const ObjectKind& theObjectKind )
74 // Object exists if there is a name attribute
75 TDataStd_Name::Set( theNewLabel, "" );
77 // Store the type of object in data label
78 TDataStd_NamedData::Set( theNewLabel );
80 Handle(TDataStd_NamedData) aNamedData;
81 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
82 aNamedData->SetInteger( "ObjectKind", theObjectKind );
84 return Object( theNewLabel );
87 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
89 Handle(HYDROData_Entity) aResult;
91 // If label has no name attribute it mean that this is not object or
92 // this object has been removed from document
93 Handle(TDataStd_Name) aNameAtt;
94 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
97 ObjectKind aKind = KIND_UNKNOWN;
99 // Retrieve the type of object from label
100 Handle(TDataStd_NamedData) aNamedData;
101 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
102 aKind = aNamedData->GetInteger( "ObjectKind" );
104 if ( aKind == KIND_UNKNOWN )
105 aKind = theLabel.Father().Tag(); // Try to get type from father label
109 case KIND_IMAGE: aResult = new HYDROData_Image(); break;
110 case KIND_POLYLINE: aResult = new HYDROData_Polyline3D(); break;
111 case KIND_BATHYMETRY: aResult = new HYDROData_Bathymetry(); break;
112 case KIND_ALTITUDE: aResult = new HYDROData_AltitudeObject(); break;
113 case KIND_IMMERSIBLE_ZONE: aResult = new HYDROData_ImmersibleZone(); break;
114 case KIND_RIVER: aResult = new HYDROData_River(); break;
115 case KIND_STREAM: aResult = new HYDROData_Stream(); break;
116 case KIND_CONFLUENCE: aResult = new HYDROData_Confluence(); break;
117 case KIND_CHANNEL: aResult = new HYDROData_Channel(); break;
118 case KIND_OBSTACLE: aResult = new HYDROData_Obstacle(); break;
119 case KIND_DIGUE: aResult = new HYDROData_Digue(); break;
120 case KIND_PROFILE: aResult = new HYDROData_Profile(); break;
121 case KIND_PROFILEUZ: aResult = new HYDROData_ProfileUZ(); break;
122 case KIND_POLYLINEXY: aResult = new HYDROData_PolylineXY(); break;
123 case KIND_CALCULATION: aResult = new HYDROData_CalculationCase(); break;
124 case KIND_REGION: aResult = new HYDROData_Region(); break;
125 case KIND_ZONE: aResult = new HYDROData_Zone(); break;
126 case KIND_VISUAL_STATE: aResult = new HYDROData_VisualState(); break;
127 case KIND_DUMMY_3D: aResult = new HYDROData_DummyObject3D(); break;
128 case KIND_EDGES_GROUP: aResult = new HYDROData_EdgesGroup(); break;
132 if ( !aResult.IsNull() )
133 aResult->SetLabel( theLabel );