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