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