1 # Copyright (C) 2012-2015 EDF
3 # This file is part of SALOME PARAMETRIC module.
5 # SALOME PARAMETRIC module is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # SALOME PARAMETRIC module is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with SALOME PARAMETRIC module. If not, see <http://www.gnu.org/licenses/>.
18 from PyQt4 import QtGui, QtCore
21 from salome.kernel.studyedit import getStudyEditor
23 from salome.parametric import ParametricStudy
24 from execparams_ui import Ui_ExecParams
27 class ExecParamsFrame(QtGui.QWidget, Ui_ExecParams):
29 def __init__(self, parent = None):
30 QtGui.QWidget.__init__(self, parent)
32 self.connect(self.selectFromSalomeButton, QtCore.SIGNAL("clicked()"), self.select_from_salome)
33 self.case_entry = None
35 def set_pyscript_label_from_vars(self, exchange_vars):
37 input_var_names = [var.name for var in exchange_vars.inputVarList]
38 text += "This script can use variable"
39 if len(input_var_names) > 1:
41 for i, var in enumerate(input_var_names):
42 if len(input_var_names) > 1 and i == len(input_var_names) - 1:
46 text += " <b>" + var + "</b>"
48 output_var_names = [var.name for var in exchange_vars.outputVarList]
49 if len(output_var_names) > 0:
50 text += "<br>It must create variable"
51 if len(output_var_names) > 1:
53 for i, var in enumerate(output_var_names):
54 if len(output_var_names) > 1 and i == len(output_var_names) - 1:
58 text += " <b>" + var + "</b>"
60 self.pyscriptLabel.setText(text)
62 def select_from_salome(self):
63 nb_entries = salome.sg.SelectedCount()
65 QtGui.QMessageBox.information(self, self.tr("Select from Salome"),
66 self.tr("Please select an entry in Salome Object Browser"))
68 QtGui.QMessageBox.information(self, self.tr("Select from Salome"),
69 self.tr("Only one entry must be selected in Salome Object Browser"))
71 self.set_case_entry(salome.sg.getSelected(0))
73 def set_case_entry(self, entry):
74 self.case_entry = entry
75 self.caseEntryLE.setText(getStudyEditor().study.FindObjectID(entry).GetName() + " (" + entry + ")")
77 def gui_to_study(self, param_study):
78 if self.salomeComponentRB.isChecked():
79 param_study.solver_code_type = ParametricStudy.SALOME_COMPONENT
80 param_study.salome_component_name = str(self.componentNameLE.text())
81 param_study.solver_case_entry = self.case_entry
83 param_study.solver_code_type = ParametricStudy.PYTHON_SCRIPT
84 param_study.python_script = str(self.pythonScriptTE.toPlainText())
85 param_study.name = str(self.studyNameLE.text())
86 param_study.nb_parallel_computations = self.nbParallelSB.value()
88 def study_to_gui(self, param_study):
89 if param_study.solver_code_type == ParametricStudy.SALOME_COMPONENT:
90 self.salomeComponentRB.setChecked(True)
91 self.componentNameLE.setText(param_study.salome_component_name)
92 if param_study.solver_case_entry is not None:
93 self.set_case_entry(param_study.solver_case_entry)
95 self.pythonScriptRB.setChecked(True)
96 self.pythonScriptTE.setText(param_study.python_script)
97 self.studyNameLE.setText(param_study.name)
98 self.nbParallelSB.setValue(param_study.nb_parallel_computations)
100 def check_values(self):