1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 from PyQt4.QtGui import *
27 from PyQt4.QtCore import *
28 from Extensions.i18n import tr
29 from monChoixCommande import MonChoixCommande
31 class JDCTree( QTreeWidget ):
32 def __init__( self, jdc_item, QWParent):
33 #if hasattr(QWParent,'widgetTree') :
34 if QWParent.widgetTree !=None :
35 QTreeWidget.__init__(self, QWParent.widgetTree )
36 QWParent.verticalLayout_2.addWidget(self)
37 self.headerItem().setText(0, "Commande ")
38 self.headerItem().setText(1, "Concept/Valeur")
39 self.setColumnWidth(0,200)
40 self.setExpandsOnDoubleClick(False)
41 self.setSelectionMode(3)
43 QTreeWidget.__init__(self, None )
46 self.editor = QWParent
47 self.editor.fenetreAffichee=None
48 self.appliEficas = self.editor.appliEficas
49 self.childrenComplete=[]
50 self.childrenIssusDesBlocs=[]
51 self.racine=self.item.itemNode(self,self.item)
53 self.itemCourrant=None
55 self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
56 self.connect(self, SIGNAL("itemDoubleClicked ( QTreeWidgetItem * ,int) "), self.handleDoubleClickedOnItem)
58 #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande
59 self.node_selected=self.racine
60 self.expandItem(self.racine)
61 if self.racine.children !=[] : self.racine.children[0].affichePanneau()
62 else : self.racine.affichePanneau()
65 def contextMenuEvent(self,event) :
66 print "contextMenuEvent"
67 coord=event.globalPos()
68 item= self.currentItem()
69 self.handleContextMenu(item,coord)
71 def handleContextMenu(self,item,coord):
73 Private slot to show the context menu of the listview.
75 @param itm the selected listview item (QListWidgetItem)
76 @param coord the position of the mouse pointer (QPoint)
77 Attention : existeMenu permet de savoir si un menu est associe a cet item
79 print "handleContextMenu"
80 if item == None : return
81 if item.existeMenu == 0 : return
83 item.createPopUpMenu()
85 if item.item.get_nom() == "DISTRIBUTION" and item.item.isvalid() :
86 item.Graphe.setEnabled(1)
87 item.menu.exec_(coord)
90 def handleOnItem(self,item,int):
91 if (len(self.selectedIndexes())!=2): return
92 self.itemCourrant=item
95 fr = item.item.get_fr()
96 if self.editor: self.editor.labelCommentaire.setText(unicode(fr))
101 def handleDoubleClickedOnItem(self,item,int):
102 #if item.fenetre == None :
103 # while not (hasattr (item,'getPanel2')) : item=item.treeParent
104 # item.affichePanneau()
105 # self.expandItem(item)
107 # item.fenetre.rendVisible()
109 while not (hasattr (itemParent,'getPanel2')) : itemParent=item.treeParent
110 itemParent.affichePanneau()
112 item.fenetre.rendVisible()
114 def choisitPremier(self,name):
115 self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
116 self.racine.fenetre.close()
117 new_node=self.racine.append_brother(name,'after')
120 COMMENT = "COMMENTAIRE"
121 PARAMETERS = "PARAMETRE"
123 class JDCNode(QTreeWidgetItem):
124 def __init__( self, treeParent, item):
125 #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent
127 self.vraiParent = treeParent
128 self.treeParent = treeParent
129 self.tree = self.treeParent.tree
130 self.editor = self.treeParent.editor
131 self.appliEficas = treeParent.appliEficas
132 self.treeParent.childrenIssusDesBlocs=[]
133 self.childrenComplete=[]
135 from InterfaceQT4 import compocomm
136 from InterfaceQT4 import compoparam
137 if (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
138 elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
139 else: name = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
140 value = self.appliEficas.trUtf8(str( item.GetText() ) )
142 mesColonnes=QStringList()
143 mesColonnes << name << value
145 ajoutAuParentduNoeud=0
146 from InterfaceQT4 import compobloc
147 while (isinstance(self.treeParent,compobloc.Node)) :
148 self.treeParent=self.treeParent.treeParent
149 ajoutAuParentduNoeud=1
150 if ajoutAuParentduNoeud :
151 treeParent.childrenComplete.append(self)
152 self.treeParent.childrenIssusDesBlocs.append(self)
153 while (isinstance(self.treeParent,compobloc.Node)) : self.treeParent=self.treeParent.treeParent
155 if isinstance(self,compobloc.Node) :
156 QTreeWidgetItem.__init__(self,None,mesColonnes)
158 QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
159 self.treeParent.childrenComplete.append(self)
161 self.setToolTip(0,QString(self.item.get_fr()))
162 self.setToolTip(1,QString(self.item.get_fr()))
164 repIcon=QString(self.appliEficas.repIcon)
165 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
166 self.setIcon(0,monIcone)
169 self.build_children()
173 self.item.connect("valid",self.onValid,())
174 self.item.connect("supp" ,self.onSupp,())
175 self.item.connect("add" ,self.onAdd,())
179 if self.item.getObject().isBLOC() : self.setExpanded(True)
184 def build_children(self,posInsertion=10000):
185 """ Construit la liste des enfants de self """
186 """ Se charge de remettre les noeuds Expanded dans le meme etat """
187 #print "*********** build_children ",self.item, self.item.GetLabelText()
190 for item in self.childrenComplete :
192 # print " je detruis ", item.item.GetLabelText() ," parent : ", item.treeParent.item.GetLabelText()
194 # print "mot clef fact"
195 if item.isExpanded():
196 if self.childrenComplete.index(item) < posInsertion :
197 listeExpanded.append(self.childrenComplete.index(item))
199 listeExpanded.append( self.childrenComplete.index(item) +1)
200 self.detruit_les_noeuds_issus_de_blocs(item)
201 parent=item.treeParent
202 parent.removeChild(item)
205 self.childrenComplete = []
206 sublist = self.item._GetSubList()
208 for item in sublist :
209 nouvelItem=item.itemNode(self,item)
210 self.children.append(nouvelItem)
211 #print " J ajoute ", nouvelItem ,nouvelItem.item.GetLabelText(),"dans" ,self.item.GetLabelText()
212 if ind in listeExpanded : nouvelItem.setExpanded(1)
214 #print "*********** fin build_children ",self.item, self.item.GetLabelText()
217 def affichePanneau(self) :
218 #print "dans affichePanneau", self.item.GetLabelText()
219 #if self.item.GetLabelText()[0]=='VCUT : ' : print y
220 if self.item.isactif():
221 panel=self.getPanel2()
223 from monInactifPanel import PanelInactif
224 panel = PanelInactif(self,self.editor)
225 if hasattr(self,'fenetre') and self.fenetre:
228 if self.editor.fenetreCentraleAffichee != None :
229 self.editor.fenetreCentraleAffichee.close()
230 self.editor.fenetreCentraleAffichee=panel
231 if self.editor.widgetTree !=None : index=1
233 self.editor.widgetCentraleLayout.addWidget(self.fenetre)
235 if self.editor.first :
236 self.editor.splitter.setSizes((400,1400,400))
237 if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
238 self.tree.expandItem(self)
242 def createPopUpMenu(self):
243 #implemente dans les noeuds derives si necessaire
248 Cette methode a pour but de commentariser la commande pointee par self
250 # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
251 # (commentariser) un commentaire.
253 pos=self.treeParent.children.index(self)
254 commande_comment = self.item.get_objet_commentarise()
255 # On signale a l editeur du panel (le JDCDisplay) une modification
256 self.editor.init_modif()
257 self.treeParent.build_children()
258 self.treeParent.children[pos].select()
259 self.treeParent.children[pos].affichePanneau()
261 traceback.print_exc()
262 QMessageBox.critical( self.editor, "TOO BAD",str(e))
264 def unCommentIt(self):
266 Realise la decommentarisation de self
269 pos=self.treeParent.children.index(self)
270 commande,nom = self.item.uncomment()
271 self.editor.init_modif()
272 self.treeParent.build_children()
273 self.treeParent.children[pos].select()
274 self.treeParent.children[pos].affichePanneau()
276 QMessageBox.critical( self.editor, "Erreur !",str(e))
278 def addComment( self, after=True ):
280 Ajoute un commentaire a l'interieur du JDC :
282 self.editor.init_modif()
287 return self.append_brother( COMMENT, pos )
289 def addParameters( self, after=True ):
291 Ajoute un parametre a l'interieur du JDC :
293 self.editor.init_modif()
298 return self.append_brother( PARAMETERS, pos )
303 Rend le noeud courant (self) selectionne et deselectionne
306 for item in self.tree.selectedItems() :
308 self.setSelected( True )
309 self.setExpanded( True )
310 self.tree.setCurrentItem( self )
311 self.tree.node_selected= self
313 #------------------------------------------------------------------
314 # Methodes de creation et destruction de noeuds
315 # Certaines de ces methodes peuvent etre appelees depuis l'externe
316 #------------------------------------------------------------------
317 def append_brother(self,name,pos='after'):
319 Permet d'ajouter un objet frere a l'objet associe au noeud self
320 par defaut on l'ajoute immediatement apres
323 #print "*********** append_brother ", self.item.GetLabelText()
324 self.editor.init_modif()
325 index = self.treeParent.children.index(self)
331 print unicode(pos), tr(" n'est pas un index valide pour append_brother")
333 return self.treeParent.append_child(name,pos=index)
335 def append_child(self,name,pos=None):
337 Methode pour ajouter un objet fils a l'objet associe au noeud self.
338 On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
339 ou en position intermediaire.
340 Si pos vaut None, on le place a la position du catalogue.
342 #print "************** append_child ",self.item.GetLabelText()
343 self.editor.init_modif()
347 index = len(self.children)
348 elif type(pos) == types.IntType :
351 elif type(pos) == types.InstanceType:
352 # pos est un item. Il faut inserer name apres pos
353 index = self.item.get_index(pos) +1
354 elif type(name) == types.InstanceType:
355 index = self.item.get_index_child(name.nom)
357 index = self.item.get_index_child(name)
358 obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
361 ## PNPNPN : cas de Map nouvelle version
365 old_obj = self.item.object.get_child(name.nom,restreint = 'oui')
367 child.affichePanneau()
370 # Souci pour gerer les copies des AFFE d'une commande à l autre
372 child=self.children[index]
373 child.affichePanneau()
375 child=self.children[index]
380 self.editor.init_modif()
381 index = self.treeParent.children.index(self) - 1
382 if index < 0 : index =0
383 ret=self.treeParent.item.deplaceEntite(self.item.getObject())
387 Methode externe pour la destruction de l'objet associe au noeud
389 self.editor.init_modif()
390 index = self.vraiParent.children.index(self) - 1
391 if index < 0 : index =0
393 if self.item.nom == "VARIABLE" :
396 ret=self.vraiParent.item.suppitem(self.item)
397 self.treeParent.build_children()
398 if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
399 else: toselect=self.treeParent
400 if recalcule : jdc.recalcule_etat_correlation()
401 from InterfaceQT4 import compojdc
402 # cas ou on detruit dans l arbre sans affichage
403 if isinstance(self.treeParent,compojdc.Node) :
404 toselect.affichePanneau()
406 if self.treeParent.fenetre== None : return
407 self.treeParent.fenetre.reaffiche(toselect)
409 def deleteMultiple(self,liste=()):
411 Methode externe pour la destruction d une liste de noeud
413 from InterfaceQT4 import compojdc
414 self.editor.init_modif()
419 while not(isinstance(jdc,compojdc.Node)):
422 if not( isinstance(noeud.treeParent, compojdc.Node)): continue
423 if noeud.item.nom == "VARIABLE" : recalcule=1
424 if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
425 if index < 0 : index =0
427 # Cas ou on détruit dans une ETape
429 parentPosition=self.treeParent
430 while not(isinstance(parentPosition, compojdc.Node)):
431 index=parentPosition.treeParent.children.index(parentPosition)
432 parentPosition=parentPosition.treeParent
435 noeud.treeParent.item.suppitem(noeud.item)
438 if recalcule : jdc.recalcule_etat_correlation()
439 try : toselect=parentPosition.children[index]
440 except : toselect=jdc
442 toselect.affichePanneau()
444 # #------------------------------------------------------------------
447 if hasattr(self,'fenetre') and self.fenetre:
448 self.fenetre.setValide()
449 if self.item.nom == "VARIABLE" and self.item.isvalid():
450 self.item.jdc.recalcule_etat_correlation()
451 if hasattr(self.item,'forceRecalcul'):
452 self.forceRecalculChildren(self.item.forceRecalcul)
453 self.editor.init_modif()
455 self.update_node_valid()
456 self.update_node_label()
457 self.update_node_texte()
459 def onAdd(self,object):
460 #print "___________________________ onAdd", object
461 self.editor.init_modif()
464 def onSupp(self,object):
465 #print "___________________________ onSupp", self.item, self.item.GetLabelText()
466 self.editor.init_modif()
469 def detruit_les_noeuds_issus_de_blocs(self,bloc):
470 from InterfaceQT4 import compobloc
471 if (isinstance(bloc,compobloc.Node)) :
472 for node in bloc.childrenComplete :
473 self.detruit_les_noeuds_issus_de_blocs(node)
474 parent=node.treeParent
475 #print "je detruit " , node.item.GetLabelText()
476 parent.removeChild(node)
478 def update_node_valid(self):
479 """Cette methode remet a jour la validite du noeud (icone)
482 repIcon=QString(self.appliEficas.repIcon)
483 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
484 self.setIcon(0,monIcone)
487 def update_node_label(self):
488 """ Met a jour le label du noeud """
489 #print "NODE update_node_label", self.item.GetLabelText()
490 labeltext,fonte,couleur = self.item.GetLabelText()
492 #self.setText(0, labeltext)
495 def update_node_label_in_blue(self):
496 if hasattr(self.appliEficas,'noeudColore'):
497 self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
498 self.appliEficas.noeudColore.update_node_label()
499 self.setTextColor( 0,Qt.blue )
500 labeltext,fonte,couleur = self.item.GetLabelText()
501 self.setText(0, labeltext)
502 self.appliEficas.noeudColore=self
504 def update_plusieurs_node_label_in_blue(self,liste):
505 if hasattr(self.appliEficas,'listeNoeudsColores'):
506 for noeud in self.appliEficas.listeNoeudsColores:
507 noeud.setTextColor( 0,Qt.black)
508 noeud.update_node_label()
509 self.appliEficas.listeNoeudsColores=[]
511 noeud.setTextColor( 0,Qt.blue )
512 labeltext,fonte,couleur = noeud.item.GetLabelText()
513 noeud.setText(0, labeltext)
514 self.appliEficas.listeNoeudsColores.append(noeud)
516 def update_node_texte_in_black(self):
517 """ Met a jour les noms des SD et valeurs des mots-cles """
518 self.setTextColor( 1,Qt.black )
519 value = self.item.GetText()
520 self.setText(1, value)
522 def update_node_texte(self):
523 """ Met a jour les noms des SD et valeurs des mots-cles """
524 value = self.item.GetText()
525 self.setText(1, value)
527 def update_node_texte_in_blue(self):
528 self.setTextColor( 1,Qt.blue )
529 value = self.item.GetText()
530 self.setText(1, value)
532 def update_nodes(self):
533 #print 'NODE update_nodes', self.item.GetLabelText()
534 self.build_children()
536 def update_valid(self) :
537 """Cette methode a pour but de mettre a jour la validite du noeud
538 et de propager la demande de mise a jour a son parent
540 #print "NODE update_valid", self.item.GetLabelText()
541 self.update_node_valid()
543 self.treeParent.update_valid()
547 def update_texte(self):
548 """ Met a jour les noms des SD et valeurs des mots-cles """
549 #print "NODE update_texte", self.item.GetLabelText()
550 self.update_node_texte()
551 if self.isExpanded() :
552 for child in self.children:
553 if child.isHidden() == false : child.update_texte()
556 def forceRecalculChildren(self,niveau):
557 if self.state=='recalcule' :
560 self.state='recalcule'
561 if hasattr(self.item,'object'):
562 self.item.object.state="modified"
563 for child in self.children:
564 if niveau > 0 : child.forceRecalculChildren(niveau - 1)
568 def doPaste(self,node_selected,pos='after'):
570 Déclenche la copie de l'objet item avec pour cible
571 l'objet passé en argument : node_selected
573 #print 'je passe dans doPaste'
574 objet_a_copier = self.item.get_copie_objet()
575 child=node_selected.doPasteCommande(objet_a_copier,pos)
578 def doPasteCommande(self,objet_a_copier,pos='after'):
580 Réalise la copie de l'objet passé en argument qui est nécessairement
585 child = self.append_brother(objet_a_copier,pos)
590 def doPastePremier(self,objet_a_copier):
592 Réalise la copie de l'objet passé en argument (objet_a_copier)
594 objet = objet_a_copier.item.get_copie_objet()
595 child = self.append_child(objet,pos='first')
600 self.setPlieChildren()
602 def setPlieChildren(self):
603 self.appartientAUnNoeudPlie=True
604 for item in self.children :
605 item.setPlieChildren()
610 self.setDeplieChildren()
612 def setDeplieChildren(self):
613 self.appartientAUnNoeudPlie=False
614 for item in self.children :
615 item.setDeplieChildren()