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