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_Image.h"
12 #include "HYDROData_ImmersibleZone.h"
13 #include "HYDROData_Obstacle.h"
14 #include "HYDROData_Polyline3D.h"
15 #include "HYDROData_PolylineXY.h"
16 #include "HYDROData_Profile.h"
17 #include "HYDROData_ProfileUZ.h"
18 #include "HYDROData_VisualState.h"
19 #include "HYDROData_Region.h"
20 #include "HYDROData_River.h"
21 #include "HYDROData_Stream.h"
22 #include "HYDROData_Zone.h"
24 #include <TDataStd_Name.hxx>
25 #include <TDataStd_NamedData.hxx>
27 #include <NCollection_DataMap.hxx>
29 //! Returns label by root objects kind and the kind of the object
30 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
32 if (theKind == KIND_UNKNOWN) return theRoot;
33 return theRoot.FindChild(theKind);
36 HYDROData_Iterator::HYDROData_Iterator( const Handle(HYDROData_Document)& theDoc,
37 const ObjectKind theKind )
38 : myIter( GetLabelByKind( theDoc->LabelOfObjects(), theKind ),
39 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN ) // iterate all sub-objects for unknown kind
43 void HYDROData_Iterator::Next()
46 // omit the properties iteration in case of UNKNOWN kind filtering
47 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
51 bool HYDROData_Iterator::More() const
56 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
58 return Object(myIter.Value()->Label());
61 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
62 const Handle(HYDROData_Document)& theDoc,
63 const ObjectKind& theObjectKind )
66 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
67 return CreateObject( aNewLab, theObjectKind );
70 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
71 const ObjectKind& theObjectKind )
73 // Object exists if there is a name attribute
74 TDataStd_Name::Set( theNewLabel, "" );
76 // Store the type of object in data label
77 TDataStd_NamedData::Set( theNewLabel );
79 Handle(TDataStd_NamedData) aNamedData;
80 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
81 aNamedData->SetInteger( "ObjectKind", theObjectKind );
83 return Object( theNewLabel );
86 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
88 Handle(HYDROData_Entity) aResult;
90 // If label has no name attribute it mean that this is not object or
91 // this object has been removed from document
92 Handle(TDataStd_Name) aNameAtt;
93 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
96 ObjectKind aKind = KIND_UNKNOWN;
98 // Retrieve the type of object from label
99 Handle(TDataStd_NamedData) aNamedData;
100 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
101 aKind = aNamedData->GetInteger( "ObjectKind" );
103 if ( aKind == KIND_UNKNOWN )
104 aKind = theLabel.Father().Tag(); // Try to get type from father label
109 aResult = new HYDROData_Image();
112 aResult = new HYDROData_Polyline3D();
114 case KIND_BATHYMETRY:
115 aResult = new HYDROData_Bathymetry();
118 aResult = new HYDROData_AltitudeObject();
120 case KIND_IMMERSIBLE_ZONE:
121 aResult = new HYDROData_ImmersibleZone();
124 aResult = new HYDROData_River();
127 aResult = new HYDROData_Stream();
129 case KIND_CONFLUENCE:
130 aResult = new HYDROData_Confluence();
133 aResult = new HYDROData_Channel();
136 aResult = new HYDROData_Obstacle();
139 aResult = new HYDROData_Digue();
142 aResult = new HYDROData_Profile();
145 aResult = new HYDROData_ProfileUZ();
147 case KIND_POLYLINEXY:
148 aResult = new HYDROData_PolylineXY();
150 case KIND_CALCULATION:
151 aResult = new HYDROData_CalculationCase();
154 aResult = new HYDROData_Region();
157 aResult = new HYDROData_Zone();
159 case KIND_VISUAL_STATE:
160 aResult = new HYDROData_VisualState();
163 aResult = new HYDROData_DummyObject3D();
169 if ( !aResult.IsNull() )
170 aResult->SetLabel( theLabel );