From: asl Date: Thu, 22 Oct 2015 13:13:03 +0000 (+0300) Subject: refs #627: colors of split polylines X-Git-Tag: v1.5~75^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fb0d542a0fb78f0084af11451080811d9e080871;p=modules%2Fhydro.git refs #627: colors of split polylines --- 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 00000000..2ec01c5a Binary files /dev/null and b/src/HYDRO_tests/reference_data/Split_Polylines_Colors.png differ 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();