h031_interpolationLineaireStream.py
h032_completeCaseNoRegions.py
h033_completeCaseModifiedRegions.py
+ h034_splitShapes.py
)
SET(HYDRO_SAMPLES
constraint1.shx
constraint2.shp
constraint2.shx
+ contour.shp
+ contour.shx
coupeDomaineAmontChevauchant.shp
coupeDomaineAmontChevauchant.shx
domaine.shp
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
h031_interpolationLineaireStream
h032_completeCaseNoRegions
h033_completeCaseModifiedRegions
+ h034_splitShapes
)
FOREACH(tfile ${EXAMPLES_TESTS})
--- /dev/null
+# -*- 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()
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())
{
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())
{
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++ )
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,
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)
{
break;
}
case HYDROGUI_SplitPolylinesDlg::Split:
- anOp.Split( doc(), aPolylinesList, aTolerance );
+ anOp.SplitAll( doc(), aPolylinesList, aTolerance );
break;
}
{
%TypeHeaderCode
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
#include <HYDROData_PolylineOperator.h>
%End
~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 ) );
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 ) );
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
};
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):
"""
"""
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() );
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 );
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 );