|
@@ -5,6 +5,7 @@ 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/primitives/utils/auto_snap.dart';
|
|
|
import 'package:fis_measure/utils/canvas.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:path_drawing/path_drawing.dart';
|
|
@@ -14,7 +15,7 @@ import '../calcuators/perimeter.dart';
|
|
|
import '../items/item.dart';
|
|
|
import '../items/item_feature.dart';
|
|
|
|
|
|
-class Trace extends MeasureItem<TraceFeature> {
|
|
|
+class Trace extends MeasureItem<TraceFeature> with AutoSnapMixin {
|
|
|
final bool _initialClosed = false;
|
|
|
PointInfo? _firstPoint;
|
|
|
|
|
@@ -40,44 +41,18 @@ class Trace extends MeasureItem<TraceFeature> {
|
|
|
if (args.pointType == PointInfoType.mouseDown) {
|
|
|
doFeatureFinish();
|
|
|
} else {
|
|
|
- _checkAutoFinish(args);
|
|
|
+ checkAutoFinish(args);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- void _doFinish() {
|
|
|
- doFeatureFinish();
|
|
|
+ @override
|
|
|
+ void doFeatureFinish() {
|
|
|
+ super.doFeatureFinish();
|
|
|
_firstPoint = null;
|
|
|
}
|
|
|
|
|
|
- void _checkAutoFinish(PointInfo current) {
|
|
|
- if (feature == null || feature!.innerPoints.length < 3) return;
|
|
|
-
|
|
|
- double autoSnapDistance = 0.01; //TODO: from config
|
|
|
- double autoSnapThreshold = 0.05;
|
|
|
- bool isAutoSnap = true; //TODO: from config
|
|
|
- if (isAutoSnap == false) return;
|
|
|
-
|
|
|
- // final viewport = feature!.hostVisualArea!.viewport!;
|
|
|
- var length = (feature!.firstPoint - current).length;
|
|
|
- if (length > autoSnapThreshold * 2.0 && !feature!.isSmartMove) {
|
|
|
- feature!.isSmartMove = true;
|
|
|
- }
|
|
|
- if (length < autoSnapThreshold && feature!.isSmartMove) {
|
|
|
- HapticFeedback.heavyImpact();
|
|
|
- _doFinish();
|
|
|
- }
|
|
|
- // final logicStart = feature!.innerPoints.first;
|
|
|
- // final logicEnd = feature!.innerPoints.last;
|
|
|
-
|
|
|
- // // isSmartMove
|
|
|
- // if (logicEnd.almostEquals(logicStart, 0.01)) {
|
|
|
- // feature!.innerPoints.add(feature!.innerPoints.first); // 强制闭合
|
|
|
- // doFeatureFinish();
|
|
|
- // }
|
|
|
- }
|
|
|
-
|
|
|
void handleMouseDownWhileWaiting(PointInfo args) {
|
|
|
// TODO: 判断是否当前area
|
|
|
// 转换为Area逻辑位置
|
|
@@ -121,7 +96,7 @@ class Trace extends MeasureItem<TraceFeature> {
|
|
|
if (args.pointType == PointInfoType.touchMove) {
|
|
|
feature?.adopt(args);
|
|
|
doCalculate();
|
|
|
- _checkAutoFinish(args);
|
|
|
+ checkAutoFinish(args);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
@@ -150,7 +125,6 @@ class Trace extends MeasureItem<TraceFeature> {
|
|
|
|
|
|
class TraceFeature extends MeasureItemFeature {
|
|
|
bool _isClosed = false;
|
|
|
- bool _isSmartMove = false;
|
|
|
|
|
|
TraceFeature(IMeasureItem refItem) : super(refItem);
|
|
|
|
|
@@ -162,14 +136,6 @@ class TraceFeature extends MeasureItemFeature {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// 是否启动智能定位
|
|
|
- bool get isSmartMove => _isSmartMove;
|
|
|
- set isSmartMove(bool value) {
|
|
|
- if (value != _isSmartMove) {
|
|
|
- _isSmartMove = value;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/// 首节点
|
|
|
DPoint get firstPoint => innerPoints.first;
|
|
|
|