Salome HOME
Modif V6_4_°
[tools/eficas.git] / Aster / Cata / cataSTA10 / SD / co_table.py
1 #@ MODIF co_table SD  DATE 30/06/2009   AUTEUR COURTOIS M.COURTOIS 
2 # -*- coding: iso-8859-1 -*-
3 #            CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2007  EDF R&D                  WWW.CODE-ASTER.ORG
6 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY  
7 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY  
8 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR     
9 # (AT YOUR OPTION) ANY LATER VERSION.                                                  
10 #                                                                       
11 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT   
12 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF            
13 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU      
14 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.                              
15 #                                                                       
16 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE     
17 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,         
18 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.        
19 # ======================================================================
20
21 import Accas
22 from SD import *
23 from sd_table import sd_table
24
25 # -----------------------------------------------------------------------------
26 class table_sdaster(ASSD, sd_table):
27    def __getitem__(self,key):
28       from Utilitai.Utmess import UTMESS
29       if not self.accessible():
30          raise Accas.AsException("Erreur dans table.__getitem__ en PAR_LOT='OUI'")
31       requete = '%-24s' % key[0]
32       tblp = '%-19s.TBLP' % self.get_name()
33       tabnom = aster.getvectjev(tblp)
34       #tabnom = self.TBLP.get()
35       if tabnom == None:
36          UTMESS('F','SDVERI_2',valk=[tblp])
37       for i in range(len(tabnom)) :
38          if tabnom[i]==requete: break
39       resu=aster.getvectjev(tabnom[i+2])
40       if resu == None:
41          UTMESS('F','SDVERI_2',valk=[tabnom[i+2]])
42       exist=aster.getvectjev(tabnom[i+3])
43       if exist == None:
44          UTMESS('F','SDVERI_2',valk=[tabnom[i+3]])
45       if key[1]>len(resu) or exist[key[1]-1]==0:
46          raise KeyError
47       else:
48          return resu[key[1]-1]
49
50    def TITRE(self):
51       """Retourne le titre d'une table Aster
52       (Utile pour récupérer le titre et uniquement le titre d'une table dont
53       on souhaite manipuler la dérivée).
54       """
55       if not self.accessible():
56          raise Accas.AsException("Erreur dans table.TITRE en PAR_LOT='OUI'")
57       titj = aster.getvectjev('%-19s.TITR' % self.get_name())
58       #titj = self.TITR.get()
59       if titj != None:
60          titr = '\n'.join(titj)
61       else:
62          titr = ''
63       return titr
64
65    def EXTR_TABLE(self) :
66       """Produit un objet Table à partir du contenu d'une table Aster
67       """
68       def Nonefy(l1,l2) :
69           if l2==0 : return None
70           else     : return l1
71       if not self.accessible():
72          raise Accas.AsException("Erreur dans table.EXTR_TABLE en PAR_LOT='OUI'")
73       from Utilitai.Table import Table
74       # titre
75       titr = self.TITRE()
76       # récupération des paramètres
77       v_tblp = aster.getvectjev('%-19s.TBLP' % self.get_name())
78       #v_tblp = self.TBLP.get()
79       if v_tblp == None:
80          # retourne une table vide
81          return Table(titr=titr)
82       tabnom=list(v_tblp)
83       nparam=len(tabnom)/4
84       lparam=[tabnom[4*i:4*i+4] for i in range(nparam)]
85       dval={}
86       # liste des paramètres et des types
87       lpar=[]
88       ltyp=[]
89       for i in lparam :
90          value=list(aster.getvectjev(i[2]))
91          exist=aster.getvectjev(i[3])
92          dval[i[0].strip()] = map(Nonefy,value,exist)
93          lpar.append(i[0].strip())
94          ltyp.append(i[1].strip())
95       n=len(dval[lpar[0]])
96       # contenu : liste de dict
97       lisdic=[]
98       for i in range(n) :
99         d={}
100         for p in lpar:
101            d[p]=dval[p][i]
102         lisdic.append(d)
103       return Table(lisdic, lpar, ltyp, titr)
104
105 # -----------------------------------------------------------------------------
106 class table_fonction(table_sdaster):
107    """Table contenant en plus une colonne FONCTION et/ou FONCTION_C dont les
108    valeurs des cellules sont des noms de fonction_sdaster ou fonction_c.
109    """
110
111 # -----------------------------------------------------------------------------
112 class table_jeveux(table_sdaster):
113    """Classe permettant d'accéder à une table jeveux qui n'a pas d'ASSD associée,
114    c'est le cas des concepts résultats (table, evol_xxxx) dérivés."""
115    def __init__(self, nom_jeveux):
116       self.nom = nom_jeveux
117       AsBase.__init__(self, nomj=self.nom)