From fb0d542a0fb78f0084af11451080811d9e080871 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 22 Oct 2015 16:13:03 +0300 Subject: [PATCH] refs #627: colors of split polylines --- src/HYDROData/HYDROData_PolylineOperator.cxx | 16 ++++-- src/HYDROData/HYDROData_PolylineOperator.h | 3 +- src/HYDROData/HYDROData_Tool.cxx | 8 +++ src/HYDROData/HYDROData_Tool.h | 3 +- src/HYDRO_tests/TestViewer.cxx | 4 ++ .../reference_data/Split_Polylines_Colors.png | Bin 0 -> 5291 bytes src/HYDRO_tests/test_HYDROData_PolylineXY.cxx | 48 ++++++++++++++++++ src/HYDRO_tests/test_HYDROData_PolylineXY.h | 2 + 8 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/HYDRO_tests/reference_data/Split_Polylines_Colors.png diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index a5768945..0bc2d326 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -48,6 +48,7 @@ #include #include #include +#include #include template void append( std::vector& theList, const std::vector& theList2 ) @@ -81,8 +82,9 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD for( int i=0, n=aCurves.size(); i aCurvesList; - Split(aCurves[i], thePoint, theTolerance, aCurvesList); - bool isLocalOK = CreatePolylines( theDoc, thePolyline->GetName(), aCurvesList, true ); + Split( aCurves[i], thePoint, theTolerance, aCurvesList ); + bool isLocalOK = CreatePolylines( theDoc, thePolyline->GetName(), + aCurvesList, true, thePolyline->GetWireColor() ); isOK = isOK && isLocalOK; } return isOK; @@ -161,7 +163,7 @@ bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theD std::vector aPolylines(1); aPolylines[0] = aWireSet; - CreatePolylines(theDoc, theName, aPolylines, false); + CreatePolylines( theDoc, theName, aPolylines, false, QColor() ); return true; } @@ -229,7 +231,7 @@ bool HYDROData_PolylineOperator::split( const Handle( HYDROData_Document )& theD } } - CreatePolylines(theDoc, thePolyline->GetName(), aResult, true); + CreatePolylines( theDoc, thePolyline->GetName(), aResult, true, thePolyline->GetWireColor() ); return true; } @@ -281,7 +283,8 @@ void HYDROData_PolylineOperator::Split( bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Document )& theDoc, const QString& theNamePrefix, const std::vector& theShapes, - bool isUseIndices ) + bool isUseIndices, + const QColor& theColor ) { if( theDoc.IsNull() ) return false; @@ -308,6 +311,9 @@ bool HYDROData_PolylineOperator::CreatePolylines( const Handle( HYDROData_Docume { aPolyline->SetName( theNamePrefix ); } + + if( theColor.isValid() ) + aPolyline->SetWireColor( theColor ); } return true; } diff --git a/src/HYDROData/HYDROData_PolylineOperator.h b/src/HYDROData/HYDROData_PolylineOperator.h index 4263370d..eefac88b 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.h +++ b/src/HYDROData/HYDROData_PolylineOperator.h @@ -85,7 +85,8 @@ protected: static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc, const QString& theNamePrefix, const std::vector& theShape, - bool isUseIndices ); + bool isUseIndices, + const QColor& theColor ); }; #endif diff --git a/src/HYDROData/HYDROData_Tool.cxx b/src/HYDROData/HYDROData_Tool.cxx index def682d9..051fdc91 100644 --- a/src/HYDROData/HYDROData_Tool.cxx +++ b/src/HYDROData/HYDROData_Tool.cxx @@ -282,6 +282,14 @@ Quantity_Color HYDROData_Tool::toOccColor( const QColor& theColor ) return Quantity_Color( r, g, b, Quantity_TOC_RGB ); } +QColor HYDROData_Tool::toQtColor( const Quantity_Color& theColor ) +{ + int r = 255 * theColor.Red(); + int g = 255 * theColor.Green(); + int b = 255 * theColor.Blue(); + return QColor( r, g, b ); +} + std::ostream& operator<<( std::ostream& theStream, const QString& theText ) { theStream << theText.toStdString(); diff --git a/src/HYDROData/HYDROData_Tool.h b/src/HYDROData/HYDROData_Tool.h index efff055d..0eeb6487 100644 --- a/src/HYDROData/HYDROData_Tool.h +++ b/src/HYDROData/HYDROData_Tool.h @@ -119,7 +119,8 @@ public: static TCollection_ExtendedString toExtString( const QString& ); static QString toQString( const TCollection_ExtendedString& ); - static Quantity_Color toOccColor( const QColor& ); + static Quantity_Color toOccColor( const QColor& ); + static QColor toQtColor( const Quantity_Color& ); }; inline bool ValuesEquals( const double& theFirst, const double& theSecond ) diff --git a/src/HYDRO_tests/TestViewer.cxx b/src/HYDRO_tests/TestViewer.cxx index 1fef8ca1..8315d811 100644 --- a/src/HYDRO_tests/TestViewer.cxx +++ b/src/HYDRO_tests/TestViewer.cxx @@ -133,6 +133,10 @@ void TestViewer::show( const TopoDS_Shape& theShape, int theMode, bool isFitAll, context()->EraseAll( Standard_False ); myKey = theKey; + + if( theShape.IsNull() ) + return; + int i = 0; if( theShape.ShapeType()==TopAbs_SHELL ) { diff --git a/src/HYDRO_tests/reference_data/Split_Polylines_Colors.png b/src/HYDRO_tests/reference_data/Split_Polylines_Colors.png new file mode 100644 index 0000000000000000000000000000000000000000..2ec01c5ae575374cc599c9536a1a4d6e48afcb34 GIT binary patch literal 5291 zcmb_f2|Seh*FVoJW|){kp(um8scfZ-Vi;S>RjGTsMap!Q8I>p{q&$RHkz}bbZPGtU zB_+y8i^?*^ze{xyvRqj*mhA6uhSq;?_kBO_`+S)B&iDDA^PF>j=eIlu9GBS1%1n|0 z0NF(gZI%NNnE-@UR4K%q@D1@sUnC!^MZZze6-ZsbAN`j0Ug+clAa`HqWFiO;~Dtl%-voY%OCt zH9RUtTQflZ#HIT}D@*!eS1n?R!^}{8Cwa1^y_fye;9ADiJKoE4?GHRob2;^H9=GJw zl{>x8r32jqmYkC8_&amjx^r9dhTC77PD4?RUa@nZ?gl95F7$}6ZBKNHgA-gKar>48 zgV`$_O`2Ab#^e1H>p^zL3p-oL{!C>C85p$?BaKJ*SYCFmf z!r=lS$L|+B(_2U4_=o=_SV%fzF0BQJW@}@=*VG z11Tgwq(RMy5agGK%JX+hsk1xR(Cg8oSaaUt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8)oOIp)Wu2EAM(Tdea7*~Dxy}ada zZ`Ce+R!@c7O}jf&GK?)rom+>ozY-`>+$8^o_Ook6mE7c^dw=b$-u*PekUJ$ZU~vs6 zNio=@$aJrfzJITDW&Ql1<+XofV$jvBtSsL*_rgY4dj>!BRtJiT zFI@1O%-M}}m`B?IkwBX#1!=Cx-xCM`|02pW!? zalUI%R2tNG#I)_hzBt!CeT4@Urw{KqH?mr=Fff^#R?A+#gjW?g3p?9vP{gr;~?q0RfX#DKR;Xac?0$K7SBRzkSCAlPN@HJNsGeAC2GpjCK2J$%UC zS7AQ%xN8&AcwFtR`IY+W?%-`eRN$<4j=sw?1tm8}0!bL1Y1;&=l1@uU1;?Hhh0zZcmqu}Qb$g!~s}*`Hnj literal 0 HcmV?d00001 diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx index e11b3a23..addeb5e9 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -263,3 +263,51 @@ void test_HYDROData_PolylineXY::test_presentation() aDoc->Close(); } + +void test_HYDROData_PolylineXY::testSplit_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(); +} diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.h b/src/HYDRO_tests/test_HYDROData_PolylineXY.h index dde74539..88094b58 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.h +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.h @@ -23,6 +23,7 @@ class test_HYDROData_PolylineXY : public CppUnit::TestFixture { CPPUNIT_TEST( testPolyline ); CPPUNIT_TEST( testCopy ); CPPUNIT_TEST( testSplit_refs_624 ); + CPPUNIT_TEST( testSplit_refs_627 ); CPPUNIT_TEST( test_presentation ); CPPUNIT_TEST( test_extraction_immersible_zone ); CPPUNIT_TEST( test_extraction_channel_refs_611 ); @@ -43,6 +44,7 @@ public: void testCopy(); void testSplit_refs_624(); + void testSplit_refs_627(); void test_extraction_immersible_zone(); void test_extraction_channel_refs_611(); -- 2.39.2