1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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/services.dart';
- mixin AutoSnapMixin<T extends MeasureItemFeature> on MeasureItem<T> {
- bool _isSmartMove = false;
- bool _isAutoSnap = true;
- double _snapThreshold = 10.0;
- bool snapState = false;
-
- bool get isSmartMove => _isSmartMove;
- set isSmartMove(bool value) {
- if (value != _isSmartMove) {
- _isSmartMove = value;
- }
- }
- bool get isAutoSnap => _isAutoSnap;
- set isAutoSnap(bool val) {
- if (val != _isAutoSnap) {
- _isAutoSnap = val;
- }
- }
-
- double get snapThreshold => _snapThreshold;
- set snapThreshold(double val) {
- if (val != _snapThreshold) {
- _snapThreshold = val;
- }
- }
-
- bool checkAutoSnap(PointInfo current) {
- if (feature == null || feature!.innerPoints.length < 3) {
- isSmartMove = false;
- return _syncState(false);
- }
-
- 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 > snapThreshold * 2.0 && !isSmartMove) {
- isSmartMove = true;
- }
- if (length < snapThreshold && isSmartMove) {
- feature!.innerPoints.last = feature!.innerPoints.first.clone();
-
-
- HapticFeedback.heavyImpact();
- doCalculate();
- doFeatureFinish();
- isSmartMove = false;
- return _syncState(true);
- } else {
- return _syncState(false);
- }
- }
- bool _syncState(bool isSnap) {
- snapState = isSnap;
- return snapState;
- }
- }
|