From: Paul RASCLE Date: Sun, 29 Nov 2020 21:19:33 +0000 (+0100) Subject: test h034 on split polylines X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=166b635309c21c9868887ca6caa65f31d2ba06e9;p=modules%2Fhydro.git test h034 on split polylines --- diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index 7b38f76f..f67ef7f0 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -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 diff --git a/doc/salome/examples/CTestTestfileInstall.cmake b/doc/salome/examples/CTestTestfileInstall.cmake index 1eabdb2b..1446fb74 100644 --- a/doc/salome/examples/CTestTestfileInstall.cmake +++ b/doc/salome/examples/CTestTestfileInstall.cmake @@ -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 index 00000000..5d6586a6 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 index 00000000..57fd4dcb 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 index 00000000..38fa162e --- /dev/null +++ b/doc/salome/examples/h034_splitShapes.py @@ -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 index 00000000..6c8efd90 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 index 00000000..421e87d2 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 index 00000000..159e0688 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 index 00000000..5538bc0f 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 index 00000000..c458f4fb 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 index 00000000..d9c9a297 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 index 00000000..68b9206e 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 index 00000000..ae03938a Binary files /dev/null and b/doc/salome/examples/testsplit.shx differ diff --git a/src/HYDROData/HYDROData_PolylineOperator.cxx b/src/HYDROData/HYDROData_PolylineOperator.cxx index 01537030..3f139058 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.cxx +++ b/src/HYDROData/HYDROData_PolylineOperator.cxx @@ -71,10 +71,10 @@ template void append( std::vector& theList, const std::vector& 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++ ) diff --git a/src/HYDROData/HYDROData_PolylineOperator.h b/src/HYDROData/HYDROData_PolylineOperator.h index ff64142a..e8f8d1be 100644 --- a/src/HYDROData/HYDROData_PolylineOperator.h +++ b/src/HYDROData/HYDROData_PolylineOperator.h @@ -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, diff --git a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx index a30a0e13..61a41a16 100644 --- a/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx +++ b/src/HYDROGUI/HYDROGUI_SplitPolylinesOp.cxx @@ -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; } diff --git a/src/HYDROPy/HYDROData_PolylineOperator.sip b/src/HYDROPy/HYDROData_PolylineOperator.sip index 90ab42be..2e7c57d4 100644 --- a/src/HYDROPy/HYDROData_PolylineOperator.sip +++ b/src/HYDROPy/HYDROData_PolylineOperator.sip @@ -24,6 +24,8 @@ class HYDROData_PolylineOperator { %TypeHeaderCode +#define _DEVDEBUG_ +#include "HYDRO_trace.hxx" #include %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&, opencascade::handle&, 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&, opencascade::handle&, opencascade::handle&, 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 thePolylines, + double theTolerance ) [bool (opencascade::handle&, const HYDROData_SequenceOfObjects&, double)]; %MethodCode + NCollection_Sequence 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 thePolylines, bool isConnectByNewSegment, double theTolerance ) [bool (opencascade::handle&, const QString&, const HYDROData_SequenceOfObjects&, bool, double)]; %MethodCode + NCollection_Sequence 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 }; diff --git a/src/HYDROTools/hydroGeoMeshUtils.py b/src/HYDROTools/hydroGeoMeshUtils.py index 6da1a4ef..30349857 100644 --- a/src/HYDROTools/hydroGeoMeshUtils.py +++ b/src/HYDROTools/hydroGeoMeshUtils.py @@ -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): """ """ diff --git a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx index 5120fb09..4d889421 100644 --- a/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx +++ b/src/HYDRO_tests/test_HYDROData_PolylineXY.cxx @@ -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 );