]> SALOME platform Git repositories - modules/eficas.git/blob - src/EFICASGUI/EFICASGUI.py
Salome HOME
Remove OpenTURNS icons
[modules/eficas.git] / src / EFICASGUI / EFICASGUI.py
1 # -*- coding: utf-8 -*-
2
3 import os
4
5 """
6     Interface PyQt
7 """
8 from PyQt4.QtGui import *
9 from PyQt4.QtCore import *
10
11 import salome
12 import SalomePyQt
13
14 from salome.kernel.studyedit import getStudyEditor
15
16 sgPyQt=SalomePyQt.SalomePyQt()
17
18 # -----------------------------------------------------------------------------
19
20 print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
21
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)
33
34
35 ################################################
36 # GUI context class
37 # Used to store actions, menus, toolbars, etc...
38 ################################################
39
40 class GUIcontext:
41     # menus/toolbars/actions IDs
42     EFICAS_MENU_ID = 90
43     ASTER_ID       = 941
44     OM_ID          = 942
45     MAP_ID         = 943
46     OT_STUDY_ID    = 944
47     OT_WRAPPER_ID  = 945
48     MULTICATALOG_ID = 946
49     CARMEL3D_ID    = 947
50     CARMELCND_ID    = 948
51
52     # constructor
53     def __init__(self):
54         # create top-level menu
55         self.mid = sgPyQt.createMenu("Eficas", -1, GUIcontext.EFICAS_MENU_ID,
56                                      sgPyQt.defaultMenuGroup())
57         # create toolbar
58         self.tid = sgPyQt.createTool("Eficas")
59
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)
63
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",
68                                     "eficaster.png")
69         self.addActionConditionally("Sep/prefs.py", GUIcontext.OM_ID,
70                                     "Eficas pour Outils Metier",
71                                     "Editer un jeu de commande Outils Metier avec Eficas",
72                                     "eficasOM.png")
73         self.addActionConditionally("MAP/prefs.py", GUIcontext.MAP_ID,
74                                     "Eficas pour Map",
75                                     "Editer un jeu de commande Map avec Eficas",
76                                     "plus.png")
77         self.addActionConditionally("CarmelCND/prefs.py", GUIcontext.CARMELCND_ID,
78                                     "Eficas pour CarmelCND",
79                                     "Editer un jeu de commande CarmelCND avec Eficas",
80                                     "eficasCND.png")
81         self.addActionConditionally("Carmel3D/prefs.py", GUIcontext.CARMEL3D_ID,
82                                     "Eficas pour Carmel3D",
83                                     "Editer un jeu de commande Carmel3D avec Eficas",
84                                     "eficascarmel.png")
85
86     def addActionConditionally(self, fileToTest, commandId, menuLabel, tipLabel, icon):
87         global eficasRoot
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)
92
93 ################################################
94 # Global variables
95 ################################################
96
97 # study-to-context map
98 __study2context__   = {}
99 # current context
100 __current_context__ = None
101
102 ###
103 # set and return current GUI context
104 # study ID is passed as parameter
105 ###
106 def _setContext( studyID ):
107     global eficasRoot
108     if eficasRoot is None:
109         return
110     global __study2context__, __current_context__
111     if not __study2context__.has_key(studyID):
112         __study2context__[studyID] = GUIcontext()
113         pass
114     __current_context__ = __study2context__[studyID]
115     return __current_context__
116
117
118 # -----------------------------------------------------------------------------
119
120 def OnGUIEvent(commandID) :
121    if dict_command.has_key(commandID):
122       print "OnGUIEvent ::::::::::  commande associée  : ",commandID      
123       dict_command[commandID]()
124    else:
125       print "Pas de commande associée a : ",commandID
126
127 # -----------------------------------------------------------------------------
128
129 def setSettings():
130    """
131    Cette méthode permet les initialisations.
132    """
133    _setContext(sgPyQt.getStudyId())
134
135 def activate():
136    """
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.
139    
140    Portage V3.
141    """
142    setSettings()
143
144
145 # -----------------------------------------------------------------------------
146
147 def activeStudyChanged(ID):
148    _setContext(ID)
149
150
151 #def definePopup(theContext, theObject, theParent):    
152 #   print "EFICASGUI --- definePopup"
153 #   print "EFICASGUI --- definePopup"
154 #   theContext= ""
155 #   theObject = "100"
156 #   theParent = "ObjectBrowser"
157 #   a=salome.sg.getAllSelected()
158     
159 #   selectedEntry = a[0]
160 #   mySO = monEditor.study.FindObjectID(selectedEntry);
161 #   aType = monEditor.getFileType(mySO)
162 #   print aType
163 #   return (theContext, theObject, theParent)
164
165
166 #def customPopup(popup, theContext, theObject, theParent):
167 #   a=salome.sg.getAllSelected()
168
169 #   selectedEntry = a[0]
170 #   mySO = monEditor.study.FindObjectID(selectedEntry);
171 #   aType = monEditor.getFileType(mySO)
172
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)
182
183
184
185 # -----------------------------------------------------------------------------
186
187 def runEficas():
188    print "-------------------------EFICASGUI::runEficas-------------------------"
189    import eficasSalome
190    eficasSalome.runEficas(multi=True)
191    
192 def runEficaspourAster():
193    import eficasSalome
194    eficasSalome.runEficas( "ASTER" )
195    
196    
197 def runEficaspourOpenturnsStudy():
198    print "runEficas Pour Openturns Study"
199    import eficasSalome
200    eficasSalome.runEficas( "OPENTURNS_STUDY" ) 
201    
202 def runEficaspourOpenturnsWrapper():
203    print "runEficas Pour Openturns Wrapper"
204    import eficasSalome
205    eficasSalome.runEficas( "OPENTURNS_WRAPPER" ) 
206    
207 def runEficaspourOM():
208    print "runEficas Pour Outils Metier"
209    import eficasSalome
210    eficasSalome.runEficas( "SEP" )
211    
212 def runEficaspourMap():
213    print "runEficas Pour Map "
214    import eficasSalome
215    eficasSalome.runEficas( "MAP" )
216    
217    
218 def runEficaspourCarmel3D():
219    print "runEficas Pour Carmel3D "
220    import eficasSalome
221    eficasSalome.runEficas( "CARMEL3D" )
222    
223 def runEficaspourCarmelCND():
224    print "runEficas Pour CarmelCND "
225    import eficasSalome
226    eficasSalome.runEficas( "CARMELCND" )
227
228 def runEficasFichier(version=None):
229    """
230    Lancement d'eficas pour ASTER
231    si un fichier est sélectionné, il est ouvert dans eficas
232    """
233    fileName = None
234    code     = None
235    a=salome.sg.getAllSelected()
236    if len(a) == 1:
237       selectedEntry = a[0]
238       
239       editor = getStudyEditor()
240       mySO = editor.study.FindObjectID(selectedEntry);
241       aType = editor.getFileType(mySO)
242       aValue = editor.getFileName(mySO)
243       if aType !=  None :
244         fileName = aValue
245         code     = aType[15:]
246    else:        
247       QMessageBox.critical(None, "Selection Invalide",
248              "Selectionner un seul fichier SVP") 
249       return;
250  
251    import eficasSalome        
252    if code:
253         if version :
254             eficasSalome.runEficas( code, fileName, version=version)
255         else :
256             eficasSalome.runEficas( code, fileName)
257         
258
259 # Partie applicative
260
261 dict_command={
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,
270
271                 9041:runEficasFichier,
272              }