Files
AohDrllTools/DrillScalingWindow.xaml.cs
Mr.Xia 29c7be3fac feat: 二钻涨缩系数记忆,载入上次系数
涨缩完成后将模式与系数写入 %LocalAppData%\DrillTools\scaling.ini,涨缩窗口新增"载入上次系数"按钮实时读取回填。每次完成涨缩覆盖更新,只保留最新一条记录(含源文件名追溯)。ini 使用 UTF-8 无 BOM,损坏时容错返回空。
2026-06-14 12:16:17 +08:00

90 lines
3.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Windows;
namespace DrillTools
{
/// <summary>
/// 钻带涨缩参数设置窗口
/// </summary>
public partial class DrillScalingWindow : Window
{
private readonly DrillScalingViewModel _viewModel;
/// <summary>
/// 用户确认后的缩放结果。
/// 保留模式与原始输入(用于系数记忆落盘),同时携带换算后的倍率(用于实际缩放)。
/// </summary>
public (ScalingMode Mode, string InputX, string InputY, double Kx, double Ky)? ScalingResult { get; private set; }
public DrillScalingWindow()
{
InitializeComponent();
_viewModel = new DrillScalingViewModel();
DataContext = _viewModel;
}
private void ModeRadioButton_Changed(object sender, RoutedEventArgs e)
{
if (_viewModel == null)
return;
if (RatioRadioButton.IsChecked == true)
_viewModel.Mode = ScalingMode.Ratio;
else if (PpmRadioButton.IsChecked == true)
_viewModel.Mode = ScalingMode.Ppm;
}
private void ExecuteButton_Click(object sender, RoutedEventArgs e)
{
var error = _viewModel.Validate();
if (error != null)
{
ErrorText.Text = error;
ErrorText.Visibility = Visibility.Visible;
return;
}
ScalingResult = (_viewModel.Mode, _viewModel.InputX, _viewModel.InputY, _viewModel.Kx, _viewModel.Ky);
DialogResult = true;
Close();
}
/// <summary>
/// 载入上次涨缩系数:实时读取 ini 并回填模式与输入框。
/// RadioButton 与 Mode 为单向事件绑定,模式回填需手动同步 RadioButton 状态。
/// </summary>
private void LoadLastButton_Click(object sender, RoutedEventArgs e)
{
try
{
var record = ScalingProfileStore.Load();
if (record == null)
{
System.Windows.MessageBox.Show("没有可载入的上次系数记录。", "载入上次系数",
MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 先同步 RadioButton设目标项为 true靠同组互斥取消另一项并触发 ModeRadioButton_Changed 联动 Mode 与派生标签),再回填输入框
if (record.Mode == ScalingMode.Ratio)
RatioRadioButton.IsChecked = true;
else
PpmRadioButton.IsChecked = true;
_viewModel.InputX = record.InputX;
_viewModel.InputY = record.InputY;
}
catch (Exception ex)
{
System.Windows.MessageBox.Show($"载入上次系数失败:\n{ex.Message}", "错误",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
ScalingResult = null;
DialogResult = false;
Close();
}
}
}