feat: ROU成型参数替换功能 — 支持 .rou/.rou1/.rou2/.roux 文件从参数 txt 自动补充 S/F/R/Z/H

This commit is contained in:
2026-08-03 18:19:33 +08:00
parent b51a5cecf8
commit 5c9a70c9f0
8 changed files with 409 additions and 51 deletions

View File

@@ -51,6 +51,7 @@ namespace DrillTools
bool canGeneratePpDrillTape = viewModel.CanGeneratePpDrillTape;
string extension = Path.GetExtension(filePath).ToLowerInvariant();
bool canScaleDrillTape = extension == ".dr2" || extension == ".dpin";
bool isRouFile = extension == ".rou" || extension == ".rou1" || extension == ".rou2" || extension == ".roux";
double minDrill = viewModel.MinDrillDiameter;
double minSlot = viewModel.MinSlotDiameter;
double minEA = viewModel.MinEADiameter;
@@ -82,7 +83,8 @@ namespace DrillTools
selectionViewModel,
canClearParameters,
canGeneratePpDrillTape,
canScaleDrillTape);
canScaleDrillTape,
canReplaceRouParameters: isRouFile);
selectionWindow.ShowDialog();
switch (selectionWindow.SelectedAction)
@@ -107,6 +109,10 @@ namespace DrillTools
PerformDrillScaling(filePath);
Shutdown();
break;
case StartupAction.ReplaceRouParameters:
PerformRouParameterReplace(filePath);
Shutdown();
break;
default:
Shutdown();
break;
@@ -222,12 +228,14 @@ namespace DrillTools
string content = CommandTypeFileReader.ReadAllText(filePath);
string scaledContent = Integration.ExcellonScaler.Scale(content, result.Kx, result.Ky);
// 备份原文件
string backupFilePath = filePath + ".bak";
File.Copy(filePath, backupFilePath, true);
// 在源文件所在目录下新建子文件夹 dr2 x{InputX} y{InputY}
string sourceDir = Path.GetDirectoryName(filePath)!;
string outputDir = Path.Combine(sourceDir, $"dr2 x{result.InputX} y{result.InputY}");
Directory.CreateDirectory(outputDir);
// 写入缩放后的内容
using var writer = new StreamWriter(filePath, false, Encoding.GetEncoding(936));
// 将涨缩后的钻带写入子文件夹,文件名不变
string outputFilePath = Path.Combine(outputDir, Path.GetFileName(filePath));
using var writer = new StreamWriter(outputFilePath, false, Encoding.GetEncoding(936));
writer.Write(scaledContent);
// 系数记忆:紧跟钻带写回立即落盘,不滞后到完成提示之后。
@@ -242,7 +250,7 @@ namespace DrillTools
memoryWarning = $"\n(系数记忆保存失败:{ex.Message})";
}
string completionMessage = $"涨缩完成,原文件已备份为:\n{Path.GetFileName(filePath)}.bak";
string completionMessage = $"涨缩完成,输出至:\n{outputFilePath}";
if (memoryWarning != null)
completionMessage += memoryWarning;
@@ -264,7 +272,7 @@ namespace DrillTools
try
{
string exePath = Process.GetCurrentProcess().MainModule!.FileName!;
string[] extensions = { ".drl", ".dr2", ".dr3", ".trg", ".dpin", ".txt" };
string[] extensions = { ".drl", ".dr2", ".dr3", ".trg", ".dpin", ".txt", ".rou", ".rou1", ".rou2", ".roux" };
string menuText = "用DrillTools打开";
foreach (string ext in extensions)
@@ -295,11 +303,57 @@ namespace DrillTools
// 检查文件扩展名是否为支持的钻带文件格式
string extension = Path.GetExtension(filePath).ToLowerInvariant();
string[] supportedExtensions = { ".txt", ".drl", ".dr2", ".dr3", ".trg", ".dpin" };
string[] supportedExtensions = { ".txt", ".drl", ".dr2", ".dr3", ".trg", ".dpin", ".rou", ".rou1", ".rou2", ".roux" };
return supportedExtensions.Contains(extension);
}
private static void PerformRouParameterReplace(string filePath)
{
try
{
#if DEBUG
string paramDir = @"C:\Users\14244\source\repos\Aoh\DrillTools\ROU-canshu\";
#else
string paramDir = @"\\aht-file-1\AHT-workdatatemp\泰国澳弘的相关说明资料及作业指引\钻锣带\成型\";
#endif
if (!Directory.Exists(paramDir))
{
System.Windows.MessageBox.Show(
$"参数文件目录不存在:\n{paramDir}",
"错误",
MessageBoxButton.OK,
MessageBoxImage.Error);
return;
}
var selectionWindow = new ParameterFileSelectionWindow(paramDir);
selectionWindow.ShowDialog();
if (selectionWindow.SelectedFilePath == null)
return;
RouParameterReplacer.ReplaceParameters(filePath, selectionWindow.SelectedFilePath);
System.Windows.MessageBox.Show(
$"参数替换完成:\n{filePath}\n原文件已备份为 .bak",
"替换完成",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(
$"参数替换失败:\n{ex.Message}",
"错误",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
/// <summary>
/// 从 MainWindowViewModel.Tools 独立遍历计算叠板用最小刀径。
/// 分类逻辑与 UpdateMinDiameterInfo 一致(按尾号使用标准),不排除 0.749mm;