]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #630: polylines merge
authorasl <asl@opencascade.com>
Mon, 26 Oct 2015 11:04:26 +0000 (14:04 +0300)
committerasl <asl@opencascade.com>
Mon, 26 Oct 2015 11:04:26 +0000 (14:04 +0300)
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_TopoCurve.h
src/HYDRO_tests/TestViewer.cxx
src/HYDRO_tests/reference_data/Merge_Polylines.png [new file with mode: 0644]
src/HYDRO_tests/test_HYDROData_PolylineXY.cxx
src/HYDRO_tests/test_HYDROData_PolylineXY.h

index 0bc2d326069380329d9f92e0bb4d15626c24eff5..03e6d6005301e00cc805b613f6e31bfcc585dfbf 100644 (file)
@@ -163,7 +163,10 @@ bool HYDROData_PolylineOperator::Merge( const Handle( HYDROData_Document )& theD
 
   std::vector<TopoDS_Shape> 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;
 }
 
index 8d2bfddda8067dba771a44ba274524a0f1f8c3e6..484e20214521a92e4aff63a19dfc0f0467179ac0 100644 (file)
@@ -148,7 +148,7 @@ public:
     std::deque<HYDROData_TopoCurve>& theCurves)
   {
     HYDROData_TopoCurve aCurve;
-    if (!aCurve.Initialize(theWire))
+    if (aCurve.Initialize(theWire))
     {
       return aCurve.Connect(theTolerance, theCurves);
     }
index ca224f32990b288b62000e6f782488796034702f..a3d5054be69aa34704f608a2edf8f856870060f9 100644 (file)
@@ -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 (file)
index 0000000..c54f55a
Binary files /dev/null and b/src/HYDRO_tests/reference_data/Merge_Polylines.png differ
index c44a9f5b574b70317c4af030a187dd0df868fd29..f89a11ae28e9591fb297a81919e968e249cb271c 100644 (file)
@@ -45,7 +45,7 @@
 #include <TopoDS_Wire.hxx>
 #include <gp_XY.hxx>
 
-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();
+}
index 3a7b53bb1eb9c1c09d405a02614260da3a73121e..588fd7dd61b95d23c7c524d117f15caf14de4eb2 100644 (file)
 
 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);