1 # -*- coding: iso-8859-1 -*-
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_enum, 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
34 """Conversion de type.
36 def __init__(self, name, typ):
40 def convert(self, obj):
43 in_as_seq = is_sequence(obj)
49 result.append(self.function(o))
54 # ne marche pas avec MACR_RECAL qui attend une liste et non un tuple
57 def function(self, o):
58 raise NotImplementedError, 'cette classe doit être dérivée'
61 class TypeConversion(Conversion):
64 def __init__(self, typ):
65 Conversion.__init__(self, 'type', typ)
68 class IntConversion(TypeConversion):
69 """Conversion en entier
72 TypeConversion.__init__(self, 'I')
74 def function(self, o):
75 if is_float(o) and has_int_value(o):
80 class FloatConversion(TypeConversion):
84 TypeConversion.__init__(self, 'R')
86 def function(self, o):
92 _convertI = IntConversion()
93 _convertR = FloatConversion()
95 def ConversionFactory(name, typ):