Salome HOME
chgt date copyright
[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
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       QWidget.__init__(self,None)
41       self.node=node
42       self.node.fenetre=self
43       #print "groupe : ",self.node.item.nom," ",self.node.fenetre
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.get_jdc()
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.Deplie)
64       if hasattr(self,'RBPlie')    : self.RBPlie.clicked.connect( self.Plie)
65       self.setAcceptDrops(True)
66      
67   def donneFocus(self):
68       for fenetre in self.listeFocus:
69           if fenetre==None : return
70           if fenetre.node.item.isvalid() == 0 :
71              fenetre.prendLeFocus=1
72              fenetre.hide()
73              fenetre.show()
74       
75
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
88
89        
90   def calculOptionnel(self):
91         self.liste_mc=[]
92         genea =self.obj.get_genealogie()
93         # Attention : les mots clefs listes (+sieurs fact )
94         # n ont pas toutes ces methodes
95         try :
96            self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
97         except :
98            return
99         
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)
105            
106
107   def ajouteMCOptionnelDesBlocs(self):
108       self.dictMCVenantDesBlocs={}
109       i=0
110       self.calculOptionnel()
111       liste=self.liste_mc
112       for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
113       # ce cas est le cas machine tournant sr le plie
114       try :
115         while i < self.commandesLayout.count():
116           from .monWidgetBloc import MonWidgetBloc
117           widget=self.commandesLayout.itemAt(i).widget()
118           i=i+1
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]
125           liste=liste+listeW
126       except : 
127         pass
128       return liste
129
130
131   def reaffiche(self,nodeAVoir=None):
132       #print "dans reaffiche de groupe.py", nodeAVoir
133       self.parentQt.reaffiche(nodeAVoir)
134
135   def recalculeListeMC(self,listeMC):
136       #print "pas si peu utile"
137       #on ajoute et on enleve
138       listeNode=[]
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("")
150          return
151       for noeud in listeNode:
152           noeud.treeParent.item.suppitem(noeud.item)
153       noeud.treeParent.build_children()
154       self.editor.affiche_infos("")
155
156   def ajoutMC(self,texteListeNom):
157       listeNom=texteListeNom.split("+")[1:]
158       firstNode=None
159       for nom in listeNom:
160         if nom not in self.dictMCVenantDesBlocs:
161            #print "bizarre, bizarre"
162            self.editor.init_modif()
163            nouveau=self.node.append_child(nom)
164         else :
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 :
173         firstNode.select()
174
175
176   def Plie(self):
177       self.node.setPlie()
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)
182              return
183          #else :
184          #  self.reaffiche(self.node)
185          #return
186       #print ('je reaffiche dans Plie')
187       self.reaffiche(self.node) 
188
189   def Deplie(self):
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)
195              return
196          #else :
197          #  self.reaffiche(self.node)
198          #return
199       #print ('je reaffiche dans Plie')
200       self.reaffiche(self.node) 
201     
202     
203   #def Plie(self):
204       #print ('Deplie', self)
205       #print (self.obj.nom)
206       #print (self.node.setPlie)
207       #print (self.parentQt)
208       #print (self)
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)
221          #return
222    #   if self.editor.code== 'MT' and (self.maCommande.obj.nom == "ZONE") :
223    #      if  (len(self.node.item.get_genealogie())==2):
224              #print (self)
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)
231              #print (index)
232    #          self.maCommande.reafficheSeulement(self,index)
233              #self.disconnect()
234              #for c in self.children(): 
235              #  print (c)
236              #  try :
237              #    c.setParent(None)
238              #    c.deleteLater()
239              # c.close()
240              #   c.disconnect()
241              #  except :
242              #    print('poum')
243              #panneau = self.node.getPanelGroupe(self.parentQt,self.maCommande,insertIn=False)
244       #       print (self.parentQt)
245       #       print (self)
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()
250    #      else :
251    #        self.reaffiche(self.node)
252    #      return
253       #print ('je reaffiche dans Plie')
254    #   self.reaffiche(self.node) 
255 #
256 #  def Deplie(self):
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)
274 #      #   return
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)
282 #             index=0
283 #             self.maCommande.reafficheSeulement(self,index)
284 #         else :
285 #           self.reaffiche(self.node)
286 #         return
287 #     
288 #      #print ('je reaffiche')
289 #      self.reaffiche(self.node) 
290
291   def traiteClicSurLabel(self,texte):
292       if self.editor.code != "CARMELCND" : self.afficheOptionnel()
293