]> SALOME platform Git repositories - modules/eficas.git/blob - src/EFICASGUI/EFICASGUI.py
Salome HOME
Changement de copyright
[modules/eficas.git] / src / EFICASGUI / EFICASGUI.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2001-2017  EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 # -*- coding: utf-8 -*-
22
23 import os
24
25 from PyQt5.QtWidgets import QMessageBox
26 from salome.kernel.studyedit import getStudyEditor
27 import SalomePyQt
28 import salome
29
30
31 sgPyQt = SalomePyQt.SalomePyQt()
32
33 # -----------------------------------------------------------------------------
34
35 print("EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::")
36
37 # Test Eficas directory
38 eficasRoot = os.getenv("EFICAS_ROOT")
39 if eficasRoot is None:
40     QMessageBox.critical(sgPyQt.getDesktop(), "Error",
41                          "Cannot initialize EFICAS module. Environment "
42                          "variable EFICAS_ROOT is not set.")
43 elif not os.path.isdir(eficasRoot):
44     QMessageBox.critical(sgPyQt.getDesktop(), "Error",
45                          "Cannot initialize EFICAS module. Directory %s does "
46                          "not exist (check EFICAS_ROOT environment "
47                          "variable)." % eficasRoot)
48
49
50 ################################################
51 # GUI context class
52 # Used to store actions, menus, toolbars, etc...
53 ################################################
54
55 class GUIcontext:
56     # menus/toolbars/actions IDs
57     EFICAS_MENU_ID = 90
58     TELEMAC_ID = 941
59     ADAO_ID = 942
60     MAP_ID = 943
61     CF_ID = 944
62     MT_ID = 945
63     SPECA_ID = 946
64     SEP_ID = 947
65     CARMEL3D_ID = 948
66     MULTICATALOG_ID = 949
67
68     # constructor
69     def __init__(self):
70         # create top-level menu
71         self.mid = sgPyQt.createMenu("Eficas", -1, GUIcontext.EFICAS_MENU_ID,
72                                      sgPyQt.defaultMenuGroup())
73         # create toolbar
74         self.tid = sgPyQt.createTool("Eficas")
75
76         a = sgPyQt.createAction(GUIcontext.MULTICATALOG_ID, "Eficas MultiCatalogue", "Lancer Eficas", "Lancer Eficas", "eficas.png")
77         sgPyQt.createMenu(a, self.mid)
78         sgPyQt.createTool(a, self.tid)
79
80         # create actions conditionally and fill menu and toolbar with actions
81         self.addActionConditionally("Telemac3/prefs.py", GUIcontext.TELEMAC_ID,
82                                     "Eficas pour Telemac",
83                                     "Editer un .cas avec Eficas",
84                                     "eficasTelemac.png")
85         self.addActionConditionally("SEP/prefs.py", GUIcontext.SEP_ID,
86                                     "Eficas pour SEP",
87                                     "Editer un jeu de commande SEP avec Eficas",
88                                     "eficasSEP.png")
89         self.addActionConditionally("SPECA/prefs.py", GUIcontext.SPECA_ID,
90                                     "Eficas pour SPECA",
91                                     "Editer un jeu de commande SPECA avec Eficas",
92                                     "eficasSPECA.png")
93         self.addActionConditionally("CF/prefs.py", GUIcontext.CF_ID,
94                                     "Eficas pour CF",
95                                     "Editer un jeu de commande CF avec Eficas",
96                                     "eficasCF.png")
97         self.addActionConditionally("MT/prefs.py", GUIcontext.MT_ID,
98                                     "Eficas pour MT",
99                                     "Editer un jeu de commande MT avec Eficas",
100                                     "eficasMT.png")
101         self.addActionConditionally("Adao/prefs.py", GUIcontext.ADAO_ID,
102                                     "Eficas pour Adao",
103                                     "Editer un jeu de commande Adao avec Eficas",
104                                     "eficasAdao.png")
105         self.addActionConditionally("MAP/prefs.py", GUIcontext.MAP_ID,
106                                     "Eficas pour Map",
107                                     "Editer un jeu de commande Map avec Eficas",
108                                     "eficasMAP.png")
109         self.addActionConditionally("Carmel3D/prefs.py", GUIcontext.CARMEL3D_ID,
110                                     "Eficas pour Carmel3D",
111                                     "Editer un jeu de commande Carmel3D avec Eficas",
112                                     "eficasCarmel3D.png")
113
114     def addActionConditionally(self, fileToTest, commandId, menuLabel, tipLabel, icon):
115         global eficasRoot
116         if os.path.isfile(os.path.join(eficasRoot, fileToTest)):
117             a = sgPyQt.createAction(commandId, menuLabel, tipLabel, tipLabel, icon)
118             sgPyQt.createMenu(a, self.mid)
119             sgPyQt.createTool(a, self.tid)
120
121 ################################################
122 # Global variables
123 ################################################
124
125 # study-to-context map
126 #__study2context__ = {}
127 # current context
128 #__current_context__ = None
129
130
131
132 # ##
133 # set and return current GUI context
134 # study ID is passed as parameter
135 # ##
136 #def _setContext(studyID):
137 #    global eficasRoot
138 #    if eficasRoot is None:
139 #        return
140 #    global __study2context__, __current_context__
141 #    if studyID not in __study2context__:
142 #        __study2context__[studyID] = GUIcontext()
143 #        pass
144 #    __current_context__ = __study2context__[studyID]
145 #    return __current_context__
146
147
148 # -----------------------------------------------------------------------------
149
150 def OnGUIEvent(commandID):
151     if commandID in dict_command:
152         print("OnGUIEvent ::::::::::  commande associée  : ", commandID)
153         dict_command[commandID]()
154     else:
155         print("Pas de commande associée a : ", commandID)
156
157
158 # -----------------------------------------------------------------------------
159
160 #def setSettings():
161 #    """
162 #    Cette méthode permet les initialisations.
163 #    """
164     #_setContext(sgPyQt.getStudyId())
165
166
167 def activate():
168     """
169     Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
170     activé dans une étude précédente.
171
172     Portage V3.
173     """
174 #    setSettings()
175     GUIcontext()
176
177
178 # -----------------------------------------------------------------------------
179
180 #def activeStudyChanged(ID):
181 #    _setContext(ID)
182
183
184 # -----------------------------------------------------------------------------
185
186 def runEficas():
187     print("-------------------------EFICASGUI::runEficas-------------------------")
188     import eficasSalome
189     eficasSalome.runEficas(multi=True)
190
191
192 def runEficaspourTelemac():
193     import eficasSalome
194     eficasSalome.runEficas("TELEMAC")
195
196
197 def runEficaspourAdao():
198     print("runEficas Pour Ada")
199     import eficasSalome
200     eficasSalome.runEficas("ADAO")
201
202
203 def runEficaspourMT():
204     print("runEficas Pour MT")
205     import eficasSalome
206     eficasSalome.runEficas("MT")
207
208
209 def runEficaspourSPECA():
210     print("runEficas Pour SPECA")
211     import eficasSalome
212     eficasSalome.runEficas("SPECA")
213
214
215 def runEficaspourSEP():
216     print("runEficas Pour SEP")
217     import eficasSalome
218     eficasSalome.runEficas("SEP")
219
220
221 def runEficaspourMap():
222     print("runEficas Pour Map ")
223     import eficasSalome
224     eficasSalome.runEficas("MAP")
225
226
227 def runEficaspourCarmel3D():
228     print("runEficas Pour Carmel3D ")
229     import eficasSalome
230     eficasSalome.runEficas("CARMEL3D")
231
232
233 def runEficaspourCF():
234     print("runEficas Pour CF ")
235     import eficasSalome
236     eficasSalome.runEficas("CF")
237
238
239 def runEficasFichier(version=None):
240     """
241     Lancement d'eficas pour ASTER
242     si un fichier est sélectionné, il est ouvert dans eficas
243     """
244     fileName = None
245     code = None
246     a = salome.sg.getAllSelected()
247     if len(a) == 1:
248         selectedEntry = a[0]
249
250         editor = getStudyEditor()
251         mySO = editor.study.FindObjectID(selectedEntry)
252         aType = editor.getFileType(mySO)
253         aValue = editor.getFileName(mySO)
254         if aType is not None:
255             fileName = aValue
256             code = aType[15:]
257     else:
258         QMessageBox.critical(None, "Selection Invalide",
259                              "Selectionner un seul fichier SVP")
260         return
261
262     import eficasSalome
263     if code:
264         if version:
265             eficasSalome.runEficas(code, fileName, version=version)
266         else:
267             eficasSalome.runEficas(code, fileName)
268
269
270 # Partie applicative
271
272 dict_command = {
273                 GUIcontext.TELEMAC_ID: runEficaspourTelemac,
274                 GUIcontext.ADAO_ID: runEficaspourAdao,
275                 GUIcontext.MT_ID: runEficaspourMT,
276                 GUIcontext.SPECA_ID: runEficaspourSPECA,
277                 GUIcontext.SEP_ID: runEficaspourSEP,
278                 GUIcontext.CF_ID: runEficaspourCF,
279                 GUIcontext.MAP_ID: runEficaspourMap,
280                 GUIcontext.CARMEL3D_ID: runEficaspourCarmel3D,
281                 GUIcontext.MULTICATALOG_ID: runEficas,
282
283                 9041: runEficasFichier,
284              }
285