Salome HOME
minor code review
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_PolylineXY.cxx
index 9ec336c1c6f70693c60f38104b8c93b01d2dd349..9b505914aaab94221c889a1aaf82577b0432e060 100644 (file)
@@ -27,6 +27,7 @@
 #include <HYDROData_Iterator.h>
 #include <HYDROData_ImmersibleZone.h>
 #include <HYDROData_Tool.h>
+#include <HYDROGUI_Shape.h>
 #include <HYDROGUI_Polyline.h>
 
 #include <AIS_DisplayMode.hxx>
@@ -37,6 +38,7 @@
 #include <QColor>
 #include <QList>
 #include <QPointF>
+#include <QTest>
 
 #include <TestShape.h>
 #include <TestViewer.h>
@@ -102,7 +104,7 @@ void test_HYDROData_PolylineXY::test_split_refs_624()
   aPolyline->SetName( "test" );
 
   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
-  TopoDS_Wire aWire = Wire( aCoords, true );
+  TopoDS_Wire aWire = Wire2d( aCoords, true );
   aPolyline->SetShape( aWire );
 
   gp_Pnt2d aPnt( 20, 20 );
@@ -135,7 +137,7 @@ void test_HYDROData_PolylineXY::test_extraction_immersible_zone()
   aPolyline->SetName( "test" );
 
   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
-  TopoDS_Wire aWire = Wire( aCoords, true );
+  TopoDS_Wire aWire = Wire2d( aCoords, true );
   aPolyline->SetShape( aWire );
 
   Handle(HYDROData_ImmersibleZone) aZone = 
@@ -175,7 +177,7 @@ void test_HYDROData_PolylineXY::test_extraction_channel_refs_611()
   aPolyline3d->SetPolylineXY( aPolyline2d );
 
   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
-  TopoDS_Wire aWire = Wire( aCoords, false );
+  TopoDS_Wire aWire = Wire2d( aCoords, false );
   aPolyline2d->SetShape( aWire );
   aPolyline3d->SetTopShape( aWire );
   aPolyline3d->SetShape3D( aWire );
@@ -184,8 +186,8 @@ void test_HYDROData_PolylineXY::test_extraction_channel_refs_611()
     Handle(HYDROData_Profile)::DownCast( aDoc->CreateObject( KIND_PROFILE ) );
   aProfile->SetName( "profile_1" );
 
-  QList<double> aCoordsPr = QList<double>() << 0.0 << 0.1 << 0.5 << 0.0 << 1.0 << 0.1;
-  TopoDS_Wire aWirePr = Wire( aCoordsPr, false );
+  QList<double> aCoordsPr = QList<double>() << 0.0 << 0.1 << 0.0 << 0.0 << 1.0 << 0.0;
+  TopoDS_Wire aWirePr = Wire3d( aCoordsPr, false );
   aProfile->SetTopShape( aWirePr );
   aProfile->SetShape3D( aWirePr );
 
@@ -253,14 +255,40 @@ void test_HYDROData_PolylineXY::test_presentation()
   aPointsPrs->SetColor( Quantity_NOC_BLUE1 );
   aPointsPrs->Attributes()->PointAspect()->SetTypeOfMarker( Aspect_TOM_O );
 
-  Handle(HYDROGUI_Polyline) aNewPolylinePrs = new HYDROGUI_Polyline( aPolyline2d->GetShape() );
-  aNewPolylinePrs->SetColor( Quantity_NOC_DARKGREEN );
+  aPolyline2d->SetWireColor( Qt::darkGreen );
+  HYDROGUI_Shape* aNewPolylinePrs = new HYDROGUI_Shape( TestViewer::context(), aPolyline2d );
+  aNewPolylinePrs->update( true, true );
 
+
+  // Check default type
+  Handle(HYDROGUI_Arrow) arr = Handle(HYDROGUI_Arrow)::DownCast( aNewPolylinePrs->getAISObjects()[1] );
+  CPPUNIT_ASSERT_EQUAL( HYDROGUI_Arrow::Cone, arr->GetType() );
+  CPPUNIT_ASSERT_EQUAL( 35, arr->GetSize() );
+
+  
+  // Check polyline presentation with default (cone) arrow
+  TestViewer::eraseAll(true);
   TestViewer::show( aPointsPrs, AIS_PointCloud::DM_Points, 0, true, "Polyline_Presentation" );
   TestViewer::show( aPolyline2d->GetShape(), 0, true, Qt::red );
