From 54ed9df836e0f11c14369537f914ea0172270061 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9?= Date: Thu, 29 Apr 2010 17:18:53 +0200 Subject: [PATCH] Export in YACS --- src/daSalome/daGUI/daGuiImpl/datassimCase.py | 55 ++++++++++++++++++- .../daGUI/daGuiImpl/datassimGuiManager.py | 14 +++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/daSalome/daGUI/daGuiImpl/datassimCase.py b/src/daSalome/daGUI/daGuiImpl/datassimCase.py index 7814e7b..e6ea931 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimCase.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimCase.py @@ -18,13 +18,18 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +import os +import subprocess +import traceback +import SalomePyQt + class DatassimCase: - __name = "new_case" - __filename = "" def __init__(self): - pass + self.__name = "new_case" + self.__filename = "" + self.__yacs_filename = "" def get_name(self): return self.__name @@ -37,3 +42,47 @@ class DatassimCase: def set_filename(self, name): self.__filename = str(name) + + def createYACSFile(self): + rtn = "" + if (self.__filename == ""): + return "You need to save your case to export it" + + filename = self.__filename[:self.__filename.rfind(".")] + '.py' + if not os.path.exists(filename): + msg = "Cannot find the py file for YACS generation \n" + msg += "Is your case correct ? \n" + msg += "(Try to load: " + filename + ")" + return msg + + if not os.environ.has_key("DATASSIM_ROOT_DIR"): + return "Please add DATASSIM_ROOT_DIR to your environnement" + + datassim_path = os.environ["DATASSIM_ROOT_DIR"] + datassim_exe = datassim_path + "/bin/salome/DatassimYacsSchemaCreator.py" + self.__yacs_filename = self.__filename[:self.__filename.rfind(".")] + '.xml' + args = [datassim_exe, filename, self.__yacs_filename] + p = subprocess.Popen(args) + (stdoutdata, stderrdata) = p.communicate() + if not os.path.exists(self.__yacs_filename): + msg = "An error occured during the execution of DatassimYacsSchemaCreator.py \n" + msg += "See erros details in your terminal \n" + return msg + return rtn + + def exportCaseToYACS(self): + rtn = "" + rtn = self.createYACSFile() + if rtn != "": + return rtn + + try: + import libYACS_Swig + yacs_swig = libYACS_Swig.YACS_Swig() + yacs_swig.loadSchema(self.__yacs_filename) + except: + msg = "Please install YACS module, error was: \n" + msg += traceback.format_exc() + return msg + return rtn + diff --git a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py index ed1b3fb..a973b19 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py @@ -60,6 +60,7 @@ ACTIONS_MAP={ UI_ELT_IDS.OPEN_DATASSIMCASE_ID:"openDatassimCase", UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID:"editDatassimCase", UI_ELT_IDS.REMOVE_DATASSIMCASE_POP_ID:"removeDatassimCase", + UI_ELT_IDS.YACS_EXPORT_POP_ID:"exportCaseToYACS", } class DatassimGuiUiComponentBuilder: @@ -111,6 +112,7 @@ class DatassimGuiActionImpl(EficasObserver): # This dialog is created once so that it can be recycled for each call # to newOmaCase(). #self.__dlgNewStudyCase = DlgNewStudyCase() + self.__parent = SalomePyQt.SalomePyQt().getDesktop() self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop()) self.__dlgEficasWrapper.addObserver(self) self.__Eficas_viewId = -1 @@ -223,6 +225,18 @@ class DatassimGuiActionImpl(EficasObserver): datassimStudyEditor.removeItem(salomeStudyId, salomeStudyItem) datassimGuiHelper.refreshObjectBrowser() + def exportCaseToYACS(self): + global __cases__ + salomeStudyId = datassimGuiHelper.getActiveStudyId() + salomeStudyItem = datassimGuiHelper.getSelectedItem(salomeStudyId) + case_key = (salomeStudyId, salomeStudyItem.GetID()) + case = __cases__[case_key] + + msg = case.exportCaseToYACS() + + if msg != "": + datassimGuiHelper.gui_warning(self.__parent, msg) + # ========================================================================== # Processing notifications from eficas # -- 2.39.2