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