-  TestViewer::show( aNewPolylinePrs, AIS_PointCloud::DM_Points, 0, true, "" );
+  //TestViewer::show( aNewPolylinePrs, AIS_PointCloud::DM_Points, 0, true, "" );
+  aNewPolylinePrs->setBorderColor( Qt::blue );
+  aNewPolylinePrs->display();
+  TestViewer::fitAll();
+  CPPUNIT_ASSERT_IMAGES
+
+
+  // Check polyline presentation with triangle arrow
+  arr->SetType( HYDROGUI_Arrow::Triangle );
+  TestViewer::eraseAll(true);
+  TestViewer::show( aPointsPrs, AIS_PointCloud::DM_Points, 0, true, "Polyline_Presentation_triangle" );
+  TestViewer::show( aPolyline2d->GetShape(), 0, true, Qt::red );
+  //TestViewer::show( aNewPolylinePrs, AIS_PointCloud::DM_Points, 0, true, "" );
+  TestViewer::context()->RecomputePrsOnly( arr );
+  aNewPolylinePrs->display();
+  TestViewer::fitAll();
   CPPUNIT_ASSERT_IMAGES
 
+  //QTest::qWait( 50000 );  
   aDoc->Close();
 }
 
@@ -273,7 +301,7 @@ void test_HYDROData_PolylineXY::test_split_refs_627()
   aPolyline->SetName( "test" );
 
   QList<double> aCoords = QList<double>() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20;
-  TopoDS_Wire aWire = Wire( aCoords, false );
+  TopoDS_Wire aWire = Wire2d( aCoords, false );
   aPolyline->SetShape( aWire );
   aPolyline->SetWireColor( Qt::red );
 
@@ -338,34 +366,34 @@ void test_HYDROData_PolylineXY::test_custom_polylines()
   CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() );
 
   CPPUNIT_ASSERT_EQUAL( false, aPolyline2->IsCustom() );
-  aPolyline2->SetShape( Wire( QList<double>() << 0 << 0 << 1 << 1 << 2 << 0 ) );
+  aPolyline2->SetShape( Wire2d( QList<double>() << 0 << 0 << 10 << 10 << 20 << 0 ) );
   CPPUNIT_ASSERT_EQUAL( true, aPolyline2->IsCustom() );
   HYDROData_PolylineXY::PointsList aPointsList = aPolyline2->GetPoints( 0 );
 
   CPPUNIT_ASSERT_EQUAL( false, aPolyline2->IsCustom() );
-  CPPUNIT_ASSERT_EQUAL( 33, aPointsList.Size() );
+  CPPUNIT_ASSERT_EQUAL( 5, aPointsList.Size() );
   CPPUNIT_ASSERT_EQUAL( gp_XY( 0, 0 ), aPointsList.Value( 1 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( 0.5625, 0.808594 ), aPointsList.Value( 10 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( 1.1875, 0.964844 ), aPointsList.Value( 20 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( 2, 0 ), aPointsList.Value( 33 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( 5, 7.5 ), aPointsList.Value( 2 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( 10, 10 ), aPointsList.Value( 3 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( 15, 7.5 ), aPointsList.Value( 4 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( 20, 0 ), aPointsList.Value( 5 ) );
 
 
   CPPUNIT_ASSERT_EQUAL( false, aPolyline3->IsCustom() );
-  aPolyline3->SetShape( WireCirc( gp_Pnt(), 1.0 ) );
+  aPolyline3->SetShape( WireCirc( gp_Pnt(), 10.0 ) );
   CPPUNIT_ASSERT_EQUAL( true, aPolyline3->IsCustom() );
   aPointsList = aPolyline3->GetPoints( 0 );
 
   CPPUNIT_ASSERT_EQUAL( HYDROData_PolylineXY::SECTION_SPLINE, aPolyline3->GetSectionType( 0 ) );
   CPPUNIT_ASSERT_EQUAL( true, aPolyline3->IsClosedSection( 0 ) );
-  CPPUNIT_ASSERT_EQUAL( 71, aPointsList.Size() );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( 1, 0 ), aPointsList.Value( 1 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( 0.699242, 0.714885 ), aPointsList.Value( 10 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( -0.110394, 0.993888 ), aPointsList.Value( 20 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( -0.839072, 0.54402 ), aPointsList.Value( 30 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( -0.952415, -0.304806 ), aPointsList.Value( 40 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( -0.367302, -0.930102 ), aPointsList.Value( 50 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( 0.487173, -0.873306 ), aPointsList.Value( 60 ) );
-  CPPUNIT_ASSERT_EQUAL( gp_XY( 0.996087, -0.0883801 ), aPointsList.Value( 71 ) );
+  CPPUNIT_ASSERT_EQUAL( 7, aPointsList.Size() );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( 10, 0 ), aPointsList.Value( 1 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( 6.2349, 7.81831 ), aPointsList.Value( 2 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( -2.225, 9.749 ), aPointsList.Value( 3 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( -9.01, 4.339 ), aPointsList.Value( 4 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( -9.01, -4.339 ), aPointsList.Value( 5 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( -2.225, -9.749 ), aPointsList.Value( 6 ) );
+  CPPUNIT_ASSERT_EQUAL( gp_XY( 6.2349, -7.81831 ), aPointsList.Value( 7 ) );
 
   aDoc->Close();
 }