]> SALOME platform Git repositories - tools/eficas.git/blob - InterfaceQT4/compofact.py
Salome HOME
Plie/Deplie MT
[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,insertIn=-1):
34         import traceback
35         maDefinition=self.item.get_definition()
36         monObjet=self.item.object
37         monNom=self.item.nom
38         maCommande=commande
39         if hasattr(parentQt,'niveau'): self.niveau=parentQt.niveau+1
40         else : self.niveau=1
41         #if  hasattr(self,'plie') :print self.item.nom, self.plie
42         #if maDefinition.sensLayout == 'horizontal':
43         #   from .monWidgetFact import MonWidgetFactHorizontal
44         #   widget=MonWidgetFactHorizontal(self,self.editor,parentQt,maDefinition,monObjet,self.niveau,maCommande)
45         #elif  hasattr(self,'plie') and self.plie==True : 
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,insertIn)
49         else:
50            from .monWidgetFact import MonWidgetFact
51            widget=MonWidgetFact(self,self.editor,parentQt,maDefinition,monObjet,self.niveau,maCommande,insertIn)
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       if not(hasattr(self.object,'getlabeltext')): return self.object.nom,None,None
76       return self.object.getlabeltext(),None,None
77
78   def isvalid(self):
79     return self.object.isvalid()
80
81   def iscopiable(self):
82     return 1
83
84   def GetIconName(self):
85     if self.object.isvalid():
86       return "ast-green-los"
87     elif self.object.isoblig():
88       return "ast-red-los"
89     else:
90       return "ast-yel-los"
91
92   #PNPN ????
93   #def keys(self):
94   #  keys=self.object.mc_dict
95   #  return keys
96
97   def GetSubList(self):
98       """
99          Reactualise la liste des items fils stockes dans self.sublist
100       """
101       liste=self.object.mc_liste
102       sublist=[None]*len(liste)
103       # suppression des items lies aux objets disparus
104       for item in self.sublist:
105          old_obj=item.getObject()
106          if old_obj in liste:
107             pos=liste.index(old_obj)
108             sublist[pos]=item
109          else:
110             pass # objets supprimes ignores
111       # ajout des items lies aux nouveaux objets
112       pos=0
113       for obj in liste:
114          if sublist[pos] is None:
115             # nouvel objet : on cree un nouvel item
116             def setfunction(value, object=obj):
117                 object.setval(value)
118             item = self.make_objecttreeitem(self.appli, obj.nom + " : ", obj, setfunction)
119             sublist[pos]=item
120          pos=pos+1
121
122       self.sublist=sublist
123       return self.sublist
124
125   def additem(self,name,pos):
126     objet = self.object.addentite(name,pos)
127     return objet
128
129   def suppitem(self,item) :
130       """ 
131          Cette methode a pour fonction de supprimer l'item passee en argument
132          des fils de l'item FACT qui est son pere
133            - item = item du MOCLE a supprimer du MOCLE pere
134            - item.getObject() = MCSIMP ou MCBLOC 
135       """
136       itemobject=item.getObject()
137       if itemobject.isoblig() :
138          #self.editor.affiche_infos(tr('Impossible de supprimer un mot-cle obligatoire '),Qt.red)
139          return (0, tr('Impossible de supprimer un mot-cle obligatoire '))
140
141       if self.object.suppentite(itemobject):
142          message = tr("Mot-cle %s supprime")+ six.text_type(itemobject.nom)
143          #self.editor.affiche_commentaire(message)
144          return (1, message)
145       else:
146          #self.editor.affiche_infos(tr('Pb interne : impossible de supprimer ce mot-cle'),Qt.red)
147          return (0,tr('Pb interne : impossible de supprimer ce mot-cle'))
148
149 import Accas
150 objet = Accas.MCFACT
151 treeitem = FACTTreeItem