Salome HOME
QString et ses amis
[tools/eficas.git] / InterfaceQT4 / compojdc.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 Editeur import Objecttreeitem
22 import browser
23 import typeNode
24 from Extensions.i18n import tr
25
26
27 class Node(browser.JDCNode,typeNode.PopUpMenuRacine):
28
29     def getPanel(self):
30         from monChoixCommande import MonChoixCommande
31         return MonChoixCommande(self,self.item, self.editor)
32         
33
34     def createPopUpMenu(self):
35         typeNode.PopUpMenuRacine.createPopUpMenu(self)
36
37     def addParameters(self,apres):
38         param=self.append_child("PARAMETRE",pos=0)
39         return param
40        
41
42
43 class JDCTreeItem(Objecttreeitem.ObjectTreeItem):
44   itemNode=Node
45   
46   def IsExpandable(self):
47     return 1
48
49   def GetText(self):
50       return  "    "
51
52   def GetLabelText(self):
53       # None --> fonte et couleur par defaut
54       return tr(self.object.nom),None,None
55
56   def get_jdc(self):
57     """
58     Retourne l'objet pointe par self
59     """
60     return self.object
61   
62   def GetIconName(self):
63     if self.object.isvalid():
64       return "ast-green-square"
65     else:
66       return "ast-red-square"
67
68   def keys(self):
69       if self.object.etapes_niveaux != []:
70           return range(len(self.object.etapes_niveaux))
71       else:
72           return range(len(self.object.etapes))
73
74   def additem(self,name,pos):
75       cmd = self._object.addentite(name,pos)
76       return cmd
77
78   def suppitem(self,item) :
79     # item             = item de l'ETAPE a supprimer du JDC
80     # item.getObject() = ETAPE ou COMMENTAIRE
81     # self.object      = JDC
82
83     itemobject=item.getObject()
84     if self.object.suppentite(itemobject):
85        if itemobject.nature == "COMMENTAIRE" :
86           message = tr("Commentaire supprime")
87        else :
88           message = tr("Commande %s supprimee",itemobject.nom)
89        return 1,message
90     else:
91        message=tr("Pb interne : impossible de supprimer cet objet")
92        return 0,message
93
94   def GetSubList(self):
95     """
96        Retourne la liste des items fils de l'item jdc.
97        Cette liste est conservee et mise a jour a chaque appel
98     """
99     if self.object.etapes_niveaux != []:
100         liste = self.object.etapes_niveaux
101     else:
102         liste = self.object.etapes
103     sublist=[None]*len(liste)
104     # suppression des items lies aux objets disparus
105     for item in self.sublist:
106        old_obj=item.getObject()
107        if old_obj in liste:
108           pos=liste.index(old_obj)
109           sublist[pos]=item
110        else:
111           pass # objets supprimes ignores
112     # ajout des items lies aux nouveaux objets
113     pos=0
114     for obj in liste:
115        if sublist[pos] is None:
116           # nouvel objet : on cree un nouvel item
117           item = self.make_objecttreeitem(self.appli, obj.nom + " : ", obj)
118           sublist[pos]=item
119        pos=pos+1
120
121     self.sublist=sublist
122     return self.sublist
123
124   def get_l_noms_etapes(self):
125       """ Retourne la liste des noms des etapes de self.object"""
126       return self.object.get_l_noms_etapes()
127
128   def get_liste_cmd(self):
129       listeCmd = self.object.niveau.definition.get_liste_cmd()
130       return listeCmd
131
132 import Accas
133 treeitem =JDCTreeItem
134 objet = Accas.JDC