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