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