X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Noyau%2FN_FONCTION.py;h=ccdf3786f828822a4c6e7351232cf5e1bb9cdee3;hb=a7d5f18fe322c770026b50343adc09ed0472c192;hp=21caeec18fb140cdd60675d5841d0cd122f9ef15;hpb=860a50d7df32b5c86f9ab536178d030ea882cae5;p=tools%2Feficas.git diff --git a/Noyau/N_FONCTION.py b/Noyau/N_FONCTION.py index 21caeec1..ccdf3786 100644 --- a/Noyau/N_FONCTION.py +++ b/Noyau/N_FONCTION.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- -#@ MODIF N_FONCTION Noyau DATE 11/03/2003 AUTEUR DURAND C.DURAND +#@ MODIF N_FONCTION Noyau DATE 17/05/2005 AUTEUR DURAND C.DURAND +# -*- coding: iso-8859-1 -*- # CONFIGURATION MANAGEMENT OF EDF VERSION # ====================================================================== # COPYRIGHT (C) 1991 - 2002 EDF R&D WWW.CODE-ASTER.ORG @@ -19,8 +19,65 @@ # # # ====================================================================== + from N_ASSD import ASSD +import string class FONCTION(ASSD):pass -class formule(FONCTION) : pass +class formule(ASSD): + def __init__(self,**args): + ASSD.__init__(self,**args) + self.nompar =None + self.expression=None + + def __call__(self,*val): + if hasattr(self.parent,'contexte_fichier_init'): + context=self.parent.contexte_fichier_init + else : context={} + i=0 + for param in self.nompar : + context[param]=val[i] + i=i+1 + try : + res=eval(self.expression,self.jdc.const_context, context) + except : + print 75*'!' + print '! '+string.ljust('Erreur evaluation formule '+self.nom,72)+'!' + print 75*'!' + raise + return res + + def setFormule(self,nom_para,texte): + """ + Cette methode sert a initialiser les attributs + nompar, expression et code qui sont utilisés + dans l'évaluation de la formule + """ + self.nompar = nom_para + self.expression = texte + try : + self.code=compile(texte,texte,'eval') + except SyntaxError : + print 75*'!' + print '! '+string.ljust('Erreur evaluation formule '+self.nom,72)+'!' + print 75*'!' + raise + + def __setstate__(self,state): + """ + Cette methode sert a restaurer l'attribut code + lors d'un unpickle + """ + self.__dict__.update(state) # update attributes + self.setFormule(self.nompar,self.expression) # restore code attribute + + def __getstate__(self): + """ + Pour les formules, il faut enlever l'attribut code + qui n'est pas picklable + """ + d=ASSD.__getstate__(self) + del d['code'] + return d +