+# -*- coding: utf-8 -*-
+
+import os
+
"""
Interface PyQt
"""
-import qt
-import libSALOME_Swig
+from PyQt4.QtGui import *
+from PyQt4.QtCore import *
+
+import salome
import SalomePyQt
-# Variable globale pour stocker le Workspace de Salome
+from salome.kernel.studyedit import getStudyEditor
-WORKSPACE=None
-currentStudyId=None
-desktop=None
+sgPyQt=SalomePyQt.SalomePyQt()
# -----------------------------------------------------------------------------
-import notifqt
-#import Tkinter
-#root.withdraw()
+print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
-def g():
- print "lastWindowClosed()"
- import Tkinter
- root=Tkinter.Tk()
- root.destroy()
+# Test Eficas directory
+eficasRoot = os.getenv("EFICAS_ROOT")
+if eficasRoot is None:
+ QMessageBox.critical(sgPyQt.getDesktop(), "Error",
+ "Cannot initialize EFICAS module. Environment "
+ "variable EFICAS_ROOT is not set.")
+elif not os.path.isdir(eficasRoot):
+ QMessageBox.critical(sgPyQt.getDesktop(), "Error",
+ "Cannot initialize EFICAS module. Directory %s does "
+ "not exist (check EFICAS_ROOT environment "
+ "variable)." % eficasRoot)
-qt.QObject.connect(qt.qApp,qt.SIGNAL("lastWindowClosed()"),g)
-# -----------------------------------------------------------------------------
+################################################
+# GUI context class
+# Used to store actions, menus, toolbars, etc...
+################################################
-import salome
+class GUIcontext:
+ # menus/toolbars/actions IDs
+ EFICAS_MENU_ID = 90
+ ASTER_ID = 941
+ OM_ID = 942
+ MAP_ID = 943
+ OT_STUDY_ID = 944
+ OT_WRAPPER_ID = 945
+ MULTICATALOG_ID = 946
+ CARMEL3D_ID = 947
-sg=salome.sg
-sgPyQt=SalomePyQt.SalomePyQt()
-import salomedsgui
-aGuiDS=salomedsgui.guiDS()
-print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
+ # constructor
+ def __init__(self):
+ # create top-level menu
+ self.mid = sgPyQt.createMenu("Eficas", -1, GUIcontext.EFICAS_MENU_ID,
+ sgPyQt.defaultMenuGroup())
+ # create toolbar
+ self.tid = sgPyQt.createTool("Eficas")
-# -----------------------------------------------------------------------------
+ a = sgPyQt.createAction(GUIcontext.MULTICATALOG_ID, "Eficas MultiCatalogue","Lancer Eficas" , "Lancer Eficas", "eficas.png")
+ sgPyQt.createMenu(a, self.mid)
+ sgPyQt.createTool(a, self.tid)
+
+ # create actions conditionally and fill menu and toolbar with actions
+ self.addActionConditionally("Aster/prefs.py", GUIcontext.ASTER_ID,
+ "Eficas pour Code_Aster",
+ "Editer un jeu de commande ASTER avec Eficas",
+ "eficaster.png")
+ self.addActionConditionally("Sep/prefs.py", GUIcontext.OM_ID,
+ "Eficas pour Outils Metier",
+ "Editer un jeu de commande Outils Metier avec Eficas",
+ "eficasOM.png")
+ self.addActionConditionally("MAP/prefs.py", GUIcontext.MAP_ID,
+ "Eficas pour Map",
+ "Editer un jeu de commande Map avec Eficas",
+ "plus.png")
+ self.addActionConditionally("Openturns_Study/prefs.py", GUIcontext.OT_STUDY_ID,
+ "Eficas pour Openturns Study",
+ "Editer un jeu de commande Openturns Study avec Eficas",
+ "eficasotstd.png")
+ self.addActionConditionally("Openturns_Wrapper/prefs.py", GUIcontext.OT_WRAPPER_ID,
+ "Eficas pour Openturns Wrapper",
+ "Editer un jeu de commande Openturns Wrapper avec Eficas",
+ "eficasotwrp.png")
+ self.addActionConditionally("Carmel3D/prefs.py", GUIcontext.CARMEL3D_ID,
+ "Eficas pour Carmel3D",
+ "Editer un jeu de commande Carmel3D avec Eficas",
+ "eficascarmel.png")
+
+ def addActionConditionally(self, fileToTest, commandId, menuLabel, tipLabel, icon):
+ global eficasRoot
+ if os.path.isfile(os.path.join(eficasRoot, fileToTest)):
+ a = sgPyQt.createAction(commandId, menuLabel, tipLabel, tipLabel, icon)
+ sgPyQt.createMenu(a, self.mid)
+ sgPyQt.createTool(a, self.tid)
-def setWorkSpace(workSpace):
- print "EficasGUI --- setWorkSpace"
- global WORKSPACE
- print workSpace
- WORKSPACE=workSpace
- print "WORKSPACE: ",WORKSPACE
- # le desktop
- desktop=sgPyQt.getDesktop()
+################################################
+# Global variables
+################################################
- # creation d'une message box
- #qt.QMessageBox.information(d,"titre","message")
+# study-to-context map
+__study2context__ = {}
+# current context
+__current_context__ = None
+
+###
+# set and return current GUI context
+# study ID is passed as parameter
+###
+def _setContext( studyID ):
+ global eficasRoot
+ if eficasRoot is None:
+ return
+ global __study2context__, __current_context__
+ if not __study2context__.has_key(studyID):
+ __study2context__[studyID] = GUIcontext()
+ pass
+ __current_context__ = __study2context__[studyID]
+ return __current_context__
- # recuperation du workspace
- ws=sgPyQt.getMainFrame()
- print ws
# -----------------------------------------------------------------------------
def OnGUIEvent(commandID) :
- print "EficasGUI :: OnGUIEvent :::::::::::::::::::::::::::::::::commandID,WORKSPACE = ",commandID,WORKSPACE
if dict_command.has_key(commandID):
- print "OnGUIEvent :::::::::: commande associée : ",commandID
- dict_command[commandID](WORKSPACE)
+ print "OnGUIEvent :::::::::: commande associée : ",commandID
+ dict_command[commandID]()
else:
- print "Pas de commande associée a : ",commandID
+ print "Pas de commande associée a : ",commandID
# -----------------------------------------------------------------------------
def setSettings():
"""
- Cette méthode permet les initialisations. On définit en particulier
- l'identifiant de l'étude courante.
+ Cette méthode permet les initialisations.
"""
- # le desktop
- desktop=sgPyQt.getDesktop()
- global currentStudyId
- currentStudyId = sgPyQt.getStudyId()
- print "setSettings: currentStudyId = " + str(currentStudyId)
- # _CS_gbo_ Voir si on peut utiliser directement sgPyQt.getStudyId()
- # dans salomedsgui?
+ _setContext(sgPyQt.getStudyId())
+
+def activate():
+ """
+ Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
+ activé dans une étude précédente.
+
+ Portage V3.
+ """
+ setSettings()
# -----------------------------------------------------------------------------
def activeStudyChanged(ID):
- # le desktop
- desktop=sgPyQt.getDesktop()
- global currentStudyId
- # ne marche pas car sg est supposé résider dans une etude
- # studyId=sg.getActiveStudyId()
- currentStudyId=ID
- print "_CS_GBO_ : EFICASGUI.activeStudyChanged : currentStudyId = ", currentStudyId
- print "_CS_GBO_ : EFICASGUI.activeStudyChanged : sgPyQt.getStudyId() = ", sgPyQt.getStudyId()
-
-def definePopup(theContext, theObject, theParent):
- print "EFICASGUI --- definePopup"
- theContext = ""
- theParent = "ObjectBrowser"
- a=salome.sg.getAllSelected()
- if len(a) >0:
- theObject="73"
- return (theContext, theObject, theParent)
+ _setContext(ID)
-def customPopup(popup, theContext, theObject, theParent):
- print "EFICASGUI --- customPopup"
- popup.removeItem(99000)
- popup.removeItem(99001)
- popup.removeItem(99002)
- popup.removeItem(99003)
+#def definePopup(theContext, theObject, theParent):
+# print "EFICASGUI --- definePopup"
+# print "EFICASGUI --- definePopup"
+# theContext= ""
+# theObject = "100"
+# theParent = "ObjectBrowser"
+# a=salome.sg.getAllSelected()
+
+# selectedEntry = a[0]
+# mySO = monEditor.study.FindObjectID(selectedEntry);
+# aType = monEditor.getFileType(mySO)
+# print aType
+# return (theContext, theObject, theParent)
-# -----------------------------------------------------------------------------
+#def customPopup(popup, theContext, theObject, theParent):
+# a=salome.sg.getAllSelected()
+
+# selectedEntry = a[0]
+# mySO = monEditor.study.FindObjectID(selectedEntry);
+# aType = monEditor.getFileType(mySO)
+
+# print "EFICASGUI --- customPopup"
+# print "EFICASGUI --- customPopup"
+# print "EFICASGUI --- customPopup"
+# print "EFICASGUI --- customPopup"
+# print "EFICASGUI --- customPopup"
+# print "EFICASGUI --- customPopup"
+# print "EFICASGUI --- customPopup"
+# print "EFICASGUI --- customPopup"
+# popup.removeItem(99003)
+
-import eficasSalome
-def runEficas(ws):
- eficasSalome.runEficas(ws,"ASTER",studyId=currentStudyId)
+# -----------------------------------------------------------------------------
+
+def runEficas():
+ print "-------------------------EFICASGUI::runEficas-------------------------"
+ import eficasSalome
+ eficasSalome.runEficas(multi=True)
+
+def runEficaspourAster():
+ import eficasSalome
+ eficasSalome.runEficas( "ASTER" )
+
+
+def runEficaspourOpenturnsStudy():
+ print "runEficas Pour Openturns Study"
+ import eficasSalome
+ eficasSalome.runEficas( "OPENTURNS_STUDY" )
+
+def runEficaspourOpenturnsWrapper():
+ print "runEficas Pour Openturns Wrapper"
+ import eficasSalome
+ eficasSalome.runEficas( "OPENTURNS_WRAPPER" )
+
+def runEficaspourOM():
+ print "runEficas Pour Outils Metier"
+ import eficasSalome
+ eficasSalome.runEficas( "SEP" )
+
+def runEficaspourMap():
+ print "runEficas Pour Map "
+ import eficasSalome
+ eficasSalome.runEficas( "MAP" )
+
+
+def runEficaspourCarmel3D():
+ print "runEficas Pour Carmel3D "
+ import eficasSalome
+ eficasSalome.runEficas( "CARMEL3D" )
-def runEficaspourHomard(ws):
- print "runEficas"
- eficasSalome.runEficas(ws,"HOMARD")
-
-def runEficasHomard(ws):
- print "runEficas"
- eficasSalome.runEficas(None,"HOMARD")
-def runEficasFichier(ws):
+def runEficasFichier(version=None):
"""
- Lancement d'eficas à partir d'un fichier sélectionné dans l'arbre
- d'étude.
+ Lancement d'eficas pour ASTER
+ si un fichier est sélectionné, il est ouvert dans eficas
"""
- print "runEficasFichier"
- attr=None
- code="ASTER"
+ fileName = None
+ code = None
a=salome.sg.getAllSelected()
if len(a) == 1:
- aGuiDS.setCurrentStudy(currentStudyId)
- boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])
- if boo :
- code = "ASTER"
- else :
- boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_HOMARD",a[0])
- code = "HOMARD"
-
- eficasSalome.runEficas(ws,code,attr,studyId=currentStudyId)
+ selectedEntry = a[0]
+
+ editor = getStudyEditor()
+ mySO = editor.study.FindObjectID(selectedEntry);
+ aType = editor.getFileType(mySO)
+ aValue = editor.getFileName(mySO)
+ if aType != None :
+ fileName = aValue
+ code = aType[15:]
+ else:
+ QMessageBox.critical(None, "Selection Invalide",
+ "Selectionner un seul fichier SVP")
+ return;
+
+ import eficasSalome
+ if code:
+ if version :
+ eficasSalome.runEficas( code, fileName, version=version)
+ else :
+ eficasSalome.runEficas( code, fileName)
+
# Partie applicative
dict_command={
- 941:runEficas,
- 946:runEficaspourHomard,
- 4041:runEficas,
- 4046:runEficaspourHomard,
- 9042:runEficasFichier,
- }
+ GUIcontext.ASTER_ID : runEficaspourAster,
+ GUIcontext.OM_ID : runEficaspourOM,
+ GUIcontext.MAP_ID : runEficaspourMap,
+ GUIcontext.OT_STUDY_ID : runEficaspourOpenturnsStudy,
+ GUIcontext.OT_WRAPPER_ID : runEficaspourOpenturnsWrapper,
+ GUIcontext.CARMEL3D_ID : runEficaspourCarmel3D,
+ GUIcontext.MULTICATALOG_ID : runEficas,
+ 9041:runEficasFichier,
+ }