Salome HOME
merge from V3_2_0_maintenance 17mar08
[modules/eficas.git] / src / EFICASGUI / EFICASGUI.py
1 # -*- coding: utf-8 -*-
2
3 """
4     Interface PyQt
5 """
6 import qt
7 import libSALOME_Swig
8 import SalomePyQt
9
10 # Variable globale pour stocker le Workspace de Salome
11
12 WORKSPACE=None
13 currentStudyId=None
14 desktop=None
15
16 # -----------------------------------------------------------------------------
17
18 import notifqt
19 #import Tkinter
20 #root.withdraw()
21
22 def g():
23    print "lastWindowClosed()"
24    import Tkinter
25    root=Tkinter.Tk()
26    root.destroy()
27
28 qt.QObject.connect(qt.qApp,qt.SIGNAL("lastWindowClosed()"),g)
29
30 # -----------------------------------------------------------------------------
31
32 import salome
33
34 sg=salome.sg
35 sgPyQt=SalomePyQt.SalomePyQt()
36
37
38 import studyManager
39
40 print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
41
42
43
44 # -----------------------------------------------------------------------------
45 #Cette méthode est obsolète en V3
46 #En V2, si on n'implémente pas cette méthode, le composant fonctionne
47 #correctement. Un message "Attribute Error" apparait dans la trace.
48 def setWorkSpace(workSpace):
49    #print "EficasGUI --- setWorkSpace"
50    global WORKSPACE
51    #print workSpace
52    WORKSPACE=workSpace
53    #print "WORKSPACE: ",WORKSPACE
54    # le desktop
55    desktop=sgPyQt.getDesktop()
56
57    # creation d'une message box
58    #qt.QMessageBox.information(d,"titre","message")
59
60    # recuperation du workspace
61    ws=sgPyQt.getMainFrame()
62    #print ws
63
64 # -----------------------------------------------------------------------------
65
66 def OnGUIEvent(commandID) :
67    print "EficasGUI :: OnGUIEvent :::::::::::::::::::::::::::::::::commandID = ",commandID
68    if dict_command.has_key(commandID):
69       print "OnGUIEvent ::::::::::  commande associée  : ",commandID      
70       dict_command[commandID]()
71    else:
72       print "Pas de commande associée a : ",commandID
73
74 # -----------------------------------------------------------------------------
75
76 def setSettings():
77    """
78    Cette méthode permet les initialisations. On définit en particulier
79    l'identifiant de l'étude courante.
80    """
81    # le desktop
82    desktop=sgPyQt.getDesktop()
83    global currentStudyId
84    currentStudyId = sgPyQt.getStudyId()
85    #print "setSettings: currentStudyId = " + str(currentStudyId)
86    # _CS_gbo_ Voir si on peut utiliser directement sgPyQt.getStudyId()
87    # dans salomedsgui?
88    
89    studyManager.palStudy.setCurrentStudyID( currentStudyId ) #CS_pbruno   
90
91 def activate():
92    """
93    Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
94    activé dans une étude précédente.
95    
96    Portage V3.
97    """
98    print "--------EFICASGUI:: activate"
99    setSettings()
100
101
102 # -----------------------------------------------------------------------------
103
104 def activeStudyChanged(ID):
105    # le desktop
106    desktop=sgPyQt.getDesktop()
107    global currentStudyId
108    # ne marche pas car sg est supposé résider dans une etude
109    # studyId=sg.getActiveStudyId()
110    currentStudyId=ID
111    
112    studyManager.palStudy.setCurrentStudyID( currentStudyId ) #CS_pbruno
113    
114
115 def definePopup(theContext, theObject, theParent):    
116    theContext= ""
117    theObject = "100"
118    theParent = "ObjectBrowser"
119    a=salome.sg.getAllSelected()
120    #print a
121     
122    selectedEntry = a[0]
123    aType, aValue = studyManager.palStudy.getTypeAndValue( selectedEntry )
124    
125    if aType == studyManager.FICHIER_EFICAS_ASTER or aType == studyManager.FICHIER_EFICAS_HOMARD \
126       or aType == studyManager.FICHIER_EFICAS_HOMARD:
127         theObject="73"    
128             
129    return (theContext, theObject, theParent)
130
131
132 def customPopup(popup, theContext, theObject, theParent):
133    print "EFICASGUI --- customPopup"
134    popup.removeItem(99000)
135    popup.removeItem(99001)
136    popup.removeItem(99002)
137    popup.removeItem(99003)
138
139
140 def windows():
141     """
142     This method is called when GUI module is being created
143     and initialized.
144     Should return a map of the SALOME dockable windows id's
145     needed to be opened when module is activated.
146     """
147     print "ASTERGUI::windows"
148     from qt import Qt
149     winMap = {}
150     winMap[ SalomePyQt.WT_ObjectBrowser ] = Qt.DockLeft
151     winMap[ SalomePyQt.WT_PyConsole ]     = Qt.DockBottom
152     return winMap   
153
154 # -----------------------------------------------------------------------------
155
156 import eficasSalome
157
158 def runEficas():
159    print "-------------------------EFICASGUI::runEficas-------------------------"
160    print currentStudyId      
161    #eficasSalome.runEficas("ASTER",studyId=currentStudyId)   
162    #ws = sgPyQt.getMainFrame()   
163    #desktop=sgPyQt.getDesktop()   
164    eficasSalome.runEficas( "ASTER" )
165    
166
167 def runEficaspourHomard():
168    print "runEficas"
169    #eficasSalome.runEficas("HOMARD")
170    desktop=sgPyQt.getDesktop()
171    eficasSalome.runEficas( "HOMARD" ) 
172    
173 def runEficaspourOpenturns():
174    print "runEficas Pour Openturns"
175    desktop=sgPyQt.getDesktop()
176    eficasSalome.runEficas( "OPENTURNS" ) 
177    
178    
179
180 def runEficasFichier(version=None):
181    """
182    Lancement d'eficas pour ASTER
183    si un fichier est sélectionné, il est ouvert dans eficas
184    """
185    fileName = None
186    code     = None
187    a=salome.sg.getAllSelected()
188    if len(a) == 1:
189       #studyManager.palStudy.setCurrentStudyID( currentStudyId )
190       #boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])      
191       selectedEntry = a[0]
192       
193       aType, aValue = studyManager.palStudy.getTypeAndValue( selectedEntry )
194       if aType == studyManager.FICHIER_EFICAS_ASTER:        
195         fileName = aValue
196         code     = "ASTER"
197       elif aType == studyManager.FICHIER_EFICAS_HOMARD:        
198         fileName = aValue
199         code     = "HOMARD"
200       elif aType == studyManager.FICHIER_EFICAS_OPENTURNS:        
201         fileName = aValue
202         code     = "OPENTURNS"
203       else:
204         fileName=None
205         code = "ASTER"
206    else:        
207         code = "ASTER"            
208         
209    if code:
210         #eficasSalome.runEficas(code,attr,studyId=currentStudyId)         
211         #desktop=sgPyQt.getDesktop()        
212         if version :
213             eficasSalome.runEficas( code, fileName, version=version)
214         else :
215             eficasSalome.runEficas( code, fileName)
216         
217
218 def runEficasFichierV8():
219     runEficasFichier(version="v8.5")
220    
221 def runEficasFichierV9():
222     runEficasFichier(version="v9.1")
223
224 # Partie applicative
225
226 dict_command={
227                 941:runEficasFichier,# runEficas,
228                 946:runEficaspourHomard,
229                 946:runEficaspourOpenturns,
230                 4041:runEficasFichier, #runEficas,
231                 4046:runEficaspourHomard,
232                 4047:runEficaspourOpenturns,
233                 9042:runEficasFichier,
234                 9043:runEficasFichierV8,
235                 9044:runEficasFichierV9,
236              }
237              
238
239
240