Salome HOME
The "MustBeUpdated" flag is moved to base data object class and implemented for calcu...
[modules/hydro.git] / src / HYDROData / HYDROData_Iterator.cxx
1
2 #include "HYDROData_Iterator.h"
3
4 #include "HYDROData_AltitudeObject.h"
5 #include "HYDROData_Bathymetry.h"
6 #include "HYDROData_CalculationCase.h"
7 #include "HYDROData_Channel.h"
8 #include "HYDROData_Confluence.h"
9 #include "HYDROData_Digue.h"
10 #include "HYDROData_Image.h"
11 #include "HYDROData_ImmersibleZone.h"
12 #include "HYDROData_Obstacle.h"
13 #include "HYDROData_Polyline.h"
14 #include "HYDROData_VisualState.h"
15 #include "HYDROData_Region.h"
16 #include "HYDROData_River.h"
17 #include "HYDROData_Stream.h"
18 #include "HYDROData_Zone.h"
19
20 #include <TDataStd_Name.hxx>
21 #include <TDataStd_NamedData.hxx>
22
23 #include <NCollection_DataMap.hxx>
24
25 //! Returns label by root objects kind and the kind of the object
26 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
27 {
28   if (theKind == KIND_UNKNOWN) return theRoot;
29   return theRoot.FindChild(theKind);
30 }
31
32 HYDROData_Iterator::HYDROData_Iterator(Handle(HYDROData_Document) theDoc, ObjectKind theKind)
33   : myIter(GetLabelByKind(theDoc->LabelOfObjects(), theKind), 
34            TDataStd_Name::GetID(), theKind == KIND_UNKNOWN) // iterate all sub-objects for unknown kind
35 {
36 }
37
38 void HYDROData_Iterator::Next()
39 {
40   myIter.Next();
41   // omit the properties iteration in case of UNKNOWN kind filtering
42   while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
43     myIter.Next();
44 }
45
46 bool HYDROData_Iterator::More() const
47 {
48   return myIter.More();
49 }
50
51 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
52 {
53   return Object(myIter.Value()->Label());
54 }
55
56 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
57   const Handle(HYDROData_Document)& theDoc,
58   const ObjectKind&                 theObjectKind )
59 {
60   TDF_Label aNewLab = 
61     GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
62   return CreateObject( aNewLab, theObjectKind );
63 }
64
65 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label&        theNewLabel, 
66                                                            const ObjectKind& theObjectKind )
67 {
68   // Object exists if there is a name attribute
69   TDataStd_Name::Set( theNewLabel, "" );
70
71   // Store the type of object in data label
72   TDataStd_NamedData::Set( theNewLabel );
73
74   Handle(TDataStd_NamedData) aNamedData;
75   theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
76   aNamedData->SetInteger( "ObjectKind", theObjectKind );
77
78   return Object( theNewLabel );
79 }
80
81 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
82 {
83   Handle(HYDROData_Entity) aResult;
84
85   // If label has no name attribute it mean that this is not object or
86   // this object has been removed from document
87   Handle(TDataStd_Name) aNameAtt;
88   if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
89     return aResult;
90
91   ObjectKind aKind = KIND_UNKNOWN;
92
93   // Retrieve the type of object from label
94   Handle(TDataStd_NamedData) aNamedData;
95   if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
96     aKind = aNamedData->GetInteger( "ObjectKind" );
97
98   if ( aKind == KIND_UNKNOWN )
99     aKind = theLabel.Father().Tag(); // Try to get type from father label
100   
101   switch( aKind )
102   {
103     case KIND_IMAGE:
104       aResult = new HYDROData_Image();
105       break;
106     case KIND_POLYLINE:
107       aResult = new HYDROData_Polyline();
108       break;
109     case KIND_BATHYMETRY:
110       aResult = new HYDROData_Bathymetry();
111       break;
112     case KIND_ALTITUDE:
113       aResult = new HYDROData_AltitudeObject();
114       break;
115     case KIND_IMMERSIBLE_ZONE:
116       aResult = new HYDROData_ImmersibleZone();
117       break;
118     case KIND_RIVER:
119       aResult = new HYDROData_River();
120       break;
121     case KIND_STREAM:
122       aResult = new HYDROData_Stream();
123       break;
124     case KIND_CONFLUENCE:
125       aResult = new HYDROData_Confluence();
126       break;
127     case KIND_CHANNEL:
128       aResult = new HYDROData_Channel();
129       break;
130     case KIND_OBSTACLE:
131       aResult = new HYDROData_Obstacle();
132       break;
133     case KIND_DIGUE:
134       aResult = new HYDROData_Digue();
135       break;
136     case KIND_CALCULATION:
137       aResult = new HYDROData_CalculationCase();
138       break;
139     case KIND_REGION:
140       aResult = new HYDROData_Region();
141       break;
142     case KIND_ZONE:
143       aResult = new HYDROData_Zone();
144       break;
145     case KIND_VISUAL_STATE:
146       aResult = new HYDROData_VisualState();
147       break;
148     default:
149       break;
150   }
151
152   if ( !aResult.IsNull() )
153     aResult->SetLabel( theLabel );
154
155   return aResult;
156 }