1 # -*- coding: utf-8 -*-
4 HYDRO_SAMPLES = os.path.join( os.environ["HYDRO_ROOT_DIR"], "bin/salome/test/HYDRO")
10 theStudy = salome.myStudy
17 from PyQt5.QtCore import *
18 from PyQt5.QtGui import *
20 hydro_doc = HYDROData_Document.Document( theStudy._get_StudyId() )
22 hydro_doc.SetLocalCS( 430000.000, 6350000.000 )
24 Strickler_table_1 = hydro_doc.CreateObject( KIND_STRICKLER_TABLE )
25 Strickler_table_1.SetName( "Strickler table_1" )
27 Strickler_table_1.SetAttrName( "CODE_06" )
29 Strickler_table_1.Set( u"Pelouses et pâturages naturels", 1.0321 )
30 Strickler_table_1.SetAttrValue( u"Pelouses et pâturages naturels", "321" )
31 Strickler_table_1.SetColor( u"Pelouses et pâturages naturels", QColor( 204, 242, 77 ) )
33 Strickler_table_1.Set( u"Aéroports", 1.0124 )
34 Strickler_table_1.SetAttrValue( u"Aéroports", "124" )
35 Strickler_table_1.SetColor( u"Aéroports", QColor( 230, 204, 230 ) )
37 Strickler_table_1.Set( u"Systèmes culturaux et parcellaires complexes", 1.0242 )
38 Strickler_table_1.SetAttrValue( u"Systèmes culturaux et parcellaires complexes", "242" )
39 Strickler_table_1.SetColor( u"Systèmes culturaux et parcellaires complexes", QColor( 255, 230, 77 ) )
41 Strickler_table_1.Set( u"Cultures annuelles associées à des cultures permanentes", 1.0241 )
42 Strickler_table_1.SetAttrValue( u"Cultures annuelles associées à des cultures permanentes", "241" )
43 Strickler_table_1.SetColor( u"Cultures annuelles associées à des cultures permanentes", QColor( 255, 230, 166 ) )
45 Strickler_table_1.Set( u"Forêt et végétation arbustive en mutation", 1.0324 )
46 Strickler_table_1.SetAttrValue( u"Forêt et végétation arbustive en mutation", "324" )
47 Strickler_table_1.SetColor( u"Forêt et végétation arbustive en mutation", QColor( 166, 242, 0 ) )
49 Strickler_table_1.Set( u"Décharges", 1.0132 )
50 Strickler_table_1.SetAttrValue( u"Décharges", "132" )
51 Strickler_table_1.SetColor( u"Décharges", QColor( 166, 77, 0 ) )
53 Strickler_table_1.Set( u"Végétation clairsemée", 1.0333 )
54 Strickler_table_1.SetAttrValue( u"Végétation clairsemée", "333" )
55 Strickler_table_1.SetColor( u"Végétation clairsemée", QColor( 204, 255, 204 ) )
57 Strickler_table_1.Set( u"Prairies et autres surfaces toujours en herbe à usage agricole", 1.0231 )
58 Strickler_table_1.SetAttrValue( u"Prairies et autres surfaces toujours en herbe à usage agricole", "231" )
59 Strickler_table_1.SetColor( u"Prairies et autres surfaces toujours en herbe à usage agricole", QColor( 230, 230, 77 ) )
61 Strickler_table_1.Set( u"Périmètres irrigués en permanence", 1.0212 )
62 Strickler_table_1.SetAttrValue( u"Périmètres irrigués en permanence", "212" )
63 Strickler_table_1.SetColor( u"Périmètres irrigués en permanence", QColor( 255, 255, 0 ) )
65 Strickler_table_1.Set( u"Plans d'eau", 1.0512 )
66 Strickler_table_1.SetAttrValue( u"Plans d'eau", "512" )
67 Strickler_table_1.SetColor( u"Plans d'eau", QColor( 128, 242, 230 ) )
69 Strickler_table_1.Set( u"Territoires agroforestiers", 1.0244 )
70 Strickler_table_1.SetAttrValue( u"Territoires agroforestiers", "244" )
71 Strickler_table_1.SetColor( u"Territoires agroforestiers", QColor( 242, 204, 166 ) )
73 Strickler_table_1.Set( u"Forêts mélangées", 1.0313 )
74 Strickler_table_1.SetAttrValue( u"Forêts mélangées", "313" )
75 Strickler_table_1.SetColor( u"Forêts mélangées", QColor( 77, 255, 0 ) )
77 Strickler_table_1.Set( u"Glaciers et neiges éternelles", 1.0335 )
78 Strickler_table_1.SetAttrValue( u"Glaciers et neiges éternelles", "335" )
79 Strickler_table_1.SetColor( u"Glaciers et neiges éternelles", QColor( 166, 230, 204 ) )
81 Strickler_table_1.Set( u"Plages, dunes et sable", 1.0331 )
82 Strickler_table_1.SetAttrValue( u"Plages, dunes et sable", "331" )
83 Strickler_table_1.SetColor( u"Plages, dunes et sable", QColor( 230, 230, 230 ) )
85 Strickler_table_1.Set( u"Zones incendiées", 1.0334 )
86 Strickler_table_1.SetAttrValue( u"Zones incendiées", "334" )
87 Strickler_table_1.SetColor( u"Zones incendiées", QColor( 0, 0, 0 ) )
89 Strickler_table_1.Set( u"Tissu urbain continu", 1.0111 )
90 Strickler_table_1.SetAttrValue( u"Tissu urbain continu", "111" )
91 Strickler_table_1.SetColor( u"Tissu urbain continu", QColor( 230, 0, 77 ) )
93 Strickler_table_1.Set( u"Chantiers", 1.0133 )
94 Strickler_table_1.SetAttrValue( u"Chantiers", "133" )
95 Strickler_table_1.SetColor( u"Chantiers", QColor( 255, 77, 255 ) )
97 Strickler_table_1.Set( u"Estuaires", 1.0522 )
98 Strickler_table_1.SetAttrValue( u"Estuaires", "522" )
99 Strickler_table_1.SetColor( u"Estuaires", QColor( 166, 255, 230 ) )
101 Strickler_table_1.Set( u"Marais maritimes", 1.0421 )
102 Strickler_table_1.SetAttrValue( u"Marais maritimes", "421" )
103 Strickler_table_1.SetColor( u"Marais maritimes", QColor( 204, 204, 255 ) )
105 Strickler_table_1.Set( u"Forêts de conifères", 1.0312 )
106 Strickler_table_1.SetAttrValue( u"Forêts de conifères", "312" )
107 Strickler_table_1.SetColor( u"Forêts de conifères", QColor( 0, 166, 0 ) )
109 Strickler_table_1.Set( u"Surfaces essentiellement agricoles, interrompues par des espaces naturels importants", 1.0243 )
110 Strickler_table_1.SetAttrValue( u"Surfaces essentiellement agricoles, interrompues par des espaces naturels importants", "243" )
111 Strickler_table_1.SetColor( u"Surfaces essentiellement agricoles, interrompues par des espaces naturels importants", QColor( 230, 204, 77 ) )
113 Strickler_table_1.Set( u"Tourbières", 1.0412 )
114 Strickler_table_1.SetAttrValue( u"Tourbières", "412" )
115 Strickler_table_1.SetColor( u"Tourbières", QColor( 77, 77, 255 ) )
117 Strickler_table_1.Set( u"Extraction de matériaux", 1.0131 )
118 Strickler_table_1.SetAttrValue( u"Extraction de matériaux", "131" )
119 Strickler_table_1.SetColor( u"Extraction de matériaux", QColor( 166, 0, 204 ) )
121 Strickler_table_1.Set( u"Réseaux routier et ferroviaire et espaces associés", 1.0122 )
122 Strickler_table_1.SetAttrValue( u"Réseaux routier et ferroviaire et espaces associés", "122" )
123 Strickler_table_1.SetColor( u"Réseaux routier et ferroviaire et espaces associés", QColor( 204, 0, 0 ) )
125 Strickler_table_1.Set( u"Mers et océans", 1.0523 )
126 Strickler_table_1.SetAttrValue( u"Mers et océans", "523" )
127 Strickler_table_1.SetColor( u"Mers et océans", QColor( 230, 242, 255 ) )
129 Strickler_table_1.Set( u"Equipements sportifs et de loisirs", 1.0142 )
130 Strickler_table_1.SetAttrValue( u"Equipements sportifs et de loisirs", "142" )
131 Strickler_table_1.SetColor( u"Equipements sportifs et de loisirs", QColor( 255, 230, 255 ) )
133 Strickler_table_1.Set( u"Forêts de feuillus", 1.0311 )
134 Strickler_table_1.SetAttrValue( u"Forêts de feuillus", "311" )
135 Strickler_table_1.SetColor( u"Forêts de feuillus", QColor( 128, 255, 0 ) )
137 Strickler_table_1.Set( u"Vergers et petits fruits", 1.0222 )
138 Strickler_table_1.SetAttrValue( u"Vergers et petits fruits", "222" )
139 Strickler_table_1.SetColor( u"Vergers et petits fruits", QColor( 242, 166, 77 ) )
141 Strickler_table_1.Set( u"Végétation sclérophylle", 1.0323 )
142 Strickler_table_1.SetAttrValue( u"Végétation sclérophylle", "323" )
143 Strickler_table_1.SetColor( u"Végétation sclérophylle", QColor( 166, 230, 77 ) )
145 Strickler_table_1.Set( u"Landes et broussailles", 1.0322 )
146 Strickler_table_1.SetAttrValue( u"Landes et broussailles", "322" )
147 Strickler_table_1.SetColor( u"Landes et broussailles", QColor( 166, 255, 128 ) )
149 Strickler_table_1.Set( u"Tissu urbain discontinu", 1.0112 )
150 Strickler_table_1.SetAttrValue( u"Tissu urbain discontinu", "112" )
151 Strickler_table_1.SetColor( u"Tissu urbain discontinu", QColor( 255, 0, 0 ) )
153 Strickler_table_1.Set( u"Cours et voies d'eau", 1.0511 )
154 Strickler_table_1.SetAttrValue( u"Cours et voies d'eau", "511" )
155 Strickler_table_1.SetColor( u"Cours et voies d'eau", QColor( 0, 204, 242 ) )
157 Strickler_table_1.Set( u"Oliveraies", 1.0223 )
158 Strickler_table_1.SetAttrValue( u"Oliveraies", "223" )
159 Strickler_table_1.SetColor( u"Oliveraies", QColor( 230, 166, 0 ) )
161 Strickler_table_1.Set( u"Vignobles", 1.0221 )
162 Strickler_table_1.SetAttrValue( u"Vignobles", "221" )
163 Strickler_table_1.SetColor( u"Vignobles", QColor( 230, 128, 0 ) )
165 Strickler_table_1.Set( u"Rizières", 1.0213 )
166 Strickler_table_1.SetAttrValue( u"Rizières", "213" )
167 Strickler_table_1.SetColor( u"Rizières", QColor( 230, 230, 0 ) )
169 Strickler_table_1.Set( u"Zones portuaires", 1.0123 )
170 Strickler_table_1.SetAttrValue( u"Zones portuaires", "123" )
171 Strickler_table_1.SetColor( u"Zones portuaires", QColor( 230, 204, 204 ) )
173 Strickler_table_1.Set( u"Zones industrielles ou commerciales et installations publiques", 1.0121 )
174 Strickler_table_1.SetAttrValue( u"Zones industrielles ou commerciales et installations publiques", "121" )
175 Strickler_table_1.SetColor( u"Zones industrielles ou commerciales et installations publiques", QColor( 204, 77, 242 ) )
177 Strickler_table_1.Set( u"Marais salants", 1.0422 )
178 Strickler_table_1.SetAttrValue( u"Marais salants", "422" )
179 Strickler_table_1.SetColor( u"Marais salants", QColor( 230, 230, 255 ) )
181 Strickler_table_1.Set( u"Marais intérieurs", 1.0411 )
182 Strickler_table_1.SetAttrValue( u"Marais intérieurs", "411" )
183 Strickler_table_1.SetColor( u"Marais intérieurs", QColor( 166, 166, 255 ) )
185 Strickler_table_1.Set( u"Espaces verts urbains", 1.0141 )
186 Strickler_table_1.SetAttrValue( u"Espaces verts urbains", "141" )
187 Strickler_table_1.SetColor( u"Espaces verts urbains", QColor( 255, 166, 255 ) )
189 Strickler_table_1.Set( u"Lagunes littorales", 1.0521 )
190 Strickler_table_1.SetAttrValue( u"Lagunes littorales", "521" )
191 Strickler_table_1.SetColor( u"Lagunes littorales", QColor( 0, 255, 166 ) )
193 Strickler_table_1.Set( u"Roches nues", 1.0332 )
194 Strickler_table_1.SetAttrValue( u"Roches nues", "332" )
195 Strickler_table_1.SetColor( u"Roches nues", QColor( 204, 204, 204 ) )
197 Strickler_table_1.Set( u"Terres arables hors périmètres d'irrigation", 1.0211 )
198 Strickler_table_1.SetAttrValue( u"Terres arables hors périmètres d'irrigation", "211" )
199 Strickler_table_1.SetColor( u"Terres arables hors périmètres d'irrigation", QColor( 255, 255, 168 ) )
201 Strickler_table_1.Set( u"Zones intertidales", 1.0423 )
202 Strickler_table_1.SetAttrValue( u"Zones intertidales", "423" )
203 Strickler_table_1.SetColor( u"Zones intertidales", QColor( 166, 166, 230 ) )
206 Strickler_table_1.Update()
208 contour = hydro_doc.CreateObject( KIND_POLYLINEXY )
209 contour.SetName( "contour" )
211 contour.SetZLevel( 0 )
213 contour.AddSection( "Section_1", 0, 1 )
214 contour.AddPoint( 0, gp_XY( 56217.97, 14517.47 ) )
215 contour.AddPoint( 0, gp_XY( 58938.24, 14526.73 ) )
216 contour.AddPoint( 0, gp_XY( 58947.49, 13277.63 ) )
217 contour.AddPoint( 0, gp_XY( 56208.72, 13286.88 ) )
222 Cloud_02 = hydro_doc.CreateObject( KIND_BATHYMETRY )
223 Cloud_02.SetName( "Cloud_02" )
225 Cloud_02.SetAltitudesInverted( 0 )
226 if not(Cloud_02.ImportFromFile( os.path.join(HYDRO_SAMPLES, "Cloud_02.xyz" ))):
227 raise ValueError('problem while loading bathymetry')
232 domaine = hydro_doc.CreateObject( KIND_IMMERSIBLE_ZONE )
233 domaine.SetName( "domaine" )
235 domaine.SetZLevel( 1 )
237 domaine.SetAltitudeObject( Cloud_02 )
238 domaine.SetPolyline( contour )
244 etude = hydro_doc.CreateObject( KIND_CALCULATION )
245 etude.SetName( "etude" )
247 etude.SetAssignmentMode( HYDROData_CalculationCase.MANUAL )
248 etude.AddGeometryObject( domaine )
250 case_geom_group = domaine.GetGroup( 0 )
251 etude.AddGeometryGroup( case_geom_group )
252 etude.SetBoundaryPolyline( contour )
254 # Start the algorithm of the partition and assignment
256 etude_Reg_1 = hydro_doc.FindObjectByName( "etude_Reg_1" )
257 etude_Zone_1 = hydro_doc.FindObjectByName( "etude_Zone_1" )
258 etude_Zone_1.SetColor( QColor( 124, 192, 64 ))
259 etude_Reg_1.AddZone( etude_Zone_1 )
260 etude_Reg_1.SetName( "etude_Reg_1" )
262 # Export of the calculation case
263 etude_entry = etude.Export( theStudy._get_StudyId() )
265 # Get geometry shape and print debug information
267 print "Entry:", etude_entry
268 HYDRO_etude_1 = salome.IDToObject( str( etude_entry ) )
269 print "Geom shape:", HYDRO_etude_1
270 print "Geom shape name:", HYDRO_etude_1.GetName()
278 from salome.geom import geomBuilder
283 geompy = geomBuilder.New(theStudy)
285 #geomObj_1 = geompy.CreateGroup(HYDRO_etude, geompy.ShapeType["EDGE"])
286 #geompy.UnionIDs(geomObj_1, [7, 9])
287 #geomObj_3 = geompy.CreateGroup(HYDRO_etude, geompy.ShapeType["EDGE"])
288 #geompy.UnionIDs(geomObj_3, [4, 11, 17, 24, 26, 28, 14, 19, 20, 22, 31, 39, 41, 33, 35, 37])
289 etude_domaine_Outer = geompy.CreateGroup(HYDRO_etude_1, geompy.ShapeType["EDGE"])
290 geompy.UnionIDs(etude_domaine_Outer, [3, 6, 8, 10])
291 domaine = geompy.CreateGroup(HYDRO_etude_1, geompy.ShapeType["FACE"])
292 geompy.UnionIDs(domaine, [1])
293 geompy.addToStudyInFather( HYDRO_etude_1, etude_domaine_Outer, 'etude_domaine_Outer' )
294 geompy.addToStudyInFather( HYDRO_etude_1, domaine, 'domaine' )
300 import SMESH, SALOMEDS
301 from salome.smesh import smeshBuilder
303 smesh = smeshBuilder.New(theStudy)
304 relief = smesh.Mesh(HYDRO_etude_1)
305 NETGEN_2D = relief.Triangle(algo=smeshBuilder.NETGEN_1D2D)
306 NETGEN_2D_Parameters_1 = NETGEN_2D.Parameters()
307 NETGEN_2D_Parameters_1.SetMaxSize( 25 )
308 NETGEN_2D_Parameters_1.SetSecondOrder( 0 )
309 NETGEN_2D_Parameters_1.SetOptimize( 1 )
310 NETGEN_2D_Parameters_1.SetFineness( 3 )
311 NETGEN_2D_Parameters_1.SetMinSize( 10 )
312 NETGEN_2D_Parameters_1.SetUseSurfaceCurvature( 1 )
313 NETGEN_2D_Parameters_1.SetFuseEdges( 1 )
314 NETGEN_2D_Parameters_1.SetQuadAllowed( 0 )
315 isDone = relief.Compute()
316 domaine_1 = relief.GroupOnGeom(domaine,'domaine',SMESH.FACE)
317 domaine_2 = relief.GroupOnGeom(domaine,'domaine',SMESH.NODE)
318 smesh.SetName(relief, 'relief')
320 med_file = r'/tmp/relief.med'
329 relief.ExportMED( med_file, 0, SMESH.MED_V2_2, 1, None ,1)
331 print 'ExportToMEDX() failed. Invalid file name?'
334 ## Set names of Mesh objects
335 smesh.SetName(domaine_1, 'domaine')
336 smesh.SetName(NETGEN_2D.GetAlgorithm(), 'NETGEN_2D')
337 smesh.SetName(relief.GetMesh(), 'relief')
338 smesh.SetName(domaine_2, 'domaine')
339 smesh.SetName(NETGEN_2D_Parameters_1, 'NETGEN 2D Parameters_1')
342 if salome.sg.hasDesktop():
343 salome.sg.updateObjBrowser(1)
345 #----------------------
346 # --- Z interpolation with HYDRO
347 #----------------------
349 from salome.hydrotools.interpolZ import interpolZ, createZfield2
350 from salome.hydrotools.controls import controlStatZ
352 # --- nom du cas dans HYDRO
355 # --- fichier med 2D(x,y) du cas, produit par SMESH
356 fichierMaillage = med_file
358 # --- dictionnaire: (clé = nom de groupe med, valeur= nom de région)
359 dicoGroupeRegion= dict(domaine = 'etude_Reg_1',
362 # --- méthode d'interpolation sur les nuages de points de bathymétrie
363 # interpolMethod = 0 : interpolation au point le plus proche
364 # interpolMethod = 1 : interpolation linéaire de l'altitude par triangulation du nuage de points
367 # --- valeur de Z à prendre quand le noeud n'est pas trouvé dans la région (détection de problèmes)
370 # --- Z interpolation Z sur la bathymetrie/altimetrie aux noeuds du maillage
371 statz = interpolZ(nomCas, fichierMaillage, dicoGroupeRegion, zUndef, interpolMethod)
372 refstatz = {'domaine': (27.101, 168.257)}
373 controlStatZ(statz, refstatz)
375 # --- add a field on nodes of type double with z values, named "BOTTOM"
376 createZfield2(fichierMaillage)