2 #include "HYDROData_Iterator.h"
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_Calculation.h"
6 #include "HYDROData_Image.h"
7 #include "HYDROData_ImmersibleZone.h"
8 #include "HYDROData_Polyline.h"
9 #include "HYDROData_VisualState.h"
10 #include "HYDROData_Region.h"
11 #include "HYDROData_Zone.h"
13 #include <TDataStd_Name.hxx>
14 #include <TDataStd_NamedData.hxx>
16 #include <NCollection_DataMap.hxx>
18 //! Returns label by root objects kind and the kind of the object
19 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
21 if (theKind == KIND_UNKNOWN) return theRoot;
22 return theRoot.FindChild(theKind);
25 HYDROData_Iterator::HYDROData_Iterator(Handle(HYDROData_Document) theDoc, ObjectKind theKind)
26 : myIter(GetLabelByKind(theDoc->LabelOfObjects(), theKind),
27 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN) // iterate all sub-objects for unknown kind
31 void HYDROData_Iterator::Next()
34 // omit the properties iteration in case of UNKNOWN kind filtering
35 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
39 bool HYDROData_Iterator::More() const
44 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
46 return Object(myIter.Value()->Label());
49 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
50 const Handle(HYDROData_Document)& theDoc,
51 const ObjectKind& theObjectKind )
54 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
55 return CreateObject( aNewLab, theObjectKind );
58 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
59 const ObjectKind& theObjectKind )
61 // Object exists if there is a name attribute
62 TDataStd_Name::Set( theNewLabel, "" );
64 // Store the type of object in data label
65 TDataStd_NamedData::Set( theNewLabel );
67 Handle(TDataStd_NamedData) aNamedData;
68 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
69 aNamedData->SetInteger( "ObjectKind", theObjectKind );
71 return Object( theNewLabel );
74 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label theLabel )
76 ObjectKind aKind = KIND_UNKNOWN;
78 // Retrieve the type of object from label
79 Handle(TDataStd_NamedData) aNamedData;
80 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
81 aKind = aNamedData->GetInteger( "ObjectKind" );
83 if ( aKind == KIND_UNKNOWN )
84 aKind = theLabel.Father().Tag(); // Try to get type from father label
86 Handle(HYDROData_Entity) aResult;
90 aResult = new HYDROData_Image();
93 aResult = new HYDROData_Polyline();
96 aResult = new HYDROData_Bathymetry();
98 case KIND_IMMERSIBLE_ZONE:
99 aResult = new HYDROData_ImmersibleZone();
101 case KIND_CALCULATION:
102 aResult = new HYDROData_Calculation();
105 aResult = new HYDROData_Region();
108 aResult = new HYDROData_Zone();
110 case KIND_VISUAL_STATE:
111 aResult = new HYDROData_VisualState();
117 if ( !aResult.IsNull() )
118 aResult->SetLabel( theLabel );