Salome HOME
Correction for hydro_test
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_DTM.cxx
index 6fc2fb9f21c561c4576900a9f8836d03bb3e9cdc..453a315f6430750f93eea1a8a6aca68aca6b4b3d 100644 (file)
@@ -58,7 +58,7 @@ public:
     myD = d;
 
     int n = pp->VertexNumber();
-    
+
     for( int i=1; i<=n; i++ )
     {
       gp_Pnt pnt = pp->Vertice( i );
@@ -162,11 +162,11 @@ void test_HYDROData_DTM::test_creation()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
 
-  Handle(HYDROData_DTM) DTM = 
+  Handle(HYDROData_DTM) DTM =
     Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
 
   CPPUNIT_ASSERT_EQUAL( false, (bool)DTM.IsNull() );
-   
+
   aDoc->Close();
 }
 
@@ -174,13 +174,13 @@ void test_HYDROData_DTM::test_hydraulic_axis()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
 
-  Handle(HYDROData_Profile) aProfile1 = 
+  Handle(HYDROData_Profile) aProfile1 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
-  Handle(HYDROData_Profile) aProfile2 = 
+  Handle(HYDROData_Profile) aProfile2 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
-  Handle(HYDROData_Profile) aProfile3 = 
+  Handle(HYDROData_Profile) aProfile3 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile1->SetParametricPoints( points );
@@ -227,10 +227,10 @@ void test_HYDROData_DTM::test_profile_conversion_to_2d()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
 
-  Handle(HYDROData_Profile) aProfile1 = 
+  Handle(HYDROData_Profile) aProfile1 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
-  Handle(HYDROData_Profile) aProfile2 = 
+  Handle(HYDROData_Profile) aProfile2 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile1->SetParametricPoints( points );
@@ -298,7 +298,7 @@ void test_HYDROData_DTM::test_profile_properties()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
 
-  Handle(HYDROData_Profile) aProfile = 
+  Handle(HYDROData_Profile) aProfile =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile->SetParametricPoints( points );
@@ -334,7 +334,7 @@ void test_HYDROData_DTM::test_profile_discretization_polyline()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
 
-  Handle(HYDROData_Profile) aProfile = 
+  Handle(HYDROData_Profile) aProfile =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile->SetParametricPoints( points );
@@ -373,7 +373,7 @@ void test_HYDROData_DTM::test_profile_discretization_spline()
 {
 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
 
-  Handle(HYDROData_Profile) aProfile = 
+  Handle(HYDROData_Profile) aProfile =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile->SetParametricPoints( points );
@@ -481,10 +481,10 @@ void test_HYDROData_DTM::test_curve_to_3d()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
 
-  Handle(HYDROData_Profile) aProfile1 = 
+  Handle(HYDROData_Profile) aProfile1 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
-  Handle(HYDROData_Profile) aProfile2 = 
+  Handle(HYDROData_Profile) aProfile2 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile1->SetParametricPoints( points );
@@ -527,10 +527,10 @@ void test_HYDROData_DTM::test_presentation()
 
   Handle(HYDROData_DTM) DTM = Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
 
-  Handle(HYDROData_Profile) aProfile1 = 
+  Handle(HYDROData_Profile) aProfile1 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
-  Handle(HYDROData_Profile) aProfile2 = 
+  Handle(HYDROData_Profile) aProfile2 =
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
 
   aProfile1->SetParametricPoints( points );
@@ -552,8 +552,8 @@ void test_HYDROData_DTM::test_presentation()
   DTM->SetSpatialStep( 1.0 );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
   DTM->Update();
-  
-  CPPUNIT_ASSERT_EQUAL( 9108, (int)DTM->GetAltitudePoints().size() ); 
+
+  CPPUNIT_ASSERT_EQUAL( 9108, (int)DTM->GetAltitudePoints().size() );
 
   Handle(AIS_InteractiveContext) aContext = TestViewer::context();
   HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
@@ -579,13 +579,13 @@ void test_HYDROData_DTM::test_presentation()
 void test_HYDROData_DTM::test_garonne()
 {
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
-  
+
   TCollection_AsciiString fname = REF_DATA_PATH.toLatin1().data();
   fname += "/Profiles.xyz";
   NCollection_Sequence<int> bad_ids;
 
   int aSize = HYDROData_Profile::ImportFromFile( aDoc, fname, bad_ids, true );
-  
+
   CPPUNIT_ASSERT_EQUAL( 0, bad_ids.Size() );
   CPPUNIT_ASSERT_EQUAL( 46, aSize );
 
@@ -606,14 +606,14 @@ void test_HYDROData_DTM::test_garonne()
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.1, DTM->GetDDZ(), EPS );
   CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, DTM->GetSpatialStep(), EPS );
   DTM->Update();
-  
-  CPPUNIT_ASSERT_EQUAL( 281898, (int)DTM->GetAltitudePoints().size() ); 
-  
+
+  CPPUNIT_ASSERT_EQUAL( 281898, (int)DTM->GetAltitudePoints().size() );
+
   Handle(AIS_InteractiveContext) aContext = TestViewer::context();
   HYDROGUI_ShapeBathymetry* aBathPrs = new HYDROGUI_ShapeBathymetry( 0, aContext, DTM );
   aBathPrs->update( true, false );
   aBathPrs->RescaleDefault();
