From 2e0da23cad20a0adf8638a95e86ee3e017accf2e Mon Sep 17 00:00:00 2001 From: Paul RASCLE Date: Wed, 26 Aug 2020 14:38:37 +0200 Subject: [PATCH] some functions for test scripts --- .../examples/h022_extensionSimpleComplete.py | 51 ++++--------------- src/HYDROTools/hydroGeoMeshUtils.py | 43 ++++++++++++++++ 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/doc/salome/examples/h022_extensionSimpleComplete.py b/doc/salome/examples/h022_extensionSimpleComplete.py index ec543f49..142faef6 100644 --- a/doc/salome/examples/h022_extensionSimpleComplete.py +++ b/doc/salome/examples/h022_extensionSimpleComplete.py @@ -37,49 +37,18 @@ from HYDROPy import * from PyQt5.QtCore import * from PyQt5.QtGui import * +from salome.hydrotools.hydroGeoMeshUtils import importPolyline, importBathymetry, createImmersibleZone + hydro_doc = HYDROData_Document.Document() hydro_doc.SetLocalCS( offsetX, offsetY ) + +limite_original = importPolyline(hydro_doc, "garonne_1_brd_FreeBorders", tmpdir, '_0', True, 4) +limite_domaine = importPolyline(hydro_doc, "extension_1_1", HYDRO_SAMPLES, '_PolyXY_0', False, 2) + +Cloud_02 = importBathymetry(hydro_doc, "Cloud_02", HYDRO_SAMPLES) -name = "garonne_1_brd_FreeBorders" -shape = os.path.join(tmpdir, name+".shp" ) -HYDROData_PolylineXY.ImportShapesFromFile(shape) -limite_original = hydro_doc.FindObjectByName(name + '_0') -for i in range(limite_original.NbSections()): - limite_original.SetSectionType(i, 1) # spline - limite_original.Update() -limite_original.SetZLevel( 4 ) - -name = "extension_1_1" -shape = os.path.join(HYDRO_SAMPLES, name+".shp" ) -HYDROData_PolylineXY.ImportShapesFromFile(shape) -limite_domaine = hydro_doc.FindObjectByName(name + '_PolyXY_0') -for i in range(limite_domaine.NbSections()): - limite_domaine.SetSectionType(i, 0) # polyline - limite_domaine.Update() -limite_domaine.SetZLevel( 2 ) - -Cloud_02 = hydro_doc.CreateObject( KIND_BATHYMETRY ) -Cloud_02.SetName( "Cloud_02" ) -Cloud_02.SetAltitudesInverted( 0 ) -if not(Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))): - raise ValueError('problem while loading bathymetry') -Cloud_02.Update() - - -domaine_original = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) -domaine_original.SetName( "domaine_original" ) -domaine_original.SetZLevel( 1 ) -domaine_original.SetAltitudeObject( Cloud_02 ) -domaine_original.SetPolyline( limite_original ) -domaine_original.SetIsSubmersible(False) -domaine_original.Update() - -domaine_englobant = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE ) -domaine_englobant.SetName( "domaine_englobant" ) -domaine_englobant.SetZLevel( 0 ) -domaine_englobant.SetAltitudeObject( Cloud_02 ) -domaine_englobant.SetPolyline( limite_domaine ) -domaine_englobant.Update() +domaine_original = createImmersibleZone(hydro_doc, "domaine_original", limite_original, Cloud_02, False, 1) +domaine_englobant = createImmersibleZone(hydro_doc, "domaine_englobant", limite_domaine, Cloud_02, True, 0) # Calculation case extension = hydro_doc.CreateObject( KIND_CALCULATION ) @@ -172,5 +141,7 @@ Source_Edges_1 = Import_1D.SourceEdges( FreeBorders ,1,1) isDone = extensionEnglobante.Compute() +controlMeshStats(extensionEnglobante, 8107, 805, 15885) + if salome.sg.hasDesktop(): salome.sg.updateObjBrowser() diff --git a/src/HYDROTools/hydroGeoMeshUtils.py b/src/HYDROTools/hydroGeoMeshUtils.py index ec96c526..04b31cf7 100644 --- a/src/HYDROTools/hydroGeoMeshUtils.py +++ b/src/HYDROTools/hydroGeoMeshUtils.py @@ -1,8 +1,13 @@ import sys +import os import salome salome.salome_init() +from HYDROPy import * +from PyQt5.QtCore import * +from PyQt5.QtGui import * + def getChildrenInStudy(obj): """ Given an object published in SALOME study (for instance a GEOM object), retreive its children. @@ -20,3 +25,41 @@ def getChildrenInStudy(obj): children[itemName] = itemObj childIterator.Next() return children + +def importPolyline(document, shapeName, shapePath, suffix, iSpline, displayLevel): + """ + """ + shapeFile = os.path.join(shapePath, shapeName+".shp") + HYDROData_PolylineXY.ImportShapesFromFile(shapeFile) + shape = document.FindObjectByName(shapeName + suffix) + shapeType = 0 # polyline + if iSpline: + shapeType = 1 # polyline + for i in range(shape.NbSections()): + shape.SetSectionType(i, shapeType) + shape.Update() + shape.SetZLevel( displayLevel ) + return shape + +def importBathymetry(document, bathyName, bathyPath): + """ + """ + bathy = document.CreateObject(KIND_BATHYMETRY) + bathy.SetName(bathyName) + bathy.SetAltitudesInverted(0) + if not(bathy.ImportFromFile( os.path.join(bathyPath, bathyName + '.xyz' ))): + raise ValueError('problem while loading bathymetry') + bathy.Update() + return bathy + +def createImmersibleZone(document, imzName, polyLine, bathy, isImmersible, displayLevel): + """ + """ + imz = document.CreateObject( KIND_IMMERSIBLE_ZONE ) + imz.SetName( imzName ) + imz.SetZLevel( displayLevel ) + imz.SetAltitudeObject( bathy ) + imz.SetPolyline( polyLine ) + imz.SetIsSubmersible(isImmersible) + imz.Update() + return imz -- 2.39.2