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 Handle(HYDROData_Entity) aResult;
78 // If label has no name attribute it mean that this is not object or
79 // this object has been removed from document
80 Handle(TDataStd_Name) aNameAtt;
81 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
84 ObjectKind aKind = KIND_UNKNOWN;
86 // Retrieve the type of object from label
87 Handle(TDataStd_NamedData) aNamedData;
88 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
89 aKind = aNamedData->GetInteger( "ObjectKind" );
91 if ( aKind == KIND_UNKNOWN )
92 aKind = theLabel.Father().Tag(); // Try to get type from father label
97 aResult = new HYDROData_Image();
100 aResult = new HYDROData_Polyline();
102 case KIND_BATHYMETRY:
103 aResult = new HYDROData_Bathymetry();
105 case KIND_IMMERSIBLE_ZONE:
106 aResult = new HYDROData_ImmersibleZone();
108 case KIND_CALCULATION:
109 aResult = new HYDROData_Calculation();
112 aResult = new HYDROData_Region();
115 aResult = new HYDROData_Zone();
117 case KIND_VISUAL_STATE:
118 aResult = new HYDROData_VisualState();
124 if ( !aResult.IsNull() )
125 aResult->SetLabel( theLabel );