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