Files
CapMachine/CapMachine.Wpf/Views/RealTimeChartView.xaml.cs
2024-12-18 15:50:21 +08:00

191 lines
7.2 KiB
C#

using Arction.Wpf.Charting;
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.Models.LightChart;
using CapMachine.Wpf.Models.Tag;
using CapMachine.Wpf.PrismEvent;
using CapMachine.Wpf.Services;
using ImTools;
using Prism.Events;
using System.Text;
using System.Timers;
using System.Windows.Controls;
namespace CapMachine.Wpf.Views
{
/// <summary>
/// RealTimeChartView.xaml 的交互逻辑
/// </summary>
public partial class RealTimeChartView : UserControl
{
private readonly DataRecordService DatRecordService;
/// <summary>
/// 定时器
/// </summary>
static System.Timers.Timer CurTimer { get; set; }
/// <summary>
/// 事件聚合器
/// </summary>
private IEventAggregator _EventAggregator { get; set; }
public MachineRtDataService MachineRtDataService { get; }
public IFreeSql FreeSql { get; }
public ILogService LogService { get; }
public ConfigService ConfigService { get; }
#region ChartManager实例集合
/// <summary>
/// Chart实例1
/// </summary>
public ChartManager Group1ChartManager { get; set; }
/// <summary>
/// Chart实例2
/// </summary>
public ChartManager Group2ChartManager { get; set; }
/// <summary>
/// Chart实例3
/// </summary>
public ChartManager Group3ChartManager { get; set; }
/// <summary>
/// Chart实例4
/// </summary>
public ChartManager Group4ChartManager { get; set; }
/// <summary>
/// Chart实例5
/// </summary>
public ChartManager Group5ChartManager { get; set; }
/// <summary>
/// Chart实例6
/// </summary>
public ChartManager Group6ChartManager { get; set; }
/// <summary>
/// Chart实例7
/// </summary>
public ChartManager Group7ChartManager { get; set; }
/// <summary>
/// Chart实例8
/// </summary>
public ChartManager Group8ChartManager { get; set; }
#endregion
/// <summary>
/// 实时变量管理
/// </summary>
public TagManager RtTagManager { get; set; }
/// <summary>
/// 实例化函数
/// </summary>
/// <param name="eventAggregator"></param>
/// <param name="machineRtDataService"></param>
public RealTimeChartView(IEventAggregator eventAggregator, DataRecordService datRecordService, MachineRtDataService machineRtDataService, IFreeSql freeSql,ILogService logService,ConfigService configService)
{
//初始化当前的页面组件,原始方法
InitializeComponent();
//事件服务
_EventAggregator = eventAggregator;
this.DatRecordService = datRecordService;
RtTagManager = machineRtDataService.TagManger;
MachineRtDataService = machineRtDataService;
FreeSql = freeSql;
LogService = logService;
ConfigService = configService;
Group1ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart1, "LgChart1", 0, "M1",true, LogService, ConfigService);
Group2ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart2, "LgChart2", 1, "M1",true, LogService , ConfigService);
Group3ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart3, "LgChart3", 2, "M1",true, LogService, ConfigService);
Group4ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart4, "LgChart4", 3, "M1",true, LogService, ConfigService);
Group5ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart5, "LgChart5", 4, "M1",true, LogService, ConfigService);
Group6ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart6, "LgChart6", 5, "M1",true, LogService, ConfigService);
Group7ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart7, "LgChart7", 6, "M1",true, LogService, ConfigService);
Group8ChartManager = new ChartManager(_EventAggregator, RtTagManager, DatRecordService, FreeSql, LgChart8, "LgChart8", 7, "M1", true, LogService, ConfigService);
//LvChartRtValue.ItemsSource = RtTagManager.DicTags.Values.ToList();
LvChartRtValueSingle1.ItemsSource = Group1ChartManager.ListChartRtSeries;
LvChartRtValuedouble1.ItemsSource = Group1ChartManager.ListChartRtSeries;
LvChartRtValueSingle2.ItemsSource = Group2ChartManager.ListChartRtSeries;
LvChartRtValuedouble2.ItemsSource = Group2ChartManager.ListChartRtSeries;
LvChartRtValueSingle3.ItemsSource = Group3ChartManager.ListChartRtSeries;
LvChartRtValuedouble3.ItemsSource = Group3ChartManager.ListChartRtSeries;
LvChartRtValueSingle4.ItemsSource = Group4ChartManager.ListChartRtSeries;
LvChartRtValuedouble4.ItemsSource = Group4ChartManager.ListChartRtSeries;
LvChartRtValueSingle5.ItemsSource = Group5ChartManager.ListChartRtSeries;
LvChartRtValuedouble5.ItemsSource = Group5ChartManager.ListChartRtSeries;
LvChartRtValueSingle6.ItemsSource = Group6ChartManager.ListChartRtSeries;
LvChartRtValuedouble6.ItemsSource = Group6ChartManager.ListChartRtSeries;
LvChartRtValueSingle7.ItemsSource = Group7ChartManager.ListChartRtSeries;
LvChartRtValuedouble7.ItemsSource = Group7ChartManager.ListChartRtSeries;
LvChartRtValueSingle8.ItemsSource = Group8ChartManager.ListChartRtSeries;
LvChartRtValuedouble8.ItemsSource = Group8ChartManager.ListChartRtSeries;
_EventAggregator.GetEvent<ChartRtEvent>().Subscribe(GetChartRtEvent);
}
/// <summary>
/// 获取曲线的实时值
/// 数据是发布过来
/// </summary>
/// <param name="value"></param>
/// <exception cref="NotImplementedException"></exception>
private void GetChartRtEvent(List<ChartRtValue> RtData)
{
//ListChartRtValue = RtData;
////UpdateLightningChartData();
//App.Current.Dispatcher.Invoke(() =>
//{
// foreach (var item in ListChartRtValue)
// {
// var Data = ListChartRtSeries.Find(a => a.Name == item.Name);
// if (Data != null)
// {
// Data.AddValue(item.Value);
// Data.Value = item.Value;
// }
// }
//});
}
/// <summary>
/// 时间序列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CurTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
}
}
}