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