From 81a17265573e6fd4d2ffc0327ff57c3f723ac288 Mon Sep 17 00:00:00 2001
From: "Mr.Xia" <1424473282@qq.com>
Date: Sat, 16 May 2026 12:07:32 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=AF=BC=E5=87=BA=E5=AD=94?=
=?UTF-8?q?=E6=95=B0=E9=87=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
App.xaml.cs | 4 +-
DrillTools.csproj | 4 +
DrillUsageReportExporter.cs | 101 ++++++++++++++++
MainWindow.xaml | 8 ++
MainWindow.xaml.cs | 19 +++
MainWindowViewModel.cs | 43 +++++++
demo_drl/s20034192b0-a2-cs.drl | 205 ++++++++++++++++++---------------
7 files changed, 291 insertions(+), 93 deletions(-)
create mode 100644 DrillUsageReportExporter.cs
diff --git a/App.xaml.cs b/App.xaml.cs
index 1e9e64e..a270fdf 100644
--- a/App.xaml.cs
+++ b/App.xaml.cs
@@ -2,6 +2,7 @@ using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
+using System.Text;
using System.Windows;
namespace DrillTools
@@ -14,6 +15,7 @@ namespace DrillTools
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// 运行孔位数据功能测试
//MainWindowViewModel.TestHoleLocationsFunctionality();
@@ -63,4 +65,4 @@ namespace DrillTools
return supportedExtensions.Contains(extension);
}
}
-}
\ No newline at end of file
+}
diff --git a/DrillTools.csproj b/DrillTools.csproj
index 1139bfd..b417527 100644
--- a/DrillTools.csproj
+++ b/DrillTools.csproj
@@ -15,4 +15,8 @@
+
+
+
+
diff --git a/DrillUsageReportExporter.cs b/DrillUsageReportExporter.cs
new file mode 100644
index 0000000..c380ebd
--- /dev/null
+++ b/DrillUsageReportExporter.cs
@@ -0,0 +1,101 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+
+namespace DrillTools
+{
+ ///
+ /// 生成 CAM350 风格的钻孔使用报告。
+ ///
+ internal static class DrillUsageReportExporter
+ {
+ public static string GenerateReport(IReadOnlyList tools, string layerName, DateTime exportTime)
+ {
+ if (tools == null)
+ throw new ArgumentNullException(nameof(tools));
+
+ var rows = tools.Select((tool, index) => CreateRow(tool, index + 1)).ToList();
+ var report = new StringBuilder();
+
+ AppendHeader(report, layerName, exportTime);
+ AppendRows(report, rows);
+ AppendTotals(report, rows);
+
+ return report.ToString();
+ }
+
+ private static ReportRow CreateRow(ToolItem tool, int order)
+ {
+ // 当前导出顺序与 Tool Ref 相同;未来如有独立钻孔执行顺序可拆分维护。
+ return new ReportRow(
+ order,
+ tool.ToolNumber,
+ FormatDiameter(tool.Diameter),
+ order,
+ tool.RegularHoles,
+ tool.SlotHoles,
+ tool.TotalHoles);
+ }
+
+ private static void AppendHeader(StringBuilder report, string layerName, DateTime exportTime)
+ {
+ report.AppendLine("Project file name: ");
+ report.AppendLine($"Date: {FormatDate(exportTime)}");
+ report.AppendLine($"Table: DrillTable_1 Layer: {layerName}");
+ report.AppendLine("Drill Usage:");
+ report.AppendLine("Table # Tool Ref Tool # Size Exp Ord Plated Hits Unplated Hits Total Hits");
+ report.AppendLine("======= ======== ====== ==== ======= =========== ============= ==========");
+ }
+
+ private static void AppendRows(StringBuilder report, IReadOnlyList rows)
+ {
+ foreach (var row in rows)
+ {
+ report.AppendLine(string.Format(
+ CultureInfo.InvariantCulture,
+ "{0,8}{1,10}{2,10}{3,17}{4,16}{5,14}{6,15}{7,12}",
+ 1,
+ row.ToolRef,
+ row.ToolNumber,
+ row.Size,
+ row.ExportOrder,
+ row.PlatedHits,
+ row.UnplatedHits,
+ row.TotalHits));
+ }
+ }
+
+ private static void AppendTotals(StringBuilder report, IReadOnlyList rows)
+ {
+ report.AppendLine("=========================================================== =========== ============= ==========");
+ report.AppendLine(string.Format(
+ CultureInfo.InvariantCulture,
+ "{0,69}{1,14}{2,15}{3,12}",
+ "Totals:",
+ rows.Sum(row => row.PlatedHits),
+ rows.Sum(row => row.UnplatedHits),
+ rows.Sum(row => row.TotalHits)));
+ }
+
+ private static string FormatDate(DateTime value)
+ {
+ return $"{value:HH:mm:ss} {value.Year}年{value.Month}月{value.Day}日";
+ }
+
+ private static string FormatDiameter(double value)
+ {
+ return value.ToString("0.###", CultureInfo.InvariantCulture);
+ }
+
+ private sealed record ReportRow(
+ int ToolRef,
+ int ToolNumber,
+ string Size,
+ int ExportOrder,
+ int PlatedHits,
+ int UnplatedHits,
+ int TotalHits);
+ }
+}
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 35db02b..48ec38a 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -172,6 +172,14 @@
Click="MoveDownButton_Click"
Content="↓ 下移"
IsEnabled="{Binding CanMoveDown}" />
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index a9614ba..69be74c 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -198,6 +198,25 @@ namespace DrillTools
}
}
+ ///
+ /// 导出孔数报表按钮点击事件
+ ///
+ private void ExportDrillUsageReportButton_Click(object sender, RoutedEventArgs e)
+ {
+ try
+ {
+ ViewModel.ExportDrillUsageReport();
+ }
+ catch (OperationCanceledException)
+ {
+ return;
+ }
+ catch (Exception ex)
+ {
+ System.Windows.MessageBox.Show($"导出孔数报表失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+
///
/// 生成排序种子按钮点击事件
///
diff --git a/MainWindowViewModel.cs b/MainWindowViewModel.cs
index 99b852d..778338e 100644
--- a/MainWindowViewModel.cs
+++ b/MainWindowViewModel.cs
@@ -1058,6 +1058,49 @@ M30";
Console.WriteLine($"\n坐标绑定验证结果: {(allMatch ? "✓ 全部正确" : "✗ 存在问题")}");
}
+ ///
+ /// 导出 CAM350 风格孔数报表
+ ///
+ public void ExportDrillUsageReport()
+ {
+ if (!HasOriginalFile)
+ throw new InvalidOperationException("没有原始文件路径,请先加载钻带文件");
+
+ if (Tools.Count == 0)
+ throw new InvalidOperationException("没有可导出的刀具数据,请先加载钻带文件");
+
+ string outputFilePath = OriginalFilePath + ".rpt";
+ ConfirmOverwriteReport(outputFilePath);
+
+ string report = DrillUsageReportExporter.GenerateReport(
+ Tools.ToList(),
+ FileNameWithoutExtension,
+ DateTime.Now);
+
+ File.WriteAllText(outputFilePath, report, CreateGb2312Encoding());
+ OpenFileExplorerAndSelectFile(outputFilePath);
+ }
+
+ private static void ConfirmOverwriteReport(string outputFilePath)
+ {
+ if (!File.Exists(outputFilePath))
+ return;
+
+ var result = System.Windows.MessageBox.Show(
+ $"孔数报表文件已存在,是否覆盖?\n\n{outputFilePath}",
+ "文件已存在",
+ MessageBoxButton.YesNo,
+ MessageBoxImage.Question);
+
+ if (result != MessageBoxResult.Yes)
+ throw new OperationCanceledException("用户取消了导出操作");
+ }
+
+ private static Encoding CreateGb2312Encoding()
+ {
+ return Encoding.GetEncoding(936);
+ }
+
///
/// 打开文件资源管理器并选中指定文件
///
diff --git a/demo_drl/s20034192b0-a2-cs.drl b/demo_drl/s20034192b0-a2-cs.drl
index 5d149eb..006d45c 100644
--- a/demo_drl/s20034192b0-a2-cs.drl
+++ b/demo_drl/s20034192b0-a2-cs.drl
@@ -2,33 +2,32 @@ M48
;600V参数-镀膜-EA-260417
T01C0.749H01200Z+0.000S062.00F098.0U1000.0
T02C3.175H00200Z-0.305S020.00F035.0U0700.0
-T03C0.300H01500Z+0.400S155.00F114.0U1000.0
-T04C0.500H01200Z+0.254S110.00F102.0U1000.0
-T05C0.650H01200Z+0.200S065.00F098.0U1000.0
-T06C0.800H01200Z+0.000S060.00F087.0U1000.0
-T07C0.950H01200Z+0.000S056.00F087.0U1000.0
-T08C1.100H01200Z+0.000S055.00F087.0U1000.0
-T09C1.150H01200Z+0.000S050.00F087.0U1000.0
-T10C1.200H01200Z+0.000S050.00F087.0U1000.0
-T11C1.250H01200Z+0.000S045.00F059.0U1000.0
-T12C1.350H01200Z+0.000S045.00F059.0U1000.0
-T13C1.450H01200Z+0.000S045.00F059.0U1000.0
-T14C1.500H01200Z+0.000S030.00F047.0U1000.0
-T15C1.550H01200Z+0.000S030.00F047.0U1000.0
-T16C1.650H01200Z-0.201S028.00F047.0U1000.0
-T17C1.700H01200Z-0.201S028.00F047.0U1000.0
-T18C1.750H01200Z-0.201S028.00F047.0U1000.0
-T19C2.000H01200Z-0.201S025.00F035.0U1000.0
-T20C2.600H00800Z-0.254S022.00F031.0U0600.0
-T21C3.100H00500Z-0.305S020.00F028.0U0600.0
-T22C3.250H00500Z-0.305S020.00F028.0U0600.0
-T23C3.600H00500Z-0.305S020.00F028.0U0600.0
-T24C4.600H00500Z-0.305S020.00F024.0U0600.0
-T25C1.056H01500Z+0.000S062.00F012.0U1000.0
-T26C1.101H02000Z+0.000S055.00F025.0U1000.0
-T27C4.601H00500Z-0.305S020.00F020.0U0700.0
-T28C1.053H15000Z+0.000S055.00F060.0U1000.0
-T29C0.499H05000Z+0.254S110.00F102.0U1000.0
+T03C0.500H01200Z+0.254S110.00F102.0U1000.0
+T04C0.650H01200Z+0.200S065.00F098.0U1000.0
+T05C0.800H01200Z+0.000S060.00F087.0U1000.0
+T06C0.950H01200Z+0.000S056.00F087.0U1000.0
+T07C1.100H01200Z+0.000S055.00F087.0U1000.0
+T08C1.150H01200Z+0.000S050.00F087.0U1000.0
+T09C1.200H01200Z+0.000S050.00F087.0U1000.0
+T10C1.250H01200Z+0.000S045.00F059.0U1000.0
+T11C1.350H01200Z+0.000S045.00F059.0U1000.0
+T12C1.450H01200Z+0.000S045.00F059.0U1000.0
+T13C1.500H01200Z+0.000S030.00F047.0U1000.0
+T14C1.550H01200Z+0.000S030.00F047.0U1000.0
+T15C1.650H01200Z-0.201S028.00F047.0U1000.0
+T16C1.700H01200Z-0.201S028.00F047.0U1000.0
+T17C1.750H01200Z-0.201S028.00F047.0U1000.0
+T18C2.000H01200Z-0.201S025.00F035.0U1000.0
+T19C2.600H00800Z-0.254S022.00F031.0U0600.0
+T20C3.100H00500Z-0.305S020.00F028.0U0600.0
+T21C3.250H00500Z-0.305S020.00F028.0U0600.0
+T22C3.600H00500Z-0.305S020.00F028.0U0600.0
+T23C4.600H00500Z-0.305S020.00F024.0U0600.0
+T24C1.056H01500Z+0.000S062.00F012.0U1000.0
+T25C1.101H02000Z+0.000S055.00F025.0U1000.0
+T26C4.601H00500Z-0.305S020.00F020.0U0700.0
+T27C1.053H15000Z+0.000S055.00F060.0U1000.0
+T28C0.499H05000Z+0.254S110.00F102.0U1000.0
%
T01
X205206Y302500
@@ -79,20 +78,6 @@ X206000Y002000
X206000Y016950
X206034Y401022
T03
-X174250Y188300
-X187750Y188300
-X174250Y378300
-X187750Y378300
-X187750Y568300
-X174250Y568300
-X-174250Y413100
-X-187750Y413100
-X-174250Y223100
-X-187750Y223100
-X-187750Y033100
-X-174250Y033100
-X206034Y405759
-T04
X079121Y360219
X080121Y360219
X080121Y359219
@@ -10281,8 +10266,8 @@ X072266Y428636
X070639Y423477
X065967Y417723
X071333Y414125
-X206034Y409159
-T05
+X206034Y405653
+T04
X-191600Y104201
X-191600Y107701
X-191600Y111201
@@ -10379,20 +10364,32 @@ X-191600Y484201
X-191600Y301201
X-191600Y297701
X-191600Y294201
-X206034Y412734
-T06
+X206034Y409228
+T05
+X-174250Y033875
+X-174250Y032325
X-188000Y014000
X-193000Y014000
X-198000Y014000
X-205000Y008585
+X-187750Y032325
+X-187750Y033875
X-193800Y097388
X-193800Y099013
X-193800Y116388
X-193800Y118013
+X-187750Y222325
+X-187750Y223875
+X-174250Y222325
+X-174250Y223875
X-193800Y287388
X-193800Y289013
X-193800Y306388
X-193800Y308013
+X-187750Y412325
+X-187750Y413875
+X-174250Y412325
+X-174250Y413875
X-193800Y477388
X-193800Y479013
X-193800Y496388
@@ -10542,14 +10539,26 @@ X188000Y591000
X193000Y591000
X198000Y591000
X205000Y596728
+X187750Y569075
+X187750Y567525
+X174250Y569075
+X174250Y567525
X193800Y504012
X193800Y502387
X193800Y485012
X193800Y483387
+X187750Y379075
+X187750Y377525
+X174250Y379075
+X174250Y377525
X193800Y314012
X193800Y312387
X193800Y295012
X193800Y293387
+X187750Y189075
+X187750Y187525
+X174250Y189075
+X174250Y187525
X193800Y124012
X193800Y122387
X193800Y105012
@@ -10558,8 +10567,8 @@ X205000Y008585
X198000Y014000
X193000Y014000
X188000Y014000
-X206034Y416459
-T07
+X206034Y412953
+T06
X-183500Y224831
X-181000Y224831
X-178500Y224831
@@ -10794,8 +10803,8 @@ X-011401Y180901
X-178500Y034831
X-181000Y034831
X-183500Y034831
-X206034Y420334
-T08
+X206034Y416828
+T07
X-052212Y327360
X-052212Y329390
X-059832Y328375
@@ -10814,8 +10823,8 @@ X-052212Y137360
X052212Y084040
X052212Y082010
X059832Y083025
-X206034Y424359
-T09
+X206034Y420853
+T08
X-118478Y421219
X-115978Y421219
X-031969Y435047
@@ -10852,8 +10861,8 @@ X031969Y163853
X031969Y166353
X115978Y180181
X118478Y180181
-X206034Y428484
-T10
+X206034Y424978
+T09
X-193575Y036204
X-191850Y037200
X-193575Y038196
@@ -10896,8 +10905,8 @@ X191850Y031200
X193575Y030204
X193575Y032196
X193575Y183204
-X206034Y432659
-T11
+X206034Y429153
+T10
X031717Y551648
X031717Y556648
X039362Y558219
@@ -11288,8 +11297,8 @@ X-076282Y488531
X-073782Y488531
X-071282Y488531
X-068782Y488531
-X206034Y436884
-T12
+X206034Y433378
+T11
X156618Y176016
X169118Y166016
X169118Y176016
@@ -11320,8 +11329,8 @@ X-169118Y045384
X-156618Y045384
X-160764Y032731
X-155765Y032731
-X206034Y441184
-T13
+X206034Y437678
+T12
X133441Y541819
X140941Y541819
X129397Y519263
@@ -11400,8 +11409,8 @@ X-164625Y574258
X-157025Y574258
X-149526Y573077
X-141926Y573077
-X206034Y445584
-T14
+X206034Y442078
+T13
X-082500Y575288
X-078550Y495650
X-080961Y489180
@@ -11714,8 +11723,8 @@ X-186300Y409400
X-186800Y455191
X-193800Y473200
X-195870Y576447
-X206034Y450059
-T15
+X206034Y446553
+T14
X113333Y075194
X120833Y075194
X129433Y075194
@@ -11896,8 +11905,8 @@ X-179118Y042884
X-171618Y042884
X-156618Y042884
X-156618Y055384
-X206034Y454584
-T16
+X206034Y451078
+T15
X-079621Y239141
X-079621Y244221
X-079621Y249301
@@ -11964,8 +11973,8 @@ X-105021Y059301
X-105021Y054221
X-105021Y049141
X-105021Y044061
-X206034Y459184
-T17
+X206034Y455678
+T16
X105795Y455028
X105795Y458829
X105795Y462628
@@ -12368,8 +12377,8 @@ X-036269Y564953
X-036269Y559953
X-029539Y564953
X-029539Y559953
-X206034Y463859
-T18
+X206034Y460353
+T17
X-169500Y487701
X-169500Y495701
X-174500Y495701
@@ -12442,8 +12451,8 @@ X-021774Y434873
X-021774Y429873
X021774Y361527
X021774Y356527
-X206034Y468584
-T19
+X206034Y465078
+T18
X081700Y487119
X-081700Y494280
X-081700Y304280
@@ -12451,7 +12460,7 @@ X-081700Y114280
X081700Y107119
X081700Y297119
X064610Y596091
-T20
+T19
X-190000Y401100
X-190000Y211100
X-190000Y021100
@@ -12459,11 +12468,27 @@ X190000Y021100
X190000Y211100
X190000Y401100
X069910Y596091
-T21
-X-193000Y391500
-X-133000Y391500
-X-073000Y391500
+T20
+X193000Y201500
+X187750Y188300
+X174250Y188300
+X167000Y201500
+X107000Y201500
+X047000Y201500
+X-013000Y201500
+X-073000Y201500
+X-187750Y033100
+X-174250Y033100
+X-133000Y201500
+X-174250Y223100
+X-193000Y201500
+X-187750Y223100
X-013000Y391500
+X-073000Y391500
+X-133000Y391500
+X-174250Y413100
+X-193000Y391500
+X-187750Y413100
X-193000Y581500
X-133000Y581500
X-073000Y581500
@@ -12471,21 +12496,17 @@ X-013000Y581500
X047000Y581500
X107000Y581500
X167000Y581500
+X174250Y568300
X193000Y581500
+X187750Y568300
X047000Y391500
X107000Y391500
X167000Y391500
+X174250Y378300
X193000Y391500
-X193000Y201500
-X167000Y201500
-X107000Y201500
-X047000Y201500
-X-013000Y201500
-X-073000Y201500
-X-133000Y201500
-X-193000Y201500
+X187750Y378300
X075760Y596091
-T22
+T21
X-193800Y497200
X-193800Y478200
X-193800Y307200
@@ -12499,7 +12520,7 @@ X193800Y313200
X193800Y484200
X193800Y503200
X081935Y596091
-T23
+T22
X-190000Y580000
X-190000Y390000
X-190000Y200000
@@ -12507,7 +12528,7 @@ X190000Y200000
X190000Y390000
X190000Y580000
X088360Y596091
-T24
+T23
X-193000Y570200
X-193000Y417200
X-193000Y380200
@@ -12521,7 +12542,7 @@ X193000Y374200
X193000Y411200
X193000Y564200
X095460Y596091
-T25
+T24
X-141775Y557837G85X-142775Y557837
X-148675Y560377G85X-149675Y560377
X-156875Y559017G85X-157875Y559017
@@ -12559,7 +12580,7 @@ X156875Y422382G85X157875Y422382
X148675Y421023G85X149675Y421023
X141775Y423563G85X142775Y423563
X101288Y596091
-T26
+T25
X-183167Y433266G85X-187217Y433266
X-183167Y243266G85X-187217Y243266
X-183167Y053266G85X-187217Y053266
@@ -12567,7 +12588,7 @@ X183167Y168133G85X187217Y168133
X183167Y358133G85X187217Y358133
X183167Y548133G85X187217Y548133
X105367Y596091
-T27
+T26
X-015982Y028183G85X-018260Y030268
X015982Y193217G85X018260Y191132
X-015982Y218183G85X-018260Y220268
@@ -12575,7 +12596,7 @@ X015982Y383217G85X018260Y381132
X-015982Y408183G85X-018260Y410268
X015982Y573217G85X018260Y571132
X111218Y596091
-T28
+T27
X-141775Y557837G85X-142775Y557837
X-148675Y560377G85X-149675Y560377
X-156875Y559017G85X-157875Y559017
@@ -12613,7 +12634,7 @@ X156875Y422382G85X157875Y422382
X148675Y421023G85X149675Y421023
X141775Y423563G85X142775Y423563
X117045Y596091
-T29
+T28
M97,B*,$S $N
X-142000Y011000
M30