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
27 from Extensions.i18n import tr
29 from Editeur import Objecttreeitem
30 from Noyau.N_OBJECT import ErrorObj
33 class Node(browser.JDCNode,typeNode.PopUpMenuNodeMinimal):
37 if self.item.isMCList() :
38 if self.item.ajout_possible():
39 from monMCListAjoutPanel import MonMCListAjoutPanel
40 return MonMCListAjoutPanel(self,parent=self.editor)
43 elif self.item.isMCFact() :
44 from monMCFactPanel import MonMCFactPanel
45 return MonMCFactPanel(self,parent=self.editor)
49 def createPopUpMenu(self):
50 typeNode.PopUpMenuNodeMinimal.createPopUpMenu(self)
52 def getPanelGroupe(self,parentQt):
53 maDefinition=self.item.get_definition()
54 monObjet=self.item.object
56 if hasattr(parentQt,'niveau'): self.niveau=parentQt.niveau+1
58 if not (monObjet.isMCList()) :
59 if hasattr(self,'plie') and self.plie==True :
60 from monWidgetFactPlie import MonWidgetFactPlie
61 widget=MonWidgetFactPlie(self,self.editor,parentQt,maDefinition,monObjet,self.niveau)
63 from monWidgetFact import MonWidgetFact
64 widget=MonWidgetFact(self,self.editor,parentQt,maDefinition,monObjet,self.niveau)
66 from monWidgetBloc import MonWidgetBloc
67 widget=MonWidgetBloc(self,self.editor,parentQt,maDefinition,monObjet,self.niveau)
71 #def doPaste(self,node_selected):
72 # objet_a_copier = self.item.get_copie_objet()
73 # child=node_selected.doPasteMCF(objet_a_copier)
74 #print "doPaste",child
77 #def doPasteMCF(self,objet_a_copier):
79 # le noeud courant est une MCList
80 # if self.item.isMCList() :
81 # child = self.append_child(objet_a_copier,pos='first',retour='oui')
83 # le noeud courant est un MCFACT
84 # elif self.item.isMCFact() :
85 # le noeud selectionne est un MCFACT dans une MCList
86 # if self.parent.item.isMCList():
87 # child = self.parent.append_child(objet_a_copier, pos=self.item, retour='oui')
89 # le noeud MCFACT selectionne n'est pas dans une MCList
91 # child = self.parent.append_child(objet_a_copier,retour='oui')
94 # QMessageBox.information( self, "Copie impossible",
95 # "Vous ne pouvez coller le mot-clé facteur copié à ce niveau de l'arborescence !")
96 # self.editor.affiche_infos("Copie refusée")
100 class MCListTreeItem(Objecttreeitem.SequenceTreeItem,compofact.FACTTreeItem):
101 """ La classe MCListTreeItem joue le role d'un adaptateur pour les objets
102 du noyau Accas instances de la classe MCLIST.
103 Elle adapte ces objets pour leur permettre d'etre intégrés en tant que
104 noeuds dans un arbre graphique (voir treewidget.py et ObjectTreeItem.py).
105 Cette classe délègue les appels de méthode et les accès
106 aux attributs à l'objet du noyau soit manuellement soit
107 automatiquement (voir classe Delegate et attribut object).
112 # Si l'objet Accas (MCList) a moins d'un mot cle facteur
113 # on utilise directement ce mot cle facteur comme delegue
114 self.updateDelegate()
116 def updateDelegate(self):
117 if len(self._object) > 1:
118 self.setdelegate(self._object)
120 self.setdelegate(self._object.data[0])
122 def panel(self,jdcdisplay,pane,node):
123 """ Retourne une instance de l'objet panneau associe a l'item (self)
124 Si la liste ne contient qu'un mot clé facteur, on utilise le panneau
126 Si la liste est plus longue on utilise le panneau MCLISTPanel.
128 if len(self._object) > 1:
129 return MCLISTPanel(jdcdisplay,pane,node)
130 elif isinstance(self._object.data[0],ErrorObj):
131 return compoerror.ERRORPanel(jdcdisplay,pane,node)
133 return compofact.FACTPanel(jdcdisplay,pane,node)
135 def IsExpandable(self):
136 if len(self._object) > 1:
137 return Objecttreeitem.SequenceTreeItem.IsExpandable(self)
139 return compofact.FACTTreeItem.IsExpandable(self)
141 def GetSubList(self):
142 self.updateDelegate()
143 if len(self._object) <= 1:
144 self._object.data[0].alt_parent=self._object
145 return compofact.FACTTreeItem.GetSubList(self)
147 liste=self._object.data
148 sublist=[None]*len(liste)
149 # suppression des items lies aux objets disparus
150 for item in self.sublist:
151 old_obj=item.getObject()
153 pos=liste.index(old_obj)
156 pass # objets supprimes ignores
157 # ajout des items lies aux nouveaux objets
160 if sublist[pos] is None:
161 # nouvel objet : on cree un nouvel item
162 def setfunction(value, object=obj):
164 item = self.make_objecttreeitem(self.appli, obj.nom + " : ", obj, setfunction)
166 #Attention : on ajoute une information supplementaire pour l'actualisation de
167 # la validite. L'attribut parent d'un MCFACT pointe sur le parent de la MCLISTE
168 # et pas sur la MCLISTE elle meme ce qui rompt la chaine de remontee des
169 # informations de validite. alt_parent permet de remedier a ce defaut.
170 obj.alt_parent=self._object
176 def GetIconName(self):
177 if self._object.isvalid():
178 return "ast-green-los"
179 elif self._object.isoblig():
185 """ Retourne la clef de doc de l'objet pointé par self """
186 return self.object.get_docu()
188 def iscopiable(self):
189 if len(self._object) > 1:
190 return Objecttreeitem.SequenceTreeItem.iscopiable(self)
192 return compofact.FACTTreeItem.iscopiable(self)
196 Retourne 1 si l'objet pointé par self est un MCFact, 0 sinon
198 return len(self._object) <= 1
202 Retourne 1 si l'objet pointé par self est une MCList, 0 sinon
204 return len(self._object) > 1
206 def get_copie_objet(self):
207 return self._object.data[0].copy()
209 def additem(self,obj,pos):
210 #print "compomclist.additem",obj,pos
211 if len(self._object) <= 1:
212 return compofact.FACTTreeItem.additem(self,obj,pos)
214 o= self.object.addentite(obj,pos)
217 def suppitem(self,item):
219 Retire un objet MCFACT de la MCList (self.object)
221 #print "compomclist.suppitem",item
223 if len(self._object) <= 1:
224 return compofact.FACTTreeItem.suppitem(self,item)
226 if self.object.suppentite(obj):
227 if len(self._object) == 1: self.updateDelegate()
228 message = "Mot-clef " + obj.nom + " supprime"
229 self.appli.affiche_infos(message)
232 self.appli.affiche_infos(tr('Impossible de supprimer ce mot-clef'),Qt.red)
239 def treeitem(appli,labeltext,object,setfunction):
240 """ Factory qui produit un objet treeitem adapte a un objet
241 Accas.MCList (attribut objet de ce module)
243 return MCListTreeItem(appli,labeltext,object,setfunction)