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
21 Module de conversion des valeurs saisies par l'utilisateur après vérification.
24 from N_types import is_int, is_float, is_sequence
27 def has_int_value(real):
28 """Est-ce que 'real' a une valeur entière ?
30 return abs(int(real) - real) < 1.e-12
35 """Conversion de type.
38 def __init__(self, name, typ):
42 def convert(self, obj):
45 in_as_seq = is_sequence(obj)
51 result.append(self.function(o))
56 # ne marche pas avec MACR_RECAL qui attend une liste et non un
60 def function(self, o):
61 raise NotImplementedError, 'cette classe doit être dérivée'
64 class TypeConversion(Conversion):
69 def __init__(self, typ):
70 Conversion.__init__(self, 'type', typ)
73 class IntConversion(TypeConversion):
75 """Conversion en entier
79 TypeConversion.__init__(self, 'I')
81 def function(self, o):
82 if is_float(o) and has_int_value(o):
87 class FloatConversion(TypeConversion):
93 TypeConversion.__init__(self, 'R')
95 def function(self, o):
101 _convertI = IntConversion()
102 _convertR = FloatConversion()
105 def ConversionFactory(name, typ):