Salome HOME
TShell cannot be disconnected; use TCompound of shells/faces instead
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_LandCoverMap.cxx
index 2cb5dead698d3bd5a70225e65891b0cb008c7193..d4da4adba918cdfee33a94e49c709524dd6b132d 100644 (file)
 #include <HYDROData_PolylineXY.h>
 #include <HYDROData_StricklerTable.h>
 #include <HYDROData_Tool.h>
+#include <HYDROData_ShapeFile.h>
 #include <HYDROGUI_LandCoverMapPrs.h>
 #include <TopoDS_Edge.hxx>
 #include <TopoDS_Wire.hxx>
 #include <TopoDS_Face.hxx>
+#include <TopoDS.hxx>
 #include <TestViewer.h>
 #include <TestShape.h>
 #include <TopTools_ListOfShape.hxx>
@@ -39,6 +41,7 @@
 #include <QDir>
 #include <BRepTools.hxx>
 #include <BRep_Builder.hxx>
+#include <BRepCheck_Analyzer.hxx>
 
 const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
 const QString DEF_STR_PATH = qgetenv( "HYDRO_SRC_DIR" ) + "/src/HYDROGUI/resources/def_strickler_table.txt";
@@ -61,7 +64,7 @@ void test_HYDROData_LandCoverMap::test_add_2_objects()
   TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
   CPPUNIT_ASSERT_IMAGES
 
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
   anIt.Next();
@@ -96,7 +99,7 @@ void test_HYDROData_LandCoverMap::test_split()
   TestViewer::show( aWire, 0, true, Qt::blue );
   CPPUNIT_ASSERT_IMAGES
 
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
   anIt.Next();
@@ -131,7 +134,7 @@ void test_HYDROData_LandCoverMap::test_incomplete_split()
   TestViewer::show( aWire, 0, true, Qt::green );
   CPPUNIT_ASSERT_IMAGES
 
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
   CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.StricklerType() );
   anIt.Next();
@@ -445,7 +448,7 @@ void test_HYDROData_LandCoverMap::test_import_dbf()
   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
   QList<int> Inds = QList<int>() << 1 << 2 << 3;
   aMap->ImportDBF(aFileName, "TESTFIELD1", aDBFV, aST, Inds);
-  HYDROData_LandCoverMap::Iterator anIt( aMap );
+  HYDROData_LandCoverMap::Explorer anIt( aMap );
  
   CPPUNIT_ASSERT_EQUAL( QString( "forest" ), anIt.StricklerType() );
   anIt.Next();
@@ -678,3 +681,265 @@ void test_HYDROData_LandCoverMap::test_assign_to_calc_case()
 
   aDoc->Close();
 }
