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