Salome HOME
2a3d2a778723a4f06acd3517e852cdd762a2c1a4
[modules/hydro.git] / src / HYDROData / HYDROData_Iterator.cxx
1 #include <HYDROData_Iterator.h>
2
3 #include <HYDROData_Image.h>
4 #include <HYDROData_Polyline.h>
5 #include <HYDROData_VisualState.h>
6 #include <HYDROData_Bathymetry.h>
7 #include <HYDROData_Calculation.h>
8
9 #include <TDataStd_Name.hxx>
10 #include <NCollection_DataMap.hxx>
11
12 //! Returns label by root objects kind and the kind of the object
13 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
14 {
15   if (theKind == KIND_UNKNOWN) return theRoot;
16   return theRoot.FindChild(theKind);
17 }
18
19 HYDROData_Iterator::HYDROData_Iterator(Handle(HYDROData_Document) theDoc, ObjectKind theKind)
20   : myIter(GetLabelByKind(theDoc->LabelOfObjects(), theKind), 
21            TDataStd_Name::GetID(), theKind == KIND_UNKNOWN) // iterate all sub-objects for unknown kind
22 {
23 }
24
25 void HYDROData_Iterator::Next()
26 {
27   myIter.Next();
28   // omit the properties iteration in case of UNKNOWN kind filtering
29   while(myIter.More() && myIter.Value()->Label().Depth() != 4) 
30     myIter.Next();
31 }
32
33 bool HYDROData_Iterator::More() const
34 {
35   return myIter.More();
36 }
37
38 Handle(HYDROData_Object) HYDROData_Iterator::Current()
39 {
40   return Object(myIter.Value()->Label());
41 }
42
43 Handle_HYDROData_Object HYDROData_Iterator::CreateObject(
44   Handle(HYDROData_Document) theDoc, ObjectKind theKind)
45 {
46   TDF_Label aNewLab = GetLabelByKind(theDoc->LabelOfObjects(), theKind).
47     FindChild(theDoc->NewID());
48   // object exists if there is name attribute
49   TDataStd_Name::Set(aNewLab, TCollection_ExtendedString(""));
50   return Object(aNewLab);
51 }
52
53 Handle_HYDROData_Object HYDROData_Iterator::Object( const TDF_Label theLabel )
54 {
55   ObjectKind aKind = theLabel.Father().Tag();
56   
57   Handle(HYDROData_Object) aResult;
58   switch( aKind )
59   {
60   case KIND_IMAGE:
61     aResult = new HYDROData_Image();
62     break;
63   case KIND_POLYLINE:
64     aResult = new HYDROData_Polyline();
65     break;
66   case KIND_VISUAL_STATE:
67     aResult = new HYDROData_VisualState();
68     break;
69   case KIND_BATHYMETRY:
70     aResult = new HYDROData_Bathymetry();
71     break;
72   case KIND_CALCULATION:
73     aResult = new HYDROData_Calculation();
74     break;
75   }
76
77   if ( !aResult.IsNull() )
78     aResult->SetLabel( theLabel );
79
80   return aResult;
81 }