Salome HOME
Update version
[tools/eficas.git] / InterfaceQT4 / groupe.py
1 # Copyright (C) 2007-2021   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
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)
71
72     def donneFocus(self):
73         for fenetre in self.listeFocus:
74             if fenetre==None : return
75             if fenetre.node.item.isValid() == 0 :
76                 fenetre.prendLeFocus=1
77                 fenetre.hide()
78                 fenetre.show()
79
80
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
90
91
92     def calculOptionnel(self):
93         self.listeMc=[]
94         self.listeMcRegle=[]
95         self.dictToolTipMc={}
96         genea =self.obj.getGenealogie()
97         # Attention : les mots clefs listes (+sieurs fact )
98         # n ont pas toutes ces methodes
99         try :
100         #if 1 :
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
109         except :
110             #print ('in except')
111             #print (self)
112             return
113
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)
119
120
121     def ajouteMCOptionnelDesBlocs(self):
122         self.dictMCVenantDesBlocs={}
123         i=0
124         self.calculOptionnel()
125         liste=self.listeMc
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
129         try :
130             while i < self.commandesLayout.count():
131                 from .monWidgetBloc import MonWidgetBloc
132                 widget=self.commandesLayout.itemAt(i).widget()
133                 i=i+1
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]
140                 liste=liste+listeW
141                 liste_rouge=liste_rouge+listeW_rouge
142         except :
143             pass
144         return (liste,liste_rouge)
145
146
147     def reaffiche(self,nodeAVoir=None):
148         #print "dans reaffiche de groupe.py", nodeAVoir
149         self.parentQt.reaffiche(nodeAVoir)
150
151     def recalculeListeMC(self,listeMC):
152         #print "pas si peu utile"
153         #on ajoute et on enleve
154         listeNode=[]
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("")
166             return
167         for noeud in listeNode:
168             noeud.treeParent.item.suppItem(noeud.item)
169         noeud.treeParent.buildChildren()
170         self.editor.afficheInfos("")
171
172     def ajoutMC(self,texteListeNom):
173         listeNom=texteListeNom.split("+")[1:]
174         firstNode=None
175         for nom in listeNom:
176             if nom not in self.dictMCVenantDesBlocs:
177             #print "bizarre, bizarre"
178                 self.editor.initModif()
179                 nouveau=self.node.appendChild(nom)
180             else :
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)
187         try :
188             self.reaffiche(firstNode)
189             if firstNode!=None and firstNode !=0 and firstNode.item!=None : firstNode.select()
190         except :
191             pass
192
193
194     def setPlie(self):
195         self.node.setPlie()
196         self.reaffiche(self.node)
197
198     def setDeplie(self):
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)
203
204
205     def traiteClicSurLabel(self,texte):
206         if self.editor.code != "CARMELCND" : self.afficheOptionnel()
207         try :
208             fr = self.node.item.getFr()
209             self.editor.afficheCommentaire(str(fr))
210         except :
211             pass
212
213
214
215     def propageChange(self,leType,donneLefocus):
216         self.parentQt.propageChange(leType,donneLefocus)