123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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<T> 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<double> {
- 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<String> {
- StringValue(
- ItemOutputMeta meta,
- String? val,
- VidUsUnit unit,
- ) : super(meta, val, unit);
- }
- class UnitFloatValue extends UnitValue<double> {
- UnitFloatValue(super.value, super.unit);
- }
- class UnitValue<T> {
- final VidUsUnit unit;
- final T value;
- UnitValue(this.value, this.unit);
- }
|