Browse Source

Merge branch 'master' of http://git.ius.plus/melon.yin/fis_lib_measure

bakamaka.guan 2 years ago
parent
commit
aeceaf3934

+ 10 - 0
lib/view/gesture/mouse_gesture.dart

@@ -171,6 +171,16 @@ class _MeasureMouseGesturePanelState extends State<MeasureMouseGesturePanel> {
 
   void _onResize(_, e) {
     _findMultiRegions();
+
+    /// 延迟进行同步,避免窗口手动缩放时引发 Error: Build scheduled during frame.
+    Future.delayed(const Duration(milliseconds: 1000), () {
+      _setScaleRatio();
+    });
+  }
+
+  /// 同步缩放比
+  void _setScaleRatio() {
+    mouseState.cursorScaleRatio = application.displayScaleRatio;
   }
 
   void _onActiveMeasureItemChanged(_, IMeasureItem? e) {

+ 27 - 2
lib/view/gesture/positioned_cursor.dart

@@ -17,15 +17,21 @@ abstract class IMouseState {
   double get cursorSize;
   set cursorSize(double value);
 
+  /// 卡尺缩放比
+  double get cursorScaleRatio;
+  set cursorScaleRatio(double value);
+
   late FEventHandler<Offset?> mousePositionChanged;
   late FEventHandler<MeasureCursorType> cursorTypeChanged;
   late FEventHandler<double> cursorSizeChanged;
+  late FEventHandler<double> cursorScaleRatioChanged;
   late FEventHandler<CrossIndicatorStyle> crossIndicatorStyleChanged;
 }
 
 class MouseState implements IMouseState {
   Offset? _mousePosition;
   double _cursorSize = 16;
+  double _cursorScaleRatio = 1;
   MeasureCursorType _cursorType = MeasureCursorType.cursor01;
 
   @override
@@ -33,6 +39,8 @@ class MouseState implements IMouseState {
 
   @override
   var cursorSizeChanged = FEventHandler<double>();
+  @override
+  var cursorScaleRatioChanged = FEventHandler<double>();
 
   @override
   var cursorTypeChanged = FEventHandler<MeasureCursorType>();
@@ -60,6 +68,16 @@ class MouseState implements IMouseState {
     }
   }
 
+  @override
+  double get cursorScaleRatio => _cursorScaleRatio;
+  @override
+  set cursorScaleRatio(double value) {
+    if (value != _cursorScaleRatio) {
+      _cursorScaleRatio = value;
+      cursorScaleRatioChanged.emit(this, value);
+    }
+  }
+
   @override
   MeasureCursorType get cursorType => _cursorType;
   @override
@@ -75,7 +93,7 @@ class MouseState implements IMouseState {
     if (mousePosition == null) return null;
 
     double dx = mousePosition!.dx, dy = mousePosition!.dy;
-    final offset = cursorSize / 2;
+    final offset = cursorScaleRatio * cursorSize / 2;
     dx -= offset;
     dy -= offset;
     return Offset(dx, dy);
@@ -95,6 +113,7 @@ class _PositionedCursorState extends State<PositionedCursor> {
   @override
   void initState() {
     mouseState.cursorSizeChanged.addListener(onCursorSizeChanged);
+    mouseState.cursorScaleRatioChanged.addListener(onCursorScaleRatioChanged);
     mouseState.cursorTypeChanged.addListener(cursorTypeChanged);
     mouseState.mousePositionChanged.addListener(mousePositionChanged);
     super.initState();
@@ -103,6 +122,8 @@ class _PositionedCursorState extends State<PositionedCursor> {
   @override
   void dispose() {
     mouseState.cursorSizeChanged.removeListener(onCursorSizeChanged);
+    mouseState.cursorScaleRatioChanged
+        .removeListener(onCursorScaleRatioChanged);
     mouseState.cursorTypeChanged.removeListener(cursorTypeChanged);
     mouseState.mousePositionChanged.removeListener(mousePositionChanged);
     super.dispose();
@@ -118,7 +139,7 @@ class _PositionedCursorState extends State<PositionedCursor> {
       top: position.dy,
       child: MeasureCursor(
         type: mouseState.cursorType,
-        size: mouseState.cursorSize,
+        size: mouseState.cursorSize * mouseState.cursorScaleRatio,
         color: MeasureColors.Primary,
       ),
     );
@@ -128,6 +149,10 @@ class _PositionedCursorState extends State<PositionedCursor> {
     onUpdate();
   }
 
+  void onCursorScaleRatioChanged(Object sender, dynamic e) {
+    onUpdate();
+  }
+
   void cursorTypeChanged(Object sender, dynamic e) {
     onUpdate();
   }

+ 1 - 1
lib/view/measure/measure_config/measure_configuation_page.dart

@@ -172,7 +172,7 @@ class MeasureConfigurationPageState extends State<MeasureConfigurationPage> {
   FWidget build(BuildContext context) {
     return FSimpleDialog(
       title: FText(
-        i18nBook.measure.config.t,
+        i18nBook.user.setting.t,
         style: const TextStyle(
           color: Colors.white,
           fontSize: 18,

+ 47 - 41
lib/view/measure/operate_type_change_button.dart

@@ -163,7 +163,7 @@ class OperateTypeChangeButtonState extends State<OperateTypeChangeButton>
   Future<void> _enterMeasure(VoidCallback rejectCallback) async {
     _setEnterMeasureState(false); // 预进入
 
-    final checked = await _checkStandardLineNotEmpty();
+    final checked = await _checkMeasureCanEnter();
     if (checked) {
       _setEnterMeasureState();
     } else {
@@ -171,54 +171,60 @@ class OperateTypeChangeButtonState extends State<OperateTypeChangeButton>
     }
   }
 
-  /// 检查第三方图像校准线信息是否空
-  Future<bool> _checkStandardLineNotEmpty() {
+  /// 检查是否可进入测量
+  Future<bool> _checkMeasureCanEnter() {
     final application = Get.find<IApplication>();
     if (application.isThirdPart) {
       final standardLine = (application as ThirdPartApplication).standardLine;
       if (standardLine.currentPixelSpacing.isEmpty) {
-        final completer = Completer<bool>();
-        FConfirmAlert.show(
-          context: context,
-          title: i18nBook.common.tip.t,
-          subTitle: i18nBook.measure.thirdImageNeedCalibratingTips.t,
-          businessParent: widget.businessParent,
-          onConfirm: () {
-            final calibrationController =
-                Get.find<IStandardLineCalibrationController>();
-
-            void onEditStateChanged(
-                Object _, StandardLineCalibrationEditState e) {
-              void finish(bool result) {
-                calibrationController.editStateChanged
-                    .removeListener(onEditStateChanged);
-                completer.complete(result);
-              }
+        // 第三方图像 像素比信息空,需要通过校准线校准
+        return _waitStandardLineDone();
+      }
+    }
+    return Future.value(true);
+  }
 
-              if (e == StandardLineCalibrationEditState.done) {
-                finish(true);
-              } else if (e == StandardLineCalibrationEditState.inactive) {
-                finish(false);
-              } else {
-                // no process
-              }
-            }
+  /// 等待校准线完成
+  Future<bool> _waitStandardLineDone() {
+    final completer = Completer<bool>();
+    FConfirmAlert.show(
+      context: context,
+      title: i18nBook.common.tip.t,
+      subTitle: i18nBook.measure.thirdImageNeedCalibratingTips.t,
+      businessParent: widget.businessParent,
+      onConfirm: () {
+        final calibrationController =
+            Get.find<IStandardLineCalibrationController>();
 
-            // 开始监听
+        void onEditStateChanged(_, StandardLineCalibrationEditState e) {
+          void finish(bool result) {
+            // 移除监听
             calibrationController.editStateChanged
-                .addListener(onEditStateChanged);
+                .removeListener(onEditStateChanged);
+            // 返回异步结果
+            completer.complete(result);
+          }
 
-            // 进入编辑
-            calibrationController.enterEditMode();
-          },
-          onCancel: () {
-            completer.complete(false);
-          },
-        );
-        return completer.future;
-      }
-    }
-    return Future.value(true);
+          if (e == StandardLineCalibrationEditState.done) {
+            finish(true);
+          } else if (e == StandardLineCalibrationEditState.inactive) {
+            finish(false);
+          } else {
+            // no process
+          }
+        }
+
+        // 开始监听
+        calibrationController.editStateChanged.addListener(onEditStateChanged);
+
+        // 进入编辑
+        calibrationController.enterEditMode();
+      },
+      onCancel: () {
+        completer.complete(false);
+      },
+    );
+    return completer.future;
   }
 
   /// 生成状态回滚函数