Salome HOME
2cb5dead698d3bd5a70225e65891b0cb008c7193
[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_CalculationCase.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_LandCoverMap.h>
23 #include <HYDROData_ImmersibleZone.h>
24 #include <HYDROData_PolylineXY.h>
25 #include <HYDROData_StricklerTable.h>
26 #include <HYDROData_Tool.h>
27 #include <HYDROGUI_LandCoverMapPrs.h>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Wire.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TestViewer.h>
32 #include <TestShape.h>
33 #include <TopTools_ListOfShape.hxx>
34 #include <AIS_DisplayMode.hxx>
35 #include <Aspect_ColorScale.hxx>
36 #include <QString>
37 #include <QColor>
38 #include <QMap>
39 #include <QDir>
40 #include <BRepTools.hxx>
41 #include <BRep_Builder.hxx>
42
43 const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
44 const QString DEF_STR_PATH = qgetenv( "HYDRO_SRC_DIR" ) + "/src/HYDROGUI/resources/def_strickler_table.txt";
45
46 void test_HYDROData_LandCoverMap::test_add_2_objects()
47 {
48   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
49
50   Handle(HYDROData_LandCoverMap) aMap =
51     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
52
53   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
54
55   TopoDS_Face aLC1 = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
56   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
57
58   TopoDS_Face aLC2 = Face( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
59   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
60
61   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
62   CPPUNIT_ASSERT_IMAGES
63
64   HYDROData_LandCoverMap::Iterator anIt( aMap );
65   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
66   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
67   anIt.Next();
68   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
69   CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.StricklerType() );
70   anIt.Next();
71   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
72
73   aDoc->Close();
74 }
75
76 void test_HYDROData_LandCoverMap::test_split()
77 {
78   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
79
80   Handle(HYDROData_LandCoverMap) aMap =
81     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
82
83   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
84
85   TopoDS_Face aLC = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
86   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
87
88   Handle(HYDROData_PolylineXY) aPolyline =
89     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
90   TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10, false );
91   aPolyline->SetShape( aWire );
92
93   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
94
95   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
96   TestViewer::show( aWire, 0, true, Qt::blue );
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( "test1" ), anIt.StricklerType() );
105   anIt.Next();
106   CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
107
108   aDoc->Close();
109 }
110
111 void test_HYDROData_LandCoverMap::test_incomplete_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 = Face( 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 = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10, false );
126   aPolyline->SetShape( aWire );
127
128   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
129
130   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
131   TestViewer::show( aWire, 0, true, Qt::green );
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( false, anIt.More() );
139
140   aDoc->Close();
141 }
142
143 void test_HYDROData_LandCoverMap::test_merge()
144 {
145   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
146
147   Handle(HYDROData_LandCoverMap) aMap =
148     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
149
150   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
151
152   TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
153
154   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
155
156   TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
157                                               44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
158                                              128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
159                                               31 << 114 );
160   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
161
162   TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
163                                             127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
164   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
165
166   //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
167   //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
168
169   //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
170
171   QString aType1, aType2;
172   gp_Pnt2d aPnt1( 25, 35 );
173   gp_Pnt2d aPnt2( 45, 55 );
174   //gp_Pnt2d aPnt3( 45, 10 );
175   //gp_Pnt2d aPnt4( 45, 80 );
176   TopTools_ListOfShape aList;
177   aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
178   aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
179   CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
180
181   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Merge_1" );
182   //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
183   CPPUNIT_ASSERT_IMAGES
184
185   aDoc->Close();
186 }
187
188 void test_HYDROData_LandCoverMap::test_remove()
189 {
190   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
191
192   Handle(HYDROData_LandCoverMap) aMap =
193     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
194
195   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
196
197   TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
198
199   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
200
201   TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
202                                               44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
203                                              128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
204                                               31 << 114 );
205   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
206
207   TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
208                                             127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
209   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) );
210
211   QString aType1, aType2;
212   gp_Pnt2d aPnt1( 25, 35 );
213   gp_Pnt2d aPnt2( 45, 55 );
214   TopTools_ListOfShape aList;
215   aList.Append( aMap->FindByPoint( aPnt1, aType1 ) );
216   aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
217   CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
218
219   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
220   CPPUNIT_ASSERT_IMAGES
221
222   aDoc->Close();
223 }
224
225 void test_HYDROData_LandCoverMap::test_merge_faces_boxes()
226 {
227   TopoDS_Shape pp1, pp2, pp3, pp4;
228   BRep_Builder BB;
229   BRepTools::Read(pp1, (REF_DATA_PATH + "/pp1.brep").toStdString().c_str(), BB);
230   BRepTools::Read(pp2, (REF_DATA_PATH + "/pp2.brep").toStdString().c_str(), BB);
231   BRepTools::Read(pp3, (REF_DATA_PATH + "/pp3.brep").toStdString().c_str(), BB);
232   BRepTools::Read(pp4, (REF_DATA_PATH + "/pp4.brep").toStdString().c_str(), BB);
233
234   CPPUNIT_ASSERT(!pp1.IsNull());
235   CPPUNIT_ASSERT(!pp2.IsNull());
236   CPPUNIT_ASSERT(!pp3.IsNull());
237   CPPUNIT_ASSERT(!pp4.IsNull());
238
239   //Test mergeFaces() func // boxes // USD == true
240   {
241     TopTools_ListOfShape Faces;
242     Faces.Append(pp1);
243     Faces.Append(pp2);
244     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
245     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_11" );
246     CPPUNIT_ASSERT_IMAGES
247     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
248   }
249   {
250     TopTools_ListOfShape Faces;
251     Faces.Append(pp1);
252     Faces.Append(pp3);
253     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
254     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_12" );
255     CPPUNIT_ASSERT_IMAGES
256     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
257   }
258   {
259     TopTools_ListOfShape Faces;
260     Faces.Append(pp1);
261     Faces.Append(pp2);
262     Faces.Append(pp4);
263     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
264     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_13" );
265     CPPUNIT_ASSERT_IMAGES
266     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
267   }
268   {
269     TopTools_ListOfShape Faces;
270     Faces.Append(pp1);
271     Faces.Append(pp3);
272     Faces.Append(pp4);
273     Faces.Append(pp2);
274     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
275     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_14" );
276     CPPUNIT_ASSERT_IMAGES
277     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
278   }
279   //
280
281   //Test mergeFaces() func // boxes // USD == false
282   {
283     TopTools_ListOfShape Faces;
284     Faces.Append(pp1);
285     Faces.Append(pp2);
286     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
287     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_21" );
288     CPPUNIT_ASSERT_IMAGES
289     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
290   }
291   {
292     TopTools_ListOfShape Faces;
293     Faces.Append(pp1);
294     Faces.Append(pp3);
295     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
296     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_22" );
297     CPPUNIT_ASSERT_IMAGES
298     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
299   }
300   {
301     TopTools_ListOfShape Faces;
302     Faces.Append(pp1);
303     Faces.Append(pp2);
304     Faces.Append(pp4);
305     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
306     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_23" );
307     CPPUNIT_ASSERT_IMAGES
308     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
309   }
310   {
311     TopTools_ListOfShape Faces;
312     Faces.Append(pp1);
313     Faces.Append(pp3);
314     Faces.Append(pp4);
315     Faces.Append(pp2);
316     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
317     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_boxes_24" );
318     CPPUNIT_ASSERT_IMAGES
319     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
320   }
321 }
322
323
324 void test_HYDROData_LandCoverMap::test_merge_faces_circles()
325 {
326   TopoDS_Shape ff1, ff2, ff3;
327   BRep_Builder BB;
328   BRepTools::Read(ff1, (REF_DATA_PATH + "/ff1.brep").toStdString().c_str(), BB);
329   BRepTools::Read(ff2, (REF_DATA_PATH + "/ff2.brep").toStdString().c_str(), BB);
330   BRepTools::Read(ff3, (REF_DATA_PATH + "/ff3.brep").toStdString().c_str(), BB);
331
332   CPPUNIT_ASSERT(!ff1.IsNull());
333   CPPUNIT_ASSERT(!ff2.IsNull());
334   CPPUNIT_ASSERT(!ff3.IsNull());
335
336   //Test mergeFaces() func // circles // USD == true
337   { 
338     TopTools_ListOfShape Faces;
339     Faces.Append(ff1);
340     Faces.Append(ff2);
341     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
342     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_11" );
343     CPPUNIT_ASSERT_IMAGES
344     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
345   }
346   {
347     TopTools_ListOfShape Faces;
348     Faces.Append(ff1);
349     Faces.Append(ff3);
350     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
351     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_12" );
352     CPPUNIT_ASSERT_IMAGES
353     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
354   }
355   {
356     TopTools_ListOfShape Faces;
357     Faces.Append(ff1);
358     Faces.Append(ff2);
359     Faces.Append(ff3);
360     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
361     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_13" );
362     CPPUNIT_ASSERT_IMAGES
363     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
364   }
365   {
366     TopTools_ListOfShape Faces;
367     Faces.Append(ff1);
368     Faces.Append(ff3);
369     Faces.Append(ff2);
370     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
371     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_14" );
372     CPPUNIT_ASSERT_IMAGES
373     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
374   }
375   //
376
377   //Test mergeFaces() func // circles // USD == false
378   {
379     TopTools_ListOfShape Faces;
380     Faces.Append(ff1);
381     Faces.Append(ff2);
382     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
383     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_21" );
384     CPPUNIT_ASSERT_IMAGES
385     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
386   }
387   {
388     TopTools_ListOfShape Faces;
389     Faces.Append(ff1);
390     Faces.Append(ff3);
391     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
392     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_22" );
393     CPPUNIT_ASSERT_IMAGES
394     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
395   }
396   {
397     TopTools_ListOfShape Faces;
398     Faces.Append(ff1);
399     Faces.Append(ff2);
400     Faces.Append(ff3);
401     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
402     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_23" );
403     CPPUNIT_ASSERT_IMAGES
404     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
405   }
406   {
407     TopTools_ListOfShape Faces;
408     Faces.Append(ff1);
409     Faces.Append(ff3);
410     Faces.Append(ff2);
411     TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
412     TestViewer::show( aMergedFace, AIS_Shaded, true, "merge_faces_circles_24" );
413     CPPUNIT_ASSERT_IMAGES
414     CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
415   }
416 }
417
418 void test_HYDROData_LandCoverMap::test_import_dbf()
419 {
420   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
421
422   Handle(HYDROData_LandCoverMap) aMap =
423     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
424
425   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
426   QString aFileName = REF_DATA_PATH + "/t1.dbf";
427   QStringList aDBFV;
428   QStringList aST;
429   aDBFV.append("100");
430   aDBFV.append("200");
431   aDBFV.append("300");
432   aST.append("water");
433   aST.append("forest");
434   aST.append("road");
435   // aST.size() == aDBFV.size()!!
436   Handle(HYDROData_PolylineXY) aPolyline =
437     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
438   TopoDS_Wire aWire = Wire( QList<double>() << 10 << 40 << 30 << 10 << 40 << 10 << 60 << 10 );
439   aPolyline->SetShape( aWire );
440   for (int i = 0; i < 3; i++)
441     aMap->Add(aPolyline, "");
442   TopoDS_Face aLC1 = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
443   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
444   
445   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
446   QList<int> Inds = QList<int>() << 1 << 2 << 3;
447   aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
448   HYDROData_LandCoverMap::Iterator anIt( aMap );
449  
450   CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() );
451   anIt.Next();
452   CPPUNIT_ASSERT_EQUAL( QString( "road" ), anIt.StricklerType() );
453
454   aDoc->Close();
455 }
456
457 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types()
458 {
459   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
460
461   Handle(HYDROData_StricklerTable) aTable =
462     Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
463   CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
464
465   Handle(HYDROData_LandCoverMap) aMap =
466     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
467
468   TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
469   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
470
471   TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
472                                               44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
473                                              128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
474                                               31 << 114 );
475   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
476
477   TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
478                                             127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
479   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
480
481   // build presentation object 
482   Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
483   aPrs->SetTable( aTable );
484   // show presentation in viewer
485   TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByTypes" );
486   // select one of faces (first)
487   TestViewer::select( 200, 300 );
488   CPPUNIT_ASSERT_IMAGES
489
490   aDoc->Close();
491 }
492
493 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff()
494 {
495   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
496
497   Handle(HYDROData_StricklerTable) aTable =
498     Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
499   CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
500
501   Handle(HYDROData_LandCoverMap) aMap =
502     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
503
504   TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
505   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "Zones de champs cultivé à végétation basse" ) );
506
507   TopoDS_Face aLC2 = Face( QList<double>() << 21 << 34 << 24 << 25 << 37   << 37 << 40  << 61 <<
508                                               44 << 95 << 85 << 100 << 104 << 66 << 107 << 33 <<
509                                              128 << 18 << 140 << 50 << 131 << 89 << 104 << 111 <<
510                                               31 << 114 );
511   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
512
513   TopoDS_Face aLC3 = Face( QList<double>() << 4 << 54 << 1   << 47 << 51  << 45 <<
514                                             127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 );
515   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "Zones de champs, prairies, sans cultures" ) );
516
517   Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
518   aPrs->SetTable( aTable );
519   aPrs->SetColorScale( TestViewer::showColorScale( true ) );
520   TestViewer::show( aPrs, AIS_Shaded, 4, true, "LandCoverMap_PrsByCoeff" );
521   CPPUNIT_ASSERT_IMAGES
522
523   TestViewer::showColorScale( false );
524   aDoc->Close();
525 }
526
527 void test_HYDROData_LandCoverMap::test_dump_python()
528 {
529   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
530
531   Handle(HYDROData_LandCoverMap) aMap =
532     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
533   aMap->SetName( "test_LCM" );
534
535   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
536
537   TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
538
539   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
540
541   TopoDS_Face aLC2 = Face( 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, "test2" ) );
546
547   TopoDS_Face aLC3 = Face( 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, "test3" ) );
550
551   QString aTmpPath = QDir::tempPath() + "/lc_dump.py";
552   CPPUNIT_ASSERT_EQUAL( true, aDoc->DumpToPython( aTmpPath, false ) );
553
554   //TODO: compare files
555
556   aDoc->Close();
557 }
558
559 void test_HYDROData_LandCoverMap::test_transparent_prs()
560 {
561   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
562
563   Handle(HYDROData_StricklerTable) aTable =
564     Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
565   CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
566
567   Handle(HYDROData_PolylineXY) aPoly =
568     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
569   aPoly->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, true );
570   aPoly->AddPoint( 0, gp_XY( 0, 0 ) );
571   aPoly->AddPoint( 0, gp_XY( 20, 0 ) );
572   aPoly->AddPoint( 0, gp_XY( 10, 10 ) );
573   aPoly->Update();
574
575   Handle(HYDROData_ImmersibleZone) aZone =
576     Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
577   aZone->SetPolyline( aPoly );
578   aZone->Update();
579
580   Handle(HYDROData_LandCoverMap) aMap =
581     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
582   aMap->LocalPartition( Face( QList<double>() << 1 << 1 << 10 << 10 << 10 << 20 ), "Zones de champs cultivé à végétation haute" );
583   aMap->LocalPartition( Face( QList<double>() << 5 << 5 << 10 << 5 << 10 << 8 << 5 << 12 << 5 << 8 ), "Zones de champs cultivé à végétation haute" );
584   aMap->SetName( "test_LCM" );
585
586   TestViewer::show( aZone->GetTopShape(), AIS_Shaded, true, "LandCoverMap_TransparentPrs" );
587
588   Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
589   aPrs->SetTable( aTable );
590   aPrs->SetTransparency( 0.5 );
591   TestViewer::show( aPrs, AIS_Shaded, 0, true, "" );
592
593   CPPUNIT_ASSERT_IMAGES
594   aDoc->Close();
595 }
596
597 void test_HYDROData_LandCoverMap::test_add_triangles()
598 {
599   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
600
601   Handle(HYDROData_PolylineXY) Polyline_1 =
602     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
603
604   Polyline_1->SetName( "Polyline_1" );
605   Polyline_1->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
606   Polyline_1->AddPoint( 0, gp_XY( -264.84, 323.44 ) );
607   Polyline_1->AddPoint( 0, gp_XY( 254.45, 301.19 ) );
608   Polyline_1->AddPoint( 0, gp_XY( -291.54, -47.48 ) );
609   Polyline_1->Update();
610
611   Handle(HYDROData_PolylineXY) Polyline_2 =
612     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
613   Polyline_2->SetName( "Polyline_2" );
614   Polyline_2->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
615   Polyline_2->AddPoint( 0, gp_XY( -42.28, -351.63 ) );
616   Polyline_2->AddPoint( 0, gp_XY( 218.84, -146.88 ) );
617   Polyline_2->AddPoint( 0, gp_XY( 413.20, -235.91 ) );
618   Polyline_2->AddPoint( 0, gp_XY( 466.62, -388.72 ) );
619   Polyline_2->Update();
620
621   Handle(HYDROData_PolylineXY) Polyline_3 =
622     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
623   Polyline_3->SetName( "Polyline_3" );
624   Polyline_3->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
625   Polyline_3->AddPoint( 0, gp_XY( -108.31, 213.65 ) );
626   Polyline_3->AddPoint( 0, gp_XY( 127.60, 382.79 ) );
627   Polyline_3->AddPoint( 0, gp_XY( 192.88, -91.99 ) );
628   Polyline_3->Update();
629
630   Handle(HYDROData_PolylineXY) Polyline_4 =
631     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
632   Polyline_4->SetName( "Polyline_4" );
633   Polyline_4->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
634   Polyline_4->AddPoint( 0, gp_XY( 215.52, 344.61 ) );
635   Polyline_4->AddPoint( 0, gp_XY( 68.25, 258.52 ) );
636   Polyline_4->AddPoint( 0, gp_XY( 200.58, 154.65 ) );
637   Polyline_4->Update();
638
639   Handle(HYDROData_PolylineXY) Polyline_5 =
640     Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
641   Polyline_5->SetName( "Polyline_5" );
642   Polyline_5->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
643   Polyline_5->AddPoint( 0, gp_XY( 16.15, -58.08 ) );
644   Polyline_5->AddPoint( 0, gp_XY( 116.47, 84.21 ) );
645   Polyline_5->AddPoint( 0, gp_XY( 266.59, 29.43 ) );
646   Polyline_5->Update();
647
648   Handle(HYDROData_LandCoverMap) aMap =
649     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
650
651   CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_1, "" ) );
652   CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_3, "" ) );
653   CPPUNIT_ASSERT_EQUAL( true, aMap->Add( Polyline_4, "" ) );
654
655   Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
656   TestViewer::show( aPrs, AIS_Shaded, 0, true, "LandCover_Triangles" );
657   CPPUNIT_ASSERT_IMAGES
658
659   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( Polyline_5 ) );
660   Handle(HYDROGUI_LandCoverMapPrs) aPrs2 = new HYDROGUI_LandCoverMapPrs( aMap );
661   TestViewer::show( aPrs2, AIS_Shaded, 0, true, "LandCover_Triangles_Split" );
662   CPPUNIT_ASSERT_IMAGES
663
664   aDoc->Close();
665 }
666
667 void test_HYDROData_LandCoverMap::test_assign_to_calc_case()
668 {
669   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
670
671   Handle(HYDROData_LandCoverMap) aMap =
672     Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
673   Handle(HYDROData_CalculationCase) aCalcCase =
674     Handle(HYDROData_CalculationCase)::DownCast( aDoc->CreateObject( KIND_CALCULATION ) );
675
676   aCalcCase->SetLandCoverMap( aMap );
677   CPPUNIT_ASSERT_EQUAL( aMap->myLab, aCalcCase->GetLandCoverMap()->myLab );
678
679   aDoc->Close();
680 }