共有变量添加
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
using Logger;
|
using Logger;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
|
using Model.Models;
|
||||||
using Notifications.Wpf.Core;
|
using Notifications.Wpf.Core;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -495,7 +496,15 @@ namespace ADP.ViewModels
|
|||||||
targetContext.Program.Parameters.Clear();
|
targetContext.Program.Parameters.Clear();
|
||||||
targetContext.Program.StepCollection.Clear();
|
targetContext.Program.StepCollection.Clear();
|
||||||
targetContext.Program.ErrorStepCollection.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}] 创建了空程序文件");
|
LoggerHelper.InfoWithNotify($"工位 [{runningScope}] 创建了空程序文件");
|
||||||
|
|
||||||
// 如果当前正看着该工位,刷新 UI 显示
|
// 如果当前正看着该工位,刷新 UI 显示
|
||||||
@@ -552,6 +561,16 @@ namespace ADP.ViewModels
|
|||||||
targetContext.Program.ErrorStepCollection = program.ErrorStepCollection;
|
targetContext.Program.ErrorStepCollection = program.ErrorStepCollection;
|
||||||
targetContext.CurrentFilePath = filePath;
|
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}");
|
LoggerHelper.SuccessWithNotify($"工位 [{runningScope}] 成功打开文件: {filePath}");
|
||||||
|
|
||||||
// 💡 3. 安全调用异步复位,确保重置的是对应工位的数据
|
// 💡 3. 安全调用异步复位,确保重置的是对应工位的数据
|
||||||
|
|||||||
@@ -173,6 +173,15 @@ namespace MainModule.ViewModels
|
|||||||
_scopedContext.Program.StepCollection = program.StepCollection;
|
_scopedContext.Program.StepCollection = program.StepCollection;
|
||||||
_scopedContext.Program.ErrorStepCollection = program.ErrorStepCollection;
|
_scopedContext.Program.ErrorStepCollection = program.ErrorStepCollection;
|
||||||
_scopedContext.CurrentFilePath = filePath;
|
_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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ namespace Model.Models
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Category { get; set; }
|
public string? Category { get; set; }
|
||||||
|
|
||||||
public bool IsGlobal { get; set; }
|
|
||||||
|
|
||||||
public object? Value { get; set; }
|
public object? Value { get; set; }
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ namespace Model.Models
|
|||||||
|
|
||||||
public bool IsUseVar { get; set; }
|
public bool IsUseVar { get; set; }
|
||||||
|
|
||||||
public bool IsSave { get; set; }
|
|
||||||
|
|
||||||
public string? VariableName { get; set; }
|
public string? VariableName { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ namespace SettingModule.ViewModels
|
|||||||
{
|
{
|
||||||
get => _deviceList;
|
get => _deviceList;
|
||||||
set => SetProperty(ref _deviceList, value);
|
set => SetProperty(ref _deviceList, value);
|
||||||
|
}
|
||||||
|
public ObservableCollection<SharedParameter> SharedParameterList
|
||||||
|
{
|
||||||
|
get => _sharedParameterList;
|
||||||
|
set => SetProperty(ref _sharedParameterList, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string StatusMessage
|
public string StatusMessage
|
||||||
@@ -72,6 +77,7 @@ namespace SettingModule.ViewModels
|
|||||||
private string _testStatus = string.Empty;
|
private string _testStatus = string.Empty;
|
||||||
private DeviceInfoVM? _selectedDevice;
|
private DeviceInfoVM? _selectedDevice;
|
||||||
private ObservableCollection<DeviceInfoVM> _deviceList;
|
private ObservableCollection<DeviceInfoVM> _deviceList;
|
||||||
|
private ObservableCollection<SharedParameter> _sharedParameterList;
|
||||||
private string _statusMessage = "请在左侧选择设备查看 / 编辑配置";
|
private string _statusMessage = "请在左侧选择设备查看 / 编辑配置";
|
||||||
#endregion
|
#endregion
|
||||||
public SettingViewModel(IContainerExtension container) : base(container)
|
public SettingViewModel(IContainerExtension container) : base(container)
|
||||||
@@ -199,6 +205,20 @@ namespace SettingModule.ViewModels
|
|||||||
SelectedDevice = DeviceList[0];
|
SelectedDevice = DeviceList[0];
|
||||||
}
|
}
|
||||||
DeviceList = SystemConfig.DeviceList;
|
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;
|
IsInitiated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -462,6 +462,33 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
|
<Border Background="White"
|
||||||
|
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||||
|
CornerRadius="4" Padding="14"
|
||||||
|
Margin="0,0,0,12">
|
||||||
|
<StackPanel>
|
||||||
|
<TextBlock Text="公共变量(SharedParameterList)" FontWeight="Bold" FontSize="14" Margin="0,0,0,10"/>
|
||||||
|
<TextBlock Foreground="#888" FontSize="12" TextWrapping="Wrap"
|
||||||
|
Text="每个台架可独立设置自己的通道号等整型变量;新建或打开程序时会用此处值覆盖程序中的同名变量。" Margin="0,0,0,10"/>
|
||||||
|
<ItemsControl ItemsSource="{Binding SharedParameterList}">
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Grid Margin="0,4">
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="160"/>
|
||||||
|
<ColumnDefinition Width="*"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<TextBlock Grid.Column="0" Text="{Binding ParameterName}" VerticalAlignment="Center"/>
|
||||||
|
<TextBox Grid.Column="1"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Text="{Binding Value, UpdateSourceTrigger=PropertyChanged}"/>
|
||||||
|
</Grid>
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
|
||||||
<Border Background="White"
|
<Border Background="White"
|
||||||
BorderBrush="#E0E0E0" BorderThickness="1"
|
BorderBrush="#E0E0E0" BorderThickness="1"
|
||||||
CornerRadius="4" Padding="14"
|
CornerRadius="4" Padding="14"
|
||||||
|
|||||||
@@ -16,13 +16,6 @@ namespace TestingModule.ViewModels
|
|||||||
public class ParametersManagerViewModel:NavigateViewModelBase, IDisposable
|
public class ParametersManagerViewModel:NavigateViewModelBase, IDisposable
|
||||||
{
|
{
|
||||||
#region 属性
|
#region 属性
|
||||||
//private ObservableCollection<DeviceConfigModel> _DeviceList;
|
|
||||||
|
|
||||||
//public ObservableCollection<DeviceConfigModel> DeviceList
|
|
||||||
//{
|
|
||||||
// get { return _DeviceList; }
|
|
||||||
// set { SetProperty(ref _DeviceList,value); }
|
|
||||||
//}
|
|
||||||
private ObservableCollection<DeviceInfoVM> _DeviceInfoModel;
|
private ObservableCollection<DeviceInfoVM> _DeviceInfoModel;
|
||||||
|
|
||||||
public ObservableCollection<DeviceInfoVM> DeviceInfoVM
|
public ObservableCollection<DeviceInfoVM> DeviceInfoVM
|
||||||
@@ -82,7 +75,6 @@ namespace TestingModule.ViewModels
|
|||||||
|
|
||||||
public ParametersManagerViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
public ParametersManagerViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||||
{
|
{
|
||||||
|
|
||||||
_ScopedContext = containerProvider.Resolve<ScopedContext>();
|
_ScopedContext = containerProvider.Resolve<ScopedContext>();
|
||||||
_systemConfig = containerProvider.Resolve<SystemConfig>();
|
_systemConfig = containerProvider.Resolve<SystemConfig>();
|
||||||
_deviceManager = containerProvider.Resolve<DeviceManager>();
|
_deviceManager = containerProvider.Resolve<DeviceManager>();
|
||||||
@@ -96,8 +88,24 @@ namespace TestingModule.ViewModels
|
|||||||
ReConnectCommand = new AsyncDelegateCommand(OnReConnect);
|
ReConnectCommand = new AsyncDelegateCommand(OnReConnect);
|
||||||
CloseCommand = new AsyncDelegateCommand(OnClose);
|
CloseCommand = new AsyncDelegateCommand(OnClose);
|
||||||
LoadedCommand = new DelegateCommand(OnLoad);
|
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()
|
private void OnLoad()
|
||||||
{
|
{
|
||||||
DeviceInfoVM = _systemConfig.DeviceList;
|
DeviceInfoVM = _systemConfig.DeviceList;
|
||||||
|
|||||||
@@ -110,10 +110,7 @@
|
|||||||
ItemsSource="{Binding EnumValues}"
|
ItemsSource="{Binding EnumValues}"
|
||||||
SelectedItem="{Binding Parameter.Value}"
|
SelectedItem="{Binding Parameter.Value}"
|
||||||
Visibility="{Binding Parameter.Type, Converter={StaticResource IsEnumTypeConverter}}" />-->
|
Visibility="{Binding Parameter.Type, Converter={StaticResource IsEnumTypeConverter}}" />-->
|
||||||
<CheckBox Margin="10,0"
|
|
||||||
VerticalAlignment="Bottom"
|
|
||||||
Content="保存数据"
|
|
||||||
IsChecked="{Binding Parameter.IsSave}" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
|||||||
@@ -621,10 +621,7 @@ namespace UIShare
|
|||||||
{
|
{
|
||||||
LoggerHelper.WarnWithNotify(tmp.Item2);
|
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();
|
var returnType = returnValue?.GetType();
|
||||||
if (returnType != null)
|
if (returnType != null)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using System.Reflection;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UIShare.UIViewModel;
|
using UIShare.UIViewModel;
|
||||||
|
using static UIShare.UIViewModel.ParameterVM;
|
||||||
|
|
||||||
namespace UIShare.GlobalVariable
|
namespace UIShare.GlobalVariable
|
||||||
{
|
{
|
||||||
@@ -27,6 +28,53 @@ namespace UIShare.GlobalVariable
|
|||||||
public string DefaultBLFFilePath { get; set; } = "";
|
public string DefaultBLFFilePath { get; set; } = "";
|
||||||
public string DefaultDBCFilePath { get; set; } = "";
|
public string DefaultDBCFilePath { get; set; } = "";
|
||||||
public ObservableCollection<DeviceInfoVM> DeviceList = new();
|
public ObservableCollection<DeviceInfoVM> DeviceList = new();
|
||||||
|
public ObservableCollection<SharedParameter> SharedParameterList = new();
|
||||||
|
[JsonIgnore]
|
||||||
|
public ObservableCollection<ParameterVM> 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<DeviceInfoVM> DeviceList { get; set; } = new()
|
// public ObservableCollection<DeviceInfoVM> DeviceList { get; set; } = new()
|
||||||
//{
|
//{
|
||||||
// new DeviceInfoVM
|
// new DeviceInfoVM
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ namespace UIShare.UIViewModel
|
|||||||
Type = source.Type;
|
Type = source.Type;
|
||||||
Category = source.Category;
|
Category = source.Category;
|
||||||
IsUseVar = source.IsUseVar;
|
IsUseVar = source.IsUseVar;
|
||||||
IsSave = source.IsSave;
|
|
||||||
VariableName = source.VariableName;
|
VariableName = source.VariableName;
|
||||||
VariableID = source.VariableID;
|
VariableID = source.VariableID;
|
||||||
IsGlobal = source.IsGlobal;
|
|
||||||
Value = source.Value;
|
Value = source.Value;
|
||||||
LowerLimit = source.LowerLimit;
|
LowerLimit = source.LowerLimit;
|
||||||
UpperLimit = source.UpperLimit;
|
UpperLimit = source.UpperLimit;
|
||||||
@@ -69,12 +67,6 @@ namespace UIShare.UIViewModel
|
|||||||
set => SetProperty(ref _category, value);
|
set => SetProperty(ref _category, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _isGlobal;
|
|
||||||
public bool IsGlobal
|
|
||||||
{
|
|
||||||
get => _isGlobal;
|
|
||||||
set => SetProperty(ref _isGlobal, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private object? _value;
|
private object? _value;
|
||||||
public object? Value
|
public object? Value
|
||||||
@@ -111,12 +103,7 @@ namespace UIShare.UIViewModel
|
|||||||
set => SetProperty(ref _isUseVar, value);
|
set => SetProperty(ref _isUseVar, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _isSave;
|
|
||||||
public bool IsSave
|
|
||||||
{
|
|
||||||
get => _isSave;
|
|
||||||
set => SetProperty(ref _isSave, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string? _variableName;
|
private string? _variableName;
|
||||||
public string? VariableName
|
public string? VariableName
|
||||||
|
|||||||
30
UIShare/UIViewModel/SharedParameter.cs
Normal file
30
UIShare/UIViewModel/SharedParameter.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user