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 __future__ import absolute_import
26 from builtins import object
29 from .N_types import is_int, is_float, is_sequence
32 def has_int_value(real):
33 """Est-ce que 'real' a une valeur entière ?
35 return abs(int(real) - real) < 1.e-12
38 class Conversion(object):
40 """Conversion de type.
43 def __init__(self, name, typ):
47 def convert(self, obj):
50 in_as_seq = is_sequence(obj)
56 result.append(self.function(o))
61 # ne marche pas avec MACR_RECAL qui attend une liste et non un
65 def function(self, o):
66 raise NotImplementedError('cette classe doit être dérivée')
69 class TypeConversion(Conversion):
74 def __init__(self, typ):
75 Conversion.__init__(self, 'type', typ)
78 class IntConversion(TypeConversion):
80 """Conversion en entier
84 TypeConversion.__init__(self, 'I')
86 def function(self, o):
87 if is_float(o) and has_int_value(o):
92 class FloatConversion(TypeConversion):
98 TypeConversion.__init__(self, 'R')
100 def function(self, o):
106 _convertI = IntConversion()
107 _convertR = FloatConversion()
110 def ConversionFactory(name, typ):