Salome HOME
refs #627: colors of split polylines
authorasl <asl@opencascade.com>
Thu, 22 Oct 2015 13:13:03 +0000 (16:13 +0300)
committerasl <asl@opencascade.com>
Thu, 22 Oct 2015 13:13:03 +0000 (16:13 +0300)
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROData/HYDROData_Tool.cxx
src/HYDROData/HYDROData_Tool.h
src/HYDRO_tests/TestViewer.cxx
src/HYDRO_tests/reference_data/Split_Polylines_Colors.png [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_PolylineXY.cxx
src/HYDRO_tests/test_HYDROData_PolylineXY.h

index a5768945013f69a6b08bf9cbfd60248161d63cbc..0bc2d326069380329d9f92e0bb4d15626c24eff5 100644 (file)
@@ -48,6 +48,7 @@
 #include <TopExp_Explorer.hxx>
 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
 #include <QStringList>
+#include <QColor>
 #include <Geom_BSplineCurve.hxx>
 
 template<class T> void append( std::vector<T>& theList, const std::vector<T>& theList2 )
@@ -81,8 +82,9 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD
   for( int i=0, n=aCurves.size(); i<n; i++ )
   {
     std::vector<TopoDS_Shape> 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<TopoDS_Shape> 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<TopoDS_Shape>& 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;
 }
index 4263370dec1c4b110091d80304bddee87c9ff25a..eefac88bad05e67ac5c3237f353eeda87b97c04d 100644 (file)
@@ -85,7 +85,8 @@ protected:
   static bool CreatePolylines( const Handle( HYDROData_Document )& theDoc,
                                const QString& theNamePrefix,
                                const std::vector<TopoDS_Shape>& theShape,
-                               bool isUseIndices );
+                               bool isUseIndices,
+                               const QColor& theColor );
 };
 
 #endif
index def682d94cc6900d6cc1ad2aaccf967460f70edc..051fdc917852ca3e767f5fb7970eeecb82232445 100644 (file)
@@ -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();
index efff055d66a2849944108836fa98461e1e203285..0eeb64871a87580606127605c5e53d45f6675e23 100644 (file)
@@ -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 )
index 1fef8ca1a5dca3e73054239941adb43b0e6a04c7..8315d811ff5d02c3cfccbe535c3a6d775c89b465 100644 (file)
@@ -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 (file)
index 0000000..2ec01c5
Binary files /dev/null and b/src/HYDRO_tests/reference_data/Split_Polylines_Colors.png differ
index e11b3a2366559564159ae82d72547512f3f98a01..addeb5e9f17954a3d94a96bff27d6778b58b65d7 100644 (file)
@@ -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<double> aCoords = QList<double>() << 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();
+}
index dde745393231b13310496eaa718aa40b26156389..88094b5819ca863999cfb49c40932d2542897538 100644 (file)
@@ -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();