Jelajahi Sumber

支持 Ellipse 测量方式

gavin.chen 2 tahun lalu
induk
melakukan
63026181a1

+ 67 - 1
lib/process/primitives/ellipse.dart

@@ -60,9 +60,63 @@ class Ellipse extends AreaItemAbstract {
     return false;
   }
 
+  bool isFirstPointMove = true;
+  DPoint touchStartPosition = DPoint(0, 0); // 相对位移起始触摸点
+  DPoint currPointLastPosition = DPoint(0, 0); // 当前操作的点之前所在位置
+
   @override
   bool onExecuteTouch(PointInfo args) {
-    return true;
+    if (state == ItemStates.finished) {
+      if (args.pointType == PointInfoType.touchDown) {
+        state = ItemStates.waiting;
+      }
+    }
+
+    if (state == ItemStates.waiting) {
+      if (args.pointType == PointInfoType.touchDown) {
+        isFirstPointMove = true;
+        handleTouchDownWhileWaiting(args);
+      }
+    } else if (state == ItemStates.running) {
+      if (feature == null) return false;
+      final f = feature! as EllipseFeature;
+      if (args.pointType == PointInfoType.touchDown) {
+        touchStartPosition = args;
+        currPointLastPosition = f.innerPoints[f.activeIndex];
+      }
+      if (args.pointType == PointInfoType.touchMove) {
+        if (isFirstPointMove) {
+          DPoint newStartPoint = args;
+          newStartPoint.addOffset(0, -0.2);
+          for (var element in f.innerPoints) {
+            element.update(newStartPoint);
+          }
+        } else {
+          DPoint newPoint = currPointLastPosition
+              .clone()
+              .addVector(args - touchStartPosition);
+          f.innerPoints[f.activeIndex] = newPoint;
+          f.adjustPoints(newPoint);
+        }
+      }
+      if (args.pointType == PointInfoType.touchUp) {
+        if (isFirstPointMove) {
+          isFirstPointMove = false;
+          f.activeIndex = 1;
+        }
+        if (f.activeIndex == 1) {
+          if (f.xAxisEnd != f.xAxisStart) {
+            f.adjustPoints(args);
+            f.activeIndex = 2;
+          }
+        } else if (f.activeIndex == 2) {
+          doFeatureFinish();
+        }
+      }
+      doCalculate();
+      return true;
+    }
+    return false;
   }
 
   void handleMouseDownWhileWaiting(PointInfo args) {
@@ -77,6 +131,18 @@ class Ellipse extends AreaItemAbstract {
     state = ItemStates.running;
   }
 
+  void handleTouchDownWhileWaiting(PointInfo args) {
+    // TODO: 判断是否当前area
+    // 转换为Area逻辑位置
+    final point = args.toAreaLogicPoint();
+    feature = EllipseFeature(this, point);
+    if (args.hostVisualArea != null) {
+      feature!.hostVisualArea = args.hostVisualArea;
+    }
+    feature!.activeIndex = 0;
+    state = ItemStates.running;
+  }
+
   static Ellipse createAreaPerimeter(ItemMeta meta, [IMeasureItem? parent]) {
     final ellipse = Ellipse(meta, parent);
     ellipse.calculator = AreaPerimeterEllipseCal(ellipse);

+ 2 - 2
lib/view/mobile_view/mobile_right_panel/mobile_measure_tool.dart

@@ -608,8 +608,8 @@ class _MobileMeasureSelector extends FState<MobileMeasureSelector> {
       "PolyLineAngle", // PolyLineAngle
       "CardiacAxis", // TwolineAngle
       "Afi", // Afi
-      // "VolumeEllipse", // Ellipse
-      // "AreaPerimeterEllipse", // Ellipse
+      "VolumeEllipse", // Ellipse
+      "AreaPerimeterEllipse", // Ellipse
     ];
     List<ItemMetaDTO> _supportedItems = [];
     if (mode.availableGroups == null || mode.availableGroups!.isEmpty) {