1 # Copyright (C) 2007-2021 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, QSpacerItem, QSizePolicy
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 #print ("groupe : ",self.node.item.nom," ",self.node.fenetre)
41 QWidget.__init__(self,None)
43 self.node.fenetre=self
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.getJdc()
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.setDeplie)
64 if hasattr(self,'RBPlie') : self.RBPlie.clicked.connect( self.setPlie)
66 self.setAcceptDrops(True)
67 #if hasattr (self, 'commandesLayout'):
68 # print (' j ajoute un spacer dans ', self.node.item.nom)
69 # spacerItem = QSpacerItem(20, 5, QSizePolicy.Minimum, QSizePolicy.Expanding)
70 # self.commandesLayout.addItem(spacerItem)
73 for fenetre in self.listeFocus:
74 if fenetre==None : return
75 if fenetre.node.item.isValid() == 0 :
76 fenetre.prendLeFocus=1
81 def afficheMots(self):
82 #print ("ds afficheMots ",self.node.item.nom,self.node.plie)
83 for node in self.node.children:
84 # non return mais continue car il faut tenir compte des blocs
85 if node.appartientAUnNoeudPlie==True : continue
86 widget=node.getPanelGroupe(self,self.maCommande)
87 #print ("widget pour ", node.item.nom, widget)
88 self.listeFocus.append(node.fenetre)
89 #print "fin pour " , self.node.item.nom
92 def calculOptionnel(self):
96 genea =self.obj.getGenealogie()
97 # Attention : les mots clefs listes (+sieurs fact )
98 # n ont pas toutes ces methodes
101 self.listeMc = self.obj.getListeMcOrdonnee(genea,self.jdc.cata_ordonne_dico)
102 listeNomsPresents=self.obj.dictMcPresents()
103 for regle in self.obj.getRegles():
104 (monToolTip,regleOk)=regle.verif(listeNomsPresents)
105 if regleOk : continue
106 for mc in regle.mcs :
107 self.listeMcRegle.append(mc)
108 self.dictToolTipMc[mc]=monToolTip
114 def afficheOptionnel(self):
115 if self.editor.maConfiguration.closeOptionnel : return
116 liste,liste_rouge=self.ajouteMCOptionnelDesBlocs()
117 self.monOptionnel=self.editor.widgetOptionnel
118 self.monOptionnel.afficheOptionnel(liste,liste_rouge,self)
121 def ajouteMCOptionnelDesBlocs(self):
122 self.dictMCVenantDesBlocs={}
124 self.calculOptionnel()
126 liste_rouge=self.listeMcRegle
127 for MC in self.listeMc : self.dictMCVenantDesBlocs[MC]=self
128 # ce cas est le cas machine tournant sr le plie
130 while i < self.commandesLayout.count():
131 from .monWidgetBloc import MonWidgetBloc
132 widget=self.commandesLayout.itemAt(i).widget()
134 if not(isinstance(widget,MonWidgetBloc)) : continue
135 widget.calculOptionnel()
136 listeW,listeW_rouge=widget.ajouteMCOptionnelDesBlocs()
137 for MC in widget.dictMCVenantDesBlocs:
138 if MC in self.dictMCVenantDesBlocs: print ("Pb Sur les MC" )
139 else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
141 liste_rouge=liste_rouge+listeW_rouge
144 return (liste,liste_rouge)
147 def reaffiche(self,nodeAVoir=None):
148 #print "dans reaffiche de groupe.py", nodeAVoir
149 self.parentQt.reaffiche(nodeAVoir)
151 def recalculeListeMC(self,listeMC):
152 #print "pas si peu utile"
153 #on ajoute et on enleve
155 for name in listeMC :
156 nodeAEnlever=self.node.appendChild(name)
157 if nodeAEnlever.item.isMCList():
158 nodeAEnlever=nodeAEnlever.children[-1]
159 listeNode.append(nodeAEnlever)
160 self.afficheOptionnel()
161 self.monOptionnel.affiche(self.listeMc)
162 if len(listeNode) == 0 : return
163 if len(listeNode) == 1 :
164 listeNode[0].delete()
165 self.editor.afficheInfos("")
167 for noeud in listeNode:
168 noeud.treeParent.item.suppItem(noeud.item)
169 noeud.treeParent.buildChildren()
170 self.editor.afficheInfos("")
172 def ajoutMC(self,texteListeNom):
173 listeNom=texteListeNom.split("+")[1:]
176 if nom not in self.dictMCVenantDesBlocs:
177 #print "bizarre, bizarre"
178 self.editor.initModif()
179 nouveau=self.node.appendChild(nom)
181 self.editor.initModif()
182 widget=self.dictMCVenantDesBlocs[nom]
183 nouveau=widget.node.appendChild(nom)
184 if firstNode==None : firstNode=nouveau
185 if nouveau == None or nouveau == 0 :
186 self.editor.afficheInfos(tr('insertion impossible a cet endroit pour '+nom),Qt.red)
188 self.reaffiche(firstNode)
189 if firstNode!=None and firstNode !=0 and firstNode.item!=None : firstNode.select()
196 self.reaffiche(self.node)
199 #print ('je passe ds setDeplie de groupe', self.obj.nom)
200 self.node.firstDeplie = False
201 self.node.setDeplie()
202 self.reaffiche(self.node)
205 def traiteClicSurLabel(self,texte):
206 if self.editor.code != "CARMELCND" : self.afficheOptionnel()
209 def propageChange(self,leType):
210 self.parentQt.propageChange(leType)