Prechádzať zdrojové kódy

clear measured items after play

melon.yin 2 rokov pred
rodič
commit
c9d8a589fd

+ 3 - 0
lib/interfaces/process/items/item.dart

@@ -54,6 +54,9 @@ abstract class IMeasureItem {
   /// 处理输入
   bool execute(PointInfo args);
 
+  /// 清空
+  void clear();
+
   /// 快照变化事件
   late FEventHandler<IMeasureItemFeature?> featureUpdated;
 }

+ 11 - 0
lib/process/items/item.dart

@@ -93,6 +93,17 @@ abstract class MeasureItem<T extends MeasureItemFeature> extends IMeasureItem {
     return result;
   }
 
+  @override
+  void clear() {
+    feature = null;
+    if (calculator != null) {
+      calculator!.finishOnce();
+      calculator!.outputs.clear();
+    }
+
+    measuredFeatures.clear();
+  }
+
   @protected
   void doFeatureUpdate() {
     featureUpdated.emit(this, feature);

+ 15 - 6
lib/process/workspace/application.dart

@@ -217,9 +217,11 @@ class Application implements IApplication {
   void _doCanMeasureChanged() {
     canMeasureChanged.emit(this, canMeasure);
 
-    _clearViewPorts();
-    if (canMeasure && frameData != null) {
-      _loadVisuals();
+    _clear();
+    if (canMeasure) {
+      if (frameData != null) {
+        _loadVisuals();
+      }
     }
   }
 
@@ -228,13 +230,20 @@ class Application implements IApplication {
   }
 
   void _loadVisuals() {
-    _visuals = [];
+    _clearVisuals();
     for (final data in frameData!.visuals) {
       _visuals!.add(VisualBase(data));
     }
   }
 
-  void _clearViewPorts() {
-    _visuals = null;
+  void _clear() {
+    for (var item in items) {
+      item.clear();
+    }
+    _clearVisuals();
+  }
+
+  void _clearVisuals() {
+    _visuals = [];
   }
 }