import 'package:fis_measure/interfaces/process/items/item_metas.dart'; import 'package:vid/us/vid_us_unit.dart'; /// 测量结果 abstract class ValueBase { /// 格式元 final ItemOutputMeta meta; String? _name; /// 数据单位 VidUsUnit unit; ValueBase(this.meta, this.unit); /// 计算结果名称 String get name => _name ?? meta.name; set name(String? val) { if (val != _name) { _name = val; } } /// 目标单位 VidUsUnit get metaUnit => meta.unit; double? pickFloat() { if (this is FloatValue) { final f = (this as FloatValue).value; return f; } return null; } } abstract class TypedValueBase extends ValueBase { T? _value; TypedValueBase( ItemOutputMeta meta, T? val, VidUsUnit unit, ) : super(meta, unit) { _value = val; } /// 测量结果值 T? get value => _value; set value(T? val) { if (val != _value) { _value = val; } } } /// 浮点值 class FloatValue extends TypedValueBase { int _fractionalDigits = 2; FloatValue( ItemOutputMeta meta, double? val, VidUsUnit unit, ) : super(meta, val, unit); /// 小数精度 int get fractionalDigits => _fractionalDigits; set fractionalDigits(int value) { if (value != _fractionalDigits) { _fractionalDigits = value; } } UnitFloatValue? toUnitFloatValue() { if (value != null) { return UnitFloatValue(value!, unit); } return null; } } /// 字符串值 class StringValue extends TypedValueBase { StringValue( ItemOutputMeta meta, String? val, VidUsUnit unit, ) : super(meta, val, unit); } class UnitFloatValue extends UnitValue { UnitFloatValue(super.value, super.unit); } class UnitValue { final VidUsUnit unit; final T value; UnitValue(this.value, this.unit); }