From: André Date: Wed, 28 Apr 2010 15:46:37 +0000 (+0200) Subject: Open and Edit case X-Git-Tag: V6_4_0rc3~157 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cac8ad4799f1bc2b8085b87da589e20b868e6006;p=modules%2Fadao.git Open and Edit case --- diff --git a/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py b/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py index eaba562..8b83a7c 100644 --- a/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py +++ b/src/daSalome/daGUI/daEficasWrapper/datassimEficasWrapper.py @@ -36,6 +36,7 @@ class DatassimEficasWrapper(EficasWrapper): __myCallbackId = {} __close_editor = None + __file_open_name = "" def __init__(self, parent, code="DATASSIM"): EficasWrapper.__init__(self, parent, code) @@ -74,17 +75,45 @@ class DatassimEficasWrapper(EficasWrapper): CaseName = self.viewmanager.myQtab.tabText(index) return CaseName else: - CaseName = self.__close_editor.fichier.split('/')[-1] + CaseName = str(self.__close_editor.fichier.split('/')[-1]) return CaseName + def getFileCaseName(self): + if self.__close_editor is None: + index = self.viewmanager.myQtab.currentIndex() + editor = self.viewmanager.dict_editors[index] + return str(editor.fichier) + else: + return str(self.__close_editor.fichier) + def Openfile(self, filename): self.viewmanager.handleOpen(fichier=filename) + def handleOpenRecent(self): + """ + @overload + """ + idx = self.sender() + fichier = self.ficRecents[idx] + self.__file_open_name = fichier + self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN) + self.__file_open_name = "" + def fileOpen(self): """ @overload """ - QtGui.QMessageBox.warning( self, "Alerte", "You cannot Open a Case into Eficas window when you are using Datassim SALOME module") + fichier = QtGui.QFileDialog.getOpenFileName(self, + self.trUtf8('Ouvrir Fichier'), + self.CONFIGURATION.savedir, + self.trUtf8('JDC Files (*.comm);;''All Files (*)')) + if fichier.isNull(): return + self.__file_open_name = fichier + self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN) + self.__file_open_name = "" + + def getOpenFileName(self): + return str(self.__file_open_name) def fileClose(self): """ diff --git a/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in b/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in index 10ed4b2..c680e4e 100644 --- a/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in +++ b/src/daSalome/daGUI/daEficasWrapper/eficasWrapper.py.in @@ -54,6 +54,7 @@ class EficasEvent: 'CLOSE', 'SAVE', 'DESTROY', + 'OPEN', 'NEW' ]) @@ -172,7 +173,7 @@ class EficasWrapper(qtEficas.Appli): self.__observer = observer def notifyObserver(self, eventType): - if eventType != EficasEvent.EVENT_TYPES.NEW: + if eventType != EficasEvent.EVENT_TYPES.NEW and eventType != EficasEvent.EVENT_TYPES.OPEN: eficasEvent = EficasEvent(eventType, self.getCallbackId()) else: eficasEvent = EficasEvent(eventType) diff --git a/src/daSalome/daGUI/daGuiImpl/datassimCase.py b/src/daSalome/daGUI/daGuiImpl/datassimCase.py index e37c9af..c6c9d88 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimCase.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimCase.py @@ -21,6 +21,7 @@ class DatassimCase: __name = "new_case" + __filename = "" def __init__(self): pass @@ -30,3 +31,9 @@ class DatassimCase: def set_name(self, name): self.__name = name + + def get_filename(self): + return self.__filename + + def set_filename(self, name): + self.__filename = name diff --git a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py index b49f4eb..744b168 100644 --- a/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/datassimGuiManager.py @@ -27,6 +27,7 @@ __author__ = "aribes/gboulant" import traceback from PyQt4.QtCore import QObject +from PyQt4 import QtGui,QtCore import SalomePyQt sgPyQt = SalomePyQt.SalomePyQt() @@ -48,6 +49,7 @@ __cases__ = {} UI_ELT_IDS = Enumerate([ 'DATASSIM_MENU_ID', 'NEW_DATASSIMCASE_ID', + 'OPEN_DATASSIMCASE_ID', 'EDIT_DATASSIMCASE_POP_ID', 'DELETE_DATASSIMCASE_POP_ID', 'YACS_EXPORT_POP_ID', @@ -55,6 +57,7 @@ UI_ELT_IDS = Enumerate([ ACTIONS_MAP={ UI_ELT_IDS.NEW_DATASSIMCASE_ID:"newDatassimCase", + UI_ELT_IDS.OPEN_DATASSIMCASE_ID:"openDatassimCase", UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID:"editDatassimCase", } @@ -79,6 +82,9 @@ class DatassimGuiUiComponentBuilder: a = sgPyQt.createAction( UI_ELT_IDS.NEW_DATASSIMCASE_ID, "New case", "New case", "Create a new datassim case", "" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) + a = sgPyQt.createAction( UI_ELT_IDS.OPEN_DATASSIMCASE_ID, "Open case", "Open case", "Open a datassim case", "" ) + sgPyQt.createMenu(a, mid) + sgPyQt.createTool(a, tid) # the following action are used in context popup a = sgPyQt.createAction( UI_ELT_IDS.EDIT_DATASSIMCASE_POP_ID, "Edit case", "Edit case", "Edit the selected study case", "" ) @@ -128,6 +134,28 @@ class DatassimGuiActionImpl(EficasObserver): def newDatassimCase(self): self.__dlgEficasWrapper.displayNew() + def openDatassimCase(self): + 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 = DatassimCase() + new_case.set_filename(str(fichier)) + new_case.set_name(str(fichier.split('/')[-1])) + salomeStudyId = datassimGuiHelper.getActiveStudyId() + salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case) + case_key = (salomeStudyId, salomeStudyItem.GetName()) + __cases__[case_key] = new_case + + # Open file in Eficas + self.__dlgEficasWrapper.Openfile(new_case.get_filename()) + callbackId = [salomeStudyId, salomeStudyItem] + self.__dlgEficasWrapper.setCallbackId(callbackId) + self.__dlgEficasWrapper.show() + datassimGuiHelper.refreshObjectBrowser() + def editDatassimCase(self): global __cases__ salomeStudyId = datassimGuiHelper.getActiveStudyId() @@ -135,7 +163,7 @@ class DatassimGuiActionImpl(EficasObserver): case_key = (salomeStudyId, salomeStudyItem.GetName()) try: case = __cases__[case_key] - self.__dlgEficasWrapper.Openfile(case.get_name()) + self.__dlgEficasWrapper.Openfile(case.get_filename()) callbackId = [salomeStudyId, salomeStudyItem] self.__dlgEficasWrapper.setCallbackId(callbackId) self.__dlgEficasWrapper.show() @@ -151,7 +179,8 @@ class DatassimGuiActionImpl(EficasObserver): EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent", EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent", EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent", - EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent" + EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent", + EficasEvent.EVENT_TYPES.OPEN : "_processEficasOpenEvent" } def processEficasEvent(self, eficasWrapper, eficasEvent): """ @@ -163,8 +192,6 @@ class DatassimGuiActionImpl(EficasObserver): return getattr(self,functionName)(eficasWrapper, eficasEvent) def _processEficasCloseEvent(self, eficasWrapper, eficasEvent): - print "This is the process of EficasCloseEvent" - print "Remove datassim case in study if empty..." pass def _processEficasNewEvent(self, eficasWrapper, eficasEvent): @@ -178,24 +205,49 @@ class DatassimGuiActionImpl(EficasObserver): callbackId = [salomeStudyId, salomeStudyItem] self.__dlgEficasWrapper.setCallbackId(callbackId) - def _processEficasSaveEvent(self, eficasWrapper, eficasEvent): + def _processEficasOpenEvent(self, eficasWrapper, eficasEvent): + global __cases__ + + # Ouverture du fichier + self.__dlgEficasWrapper.Openfile(self.__dlgEficasWrapper.getOpenFileName()) + + # Creation d'un nouveau cas + new_case = DatassimCase() + salomeStudyId = datassimGuiHelper.getActiveStudyId() + salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case) + case_key = (salomeStudyId, salomeStudyItem.GetName()) + __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__ - callbackId = eficasEvent.callbackId 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 ): + [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 ! - file_name = eficasWrapper.getCaseName() - if file_name != "" : + case_name = eficasWrapper.getCaseName() + file_case_name = eficasWrapper.getFileCaseName() + if case_name != "" : # Get case old_case_key = (targetSalomeStudyId, targetSalomeStudyItem.GetName()) case =__cases__[old_case_key] # Set new informations - case.set_name(file_name) + case.set_name(case_name) + case.set_filename(file_case_name) datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case) # Case key changed !