]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/browser.py
Salome HOME
f538643e0c87f8becb7c5bbb96b23374d4d56297
[tools/eficas.git] / InterfaceQT4 / browser.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   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.
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 import string,re
22 import types,sys,os
23 import traceback
24 import typeNode
25 #import pdb
26
27 from determine import monEnvQT5
28 if monEnvQT5 :
29   from PyQt5.QtWidgets import QTreeWidget , QTreeWidgetItem
30   from PyQt5.QtGui import QIcon
31   from PyQt5.QtCore  import Qt
32 else :
33   from PyQt4.QtGui  import *
34   from PyQt4.QtCore  import *
35 from Extensions.i18n import tr
36 from gereRegles import GereRegles
37 from monChoixCommande import MonChoixCommande
38
39 class JDCTree( QTreeWidget,GereRegles ):
40     def __init__( self, jdc_item, QWParent):        
41         #if hasattr(QWParent,'widgetTree') : 
42         self.editor        = QWParent
43         self.plie=False
44         if self.editor.widgetTree !=None  :
45            QTreeWidget.__init__(self, self.editor.widgetTree ) 
46            self.editor.verticalLayout_2.addWidget(self)
47            if self.editor.enteteQTree=='complet':
48                  self.headerItem().setText(0,  "Commande   ")
49                  self.headerItem().setText(1, "Concept/Valeur")
50            else :
51                  self.headerItem().setText(0,  "Commande   ")
52            self.setColumnWidth(0,200)
53            self.setExpandsOnDoubleClick(False)
54            self.setSelectionMode(3)
55         else :
56            QTreeWidget.__init__(self, None ) 
57         self.item          = jdc_item
58         self.tree          = self        
59         self.appliEficas   = self.editor.appliEficas
60         self.childrenComplete=[]
61         self.racine=self.item.itemNode(self,self.item)
62  
63         self.itemCourrant=None
64
65         if monEnvQT5 :
66            self.itemClicked.connect(self.handleOnItem)
67            self.itemCollapsed.connect(self.handleCollapsedItem)
68            self.itemExpanded.connect(self.handleExpandedItem)
69         else :
70            self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
71            self.connect(self, SIGNAL("itemCollapsed ( QTreeWidgetItem *) "), self.handleCollapsedItem)
72            self.connect(self, SIGNAL("itemExpanded ( QTreeWidgetItem *) "), self.handleExpandedItem)
73
74         #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande
75         self.node_selected=self.racine
76         self.inhibeExpand=True
77         self.expandItem(self.racine)
78         self.inhibeExpand=False
79         #print "self.editor.afficheCommandesPliees", self.editor.afficheCommandesPliees
80         if self.racine.children !=[] :  
81
82             
83            if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
84            else : self.racine.children[0].deplieToutEtReaffiche()
85         
86
87            self.racine.children[0].fenetre.donnePremier()
88         else : self.racine.affichePanneau()
89         #PNPNPN
90         #pdb.set_trace()
91
92     def contextMenuEvent(self,event) :
93         #print "contextMenuEvent"
94         coord=event.globalPos()
95         item= self.currentItem()
96         self.handleContextMenu(item,coord)
97
98     def handleContextMenu(self,item,coord):
99         """
100         Private slot to show the context menu of the listview.
101         
102         @param itm the selected listview item (QListWidgetItem)
103         @param coord the position of the mouse pointer (QPoint)
104         Attention : existeMenu permet de savoir si un menu est associe a cet item
105         """
106         #print "handleContextMenu"
107         if item == None : return
108         if item.existeMenu == 0 : return
109         if item.menu == None:
110            item.createPopUpMenu()
111         if item.menu != None:
112            if item.item.get_nom() == "DISTRIBUTION" and item.item.isvalid() :
113               item.Graphe.setEnabled(1)
114            item.menu.exec_(coord)            
115             
116
117     def handleCollapsedItem(self,item):
118         #print "dans CollapsedItem", self.inhibeExpand  
119         if self.inhibeExpand == True : return
120         # On traite le cas de l item non selectionne
121         itemParent=item
122         while not (hasattr (itemParent,'getPanel')) : 
123            itemParent=itemParent.treeParent 
124         if self.tree.node_selected != itemParent : 
125              item.setExpanded(False)
126              return
127
128         itemParent=item
129         item.setPlie()
130         item.plieToutEtReaffiche()
131         item.select()
132
133     def handleExpandedItem(self,item):
134         #print "handleExpandedItem pour ", item.item.nom, self.inhibeExpand
135         if self.inhibeExpand == True : return
136         itemParent=item
137         while not (hasattr (itemParent,'getPanel')) : 
138            if itemParent.plie==True : itemParent.setDeplie()
139            itemParent=itemParent.treeParent 
140         if self.tree.node_selected != itemParent : 
141              item.setExpanded(True)
142              return
143         item.deplieToutEtReaffiche()
144         self.inhibeExpand == False 
145
146
147     def handleOnItem(self,item,int):
148         print "je passe dans handleOnItem pour ",self, item.item.nom, item, item.item
149         
150         from InterfaceQT4 import composimp
151         self.inhibeExpand == True 
152         self.itemCourrant=item
153         itemParent=item
154
155         while not (hasattr (itemParent,'getPanel')) : 
156            if itemParent.plie==True : itemParent.setDeplie()
157            itemParent=itemParent.treeParent 
158
159         if itemParent.fenetre != self.editor.fenetreCentraleAffichee : 
160               
161             estUneFeuille=(isinstance(item,composimp.Node))
162              # il faut afficher le parent
163             print "estUneFeuille", estUneFeuille
164             print "afficheCommandesPliees", self.editor.afficheCommandesPliees
165             if estUneFeuille                        : itemParent.affichePanneau()
166             elif self.editor.afficheCommandesPliees : itemParent.plieToutEtReafficheSaufItem(item)
167             else                                    : itemParent.affichePanneau()
168
169
170         if (isinstance(item,composimp.Node)) and item.fenetre : item.fenetre.rendVisible()
171         elif itemParent!=item:
172              #self.tree.handleExpandedItem(item)
173              #item.fenetre.donnePremier()
174              #item.fenetre.rendActif()
175              print 'il faut afficher le 1er'
176         try :
177            fr = item.item.get_fr()
178            if self.editor: self.editor.affiche_commentaire(unicode(fr))
179         except:
180             pass
181         item.select()
182         self.inhibeExpand == False 
183         #print "je mets inhibeExpand a false handleOnItem"
184
185
186     def choisitPremier(self,name):
187         self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
188         self.racine.fenetre.close()
189         new_node=self.racine.append_brother(name,'after')
190  
191 # type de noeud
192 COMMENT     = "COMMENTAIRE"
193 PARAMETERS  = "PARAMETRE"
194  
195 class JDCNode(QTreeWidgetItem,GereRegles):
196     def __init__( self, treeParent, item, itemExpand=False, ancien=False ):
197         #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent, self
198         #self.a=0
199         self.item        = item
200         self.vraiParent  = treeParent
201         self.treeParent  = treeParent
202         self.tree        = self.treeParent.tree
203         self.editor      = self.treeParent.editor
204         self.appliEficas = treeParent.appliEficas
205         self.JESUISOFF=0
206         self.childrenComplete=[]
207
208                         
209         from InterfaceQT4 import compocomm
210         from InterfaceQT4 import compoparam
211         from InterfaceQT4 import composimp
212         if   (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
213         elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=tr(str(item.GetLabelText()[0]))
214         else:   name  = tr(str(tr( item.nom))+" :")
215         value = tr(str( item.GetText() ) )
216  
217
218         if monEnvQT5:
219            if self.editor.enteteQTree=='complet':mesColonnes=(name,value)
220            else : mesColonnes=(name,)
221         else :
222            mesColonnes=QStringList()
223            if self.editor.enteteQTree=='complet': mesColonnes <<  name << value
224            else : mesColonnes <<  name
225
226         if self.treeParent.plie==True :
227             self.plie        = True
228             self.appartientAUnNoeudPlie=True
229             if self.treeParent.item.isMCList() : self.appartientAUnNoeudPlie =  self.treeParent.appartientAUnNoeudPlie
230         else :
231             self.plie        = False
232             self.appartientAUnNoeudPlie = False
233
234         #if item.nom == "POUTRE" :print "creation d'un noeud : ", item, " ",item.nom,"", self.treeParent, self.appartientAUnNoeudPlie , self.plie
235
236         if ancien and itemExpand     : self.plie = False
237         if ancien and not itemExpand : self.plie = True 
238         if (isinstance(self.item,composimp.SIMPTreeItem)) : self.plie=False
239
240         from InterfaceQT4 import compobloc
241         from InterfaceQT4 import compomclist
242
243         ajoutAuParentduNoeud=0
244         self.treeParent=treeParent
245         while (isinstance(self.treeParent,compobloc.Node) or ( isinstance(self.treeParent,compomclist.Node) and self.treeParent.item.isMCList())) : 
246               self.treeParent.childrenComplete.append(self)
247               self.treeParent=self.treeParent.vraiParent
248         self.treeParent.childrenComplete.append(self)
249         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
250            QTreeWidgetItem.__init__(self,None,mesColonnes)
251         else :
252            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
253
254         if monEnvQT5 :
255            self.setToolTip(0,self.item.get_fr())
256            self.setToolTip(1,self.item.get_fr())
257            repIcon=self.appliEficas.repIcon
258         else :
259            self.setToolTip(0,QString(self.item.get_fr()))
260            self.setToolTip(1,QString(self.item.get_fr()))
261            repIcon=QString(self.appliEficas.repIcon)
262
263         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
264         self.setIcon(0,monIcone)
265
266         self.children = []
267         self.build_children()
268         self.menu=None
269         self.existeMenu=1
270
271         self.item.connect("valid",self.onValid,())
272         self.item.connect("supp" ,self.onSupp,())
273         self.item.connect("add"  ,self.onAdd,())
274
275         self.state=""
276         self.fenetre=None
277         try :
278           if self.item.getObject().isBLOC() : 
279                 self.setExpanded(True) 
280                 self.plie=False
281         except :
282           pass
283
284
285     def build_children(self,posInsertion=10000):
286         """ Construit la liste des enfants de self """
287         """ Se charge de remettre les noeuds Expanded dans le meme etat """
288         #print "*********** build_children ",self,self.item, self.item.nom
289         
290         self.listeItemExpanded=[]
291         self.listeItemPlie=[]
292
293         for enfant in self.childrenComplete :
294             if enfant.plie : self.listeItemPlie.append(enfant.item)
295             else : self.listeItemExpanded.append(enfant.item)
296
297         for enfant in self.childrenComplete :
298             parent=enfant.treeParent
299             parent.removeChild(enfant)
300             enfant.JESUISOFF=1
301          
302         
303         self.children = []
304         self.childrenComplete = []
305         sublist = self.item._GetSubList()
306         ind=0
307         
308         for item in sublist :
309             itemExpand=False
310             ancien=False
311             if item in self.listeItemExpanded : itemExpand=True;  ancien=True
312             if item in self.listeItemPlie     : itemExpand=False; ancien=True
313             nouvelItem=item.itemNode(self,item,itemExpand,ancien)
314             self.children.append(nouvelItem)
315
316         #print "fin *********** build_children ",self,self.item, self.item.nom
317
318         
319     def chercheNoeudCorrespondant(self,objSimp):
320         sublist = self.item._GetSubList()
321         for node in self.childrenComplete:
322             if node.item.object==objSimp : return node
323         return None
324
325
326     def affichePanneau(self) :
327         #if self.item.isactif(): 
328         #if self.editor.code == 'ASTER' and not(self.item.isactif()) : 
329         # posera des pb si un code decide d appeler FIN un mot clef
330         # on resoudera a ce moment la
331         # pour l instant pas de poussiere sous le tapis
332         if  not(self.item.isactif()) : 
333             from monWidgetInactif import MonWidgetInactif
334             self.fenetre = MonWidgetInactif(self,self.editor)
335         else:
336            itemParent=self
337            while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent 
338            if itemParent!=self : 
339               itemParent.affichePanneau()
340               return
341            self.fenetre=self.getPanel()
342          
343         #print "hhhhhhhhhh", self.editor.splitter.sizes()
344         for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
345             widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
346             self.editor.widgetCentraleLayout.removeItem(widget)
347         # ceinture et bretelle
348         #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
349         #print "iiiiiiiiiiiiiii", self.editor.splitter.sizes()
350         if self.editor.fenetreCentraleAffichee != None : 
351             #print "j enleve ", self.editor.fenetreCentraleAffichee, self.editor.fenetreCentraleAffichee.node.item.nom
352             self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
353             self.editor.fenetreCentraleAffichee.setParent(None)
354             self.editor.fenetreCentraleAffichee.close()
355             self.editor.fenetreCentraleAffichee.deleteLater()
356
357         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
358         #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom
359         self.editor.fenetreCentraleAffichee=self.fenetre
360         self.tree.node_selected= self
361
362         if self.editor.first :
363            #self.editor.splitter.setSizes((400,1400,400))
364            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
365         self.tree.inhibeExpand=True
366         self.tree.expandItem(self)
367         #self.select()
368         self.tree.inhibeExpand=False
369         #print "fin de affichePanneau", self.item.nom
370         #print "______________________________"
371           
372
373     def createPopUpMenu(self):
374         #implemente dans les noeuds derives si necessaire
375         self.existeMenu = 0
376
377     def commentIt(self):
378         """
379         Cette methode a pour but de commentariser la commande pointee par self
380         """
381         # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
382         # (commentariser) un commentaire.
383         try :
384             pos=self.treeParent.children.index(self)
385             commande_comment = self.item.get_objet_commentarise()
386             # On signale a l editeur du panel (le JDCDisplay) une modification
387             self.editor.init_modif()
388             self.treeParent.build_children()
389             self.treeParent.children[pos].select()
390             self.treeParent.children[pos].affichePanneau()
391         except Exception,e:
392             traceback.print_exc()
393             QMessageBox.critical( self.editor, "TOO BAD",str(e))
394         
395     def unCommentIt(self):
396         """
397         Realise la decommentarisation de self
398         """
399         try :
400             pos=self.treeParent.children.index(self)
401             commande,nom = self.item.uncomment()
402             self.editor.init_modif()
403             self.treeParent.build_children()
404             self.treeParent.children[pos].select()
405             self.treeParent.children[pos].affichePanneau()
406         except Exception,e:
407             QMessageBox.critical( self.editor, "Erreur !",str(e))
408         
409     def addComment( self, after=True ):
410         """
411         Ajoute un commentaire a l'interieur du JDC :
412         """
413         self.editor.init_modif()
414         if after:
415             pos = 'after'
416         else:
417             pos = 'before'
418         return self.append_brother( COMMENT, pos )
419                 
420     def addParameters( self, after=True ):
421         """
422         Ajoute un parametre a l'interieur du JDC :
423         """
424         self.editor.init_modif()
425         if after: pos = 'after'
426         else: pos = 'before'
427         child=self.append_brother( PARAMETERS, pos )
428         return  child
429     
430     
431     def select( self ):
432         """
433         Rend le noeud courant (self) selectionne et deselectionne
434         tous les autres
435         """        
436         #print "select pour", self.item.nom
437         for item in self.tree.selectedItems() :
438             item.setSelected(0)
439         self.tree.setCurrentItem( self )    
440                                
441     #------------------------------------------------------------------
442     # Methodes de creation et destruction de noeuds
443     # Certaines de ces methodes peuvent etre appelees depuis l'externe
444     #------------------------------------------------------------------
445     def append_brother(self,name,pos='after',plier=False):
446         """
447         Permet d'ajouter un objet frere a l'objet associe au noeud self
448         par defaut on l'ajoute immediatement apres 
449         Methode externe
450         """
451         self.editor.init_modif()
452
453         from InterfaceQT4 import compojdc
454         if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
455         
456         index = self.treeParent.children.index(self)
457         if   pos == 'before': index = index
458         elif pos == 'after': index = index +1
459         else:
460             print unicode(pos), tr("  n'est pas un index valide pour append_brother")
461             return 0
462         return self.treeParent.append_child(name,pos=index,plier=plier)
463
464     def verifiePosition(self,name,pos,aLaRacine=False):
465         if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
466         indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
467
468         etapes=self.item.get_jdc().etapes
469         if etapes == [] : return True
470
471         if aLaRacine == False :indexOu=etapes.index(self.item.object)
472         else : indexOu=0
473
474         if pos=="after" : indexOu = indexOu+1
475         for e in etapes[:indexOu] :
476             nom=e.nom
477             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
478             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
479             if indexEtape > indexName :
480                comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
481                QMessageBox.information( None,tr('insertion impossible'),comment, )
482                return False
483         for e in etapes[indexOu:] :
484             nom=e.nom
485             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
486             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
487             if indexEtape < indexName :
488                comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
489                QMessageBox.information( None,tr('insertion impossible'),comment, )
490                return False
491         return True
492
493     def append_child(self,name,pos=None,plier=False):
494         """
495            Methode pour ajouter un objet fils a l'objet associe au noeud self.
496            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
497            ou en position intermediaire.
498            Si pos vaut None, on le place a la position du catalogue.
499         """
500         #print "************** append_child ",self.item.GetLabelText(), plier
501
502          
503         self.editor.init_modif()
504         if pos == 'first':
505             index = 0
506         elif pos == 'last':
507             index = len(self.children)
508         elif type(pos) == types.IntType :
509             # position fixee
510             index = pos
511         elif type(pos) == types.InstanceType:
512             # pos est un item. Il faut inserer name apres pos
513             index = self.item.get_index(pos) +1
514         elif type(name) == types.InstanceType:
515             index = self.item.get_index_child(name.nom)
516         else:
517             index = self.item.get_index_child(name)
518
519         # si on essaye d inserer a la racine
520         if (isinstance(self.treeParent,JDCTree) and index==0) :
521            verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
522            if not verifiePosition : return 0
523
524         self.tree.inhibeExpand=True
525         obj=self.item.additem(name,index) # emet le signal 'add'
526         if obj is None:obj=0
527         if obj == 0:return 0
528         try :
529            child=self.children[index]
530            if plier == True : child.setPlie()
531            else             : child.setDeplie() 
532         except :
533            child=self.children[index]
534         self.tree.inhibeExpand=False
535         #print " fin append child"
536         return child
537
538     def deplace(self):
539         self.editor.init_modif()
540         index = self.treeParent.children.index(self) - 1 
541         if index < 0 : index =0
542         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
543
544     def delete(self):
545         """ 
546             Methode externe pour la destruction de l'objet associe au noeud
547         """
548         self.editor.init_modif()
549         index = self.vraiParent.children.index(self) - 1 
550         if index < 0 : index =0
551         recalcule=0
552         if self.item.nom == "VARIABLE" :
553            recalcule=1
554            jdc=self.item.jdc
555         ret,commentaire=self.vraiParent.item.suppitem(self.item)
556         if ret==0 :
557           self.editor.affiche_infos(commentaire,Qt.red)
558         else :
559           self.editor.affiche_infos(commentaire)
560         self.treeParent.build_children()
561         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
562         else: toselect=self.treeParent
563         if recalcule : jdc.recalcule_etat_correlation()
564         if ret==0 :
565             if self.treeParent.childrenComplete :
566                 notdeleted=self.treeParent.childrenComplete[index+1]
567                 notdeleted.select()
568         else :
569             toselect.select()
570         from InterfaceQT4 import compojdc
571         # cas ou on detruit dans l arbre sans affichage
572         if isinstance(self.treeParent,compojdc.Node) : 
573            toselect.affichePanneau()
574         else :
575            if self.treeParent.fenetre== None : return
576            #print "J appelle reaffiche de browser apres delete"
577            self.treeParent.fenetre.reaffiche(toselect)
578
579     def deleteMultiple(self,liste=()):
580         """ 
581             Methode externe pour la destruction d une liste de noeud
582         """
583         from InterfaceQT4 import compojdc 
584         self.editor.init_modif()
585         index=9999
586         recalcule=0
587         jdc=self.treeParent
588         parentPosition=jdc
589         while not(isinstance(jdc,compojdc.Node)):
590               jdc=jdc.treeParent
591         for noeud in liste :
592             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
593             if noeud.item.nom == "VARIABLE" : recalcule=1
594             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
595         if index < 0 : index =0
596
597         # Cas ou on détruit dans une ETape
598         if index == 9999 : 
599               parentPosition=self.treeParent
600               while not(isinstance(parentPosition, compojdc.Node)):
601                  index=parentPosition.treeParent.children.index(parentPosition)
602                  parentPosition=parentPosition.treeParent
603
604         for noeud in liste:
605             noeud.treeParent.item.suppitem(noeud.item)
606
607         jdc.build_children()
608         if recalcule : jdc.recalcule_etat_correlation()
609         try    : toselect=parentPosition.children[index]
610         except : toselect=jdc
611         toselect.select()
612         toselect.affichePanneau()
613 #        
614 #    #------------------------------------------------------------------
615     def onValid(self):        
616
617         #print "onValid pour ", self.item.nom
618         if self.JESUISOFF==1 : return
619         if hasattr(self,'fenetre') and self.fenetre: 
620            try :
621              self.fenetre.setValide()
622            except :
623              print "onValid pour ", self.item.nom, self,'pb'
624
625         if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
626            self.item.jdc.recalcule_etat_correlation()
627         if hasattr(self.item,'forceRecalcul'):
628            self.forceRecalculChildren(self.item.forceRecalcul)
629         self.editor.init_modif()
630         
631         self.update_node_valid()
632         self.update_node_label()
633         self.update_node_texte()
634
635     def onAdd(self,object):
636         if self.JESUISOFF==1 : return
637         #print "onAdd pour ", self.item.nom, object.nom
638         self.editor.init_modif()
639         self.update_nodes()
640         # PN -- non necessaire si item=jdc
641         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
642  
643     def onSupp(self,object):
644         if self.JESUISOFF==1 : return
645         #print "onSup pour ", self.item.nom, object.nom
646         self.editor.init_modif()
647         self.update_nodes()
648         # PN -- non necessaire si item=jdc
649         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
650          
651
652
653     def update_node_valid(self):
654         """Cette methode remet a jour la validite du noeud (icone)
655            Elle appelle isvalid
656         """
657         if monEnvQT5 : repIcon=self.appliEficas.repIcon
658         else : repIcon=QString(self.appliEficas.repIcon)
659         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
660         self.setIcon(0,monIcone)
661
662
663     def update_node_label(self):
664         """ Met a jour le label du noeud """
665         #print "NODE update_node_label", self.item.GetLabelText()
666         labeltext,fonte,couleur = self.item.GetLabelText()
667         # PNPN a reflechir
668         #self.setText(0, labeltext)        
669     
670     
671     def update_node_label_in_blue(self):
672         if hasattr(self.appliEficas,'noeudColore'):
673            self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
674            self.appliEficas.noeudColore.update_node_label()
675         self.setTextColor( 0,Qt.blue )
676         labeltext,fonte,couleur = self.item.GetLabelText()
677         self.setText(0, labeltext)        
678         self.appliEficas.noeudColore=self
679
680     def update_plusieurs_node_label_in_blue(self,liste):
681         if hasattr(self.appliEficas,'listeNoeudsColores'):
682            for noeud in self.appliEficas.listeNoeudsColores:
683                noeud.setTextColor( 0,Qt.black)
684                noeud.update_node_label()
685         self.appliEficas.listeNoeudsColores=[]
686         for noeud in liste :
687             noeud.setTextColor( 0,Qt.blue )
688             labeltext,fonte,couleur = noeud.item.GetLabelText()
689             noeud.setText(0, labeltext)        
690             self.appliEficas.listeNoeudsColores.append(noeud)
691
692     def update_node_texte_in_black(self):
693         """ Met a jour les noms des SD et valeurs des mots-cles """
694         self.setTextColor( 1,Qt.black )
695         value = self.item.GetText()
696         self.setText(1, value)
697
698     def update_node_texte(self):
699         """ Met a jour les noms des SD et valeurs des mots-cles """
700         value = self.item.GetText()
701         self.setText(1, value)
702         
703
704     def update_node_texte_in_blue(self):
705         self.setTextColor( 1,Qt.blue )
706         value = self.item.GetText()
707         self.setText(1, value)
708
709     def update_nodes(self):
710         #print 'NODE update_nodes', self.item.GetLabelText()
711         self.build_children()
712
713     def update_valid(self) :
714         """Cette methode a pour but de mettre a jour la validite du noeud
715            et de propager la demande de mise a jour a son parent
716         """
717         #print "NODE update_valid", self.item.GetLabelText()
718         self.update_node_valid()
719         try :
720           self.treeParent.update_valid()
721         except:
722           pass
723             
724     def update_texte(self):
725         """ Met a jour les noms des SD et valeurs des mots-cles """
726         #print "NODE update_texte", self.item.GetLabelText()
727         self.update_node_texte()
728         if self.isExpanded() :
729             for child in self.children:
730                 if child.isHidden() == false : child.update_texte()
731
732
733     def forceRecalculChildren(self,niveau):
734         if self.state=='recalcule' : 
735            self.state=""
736            return
737         self.state='recalcule'
738         if hasattr(self.item,'object'):
739            self.item.object.state="modified"
740         for child in self.children:
741            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
742               
743         
744
745     def doPaste(self,node_selected,pos='after'):
746         """
747             Déclenche la copie de l'objet item avec pour cible
748             l'objet passé en argument : node_selected
749         """
750         #print 'je passe dans doPaste'
751         objet_a_copier = self.item.get_copie_objet()
752         child=node_selected.doPasteCommande(objet_a_copier,pos)
753         return child
754
755     def doPasteCommande(self,objet_a_copier,pos='after'):
756         """
757           Réalise la copie de l'objet passé en argument qui est nécessairement
758           une commande
759         """
760         child=None
761         try :
762           child = self.append_brother(objet_a_copier,pos)
763         except :
764            pass
765         return child
766
767     def doPastePremier(self,objet_a_copier):
768         """
769            Réalise la copie de l'objet passé en argument (objet_a_copier)
770         """
771         objet = objet_a_copier.item.get_copie_objet()
772         child = self.append_child(objet,pos='first')
773         return child
774
775     def plieToutEtReafficheSaufItem(self, itemADeplier):
776         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
777         from InterfaceQT4 import compojdc
778         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
779         self.editor.deplier = False
780         for item in self.children :
781             # il ne faut pas plier les blocs 
782             from InterfaceQT4 import compobloc
783             if (isinstance(item,compobloc.Node)) : continue
784             item.setPlie()
785             if item==itemADeplier : 
786                   itemADeplier.setDeplie()
787         self.affichePanneau()
788
789     def plieToutEtReaffiche(self):
790         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
791         from InterfaceQT4 import compojdc
792         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
793         self.editor.deplier = False
794         for item in self.children :
795             # il ne faut pas plier les blocs 
796             from InterfaceQT4 import compobloc
797             if (isinstance(item,compobloc.Node)) : continue
798             item.setPlie()
799         self.affichePanneau()
800
801     def deplieToutEtReaffiche(self):
802         self.editor.deplier = True
803         for item in self.children :
804             item.setDeplie()
805         self.affichePanneau()
806
807     def setPlie(self):
808         #print "je mets inhibeExpand a true dans setPlie"
809         #print "je suis dans plieTout", self.item.get_nom()
810         import compojdc
811         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
812            return
813         self.tree.inhibeExpand=True
814         self.tree.collapseItem(self)
815         self.setPlieChildren()
816         self.tree.inhibeExpand=False
817         #print "je mets inhibeExpand a false dans setPlie"
818
819
820         # on ne plie pas au niveau 1
821         #   self.plie=False
822         #   for item in self.children :
823         #       item.appartientAUnNoeudPlie=False
824
825     def setPlieChildren(self):
826         #print "dans setPlieChildren pour", self.item.nom
827         self.plie=True
828         for c in self.children :
829             c.setPlieChildren()
830             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
831             c.appartientAUnNoeudPlie=True
832             c.plie=True
833             #print "dans setPlieChildren plie", c.item.nom
834             c.setExpanded(False)
835
836         # Pour les blocs et les motcles list
837         # on affiche un niveau de plus
838         from InterfaceQT4 import compobloc
839         from InterfaceQT4 import compomclist
840         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
841             niveauPere=self.treeParent
842             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
843                niveauPere=niveauPere.treeParent
844             for c in self.children :
845                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
846                 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie
847                 c.setExpanded(False)
848
849         # on affiche un niveau de plus
850         #if isinstance(self,compomclist.Node)  : 
851         #if isinstance(self,compobloc.Node)  : 
852         #    niveauPere=self.treeParent
853         #    while (isinstance(niveauPere,compobloc.Node)):
854         #       niveauPere=niveauPere.treeParent
855         #    for c in self.children :
856         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
857
858     def setDeplie(self):
859         #print "dans setPlieChildren pour", self.item.nom
860         #print "je mets inhibeExpand a true dans setDeplie"
861         self.tree.inhibeExpand=True
862         self.plie=False
863         self.tree.expandItem(self)
864         self.setDeplieChildren()
865         self.tree.inhibeExpand=False
866         #print "je mets inhibeExpand a false dans setDePlie"
867
868     def setDeplieChildren(self):
869         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
870         for c in self.children :
871             c.setDeplieChildren()
872             #print "dans setDeplieChildren ", c.item.nom
873             c.appartientAUnNoeudPlie=False
874             c.setExpanded(True)
875             c.plie=False
876        
877     def selectAvant(self):
878         i=self.item.jdc.etapes.index(self.item.object)
879         try :
880            cherche=self.item.jdc.etapes[i-1]
881         except :
882            cherche=self.item.jdc.etapes[-1]
883         node=None
884         for i in self.tree.racine.children :
885             if i.item.object== cherche  : 
886                node=i
887                break
888         if node : 
889           node.affichePanneau()
890           node.select()
891
892     def selectApres(self):
893         i=self.item.jdc.etapes.index(self.item.object)
894         try :
895            cherche=self.item.jdc.etapes[i+1]
896         except :
897            cherche=self.item.jdc.etapes[0]
898         node=None
899         for i in self.tree.racine.children :
900             if i.item.object== cherche  : 
901                node=i
902                break
903         if node : 
904            node.affichePanneau()
905            node.select()