Salome HOME
optim eciture
[tools/eficas.git] / InterfaceQT4 / groupe.py
1 # Copyright (C) 2007-2013   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
32     
33 # Import des panels
34
35 class Groupe(QWidget,FacultatifOuOptionnel):
36   """
37   """
38   def __init__(self,node,editor,parentQt,definition,obj,niveau,commande=None):
39       QWidget.__init__(self,None)
40       self.node=node
41       self.node.fenetre=self
42       #print "groupe : ",self.node.item.nom," ",self.node.fenetre
43       self.setupUi(self)
44       self.editor=editor
45       self.obj=obj
46       self.niveau=niveau
47       self.definition=definition
48       self.parentQt=parentQt
49       self.maCommande=commande
50       self.listeFocus=[]
51       self.appliEficas=self.editor.appliEficas
52       self.repIcon=self.appliEficas.repIcon
53       self.jdc=self.node.item.get_jdc()
54       self.setIconePoubelle()
55       self.setIconesGenerales()
56       self.setRun()
57       self.setValide()
58       self.setReglesEtAide()
59       self.afficheMots()
60       self.listeMCAAjouter=[]
61       self.dictMCVenantDesBlocs={}
62       if hasattr(self,'RBDeplie')  : self.RBDeplie.clicked.connect(self.Deplie)
63       if hasattr(self,'RBPlie')    : self.RBPlie.clicked.connect( self.Plie)
64       self.setAcceptDrops(True)
65      
66   def donneFocus(self):
67       for fenetre in self.listeFocus:
68           if fenetre==None : return
69           if fenetre.node.item.isvalid() == 0 :
70              fenetre.prendLeFocus=1
71              fenetre.hide()
72              fenetre.show()
73       
74
75   def afficheMots(self):
76       #print "ds afficheMots ",self.node.item.nom
77       for node in self.node.children:
78            #if node.item.nom == "Background" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
79            #if node.item.nom == "BackgroundError" :print "afficheMots ",node," " ,node.item.nom, " ",node.plie ," ", node.appartientAUnNoeudPlie,node.getPanelGroupe
80            # non return mais  continue car il faut tenir compte des blocs
81            if node.appartientAUnNoeudPlie==True : continue
82            #print "je suis apres le if pour ",node.item.nom
83            widget=node.getPanelGroupe(self,self.maCommande)
84            #print "widget pour ", node.item.nom, widget
85            self.listeFocus.append(node.fenetre)
86       #print "fin pour " , self.node.item.nom
87
88        
89   def calculOptionnel(self):
90         self.liste_mc=[]
91         genea =self.obj.get_genealogie()
92         # Attention : les mots clefs listes (+sieurs fact )
93         # n ont pas toutes ces methodes
94         try :
95            self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
96         except :
97            return
98         
99   def afficheOptionnel(self):
100         liste=self.ajouteMCOptionnelDesBlocs()
101         self.monOptionnel=self.editor.widgetOptionnel
102         self.monOptionnel.afficheOptionnel(liste,self)
103         #self.monOptionnel.affiche(liste)
104            
105
106   def ajouteMCOptionnelDesBlocs(self):
107        #print ("Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom)
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       while i < self.commandesLayout.count():
114           from .monWidgetBloc import MonWidgetBloc
115           widget=self.commandesLayout.itemAt(i).widget()
116           i=i+1
117           if not(isinstance(widget,MonWidgetBloc)) : continue
118           widget.calculOptionnel()
119           listeW=widget.ajouteMCOptionnelDesBlocs() 
120           for MC in widget.dictMCVenantDesBlocs:
121               if MC in self.dictMCVenantDesBlocs: print ("Pb Sur les MC" )
122               else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
123           liste=liste+listeW
124       return liste
125
126
127   def reaffiche(self,nodeAVoir=None):
128       #print "dans reaffiche de groupe.py", nodeAVoir
129       self.parentQt.reaffiche(nodeAVoir)
130
131   def recalculeListeMC(self,listeMC):
132       #print "pas si peu utile"
133       #on ajoute et on enleve
134       listeNode=[]
135       for name in listeMC :
136           nodeAEnlever=self.node.append_child(name)
137           if nodeAEnlever.item.isMCList(): 
138              nodeAEnlever=nodeAEnlever.children[-1]
139           listeNode.append(nodeAEnlever)
140       self.afficheOptionnel()
141       self.monOptionnel.affiche(self.liste_mc)
142       if len(listeNode) == 0 : return
143       if len(listeNode) == 1 : 
144          listeNode[0].delete()
145          self.editor.affiche_infos("")
146          return
147       for noeud in listeNode:
148           noeud.treeParent.item.suppitem(noeud.item)
149       noeud.treeParent.build_children()
150       self.editor.affiche_infos("")
151
152   def ajoutMC(self,texteListeNom):
153       listeNom=texteListeNom.split("+")[1:]
154       firstNode=None
155       for nom in listeNom:
156         if nom not in self.dictMCVenantDesBlocs:
157            #print "bizarre, bizarre"
158            self.editor.init_modif()
159            nouveau=self.node.append_child(nom)
160         else :
161            self.editor.init_modif()
162            widget=self.dictMCVenantDesBlocs[nom]
163            nouveau=widget.node.append_child(nom)
164         if firstNode==None : firstNode=nouveau 
165         if nouveau == None or nouveau == 0  : 
166            self.editor.affiche_infos(tr('insertion impossible a cet endroit pour '+nom),Qt.red)
167       self.reaffiche(firstNode)
168       if firstNode!=None and firstNode !=0 and firstNode.item!=None :
169         firstNode.select()
170
171
172   def Plie(self):
173       self.node.setPlie()
174       self.reaffiche(self.node) 
175
176   def Deplie(self):
177       self.node.setDeplie()
178       self.reaffiche(self.node) 
179
180   def traiteClicSurLabel(self,texte):
181       if self.editor.code != "CARMELCND" : self.afficheOptionnel()
182