1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_Iterator.h"
25 #include "HYDROData_AltitudeObject.h"
26 #include "HYDROData_Bathymetry.h"
27 #include "HYDROData_CalculationCase.h"
28 #include "HYDROData_Channel.h"
29 #include "HYDROData_Confluence.h"
30 #include "HYDROData_DummyObject3D.h"
31 #include "HYDROData_Digue.h"
32 #include "HYDROData_ShapesGroup.h"
33 #include "HYDROData_Image.h"
34 #include "HYDROData_ImmersibleZone.h"
35 #include "HYDROData_Obstacle.h"
36 #include "HYDROData_ObstacleAltitude.h"
37 #include "HYDROData_Polyline3D.h"
38 #include "HYDROData_PolylineXY.h"
39 #include "HYDROData_Profile.h"
40 #include "HYDROData_ProfileUZ.h"
41 #include "HYDROData_VisualState.h"
42 #include "HYDROData_Region.h"
43 #include "HYDROData_River.h"
44 #include "HYDROData_SplittedShapesGroup.h"
45 #include "HYDROData_Stream.h"
46 #include "HYDROData_StreamAltitude.h"
47 #include "HYDROData_Zone.h"
49 #include <TDataStd_Name.hxx>
50 #include <TDataStd_NamedData.hxx>
52 #include <NCollection_DataMap.hxx>
54 //! Returns label by root objects kind and the kind of the object
55 static TDF_Label GetLabelByKind(TDF_Label theRoot, ObjectKind theKind)
57 if (theKind == KIND_UNKNOWN) return theRoot;
58 return theRoot.FindChild(theKind);
61 HYDROData_Iterator::HYDROData_Iterator( const Handle(HYDROData_Document)& theDoc,
62 const ObjectKind theKind )
63 : myIter( GetLabelByKind( theDoc->LabelOfObjects(), theKind ),
64 TDataStd_Name::GetID(), theKind == KIND_UNKNOWN ) // iterate all sub-objects for unknown kind
68 void HYDROData_Iterator::Next()
71 // omit the properties iteration in case of UNKNOWN kind filtering
72 while ( myIter.More() && myIter.Value()->Label().Depth() < 4 )
76 bool HYDROData_Iterator::More() const
81 Handle(HYDROData_Entity) HYDROData_Iterator::Current()
83 return Object(myIter.Value()->Label());
86 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject(
87 const Handle(HYDROData_Document)& theDoc,
88 const ObjectKind& theObjectKind )
91 GetLabelByKind( theDoc->LabelOfObjects(), theObjectKind ).FindChild( theDoc->NewID() );
92 return CreateObject( aNewLab, theObjectKind );
95 Handle(HYDROData_Entity) HYDROData_Iterator::CreateObject( TDF_Label& theNewLabel,
96 const ObjectKind& theObjectKind )
98 // Object exists if there is a name attribute
99 TDataStd_Name::Set( theNewLabel, "" );
101 // Store the type of object in data label
102 TDataStd_NamedData::Set( theNewLabel );
104 Handle(TDataStd_NamedData) aNamedData;
105 theNewLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData );
106 aNamedData->SetInteger( "ObjectKind", theObjectKind );
108 return Object( theNewLabel );
111 Handle(HYDROData_Entity) HYDROData_Iterator::Object( const TDF_Label& theLabel )
113 Handle(HYDROData_Entity) aResult;
115 // If label has no name attribute it mean that this is not object or
116 // this object has been removed from document
117 Handle(TDataStd_Name) aNameAtt;
118 if ( !theLabel.FindAttribute( TDataStd_Name::GetID(), aNameAtt ) )
121 ObjectKind aKind = KIND_UNKNOWN;
123 // Retrieve the type of object from label
124 Handle(TDataStd_NamedData) aNamedData;
125 if ( theLabel.FindAttribute( TDataStd_NamedData::GetID(), aNamedData ) )
126 aKind = aNamedData->GetInteger( "ObjectKind" );
128 if ( aKind == KIND_UNKNOWN )
129 aKind = theLabel.Father().Tag(); // Try to get type from father label
133 case KIND_IMAGE: aResult = new HYDROData_Image(); break;
134 case KIND_POLYLINE: aResult = new HYDROData_Polyline3D(); break;
135 case KIND_BATHYMETRY: aResult = new HYDROData_Bathymetry(); break;
136 case KIND_ALTITUDE: aResult = new HYDROData_AltitudeObject(); break;
137 case KIND_IMMERSIBLE_ZONE: aResult = new HYDROData_ImmersibleZone(); break;
138 case KIND_RIVER: aResult = new HYDROData_River(); break;
139 case KIND_STREAM: aResult = new HYDROData_Stream(); break;
140 case KIND_CONFLUENCE: aResult = new HYDROData_Confluence(); break;
141 case KIND_CHANNEL: aResult = new HYDROData_Channel(); break;
142 case KIND_OBSTACLE: aResult = new HYDROData_Obstacle(); break;
143 case KIND_DIGUE: aResult = new HYDROData_Digue(); break;
144 case KIND_PROFILE: aResult = new HYDROData_Profile(); break;
145 case KIND_PROFILEUZ: aResult = new HYDROData_ProfileUZ(); break;
146 case KIND_POLYLINEXY: aResult = new HYDROData_PolylineXY(); break;
147 case KIND_CALCULATION: aResult = new HYDROData_CalculationCase(); break;
148 case KIND_REGION: aResult = new HYDROData_Region(); break;
149 case KIND_ZONE: aResult = new HYDROData_Zone(); break;
150 case KIND_VISUAL_STATE: aResult = new HYDROData_VisualState(); break;
151 case KIND_DUMMY_3D: aResult = new HYDROData_DummyObject3D(); break;
152 case KIND_SHAPES_GROUP: aResult = new HYDROData_ShapesGroup(); break;
153 case KIND_SPLITTED_GROUP: aResult = new HYDROData_SplittedShapesGroup(); break;
154 case KIND_STREAM_ALTITUDE: aResult = new HYDROData_StreamAltitude(); break;
155 case KIND_OBSTACLE_ALTITUDE: aResult = new HYDROData_ObstacleAltitude(); break;
159 if ( !aResult.IsNull() )
160 aResult->SetLabel( theLabel );