123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import 'package:fis_measure/interfaces/date_types/int_size.dart';
- import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
- import 'package:fis_measure/process/items/item.dart';
- import 'package:fis_measure/process/items/item_feature.dart';
- import 'package:flutter/painting.dart';
- import 'package:flutter/services.dart';
- mixin AutoSnapMixin<T extends MeasureItemFeature> on MeasureItem<T> {
- bool _isSmartMove = false;
- /// 是否启动智能定位
- bool get isSmartMove => _isSmartMove;
- set isSmartMove(bool value) {
- if (value != _isSmartMove) {
- _isSmartMove = value;
- }
- }
- /// 自动结束检测
- bool checkAutoFinish(PointInfo current) {
- if (feature == null || feature!.innerPoints.length < 3) {
- isSmartMove = false;
- return false;
- }
- // final viewport = feature!.hostVisualArea!.viewport!;
- double autoSnapThreshold = 10; //TODO: from config, pixel
- bool isAutoSnap = true; //TODO: from config
- if (isAutoSnap == false) return false;
- final pixelSize = IntSize.fill(
- application.frameData!.width,
- application.frameData!.height,
- ).toDoubleSize();
- final p1 = feature!.innerPoints.first.scale2Size(pixelSize);
- final p2 = current.scale2Size(pixelSize);
- final length = (p1 - p2).length;
- if (length > autoSnapThreshold * 2.0 && !isSmartMove) {
- isSmartMove = true;
- }
- if (length < autoSnapThreshold && isSmartMove) {
- HapticFeedback.heavyImpact();
- doFeatureFinish();
- isSmartMove = false;
- return true;
- } else {
- return false;
- }
- }
- }
|