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