Salome HOME
Porting on OCCT 7.0 and Qt 5. Make compilable version.
[modules/hydro.git] / doc / salome / examples / h010_normalCaseManualMesh.py
index 66fa95a93d3a15d6987018430426c4ad6c0bdf87..4b205db5bfbbfef11eada01366c71157b65d67ee 100644 (file)
@@ -8,62 +8,6 @@ import salome
 
 salome.salome_init()
 theStudy = salome.myStudy
-
-# -------------------------------------
-
-def controlGeomProps(geomShape, refLength, refArea):
-  props = geompy.BasicProperties(geomShape)
-  print " Wires length: ", props[0]
-  print " Surface area: ", props[1]
-  print " Volume      : ", props[2]
-  deltaLength = 2.0*abs((props[0] - refLength)/(props[0] + refLength))
-  deltaArea   = 2.0*abs((props[1] - refArea)/(props[1] + refArea))
-  if deltaLength > 1e-7 or deltaArea > 1e-7 or props[2] != 0:
-    print "While must be:"
-    print " Wires length: ", refLength
-    print " Surface area: ", refArea
-    print " Volume      : ", 0.
-    raise ValueError("Bad length or area") 
-
-# -------------------------------------
-
-def controlMeshStats(aMesh, nbNodes, nbEdges, nbTriangles):
-  """
-  Only for a mesh, not for a subMesh
-  """
-  tolerance = 0.05
-  references = {}
-  references['Entity_Node'] = nbNodes
-  references['Entity_Edge'] = nbEdges
-  references['Entity_Triangle'] = nbTriangles
-  
-  mesures = aMesh.GetMeshInfo()
-  #print mesures
-  d= {}
-  for key, value in mesures.iteritems():
-    d[str(key)] = value
-  #print d
-  for key in ('Entity_Triangle', 'Entity_Edge', 'Entity_Node'):
-    if (d[key] < (1.0 - tolerance)*references[key]) \
-    or (d[key] > (1.0 + tolerance)*references[key]):
-      print aMesh.GetName()
-      print key, ": value: ", d[key], " reference: ", references[key]
-      raise ValueError("Bad number of nodes or elements") 
-  
-# -------------------------------------
-
-def controlSubMeshStats(aSubMesh, nbItems):
-  """
-  Only for a mesh, not for a subMesh
-  """
-  tolerance = 0.05
-  mesures = aSubMesh.GetMeshInfo()
-  nbRef = sum(mesures)
-  if (nbItems < (1.0 - tolerance)*nbRef) \
-  or (nbItems > (1.0 + tolerance)*nbRef):
-    print aSubMesh.GetName()
-    print "value: ", nbItems, " reference: ", nbRef
-    raise ValueError("Bad number of nodes or elements") 
   
 #----------------------
 # --- HYDRO 
@@ -83,7 +27,8 @@ garonne_ign_01.SetName( "garonne_ign_01" )
 garonne_ign_01.SetZLevel( 0 )
 
 
-garonne_ign_01.LoadImage(os.path.join(HYDRO_SAMPLES, "garonne_ign_01.png" ))
+if not(garonne_ign_01.LoadImage(os.path.join(HYDRO_SAMPLES, "garonne_ign_01.png" ))):
+  raise ValueError('problem while loading image')
 
 garonne_ign_01.SetLocalPoints( QPoint( 40, 817 ),
                                QPoint( 1325, 85 ) )
@@ -100,7 +45,8 @@ garonne_ign_02.SetName( "garonne_ign_02" )
 garonne_ign_02.SetZLevel( 1 )
 
 
-garonne_ign_02.LoadImage( os.path.join(HYDRO_SAMPLES, "garonne_ign_02.png" ))
+if not(garonne_ign_02.LoadImage( os.path.join(HYDRO_SAMPLES, "garonne_ign_02.png" ))):
+  raise ValueError('problem while loading image')
 
 garonne_ign_02.SetLocalPoints( QPoint( 1389, 447 ),
                                QPoint( 784, 481 ) )
@@ -253,7 +199,8 @@ Cloud_02 = hydro_doc.CreateObject( KIND_BATHYMETRY )
 Cloud_02.SetName( "Cloud_02" )
 
 Cloud_02.SetAltitudesInverted( 0 )
-Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))
+if not(Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))):
+  raise ValueError('problem while loading bathymetry')
 
 Cloud_02.Update()
 
@@ -262,7 +209,8 @@ garonne_point_L93 = hydro_doc.CreateObject( KIND_BATHYMETRY )
 garonne_point_L93.SetName( "garonne_point_L93" )
 
 garonne_point_L93.SetAltitudesInverted( 0 )
-garonne_point_L93.ImportFromFile( os.path.join(HYDRO_SAMPLES, "garonne_point_L93.xyz" ))
+if not(garonne_point_L93.ImportFromFile( os.path.join(HYDRO_SAMPLES, "garonne_point_L93.xyz" ))):
+  raise ValueError('problem while loading bathymetry')
 
 garonne_point_L93.Update()
 
@@ -309,7 +257,6 @@ garonne_1 = hydro_doc.CreateObject( KIND_CALCULATION )
 garonne_1.SetName( "garonne_1" )
 
 garonne_1.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
-garonne_1.SetAssignmentLandCoverMode( HYDROData_CalculationCase.AUTOMATIC )
 garonne_1.AddGeometryObject( litMineur )
 garonne_1.AddGeometryObject( domaineEtendu )
 garonne_1.AddGeometryObject( litMajeur )
@@ -355,6 +302,7 @@ import GEOM
 from salome.geom import geomBuilder
 import math
 import SALOMEDS
+from salome.hydrotools.controls import controlGeomProps
 
 geompy = geomBuilder.New(theStudy)
 
@@ -394,9 +342,9 @@ geompy.addToStudyInFather( HYDRO_garonne_1, bordGaucheDomaine, 'bordGaucheDomain
 geompy.addToStudyInFather( HYDRO_garonne_1, bordDroiteDomaine, 'bordDroiteDomaine' )
 
 # --- basic properties control: edges length, surfaces
-controlGeomProps(riveGauche,  29149.36918,  35992556.454929)
-controlGeomProps(litMineur,   30337.548492,  3646827.749809)
-controlGeomProps(riveDroite,  32012.343241, 26177085.460092)
+controlGeomProps(geompy, riveGauche,  29149.36918,  35948828.352061)
+controlGeomProps(geompy, litMineur,   30337.548492,  3488480.304388)
+controlGeomProps(geompy, riveDroite,  32012.343241, 25998769.23615)
 
 #----------------------
 # --- Meshing 
@@ -404,6 +352,7 @@ controlGeomProps(riveDroite,  32012.343241, 26177085.460092)
 
 import  SMESH, SALOMEDS
 from salome.smesh import smeshBuilder
+from salome.hydrotools.controls import controlMeshStats, controlSubMeshStats
 
 smesh = smeshBuilder.New(theStudy)
 
@@ -438,6 +387,7 @@ isDone = garonne_1.SetMeshOrder( [ [ subMesh_SectionsGaronne, subMesh_litMineur
 # --- compute mesh
 isDone = garonne_1.Compute()
 isDone = garonne_1.SplitQuadObject( garonne_1, 1 )
+isDone = garonne_1.ReorientObject( garonne_1 )
 
 # --- geometrical groups of edges
 garonne_1_litMineur_Outer_1 = garonne_1.GroupOnGeom(garonne_1_litMineur_Outer,'garonne_1_litMineur_Outer',SMESH.EDGE)