1 # -*- coding: utf-8 -*-
7 pythonVersion = 'python' + sysconfig.get_python_version()
8 hydro_solver_root = os.path.join(os.environ['HYDROSOLVER_ROOT_DIR'], 'lib', pythonVersion, 'site-packages', 'salome', 'salome', 'hydro')
14 from salome.hydrotools.interpolS import assignStrickler
16 from .generate_interpolz import replace
18 from PyQt5.QtWidgets import QDialog, QFileDialog, QTableWidgetItem, QComboBox, QMessageBox
23 salome_gui = libSALOME_Swig.SALOMEGUI_Swig()
26 def get_selected_calc_case():
27 ind = SalomePyQt.SalomePyQt.getObjectBrowser().selectionModel().selectedIndexes()
28 #aStudyId = salome.myStudyId
29 doc = HYDROPy.HYDROData_Document.Document()
33 case = doc.FindObjectByName( name )
34 if isinstance(case, HYDROPy.HYDROData_CalculationCase):
38 class assignStricklerDlg( QDialog ):
39 def __init__(self, parent = None):
40 QDialog.__init__( self, parent )
42 uic.loadUi( p+'/assignStrickler.ui', self )
43 self.setWindowTitle( 'Generate assignStrickler script' )
44 SalomePyQt.SalomePyQt.getObjectBrowser().selectionChanged.connect(self.onSelectionChanged)
45 self.btnOutputPath.clicked.connect(self.onOutputFile)
46 self.btnMEDFile.clicked.connect(self.onMEDFile)
47 self.CalcCase.textChanged.connect(self.onCalcCaseChanged)
48 self.MEDFile.textChanged.connect(self.onMEDChanged)
49 self.ApplyClose.clicked.connect(self.onApplyClose)
50 self.Apply.clicked.connect(self.onApply)
51 self.Close.clicked.connect(self.onClose)
52 self.Help.clicked.connect(self.onHelp)
53 self.onSelectionChanged()
55 def onSelectionChanged( self ):
56 calc_case_name = get_selected_calc_case()
57 if calc_case_name is not None:
58 self.CalcCase.setText( calc_case_name )
60 def onOutputFile( self ):
61 caption = "Python file"
64 fname, filt = QFileDialog.getSaveFileName( self, caption, theDir, mask )
65 #print("fname: %s"%fname)
66 if fname!=None and fname!="":
67 if fname.split('.')[-1] != 'py':
69 self.OutputPath.setText( fname )
71 def onMEDFile( self ):
74 fname, filt = QFileDialog.getOpenFileName( self, caption, ".", mask )
75 if fname!=None and fname!="":
76 self.MEDFile.setText( fname )
78 def onCalcCaseChanged( self ):
81 def onMEDChanged( self ):
84 def onApplyClose( self ):
88 def generateScript( self, path, calc_case, med_file ):
90 tf = open( hydro_solver_root+"/assignStrickler.template", "r" )
91 templ = tf.readlines()
92 replace( templ, "<case_name_from_dlg>", calc_case )
93 replace( templ, "<MED_file_path_from_dlg>", med_file )
99 path = str(self.OutputPath.text())
100 calc_case = str(self.CalcCase.text())
101 med_file = str(self.MEDFile.text())
102 isScriptExec = self.cb_scriptExec.isChecked()
105 msg = "Please input the output path"
106 elif len(calc_case)==0:
107 msg = "Please choose the calculation case"
108 elif len(med_file)==0:
109 msg = "Please choose the MED file"
114 self.generateScript( path, calc_case, med_file )
115 msg = "Strickler script is successfully generated"
117 assignStrickler(calc_case, med_file) #, output_file_name=fichierMaillage_out, verbose=True)
118 msg = "Strickler script is successfully generated and executed"
121 QMessageBox.information( self, "", msg )
127 """Shows help page"""
130 <h2>assignStrickler dialog</h2>
132 This dialog is a tool for generation and execution of the script <b>assignStrickler.py</b>.
134 <h3>Calculation case</h3>
135 The name of the calculation case. It can be filled automatically on the base of selection or can be set by user.
137 <h3>Script output path</h3>
138 The path for the output, i.e. the path of the target script assignStrickler.
140 <h3>Input MED file</h3>
141 The path to MED file where the MED field is written.
143 <h3>Execute the script</h3>
144 Execute the script on Apply if checked, or just keep it for later use.
146 QMessageBox.about(self, self.tr("About assign Strckler coefficients dialog"), msg);
149 if __name__=='__main__':
150 dlg = assignStricklerDlg()