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