|
@@ -0,0 +1,107 @@
|
|
|
+import 'package:fis_measure/interfaces/enums/annotation.dart';
|
|
|
+import 'package:fis_measure/interfaces/process/workspace/application.dart';
|
|
|
+import 'package:fis_measure/interfaces/process/workspace/recorder.dart';
|
|
|
+
|
|
|
+class MeasureRecorder implements IMeasureRecorder {
|
|
|
+ int _lastId = 0;
|
|
|
+ final List<_RecordModelBase> _records = [];
|
|
|
+ late final IApplication _application;
|
|
|
+
|
|
|
+ MeasureRecorder(IApplication application) {
|
|
|
+ _application = application;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @override
|
|
|
+ int newRecordId() {
|
|
|
+ return _lastId + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @override
|
|
|
+ void recordMeasureItem(String name) {
|
|
|
+ _records.add(_MeasureModel(name));
|
|
|
+ _increaseId();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @override
|
|
|
+ void recordAnnotation(AnnotationType type) {
|
|
|
+ _records.add(_AnnotationModel(type));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ bool undoOnce() {
|
|
|
+ final record = _records.last;
|
|
|
+ bool removed = false;
|
|
|
+ if (record.recordType == MeasureRecordType.measure) {
|
|
|
+ removed = _undoOnceMeasure(record as _MeasureModel);
|
|
|
+ } else if (record.recordType == MeasureRecordType.annotation) {
|
|
|
+ removed = _undoOnceAnnotation(record as _AnnotationModel);
|
|
|
+ }
|
|
|
+ if (removed) {
|
|
|
+ _records.removeLast();
|
|
|
+ }
|
|
|
+ return removed;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ void clear() {
|
|
|
+ final len = _records.length;
|
|
|
+ for (var i = 0; i < len; i++) {
|
|
|
+ undoOnce();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bool _undoOnceMeasure(_MeasureModel record) {
|
|
|
+ final matchs =
|
|
|
+ _application.measureItems.where((e) => e.meta.name == record.name);
|
|
|
+ if (matchs.isEmpty) return false;
|
|
|
+
|
|
|
+ final item = matchs.last;
|
|
|
+ item.measuredFeatures.removeLast();
|
|
|
+ item.calculator?.outputs.removeLast();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ bool _undoOnceAnnotation(_AnnotationModel record) {
|
|
|
+ final matchs =
|
|
|
+ _application.annotationItems.where((e) => e.type == record.type);
|
|
|
+ if (matchs.isEmpty) return false;
|
|
|
+
|
|
|
+ final item = matchs.last;
|
|
|
+ item.features.removeLast();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ void _increaseId() {
|
|
|
+ _lastId++;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class _MeasureModel extends _RecordModelBase {
|
|
|
+ _MeasureModel(this.name) : super(MeasureRecordType.measure);
|
|
|
+
|
|
|
+ String name;
|
|
|
+}
|
|
|
+
|
|
|
+class _AnnotationModel extends _RecordModelBase {
|
|
|
+ _AnnotationModel(this.type) : super(MeasureRecordType.annotation);
|
|
|
+
|
|
|
+ AnnotationType type;
|
|
|
+}
|
|
|
+
|
|
|
+class _RecordModelBase {
|
|
|
+ _RecordModelBase(this.recordType);
|
|
|
+ MeasureRecordType recordType;
|
|
|
+}
|
|
|
+
|
|
|
+enum MeasureRecordType {
|
|
|
+ measure,
|
|
|
+ annotation,
|
|
|
+}
|