From fe2aa4880d5c9fd88088ad0ed81ebaca05629f5f Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 17:59:45 +0800
Subject: [PATCH] feat: 集成CAN驱动/模拟器 + 仪器仪表注册/硬件调试模块
---
Plugin.SeqEditor/ViewModel/SeqEditorViewModel.cs | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 106 insertions(+), 8 deletions(-)
diff --git a/Plugin.SeqEditor/ViewModel/SeqEditorViewModel.cs b/Plugin.SeqEditor/ViewModel/SeqEditorViewModel.cs
index 70fcd05..fe22156 100644
--- a/Plugin.SeqEditor/ViewModel/SeqEditorViewModel.cs
+++ b/Plugin.SeqEditor/ViewModel/SeqEditorViewModel.cs
@@ -12,6 +12,7 @@
using Plugin.SeqEditor.Util;
using System.Collections.ObjectModel;
using System.IO;
+using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
@@ -60,6 +61,9 @@
private Engine engine;
private SequenceFile sequenceFile;
+
+ public Dictionary<string, SequenceFile> cacheFiles = new Dictionary<string, SequenceFile>();
+
private bool isLoaded;
private ILog log;
public SeqEditor control { get; private set; }
@@ -68,6 +72,15 @@
private HashSet<string> edits = new HashSet<string>();
public Dictionary<Sequence, ObservableCollection<StepUI>> sequenceCache { get; private set; } = new();
+
+ private HashSet<string> indexType = new HashSet<string> {
+ StepTypeStr.PassFailTest,
+ StepTypeStr.NumericLimitTest,
+ StepTypeStr.NI_MultipleNumericLimitTest,
+ StepTypeStr.StringValueTest,
+ StepTypeStr.NI_Wait,
+ StepTypeStr.Action
+ };
public SeqEditorViewModel(SeqEditor control, ILog log)
{
@@ -87,18 +100,23 @@
{
engine.ReleaseSequenceFileEx(sequenceFile);
}
+ foreach (var file in cacheFiles.Values)
+ {
+ engine.ReleaseSequenceFileEx(file);
+ }
engine.ShutDown(true);
// 涓嶅姞寤舵椂浼氬脊绐梞d
- System.Threading.Thread.Sleep(2500);
+ //System.Threading.Thread.Sleep(2500);
}
}
private ObservableCollection<StepUI> LoadSteps(Sequence seq, string group = null)
{
- if (sequenceCache.ContainsKey(seq))
- {
- return sequenceCache[seq];
- }
+ //if (sequenceCache.ContainsKey(seq))
+ //{
+ // return sequenceCache[seq];
+ //}
+
//setupSteps.Clear();
//var steps = new ObservableCollection<StepUI>();
//int num = seq.GetNumSteps(StepGroups.StepGroup_Setup);
@@ -185,6 +203,8 @@
return steps;
}
+ private int indexCache = 0;
+
private StepUI Convert2StepUI(int index, Step step, Sequence sequence, string group)
{
var ui = new StepUI(step, sequence);
@@ -229,6 +249,39 @@
}
ui.Children = LoadSteps(sunSequence, group);
}
+ else
+ {
+ string seqName = po.GetValString("SeqName", 0);
+ if (!Path.IsPathRooted(sfPath))
+ {
+ sfPath = Path.Combine(Path.GetDirectoryName(CurrentFilePath), sfPath);
+ }
+ SequenceFile diffSequence = null;
+ try
+ {
+ if (cacheFiles.ContainsKey(sfPath))
+ {
+ diffSequence = cacheFiles[sfPath];
+ }
+ else if (File.Exists(sfPath))
+ {
+ diffSequence = engine.GetSequenceFileEx(sfPath);
+ cacheFiles[sfPath] = diffSequence;
+ }
+ }
+ catch (Exception ex)
+ {
+ log.Warn("Read Diff SubSequence Failed.", ex);
+ }
+ if (diffSequence != null)
+ {
+ Sequence sunSequence = diffSequence.GetSequenceByName(seqName);
+ ui.Children = LoadSteps(sunSequence, group);
+ }
+ }
+ }
+ else
+ {
}
if (CurrentSeqUI != null)
{
@@ -303,6 +356,10 @@
{
sequenceFile?.Save(CurrentFilePath);
CurrentSeqUI.IsChanged = false;
+ foreach (var key in cacheFiles.Keys)
+ {
+ cacheFiles[key]?.Save(key);
+ }
ToastHelper.Success(LangUtil.Get("App.SaveSuccess"));
}
catch (Exception ex)
@@ -326,6 +383,10 @@
{
sequenceFile.Save(sfd.FileName);
CurrentFilePath = sfd.FileName;
+ foreach (var key in cacheFiles.Keys)
+ {
+ cacheFiles[key]?.Save(key);
+ }
ToastHelper.Success(LangUtil.Get("App.SaveSuccess"));
CurrentSeqUI.IsChanged = false;
}
@@ -363,9 +424,14 @@
if (engine != null && sequenceFile != null)
{
engine.ReleaseSequenceFileEx(sequenceFile);
+ foreach (var file in cacheFiles.Values)
+ {
+ engine.ReleaseSequenceFileEx(file);
+ }
sequenceFile = null;
}
+ cacheFiles.Clear();
setupSteps.Clear();
mainSteps.Clear();
cleanupSteps.Clear();
@@ -468,7 +534,7 @@
}
var newUI = new StepUI(newStep, targetSequence);
-
+
targetSequence.InsertStep(newStep, index + 1, group);
ObservableCollection<StepUI> datasource = sequenceCache[targetSequence];
int uiIndex = datasource.IndexOf(CurrentStepUI);
@@ -488,7 +554,7 @@
// var items = parentItem.Items;
// int innerIndex = items.IndexOf(TreeItemData);
-
+
// items.Insert(innerIndex + 1, newItem);
// TreeItemDataCollection.ResetSubItems(items);
//}
@@ -544,8 +610,40 @@
public void RefreshData()
{
+ indexCache = 0;
sequenceCache.Clear();
- AllSteps = LoadSteps(CurrentSeqUI.sequence);
+ foreach (var file in cacheFiles.Values)
+ {
+ try
+ {
+ engine.ReleaseSequenceFileEx(file);
+ Marshal.ReleaseComObject(file);
+ }
+ catch (Exception ex)
+ {
+ log.Error("RefreshData Release Last CacheFile Failed.", ex);
+ }
+ }
+ var converter = control.Resources["treeNumber"] as RowNumberConverter;
+ converter.Reset();
+ var temp = LoadSteps(CurrentSeqUI.sequence);
+ SetIndex(temp);
+ AllSteps = temp;
+ }
+
+ void SetIndex(IEnumerable<StepUI> datas)
+ {
+ foreach (var data in datas)
+ {
+ if (indexType.Contains(data.Type))
+ {
+ data.CustomIndex = ++indexCache;
+ }
+ if (data.Children != null && data.Children.Count > 0)
+ {
+ SetIndex(data.Children);
+ }
+ }
}
partial void OnAllStepsChanged(ObservableCollection<StepUI> data)
--
Gitblit v1.9.1