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.appliEficas = self.editor.appliEficas
48 self.childrenComplete=[]
49 self.childrenIssusDesBlocs=[]
50 self.racine=self.item.itemNode(self,self.item)
52 self.itemCourrant=None
54 self.connect(self, SIGNAL("itemClicked ( QTreeWidgetItem * ,int) "), self.handleOnItem)
55 #self.connect(self, SIGNAL("itemDoubleClicked ( QTreeWidgetItem * ,int) "), self.handleDoubleClickedOnItem)
57 #PNPNPN verifier dans quel cas on se trouve : affiche l arbre ou la commande
58 self.node_selected=self.racine
59 self.expandItem(self.racine)
60 if self.racine.children !=[] :
61 self.racine.children[0].affichePanneau()
62 if self.editor.afficheCommandesPliees : self.racine.children[0].plieToutEtReaffiche()
63 else : self.racine.affichePanneau()
66 def contextMenuEvent(self,event) :
67 print "contextMenuEvent"
68 coord=event.globalPos()
69 item= self.currentItem()
70 self.handleContextMenu(item,coord)
72 def handleContextMenu(self,item,coord):
74 Private slot to show the context menu of the listview.
76 @param itm the selected listview item (QListWidgetItem)
77 @param coord the position of the mouse pointer (QPoint)
78 Attention : existeMenu permet de savoir si un menu est associe a cet item
80 print "handleContextMenu"
81 if item == None : return
82 if item.existeMenu == 0 : return
84 item.createPopUpMenu()
86 if item.item.get_nom() == "DISTRIBUTION" and item.item.isvalid() :
87 item.Graphe.setEnabled(1)
88 item.menu.exec_(coord)
91 def handleOnItem(self,item,int):
92 if (len(self.selectedIndexes())!=2): return
93 self.itemCourrant=item
94 self.handleDoubleClickedOnItem(item,int)
97 fr = item.item.get_fr()
98 if self.editor: self.editor.labelCommentaire.setText(unicode(fr))
103 def handleDoubleClickedOnItem(self,item,int):
105 while not (hasattr (itemParent,'getPanel2')) : itemParent=item.treeParent
106 itemParent.affichePanneau()
108 item.fenetre.rendVisible()
110 def choisitPremier(self,name):
111 self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
112 self.racine.fenetre.close()
113 new_node=self.racine.append_brother(name,'after')
116 COMMENT = "COMMENTAIRE"
117 PARAMETERS = "PARAMETRE"
119 class JDCNode(QTreeWidgetItem):
120 def __init__( self, treeParent, item):
121 #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent
124 self.vraiParent = treeParent
125 self.treeParent = treeParent
126 self.tree = self.treeParent.tree
127 self.editor = self.treeParent.editor
128 self.appliEficas = treeParent.appliEficas
129 self.treeParent.childrenIssusDesBlocs=[]
130 self.childrenComplete=[]
132 from InterfaceQT4 import compocomm
133 from InterfaceQT4 import compoparam
134 if (isinstance(self.item,compocomm.COMMTreeItem)) : name=tr("Commentaire")
135 elif (isinstance(self.item,compoparam.PARAMTreeItem)) : name=self.appliEficas.trUtf8(str(item.GetLabelText()[0]))
136 else: name = self.appliEficas.trUtf8(str(tr( item.nom))+" :")
137 value = self.appliEficas.trUtf8(str( item.GetText() ) )
139 mesColonnes=QStringList()
140 mesColonnes << name << value
142 ajoutAuParentduNoeud=0
143 from InterfaceQT4 import compobloc
144 while (isinstance(self.treeParent,compobloc.Node)) :
145 self.treeParent=self.treeParent.treeParent
146 ajoutAuParentduNoeud=1
147 if ajoutAuParentduNoeud :
148 treeParent.childrenComplete.append(self)
149 self.treeParent.childrenIssusDesBlocs.append(self)
150 while (isinstance(self.treeParent,compobloc.Node)) : self.treeParent=self.treeParent.treeParent
152 if isinstance(self,compobloc.Node) :
153 QTreeWidgetItem.__init__(self,None,mesColonnes)
155 QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
156 self.treeParent.childrenComplete.append(self)
158 self.setToolTip(0,QString(self.item.get_fr()))
159 self.setToolTip(1,QString(self.item.get_fr()))
161 repIcon=QString(self.appliEficas.repIcon)
162 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
163 self.setIcon(0,monIcone)
166 self.build_children()
170 self.item.connect("valid",self.onValid,())
171 self.item.connect("supp" ,self.onSupp,())
172 self.item.connect("add" ,self.onAdd,())
176 if self.item.getObject().isBLOC() : self.setExpanded(True)
181 def build_children(self,posInsertion=10000):
182 """ Construit la liste des enfants de self """
183 """ Se charge de remettre les noeuds Expanded dans le meme etat """
184 #print "*********** build_children ",self.item, self.item.GetLabelText()
187 for item in self.childrenComplete :
189 # print " je detruis ", item.item.GetLabelText() ," parent : ", item.treeParent.item.GetLabelText()
191 # print "mot clef fact"
192 if item.isExpanded():
193 if self.childrenComplete.index(item) < posInsertion :
194 listeExpanded.append(self.childrenComplete.index(item))
196 listeExpanded.append( self.childrenComplete.index(item) +1)
197 self.detruit_les_noeuds_issus_de_blocs(item)
198 parent=item.treeParent
199 parent.removeChild(item)
202 self.childrenComplete = []
203 sublist = self.item._GetSubList()
205 for item in sublist :
206 nouvelItem=item.itemNode(self,item)
207 self.children.append(nouvelItem)
208 #print " J ajoute ", nouvelItem ,nouvelItem.item.GetLabelText(),"dans" ,self.item.GetLabelText()
209 if ind in listeExpanded : nouvelItem.setExpanded(1)
211 #print "*********** fin build_children ",self.item, self.item.GetLabelText()
213 def chercheNoeudCorrespondant(self,objSimp):
214 sublist = self.item._GetSubList()
215 for node in self.childrenComplete:
216 if node.item.object==objSimp : return node
219 def affichePanneau(self) :
220 #print "______________________________"
221 #print "dans affichePanneau appel getPanel2", self.item.GetLabelText()
223 if self.item.isactif(): self.fenetre=self.getPanel2()
225 from monInactifPanel import PanelInactif
226 self.fenetre = PanelInactif(self,self.editor)
227 self.editor.widgetCentraleLayout.addWidget(self.fenetre)
229 self.editor.anciennefenetre=self.editor.fenetreCentraleAffichee
230 self.editor.fenetreCentraleAffichee=self.fenetre
232 if self.editor.anciennefenetre != None :
233 self.editor.anciennefenetre.close()
235 if self.editor.widgetTree !=None : index=1
238 if self.editor.first :
239 self.editor.splitter.setSizes((400,1400,400))
240 if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
241 self.tree.expandItem(self)
243 #print "fin de affichePanneau"
244 #print "______________________________"
247 def createPopUpMenu(self):
248 #implemente dans les noeuds derives si necessaire
253 Cette methode a pour but de commentariser la commande pointee par self
255 # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
256 # (commentariser) un commentaire.
258 pos=self.treeParent.children.index(self)
259 commande_comment = self.item.get_objet_commentarise()
260 # On signale a l editeur du panel (le JDCDisplay) une modification
261 self.editor.init_modif()
262 self.treeParent.build_children()
263 self.treeParent.children[pos].select()
264 self.treeParent.children[pos].affichePanneau()
266 traceback.print_exc()
267 QMessageBox.critical( self.editor, "TOO BAD",str(e))
269 def unCommentIt(self):
271 Realise la decommentarisation de self
274 pos=self.treeParent.children.index(self)
275 commande,nom = self.item.uncomment()
276 self.editor.init_modif()
277 self.treeParent.build_children()
278 self.treeParent.children[pos].select()
279 self.treeParent.children[pos].affichePanneau()
281 QMessageBox.critical( self.editor, "Erreur !",str(e))
283 def addComment( self, after=True ):
285 Ajoute un commentaire a l'interieur du JDC :
287 self.editor.init_modif()
292 return self.append_brother( COMMENT, pos )
294 def addParameters( self, after=True ):
296 Ajoute un parametre a l'interieur du JDC :
298 self.editor.init_modif()
303 return self.append_brother( PARAMETERS, pos )
308 Rend le noeud courant (self) selectionne et deselectionne
311 for item in self.tree.selectedItems() :
313 self.setSelected( True )
314 self.setExpanded( True )
315 self.tree.setCurrentItem( self )
316 self.tree.node_selected= self
318 #------------------------------------------------------------------
319 # Methodes de creation et destruction de noeuds
320 # Certaines de ces methodes peuvent etre appelees depuis l'externe
321 #------------------------------------------------------------------
322 def append_brother(self,name,pos='after'):
324 Permet d'ajouter un objet frere a l'objet associe au noeud self
325 par defaut on l'ajoute immediatement apres
328 #print "*********** append_brother ", self.item.GetLabelText()
329 self.editor.init_modif()
330 index = self.treeParent.children.index(self)
336 print unicode(pos), tr(" n'est pas un index valide pour append_brother")
338 return self.treeParent.append_child(name,pos=index)
340 def append_child(self,name,pos=None):
342 Methode pour ajouter un objet fils a l'objet associe au noeud self.
343 On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
344 ou en position intermediaire.
345 Si pos vaut None, on le place a la position du catalogue.
347 print "************** append_child ",self.item.GetLabelText()
348 self.editor.init_modif()
352 index = len(self.children)
353 elif type(pos) == types.IntType :
356 elif type(pos) == types.InstanceType:
357 # pos est un item. Il faut inserer name apres pos
358 index = self.item.get_index(pos) +1
359 elif type(name) == types.InstanceType:
360 index = self.item.get_index_child(name.nom)
362 index = self.item.get_index_child(name)
363 obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
367 old_obj = self.item.object.get_child(name.nom,restreint = 'oui')
369 child.affichePanneau()
370 print "dans le 1er Try"
373 # Souci pour gerer les copies des AFFE d'une commande à l autre
375 child=self.children[index]
376 child.affichePanneau()
377 print "dans le 2nd Try"
379 child=self.children[index]
380 print "dans le except"
384 self.editor.init_modif()
385 index = self.treeParent.children.index(self) - 1
386 if index < 0 : index =0
387 ret=self.treeParent.item.deplaceEntite(self.item.getObject())
391 Methode externe pour la destruction de l'objet associe au noeud
393 self.editor.init_modif()
394 index = self.vraiParent.children.index(self) - 1
395 if index < 0 : index =0
397 if self.item.nom == "VARIABLE" :
400 ret=self.vraiParent.item.suppitem(self.item)
401 self.treeParent.build_children()
402 if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
403 else: toselect=self.treeParent
404 if recalcule : jdc.recalcule_etat_correlation()
405 from InterfaceQT4 import compojdc
406 # cas ou on detruit dans l arbre sans affichage
407 if isinstance(self.treeParent,compojdc.Node) :
408 toselect.affichePanneau()
410 if self.treeParent.fenetre== None : return
411 print "J appelle reaffiche de browser apres delete"
412 self.treeParent.fenetre.reaffiche(toselect)
414 def deleteMultiple(self,liste=()):
416 Methode externe pour la destruction d une liste de noeud
418 from InterfaceQT4 import compojdc
419 self.editor.init_modif()
424 while not(isinstance(jdc,compojdc.Node)):
427 if not( isinstance(noeud.treeParent, compojdc.Node)): continue
428 if noeud.item.nom == "VARIABLE" : recalcule=1
429 if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
430 if index < 0 : index =0
432 # Cas ou on détruit dans une ETape
434 parentPosition=self.treeParent
435 while not(isinstance(parentPosition, compojdc.Node)):
436 index=parentPosition.treeParent.children.index(parentPosition)
437 parentPosition=parentPosition.treeParent
440 noeud.treeParent.item.suppitem(noeud.item)
443 if recalcule : jdc.recalcule_etat_correlation()
444 try : toselect=parentPosition.children[index]
445 except : toselect=jdc
447 toselect.affichePanneau()
449 # #------------------------------------------------------------------
452 #print "onValid pour ", self.item.nom
453 if hasattr(self,'fenetre') and self.fenetre:
454 self.fenetre.setValide()
455 if self.item.nom == "VARIABLE" and self.item.isvalid():
456 self.item.jdc.recalcule_etat_correlation()
457 if hasattr(self.item,'forceRecalcul'):
458 self.forceRecalculChildren(self.item.forceRecalcul)
459 self.editor.init_modif()
461 self.update_node_valid()
462 self.update_node_label()
463 self.update_node_texte()
465 def onAdd(self,object):
466 #print "onAdd pour ", self.item.nom
467 self.editor.init_modif()
469 print "dans onAdd" ,self.item
470 # PN -- non necessaire si item=jdc
471 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
473 def onSupp(self,object):
474 #print "onSupp pour ", self.item.nom
475 self.editor.init_modif()
477 # PN -- non necessaire si item=jdc
478 if hasattr(self.item,'jdc'): self.item.jdc.aReafficher=True
480 def detruit_les_noeuds_issus_de_blocs(self,bloc):
481 from InterfaceQT4 import compobloc
482 if (isinstance(bloc,compobloc.Node)) :
483 for node in bloc.childrenComplete :
484 self.detruit_les_noeuds_issus_de_blocs(node)
485 parent=node.treeParent
486 #print "je detruit " , node.item.GetLabelText()
487 parent.removeChild(node)
489 def update_node_valid(self):
490 """Cette methode remet a jour la validite du noeud (icone)
493 repIcon=QString(self.appliEficas.repIcon)
494 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
495 self.setIcon(0,monIcone)
498 def update_node_label(self):
499 """ Met a jour le label du noeud """
500 #print "NODE update_node_label", self.item.GetLabelText()
501 labeltext,fonte,couleur = self.item.GetLabelText()
503 #self.setText(0, labeltext)
506 def update_node_label_in_blue(self):
507 if hasattr(self.appliEficas,'noeudColore'):
508 self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
509 self.appliEficas.noeudColore.update_node_label()
510 self.setTextColor( 0,Qt.blue )
511 labeltext,fonte,couleur = self.item.GetLabelText()
512 self.setText(0, labeltext)
513 self.appliEficas.noeudColore=self
515 def update_plusieurs_node_label_in_blue(self,liste):
516 if hasattr(self.appliEficas,'listeNoeudsColores'):
517 for noeud in self.appliEficas.listeNoeudsColores:
518 noeud.setTextColor( 0,Qt.black)
519 noeud.update_node_label()
520 self.appliEficas.listeNoeudsColores=[]
522 noeud.setTextColor( 0,Qt.blue )
523 labeltext,fonte,couleur = noeud.item.GetLabelText()
524 noeud.setText(0, labeltext)
525 self.appliEficas.listeNoeudsColores.append(noeud)
527 def update_node_texte_in_black(self):
528 """ Met a jour les noms des SD et valeurs des mots-cles """
529 self.setTextColor( 1,Qt.black )
530 value = self.item.GetText()
531 self.setText(1, value)
533 def update_node_texte(self):
534 """ Met a jour les noms des SD et valeurs des mots-cles """
535 value = self.item.GetText()
536 self.setText(1, value)
538 def update_node_texte_in_blue(self):
539 self.setTextColor( 1,Qt.blue )
540 value = self.item.GetText()
541 self.setText(1, value)
543 def update_nodes(self):
544 #print 'NODE update_nodes', self.item.GetLabelText()
545 self.build_children()
547 def update_valid(self) :
548 """Cette methode a pour but de mettre a jour la validite du noeud
549 et de propager la demande de mise a jour a son parent
551 #print "NODE update_valid", self.item.GetLabelText()
552 self.update_node_valid()
554 self.treeParent.update_valid()
558 def update_texte(self):
559 """ Met a jour les noms des SD et valeurs des mots-cles """
560 #print "NODE update_texte", self.item.GetLabelText()
561 self.update_node_texte()
562 if self.isExpanded() :
563 for child in self.children:
564 if child.isHidden() == false : child.update_texte()
567 def forceRecalculChildren(self,niveau):
568 if self.state=='recalcule' :
571 self.state='recalcule'
572 if hasattr(self.item,'object'):
573 self.item.object.state="modified"
574 for child in self.children:
575 if niveau > 0 : child.forceRecalculChildren(niveau - 1)
579 def doPaste(self,node_selected,pos='after'):
581 Déclenche la copie de l'objet item avec pour cible
582 l'objet passé en argument : node_selected
584 #print 'je passe dans doPaste'
585 objet_a_copier = self.item.get_copie_objet()
586 child=node_selected.doPasteCommande(objet_a_copier,pos)
589 def doPasteCommande(self,objet_a_copier,pos='after'):
591 Réalise la copie de l'objet passé en argument qui est nécessairement
596 child = self.append_brother(objet_a_copier,pos)
601 def doPastePremier(self,objet_a_copier):
603 Réalise la copie de l'objet passé en argument (objet_a_copier)
605 objet = objet_a_copier.item.get_copie_objet()
606 child = self.append_child(objet,pos='first')
609 def plieToutEtReaffiche(self):
610 self.editor.deplier = False
611 for item in self.children :
613 self.affichePanneau()
615 def deplieToutEtReaffiche(self):
616 self.editor.deplier = True
617 for item in self.children :
619 self.affichePanneau()
623 self.setPlieChildren()
625 def setPlieChildren(self):
626 self.appartientAUnNoeudPlie=True
627 for item in self.children :
628 item.setPlieChildren()
632 self.setDeplieChildren()
634 def setDeplieChildren(self):
635 self.appartientAUnNoeudPlie=False
636 for item in self.children :
637 item.setDeplieChildren()