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