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