diff --git a/CapMachine.Shared/Controls/Meter.xaml b/CapMachine.Shared/Controls/Meter.xaml new file mode 100644 index 0000000..a56d94e --- /dev/null +++ b/CapMachine.Shared/Controls/Meter.xaml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CapMachine.Shared/Controls/Meter.xaml.cs b/CapMachine.Shared/Controls/Meter.xaml.cs new file mode 100644 index 0000000..992f75e --- /dev/null +++ b/CapMachine.Shared/Controls/Meter.xaml.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace CapMachine.Shared.Controls +{ + /// + /// Meter.xaml 的交互逻辑 + /// + public partial class Meter : UserControl + { + public Meter() + { + InitializeComponent(); + } + + /// + /// 仪表名称 + /// + public string MeterName + { + get + { + return (string)base.GetValue(MeterConfig.MeterNameProperty); + } + set + { + base.SetValue(MeterConfig.MeterNameProperty, value); + } + } + public static readonly DependencyProperty MeterNameProperty = DependencyProperty.Register("MeterName", typeof(string), typeof(MeterConfig), new PropertyMetadata("速度")); + + + + + } +} diff --git a/CapMachine.Wpf/Assets/Images/参考工艺图.png b/CapMachine.Wpf/Assets/Images/参考工艺图.png new file mode 100644 index 0000000..dc40cbe Binary files /dev/null and b/CapMachine.Wpf/Assets/Images/参考工艺图.png differ diff --git a/CapMachine.Wpf/CapMachine.Wpf.csproj b/CapMachine.Wpf/CapMachine.Wpf.csproj index 0d702c7..6bb4200 100644 --- a/CapMachine.Wpf/CapMachine.Wpf.csproj +++ b/CapMachine.Wpf/CapMachine.Wpf.csproj @@ -7,6 +7,16 @@ enable true + + + + + + + + Never + + @@ -25,7 +35,6 @@ - diff --git a/CapMachine.Wpf/Models/ChartRtSeries.cs b/CapMachine.Wpf/Models/ChartRtSeries.cs index c3810f3..eb85c91 100644 --- a/CapMachine.Wpf/Models/ChartRtSeries.cs +++ b/CapMachine.Wpf/Models/ChartRtSeries.cs @@ -1,9 +1,11 @@ using Arction.Wpf.Charting; using Arction.Wpf.Charting.Annotations; using Arction.Wpf.Charting.Axes; +using Arction.Wpf.Charting.Maps; using Arction.Wpf.Charting.Series3D; using Arction.Wpf.Charting.SeriesXY; using Arction.Wpf.Charting.Views.ViewXY; +using CapMachine.Model; using ImTools; using Prism.Mvvm; using System; @@ -18,60 +20,64 @@ namespace CapMachine.Wpf.Models /// /// 曲线实时系列模型 /// - public class ChartRtSeries:BindableBase + public class ChartRtSeries : BindableBase { - public ChartRtSeries(AxisY axisY, LightningChart lightningChart, string SeriesName) - { - //var CreateAxisY = new AxisY(); - //CreateAxisY.Title.Text = Name; - //CreateAxisY.Title.AllowDragging = false; - //CreateAxisY.SetRange(0, 100); - //CreateAxisY.MajorGrid.Visible = false; - ////取消滚轮缩放 - //CreateAxisY.ZoomingEnabled = false; + /// + /// 实例化函数 + /// + /// + /// + /// + //public ChartRtSeries(AxisY axisY, LightningChart lightningChart, string SeriesName) + //{ + // //var CreateAxisY = new AxisY(); + // //CreateAxisY.Title.Text = Name; + // //CreateAxisY.Title.AllowDragging = false; + // //CreateAxisY.SetRange(0, 100); + // //CreateAxisY.MajorGrid.Visible = false; + // ////取消滚轮缩放 + // //CreateAxisY.ZoomingEnabled = false; + // //模型赋值 + // LightningChartInstance = lightningChart; + // //ChartAxisY = axisY; + // ChartAxisX = lightningChart.ViewXY.XAxes[0]; + // Name = SeriesName; + + // //Unit = "℃"; + + // //判断别重复,因为可能共用Y轴的信息 + // //绑定lightningChart + // lightningChart.ViewXY.YAxes.Add(axisY); + + // ChartPointLineSeries = new PointLineSeries(lightningChart.ViewXY, lightningChart.ViewXY.XAxes[0], axisY); + // ChartPointLineSeries.Title.Text = SeriesName; + // //绑定lightningChart + // lightningChart.ViewXY.PointLineSeries.Add(ChartPointLineSeries); + + + //} + + /// + /// 实例化函数 + /// + public ChartRtSeries(LightningChart lightningChart, ChartConfig chartConfig, List listchartRtSeries, ConfigChartSelect configChartSelect) + { //模型赋值 LightningChartInstance = lightningChart; - ChartAxisY = axisY; - ChartAxisX = lightningChart.ViewXY.XAxes[0]; - Name = SeriesName; + ChartConfigInfo = chartConfig; + ChartAxisY = configChartSelect.ConfigChartYAxis; + ChartAxisX = LightningChartInstance.ViewXY.XAxes[0]; + Name = configChartSelect.Name; + ListChartRtSeries= listchartRtSeries; - Unit = "℃"; + AddSeries(configChartSelect.Name!, configChartSelect.ConfigChartYAxis!); - //判断别重复,因为可能共用Y轴的信息 - //绑定lightningChart - lightningChart.ViewXY.YAxes.Add(axisY); - - ChartPointLineSeries = new PointLineSeries(lightningChart.ViewXY, lightningChart.ViewXY.XAxes[0], axisY); - ChartPointLineSeries.Title.Text = SeriesName; - //绑定lightningChart - lightningChart.ViewXY.PointLineSeries.Add(ChartPointLineSeries); } - ///// - ///// 名称 - ///// - //public string? Name { get; set; } - ///// - ///// 值 - ///// - //public double Value { get; set; } + #region 基本信息 - ///// - ///// Max - ///// - //public double Max { get; set; } - - ///// - ///// Min - ///// - //public double Min { get; set; } - - ///// - ///// 单位 - ///// - //public string? Unit { get; set; } private string? _Name; /// @@ -93,37 +99,159 @@ namespace CapMachine.Wpf.Models set { _Value = value; RaisePropertyChanged(); } } - private double _Max; + + //private string? _Unit; + ///// + ///// 单位 + ///// + //public string? Unit + //{ + // get { return _Unit; } + // set { _Unit = value; RaisePropertyChanged(); } + //} + + + #endregion + + /// - /// Max + /// 删除Y轴信息 /// - public double Max + public void DeleteAxisY() { - get { return _Max; } - set { _Max = value; RaisePropertyChanged(); } + //删除Y轴信息 + LightningChartInstance.ViewXY.YAxes.Remove(LightningChartInstance.ViewXY.YAxes.FindFirst(a => a.Title.Text == ChartAxisY.Name)); } - private double _Min; /// - /// Min + /// 删除系列 /// - public double Min + public void DeleteSeries() { - get { return _Min; } - set { _Min = value; RaisePropertyChanged(); } + LightningChartInstance.BeginUpdate(); + + LightningChartInstance.ViewXY.PointLineSeries.Remove(ChartPointLineSeries); + + LightningChartInstance.EndUpdate(); + + ListChartRtSeries.Remove(ListChartRtSeries.FindFirst(a=>a.Name== Name)); } - private string? _Unit; /// - /// 单位 + /// 增加系列 /// - public string? Unit + /// + private void AddSeries(string SeriesName, ConfigChartYAxis configChartYAxis) { - get { return _Unit; } - set { _Unit = value; RaisePropertyChanged(); } + LightningChartInstance.BeginUpdate(); + + //判断之前的系列是否已经存在(依据名称),存在使用之前的系列,否则新增 + var AxisYInfo = GetAxisY(configChartYAxis.Name); + if (AxisYInfo == null) + { + //新增 + AxisYInfo = new AxisY(); + AxisYInfo.Title.Text = configChartYAxis.Name; + AxisYInfo.Title.AllowDragging = false; + AxisYInfo.SetRange(configChartYAxis.Min, configChartYAxis.Max); + AxisYInfo.MajorGrid.Visible = false; + //取消滚轮缩放 + AxisYInfo.ZoomingEnabled = false; + LightningChartInstance.ViewXY.YAxes.Add(AxisYInfo); + } + else + { + //使用之前 + AxisYInfo.SetRange(configChartYAxis.Min, configChartYAxis.Max); + } + + var SeriesInfo = GetPointLineSeries(SeriesName); + if (SeriesInfo == null) + { + //新增 + SeriesInfo = new PointLineSeries(LightningChartInstance.ViewXY, LightningChartInstance.ViewXY.XAxes[0], AxisYInfo); + SeriesInfo.Title.Text = SeriesName; + SeriesInfo.LineStyle.Color = ChartConfigInfo.ListColor[LightningChartInstance.ViewXY.YAxes.Count + 1]; + SeriesInfo.AllowUserInteraction = false; + LightningChartInstance.ViewXY.PointLineSeries.Add(SeriesInfo); + } + else + { + //使用之前 + SeriesInfo.AssignYAxisIndex = AxisYInfo.SegmentIndex; + } + + //赋值给当前的模型 + ChartPointLineSeries = SeriesInfo; + + //Configure and add series to the chart + + + LightningChartInstance.EndUpdate(); } + /// + /// 获取AxisY信息 + /// + /// + /// + private AxisY GetAxisY(string AxisName) + { + var AxisYs = LightningChartInstance.ViewXY.YAxes; + + if (AxisYs != null) + { + var findAxis = AxisYs.FindFirst(a => a.Title.Text == AxisName); + if (findAxis != null) + { + return findAxis; + } + else + { + return null; + } + } + else + { + return null; + } + } + + /// + /// 获取PointLineSeries信息 + /// + /// + /// + private PointLineSeries GetPointLineSeries(string SeriesName) + { + var PointLineSeries = LightningChartInstance.ViewXY.PointLineSeries; + + if (PointLineSeries != null) + { + var findSeries = PointLineSeries.FindFirst(a => a.Title.Text == SeriesName); + if (findSeries != null) + { + return findSeries; + } + else + { + return null; + } + } + else + { + return null; + } + } + + + /// + /// 上层管理集合 + /// + public List ListChartRtSeries { get; set; } + + /// /// 曲线 /// @@ -132,7 +260,7 @@ namespace CapMachine.Wpf.Models /// /// Y轴 /// - public AxisY? ChartAxisY { get; set; } + public ConfigChartYAxis? ChartAxisY { get; set; } /// /// X轴 @@ -144,6 +272,12 @@ namespace CapMachine.Wpf.Models /// public LightningChart LightningChartInstance { get; set; } + /// + /// 曲线配置信息 + /// + public ChartConfig ChartConfigInfo { get; set; } + + /// /// X轴滚动 /// @@ -160,7 +294,7 @@ namespace CapMachine.Wpf.Models /// public void AddValue(double Data) { - //foreach (var item in lightningChart1.ViewXY.PointLineSeries) + //foreach (var item in LightningChartInstance.ViewXY.PointLineSeries) //{ //Disable updates, to prevent several extra refreshes LightningChartInstance.BeginUpdate(); @@ -183,10 +317,11 @@ namespace CapMachine.Wpf.Models LightningChartInstance.ViewXY.XAxes[0].ScrollPosition = _previousX; } - //Allow updates again, and update LightningChartInstance.EndUpdate(); + Value = Data; + //} } diff --git a/CapMachine.Wpf/Models/ChartRtValue.cs b/CapMachine.Wpf/Models/ChartRtValue.cs index 7d1aa12..61cf327 100644 --- a/CapMachine.Wpf/Models/ChartRtValue.cs +++ b/CapMachine.Wpf/Models/ChartRtValue.cs @@ -1,5 +1,6 @@ using Arction.Wpf.Charting.Axes; using Arction.Wpf.Charting.SeriesXY; +using Prism.Mvvm; using System; using System.Collections.Generic; using System.Linq; @@ -11,7 +12,7 @@ namespace CapMachine.Wpf.Models /// /// 曲线实时数据模型 /// - public class ChartRtValue + public class ChartRtValue:BindableBase { public ChartRtValue() { @@ -23,10 +24,15 @@ namespace CapMachine.Wpf.Models /// public string? Name { get; set; } + private double _Value; /// /// 值 /// - public double Value { get; set; } + public double Value + { + get { return _Value; } + set { _Value = value; RaisePropertyChanged(); } + } /// /// Max diff --git a/CapMachine.Wpf/Services/MachineRtDataService.cs b/CapMachine.Wpf/Services/MachineRtDataService.cs index 9206b2c..fd860c2 100644 --- a/CapMachine.Wpf/Services/MachineRtDataService.cs +++ b/CapMachine.Wpf/Services/MachineRtDataService.cs @@ -54,28 +54,28 @@ namespace CapMachine.Wpf.Services - Stopwatch stopwatch = new Stopwatch(); - //第一次计时 - stopwatch.Start(); //启动Stopwatch + //Stopwatch stopwatch = new Stopwatch(); + ////第一次计时 + //stopwatch.Start(); //启动Stopwatch - for (var i = 0; i < 10000000; i++) - { - keyValuePairs.TryAdd(DateTime.UtcNow, new RecordInfo() - { - CreateTime = DateTime.UtcNow, - WorkCondition = "dadf", - Temp = 23.3 - }); - //keyValuePairs.Add(new RecordInfo() - //{ - // CreateTime = DateTime.UtcNow, - // WorkCondition = "dadf", - // Temp = 23.3 - //}); - } + //for (var i = 0; i < 10000000; i++) + //{ + // keyValuePairs.TryAdd(DateTime.UtcNow, new RecordInfo() + // { + // CreateTime = DateTime.UtcNow, + // WorkCondition = "dadf", + // Temp = 23.3 + // }); + // //keyValuePairs.Add(new RecordInfo() + // //{ + // // CreateTime = DateTime.UtcNow, + // // WorkCondition = "dadf", + // // Temp = 23.3 + // //}); + //} - stopwatch.Stop(); //停止Stopwatch - Console.WriteLine("Add Elapsed output runTime:{0}", stopwatch.Elapsed.ToString()); + //stopwatch.Stop(); //停止Stopwatch + //Console.WriteLine("Add Elapsed output runTime:{0}", stopwatch.Elapsed.ToString()); //事件服务 _EventAggregator = eventAggregator; @@ -216,12 +216,13 @@ namespace CapMachine.Wpf.Services await Task.Delay(1000); _EventAggregator.GetEvent().Publish(new List() { - new Models.ChartRtValue(){Name="室温0",Value=random.NextDouble()*100,Unit="℃"}, - new Models.ChartRtValue(){Name="室温1",Value=random.NextDouble()*100,Unit="℃"}, - new Models.ChartRtValue(){Name="室温2",Value=random.NextDouble()*100,Unit="℃"}, - new Models.ChartRtValue(){Name="室温3",Value=random.NextDouble()*100,Unit="℃"}, - new Models.ChartRtValue(){Name="室温4",Value=random.NextDouble()*100,Unit="℃"}, - new Models.ChartRtValue(){Name="室温5",Value=random.NextDouble()*100,Unit="℃"}, + new Models.ChartRtValue(){Name="EVA风量",Value=random.NextDouble()*100,Unit="℃"}, + new Models.ChartRtValue(){Name="中间轴转速",Value=random.NextDouble()*100,Unit="℃"}, + new Models.ChartRtValue(){Name="加热电力",Value=random.NextDouble()*100,Unit="℃"}, + new Models.ChartRtValue(){Name="加湿电力",Value=random.NextDouble()*100,Unit="℃"}, + new Models.ChartRtValue(){Name="EMPCV电流",Value=random.NextDouble()*100,Unit="℃"}, + new Models.ChartRtValue(){Name="INJ压力",Value=random.NextDouble()*100,Unit="℃"}, + new Models.ChartRtValue(){Name="冷媒流量",Value=random.NextDouble()*100,Unit="℃"}, }); } diff --git a/CapMachine.Wpf/ViewModels/MonitorViewModel.cs b/CapMachine.Wpf/ViewModels/MonitorViewModel.cs index 809066a..e1c46eb 100644 --- a/CapMachine.Wpf/ViewModels/MonitorViewModel.cs +++ b/CapMachine.Wpf/ViewModels/MonitorViewModel.cs @@ -1,14 +1,39 @@ using CapMachine.Core; +using CapMachine.Wpf.Models; +using CapMachine.Wpf.PrismEvent; +using Prism.Events; namespace CapMachine.Wpf.ViewModels { public class MonitorViewModel : NavigationViewModel { - public MonitorViewModel() + public MonitorViewModel(IEventAggregator eventAggregator) { - + //事件服务 + _EventAggregator = eventAggregator; + _EventAggregator.GetEvent().Subscribe(GetChartRtEvent); } + private IEventAggregator _EventAggregator { get; set; } + + public List ListChartRtValue { get; set; } = new List() + { + new ChartRtValue(){ Name="温度",Value=12.3,Unit="℃"}, + new ChartRtValue(){ Name="压力",Value=12.3,Unit="bar"}, + new ChartRtValue(){ Name="湿度",Value=12.3,Unit="%"}, + }; + + /// + /// 获取曲线的实时值 + /// 数据是发布过来 + /// + /// + /// + private void GetChartRtEvent(List RtData) + { + //ListChartRtValue = RtData; + + } } } diff --git a/CapMachine.Wpf/Views/MainView.xaml b/CapMachine.Wpf/Views/MainView.xaml index a8e6685..4e1b275 100644 --- a/CapMachine.Wpf/Views/MainView.xaml +++ b/CapMachine.Wpf/Views/MainView.xaml @@ -17,6 +17,7 @@ + @@ -160,5 +161,74 @@ x:Name="MainViewContentControl" prism:RegionManager.RegionName="MainViewContentRegion" Visibility="Collapsed" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CapMachine.Wpf/Views/MonitorView.xaml b/CapMachine.Wpf/Views/MonitorView.xaml index baddd2a..1491dde 100644 --- a/CapMachine.Wpf/Views/MonitorView.xaml +++ b/CapMachine.Wpf/Views/MonitorView.xaml @@ -2,42 +2,317 @@ x:Class="CapMachine.Wpf.Views.MonitorView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:Controls="clr-namespace:CapMachine.Shared.Controls;assembly=CapMachine.Shared" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CapMachine.Wpf.Views" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="1000" d:DesignWidth="1920" mc:Ignorable="d"> - - - - - - - - - - - - + + + + + + + +