1 # Copyright (C) 2007-2017 EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from __future__ import absolute_import
23 from __future__ import print_function
24 from PyQt5.QtWidgets import QWidget
25 from PyQt5.QtCore import Qt
27 from Extensions.i18n import tr
29 from .gereIcones import FacultatifOuOptionnel
36 class Groupe(QWidget,FacultatifOuOptionnel):
39 def __init__(self,node,editor,parentQt,definition,obj,niveau,commande=None):
40 QWidget.__init__(self,None)
42 self.node.fenetre=self
43 #print "groupe : ",self.node.item.nom," ",self.node.fenetre
48 self.definition=definition
49 self.parentQt=parentQt
50 self.maCommande=commande
52 self.appliEficas=self.editor.appliEficas
53 self.repIcon=self.appliEficas.repIcon
54 self.jdc=self.node.item.get_jdc()
55 self.setIconePoubelle()
56 self.setIconesGenerales()
59 self.setReglesEtAide()
61 self.listeMCAAjouter=[]
62 self.dictMCVenantDesBlocs={}
63 if hasattr(self,'RBDeplie') : self.RBDeplie.clicked.connect(self.Deplie)
64 if hasattr(self,'RBPlie') : self.RBPlie.clicked.connect( self.Plie)
65 self.setAcceptDrops(True)
68 for fenetre in self.listeFocus:
69 if fenetre==None : return
70 if fenetre.node.item.isvalid() == 0 :
71 fenetre.prendLeFocus=1
76 def afficheMots(self):
77 #print "ds afficheMots ",self.node.item.nom
78 for node in self.node.children:
79 #if node.item.nom == "Background" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
80 #if node.item.nom == "BackgroundError" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
81 # non return mais continue car il faut tenir compte des blocs
82 if node.appartientAUnNoeudPlie==True : continue
83 #print "je suis apres le if pour ",node.item.nom
84 widget=node.getPanelGroupe(self,self.maCommande)
85 #print "widget pour ", node.item.nom, widget
86 self.listeFocus.append(node.fenetre)
87 #print "fin pour " , self.node.item.nom
90 def calculOptionnel(self):
92 genea =self.obj.get_genealogie()
93 # Attention : les mots clefs listes (+sieurs fact )
94 # n ont pas toutes ces methodes
96 self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
100 def afficheOptionnel(self):
101 liste=self.ajouteMCOptionnelDesBlocs()
102 self.monOptionnel=self.editor.widgetOptionnel
103 self.monOptionnel.afficheOptionnel(liste,self)
104 #self.monOptionnel.affiche(liste)
107 def ajouteMCOptionnelDesBlocs(self):
108 self.dictMCVenantDesBlocs={}
110 self.calculOptionnel()
112 for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
113 # ce cas est le cas machine tournant sr le plie
115 while i < self.commandesLayout.count():
116 from .monWidgetBloc import MonWidgetBloc
117 widget=self.commandesLayout.itemAt(i).widget()
119 if not(isinstance(widget,MonWidgetBloc)) : continue
120 widget.calculOptionnel()
121 listeW=widget.ajouteMCOptionnelDesBlocs()
122 for MC in widget.dictMCVenantDesBlocs:
123 if MC in self.dictMCVenantDesBlocs: print ("Pb Sur les MC" )
124 else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
131 def reaffiche(self,nodeAVoir=None):
132 #print "dans reaffiche de groupe.py", nodeAVoir
133 self.parentQt.reaffiche(nodeAVoir)
135 def recalculeListeMC(self,listeMC):
136 #print "pas si peu utile"
137 #on ajoute et on enleve
139 for name in listeMC :
140 nodeAEnlever=self.node.append_child(name)
141 if nodeAEnlever.item.isMCList():
142 nodeAEnlever=nodeAEnlever.children[-1]
143 listeNode.append(nodeAEnlever)
144 self.afficheOptionnel()
145 self.monOptionnel.affiche(self.liste_mc)
146 if len(listeNode) == 0 : return
147 if len(listeNode) == 1 :
148 listeNode[0].delete()
149 self.editor.affiche_infos("")
151 for noeud in listeNode:
152 noeud.treeParent.item.suppitem(noeud.item)
153 noeud.treeParent.build_children()
154 self.editor.affiche_infos("")
156 def ajoutMC(self,texteListeNom):
157 listeNom=texteListeNom.split("+")[1:]
160 if nom not in self.dictMCVenantDesBlocs:
161 #print "bizarre, bizarre"
162 self.editor.init_modif()
163 nouveau=self.node.append_child(nom)
165 self.editor.init_modif()
166 widget=self.dictMCVenantDesBlocs[nom]
167 nouveau=widget.node.append_child(nom)
168 if firstNode==None : firstNode=nouveau
169 if nouveau == None or nouveau == 0 :
170 self.editor.affiche_infos(tr('insertion impossible a cet endroit pour '+nom),Qt.red)
171 self.reaffiche(firstNode)
172 if firstNode!=None and firstNode !=0 and firstNode.item!=None :
178 if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") :
179 #if (len(self.node.item.get_genealogie())==2):
180 index=self.maCommande.commandesLayout.indexOf(self)
181 self.maCommande.reafficheSeulement(self,index)
184 # self.reaffiche(self.node)
186 #print ('je reaffiche dans Plie')
187 self.reaffiche(self.node)
190 self.node.setDeplie()
191 if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") :
192 #if (len(self.node.item.get_genealogie())==2):
193 index=self.parentQt.commandesLayout.indexOf(self)
194 self.maCommande.reafficheSeulement(self,index)
197 # self.reaffiche(self.node)
199 #print ('je reaffiche dans Plie')
200 self.reaffiche(self.node)
204 #print ('Deplie', self)
205 #print (self.obj.nom)
206 #print (self.node.setPlie)
207 #print (self.parentQt)
209 # self.node.setPlie()
210 #if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") :
211 # itemAtraiter = self.node.item
212 # nodeAtraiter=self.node
213 #while (len(itemAtraiter.get_genealogie()) > 2 ):
214 # itemAtraiter=itemAtraiter.parent
215 # nodeAtraiter=nodeAtraiter.vraiParent
216 #ancien=nodeAtraiter.fenetre
217 #panneau = nodeAtraiter.getPanelGroupe(self,self.maCommande,insertIn=False)
218 #print (itemAtraiter,nodeAtraiter)
219 #self.parentQt.commandesLayout.replaceWidget(ancien,panneau,Qt.FindDirectChildrenOnly)
220 #nodeAtraiter.vraiParent.fenetre.commandesLayout.replaceWidget(ancien,panneau,Qt.FindDirectChildrenOnly)
222 # if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") :
223 # if (len(self.node.item.get_genealogie())==2):
225 #print (self.obj.nom)
226 #print (self.node.item.getlabeltext())
227 #print (self.parentQt)
228 #print (self.editor.fenetreCentraleAffichee)
229 #print (self.maCommande)
230 # index=self.parentQt.commandesLayout.indexOf(self)
232 # self.maCommande.reafficheSeulement(self,index)
234 #for c in self.children():
243 #panneau = self.node.getPanelGroupe(self.parentQt,self.maCommande,insertIn=False)
244 # print (self.parentQt)
246 #self.parentQt.commandesLayout.replaceWidget(self,panneau,Qt.FindDirectChildrenOnly)
247 # self.parentQt.setUpdatesEnabled(True)
248 # print (dir(self.parentQt.commandesLayout))
249 #self.parentQt.commandesLayout.updateGeometry()
251 # self.reaffiche(self.node)
253 #print ('je reaffiche dans Plie')
254 # self.reaffiche(self.node)
257 # print ('Deplie', self)
258 # print (self.obj.nom)
259 # print (self.node.item.GetLabelText())
260 # self.node.setDeplie()
261 # #if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") and (len(self.node.item.get_genealogie())==2):
262 # #print (self.node.vraiParent.children)
263 # #if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") :
264 # # itemAtraiter = self.node.item
265 # # nodeAtraiter=self.node
266 # # while (len(itemAtraiter.get_genealogie()) > 2 ):
267 # # itemAtraiter=itemAtraiter.parent
268 # # nodeAtraiter=nodeAtraiter.vraiParent
269 # # ancien=nodeAtraiter.fenetre
270 # # panneau = nodeAtraiter.getPanelGroupe(self,self.maCommande,insertIn=False)
271 # #print (itemAtraiter,nodeAtraiter)
272 # #self.parentQt.commandesLayout.replaceWidget(ancien,panneau,Qt.FindDirectChildrenOnly)
273 # # nodeAtraiter.vraiParent.fenetre.commandesLayout.replaceWidget(ancien,panneau,Qt.FindDirectChildrenOnly)
275 # if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") :
276 # if (len(self.node.item.get_genealogie())==2):
277 # #panneau = self.node.getPanelGroupe(self.parentQt,self.maCommande,insertIn=False)
278 # #self.parentQt.commandesLayout.replaceWidget(self,panneau,Qt.FindDirectChildrenOnly)
279 # #index=self.parentQt.commandesLayout.indexOf(self)
280 # #index=self.maCommande.commandesLayout.indexOf(self)
281 # #print ('index = ', index)
283 # self.maCommande.reafficheSeulement(self,index)
285 # self.reaffiche(self.node)
288 # #print ('je reaffiche')
289 # self.reaffiche(self.node)
291 def traiteClicSurLabel(self,texte):
292 if self.editor.code != "CARMELCND" : self.afficheOptionnel()