From 7801bb11d9c4c98c23459286b4434df65f362009 Mon Sep 17 00:00:00 2001 From: asl Date: Mon, 26 Oct 2015 14:04:26 +0300 Subject: [PATCH] refs #630: polylines merge --- src/HYDROData/HYDROData_PolylineOperator.cxx | 5 +- src/HYDROData/HYDROData_TopoCurve.h | 2 +- src/HYDRO_tests/TestViewer.cxx | 11 ++-- .../reference_data/Merge_Polylines.png | Bin 0 -> 5479 bytes src/HYDRO_tests/test_HYDROData_PolylineXY.cxx | 59 ++++++++++++++++-- src/HYDRO_tests/test_HYDROData_PolylineXY.h | 18 +++--- 6 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 src/HYDRO_tests/reference_data/Merge_Polylines.png 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 0000000000000000000000000000000000000000..c54f55a0177722359e4ab32a3b1eec5569ddbc5d GIT binary patch literal 5479 zcmb_gdpJ~U`+nAp!x)E|GC37S?Hy7Xa!O%QQEf5BE_TV3q|%Wj=S4bvr6}x3YDgI! z)sBi{I*61gax8XHgi_2Xr=YH?!eb?(hY$pdrssn)NZRwyrrSC^v76*KnVmj) z!F=uXQ>A(o!M(5B*71||bx2JlP22S23#s>XGPE@A>rU}?qU{m{-}&;g$ET}l=u(cg z_D$9o4gaT&H~I#vzYJ7cW_BPr|LcppG5+dl6f`H<>3DyW^TkCI-yBy2{=r_V#$%a- z-sE4jV;{K*t+pt+-qvNHU}REA2gnOn{WRyw1wn`YX-@#$Ws{=Dq45hJzS~Cz z*DN9Ts$S$zCnhQY+r;*aXG2$Jh=r8-1mIGl>~Ggu1;+NbtS3Rn^(}BZ? zvQKtgQ2q8H1`3NSc=60@)65lss~TmWB6ZaJ)>439#+lR}W?s`XrvPU~l+1-Br@@GI z*5Zv+qtMnjyqKiUFS}NU-)2R!fP{tsa%zK6rZ<5#In)OLht`U*IJ~wDrv`c8{ z#?=(=k2`Ou1l?{^**iTx$kREe^5!kfQI&zKoA;1JuG=VC-RZ#DJ%{X&Dlg4(4A>Xf zK9d6bbhd*R&oJ6Gzz8a|BgrM{m+8yO_5wdxN{RVLu-(E5su(=3`@r9=d03O@uBnsp zRUU}J6XOryg*=$zf0bbST75< zoBtr~j<=)$dAubw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TRwugTDTKHoVue2sZiXixFw{EvAZR|-V! z<%I*?j|)RSZuVZ*(F_m9$6(3a3{hvFi_HaQfaPeCx78UJXtXME<=%F7*jhrevy`Kmmx@kSu# z;nR)5I#VC{YSvWkQ2!++vn?9-<@g^pF^qO&-yMpk0rSdI75x-dvrLbgfGeK8qGPdz zjdjYrhR&w_5wd`@oFB;!H@t|O_$Zn>PU%6^5rRme64uI1iQiHed7Lq{1X)g=_{S!ssi zpjJ|G+oR+ji%)g!#=k+(YqH_M`{T5s?oXZlzZl*TT-zf{E9mNN*k<#rwfUrVm?;1F zD!)hG`)S%ky`3YvX$pT_mv9Gkcy83i~=BjV48j zx6L@{e9~fv!-Hn)flv2uq*{ga_K%BAjO84QZNdOQ@BwRipLu%7sj9i)>zhNdjX|xc zD;%s=t4qc2{%8a^&mC?J5B1xq3X^DaKk-|y6b^|VJBwA#E1sUhd9M8h{X1y=^;t|b zdHa<#>t7BHDm%~J5qhBbR&Twp&GoBSukPsWtSi)>?blLVKDXyd*u1$;9w&|5Up)=^ zqeqJb^tOVHHLuLA{NKg4HV*VOoC@uJv~6bpjluO^UZSdX#(`L9dsS9`;Lv7Y-;R#Q z)+#;MwH$xDy&fG!4|mUIdJeq#wRL9Uz~J$dbNkM=ZVN5fJsr~VDD>Sd?Y?{O-Z}r? zmp^sbv+GWMKxM@3&-P!+-(TzN%N$;X9)x+%(y7 z*fMoj6Wx-kY-HpfI42BL-qI`!(}Bsvo #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); -- 2.39.2