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