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