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