X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDRO_tests%2Ftest_HYDROData_PolylineXY.cxx;h=9ec336c1c6f70693c60f38104b8c93b01d2dd349;hb=71ba58001e1084f0995fff43bf5e4643b153e5e0;hp=a311e48d3761a2533297ce4317f6b5998617ab58;hpb=6907327a9c59fb980a374ecaa1bbf28ffd583958;p=modules%2Fhydro.git diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx index a311e48d..9ec336c1 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -27,8 +27,13 @@ #include #include #include +#include #include +#include +#include +#include +#include #include #include #include @@ -38,8 +43,9 @@ #include #include #include +#include -void test_HYDROData_PolylineXY::testPolyline() +void test_HYDROData_PolylineXY::test_polyline() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); @@ -69,8 +75,7 @@ void test_HYDROData_PolylineXY::testPolyline() aDoc->Close(); } - -void test_HYDROData_PolylineXY::testCopy() +void test_HYDROData_PolylineXY::test_copy() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); Handle(HYDROData_PolylineXY) aPolyline1 = @@ -88,7 +93,7 @@ void test_HYDROData_PolylineXY::testCopy() aDoc->Close(); } -void test_HYDROData_PolylineXY::testSplit_refs_624() +void test_HYDROData_PolylineXY::test_split_refs_624() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); @@ -157,7 +162,7 @@ void test_HYDROData_PolylineXY::test_extraction_immersible_zone() void test_HYDROData_PolylineXY::test_extraction_channel_refs_611() { -Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); Handle(HYDROData_PolylineXY) aPolyline2d = Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); @@ -211,3 +216,277 @@ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); aDoc->Close(); } + +void test_HYDROData_PolylineXY::test_presentation() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + + Handle(HYDROData_PolylineXY) aPolyline2d = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline2d->SetName( "polyline2d_1" ); + aPolyline2d->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false ); + + QList aPoints = QList() << gp_XY( 0, 0 ) + << gp_XY( 10, 10 ) + << gp_XY( 20, 40 ) + << gp_XY( 30, 10 ) + << gp_XY( 40, 50 ) + << gp_XY( 50, 60 ) + << gp_XY( -10, 40 ) + << gp_XY( -9, 39 ) + << gp_XY( -8, 38 ) + << gp_XY( 0, 20 ); + Handle(TColgp_HArray1OfPnt) aPnts = new TColgp_HArray1OfPnt( 1, aPoints.size() ); + int i = 1; + foreach( gp_XY aPoint, aPoints ) + { + aPolyline2d->AddPoint( 0, aPoint ); + aPnts->SetValue( i, gp_Pnt( aPoint.X(), aPoint.Y(), 0 ) ); + i++; + } + aPolyline2d->Update(); + + CPPUNIT_ASSERT_EQUAL( false, (bool)aPolyline2d->GetShape().IsNull() ); + + Handle(AIS_PointCloud) aPointsPrs = new AIS_PointCloud(); + aPointsPrs->SetPoints( aPnts ); + 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 ); + + 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, "" ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_split_refs_627() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + aPolyline->SetName( "test" ); + + QList aCoords = QList() << 10 << 10 << 20 << 10 << 20 << 20 << 10 << 20; + TopoDS_Wire aWire = Wire( aCoords, false ); + aPolyline->SetShape( aWire ); + aPolyline->SetWireColor( Qt::red ); + + gp_Pnt2d aPnt( 20, 20 ); + + HYDROData_PolylineOperator anOp; + CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) ); + + TestViewer::show( TopoDS_Shape(), 0, true, "Split_Polylines_Colors" ); + HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY ); + for( ; anIt.More(); anIt.Next() ) + { + Handle(HYDROData_PolylineXY) anObj = Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() ); + if( aPolyline->Label() != anObj->Label() ) + TestViewer::show( anObj->GetShape(), 0, true, anObj->GetWireColor() ); + } + CPPUNIT_ASSERT_IMAGES + + HYDROData_Iterator anIt2( aDoc, KIND_POLYLINEXY ); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test" ), anIt2.Current()->GetName() ); + CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), + Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test_1" ), anIt2.Current()->GetName() ); + CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), + Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt2.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test_2" ), anIt2.Current()->GetName() ); + CPPUNIT_ASSERT_EQUAL( QColor( Qt::red ), + Handle(HYDROData_PolylineXY)::DownCast( anIt2.Current() )->GetWireColor() ); + anIt2.Next(); + CPPUNIT_ASSERT_EQUAL( false, anIt2.More() ); + anIt2.Next(); + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_custom_polylines() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline1 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + Handle(HYDROData_PolylineXY) aPolyline2 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + Handle(HYDROData_PolylineXY) aPolyline3 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + + aPolyline1->SetName( "test1" ); + aPolyline2->SetName( "test2" ); + aPolyline3->SetName( "test3" ); + + CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() ); + aPolyline1->AddSection( "", HYDROData_IPolyline::SECTION_SPLINE, false ); + aPolyline1->Update(); + CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() ); + aPolyline1->AddPoint( 0, gp_XY( 0, 0 ) ); + aPolyline1->Update(); + CPPUNIT_ASSERT_EQUAL( false, aPolyline1->IsCustom() ); + + CPPUNIT_ASSERT_EQUAL( false, aPolyline2->IsCustom() ); + aPolyline2->SetShape( Wire( QList() << 0 << 0 << 1 << 1 << 2 << 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( 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( false, aPolyline3->IsCustom() ); + aPolyline3->SetShape( WireCirc( gp_Pnt(), 1.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 ) ); + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_merge_refs_630() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline1 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + Handle(HYDROData_PolylineXY) aPolyline2 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + + aPolyline1->SetName( "test1" ); + aPolyline1->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false ); + aPolyline1->AddPoint( 0, gp_XY( 0, 0 ) ); + aPolyline1->AddPoint( 0, gp_XY( 10, 0 ) ); + aPolyline1->AddPoint( 0, gp_XY( 10, 10 ) ); + aPolyline1->Update(); + + aPolyline2->SetName( "test2" ); + aPolyline2->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false ); + aPolyline2->AddPoint( 0, gp_XY( 20, 20 ) ); + aPolyline2->AddPoint( 0, gp_XY( 30, 20 ) ); + aPolyline2->AddPoint( 0, gp_XY( 30, 0 ) ); + aPolyline2->Update(); + + HYDROData_PolylineOperator anOp; + HYDROData_SequenceOfObjects aPolylines; + aPolylines.Append( aPolyline1 ); + aPolylines.Append( aPolyline2 ); + CPPUNIT_ASSERT_EQUAL( true, anOp.Merge( aDoc, "", aPolylines, true, 1E-3 ) ); + //TODO: check false in merge + + HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY ); + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.Current()->GetName() ); + anIt.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.Current()->GetName() ); + anIt.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "merged_1" ), anIt.Current()->GetName() ); + Handle(HYDROData_PolylineXY) aMerged = + Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() ); + anIt.Next(); + CPPUNIT_ASSERT_EQUAL( false, anIt.More() ); + + TestViewer::show( aMerged->GetShape(), 0, true, "Merge_Polylines" ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +} + +void test_HYDROData_PolylineXY::test_split_straight_refs_634() +{ + Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); + + Handle(HYDROData_PolylineXY) aPolyline1 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + Handle(HYDROData_PolylineXY) aPolyline2 = + Handle(HYDROData_PolylineXY)::DownCast( aDoc->CreateObject( KIND_POLYLINEXY ) ); + + aPolyline1->SetName( "test1" ); + aPolyline1->AddSection( "", HYDROData_PolylineXY::SECTION_POLYLINE, false ); + aPolyline1->AddPoint( 0, gp_XY( 0, 0 ) ); + aPolyline1->AddPoint( 0, gp_XY( 10, 20 ) ); + aPolyline1->AddPoint( 0, gp_XY( 30, 10 ) ); + aPolyline1->Update(); + + aPolyline2->SetName( "test2" ); + aPolyline2->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false ); + aPolyline2->AddPoint( 0, gp_XY( 0, 30 ) ); + aPolyline2->AddPoint( 0, gp_XY( 10, 10 ) ); + aPolyline2->AddPoint( 0, gp_XY( 30, 20 ) ); + aPolyline2->Update(); + + HYDROData_PolylineOperator anOp; + HYDROData_SequenceOfObjects aPolylines; + aPolylines.Append( aPolyline1 ); + aPolylines.Append( aPolyline2 ); + bool isIntersected; + CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline1, aPolyline2, 1E-3, isIntersected ) ); + CPPUNIT_ASSERT_EQUAL( true, isIntersected ); + + HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY ); + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test1" ), anIt.Current()->GetName() ); + anIt.Next(); + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test2" ), anIt.Current()->GetName() ); + anIt.Next(); + + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test1_1" ), anIt.Current()->GetName() ); + Handle(HYDROData_PolylineXY) aPart1 = + Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() ); + CPPUNIT_ASSERT_EQUAL( HYDROData_PolylineXY::SECTION_POLYLINE, aPart1->GetSectionType( 0 ) ); + anIt.Next(); + + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test1_2" ), anIt.Current()->GetName() ); + Handle(HYDROData_PolylineXY) aPart2 = + Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() ); + CPPUNIT_ASSERT_EQUAL( HYDROData_PolylineXY::SECTION_POLYLINE, aPart2->GetSectionType( 0 ) ); + anIt.Next(); + + CPPUNIT_ASSERT_EQUAL( true, anIt.More() ); + CPPUNIT_ASSERT_EQUAL( QString( "test1_3" ), anIt.Current()->GetName() ); + Handle(HYDROData_PolylineXY) aPart3 = + Handle(HYDROData_PolylineXY)::DownCast( anIt.Current() ); + CPPUNIT_ASSERT_EQUAL( HYDROData_PolylineXY::SECTION_POLYLINE, aPart3->GetSectionType( 0 ) ); + anIt.Next(); + + CPPUNIT_ASSERT_EQUAL( false, anIt.More() ); + + TestViewer::show( aPart1->GetShape(), 0, true, "Split_Straight" ); + TestViewer::show( aPart2->GetShape(), 0, true, Qt::red ); + TestViewer::show( aPart3->GetShape(), 0, true, Qt::green ); + TestViewer::show( aPolyline2->GetShape(), 0, true, Qt::darkGreen ); + CPPUNIT_ASSERT_IMAGES + + aDoc->Close(); +}