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_Polyline.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(Handle(HYDROData_Document) theDoc, ObjectKind theKind)
35 : myIter(GetLabelByKind(theDoc->LabelOfObjects(), theKind),
36 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN) // iterate all sub-objects for unknown kind
40 void HYDROData_Iterator::Next()
43 // omit the properties iteration in case of UNKNOWN kind filtering
44 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
48 bool HYDROData_Iterator::More() const
53 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
55 return Object(myIter.Value()->Label());
58 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
59 const Handle(HYDROData_Document)& theDoc,
60 const ObjectKind& theObjectKind )
63 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
64 return CreateObject( aNewLab, theObjectKind );
67 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
68 const ObjectKind& theObjectKind )
70 // Object exists if there is a name attribute
71 TDataStd_Name::Set( theNewLabel, "" );
73 // Store the type of object in data label
74 TDataStd_NamedData::Set( theNewLabel );
76 Handle(TDataStd_NamedData) aNamedData;
77 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
78 aNamedData->SetInteger( "ObjectKind", theObjectKind );
80 return Object( theNewLabel );
83 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
85 Handle(HYDROData_Entity) aResult;
87 // If label has no name attribute it mean that this is not object or
88 // this object has been removed from document
89 Handle(TDataStd_Name) aNameAtt;
90 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
93 ObjectKind aKind = KIND_UNKNOWN;
95 // Retrieve the type of object from label
96 Handle(TDataStd_NamedData) aNamedData;
97 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
98 aKind = aNamedData->GetInteger( "ObjectKind" );
100 if ( aKind == KIND_UNKNOWN )
101 aKind = theLabel.Father().Tag(); // Try to get type from father label
106 aResult = new HYDROData_Image();
109 aResult = new HYDROData_Polyline();
111 case KIND_BATHYMETRY:
112 aResult = new HYDROData_Bathymetry();
115 aResult = new HYDROData_AltitudeObject();
117 case KIND_IMMERSIBLE_ZONE:
118 aResult = new HYDROData_ImmersibleZone();
121 aResult = new HYDROData_River();
124 aResult = new HYDROData_Stream();
126 case KIND_CONFLUENCE:
127 aResult = new HYDROData_Confluence();
130 aResult = new HYDROData_Channel();
133 aResult = new HYDROData_Obstacle();
136 aResult = new HYDROData_Digue();
139 aResult = new HYDROData_Profile();
142 aResult = new HYDROData_ProfileUZ();
144 case KIND_CALCULATION:
145 aResult = new HYDROData_CalculationCase();
148 aResult = new HYDROData_Region();
151 aResult = new HYDROData_Zone();
153 case KIND_VISUAL_STATE:
154 aResult = new HYDROData_VisualState();
160 if ( !aResult.IsNull() )
161 aResult->SetLabel( theLabel );