This commit is contained in:
2024-12-18 15:50:21 +08:00
parent 684973e6b7
commit b2c54119ea
214 changed files with 65908 additions and 8461 deletions

View File

@@ -1,24 +1,41 @@
using CapMachine.Core;
using AutoMapper;
using CapMachine.Core;
using CapMachine.Model;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.PrismEvent;
using Prism.Commands;
using Prism.Events;
using Prism.Services.Dialogs;
using SharpDX.Direct3D9;
using System;
using System.Windows;
using System.Collections.ObjectModel;
namespace CapMachine.Wpf.ViewModels
{
/// <summary>
/// 实时曲线的模型
/// </summary>
public class RealTimeChartViewModel : NavigationViewModel
{
/// <summary>
/// 实例化函数
/// </summary>
public RealTimeChartViewModel(IDialogService dialogService, IFreeSql freeSql, IEventAggregator eventAggregator)
public RealTimeChartViewModel(IDialogService dialogService, IFreeSql freeSql, IEventAggregator eventAggregator, IMapper mapper)
{
DialogService = dialogService;
FreeSql = freeSql;
EventAggregator = eventAggregator;
Mapper = mapper;
ListChartTabGroupDto = Mapper.Map<List<ChartTabGroupDto>>(FreeSql.Select<ChartTabGroup>().Where(a => a.IsEnable == true).ToList());
//都要加载数据
EventAggregator.GetEvent<ChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 0, ActionMsg = "Start" });
EventAggregator.GetEvent<ChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 1, ActionMsg = "Start" });
EventAggregator.GetEvent<ChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 2, ActionMsg = "Start" });
EventAggregator.GetEvent<ChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 3, ActionMsg = "Start" });
EventAggregator.GetEvent<ChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 4, ActionMsg = "Start" });
EventAggregator.GetEvent<ChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg() { Machine = "M1", GroupTabIndex = 5, ActionMsg = "Start" });
}
/// <summary>
@@ -26,11 +43,135 @@ namespace CapMachine.Wpf.ViewModels
/// </summary>
public IDialogService DialogService { get; }
/// <summary>
/// AutoMap映射
/// </summary>
public IMapper Mapper { get; }
/// <summary>
/// FreeSQL 实例
/// </summary>
public IFreeSql FreeSql { get; }
private List<ChartTabGroupDto> _ListChartTabGroupDto;
/// <summary>
/// Tab集合信息数据
/// </summary>
public List<ChartTabGroupDto> ListChartTabGroupDto
{
get { return _ListChartTabGroupDto; }
set { _ListChartTabGroupDto = value; RaisePropertyChanged(); }
}
/// <summary>
/// 当前的Machine
/// </summary>
private string CurSelectedMachine { get; set; } = "M1";
#region TabIndex信息
private int _SeletedGroupTabIndex;
/// <summary>
/// 选中的Group TabIndex
/// </summary>
public int SeletedGroupTabIndex
{
get { return _SeletedGroupTabIndex; }
set { _SeletedGroupTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup1ListViewTabIndex;
/// <summary>
/// 选中的Group1的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup1ListViewTabIndex
{
get { return _SeletedGroup1ListViewTabIndex; }
set { _SeletedGroup1ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup2ListViewTabIndex;
/// <summary>
/// 选中的Group2的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup2ListViewTabIndex
{
get { return _SeletedGroup2ListViewTabIndex; }
set { _SeletedGroup2ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup3ListViewTabIndex;
/// <summary>
/// 选中的Group3的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup3ListViewTabIndex
{
get { return _SeletedGroup3ListViewTabIndex; }
set { _SeletedGroup3ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup4ListViewTabIndex;
/// <summary>
/// 选中的Group4的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup4ListViewTabIndex
{
get { return _SeletedGroup4ListViewTabIndex; }
set { _SeletedGroup4ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup5ListViewTabIndex;
/// <summary>
/// 选中的Group5的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup5ListViewTabIndex
{
get { return _SeletedGroup5ListViewTabIndex; }
set { _SeletedGroup5ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup6ListViewTabIndex;
/// <summary>
/// 选中的Group6的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup6ListViewTabIndex
{
get { return _SeletedGroup6ListViewTabIndex; }
set { _SeletedGroup6ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup7ListViewTabIndex;
/// <summary>
/// 选中的Group7的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup7ListViewTabIndex
{
get { return _SeletedGroup7ListViewTabIndex; }
set { _SeletedGroup7ListViewTabIndex = value; RaisePropertyChanged(); }
}
private int _SeletedGroup8ListViewTabIndex;
/// <summary>
/// 选中的Group8的 ListView TabIndex
/// 单游标和双游标的显示数据
/// </summary>
public int SeletedGroup8ListViewTabIndex
{
get { return _SeletedGroup8ListViewTabIndex; }
set { _SeletedGroup8ListViewTabIndex = value; RaisePropertyChanged(); }
}
#endregion
/// <summary>
/// 事件聚合器
/// </summary>
@@ -55,21 +196,25 @@ namespace CapMachine.Wpf.ViewModels
return _ChartConfigCmd;
}
}
/// <summary>
/// 编辑曲线数据执行方法
/// </summary>
private void ChartConfigCmdMethod()
{
//弹窗
DialogService.ShowDialog("DialogChartRtConfigView", new DialogParameters() { { "Name", "" } }, (par) =>
DialogService.ShowDialog("DialogChartRtConfigView", new DialogParameters() { { "TabIndex", SeletedGroupTabIndex } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
var ReturnValue = par.Parameters.GetValue<string>("Name");
//返回数据刷新Chart
EventAggregator.GetEvent<ChartRtActionEvent>().Publish(ChartActionType.ReLoadChart);
EventAggregator.GetEvent<ChartRtSeriesActionEvent>().Publish(new ChartRtSeriesActionMsg()
{
Machine = CurSelectedMachine,
GroupTabIndex = SeletedGroupTabIndex,
ActionMsg = "Start"
});
}
else if (par.Result == ButtonResult.Cancel)
{
@@ -80,61 +225,358 @@ namespace CapMachine.Wpf.ViewModels
});
}
#region 线
//private LightningChart _LightningChartInstance;
///// <summary>
///// LightningChart 实例
///// </summary>
//public LightningChart LightningChartInstance
//{
// get { return _LightningChartInstance; }
// set { _LightningChartInstance = value; RaisePropertyChanged(); }
//}
///// <summary>
///// 获取实例
///// </summary>
///// <param name="chart"></param>
//public void SetChart(LightningChart chart)
//{
// LightningChartInstance = chart;
//}
//private AxisYCollection _YAxes=new AxisYCollection();
///// <summary>
///// Y轴配置
///// </summary>
//public AxisYCollection YAxes
//{
// get { return _YAxes; }
// set { _YAxes = value; RaisePropertyChanged(); }
//}
private DelegateCommand<object> _BtnSwitchGroupCmd;
/// <summary>
/// 切换组的指令
/// </summary>
public DelegateCommand<object> BtnSwitchGroupCmd
{
set
{
_BtnSwitchGroupCmd = value;
}
get
{
if (_BtnSwitchGroupCmd == null)
{
_BtnSwitchGroupCmd = new DelegateCommand<object>((p) => BtnSwitchGroupCmdMethod(p));
}
return _BtnSwitchGroupCmd;
}
}
private void BtnSwitchGroupCmdMethod(object par)
{
var Data = (ChartTabGroupDto)par;
SeletedGroupTabIndex = Data.Index;
EventAggregator.GetEvent<ChartTabGroupSwitchEvent>().Publish(new ChartTabGroupSwitchMsg()
{
Machine = CurSelectedMachine,
GroupTabIndex = SeletedGroupTabIndex
});
//switch (Data.Index)
//{
// case 0:
// SeletedGroupTabIndex = Data.Index;
// EventAggregator.GetEvent<ChartGroupSwitchEvent>().Publish(Data.Name);
// break;
// case 1:
// SeletedGroupTabIndex = Data.Index;
// EventAggregator.GetEvent<ChartGroupSwitchEvent>().Publish(Data.Name);
// break;
// case 2:
// SeletedGroupTabIndex = Data.Index;
// EventAggregator.GetEvent<ChartGroupSwitchEvent>().Publish(Data.Name);
// break;
// default:
// break;
//}
}
//private AxisXCollection _XAxes = new AxisXCollection();
///// <summary>
///// X轴配
///// </summary>
//public AxisXCollection XAxes
//{
// get { return _XAxes; }
// set { _XAxes = value; RaisePropertyChanged(); }
//}
private DelegateCommand<object> _BtnChartSetCmd;
/// <summary>
/// Chart 设置命令 多次设
/// </summary>
public DelegateCommand<object> BtnChartSetCmd
{
set
{
_BtnChartSetCmd = value;
}
get
{
if (_BtnChartSetCmd == null)
{
_BtnChartSetCmd = new DelegateCommand<object>((p) => BtnChartSetCmdMethod(p));
}
return _BtnChartSetCmd;
}
}
private void BtnChartSetCmdMethod(object par)
{
//两个动作曲线显示游标和不同的游标对应不同的ListView信息
var Info = (string)par;
switch (Info)
{
case "单游标":
//单双游标需要界面配合切换ListView信息
SwitchListViewTab(SeletedGroupTabIndex, "单游标");
//Chart操作
EventAggregator.GetEvent<ChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "单游标" });
break;
case "双游标":
//单双游标需要界面配合切换ListView信息
SwitchListViewTab(SeletedGroupTabIndex, "双游标");
//Chart操作
EventAggregator.GetEvent<ChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "双游标" });
break;
case "游标置中":
//Chart操作
EventAggregator.GetEvent<ChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "游标置中" });
break;
case "游标放大":
//Chart操作
EventAggregator.GetEvent<ChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "游标放大" });
break;
case "保存照片":
//Chart操作
EventAggregator.GetEvent<ChartSetEvent>().Publish(new ChartSetMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "保存照片" });
break;
default:
break;
}
}
//private SampleDataSeriesCollection _ChartDataSeries;
///// <summary>
///// 曲线集合数据
///// </summary>
//public SampleDataSeriesCollection ChartDataSeries
//{
// get { return _ChartDataSeries; }
// set { _ChartDataSeries = value; RaisePropertyChanged(); }
//}
private DelegateCommand<object> _BtnChartScrollEnableSetCmd;
/// <summary>
/// Chart 启用和非启用的设置命令 带有状态的
/// 实时滚动
/// </summary>
public DelegateCommand<object> BtnChartScrollEnableSetCmd
{
set
{
_BtnChartScrollEnableSetCmd = value;
}
get
{
if (_BtnChartScrollEnableSetCmd == null)
{
_BtnChartScrollEnableSetCmd = new DelegateCommand<object>((p) => BtnChartScrollEnableSetCmdMethod(p));
}
return _BtnChartScrollEnableSetCmd;
}
}
private void BtnChartScrollEnableSetCmdMethod(object par)
{
//是否滚动设置
var Result = (bool)par;
EventAggregator.GetEvent<ChartSetEnableEvent>().Publish(new ChartSetEnableMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "实时滚动", Enable = Result });
}
#endregion
private DelegateCommand<object> _BtnChartLegendHideEnableSetCmd;
/// <summary>
/// Chart 启用和非启用的设置命令 带有状态的
/// 图例隐藏
/// </summary>
public DelegateCommand<object> BtnChartLegendHideEnableSetCmd
{
set
{
_BtnChartLegendHideEnableSetCmd = value;
}
get
{
if (_BtnChartLegendHideEnableSetCmd == null)
{
_BtnChartLegendHideEnableSetCmd = new DelegateCommand<object>((p) => BtnChartLegendHideEnableSetCmdMethod(p));
}
return _BtnChartLegendHideEnableSetCmd;
}
}
private void BtnChartLegendHideEnableSetCmdMethod(object par)
{
//是否滚动设置
var Result = (bool)par;
EventAggregator.GetEvent<ChartSetEnableEvent>().Publish(new ChartSetEnableMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ChartSetInfo = "隐藏图例", Enable = Result });
}
private DelegateCommand<object> _TabItemCmd;
/// <summary>
/// Tab内容编辑命令
/// </summary>
public DelegateCommand<object> TabItemCmd
{
set
{
_TabItemCmd = value;
}
get
{
if (_TabItemCmd == null)
{
_TabItemCmd = new DelegateCommand<object>((p) => TabItemCmdMethod());
}
return _TabItemCmd;
}
}
private void TabItemCmdMethod()
{
//弹窗
DialogService.ShowDialog("DialogChartGroupTabView", new DialogParameters() { { "Name", "" } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
ListChartTabGroupDto = par.Parameters.GetValue<List<ChartTabGroupDto>>("NewData");
//返回数据刷新Chart
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
/// <summary>
/// 切换ListViewTab的信息
/// </summary>
private void SwitchListViewTab(int GroupIndex, string Msg)
{
//全部组同时设置
if (Msg == "单游标")
{
SeletedGroup1ListViewTabIndex = 0;
SeletedGroup2ListViewTabIndex = 0;
SeletedGroup3ListViewTabIndex = 0;
SeletedGroup4ListViewTabIndex = 0;
SeletedGroup5ListViewTabIndex = 0;
SeletedGroup6ListViewTabIndex = 0;
SeletedGroup7ListViewTabIndex = 0;
SeletedGroup8ListViewTabIndex = 0;
}
else
{
SeletedGroup1ListViewTabIndex = 1;
SeletedGroup2ListViewTabIndex = 1;
SeletedGroup3ListViewTabIndex = 1;
SeletedGroup4ListViewTabIndex = 1;
SeletedGroup5ListViewTabIndex = 1;
SeletedGroup6ListViewTabIndex = 1;
SeletedGroup7ListViewTabIndex = 1;
SeletedGroup8ListViewTabIndex = 1;
}
//只设置当前的组
//switch (GroupIndex)
//{
// case 0:
// if (Msg == "单游标")
// {
// SeletedGroup1ListViewTabIndex = 0;
// return;
// }
// SeletedGroup1ListViewTabIndex = 1;
// break;
// case 1:
// if (Msg == "单游标")
// {
// SeletedGroup2ListViewTabIndex = 0;
// return;
// }
// SeletedGroup2ListViewTabIndex = 1;
// break;
// case 2:
// if (Msg == "单游标")
// {
// SeletedGroup3ListViewTabIndex = 0;
// return;
// }
// SeletedGroup3ListViewTabIndex = 1;
// break;
// case 3:
// if (Msg == "单游标")
// {
// SeletedGroup4ListViewTabIndex = 0;
// return;
// }
// SeletedGroup4ListViewTabIndex = 1;
// break;
// case 4:
// if (Msg == "单游标")
// {
// SeletedGroup5ListViewTabIndex = 0;
// return;
// }
// SeletedGroup5ListViewTabIndex = 1;
// break;
// case 5:
// if (Msg == "单游标")
// {
// SeletedGroup6ListViewTabIndex = 0;
// return;
// }
// SeletedGroup6ListViewTabIndex = 1;
// break;
// case 6:
// if (Msg == "单游标")
// {
// SeletedGroup7ListViewTabIndex = 0;
// return;
// }
// SeletedGroup7ListViewTabIndex = 1;
// break;
// case 7:
// if (Msg == "单游标")
// {
// SeletedGroup8ListViewTabIndex = 0;
// return;
// }
// SeletedGroup8ListViewTabIndex = 1;
// break;
// default:
// break;
//}
}
private DelegateCommand _ChartYAxisConfigCmd;
/// <summary>
/// 编辑曲线Y轴配置的数据
/// </summary>
public DelegateCommand ChartYAxisConfigCmd
{
set
{
_ChartYAxisConfigCmd = value;
}
get
{
if (_ChartYAxisConfigCmd == null)
{
_ChartYAxisConfigCmd = new DelegateCommand(() => ChartYAxisConfigCmdMethod());
}
return _ChartYAxisConfigCmd;
}
}
private void ChartYAxisConfigCmdMethod()
{
//弹窗
DialogService.ShowDialog("DialogYAxisConfigView", new DialogParameters() { { "Name", "" } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
//ListChartTabGroupDto = par.Parameters.GetValue<List<ChartTabGroupDto>>("NewData");
//返回数据刷新Chart
var Data = FreeSql.Select<ConfigChartYAxis>().ToList();
EventAggregator.GetEvent<ChartYAxisConfigEvent>().Publish(new ChartYAxisConfigMsg() { Machine = CurSelectedMachine, GroupTabIndex = SeletedGroupTabIndex, ConfigChartYAxes = Data });
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
}
}