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_VisualState.h"
15 #include "HYDROData_Region.h"
16 #include "HYDROData_River.h"
17 #include "HYDROData_Stream.h"
18 #include "HYDROData_Zone.h"
20 #include <TDataStd_Name.hxx>
21 #include <TDataStd_NamedData.hxx>
23 #include <NCollection_DataMap.hxx>
25 //! Returns label by root objects kind and the kind of the object
26 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
28 if (theKind == KIND_UNKNOWN) return theRoot;
29 return theRoot.FindChild(theKind);
32 HYDROData_Iterator::HYDROData_Iterator(Handle(HYDROData_Document) theDoc, ObjectKind theKind)
33 : myIter(GetLabelByKind(theDoc->LabelOfObjects(), theKind),
34 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN) // iterate all sub-objects for unknown kind
38 void HYDROData_Iterator::Next()
41 // omit the properties iteration in case of UNKNOWN kind filtering
42 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
46 bool HYDROData_Iterator::More() const
51 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
53 return Object(myIter.Value()->Label());
56 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
57 const Handle(HYDROData_Document)& theDoc,
58 const ObjectKind& theObjectKind )
61 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
62 return CreateObject( aNewLab, theObjectKind );
65 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
66 const ObjectKind& theObjectKind )
68 // Object exists if there is a name attribute
69 TDataStd_Name::Set( theNewLabel, "" );
71 // Store the type of object in data label
72 TDataStd_NamedData::Set( theNewLabel );
74 Handle(TDataStd_NamedData) aNamedData;
75 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
76 aNamedData->SetInteger( "ObjectKind", theObjectKind );
78 return Object( theNewLabel );
81 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
83 Handle(HYDROData_Entity) aResult;
85 // If label has no name attribute it mean that this is not object or
86 // this object has been removed from document
87 Handle(TDataStd_Name) aNameAtt;
88 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
91 ObjectKind aKind = KIND_UNKNOWN;
93 // Retrieve the type of object from label
94 Handle(TDataStd_NamedData) aNamedData;
95 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
96 aKind = aNamedData->GetInteger( "ObjectKind" );
98 if ( aKind == KIND_UNKNOWN )
99 aKind = theLabel.Father().Tag(); // Try to get type from father label
104 aResult = new HYDROData_Image();
107 aResult = new HYDROData_Polyline();
109 case KIND_BATHYMETRY:
110 aResult = new HYDROData_Bathymetry();
113 aResult = new HYDROData_AltitudeObject();
115 case KIND_IMMERSIBLE_ZONE:
116 aResult = new HYDROData_ImmersibleZone();
119 aResult = new HYDROData_River();
122 aResult = new HYDROData_Stream();
124 case KIND_CONFLUENCE:
125 aResult = new HYDROData_Confluence();
128 aResult = new HYDROData_Channel();
131 aResult = new HYDROData_Obstacle();
134 aResult = new HYDROData_Digue();
136 case KIND_CALCULATION:
137 aResult = new HYDROData_CalculationCase();
140 aResult = new HYDROData_Region();
143 aResult = new HYDROData_Zone();
145 case KIND_VISUAL_STATE:
146 aResult = new HYDROData_VisualState();
152 if ( !aResult.IsNull() )
153 aResult->SetLabel( theLabel );