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