1 # -*- coding: utf-8 -*-
6 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', 'python2.7', 'site-packages', 'salome', 'salome', 'hydro')
12 from salome.hydrotools.interpolS import assignStrickler
14 from generate_interpolz import replace
16 from PyQt5.QtWidgets import QDialog, QFileDialog, QTableWidgetItem, QComboBox, QMessageBox
21 salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
24 def get_selected_calc_case():
25 ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
26 aStudyId = salome.myStudyId
27 doc = HYDROPy.HYDROData_Document.Document( aStudyId )
31 case = doc.FindObjectByName( name )
32 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
36 class assignStricklerDlg( QDialog ):
37 def __init__(self, parent = None):
38 QDialog.__init__( self, parent )
40 uic.loadUi( p+'/assignStrickler.ui', self )
41 self.setWindowTitle( 'Generate assignStrickler script' )
42 SalomePyQt.SalomePyQt.getObjectBrowser().selectionChanged.connect(self.onSelectionChanged)
43 self.btnOutputPath.clicked.connect(self.onOutputFile)
44 self.btnMEDFile.clicked.connect(self.onMEDFile)
45 self.CalcCase.textChanged.connect(self.onCalcCaseChanged)
46 self.MEDFile.textChanged.connect(self.onMEDChanged)
47 self.ApplyClose.clicked.connect(self.onApplyClose)
48 self.Apply.clicked.connect(self.onApply)
49 self.Close.clicked.connect(self.onClose)
50 self.Help.clicked.connect(self.onHelp)
51 self.onSelectionChanged()
53 def onSelectionChanged( self ):
54 calc_case_name = get_selected_calc_case()
55 if calc_case_name is not None:
56 self.CalcCase.setText( calc_case_name )
58 def onOutputFile( self ):
59 caption = "Python file"
61 fname, filt = QFileDialog.getSaveFileName( self, caption, ".", mask )
62 if fname!=None and fname!="":
63 if string.split(fname, '.')[-1] != 'py':
65 self.OutputPath.setText( fname )
67 def onMEDFile( self ):
70 fname, filt = QFileDialog.getOpenFileName( self, caption, ".", mask )
71 if fname!=None and fname!="":
72 self.MEDFile.setText( fname )
74 def onCalcCaseChanged( self ):
77 def onMEDChanged( self ):
80 def onApplyClose( self ):
84 def generateScript( self, path, calc_case, med_file ):
86 tf = open( hydro_solver_root+"/assignStrickler.template", "r" )
87 templ = tf.readlines()
88 replace( templ, "<case_name_from_dlg>", calc_case )
89 replace( templ, "<MED_file_path_from_dlg>", med_file )
95 path = str(self.OutputPath.text())
96 calc_case = str(self.CalcCase.text())
97 med_file = str(self.MEDFile.text())
98 isScriptExec = self.cb_scriptExec.isChecked()
101 msg = "Please input the output path"
102 elif len(calc_case)==0:
103 msg = "Please choose the calculation case"
104 elif len(med_file)==0:
105 msg = "Please choose the MED file"
110 self.generateScript( path, calc_case, med_file )
111 msg = "Strickler script is successfully generated"
113 assignStrickler(calc_case, med_file) #, output_file_name=fichierMaillage_out, verbose=True)
114 msg = "Strickler script is successfully generated and executed"
117 QMessageBox.information( self, "", msg )
123 """Shows help page"""
126 <h2>assignStrickler dialog</h2>
128 This dialog is a tool for automation the writing of the script <b>assignStrickler.py</b>.
130 <h3>Calculation case</h3>
131 The name of the calculation case. It can be filled automatically on the base of selection or can be input by user.
134 The path for the output, i.e. the path of the target script assignStrickler.
137 The path to MED file where MED groups are extracted.
140 The interpolation method (interpolation at the nearest point and linear interpolation from a triangulation of the cloud of points).
143 The Z value for nodes outside the regions.
146 The table with MED groups and regions names.
148 When the data is input, the user clicks on "Apply" or "Apply and Close" button to perform the script generation.
150 QMessageBox.about(self, self.tr("About boundary conditions dialog"), msg);
153 if __name__=='__main__':
154 dlg = assignStricklerDlg()