From b2523d7cc7868d8fd1662b53e9469cf1e90a7d61 Mon Sep 17 00:00:00 2001 From: asl Date: Thu, 13 Oct 2016 13:45:08 +0300 Subject: [PATCH] Lot 6: finalization of the script generation --- src/salome_hydro/generate_interpolz.py | 9 ++-- src/salome_hydro/interpolz_gui.py | 63 ++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/salome_hydro/generate_interpolz.py b/src/salome_hydro/generate_interpolz.py index 8879667..fe3ebc0 100644 --- a/src/salome_hydro/generate_interpolz.py +++ b/src/salome_hydro/generate_interpolz.py @@ -1,4 +1,7 @@ +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] @@ -26,7 +29,7 @@ def replace( lines, pattern, subst ): 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, "", calc_case ) @@ -40,5 +43,5 @@ def generate( path, calc_case, med_file, med_groups_regions, z_undef, interp ): 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" ) diff --git a/src/salome_hydro/interpolz_gui.py b/src/salome_hydro/interpolz_gui.py index d90b4ce..4d88c38 100644 --- a/src/salome_hydro/interpolz_gui.py +++ b/src/salome_hydro/interpolz_gui.py @@ -1,6 +1,8 @@ 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() @@ -14,6 +16,8 @@ import SalomePyQt 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: @@ -58,7 +62,7 @@ def get_selected_calc_case(): 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 ) @@ -66,6 +70,12 @@ class InterpolzDlg( QtGui.QDialog ): 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() @@ -88,18 +98,55 @@ class InterpolzDlg( QtGui.QDialog ): 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" ) -- 2.39.2