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