Salome HOME
- On gére bien le GUI EFICAS
[modules/adao.git] / src / daSalome / daGUI / daGuiImpl / datassimGuiManager.py
index 811ef9db962e65b2c07d0cd9ecdb02bb256ae5ef..231d7cbaee604cfc10c1a96ff0a90d48e24bc822 100644 (file)
@@ -31,6 +31,15 @@ import SalomePyQt
 sgPyQt = SalomePyQt.SalomePyQt()
 
 from daGuiImpl.enumerate import Enumerate
+from daGuiImpl.datassimCase import DatassimCase
+from daEficasWrapper.datassimEficasWrapper import DatassimEficasWrapper
+from daEficasWrapper.eficasWrapper import EficasObserver
+from daEficasWrapper.eficasWrapper import EficasEvent
+import datassimGuiHelper
+import datassimStudyEditor
+
+__cases__ = {}
+
 #
 # ==============================================================================
 # Classes to manage the building of UI components
@@ -67,12 +76,11 @@ class DatassimGuiUiComponentBuilder:
         sgPyQt.createMenu(a, mid)
         sgPyQt.createTool(a, tid)
 
-class DatassimGuiActionImpl():
+class DatassimGuiActionImpl(EficasObserver):
     """
     This class implements the ui actions concerning the management of oma study
     cases.
     """
-    __dlgNewStudyCase = None
     __dlgEficasWrapper = None
 
     def __init__(self):
@@ -80,7 +88,8 @@ class DatassimGuiActionImpl():
         # This dialog is created once so that it can be recycled for each call
         # to newOmaCase().
         #self.__dlgNewStudyCase = DlgNewStudyCase()
-        #self.__dlgEficasWrapper = OmaEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
+        self.__dlgEficasWrapper = DatassimEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
+        self.__dlgEficasWrapper.addObserver(self)
 
     # ==========================================================================
     # Processing of ui actions
@@ -100,4 +109,71 @@ class DatassimGuiActionImpl():
             print msg
 
     def newDatassimCase(self):
-      print "newDatassimCase"
+      self.__dlgEficasWrapper.displayNew()
+
+    # ==========================================================================
+    # Processing notifications from eficas
+    #
+    __processOptions={
+        EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
+        EficasEvent.EVENT_TYPES.SAVE  : "_processEficasSaveEvent",
+        EficasEvent.EVENT_TYPES.NEW  : "_processEficasNewEvent",
+        EficasEvent.EVENT_TYPES.DESTROY  : "_processEficasDestroyEvent"
+        }
+    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):
+        print "This is the process of EficasCloseEvent"
+        print "Remove datassim case in study if empty..."
+        pass
+
+    def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
+      global __cases__
+      new_case = DatassimCase()
+      salomeStudyId   = datassimGuiHelper.getActiveStudyId()
+      salomeStudyItem = datassimStudyEditor.addInStudy(salomeStudyId, new_case)
+      case_key = (salomeStudyId, salomeStudyItem)
+      __cases__[case_key] = new_case
+      datassimGuiHelper.refreshObjectBrowser()
+      callbackId = [salomeStudyId, salomeStudyItem]
+      self.__dlgEficasWrapper.setCallbackId(callbackId)
+
+    def _processEficasSaveEvent(self, eficasWrapper, eficasEvent):
+        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")
+
+        # Get Editor All infos we need !
+        file_name = eficasWrapper.getCaseName()
+        if file_name != "" :
+          case_key = (targetSalomeStudyId, targetSalomeStudyItem)
+          case =__cases__[case_key]
+          case.set_name(file_name)
+          datassimStudyEditor.updateItem(targetSalomeStudyId, targetSalomeStudyItem, case)
+          datassimGuiHelper.refreshObjectBrowser()
+
+    def _processEficasDestroyEvent(self, eficasWrapper, eficasEvent):
+        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)
+        __cases__.pop(case_key)
+        datassimStudyEditor.removeItem(targetSalomeStudyId, targetSalomeStudyItem)
+        datassimGuiHelper.refreshObjectBrowser()
+
+    def _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
+      print "Unknown Eficas Event"