1 # -*- coding: utf-8 -*-
8 from PyQt4.QtGui import *
9 from PyQt4.QtCore import *
14 from salome.kernel.studyedit import getStudyEditor
16 sgPyQt=SalomePyQt.SalomePyQt()
18 # -----------------------------------------------------------------------------
20 print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
22 # Test Eficas directory
23 eficasRoot = os.getenv("EFICAS_ROOT")
24 if eficasRoot is None:
25 QMessageBox.critical(sgPyQt.getDesktop(), "Error",
26 "Cannot initialize EFICAS module. Environment "
27 "variable EFICAS_ROOT is not set.")
28 elif not os.path.isdir(eficasRoot):
29 QMessageBox.critical(sgPyQt.getDesktop(), "Error",
30 "Cannot initialize EFICAS module. Directory %s does "
31 "not exist (check EFICAS_ROOT environment "
32 "variable)." % eficasRoot)
35 ################################################
37 # Used to store actions, menus, toolbars, etc...
38 ################################################
41 # menus/toolbars/actions IDs
53 # create top-level menu
54 self.mid = sgPyQt.createMenu("Eficas", -1, GUIcontext.EFICAS_MENU_ID,
55 sgPyQt.defaultMenuGroup())
57 self.tid = sgPyQt.createTool("Eficas")
59 a = sgPyQt.createAction(GUIcontext.MULTICATALOG_ID, "Eficas MultiCatalogue","Lancer Eficas" , "Lancer Eficas", "eficas.png")
60 sgPyQt.createMenu(a, self.mid)
61 sgPyQt.createTool(a, self.tid)
63 # create actions conditionally and fill menu and toolbar with actions
64 self.addActionConditionally("Aster/prefs.py", GUIcontext.ASTER_ID,
65 "Eficas pour Code_Aster",
66 "Editer un jeu de commande ASTER avec Eficas",
68 self.addActionConditionally("Sep/prefs.py", GUIcontext.OM_ID,
69 "Eficas pour Outils Metier",
70 "Editer un jeu de commande Outils Metier avec Eficas",
72 self.addActionConditionally("MAP/prefs.py", GUIcontext.MAP_ID,
74 "Editer un jeu de commande Map avec Eficas",
76 self.addActionConditionally("Openturns_Study/prefs.py", GUIcontext.OT_STUDY_ID,
77 "Eficas pour Openturns Study",
78 "Editer un jeu de commande Openturns Study avec Eficas",
80 self.addActionConditionally("Openturns_Wrapper/prefs.py", GUIcontext.OT_WRAPPER_ID,
81 "Eficas pour Openturns Wrapper",
82 "Editer un jeu de commande Openturns Wrapper avec Eficas",
84 self.addActionConditionally("Carmel3D/prefs.py", GUIcontext.CARMEL3D_ID,
85 "Eficas pour Carmel3D",
86 "Editer un jeu de commande Carmel3D avec Eficas",
89 def addActionConditionally(self, fileToTest, commandId, menuLabel, tipLabel, icon):
91 if os.path.isfile(os.path.join(eficasRoot, fileToTest)):
92 a = sgPyQt.createAction(commandId, menuLabel, tipLabel, tipLabel, icon)
93 sgPyQt.createMenu(a, self.mid)
94 sgPyQt.createTool(a, self.tid)
96 ################################################
98 ################################################
100 # study-to-context map
101 __study2context__ = {}
103 __current_context__ = None
106 # set and return current GUI context
107 # study ID is passed as parameter
109 def _setContext( studyID ):
111 if eficasRoot is None:
113 global __study2context__, __current_context__
114 if not __study2context__.has_key(studyID):
115 __study2context__[studyID] = GUIcontext()
117 __current_context__ = __study2context__[studyID]
118 return __current_context__
121 # -----------------------------------------------------------------------------
123 def OnGUIEvent(commandID) :
124 if dict_command.has_key(commandID):
125 print "OnGUIEvent :::::::::: commande associée : ",commandID
126 dict_command[commandID]()
128 print "Pas de commande associée a : ",commandID
130 # -----------------------------------------------------------------------------
134 Cette méthode permet les initialisations.
136 _setContext(sgPyQt.getStudyId())
140 Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
141 activé dans une étude précédente.
148 # -----------------------------------------------------------------------------
150 def activeStudyChanged(ID):
154 #def definePopup(theContext, theObject, theParent):
155 # print "EFICASGUI --- definePopup"
156 # print "EFICASGUI --- definePopup"
159 # theParent = "ObjectBrowser"
160 # a=salome.sg.getAllSelected()
162 # selectedEntry = a[0]
163 # mySO = monEditor.study.FindObjectID(selectedEntry);
164 # aType = monEditor.getFileType(mySO)
166 # return (theContext, theObject, theParent)
169 #def customPopup(popup, theContext, theObject, theParent):
170 # a=salome.sg.getAllSelected()
172 # selectedEntry = a[0]
173 # mySO = monEditor.study.FindObjectID(selectedEntry);
174 # aType = monEditor.getFileType(mySO)
176 # print "EFICASGUI --- customPopup"
177 # print "EFICASGUI --- customPopup"
178 # print "EFICASGUI --- customPopup"
179 # print "EFICASGUI --- customPopup"
180 # print "EFICASGUI --- customPopup"
181 # print "EFICASGUI --- customPopup"
182 # print "EFICASGUI --- customPopup"
183 # print "EFICASGUI --- customPopup"
184 # popup.removeItem(99003)
188 # -----------------------------------------------------------------------------
191 print "-------------------------EFICASGUI::runEficas-------------------------"
193 eficasSalome.runEficas(multi=True)
195 def runEficaspourAster():
197 eficasSalome.runEficas( "ASTER" )
200 def runEficaspourOpenturnsStudy():
201 print "runEficas Pour Openturns Study"
203 eficasSalome.runEficas( "OPENTURNS_STUDY" )
205 def runEficaspourOpenturnsWrapper():
206 print "runEficas Pour Openturns Wrapper"
208 eficasSalome.runEficas( "OPENTURNS_WRAPPER" )
210 def runEficaspourOM():
211 print "runEficas Pour Outils Metier"
213 eficasSalome.runEficas( "SEP" )
215 def runEficaspourMap():
216 print "runEficas Pour Map "
218 eficasSalome.runEficas( "MAP" )
221 def runEficaspourCarmel3D():
222 print "runEficas Pour Carmel3D "
224 eficasSalome.runEficas( "CARMEL3D" )
227 def runEficasFichier(version=None):
229 Lancement d'eficas pour ASTER
230 si un fichier est sélectionné, il est ouvert dans eficas
234 a=salome.sg.getAllSelected()
238 editor = getStudyEditor()
239 mySO = editor.study.FindObjectID(selectedEntry);
240 aType = editor.getFileType(mySO)
241 aValue = editor.getFileName(mySO)
246 QMessageBox.critical(None, "Selection Invalide",
247 "Selectionner un seul fichier SVP")
253 eficasSalome.runEficas( code, fileName, version=version)
255 eficasSalome.runEficas( code, fileName)
261 GUIcontext.ASTER_ID : runEficaspourAster,
262 GUIcontext.OM_ID : runEficaspourOM,
263 GUIcontext.MAP_ID : runEficaspourMap,
264 GUIcontext.OT_STUDY_ID : runEficaspourOpenturnsStudy,
265 GUIcontext.OT_WRAPPER_ID : runEficaspourOpenturnsWrapper,
266 GUIcontext.CARMEL3D_ID : runEficaspourCarmel3D,
267 GUIcontext.MULTICATALOG_ID : runEficas,
269 9041:runEficasFichier,