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