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_Polyline3D.h"
14 #include "HYDROData_PolylineXY.h"
15 #include "HYDROData_Profile.h"
16 #include "HYDROData_ProfileUZ.h"
17 #include "HYDROData_VisualState.h"
18 #include "HYDROData_Region.h"
19 #include "HYDROData_River.h"
20 #include "HYDROData_Stream.h"
21 #include "HYDROData_Zone.h"
23 #include <TDataStd_Name.hxx>
24 #include <TDataStd_NamedData.hxx>
26 #include <NCollection_DataMap.hxx>
28 //! Returns label by root objects kind and the kind of the object
29 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
31 if (theKind == KIND_UNKNOWN) return theRoot;
32 return theRoot.FindChild(theKind);
35 HYDROData_Iterator::HYDROData_Iterator( const Handle(HYDROData_Document)& theDoc,
36 const ObjectKind theKind )
37 : myIter( GetLabelByKind( theDoc->LabelOfObjects(), theKind ),
38 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN ) // iterate all sub-objects for unknown kind
42 void HYDROData_Iterator::Next()
45 // omit the properties iteration in case of UNKNOWN kind filtering
46 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
50 bool HYDROData_Iterator::More() const
55 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
57 return Object(myIter.Value()->Label());
60 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
61 const Handle(HYDROData_Document)& theDoc,
62 const ObjectKind& theObjectKind )
65 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
66 return CreateObject( aNewLab, theObjectKind );
69 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
70 const ObjectKind& theObjectKind )
72 // Object exists if there is a name attribute
73 TDataStd_Name::Set( theNewLabel, "" );
75 // Store the type of object in data label
76 TDataStd_NamedData::Set( theNewLabel );
78 Handle(TDataStd_NamedData) aNamedData;
79 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
80 aNamedData->SetInteger( "ObjectKind", theObjectKind );
82 return Object( theNewLabel );
85 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
87 Handle(HYDROData_Entity) aResult;
89 // If label has no name attribute it mean that this is not object or
90 // this object has been removed from document
91 Handle(TDataStd_Name) aNameAtt;
92 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
95 ObjectKind aKind = KIND_UNKNOWN;
97 // Retrieve the type of object from label
98 Handle(TDataStd_NamedData) aNamedData;
99 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
100 aKind = aNamedData->GetInteger( "ObjectKind" );
102 if ( aKind == KIND_UNKNOWN )
103 aKind = theLabel.Father().Tag(); // Try to get type from father label
108 aResult = new HYDROData_Image();
111 aResult = new HYDROData_Polyline3D();
113 case KIND_BATHYMETRY:
114 aResult = new HYDROData_Bathymetry();
117 aResult = new HYDROData_AltitudeObject();
119 case KIND_IMMERSIBLE_ZONE:
120 aResult = new HYDROData_ImmersibleZone();
123 aResult = new HYDROData_River();
126 aResult = new HYDROData_Stream();
128 case KIND_CONFLUENCE:
129 aResult = new HYDROData_Confluence();
132 aResult = new HYDROData_Channel();
135 aResult = new HYDROData_Obstacle();
138 aResult = new HYDROData_Digue();
141 aResult = new HYDROData_Profile();
144 aResult = new HYDROData_ProfileUZ();
146 case KIND_POLYLINEXY:
147 aResult = new HYDROData_PolylineXY();
149 case KIND_CALCULATION:
150 aResult = new HYDROData_CalculationCase();
153 aResult = new HYDROData_Region();
156 aResult = new HYDROData_Zone();
158 case KIND_VISUAL_STATE:
159 aResult = new HYDROData_VisualState();
165 if ( !aResult.IsNull() )
166 aResult->SetLabel( theLabel );