Salome HOME
modif pour MT
[tools/eficas.git] / InterfaceQT4 / groupe.py
1 # Copyright (C) 2007-2017   EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Modules Python
20 # Modules Eficas
21
22 from __future__ import absolute_import
23 from __future__ import print_function
24 from PyQt5.QtWidgets import QWidget, QSpacerItem, QSizePolicy
25 from PyQt5.QtCore import Qt
26
27 from Extensions.i18n import tr
28
29 from .gereIcones import FacultatifOuOptionnel
30 import Accas 
31 import traceback
32
33     
34 # Import des panels
35
36 class Groupe(QWidget,FacultatifOuOptionnel):
37   """
38   """
39   def __init__(self,node,editor,parentQt,definition,obj,niveau,commande=None):
40       #print ("groupe : ",self.node.item.nom," ",self.node.fenetre)
41       QWidget.__init__(self,None)
42       self.node=node
43       self.node.fenetre=self
44       self.setupUi(self)
45       self.editor=editor
46       self.obj=obj
47       self.niveau=niveau
48       self.definition=definition
49       self.parentQt=parentQt
50       self.maCommande=commande
51       self.listeFocus=[]
52       self.appliEficas=self.editor.appliEficas
53       self.repIcon=self.appliEficas.repIcon
54       self.jdc=self.node.item.getJdc()
55       self.setIconePoubelle()
56       self.setIconesGenerales()
57       self.setRun()
58       self.setValide()
59       self.setReglesEtAide()
60       self.afficheMots()
61       self.listeMCAAjouter=[]
62       self.dictMCVenantDesBlocs={}
63       if hasattr(self,'RBDeplie')  : self.RBDeplie.clicked.connect(self.setDeplie)
64       if hasattr(self,'RBPlie')    : self.RBPlie.clicked.connect( self.setPlie)
65       self.setAcceptDrops(True)
66       if hasattr (self, 'commandesLayout'): 
67          spacerItem = QSpacerItem(20, 5, QSizePolicy.Minimum, QSizePolicy.Expanding)
68          self.commandesLayout.addItem(spacerItem)
69      
70   def donneFocus(self):
71       for fenetre in self.listeFocus:
72           if fenetre==None : return
73           if fenetre.node.item.isValid() == 0 :
74              fenetre.prendLeFocus=1
75              fenetre.hide()
76              fenetre.show()
77       
78
79   def afficheMots(self):
80       #print ("ds afficheMots ",self.node.item.nom,self.node.plie)
81       for node in self.node.children:
82            # non return mais  continue car il faut tenir compte des blocs
83            if node.appartientAUnNoeudPlie==True : continue
84            #print "je suis apres le if pour ",node.item.nom
85            widget=node.getPanelGroupe(self,self.maCommande)
86            #print ("widget pour ", node.item.nom, widget)
87            self.listeFocus.append(node.fenetre)
88       #print "fin pour " , self.node.item.nom
89
90        
91   def calculOptionnel(self):
92         self.listeMc=[]
93         self.listeMcRegle=[]
94         self.dictToolTipMc={}
95         genea =self.obj.getGenealogie()
96         # Attention : les mots clefs listes (+sieurs fact )
97         # n ont pas toutes ces methodes
98         try :
99         #if 1 :
100            self.listeMc     = self.obj.getListeMcOrdonnee(genea,self.jdc.cata_ordonne_dico)
101            listeNomsPresents=self.obj.dictMcPresents()
102            for regle in self.obj.getRegles():
103                (monToolTip,regleOk)=regle.verif(listeNomsPresents)
104                if regleOk : continue
105                for mc in regle.mcs :
106                    self.listeMcRegle.append(mc)
107                    self.dictToolTipMc[mc]=monToolTip
108         except :
109            #print ('in except')
110            #print (self)
111            return
112         
113   def afficheOptionnel(self):
114         liste,liste_rouge=self.ajouteMCOptionnelDesBlocs()
115         self.monOptionnel=self.editor.widgetOptionnel
116         self.monOptionnel.afficheOptionnel(liste,liste_rouge,self)
117         #self.monOptionnel.affiche(liste)
118            
119
120   def ajouteMCOptionnelDesBlocs(self):
121       self.dictMCVenantDesBlocs={}
122       i=0
123       self.calculOptionnel()
124       liste=self.listeMc
125       liste_rouge=self.listeMcRegle
126       for MC in self.listeMc : self.dictMCVenantDesBlocs[MC]=self
127       # ce cas est le cas machine tournant sr le plie
128       try :
129         while i < self.commandesLayout.count():
130           from .monWidgetBloc import MonWidgetBloc
131           widget=self.commandesLayout.itemAt(i).widget()
132           i=i+1
133           if not(isinstance(widget,MonWidgetBloc)) : continue
134           widget.calculOptionnel()
135           listeW,listeW_rouge=widget.ajouteMCOptionnelDesBlocs() 
136           for MC in widget.dictMCVenantDesBlocs:
137               if MC in self.dictMCVenantDesBlocs: print ("Pb Sur les MC" )
138               else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
139           liste=liste+listeW
140           liste_rouge=liste_rouge+listeW_rouge
141       except : 
142         pass
143       return (liste,liste_rouge)
144
145
146   def reaffiche(self,nodeAVoir=None):
147       #print "dans reaffiche de groupe.py", nodeAVoir
148       self.parentQt.reaffiche(nodeAVoir)
149
150   def recalculeListeMC(self,listeMC):
151       #print "pas si peu utile"
152       #on ajoute et on enleve
153       listeNode=[]
154       for name in listeMC :
155           nodeAEnlever=self.node.appendChild(name)
156           if nodeAEnlever.item.isMCList(): 
157              nodeAEnlever=nodeAEnlever.children[-1]
158           listeNode.append(nodeAEnlever)
159       self.afficheOptionnel()
160       self.monOptionnel.affiche(self.listeMc)
161       if len(listeNode) == 0 : return
162       if len(listeNode) == 1 : 
163          listeNode[0].delete()
164          self.editor.afficheInfos("")
165          return
166       for noeud in listeNode:
167           noeud.treeParent.item.suppItem(noeud.item)
168       noeud.treeParent.buildChildren()
169       self.editor.afficheInfos("")
170
171   def ajoutMC(self,texteListeNom):
172       listeNom=texteListeNom.split("+")[1:]
173       firstNode=None
174       for nom in listeNom:
175         if nom not in self.dictMCVenantDesBlocs:
176            #print "bizarre, bizarre"
177            self.editor.initModif()
178            nouveau=self.node.appendChild(nom)
179         else :
180            self.editor.initModif()
181            widget=self.dictMCVenantDesBlocs[nom]
182            nouveau=widget.node.appendChild(nom)
183         if firstNode==None : firstNode=nouveau 
184         if nouveau == None or nouveau == 0  : 
185            self.editor.afficheInfos(tr('insertion impossible a cet endroit pour '+nom),Qt.red)
186       try :
187        self.reaffiche(firstNode)
188        if firstNode!=None and firstNode !=0 and firstNode.item!=None : firstNode.select()
189       except :
190        pass
191
192
193   def setPlie(self):
194       self.node.setPlie()
195       self.reaffiche(self.node) 
196
197   def setDeplie(self):
198       #print ('je passe ds setDeplie de groupe')
199       self.node.setDeplie()
200       self.reaffiche(self.node) 
201     
202
203   def traiteClicSurLabel(self,texte):
204       if self.editor.code != "CARMELCND" : self.afficheOptionnel()
205