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"
mypkgpython_PYTHON = \
eficasWrapper.py \
__init__.py \
- adaoEficasWrapper.py
+ adaoEficasWrapper.py \
+ adaoWrapperUtils.py
EXTRA_DIST = eficasWrapper.py.in
# 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):
"""
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)
+
--- /dev/null
+# -*- 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
self.initUiComponents()
def initUiComponents(self):
-
+
objectTR = QObject()
# create top-level menu
def showEficas(self):
if self.__Eficas_viewId == -1:
- print "First showEficas"
self.__dlgEficasWrapper.init_gui()
# Scroll Widget
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
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__
adaoStudyEditor.removeItem(salomeStudyId, salomeStudyItem)
adaoGuiHelper.refreshObjectBrowser()
+ # Remove Callback in adaoEficasWrapper
+ self.__dlgEficasWrapper.removeCallbackId(callbackId)
+
def exportCaseToYACS(self):
global __cases__
salomeStudyId = adaoGuiHelper.getActiveStudyId()
case = __cases__[case_key]
msg = case.exportCaseToYACS()
-
if msg != "":
adaoGuiHelper.gui_warning(self.__parent, msg)
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]
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()