Browse Source

增加 URM 测量项

gavin.chen 10 months ago
parent
commit
6bef421228

+ 263 - 21
lib/process/calcuators/urm.dart

@@ -5,15 +5,17 @@ import 'package:fis_common/logger/logger.dart';
 import 'package:fis_jsonrpc/rpc.dart';
 import 'package:fis_measure/interfaces/date_types/point.dart';
 import 'package:fis_measure/interfaces/process/items/types.dart';
-import 'package:fis_measure/process/primitives/urm.dart';
+import 'package:fis_measure/process/primitives/location.dart';
+import 'package:fis_measure/process/primitives/straightline.dart';
+import 'package:fis_measure/process/primitives/urm_rect.dart';
 import 'package:fis_measure/process/workspace/rpc_bridge.dart';
 import 'package:fis_measure/process/workspace/urm/application.dart';
 import 'package:vid/us/vid_us_unit.dart';
 
 import 'calculator.dart';
 
-class URMCal extends Calculator<URMMeasure, double> {
-  URMCal(URMMeasure ref, this.type) : super(ref);
+class URMCal extends Calculator<URMRect, double> {
+  URMCal(URMRect ref, this.type) : super(ref);
   String type = '';
   @override
   void calculate() {
@@ -55,42 +57,43 @@ class URMCal extends Calculator<URMMeasure, double> {
     /// [URM] ✅在此处通知 Server 计算,获取 description
     switch (type) {
       case MeasureTypes.SRCurvature:
-        callServerMethodToGetResult();
+        getSRCurvatureResult(startPoint, endPoint);
         break;
       case MeasureTypes.SRRoiDensity:
-        getSRCurvatureResult(startPoint, endPoint);
+        getSRRoiDensityResult(startPoint, endPoint);
         break;
       case MeasureTypes.SRRoiFractalDim:
-        callServerMethodToGetResult();
+        getSRRoiFractalDimResult(startPoint, endPoint);
         break;
       case MeasureTypes.SRTraceDensity:
-        callServerMethodToGetResult();
+        getSRTraceDensityResult([startPoint, endPoint]);
+        // callServerMethodToGetResult();
         break;
       case MeasureTypes.SRTraceFD:
-        callServerMethodToGetResult();
+        getSRTraceFDResult([startPoint, endPoint]);
+        // callServerMethodToGetResult();
         break;
       case MeasureTypes.SRLoactionVel:
-        callServerMethodToGetResult();
+        getSRLoactionVelResult(startPoint);
+        // callServerMethodToGetResult();
         break;
       case MeasureTypes.SRRoiVel:
-        callServerMethodToGetResult();
+        getSRRoiVelResult(startPoint, endPoint);
+        // callServerMethodToGetResult();
         break;
       case MeasureTypes.URMDensityMeasure:
-        callServerMethodToGetResult();
+        getURMDensityMeasureResult(startPoint, endPoint);
+        // callServerMethodToGetResult();
         break;
       case MeasureTypes.URMVelMeasure:
-        callServerMethodToGetResult();
-        break;
-      case MeasureTypes.VesselDiameter:
-        callServerMethodToGetResult();
-        break;
-      case MeasureTypes.VesselDistance:
-        callServerMethodToGetResult();
+        getURMVelMeasureResult(startPoint, endPoint);
+        // callServerMethodToGetResult();
         break;
       default:
     }
   }
 
+  // URM 测量项 1
   void getSRCurvatureResult(DPoint startPoint, DPoint endPoint) async {
     bool success = false;
     String description = "URM\n Measuring";
@@ -102,11 +105,146 @@ class URMCal extends Calculator<URMMeasure, double> {
       description = " ";
       return;
     }
-    print("URM Measure leftTopPoint: $startPoint");
-    print("URM Measure rightBottomPoint: $endPoint");
     description = "${(12.34567).toStringAsFixed(2)}mm/s";
     updateStringValue(description);
-    // updateFloatValue(12.34567, unit: VidUsUnit.mm, useRound: true);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 2
+  void getSRRoiDensityResult(DPoint startPoint, DPoint endPoint) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 3
+  void getSRRoiFractalDimResult(DPoint startPoint, DPoint endPoint) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 4
+  void getSRTraceDensityResult(List<DPoint> points) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 5
+  void getSRTraceFDResult(List<DPoint> points) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 6
+  void getSRLoactionVelResult(
+    DPoint point,
+  ) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 7
+  void getSRRoiVelResult(DPoint startPoint, DPoint endPoint) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 8
+  void getURMDensityMeasureResult(DPoint startPoint, DPoint endPoint) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+
+  // URM 测量项 9
+  void getURMVelMeasureResult(DPoint startPoint, DPoint endPoint) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
     ref.application.updateRenderReady.emit(this, null);
   }
 
@@ -147,3 +285,107 @@ class URMCal extends Calculator<URMMeasure, double> {
     }
   }
 }
+
+class URMLocationCal extends Calculator<Location, double> {
+  URMLocationCal(Location ref) : super(ref);
+
+  @override
+  void calculate() {
+    if (ref.feature == null) return;
+    Size urmResultSize = const Size(0, 0);
+    try {
+      if (ref.application is! URMApplication) {
+        return;
+      }
+      final URMApplication urmApplication = ref.application as URMApplication;
+      urmResultSize = Size(urmApplication.resultWidth.toDouble(),
+          urmApplication.resultHeight.toDouble());
+      // urmResultWidth = urmApplication.resultWidth;
+      // urmResultHeight = urmApplication.resultHeight;
+    } catch (e) {
+      logger.e('URM Measure error: $e');
+      return;
+    }
+
+    final point = ref.feature!.point.clone();
+    final startPoint = point.scale2Size(urmResultSize);
+    print("URM Measure startPoint: $startPoint");
+    getSRLoactionVelResult(startPoint);
+  }
+
+  // URM 测量项 6
+  void getSRLoactionVelResult(
+    DPoint point,
+  ) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+      print("调接口获取测量值");
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+}
+
+class URMStraightLineCal extends Calculator<StraightLine, double> {
+  URMStraightLineCal(StraightLine ref) : super(ref);
+
+  @override
+  void calculate() {
+    if (ref.feature == null) return;
+    Size urmResultSize = const Size(0, 0);
+    try {
+      if (ref.application is! URMApplication) {
+        return;
+      }
+      final URMApplication urmApplication = ref.application as URMApplication;
+      urmResultSize = Size(urmApplication.resultWidth.toDouble(),
+          urmApplication.resultHeight.toDouble());
+      // urmResultWidth = urmApplication.resultWidth;
+      // urmResultHeight = urmApplication.resultHeight;
+    } catch (e) {
+      logger.e('URM Measure error: $e');
+      return;
+    }
+    final p1 = ref.feature!.startPoint;
+    final p2 = ref.feature!.endPoint;
+    //左上顶点
+    final leftTopPercent =
+        DPoint(p1.x < p2.x ? p1.x : p2.x, p1.y < p2.y ? p1.y : p2.y);
+    //右下顶点
+    final rightBottomPercent =
+        DPoint(p1.x > p2.x ? p1.x : p2.x, p1.y > p2.y ? p1.y : p2.y);
+    //画布尺寸
+    final canavsSize = ref.application.displaySize;
+
+    final startPoint = leftTopPercent.scale2Size(urmResultSize);
+    final endPoint = rightBottomPercent.scale2Size(urmResultSize);
+
+    getSRCurvatureResult(startPoint, endPoint);
+  }
+
+  // URM 测量项 1
+  void getSRCurvatureResult(DPoint startPoint, DPoint endPoint) async {
+    bool success = false;
+    String description = "URM\n Measuring";
+    try {
+      // TODO 换成真实接口
+      // var result = await RPCBridge.ins.rpc.lab.getFileListByFolderAsync(     );
+      print("调接口获取测量值");
+    } catch (e) {
+      success = false;
+      description = " ";
+      return;
+    }
+    description = "${(12.34567).toStringAsFixed(2)}mm/s";
+    updateStringValue(description);
+    ref.application.updateRenderReady.emit(this, null);
+  }
+}

+ 7 - 2
lib/process/items/factory.dart

@@ -32,7 +32,9 @@ import 'package:fis_measure/process/primitives/spline.dart';
 import 'package:fis_measure/process/primitives/straightline.dart';
 import 'package:fis_measure/process/primitives/trace.dart';
 import 'package:fis_measure/process/primitives/twoline_angle.dart';
-import 'package:fis_measure/process/primitives/urm.dart';
+import 'package:fis_measure/process/primitives/urm_location.dart';
+import 'package:fis_measure/process/primitives/urm_rect.dart';
+import 'package:fis_measure/process/primitives/urm_straightline.dart';
 
 /// 测量项创建器
 ///
@@ -234,6 +236,9 @@ class MeasureItemFactory {
 
     // URM
     _singleton._register(
-        MeasureTypes.SRRoiDensity, URMMeasure.createMeasureRect);
+        MeasureTypes.SRCurvature, URMStraightLine.createURMStraightline);
+    _singleton._register(MeasureTypes.SRRoiDensity, URMRect.createMeasureRect);
+    _singleton._register(
+        MeasureTypes.SRLoactionVel, URMLoaction.createURMLocation);
   }
 }

