Salome HOME
ee9c95f14c139b67129b05521f76d6c73fee8d8b
[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 PyQt4  import *
23 from PyQt4.QtGui import *
24 from PyQt4.QtCore import *
25 from Extensions.i18n import tr
26 from gereIcones import FacultatifOuOptionnel
27 import Accas 
28
29     
30 # Import des panels
31
32 class Groupe(QtGui.QWidget,FacultatifOuOptionnel):
33   """
34   """
35   def __init__(self,node,editor,parentQt,definition,obj,niveau):
36       QtGui.QWidget.__init__(self,None)
37       self.node=node
38       self.node.fenetre=self
39       #print "groupe : ",self.node.item.nom," ",self.node.fenetre
40       #self.setFocusPolicy(Qt.StrongFocus)
41       self.setupUi(self)
42       self.editor=editor
43       self.obj=obj
44       self.niveau=niveau
45       self.definition=definition
46       self.parentQt=parentQt
47       self.listeFocus=[]
48       self.appliEficas=self.editor.appliEficas
49       self.repIcon=self.appliEficas.repIcon
50       self.jdc=self.node.item.get_jdc()
51       self.setPoubelle()
52       self.setValide()
53       self.setReglesEtAide()
54       self.afficheMots()
55       self.listeMCAAjouter=[]
56       self.dictMCVenantDesBlocs={}
57       if hasattr(self,'RBDeplie') : self.connect(self.RBDeplie,SIGNAL("clicked()"), self.Deplie)
58       if hasattr(self,'RBPlie') : self.connect(self.RBPlie,SIGNAL("clicked()"), self.Plie)
59       self.setAcceptDrops(True)
60       #self.donneFocus()
61      
62   def donneFocus(self):
63       for fenetre in self.listeFocus:
64           if fenetre==None : return
65           if fenetre.node.item.isvalid() == 0 :
66              fenetre.prendLeFocus=1
67              fenetre.hide()
68              fenetre.show()
69              break
70       
71
72   def afficheMots(self):
73       for node in self.node.children:
74            #if node in self.node.listeMCVenantDesBlocs : continue
75            #   print "pas ", node.item.nom
76            #   continue
77            if hasattr(self.node,'appartientAUnNoeudPlie') and self.node.appartientAUnNoeudPlie==True : return
78            else : widget=node.getPanelGroupe(self)
79            #print node
80            #print node.item.nom
81            self.listeFocus.append(node.fenetre)
82       #print "fin afficheMots pou " ,self.node.item.nom
83
84        
85   def calculOptionnel(self):
86         self.liste_mc=[]
87         genea =self.obj.get_genealogie()
88         # Attention : les mots clefs listes (+sieurs fact )
89         # n ont pas toutes ces methodes
90         try :
91            self.liste_mc=self.obj.get_liste_mc_ordonnee(genea,self.jdc.cata_ordonne_dico)
92         except :
93            return
94         
95   def afficheOptionnel(self):
96         liste=self.ajouteMCOptionnelDesBlocs()
97         #chercheOptionnel=self.parentQt
98         # Boucle necessaire pour les regroupements Adao
99         #while not( hasattr(chercheOptionnel,'monOptionnel')):
100         #    chercheOptionnel=chercheOptionnel.parentQt
101         #self.monOptionnel=chercheOptionnel.monOptionnel
102         self.monOptionnel=self.editor.widgetOptionnel
103         self.monOptionnel.parentMC=self
104         self.monOptionnel.affiche(liste)
105            
106
107   def ajouteMCOptionnelDesBlocs(self):
108       #print "Je passe dans ajouteMCOptionnelDesBlocs pour", self.node.item.nom
109       self.dictMCVenantDesBlocs={}
110       i=0
111       self.calculOptionnel()
112       liste=self.liste_mc
113       for MC in self.liste_mc : self.dictMCVenantDesBlocs[MC]=self
114       while i < self.commandesLayout.count():
115           from monWidgetBloc import MonWidgetBloc
116           widget=self.commandesLayout.itemAt(i).widget()
117           i=i+1
118           if not(isinstance(widget,MonWidgetBloc)) : continue
119           widget.calculOptionnel()
120           listeW=widget.ajouteMCOptionnelDesBlocs() 
121           for MC in widget.dictMCVenantDesBlocs.keys():
122               if MC in self.dictMCVenantDesBlocs.keys(): print "Pb Sur les MC" 
123               else : self.dictMCVenantDesBlocs[MC]=widget.dictMCVenantDesBlocs[MC]
124           liste=liste+listeW
125       return liste
126
127
128   def reaffiche(self,nodeAVoir=None):
129       print "dans reaffiche ________________________", nodeAVoir
130       self.parentQt.reaffiche(nodeAVoir)
131
132   def recalculeListeMC(self,listeMC):
133       #print "pas si peu utile"
134       #on ajoute et on enleve
135       listeNode=[]
136       for name in listeMC :
137           nodeAEnlever=self.node.append_child(name)
138           if nodeAEnlever.item.isMCList(): 
139              nodeAEnlever=nodeAEnlever.children[-1]
140           listeNode.append(nodeAEnlever)
141       self.afficheOptionnel()
142       self.monOptionnel.affiche(self.liste_mc)
143       if len(listeNode) == 0 : return
144       if len(listeNode) == 1 : 
145          listeNode[0].delete()
146          self.editor.affiche_infos("")
147          return
148       for noeud in listeNode:
149           noeud.treeParent.item.suppitem(noeud.item)
150       noeud.treeParent.build_children()
151       self.editor.affiche_infos("")
152
153   def ajoutMC(self,texteListeNom):
154       listeNom=texteListeNom.split("+")[1:]
155       firstNode=None
156       for nom in listeNom:
157         if nom not in self.dictMCVenantDesBlocs.keys():
158            print "bizarre, bizarre"
159            self.editor.init_modif()
160            nouveau=self.node.append_child(nom)
161         else :
162            self.editor.init_modif()
163            widget=self.dictMCVenantDesBlocs[nom]
164            nouveau=widget.node.append_child(nom)
165         if firstNode==None : firstNode=nouveau 
166         if nouveau == None or nouveau == 0  : 
167            self.editor.affiche_infos(str('insertion impossible a cet endroit pour '+nom),Qt.red)
168       self.reaffiche(firstNode)
169       
170
171
172   def Plie(self):
173       self.node.setPlie()
174       self.reaffiche() 
175
176   def Deplie(self):
177       self.node.setDeplie()
178       self.reaffiche() 
179
180