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