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