Salome HOME
Merge branch 'nouvelEficas' of http://git.forge-pleiade.der.edf.fr/git/eficas into...
[tools/eficas.git] / Extensions / interpreteur_formule.py
index 4d1b93d4cc7a1e854b991afeaafd012811bab0d4..a62c543b4c1cb4363b9f0333e55db9a938349a1b 100644 (file)
@@ -1,25 +1,27 @@
-#            CONFIGURATION MANAGEMENT OF EDF VERSION
-# ======================================================================
-# COPYRIGHT (C) 1991 - 2002  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.
+# -*- coding: utf-8 -*-
+# 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
 #
-# ======================================================================
 import string,re,sys,exceptions,types
 
 from Noyau.N_CR import CR
+from Extensions.i18n import tr
+
 
 def group(*choices): return '(' + string.join(choices, '|') + ')'
 def any(*choices): return apply(group, choices) + '*'
@@ -92,7 +94,7 @@ class Interpreteur_Formule:
         Méthode externe
         """
         if type(formule) != types.TupleType:
-            raise InterpreteurException,"La formule passée à l'interpréteur doit être sous forme de tuple"
+            raise InterpreteurException,tr("La formule passee a l'interpreteur doit etre sous forme de tuple")
         self.t_formule = formule
         self.init_cr()
         self.modify_listes()
@@ -105,8 +107,8 @@ class Interpreteur_Formule:
         nom = self.t_formule[0]
         if nom :
             if nom[0] in ('+','-') : nom = nom[1:]
-        self.cr.debut = "Début Fonction %s" %nom
-        self.cr.fin = "Fin Fonction %s" %nom
+        self.cr.debut = tr("Debut Fonction %s", nom)
+        self.cr.fin = tr("Fin Fonction %s", nom)
         
     def str(self):
         """
@@ -151,7 +153,7 @@ class Interpreteur_Formule:
         """
         Réalise l'interprétation du corps de la formule
         """
-        texte = self.t_formule[3]\r
+        texte = self.t_formule[3]
         if not texte : return
         if type(texte) != types.ListType:
             texte = [texte,]
@@ -162,7 +164,7 @@ class Interpreteur_Formule:
             try:
                 self.l_operateurs.append(self.split_operateurs(text_arg))
             except InterpreteurException,e:
-                self.cr.fatal(str(e))
+                self.cr.fatal(e.__str__())
 
     def modify_listes(self):
         """
@@ -213,25 +215,25 @@ class Interpreteur_Formule:
         try:
             oper,reste = self.cherche_nombre(texte)
         except InterpreteurException,e:
-            raise InterpreteurException,str(e)
+            raise InterpreteurException,e.__str__()
         if not oper :
             # on recherche une constante en début de texte
             try:
                 oper,reste = self.cherche_constante(texte)
             except InterpreteurException,e:
-                raise InterpreteurException,str(e)
+                raise InterpreteurException,e.__str__()
             if not oper :
                 # on recherche une expression entre parenthèses...
                 try:
                     oper,reste = self.cherche_expression_entre_parentheses(texte)
                 except InterpreteurException,e:
-                    raise InterpreteurException,str(e)
+                    raise InterpreteurException,e.__str__()
                 if not oper :
                     # on recherche le début d'un opérateur unaire en début de texte
                     try:
                         oper,reste = self.cherche_operateur_unaire(texte)
                     except InterpreteurException,e:
-                        raise InterpreteurException,str(e)
+                        raise InterpreteurException,e.__str__()
                     if not oper :
                         type_objet,nom_objet = self.get_type(texte)
                         if type_objet == 'constante':
@@ -257,7 +259,7 @@ class Interpreteur_Formule:
                 try:
                     l_op = self.split_operateurs(reste)
                 except InterpreteurException,e:
-                    raise InterpreteurException,str(e)
+                    raise InterpreteurException,e.__str__()
                 l_operateurs.extend(l_op)
                 return l_operateurs
         else:
@@ -398,7 +400,7 @@ class Interpreteur_Formule:
             try:
                 args,reste = self.cherche_args(texte)
             except InterpreteurException,e:
-                raise InterpreteurException,str(e)
+                raise InterpreteurException,e.__str__()
             if not args :
                 # opérateur unaire sans arguments
                 raise InterpreteurException,'opérateur unaire  %s sans arguments' %operateur
@@ -434,7 +436,7 @@ class Interpreteur_Formule:
             try:
                 args,reste = self.cherche_args(reste)
             except InterpreteurException,e:
-                raise InterpreteurException,str(e)
+                raise InterpreteurException,e.__str__()
             if not args :
                 # opérateur unaire sans arguments
                 # en principe on ne doit jamais être dans ce cas car il est déjà trappé par cherche_constante ...
@@ -453,17 +455,17 @@ class Interpreteur_Formule:
                 texte = reste
                 return operateur,reste
         elif texte[0] == '-':
-           # Il faut pouvoir trapper les expressions du type exp(-(x+1)) ...
-           try :
-              args,reste = self.cherche_args(texte[1:])
-           except InterpreteurException,e:
-                raise InterpreteurException,str(e)
-           if not args :
-              # Il ne s'agit pas de '-' comme opérateur unaire --> on retourne None
-              return None,texte
-           else:
-              identificateur = '-'
-              args = self.split_args(identificateur,args,self.d_fonctions_unaires[identificateur])
+            # Il faut pouvoir trapper les expressions du type exp(-(x+1)) ...
+            try :
+               args,reste = self.cherche_args(texte[1:])
+            except InterpreteurException,e:
+                raise InterpreteurException,e.__str__()
+            if not args :
+               # Il ne s'agit pas de '-' comme opérateur unaire --> on retourne None
+               return None,texte
+            else:
+               identificateur = '-'
+               args = self.split_args(identificateur,args,self.d_fonctions_unaires[identificateur])
                formule_operateur = (identificateur,'',self.t_formule[2],args)
                operateur = Interpreteur_Formule(formule = formule_operateur,
                                                  constantes = self.new_constantes,