From ef52fd6fd07508883dce4eb002acda59f0169e59 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 23 四月 2026 10:19:33 +0800
Subject: [PATCH] 优化;
---
Plugin.SeqEditor/Entity/StepUI.cs | 316 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 310 insertions(+), 6 deletions(-)
diff --git a/Plugin.SeqEditor/Entity/StepUI.cs b/Plugin.SeqEditor/Entity/StepUI.cs
index 79f71b0..84275ef 100644
--- a/Plugin.SeqEditor/Entity/StepUI.cs
+++ b/Plugin.SeqEditor/Entity/StepUI.cs
@@ -1,21 +1,55 @@
锘縰sing CommunityToolkit.Mvvm.ComponentModel;
using NationalInstruments.TestStand.Interop.API;
+using Plugin.SeqEditor.Constant;
using System.Collections.ObjectModel;
+using System.Runtime.InteropServices;
namespace Plugin.SeqEditor.Entity
{
public partial class StepUI : ObservableObject
{
- public Step step { get; private set; }
- public StepUI(Step step)
+ ~StepUI()
+ {
+ if (step != null)
+ {
+ Marshal.ReleaseComObject(step);
+ }
+ }
+
+ public Step step { get; private set; }
+ public Sequence sequence { get; private set; }
+
+ public event EventHandler<string> SettingChanged;
+
+ public int IndexInSequence
+ {
+ get
+ {
+ return step.StepIndex;
+ }
+ }
+
+ public int? CustomIndex
+ {
+ get; set;
+ }
+
+ public StepUI(Step step, Sequence sequence)
{
this.step = step;
+ this.sequence = sequence;
}
public void UpdatePropertyChanged(string name)
{
OnPropertyChanged(name);
+ }
+
+ protected new void OnPropertyChanged(string name)
+ {
+ base.OnPropertyChanged(name);
+ SettingChanged?.Invoke(this, name);
}
public string Name
@@ -31,6 +65,11 @@
}
}
+ public string Id
+ {
+ get => step?.UniqueStepId;
+ }
+
public string Description
{
get => step?.Description;
@@ -38,7 +77,11 @@
public string RunMode
{
- get => step?.GetRunModeEx();
+ get
+ {
+ var t = step?.GetRunModeEx();
+ return t;
+ }
set
{
if (step != null)
@@ -72,13 +115,84 @@
}
}
+ public bool HasLow => Type == StepTypeStr.NumericLimitTest || Type == StepTypeStr.StringValueTest;
+ public bool HasHigh => Type == StepTypeStr.NumericLimitTest;
-
- public StepGroups? StepGroup
+ public string Low
{
get
{
- return step?.StepGroup;
+ if (Type == StepTypeStr.NumericLimitTest)
+ {
+ return step?.AsPropertyObject()?.GetValNumber("Limits.Low", 0).ToString();
+ }
+ else if (Type == StepTypeStr.StringValueTest)
+ {
+ var value = step?.AsPropertyObject()?.GetValString("Limits.String", 0);
+ if (string.IsNullOrEmpty(value))
+ {
+ value = step?.AsPropertyObject()?.GetValString("Limits.StringExpr", 0);
+ }
+ return value;
+ }
+ return null;
+ }
+ set
+ {
+ if (step != null && HasLow)
+ {
+ if (Type == StepTypeStr.NumericLimitTest)
+ {
+ double.TryParse(value, out double tmp);
+ step?.AsPropertyObject().SetValNumber("Limits.Low", 0, tmp);
+ }
+ else if (Type == StepTypeStr.StringValueTest)
+ {
+ step?.AsPropertyObject()?.SetValString("Limits.String", 0, value);
+ step?.AsPropertyObject()?.SetValString("Limits.StringExpr", 0, null);
+ step?.AsPropertyObject()?.SetValBoolean("Limits.UseStringExpr", 0, false);
+ }
+ UpdatePropertyChanged("Low");
+ UpdatePropertyChanged("Description");
+ }
+ }
+ }
+
+ public double? High
+ {
+ get => HasHigh ? step?.AsPropertyObject()?.GetValNumber("Limits.High", 0) : null;
+ set
+ {
+ if (step != null && HasHigh)
+ {
+ step?.AsPropertyObject().SetValNumber("Limits.High", 0, value ?? 0);
+ UpdatePropertyChanged("High");
+ UpdatePropertyChanged("Description");
+ }
+ }
+ }
+
+ public StepGroups StepGroup
+ {
+ get
+ {
+ return step.StepGroup;
+ }
+ }
+
+ public string CallSeqPath
+ {
+ get
+ {
+ return step?.Module?.AsPropertyObject()?.GetValString("SFPath", 0); ;
+ }
+ }
+
+ public string CallSeqName
+ {
+ get
+ {
+ return step?.Module?.AsPropertyObject()?.GetValString("SeqName", 0); ;
}
}
@@ -87,5 +201,195 @@
[ObservableProperty]
public ObservableCollection<StepUI> children = new();
+
+ public string LoopType
+ {
+ get => step?.AsPropertyObject()?.GetValString("TS.LoopType", 0);
+ set
+ {
+ if (step != null)
+ {
+ if (value == "FixedNumLoops")
+ {
+ step.AsPropertyObject().SetValString("TS.LoopType", 0, value);
+ step.AsPropertyObject().SetValString("TS.LoopWhile", 0, "RunState.LoopIndex < 10");
+ step.AsPropertyObject().SetValString("TS.LoopStatus", 0, "RunState.LoopNumPassed / RunState.LoopNumIterations < 1 ? \"Failed\" : \"Passed\"");
+ }
+ else if (value == "PassFailCount")
+ {
+ step.AsPropertyObject().SetValString("TS.LoopType", 0, value);
+ step.AsPropertyObject().SetValString("TS.LoopWhile", 0, "RunState.LoopIndex < 100 && RunState.LoopNumFailed < 10");
+ step.AsPropertyObject().SetValString("TS.LoopStatus", 0, "RunState.LoopNumFailed >= 10 ? \"Failed\" : \"Passed\"");
+ }
+ UpdatePropertyChanged("LoopType");
+ UpdatePropertyChanged("LoopCount");
+ UpdatePropertyChanged("LoopCondition");
+ UpdatePropertyChanged("LoopMax");
+ UpdatePropertyChanged("LoopDescription");
+ }
+ }
+ }
+
+ public string LoopCount
+ {
+ get
+ {
+ if (step == null || step?.AsPropertyObject() == null) return null;
+ string type = step.AsPropertyObject().GetValString("TS.LoopType", 0);
+ string loopWhile;
+ switch (type)
+ {
+ case "FixedNumLoops":
+ loopWhile = step.AsPropertyObject().GetValString("TS.LoopWhile", 0);
+ return loopWhile.Replace($"RunState.LoopIndex < ", "");
+ case "PassFailCount":
+ loopWhile = step.AsPropertyObject().GetValString("TS.LoopWhile", 0);
+ return loopWhile.Split(' ')[2];
+ default:
+ return null;
+ }
+ }
+ set
+ {
+ if (step != null)
+ {
+ string type = step.AsPropertyObject().GetValString("TS.LoopType", 0);
+ switch (type)
+ {
+ case "FixedNumLoops":
+ step.AsPropertyObject().SetValString("TS.LoopWhile", 0, $"RunState.LoopIndex < {value}");
+ UpdatePropertyChanged("LoopDescription");
+ return;
+ case "PassFailCount":
+ var field = LoopCondition == "pass" ? "LoopNumPassed" : "LoopNumFailed";
+ step.AsPropertyObject().SetValString("TS.LoopWhile", 0,
+ $"RunState.LoopIndex < {value} && RunState.{field} < {LoopMax}");
+ UpdatePropertyChanged("LoopDescription");
+ return;
+ default:
+ return;
+ }
+ }
+ }
+ }
+
+ public string LoopCondition
+ {
+ get
+ {
+ if (step == null || step?.AsPropertyObject() == null) return null;
+ string type = step.AsPropertyObject().GetValString("TS.LoopType", 0);
+ string loopStatus;
+ switch (type)
+ {
+ case "FixedNumLoops":
+ loopStatus = step.AsPropertyObject().GetValString("TS.LoopStatus", 0);
+ return loopStatus.Split(' ')[3];
+ case "PassFailCount":
+ loopStatus = step.AsPropertyObject().GetValString("TS.LoopStatus", 0);
+ return loopStatus.Split(' ')[0] == "RunState.LoopNumPassed" ? "pass" : "fail";
+ default:
+ return null;
+ }
+ }
+ set
+ {
+ if (step != null)
+ {
+ string type = step.AsPropertyObject().GetValString("TS.LoopType", 0);
+ switch (type)
+ {
+ case "FixedNumLoops":
+ step.AsPropertyObject().SetValString("TS.LoopStatus", 0,
+ $"RunState.LoopNumPassed / RunState.LoopNumIterations {value} {double.Parse(LoopMax) / 100} ? \"Failed\" : \"Passed\"");
+ UpdatePropertyChanged("LoopDescription");
+ return;
+ case "PassFailCount":
+ var field = value == "pass" ? "LoopNumPassed" : "LoopNumFailed";
+ var sb = value == "pass" ? "\"Passed\" : \"Failed\"" : "\"Failed\" : \"Passed\"";
+ step.AsPropertyObject().SetValString("TS.LoopWhile", 0,
+ $"RunState.LoopIndex < {LoopCount} && RunState.{field} < {LoopMax}");
+ step.AsPropertyObject().SetValString("TS.LoopStatus", 0,
+ $"RunState.{field} >= {LoopMax} ? {sb}");
+ UpdatePropertyChanged("LoopDescription");
+ return;
+ default:
+ return;
+ }
+
+ }
+ }
+ }
+
+ public string LoopMax
+ {
+ get
+ {
+ if (step == null || step?.AsPropertyObject() == null) return null;
+ string type = step.AsPropertyObject().GetValString("TS.LoopType", 0);
+ string data;
+ switch (type)
+ {
+ case "FixedNumLoops":
+ data = step.AsPropertyObject().GetValString("TS.LoopStatus", 0);
+ return (double.Parse(data.Split(' ')[4]) * 100).ToString();
+ case "PassFailCount":
+ data = step.AsPropertyObject().GetValString("TS.LoopWhile", 0);
+ return data.Split(' ')[6];
+ default:
+ return null;
+ }
+ }
+ set
+ {
+ if (step != null)
+ {
+ string type = step.AsPropertyObject().GetValString("TS.LoopType", 0);
+ switch (type)
+ {
+ case "FixedNumLoops":
+ step.AsPropertyObject().SetValString("TS.LoopStatus", 0,
+ $"RunState.LoopNumPassed / RunState.LoopNumIterations {LoopCondition} {double.Parse(value) / 100} ? \"Failed\" : \"Passed\"");
+ UpdatePropertyChanged("LoopDescription");
+ return;
+ case "PassFailCount":
+ var field = LoopCondition == "pass" ? "LoopNumPassed" : "LoopNumFailed";
+ step.AsPropertyObject().SetValString("TS.LoopWhile", 0,
+ $"RunState.LoopIndex < {LoopCount} && RunState.{field} < {value}");
+ UpdatePropertyChanged("LoopDescription");
+ return;
+ default:
+ return;
+ }
+
+ }
+ }
+ }
+
+ public string LoopDescription
+ {
+ get
+ {
+ if (step == null || step?.AsPropertyObject() == null) return null;
+ string type = step.AsPropertyObject().GetValString("TS.LoopType", 0);
+ switch (type)
+ {
+ case "FixedNumLoops":
+ return $"寰幆{LoopCount}娆★紝閫氳繃鐜噞LoopCondition}{LoopMax}%鏃剁粨鏋滀负PASS";
+ case "PassFailCount":
+ return $"寰幆{LoopCount}娆★紝{LoopCondition} {LoopMax}娆′互涓婄粨鏋滀负{LoopCondition}";
+ default:
+ return null;
+ }
+ }
+ set
+ {
+ }
+ }
+
+ public override string ToString()
+ {
+ return Name;
+ }
}
}
--
Gitblit v1.9.1