123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- import 'dart:developer';
- import 'package:fis_measure/interfaces/process/calculators/values.dart';
- import 'package:fis_measure/interfaces/process/items/item.dart';
- import 'package:fis_measure/interfaces/process/items/item_feature.dart';
- import 'package:fis_measure/interfaces/process/items/item_metas.dart';
- import 'package:fis_measure/interfaces/process/items/terms.dart';
- import 'package:fis_measure/interfaces/process/items/types.dart';
- import 'package:fis_measure/process/unit/convert/convert.dart';
- import 'package:fis_measure/process/workspace/measure_data_controller.dart';
- import 'package:fis_measure/values/unit_desc.dart';
- import 'package:fis_measure/view/result/results_panel.dart';
- import 'package:get/get.dart';
- import 'package:vid/us/vid_us_unit.dart';
- class FeatureValueDescConverter {
- final IMeasureItemFeature feature;
- FeatureValueDescConverter(this.feature);
- String idPlaceStr = ' ';
- String idStr = ' ';
- String kidIdPlaceStr = ' ';
- String kidIdStr = ' ';
- bool _isCurrURM = false;
- List<ResultLine> generate(int idLength) {
- idPlaceStr = ' '.padRight(idLength, ' ');
- idStr = feature.id.toString().padRight(idLength, ' ');
- _isCurrURM = feature.refItem.meta.name.contains("URM");
- final List<ResultLine> arr = [];
- List<ResultLine> mainLines = [];
- if ([
- MeasureTypes.URMShellDenMeasure,
- MeasureTypes.URMShellVelMeasure,
- MeasureTypes.URMShellDenVelMeasure
- ].contains(feature.refItem.meta.measureType)) {
- mainLines = _findSpecialRimFeatureLines(feature);
- } else {
- mainLines = _findFeatureLines(feature);
- }
- arr.addAll(mainLines);
- final ref = feature.refItem;
- if (ref is ITopMeasureItem && ref.canChildOutputSelf) {
- _buildChildOutputs(arr, ref.childItems);
- }
- return arr;
- }
- void _buildChildOutputs(List<ResultLine> arr, List<IMeasureItem> childItems) {
- for (var i = 0; i < childItems.length; i++) {
- kidIdPlaceStr = ' '.padRight(2, ' ');
- kidIdStr = " ${i + 1}".padRight(2, ' ');
- final child = childItems[i];
- for (final feature in child.measuredFeatures) {
- arr.addAll(_pickFeatureLines(feature));
- }
- if (child.feature != null) {
- arr.addAll(_pickFeatureLines(child.feature!));
- }
- }
- }
- List<ResultLine> _pickFeatureLines(IMeasureItemFeature feature) {
- final lines = _findKidFeatureLines(feature);
- return lines;
- }
- ResultLine? _findChildLine(IMeasureItemFeature feature) {
- if (feature.value == null) return null;
- final value = feature.value!;
- final valueStr = _pickValueStr(value);
- final name = feature.refItem.description;
- return ResultLine(label: ' $idPlaceStr $name', value: valueStr);
- }
- List<ResultLine> _findKidFeatureLines(IMeasureItemFeature feature) {
- final count = feature.values.length;
- final itemName = _findMetaDisplayName(feature.refItem.meta, true);
- if (count == 0) {
- return [];
- }
- List<ResultLine> arr = [];
- for (var i = 0; i < count; i++) {
- final val = feature.values[i];
- final meta = val.meta;
- final valueStr = _pickValueStr(val);
- if (i == 0) {
- arr.add(ResultLine(label: "$kidIdStr $itemName", value: valueStr));
- } else {
- final name = _findOutputMetaDisplayName(
- meta, feature.featureStyle.showBriefAnnotation);
- arr.add(ResultLine(label: "$kidIdPlaceStr $name", value: valueStr));
- }
- }
- return arr;
- }
- List<ResultLine> _findFeatureLines(IMeasureItemFeature feature) {
- final count = feature.values.length;
- final itemName = _findMetaDisplayName(
- feature.refItem.meta, feature.featureStyle.showBriefAnnotation);
- if (count == 0) {
- return [ResultLine(label: '$idStr $itemName')];
- }
- List<ResultLine> arr = [];
- for (var i = 0; i < count; i++) {
- final val = feature.values[i];
- final meta = val.meta;
- final valueStr = _pickValueStr(val);
- if (i == 0) {
- arr.add(ResultLine(label: "$idStr $itemName", value: valueStr));
- } else {
- final name = _findOutputMetaDisplayName(
- meta, feature.featureStyle.showBriefAnnotation);
- arr.add(ResultLine(label: "$idPlaceStr $name", value: valueStr));
- }
- }
- return arr;
- }
- List<ResultLine> _findSpecialRimFeatureLines(IMeasureItemFeature feature) {
- final count = feature.values.length;
- final itemName = _findMetaDisplayName(
- feature.refItem.meta, feature.featureStyle.showBriefAnnotation);
- if (count == 0) {
- return [ResultLine(label: '$idStr $itemName')];
- }
- List<ResultLine> arr = [];
- for (var i = 0; i < count; i++) {
- final val = feature.values[i];
- final meta = val.meta;
- final valueStr = _pickValueStr(val);
- if (i == 0) {
- arr.add(ResultLine(label: "$idStr $itemName", value: valueStr));
- } else {
- if (meta.description == MeasureTerms.Area) {
- final name = _findOutputMetaDisplayName(
- meta, feature.featureStyle.showBriefAnnotation);
- arr.add(ResultLine(label: "$idPlaceStr $name", value: valueStr));
- }
- }
- }
- return arr;
- }
- String _pickValueStr(ValueBase value) {
- if (value is FloatValue) {
- final floatVal = _roundDouble(value.value!, 6);
- if (floatVal.isNaN) {
- return '';
- }
- final unit = value.unit;
- // final targetUnit = getUnitFromConfig(value.metaUnit);
- final targetVal =
- UnitValueConverter.convert(unit, value.metaUnit, floatVal);
- final targetValRound =
- _roundDoubleToString(targetVal, value.meta.fractionalDigits);
- final unitStr = UnitDescriptionMap.getDesc(value.metaUnit);
- return '$targetValRound $unitStr';
- } else if (value is StringValue) {
- return value.value!;
- }
- return '';
- }
- String _findMetaDisplayName(ItemMeta meta,
- [bool showBriefAnnotation = false]) {
- if (showBriefAnnotation) {
- if (meta.briefAnnotation.isNotEmpty) {
- return meta.briefAnnotation;
- }
- }
- return meta.description;
- }
- String _findOutputMetaDisplayName(ItemOutputMeta meta,
- [bool showBriefAnnotation = false]) {
- if (showBriefAnnotation) {
- if (meta.briefAnnotation != null && meta.briefAnnotation!.isNotEmpty) {
- return meta.briefAnnotation!;
- }
- }
- return meta.description;
- }
- double _roundDouble(double value, [int digits = 2]) {
- final digitsStr = value.toStringAsFixed(digits);
- final result = double.parse(digitsStr);
- return result;
- }
- String _roundDoubleToString(double value, [int digits = 2]) {
- final digitsStr = value.toStringAsFixed(digits);
- return digitsStr;
- }
- VidUsUnit getUnitFromConfig(VidUsUnit unit) {
- try {
- final measureData = Get.find<MeasureDataController>();
- if (distanceUnits.contains(unit)) {
- if (_isCurrURM) {
- return VidUsUnitMap.getUnit(
- measureData.measureSystemSetting.uRMDistanceUnit.index);
- } else {
- return VidUsUnitMap.getUnit(
- measureData.measureSystemSetting.distanceUnit.index);
- }
- }
- if (areaUnits.contains(unit)) {
- return VidUsUnitMap.getUnit(
- measureData.measureSystemSetting.areaUnit.index);
- }
- if (velocityUnits.contains(unit)) {
- return VidUsUnitMap.getUnit(
- measureData.measureSystemSetting.velocityUnit.index);
- }
- if (timeUnits.contains(unit)) {
- return VidUsUnitMap.getUnit(
- measureData.measureSystemSetting.timeUnit.index);
- }
- return unit;
- } catch (e) {
- log('getUnitFromConfig error: $e');
- return unit;
- }
- }
- static final List<VidUsUnit> distanceUnits = [
- VidUsUnit.mm,
- VidUsUnit.cm,
- VidUsUnit.um,
- VidUsUnit.inch,
- VidUsUnit.ft,
- ];
- static final List<VidUsUnit> areaUnits = [
- VidUsUnit.mm2,
- VidUsUnit.cm2,
- VidUsUnit.m2,
- ];
- static final List<VidUsUnit> velocityUnits = [
- VidUsUnit.mms,
- VidUsUnit.cms,
- VidUsUnit.ms,
- ];
- static final List<VidUsUnit> timeUnits = [
- VidUsUnit.msec,
- VidUsUnit.s,
- VidUsUnit.hour,
- VidUsUnit.minute,
- ];
- static final List<VidUsUnit> volumeUnits = [
- VidUsUnit.cm3,
- VidUsUnit.ml,
- VidUsUnit.mm3,
- VidUsUnit.L,
- ];
- static final List<VidUsUnit> weightUnits = [
- VidUsUnit.kg,
- VidUsUnit.g,
- VidUsUnit.mg,
- ];
- static final List<VidUsUnit> pressureUnits = [
- VidUsUnit.cm3s,
- VidUsUnit.mls,
- VidUsUnit.mlmin,
- VidUsUnit.Lmin,
- ];
- }
|