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