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

支持 MultiTrace 测量方式

gavin.chen 2 жил өмнө
parent
commit
183a068e2b

+ 46 - 2
lib/process/primitives/multi_method/multiple_trace.dart

@@ -9,10 +9,13 @@ import 'package:fis_measure/process/calcuators/trace.dart';
 import 'package:fis_measure/process/items/item.dart';
 import 'package:fis_measure/process/items/item_feature.dart';
 import 'package:fis_measure/utils/canvas.dart';
+import 'package:fis_measure/view/gesture/positioned_touch_cursor.dart';
+import 'package:get/get.dart';
 
 /// 手势轨迹图形
 class MultiTrace extends TraceItemAbstract {
   MultiTrace(ItemMeta meta, IMeasureItem? parent) : super(meta, parent);
+  late final touchState = Get.find<ITouchPointState>();
 
   @override
   bool onExecuteMouse(PointInfo args) {
@@ -55,7 +58,21 @@ class MultiTrace extends TraceItemAbstract {
     state = ItemStates.running;
   }
 
+  void handleTouchDownWhileWaiting(PointInfo args) {
+    // TODO: 判断是否当前area
+    // 转换为Area逻辑位置
+    feature = MultiTraceFeature(this);
+    if (args.hostVisualArea != null) {
+      feature!.hostVisualArea = args.hostVisualArea;
+    }
+    final point = args.toAreaLogicPoint();
+    feature!.adopt(point);
+    // state = ItemStates.running;
+  }
+
   PointInfo? startPoint;
+  DPoint touchStartPosition = DPoint(0, 0); // 相对位移起始触摸点
+  bool isFirstPointMove = false;
   @override
   bool onExecuteTouch(PointInfo args) {
     if (state == ItemStates.finished) {
@@ -65,24 +82,46 @@ class MultiTrace extends TraceItemAbstract {
     }
 
     if (state == ItemStates.waiting) {
+      if (isFirstPointMove) {
+        args.addOffset(0, -0.2);
+      }
       switch (args.pointType) {
         case PointInfoType.touchDown:
+          isFirstPointMove = false;
           startPoint = args; // 设置线段起点
+          handleTouchDownWhileWaiting(startPoint!); // 通过设置的起点开始一个绘制事件
           break;
         case PointInfoType.touchUp:
+          startPoint = args; // 设置线段起点
+          state = ItemStates.running;
+          touchState.touchOffset = Offset.zero;
           break; // 按下立即抬起无事发生
         case PointInfoType.touchMove:
-          handleMouseDownWhileWaiting(startPoint!); // 通过设置的起点开始一个绘制事件
+          isFirstPointMove = true;
+          final pixelSize = application.displaySize;
+          touchState.touchOffset =
+              DPoint(0, -0.2).scale2Size(pixelSize).toOffset();
+          feature?.innerPoints.first = args;
           break;
         default:
           break;
       }
     } else if (state == ItemStates.running) {
+      if (args.pointType == PointInfoType.touchDown) {
+        touchStartPosition = args;
+        final pixelSize = application.displaySize;
+        touchState.touchOffset = startPoint!.scale2Size(pixelSize).toOffset() -
+            args.scale2Size(pixelSize).toOffset();
+      }
       if (args.pointType == PointInfoType.touchUp) {
+        touchState.touchOffset = Offset.zero;
         doFeatureFinish();
       }
       if (args.pointType == PointInfoType.touchMove) {
-        feature?.adopt(args);
+        PointInfo newPoint = PointInfo.fromOffset(
+            startPoint!.clone().addVector(args - touchStartPosition).toOffset(),
+            startPoint!.pointType);
+        feature?.adopt(newPoint);
         doCalculate();
       }
     }
@@ -120,6 +159,11 @@ class MultiTraceFeature extends TraceItemFeatureAbstract {
         hostVisualArea!.displayRegion.bottom * size.height;
 
     if (innerPoints.isEmpty) return;
+    if (innerPoints.length == 1) {
+      drawVertex(canvas, convert2ViewPoint(size, innerPoints[0]).toOffset());
+      drawId(canvas, size);
+      return;
+    }
     double maxDistance = 0;
     drawId(canvas, size);
 

+ 4 - 3
lib/view/gesture/cross_position_indicator.dart

@@ -98,8 +98,9 @@ class MobileCrossIndicatorState extends State<MobileCrossIndicator> {
 
   @override
   Widget build(BuildContext context) {
-    final position = touchState.mousePosition;
+    final position = touchState.touchPosition;
     if (position == null) return Container();
+    final centerOffset = position + touchState.touchOffset;
     return Positioned(
       top: widget.areaRegion.top,
       width: widget.areaRegion.width,
@@ -109,8 +110,8 @@ class MobileCrossIndicatorState extends State<MobileCrossIndicator> {
             painter: _CrossIndicatorPainter(
                 strokeWidth: 1,
                 color: MeasureColors.ActiveCaliper,
-                centerOffset:
-                    Offset(position.dx, position.dy - widget.areaRegion.top),
+                centerOffset: Offset(
+                    centerOffset.dx, centerOffset.dy - widget.areaRegion.top),
                 style: indicatorStyle)),
       ),
     );

+ 23 - 9
lib/view/gesture/positioned_touch_cursor.dart

@@ -6,8 +6,11 @@ import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 
 abstract class ITouchPointState {
-  Offset? get mousePosition;
-  set mousePosition(Offset? value);
+  Offset? get touchPosition;
+  set touchPosition(Offset? value);
+
+  Offset get touchOffset;
+  set touchOffset(Offset value);
 
   Offset? get cursorPosition;
 
@@ -29,7 +32,8 @@ abstract class ITouchPointState {
 }
 
 class TouchPointState implements ITouchPointState {
-  Offset? _mousePosition;
+  Offset? _touchPosition;
+  Offset _touchOffset = Offset.zero;
   double _cursorSize = 16;
   double _cursorScaleRatio = 1;
   MeasureCursorType _cursorType = MeasureCursorType.cursor01;
@@ -49,15 +53,25 @@ class TouchPointState implements ITouchPointState {
   var crossIndicatorStyleChanged = FEventHandler<CrossIndicatorStyle>();
 
   @override
-  Offset? get mousePosition => _mousePosition;
+  Offset? get touchPosition => _touchPosition;
+
   @override
-  set mousePosition(Offset? value) {
-    if (value != _mousePosition) {
-      _mousePosition = value;
+  set touchPosition(Offset? value) {
+    if (value != _touchPosition) {
+      _touchPosition = value;
       mousePositionChanged.emit(this, value);
     }
   }
 
+  @override
+  Offset get touchOffset => _touchOffset;
+  @override
+  set touchOffset(Offset value) {
+    if (value != _touchOffset) {
+      _touchOffset = value;
+    }
+  }
+
   @override
   double get cursorSize => _cursorSize;
   @override
@@ -90,9 +104,9 @@ class TouchPointState implements ITouchPointState {
 
   @override
   Offset? get cursorPosition {
-    if (mousePosition == null) return null;
+    if (touchPosition == null) return null;
 
-    double dx = mousePosition!.dx, dy = mousePosition!.dy;
+    double dx = touchPosition!.dx, dy = touchPosition!.dy;
     final offset = cursorScaleRatio * cursorSize / 2;
     dx -= offset;
     dy -= offset;

+ 3 - 3
lib/view/gesture/touch_gesture.dart

@@ -43,7 +43,7 @@ class _MeasureTouchGesturePanelState extends State<MeasureTouchGesturePanel> {
     return GestureDetector(
       behavior: HitTestBehavior.opaque,
       onPanDown: (details) {
-        touchState.mousePosition = details.localPosition;
+        touchState.touchPosition = details.localPosition;
         _handleAreaChange(details.localPosition);
         application.createPointInfo(
           details.localPosition,
@@ -51,7 +51,7 @@ class _MeasureTouchGesturePanelState extends State<MeasureTouchGesturePanel> {
         );
       },
       onPanUpdate: (details) {
-        touchState.mousePosition = details.localPosition;
+        touchState.touchPosition = details.localPosition;
         _handleAreaChange(details.localPosition);
         _lastPosition = details.localPosition;
         application.createPointInfo(
@@ -60,7 +60,7 @@ class _MeasureTouchGesturePanelState extends State<MeasureTouchGesturePanel> {
         );
       },
       onTapUp: (details) {
-        touchState.mousePosition = details.localPosition;
+        touchState.touchPosition = details.localPosition;
         setState(() {
           displayType = CursorDisplayType.normal;
         });

+ 1 - 0
lib/view/mobile_view/mobile_right_panel/mobile_measure_tool.dart

@@ -610,6 +610,7 @@ class _MobileMeasureSelector extends FState<MobileMeasureSelector> {
       "Afi", // Afi
       "VolumeEllipse", // Ellipse
       "AreaPerimeterEllipse", // Ellipse
+      "DopplerTrace", // MultiTrace
     ];
     List<ItemMetaDTO> _supportedItems = [];
     if (mode.availableGroups == null || mode.availableGroups!.isEmpty) {