diff --git a/ADP/ViewModels/ShellViewModel.cs b/ADP/ViewModels/ShellViewModel.cs index eca07c9..6e27550 100644 --- a/ADP/ViewModels/ShellViewModel.cs +++ b/ADP/ViewModels/ShellViewModel.cs @@ -1,6 +1,7 @@  using Logger; using MaterialDesignThemes.Wpf; +using Model.Models; using Notifications.Wpf.Core; using System.Collections.Concurrent; using System.Diagnostics; @@ -495,7 +496,15 @@ namespace ADP.ViewModels targetContext.Program.Parameters.Clear(); targetContext.Program.StepCollection.Clear(); targetContext.Program.ErrorStepCollection.Clear(); - + foreach (var item in CurrentConfig.ParameterList) + { + var param = CurrentConfig.SharedParameterList.FirstOrDefault(x => x.ParameterName == item.Name); + if (param != null) + { + item.Value = param.Value; + } + targetContext.Program.Parameters.Add(item); + } LoggerHelper.InfoWithNotify($"工位 [{runningScope}] 创建了空程序文件"); // 如果当前正看着该工位,刷新 UI 显示 @@ -552,6 +561,16 @@ namespace ADP.ViewModels targetContext.Program.ErrorStepCollection = program.ErrorStepCollection; targetContext.CurrentFilePath = filePath; + foreach (var item in CurrentConfig.SharedParameterList) + { + var parameter = targetContext?.Program?.Parameters?.FirstOrDefault(x => x.Name == item.ParameterName); + + if (parameter != null) + { + parameter.Value = item.Value; + } + } + LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 成功打开文件: {filePath}"); // 💡 3. 安全调用异步复位,确保重置的是对应工位的数据 diff --git a/MainModule/ViewModels/AutomatedTestingViewModel.cs b/MainModule/ViewModels/AutomatedTestingViewModel.cs index 7b566e4..865034a 100644 --- a/MainModule/ViewModels/AutomatedTestingViewModel.cs +++ b/MainModule/ViewModels/AutomatedTestingViewModel.cs @@ -173,6 +173,15 @@ namespace MainModule.ViewModels _scopedContext.Program.StepCollection = program.StepCollection; _scopedContext.Program.ErrorStepCollection = program.ErrorStepCollection; _scopedContext.CurrentFilePath = filePath; + foreach (var item in _systemConfig.SharedParameterList) + { + var parameter = _scopedContext?.Program?.Parameters?.FirstOrDefault(x => x.Name == item.ParameterName); + + if (parameter != null) + { + parameter.Value = item.Value; + } + } } } diff --git a/Model/Models/Parameter.cs b/Model/Models/Parameter.cs index d8b0aa5..24a45c3 100644 --- a/Model/Models/Parameter.cs +++ b/Model/Models/Parameter.cs @@ -24,7 +24,6 @@ namespace Model.Models /// public string? Category { get; set; } - public bool IsGlobal { get; set; } public object? Value { get; set; } @@ -36,7 +35,6 @@ namespace Model.Models public bool IsUseVar { get; set; } - public bool IsSave { get; set; } public string? VariableName { get; set; } diff --git a/SettingModule/ViewModels/SettingViewModel.cs b/SettingModule/ViewModels/SettingViewModel.cs index 2e996be..d1ba846 100644 --- a/SettingModule/ViewModels/SettingViewModel.cs +++ b/SettingModule/ViewModels/SettingViewModel.cs @@ -44,6 +44,11 @@ namespace SettingModule.ViewModels { get => _deviceList; set => SetProperty(ref _deviceList, value); + } + public ObservableCollection SharedParameterList + { + get => _sharedParameterList; + set => SetProperty(ref _sharedParameterList, value); } public string StatusMessage @@ -72,6 +77,7 @@ namespace SettingModule.ViewModels private string _testStatus = string.Empty; private DeviceInfoVM? _selectedDevice; private ObservableCollection _deviceList; + private ObservableCollection _sharedParameterList; private string _statusMessage = "请在左侧选择设备查看 / 编辑配置"; #endregion public SettingViewModel(IContainerExtension container) : base(container) @@ -199,6 +205,20 @@ namespace SettingModule.ViewModels SelectedDevice = DeviceList[0]; } DeviceList = SystemConfig.DeviceList; + SharedParameterList=SystemConfig.SharedParameterList; + if (SharedParameterList.Count == 0) + { + foreach (var device in SystemConfig.ParameterList) + { + var sharedParam = new SharedParameter + { + Id = device.ID.ToString(), + ParameterName = device.Name, + Value = device.Value is int intVal ? intVal : Convert.ToInt32(device.Value) + }; + SharedParameterList.Add(sharedParam); + } + } IsInitiated = true; } } diff --git a/SettingModule/Views/SettingView.xaml b/SettingModule/Views/SettingView.xaml index 9b5f5cb..ca90ae7 100644 --- a/SettingModule/Views/SettingView.xaml +++ b/SettingModule/Views/SettingView.xaml @@ -462,6 +462,33 @@ + + + + + + + + + + + + + + + + + + + + + _DeviceList; - - //public ObservableCollection DeviceList - //{ - // get { return _DeviceList; } - // set { SetProperty(ref _DeviceList,value); } - //} private ObservableCollection _DeviceInfoModel; public ObservableCollection DeviceInfoVM @@ -82,7 +75,6 @@ namespace TestingModule.ViewModels public ParametersManagerViewModel(IContainerProvider containerProvider) : base(containerProvider) { - _ScopedContext = containerProvider.Resolve(); _systemConfig = containerProvider.Resolve(); _deviceManager = containerProvider.Resolve(); @@ -96,8 +88,24 @@ namespace TestingModule.ViewModels ReConnectCommand = new AsyncDelegateCommand(OnReConnect); CloseCommand = new AsyncDelegateCommand(OnClose); LoadedCommand = new DelegateCommand(OnLoad); + InitParameters(); + } + + + #region 委托命令 + private void InitParameters() + { + foreach(var item in _systemConfig.ParameterList) + { + var copy=new ParameterVM(item); + var param = _systemConfig.SharedParameterList.FirstOrDefault(x => x.ParameterName == copy.Name); + if (param != null) + { + copy.Value = param.Value; + } + Program.Parameters.Add(copy); + } } - #region 委托命令 private void OnLoad() { DeviceInfoVM = _systemConfig.DeviceList; diff --git a/TestingModule/Views/Dialogs/ParameterSetting.xaml b/TestingModule/Views/Dialogs/ParameterSetting.xaml index cf15558..1d0ea0c 100644 --- a/TestingModule/Views/Dialogs/ParameterSetting.xaml +++ b/TestingModule/Views/Dialogs/ParameterSetting.xaml @@ -110,10 +110,7 @@ ItemsSource="{Binding EnumValues}" SelectedItem="{Binding Parameter.Value}" Visibility="{Binding Parameter.Type, Converter={StaticResource IsEnumTypeConverter}}" />--> - + diff --git a/UIShare/GlobalVariable/StepRunning.cs b/UIShare/GlobalVariable/StepRunning.cs index 539625c..f359849 100644 --- a/UIShare/GlobalVariable/StepRunning.cs +++ b/UIShare/GlobalVariable/StepRunning.cs @@ -621,10 +621,7 @@ namespace UIShare { LoggerHelper.WarnWithNotify(tmp.Item2); } - //if (currentPara.IsSave && _scopedContext.Program.Parameters.FirstOrDefault(x => x.ID == currentPara.ID) != null) - //{ - // _ = SaveDataToDatabase(_scopedContext.Program.ID, currentPara); - //} + } var returnType = returnValue?.GetType(); if (returnType != null) diff --git a/UIShare/GlobalVariable/SystemConfig.cs b/UIShare/GlobalVariable/SystemConfig.cs index 09f812a..f43b872 100644 --- a/UIShare/GlobalVariable/SystemConfig.cs +++ b/UIShare/GlobalVariable/SystemConfig.cs @@ -9,6 +9,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using UIShare.UIViewModel; +using static UIShare.UIViewModel.ParameterVM; namespace UIShare.GlobalVariable { @@ -27,6 +28,53 @@ namespace UIShare.GlobalVariable public string DefaultBLFFilePath { get; set; } = ""; public string DefaultDBCFilePath { get; set; } = ""; public ObservableCollection DeviceList = new(); + public ObservableCollection SharedParameterList = new(); + [JsonIgnore] + public ObservableCollection ParameterList = new() + { + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "继电器占位1", + Value = 0, + }, + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "继电器占位2", + Value = 1, + }, + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "CAN通道", + Value = 0, + }, + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "示波器通道", + Value = 0, + }, + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "功率分析仪通道1", + Value = 0, + }, + new ParameterVM + { + Category = ParameterCategory.Input, + Type = typeof(int), + Name = "功率分析仪通道2", + Value = 0, + }, + }; // public ObservableCollection DeviceList { get; set; } = new() //{ // new DeviceInfoVM diff --git a/UIShare/UIViewModel/ParameterVM.cs b/UIShare/UIViewModel/ParameterVM.cs index c2fd642..68ac020 100644 --- a/UIShare/UIViewModel/ParameterVM.cs +++ b/UIShare/UIViewModel/ParameterVM.cs @@ -23,10 +23,8 @@ namespace UIShare.UIViewModel Type = source.Type; Category = source.Category; IsUseVar = source.IsUseVar; - IsSave = source.IsSave; VariableName = source.VariableName; VariableID = source.VariableID; - IsGlobal = source.IsGlobal; Value = source.Value; LowerLimit = source.LowerLimit; UpperLimit = source.UpperLimit; @@ -69,12 +67,6 @@ namespace UIShare.UIViewModel set => SetProperty(ref _category, value); } - private bool _isGlobal; - public bool IsGlobal - { - get => _isGlobal; - set => SetProperty(ref _isGlobal, value); - } private object? _value; public object? Value @@ -111,12 +103,7 @@ namespace UIShare.UIViewModel set => SetProperty(ref _isUseVar, value); } - private bool _isSave; - public bool IsSave - { - get => _isSave; - set => SetProperty(ref _isSave, value); - } + private string? _variableName; public string? VariableName diff --git a/UIShare/UIViewModel/SharedParameter.cs b/UIShare/UIViewModel/SharedParameter.cs new file mode 100644 index 0000000..7c3f067 --- /dev/null +++ b/UIShare/UIViewModel/SharedParameter.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UIShare.UIViewModel +{ + public class SharedParameter:BindableBase + { + private string _id; + public string Id + { + get => _id; + set => SetProperty(ref _id, value); + } + private string _parameterName; + public string ParameterName + { + get => _parameterName; + set => SetProperty(ref _parameterName, value); + } + private int _value; + public int Value + { + get => _value; + set => SetProperty(ref _value, value); + } + } +}