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