Salome HOME
QString et ses amis
[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
250
251         if (isinstance(self,compobloc.Node) or (isinstance(self,compomclist.Node) and self.item.isMCList()) or ( hasattr(self.item.parent,'inhibeValidator') and isinstance(self,compomclist.Node) and self.item.parent.inhibeValidator)) : 
252         # Le dernier or ne sert que lorsqu'on est en train de creer une liste par les validator
253            QTreeWidgetItem.__init__(self,None,mesColonnes)
254         else :
255            QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
256
257         if monEnvQT5 :
258            self.setToolTip(0,self.item.get_fr())
259            self.setToolTip(1,self.item.get_fr())
260            repIcon=self.appliEficas.repIcon
261         else :
262            self.setToolTip(0,QString(self.item.get_fr()))
263            self.setToolTip(1,QString(self.item.get_fr()))
264            repIcon=QString(self.appliEficas.repIcon)
265
266         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
267         self.setIcon(0,monIcone)
268
269         self.children = []
270         self.build_children()
271         self.menu=None
272         self.existeMenu=1
273
274         self.item.connect("valid",self.onValid,())
275         self.item.connect("supp" ,self.onSupp,())
276         self.item.connect("add"  ,self.onAdd,())
277
278         self.state=""
279         self.fenetre=None
280         try :
281           if self.item.getObject().isBLOC() : 
282                 self.setExpanded(True) 
283                 self.plie=False
284         except :
285           pass
286
287
288     def build_children(self,posInsertion=10000):
289         """ Construit la liste des enfants de self """
290         """ Se charge de remettre les noeuds Expanded dans le meme etat """
291         #print "*********** build_children ",self,self.item, self.item.nom
292         
293         self.listeItemExpanded=[]
294         self.listeItemPlie=[]
295
296         for enfant in self.childrenComplete :
297             if enfant.plie : self.listeItemPlie.append(enfant.item)
298             else : self.listeItemExpanded.append(enfant.item)
299
300         for enfant in self.childrenComplete :
301             parent=enfant.treeParent
302             parent.removeChild(enfant)
303             enfant.JESUISOFF=1
304          
305         
306         self.children = []
307         self.childrenComplete = []
308         sublist = self.item._GetSubList()
309         ind=0
310         
311         for item in sublist :
312             itemExpand=False
313             ancien=False
314             if item in self.listeItemExpanded : itemExpand=True;  ancien=True
315             if item in self.listeItemPlie     : itemExpand=False; ancien=True
316             nouvelItem=item.itemNode(self,item,itemExpand,ancien)
317             self.children.append(nouvelItem)
318
319         #print "fin *********** build_children ",self,self.item, self.item.nom
320
321         
322     def chercheNoeudCorrespondant(self,objSimp):
323         sublist = self.item._GetSubList()
324         for node in self.childrenComplete:
325             if node.item.object==objSimp : return node
326         return None
327
328
329     def affichePanneau(self) :
330         #if self.item.isactif(): 
331         #if self.editor.code == 'ASTER' and not(self.item.isactif()) : 
332         # posera des pb si un code decide d appeler FIN un mot clef
333         # on resoudera a ce moment la
334         # pour l instant pas de poussiere sous le tapis
335         if  not(self.item.isactif()) : 
336             from monWidgetInactif import MonWidgetInactif
337             self.fenetre = MonWidgetInactif(self,self.editor)
338         else:
339            itemParent=self
340            while not (hasattr (itemParent,'getPanel')) : itemParent=itemParent.treeParent 
341            if itemParent!=self : 
342               itemParent.affichePanneau()
343               return
344            self.fenetre=self.getPanel()
345          
346         #print "hhhhhhhhhh", self.editor.splitter.sizes()
347         for indiceWidget in range(self.editor.widgetCentraleLayout.count()):
348             widget=self.editor.widgetCentraleLayout.itemAt(indiceWidget)
349             self.editor.widgetCentraleLayout.removeItem(widget)
350         # ceinture et bretelle
351         #print 'old fenetre = ',self.editor.fenetreCentraleAffichee
352         #print "iiiiiiiiiiiiiii", self.editor.splitter.sizes()
353         if self.editor.fenetreCentraleAffichee != None : 
354             #print "j enleve ", self.editor.fenetreCentraleAffichee, self.editor.fenetreCentraleAffichee.node.item.nom
355             self.editor.widgetCentraleLayout.removeWidget(self.editor.fenetreCentraleAffichee)
356             self.editor.fenetreCentraleAffichee.setParent(None)
357             self.editor.fenetreCentraleAffichee.close()
358             self.editor.fenetreCentraleAffichee.deleteLater()
359
360         self.editor.widgetCentraleLayout.addWidget(self.fenetre)
361         #print "j ajoute ", self.fenetre, self.fenetre.node.item.nom
362         self.editor.fenetreCentraleAffichee=self.fenetre
363         self.tree.node_selected= self
364
365         if self.editor.first :
366            #self.editor.splitter.setSizes((400,1400,400))
367            if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
368         self.tree.inhibeExpand=True
369         self.tree.expandItem(self)
370         #self.select()
371         self.tree.inhibeExpand=False
372         #print "fin de affichePanneau", self.item.nom
373         #print "______________________________"
374           
375
376     def createPopUpMenu(self):
377         #implemente dans les noeuds derives si necessaire
378         self.existeMenu = 0
379
380     def commentIt(self):
381         """
382         Cette methode a pour but de commentariser la commande pointee par self
383         """
384         # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
385         # (commentariser) un commentaire.
386         try :
387             pos=self.treeParent.children.index(self)
388             commande_comment = self.item.get_objet_commentarise()
389             # On signale a l editeur du panel (le JDCDisplay) une modification
390             self.editor.init_modif()
391             self.treeParent.build_children()
392             self.treeParent.children[pos].select()
393             self.treeParent.children[pos].affichePanneau()
394         except Exception,e:
395             traceback.print_exc()
396             QMessageBox.critical( self.editor, "TOO BAD",str(e))
397         
398     def unCommentIt(self):
399         """
400         Realise la decommentarisation de self
401         """
402         try :
403             pos=self.treeParent.children.index(self)
404             commande,nom = self.item.uncomment()
405             self.editor.init_modif()
406             self.treeParent.build_children()
407             self.treeParent.children[pos].select()
408             self.treeParent.children[pos].affichePanneau()
409         except Exception,e:
410             QMessageBox.critical( self.editor, "Erreur !",str(e))
411         
412     def addComment( self, after=True ):
413         """
414         Ajoute un commentaire a l'interieur du JDC :
415         """
416         self.editor.init_modif()
417         if after:
418             pos = 'after'
419         else:
420             pos = 'before'
421         return self.append_brother( COMMENT, pos )
422                 
423     def addParameters( self, after=True ):
424         """
425         Ajoute un parametre a l'interieur du JDC :
426         """
427         self.editor.init_modif()
428         if after: pos = 'after'
429         else: pos = 'before'
430         child=self.append_brother( PARAMETERS, pos )
431         return  child
432     
433     
434     def select( self ):
435         """
436         Rend le noeud courant (self) selectionne et deselectionne
437         tous les autres
438         """        
439         #print "select pour", self.item.nom
440         for item in self.tree.selectedItems() :
441             item.setSelected(0)
442         self.tree.setCurrentItem( self )    
443                                
444     #------------------------------------------------------------------
445     # Methodes de creation et destruction de noeuds
446     # Certaines de ces methodes peuvent etre appelees depuis l'externe
447     #------------------------------------------------------------------
448     def append_brother(self,name,pos='after',plier=False):
449         """
450         Permet d'ajouter un objet frere a l'objet associe au noeud self
451         par defaut on l'ajoute immediatement apres 
452         Methode externe
453         """
454         self.editor.init_modif()
455
456         from InterfaceQT4 import compojdc
457         if (isinstance(self.treeParent, compojdc.Node)) and not self.verifiePosition(name,pos)  : return 0
458         
459         index = self.treeParent.children.index(self)
460         if   pos == 'before': index = index
461         elif pos == 'after': index = index +1
462         else:
463             print unicode(pos), tr("  n'est pas un index valide pour append_brother")
464             return 0
465         return self.treeParent.append_child(name,pos=index,plier=plier)
466
467     def verifiePosition(self,name,pos,aLaRacine=False):
468         if name not in self.editor.Classement_Commandes_Ds_Arbre : return True
469         indexName=self.editor.Classement_Commandes_Ds_Arbre.index(name)
470
471         etapes=self.item.get_jdc().etapes
472         if etapes == [] : return True
473
474         if aLaRacine == False :indexOu=etapes.index(self.item.object)
475         else : indexOu=0
476
477         if pos=="after" : indexOu = indexOu+1
478         for e in etapes[:indexOu] :
479             nom=e.nom
480             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
481             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
482             if indexEtape > indexName :
483                comment=tr('le mot clef ')+name+tr(' doit etre insere avant ')+nom
484                QMessageBox.information( None,tr('insertion impossible'),comment, )
485                return False
486         for e in etapes[indexOu:] :
487             nom=e.nom
488             if nom not in self.editor.Classement_Commandes_Ds_Arbre : continue
489             indexEtape=self.editor.Classement_Commandes_Ds_Arbre.index(nom)
490             if indexEtape < indexName :
491                comment=tr('le mot clef ')+name+tr(' doit etre insere apres ')+nom
492                QMessageBox.information( None,tr('insertion impossible'),comment, )
493                return False
494         return True
495
496     def append_child(self,name,pos=None,plier=False):
497         """
498            Methode pour ajouter un objet fils a l'objet associe au noeud self.
499            On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
500            ou en position intermediaire.
501            Si pos vaut None, on le place a la position du catalogue.
502         """
503         #print "************** append_child ",self.item.GetLabelText(), plier
504
505          
506         self.editor.init_modif()
507         if pos == 'first':
508             index = 0
509         elif pos == 'last':
510             index = len(self.children)
511         elif type(pos) == types.IntType :
512             # position fixee
513             index = pos
514         elif type(pos) == types.InstanceType:
515             # pos est un item. Il faut inserer name apres pos
516             index = self.item.get_index(pos) +1
517         elif type(name) == types.InstanceType:
518             index = self.item.get_index_child(name.nom)
519         else:
520             index = self.item.get_index_child(name)
521
522         # si on essaye d inserer a la racine
523         if (isinstance(self.treeParent,JDCTree) and index==0) :
524            verifiePosition=self.verifiePosition(name,'first',aLaRacine=True)
525            if not verifiePosition : return 0
526
527         self.tree.inhibeExpand=True
528         obj=self.item.additem(name,index) # emet le signal 'add'
529         if obj is None:obj=0
530         if obj == 0:return 0
531         try :
532            child=self.children[index]
533            if plier == True : child.setPlie()
534            else             : child.setDeplie() 
535         except :
536            child=self.children[index]
537         self.tree.inhibeExpand=False
538         #print " fin append child"
539         return child
540
541     def deplace(self):
542         self.editor.init_modif()
543         index = self.treeParent.children.index(self) - 1 
544         if index < 0 : index =0
545         ret=self.treeParent.item.deplaceEntite(self.item.getObject())
546
547     def delete(self):
548         """ 
549             Methode externe pour la destruction de l'objet associe au noeud
550         """
551         self.editor.init_modif()
552         index = self.vraiParent.children.index(self) - 1 
553         if index < 0 : index =0
554         recalcule=0
555         if self.item.nom == "VARIABLE" :
556            recalcule=1
557            jdc=self.item.jdc
558         ret,commentaire=self.vraiParent.item.suppitem(self.item)
559         if ret==0 :
560           self.editor.affiche_infos(commentaire,Qt.red)
561         else :
562           self.editor.affiche_infos(commentaire)
563         self.treeParent.build_children()
564         if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
565         else: toselect=self.treeParent
566         if recalcule : jdc.recalcule_etat_correlation()
567         if ret==0 :
568             if self.treeParent.childrenComplete :
569                 notdeleted=self.treeParent.childrenComplete[index+1]
570                 notdeleted.select()
571         else :
572             toselect.select()
573         from InterfaceQT4 import compojdc
574         # cas ou on detruit dans l arbre sans affichage
575         if isinstance(self.treeParent,compojdc.Node) : 
576            toselect.affichePanneau()
577         else :
578            if self.treeParent.fenetre== None : return
579            #print "J appelle reaffiche de browser apres delete"
580            self.treeParent.fenetre.reaffiche(toselect)
581
582     def deleteMultiple(self,liste=()):
583         """ 
584             Methode externe pour la destruction d une liste de noeud
585         """
586         from InterfaceQT4 import compojdc 
587         self.editor.init_modif()
588         index=9999
589         recalcule=0
590         jdc=self.treeParent
591         parentPosition=jdc
592         while not(isinstance(jdc,compojdc.Node)):
593               jdc=jdc.treeParent
594         for noeud in liste :
595             if not( isinstance(noeud.treeParent, compojdc.Node)): continue
596             if noeud.item.nom == "VARIABLE" : recalcule=1
597             if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
598         if index < 0 : index =0
599
600         # Cas ou on détruit dans une ETape
601         if index == 9999 : 
602               parentPosition=self.treeParent
603               while not(isinstance(parentPosition, compojdc.Node)):
604                  index=parentPosition.treeParent.children.index(parentPosition)
605                  parentPosition=parentPosition.treeParent
606
607         for noeud in liste:
608             noeud.treeParent.item.suppitem(noeud.item)
609
610         jdc.build_children()
611         if recalcule : jdc.recalcule_etat_correlation()
612         try    : toselect=parentPosition.children[index]
613         except : toselect=jdc
614         toselect.select()
615         toselect.affichePanneau()
616 #        
617 #    #------------------------------------------------------------------
618     def onValid(self):        
619
620         #print "onValid pour ", self.item.nom
621         if self.JESUISOFF==1 : return
622         if hasattr(self,'fenetre') and self.fenetre: 
623            try :
624              self.fenetre.setValide()
625            except :
626              print "onValid pour ", self.item.nom, self,'pb'
627
628         if (self.item.nom == "VARIABLE" or self.item.nom == "DISTRIBUTION") and self.item.isvalid():
629            self.item.jdc.recalcule_etat_correlation()
630         if hasattr(self.item,'forceRecalcul'):
631            self.forceRecalculChildren(self.item.forceRecalcul)
632         self.editor.init_modif()
633         
634         self.update_node_valid()
635         self.update_node_label()
636         self.update_node_texte()
637
638     def onAdd(self,object):
639         if self.JESUISOFF==1 : return
640         #print "onAdd pour ", self.item.nom, object.nom
641         self.editor.init_modif()
642         self.update_nodes()
643         # PN -- non necessaire si item=jdc
644         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
645  
646     def onSupp(self,object):
647         if self.JESUISOFF==1 : return
648         #print "onSup pour ", self.item.nom, object.nom
649         self.editor.init_modif()
650         self.update_nodes()
651         # PN -- non necessaire si item=jdc
652         if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
653          
654
655
656     def update_node_valid(self):
657         """Cette methode remet a jour la validite du noeud (icone)
658            Elle appelle isvalid
659         """
660         if monEnvQT5 : repIcon=self.appliEficas.repIcon
661         else : repIcon=QString(self.appliEficas.repIcon)
662         monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
663         self.setIcon(0,monIcone)
664
665
666     def update_node_label(self):
667         """ Met a jour le label du noeud """
668         #print "NODE update_node_label", self.item.GetLabelText()
669         labeltext,fonte,couleur = self.item.GetLabelText()
670         # PNPN a reflechir
671         #self.setText(0, labeltext)        
672     
673     
674     def update_node_label_in_blue(self):
675         if hasattr(self.appliEficas,'noeudColore'):
676            self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
677            self.appliEficas.noeudColore.update_node_label()
678         self.setTextColor( 0,Qt.blue )
679         labeltext,fonte,couleur = self.item.GetLabelText()
680         self.setText(0, labeltext)        
681         self.appliEficas.noeudColore=self
682
683     def update_plusieurs_node_label_in_blue(self,liste):
684         if hasattr(self.appliEficas,'listeNoeudsColores'):
685            for noeud in self.appliEficas.listeNoeudsColores:
686                noeud.setTextColor( 0,Qt.black)
687                noeud.update_node_label()
688         self.appliEficas.listeNoeudsColores=[]
689         for noeud in liste :
690             noeud.setTextColor( 0,Qt.blue )
691             labeltext,fonte,couleur = noeud.item.GetLabelText()
692             noeud.setText(0, labeltext)        
693             self.appliEficas.listeNoeudsColores.append(noeud)
694
695     def update_node_texte_in_black(self):
696         """ Met a jour les noms des SD et valeurs des mots-cles """
697         self.setTextColor( 1,Qt.black )
698         value = self.item.GetText()
699         self.setText(1, value)
700
701     def update_node_texte(self):
702         """ Met a jour les noms des SD et valeurs des mots-cles """
703         value = self.item.GetText()
704         self.setText(1, value)
705         
706
707     def update_node_texte_in_blue(self):
708         self.setTextColor( 1,Qt.blue )
709         value = self.item.GetText()
710         self.setText(1, value)
711
712     def update_nodes(self):
713         #print 'NODE update_nodes', self.item.GetLabelText()
714         self.build_children()
715
716     def update_valid(self) :
717         """Cette methode a pour but de mettre a jour la validite du noeud
718            et de propager la demande de mise a jour a son parent
719         """
720         #print "NODE update_valid", self.item.GetLabelText()
721         self.update_node_valid()
722         try :
723           self.treeParent.update_valid()
724         except:
725           pass
726             
727     def update_texte(self):
728         """ Met a jour les noms des SD et valeurs des mots-cles """
729         #print "NODE update_texte", self.item.GetLabelText()
730         self.update_node_texte()
731         if self.isExpanded() :
732             for child in self.children:
733                 if child.isHidden() == false : child.update_texte()
734
735
736     def forceRecalculChildren(self,niveau):
737         if self.state=='recalcule' : 
738            self.state=""
739            return
740         self.state='recalcule'
741         if hasattr(self.item,'object'):
742            self.item.object.state="modified"
743         for child in self.children:
744            if niveau > 0 : child.forceRecalculChildren(niveau - 1)
745               
746         
747
748     def doPaste(self,node_selected,pos='after'):
749         """
750             Déclenche la copie de l'objet item avec pour cible
751             l'objet passé en argument : node_selected
752         """
753         #print 'je passe dans doPaste'
754         objet_a_copier = self.item.get_copie_objet()
755         child=node_selected.doPasteCommande(objet_a_copier,pos)
756         return child
757
758     def doPasteCommande(self,objet_a_copier,pos='after'):
759         """
760           Réalise la copie de l'objet passé en argument qui est nécessairement
761           une commande
762         """
763         child=None
764         try :
765           child = self.append_brother(objet_a_copier,pos)
766         except :
767            pass
768         return child
769
770     def doPastePremier(self,objet_a_copier):
771         """
772            Réalise la copie de l'objet passé en argument (objet_a_copier)
773         """
774         objet = objet_a_copier.item.get_copie_objet()
775         child = self.append_child(objet,pos='first')
776         return child
777
778     def plieToutEtReafficheSaufItem(self, itemADeplier):
779         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
780         from InterfaceQT4 import compojdc
781         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
782         self.editor.deplier = False
783         for item in self.children :
784             # il ne faut pas plier les blocs 
785             from InterfaceQT4 import compobloc
786             if (isinstance(item,compobloc.Node)) : continue
787             item.setPlie()
788             if item==itemADeplier : 
789                   itemADeplier.setDeplie()
790         self.affichePanneau()
791
792     def plieToutEtReaffiche(self):
793         #print "je suis dans plieToutEtReaffiche", self.item.get_nom()
794         from InterfaceQT4 import compojdc
795         if (isinstance(self, compojdc.Node)) : self.affichePanneau(); return 
796         self.editor.deplier = False
797         for item in self.children :
798             # il ne faut pas plier les blocs 
799             from InterfaceQT4 import compobloc
800             if (isinstance(item,compobloc.Node)) : continue
801             item.setPlie()
802         self.affichePanneau()
803
804     def deplieToutEtReaffiche(self):
805         self.editor.deplier = True
806         for item in self.children :
807             item.setDeplie()
808         self.affichePanneau()
809
810     def setPlie(self):
811         #print "je mets inhibeExpand a true dans setPlie"
812         #print "je suis dans plieTout", self.item.get_nom()
813         import compojdc
814         if self.fenetre == self.editor.fenetreCentraleAffichee  and isinstance(self.treeParent,compojdc.Node): 
815            return
816         self.tree.inhibeExpand=True
817         self.tree.collapseItem(self)
818         self.setPlieChildren()
819         self.tree.inhibeExpand=False
820         #print "je mets inhibeExpand a false dans setPlie"
821
822
823         # on ne plie pas au niveau 1
824         #   self.plie=False
825         #   for item in self.children :
826         #       item.appartientAUnNoeudPlie=False
827
828     def setPlieChildren(self):
829         #print "dans setPlieChildren pour", self.item.nom
830         self.plie=True
831         for c in self.children :
832             c.setPlieChildren()
833             #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0]
834             c.appartientAUnNoeudPlie=True
835             c.plie=True
836             #print "dans setPlieChildren plie", c.item.nom
837             c.setExpanded(False)
838
839         # Pour les blocs et les motcles list
840         # on affiche un niveau de plus
841         from InterfaceQT4 import compobloc
842         from InterfaceQT4 import compomclist
843         if (isinstance(self,compobloc.Node) or ( isinstance(self,compomclist.Node) and self.item.isMCList())) : 
844             niveauPere=self.treeParent
845             while (isinstance(niveauPere,compobloc.Node) or (isinstance(niveauPere,compomclist.Node) and niveauPere.item.isMCList())) : 
846                niveauPere=niveauPere.treeParent
847             for c in self.children :
848                 c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
849                 #print "dans setPlieChildren appartientAUnNoeudPlie=True ", c, c.item.GetLabelText()[0], "mis a la valeur ", niveauPere.appartientAUnNoeudPlie
850                 c.setExpanded(False)
851
852         # on affiche un niveau de plus
853         #if isinstance(self,compomclist.Node)  : 
854         #if isinstance(self,compobloc.Node)  : 
855         #    niveauPere=self.treeParent
856         #    while (isinstance(niveauPere,compobloc.Node)):
857         #       niveauPere=niveauPere.treeParent
858         #    for c in self.children :
859         #        c.appartientAUnNoeudPlie=niveauPere.appartientAUnNoeudPlie
860
861     def setDeplie(self):
862         #print "dans setPlieChildren pour", self.item.nom
863         #print "je mets inhibeExpand a true dans setDeplie"
864         self.tree.inhibeExpand=True
865         self.plie=False
866         self.tree.expandItem(self)
867         self.setDeplieChildren()
868         self.tree.inhibeExpand=False
869         #print "je mets inhibeExpand a false dans setDePlie"
870
871     def setDeplieChildren(self):
872         #print "dans setDeplieChildren appartientAUnNoeudPlie=False ", self.item.GetLabelText()
873         for c in self.children :
874             c.setDeplieChildren()
875             #print "dans setDeplieChildren ", c.item.nom
876             c.appartientAUnNoeudPlie=False
877             c.setExpanded(True)
878             c.plie=False
879        
880     def selectAvant(self):
881         i=self.item.jdc.etapes.index(self.item.object)
882         try :
883            cherche=self.item.jdc.etapes[i-1]
884         except :
885            cherche=self.item.jdc.etapes[-1]
886         node=None
887         for i in self.tree.racine.children :
888             if i.item.object== cherche  : 
889                node=i
890                break
891         if node : 
892           node.affichePanneau()
893           node.select()
894
895     def selectApres(self):
896         i=self.item.jdc.etapes.index(self.item.object)
897         try :
898            cherche=self.item.jdc.etapes[i+1]
899         except :
900            cherche=self.item.jdc.etapes[0]
901         node=None
902         for i in self.tree.racine.children :
903             if i.item.object== cherche  : 
904                node=i
905                break
906         if node : 
907            node.affichePanneau()
908            node.select()