删除了一些测试方法
新增了刀序重排确认窗口 优化了应用刀序到钻带后的一些操作
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using DrillTools.Integration;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace DrillTools
|
||||
{
|
||||
@@ -17,6 +18,7 @@ namespace DrillTools
|
||||
public class MainWindowViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private ObservableCollection<ToolItem> _tools = new();
|
||||
private ObservableCollection<ToolItem> _originalTools = new(); // 保存原始刀具顺序
|
||||
private ToolItem? _selectedTool;
|
||||
private string _drillTapeContent = string.Empty;
|
||||
private bool _canMoveUp;
|
||||
@@ -90,6 +92,15 @@ namespace DrillTools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原始刀具顺序集合(按文件中的出现顺序)
|
||||
/// </summary>
|
||||
public ObservableCollection<ToolItem> OriginalTools
|
||||
{
|
||||
get => _originalTools;
|
||||
set => SetProperty(ref _originalTools, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否有原始文件
|
||||
/// </summary>
|
||||
@@ -103,12 +114,13 @@ namespace DrillTools
|
||||
{
|
||||
DrillTapeContent = drillTapeContent;
|
||||
Tools.Clear();
|
||||
|
||||
OriginalTools.Clear(); // 清空原始刀具顺序
|
||||
|
||||
try
|
||||
{
|
||||
// 使用现有的 DrillTapeProcessor 处理钻带数据
|
||||
var result = DrillTapeProcessor.ProcessDrillTape(drillTapeContent);
|
||||
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
foreach (var toolResult in result.ToolResults)
|
||||
@@ -126,16 +138,16 @@ namespace DrillTools
|
||||
ToolCategory = toolResult.ToolCategory,
|
||||
HoleLocations = toolResult.Locations ?? new List<string>()
|
||||
};
|
||||
|
||||
|
||||
// 如果是机台码,使用DrillTapeProcessor已经解析出的机台码信息
|
||||
if (toolResult.ToolType == ToolType.MachineCode)
|
||||
{
|
||||
toolItem.MachineCodeCommand = toolResult.MachineCodeCommand;
|
||||
toolItem.MachineCodeType = toolResult.MachineCodeType;
|
||||
|
||||
|
||||
// 添加日志验证机台码信息传递
|
||||
System.Diagnostics.Debug.WriteLine($"[机台码传递] T{toolResult.ToolNumber:D2}: 命令={toolItem.MachineCodeCommand}, 类型={toolItem.MachineCodeType}");
|
||||
|
||||
|
||||
// 如果 toolResult.Locations 已经包含坐标数据,则使用它
|
||||
// 否则从原始钻带内容中提取坐标行
|
||||
if (toolItem.HoleLocations == null || toolItem.HoleLocations.Count == 0)
|
||||
@@ -143,29 +155,43 @@ namespace DrillTools
|
||||
// 从钻带内容中提取机台码坐标行
|
||||
var toolPattern = $@"%.+?T{toolResult.ToolNumber:D2}(.*?)(?=T\d{{2}}|M30)";
|
||||
var match = System.Text.RegularExpressions.Regex.Match(DrillTapeContent, toolPattern, System.Text.RegularExpressions.RegexOptions.Singleline);
|
||||
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
string holeSection = match.Groups[1].Value;
|
||||
|
||||
|
||||
// 查找机台码坐标行
|
||||
var coordinatePattern = @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)";
|
||||
var coordinateMatches = System.Text.RegularExpressions.Regex.Matches(holeSection, coordinatePattern);
|
||||
|
||||
|
||||
toolItem.HoleLocations = new List<string>();
|
||||
foreach (Match coordMatch in coordinateMatches)
|
||||
{
|
||||
toolItem.HoleLocations.Add(coordMatch.Value);
|
||||
}
|
||||
|
||||
|
||||
System.Diagnostics.Debug.WriteLine($"[机台码坐标] T{toolResult.ToolNumber:D2}: 找到{toolItem.HoleLocations.Count}个坐标");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Tools.Add(toolItem);
|
||||
|
||||
// 同时添加到原始刀具顺序集合中
|
||||
var originalToolItem = new ToolItem
|
||||
{
|
||||
ToolNumber = toolResult.ToolNumber,
|
||||
Diameter = toolResult.Diameter,
|
||||
ToolType = toolResult.ToolType,
|
||||
ToolSuffixType = toolResult.ToolSuffixType,
|
||||
ToolCategory = toolResult.ToolCategory,
|
||||
HoleLocations = toolResult.Locations ?? new List<string>(),
|
||||
MachineCodeCommand = toolResult.MachineCodeCommand,
|
||||
MachineCodeType = toolResult.MachineCodeType
|
||||
};
|
||||
OriginalTools.Add(originalToolItem);
|
||||
}
|
||||
|
||||
|
||||
// 更新按钮状态
|
||||
UpdateMoveButtonsState();
|
||||
}
|
||||
@@ -398,6 +424,9 @@ namespace DrillTools
|
||||
// 4. 更新当前钻带内容
|
||||
DrillTapeContent = reorderedDrillTape;
|
||||
|
||||
// 5. 打开文件资源管理器并选中文件
|
||||
OpenFileExplorerAndSelectFile(OriginalFilePath);
|
||||
|
||||
return reorderedDrillTape;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@@ -415,18 +444,71 @@ namespace DrillTools
|
||||
/// 重排刀序并重新编号
|
||||
/// </summary>
|
||||
/// <returns>重排后的钻带内容</returns>
|
||||
public string ReorderAndRenumberTools()
|
||||
public string ReorderAndRenumberTools(bool isApply = false)
|
||||
{
|
||||
if (Tools.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("没有可重排的刀具");
|
||||
}
|
||||
|
||||
// 保存原始刀具列表(按文件中的原始顺序)
|
||||
var originalTools = OriginalTools.Select(t => new ToolItem
|
||||
{
|
||||
ToolNumber = t.ToolNumber,
|
||||
Diameter = t.Diameter,
|
||||
ToolType = t.ToolType,
|
||||
ToolSuffixType = t.ToolSuffixType,
|
||||
ToolCategory = t.ToolCategory,
|
||||
HoleLocations = new List<string>(t.HoleLocations ?? new List<string>()),
|
||||
MachineCodeCommand = t.MachineCodeCommand,
|
||||
MachineCodeType = t.MachineCodeType
|
||||
}).ToList();
|
||||
|
||||
// 1. 创建原始刀具编号到新编号的映射
|
||||
var toolNumberMapping = new Dictionary<int, int>();
|
||||
var originalToNewMapping = new Dictionary<int, int>(); // 保存原始映射关系
|
||||
|
||||
// 创建重排后的刀具列表(基于用户已调整的顺序)
|
||||
// 注意:Tools 列表已经反映了用户通过拖放操作调整后的顺序
|
||||
var reorderedTools = new List<ToolItem>();
|
||||
reorderedTools = Tools.Select(t => new ToolItem
|
||||
{
|
||||
ToolNumber = t.ToolNumber,
|
||||
Diameter = t.Diameter,
|
||||
ToolType = t.ToolType,
|
||||
ToolSuffixType = t.ToolSuffixType,
|
||||
ToolCategory = t.ToolCategory,
|
||||
HoleLocations = new List<string>(t.HoleLocations ?? new List<string>()),
|
||||
MachineCodeCommand = t.MachineCodeCommand,
|
||||
MachineCodeType = t.MachineCodeType
|
||||
}).ToList();
|
||||
|
||||
//检查是否所有刀序没有变化
|
||||
int checkindex = 1;
|
||||
for (int i = 0; i < originalTools.Count; i++)
|
||||
{
|
||||
if (reorderedTools[i].ToolNumber == originalTools[i].ToolNumber)
|
||||
checkindex++;
|
||||
}
|
||||
if (checkindex == originalTools.Count)
|
||||
{
|
||||
if (isApply)
|
||||
{
|
||||
ApplyToolOrderToDrillTape();
|
||||
return DrillTapeContent;
|
||||
}
|
||||
throw new InvalidOperationException("刀具顺序未发生变化,无需重排");
|
||||
}
|
||||
|
||||
// 显示确认窗口
|
||||
var confirmationWindow = new ToolReorderConfirmationWindow(originalTools, reorderedTools);
|
||||
confirmationWindow.Owner = System.Windows.Application.Current.MainWindow;
|
||||
confirmationWindow.ShowDialog();
|
||||
if (!confirmationWindow.IsConfirmed)
|
||||
throw new OperationCanceledException("取消刀序重排操作");
|
||||
|
||||
// 2. 按当前列表顺序重新编号(T01, T02, T03...)
|
||||
|
||||
var toolNumberMapping = new Dictionary<int, int>();
|
||||
var originalToNewMapping = new Dictionary<int, int>(); // 保存原始映射关系
|
||||
int newToolNumber = 1;
|
||||
foreach (var tool in Tools.ToList())
|
||||
{
|
||||
@@ -453,6 +535,9 @@ namespace DrillTools
|
||||
// 5. 更新界面显示
|
||||
OnPropertyChanged(nameof(Tools));
|
||||
|
||||
if (isApply)
|
||||
ApplyToolOrderToDrillTape();
|
||||
|
||||
return updatedDrillTape;
|
||||
}
|
||||
|
||||
@@ -587,6 +672,7 @@ namespace DrillTools
|
||||
// 清空原始文件路径,因为这是示例数据
|
||||
OriginalFilePath = string.Empty;
|
||||
Tools.Clear();
|
||||
OriginalTools.Clear(); // 清空原始刀具顺序
|
||||
|
||||
// 添加示例刀具数据
|
||||
Tools.Add(new ToolItem
|
||||
@@ -709,6 +795,23 @@ namespace DrillTools
|
||||
HoleLocations = new List<string> { "X-194000Y002000" } // 机台码刀具的坐标数据
|
||||
});
|
||||
|
||||
// 同时添加到原始刀具顺序集合中
|
||||
foreach (var tool in Tools)
|
||||
{
|
||||
var originalToolItem = new ToolItem
|
||||
{
|
||||
ToolNumber = tool.ToolNumber,
|
||||
Diameter = tool.Diameter,
|
||||
ToolType = tool.ToolType,
|
||||
ToolSuffixType = tool.ToolSuffixType,
|
||||
ToolCategory = tool.ToolCategory,
|
||||
HoleLocations = new List<string>(tool.HoleLocations ?? new List<string>()),
|
||||
MachineCodeCommand = tool.MachineCodeCommand,
|
||||
MachineCodeType = tool.MachineCodeType
|
||||
};
|
||||
OriginalTools.Add(originalToolItem);
|
||||
}
|
||||
|
||||
// 更新按钮状态
|
||||
UpdateMoveButtonsState();
|
||||
|
||||
@@ -779,114 +882,6 @@ M30";
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试机台码孔数计算功能
|
||||
/// </summary>
|
||||
public void TestMachineCodeHoleCalculation()
|
||||
{
|
||||
Console.WriteLine("=== 机台码孔数计算测试 ===");
|
||||
|
||||
// 测试钻带内容
|
||||
string drillTapeContent = @"M48
|
||||
;厚铜板参数-镀膜-EA-250618
|
||||
T01C0.799H05000Z+0.000S060.00F105.0U0700.0
|
||||
T02C0.656H01500Z+0.150S070.00F008.0U0800.0
|
||||
T03C1.601H03000Z-0.200S040.00F030.0U0900.0
|
||||
T04C0.499
|
||||
%
|
||||
T01
|
||||
X-167525Y013500
|
||||
X-167525Y018500
|
||||
X-167525Y023500
|
||||
X167525Y013500
|
||||
X167525Y018500
|
||||
X167525Y023500
|
||||
X099366Y502000
|
||||
T02
|
||||
X-065975Y115250
|
||||
X-085825Y122450
|
||||
X-085825Y124550
|
||||
X-097425Y115250
|
||||
X103093Y502000
|
||||
T03
|
||||
X-069659Y016450G85X-094159Y016450
|
||||
X-181341Y195550G85X-156841Y195550
|
||||
X-069659Y210450G85X-094159Y210450
|
||||
X-181341Y389550G85X-156841Y389550
|
||||
X-069659Y404450G85X-094159Y404450
|
||||
X-181341Y583550G85X-156841Y583550
|
||||
X162939Y596000
|
||||
T04
|
||||
M97,A*,$S $N
|
||||
X-194000Y002000
|
||||
M30";
|
||||
|
||||
// 处理钻带
|
||||
var result = DrillTapeProcessor.ProcessDrillTape(drillTapeContent);
|
||||
|
||||
// 输出结果
|
||||
Console.WriteLine($"处理状态: {(result.Success ? "成功" : "失败")}");
|
||||
if (!result.Success)
|
||||
{
|
||||
Console.WriteLine($"错误信息: {result.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("\n刀具统计:");
|
||||
Console.WriteLine("刀具\t孔径(mm)\t类型\t\t普通孔数\t槽孔数\t总孔数\t孔位数量");
|
||||
Console.WriteLine("========================================================================");
|
||||
|
||||
foreach (var tool in result.ToolResults)
|
||||
{
|
||||
string toolTypeDisplay = tool.ToolType switch
|
||||
{
|
||||
ToolType.Regular => "圆孔",
|
||||
ToolType.Slot => "槽孔",
|
||||
ToolType.MachineCode => "机台码",
|
||||
_ => "未知"
|
||||
};
|
||||
|
||||
Console.WriteLine($"T{tool.ToolNumber:D2}\t{tool.Diameter:F3}\t\t{toolTypeDisplay}\t{tool.RegularHoles}\t\t{tool.SlotHoles}\t{tool.TotalHoles}\t{tool.Locations?.Count ?? 0}");
|
||||
}
|
||||
|
||||
Console.WriteLine($"\n总孔数: {result.TotalHoles}");
|
||||
|
||||
// 验证结果
|
||||
Console.WriteLine("\n=== 验证结果 ===");
|
||||
VerifyResults(result);
|
||||
|
||||
// 测试孔位数据
|
||||
Console.WriteLine("\n=== 孔位数据测试 ===");
|
||||
TestHoleLocations(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试孔位数据
|
||||
/// </summary>
|
||||
/// <param name="result">钻带处理结果</param>
|
||||
private void TestHoleLocations(DrillTapeResult result)
|
||||
{
|
||||
foreach (var tool in result.ToolResults)
|
||||
{
|
||||
Console.WriteLine($"\nT{tool.ToolNumber:D2} 孔位数据 ({tool.Locations?.Count ?? 0} 个):");
|
||||
if (tool.Locations != null && tool.Locations.Count > 0)
|
||||
{
|
||||
foreach (var location in tool.Locations.Take(5)) // 只显示前5个
|
||||
{
|
||||
Console.WriteLine($" {location}");
|
||||
}
|
||||
if (tool.Locations.Count > 5)
|
||||
{
|
||||
Console.WriteLine($" ... 还有 {tool.Locations.Count - 5} 个孔位");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(" 无孔位数据");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void VerifyResults(DrillTapeResult result)
|
||||
{
|
||||
// CAM350的预期结果
|
||||
@@ -925,254 +920,6 @@ M30";
|
||||
Console.WriteLine($"\n总体结果: {(allMatch ? "✓ 所有结果与CAM350一致" : "✗ 存在不一致的结果")}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试刀具尾号类型功能
|
||||
/// </summary>
|
||||
public void TestToolSuffixTypeFunctionality()
|
||||
{
|
||||
Console.WriteLine("=== 刀具尾号类型功能测试 ===");
|
||||
|
||||
// 测试不同孔径的尾号类型
|
||||
double[] testDiameters = { 1.049, 1.550, 1.156, 1.451, 1.153, 1.255, 1.266, 1.277, 1.288, 1.299 };
|
||||
|
||||
Console.WriteLine("孔径(mm)\t尾号\t尾号类型\t\t大类");
|
||||
Console.WriteLine("==============================================");
|
||||
|
||||
foreach (double diameter in testDiameters)
|
||||
{
|
||||
string diameterStr = diameter.ToString("F3");
|
||||
char lastChar = diameterStr[diameterStr.Length - 1];
|
||||
int suffix = int.Parse(lastChar.ToString());
|
||||
var suffixType = ToolItem.GetToolSuffixType(diameter);
|
||||
var category = ToolItem.GetToolCategory(suffixType);
|
||||
var suffixDisplay = ToolItem.GetToolSuffixTypeDisplay(suffixType);
|
||||
var categoryDisplay = ToolItem.GetToolCategoryDisplay(category);
|
||||
|
||||
Console.WriteLine($"{diameter:F3}\t{suffix}\t{suffixDisplay}\t{categoryDisplay}");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("=== 测试钻带处理功能 ===");
|
||||
|
||||
// 测试钻带处理
|
||||
string drillTapeContent = @"M48
|
||||
T10C1.049
|
||||
T11C1.550
|
||||
T12C1.156
|
||||
T13C1.451
|
||||
T14C1.153
|
||||
T15C1.255
|
||||
T16C1.266
|
||||
T17C1.277
|
||||
%
|
||||
T10
|
||||
X01000Y01000
|
||||
T11
|
||||
X02000Y02000
|
||||
T12
|
||||
X03000Y03000
|
||||
T13
|
||||
X04000Y04000
|
||||
T14
|
||||
X05000Y05000
|
||||
T15
|
||||
X06000Y06000
|
||||
T16
|
||||
X07000Y07000
|
||||
T17
|
||||
X08000Y08000
|
||||
M30";
|
||||
|
||||
var result = DrillTapeProcessor.ProcessDrillTape(drillTapeContent);
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
Console.WriteLine("钻带处理成功!");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("刀具编号\t孔径(mm)\t类型\t\t尾号类型\t大类\t\t孔数");
|
||||
Console.WriteLine("================================================================");
|
||||
|
||||
foreach (var tool in result.ToolResults)
|
||||
{
|
||||
string toolTypeDisplay = tool.ToolType switch
|
||||
{
|
||||
ToolType.Regular => "圆孔",
|
||||
ToolType.Slot => "槽孔",
|
||||
ToolType.MachineCode => "机台码",
|
||||
_ => "未知"
|
||||
};
|
||||
|
||||
string suffixTypeDisplay = tool.ToolSuffixType switch
|
||||
{
|
||||
ToolSuffixType.Drill => "钻针",
|
||||
ToolSuffixType.Slot => "槽刀",
|
||||
ToolSuffixType.EASlot => "EA型槽刀",
|
||||
ToolSuffixType.DustSlot => "粉尘刀",
|
||||
ToolSuffixType.DeburrSlot => "去毛刺刀",
|
||||
ToolSuffixType.NonStandard => "非标刀",
|
||||
ToolSuffixType.EASlot2 => "EA型槽刀",
|
||||
ToolSuffixType.Special => "特殊刀具",
|
||||
_ => "未知"
|
||||
};
|
||||
|
||||
string categoryDisplay = tool.ToolCategory switch
|
||||
{
|
||||
ToolCategory.Drill => "钻针",
|
||||
ToolCategory.Slot => "槽刀",
|
||||
ToolCategory.EA => "EA刀",
|
||||
ToolCategory.NonStandard => "非标刀",
|
||||
ToolCategory.Special => "特殊刀",
|
||||
_ => "未知"
|
||||
};
|
||||
|
||||
Console.WriteLine($"T{tool.ToolNumber:D2}\t{tool.Diameter:F3}\t\t{toolTypeDisplay}\t{suffixTypeDisplay}\t{categoryDisplay}\t{tool.TotalHoles}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"钻带处理失败: {result.Message}");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("测试完成!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试孔位数据功能(可在应用启动时调用)
|
||||
/// </summary>
|
||||
public static void TestHoleLocationsFunctionality()
|
||||
{
|
||||
Console.WriteLine("=== 孔位数据功能测试 ===");
|
||||
Console.WriteLine();
|
||||
|
||||
// 使用用户提供的钻带数据示例
|
||||
string drillTapeContent = @"M48
|
||||
T01C0.799H05000Z+0.000S060.00F105.0U0700.0
|
||||
T02C1.049H05000Z+0.000S045.00F105.0U0700.0
|
||||
%
|
||||
T01
|
||||
X-281000Y003000
|
||||
X-276000Y003000
|
||||
X-271000Y003000
|
||||
X271000Y003000
|
||||
X276000Y003000
|
||||
X281000Y003000
|
||||
X-281000Y702500
|
||||
X-276000Y702500
|
||||
X-271000Y702500
|
||||
X271000Y703000
|
||||
X276000Y703000
|
||||
X281000Y703000
|
||||
X077370Y704000
|
||||
T02
|
||||
X-100000Y100000
|
||||
X-200000Y200000
|
||||
X-300000Y300000
|
||||
M30";
|
||||
|
||||
// 处理钻带
|
||||
var result = DrillTapeProcessor.ProcessDrillTape(drillTapeContent);
|
||||
|
||||
// 输出结果
|
||||
Console.WriteLine($"处理状态: {(result.Success ? "成功" : "失败")}");
|
||||
if (!result.Success)
|
||||
{
|
||||
Console.WriteLine($"错误信息: {result.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("\n刀具统计:");
|
||||
Console.WriteLine("刀具\t孔径(mm)\t类型\t\t普通孔数\t槽孔数\t总孔数\t孔位数量");
|
||||
Console.WriteLine("========================================================================");
|
||||
|
||||
foreach (var tool in result.ToolResults)
|
||||
{
|
||||
string toolTypeDisplay = tool.ToolType switch
|
||||
{
|
||||
ToolType.Regular => "圆孔",
|
||||
ToolType.Slot => "槽孔",
|
||||
ToolType.MachineCode => "机台码",
|
||||
_ => "未知"
|
||||
};
|
||||
|
||||
Console.WriteLine($"T{tool.ToolNumber:D2}\t{tool.Diameter:F3}\t\t{toolTypeDisplay}\t{tool.RegularHoles}\t\t{tool.SlotHoles}\t{tool.TotalHoles}\t{tool.Locations?.Count ?? 0}");
|
||||
}
|
||||
|
||||
Console.WriteLine($"\n总孔数: {result.TotalHoles}");
|
||||
|
||||
// 详细显示孔位数据
|
||||
Console.WriteLine("\n=== 详细孔位数据 ===");
|
||||
foreach (var tool in result.ToolResults)
|
||||
{
|
||||
Console.WriteLine($"\nT{tool.ToolNumber:D2} 孔位数据 ({tool.Locations?.Count ?? 0} 个):");
|
||||
if (tool.Locations != null && tool.Locations.Count > 0)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (var location in tool.Locations)
|
||||
{
|
||||
Console.WriteLine($" [{++count:D2}] {location}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(" 无孔位数据");
|
||||
}
|
||||
}
|
||||
|
||||
// 验证T01的孔位数据是否符合预期
|
||||
Console.WriteLine("\n=== 验证T01孔位数据 ===");
|
||||
var t01Result = result.ToolResults.Find(t => t.ToolNumber == 1);
|
||||
if (t01Result != null && t01Result.Locations != null)
|
||||
{
|
||||
var expectedLocations = new System.Collections.Generic.List<string>
|
||||
{
|
||||
"X-281000Y003000",
|
||||
"X-276000Y003000",
|
||||
"X-271000Y003000",
|
||||
"X271000Y003000",
|
||||
"X276000Y003000",
|
||||
"X281000Y003000",
|
||||
"X-281000Y702500",
|
||||
"X-276000Y702500",
|
||||
"X-271000Y702500",
|
||||
"X271000Y703000",
|
||||
"X276000Y703000",
|
||||
"X281000Y703000",
|
||||
"X077370Y704000"
|
||||
};
|
||||
|
||||
bool allMatch = true;
|
||||
if (t01Result.Locations.Count == expectedLocations.Count)
|
||||
{
|
||||
for (int i = 0; i < expectedLocations.Count; i++)
|
||||
{
|
||||
if (t01Result.Locations[i] != expectedLocations[i])
|
||||
{
|
||||
Console.WriteLine($" 位置 {i + 1}: 预期 {expectedLocations[i]}, 实际 {t01Result.Locations[i]} ✗");
|
||||
allMatch = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($" 位置 {i + 1}: {t01Result.Locations[i]} ✓");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($" 孔位数量不匹配: 预期 {expectedLocations.Count}, 实际 {t01Result.Locations.Count} ✗");
|
||||
allMatch = false;
|
||||
}
|
||||
|
||||
Console.WriteLine($"\nT01孔位数据验证结果: {(allMatch ? "✓ 全部匹配" : "✗ 存在不匹配")}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("未找到T01刀具数据 ✗");
|
||||
}
|
||||
|
||||
Console.WriteLine("\n孔位数据功能测试完成!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示刀具详情窗口
|
||||
/// </summary>
|
||||
@@ -1296,311 +1043,32 @@ M30";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试修正后的重排刀序功能
|
||||
/// 打开文件资源管理器并选中指定文件
|
||||
/// </summary>
|
||||
public void TestFixedReorderFunction()
|
||||
/// <param name="filePath">要选中的文件路径</param>
|
||||
private void OpenFileExplorerAndSelectFile(string filePath)
|
||||
{
|
||||
Console.WriteLine("=== 测试修正后的重排刀序功能 ===");
|
||||
|
||||
// 1. 加载测试数据
|
||||
LoadSampleData();
|
||||
|
||||
Console.WriteLine("原始刀具顺序:");
|
||||
foreach (var tool in Tools)
|
||||
{
|
||||
Console.WriteLine($"T{tool.ToolNumber:D2}C{tool.Diameter:F3}");
|
||||
}
|
||||
|
||||
// 2. 模拟用户重排操作:将T02移到第一位
|
||||
if (Tools.Count >= 2)
|
||||
{
|
||||
var toolToMove = Tools.FirstOrDefault(t => t.ToolNumber == 2);
|
||||
if (toolToMove != null && toolToMove.ToolType != ToolType.MachineCode)
|
||||
{
|
||||
int oldIndex = Tools.IndexOf(toolToMove);
|
||||
ReorderTools(oldIndex, 0);
|
||||
|
||||
Console.WriteLine("\n重排后刀具顺序(重新编号前):");
|
||||
foreach (var tool in Tools)
|
||||
{
|
||||
Console.WriteLine($"T{tool.ToolNumber:D2}C{tool.Diameter:F3}");
|
||||
}
|
||||
|
||||
// 3. 执行重新编号
|
||||
string reorderedDrillTape = ReorderAndRenumberTools();
|
||||
|
||||
Console.WriteLine("\n重排并重新编号后的刀具顺序:");
|
||||
foreach (var tool in Tools)
|
||||
{
|
||||
Console.WriteLine($"T{tool.ToolNumber:D2}C{tool.Diameter:F3}");
|
||||
}
|
||||
|
||||
// 4. 验证刀具定义部分是否按顺序排列
|
||||
Console.WriteLine("\n=== 验证结果 ===");
|
||||
var lines = reorderedDrillTape.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var toolDefinitionOrder = new List<int>();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.Trim() == "%")
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (Regex.IsMatch(line, @"^T(\d+)C"))
|
||||
{
|
||||
var match = Regex.Match(line, @"^T(\d+)C");
|
||||
if (match.Success)
|
||||
{
|
||||
toolDefinitionOrder.Add(int.Parse(match.Groups[1].Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("刀具定义部分的顺序: " + string.Join(", ", toolDefinitionOrder.Select(t => $"T{t:D2}")));
|
||||
|
||||
bool isOrdered = true;
|
||||
for (int i = 1; i < toolDefinitionOrder.Count; i++)
|
||||
{
|
||||
if (toolDefinitionOrder[i] < toolDefinitionOrder[i - 1])
|
||||
{
|
||||
isOrdered = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"刀具定义部分是否按顺序排列: {(isOrdered ? "是" : "否")}");
|
||||
|
||||
if (isOrdered)
|
||||
{
|
||||
Console.WriteLine("✓ 重排刀序功能修正成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("✗ 重排刀序功能仍有问题!");
|
||||
}
|
||||
|
||||
// 5. 显示完整的重排后钻带内容
|
||||
Console.WriteLine("\n重排后的钻带内容:");
|
||||
Console.WriteLine(reorderedDrillTape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试机台码坐标数据完整性
|
||||
/// </summary>
|
||||
public void TestMachineCodeCoordinateIntegrity()
|
||||
{
|
||||
Console.WriteLine("=== 机台码坐标数据完整性测试 ===");
|
||||
|
||||
// 1. 加载示例数据
|
||||
LoadSampleData();
|
||||
|
||||
// 2. 执行重排刀序操作
|
||||
string reorderedDrillTape = ReorderAndRenumberTools();
|
||||
|
||||
// 3. 验证机台码坐标数据
|
||||
Console.WriteLine("重排后的钻带内容:");
|
||||
Console.WriteLine(reorderedDrillTape);
|
||||
|
||||
// 4. 检查机台码部分是否包含坐标数据
|
||||
var lines = reorderedDrillTape.Split(new[] { '\r', '\n' }, StringSplitOptions.None);
|
||||
bool foundMachineCode = false;
|
||||
bool foundCoordinate = false;
|
||||
int machineCodeToolNumber = -1;
|
||||
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
string line = lines[i].Trim();
|
||||
|
||||
// 查找机台码刀具
|
||||
if (Regex.IsMatch(line, @"^T(\d+)"))
|
||||
{
|
||||
var match = Regex.Match(line, @"^T(\d+)");
|
||||
if (match.Success)
|
||||
{
|
||||
int toolNumber = int.Parse(match.Groups[1].Value);
|
||||
var tool = Tools.FirstOrDefault(t => t.ToolNumber == toolNumber);
|
||||
|
||||
if (tool != null && tool.ToolType == ToolType.MachineCode)
|
||||
{
|
||||
foundMachineCode = true;
|
||||
machineCodeToolNumber = toolNumber;
|
||||
Console.WriteLine($"\n找到机台码刀具 T{toolNumber:D2}");
|
||||
|
||||
// 检查下一行是否是机台码命令
|
||||
if (i + 1 < lines.Length)
|
||||
{
|
||||
string nextLine = lines[i + 1].Trim();
|
||||
if (Regex.IsMatch(nextLine, @"(M97|M98),(A\*|B\*),\$S \$N"))
|
||||
{
|
||||
Console.WriteLine($" 机台码命令: {nextLine}");
|
||||
|
||||
// 检查下下行是否是坐标数据
|
||||
if (i + 2 < lines.Length)
|
||||
{
|
||||
string coordinateLine = lines[i + 2].Trim();
|
||||
if (Regex.IsMatch(coordinateLine, @"X([+-]?\d+\.?\d*)Y([+-]?\d+\.?\d*)"))
|
||||
{
|
||||
foundCoordinate = true;
|
||||
Console.WriteLine($" 坐标数据: {coordinateLine}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 输出测试结果
|
||||
Console.WriteLine("\n=== 测试结果 ===");
|
||||
Console.WriteLine($"找到机台码刀具: {(foundMachineCode ? "是" : "否")}");
|
||||
Console.WriteLine($"找到坐标数据: {(foundCoordinate ? "是" : "否")}");
|
||||
|
||||
if (foundMachineCode && foundCoordinate)
|
||||
{
|
||||
Console.WriteLine("✓ 机台码坐标数据完整性测试通过!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("✗ 机台码坐标数据完整性测试失败!");
|
||||
|
||||
if (!foundMachineCode)
|
||||
Console.WriteLine(" 原因:未找到机台码刀具");
|
||||
if (!foundCoordinate)
|
||||
Console.WriteLine(" 原因:机台码刀具缺少坐标数据");
|
||||
}
|
||||
|
||||
// 6. 验证ToolItem中的坐标数据
|
||||
var machineCodeTool = Tools.FirstOrDefault(t => t.ToolType == ToolType.MachineCode);
|
||||
if (machineCodeTool != null)
|
||||
{
|
||||
Console.WriteLine($"\nToolItem中的机台码坐标数据:");
|
||||
Console.WriteLine($" 刀具编号: T{machineCodeTool.ToolNumber:D2}");
|
||||
Console.WriteLine($" 机台码命令: {machineCodeTool.MachineCodeCommand}");
|
||||
Console.WriteLine($" 机台码类型: {machineCodeTool.MachineCodeType}");
|
||||
Console.WriteLine($" 坐标数量: {machineCodeTool.HoleLocations?.Count ?? 0}");
|
||||
|
||||
if (machineCodeTool.HoleLocations != null && machineCodeTool.HoleLocations.Count > 0)
|
||||
{
|
||||
foreach (var location in machineCodeTool.HoleLocations)
|
||||
{
|
||||
Console.WriteLine($" 坐标: {location}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试机台码处理修复效果
|
||||
/// </summary>
|
||||
public void TestMachineCodeProcessingFix()
|
||||
{
|
||||
Console.WriteLine("=== 测试机台码处理修复效果 ===");
|
||||
|
||||
// 测试钻带内容(包含机台码)
|
||||
string testDrillTape = @"M48
|
||||
;厚铜板参数-镀膜-EA-250618
|
||||
T01C1.049H05000Z+0.000S060.00F105.0U0700.0
|
||||
T02C1.550H01500Z+0.150S070.00F008.0U0800.0
|
||||
T03C1.156H03000Z-0.200S040.00F030.0U0900.0
|
||||
T04C0.499H01500Z+0.150S070.00F008.0U0800.0
|
||||
%
|
||||
T01
|
||||
X-167525Y013500
|
||||
X-167525Y018500
|
||||
X-167525Y023500
|
||||
T02
|
||||
X-065975Y115250
|
||||
X-085825Y122450
|
||||
T03
|
||||
X-069659Y016450G85X-094159Y016450
|
||||
X-181341Y195550G85X-156841Y195550
|
||||
T04
|
||||
M97,A*,$S $N
|
||||
X-194000Y002000
|
||||
M30";
|
||||
|
||||
try
|
||||
{
|
||||
// 1. 使用DrillTapeProcessor处理钻带
|
||||
Console.WriteLine("\n1. 使用DrillTapeProcessor处理钻带:");
|
||||
var result = DrillTapeProcessor.ProcessDrillTape(testDrillTape);
|
||||
|
||||
if (!result.Success)
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Console.WriteLine($"处理失败: {result.Message}");
|
||||
System.Windows.MessageBox.Show($"文件不存在: {filePath}", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. 检查ToolResult中的机台码信息
|
||||
Console.WriteLine("\n2. 检查ToolResult中的机台码信息:");
|
||||
foreach (var toolResult in result.ToolResults)
|
||||
// 使用 explorer.exe 的 /select 参数来打开文件资源管理器并选中文件
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
Console.WriteLine($"T{toolResult.ToolNumber:D2}: 类型={toolResult.ToolType}, 命令={toolResult.MachineCodeCommand}, 类型={toolResult.MachineCodeType}");
|
||||
}
|
||||
FileName = "explorer.exe",
|
||||
Arguments = $"/select,\"{filePath}\"",
|
||||
UseShellExecute = true
|
||||
};
|
||||
|
||||
// 3. 使用LoadToolsFromDrillTape方法加载到ViewModel
|
||||
Console.WriteLine("\n3. 加载到ViewModel并检查ToolItem中的机台码信息:");
|
||||
DrillTapeContent = testDrillTape;
|
||||
Tools.Clear();
|
||||
LoadToolsFromDrillTape(testDrillTape);
|
||||
|
||||
foreach (var tool in Tools)
|
||||
{
|
||||
Console.WriteLine($"T{tool.ToolNumber:D2}: 类型={tool.ToolType}, 命令={tool.MachineCodeCommand}, 类型={tool.MachineCodeType}");
|
||||
}
|
||||
|
||||
// 4. 测试GenerateReorderedDrillTape方法
|
||||
Console.WriteLine("\n4. 测试GenerateReorderedDrillTape方法:");
|
||||
string reorderedDrillTape = DrillTapeProcessorExtensions.GenerateReorderedDrillTape(testDrillTape, Tools.ToList());
|
||||
Console.WriteLine("重排后的钻带内容:");
|
||||
Console.WriteLine(reorderedDrillTape);
|
||||
|
||||
// 5. 验证机台码信息是否正确保留
|
||||
Console.WriteLine("\n5. 验证机台码信息是否正确保留:");
|
||||
bool machineCodeFound = false;
|
||||
bool machineCodeCommandFound = false;
|
||||
bool machineCodeTypeFound = false;
|
||||
|
||||
var lines = reorderedDrillTape.Split(new[] { '\r', '\n' }, StringSplitOptions.None);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line.Contains("M97") || line.Contains("M98"))
|
||||
{
|
||||
machineCodeFound = true;
|
||||
if (line.Contains("M97") || line.Contains("M98"))
|
||||
{
|
||||
machineCodeCommandFound = true;
|
||||
}
|
||||
if (line.Contains("A*") || line.Contains("B*"))
|
||||
{
|
||||
machineCodeTypeFound = true;
|
||||
}
|
||||
Console.WriteLine($"找到机台码命令行: {line}");
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"\n验证结果:");
|
||||
Console.WriteLine($"机台码命令存在: {machineCodeFound}");
|
||||
Console.WriteLine($"机台码命令类型正确: {machineCodeCommandFound}");
|
||||
Console.WriteLine($"机台码类型正确: {machineCodeTypeFound}");
|
||||
|
||||
if (machineCodeFound && machineCodeCommandFound && machineCodeTypeFound)
|
||||
{
|
||||
Console.WriteLine("\n✓ 机台码处理修复效果验证成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("\n✗ 机台码处理修复效果验证失败!");
|
||||
}
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"测试过程中发生异常: {ex.Message}");
|
||||
Console.WriteLine($"堆栈跟踪: {ex.StackTrace}");
|
||||
System.Windows.MessageBox.Show($"打开文件资源管理器失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user