apply main unit also in structured types
Change-Id: I5a3efb167f2b460b847d8e7ac75a21848976b5f8
This commit is contained in:
parent
aad1c33742
commit
4287ec6477
@ -124,6 +124,9 @@ class DataType(HasProperties):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def set_main_unit(self, unit):
|
||||||
|
"""replace $ in unit by argument"""
|
||||||
|
|
||||||
|
|
||||||
class Stub(DataType):
|
class Stub(DataType):
|
||||||
"""incomplete datatype, to be replaced with a proper one later during module load
|
"""incomplete datatype, to be replaced with a proper one later during module load
|
||||||
@ -155,9 +158,17 @@ class Stub(DataType):
|
|||||||
prop.datatype = globals()[stub.name](*stub.args, **stub.kwds)
|
prop.datatype = globals()[stub.name](*stub.args, **stub.kwds)
|
||||||
|
|
||||||
|
|
||||||
|
class HasUnit:
|
||||||
|
unit = Property('physical unit', Stub('StringType', isUTF8=True), extname='unit', default='')
|
||||||
|
|
||||||
|
def set_main_unit(self, unit):
|
||||||
|
if '$' in self.unit:
|
||||||
|
self.setProperty('unit', self.unit.replace('$', unit))
|
||||||
|
|
||||||
|
|
||||||
# SECoP types:
|
# SECoP types:
|
||||||
|
|
||||||
class FloatRange(DataType):
|
class FloatRange(HasUnit, DataType):
|
||||||
"""(restricted) float type
|
"""(restricted) float type
|
||||||
|
|
||||||
:param minval: (property **min**)
|
:param minval: (property **min**)
|
||||||
@ -166,7 +177,6 @@ class FloatRange(DataType):
|
|||||||
"""
|
"""
|
||||||
min = Property('low limit', Stub('FloatRange'), extname='min', default=-sys.float_info.max)
|
min = Property('low limit', Stub('FloatRange'), extname='min', default=-sys.float_info.max)
|
||||||
max = Property('high limit', Stub('FloatRange'), extname='max', default=sys.float_info.max)
|
max = Property('high limit', Stub('FloatRange'), extname='max', default=sys.float_info.max)
|
||||||
unit = Property('physical unit', Stub('StringType', isUTF8=True), extname='unit', default='')
|
|
||||||
fmtstr = Property('format string', Stub('StringType'), extname='fmtstr', default='%g')
|
fmtstr = Property('format string', Stub('StringType'), extname='fmtstr', default='%g')
|
||||||
absolute_resolution = Property('absolute resolution', Stub('FloatRange', 0),
|
absolute_resolution = Property('absolute resolution', Stub('FloatRange', 0),
|
||||||
extname='absolute_resolution', default=0.0)
|
extname='absolute_resolution', default=0.0)
|
||||||
@ -331,7 +341,7 @@ class IntRange(DataType):
|
|||||||
raise BadValueError('incompatible datatypes')
|
raise BadValueError('incompatible datatypes')
|
||||||
|
|
||||||
|
|
||||||
class ScaledInteger(DataType):
|
class ScaledInteger(HasUnit, DataType):
|
||||||
"""scaled integer (= fixed resolution float) type
|
"""scaled integer (= fixed resolution float) type
|
||||||
|
|
||||||
:param minval: (property **min**)
|
:param minval: (property **min**)
|
||||||
@ -344,7 +354,6 @@ class ScaledInteger(DataType):
|
|||||||
scale = Property('scale factor', FloatRange(sys.float_info.min), extname='scale', mandatory=True)
|
scale = Property('scale factor', FloatRange(sys.float_info.min), extname='scale', mandatory=True)
|
||||||
min = Property('low limit', FloatRange(), extname='min', mandatory=True)
|
min = Property('low limit', FloatRange(), extname='min', mandatory=True)
|
||||||
max = Property('high limit', FloatRange(), extname='max', mandatory=True)
|
max = Property('high limit', FloatRange(), extname='max', mandatory=True)
|
||||||
unit = Property('physical unit', Stub('StringType', isUTF8=True), extname='unit', default='')
|
|
||||||
fmtstr = Property('format string', Stub('StringType'), extname='fmtstr', default='%g')
|
fmtstr = Property('format string', Stub('StringType'), extname='fmtstr', default='%g')
|
||||||
absolute_resolution = Property('absolute resolution', FloatRange(0),
|
absolute_resolution = Property('absolute resolution', FloatRange(0),
|
||||||
extname='absolute_resolution', default=0.0)
|
extname='absolute_resolution', default=0.0)
|
||||||
@ -806,6 +815,9 @@ class ArrayOf(DataType):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise BadValueError('incompatible datatypes') from None
|
raise BadValueError('incompatible datatypes') from None
|
||||||
|
|
||||||
|
def set_main_unit(self, unit):
|
||||||
|
self.members.set_main_unit(unit)
|
||||||
|
|
||||||
|
|
||||||
class TupleOf(DataType):
|
class TupleOf(DataType):
|
||||||
"""data structure with fields of inhomogeneous type
|
"""data structure with fields of inhomogeneous type
|
||||||
@ -872,6 +884,10 @@ class TupleOf(DataType):
|
|||||||
for a, b in zip(self.members, other.members):
|
for a, b in zip(self.members, other.members):
|
||||||
a.compatible(b)
|
a.compatible(b)
|
||||||
|
|
||||||
|
def set_main_unit(self, unit):
|
||||||
|
for member in self.members:
|
||||||
|
member.set_main_unit(unit)
|
||||||
|
|
||||||
|
|
||||||
class ImmutableDict(dict):
|
class ImmutableDict(dict):
|
||||||
def _no(self, *args, **kwds):
|
def _no(self, *args, **kwds):
|
||||||
@ -961,6 +977,10 @@ class StructOf(DataType):
|
|||||||
except (AttributeError, TypeError, KeyError):
|
except (AttributeError, TypeError, KeyError):
|
||||||
raise BadValueError('incompatible datatypes') from None
|
raise BadValueError('incompatible datatypes') from None
|
||||||
|
|
||||||
|
def set_main_unit(self, unit):
|
||||||
|
for member in self.members.values():
|
||||||
|
member.set_main_unit(unit)
|
||||||
|
|
||||||
|
|
||||||
class CommandType(DataType):
|
class CommandType(DataType):
|
||||||
"""command
|
"""command
|
||||||
|
@ -476,10 +476,10 @@ class Module(HasAccessibles):
|
|||||||
aobj.finish()
|
aobj.finish()
|
||||||
|
|
||||||
# Modify units AFTER applying the cfgdict
|
# Modify units AFTER applying the cfgdict
|
||||||
|
mainunit = self.parameters['value'].datatype.unit
|
||||||
|
if mainunit:
|
||||||
for pname, pobj in self.parameters.items():
|
for pname, pobj in self.parameters.items():
|
||||||
dt = pobj.datatype
|
pobj.datatype.set_main_unit(mainunit)
|
||||||
if '$' in dt.unit:
|
|
||||||
dt.setProperty('unit', dt.unit.replace('$', self.parameters['value'].datatype.unit))
|
|
||||||
|
|
||||||
# 6) check complete configuration of * properties
|
# 6) check complete configuration of * properties
|
||||||
if not errors:
|
if not errors:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user