Salome HOME
c34e700b21563f152317381a9bb037f24b09cc2a
[tools/eficas.git] / InterfaceQT4 / compofact.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 from PyQt4 import *
22 from PyQt4.QtGui  import *
23 from PyQt4.QtCore import *
24 import browser
25 import typeNode
26 from Extensions.i18n import tr
27
28
29 from Editeur import Objecttreeitem
30
31
32 class Node(browser.JDCNode,typeNode.PopUpMenuNodePartiel):
33     def getPanel(self):
34         """
35         """
36         from monMCFactPanel import MonMCFactPanel
37         return MonMCFactPanel(self,parent=self.editor) 
38
39     def getPanelGroupe(self,parentQt,commande):
40         maDefinition=self.item.get_definition()
41         monObjet=self.item.object
42         monNom=self.item.nom
43         maCommande=commande
44         if hasattr(parentQt,'niveau'): self.niveau=parentQt.niveau+1
45         else : self.niveau=1
46         if  hasattr(self,'plie') and self.plie==True : 
47            from monWidgetFactPlie import MonWidgetFactPlie
48            widget=MonWidgetFactPlie(self,self.editor,parentQt,maDefinition,monObjet,self.niveau,maCommande)
49         else:
50            from monWidgetFact import MonWidgetFact
51            widget=MonWidgetFact(self,self.editor,parentQt,maDefinition,monObjet,self.niveau,maCommande)
52         return widget
53
54
55     def createPopUpMenu(self):
56         typeNode.PopUpMenuNodeMinimal.createPopUpMenu(self)
57
58
59 class FACTTreeItem(Objecttreeitem.ObjectTreeItem):
60   itemNode=Node
61   
62   def IsExpandable(self):
63     return 1
64
65   def GetText(self):
66       return  ''
67
68   def GetLabelText(self):
69       """ Retourne 3 valeurs :
70         - le texte à afficher dans le noeud representant l'item
71         - la fonte dans laquelle afficher ce texte
72         - la couleur du texte
73       """
74       # None --> fonte et couleur par defaut
75       return self.object.getlabeltext(),None,None
76
77   def isvalid(self):
78     return self.object.isvalid()
79
80   def iscopiable(self):
81     return 1
82
83   def GetIconName(self):
84     if self.object.isvalid():
85       return "ast-green-los"
86     elif self.object.isoblig():
87       return "ast-red-los"
88     else:
89       return "ast-yel-los"
90
91   def keys(self):
92     keys=self.object.mc_dict.keys()
93     return keys
94
95   def GetSubList(self):
96       """
97          Reactualise la liste des items fils stockes dans self.sublist
98       """
99       liste=self.object.mc_liste
100       sublist=[None]*len(liste)
101       # suppression des items lies aux objets disparus
102       for item in self.sublist:
103          old_obj=item.getObject()
104          if old_obj in liste:
105             pos=liste.index(old_obj)
106             sublist[pos]=item
107          else:
108             pass # objets supprimes ignores
109       # ajout des items lies aux nouveaux objets
110       pos=0
111       for obj in liste:
112          if sublist[pos] is None:
113             # nouvel objet : on cree un nouvel item
114             def setfunction(value, object=obj):
115                 object.setval(value)
116             item = self.make_objecttreeitem(self.appli, obj.nom + " : ", obj, setfunction)
117             sublist[pos]=item
118          pos=pos+1
119
120       self.sublist=sublist
121       return self.sublist
122
123   def additem(self,name,pos):
124     objet = self.object.addentite(name,pos)
125     return objet
126
127   def suppitem(self,item) :
128       """ 
129          Cette methode a pour fonction de supprimer l'item passee en argument
130          des fils de l'item FACT qui est son pere
131            - item = item du MOCLE a supprimer du MOCLE pere
132            - item.getObject() = MCSIMP ou MCBLOC 
133       """
134       itemobject=item.getObject()
135       if itemobject.isoblig() :
136          self.editor.affiche_infos(tr('Impossible de supprimer un mot-cle obligatoire '),Qt.red)
137          return 0
138
139       if self.object.suppentite(itemobject):
140          message = tr("Mot-cle %s supprime")+ unicode(itemobject.nom)
141          self.editor.affiche_commentaire(message)
142          return 1
143       else:
144          self.editor.affiche_infos(tr('Pb interne : impossible de supprimer ce mot-cle'),Qt.red)
145          return 0
146
147 import Accas
148 objet = Accas.MCFACT
149 treeitem = FACTTreeItem