-  
+
   bool ColorScaleIsDisp = TestViewer::ColorScaleIsDisplayed();
 
   TestViewer::showColorScale( true );
@@ -622,7 +622,7 @@ void test_HYDROData_DTM::test_garonne()
   aCS->SetMax( 25.0 );
   aCS->SetNumberOfIntervals( 30 );
   aBathPrs->UpdateWithColorScale( aCS );
-  
+
   QImage aDTMPrs = draw_DTM( aBathPrs, 0.5, 600, 600 );
   CPPUNIT_ASSERT_IMAGES3( &aDTMPrs, "DTM_2", false );
   TestViewer::showColorScale( ColorScaleIsDisp );
@@ -637,10 +637,10 @@ void test_HYDROData_DTM::test_classifier_1()
   CPPUNIT_ASSERT_EQUAL( (int)DocError_OK, (int)HYDROData_Document::Load( fname.ToCString() ) );
 
   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
-  
-  Handle(HYDROData_CalculationCase) aCase = 
+
+  Handle(HYDROData_CalculationCase) aCase =
     Handle(HYDROData_CalculationCase)::DownCast( aDoc->FindObjectByName( "Case_1" ) );
-  CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() ); 
+  CPPUNIT_ASSERT_EQUAL( false, aCase.IsNull() );
   std::vector<gp_XY> points;
   points.push_back( gp_XY( 43.4842, 3.33176  ) );
   points.push_back( gp_XY( -125.777, 2.24728 ) );
@@ -670,3 +670,82 @@ void test_HYDROData_DTM::test_classifier_1()
   aDoc->Close();
 }
 
+void test_HYDROData_DTM::test_profile_discretization_warnings()
+{
+  Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
+
+  {
+    Handle(HYDROData_Profile) aProfile =
+      Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+    NCollection_Sequence<gp_XY> pnts;
+    pnts.Append( gp_XY( 0.0, 1.0 ) );
+    pnts.Append( gp_XY( 1.0, 0.0 ) );
+    pnts.Append( gp_XY( 2.0, 4.0 ) );
+    pnts.Append( gp_XY( 3.0, 5.0 ) );
+
+    aProfile->SetParametricPoints( pnts );
+    aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+    aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
+    aProfile->SetRightPoint( gp_XY( 10, 20 ) );
+
+    HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
+    int dummy = 0;
+    QSet<QString> warnings;
+    HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
+
+    //CPPUNIT_ASSERT_EQUAL(1, warnings.size());
+    CPPUNIT_ASSERT( warnings.contains("One of the extreme points is higher than another"));
+  }
+  {
+    Handle(HYDROData_Profile) aProfile =
+      Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+    NCollection_Sequence<gp_XY> pnts;
+    pnts.Append( gp_XY( 0.0, 1.0 ) );
+    pnts.Append( gp_XY( 1.0, 0.0 ) );
+    pnts.Append( gp_XY( 2.0, 5.0 ) );
+    pnts.Append( gp_XY( 3.0, 0.0 ) );
+    pnts.Append( gp_XY( 4.0, 1.0 ) );
+
+    aProfile->SetParametricPoints( pnts );
+    aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+    aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
+    aProfile->SetRightPoint( gp_XY( 10, 20 ) );
+
+    HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
+    int dummy = 0;
+    QSet<QString> warnings;
+    HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
+
+    CPPUNIT_ASSERT_EQUAL(1, warnings.size());
+    CPPUNIT_ASSERT( warnings.contains("More than 2 intersections between profile & altitude Z-lines found"));
+  }
+  {
+    //plato case
+    Handle(HYDROData_Profile) aProfile =
+      Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
+
+    NCollection_Sequence<gp_XY> pnts;
+    pnts.Append( gp_XY( 0.0, 5.0 ) );
+    pnts.Append( gp_XY( 1.0, 5.0 ) );
+    pnts.Append( gp_XY( 2.0, 0.5 ) );
+    pnts.Append( gp_XY( 3.0, 5.0 ) );
+    pnts.Append( gp_XY( 4.0, 5.0 ) );
+
+    aProfile->SetParametricPoints( pnts );
+    aProfile->GetProfileUZ()->SetSectionType( 0, HYDROData_IPolyline::SECTION_POLYLINE );
+    aProfile->SetLeftPoint( gp_XY( 10, 10 ) );
+    aProfile->SetRightPoint( gp_XY( 10, 20 ) );
+
+    HYDROData_DTM::CurveUZ aMid( 0.0, gp_Vec2d(), 0, 0 ), aWid( 0.0, gp_Vec2d(), 0, 0 );
+    int dummy = 0;
+    QSet<QString> warnings;
+    HYDROData_DTM::ProfileDiscretization( aProfile, 0.0, 0.0, 5.0, 5.0, 0.5, aMid, aWid, dummy, 1E-6, warnings );
+
+    CPPUNIT_ASSERT_EQUAL(2, warnings.size());
+    CPPUNIT_ASSERT( warnings.contains("Plato case on extremes"));
+  }
+
+  aDoc->Close();
+}