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