1 #@ MODIF N_FONCTION Noyau DATE 28/06/2011 AUTEUR COURTOIS M.COURTOIS
2 # -*- coding: iso-8859-1 -*-
3 # RESPONSABLE COURTOIS M.COURTOIS
4 # CONFIGURATION MANAGEMENT OF EDF VERSION
5 # ======================================================================
6 # COPYRIGHT (C) 1991 - 2011 EDF R&D WWW.CODE-ASTER.ORG
7 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
8 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
9 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
10 # (AT YOUR OPTION) ANY LATER VERSION.
12 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
13 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
14 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
15 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
17 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
18 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
19 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
22 # ======================================================================
24 # Attention : cet import permet d'avoir, en Python, le comportement
25 # de la division réelle pour les entiers, et non la division entière
26 # 1/2=0.5 (et non 0). Comportement par défaut dans Python 3.0.
27 from __future__ import division
29 from N_ASSD import ASSD
30 from N_info import message, SUPERV
36 def __init__(self, *args, **kwargs):
37 ASSD.__init__(self, *args, **kwargs)
39 self.expression = None
41 def __call__(self, *val):
43 # cas de INCLUDE (ou POURSUITE dans Eficas)
44 context.update(getattr(self.parent, 'contexte_fichier_init', {}))
45 # récupération des constantes locales en cas de MACRO
46 context.update(getattr(self.parent, 'macro_const_context', {}))
47 for param, value in zip(self.nompar, val):
48 context[param] = value
50 res = eval(self.expression, self.jdc.const_context, context)
51 except Exception, exc:
52 message.error(SUPERV, "ERREUR LORS DE L'ÉVALUATION DE LA FORMULE '%s' " \
53 ":\n>> %s",self.nom, str(exc))
57 def setFormule(self, nom_para, texte):
58 """Cette methode sert a initialiser les attributs
59 nompar, expression et code qui sont utilisés
60 dans l'évaluation de la formule."""
61 self.nompar = nom_para
62 self.expression = texte
64 self.code = compile(texte, texte, 'eval')
65 except SyntaxError, exc:
66 message.error(SUPERV, "ERREUR LORS DE LA CREATION DE LA FORMULE '%s' " \
67 ":\n>> %s", self.nom, str(exc))
70 def __setstate__(self,state):
71 """Cette methode sert a restaurer l'attribut code lors d'un unpickle."""
72 self.__dict__.update(state) # update attributes
73 self.setFormule(self.nompar, self.expression) # restore code attribute
75 def __getstate__(self):
76 """Pour les formules, il faut enlever l'attribut code qui n'est
78 d = ASSD.__getstate__(self)
83 """Equivalent de fonction.Parametres pour pouvoir utiliser des formules
84 à la place de fonctions dans certaines macro-commandes.
86 from SD.sd_fonction import sd_formule
87 from Utilitai.Utmess import UTMESS
89 TypeProl={ 'E':'EXCLU', 'L':'LINEAIRE', 'C':'CONSTANT', 'I':'INTERPRE' }
90 sd = sd_formule(self.get_name())
93 if prol is None or nova is None:
94 UTMESS('F', 'SDVERI_2', valk=[objev])
96 'INTERPOL' : ['LIN','LIN'],
97 'NOM_PARA' : [s.strip() for s in nova],
98 'NOM_RESU' : prol[3][0:16].strip(),
99 'PROL_DROITE' : TypeProl['E'],
100 'PROL_GAUCHE' : TypeProl['E'],
103 raise Accas.AsException("Erreur dans fonction.Parametres en PAR_LOT='OUI'")
107 class formule_c(formule):