Salome HOME
5c1f9e39ae0bea42a7ae559d4ee391b370d975f7
[modules/hydro.git] / src / HYDROData / HYDROData_LandCoverMap.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROData_LandCoverMap.h>
20 #include <HYDROData_Tool.h>
21
22 #include <BOPAlgo_Builder.hxx>
23 #include <BOPAlgo_PaveFiller.hxx>
24 #include <BOPCol_ListOfShape.hxx>
25 #include <BRep_Builder.hxx>
26 #include <NCollection_IndexedMap.hxx>
27 #include <TNaming_Builder.hxx>
28 #include <TNaming_NamedShape.hxx>
29 #include <TopoDS.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Shell.hxx>
34
35 #include <QString>
36
37 IMPLEMENT_STANDARD_HANDLE(HYDROData_LandCoverMap, HYDROData_Entity)
38 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_LandCoverMap, HYDROData_Entity)
39
40 class HYDROData_MapOfShapeToStricklerType : public NCollection_IndexedDataMap<TopoDS_Shape, QString>
41 {
42 };
43
44 /**
45   Constructor
46   @param theMap the land cover map to iterate through
47 */
48 HYDROData_LandCoverMap::Iterator::Iterator( const HYDROData_LandCoverMap& theMap )
49 {
50   Init( theMap );
51 }
52
53 /**
54   Initialize the iterator
55   @param theMap the land cover map to iterate through
56 */
57 void HYDROData_LandCoverMap::Iterator::Init( const HYDROData_LandCoverMap& theMap )
58 {
59   myIterator = new TopoDS_Iterator( theMap.GetShape() );
60   myIndex = 0;
61   theMap.myLab.FindChild( DataTag_Types ).FindAttribute( TDataStd_ExtStringArray::GetID(), myArray );
62 }
63
64 /**
65   Destructor
66 */
67 HYDROData_LandCoverMap::Iterator::~Iterator()
68 {
69   delete myIterator;
70 }
71
72 /**
73   Return if the iterator has more elements
74   @return if the iterator has more elements
75 */
76 bool HYDROData_LandCoverMap::Iterator::More() const
77 {
78   return !myArray.IsNull() && myIterator->More();
79 }
80
81 /**
82   Move iterator to the next element
83 */
84 void HYDROData_LandCoverMap::Iterator::Next()
85 {
86   myIterator->Next();
87 }
88
89 /**
90   Get the current land cover (face)
91   @return the land cover's face
92 */
93 TopoDS_Face HYDROData_LandCoverMap::Iterator::Face() const
94 {
95   return TopoDS::Face( myIterator->Value() );
96 }
97
98 /**
99   Get the current land cover's Strickler type 
100   @return the land cover's Strickler type 
101 */
102 QString HYDROData_LandCoverMap::Iterator::StricklerType() const
103 {
104   if( myArray.IsNull() || myIndex < myArray->Lower() || myIndex > myArray->Upper() )
105     return "";
106   else
107     return HYDROData_Tool::toQString( myArray->Value( myIndex ) );
108 }
109
110 /**
111   Constructor
112 */
113 HYDROData_LandCoverMap::HYDROData_LandCoverMap()
114 {
115 }
116
117 /**
118   Destructor
119 */
120 HYDROData_LandCoverMap::~HYDROData_LandCoverMap()
121 {
122 }
123
124 /**
125   Import the land cover map from QGIS
126   @param theFileName the name of file
127   @return if the import is successful
128 */
129 bool HYDROData_LandCoverMap::ImportQGIS( const QString& theFileName )
130 {
131   //TODO
132   return false;
133 }
134
135 /**
136   Export the land cover map to QGIS
137   @param theFileName the name of file
138   @return if the export is successful
139 */
140 bool HYDROData_LandCoverMap::ExportQGIS( const QString& theFileName ) const
141 {
142   //TODO
143   return false;
144 }
145
146 /**
147   Export the land cover map for the solver (Telemac)
148   @param theFileName the name of file
149   @return if the export is successful
150 */
151 bool HYDROData_LandCoverMap::ExportTelemac( const QString& theFileName ) const
152 {
153   //TODO
154   return false;
155 }
156
157 /**
158   Add a new object as land cover
159   @param theObject the object to add as land cover
160   @param theType the Strickler type for the new land cover
161   @return if the addition is successful
162 */
163 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Object )& theObject, const QString& theType )
164 {
165   //TODO
166   return false;
167 }
168
169 /**
170   Add a new polyline as land cover
171   @param thePolyline the polyline to add as land cover
172   @param theType the Strickler type for the new land cover
173   @return if the addition is successful
174 */
175 bool HYDROData_LandCoverMap::Add( const Handle( HYDROData_Polyline )& thePolyline, const QString& theType )
176 {
177   //TODO
178   return false;
179 }
180
181 /**
182   Remove the given face from land cover map
183   @param theFace the face to be removed
184   @return if the removing is successful
185 */
186 bool HYDROData_LandCoverMap::Remove( const TopoDS_Face& theFace )
187 {
188   //TODO
189   return false;
190 }
191
192 /**
193   Split the land cover map by the given polyline
194   @param thePolyline the tool polyline to split the land cover map
195   @return if the removing is successful
196 */
197 bool HYDROData_LandCoverMap::Split( const Handle( HYDROData_Polyline )& thePolyline )
198 {
199   //TODO
200   return false;
201 }
202
203 /**
204   Merge the given faces in the land cover
205   @param theFaces the faces to merge in the land cover map
206   @param theType the Strickler type for the merged land cover
207   @return if the merge is successful
208 */
209 bool HYDROData_LandCoverMap::Merge( const TopTools_ListOfShape& theFaces, const QString& theType )
210 {
211   //TODO
212   return false;
213 }
214
215 /**
216   Get the shape of the land cover map
217 */
218 TopoDS_Shape HYDROData_LandCoverMap::GetShape() const
219 {
220   TDF_Label aLabel = myLab.FindChild( DataTag_Shape, false );
221   if ( !aLabel.IsNull() )
222   {
223     Handle(TNaming_NamedShape) aNamedShape;
224     if( aLabel.FindAttribute( TNaming_NamedShape::GetID(), aNamedShape ) )
225       return aNamedShape->Get();
226   }
227   return TopoDS_Shape();
228 }
229
230 /**
231   Set the shape of the land cover map
232   @param theShape the new shape for the land cover map
233 */
234 void HYDROData_LandCoverMap::SetShape( const TopoDS_Shape& theShape )
235 {
236   TNaming_Builder aBuilder( myLab.FindChild( DataTag_Shape ) );
237   aBuilder.Generated( theShape );
238 }
239
240 /**
241   Perform the local partition algorithm on the land cover
242   @param theNewShape the new shape to add into the land cover
243   @param theNewType the new Strickler type for the new land cover
244   @return if the local partition is successful
245 */
246 bool HYDROData_LandCoverMap::LocalPartition( const TopoDS_Shape& theNewShape, const QString& theNewType )
247 {
248   //TODO
249 }
250
251 /**
252   Replace the set of land covers in the land cover map
253   @param theMap the map of shape (face) to Strickler type (string)
254 */
255 void HYDROData_LandCoverMap::StoreLandCovers( const HYDROData_MapOfShapeToStricklerType& theMap )
256 {
257   TopoDS_Compound aCompound;
258   BRep_Builder aCompoundBuilder;
259   aCompoundBuilder.MakeCompound( aCompound );
260
261   int n = theMap.Size();
262   Handle( TDataStd_ExtStringArray ) aTypes = 
263     TDataStd_ExtStringArray::Set( myLab.FindChild( DataTag_Types ), 0, n-1, Standard_True );
264   HYDROData_MapOfShapeToStricklerType::Iterator aNFIt( theMap );
265   for( int i=0; aNFIt.More(); aNFIt.Next(), i++ )
266   {
267     aCompoundBuilder.Add( aCompound, aNFIt.Key() );
268     aTypes->SetValue( i, HYDROData_Tool::toExtString( aNFIt.Value() ) );
269   }
270
271   SetShape( aCompound );
272 }