Salome HOME
5726f2966296b27398fbc66e3e1a6dd0601e3a47
[modules/hydro.git] / src / HYDRO_tests / test_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 <test_HYDROData_LandCoverMap.h>
20 #include <HYDROData_Document.h>
21 #include <HYDROData_LandCoverMap.h>
22 #include <HYDROData_PolylineXY.h>
23 #include <HYDROData_StricklerTable.h>
24 #include <HYDROData_Tool.h>
25 #include <HYDROGUI_LandCoverMapPrs.h>
26 #include <TopoDS_Edge.hxx>
27 #include <TopoDS_Wire.hxx>
28 #include <TopoDS_Face.hxx>
29 #include <TColgp_HArray1OfPnt.hxx>
30 #include <GeomAPI_Interpolate.hxx>
31 #include <BRepBuilderAPI_MakeEdge.hxx>
32 #include <BRepBuilderAPI_MakeFace.hxx>
33 #include <BRepBuilderAPI_MakeWire.hxx>
34 #include <TestViewer.h>
35 #include <TopTools_ListOfShape.hxx>
36 #include <AIS_DisplayMode.hxx>
37 #include <Aspect_ColorScale.hxx>
38 #include <QString>
39 #include <QColor>
40 #include <QMap>
41 #include <BRepTools.hxx>
42 #include <BRep_Builder.hxx>
43
44 const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
45 const QString DEF_STR_PATH = qgetenv( "HYDRO_ROOT_DIR" ) + "/share/salome/resources/hydro/def_strickler_table.txt";
46
47 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
48 {
49   int n = theXYList.size()/2;
50   Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
51   for( int i=1; i<=n; i++ )
52   {
53     double x = theXYList[2*i-2];
54     double y = theXYList[2*i-1];
55     gp_Pnt aPnt( x, y, 0 );
56     aPointsArray->SetValue( i, aPnt );
57   }
58   GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
59   anInterpolator.Perform();
60   bool aResult = anInterpolator.IsDone() == Standard_True;
61   if( aResult )
62   {
63     Handle( Geom_BSplineCurve ) aCurve = anInterpolator.Curve();
64     return BRepBuilderAPI_MakeEdge( aCurve ).Edge();
65   }
66   else
67     return TopoDS_Edge();
68 }
69
70 TopoDS_Face LandCover( const QList<double>& theXYList )
71 {
72   TopoDS_Edge anEdge = Spline( theXYList, true );
73   if( anEdge.IsNull() )
74     return TopoDS_Face();
75
76   TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
77   TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face();
78   return aFace;
79 }
80
81 void test_HYDROData_LandCoverMap::test_add_2_objects()
82 {
83   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
84
85   Handle(HYDROData_LandCoverMap) aMap =
86     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
87
88   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
89
90   TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
91   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
92
93   TopoDS_Face aLC2 = LandCover( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
94   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
95
96   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
97   CPPUNIT_ASSERT_IMAGES
98
99   HYDROData_LandCoverMap::Iterator anIt( aMap );
100   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
101   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
102   anIt.Next();
103   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
104   CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.StricklerType() );
105   anIt.Next();
106   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
107
108   aDoc->Close();
109 }
110
111 void test_HYDROData_LandCoverMap::test_split()
112 {
113   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
114
115   Handle(HYDROData_LandCoverMap) aMap =
116     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
117
118   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
119
120   TopoDS_Face aLC = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
121   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
122
123   Handle(HYDROData_PolylineXY) aPolyline =
124     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
125   TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire();
126   aPolyline->SetShape( aWire );
127
128   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
129
130   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
131   TestViewer::show( aWire, 0, true, Qt::blue );
132   CPPUNIT_ASSERT_IMAGES
133
134   HYDROData_LandCoverMap::Iterator anIt( aMap );
135   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
136   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
137   anIt.Next();
138   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
139   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
140   anIt.Next();
141   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
142
143   aDoc->Close();
144 }
145
146 void test_HYDROData_LandCoverMap::test_incomplete_split()
147 {
148   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
149
150   Handle(HYDROData_LandCoverMap) aMap =
151     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
152
153   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
154
155   TopoDS_Face aLC = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
156   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
157
158   Handle(HYDROData_PolylineXY) aPolyline =
159     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
160   TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 ) ).Wire();
161   aPolyline->SetShape( aWire );
162
163   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
164
165   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
166   TestViewer::show( aWire, 0, true, Qt::green );
167   CPPUNIT_ASSERT_IMAGES
168
169   HYDROData_LandCoverMap::Iterator anIt( aMap );
170   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
171   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
172   anIt.Next();
173   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
174
175   aDoc->Close();
176 }
177
178 void test_HYDROData_LandCoverMap::test_merge()
179 {
180   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
181
182   Handle(HYDROData_LandCoverMap) aMap =
183     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
184
185   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
186
187   TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
188
189   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
190
191   TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
192                                                    44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
193                                                   128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
194                                                   31 << 114 );
195   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
196
197   TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
198                                                  127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
199   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
200
201   //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
202   //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
203
204   //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
205
206   QString aType1, aType2;
207   gp_Pnt2d aPnt1( 25, 35 );
208   gp_Pnt2d aPnt2( 45, 55 );
209   //gp_Pnt2d aPnt3( 45, 10 );
210   //gp_Pnt2d aPnt4( 45, 80 );
211   TopTools_ListOfShape aList;
212   aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
213   aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
214   CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
215
216   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Merge_1" );
217   //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
218   CPPUNIT_ASSERT_IMAGES
219
220   aDoc->Close();
221 }
222
223 void test_HYDROData_LandCoverMap::test_remove()
224 {
225   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
226
227   Handle(HYDROData_LandCoverMap) aMap =
228     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
229
230   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
231
232   TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
233
234   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
235
236   TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
237                                                    44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
238                                                   128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
239                                                   31 << 114 );
240   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
241
242   TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
243                                                  127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
244   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
245
246   QString aType1, aType2;
247   gp_Pnt2d aPnt1( 25, 35 );
248   gp_Pnt2d aPnt2( 45, 55 );
249   TopTools_ListOfShape aList;
250   aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
251   aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
252   CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
253
254   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
255   CPPUNIT_ASSERT_IMAGES
256
257   aDoc->Close();
258 }
259
260 void test_HYDROData_LandCoverMap::test_merge_faces_boxes()
261 {
262   TopoDS_Shape pp1, pp2, pp3, pp4;
263   BRep_Builder BB;
264   BRepTools::Read(pp1, (REF_DATA_PATH + "/pp1.brep").toStdString().c_str(), BB);
265   BRepTools::Read(pp2, (REF_DATA_PATH + "/pp2.brep").toStdString().c_str(), BB);
266   BRepTools::Read(pp3, (REF_DATA_PATH + "/pp3.brep").toStdString().c_str(), BB);
267   BRepTools::Read(pp4, (REF_DATA_PATH + "/pp4.brep").toStdString().c_str(), BB);
268
269   CPPUNIT_ASSERT(!pp1.IsNull());
270   CPPUNIT_ASSERT(!pp2.IsNull());
271   CPPUNIT_ASSERT(!pp3.IsNull());
272   CPPUNIT_ASSERT(!pp4.IsNull());
273
274   //Test mergeFaces() func // boxes // USD == true
275   {
276     TopTools_ListOfShape Faces;
277     Faces.Append(pp1);
278     Faces.Append(pp2);
279     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
280     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_11" );
281     CPPUNIT_ASSERT_IMAGES
282     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
283   }
284   {
285     TopTools_ListOfShape Faces;
286     Faces.Append(pp1);
287     Faces.Append(pp3);
288     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
289     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_12" );
290     CPPUNIT_ASSERT_IMAGES
291     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
292   }
293   {
294     TopTools_ListOfShape Faces;
295     Faces.Append(pp1);
296     Faces.Append(pp2);
297     Faces.Append(pp4);
298     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
299     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_13" );
300     CPPUNIT_ASSERT_IMAGES
301     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
302   }
303   {
304     TopTools_ListOfShape Faces;
305     Faces.Append(pp1);
306     Faces.Append(pp3);
307     Faces.Append(pp4);
308     Faces.Append(pp2);
309     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
310     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_14" );
311     CPPUNIT_ASSERT_IMAGES
312     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
313   }
314   //
315
316   //Test mergeFaces() func // boxes // USD == false
317   {
318     TopTools_ListOfShape Faces;
319     Faces.Append(pp1);
320     Faces.Append(pp2);
321     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
322     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_21" );
323     CPPUNIT_ASSERT_IMAGES
324     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
325   }
326   {
327     TopTools_ListOfShape Faces;
328     Faces.Append(pp1);
329     Faces.Append(pp3);
330     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
331     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_22" );
332     CPPUNIT_ASSERT_IMAGES
333     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
334   }
335   {
336     TopTools_ListOfShape Faces;
337     Faces.Append(pp1);
338     Faces.Append(pp2);
339     Faces.Append(pp4);
340     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
341     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_23" );
342     CPPUNIT_ASSERT_IMAGES
343     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
344   }
345   {
346     TopTools_ListOfShape Faces;
347     Faces.Append(pp1);
348     Faces.Append(pp3);
349     Faces.Append(pp4);
350     Faces.Append(pp2);
351     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
352     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_24" );
353     CPPUNIT_ASSERT_IMAGES
354     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
355   }
356 }
357
358
359 void test_HYDROData_LandCoverMap::test_merge_faces_circles()
360 {
361   TopoDS_Shape ff1, ff2, ff3;
362   BRep_Builder BB;
363   BRepTools::Read(ff1, (REF_DATA_PATH + "/ff1.brep").toStdString().c_str(), BB);
364   BRepTools::Read(ff2, (REF_DATA_PATH + "/ff2.brep").toStdString().c_str(), BB);
365   BRepTools::Read(ff3, (REF_DATA_PATH + "/ff3.brep").toStdString().c_str(), BB);
366
367   CPPUNIT_ASSERT(!ff1.IsNull());
368   CPPUNIT_ASSERT(!ff2.IsNull());
369   CPPUNIT_ASSERT(!ff3.IsNull());
370
371   //Test mergeFaces() func // circles // USD == true
372   { 
373     TopTools_ListOfShape Faces;
374     Faces.Append(ff1);
375     Faces.Append(ff2);
376     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
377     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_11" );
378     CPPUNIT_ASSERT_IMAGES
379     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
380   }
381   {
382     TopTools_ListOfShape Faces;
383     Faces.Append(ff1);
384     Faces.Append(ff3);
385     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
386     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_12" );
387     CPPUNIT_ASSERT_IMAGES
388     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
389   }
390   {
391     TopTools_ListOfShape Faces;
392     Faces.Append(ff1);
393     Faces.Append(ff2);
394     Faces.Append(ff3);
395     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
396     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_13" );
397     CPPUNIT_ASSERT_IMAGES
398     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
399   }
400   {
401     TopTools_ListOfShape Faces;
402     Faces.Append(ff1);
403     Faces.Append(ff3);
404     Faces.Append(ff2);
405     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
406     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_14" );
407     CPPUNIT_ASSERT_IMAGES
408     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
409   }
410   //
411
412   //Test mergeFaces() func // circles // USD == false
413   {
414     TopTools_ListOfShape Faces;
415     Faces.Append(ff1);
416     Faces.Append(ff2);
417     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
418     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_21" );
419     CPPUNIT_ASSERT_IMAGES
420     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
421   }
422   {
423     TopTools_ListOfShape Faces;
424     Faces.Append(ff1);
425     Faces.Append(ff3);
426     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
427     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_22" );
428     CPPUNIT_ASSERT_IMAGES
429     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
430   }
431   {
432     TopTools_ListOfShape Faces;
433     Faces.Append(ff1);
434     Faces.Append(ff2);
435     Faces.Append(ff3);
436     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
437     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_23" );
438     CPPUNIT_ASSERT_IMAGES
439     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
440   }
441   {
442     TopTools_ListOfShape Faces;
443     Faces.Append(ff1);
444     Faces.Append(ff3);
445     Faces.Append(ff2);
446     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
447     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_24" );
448     CPPUNIT_ASSERT_IMAGES
449     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
450   }
451
452 }
453
454 void test_HYDROData_LandCoverMap::test_import_dbf()
455 {
456   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
457
458   Handle(HYDROData_LandCoverMap) aMap =
459     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
460
461   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
462   QString aFileName = REF_DATA_PATH + "/t1.dbf";
463   QStringList aDBFV;
464   QStringList aST;
465   aDBFV.append("100");
466   aDBFV.append("200");
467   aDBFV.append("300");
468   aST.append("water");
469   aST.append("forest");
470   aST.append("road");
471   // aST.size() == aDBFV.size()!!
472   Handle(HYDROData_PolylineXY) aPolyline =
473     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
474   TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( Spline( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 ) ).Wire();
475   aPolyline->SetShape( aWire );
476   for (int i = 0; i < 3; i++)
477     aMap->Add(aPolyline, "");
478   TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
479   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
480   
481   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
482   QMap<int, int> Inds;
483   Inds.insert(1, 1);
484   Inds.insert(2, 2);
485   Inds.insert(3, 3);
486   aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
487   HYDROData_LandCoverMap::Iterator anIt( aMap );
488  
489   CPPUNIT_ASSERT_EQUAL(true, "water" == anIt.StricklerType());
490   anIt.Next();
491   CPPUNIT_ASSERT_EQUAL(true, "forest" == anIt.StricklerType());
492
493 }
494
495 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types()
496 {
497   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
498
499   Handle(HYDROData_StricklerTable) aTable =
500     Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
501   CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
502
503   Handle(HYDROData_LandCoverMap) aMap =
504     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
505
506   TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
507   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
508
509   TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
510                                                    44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
511                                                   128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
512                                                   31 << 114 );
513   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
514
515   TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
516                                                  127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
517   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
518
519   Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
520   aPrs->SetTable( aTable );
521   TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByTypes" );
522   CPPUNIT_ASSERT_IMAGES
523
524   aDoc->Close();
525 }
526
527 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff()
528 {
529   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
530
531   Handle(HYDROData_StricklerTable) aTable =
532     Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
533   CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
534
535   Handle(HYDROData_LandCoverMap) aMap =
536     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
537
538   TopoDS_Face aLC1 = LandCover( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
539   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
540
541   TopoDS_Face aLC2 = LandCover( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
542                                                    44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
543                                                   128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
544                                                   31 << 114 );
545   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
546
547   TopoDS_Face aLC3 = LandCover( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
548                                                  127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
549   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
550
551   Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
552   aPrs->SetTable( aTable );
553   aPrs->SetColorScale( TestViewer::showColorScale( true ) );
554   TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByCoeff" );
555   CPPUNIT_ASSERT_IMAGES
556
557   TestViewer::showColorScale( false );
558   aDoc->Close();
559 }
560