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_Digue.h"
10 #include "HYDROData_Image.h"
11 #include "HYDROData_ImmersibleZone.h"
12 #include "HYDROData_Obstacle.h"
13 #include "HYDROData_PolylineXY.h"
14 #include "HYDROData_Profile.h"
15 #include "HYDROData_ProfileUZ.h"
16 #include "HYDROData_VisualState.h"
17 #include "HYDROData_Region.h"
18 #include "HYDROData_River.h"
19 #include "HYDROData_Stream.h"
20 #include "HYDROData_Zone.h"
22 #include <TDataStd_Name.hxx>
23 #include <TDataStd_NamedData.hxx>
25 #include <NCollection_DataMap.hxx>
27 //! Returns label by root objects kind and the kind of the object
28 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
30 if (theKind == KIND_UNKNOWN) return theRoot;
31 return theRoot.FindChild(theKind);
34 HYDROData_Iterator::HYDROData_Iterator( const Handle(HYDROData_Document)& theDoc,
35 const ObjectKind theKind )
36 : myIter( GetLabelByKind( theDoc->LabelOfObjects(), theKind ),
37 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN ) // iterate all sub-objects for unknown kind
41 void HYDROData_Iterator::Next()
44 // omit the properties iteration in case of UNKNOWN kind filtering
45 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
49 bool HYDROData_Iterator::More() const
54 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
56 return Object(myIter.Value()->Label());
59 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
60 const Handle(HYDROData_Document)& theDoc,
61 const ObjectKind& theObjectKind )
64 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
65 return CreateObject( aNewLab, theObjectKind );
68 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
69 const ObjectKind& theObjectKind )
71 // Object exists if there is a name attribute
72 TDataStd_Name::Set( theNewLabel, "" );
74 // Store the type of object in data label
75 TDataStd_NamedData::Set( theNewLabel );
77 Handle(TDataStd_NamedData) aNamedData;
78 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
79 aNamedData->SetInteger( "ObjectKind", theObjectKind );
81 return Object( theNewLabel );
84 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
86 Handle(HYDROData_Entity) aResult;
88 // If label has no name attribute it mean that this is not object or
89 // this object has been removed from document
90 Handle(TDataStd_Name) aNameAtt;
91 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
94 ObjectKind aKind = KIND_UNKNOWN;
96 // Retrieve the type of object from label
97 Handle(TDataStd_NamedData) aNamedData;
98 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
99 aKind = aNamedData->GetInteger( "ObjectKind" );
101 if ( aKind == KIND_UNKNOWN )
102 aKind = theLabel.Father().Tag(); // Try to get type from father label
107 aResult = new HYDROData_Image();
109 //case KIND_POLYLINE:
110 //aResult = new HYDROData_Polyline();
112 case KIND_BATHYMETRY:
113 aResult = new HYDROData_Bathymetry();
116 aResult = new HYDROData_AltitudeObject();
118 case KIND_IMMERSIBLE_ZONE:
119 aResult = new HYDROData_ImmersibleZone();
122 aResult = new HYDROData_River();
125 aResult = new HYDROData_Stream();
127 case KIND_CONFLUENCE:
128 aResult = new HYDROData_Confluence();
131 aResult = new HYDROData_Channel();
134 aResult = new HYDROData_Obstacle();
137 aResult = new HYDROData_Digue();
140 aResult = new HYDROData_Profile();
143 aResult = new HYDROData_ProfileUZ();
145 case KIND_POLYLINEXY:
146 aResult = new HYDROData_PolylineXY();
148 case KIND_CALCULATION:
149 aResult = new HYDROData_CalculationCase();
152 aResult = new HYDROData_Region();
155 aResult = new HYDROData_Zone();
157 case KIND_VISUAL_STATE:
158 aResult = new HYDROData_VisualState();
164 if ( !aResult.IsNull() )
165 aResult->SetLabel( theLabel );