From: asl Date: Mon, 26 Oct 2015 11:04:26 +0000 (+0300) Subject: refs #630: polylines merge X-Git-Tag: v1.5~64 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7801bb11d9c4c98c23459286b4434df65f362009;p=modules%2Fhydro.git refs #630: polylines merge --- diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index 0bc2d326..03e6d600 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -163,7 +163,10 @@ bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theD std::vector aPolylines(1); aPolylines[0] = aWireSet; - CreatePolylines( theDoc, theName, aPolylines, false, QColor() ); + QString aName = theName; + if( aName.isEmpty() ) + aName = "merged"; + CreatePolylines( theDoc, aName, aPolylines, true, QColor() ); return true; } diff --git a/src/HYDROData/HYDROData_TopoCurve.h b/src/HYDROData/HYDROData_TopoCurve.h index 8d2bfddd..484e2021 100644 --- a/src/HYDROData/HYDROData_TopoCurve.h +++ b/src/HYDROData/HYDROData_TopoCurve.h @@ -148,7 +148,7 @@ public: std::deque& theCurves) { HYDROData_TopoCurve aCurve; - if (!aCurve.Initialize(theWire)) + if (aCurve.Initialize(theWire)) { return aCurve.Connect(theTolerance, theCurves); } diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index ca224f32..a3d5054b 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -146,10 +146,13 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, const char* theKey ) { - context()->CloseLocalContext(); - context()->EraseAll( Standard_False ); - - myKey = theKey; + QString aNewKey = theKey; + if( !aNewKey.isEmpty() ) + { + context()->CloseLocalContext(); + context()->EraseAll( Standard_False ); + myKey = aNewKey; + } if( theShape.IsNull() ) return; diff --git a/src/HYDRO_tests/reference_data/Merge_Polylines.png b/src/HYDRO_tests/reference_data/Merge_Polylines.png new file mode 100644 index 00000000..c54f55a0 Binary files /dev/null and b/src/HYDRO_tests/reference_data/Merge_Polylines.png differ diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx index c44a9f5b..f89a11ae 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -45,7 +45,7 @@ #include #include -void test_HYDROData_PolylineXY::testPolyline() +void test_HYDROData_PolylineXY::test_polyline() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); @@ -75,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 = @@ -94,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 ); @@ -265,7 +264,7 @@ void test_HYDROData_PolylineXY::test_presentation() aDoc->Close(); } -void test_HYDROData_PolylineXY::testSplit_refs_627() +void test_HYDROData_PolylineXY::test_split_refs_627() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( 1 ); @@ -370,3 +369,53 @@ void test_HYDROData_PolylineXY::test_custom_polylines() 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(); +} diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.h b/src/HYDRO_tests/test_HYDROData_PolylineXY.h index 3a7b53bb..588fd7dd 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.h +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.h @@ -20,14 +20,15 @@ class test_HYDROData_PolylineXY : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE( test_HYDROData_PolylineXY ); - CPPUNIT_TEST( testPolyline ); - CPPUNIT_TEST( testCopy ); - CPPUNIT_TEST( testSplit_refs_624 ); - CPPUNIT_TEST( testSplit_refs_627 ); + CPPUNIT_TEST( test_polyline ); + CPPUNIT_TEST( test_copy ); + CPPUNIT_TEST( test_split_refs_624 ); + CPPUNIT_TEST( test_split_refs_627 ); CPPUNIT_TEST( test_presentation ); CPPUNIT_TEST( test_extraction_immersible_zone ); CPPUNIT_TEST( test_extraction_channel_refs_611 ); CPPUNIT_TEST( test_custom_polylines ); + CPPUNIT_TEST( test_merge_refs_630 ); CPPUNIT_TEST_SUITE_END(); private: @@ -39,18 +40,19 @@ public: void tearDown() {} // checks save/restore QImages information - void testPolyline(); + void test_polyline(); // checks the image properties copy/paste - void testCopy(); + void test_copy(); - void testSplit_refs_624(); - void testSplit_refs_627(); + void test_split_refs_624(); + void test_split_refs_627(); void test_extraction_immersible_zone(); void test_extraction_channel_refs_611(); void test_presentation(); void test_custom_polylines(); + void test_merge_refs_630(); }; CPPUNIT_TEST_SUITE_REGISTRATION(test_HYDROData_PolylineXY);