]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
test h034 on split polylines
authorPaul RASCLE <paul.rascle@openfields.fr>
Sun, 29 Nov 2020 21:19:33 +0000 (22:19 +0100)
committerYOANN AUDOUIN <B61570@dsp0919998.atlas.edf.fr>
Fri, 11 Dec 2020 14:53:30 +0000 (15:53 +0100)
19 files changed:
doc/salome/examples/CMakeLists.txt
doc/salome/examples/CTestTestfileInstall.cmake
doc/salome/examples/contour.shp [new file with mode: 0644]
doc/salome/examples/contour.shx [new file with mode: 0644]
doc/salome/examples/h034_splitShapes.py [new file with mode: 0644]
doc/salome/examples/lm2.shp [new file with mode: 0644]
doc/salome/examples/lm2.shx [new file with mode: 0644]
doc/salome/examples/lmajeur.shp [new file with mode: 0644]
doc/salome/examples/lmajeur.shx [new file with mode: 0644]
doc/salome/examples/openPoly.shp [new file with mode: 0644]
doc/salome/examples/openPoly.shx [new file with mode: 0644]
doc/salome/examples/testsplit.shp [new file with mode: 0644]
doc/salome/examples/testsplit.shx [new file with mode: 0644]
src/HYDROData/HYDROData_PolylineOperator.cxx
src/HYDROData/HYDROData_PolylineOperator.h
src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx
src/HYDROPy/HYDROData_PolylineOperator.sip
src/HYDROTools/hydroGeoMeshUtils.py
src/HYDRO_tests/test_HYDROData_PolylineXY.cxx