+
+void test_HYDROData_LandCoverMap::test_shp_import_cyp()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  QString aFileName = REF_DATA_PATH + "/cyprus_natural.shp";
+  HYDROData_ShapeFile anImporter;
+  QStringList PolygonList;
+  TopTools_SequenceOfShape PolygonFaces;
+  int Type = -1;
+  int aStat = anImporter.ImportPolygons(aFileName, PolygonList, PolygonFaces, Type);
+  CPPUNIT_ASSERT(aStat == 1);
+  CPPUNIT_ASSERT_EQUAL(5, Type);
+  CPPUNIT_ASSERT_EQUAL(268, PolygonFaces.Length());
+  
+  Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+  HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+  for ( int i = 1; i <= PolygonFaces.Length(); i++ )
+  {
+    TopoDS_Shape aShape = PolygonFaces(i);
+    if ( aShape.IsNull() ) 
+      continue;
+    aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+  }
+
+  LCM->StoreLandCovers(aMapFace2ST);
+  TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "cyprus_natural_all" );
+  CPPUNIT_ASSERT_IMAGES
+  aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_shp_import_clc_dec()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  QString aFileName = REF_DATA_PATH + "/CLC_decoupe.shp";
+  HYDROData_ShapeFile anImporter;
+  QStringList PolygonList;
+  TopTools_SequenceOfShape PolygonFaces;
+  int Type = -1;
+  int aStat = anImporter.ImportPolygons(aFileName, PolygonList, PolygonFaces, Type);
+  CPPUNIT_ASSERT(aStat == 1);
+  CPPUNIT_ASSERT_EQUAL(5, Type);
+  CPPUNIT_ASSERT_EQUAL(625, PolygonFaces.Length());
+  
+  Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+  HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+  for ( int i = 150; i <= 350; i++ )
+  {
+    TopoDS_Shape aShape = PolygonFaces(i);
+    if ( aShape.IsNull() ) 
+      continue;
+    aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+  }
+
+  LCM->StoreLandCovers(aMapFace2ST);
+  TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "clc_dec_150_350" );
+  CPPUNIT_ASSERT_IMAGES
+  aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_shp_import_nld_areas()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+  QString aFileName = REF_DATA_PATH + "/NLD_water_areas_dcw.shp";
+  HYDROData_ShapeFile anImporter;
+  QStringList PolygonList;
+  TopTools_SequenceOfShape PolygonFaces;
+  int Type = -1;
+  int aStat = anImporter.ImportPolygons(aFileName, PolygonList, PolygonFaces, Type);
+  CPPUNIT_ASSERT(aStat == 1);
+  CPPUNIT_ASSERT_EQUAL(5, Type);
+  CPPUNIT_ASSERT_EQUAL(127, PolygonFaces.Length());
+  
+  Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+  HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+  for ( int i = 1; i <= PolygonFaces.Length(); i++ )
+  {
+    TopoDS_Shape aShape = PolygonFaces(i);
+    if ( aShape.IsNull() ) 
+      continue;
+    aMapFace2ST.Add( TopoDS::Face( aShape ), "" );
+  }
+
+  LCM->StoreLandCovers(aMapFace2ST);
+  TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "NLD_water_areas_dcw" );
+  CPPUNIT_ASSERT_IMAGES
+  aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_shp_loop_back()
+{
+  QString aFFileName = REF_DATA_PATH + "/CLC06-cut_1.shp";
+  QString aSFileName = REF_DATA_PATH + "/CLC06-cut_1_res.shp";
+  //This test verify only some geom data (shp+shx) without any dbf reading/writing 
+  {
+    Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+    HYDROData_ShapeFile anImporter;
+    QStringList PolygonList;
+    TopTools_SequenceOfShape PolygonFaces;
+    int Type = -1;
+
+    //import LCM from file (#2-4; #12-14 polygons)
+    CPPUNIT_ASSERT( anImporter.ImportPolygons(aFFileName, PolygonList, PolygonFaces, Type));
+    Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+    HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+
+    aMapFace2ST.Add( TopoDS::Face( PolygonFaces(2) ), "" );
+    aMapFace2ST.Add( TopoDS::Face( PolygonFaces(3) ), "" );
+    aMapFace2ST.Add( TopoDS::Face( PolygonFaces(4) ), "" );
+    aMapFace2ST.Add( TopoDS::Face( PolygonFaces(12) ), "" );
+    aMapFace2ST.Add( TopoDS::Face( PolygonFaces(13) ), "" );
+    aMapFace2ST.Add( TopoDS::Face( PolygonFaces(14) ), "" );
+
+    LCM->StoreLandCovers(aMapFace2ST);
+    LCM->SetName("lcm_1");
+
+    TopoDS_Shape aSh = LCM->GetShape();
+    BRepCheck_Analyzer aBCA(aSh);
+    CPPUNIT_ASSERT(aBCA.IsValid());
+
+    //export lcm
+    HYDROData_ShapeFile anExporter;
+    QStringList aNonExpList;
+    anExporter.Export(aSFileName, LCM, aNonExpList);
+    CPPUNIT_ASSERT (aNonExpList.empty());
+
+    aDoc->Close();
+  }
+  {
+    Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+    HYDROData_ShapeFile anImporter;
+    QStringList PolygonList;
+    TopTools_SequenceOfShape PolygonFaces;
+    int Type = -1;
+
+    //import all
+    CPPUNIT_ASSERT( anImporter.ImportPolygons(aSFileName, PolygonList, PolygonFaces, Type));
+    Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+    HYDROData_MapOfFaceToStricklerType aMapFace2ST;
+    CPPUNIT_ASSERT_EQUAL(PolygonFaces.Length(), 6);
+    for ( int i = 1; i <= PolygonFaces.Length(); i++ )
+      aMapFace2ST.Add( TopoDS::Face( PolygonFaces(i) ), "" );
+
+    LCM->StoreLandCovers(aMapFace2ST);
+    LCM->SetName("lcm_2");
+
+    TopoDS_Shape OutSh = LCM->GetShape();
+    BRepCheck_Analyzer aBCA(OutSh);
+    CPPUNIT_ASSERT(aBCA.IsValid());
+
+    TestViewer::show( OutSh, AIS_Shaded, true, "CLC06-cut_1_res" );
+    CPPUNIT_ASSERT_IMAGES
+
+    aDoc->Close();
+  }
+  CPPUNIT_ASSERT_EQUAL(0, remove(aSFileName.toStdString().c_str()));
+}
+
+void test_HYDROData_LandCoverMap::test_add_2_section_poly()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+
+  Handle(HYDROData_PolylineXY) Polyline_12 =
+    Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  Polyline_12->SetName( "Polyline_12" );
+
+  Polyline_12->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
+  Polyline_12->AddPoint( 0, gp_XY( -148.70, 145.68 ) );
+  Polyline_12->AddPoint( 0, gp_XY( -81.71, 210.97 ) );
+  Polyline_12->AddPoint( 0, gp_XY( -21.09, 122.79 ) );
+  Polyline_12->AddPoint( 0, gp_XY( -106.30, 102.44 ) );
+  Polyline_12->AddSection( "Section_2", HYDROData_PolylineXY::SECTION_POLYLINE, true );
+  Polyline_12->AddPoint( 1, gp_XY( -7.09, 227.08 ) );
+  Polyline_12->AddPoint( 1, gp_XY( 46.32, 228.78 ) );
+  Polyline_12->AddPoint( 1, gp_XY( 69.64, 165.61 ) );
+  Polyline_12->AddPoint( 1, gp_XY( 13.68, 156.28 ) );
+
+  Polyline_12->Update();
+
+  Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+  CPPUNIT_ASSERT_EQUAL( true, LCM->Add( Polyline_12, "" ) );
+
+  TestViewer::show( LCM->GetShape(), AIS_Shaded, true, "lcm_poly_2_sections" );
+  CPPUNIT_ASSERT_IMAGES
+
+  aDoc->Close();
+}
+
+void test_HYDROData_LandCoverMap::test_split_2()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 );
+
+  Handle(HYDROData_PolylineXY) Polyline_1 =
+    Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  Polyline_1->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
+  Polyline_1->AddPoint( 0, gp_XY( -264.84, 323.44 ) );
+  Polyline_1->AddPoint( 0, gp_XY( 254.45, 301.19 ) );
+  Polyline_1->AddPoint( 0, gp_XY( -291.54, -47.48 ) );
+  Polyline_1->Update();
+
+  Handle(HYDROData_PolylineXY) Polyline_6 =
+    Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  Polyline_6->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
+  Polyline_6->AddPoint( 0, gp_XY( -155.15, 199.47 ) );
+  Polyline_6->AddPoint( 0, gp_XY( -71.19, 289.12 ) );
+  Polyline_6->AddPoint( 0, gp_XY( 22.01, 211.57 ) );
+  Polyline_6->AddPoint( 0, gp_XY( -84.00, 134.73 ) );
+  Polyline_6->Update();
+
+  Handle(HYDROData_PolylineXY) Polyline_7 =
+    Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  Polyline_7->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
+  Polyline_7->AddPoint( 0, gp_XY( -50.56, 232.20 ) );
+  Polyline_7->AddPoint( 0, gp_XY( 40.51, 286.98 ) );
+  Polyline_7->AddPoint( 0, gp_XY( 118.77, 256.39 ) );
+  Polyline_7->AddPoint( 0, gp_XY( 72.52, 114.10 ) );
+  Polyline_7->Update();
+
+  Handle(HYDROData_PolylineXY) Polyline_8 =
+    Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  Polyline_8->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, true );
+  Polyline_8->AddPoint( 0, gp_XY( -44.16, 190.93 ) );
+  Polyline_8->AddPoint( 0, gp_XY( 9.91, 226.51 ) );
+  Polyline_8->AddPoint( 0, gp_XY( 35.53, 175.99 ) );
+  Polyline_8->AddPoint( 0, gp_XY( -9.30, 157.50 ) );
+  Polyline_8->Update();
+
+  Handle(HYDROData_PolylineXY) Polyline_9 =
+    Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) );
+  Polyline_9->AddSection( "Section_1", HYDROData_PolylineXY::SECTION_POLYLINE, false );
+  Polyline_9->AddPoint( 0, gp_XY( -103.92, 288.40 ) );
+  Polyline_9->AddPoint( 0, gp_XY( -100.09, 285.22 ) );
+  Polyline_9->AddPoint( 0, gp_XY( -96.10, 281.90 ) );
+  Polyline_9->AddPoint( 0, gp_XY( -90.43, 277.19 ) );
+  Polyline_9->AddPoint( 0, gp_XY( -53.41, 246.43 ) );
+  Polyline_9->AddPoint( 0, gp_XY( 10.62, 245.01 ) );
+
+
+  Polyline_9->Update();
+
+
+  Handle(HYDROData_LandCoverMap) LCM = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) );
+  CPPUNIT_ASSERT_EQUAL( true, LCM->Add( Polyline_1, "" ) );
+  CPPUNIT_ASSERT_EQUAL( true, LCM->Add( Polyline_6, "" ) );
+  CPPUNIT_ASSERT_EQUAL( true, LCM->Add( Polyline_7, "" ) );
+
+  CPPUNIT_ASSERT_EQUAL( true, LCM->Split( Polyline_9 ) );
+
+  //Handle(HYDROGUI_LandCoverMapPrs) aPrs1 = new HYDROGUI_LandCoverMapPrs( LCM );
+  TestViewer::show( LCM->GetShape(), AIS_Shaded, /*0,*/ true, "LCM_split_2a" );
+  CPPUNIT_ASSERT_IMAGES
+
+  CPPUNIT_ASSERT_EQUAL( true, LCM->Split( Polyline_8 ) );
+
+  // Handle(HYDROGUI_LandCoverMapPrs) aPrs2 = new HYDROGUI_LandCoverMapPrs( LCM );
+  TestViewer::show( LCM->GetShape(), AIS_Shaded, /*0,*/ true, "LCM_split_2b" );
+  CPPUNIT_ASSERT_IMAGES
+
+  aDoc->Close();
+}