2 #include "HYDROData_Iterator.h"
4 #include "HYDROData_AltitudeObject.h"
5 #include "HYDROData_Bathymetry.h"
6 #include "HYDROData_Calculation.h"
7 #include "HYDROData_Image.h"
8 #include "HYDROData_ImmersibleZone.h"
9 #include "HYDROData_Polyline.h"
10 #include "HYDROData_VisualState.h"
11 #include "HYDROData_Region.h"
12 #include "HYDROData_Zone.h"
14 #include <TDataStd_Name.hxx>
15 #include <TDataStd_NamedData.hxx>
17 #include <NCollection_DataMap.hxx>
19 //! Returns label by root objects kind and the kind of the object
20 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
22 if (theKind == KIND_UNKNOWN) return theRoot;
23 return theRoot.FindChild(theKind);
26 HYDROData_Iterator::HYDROData_Iterator(Handle(HYDROData_Document) theDoc, ObjectKind theKind)
27 : myIter(GetLabelByKind(theDoc->LabelOfObjects(), theKind),
28 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN) // iterate all sub-objects for unknown kind
32 void HYDROData_Iterator::Next()
35 // omit the properties iteration in case of UNKNOWN kind filtering
36 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
40 bool HYDROData_Iterator::More() const
45 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
47 return Object(myIter.Value()->Label());
50 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
51 const Handle(HYDROData_Document)& theDoc,
52 const ObjectKind& theObjectKind )
55 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
56 return CreateObject( aNewLab, theObjectKind );
59 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
60 const ObjectKind& theObjectKind )
62 // Object exists if there is a name attribute
63 TDataStd_Name::Set( theNewLabel, "" );
65 // Store the type of object in data label
66 TDataStd_NamedData::Set( theNewLabel );
68 Handle(TDataStd_NamedData) aNamedData;
69 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
70 aNamedData->SetInteger( "ObjectKind", theObjectKind );
72 return Object( theNewLabel );
75 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
77 Handle(HYDROData_Entity) aResult;
79 // If label has no name attribute it mean that this is not object or
80 // this object has been removed from document
81 Handle(TDataStd_Name) aNameAtt;
82 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
85 ObjectKind aKind = KIND_UNKNOWN;
87 // Retrieve the type of object from label
88 Handle(TDataStd_NamedData) aNamedData;
89 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
90 aKind = aNamedData->GetInteger( "ObjectKind" );
92 if ( aKind == KIND_UNKNOWN )
93 aKind = theLabel.Father().Tag(); // Try to get type from father label
98 aResult = new HYDROData_Image();
101 aResult = new HYDROData_Polyline();
103 case KIND_BATHYMETRY:
104 aResult = new HYDROData_Bathymetry();
107 aResult = new HYDROData_AltitudeObject();
109 case KIND_IMMERSIBLE_ZONE:
110 aResult = new HYDROData_ImmersibleZone();
112 case KIND_CALCULATION:
113 aResult = new HYDROData_Calculation();
116 aResult = new HYDROData_Region();
119 aResult = new HYDROData_Zone();
121 case KIND_VISUAL_STATE:
122 aResult = new HYDROData_VisualState();
128 if ( !aResult.IsNull() )
129 aResult->SetLabel( theLabel );