From 4e27c9ec6be8d5ed097b7b8e4e347f88cdadde60 Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Wed, 11 Mar 2026 16:27:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrendPointCollectionConverter.cs | 57 +++ Cardiopulmonarybypasssystems/MainWindow.xaml | 440 ++++++++++++++---- .../Models/PumpControlChannel.cs | 58 +++ .../Services/IModbusTelemetryService.cs | 2 + .../Services/MockModbusTelemetryService.cs | 252 +++++++--- .../ViewModels/MainViewModel.cs | 224 ++++++++- 6 files changed, 849 insertions(+), 184 deletions(-) create mode 100644 Cardiopulmonarybypasssystems/Converters/TrendPointCollectionConverter.cs create mode 100644 Cardiopulmonarybypasssystems/Models/PumpControlChannel.cs diff --git a/Cardiopulmonarybypasssystems/Converters/TrendPointCollectionConverter.cs b/Cardiopulmonarybypasssystems/Converters/TrendPointCollectionConverter.cs new file mode 100644 index 0000000..ec496a3 --- /dev/null +++ b/Cardiopulmonarybypasssystems/Converters/TrendPointCollectionConverter.cs @@ -0,0 +1,57 @@ +using System.Collections; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media; + +namespace Cardiopulmonarybypasssystems.Converters; + +public sealed class TrendPointCollectionConverter : IMultiValueConverter +{ + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Length < 4 + || values[0] is not IEnumerable enumerable + || values[1] is not double width + || values[2] is not double height + || values[3] is not double maxValue + || width <= 0 + || height <= 0 + || maxValue <= 0) + { + return new PointCollection(); + } + + var samples = enumerable.Cast() + .Select(item => item is double value ? value : System.Convert.ToDouble(item, culture)) + .ToList(); + + if (samples.Count == 0) + { + return new PointCollection(); + } + + if (samples.Count == 1) + { + return new PointCollection + { + new System.Windows.Point(0, height - samples[0] / maxValue * height) + }; + } + + var points = new PointCollection(samples.Count); + var xStep = width / Math.Max(samples.Count - 1, 1); + + for (var index = 0; index < samples.Count; index++) + { + var x = xStep * index; + var yRatio = Math.Clamp(samples[index] / maxValue, 0d, 1d); + var y = height - yRatio * height; + points.Add(new System.Windows.Point(x, y)); + } + + return points; + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) => + throw new NotSupportedException(); +} diff --git a/Cardiopulmonarybypasssystems/MainWindow.xaml b/Cardiopulmonarybypasssystems/MainWindow.xaml index f466006..d93d937 100644 --- a/Cardiopulmonarybypasssystems/MainWindow.xaml +++ b/Cardiopulmonarybypasssystems/MainWindow.xaml @@ -4,11 +4,15 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:models="clr-namespace:Cardiopulmonarybypasssystems.Models" + xmlns:converters="clr-namespace:Cardiopulmonarybypasssystems.Converters" mc:Ignorable="d" Title="心肺转流检测" Width="1024" Height="800" WindowStartupLocation="CenterScreen"> + + + @@ -398,150 +402,380 @@ + + + + + + + + + + + +