From: André Ribes Date: Wed, 9 Mar 2011 14:15:58 +0000 (+0100) Subject: Implémentation de la fonction ExportToYACS X-Git-Tag: V6_4_0rc3~72 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=90c4089a95b29a26eff3d0ffc3f4bafe5c54a7c1;p=modules%2Fadao.git Implémentation de la fonction ExportToYACS Nettoyage du code mort --- diff --git a/doc/images/eficas_yacs.png b/doc/images/eficas_yacs.png new file mode 100644 index 0000000..1256933 Binary files /dev/null and b/doc/images/eficas_yacs.png differ diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index 4b1ce67..5eb13a9 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -55,9 +55,7 @@ UI_ELT_IDS = Enumerate([ 'SAVE_ADAOCASE_ID', 'SAVE_AS_ADAOCASE_ID', 'CLOSE_ADAOCASE_ID', - - 'EDIT_ADAOCASE_POP_ID', - 'YACS_EXPORT_POP_ID', + 'YACS_EXPORT_ID', ],offset=6950) ACTIONS_MAP={ @@ -66,9 +64,7 @@ ACTIONS_MAP={ UI_ELT_IDS.SAVE_ADAOCASE_ID:"saveAdaoCase", UI_ELT_IDS.SAVE_AS_ADAOCASE_ID:"saveasAdaoCase", UI_ELT_IDS.CLOSE_ADAOCASE_ID:"closeAdaoCase", - - UI_ELT_IDS.EDIT_ADAOCASE_POP_ID:"editAdaoCase", - UI_ELT_IDS.YACS_EXPORT_POP_ID:"exportCaseToYACS", + UI_ELT_IDS.YACS_EXPORT_ID:"exportCaseToYACS", } @@ -288,6 +284,30 @@ class AdaoCaseManager(EficasObserver): # Suppression du cas del self.cases[editor] +####### +# +# Gestion de la connexion avec YACS +# 1: la fonction exportCasToYACS exporte l'étude vers YACS +# +####### + def exportCaseToYACS(self): + adaoLogger.debug("Export du cas vers YACS") + + # A priori, l'utilisateur s'attend à exporter le cas qui est ouvert + # dans le GUI d'Eficas + self.harmonizeSelectionFromEficas() + salomeStudyItem = adaoGuiHelper.getSelectedItem() + for case_name, adao_case in self.cases.iteritems(): + if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID(): + if adao_case.isOk(): + msg = adao_case.exportCaseToYACS() + # If msg is not empty -> error found + if msg != "": + adaoGuiHelper.gui_warning(SalomePyQt.SalomePyQt().getDesktop(), msg) + else: + adaoGuiHelper.gui_warning(SalomePyQt.SalomePyQt().getDesktop(), "Cannot export case, case is not valid") + break + ####### # # Méthodes secondaires permettant de rediriger les évènements @@ -365,352 +385,16 @@ class AdaoGuiUiComponentBuilder: 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) + a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "eficas_yacs.png" ) + sgPyQt.createMenu(a, mid) + sgPyQt.createTool(a, tid) # the following action are used in context popup a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close case", "Close case", "Close the selected case", "" ) - - a = sgPyQt.createAction( UI_ELT_IDS.EDIT_ADAOCASE_POP_ID, "Edit case", "Edit case", "Edit the selected study case", "" ) - a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_POP_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "" ) + a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "" ) def createPopupMenuOnItem(self,popup,salomeSudyId, item): if adaoStudyEditor.isValidAdaoCaseItem(salomeSudyId, item): popup.addAction( sgPyQt.action( UI_ELT_IDS.CLOSE_ADAOCASE_ID ) ) - - popup.addAction( sgPyQt.action( UI_ELT_IDS.EDIT_ADAOCASE_POP_ID ) ) - popup.addAction( sgPyQt.action( UI_ELT_IDS.YACS_EXPORT_POP_ID ) ) - + popup.addAction( sgPyQt.action( UI_ELT_IDS.YACS_EXPORT_ID ) ) return popup - -class AdaoGuiActionImpl(EficasObserver): - """ - This class implements the ui actions concerning the management of oma study - cases. - """ - - def __init__(self): - pass - # 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 = AdaoEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop()) - self.__dlgEficasWrapper.addObserver(self) - self.__Eficas_viewId = -1 - - # ========================================================================== - # Processing of ui actions - # - def processAction(self,actionId): - """ - Main switch function for ui actions processing - """ - if ACTIONS_MAP.has_key(actionId): - try: - functionName = ACTIONS_MAP[actionId] - getattr(self,functionName)() - except: - traceback.print_exc() - else: - msg = "The requested action is not implemented: " + str(actionId) - print msg - - def showEficas(self): - if self.__Eficas_viewId == -1: - self.__dlgEficasWrapper.init_gui() - - - # Scroll Widget - area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop()); - area.setWidget( self.__dlgEficasWrapper) - area.setWidgetResizable(1) - - wmType = "ADAO View" - self.__Eficas_viewId = sgPyQt.createView(wmType, area) - sgPyQt.setViewClosable(self.__Eficas_viewId, False) - else: - if SalomePyQt.SalomePyQt().getActiveView() != self.__Eficas_viewId : - result_activate = SalomePyQt.SalomePyQt().activateView(self.__Eficas_viewId) - if result_activate == False: - self.__dlgEficasWrapper.init_gui() - - # Scroll Widget - area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop()); - area.setWidget( self.__dlgEficasWrapper) - area.setWidgetResizable(1) - - wmType = "ADAO View" - self.__Eficas_viewId = sgPyQt.createView(wmType, area) - sgPyQt.setViewClosable(self.__Eficas_viewId, False) - self.__dlgEficasWrapper.setEnabled(True) - - def activate(self): - self.showEficas() - - def deactivate(self): - self.showEficas() - if self.__Eficas_viewId != -1: - self.__dlgEficasWrapper.setEnabled(False) - - # Actions from SALOME GUI - - def newAdaoCase(self): - - adaoLogger.debug("newAdaoCase") - self.showEficas() - self.__dlgEficasWrapper.fileNew() - - def openAdaoCase(self): - - adaoLogger.debug("openAdaoCase") - self.showEficas() - global __cases__ - fichier = QtGui.QFileDialog.getOpenFileName(SalomePyQt.SalomePyQt().getDesktop(), - self.__dlgEficasWrapper.trUtf8('Ouvrir Fichier'), - self.__dlgEficasWrapper.CONFIGURATION.savedir, - self.__dlgEficasWrapper.trUtf8('JDC Files (*.comm);;''All Files (*)')) - if fichier.isNull(): return - new_case = AdaoCase() - new_case.set_filename(str(fichier)) - new_case.set_name(str(fichier.split('/')[-1])) - salomeStudyId = adaoGuiHelper.getActiveStudyId() - salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case) - case_key = (salomeStudyId, salomeStudyItem.GetID()) - __cases__[case_key] = new_case - - # Open file in Eficas - self.__dlgEficasWrapper.Openfile(new_case.get_filename()) - callbackId = [salomeStudyId, salomeStudyItem] - self.__dlgEficasWrapper.setCallbackId(callbackId) - self.showEficas() - adaoGuiHelper.refreshObjectBrowser() - - def editAdaoCase(self): - - adaoLogger.debug("editAdaoCase") - global __cases__ - - # Take study item - salomeStudyId = adaoGuiHelper.getActiveStudyId() - salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId) - case_key = (salomeStudyId, salomeStudyItem.GetID()) - - # ShowEficas, If case is an empty case - case is destroyed by reopen - self.showEficas() - try: - case = __cases__[case_key] - # Search if case is in Eficas ! - callbackId = [salomeStudyId, salomeStudyItem] - case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId) - - # If case is not in eficas Open It ! - if case_open_in_eficas == False: - if case.get_filename() != "": - self.__dlgEficasWrapper.Openfile(case.get_filename()) - callbackId = [salomeStudyId, salomeStudyItem] - self.__dlgEficasWrapper.setCallbackId(callbackId) - except: - # Case has been destroyed - create a new one - self.__dlgEficasWrapper.fileNew() - - def closeAdaoCase(self): - - adaoLogger.debug("closeAdaoCase") - global __cases__ - - # First step: get selected case - salomeStudyId = adaoGuiHelper.getActiveStudyId() - salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId) - - # Check if there is a selected case - if salomeStudyItem is None: - print "[Close case] Please select a case" - return - - callbackId = [salomeStudyId, salomeStudyItem] - case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId) - - # If case is in eficas close it ! - if case_open_in_eficas: - # fileClose: remove the CallbackId - # fileClose: sends a destroy event - self.__dlgEficasWrapper.fileClose() - else: - # Test if case exists - case_key = (salomeStudyId, salomeStudyItem.GetID()) - if __cases__.has_key(case_key): - __cases__.pop(case_key) - adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem) - adaoGuiHelper.refreshObjectBrowser() - - def saveAdaoCase(self): - - adaoLogger.debug("saveAdaoCase") - global __cases__ - - def saveasAdaoCase(self): - - adaoLogger.debug("saveasAdaoCase") - global __cases__ - - def exportCaseToYACS(self): - - adaoLogger.debug("exportCaseToYACS") - global __cases__ - - # Get case from study - salomeStudyId = adaoGuiHelper.getActiveStudyId() - salomeStudyItem = adaoGuiHelper.getSelectedItem(salomeStudyId) - case_key = (salomeStudyId, salomeStudyItem.GetID()) - case = __cases__[case_key] - - # Generates YACS schema and export it - msg = case.exportCaseToYACS() - - # If msg is not empty -> error found - if msg != "": - adaoGuiHelper.gui_warning(self.__parent, msg) - - # ========================================================================== - # Processing notifications from adaoEficasWrapper - # - __processOptions={ - EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent", - EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent", - EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent", - EficasEvent.EVENT_TYPES.OPEN : "_processEficasOpenEvent", - EficasEvent.EVENT_TYPES.REOPEN : "_processEficasReOpenEvent" - } - def processEficasEvent(self, eficasWrapper, eficasEvent): - """ - Implementation of the interface EficasObserver. The implementation is a - switch on the possible types of events defined in EficasEvent.EVENT_TYPES. - @overload - """ - functionName = self.__processOptions.get(eficasEvent.eventType, lambda : "_processEficasUnknownEvent") - return getattr(self,functionName)(eficasWrapper, eficasEvent) - - def _processEficasCloseEvent(self, eficasWrapper, eficasEvent): - pass - - def _processEficasNewEvent(self, eficasWrapper, eficasEvent): - global __cases__ - - new_case = AdaoCase() - case_name = eficasWrapper.getCaseName() - new_case.set_name(case_name) - salomeStudyId = adaoGuiHelper.getActiveStudyId() - salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case) - case_key = (salomeStudyId, salomeStudyItem.GetID()) - __cases__[case_key] = new_case - adaoGuiHelper.refreshObjectBrowser() - callbackId = [salomeStudyId, salomeStudyItem] - self.__dlgEficasWrapper.setCallbackId(callbackId) - - # We need to select the case - adaoGuiHelper.selectItem(salomeStudyItem.GetID()) - - - def _processEficasOpenEvent(self, eficasWrapper, eficasEvent): - global __cases__ - - # Ouverture du fichier - self.__dlgEficasWrapper.Openfile(self.__dlgEficasWrapper.getOpenFileName()) - - # Creation d'un nouveau cas - new_case = AdaoCase() - salomeStudyId = adaoGuiHelper.getActiveStudyId() - salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, new_case) - case_key = (salomeStudyId, salomeStudyItem.GetID()) - __cases__[case_key] = new_case - - # Connexion du nouveau cas - callbackId = [salomeStudyId, salomeStudyItem] - self.__dlgEficasWrapper.setCallbackId(callbackId) - - # On sauvegarde le cas - self._processEficasSaveEvent(self.__dlgEficasWrapper, None, callbackId) - - def _processEficasSaveEvent(self, eficasWrapper, eficasEvent, callbackId=None): - global __cases__ - if callbackId is None: - callbackId = eficasEvent.callbackId - if callbackId is None: - raise DevelException("the callback data should not be None. Can't guess what are the study and case") - [targetSalomeStudyId,targetSalomeStudyItem] = callbackId - if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ): - raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None") - else: - [targetSalomeStudyId,targetSalomeStudyItem] = callbackId - - # Get Editor All infos we need ! - case_name = eficasWrapper.getCaseName() - file_case_name = eficasWrapper.getFileCaseName() - if case_name != "" : - # Get case - old_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID()) - case =__cases__[old_case_key] - - # Set new informations - case.set_name(case_name) - if str(case_name).startswith("Untitled"): - pass - else: - case.set_filename(file_case_name) - adaoStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case) - - # Case key changed ! - #new_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID()) - # A ne pas inverser !!! - #__cases__.pop(old_case_key) - #__cases__[new_case_key] = case - - adaoGuiHelper.refreshObjectBrowser() - - def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent): - global __cases__ - callbackId = eficasEvent.callbackId - if callbackId is None: - raise DevelException("the callback data should not be None. Can't guess what are the study and case") - [targetSalomeStudyId,targetSalomeStudyItem] = callbackId - if ( targetSalomeStudyId is None ) or ( targetSalomeStudyItem is None ): - raise DevelException("the parameters targetSalomeStudyId and targetSalomeStudyItem should not be None") - - case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetID()) - __cases__.pop(case_key) - adaoStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem) - adaoGuiHelper.refreshObjectBrowser() - - # Deprecated - # Normalement on ne ferme plus le GUI donc on ne passe plus par là - def _processEficasReOpenEvent(self, eficasWrapper, eficasEvent): - - adaoLogger.warning("_processEficasReOpenEvent") - global __cases__ - - try: - callbackId = eficasEvent.callbackId - [salomeStudyId, salomeStudyItem] = callbackId - case_key = (salomeStudyId, salomeStudyItem.GetID()) - case = __cases__[case_key] - # Search if case is in Eficas ! - callbackId = [salomeStudyId, salomeStudyItem] - case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId) - # If case is not in eficas Open It ! - if case_open_in_eficas == False: - if case.get_filename() != "": - self.__dlgEficasWrapper.Openfile(case.get_filename()) - callbackId = [salomeStudyId, salomeStudyItem] - self.__dlgEficasWrapper.setCallbackId(callbackId) - else: - # Since I am an empty case I destroy myself before reloading - adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem) - adaoGuiHelper.refreshObjectBrowser() - __cases__.pop(case_key) - callbackId = [salomeStudyId, salomeStudyItem] - self.__dlgEficasWrapper.removeCallbackId(callbackId) - except: - print "Oups - cannot reopen case !" - traceback.print_exc() - - def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent): - print "Unknown Eficas Event"