Salome HOME
some functions for test scripts
authorPaul RASCLE <paul.rascle@openfields.fr>
Wed, 26 Aug 2020 12:38:37 +0000 (14:38 +0200)
committerYOANN AUDOUIN <B61570@dsp0851742.postes.calibre.edf.fr>
Fri, 30 Oct 2020 16:06:22 +0000 (17:06 +0100)
doc/salome/examples/h022_extensionSimpleComplete.py
src/HYDROTools/hydroGeoMeshUtils.py

index ec543f49f5da94d69d84273d36c6bb1dbc3dc99e..142faef6a189401e9f59bbfaa3f1e750adeca551 100644 (file)
@@ -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()
index ec96c526a049aff798546ff2c7f5810d2ef32172..04b31cf70ca36c5631772dc300986223be1f79d2 100644 (file)
@@ -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