Salome HOME
code revision for Linux
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_LandCoverMap.cxx
index 5168523c47438fef7edfb53a01fcd836db7952b3..e1589b7b13e913c608eb996b7b91eacb58460908 100644 (file)
@@ -36,6 +36,9 @@
 #include <QColor>
 
 #include <BRepTools.hxx>
+#include <BRep_Builder.hxx>
+
+const QString REF_DATA_PATH = qgetenv( "HYDRO_REFERENCE_DATA" );
 
 TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
 {
@@ -86,8 +89,8 @@ void test_HYDROData_LandCoverMap::test_add_2_objects()
   TopoDS_Face aLC2 = LandCover( QList<double>() << 30 << 20 << 60 << 10 << 70 << 35 << 40 << 40 );
   CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC2, "test2" ) );
 
-  TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
-  TestViewer::AssertEqual( "LandCoverMap_Add_2_Objects" );
+  TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Add_2_Objects" );
+  CPPUNIT_ASSERT_IMAGES
 
   HYDROData_LandCoverMap::Iterator anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
@@ -120,9 +123,9 @@ void test_HYDROData_LandCoverMap::test_split()
 
   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
 
-  TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
-  TestViewer::show( aWire, QColor(), 0 );
-  TestViewer::AssertEqual( "LandCoverMap_Split_1" );
+  TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_1" );
+  TestViewer::show( aWire, 0, true, Qt::blue );
+  CPPUNIT_ASSERT_IMAGES
 
   HYDROData_LandCoverMap::Iterator anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
@@ -155,9 +158,9 @@ void test_HYDROData_LandCoverMap::test_incomplete_split()
 
   CPPUNIT_ASSERT_EQUAL( true, aMap->Split( aPolyline ) );
 
-  TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
-  TestViewer::show( aWire, QColor(), 0 );
-  TestViewer::AssertEqual( "LandCoverMap_Split_2" );
+  TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Split_2" );
+  TestViewer::show( aWire, 0, true, Qt::blue );
+  CPPUNIT_ASSERT_IMAGES
 
   HYDROData_LandCoverMap::Iterator anIt( aMap );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
@@ -206,10 +209,9 @@ void test_HYDROData_LandCoverMap::test_merge()
   aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
   CPPUNIT_ASSERT_EQUAL( true, aMap->Merge( aList, "new" ) );
 
-
-  TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
+  TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Merge_1" );
   //TestViewer::show( BRepBuilderAPI_MakeEdge( gp_Pnt(aPnt1.X(), aPnt1.Y(), 0), gp_Pnt(aPnt2.X(), aPnt2.Y(), 0) ).Edge(), QColor( Qt::blue ), AIS_Shaded );
-  TestViewer::AssertEqual( "LandCoverMap_Merge_1" );
+  CPPUNIT_ASSERT_IMAGES
 
   aDoc->Close();
 }
@@ -245,8 +247,106 @@ void test_HYDROData_LandCoverMap::test_remove()
   aList.Append( aMap->FindByPoint( aPnt2, aType2 ) );
   CPPUNIT_ASSERT_EQUAL( true, aMap->Remove( aList ) );
 
-  TestViewer::show( aMap->GetShape(), AIS_Shaded, true );
-  TestViewer::AssertEqual( "LandCoverMap_Remove_1" );
+  TestViewer::show( aMap->GetShape(), AIS_Shaded, true, "LandCoverMap_Remove_1" );
+  CPPUNIT_ASSERT_IMAGES
 
   aDoc->Close();
 }
+
+void test_HYDROData_LandCoverMap::test_merge_faces()
+{
+  TopoDS_Shape pp1, pp2, pp3, pp4;
+  BRep_Builder BB;
+  BRepTools::Read(pp1, (REF_DATA_PATH + "/pp1.brep").toStdString().c_str(), BB);
+  BRepTools::Read(pp2, (REF_DATA_PATH + "/pp2.brep").toStdString().c_str(), BB);
+  BRepTools::Read(pp3, (REF_DATA_PATH + "/pp3.brep").toStdString().c_str(), BB);
+  BRepTools::Read(pp4, (REF_DATA_PATH + "/pp4.brep").toStdString().c_str(), BB);
+
+  CPPUNIT_ASSERT(!pp1.IsNull());
+  CPPUNIT_ASSERT(!pp2.IsNull());
+  CPPUNIT_ASSERT(!pp3.IsNull());
+  CPPUNIT_ASSERT(!pp4.IsNull());
+
+  //Test mergeFaces() func; USD == true
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp2);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs11" );
+    CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
+  }
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp3);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs12" );
+    CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
+  }
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp2);
+    Faces.Append(pp4);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs13" );
+    CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
+  }
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp3);
+    Faces.Append(pp4);
+    Faces.Append(pp2);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, true );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs14" );
+    CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_FACE);
+  }
+  //
+
+  //Test mergeFaces() func; USD == false
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp2);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs21" );
+    CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
+  }
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp3);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs22" );
+    CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
+  }
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp2);
+    Faces.Append(pp4);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs23" );
+   CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
+  }
+  {
+    TopTools_ListOfShape Faces;
+    Faces.Append(pp1);
+    Faces.Append(pp3);
+    Faces.Append(pp4);
+    Faces.Append(pp2);
+    TopoDS_Shape aMergedFace = HYDROData_LandCoverMap::MergeFaces( Faces, false );
+    TestViewer::show( aMergedFace, AIS_Shaded, true, "cs24" );
+    CPPUNIT_ASSERT_IMAGES
+    CPPUNIT_ASSERT(aMergedFace.ShapeType() == TopAbs_SHELL);
+  }
+}