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
54 # create top-level menu
55 self.mid = sgPyQt.createMenu("Eficas", -1, GUIcontext.EFICAS_MENU_ID,
56 sgPyQt.defaultMenuGroup())
58 self.tid = sgPyQt.createTool("Eficas")
60 a = sgPyQt.createAction(GUIcontext.MULTICATALOG_ID, "Eficas MultiCatalogue","Lancer Eficas" , "Lancer Eficas", "eficas.png")
61 sgPyQt.createMenu(a, self.mid)
62 sgPyQt.createTool(a, self.tid)
64 # create actions conditionally and fill menu and toolbar with actions
65 self.addActionConditionally("Aster/prefs.py", GUIcontext.ASTER_ID,
66 "Eficas pour Code_Aster",
67 "Editer un jeu de commande ASTER avec Eficas",
69 self.addActionConditionally("Sep/prefs.py", GUIcontext.OM_ID,
70 "Eficas pour Outils Metier",
71 "Editer un jeu de commande Outils Metier avec Eficas",
73 self.addActionConditionally("MAP/prefs.py", GUIcontext.MAP_ID,
75 "Editer un jeu de commande Map avec Eficas",
77 self.addActionConditionally("CarmelCND/prefs.py", GUIcontext.CARMELCND_ID,
78 "Eficas pour CarmelCND",
79 "Editer un jeu de commande CarmelCND avec Eficas",
81 self.addActionConditionally("Carmel3D/prefs.py", GUIcontext.CARMEL3D_ID,
82 "Eficas pour Carmel3D",
83 "Editer un jeu de commande Carmel3D avec Eficas",
86 def addActionConditionally(self, fileToTest, commandId, menuLabel, tipLabel, icon):
88 if os.path.isfile(os.path.join(eficasRoot, fileToTest)):
89 a = sgPyQt.createAction(commandId, menuLabel, tipLabel, tipLabel, icon)
90 sgPyQt.createMenu(a, self.mid)
91 sgPyQt.createTool(a, self.tid)
93 ################################################
95 ################################################
97 # study-to-context map
98 __study2context__ = {}
100 __current_context__ = None
103 # set and return current GUI context
104 # study ID is passed as parameter
106 def _setContext( studyID ):
108 if eficasRoot is None:
110 global __study2context__, __current_context__
111 if not __study2context__.has_key(studyID):
112 __study2context__[studyID] = GUIcontext()
114 __current_context__ = __study2context__[studyID]
115 return __current_context__
118 # -----------------------------------------------------------------------------
120 def OnGUIEvent(commandID) :
121 if dict_command.has_key(commandID):
122 print "OnGUIEvent :::::::::: commande associée : ",commandID
123 dict_command[commandID]()
125 print "Pas de commande associée a : ",commandID
127 # -----------------------------------------------------------------------------
131 Cette méthode permet les initialisations.
133 _setContext(sgPyQt.getStudyId())
137 Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
138 activé dans une étude précédente.
145 # -----------------------------------------------------------------------------
147 def activeStudyChanged(ID):
151 #def definePopup(theContext, theObject, theParent):
152 # print "EFICASGUI --- definePopup"
153 # print "EFICASGUI --- definePopup"
156 # theParent = "ObjectBrowser"
157 # a=salome.sg.getAllSelected()
159 # selectedEntry = a[0]
160 # mySO = monEditor.study.FindObjectID(selectedEntry);
161 # aType = monEditor.getFileType(mySO)
163 # return (theContext, theObject, theParent)
166 #def customPopup(popup, theContext, theObject, theParent):
167 # a=salome.sg.getAllSelected()
169 # selectedEntry = a[0]
170 # mySO = monEditor.study.FindObjectID(selectedEntry);
171 # aType = monEditor.getFileType(mySO)
173 # print "EFICASGUI --- customPopup"
174 # print "EFICASGUI --- customPopup"
175 # print "EFICASGUI --- customPopup"
176 # print "EFICASGUI --- customPopup"
177 # print "EFICASGUI --- customPopup"
178 # print "EFICASGUI --- customPopup"
179 # print "EFICASGUI --- customPopup"
180 # print "EFICASGUI --- customPopup"
181 # popup.removeItem(99003)
185 # -----------------------------------------------------------------------------
188 print "-------------------------EFICASGUI::runEficas-------------------------"
190 eficasSalome.runEficas(multi=True)
192 def runEficaspourAster():
194 eficasSalome.runEficas( "ASTER" )
197 def runEficaspourOpenturnsStudy():
198 print "runEficas Pour Openturns Study"
200 eficasSalome.runEficas( "OPENTURNS_STUDY" )
202 def runEficaspourOpenturnsWrapper():
203 print "runEficas Pour Openturns Wrapper"
205 eficasSalome.runEficas( "OPENTURNS_WRAPPER" )
207 def runEficaspourOM():
208 print "runEficas Pour Outils Metier"
210 eficasSalome.runEficas( "SEP" )
212 def runEficaspourMap():
213 print "runEficas Pour Map "
215 eficasSalome.runEficas( "MAP" )
218 def runEficaspourCarmel3D():
219 print "runEficas Pour Carmel3D "
221 eficasSalome.runEficas( "CARMEL3D" )
223 def runEficaspourCarmelCND():
224 print "runEficas Pour CarmelCND "
226 eficasSalome.runEficas( "CARMELCND" )
228 def runEficasFichier(version=None):
230 Lancement d'eficas pour ASTER
231 si un fichier est sélectionné, il est ouvert dans eficas
235 a=salome.sg.getAllSelected()
239 editor = getStudyEditor()
240 mySO = editor.study.FindObjectID(selectedEntry);
241 aType = editor.getFileType(mySO)
242 aValue = editor.getFileName(mySO)
247 QMessageBox.critical(None, "Selection Invalide",
248 "Selectionner un seul fichier SVP")
254 eficasSalome.runEficas( code, fileName, version=version)
256 eficasSalome.runEficas( code, fileName)
262 GUIcontext.ASTER_ID : runEficaspourAster,
263 GUIcontext.OM_ID : runEficaspourOM,
264 GUIcontext.MAP_ID : runEficaspourMap,
265 GUIcontext.OT_STUDY_ID : runEficaspourOpenturnsStudy,
266 GUIcontext.OT_WRAPPER_ID : runEficaspourOpenturnsWrapper,
267 GUIcontext.CARMELCND_ID : runEficaspourCarmelCND,
268 GUIcontext.CARMEL3D_ID : runEficaspourCarmel3D,
269 GUIcontext.MULTICATALOG_ID : runEficas,
271 9041:runEficasFichier,