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