From: isn Date: Fri, 25 Jan 2019 17:49:59 +0000 (+0300) Subject: lot 19 : GUI part X-Git-Tag: SH_V2_2_0~27^2~9^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1cf40305ccab872860bc81d89d56c9ff046e9460;p=modules%2Fhydrosolver.git lot 19 : GUI part --- diff --git a/src/salome_hydro/CMakeLists.txt b/src/salome_hydro/CMakeLists.txt index 0137546..1d5ca30 100644 --- a/src/salome_hydro/CMakeLists.txt +++ b/src/salome_hydro/CMakeLists.txt @@ -38,6 +38,7 @@ SET(UIFILES SET(TEMPLFILES interpolz.template + interpolz_b.template assignStrickler.template ) diff --git a/src/salome_hydro/generate_interpolz.py b/src/salome_hydro/generate_interpolz.py index fad48c4..93b22dd 100644 --- a/src/salome_hydro/generate_interpolz.py +++ b/src/salome_hydro/generate_interpolz.py @@ -42,6 +42,20 @@ def generate( path, calc_case, med_file, med_groups_regions, z_undef, regions_in f.write( line ) f.close() +def generate_B( path, bathy_name, med_file, group_name, z_undef, iinterp ): + f = open( path, "w" ) + tf = open( hydro_solver_root+"/interpolz_b.template", "r" ) + templ = tf.readlines() + + replace( templ, "", bathy_name ) + replace( templ, "", med_file ) + replace( templ, "", group_name ) + replace( templ, "", z_undef ) + replace( templ, "", iinterp ) + + for line in templ: + f.write( line ) + f.close() if __name__=='__main__': generate( "test_interpolz.py", "case_1", "mesh.med", {"group_1":"reg_1", "group_2":"reg_2"}, -9999, {"reg_1" : 0, "reg_2": 1} ) diff --git a/src/salome_hydro/interpolz.ui b/src/salome_hydro/interpolz.ui index 29a1f83..c6eec98 100644 --- a/src/salome_hydro/interpolz.ui +++ b/src/salome_hydro/interpolz.ui @@ -6,131 +6,15 @@ 0 0 - 800 - 580 + 850 + 651 Dialog - - - - - - Calculation case: - - - - - - - - - - - - Paths - - - - - - - - Output path: - - - - - - - - - - MED file: - - - - - - - - - - ... - - - - - - - ... - - - - - - - - - - - Parameters - - - - - - - - Undefined Z: - - - - - - - Interpolation method: - - - - - - - - - - - - - - - 250 - - - - MED group - - - - - Region - - - - - Interpolation method - - - - - - - - QFrame::NoFrame @@ -198,6 +82,223 @@ + + + + Paths + + + + + + + + ... + + + + + + + ... + + + + + + + + + + Output path: + + + + + + + + + + MED file: + + + + + + + + + + + + 1 + + + + Calculation Case + + + + + + + + Calculation case: + + + + + + + + + + + + Parameters + + + + + + + + Undefined Z: + + + + + + + Interpolation method: + + + + + + + + + + + + + + + 250 + + + + MED group + + + + + Region + + + + + Interpolation method + + + + + + + + + + + + Bathymetry + + + + + + + 0 + 0 + + + + Parameters + + + + + + + + Interpolation method: + + + + + + + + + + Undefined Z: + + + + + + + + + + + + + + + + + + + + MED Group: + + + + + + + + + + + Bathymetry: + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + diff --git a/src/salome_hydro/interpolz_b.template b/src/salome_hydro/interpolz_b.template new file mode 100644 index 0000000..2db6325 --- /dev/null +++ b/src/salome_hydro/interpolz_b.template @@ -0,0 +1,21 @@ +# Z interpolation with HYDRO +from salome.hydrotools.interpolZ import interpolZ_B + +# Bathymetry name in HYDRO +bathyName = + +# MED file 2D(x,y) of the case produced by SMESH +medFile = + +# med group name +med_group_name = + +# Value to use for undefined Z (used to detect problems) +zUndef = + +# Interpolation method +im = + +# Z interpolation on the bathymetry on the mesh nodes of given group +statZ = interpolZ_B(bathyName, medFile, med_group_name, zUndef, im) + diff --git a/src/salome_hydro/interpolz_gui.py b/src/salome_hydro/interpolz_gui.py index d01a043..16e06c5 100644 --- a/src/salome_hydro/interpolz_gui.py +++ b/src/salome_hydro/interpolz_gui.py @@ -23,7 +23,7 @@ import SalomePyQt import libSALOME_Swig salome_gui = libSALOME_Swig.SALOMEGUI_Swig() -from generate_interpolz import generate +from generate_interpolz import generate, generate_B def get_med_groups( file_path ): #print "get_med_groups", file_path @@ -84,6 +84,18 @@ def get_selected_calc_case(): return name return None +def get_selected_bathy(): + ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes() + aStudyId = salome.myStudyId + doc = HYDROPy.HYDROData_Document.Document( aStudyId ) + for i in ind: + if i.column()==0: + name = str(i.data()) + case = doc.FindObjectByName( name ) + if isinstance(case, HYDROPy.HYDROData_Bathymetry): + return name + return None + class InterpolzDlg( QDialog ): def __init__(self, parent = None): QDialog.__init__( self, parent ) @@ -94,9 +106,14 @@ class InterpolzDlg( QDialog ): self.btnOutputPath.clicked.connect(self.onOutputFile) self.btnMEDFile.clicked.connect(self.onMEDFile) self.CalcCase.textChanged.connect(self.onCalcCaseChanged) + #self.BathyName.textChanged.connect(self.onBathyNameChanged) self.MEDFile.textChanged.connect(self.onMEDChanged) self.UndefZ.setRange( -100000, 100000 ) self.UndefZ.setValue( -9999 ) + self.UndefZ_B.setRange( -100000, 100000 ) + self.UndefZ_B.setValue( -9999 ) + self.InterpMethod_B.addItem( "Interpolation at the nearest point" ) + self.InterpMethod_B.addItem( "Linear interpolation on a cloud triangulation" ) self.InterpMethod.addItem( "Interpolation at the nearest point" ) self.InterpMethod.addItem( "Linear interpolation on a cloud triangulation" ) self.InterpMethod.currentIndexChanged.connect(self.onInterpChanged) @@ -105,11 +122,16 @@ class InterpolzDlg( QDialog ): self.Close.clicked.connect(self.onClose) self.Help.clicked.connect(self.onHelp) self.onSelectionChanged() + self.tabWidget.setCurrentIndex(0) + self.regions = [] #to avoid attrib error def onSelectionChanged( self ): calc_case_name = get_selected_calc_case() if calc_case_name is not None: self.CalcCase.setText( calc_case_name ) + bathy_name = get_selected_bathy() + if bathy_name is not None: + self.BathyName.setText( bathy_name ) def onOutputFile( self ): caption = "Python file" @@ -130,12 +152,20 @@ class InterpolzDlg( QDialog ): def onCalcCaseChanged( self ): self.regions = get_hydro_regions( str(self.CalcCase.text()) ) self.onMEDChanged() + + #def onBathyNameChanged( self ): + # #self.regions = get_hydro_regions( str(self.CalcCase.text()) ) + # self.onMEDChanged() def onMEDChanged( self ): self.med_groups = get_med_groups( str(self.MEDFile.text()) ) print self.med_groups n = len( self.med_groups ) self.Groups.setRowCount( n ) + self.medGroupNames.clear() + for i in range( 0, n ): + self.medGroupNames.addItem(self.med_groups[i]) + for i in range( 0, n ): if self.Groups.item( i, 0 ) is None: self.Groups.setItem( i, 0, QTableWidgetItem() ) @@ -154,7 +184,8 @@ class InterpolzDlg( QDialog ): icb.addItem( 'Linear interpolation on a cloud triangulation' ) self.Groups.setCellWidget( i, 2, icb ) icb.currentIndexChanged.connect(self.onCBInterpChanged) - + + def onCBInterpChanged( self ): ind_set = set() for i in range( 0, self.Groups.rowCount() ): @@ -176,44 +207,77 @@ class InterpolzDlg( QDialog ): def onApply( self ): path = str(self.OutputPath.text()) - calc_case = str(self.CalcCase.text()) med_file = str(self.MEDFile.text()) - med_groups_regions = {} - regions_interp_method = {} - 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() ) - if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' : - med_groups_regions[med_group] = hydro_reg - interp_ind = str( self.Groups.cellWidget( i, 2 ).currentIndex() ) - regions_interp_method[hydro_reg] = interp_ind - z_undef = self.UndefZ.value() - #interp = str(self.InterpMethod.currentText()) - - msg = "" - if len(path)==0: - msg = "Please input the output path" - elif len(calc_case)==0: - msg = "Please choose the calculation case" - elif len(med_file)==0: - msg = "Please choose the MED file" - elif len(med_groups_regions)==0: - msg = "Please fill groups table" - #elif len(interp)==0: - # msg = "Please choose interpolation method" - - result = False - if len(msg)==0: - iinterp = 0 - #if 'Linear' in interp: - # iinterp = 1 - #generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp ) - generate( path, calc_case, med_file, med_groups_regions, z_undef, regions_interp_method ) - msg = "InterpolZ script is successfully generated" - result = True - - QMessageBox.information( self, "", msg ) - return result + print 'current TAB = ', self.tabWidget.currentIndex() + if self.tabWidget.currentIndex() == 0: #calc case tab + calc_case = str(self.CalcCase.text()) + med_groups_regions = {} + regions_interp_method = {} + 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() ) + if len(med_group)>0 and len(hydro_reg)>0 and hydro_reg != 'None' : + med_groups_regions[med_group] = hydro_reg + interp_ind = str( self.Groups.cellWidget( i, 2 ).currentIndex() ) + regions_interp_method[hydro_reg] = interp_ind + z_undef = self.UndefZ.value() + #interp = str(self.InterpMethod.currentText()) + + msg = "" + if len(path)==0: + msg = "Please input the output path" + elif len(calc_case)==0: + msg = "Please choose the calculation case" + elif len(med_file)==0: + msg = "Please choose the MED file" + elif len(med_groups_regions)==0: + msg = "Please fill groups table" + #elif len(interp)==0: + # msg = "Please choose interpolation method" + + result = False + if len(msg)==0: + #iinterp = 0 + #if 'Linear' in interp: + # iinterp = 1 + #generate( path, calc_case, med_file, med_groups_regions, z_undef, iinterp ) + generate( path, calc_case, med_file, med_groups_regions, z_undef, regions_interp_method ) + msg = "InterpolZ script is successfully generated" + result = True + + QMessageBox.information( self, "", msg ) + return result + + elif self.tabWidget.currentIndex() == 1: #bathymetry tab + bathy_name = str(self.BathyName.text()) + group_name = str(self.medGroupNames.currentText()) + interp = str(self.InterpMethod_B.currentText()) + z_undef = self.UndefZ_B.value() + + msg = "" + if len(path)==0: + msg = "Please input the output path" + elif len(bathy_name)==0: + msg = "Please choose the bathymetry" + elif len(med_file)==0: + msg = "Please choose the MED file" + elif len(group_name)==0: + msg = "Please choose MED group" + elif len(interp)==0: + msg = "Please choose interpolation method" + + result = False + + if len(msg)==0: + iinterp = 0 + if 'Linear' in interp: + iinterp = 1 + generate_B( path, bathy_name, med_file, group_name, z_undef, iinterp ) + msg = "InterpolZ_B script is successfully generated" + result = True + + QMessageBox.information( self, "", msg ) + return result def onClose( self ): self.close()