Salome HOME
Updating date copyright information
[modules/adao.git] / src / daSalome / daGUI / daEficasWrapper / adaoEficasWrapper.py
index b57935b4b5aa81fc0acfd1ee8db11cfb62c0e9fd..c73948cd7fca2a2d34c4baf50aa50e89ad32fc58 100644 (file)
@@ -1,5 +1,5 @@
-# -*- coding: utf-8 -*-
-#  Copyright (C) 2010 EDF R&D
+#-*-coding:iso-8859-1-*-
+#  Copyright (C) 2010-2013 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
 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-from eficasWrapper import *
-from PyQt4 import QtGui,QtCore
 import sys
+import os
 
-# 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]
+import eficasSalome               # Import from EFICAS_SRC
+from InterfaceQT4 import qtEficas # Import from Eficas
+from PyQt4.QtGui  import *        # Import from PyQT
+from PyQt4.QtCore import *        # Import from PyQT
+# from PyQt4.QtAssistant import *   # Import from PyQT
+
+from daUtils.adaoEficasEvent import *
+from daUtils.adaoLogger 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.insert(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
-      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):
+
+      eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
+      self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged)
+      self.menubar.hide()
+      self.toolBar.hide()
+
+    def addJdcInSalome(self, jdcPath):
+      debug("addJdcInSalome is called " + str(jdcPath))
+      # On gere nous meme l'etude
+      pass
+
+#######
+#
+# Gestion des évènements provenant des widgets QT d'Eficas
+#
+#######
+
+    def tabChanged(self, index):
+      debug("tabChanged " + str(index))
+      # This signal is also emit when a new case is created/added
+      # On regarde que le dictionnaire contient l'index
+      if index in self.viewmanager.dict_editors.keys():
+        self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
+
+#######
+#
+# Méthodes gérant les boutons dans SALOME
+#
+#######
+
+# Rq: Utilisation de la méthode str() pour passer d'un Qstring à un string
+
+    def adaofileNew(self, adao_case):
+
+      qtEficas.Appli.fileNew(self)
       index = self.viewmanager.myQtab.currentIndex()
-      self.__myCallbackId[self.viewmanager.dict_editors[index]] = callbackId
+      adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
+      adao_case.setEditor(self.viewmanager.dict_editors[index])
+      self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
 
-    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 adaoFileSave(self, adao_case):
 
-    def fileSave(self):
-        """
-        @overload
-        """
-        qtEficas.Appli.fileSave(self)
+      ok = qtEficas.Appli.fileSave(self)
+      if ok:
         index = self.viewmanager.myQtab.currentIndex()
-        if index > -1 :
-          self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
+        adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
+        adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
+        adao_case.setEditor(self.viewmanager.dict_editors[index])
+        self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
 
-    def fileSaveAs(self):
-        """
-        @overload
-        """
-        qtEficas.Appli.fileSaveAs(self)
-        self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
+    def adaoFileSaveAs(self, adao_case):
 
-    def getCaseName(self):
-      if self.__close_editor is None:
-        index = self.viewmanager.myQtab.currentIndex()
-        CaseName = self.viewmanager.myQtab.tabText(index)
-        return CaseName
-      else:
-        CaseName = str(self.__close_editor.fichier.split('/')[-1])
-        return CaseName
-
-    def getFileCaseName(self):
-      if self.__close_editor is None:
+      ok = qtEficas.Appli.fileSaveAs(self)
+      if ok:
         index = self.viewmanager.myQtab.currentIndex()
-        editor = self.viewmanager.dict_editors[index]
-        return editor.fichier
-      else:
-        return 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
-        """
-        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 selectCase(self, callbackId):
-      rtn = False
-      for editor, myCallbackId in self.__myCallbackId.iteritems():
-        if myCallbackId[0] == callbackId[0]:
-          if myCallbackId[1].GetID() == callbackId[1].GetID():
-            try:
-              for indexEditor in self.viewmanager.dict_editors.keys():
-                if editor is self.viewmanager.dict_editors[indexEditor]:
-                  self.viewmanager.myQtab.setCurrentIndex(indexEditor)
-                  rtn = True
-            except:
-              pass
-      return rtn
+        adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
+        adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
+        adao_case.setEditor(self.viewmanager.dict_editors[index])
+        self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE, callbackId=adao_case)
+
+    def adaoFileOpen(self, adao_case):
+
+      tab_number = self.viewmanager.myQtab.count()
+      ok = self.viewmanager.handleOpen()
+      if ok:
+        # On regarde si c'est un nouveau editeur
+        if self.viewmanager.myQtab.count() > tab_number:
+          index = self.viewmanager.myQtab.currentIndex()
+          adao_case.name          = str(self.viewmanager.myQtab.tabText(index))
+          adao_case.filename      = str(self.viewmanager.dict_editors[index].fichier)
+          adao_case.setEditor(self.viewmanager.dict_editors[index])
+          self.notifyObserver(EficasEvent.EVENT_TYPES.OPEN, callbackId=adao_case)
+
+    def adaoFileClose(self, adao_case):
 
-    def fileClose(self):
-        """
-        @overload
-        """
         index = self.viewmanager.myQtab.currentIndex()
-        self.__close_editor = self.viewmanager.dict_editors[index]
+        close_editor = self.viewmanager.dict_editors[index]
         res = self.viewmanager.handleClose(self)
         if res != 2: # l utilsateur a annule
-          if self.__close_editor.fichier is None:
-            # We have to destroy the case
-            self.notifyObserver(EficasEvent.EVENT_TYPES.DESTROY)
-            self.__myCallbackId.pop(self.__close_editor)
+          if close_editor.fichier is None:
+            # Cas fichier vide
+            self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
           else:
-            # Il faudrait en faire plus -> Voir Edit dans SALOME !
-            self.notifyObserver(EficasEvent.EVENT_TYPES.SAVE)
-            self.__myCallbackId.pop(self.__close_editor)
-        self.__close_editor = None
-        return res
-
-    def fileCloseAll(self):
-      """
-      @overload
-      """
-      while len(self.viewmanager.dict_editors) > 0:
-        self.viewmanager.myQtab.setCurrentIndex(0)
-        if self.viewmanager.myQtab.currentIndex() == 0:
-          res = self.fileClose()
-          if res==2 : return res   # l utilsateur a annule
-        else:
-          return 0
+            # Cas fichier existant
+            self.notifyObserver(EficasEvent.EVENT_TYPES.CLOSE, callbackId=close_editor)
+
+#######
+#
+# Méthodes auxiliares de gestion du GUI Eficas pour synchronisation
+# avec la partie GUI de SALOME
+#
+#######
+
+    def selectCase(self, editor):
+      rtn = False
+      for indexEditor in self.viewmanager.dict_editors.keys():
+        if editor is self.viewmanager.dict_editors[indexEditor]:
+          self.viewmanager.myQtab.setCurrentIndex(indexEditor)
+          rtn = True
+          break
+      return rtn
 
+    def getCurrentEditor(self):
+      index = self.viewmanager.myQtab.currentIndex()
+      editor = None
+      if index >= 0:
+        editor = self.viewmanager.dict_editors[index]
+      return editor
+
+
+
+
+#######
+#
+# Méthodes secondaires permettant de gérer les observeurs du
+# GUI d'Eficas
+#
+#######
+
+    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):
+      eficasEvent = EficasEvent(eventType, callbackId)
+      self.__observer.processEficasEvent(self, eficasEvent)