From: Jean-Philippe ARGAUD Date: Wed, 29 Sep 2021 19:10:53 +0000 (+0200) Subject: Add TUI export menu in EFICAS interface X-Git-Tag: V9_8_0a1~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eb765454b0323133958aade1752d7799db4f5ba8;p=modules%2Fadao.git Add TUI export menu in EFICAS interface --- diff --git a/doc/en/images/eficas_totui.png b/doc/en/images/eficas_totui.png new file mode 100644 index 0000000..856ea6f Binary files /dev/null and b/doc/en/images/eficas_totui.png differ diff --git a/doc/fr/images/eficas_totui.png b/doc/fr/images/eficas_totui.png new file mode 100644 index 0000000..856ea6f Binary files /dev/null and b/doc/fr/images/eficas_totui.png differ diff --git a/src/daSalome/daGUI/daGuiImpl/adaoCase.py b/src/daSalome/daGUI/daGuiImpl/adaoCase.py index e966e01..13a0373 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoCase.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoCase.py @@ -34,106 +34,136 @@ from . import adaoStudyEditor class AdaoCase: - def __init__(self): - - self.name = "not yet defined" # Name of the case - - self.filename = "not yet defined" # Python filename generated by Eficas - self.yacs_filename = "not yet defined" # Yacs schema filename - - #~ self.salome_study_id = -1 # Study of the case - self.salome_study_item = None # Study item object - - self.eficas_editor = None # Editor object from Eficas - self.arbreOuvert = False - - def setEditor(self, editor): - if editor is not self.eficas_editor: - self.eficas_editor = editor - # Connect to the jdc - CONNECTOR.Connect(self.eficas_editor.jdc, "valid", self.editorValidEvent, ()) - - # Rq on notera que l'on utilise isValid dans isOk - # et que isOk appelle editorValidEvent - # il n'y a pas de boucle infini car isValid n'émet - # son signal que si l'état a changé - def editorValidEvent(self): - adaoStudyEditor.updateItem(self.salome_study_item, self) # self.salome_study_id, self.salome_study_item, self) - adaoGuiHelper.refreshObjectBrowser() - - def isOk(self): - if self.eficas_editor.jdc: - return self.eficas_editor.jdc.isValid() - return False - - def createYACSFile(self): - rtn = "" - if (self.filename == "" or self.filename == "not yet defined"): - return "You need to save your case before exporting it." - - self.yacs_filename = self.filename[:self.filename.rfind(".")] + '.xml' - yacs_filename_backup = self.filename[:self.filename.rfind(".")] + '.xml.back' - if os.path.exists(self.yacs_filename): - os.rename(self.yacs_filename, yacs_filename_backup) - - self.eficas_editor.modified = True - self.eficas_editor.saveFile() - filename = self.filename[:self.filename.rfind(".")] + '.py' - retry = 0 - while (not os.path.exists(filename) and retry < 30): - time.sleep(0.1) - retry += 1 - if not os.path.exists(filename): - msg = "Cannot find the COMM/PY associated EFICAS/Python files for YACS\n" - msg += "generation. Is your case correct? Try to close and re-open the\n" - msg += "case with the ADAO/EFICAS editor." - return msg - - if "ADAO_ENGINE_ROOT_DIR" not in os.environ: - return "Please add ADAO_ENGINE_ROOT_DIR to your environnement." - - adao_path = os.environ["ADAO_ENGINE_ROOT_DIR"] - adao_exe = adao_path + "/bin/AdaoYacsSchemaCreator.py" - args = ["python", adao_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 the ADAO YACS Schema\n" - msg += "Creator. If SALOME GUI is launched by command line, see errors\n" - msg += "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, 1, 1) - yacs_swig.loadSchema(self.yacs_filename, True, True) - except: - msg = "Please install YACS module, error was: \n" - msg += traceback.format_exc() - return msg - return rtn - - def validationReportforJDC(self): - rtn = "Validation report is empty." - if self.eficas_editor.jdc: - rtn = "Validation report for the selected ADAO case:\n\n" - rtn += str( self.eficas_editor.jdc.report() ) - return rtn - - def showTreeAdaoCase(self): - if self.eficas_editor: - if self.arbreOuvert: - self.eficas_editor.fermeArbre() + def __init__(self): + + self.name = "not yet defined" # Name of the case + + self.filename = "not yet defined" # Python filename generated by Eficas + self.yacs_filename = "not yet defined" # Yacs schema filename + self.tui_filename = "not yet defined" # Yacs schema filename + + #~ self.salome_study_id = -1 # Study of the case + self.salome_study_item = None # Study item object + + self.eficas_editor = None # Editor object from Eficas self.arbreOuvert = False - else: - self.eficas_editor.ouvreArbre() - self.arbreOuvert = True - return self.arbreOuvert + + def setEditor(self, editor): + if editor is not self.eficas_editor: + self.eficas_editor = editor + # Connect to the jdc + CONNECTOR.Connect(self.eficas_editor.jdc, "valid", self.editorValidEvent, ()) + + # Rq on notera que l'on utilise isValid dans isOk + # et que isOk appelle editorValidEvent + # il n'y a pas de boucle infinie car isValid n'émet + # son signal que si l'état a changé + def editorValidEvent(self): + adaoStudyEditor.updateItem(self.salome_study_item, self) # self.salome_study_id, self.salome_study_item, self) + adaoGuiHelper.refreshObjectBrowser() + + def isOk(self): + if self.eficas_editor.jdc: + return self.eficas_editor.jdc.isValid() + return False + + def createYACSFile(self): + rtn = "" + if (self.filename == "" or self.filename == "not yet defined"): + return "You need to save your case before exporting it." + + self.yacs_filename = self.filename[:self.filename.rfind(".")] + '.xml' + yacs_filename_backup = self.filename[:self.filename.rfind(".")] + '.xml.back' + if os.path.exists(self.yacs_filename): + os.rename(self.yacs_filename, yacs_filename_backup) + + self.eficas_editor.modified = True + self.eficas_editor.saveFile() + filename = self.filename[:self.filename.rfind(".")] + '.py' + retry = 0 + while (not os.path.exists(filename) and retry < 30): + time.sleep(0.1) + retry += 1 + if not os.path.exists(filename): + msg = "Cannot find the COMM/PY associated EFICAS/Python files for YACS\n" + msg += "generation. Is your case correct? Try to close and re-open the\n" + msg += "case with the ADAO/EFICAS editor." + return msg + + if "ADAO_ENGINE_ROOT_DIR" not in os.environ: + return "Please add ADAO_ENGINE_ROOT_DIR to your environment." + + adao_path = os.environ["ADAO_ENGINE_ROOT_DIR"] + adao_exe = adao_path + "/bin/AdaoYacsSchemaCreator.py" + args = ["python", adao_exe, filename, self.yacs_filename] + p = subprocess.Popen(args) + (stdoutdata, stderrdata) = p.communicate() + if not os.path.exists(self.yacs_filename): + msg = "An error occurred during the execution of the ADAO YACS\n" + msg += "Schema Creator. If SALOME GUI is launched by command\n" + msg += "line, see error details in your terminal.\n" + return msg + return rtn + + def exportTUIFile(self): + if (self.filename == "" or self.filename == "not yet defined"): + return "You need to save your case before exporting it." + + self.tui_filename = self.filename[:self.filename.rfind(".")] + '_TUI.py' + tui_filename_backup = self.filename[:self.filename.rfind(".")] + '_TUI.py.back' + if os.path.exists(self.tui_filename): + os.rename(self.tui_filename, tui_filename_backup) + + self.eficas_editor.modified = True + self.eficas_editor.saveFile() + # + import adaoBuilder + fullcase = adaoBuilder.New() + rtn = fullcase.convert(FileNameFrom=self.filename, FormaterFrom="COM", + FileNameTo=self.tui_filename, FormaterTo="TUI", + ) + del fullcase + # + if not os.path.exists(self.tui_filename) or len(rtn) == 0: + msg = "An error occurred during the conversion of the COMM case\n" + msg += "to the TUI one. If SALOME GUI is launched by command\n" + msg += "line, see error details in your terminal.\n" + else: + msg = "The current ADAO case has been successfully exported to\n" + msg += "the file named %s.\n"%self.tui_filename + msg += "Take the time to review it before executing it as a case.\n" + return msg + + 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, 1, 1) + yacs_swig.loadSchema(self.yacs_filename, True, True) + except: + msg = "Please install YACS module, error was: \n" + msg += traceback.format_exc() + return msg + return rtn + + def validationReportforJDC(self): + rtn = "Validation report is empty." + if self.eficas_editor.jdc: + rtn = "Validation report for the selected ADAO case:\n\n" + rtn += str( self.eficas_editor.jdc.report() ) + return rtn + + def showTreeAdaoCase(self): + if self.eficas_editor: + if self.arbreOuvert: + self.eficas_editor.fermeArbre() + self.arbreOuvert = False + else: + self.eficas_editor.ouvreArbre() + self.arbreOuvert = True + return self.arbreOuvert diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index 553335a..a7aeb45 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -59,6 +59,7 @@ UI_ELT_IDS = Enumerate([ 'VALIDATE_ADAOCASE_ID', 'SHOWTREE_ADAOCASE_ID', 'CLOSE_ADAOCASE_ID', + 'TUI_EXPORT_ID', 'YACS_EXPORT_ID', ],offset=6950) @@ -71,6 +72,7 @@ ACTIONS_MAP={ UI_ELT_IDS.SHOWTREE_ADAOCASE_ID:"showTreeAdaoCase", UI_ELT_IDS.CLOSE_ADAOCASE_ID:"closeAdaoCase", UI_ELT_IDS.YACS_EXPORT_ID:"exportCaseToYACS", + UI_ELT_IDS.TUI_EXPORT_ID:"exportTUIFile", } @@ -321,7 +323,7 @@ class AdaoCaseManager(EficasObserver): ####### # # Gestion de l'affichage de l'arbre EFICAS -# 1: la fonction showTreeAdaoCase est appelee par le GUI SALOME +# 1: la fonction showTreeAdaoCase est appelée par le GUI SALOME # ####### @@ -337,9 +339,10 @@ class AdaoCaseManager(EficasObserver): ####### # # Gestion de la connexion avec YACS -# 1: la fonction exportCaseToYACS exporte l'etude vers YACS +# 1: la fonction exportCaseToYACS exporte l'étude vers YACS # ####### + def exportCaseToYACS(self): adaoLogger.debug("Export du cas vers YACS") @@ -358,6 +361,29 @@ class AdaoCaseManager(EficasObserver): adaoGuiHelper.gui_warning(SalomePyQt.SalomePyQt().getDesktop(), "ADAO/EFICAS case can't be exported to ADAO/YACS, it is incomplete or invalid. Please return to ADAO/EFICAS edition stage.") break +####### +# +# Gestion de l'export en TUI +# 1: la fonction exportTUIFile exporte l'étude en TUI +# +####### + + def exportTUIFile(self): + adaoLogger.debug("Export du cas en TUI") + + # A priori, l'utilisateur s'attend a exporter le cas qui est ouvert + # dans le GUI d'Eficas + self.harmonizeSelectionFromEficas() + salomeStudyItem = adaoGuiHelper.getSelectedItem() + for case_name, adao_case in self.cases.items(): + if hasattr(salomeStudyItem,"GetID") and adao_case.salome_study_item.GetID() == salomeStudyItem.GetID(): + if adao_case.isOk(): + msg = adao_case.exportTUIFile() + adaoGuiHelper.gui_information(SalomePyQt.SalomePyQt().getDesktop(), msg) + else: + adaoGuiHelper.gui_warning(SalomePyQt.SalomePyQt().getDesktop(), "ADAO/EFICAS case can't be exported to ADAO/TUI, it is incomplete or invalid. Please return to ADAO/EFICAS edition stage.") + break + ####### # # Methodes secondaires permettant de rediriger les evenements @@ -438,6 +464,9 @@ class AdaoGuiUiComponentBuilder: a = sgPyQt.createAction( UI_ELT_IDS.SHOWTREE_ADAOCASE_ID, "Show tree", "Show tree", "Show the commands tree", "eficas_tree.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) + a = sgPyQt.createAction( UI_ELT_IDS.TUI_EXPORT_ID, "Export to TUI", "Export to TUI", "Generate an ADAO TUI version of this case", "eficas_totui.png" ) + sgPyQt.createMenu(a, mid) + sgPyQt.createTool(a, tid) a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close case", "Close case", "Close an ADAO case", "eficas_close.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid)