From e97c79a1c2ec98868ea00f27f6e218b7bf52ce8c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Tue, 6 Jul 2010 16:54:20 +0200 Subject: [PATCH] - On utilise maintenant EFICAS_SRC --- src/daEficas/configuration_ADAO.py | 1 + .../daGUI/daEficasWrapper/Makefile.am | 3 +- .../daEficasWrapper/adaoEficasWrapper.py | 101 ++++++++++++++---- .../daGUI/daEficasWrapper/adaoWrapperUtils.py | 82 ++++++++++++++ .../daGUI/daGuiImpl/adaoGuiManager.py | 19 ++-- 5 files changed, 173 insertions(+), 33 deletions(-) create mode 100644 src/daSalome/daGUI/daEficasWrapper/adaoWrapperUtils.py diff --git a/src/daEficas/configuration_ADAO.py b/src/daEficas/configuration_ADAO.py index 7a27a1d..2472027 100644 --- a/src/daEficas/configuration_ADAO.py +++ b/src/daEficas/configuration_ADAO.py @@ -21,6 +21,7 @@ class CONFIG: self.appli = appli self.code = appli.code self.rep_ini = repIni + self.rep_mat=" " # Compatbilite Aster self.savedir = self.rep_user self.generator_module = "generator_adao" self.convert_module = "convert_adao" diff --git a/src/daSalome/daGUI/daEficasWrapper/Makefile.am b/src/daSalome/daGUI/daEficasWrapper/Makefile.am index e8ba8b4..2450e5a 100644 --- a/src/daSalome/daGUI/daEficasWrapper/Makefile.am +++ b/src/daSalome/daGUI/daEficasWrapper/Makefile.am @@ -24,7 +24,8 @@ mypkgpythondir =$(salomepythondir)/daEficasWrapper mypkgpython_PYTHON = \ eficasWrapper.py \ __init__.py \ - adaoEficasWrapper.py + adaoEficasWrapper.py \ + adaoWrapperUtils.py EXTRA_DIST = eficasWrapper.py.in diff --git a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py index b57935b..f9b4056 100644 --- a/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py +++ b/src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py @@ -18,46 +18,59 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from eficasWrapper import * -from PyQt4 import QtGui,QtCore import sys +import os +from PyQt4 import QtGui,QtCore + +# Import from EFICAS_SRC +import eficasSalome +# Import from Eficas +from InterfaceQT4 import qtEficas -# Configuration de l'installation -my_path = os.path.dirname(os.path.abspath(__file__)) -ADAO_INSTALL_DIR = my_path + "/../daEficas" -sys.path[:0]=[ADAO_INSTALL_DIR] +from adaoWrapperUtils import * # # ============================================ # Specialization of the EficasWrapper for ADAO # ============================================ # -class AdaoEficasWrapper(EficasWrapper): +class AdaoEficasWrapper(eficasSalome.MyEficas): + + def __init__(self, parent): + # Configuration de l'installation + # Permet à EFICAS de faire ses import correctement + my_path = os.path.dirname(os.path.abspath(__file__)) + ADAO_INSTALL_DIR = my_path + "/../daEficas" + sys.path[:0]=[ADAO_INSTALL_DIR] - def __init__(self, parent, code="ADAO"): - EficasWrapper.__init__(self, parent, code) self.__myCallbackId = {} self.__close_editor = None self.__file_open_name = "" + self.__parent = parent def init_gui(self): - EficasWrapper.init_gui(self) - print "self.__myCallbackId", self.__myCallbackId + eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO") + # On réouvre tous les fichiers comm + # On fait une copie pour ne pas tomber dans une boucle infinie save_CallbackId = self.__myCallbackId.copy() for editor, myCallbackId in save_CallbackId.iteritems(): self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId) - # Association de l'objet editor avec le callbackId - def setCallbackId(self, callbackId): - index = self.viewmanager.myQtab.currentIndex() - self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId + def addJdcInSalome( self, jdcPath ): + # On gere nous meme l'etude + pass - def getCallbackId(self): - if self.__close_editor is None: - index = self.viewmanager.myQtab.currentIndex() - return self.__myCallbackId[self.viewmanager.dict_editors[index]] - else: - return self.__myCallbackId[self.__close_editor] + def fileNew(self): + """ + @overload + """ + qtEficas.Appli.fileNew(self) + self.notifyObserver(EficasEvent.EVENT_TYPES.NEW) + + def openEmptyCase(self, callbackId): + qtEficas.Appli.fileNew(self) + self.removeCallbackId(callbackId) + self.setCallbackId(callbackId) def fileSave(self): """ @@ -166,3 +179,49 @@ class AdaoEficasWrapper(EficasWrapper): else: return 0 + # ========================================================================== + # Function for the notification interface between an EficasWrapper an an + # EficasObserver. + + # Association de l'objet editor avec le callbackId + def setCallbackId(self, callbackId): + index = self.viewmanager.myQtab.currentIndex() + self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId + + def removeCallbackId(self, callbackId): + key_to_remove = None + for k, v in self.__myCallbackId.iteritems(): + if v[0] == callbackId[0] and v[1].GetID() == callbackId[1].GetID(): + key_to_remove = k + if key_to_remove is not None: + del self.__myCallbackId[key_to_remove] + else: + print "Oups - cannot find callbackId" + + def getCallbackId(self): + if self.__close_editor is None: + index = self.viewmanager.myQtab.currentIndex() + return self.__myCallbackId[self.viewmanager.dict_editors[index]] + else: + return self.__myCallbackId[self.__close_editor] + + def addObserver(self, observer): + """ + In fact, only one observer may be defined for the moment. + """ + try: + observer.processEficasEvent + except: + raise DevelException("the argument should implement the function processEficasEvent") + self.__observer = observer + + def notifyObserver(self, eventType, callbackId=None): + if eventType != EficasEvent.EVENT_TYPES.NEW and eventType != EficasEvent.EVENT_TYPES.OPEN: + if callbackId is None : + eficasEvent = EficasEvent(eventType, self.getCallbackId()) + else: + eficasEvent = EficasEvent(eventType, callbackId) + else: + eficasEvent = EficasEvent(eventType) + self.__observer.processEficasEvent(self, eficasEvent) + diff --git a/src/daSalome/daGUI/daEficasWrapper/adaoWrapperUtils.py b/src/daSalome/daGUI/daEficasWrapper/adaoWrapperUtils.py new file mode 100644 index 0000000..921a6d2 --- /dev/null +++ b/src/daSalome/daGUI/daEficasWrapper/adaoWrapperUtils.py @@ -0,0 +1,82 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2010 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +__author__="André Ribes - EDF R&D" + +class DevelException(Exception): + def __init__(self, message): + """Canonical constructor""" + Exception.__init__(self,message) + +# +# ============================================================================== +# Interface of an eficas observer (for implementing the subject/observer pattern) +# ============================================================================== +# +from daGuiImpl.enumerate import Enumerate + +class EficasObserver: + """ + This class specifies the interface of an eficas observer. See example at the + bottom of this file. + """ + def processEficasEvent(self, eficasWrapper, eficasEvent): + """ + This function should be implemented in the concrete Observer. + @param eficasWrapper the instance of the source EficasWrapper + @param eficasEvent the emitted event (instance of EficasEvent) + """ + raise DevelException("processEficasEvent not implemented yet") + +class EficasEvent: + EVENT_TYPES=Enumerate([ + 'CLOSE', + 'SAVE', + 'DESTROY', + 'OPEN', + 'REOPEN', + 'NEW' + ]) + + def __init__(self,eventType,callbackId=None): + """ + Creates an eficas event to be used by an EficasWrapper to notify an + EficasObserver. + + The eventType depends of the context of creation. It specify the nature + of the event inside EficasWrapper that triggers the creation of this instance. + + The callbackId is an object used by the EficasObserver to map the + notification (this received event) with the initial event (callback) + This object can be anything and has to be defined through a convention + that both the EficasWrapper and the EficasObserver can understand. + Typically, the eficas observer set the callback id to the eficas wrapper + before running the asynchronous show. Then, when an event is raised by + the eficas wrapper toward its observer, it embeds the callback id so that + the observer can match the received event to the initial trigger context. + + @param the eventType to be choosen in the EVENT_TYPES + @param callbackId an arbitrary data object + """ + if not self.EVENT_TYPES.isValid(eventType): + raise DevelException("The event type "+str(eventType)+" is not defined") + + self.eventType = eventType + self.callbackId = callbackId diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index 31cd899..359565b 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -73,7 +73,7 @@ class AdaoGuiUiComponentBuilder: self.initUiComponents() def initUiComponents(self): - + objectTR = QObject() # create top-level menu @@ -136,7 +136,6 @@ class AdaoGuiActionImpl(EficasObserver): def showEficas(self): if self.__Eficas_viewId == -1: - print "First showEficas" self.__dlgEficasWrapper.init_gui() # Scroll Widget @@ -145,12 +144,9 @@ class AdaoGuiActionImpl(EficasObserver): area.setWidgetResizable(1) self.__Eficas_viewId = SalomePyQt.SalomePyQt().createViewWithWidget(area) else: - print "myViewId =", self.__Eficas_viewId - print "activeView =", SalomePyQt.SalomePyQt().getActiveView() if SalomePyQt.SalomePyQt().getActiveView() != self.__Eficas_viewId : result_activate = SalomePyQt.SalomePyQt().activateView(self.__Eficas_viewId) if result_activate == False: - print "View was close - create a new eficas widget" self.__dlgEficasWrapper.init_gui() # Scroll Widget @@ -213,8 +209,8 @@ class AdaoGuiActionImpl(EficasObserver): callbackId = [salomeStudyId, salomeStudyItem] self.__dlgEficasWrapper.setCallbackId(callbackId) except: - print "Oups - cannot edit case !" - traceback.print_exc() + # Case has been destroyed - create a new one + self.__dlgEficasWrapper.fileNew() def removeAdaoCase(self): global __cases__ @@ -235,6 +231,9 @@ class AdaoGuiActionImpl(EficasObserver): adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem) adaoGuiHelper.refreshObjectBrowser() + # Remove Callback in adaoEficasWrapper + self.__dlgEficasWrapper.removeCallbackId(callbackId) + def exportCaseToYACS(self): global __cases__ salomeStudyId = adaoGuiHelper.getActiveStudyId() @@ -243,7 +242,6 @@ class AdaoGuiActionImpl(EficasObserver): case = __cases__[case_key] msg = case.exportCaseToYACS() - if msg != "": adaoGuiHelper.gui_warning(self.__parent, msg) @@ -292,11 +290,9 @@ class AdaoGuiActionImpl(EficasObserver): case = __cases__[case_key] # Search if case is in Eficas ! callbackId = [salomeStudyId, salomeStudyItem] - print "selectCase" case_open_in_eficas = self.__dlgEficasWrapper.selectCase(callbackId) # If case is not in eficas Open It ! if case_open_in_eficas == False: - print "reopen selectCase" if case.get_filename() != "": self.__dlgEficasWrapper.Openfile(case.get_filename()) callbackId = [salomeStudyId, salomeStudyItem] @@ -306,7 +302,8 @@ class AdaoGuiActionImpl(EficasObserver): adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem) adaoGuiHelper.refreshObjectBrowser() __cases__.pop(case_key) - self.__dlgEficasWrapper.fileNew() + callbackId = [salomeStudyId, salomeStudyItem] + self.__dlgEficasWrapper.removeCallbackId(callbackId) except: print "Oups - cannot reopen case !" traceback.print_exc() -- 2.39.2