Salome HOME
custom test runner to run only a subset of complete test suite
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_LandCoverMap.cxx
index d81d898cbde80314654c6428804792b73e989c11..aa9135f47f6073a29ae4445688e8c170dc80f201 100644 (file)
 #include <HYDROData_Document.h>
 #include <HYDROData_LandCoverMap.h>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS_Wire.hxx>
+#include <TopoDS_Face.hxx>
 #include <TColgp_HArray1OfPnt.hxx>
 #include <GeomAPI_Interpolate.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
-#include <stdarg.h>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <TestViewer.h>
+#include <AIS_DisplayMode.hxx>
+#include <QString>
 
-TopoDS_Edge Spline( bool isClosed, double x, double y, ... )
+TopoDS_Edge Spline( const QList<double>& theXYList, bool isClosed = false )
 {
-  va_list anArgs;
-  va_start( anArgs, y );
-  QList<gp_Pnt> aPointsList;
-  while( true )
+  int n = theXYList.size()/2;
+  Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
+  for( int i=1; i<=n; i++ )
   {
-    double x = va_arg( anArgs, double );
-    if( x <= 0 )
-      break;
-    double y = va_arg( anArgs, double );
+    double x = theXYList[2*i-2];
+    double y = theXYList[2*i-1];
     gp_Pnt aPnt( x, y, 0 );
-    aPointsList.append( aPnt );
+    aPointsArray->SetValue( i, aPnt );
   }
-  va_end( anArgs );
-
-  int n = aPointsList.size();
-  Handle(TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt( 1, n );
-  for( int i=1; i<=n; i++ )
-    aPointsArray->SetValue( i, aPointsList[i-1] );
-
   GeomAPI_Interpolate anInterpolator( aPointsArray, isClosed, 1E-3 );
   anInterpolator.Perform();
   bool aResult = anInterpolator.IsDone() == Standard_True;
@@ -58,6 +54,17 @@ TopoDS_Edge Spline( bool isClosed, double x, double y, ... )
     return TopoDS_Edge();
 }
 
+TopoDS_Face LandCover( const QList<double>& theXYList )
+{
+  TopoDS_Edge anEdge = Spline( theXYList, true );
+  if( anEdge.IsNull() )
+    return TopoDS_Face();
+
+  TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
+  TopoDS_Face aFace = BRepBuilderAPI_MakeFace( aWire, Standard_True ).Face();
+  return aFace;
+}
+
 void test_HYDROData_LandCoverMap::test_local_partition()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
@@ -67,7 +74,14 @@ void test_HYDROData_LandCoverMap::test_local_partition()
 
   CPPUNIT_ASSERT_EQUAL( KIND_LAND_COVER_MAP, aMap->GetKind() );
 
+  TopoDS_Face aLC1 = LandCover( QList<double>() << 10 << 10 << 50 << 20 << 30 << 50 << 15 << 30 );
+  CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC1, "test1" ) );
+
+  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" );
 
   aDoc->Close();
 }