Эх сурвалжийг харах

support single distance items

melon.yin 2 жил өмнө
parent
commit
fb5ebd1b10

+ 8 - 1
lib/interfaces/process/calculators/values.dart

@@ -6,13 +6,20 @@ abstract class ValueBase {
   /// 格式元
   final ItemOutputMeta meta;
 
+  String? _name;
+
   /// 数据单位
   VidUsUnit unit;
 
   ValueBase(this.meta, this.unit);
 
   /// 计算结果名称
-  String get name => meta.name;
+  String get name => _name ?? meta.name;
+  set name(String? val) {
+    if (val != _name) {
+      _name = val;
+    }
+  }
 
   /// 目标单位
   VidUsUnit get targetUnit => meta.unit;

+ 3 - 0
lib/interfaces/process/items/item.dart

@@ -10,6 +10,9 @@ abstract class IMeasureItem {
   /// 标签信息
   ItemMeta get meta;
 
+  /// 外显名称
+  String get displayName;
+
   /// 描述
   String get description;
 

+ 152 - 0
lib/item_create_test.dart

@@ -37,6 +37,34 @@ class ItemCreateTest {
   void run() async {
     final txt = await rootBundle.loadString('assets/items.json');
     final mapList = jsonDecode(txt) as List<dynamic>;
+    final singleList = <String, List<dynamic>>{};
+    for (var map in mapList) {
+      bool hasChild = false;
+      bool hasMulti = false;
+      if (map['MethodChildItems'] != null) {
+        var list = map['MethodChildItems'] as List;
+        if (list.isNotEmpty) {
+          hasChild = true;
+        }
+      }
+      if (map['MultiMethodItems'] != null) {
+        var list = map['MultiMethodItems'] as List;
+        if (list.isNotEmpty) {
+          hasMulti = true;
+        }
+      }
+      if (!hasChild && !hasMulti) {
+        final typeKey = map['MeasureTypeName']! as String;
+        if (!singleList.containsKey(typeKey)) {
+          singleList[typeKey] = <dynamic>[];
+        }
+        final set = singleList[typeKey]!;
+        set.add(map);
+      }
+    }
+    final out = jsonEncode(singleList);
+    print(out);
+    return;
     final workingMaps =
         mapList.where((e) => C_Working_Items.contains(e['Name']));
     // mapList.where((e) => C_Working_Items.contains(e['MeasureTypeName']));
@@ -55,3 +83,127 @@ class ItemCreateTest {
     }
   }
 }
+
+class TestItems {
+  TestItems._();
+  static final C_DISTANCE_ITEMS = [
+    "MV Ann Diam",
+    "Distance",
+    "Aorta Diameter",
+    "Renal Len.(L)",
+    "Renal Len.(R)",
+    "YS",
+    "CRL",
+    "En.",
+    "Nasal Bone",
+    "Lat Ventricle",
+    "Internal os",
+    "CD",
+    "TCD",
+    "CM",
+    "BD",
+    "OOD",
+    "IOD",
+    "APAD",
+    "TAD",
+    "APTD",
+    "TTD",
+    "THD",
+    "SL",
+    "ULNA",
+    "RAD",
+    "TIB",
+    "FIB",
+    "Ft",
+    "PT",
+    "AFI-Q1",
+    "AFI-Q2",
+    "AFI-Q3",
+    "AFI-Q4",
+    "IVSd",
+    "LVIDd",
+    "LVPWd",
+    "IVSs",
+    "LVIDs",
+    "LVPWs",
+    "LVd Major",
+    "LVd Minor",
+    "LVs Major",
+    "LVs Minor",
+    "LVOT Diam",
+    "EPSS",
+    "MR Radius",
+    "Ao Diam",
+    "Ao Arch Diam",
+    "Ao Asc Diam",
+    "Ao Desc Diam",
+    "Ao lsthmus",
+    "Ao ST Junct",
+    "Ao Sinusus",
+    "Ao Annulus",
+    "AV_Diam",
+    "AV_Cusp",
+    "AR Radius",
+    "LA Diam",
+    "LAd Major",
+    "LAd Minor",
+    "LAs Major",
+    "LAs Minor",
+    "RVAWd",
+    "RVIDd",
+    "RVAWs",
+    "RVIDs",
+    "RVd Major",
+    "RVd Minor",
+    "RVs Major",
+    "RVs Minor",
+    "RVOT Diam",
+    "LPA Diam",
+    "RPA Diam",
+    "MPA Diam",
+    "Basal RVD",
+    "Mid RVD",
+    "Base-Apex L",
+    "TV Ann Diam",
+    "TR Radius",
+    "Pulmonic Diam",
+    "Systemic Diam",
+    "PV Ann Diam",
+    "PR Radius",
+    "RAd Major",
+    "RAd Minor",
+    "RAs Major",
+    "RAs Minor",
+    "IVC Diam",
+    "Systemic Vein Diam",
+    "PDA Diam",
+    "PFO Diam",
+    "VSD Diam",
+    "ASD Diam",
+    "PEd",
+    "Levator Hiatus LR",
+    "Levator Hiatus AP",
+    "Left LUG",
+    "Right LUG",
+    "ACT L",
+    "ACT R",
+    "NF",
+    "AP",
+    "LVLd",
+    "LVLs",
+    "A2C LVLd",
+    "A2C LVLs",
+    "A4C LVLd",
+    "A4C LVLs",
+    "MR VC Width",
+    "PR VC Width",
+    "TR VC Width",
+    "HW",
+    "BS",
+    "BSOB",
+    "Duct Art Diam",
+    "RV Inlet",
+    "LV Inlet",
+    "SV Diam",
+  ];
+}

+ 15 - 2
lib/main.dart

@@ -1,3 +1,4 @@
+import 'dart:convert';
 import 'dart:ui';
 import 'package:fis_common/index.dart';
 import 'package:fis_common/logger/logger.dart';
@@ -7,6 +8,7 @@ import 'package:fis_measure/process/layout/configuration.dart';
 import 'package:fis_measure/view/measure/measure_view.dart';
 import 'package:fis_vid/index.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 import 'package:get/get.dart';
 import 'package:fis_i18n/i18n.dart';
 
@@ -56,6 +58,8 @@ class MyHomePage extends StatefulWidget {
 class _MyHomePageState extends State<MyHomePage> {
   void _incrementCounter() {}
 
+  String _playerBtnText = "Player";
+
   @override
   Widget build(BuildContext context) {
     return Scaffold(
@@ -75,7 +79,16 @@ class _MyHomePageState extends State<MyHomePage> {
             ),
             const SizedBox(height: 10),
             ElevatedButton(
-              onPressed: () {
+              onPressed: () async {
+                setState(() {
+                  _playerBtnText = "Player loading...";
+                });
+                final txt = await rootBundle.loadString('assets/items.json');
+                MeasureTestPage.MetaDTOList = jsonDecode(txt) as List<dynamic>;
+                setState(() {
+                  _playerBtnText = "Player";
+                });
+
                 Navigator.of(context).push(
                   MaterialPageRoute(
                     builder: (context) => const MeasureTestPage(),
@@ -93,7 +106,7 @@ class _MyHomePageState extends State<MyHomePage> {
                 //   ),
                 // );
               },
-              child: const Text("Player"),
+              child: Text(_playerBtnText),
             ),
             const SizedBox(
               height: 15,

+ 56 - 34
lib/measure_page_test.dart

@@ -3,12 +3,14 @@ import 'dart:typed_data';
 import 'package:fis_jsonrpc/rpc.dart';
 import 'package:fis_measure/interfaces/enums/annotation.dart';
 import 'package:fis_measure/interfaces/process/items/item.dart';
+import 'package:fis_measure/interfaces/process/items/item_metas.dart';
 import 'package:fis_measure/interfaces/process/items/types.dart';
 import 'package:fis_measure/interfaces/process/player/play_controller.dart';
 import 'package:fis_measure/interfaces/process/standard_line/calibration.dart';
 import 'package:fis_measure/interfaces/process/workspace/application.dart';
 import 'package:fis_measure/interfaces/process/workspace/exam_info.dart';
 import 'package:fis_measure/interfaces/process/workspace/measure_controller.dart';
+import 'package:fis_measure/process/items/item_meta_convert.dart';
 import 'package:fis_measure/process/workspace/measure_3d_view_controller.dart';
 import 'package:fis_measure/process/workspace/measure_controller.dart';
 import 'package:fis_measure/process/workspace/measure_data_controller.dart';
@@ -16,6 +18,7 @@ import 'package:fis_measure/view/measure/measure_main_view.dart';
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 
+import 'item_create_test.dart';
 import 'process/workspace/measure_handler.dart';
 
 class MeasureDataTester {
@@ -81,6 +84,9 @@ class MeasureDataTester {
 class MeasureTestPage extends StatefulWidget {
   const MeasureTestPage({Key? key}) : super(key: key);
 
+  // ignore: non_constant_identifier_names
+  static List<dynamic> MetaDTOList = [];
+
   @override
   State<StatefulWidget> createState() => _MeasureTestPageState();
 }
@@ -344,14 +350,22 @@ class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
     MeasureTypes.AreaPerimeterPolyline,
   ];
 
+  late final List<String> passeItems;
+
   final scrollController = ScrollController();
   final application = Get.find<IApplication>();
 
   int activeIndex = 0;
 
+  late final List<ItemMeta> workingItems;
+
   @override
   void initState() {
-    application.switchItemByName(C_SUPPORTED_ITEMS[0]);
+    // passeItems = C_SUPPORTED_ITEMS;
+    passeItems = TestItems.C_DISTANCE_ITEMS;
+    loadItems();
+    // application.switchItemByName(C_SUPPORTED_ITEMS[0]);
+    // changeItemByMeta(0);
     application.canMeasureChanged.addListener(_onCanMeasureChanged);
     super.initState();
   }
@@ -364,7 +378,18 @@ class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
 
   _onCanMeasureChanged(Object sender, bool e) {
     if (e && mounted) {
-      changeItem(0);
+      changeItemByMeta(0);
+    }
+  }
+
+  void loadItems() {
+    workingItems = [];
+    final workingItemDtos = MeasureTestPage.MetaDTOList.where(
+        (e) => passeItems.contains(e['Name']));
+    for (var map in workingItemDtos) {
+      final dto = ItemMetaDTO.fromJson(map);
+      final item = ItemMetaConverter(dto).output();
+      workingItems.add(item);
     }
   }
 
@@ -378,20 +403,27 @@ class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
         isAlwaysShown: true,
         child: ListView.separated(
           controller: scrollController,
-          itemCount: C_SUPPORTED_ITEMS.length,
+          // itemCount: C_SUPPORTED_ITEMS.length,
+          itemCount: workingItems.length,
           itemBuilder: (BuildContext context, int index) {
-            final name = C_SUPPORTED_ITEMS[index];
+            // final name = C_SUPPORTED_ITEMS[index];
+            final item = workingItems[index];
+            final name = item.name;
             final active = index == activeIndex;
             return active
                 ? ElevatedButton(
-                    onPressed: () => changeItem(index),
+                    // onPressed: () => changeItem(index),
+                    onPressed: () {
+                      changeItemByMeta(index);
+                    },
                     child: Text(name),
                     style: ElevatedButton.styleFrom(
                       fixedSize: const Size.fromHeight(50),
                     ),
                   )
                 : OutlinedButton(
-                    onPressed: () => changeItem(index),
+                    // onPressed: () => changeItem(index),
+                    onPressed: () => changeItemByMeta(index),
                     child: Text(name),
                     style: OutlinedButton.styleFrom(
                       fixedSize: const Size.fromHeight(50),
@@ -406,31 +438,19 @@ class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
     );
   }
 
-  void buildItems() {
-    final count = C_SUPPORTED_ITEMS.length;
-    final children = <Widget>[];
-    for (var i = 0; i < count; i++) {
-      final name = C_SUPPORTED_ITEMS[i];
-      final active = i == activeIndex;
-      final widget = active
-          ? ElevatedButton(
-              onPressed: () => changeItem(i),
-              child: Text(name),
-              style: ElevatedButton.styleFrom(
-                fixedSize: const Size.fromHeight(50),
-              ),
-            )
-          : OutlinedButton(
-              onPressed: () => changeItem(i),
-              child: Text(name),
-              style: OutlinedButton.styleFrom(
-                fixedSize: const Size.fromHeight(50),
-              ),
-            );
-      if (i > 0) {
-        children.add(const SizedBox(height: 8));
+  void changeItemByMeta(int index) {
+    setState(() {
+      activeIndex = index;
+    });
+    final meta = workingItems[index];
+    application.switchItem(meta);
+    print(application.activeMeasureItem?.meta.name);
+    // handle combo item
+    if (application.activeMeasureItem != null) {
+      final item = application.activeMeasureItem!;
+      if (item is ITopMeasureItem) {
+        item.switchChild(0);
       }
-      children.add(widget);
     }
   }
 
@@ -438,12 +458,14 @@ class _MeasureLeftBoardState extends State<_MeasureLeftBoard> {
     setState(() {
       activeIndex = index;
     });
-    final name = C_SUPPORTED_ITEMS[index];
+    final name = passeItems[index];
     application.switchItemByName(name);
     // handle combo item
-    final item = application.activeMeasureItem!;
-    if (item is ITopMeasureItem) {
-      item.switchChild(0);
+    if (application.activeMeasureItem != null) {
+      final item = application.activeMeasureItem!;
+      if (item is ITopMeasureItem) {
+        item.switchChild(0);
+      }
     }
   }
 }

+ 11 - 6
lib/process/calcuators/calculator.dart

@@ -1,6 +1,7 @@
 import 'package:fis_common/event/event_type.dart';
 import 'package:fis_measure/interfaces/process/calculators/calculator.dart';
 import 'package:fis_measure/interfaces/process/calculators/output.dart';
+import 'package:fis_measure/interfaces/process/calculators/values.dart';
 import 'package:fis_measure/interfaces/process/items/item.dart';
 import 'package:fis_measure/process/items/item_feature.dart';
 import 'package:flutter/foundation.dart';
@@ -23,18 +24,22 @@ abstract class Calculator<T extends IMeasureItem, TValue>
   void finishOnce() {}
 
   @protected
-  void updateFloatValue(double value) {
-    if (ref.feature == null) return;
+  FloatValue? updateFloatValue(double value) {
+    if (ref.feature == null) return null;
     final feature = ref.feature! as MeasureItemFeature;
     final viewport = feature.hostVisualArea!.viewport!;
-    feature.updateFloatValue(ref.meta.outputs.first, value, viewport.xUnit);
+    return feature.updateFloatValue(
+      ref.meta.outputs.first,
+      value,
+      viewport.xUnit,
+    );
   }
 
   @protected
-  void updateStringValue(String value) {
-    if (ref.feature == null) return;
+  StringValue? updateStringValue(String value) {
+    if (ref.feature == null) return null;
     final feature = ref.feature! as MeasureItemFeature;
-    feature.updateStringValue(ref.meta.outputs.first, value);
+    return feature.updateStringValue(ref.meta.outputs.first, value);
   }
 
   /// 对double四舍五入

+ 2 - 1
lib/process/calcuators/distance.dart

@@ -22,6 +22,7 @@ class DistanceCal extends Calculator<StraightLine, double> {
     final pp2 = viewport.convert(p2);
 
     final value = (pp2 - pp1).length.abs();
-    updateFloatValue(value);
+    final floatValue = updateFloatValue(value);
+    floatValue!.name = ref.displayName;
   }
 }

+ 4 - 9
lib/process/items/factory.dart

@@ -32,24 +32,19 @@ class MeasureItemFactory {
 
   final _itemCreatorMap = <String, MeasureItemCreator>{};
 
-  void _register(String typeName, MeasureItemCreator creator,
-      [String? suffix]) {
-    final key = _buildKey(typeName, suffix);
+  void _register(String typeName, MeasureItemCreator creator) {
+    final key = typeName;
     _itemCreatorMap[key] = creator;
   }
 
   MeasureItemCreator? _findCreator(String typeName) {
-    final key = typeName; //_buildKey(typeName, suffix);
+    final key = typeName;
     if (_itemCreatorMap.containsKey(key)) {
       return _itemCreatorMap[key];
     }
     return null;
   }
 
-  String _buildKey(String typeName, [String? suffix]) {
-    return suffix == null ? typeName : '${typeName}_$suffix';
-  }
-
   /// 创建测量项
   ///
   /// [meta] 元信息
@@ -68,7 +63,7 @@ class MeasureItemFactory {
   static void _registerItemCreators() {
     _singleton._register(MeasureTypes.Distance, StraightLine.createDistance);
     _singleton._register(
-        MeasureTypes.Volume, LWHStraightLine.createVolume, "LWH");
+        MeasureTypes.VolumeThreeDistance, LWHStraightLine.createVolume);
 
     //Ellipse
     _singleton._register(

+ 11 - 0
lib/process/items/item.dart

@@ -26,6 +26,17 @@ abstract class MeasureItem<T extends MeasureItemFeature> extends IMeasureItem {
     _meta = meta;
   }
 
+  @override
+  String get displayName {
+    if (briefAnnotation.isNotEmpty) {
+      return briefAnnotation;
+    }
+    if (description.isNotEmpty) {
+      return description;
+    }
+    return meta.name;
+  }
+
   @override
   String get briefAnnotation => meta.briefAnnotation;
 

+ 11 - 6
lib/process/items/item_feature.dart

@@ -82,24 +82,27 @@ abstract class MeasureItemFeature implements IMeasureItemFeature {
   ValueBase? get value => _values.isNotEmpty ? _values.first : null;
 
   /// 更新浮点型结果值
-  void updateFloatValue(
+  FloatValue? updateFloatValue(
     ItemOutputMeta outputMeta,
     double value,
     VidUsUnit unit,
   ) {
-    final valueBase = values.firstWhereOrNull((e) => e.name == outputMeta.name);
+    final valueBase =
+        values.firstWhereOrNull((e) => e.meta.name == outputMeta.name);
     if (valueBase == null) {
       final floatValue = FloatValue(outputMeta, value, unit);
       values.add(floatValue);
+      return floatValue;
     } else {
       final floatValue = valueBase as FloatValue;
       floatValue.value = value;
       floatValue.unit = unit;
+      return floatValue;
     }
   }
 
   /// 更新字符串结果值
-  void updateStringValue(
+  StringValue updateStringValue(
     ItemOutputMeta outputMeta,
     String value, [
     VidUsUnit unit = VidUsUnit.None,
@@ -108,10 +111,12 @@ abstract class MeasureItemFeature implements IMeasureItemFeature {
     if (valueBase == null) {
       final stringValue = StringValue(outputMeta, value, unit);
       values.add(stringValue);
+      return stringValue;
     } else {
-      final floatValue = valueBase as StringValue;
-      floatValue.value = value;
-      floatValue.unit = unit;
+      final stringValue = valueBase as StringValue;
+      stringValue.value = value;
+      stringValue.unit = unit;
+      return stringValue;
     }
   }
 

+ 3 - 2
lib/process/workspace/application.dart

@@ -294,8 +294,9 @@ class Application implements IApplication {
 
   @override
   void switchItem(ItemMeta meta) {
-    switchItemByName(meta.name);
-    activeMeasureItem ??= MeasureItemFactory.createItem(meta);
+    // switchItemByName(meta.name);
+    // activeMeasureItem ??= MeasureItemFactory.createItem(meta);
+    activeMeasureItem = MeasureItemFactory.createItem(meta);
   }
 
   @override

+ 5 - 7
lib/view/result/converter.dart

@@ -52,11 +52,9 @@ class FeatureValueDescConverter {
 
   List<String> _findFeatureLines(IMeasureItemFeature feature) {
     final count = feature.values.length;
+    final itemName = feature.refItem.displayName;
     if (count == 0) {
-      final output = feature.refItem.meta.outputs.first;
-      final name =
-          _findDisplayName(output.description, output.briefAnnotation, false);
-      return ['$idStr $name'];
+      return ['$idStr $itemName'];
     }
 
     List<String> arr = [];
@@ -64,12 +62,12 @@ class FeatureValueDescConverter {
       final val = feature.values[i];
       final meta = val.meta;
       final valueStr = _pickValueStr(val);
-      final name =
-          _findDisplayName(meta.description, meta.briefAnnotation, false);
 
       if (i == 0) {
-        arr.add('$idStr $name: $valueStr');
+        arr.add('$idStr $itemName: $valueStr');
       } else {
+        final name =
+            _findDisplayName(meta.description, meta.briefAnnotation, false);
         arr.add('$idPlaceStr $name: $valueStr');
       }
     }