+import os
+hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro')
+
def replace( lines, pattern, subst ):
for i in range( 0, len( lines ) ):
line = lines[i]
def generate( path, calc_case, med_file, med_groups_regions, z_undef, interp ):
f = open( path, "w" )
- tf = open( "interpolz.template", "r" )
+ tf = open( hydro_solver_root+"/interpolz.template", "r" )
templ = tf.readlines()
replace( templ, "<case_name_from_dlg>", calc_case )
f.close()
-
-generate( "test_interpolz.py", "case_1", "mesh.med", {"group_1":"reg_1", "group_2":"reg_2"}, -9999, "linear" )
+if __name__=='__main__':
+ generate( "test_interpolz.py", "case_1", "mesh.med", {"group_1":"reg_1", "group_2":"reg_2"}, -9999, "linear" )
import sys, os
sys.path.append(os.path.join(os.environ['MEDFILE_ROOT_DIR'], 'lib/python2.7/site-packages/med'))
+hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro')
+sys.path.append(hydro_solver_root)
import salome
salome.salome_init()
import libSALOME_Swig
salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
+from generate_interpolz import generate
+
def get_med_groups( file_path ):
#print "get_med_groups", file_path
try:
class InterpolzDlg( QtGui.QDialog ):
def __init__(self, parent = None):
QtGui.QDialog.__init__( self, parent )
- p = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro')
+ p = hydro_solver_root
uic.loadUi( p+'/interpolz.ui', self )
self.setWindowTitle( 'Generate interpolz script' )
self.connect( SalomePyQt.SalomePyQt.getObjectBrowser(), QtCore.SIGNAL("selectionChanged()"), self.onSelectionChanged )
self.connect( self.btnMEDFile, QtCore.SIGNAL( "clicked()" ), self.onMEDFile )
self.connect( self.CalcCase, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onCalcCaseChanged )
self.connect( self.MEDFile, QtCore.SIGNAL( "textChanged( const QString& )" ), self.onMEDChanged )
+ self.UndefZ.setText( "-9999" )
+ self.InterpMethod.addItem( "Interpolation at the nearest point" )
+ self.connect( self.ApplyClose, QtCore.SIGNAL( "clicked()" ), self.onApplyClose )
+ self.connect( self.Apply, QtCore.SIGNAL( "clicked()" ), self.onApply )
+ self.connect( self.Close, QtCore.SIGNAL( "clicked()" ), self.onClose )
+ self.connect( self.Help, QtCore.SIGNAL( "clicked()" ), self.onHelp )
def onSelectionChanged( self ):
calc_case_name = get_selected_calc_case()
def onCalcCaseChanged( self ):
self.regions = get_hydro_regions( str(self.CalcCase.text()) )
- print self.regions
+ self.onMEDChanged()
def onMEDChanged( self ):
self.med_groups = get_med_groups( str(self.MEDFile.text()) )
- print self.med_groups
+ #print self.med_groups
+ n = len( self.med_groups )
+ self.Groups.setRowCount( n )
+ for i in range( 0, n ):
+ if self.Groups.item( i, 0 ) is None:
+ self.Groups.setItem( i, 0, QtGui.QTableWidgetItem() )
+ self.Groups.setItem( i, 1, QtGui.QTableWidgetItem() )
+ self.Groups.item( i, 0 ).setText( self.med_groups[i] )
+
+ cb = QtGui.QComboBox( self.Groups )
+ for r in self.regions:
+ cb.addItem( r )
+ self.Groups.setCellWidget( i, 1, cb )
+
+ def onApplyClose( self ):
+ self.onApply()
+ self.onClose()
+
+ def onApply( self ):
+ path = str(self.OutputPath.text())
+ calc_case = str(self.CalcCase.text())
+ med_file = str(self.MEDFile.text())
+ med_groups_regions = {}
+ for i in range( 0, self.Groups.rowCount() ):
+ med_group = str( self.Groups.item( i, 0 ).text() )
+ hydro_reg = str( self.Groups.cellWidget( i, 1 ).currentText() )
+ med_groups_regions[med_group] = hydro_reg
+ z_undef = int(str(self.UndefZ.text()))
+ interp = str(self.InterpMethod.currentText())
+ generate( path, calc_case, med_file, med_groups_regions, z_undef, interp )
+
+ def onClose( self ):
+ self.close()
+
+ def onHelp( self ):
+ pass
-dlg = InterpolzDlg()
-dlg.show()
-dlg.CalcCase.setText( 'Case_1' )
-dlg.OutputPath.setText( '/dn26/HYDRO/interp1.py' )
-dlg.MEDFile.setText( '/dn26/HYDRO/channel.med' )
+if __name__=='__main__':
+ dlg = InterpolzDlg()
+ dlg.show()
+ dlg.CalcCase.setText( 'Case_1' )
+ dlg.OutputPath.setText( '/dn26/HYDRO/interp1.py' )
+ dlg.MEDFile.setText( '/dn26/HYDRO/channel.med' )
+ dlg.onApply()
#print get_med_groups( "/dn26/HYDRO/channel.med" )
#print get_hydro_regions( "Case_1" )