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