+ 2 - 17
lib/process/primitives/location.dart

@@ -1,3 +1,4 @@
+import 'dart:html';
 import 'dart:ui';
 import 'dart:math' as math;
 
@@ -10,6 +11,7 @@ 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/workspace/application.dart';
 import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
+import 'package:fis_measure/process/calcuators/urm.dart';
 import 'package:fis_measure/process/calcuators/velocity.dart';
 import 'package:fis_measure/process/visual/tissue_area.dart';
 import 'package:fis_measure/utils/canvas.dart';
@@ -47,23 +49,6 @@ class Location extends MeasureItem<LocationFeature> {
     return true;
   }
 
-  String mapPointInfoType(PointInfoType type) {
-    switch (type) {
-      case PointInfoType.mouseUp:
-        return '⬆️';
-      case PointInfoType.mouseDown:
-        return '⬇️';
-      case PointInfoType.mouseMove:
-        return '⭐';
-      case PointInfoType.touchUp:
-        return '⬆️';
-      case PointInfoType.touchDown:
-        return '⬇️';
-      case PointInfoType.touchMove:
-        return '⭐';
-    }
-  }
-
   @override
   bool onExecuteTouch(PointInfo args) {
     if (state == ItemStates.finished || state == ItemStates.waiting) {

+ 62 - 0
lib/process/primitives/urm_location.dart

@@ -0,0 +1,62 @@
+import 'dart:ui';
+
+import 'package:fis_measure/interfaces/date_types/point.dart';
+import 'package:fis_measure/interfaces/enums/items.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/workspace/point_info.dart';
+import 'package:fis_measure/process/calcuators/urm.dart';
+import 'package:fis_measure/process/items/item.dart';
+import 'package:fis_measure/process/primitives/location.dart';
+import 'package:fis_measure/utils/canvas.dart';
+
+import '../items/item_feature.dart';
+
+class URMLoaction extends Location {
+  URMLoaction(ItemMeta meta, IMeasureItem? parent) : super(meta, parent);
+
+  static URMLoaction createURMLocation(
+    ItemMeta meta, [
+    IMeasureItem? parent,
+  ]) {
+    URMLoaction location = URMLoaction(meta, parent);
+    location.calculator = URMLocationCal(location);
+    return location;
+  }
+
+  @override
+  bool onExecuteMouse(PointInfo args) {
+    if (state == ItemStates.finished || state == ItemStates.waiting) {
+      if (args.pointType == PointInfoType.mouseMove) {
+        handleMouseMoveWhileFinish(args);
+      }
+    }
+    if (state == ItemStates.running) {
+      if (args.pointType == PointInfoType.mouseUp) return false;
+
+      feature?.point = args;
+      if (args.pointType == PointInfoType.mouseDown) {
+        doCalculate();
+        doFeatureFinish();
+      }
+    }
+    return true;
+  }
+
+  @override
+  bool onExecuteTouch(PointInfo args) {
+    if (state == ItemStates.finished || state == ItemStates.waiting) {
+      if (args.pointType == PointInfoType.touchDown) {
+        handleMouseMoveWhileFinish(args);
+      }
+    }
+    if (state == ItemStates.running) {
+      if (args.pointType == PointInfoType.touchDown) {
+        feature?.point = args;
+        doCalculate();
+        doFeatureFinish();
+      }
+    }
+    return true;
+  }
+}

+ 7 - 7
lib/process/primitives/urm.dart → lib/process/primitives/urm_rect.dart

@@ -11,11 +11,11 @@ import 'package:fis_measure/utils/canvas.dart';
 
 import '../items/item_feature.dart';
 
-class URMMeasure extends MeasureItem<URMMeasureFeature> {
-  URMMeasure(ItemMeta meta, IMeasureItem? parent) : super(meta, parent);
+class URMRect extends MeasureItem<URMRectFeature> {
+  URMRect(ItemMeta meta, IMeasureItem? parent) : super(meta, parent);
 
-  static URMMeasure createMeasureRect(ItemMeta meta, [IMeasureItem? parent]) {
-    URMMeasure measureRect = URMMeasure(meta, parent);
+  static URMRect createMeasureRect(ItemMeta meta, [IMeasureItem? parent]) {
+    URMRect measureRect = URMRect(meta, parent);
     measureRect.calculator = URMCal(measureRect, meta.name);
     return measureRect;
   }
@@ -61,7 +61,7 @@ class URMMeasure extends MeasureItem<URMMeasureFeature> {
     // TODO: 判断是否当前area
     // 转换为Area逻辑位置
     final point = args.toAreaLogicPoint();
-    feature = URMMeasureFeature(this, point, point);
+    feature = URMRectFeature(this, point, point);
     if (args.hostVisualArea != null) {
       feature!.hostVisualArea = args.hostVisualArea;
     }
@@ -69,8 +69,8 @@ class URMMeasure extends MeasureItem<URMMeasureFeature> {
   }
 }
 
-class URMMeasureFeature extends MeasureItemFeature {
-  URMMeasureFeature(
+class URMRectFeature extends MeasureItemFeature {
+  URMRectFeature(
     IMeasureItem refItem,
     DPoint startPoint,
     DPoint endPoint,

+ 55 - 0
lib/process/primitives/urm_straightline.dart

@@ -0,0 +1,55 @@
+import 'dart:ui';
+
+import 'package:fis_measure/interfaces/date_types/point.dart';
+import 'package:fis_measure/interfaces/enums/items.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/workspace/point_info.dart';
+import 'package:fis_measure/process/calcuators/urm.dart';
+import 'package:fis_measure/process/items/item.dart';
+import 'package:fis_measure/process/primitives/location.dart';
+import 'package:fis_measure/process/primitives/straightline.dart';
+import 'package:fis_measure/utils/canvas.dart';
+
+import '../items/item_feature.dart';
+
+class URMStraightLine extends StraightLine {
+  URMStraightLine(ItemMeta meta, IMeasureItem? parent) : super(meta, parent);
+
+  static URMStraightLine createURMStraightline(ItemMeta meta,
+      [IMeasureItem? parent]) {
+    URMStraightLine sraightLine = URMStraightLine(meta, parent);
+    sraightLine.repeatableEditable = true;
+    sraightLine.calculator = URMStraightLineCal(sraightLine);
+    return sraightLine;
+  }
+
+  @override
+  bool onExecuteMouse(PointInfo args) {
+    if (state == ItemStates.finished) {
+      if (args.pointType == PointInfoType.mouseDown) {
+        state = ItemStates.waiting;
+      } else {
+        return false;
+      }
+    }
+
+    if (state == ItemStates.waiting) {
+      if (args.pointType == PointInfoType.mouseDown) {
+        handleMouseDownWhileWaiting(args);
+      }
+    } else if (state == ItemStates.running) {
+      if (args.pointType == PointInfoType.mouseUp) return false;
+
+      feature?.endPoint = args;
+      if (args.pointType == PointInfoType.mouseDown) {
+        doCalculate();
+        doFeatureFinish();
+
+        ///重置十字样式
+        // changeCrossIndicatorStyle(CrossIndicatorStyle.nomal);
+      }
+    }
+    return true;
+  }
+}