增加监控界面

This commit is contained in:
2024-07-12 10:39:55 +08:00
parent 1e0cba7b53
commit c9f4e88e04
11 changed files with 892 additions and 141 deletions

View File

@@ -3,10 +3,12 @@ using Arction.Wpf.Charting.Annotations;
using Arction.Wpf.Charting.Axes;
using Arction.Wpf.Charting.SeriesXY;
using Arction.Wpf.Charting.Views.ViewXY;
using CapMachine.Model;
using CapMachine.Wpf.Models;
using CapMachine.Wpf.PrismEvent;
using CapMachine.Wpf.Services;
using CapMachine.Wpf.ViewModels;
using ImTools;
using NLog;
using Prism.Events;
using System.Text;
@@ -28,18 +30,19 @@ namespace CapMachine.Wpf.Views
private IEventAggregator _EventAggregator { get; set; }
public MachineRtDataService MachineRtDataService { get; }
public IFreeSql FreeSql { get; }
/// <summary>
/// 曲线配置
/// </summary>
public ChartConfig ChartConfigInfo { get; set; }
public ChartConfig ChartConfigInfo { get; set; } = new ChartConfig();
/// <summary>
/// 实例化函数
/// </summary>
/// <param name="eventAggregator"></param>
/// <param name="machineRtDataService"></param>
public RealTimeChartView(IEventAggregator eventAggregator, MachineRtDataService machineRtDataService)
public RealTimeChartView(IEventAggregator eventAggregator, MachineRtDataService machineRtDataService, IFreeSql freeSql)
{
InitializeComponent();
@@ -51,18 +54,10 @@ namespace CapMachine.Wpf.Views
//事件服务
_EventAggregator = eventAggregator;
MachineRtDataService = machineRtDataService;
FreeSql = freeSql;
_EventAggregator.GetEvent<ChartRtEvent>().Subscribe(GetChartRtEvent);
_EventAggregator.GetEvent<ChartRtActionEvent>().Subscribe(ReLoadData);
var CreateAxisY = new AxisY();
CreateAxisY.Title.Text = Name;
CreateAxisY.Title.AllowDragging = false;
CreateAxisY.SetRange(0, 100);
CreateAxisY.MajorGrid.Visible = false;
//取消滚轮缩放
CreateAxisY.ZoomingEnabled = false;
ListChartRtSeries.Add(new ChartRtSeries(CreateAxisY, lightningChart1, "室温0"));
}
/// <summary>
@@ -73,7 +68,17 @@ namespace CapMachine.Wpf.Views
/// <exception cref="NotImplementedException"></exception>
private void ReLoadData(ChartActionType type)
{
throw new NotImplementedException();
//
switch (type)
{
case ChartActionType.ReLoadChart:
var ChartSelectedData = FreeSql.Select<ConfigChartSelect>().Include(a => a.ConfigChartYAxis).ToList();
LoadChartConfigSelect(ChartSelectedData);
break;
default:
break;
}
}
@@ -106,23 +111,97 @@ namespace CapMachine.Wpf.Views
}
private void CurTimer2_Elapsed(object? sender, ElapsedEventArgs e)
{
}
/// <summary>
/// 时间序列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CurTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
}
#region ListView配置
#region
#endregion
#region 线
/// <summary>
/// 当前曲线配置信息
/// </summary>
public List<ConfigChartSelect> CurListConfigChartSelect { get; set; }
/// <summary>
/// 加载曲线配置信息
/// </summary>
private void LoadChartConfigSelect(List<ConfigChartSelect> configChartSelects)
{
//从配置入手对比目前的状态,针对配置新增
foreach (var itemConfig in configChartSelects)
{
//曲线增加时
var data = ListChartRtSeries.FindFirst(a => a.Name == itemConfig.Name);
if (data == null)
{
ListChartRtSeries.Add(new ChartRtSeries(lightningChart1, ChartConfigInfo, ListChartRtSeries, itemConfig));
}
else
{
//修改
}
}
////从目前的状态对比配置,针对删除项目
//foreach (var itemSeries in ListChartRtSeries)
//{
// var data = configChartSelects.FindFirst(a => a.Name == itemSeries.Name);
// if (data == null)
// {
// //查找删除的系列的Y轴是否还有其他的配置使用
// var configChartYAxis = configChartSelects.Find(a => a.ConfigChartYAxis.Name == itemSeries.ChartAxisY.Name);
// if (configChartYAxis == null)
// {
// //Y轴没有使用则删除
// itemSeries.DeleteAxisY();
// }
// //未找到,则删除
// ListChartRtSeries.Remove(itemSeries);
// }
// else
// {
// //存在就不需要操作
// }
//}
//从目前的状态对比配置,针对删除项目
for (int i = 0; i < ListChartRtSeries.Count; i++)
{
var data = configChartSelects.FindFirst(a => a.Name == ListChartRtSeries[i].Name);
if (data == null)
{
//查找删除的系列的Y轴是否还有其他的配置使用-先删除Y轴
var configChartYAxis = configChartSelects.Find(a => a.ConfigChartYAxis.Name == ListChartRtSeries[i].ChartAxisY.Name);
if (configChartYAxis == null)
{
//Y轴没有使用则删除
ListChartRtSeries[i].DeleteAxisY();
}
//未找到,则删除 曲线实例删除
ListChartRtSeries[i].DeleteSeries();
}
else
{
//存在就不需要操作
}
}
}
/// <summary>
/// 实时曲线数据集合
/// </summary>
@@ -502,6 +581,7 @@ namespace CapMachine.Wpf.Views
MainRealTimeChartSeriesCount++;
}
private void DeleteYAxis(string Name)
{
lightningChart1.BeginUpdate();