Salome HOME
Portage V3:
[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 # gestionnaire arbre d'étude
41 from EficasStudy import study
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    study.setCurrentStudyID( currentStudyId )
89
90 def activate():
91    """
92    Cette méthode permet l'activation du module, s'il a été chargé mais pas encore
93    activé dans une étude précédente.
94    
95    Portage V3.
96    """
97    print "--------EFICASGUI:: activate"
98    setSettings()
99
100
101 # -----------------------------------------------------------------------------
102
103 def activeStudyChanged(ID):
104    # le desktop
105    desktop=sgPyQt.getDesktop()
106    global currentStudyId
107    # ne marche pas car sg est supposé résider dans une etude
108    # studyId=sg.getActiveStudyId()
109    currentStudyId=ID
110    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : currentStudyId = ", currentStudyId
111    print "_CS_GBO_ : EFICASGUI.activeStudyChanged : sgPyQt.getStudyId() = ", sgPyQt.getStudyId()   
112    study.setCurrentStudyID( ID )
113    
114
115 def definePopup(theContext, theObject, theParent):
116    print "EFICASGUI --- definePopup"
117    theContext = ""
118    theParent = "ObjectBrowser"
119    a=salome.sg.getAllSelected()
120    if len(a) >0:
121        theObject="73"
122    return (theContext, theObject, theParent)
123
124
125 def customPopup(popup, theContext, theObject, theParent):
126    print "EFICASGUI --- customPopup"
127    popup.removeItem(99000)
128    popup.removeItem(99001)
129    popup.removeItem(99002)
130    popup.removeItem(99003)
131
132
133 # -----------------------------------------------------------------------------
134
135 import eficasSalome
136
137 def runEficas():
138    print "-------------------------EFICASGUI::runEficas-------------------------"
139    print currentStudyId
140    eficasSalome.runEficas("ASTER",studyId=currentStudyId)
141    
142 def runEELIH(code="ASTER"):
143    # Enregistrement dans l étude
144    import eficasEtude
145    import appli
146    print "++++++++++++++++++++++++++++++++++++++++++++++++++++"
147    print currentStudyId
148    
149    MaRef=eficasEtude.Eficas_In_Study(code,studyId=currentStudyId)
150    # flag = E pour Eficas (enregistrement manuel du fichier de commandes)
151    flag = 'E'
152    moi=appli.Appli(MaRef, flag)
153    
154 def runEficaspourHomard():
155    print "runEficas"
156    eficasSalome.runEficas("HOMARD")
157     
158 def runEficasHomard():
159    print "runEficas"
160    eficasSalome.runEficas("HOMARD")
161
162 def runEficasFichier():
163    """
164    Lancement d'eficas à partir d'un fichier sélectionné dans l'arbre
165    d'étude. 
166    """
167    print "runEficasFichier"
168    attr=None
169    code="ASTER"
170    a=salome.sg.getAllSelected()
171    if len(a) == 1:
172       aGuiDS.setCurrentStudy(currentStudyId)
173       boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_ASTER",a[0])
174       if boo :
175          code = "ASTER" 
176       else :
177          boo,attr=aGuiDS.getExternalFileAttribute("FICHIER_EFICAS_HOMARD",a[0])
178          code = "HOMARD"
179    
180    eficasSalome.runEficas(code,attr,studyId=currentStudyId)
181
182 # Partie applicative
183
184 dict_command={
185                 941:runEficas,
186                 943:runEELIH,
187                 946:runEficaspourHomard,
188                 4041:runEficas,
189                 4043:runEELIH,
190                 4046:runEficaspourHomard,
191                 9042:runEficasFichier,
192              }
193