This commit is contained in:
@@ -78,6 +78,7 @@ namespace MembranePoreTester.ViewModels
|
|||||||
set => SetProperty(ref _pressButtonText, value);
|
set => SetProperty(ref _pressButtonText, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool EnableStatus
|
public bool EnableStatus
|
||||||
{
|
{
|
||||||
get => _enableStatus;
|
get => _enableStatus;
|
||||||
@@ -85,12 +86,17 @@ namespace MembranePoreTester.ViewModels
|
|||||||
{
|
{
|
||||||
if (SetProperty(ref _enableStatus, value))
|
if (SetProperty(ref _enableStatus, value))
|
||||||
{
|
{
|
||||||
// 当 EnableStatus 变化时,通知依赖的属性也变化
|
// 当设备停止运行时,停止孔分布自动采集
|
||||||
|
if (!value)
|
||||||
|
{
|
||||||
|
PoreDistributionVM?.StopCollecting();
|
||||||
|
}
|
||||||
OnPropertyChanged(nameof(EnableStatusText));
|
OnPropertyChanged(nameof(EnableStatusText));
|
||||||
OnPropertyChanged(nameof(EnableStatusColor));
|
OnPropertyChanged(nameof(EnableStatusColor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使能状态显示文本
|
// 使能状态显示文本
|
||||||
public string EnableStatusText => EnableStatus ? "运行中" : "未启动";
|
public string EnableStatusText => EnableStatus ? "运行中" : "未启动";
|
||||||
|
|
||||||
@@ -113,23 +119,25 @@ namespace MembranePoreTester.ViewModels
|
|||||||
|
|
||||||
private double _pressureUpperLimit;
|
private double _pressureUpperLimit;
|
||||||
private double _pressureRate;
|
private double _pressureRate;
|
||||||
|
// 防止从PLC读取时触发校验弹窗
|
||||||
|
private bool _suppressPressureValidation = false;
|
||||||
|
|
||||||
public double PressureUpperLimit
|
public double PressureUpperLimit
|
||||||
{
|
{
|
||||||
get => _pressureUpperLimit;
|
get => _pressureUpperLimit;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (SetProperty(ref _pressureUpperLimit, value))
|
// 如果不是从PLC读取(即用户交互或程序主动设置),先校验再设置
|
||||||
|
if (!_suppressPressureValidation && HighLowPressure.Contains("低压") && value > 200)
|
||||||
|
{
|
||||||
|
MessageBox.Show("低压模式,加压上限不能超过200!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool changed = SetProperty(ref _pressureUpperLimit, value);
|
||||||
|
// 仅在非抑制模式下将改变写回PLC,避免把PLC读回的值再次写入造成循环
|
||||||
|
if (changed && !_suppressPressureValidation)
|
||||||
{
|
{
|
||||||
if (HighLowPressure == "低压")
|
|
||||||
{
|
|
||||||
if (value > 200)
|
|
||||||
{
|
|
||||||
MessageBox.Show("低压模式,加压上限不能超过200!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 值改变时写入PLC
|
|
||||||
_ = _plcService.WriteMultipleRegistersAsync(_plcConfig.PressureUpperLimit, (float)value);
|
_ = _plcService.WriteMultipleRegistersAsync(_plcConfig.PressureUpperLimit, (float)value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,8 +169,11 @@ namespace MembranePoreTester.ViewModels
|
|||||||
|
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
// 在将PLC读取的值赋回到属性时,抑制用户校验提示和避免回写PLC
|
||||||
|
_suppressPressureValidation = true;
|
||||||
PressureUpperLimit = upperLimit;
|
PressureUpperLimit = upperLimit;
|
||||||
PressureRate = rate;
|
PressureRate = rate;
|
||||||
|
_suppressPressureValidation = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -407,17 +407,33 @@ namespace MembranePoreTester.ViewModels
|
|||||||
// 修改 Calculate 方法:
|
// 修改 Calculate 方法:
|
||||||
private void Calculate()
|
private void Calculate()
|
||||||
{
|
{
|
||||||
var cleanedPoints = CleanDataPoints(Record.DataPoints);
|
// 先清洗数据并替换到绑定的集合中,确保DataGrid和曲线显示清洗后的数据
|
||||||
if (Record.DataPoints.Count < 2) return;
|
var originalPoints = Record.DataPoints.ToList();
|
||||||
|
var cleanedPoints = CleanDataPoints(originalPoints);
|
||||||
|
|
||||||
|
if (cleanedPoints.Count < 2)
|
||||||
|
{
|
||||||
|
MessageBox.Show("有效数据点不足,至少需要 2 个数据点进行计算。");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int invalidCount = originalPoints.Count - cleanedPoints.Count;
|
||||||
|
|
||||||
|
// 用清洗后的点替换 ObservableCollection 的内容(触发UI更新)
|
||||||
|
Record.DataPoints.Clear();
|
||||||
|
foreach (var p in cleanedPoints)
|
||||||
|
Record.DataPoints.Add(p);
|
||||||
|
|
||||||
|
// 刷新曲线以显示清洗后的数据
|
||||||
|
UpdatePlot();
|
||||||
|
|
||||||
|
// 使用清洗后的集合进行计算
|
||||||
AveragePoreSize = PoreDistributionAnalysis.CalculateAveragePore(
|
AveragePoreSize = PoreDistributionAnalysis.CalculateAveragePore(
|
||||||
Record.DataPoints, Record.PressureUnit, Record.Liquid);
|
Record.DataPoints, Record.PressureUnit, Record.Liquid);
|
||||||
|
|
||||||
RangePercentage = PoreDistributionAnalysis.CalculatePoreRangePercentage(
|
RangePercentage = PoreDistributionAnalysis.CalculatePoreRangePercentage(
|
||||||
Record.DataPoints, Record.PressureUnit, Record.Liquid, LowerPore, UpperPore);
|
Record.DataPoints, Record.PressureUnit, Record.Liquid, LowerPore, UpperPore);
|
||||||
|
|
||||||
// 可选:提示用户过滤了多少无效点
|
|
||||||
int invalidCount = Record.DataPoints.Count - cleanedPoints.Count;
|
|
||||||
if (invalidCount > 0)
|
if (invalidCount > 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show($"已自动过滤 {invalidCount} 个无效数据点");
|
MessageBox.Show($"已自动过滤 {invalidCount} 个无效数据点");
|
||||||
|
|||||||
@@ -207,7 +207,7 @@
|
|||||||
|
|
||||||
<!-- 湿膜表格 -->
|
<!-- 湿膜表格 -->
|
||||||
<GroupBox Grid.Column="0" Header="💧 湿膜数据" Margin="0,0,5,0">
|
<GroupBox Grid.Column="0" Header="💧 湿膜数据" Margin="0,0,5,0">
|
||||||
<DataGrid ItemsSource="{Binding Record.DataPoints}"
|
<DataGrid x:Name="dgWetData" ItemsSource="{Binding Record.DataPoints}"
|
||||||
SelectedItem="{Binding SelectedDataPoint}"
|
SelectedItem="{Binding SelectedDataPoint}"
|
||||||
AutoGenerateColumns="False"
|
AutoGenerateColumns="False"
|
||||||
CanUserAddRows="False"
|
CanUserAddRows="False"
|
||||||
@@ -225,7 +225,7 @@
|
|||||||
|
|
||||||
<!-- 干膜表格 -->
|
<!-- 干膜表格 -->
|
||||||
<GroupBox Grid.Column="1" Header="🔥 干膜数据" Margin="5,0,0,0">
|
<GroupBox Grid.Column="1" Header="🔥 干膜数据" Margin="5,0,0,0">
|
||||||
<DataGrid ItemsSource="{Binding Record.DataPoints}"
|
<DataGrid x:Name="dgDryData" ItemsSource="{Binding Record.DataPoints}"
|
||||||
SelectedItem="{Binding SelectedDataPoint}"
|
SelectedItem="{Binding SelectedDataPoint}"
|
||||||
AutoGenerateColumns="False"
|
AutoGenerateColumns="False"
|
||||||
CanUserAddRows="False"
|
CanUserAddRows="False"
|
||||||
@@ -276,7 +276,7 @@
|
|||||||
<TextBlock Text="~" VerticalAlignment="Center" Margin="1"/>
|
<TextBlock Text="~" VerticalAlignment="Center" Margin="1"/>
|
||||||
<TextBox Text="{Binding UpperPore}" Width="48" Margin="1"/>
|
<TextBox Text="{Binding UpperPore}" Width="48" Margin="1"/>
|
||||||
<TextBlock Text="μm" VerticalAlignment="Center" Margin="2,0,5,0"/>
|
<TextBlock Text="μm" VerticalAlignment="Center" Margin="2,0,5,0"/>
|
||||||
<Button Content="计算" Command="{Binding CalculateCommand}" Margin="2,0" Padding="8,5" Background="#2196F3"/>
|
<Button Content="计算" Command="{Binding CalculateCommand}" Margin="2,0" Padding="8,5" Background="#2196F3" Click="Button_Click"/>
|
||||||
<TextBlock Text="{Binding RangePercentage, StringFormat={}{0:F1}%}" FontSize="14" FontWeight="Bold" VerticalAlignment="Center" Margin="5,0" Foreground="#4CAF50"/>
|
<TextBlock Text="{Binding RangePercentage, StringFormat={}{0:F1}%}" FontSize="14" FontWeight="Bold" VerticalAlignment="Center" Margin="5,0" Foreground="#4CAF50"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using MembranePoreTester.ViewModels;
|
using MembranePoreTester.ViewModels;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
namespace MembranePoreTester.Views
|
namespace MembranePoreTester.Views
|
||||||
@@ -23,6 +24,43 @@ namespace MembranePoreTester.Views
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.Loaded += OnLoaded;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var vm = this.DataContext as PoreDistributionViewModel;
|
||||||
|
if (vm != null)
|
||||||
|
{
|
||||||
|
vm.Record.DataPoints.CollectionChanged += DataPoints_CollectionChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataPoints_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
|
||||||
|
{
|
||||||
|
// 滚动湿膜表格到底部
|
||||||
|
ScrollDataGridToEnd(dgWetData);
|
||||||
|
// 滚动干膜表格到底部
|
||||||
|
ScrollDataGridToEnd(dgDryData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ScrollDataGridToEnd(DataGrid dataGrid)
|
||||||
|
{
|
||||||
|
if (dataGrid.Items.Count > 0)
|
||||||
|
{
|
||||||
|
dataGrid.ScrollIntoView(dataGrid.Items[dataGrid.Items.Count - 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user