import eficasSalome # Import from EFICAS_SRC
from InterfaceQT4 import qtEficas # Import from Eficas
-from PyQt4 import QtGui,QtCore # Import from PyQT
+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 daGuiImpl.adaoLogger import *
#
# ============================================
self.__parent = parent
def init_gui(self):
+
eficasSalome.MyEficas.__init__(self, self.__parent, code="ADAO", module="ADAO")
+ self.connect(self.viewmanager.myQtab, SIGNAL('currentChanged(int)'), self.tabChanged)
# On réouvre tous les fichiers comm
for editor, myCallbackId in save_CallbackId.iteritems():
self.notifyObserver(EficasEvent.EVENT_TYPES.REOPEN, callbackId=myCallbackId)
+ def tabChanged(self, index):
+ debug("tabChanged " + str(index))
+ self.notifyObserver(EficasEvent.EVENT_TYPES.TABCHANGED, callbackId=self.viewmanager.dict_editors[index])
+
def addJdcInSalome( self, jdcPath ):
# On gere nous meme l'etude
pass
- def fileNew(self):
- """
- @overload
- """
+ def adaofileNew(self, adao_case):
+
qtEficas.Appli.fileNew(self)
- self.notifyObserver(EficasEvent.EVENT_TYPES.NEW)
+ index = self.viewmanager.myQtab.currentIndex()
+ adao_case.name = str(self.viewmanager.myQtab.tabText(index)) # Utilisation de str() pour passer d'un Qstring à un string
+ adao_case.eficas_editor = self.viewmanager.dict_editors[index]
+ self.notifyObserver(EficasEvent.EVENT_TYPES.NEW, callbackId=adao_case)
def openEmptyCase(self, callbackId):
qtEficas.Appli.fileNew(self)
"""
@overload
"""
- fichier = QtGui.QFileDialog.getOpenFileName(self,
- self.trUtf8('Ouvrir Fichier'),
- self.CONFIGURATION.savedir,
- self.trUtf8('JDC Files (*.comm);;''All Files (*)'))
+ fichier = 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.__observer = observer
def notifyObserver(self, eventType, callbackId=None):
- if eventType != EficasEvent.EVENT_TYPES.NEW and eventType != EficasEvent.EVENT_TYPES.OPEN:
+ if eventType != EficasEvent.EVENT_TYPES.OPEN:
if callbackId is None :
eficasEvent = EficasEvent(eventType, self.getCallbackId())
else:
# creates the menu and toolbar items (must be created for every study)
from daGuiImpl import adaoGuiHelper
-from daGuiImpl.adaoGuiManager import AdaoGuiUiComponentBuilder
-from daGuiImpl.adaoGuiManager import AdaoGuiActionImpl
+from daGuiImpl.adaoGuiManager import AdaoCaseManager
+
class GUIcontext:
- uiComponentBuilder = None
- actionImpl = None
+ adaoCaseManager = None
def __init__(self):
- self.uiComponentBuilder = AdaoGuiUiComponentBuilder()
- self.actionImpl = AdaoGuiActionImpl()
-
+ self.adaoCaseManager = AdaoCaseManager()
__study2context__ = {}
__current_context__ = None
def _setContext( studyID ):
global __study2context__, __current_context__
if not __study2context__.has_key(studyID):
- print "create new context"
__study2context__[studyID] = GUIcontext()
pass
__current_context__ = __study2context__[studyID]
# called when module is activated
# returns True if activating is successfull and False otherwise
def activate():
- print "activate study", sgPyQt.getStudyId()
ctx = _setContext( sgPyQt.getStudyId() )
- ctx.actionImpl.activate()
+ ctx.adaoCaseManager.activate()
return True
# called when module is deactivated
def deactivate():
ctx = _setContext( sgPyQt.getStudyId() )
- ctx.actionImpl.deactivate()
+ ctx.adaoCaseManager.deactivate()
pass
# called when active study is changed
ctx = _setContext( sgPyQt.getStudyId() )
pass
-
# called when popup menu is invoked
# popup menu and menu context are passed as parameters
def createPopupMenu( popup, context ):
selcount, selected = adaoGuiHelper.getAllSelected(activeStudyId)
if selcount == 1:
selectedItem = adaoGuiHelper.getSelectedItem(activeStudyId)
- popup = ctx.uiComponentBuilder.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
+ popup = ctx.adaoCaseManager.salome_manager.createPopupMenuOnItem(popup, activeStudyId, selectedItem)
def OnGUIEvent(actionId) :
"""
pass
print "OnGUIEvent", actionId
ctx = _setContext( sgPyQt.getStudyId() )
- ctx.actionImpl.processAction(actionId)
+ ctx.adaoCaseManager.processGUIEvent(actionId)
# called when module's preferences are changed
# preference's resources section and setting name are passed as parameters
class AdaoCase:
def __init__(self):
- self.__name = "new_case"
- self.__filename = ""
- self.__yacs_filename = ""
- def get_name(self):
- return self.__name
+ self.name = "not yet defined" # Name of the case
- def set_name(self, name):
- self.__name = str(name)
+ self.filename = "not yet defined" # Python filename generated by Eficas
+ self.yacs_filename = "not yet defined" # Yacs schema filename
- def get_filename(self):
- return self.__filename
+ self.salome_study_id = -1 # Study of the case
+ self.salome_study_item = None # Study item object
- def set_filename(self, name):
- self.__filename = str(name)
+ self.eficas_editor = None # Editor object from Eficas
def createYACSFile(self):
rtn = ""
- if (self.__filename == ""):
+ if (self.filename == ""):
return "You need to save your case to export it"
- filename = self.__filename[:self.__filename.rfind(".")] + '.py'
+ filename = self.filename[:self.filename.rfind(".")] + '.py'
if not os.path.exists(filename):
msg = "Cannot find the py file for YACS generation \n"
msg += "Is your case correct ? \n"
adao_path = os.environ["ADAO_ROOT_DIR"]
adao_exe = adao_path + "/bin/salome/AdaoYacsSchemaCreator.py"
- self.__yacs_filename = self.__filename[:self.__filename.rfind(".")] + '.xml'
- args = ["python", adao_exe, filename, self.__yacs_filename]
+ self.yacs_filename = self.filename[:self.filename.rfind(".")] + '.xml'
+ args = ["python", adao_exe, filename, self.yacs_filename]
p = subprocess.Popen(args)
(stdoutdata, stderrdata) = p.communicate()
- if not os.path.exists(self.__yacs_filename):
+ if not os.path.exists(self.yacs_filename):
msg = "An error occured during the execution of AdaoYacsSchemaCreator.py \n"
msg += "See erros details in your terminal \n"
return msg
try:
import libYACS_Swig
yacs_swig = libYACS_Swig.YACS_Swig()
- yacs_swig.loadSchema(self.__yacs_filename)
+ yacs_swig.loadSchema(self.yacs_filename)
except:
msg = "Please install YACS module, error was: \n"
msg += traceback.format_exc()
return msg
return rtn
-
'EDIT_ADAOCASE_POP_ID',
'YACS_EXPORT_POP_ID',
- ],offset=950)
+ ],offset=6950)
ACTIONS_MAP={
UI_ELT_IDS.NEW_ADAOCASE_ID:"newAdaoCase",
UI_ELT_IDS.YACS_EXPORT_POP_ID:"exportCaseToYACS",
}
+
+class AdaoCaseManager(EficasObserver):
+ """
+ Cette classe gére les cas ADAO et coordonne les GUI de SALOME (l'étude)
+ et le GUI de l'objet Eficas (héritage du module Eficas)
+ """
+ def __init__(self):
+
+ # Création d'un dictionnaire de cas
+ # Key == nom du cas
+ # Value == objet AdaoCase()
+ self.cases = {}
+
+
+ # Création des deux managers
+ self.salome_manager = AdaoGuiUiComponentBuilder()
+ self.eficas_manager = AdaoEficasWrapper(parent=SalomePyQt.SalomePyQt().getDesktop())
+
+ # On s'enregistre comme observer pour les évènements venant d'Eficas
+ # Les évènements du salome_manager viennent par le biais de la méthode
+ # processGUIEvent
+ self.eficas_manager.addObserver(self)
+
+ # Création du GUI Eficas
+ self.eficas_manager.init_gui()
+
+ # Création du viewer QT
+ # Scroll Widget (pour les petites résolutions)
+ area = QtGui.QScrollArea(SalomePyQt.SalomePyQt().getDesktop());
+ area.setWidget(self.eficas_manager)
+ area.setWidgetResizable(1)
+ wmType = "ADAO View"
+ self.eficas_viewId = sgPyQt.createView(wmType, area)
+
+ # On interdit que la vue soit fermée
+ # Cela simplifier grandement le code
+ sgPyQt.setViewClosable(self.eficas_viewId, False)
+
+ def activate(self):
+ self.__dlgEficasWrapper.setEnabled(True)
+
+ def deactivate(self):
+ self.__dlgEficasWrapper.setEnabled(False)
+
+ def _processEficasTabChanged(self, eficasWrapper, eficasEvent):
+ """
+ Gestion de la synchonisation entre le tab courant et la selection
+ dans l'étude
+ """
+ editor = eficasEvent.callbackId
+ for case_name, adao_case in self.cases.iteritems():
+ if adao_case.eficas_editor is editor:
+ adaoGuiHelper.selectItem(adao_case.salome_study_item.GetID())
+ break
+
+ # Création d'un nouveau cas
+ # 1: la fonction newAdaoCase est appelée par le GUI SALOME
+ # 2: la fonction _processEficasNewEvent est appelée par le manager EFICAS
+ def newAdaoCase(self):
+ adaoLogger.debug("Création d'un nouveau cas adao")
+ self.eficas_manager.adaofileNew(AdaoCase())
+
+ def _processEficasNewEvent(self, eficasWrapper, eficasEvent):
+ adao_case = eficasEvent.callbackId
+ # Ajout dand l'étude
+ salomeStudyId = adaoGuiHelper.getActiveStudyId()
+ salomeStudyItem = adaoStudyEditor.addInStudy(salomeStudyId, adao_case)
+ # Affichage correct dans l'étude
+ adaoGuiHelper.refreshObjectBrowser()
+ adaoGuiHelper.selectItem(salomeStudyItem.GetID())
+ # Finalisation des données du cas
+ adao_case.salome_study_id = salomeStudyId
+ adao_case.salome_study_item = salomeStudyItem
+ # Ajout du cas
+ self.cases[adao_case.name] = adao_case
+
+
+
+
+
+
+
+
+
+
+ # Gestion des évènements venant du manager Eficas
+ __processOptions={
+ EficasEvent.EVENT_TYPES.CLOSE : "_processEficasCloseEvent",
+ EficasEvent.EVENT_TYPES.SAVE : "_processEficasSaveEvent",
+ EficasEvent.EVENT_TYPES.NEW : "_processEficasNewEvent",
+ EficasEvent.EVENT_TYPES.DESTROY : "_processEficasDestroyEvent",
+ EficasEvent.EVENT_TYPES.OPEN : "_processEficasOpenEvent",
+ EficasEvent.EVENT_TYPES.REOPEN : "_processEficasReOpenEvent",
+ EficasEvent.EVENT_TYPES.TABCHANGED : "_processEficasTabChanged"
+ }
+
+ 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 _processEficasUnknownEvent(self, eficasWrapper, eficasEvent):
+ adaoLogger.error("Unknown Eficas Event")
+
+ # Gestion des évènements venant du GUI de SALOME
+ def processGUIEvent(self, actionId):
+ """
+ Main switch function for ui actions processing
+ """
+ if ACTIONS_MAP.has_key(actionId):
+ try:
+ functionName = ACTIONS_MAP[actionId]
+ getattr(self,functionName)()
+ except:
+ traceback.print_exc()
+ else:
+ adaoLogger.warning("The requested action is not implemented: " + str(actionId))
+
class AdaoGuiUiComponentBuilder:
"""
The initialisation of this class creates the graphic components involved
in the GUI (menu, menu item, toolbar). A ui component builder should be
- created for each opened study and associated to its context (see usage in OMAGUI.py).
+ created for each opened study and associated to its context.
"""
def __init__(self):
self.initUiComponents()
adaoRootEntry = studyEditor.findOrCreateComponent(
moduleName = adaoModuleHelper.componentName(),
- componentName = adaoModuleHelper.componentUserName())
+ componentName = adaoModuleHelper.componentUserName(),
+ icon = adaoModuleHelper.modulePixmap())
- itemName = adaoCase.get_name()
- itemValue = str(adaoCase.get_filename())
+ itemName = adaoCase.name
+ itemValue = adaoCase.filename
itemType = ADAO_ITEM_TYPES.ADAO_CASE
salomeStudyItem = studyEditor.createItem(
adaoRootEntry, itemName,
comment = itemValue,
typeId = itemType)
- # _MEM_ Note that we use the comment attribute to store the serialize
- # description of the data.
return salomeStudyItem
'DESTROY',
'OPEN',
'REOPEN',
- 'NEW'
+ 'NEW',
+ 'TABCHANGED'
])
def __init__(self,eventType,callbackId=None):