X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Noyau%2FN_FONCTION.py;h=2fb52b665a79f0d86bdc3394d1aa4efa2231b430;hb=2c5a8689b9c6cc46804fd268d416d1de2777059e;hp=971af63625f244b3cc36ce71d77f8092d4295e8e;hpb=cdd358f4041f957701ac10d86766a85baaef4f78;p=tools%2Feficas.git diff --git a/Noyau/N_FONCTION.py b/Noyau/N_FONCTION.py index 971af636..2fb52b66 100644 --- a/Noyau/N_FONCTION.py +++ b/Noyau/N_FONCTION.py @@ -1,30 +1,29 @@ -#@ MODIF N_FONCTION Noyau DATE 28/06/2011 AUTEUR COURTOIS M.COURTOIS # -*- coding: iso-8859-1 -*- -# RESPONSABLE COURTOIS M.COURTOIS -# CONFIGURATION MANAGEMENT OF EDF VERSION -# ====================================================================== -# COPYRIGHT (C) 1991 - 2011 EDF R&D WWW.CODE-ASTER.ORG -# THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY -# IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY -# THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR -# (AT YOUR OPTION) ANY LATER VERSION. +# Copyright (C) 2007-2013 EDF R&D # -# THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT -# WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF -# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU -# GENERAL PUBLIC LICENSE FOR MORE DETAILS. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. # -# YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE -# ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER, -# 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# ====================================================================== # Attention : cet import permet d'avoir, en Python, le comportement # de la division réelle pour les entiers, et non la division entière # 1/2=0.5 (et non 0). Comportement par défaut dans Python 3.0. from __future__ import division +from math import sin, cos, tan, asin, acos, atan2, atan, sinh, cosh, tanh +from math import pi, exp, log, log10, sqrt from N_ASSD import ASSD from N_info import message, SUPERV @@ -37,17 +36,21 @@ class formule(ASSD): ASSD.__init__(self, *args, **kwargs) self.nompar = None self.expression = None + ctxt = {} + ctxt.update(getattr(self.parent, 'const_context', {})) + ctxt.update(getattr(self.parent, 'macro_const_context', {})) + self.parent_context = self.filter_context(ctxt) + #message.debug(SUPERV, "add parent_context %s %s", self.nom, self.parent_context) def __call__(self, *val): - context = {} - # cas de INCLUDE (ou POURSUITE dans Eficas) - context.update(getattr(self.parent, 'contexte_fichier_init', {})) - # récupération des constantes locales en cas de MACRO - context.update(getattr(self.parent, 'macro_const_context', {})) + """Evaluation de la formule""" + # en POURSUITE, self.parent_context is None, on essaie de reprendre const_context + context = getattr(self, 'parent_context') or getattr(self.parent, 'const_context', {}) for param, value in zip(self.nompar, val): context[param] = value try: - res = eval(self.expression, self.jdc.const_context, context) + # globals() pour math.* + res = eval(self.code, context, globals()) except Exception, exc: message.error(SUPERV, "ERREUR LORS DE L'ÉVALUATION DE LA FORMULE '%s' " \ ":\n>> %s",self.nom, str(exc)) @@ -79,6 +82,27 @@ class formule(ASSD): del d['code'] return d + def supprime(self, force=False): + """ + Cassage des boucles de références pour destruction du JDC. + 'force' est utilisée pour faire des suppressions complémentaires. + + Pour être évaluées, les formules ont besoin du contexte des "constantes" + (objets autres que les concepts) qui sont soit dans (jdc).const_context, + soit dans (macro).macro_const_context. + On le stocke dans 'parent_context'. + Deux précautions valent mieux qu'une : on retire tous les concepts. + + Lors de la suppression du concept, 'supprime' est appelée par + 'build_detruire' avec force=True afin de supprimer le "const_context" + conservé. + """ + if force: + for ctxt in ('parent_context', 'g_context'): + if hasattr(self, ctxt): + setattr(self, ctxt, None) + ASSD.supprime(self, force) + def Parametres(self): """Equivalent de fonction.Parametres pour pouvoir utiliser des formules à la place de fonctions dans certaines macro-commandes.