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 item.affichePanneau()
103 self.expandItem(item)
105 def choisitPremier(self,name):
106 self.editor.layoutJDCCHOIX.removeWidget(self.racine.fenetre)
107 self.racine.fenetre.close()
108 new_node=self.racine.append_brother(name,'after')
111 COMMENT = "COMMENTAIRE"
112 PARAMETERS = "PARAMETRE"
114 class JDCNode(QTreeWidgetItem):
115 def __init__( self, treeParent, item):
116 #print "creation d'un noeud : ", item, " ",item.nom,"", treeParent
118 self.vraiParent = treeParent
119 self.treeParent = treeParent
120 self.tree = self.treeParent.tree
121 self.editor = self.treeParent.editor
122 self.appliEficas = treeParent.appliEficas
123 self.treeParent.childrenIssusDesBlocs=[]
124 self.childrenComplete=[]
126 name = self.appliEficas.trUtf8( str( item.GetLabelText()[0] ) )
127 value = self.appliEficas.trUtf8( str( item.GetText() ) )
128 mesColonnes=QStringList()
129 mesColonnes << name << value
130 from InterfaceQT4 import compobloc
132 ajoutAuParentduNoeud=0
133 while (isinstance(self.treeParent,compobloc.Node)) :
134 self.treeParent=self.treeParent.treeParent
135 ajoutAuParentduNoeud=1
136 if ajoutAuParentduNoeud :
137 treeParent.childrenComplete.append(self)
138 self.treeParent.childrenIssusDesBlocs.append(self)
139 while (isinstance(self.treeParent,compobloc.Node)) : self.treeParent=self.treeParent.treeParent
141 if isinstance(self,compobloc.Node) :
142 QTreeWidgetItem.__init__(self,None,mesColonnes)
144 QTreeWidgetItem.__init__(self,self.treeParent,mesColonnes)
145 self.treeParent.childrenComplete.append(self)
147 self.setToolTip(0,QString(self.item.get_fr()))
148 self.setToolTip(1,QString(self.item.get_fr()))
150 repIcon=QString(self.appliEficas.repIcon)
151 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
152 self.setIcon(0,monIcone)
155 self.build_children()
159 self.item.connect("valid",self.onValid,())
160 self.item.connect("supp" ,self.onSupp,())
161 self.item.connect("add" ,self.onAdd,())
165 if self.item.getObject().isBLOC() : self.setExpanded(True)
170 def build_children(self,posInsertion=10000):
171 """ Construit la liste des enfants de self """
172 """ Se charge de remettre les noeuds Expanded dans le meme etat """
173 #print "*********** build_children ",self.item, self.item.GetLabelText()
174 #print self.childrenComplete
177 for item in self.childrenComplete :
179 # print " je detruis ", item.item.GetLabelText() ," parent : ", item.treeParent.item.GetLabelText()
181 # print "mot clef fact"
182 if item.isExpanded():
183 if self.childrenComplete.index(item) < posInsertion :
184 listeExpanded.append(self.childrenComplete.index(item))
186 listeExpanded.append( self.childrenComplete.index(item) +1)
187 self.detruit_les_noeuds_issus_de_blocs(item)
188 parent=item.treeParent
189 parent.removeChild(item)
192 sublist = self.item._GetSubList()
194 for item in sublist :
195 nouvelItem=item.itemNode(self,item)
196 self.children.append(nouvelItem)
197 #print " J ajoute ", nouvelItem ,nouvelItem.item.GetLabelText(),"dans" ,self.item.GetLabelText()
198 if ind in listeExpanded : nouvelItem.setExpanded(1)
200 #print "*********** fin build_children ",self.item, self.item.GetLabelText()
203 def affichePanneau(self) :
204 #print "affichePanneau pour" ,self.item.nom
206 if self.item.isactif():
207 panel=self.getPanel2()
209 from monInactifPanel import PanelInactif
210 panel = PanelInactif(self,self.editor)
211 if hasattr(self,'fenetre') and self.fenetre:
214 if self.editor.fenetreCentraleAffichee != None :
215 self.editor.fenetreCentraleAffichee.close()
216 self.editor.fenetreCentraleAffichee=panel
217 if self.editor.widgetTree !=None : index=1
219 self.editor.widgetCentraleLayout.addWidget(self.fenetre)
221 if self.editor.first :
222 self.editor.splitter.setSizes((400,1400,400))
223 if not(isinstance(self.fenetre,MonChoixCommande)): self.editor.first=False
224 self.tree.expandItem(self)
225 #print "fin affichePanneau"
228 def createPopUpMenu(self):
229 #implemente dans les noeuds derives si necessaire
234 Cette methode a pour but de commentariser la commande pointee par self
236 # On traite par une exception le cas ou l'utilisateur final cherche a désactiver
237 # (commentariser) un commentaire.
239 pos=self.treeParent.children.index(self)
240 commande_comment = self.item.get_objet_commentarise()
241 # On signale a l editeur du panel (le JDCDisplay) une modification
242 self.editor.init_modif()
243 self.treeParent.build_children()
244 self.treeParent.children[pos].select()
245 self.treeParent.children[pos].affichePanneau()
247 traceback.print_exc()
248 QMessageBox.critical( self.editor, "TOO BAD",str(e))
250 def unCommentIt(self):
252 Realise la decommentarisation de self
255 pos=self.treeParent.children.index(self)
256 commande,nom = self.item.uncomment()
257 self.editor.init_modif()
258 self.treeParent.build_children()
259 self.treeParent.children[pos].select()
260 self.treeParent.children[pos].affichePanneau()
262 QMessageBox.critical( self.editor, "Erreur !",str(e))
264 def addComment( self, after=True ):
266 Ajoute un commentaire a l'interieur du JDC :
268 self.editor.init_modif()
273 return self.append_brother( COMMENT, pos )
275 def addParameters( self, after=True ):
277 Ajoute un parametre a l'interieur du JDC :
279 self.editor.init_modif()
284 return self.append_brother( PARAMETERS, pos )
289 Rend le noeud courant (self) selectionne et deselectionne
292 for item in self.tree.selectedItems() :
294 #print "select -----------> " , self.item.GetLabelText()
295 self.setSelected( True )
296 self.setExpanded( True )
297 self.tree.setCurrentItem( self )
298 self.tree.node_selected= self
300 #------------------------------------------------------------------
301 # Methodes de creation et destruction de noeuds
302 # Certaines de ces methodes peuvent etre appelees depuis l'externe
303 #------------------------------------------------------------------
304 def append_brother(self,name,pos='after'):
306 Permet d'ajouter un objet frere a l'objet associe au noeud self
307 par defaut on l'ajoute immediatement apres
310 #print "*********** append_brother ", self.item.GetLabelText()
311 self.editor.init_modif()
312 index = self.treeParent.children.index(self)
318 print unicode(pos), tr(" n'est pas un index valide pour append_brother")
320 return self.treeParent.append_child(name,pos=index)
322 def append_child(self,name,pos=None):
324 Methode pour ajouter un objet fils a l'objet associe au noeud self.
325 On peut l'ajouter en debut de liste (pos='first'), en fin (pos='last')
326 ou en position intermediaire.
327 Si pos vaut None, on le place a la position du catalogue.
329 #print "************** append_child ",self.item.GetLabelText()
330 self.editor.init_modif()
334 index = len(self.children)
335 elif type(pos) == types.IntType :
338 elif type(pos) == types.InstanceType:
339 # pos est un item. Il faut inserer name apres pos
340 index = self.item.get_index(pos) +1
341 elif type(name) == types.InstanceType:
342 index = self.item.get_index_child(name.nom)
344 index = self.item.get_index_child(name)
345 obj=self.item.additem(name,index) #CS_pbruno emet le signal 'add'
348 ## PNPNPN : cas de Map nouvelle version
352 old_obj = self.item.object.get_child(name.nom,restreint = 'oui')
354 child.affichePanneau()
357 # Souci pour gerer les copies des AFFE d'une commande à l autre
359 child=self.children[index]
360 child.affichePanneau()
362 child=self.children[index]
367 self.editor.init_modif()
368 index = self.treeParent.children.index(self) - 1
369 if index < 0 : index =0
370 ret=self.treeParent.item.deplaceEntite(self.item.getObject())
374 Methode externe pour la destruction de l'objet associe au noeud
376 self.editor.init_modif()
377 index = self.vraiParent.children.index(self) - 1
378 if index < 0 : index =0
380 if self.item.nom == "VARIABLE" :
383 ret=self.vraiParent.item.suppitem(self.item)
384 self.treeParent.build_children()
385 if self.treeParent.childrenComplete : toselect=self.treeParent.childrenComplete[index]
386 else: toselect=self.treeParent
388 jdc.recalcule_etat_correlation()
390 #toselect.affichePanneau()
392 def deleteMultiple(self,liste=()):
394 Methode externe pour la destruction d une liste de noeud
396 from InterfaceQT4 import compojdc
397 self.editor.init_modif()
402 while not(isinstance(jdc,compojdc.Node)):
405 if not( isinstance(noeud.treeParent, compojdc.Node)): continue
406 if noeud.item.nom == "VARIABLE" : recalcule=1
407 if noeud.treeParent.children.index(noeud) < index : index=noeud.treeParent.children.index(noeud)
408 if index < 0 : index =0
410 # Cas ou on détruit dans une ETape
412 parentPosition=self.treeParent
413 while not(isinstance(parentPosition, compojdc.Node)):
414 index=parentPosition.treeParent.children.index(parentPosition)
415 parentPosition=parentPosition.treeParent
418 noeud.treeParent.item.suppitem(noeud.item)
421 if recalcule : jdc.recalcule_etat_correlation()
422 try : toselect=parentPosition.children[index]
423 except : toselect=jdc
425 toselect.affichePanneau()
427 # #------------------------------------------------------------------
430 if hasattr(self,'fenetre') and self.fenetre:
431 self.fenetre.setValide()
432 if self.item.nom == "VARIABLE" and self.item.isvalid():
433 self.item.jdc.recalcule_etat_correlation()
434 if hasattr(self.item,'forceRecalcul'):
435 self.forceRecalculChildren(self.item.forceRecalcul)
436 self.editor.init_modif()
438 self.update_node_valid()
439 self.update_node_label()
440 self.update_node_texte()
442 def onAdd(self,object):
443 #print "___________________________ onAdd", object
444 self.editor.init_modif()
447 def onSupp(self,object):
448 #print "___________________________ onSupp", self.item, self.item.GetLabelText()
449 self.editor.init_modif()
452 def detruit_les_noeuds_issus_de_blocs(self,bloc):
453 from InterfaceQT4 import compobloc
454 if (isinstance(bloc,compobloc.Node)) :
455 for node in bloc.childrenComplete :
456 self.detruit_les_noeuds_issus_de_blocs(node)
457 parent=node.treeParent
458 #print "je detruit " , node.item.GetLabelText()
459 parent.removeChild(node)
461 def update_node_valid(self):
462 """Cette methode remet a jour la validite du noeud (icone)
465 repIcon=QString(self.appliEficas.repIcon)
466 monIcone = QIcon(repIcon+"/" +self.item.GetIconName() + ".png")
467 self.setIcon(0,monIcone)
470 def update_node_label(self):
471 """ Met a jour le label du noeud """
472 #print "NODE update_node_label", self.item.GetLabelText()
473 labeltext,fonte,couleur = self.item.GetLabelText()
475 #self.setText(0, labeltext)
478 def update_node_label_in_blue(self):
479 if hasattr(self.appliEficas,'noeudColore'):
480 self.appliEficas.noeudColore.setTextColor( 0,Qt.black)
481 self.appliEficas.noeudColore.update_node_label()
482 self.setTextColor( 0,Qt.blue )
483 labeltext,fonte,couleur = self.item.GetLabelText()
484 self.setText(0, labeltext)
485 self.appliEficas.noeudColore=self
487 def update_plusieurs_node_label_in_blue(self,liste):
488 if hasattr(self.appliEficas,'listeNoeudsColores'):
489 for noeud in self.appliEficas.listeNoeudsColores:
490 noeud.setTextColor( 0,Qt.black)
491 noeud.update_node_label()
492 self.appliEficas.listeNoeudsColores=[]
494 noeud.setTextColor( 0,Qt.blue )
495 labeltext,fonte,couleur = noeud.item.GetLabelText()
496 noeud.setText(0, labeltext)
497 self.appliEficas.listeNoeudsColores.append(noeud)
499 def update_node_texte_in_black(self):
500 """ Met a jour les noms des SD et valeurs des mots-cles """
501 self.setTextColor( 1,Qt.black )
502 value = self.item.GetText()
503 self.setText(1, value)
505 def update_node_texte(self):
506 """ Met a jour les noms des SD et valeurs des mots-cles """
507 value = self.item.GetText()
508 self.setText(1, value)
510 def update_node_texte_in_blue(self):
511 self.setTextColor( 1,Qt.blue )
512 value = self.item.GetText()
513 self.setText(1, value)
515 def update_nodes(self):
516 #print 'NODE update_nodes', self.item.GetLabelText()
517 self.build_children()
519 def update_valid(self) :
520 """Cette methode a pour but de mettre a jour la validite du noeud
521 et de propager la demande de mise a jour a son parent
523 #print "NODE update_valid", self.item.GetLabelText()
524 self.update_node_valid()
526 self.treeParent.update_valid()
530 def update_texte(self):
531 """ Met a jour les noms des SD et valeurs des mots-cles """
532 #print "NODE update_texte", self.item.GetLabelText()
533 self.update_node_texte()
534 if self.isExpanded() :
535 for child in self.children:
536 if child.isHidden() == false : child.update_texte()
539 def forceRecalculChildren(self,niveau):
540 if self.state=='recalcule' :
543 self.state='recalcule'
544 if hasattr(self.item,'object'):
545 self.item.object.state="modified"
546 for child in self.children:
547 if niveau > 0 : child.forceRecalculChildren(niveau - 1)
551 def doPaste(self,node_selected,pos='after'):
553 Déclenche la copie de l'objet item avec pour cible
554 l'objet passé en argument : node_selected
556 #print 'je passe dans doPaste'
557 objet_a_copier = self.item.get_copie_objet()
558 child=node_selected.doPasteCommande(objet_a_copier,pos)
561 def doPasteCommande(self,objet_a_copier,pos='after'):
563 Réalise la copie de l'objet passé en argument qui est nécessairement
568 child = self.append_brother(objet_a_copier,pos)
573 def doPastePremier(self,objet_a_copier):
575 Réalise la copie de l'objet passé en argument (objet_a_copier)
577 objet = objet_a_copier.item.get_copie_objet()
578 child = self.append_child(objet,pos='first')
583 self.setPlieChildren()
585 def setPlieChildren(self):
586 self.appartientAUnNoeudPlie=True
587 for item in self.children :
588 item.setPlieChildren()
593 self.setDeplieChildren()
595 def setDeplieChildren(self):
596 self.appartientAUnNoeudPlie=False
597 for item in self.children :
598 item.setDeplieChildren()