index 7b38f76f7b8df65020bcbccd282adf46820ce559..f67ef7f09f60bca418d2f4b35cbd21356530f203 100644 (file)
@@ -56,6 +56,7 @@ SET(EXAMPLES_TESTS
   h031_interpolationLineaireStream.py
   h032_completeCaseNoRegions.py
   h033_completeCaseModifiedRegions.py
+  h034_splitShapes.py
 )
 
 SET(HYDRO_SAMPLES
@@ -69,6 +70,8 @@ SET(HYDRO_SAMPLES
   constraint1.shx
   constraint2.shp
   constraint2.shx
+  contour.shp
+  contour.shx
   coupeDomaineAmontChevauchant.shp
   coupeDomaineAmontChevauchant.shx
   domaine.shp
@@ -99,8 +102,14 @@ SET(HYDRO_SAMPLES
   jonction_5_2.shx
   lit_majeur.shp
   lit_majeur.shx
+  lm2.shp
+  lm2.shx
+  lmajeur.shp
+  lmajeur.shx
   nouvelleDigue.shp
   nouvelleDigue.shx
+  openPoly.shp
+  openPoly.shx
   raccord_4_1.shp
   raccord_4_1.shx
   raccord_4_2.shp
index 1eabdb2b3e9a74da0bed977521b9bee4a547758e..1446fb748d02c3e48c21dcc220b946c1edcab7d6 100644 (file)
@@ -58,6 +58,7 @@ SET(EXAMPLES_TESTS
   h031_interpolationLineaireStream
   h032_completeCaseNoRegions
   h033_completeCaseModifiedRegions
+  h034_splitShapes
   )
 
 FOREACH(tfile ${EXAMPLES_TESTS})
diff --git a/doc/salome/examples/contour.shp b/doc/salome/examples/contour.shp
new file mode 100644 (file)
index 0000000..5d6586a
Binary files /dev/null and b/doc/salome/examples/contour.shp differ
diff --git a/doc/salome/examples/contour.shx b/doc/salome/examples/contour.shx
new file mode 100644 (file)
index 0000000..57fd4dc
Binary files /dev/null and b/doc/salome/examples/contour.shx differ
diff --git a/doc/salome/examples/h034_splitShapes.py b/doc/salome/examples/h034_splitShapes.py
new file mode 100644 (file)
index 0000000..38fa162
--- /dev/null
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+
+import os
+HYDRO_SAMPLES = os.path.join( os.environ["HYDRO_ROOT_DIR"], "bin/salome/test/HYDRO")
+HYDRO_TEST_RESOURCES = os.path.join(os.environ["HYDRO_DIR"], "bin", "salome", "test", "tmp_test")
+
+import tempfile
+tmpdir = tempfile.mkdtemp()
+print("tmpdir=",tmpdir)
+
+# ----------------------------------------------------------------------------------
+# --- domain extension
+
+import sys
+import salome
+
+salome.salome_init()
+
+offsetX = 430000.
+offsetY = 6350000.
+
+#----------------------
+# --- HYDRO
+#----------------------
+
+from HYDROPy import *
+from PyQt5.QtCore import *
+from PyQt5.QtGui import *
+
+from salome.hydrotools.hydroGeoMeshUtils import importPolylines, splitShapesAll
+
+hydro_doc = HYDROData_Document.Document()
+hydro_doc.SetLocalCS( offsetX, offsetY )
+
+contours = importPolylines(hydro_doc, os.path.join(HYDRO_SAMPLES, "contour.shp"), 'contour_PolyXY', False, 0)
+lmajeurs = importPolylines(hydro_doc, os.path.join(HYDRO_SAMPLES, "lmajeur.shp"), 'lmajeur_PolyXY', True, 0)
+lm2s = importPolylines(hydro_doc, os.path.join(HYDRO_SAMPLES, "lm2.shp"), 'lm2_PolyXY', True, 0)
+openPolys = importPolylines(hydro_doc, os.path.join(HYDRO_SAMPLES, "openPoly.shp"), 'openPoly_PolyXY', False, 0)
+                           
+seq = contours + lmajeurs
+shapeList = splitShapesAll(hydro_doc, seq)
+if len(shapeList) != 8:
+    raise ValueError("Bad nunber of shapes after splitShapesAll, found %d instead of 8"%len(shapeList))
+seq2 = contours + lm2s
+shapeList2 = splitShapesAll(hydro_doc, seq2)
+if len(shapeList2) != 16:
+    raise ValueError("Bad nunber of shapes after splitShapesAll, found %d instead of 16"%len(shapeList2))
+seq3 = contours + lm2s + lmajeurs + openPolys
+shapeList3 = splitShapesAll(hydro_doc, seq3)
+if len(shapeList3) != 89:
+    raise ValueError("Bad nunber of shapes after splitShapesAll, found %d instead of 89"%len(shapeList3))
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser()
diff --git a/doc/salome/examples/lm2.shp b/doc/salome/examples/lm2.shp
new file mode 100644 (file)
index 0000000..6c8efd9
Binary files /dev/null and b/doc/salome/examples/lm2.shp differ
diff --git a/doc/salome/examples/lm2.shx b/doc/salome/examples/lm2.shx
new file mode 100644 (file)
index 0000000..421e87d
Binary files /dev/null and b/doc/salome/examples/lm2.shx differ
diff --git a/doc/salome/examples/lmajeur.shp b/doc/salome/examples/lmajeur.shp
new file mode 100644 (file)
index 0000000..159e068
Binary files /dev/null and b/doc/salome/examples/lmajeur.shp differ
diff --git a/doc/salome/examples/lmajeur.shx b/doc/salome/examples/lmajeur.shx
new file mode 100644 (file)
index 0000000..5538bc0
Binary files /dev/null and b/doc/salome/examples/lmajeur.shx differ
diff --git a/doc/salome/examples/openPoly.shp b/doc/salome/examples/openPoly.shp
new file mode 100644 (file)
index 0000000..c458f4f
Binary files /dev/null and b/doc/salome/examples/openPoly.shp differ
diff --git a/doc/salome/examples/openPoly.shx b/doc/salome/examples/openPoly.shx
new file mode 100644 (file)
index 0000000..d9c9a29
Binary files /dev/null and b/doc/salome/examples/openPoly.shx differ
diff --git a/doc/salome/examples/testsplit.shp b/doc/salome/examples/testsplit.shp
new file mode 100644 (file)
index 0000000..68b9206
Binary files /dev/null and b/doc/salome/examples/testsplit.shp differ
diff --git a/doc/salome/examples/testsplit.shx b/doc/salome/examples/testsplit.shx
new file mode 100644 (file)
index 0000000..ae03938
Binary files /dev/null and b/doc/salome/examples/testsplit.shx differ
index 01537030037778b25b120f97755d41ffb34c6119..3f139058c2f4110c02b9cdb13b07ce5f765a6983 100644 (file)
@@ -71,10 +71,10 @@ template<class T> void append( std::vector<T>& theList, const std::vector<T>& th
     theList[i] = theList2[j];
 }
 
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
-                                        const Handle( HYDROData_PolylineXY )& thePolyline,
-                                        const gp_Pnt2d& thePoint,
-                                        double theTolerance ) const
+bool HYDROData_PolylineOperator::SplitPoint( const Handle( HYDROData_Document )& theDoc,
+                                             const Handle( HYDROData_PolylineXY )& thePolyline,
+                                             const gp_Pnt2d& thePoint,
+                                             double theTolerance ) const
 {
   if (thePolyline.IsNull())
   {
@@ -123,11 +123,11 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD
   return isOK;
 }
 
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
-              const Handle( HYDROData_PolylineXY )& thePolyline,
-              const Handle( HYDROData_PolylineXY )& theTool,
-              double theTolerance,
-              bool& theIsIntersected) const
+bool HYDROData_PolylineOperator::SplitTool( const Handle( HYDROData_Document )& theDoc,
+                                            const Handle( HYDROData_PolylineXY )& thePolyline,
+                                            const Handle( HYDROData_PolylineXY )& theTool,
+                                            double theTolerance,
+                                            bool& theIsIntersected) const
 {
   if (thePolyline.IsNull() || theTool.IsNull())
   {
@@ -139,9 +139,9 @@ bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theD
   return split( theDoc, thePolyline, aSeq, theTolerance, -1, theIsIntersected);
 }
 
-bool HYDROData_PolylineOperator::Split( const Handle( HYDROData_Document )& theDoc,
-                                        const HYDROData_SequenceOfObjects& thePolylines,
-                                        double theTolerance )
+bool HYDROData_PolylineOperator::SplitAll( const Handle( HYDROData_Document )& theDoc,
+                                           const HYDROData_SequenceOfObjects& thePolylines,
+                                           double theTolerance )
 {
   int f = thePolylines.Lower(), l = thePolylines.Upper();
   for( int i=f; i<=l; i++ )
index ff64142abf0bafff4d5334476938ebb6939ec83b..e8f8d1be67bf850dc29283ea45df9fcd434a55b7 100644 (file)
@@ -32,18 +32,18 @@ class HYDROData_Object;
 class HYDRODATA_EXPORT HYDROData_PolylineOperator
 {
 public:
-  bool Split( const Handle( HYDROData_Document )& theDoc,
-              const Handle( HYDROData_PolylineXY )& thePolyline,
-              const gp_Pnt2d& thePoint,
-              double theTolerance ) const;
-  bool Split( const Handle( HYDROData_Document )& theDoc,
-              const Handle( HYDROData_PolylineXY )& thePolyline,
-              const Handle( HYDROData_PolylineXY )& theTool,
-              double theTolerance,
-              bool& theIsIntersected) const;
-  bool Split( const Handle( HYDROData_Document )& theDoc,
-              const HYDROData_SequenceOfObjects& thePolylines,
-              double theTolerance );
+  bool SplitPoint( const Handle( HYDROData_Document )& theDoc,
+                   const Handle( HYDROData_PolylineXY )& thePolyline,
+                   const gp_Pnt2d& thePoint,
+                   double theTolerance ) const;
+  bool SplitTool( const Handle( HYDROData_Document )& theDoc,
+                  const Handle( HYDROData_PolylineXY )& thePolyline,
+                  const Handle( HYDROData_PolylineXY )& theTool,
+                  double theTolerance,
+                  bool& theIsIntersected) const;
+  bool SplitAll( const Handle( HYDROData_Document )& theDoc,
+                 const HYDROData_SequenceOfObjects& thePolylines,
+                 double theTolerance );
   bool Merge( const Handle( HYDROData_Document )& theDoc,
               const QString& theName,
               const HYDROData_SequenceOfObjects& thePolylines,
index a30a0e13a537205c46d1791a9c860633fd02e780..61a41a160e2928cefed9cf5cce915ffe22d45c54 100644 (file)
@@ -101,12 +101,12 @@ bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags,
   switch( aPanel->GetMode() )
   {
   case HYDROGUI_SplitPolylinesDlg::ByPoint:
-    anOp.Split( doc(), aMainPolyline, aPoint, aTolerance );
+    anOp.SplitPoint( doc(), aMainPolyline, aPoint, aTolerance );
     break;
   case HYDROGUI_SplitPolylinesDlg::ByTool:
   {
     bool isIntersected = false;
-    anOp.Split( doc(), aMainPolyline, aToolPolyline, aTolerance, isIntersected);
+    anOp.SplitTool( doc(), aMainPolyline, aToolPolyline, aTolerance, isIntersected);
 
     if (!isIntersected)
     {
@@ -117,7 +117,7 @@ bool HYDROGUI_SplitPolylinesOp::processApply( int& theUpdateFlags,
     break;
   }
   case HYDROGUI_SplitPolylinesDlg::Split:
-    anOp.Split( doc(), aPolylinesList, aTolerance );
+    anOp.SplitAll( doc(), aPolylinesList, aTolerance );
     break;
   }
 
index 90ab42befb80bc7b225e129fd3cae9c8ddc2ea60..2e7c57d4e6245ecd74c24859bf6ece979d700fc1 100644 (file)
@@ -24,6 +24,8 @@ class HYDROData_PolylineOperator
 {
 
 %TypeHeaderCode
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
 #include <HYDROData_PolylineOperator.h>
 %End
 
@@ -33,10 +35,10 @@ public:
 
   ~HYDROData_PolylineOperator();
 
-  bool Split( HYDROData_Document theDoc,
-              HYDROData_PolylineXY thePolyline,
-              double x, double y,
-              double theTolerance ) const
+  bool SplitPoint( HYDROData_Document theDoc,
+                   HYDROData_PolylineXY thePolyline,
+                   double x, double y,
+                   double theTolerance ) const
               [bool (opencascade::handle<HYDROData_Document>&, opencascade::handle<HYDROData_PolylineXY>&, const gp_Pnt2d&,  double)];
   %MethodCode
     Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast( createHandle( a1 ) );
@@ -44,17 +46,17 @@ public:
     if ( !aPoly.IsNull() )
     {
       Py_BEGIN_ALLOW_THREADS
-      sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::Split( a0, aPoly, aPnt, a4 ):
-                               sipCpp->Split( a0, aPoly, aPnt, a4 );
+      sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::SplitPoint( a0, aPoly, aPnt, a4 ):
+                               sipCpp->SplitPoint( a0, aPoly, aPnt, a4 );
       Py_END_ALLOW_THREADS
     }
   %End
 
-  bool Split( HYDROData_Document theDoc,
-              HYDROData_PolylineXY thePolyline,
-               HYDROData_PolylineXY theTool,
-              double theTolerance,
-              bool& theIsIntersected) const
+  bool SplitTool( HYDROData_Document theDoc,
+                  HYDROData_PolylineXY thePolyline,
+                  HYDROData_PolylineXY theTool,
+                  double theTolerance,
+                  bool& theIsIntersected) const
               [bool (opencascade::handle<HYDROData_Document>&, opencascade::handle<HYDROData_PolylineXY>&, opencascade::handle<HYDROData_PolylineXY>&, double,  bool&)];
   %MethodCode
     Handle(HYDROData_PolylineXY) aPoly = Handle(HYDROData_PolylineXY)::DownCast( createHandle( a1 ) );
@@ -62,33 +64,47 @@ public:
     if ( !aPoly.IsNull()  && !aTool.IsNull())
     {
       Py_BEGIN_ALLOW_THREADS
-      sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::Split( a0, aPoly, aTool, a3, a4 ):
-                               sipCpp->Split( a0, aPoly, aTool, a3, a4 );
+      sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::SplitTool( a0, aPoly, aTool, a3, a4 ):
+                               sipCpp->SplitTool( a0, aPoly, aTool, a3, a4 );
       Py_END_ALLOW_THREADS
     }
   %End
 
-  bool Split( HYDROData_Document theDoc,
-              const HYDROData_SequenceOfObjects& thePolylines,
-              double theTolerance )
+  bool SplitAll( HYDROData_Document theDoc,
+                 std::vector<HYDROData_Entity*> thePolylines,
+                 double theTolerance )
               [bool (opencascade::handle<HYDROData_Document>&, const HYDROData_SequenceOfObjects&, double)];
   %MethodCode
+    NCollection_Sequence<Handle(HYDROData_Entity)> objs;
+    for (size_t i = 0; i != a1->size(); i++)
+    {
+        DEBTRACE("item " <<  i);
+        Handle(HYDROData_Entity) anEnt = createHandle( (*a1)[i] );
+        objs.Append(anEnt);
+    }
     Py_BEGIN_ALLOW_THREADS
-    sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::Split( a0, *a1, a2):
-                            sipCpp->Split( a0, *a1, a2);
+    sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::SplitAll( a0, objs, a2):
+                            sipCpp->SplitAll( a0, objs, a2);
     Py_END_ALLOW_THREADS
   %End
 
   bool Merge( HYDROData_Document theDoc,
               const QString& theName,
-              const HYDROData_SequenceOfObjects& thePolylines,
+              std::vector<HYDROData_Entity*> thePolylines,
               bool isConnectByNewSegment,
               double theTolerance )
               [bool (opencascade::handle<HYDROData_Document>&, const QString&, const HYDROData_SequenceOfObjects&, bool, double)];
   %MethodCode
+    NCollection_Sequence<Handle(HYDROData_Entity)> objs;
+    for (size_t i = 0; i != a2->size(); i++)
+    {
+        DEBTRACE("item " <<  i);
+        Handle(HYDROData_Entity) anEnt = createHandle( (*a2)[i] );
+        objs.Append(anEnt);
+    }
     Py_BEGIN_ALLOW_THREADS
-    sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::Merge( a0, *a1, *a2, a3, a4):
-                            sipCpp->Merge( a0, *a1, *a2, a3, a4);
+    sipRes = sipSelfWasArg ? sipCpp->HYDROData_PolylineOperator::Merge( a0, *a1, objs, a3, a4):
+                            sipCpp->Merge( a0, *a1, objs, a3, a4);
     Py_END_ALLOW_THREADS
   %End
 };
index 6da1a4efd8488c0897870f06b662499a0e084d34..30349857c50600bc29810a7f7bd9f796bd8b8cbc 100644 (file)
@@ -91,6 +91,46 @@ def importPolylines(document, shapeFile, shapeName, iSpline, displayLevel):
             shapes.append(shape)
     return shapes
 
+def splitShapesAll(document, shapeslist, precision=1.E-2):
+    """
+    Split all the shapes in the list by all the other shapes.
+    return a list of all the other shapes, named after their original shape name, with a sequence suffix _n
+    """
+    names = [s.GetName() for s in shapeslist]
+    
+    existingNbSplit = {}
+    for name in names:
+        index = 1
+        found = True
+        while found:
+            nameIndex = name + "_%d"%(index)
+            shape = document.FindObjectByName(nameIndex)
+            if shape is None:
+                found = False
+            else:
+                index = index + 1
+        existingNbSplit[name] = index
+    print(existingNbSplit)
+
+    op = HYDROData_PolylineOperator()
+    op.SplitAll(document, shapeslist, 1.E-2)
+
+    listSplit = []
+    for name in names:
+        index = existingNbSplit[name]
+        found = True
+        while found:
+            nameIndex = name + "_%d"%(index)
+            shape = document.FindObjectByName(nameIndex)
+            if shape is None:
+                found = False
+            else:
+                print("found %s"%nameIndex)
+                index = index + 1
+                listSplit.append(shape)
+    return listSplit
+    
+    
 def importBathymetry(document, bathyName, bathyPath):
     """
     """
index 5120fb092dd2cae49e4a77a6d57595aec2e75b5e..4d889421342599a1f59d3f8886b773c5e51f93b7 100644 (file)
@@ -119,7 +119,7 @@ void test_HYDROData_PolylineXY::test_split_refs_624()
   CPPUNIT_ASSERT_IMAGES
 
   HYDROData_PolylineOperator anOp;
-  CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
+  CPPUNIT_ASSERT_EQUAL( true, anOp.SplitPoint( aDoc, aPolyline, aPnt, 1E-3 ) );
 
   HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
   CPPUNIT_ASSERT_EQUAL( true, anIt.More() );
@@ -325,7 +325,7 @@ void test_HYDROData_PolylineXY::test_split_refs_627()
   gp_Pnt2d aPnt( 20, 20 );
   
   HYDROData_PolylineOperator anOp;
-  CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline, aPnt, 1E-3 ) );
+  CPPUNIT_ASSERT_EQUAL( true, anOp.SplitPoint( aDoc, aPolyline, aPnt, 1E-3 ) );
 
   TestViewer::show( TopoDS_Shape(), 0, true, "Split_Polylines_Colors" );
   HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );
@@ -502,7 +502,7 @@ void test_HYDROData_PolylineXY::test_split_straight_refs_634()
   aPolylines.Append( aPolyline1 );
   aPolylines.Append( aPolyline2 );
   bool isIntersected;
-  CPPUNIT_ASSERT_EQUAL( true, anOp.Split( aDoc, aPolyline1, aPolyline2, 1E-3, isIntersected ) );
+  CPPUNIT_ASSERT_EQUAL( true, anOp.SplitTool( aDoc, aPolyline1, aPolyline2, 1E-3, isIntersected ) );
   CPPUNIT_ASSERT_EQUAL( true, isIntersected );
 
   HYDROData_Iterator anIt( aDoc, KIND_POLYLINEXY );