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.
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.
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
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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>
40 #include <BRepTools.hxx>
41 #include <BRep_Builder.hxx>
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";
46 void test_HYDROData_LandCoverMap::test_add_2_objects()
48 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
50 Handle(HYDROData_LandCoverMap) aMap =
51 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
53 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
55 TopoDS_Face aLC1 = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
56 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
58 TopoDS_Face aLC2 = Face( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
59 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
61 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
64 HYDROData_LandCoverMap::Iterator anIt( aMap );
65 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
66 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
68 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
69 CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.StricklerType() );
71 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
76 void test_HYDROData_LandCoverMap::test_split()
78 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
80 Handle(HYDROData_LandCoverMap) aMap =
81 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
83 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
85 TopoDS_Face aLC = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
86 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
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 );
93 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
95 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
96 TestViewer::show( aWire, 0, true, Qt::blue );
99 HYDROData_LandCoverMap::Iterator anIt( aMap );
100 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
101 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
103 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
104 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
106 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
111 void test_HYDROData_LandCoverMap::test_incomplete_split()
113 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
115 Handle(HYDROData_LandCoverMap) aMap =
116 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
118 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
120 TopoDS_Face aLC = Face( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
121 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC, "test1" ) );
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 );
128 CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
130 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
131 TestViewer::show( aWire, 0, true, Qt::green );
132 CPPUNIT_ASSERT_IMAGES
134 HYDROData_LandCoverMap::Iterator anIt( aMap );
135 CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
136 CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
138 CPPUNIT_ASSERT_EQUAL( false, anIt.More() );
143 void test_HYDROData_LandCoverMap::test_merge()
145 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
147 Handle(HYDROData_LandCoverMap) aMap =
148 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
150 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
152 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
154 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
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 <<
160 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
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" ) );
166 //TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
167 //TestViewer::AssertEqual( "LandCoverMap_Before_Merge" );
169 //BRepTools::Write( aMap->GetShape(), "c:\\map.brep" );
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" ) );
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
188 void test_HYDROData_LandCoverMap::test_remove()
190 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
192 Handle(HYDROData_LandCoverMap) aMap =
193 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
195 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
197 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
199 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
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 <<
205 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
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" ) );
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 ) );
219 TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
220 CPPUNIT_ASSERT_IMAGES
225 void test_HYDROData_LandCoverMap::test_merge_faces_boxes()
227 TopoDS_Shape pp1, pp2, pp3, pp4;
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);
234 CPPUNIT_ASSERT(!pp1.IsNull());
235 CPPUNIT_ASSERT(!pp2.IsNull());
236 CPPUNIT_ASSERT(!pp3.IsNull());
237 CPPUNIT_ASSERT(!pp4.IsNull());
239 //Test mergeFaces() func // boxes // USD == true
241 TopTools_ListOfShape Faces;
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);
250 TopTools_ListOfShape Faces;
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);
259 TopTools_ListOfShape Faces;
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);
269 TopTools_ListOfShape Faces;
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);
281 //Test mergeFaces() func // boxes // USD == false
283 TopTools_ListOfShape Faces;
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);
292 TopTools_ListOfShape Faces;
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);
301 TopTools_ListOfShape Faces;
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);
311 TopTools_ListOfShape Faces;
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);
324 void test_HYDROData_LandCoverMap::test_merge_faces_circles()
326 TopoDS_Shape ff1, ff2, ff3;
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);
332 CPPUNIT_ASSERT(!ff1.IsNull());
333 CPPUNIT_ASSERT(!ff2.IsNull());
334 CPPUNIT_ASSERT(!ff3.IsNull());
336 //Test mergeFaces() func // circles // USD == true
338 TopTools_ListOfShape Faces;
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);
347 TopTools_ListOfShape Faces;
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);
356 TopTools_ListOfShape Faces;
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);
366 TopTools_ListOfShape Faces;
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);
377 //Test mergeFaces() func // circles // USD == false
379 TopTools_ListOfShape Faces;
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);
388 TopTools_ListOfShape Faces;
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);
397 TopTools_ListOfShape Faces;
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);
407 TopTools_ListOfShape Faces;
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);
418 void test_HYDROData_LandCoverMap::test_import_dbf()
420 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
422 Handle(HYDROData_LandCoverMap) aMap =
423 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
425 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
426 QString aFileName = REF_DATA_PATH + "/t1.dbf";
433 aST.append("forest");
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" ) );
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 );
450 CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() );
452 CPPUNIT_ASSERT_EQUAL( QString( "road" ), anIt.StricklerType() );
457 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_types()
459 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
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 ) );
465 Handle(HYDROData_LandCoverMap) aMap =
466 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
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" ) );
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 <<
475 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
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" ) );
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
493 void test_HYDROData_LandCoverMap::test_land_cover_prs_by_coeff()
495 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
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 ) );
501 Handle(HYDROData_LandCoverMap) aMap =
502 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
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" ) );
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 <<
511 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "Zones de champs cultivé à végétation haute" ) );
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" ) );
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
523 TestViewer::showColorScale( false );
527 void test_HYDROData_LandCoverMap::test_dump_python()
529 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
531 Handle(HYDROData_LandCoverMap) aMap =
532 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
533 aMap->SetName( "test_LCM" );
535 CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
537 TopoDS_Face aLC1 = Face( QList<double>() << 12 << 19 << 82 << 9 << 126 << 53 << 107 << 80 << 29 << 75 );
539 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
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 <<
545 CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
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" ) );
551 QString aTmpPath = QDir::tempPath() + "/lc_dump.py";
552 CPPUNIT_ASSERT_EQUAL( true, aDoc->DumpToPython( aTmpPath, false ) );
554 //TODO: compare files
559 void test_HYDROData_LandCoverMap::test_transparent_prs()
561 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
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 ) );
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 ) );
575 Handle(HYDROData_ImmersibleZone) aZone =
576 Handle(HYDROData_ImmersibleZone)::DownCast( aDoc->CreateObject( KIND_IMMERSIBLE_ZONE ) );
577 aZone->SetPolyline( aPoly );
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" );
586 TestViewer::show( aZone->GetTopShape(), AIS_Shaded, true, "LandCoverMap_TransparentPrs" );
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, "" );
593 CPPUNIT_ASSERT_IMAGES
597 void test_HYDROData_LandCoverMap::test_add_triangles()
599 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
601 Handle(HYDROData_PolylineXY) Polyline_1 =
602 Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
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();
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();
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();
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();
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();
648 Handle(HYDROData_LandCoverMap) aMap =
649 Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
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, "" ) );
655 Handle(HYDROGUI_LandCoverMapPrs) aPrs = new HYDROGUI_LandCoverMapPrs( aMap );
656 TestViewer::show( aPrs, AIS_Shaded, 0, true, "LandCover_Triangles" );
657 CPPUNIT_ASSERT_IMAGES
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
667 void test_HYDROData_LandCoverMap::test_assign_to_calc_case()
669 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
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 ) );
676 aCalcCase->SetLandCoverMap( aMap );
677 CPPUNIT_ASSERT_EQUAL( aMap->myLab, aCalcCase->GetLandCoverMap()->myLab );