1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from __future__ import absolute_import
21 from __future__ import print_function
22 from .I_ASSD import ASSD
23 from Extensions.i18n import tr
24 from Extensions.eficas_exception import EficasException
27 def __init__(self,etape=None,sd=None,reg='oui'):
29 self.jdc.register_fonction(self)
31 def get_formule(self):
33 Retourne une formule decrivant self sous la forme d'un tuple :
34 (nom,type_retourne,arguments,corps)
36 if hasattr(self.etape,'get_formule'):
37 # on est dans le cas d'une formule Aster
38 return self.etape.get_formule()
40 # on est dans le cas d'une fonction
41 return (self.nom,'REEL','(REEL:x)','''bidon''')
43 # On ajoute la classe formule pour etre coherent avec la
44 # modification de C Durand sur la gestion des formules dans le superviseur
45 # On conserve l'ancienne classe fonction (ceinture et bretelles)
46 class fonction(FONCTION) : pass
48 from Extensions import param2
49 class formule(FONCTION) :
50 def __call__(self,*val):
51 if len(val) != len(self.nompar):
52 raise TypeError(" %s() takes exactly %d argument (%d given)" % (self.nom,len(self.nompar),len(val)))
53 return param2.Unop2(self.nom,self.real_call,val)
55 def real_call(self,*val):
56 if hasattr(self.parent,'contexte_fichier_init'):
57 context=self.parent.contexte_fichier_init
60 for param in self.nompar :
64 res=eval(self.expression,self.jdc.const_context, context)
67 print ('! ' + "Erreur evaluation formule %s" % self.nom + 20*'!')