interface PARAMETRIC_Gen : Engines::EngineComponent, SALOMEDS::Driver
{
- void RunStudy(in long studyID, in SALOMEDS::ID caseEntry)
+ void AddParametricStudy(in Engines::fileBlock parametricStudy,
+ in long salomeStudyID)
+ raises (SALOME::SALOME_Exception);
+
+ void SetParametricStudy(in Engines::fileBlock parametricStudy,
+ in long salomeStudyID,
+ in SALOMEDS::ID entry)
+ raises (SALOME::SALOME_Exception);
+
+ Engines::fileBlock GetParametricStudy(in long salomeStudyID,
+ in SALOMEDS::ID entry)
+ raises (SALOME::SALOME_Exception);
+
+ void RunStudy(in long salomeStudyID,
+ in SALOMEDS::ID entry)
raises (SALOME::SALOME_Exception);
};
import inspect
import traceback
import copy
+import cPickle
import salome
import SALOME
import SALOMERuntime
import pilot
+from salome.kernel.studyedit import getStudyEditor
from salome.kernel.logger import Logger
from salome.kernel import termcolor
logger = Logger("PARAMETRIC", color = termcolor.BLUE)
logger.setLevel(logging.DEBUG)
-from salome.parametric import ParametricStudyEditor, ParametricStudy, parse_entry
+from salome.parametric import PARAM_STUDY_TYPE_ID, ParametricStudy, parse_entry
+
+# module constants
+MODULE_NAME = "PARAMETRIC"
+
+COMPONENT_NAME = "Parametric"
+COMPONENT_ICON = "PARAMETRIC_small.png"
+
+PARAM_STUDY_ICON = "param_study.png"
start_script = """
from salome.kernel.parametric.pyscript_utils import \
def __init__(self, orb, poa, contID, containerName, instanceName, interfaceName):
SALOME_ComponentPy_i.__init__(self, orb, poa, contID, containerName, instanceName, interfaceName, 0)
SALOME_DriverPy_i.__init__(self, interfaceName)
+ self.param_comp = {}
+ self.param_study_dict = {}
self.salome_runtime = None
self.session_catalog = None
inspect.stack()[1][1], inspect.stack()[1][2])
raise SALOME.SALOME_Exception(exc)
+ def _find_or_create_param_component(self, salomeStudyID):
+ """
+ Find the component "Parametric" or create it if none is found
+ :return: the SComponent found or created.
+ """
+ if salomeStudyID not in self.param_comp:
+ ed = getStudyEditor(salomeStudyID)
+ self.param_comp[salomeStudyID] = ed.findOrCreateComponent(MODULE_NAME, COMPONENT_NAME, COMPONENT_ICON)
+ return self.param_comp[salomeStudyID]
+
+ def _set_param_study_sobj(self, parametric_study, salomeStudyID, sobj):
+ getStudyEditor(salomeStudyID).setItem(sobj,
+ name = parametric_study.name,
+ icon = PARAM_STUDY_ICON,
+ typeId = PARAM_STUDY_TYPE_ID)
+ if salomeStudyID not in self.param_study_dict:
+ self.param_study_dict[salomeStudyID] = {}
+ entry = sobj.GetID()
+ self.param_study_dict[salomeStudyID][entry] = parametric_study
+
+ def AddParametricStudy(self, parametricStudy, salomeStudyID):
+ try:
+ self.beginService("PARAMETRIC.AddParametricStudy")
+ param_study = cPickle.loads(parametricStudy)
+ param_comp = self._find_or_create_param_component(salomeStudyID)
+ sobj = getStudyEditor(salomeStudyID).createItem(param_comp, "__NEW_STUDY__")
+ self._set_param_study_sobj(param_study, salomeStudyID, sobj)
+ self.endService("PARAMETRIC.AddParametricStudy")
+ except:
+ self._raiseSalomeError()
+
+ def _set_parametric_study(self, param_study, salomeStudyID, entry):
+ sobj = getStudyEditor(salomeStudyID).study.FindObjectID(entry)
+ self._set_param_study_sobj(param_study, salomeStudyID, sobj)
+
+ def SetParametricStudy(self, parametricStudy, salomeStudyID, entry):
+ try:
+ self.beginService("PARAMETRIC.SetParametricStudy")
+ param_study = cPickle.loads(parametricStudy)
+ self._set_parametric_study(param_study, salomeStudyID, entry)
+ self.endService("PARAMETRIC.SetParametricStudy")
+ except:
+ self._raiseSalomeError()
+
+ def _get_parametric_study(self, salomeStudyID, entry):
+ if salomeStudyID not in self.param_study_dict or entry not in self.param_study_dict[salomeStudyID]:
+ raise Exception("No valid parametric study at entry %s" % entry)
+ param_study = self.param_study_dict[salomeStudyID][entry]
+ param_study.entry = entry
+ return param_study
+
+ def GetParametricStudy(self, salomeStudyID, entry):
+ try:
+ self.beginService("PARAMETRIC.GetParametricStudy")
+ param_study = self._get_parametric_study(salomeStudyID, entry)
+ return cPickle.dumps(param_study)
+ self.endService("PARAMETRIC.GetParametricStudy")
+ except:
+ self._raiseSalomeError()
+
def _get_salome_runtime(self):
if self.salome_runtime is None:
# Initialize runtime for YACS
self.salome_runtime.addCatalog(self.session_catalog)
return self.salome_runtime
- def RunStudy(self, studyId, caseEntry):
+ def RunStudy(self, salomeStudyID, entry):
try:
self.beginService("PARAMETRIC.RunStudy")
PARAMETRIC.lock.release()
# Get parametric study from the case in Salome study
- ed = ParametricStudyEditor(studyId)
- param_study = ed.get_parametric_study(caseEntry)
+ param_study = self._get_parametric_study(salomeStudyID, entry)
# Generate YACS schema
runtime = self._get_salome_runtime()
init_solver = solver_compo_def._serviceMap["Init"].clone(None)
init_solver.setComponent(solver_compo_inst)
- init_solver.getInputPort("studyID").edInit(studyId)
- entry = parse_entry(param_study.solver_case_entry)
- init_solver.getInputPort("detCaseEntry").edInit(entry)
+ init_solver.getInputPort("studyID").edInit(salomeStudyID)
+ solver_case_entry = parse_entry(param_study.solver_case_entry)
+ init_solver.getInputPort("detCaseEntry").edInit(solver_case_entry)
foreach.edSetInitNode(init_solver)
exec_solver = solver_compo_def._serviceMap["Exec"].clone(None)
param_study.data["__ERROR_MESSAGE__"].append(result["errorMessage"])
# Save results in Salome study
- ed.set_parametric_study_at_entry(param_study, caseEntry)
+ self._set_parametric_study(param_study, salomeStudyID, entry)
self.endService("PARAMETRIC.RunStudy")
except:
qapp = QtGui.QApplication
try:
qapp.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
- study_id = sgPyQt.getStudyId()
+ ed = ParametricStudyEditor()
entry = salome.sg.getSelected(0)
- engine = salome.lcc.FindOrLoadComponent("ParametricContainer", "PARAMETRIC")
- engine.RunStudy(study_id, entry)
+ engine = ed.find_or_create_engine()
+ engine.RunStudy(ed.study_id, entry)
qapp.restoreOverrideCursor()
except SALOME.SALOME_Exception, exc:
qapp.restoreOverrideCursor()
import study
import genjob
+PARAM_STUDY_TYPE_ID = study.PARAM_STUDY_TYPE_ID
ParametricStudy = study.ParametricStudy
ParametricVariable = study.ParametricVariable
ParametricStudyEditor = study.ParametricStudyEditor
self.exec_params_frame.set_pyscript_label_from_vars(exchange_vars)
def validate(self):
- if not self.step_frames[self.curstep].check_values():
- return
- param_study = ParametricStudy()
- # Input variables
- for (name, range_widget) in self.define_values_frame.varwidgets.iteritems():
- minval = range_widget.fromSpinBox.value()
- maxval = range_widget.toSpinBox.value()
- step = range_widget.stepSpinBox.value()
- var = ParametricVariable(name, minval, maxval, step)
- param_study.add_input_variable(var)
- # Output variables
- exch_vars = self.select_vars_frame.getSelectedExchangeVariables()
- for outvar in exch_vars.outputVarList:
- param_study.add_output_variable(outvar.name)
- # Execution parameters
- self.exec_params_frame.gui_to_study(param_study)
-
- # Save to Salome study
- ed = ParametricStudyEditor()
- if self.entry is not None:
- ed.set_parametric_study_at_entry(param_study, self.entry)
- else:
- ed.add_parametric_study(param_study)
- salome.sg.updateObjBrowser(0)
- self.close()
+ try:
+ if not self.step_frames[self.curstep].check_values():
+ return
+ param_study = ParametricStudy()
+ # Input variables
+ for (name, range_widget) in self.define_values_frame.varwidgets.iteritems():
+ minval = range_widget.fromSpinBox.value()
+ maxval = range_widget.toSpinBox.value()
+ step = range_widget.stepSpinBox.value()
+ var = ParametricVariable(name, minval, maxval, step)
+ param_study.add_input_variable(var)
+ # Output variables
+ exch_vars = self.select_vars_frame.getSelectedExchangeVariables()
+ for outvar in exch_vars.outputVarList:
+ param_study.add_output_variable(outvar.name)
+ # Execution parameters
+ self.exec_params_frame.gui_to_study(param_study)
+
+ # Save to Salome study
+ ed = ParametricStudyEditor()
+ if self.entry is not None:
+ ed.set_parametric_study_at_entry(param_study, self.entry)
+ else:
+ ed.add_parametric_study(param_study)
+ salome.sg.updateObjBrowser(0)
+ self.close()
+ except Exception, exc:
+ QtGui.QMessageBox.critical(self, self.tr("Error"), str(exc))
def set_study(self, param_study):
self.entry = param_study.entry
import cPickle
import numpy
-from salome.kernel.studyedit import getStudyEditor
+import salome
+import SALOME
+from salome.kernel.studyedit import getActiveStudyId
+import PARAMETRIC
-# module constants
-MODULE_NAME = "PARAMETRIC"
-
-COMPONENT_NAME = "Parametric"
-COMPONENT_ICON = "PARAMETRIC_small.png"
-
-PARAM_STUDY_ICON = "param_study.png"
PARAM_STUDY_TYPE_ID = 1
class ParametricStudyEditor:
it is :const:`None`, the edited study will be the current study.
"""
def __init__(self, study_id = None):
- self.editor = getStudyEditor(study_id)
- self.param_comp = None
+ self.study_id = study_id
+ if self.study_id is None:
+ self.study_id = getActiveStudyId()
+ self.engine = None
- def find_or_create_param_component(self):
+ def find_or_create_engine(self):
"""
- Find the component "Parametric" or create it if none is found
- :return: the SComponent found or created.
+ Find the engine "PARAMETRIC" or create it if none is found
+ :return: the PARAMETRIC engine
"""
- if self.param_comp is None:
- self.param_comp = self.editor.findOrCreateComponent(MODULE_NAME, COMPONENT_NAME, COMPONENT_ICON)
- return self.param_comp
+ if self.engine is None:
+ self.engine = salome.lcc.FindOrLoadComponent("FactoryServer", "PARAMETRIC")
+ return self.engine
def add_parametric_study(self, parametric_study):
- self.find_or_create_param_component()
- sobj = self.editor.createItem(self.param_comp, "__NEW_STUDY__")
- self._set_sobj(parametric_study, sobj)
+ engine = self.find_or_create_engine()
+ pickled_param_study = cPickle.dumps(parametric_study)
+ try:
+ engine.AddParametricStudy(pickled_param_study, self.study_id)
+ except SALOME.SALOME_Exception, exc:
+ raise Exception(exc.details.text)
def set_parametric_study_at_entry(self, parametric_study, entry):
- sobj = self.editor.study.FindObjectID(entry)
- self._set_sobj(parametric_study, sobj)
-
- def _set_sobj(self, parametric_study, sobj):
- self.editor.setItem(sobj,
- name = parametric_study.name,
- icon = PARAM_STUDY_ICON,
- typeId = PARAM_STUDY_TYPE_ID)
- attr = self.editor.builder.FindOrCreateAttribute(sobj, "AttributeParameter")
- attr.SetString("study", cPickle.dumps(parametric_study))
+ engine = self.find_or_create_engine()
+ pickled_param_study = cPickle.dumps(parametric_study)
+ try:
+ engine.SetParametricStudy(pickled_param_study, self.study_id, entry)
+ except SALOME.SALOME_Exception, exc:
+ raise Exception(exc.details.text)
def get_parametric_study(self, entry):
- sobj = self.editor.study.FindObjectID(entry)
- if sobj is None or self.editor.getTypeId(sobj) != PARAM_STUDY_TYPE_ID:
- raise Exception("No valid parametric study at entry %s" % entry)
- found, attr = self.editor.builder.FindAttribute(sobj, "AttributeParameter")
- if not found:
- raise Exception("No valid parametric study at entry %s" % entry)
- param_study = cPickle.loads(attr.GetString("study"))
- param_study.entry = entry
+ engine = self.find_or_create_engine()
+ try:
+ pickled_param_study = engine.GetParametricStudy(self.study_id, entry)
+ except SALOME.SALOME_Exception, exc:
+ raise Exception(exc.details.text)
+ param_study = cPickle.loads(pickled_param_study)
return param_study