5 pythonVersion = 'python' + sysconfig.get_python_version()
6 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', pythonVersion, 'site-packages', 'salome', 'salome', 'hydro')
12 from salome.smesh import smeshBuilder
13 smesh = smeshBuilder.New()
18 from PyQt5.QtWidgets import QDialog, QFileDialog, QTableWidgetItem, QComboBox, QMessageBox
23 salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
25 from .generate_interpolz import generate, generate_B
27 def get_med_groups( file_path ):
28 #print "get_med_groups", file_path
30 #meshes = MEDLoader.GetMeshNames(file_path)
31 (meshes, status) = smesh.CreateMeshesFromMED(file_path)
33 print('No meshes found')
36 print('No mesh found')
39 print('Found mesh:', mesh1)
41 #groups = list(MEDLoader.GetMeshGroupsNames(file_path, mesh1))
42 grps = mesh1.GetGroups()
43 groups = [grp.GetName() for grp in grps if grp.GetType() == SMESH.FACE]
45 print("Problem! There are no groups of faces in the mesh!")
46 print("Please create at least the groups of faces corresponding to each region of the HYDRO case")
48 print('Found groups:', groups)
50 print('No groups found')
54 def get_hydro_regions( calc_case_name ):
55 #aStudyId = salome.myStudyId
56 doc = HYDROPy.HYDROData_Document.Document()
57 case = doc.FindObjectByName( calc_case_name )
58 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
59 regions = case.GetRegions()
63 regions_names.append( str(rname) )
65 # shape_groups = case.GetGeometryGroups()
66 # for sg in shape_groups:
67 # sgname = sg.GetName()
68 # regions_names.append( sgname )
74 def get_selected_calc_case():
75 ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
76 #aStudyId = salome.myStudyId
77 doc = HYDROPy.HYDROData_Document.Document()
81 case = doc.FindObjectByName( name )
82 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
86 def get_selected_bathy():
87 ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
88 #aStudyId = salome.myStudyId
89 doc = HYDROPy.HYDROData_Document.Document()
93 case = doc.FindObjectByName( name )
94 if isinstance(case, HYDROPy.HYDROData_Bathymetry):
98 class InterpolzDlg( QDialog ):
99 def __init__(self, parent = None):
100 QDialog.__init__( self, parent )
101 p = hydro_solver_root
102 uic.loadUi( p+'/interpolz.ui', self )
103 self.setWindowTitle( 'Generate interpolz script' )
104 SalomePyQt.SalomePyQt.getObjectBrowser().selectionChanged.connect(self.onSelectionChanged)
105 self.btnOutputPath.clicked.connect(self.onOutputFile)
106 self.btnMEDFile.clicked.connect(self.onMEDFile)
107 self.CalcCase.textChanged.connect(self.onCalcCaseChanged)
108 #self.BathyName.textChanged.connect(self.onBathyNameChanged)
109 self.MEDFile.textChanged.connect(self.onMEDChanged)
110 self.UndefZ.setRange( -100000, 100000 )
111 self.UndefZ.setValue( -9999 )
112 self.UndefZ_B.setRange( -100000, 100000 )
113 self.UndefZ_B.setValue( -9999 )
114 self.InterpMethod_B.addItem( "Interpolation at the nearest point" )
115 self.InterpMethod_B.addItem( "Linear interpolation on a cloud triangulation" )
116 self.InterpMethod.addItem( "Interpolation at the nearest point" )
117 self.InterpMethod.addItem( "Linear interpolation on a cloud triangulation" )
118 self.InterpMethod.currentIndexChanged.connect(self.onInterpChanged)
119 self.ApplyClose.clicked.connect(self.onApplyClose)
120 self.Apply.clicked.connect(self.onApply)
121 self.Close.clicked.connect(self.onClose)
122 self.Help.clicked.connect(self.onHelp)
123 self.onSelectionChanged()
124 self.tabWidget.setCurrentIndex(0)
125 self.regions = [] #to avoid attrib error
127 def onSelectionChanged( self ):
128 calc_case_name = get_selected_calc_case()
129 if calc_case_name is not None:
130 self.CalcCase.setText( calc_case_name )
131 bathy_name = get_selected_bathy()
132 if bathy_name is not None:
133 self.BathyName.setText( bathy_name )
135 def onOutputFile( self ):
136 caption = "Python file"
138 fname, filt = QFileDialog.getSaveFileName( self, caption, ".", mask )
139 if fname!=None and fname!="":
140 if fname.split('.')[-1] != 'py':
142 self.OutputPath.setText( fname )
144 def onMEDFile( self ):
147 fname, filt = QFileDialog.getOpenFileName( self, caption, ".", mask )
148 if fname!=None and fname!="":
149 self.MEDFile.setText( fname )
151 def onCalcCaseChanged( self ):
152 self.regions = get_hydro_regions( str(self.CalcCase.text()) )
155 #def onBathyNameChanged( self ):
156 # #self.regions = get_hydro_regions( str(self.CalcCase.text()) )
157 # self.onMEDChanged()
159 def onMEDChanged( self ):
160 self.med_groups = get_med_groups( str(self.MEDFile.text()) )
161 print(self.med_groups)
162 n = len( self.med_groups )
163 self.Groups.setRowCount( n )
164 self.medGroupNames.clear()
165 for i in range( 0, n ):
166 self.medGroupNames.addItem(self.med_groups[i])
168 for i in range( 0, n ):
169 if self.Groups.item( i, 0 ) is None:
170 self.Groups.setItem( i, 0, QTableWidgetItem() )
171 self.Groups.setItem( i, 1, QTableWidgetItem() )
172 self.Groups.setItem( i, 2, QTableWidgetItem() )
173 self.Groups.item( i, 0 ).setText( self.med_groups[i] )
175 cb = QComboBox( self.Groups )
177 for r in self.regions:
179 self.Groups.setCellWidget( i, 1, cb )
181 icb = QComboBox( self.Groups )
182 icb.addItem( 'Interpolation at the nearest point' )
183 icb.addItem( 'Linear interpolation on a cloud triangulation' )
184 self.Groups.setCellWidget( i, 2, icb )
185 icb.currentIndexChanged.connect(self.onCBInterpChanged)
188 def onCBInterpChanged( self ):
190 for i in range( 0, self.Groups.rowCount() ):
191 ind_set.add( self.Groups.cellWidget( i, 2 ).currentIndex() )
192 if len(ind_set) == 2:
193 self.InterpMethod.setStyleSheet("QComboBox { background-color: grey; }")
194 elif len(ind_set) == 1:
195 self.InterpMethod.setStyleSheet("")
197 def onInterpChanged( self ):
198 n = self.Groups.rowCount()
199 for i in range( 0, n ):
200 icb = self.Groups.cellWidget(i, 2)
201 icb.setCurrentIndex(self.InterpMethod.currentIndex())
203 def onApplyClose( self ):
208 path = str(self.OutputPath.text())
209 med_file = str(self.MEDFile.text())
210 print('current TAB = ', self.tabWidget.currentIndex())
211 isScriptExec = self.cb_scriptExec.isChecked()
213 if self.tabWidget.currentIndex() == 0: #calc case tab
214 calc_case = str(self.CalcCase.text())
215 med_groups_regions = {}
216 regions_interp_method = {}
217 for i in range( 0, self.Groups.rowCount() ):
218 med_group = str( self.Groups.item( i, 0 ).text() )
219 hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
220 if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' :
221 med_groups_regions[med_group] = hydro_reg
222 interp_ind = str( self.Groups.cellWidget( i, 2 ).currentIndex() )
223 regions_interp_method[hydro_reg] = interp_ind
224 z_undef = self.UndefZ.value()
225 #interp = str(self.InterpMethod.currentText())
229 msg = "Please input the output path"
230 elif len(calc_case)==0:
231 msg = "Please choose the calculation case"
232 elif len(med_file)==0:
233 msg = "Please choose the MED file"
234 elif len(med_groups_regions)==0:
235 msg = "Please fill groups table"
236 #elif len(interp)==0:
237 # msg = "Please choose interpolation method"
242 #if 'Linear' in interp:
244 #generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp )
245 generate( path, calc_case, med_file, med_groups_regions, z_undef, regions_interp_method )
246 msg = "InterpolZ script is successfully generated"
250 msg = msg + " and executed"
251 exec(open(path).read())
253 QMessageBox.information( self, "", msg )
256 elif self.tabWidget.currentIndex() == 1: #bathymetry tab
257 bathy_name = str(self.BathyName.text())
258 group_name = str(self.medGroupNames.currentText())
259 interp = str(self.InterpMethod_B.currentText())
260 z_undef = self.UndefZ_B.value()
264 msg = "Please input the output path"
265 elif len(bathy_name)==0:
266 msg = "Please choose the bathymetry"
267 elif len(med_file)==0:
268 msg = "Please choose the MED file"
269 elif len(group_name)==0:
270 msg = "Please choose MED group"
272 msg = "Please choose interpolation method"
278 if 'Linear' in interp:
280 generate_B( path, bathy_name, med_file, group_name, z_undef, iinterp )
281 msg = "InterpolZ_B script is successfully generated"
285 msg = msg + " and executed"
286 exec(open(path).read())
288 QMessageBox.information( self, "", msg )
294 """Shows help page"""
297 <h1>Interpolz dialog</h1>
299 This dialog is a tool for generation and execution of the script <b>interpolz.py</b>.
301 <h3>Input MED file</h3>
302 The path to MED file where MED groups are extracted.
304 <h2>TAB: Calculation Case</h2>
306 <ol><h3>Calculation case</h3>
307 The name of the calculation case. It can be filled automatically on the base of selection or can be set by user.
310 The interpolation method (interpolation at the nearest point and linear interpolation from a triangulation of the cloud of points).
313 The Z value for nodes outside the regions.
316 The table with MED groups and regions names.</ol>
318 <h2>TAB: MED group bathymetry</h2>
320 <ol><h3>Bathymetry</h3>
321 The name of the bathymetry. It can be filled automatically on the base of selection or can be set by user.
324 Select the face group on which to apply the new bathymetry.
327 The interpolation method (interpolation at the nearest point and linear interpolation from a triangulation of the cloud of points).
330 The Z value for nodes outside the regions.</ol>
332 <h3>Script output path</h3>
333 The path for the output, i.e. the path of the target script interpolz.
335 <h3>Execute the script</h3>
336 Execute the script on Apply if checked, or just keep it for later use.
338 When the data is set, the user clicks on "Apply" or "Apply and Close" button to perform the script generation.
340 QMessageBox.about(self, self.tr("About bathymetry interpolation dialog"), msg);
343 if __name__=='__main__':