]> SALOME platform Git repositories - modules/adao.git/commitdiff
Salome HOME
- On utilise maintenant EFICAS_SRC
authorAndré Ribes <andre.ribes@edf.fr>
Tue, 6 Jul 2010 14:54:20 +0000 (16:54 +0200)
committerAndré Ribes <andre.ribes@edf.fr>
Tue, 6 Jul 2010 14:54:20 +0000 (16:54 +0200)
src/daEficas/configuration_ADAO.py
src/daSalome/daGUI/daEficasWrapper/Makefile.am
src/daSalome/daGUI/daEficasWrapper/adaoEficasWrapper.py
src/daSalome/daGUI/daEficasWrapper/adaoWrapperUtils.py [new file with mode: 0644]
src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py

index 7a27a1d0e1f86c4357a9d3d42f21ec4bb0d477fc..247202770ac47dfc7b8defa31a29a33e1c5a10ec 100644 (file)
@@ -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"
index e8ba8b481f00f7d4a712247e7b45f33163f65e91..2450e5a6483d7a8c48b0f6d50e27d8b4152fed48 100644 (file)
@@ -24,7 +24,8 @@ mypkgpythondir =$(salomepythondir)/daEficasWrapper
 mypkgpython_PYTHON = \
                     eficasWrapper.py \
                     __init__.py \
-                    adaoEficasWrapper.py
+                    adaoEficasWrapper.py \
+                    adaoWrapperUtils.py
 
 EXTRA_DIST = eficasWrapper.py.in
 
index b57935b4b5aa81fc0acfd1ee8db11cfb62c0e9fd..f9b40561c7baf2c079569f5d0ef0423d69e6c49d 100644 (file)
 #  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 (file)
index 0000000..921a6d2
--- /dev/null
@@ -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
index 31cd89959e2a92e7139b2caff0264a01e36086e8..359565baa51287a5ccd993e80dcd8a730b1e6b98 100644 (file)
@@ -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()