Salome HOME
ajout d'un gestionnaire de l'arbre d'étude ( cf module EficasStudy )
[modules/eficas.git] / src / EFICASGUI / EFICASGUI.py
1 """
2     Interface PyQt
3 """
4 import qt
5 import libSALOME_Swig
6 import SalomePyQt
7
8 # Variable globale pour stocker le Workspace de Salome
9
10 WORKSPACE=None
11 currentStudyId=None
12 desktop=None
13
14 # -----------------------------------------------------------------------------
15
16 import notifqt
17 #import Tkinter
18 #root.withdraw()
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 import salomedsgui
35 aGuiDS=salomedsgui.guiDS()
36 print "EFicasGUI :: :::::::::::::::::::::::::::::::::::::::::::::::::::::"
37
38
39
40 # -----------------------------------------------------------------------------
41 # gestionnaire arbre d'étude
42 from EficasStudy import study
43
44
45 # -----------------------------------------------------------------------------
46
47 def setWorkSpace(workSpace):
48    print "EficasGUI --- setWorkSpace"
49    global WORKSPACE
50    print workSpace
51    WORKSPACE=workSpace
52    print "WORKSPACE: ",WORKSPACE
53    # le desktop
54    desktop=sgPyQt.getDesktop()
55
56    # creation d'une message box
57    #qt.QMessageBox.information(d,"titre","message")
58
59    # recuperation du workspace
60    ws=sgPyQt.getMainFrame()
61    print ws
62
63 # -----------------------------------------------------------------------------
64
65 def OnGUIEvent(commandID) :
66    print "EficasGUI :: OnGUIEvent :::::::::::::::::::::::::::::::::commandID,WORKSPACE = ",commandID,WORKSPACE
67    if dict_command.has_key(commandID):
68       print "OnGUIEvent ::::::::::  commande associée  : ",commandID      
69       dict_command[commandID](WORKSPACE)
70    else:
71       print "Pas de commande associée a : ",commandID
72
73 # -----------------------------------------------------------------------------
74
75 def setSettings():
76    """
77    Cette méthode permet les initialisations. On définit en particulier
78    l'identifiant de l'étude courante.
79    """
80    # le desktop
81    desktop=sgPyQt.getDesktop()
82    global currentStudyId
83    currentStudyId = sgPyQt.getStudyId()
84    print "setSettings: currentStudyId = " + str(currentStudyId)
85    # _CS_gbo_ Voir si on peut utiliser directement sgPyQt.getStudyId()
86    # dans salomedsgui?   
87    study.setCurrentStudyID( currentStudyId )
88
89
90 # -----------------------------------------------------------------------------
91
92 def activeStudyChanged(ID):
93    # le desktop
94    desktop=sgPyQt.getDesktop()
95    global currentStudyId
96    # ne marche pas car sg est supposé résider dans une etude
97    # studyId=sg.getActiveStudyId()
98    currentStudyId=ID
99    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : currentStudyId = ", currentStudyId
100    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : sgPyQt.getStudyId() = ", sgPyQt.getStudyId()   
101    study.setCurrentStudyID( ID )
102    
103
104 def definePopup(theContext, theObject, theParent):
105    print "EFICASGUI --- definePopup"
106    theContext = ""
107    theParent = "ObjectBrowser"
108    a=salome.sg.getAllSelected()
109    if len(a) >0:
110        theObject="73"
111    return (theContext, theObject, theParent)
112
113
114 def customPopup(popup, theContext, theObject, theParent):
115    print "EFICASGUI --- customPopup"
116    popup.removeItem(99000)
117    popup.removeItem(99001)
118    popup.removeItem(99002)
119    popup.removeItem(99003)
120
121
122 # -----------------------------------------------------------------------------
123
124 import eficasSalome
125
126 def runEficas(ws):
127    print "--------------------------------------------------"
128    print currentStudyId
129    eficasSalome.runEficas(ws,"ASTER",studyId=currentStudyId)
130    
131 def runEELIH(ws,code="ASTER"):
132    # Enregistrement dans l étude
133    import eficasEtude
134    import appli
135    print "++++++++++++++++++++++++++++++++++++++++++++++++++++"
136    print currentStudyId
137    
138    MaRef=eficasEtude.Eficas_In_Study(code,studyId=currentStudyId)
139    # flag = E pour Eficas (enregistrement manuel du fichier de commandes)
140    flag = 'E'
141    moi=appli.Appli(MaRef, flag)
142    
143 def runEficaspourHomard(ws):
144    print "runEficas"
145    eficasSalome.runEficas(ws,"HOMARD")
146     
147 def runEficasHomard(ws):
148    print "runEficas"
149    eficasSalome.runEficas(None,"HOMARD")
150
151 def runEficasFichier(ws):
152    """
153    Lancement d'eficas à partir d'un fichier sélectionné dans l'arbre
154    d'étude. 
155    """
156    print "runEficasFichier"
157    attr=None
158    code="ASTER"
159    a=salome.sg.getAllSelected()
160    if len(a) == 1:
161       aGuiDS.setCurrentStudy(currentStudyId)
162       boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])
163       if boo :
164          code = "ASTER" 
165       else :
166          boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_HOMARD",a[0])
167          code = "HOMARD"
168    
169    eficasSalome.runEficas(ws,code,attr,studyId=currentStudyId)
170
171 # Partie applicative
172
173 dict_command={
174                941:runEficas,
175                943:runEELIH,
176                946:runEficaspourHomard,
177                4041:runEficas,
178                4043:runEELIH,
179                4046:runEficaspourHomard,
180                9042:runEficasFichier,
181              }
182