From e0326c2d80538643169872cdd3df0af088dab71c Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 23 Apr 2026 07:14:10 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=BB=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=EF=BC=9B=E5=A2=9E=E5=8A=A0=E6=8A=A5=E5=91=8A=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- XplorePlane/Doc/CNC多检测结果归档.md | 505 +++++++++++++++++++++++++ XplorePlane/Views/Main/MainWindow.xaml | 4 +- 3 files changed, 509 insertions(+), 4 deletions(-) create mode 100644 XplorePlane/Doc/CNC多检测结果归档.md diff --git a/README.md b/README.md index ca86f50..6d8de7a 100644 --- a/README.md +++ b/README.md @@ -106,5 +106,5 @@ dotnet build XplorePlane.sln -c Release - [x] 相机实时影像集成(连接、采集、Live View、像素坐标显示) - [x] 相机参数设置对话框(曝光、增益、分辨率、像素格式) - [x] 主界面硬件栏相机设置按钮 -- [ ] 打通与硬件层的调用流程 -- [ ] 打通与图像层的调用流程 +- [x] 打通与硬件层的调用流程 +- [x] 打通与图像层的调用流程 diff --git a/XplorePlane/Doc/CNC多检测结果归档.md b/XplorePlane/Doc/CNC多检测结果归档.md new file mode 100644 index 0000000..fd167f3 --- /dev/null +++ b/XplorePlane/Doc/CNC多检测结果归档.md @@ -0,0 +1,505 @@ +# CNC 多检测结果归档与报告取数说明 + +## 1. 目标 + +为 CNC 执行结果提供一套适合报告模块直接取数的归档结构。 + +设计目标: + +- 以“一次工件检测实例”作为主归档单位 +- 同时保留到“检测节点级别”的明细 +- 支持保存: + - CNC 程序名 + - 工件号 / 序列号 + - 检测节点信息 + - 节点使用的 Pipeline / 配方快照 + - 原图、节点输入图、节点最终结果图 + - 节点输出的多个数值结果 + - 节点判定和整次实例判定 +- 方便后续报告模块直接读取,不依赖运行时最新配方 + +当前实现采用: + +- SQLite 保存结构化索引数据 +- 文件系统保存图片资产和 `manifest.json` + +--- + +## 2. 总体设计 + +一次检测实例会生成: + +1. 一组数据库记录 +2. 一组文件目录和图像文件 +3. 一份 `manifest.json` 快照文件 + +归档核心对象: + +- `InspectionRunRecord` + - 一次完整检测实例 +- `InspectionNodeResult` + - 一个 CNC 检测节点的结果 +- `InspectionMetricResult` + - 节点输出的数值结果 +- `InspectionAssetRecord` + - 图像或附件索引 +- `PipelineExecutionSnapshot` + - 节点执行时使用的 Pipeline 快照 + +默认图片保留策略: + +- 整次实例原图 +- 每个节点的输入图 +- 每个节点的最终结果图 + +不默认保存每个算法步骤的中间图。 + +--- + +## 3. 文件存储结构 + +### 3.1 根目录 + +默认根目录: + +```text +%AppData%\XplorePlane\InspectionResults +``` + +每次检测实例按日期和 `RunId` 分层: + +```text +Results/{yyyy}/{MM}/{dd}/{RunId}/ +``` + +### 3.2 示例目录 + +假设: + +- `ProgramName = NewCncProgram` +- `WorkpieceId = QFN_1` +- `SerialNumber = SN-001` +- `RunId = 7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` +- 检测节点共 2 个 + +则文件结构大致为: + +```text +%AppData%\XplorePlane\InspectionResults\ +└─ Results\ + └─ 2026\ + └─ 04\ + └─ 21\ + └─ 7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a\ + ├─ manifest.json + ├─ run\ + │ └─ source.bmp + └─ nodes\ + ├─ 001_检测节点1\ + │ ├─ input.bmp + │ └─ result_overlay.bmp + └─ 002_检测节点2\ + └─ result_overlay.bmp +``` + +### 3.3 文件说明 + +- `run/source.bmp` + - 本次工件检测实例的原始输入图 +- `nodes/001_检测节点1/input.bmp` + - 节点 1 输入图 +- `nodes/001_检测节点1/result_overlay.bmp` + - 节点 1 最终结果图 +- `nodes/002_检测节点2/result_overlay.bmp` + - 节点 2 最终结果图 +- `manifest.json` + - 本次检测完整快照,便于离线查看、调试和导出 + +--- + +## 4. 数据库表设计 + +当前实现包含 5 张主表。 + +### 4.1 `inspection_runs` + +用途:保存一次完整检测实例的主记录。 + +| 字段 | 类型 | 说明 | +|---|---|---| +| `run_id` | `TEXT` | 主键,检测实例 ID,GUID | +| `program_name` | `TEXT` | CNC 程序名 | +| `workpiece_id` | `TEXT` | 工件号 | +| `serial_number` | `TEXT` | 序列号 | +| `started_at` | `TEXT` | 开始时间,ISO 8601 | +| `completed_at` | `TEXT` | 结束时间,ISO 8601,可空 | +| `overall_pass` | `INTEGER` | 整体判定,`0/1` | +| `source_image_path` | `TEXT` | 原图相对路径 | +| `result_root_path` | `TEXT` | 本次结果包根目录相对路径 | +| `node_count` | `INTEGER` | 节点数量 | + +样例数据: + +| run_id | program_name | workpiece_id | serial_number | started_at | completed_at | overall_pass | source_image_path | result_root_path | node_count | +|---|---|---|---|---|---|---:|---|---|---:| +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `NewCncProgram` | `QFN_1` | `SN-001` | `2026-04-21T10:00:00.0000000Z` | `2026-04-21T10:00:03.2000000Z` | `0` | `Results/2026/04/21/7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a/run/source.bmp` | `Results/2026/04/21/7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `2` | + +### 4.2 `inspection_node_results` + +用途:保存一次检测实例中的节点级结果。 + +| 字段 | 类型 | 说明 | +|---|---|---| +| `run_id` | `TEXT` | 所属检测实例 ID | +| `node_id` | `TEXT` | 节点 ID,GUID | +| `node_index` | `INTEGER` | 节点序号 | +| `node_name` | `TEXT` | 节点名称 | +| `pipeline_id` | `TEXT` | Pipeline ID,GUID | +| `pipeline_name` | `TEXT` | Pipeline 名称 | +| `pipeline_version_hash` | `TEXT` | Pipeline 快照 hash | +| `node_pass` | `INTEGER` | 节点判定,`0/1` | +| `source_image_path` | `TEXT` | 节点输入图相对路径 | +| `result_image_path` | `TEXT` | 节点结果图相对路径 | +| `status` | `TEXT` | 节点状态:`Succeeded / Failed / PartialSuccess / AssetMissing` | +| `duration_ms` | `INTEGER` | 节点耗时 | + +样例数据: + +| run_id | node_id | node_index | node_name | pipeline_name | pipeline_version_hash | node_pass | source_image_path | result_image_path | status | duration_ms | +|---|---|---:|---|---|---|---:|---|---|---|---:| +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `11111111-1111-1111-1111-111111111111` | `1` | `检测节点1` | `Recipe-A` | `A1B2C3...` | `1` | `Results/2026/04/21/.../nodes/001_检测节点1/input.bmp` | `Results/2026/04/21/.../nodes/001_检测节点1/result_overlay.bmp` | `Succeeded` | `135` | +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `22222222-2222-2222-2222-222222222222` | `2` | `检测节点2` | `Recipe-B` | `D4E5F6...` | `0` | `` | `Results/2026/04/21/.../nodes/002_检测节点2/result_overlay.bmp` | `Failed` | `240` | + +### 4.3 `inspection_metric_results` + +用途:保存节点输出的结构化数值结果。 + +| 字段 | 类型 | 说明 | +|---|---|---| +| `run_id` | `TEXT` | 所属检测实例 ID | +| `node_id` | `TEXT` | 所属节点 ID | +| `metric_key` | `TEXT` | 指标 key | +| `metric_name` | `TEXT` | 指标名称 | +| `metric_value` | `REAL` | 指标值 | +| `unit` | `TEXT` | 单位 | +| `lower_limit` | `REAL` | 下限,可空 | +| `upper_limit` | `REAL` | 上限,可空 | +| `is_pass` | `INTEGER` | 单指标判定,`0/1` | +| `display_order` | `INTEGER` | 展示顺序 | + +样例数据: + +| run_id | node_id | metric_key | metric_name | metric_value | unit | lower_limit | upper_limit | is_pass | display_order | +|---|---|---|---|---:|---|---:|---:|---:|---:| +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `11111111-1111-1111-1111-111111111111` | `bridge.rate` | `Bridge Rate` | `0.12` | `%` | | `0.2` | `1` | `1` | +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `11111111-1111-1111-1111-111111111111` | `void.area` | `Void Area` | `5.6` | `px` | | `8` | `1` | `2` | +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `22222222-2222-2222-2222-222222222222` | `solder.height` | `Solder Height` | `1.7` | `mm` | `1.8` | | `0` | `1` | + +### 4.4 `inspection_assets` + +用途:保存文件资产索引。 + +| 字段 | 类型 | 说明 | +|---|---|---| +| `run_id` | `TEXT` | 所属检测实例 ID | +| `node_id` | `TEXT` | 所属节点 ID,可空 | +| `asset_type` | `TEXT` | 资产类型 | +| `relative_path` | `TEXT` | 相对路径 | +| `file_format` | `TEXT` | 文件格式 | +| `width` | `INTEGER` | 宽度 | +| `height` | `INTEGER` | 高度 | + +约定的 `asset_type`: + +- `RunSourceImage` +- `NodeInputImage` +- `NodeResultImage` + +样例数据: + +| run_id | node_id | asset_type | relative_path | file_format | width | height | +|---|---|---|---|---|---:|---:| +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | | `RunSourceImage` | `Results/2026/04/21/.../run/source.bmp` | `bmp` | `0` | `0` | +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `11111111-1111-1111-1111-111111111111` | `NodeInputImage` | `Results/2026/04/21/.../nodes/001_检测节点1/input.bmp` | `bmp` | `0` | `0` | +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `11111111-1111-1111-1111-111111111111` | `NodeResultImage` | `Results/2026/04/21/.../nodes/001_检测节点1/result_overlay.bmp` | `bmp` | `0` | `0` | +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `22222222-2222-2222-2222-222222222222` | `NodeResultImage` | `Results/2026/04/21/.../nodes/002_检测节点2/result_overlay.bmp` | `bmp` | `0` | `0` | + +### 4.5 `pipeline_execution_snapshots` + +用途:保存节点执行时的 Pipeline 快照,避免后续配方修改影响历史报告。 + +| 字段 | 类型 | 说明 | +|---|---|---| +| `run_id` | `TEXT` | 所属检测实例 ID | +| `node_id` | `TEXT` | 所属节点 ID | +| `pipeline_name` | `TEXT` | Pipeline 名称 | +| `pipeline_definition_json` | `TEXT` | Pipeline 序列化 JSON | +| `pipeline_hash` | `TEXT` | Pipeline JSON 的 SHA-256 | + +样例数据: + +| run_id | node_id | pipeline_name | pipeline_hash | +|---|---|---|---| +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `11111111-1111-1111-1111-111111111111` | `Recipe-A` | `A1B2C3...` | +| `7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a` | `22222222-2222-2222-2222-222222222222` | `Recipe-B` | `D4E5F6...` | + +--- + +## 5. `manifest.json` 示例 + +每次 `CompleteRunAsync` 后,会在结果包目录下生成 `manifest.json`。 + +示例: + +```json +{ + "Run": { + "RunId": "7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a", + "ProgramName": "NewCncProgram", + "WorkpieceId": "QFN_1", + "SerialNumber": "SN-001", + "StartedAt": "2026-04-21T10:00:00.0000000Z", + "CompletedAt": "2026-04-21T10:00:03.2000000Z", + "OverallPass": false, + "SourceImagePath": "Results/2026/04/21/7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a/run/source.bmp", + "ResultRootPath": "Results/2026/04/21/7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a", + "NodeCount": 2 + }, + "Nodes": [ + { + "RunId": "7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a", + "NodeId": "11111111-1111-1111-1111-111111111111", + "NodeIndex": 1, + "NodeName": "检测节点1", + "PipelineName": "Recipe-A", + "PipelineVersionHash": "A1B2C3...", + "NodePass": true, + "SourceImagePath": "Results/2026/04/21/7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a/nodes/001_检测节点1/input.bmp", + "ResultImagePath": "Results/2026/04/21/7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a/nodes/001_检测节点1/result_overlay.bmp", + "Status": 0, + "DurationMs": 135 + }, + { + "RunId": "7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a", + "NodeId": "22222222-2222-2222-2222-222222222222", + "NodeIndex": 2, + "NodeName": "检测节点2", + "PipelineName": "Recipe-B", + "PipelineVersionHash": "D4E5F6...", + "NodePass": false, + "SourceImagePath": "", + "ResultImagePath": "Results/2026/04/21/7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a/nodes/002_检测节点2/result_overlay.bmp", + "Status": 1, + "DurationMs": 240 + } + ], + "Metrics": [ + { + "RunId": "7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a", + "NodeId": "11111111-1111-1111-1111-111111111111", + "MetricKey": "bridge.rate", + "MetricName": "Bridge Rate", + "MetricValue": 0.12, + "Unit": "%", + "LowerLimit": null, + "UpperLimit": 0.2, + "IsPass": true, + "DisplayOrder": 1 + }, + { + "RunId": "7d7d8d7d-1234-4567-89ab-9f0e1d2c3b4a", + "NodeId": "22222222-2222-2222-2222-222222222222", + "MetricKey": "solder.height", + "MetricName": "Solder Height", + "MetricValue": 1.7, + "Unit": "mm", + "LowerLimit": 1.8, + "UpperLimit": null, + "IsPass": false, + "DisplayOrder": 1 + } + ] +} +``` + +说明: + +- `manifest.json` 是文件侧的完整快照 +- SQLite 是主索引 +- 报告模块可以优先查库,再按需读取文件 + +--- + +## 6. 报告模块如何取数 + +### 6.1 首页列表 / 历史查询 + +建议通过: + +- `inspection_runs` +- 必要时联查 `inspection_node_results` + +可支持筛选条件: + +- 时间范围 +- 程序名 +- 工件号 +- 序列号 +- Pipeline 名称 + +### 6.2 单份报告生成 + +建议按 `RunId` 调用: + +- `GetRunDetailAsync(runId)` + +得到: + +- `Run` +- `Nodes` +- `Metrics` +- `Assets` +- `PipelineSnapshots` + +即可直接组装报告: + +- 报告首页 + - 工件号、序列号、程序名、开始/结束时间、整体判定 +- 节点章节 + - 节点名称 + - 配方名 + - 结果图 + - 关键指标值 + - 节点判定 +- 追溯信息 + - Pipeline 快照 hash + - 原图路径 + - 结果图路径 + +### 6.3 离线导出 + +若后续需要将单个检测实例导出给第三方或留档,可直接复制: + +- 整个 `Results/{yyyy}/{MM}/{dd}/{RunId}` 目录 + +这样会同时带走: + +- `manifest.json` +- 原图 +- 节点图 + +--- + +## 7. 当前实现接口 + +当前服务接口: + +- `BeginRunAsync(...)` + - 创建实例记录和结果目录 +- `AppendNodeResultAsync(...)` + - 写入节点结果、指标、图片索引、Pipeline 快照 +- `CompleteRunAsync(...)` + - 回填结束时间、整体判定,并写出 `manifest.json` +- `QueryRunsAsync(...)` + - 查询检测实例列表 +- `GetRunDetailAsync(...)` + - 查询单个实例的完整报告数据 + +当前 DI 注册: + +- `IInspectionResultStore -> InspectionResultStore` + +--- + +## 8. 设计约束与说明 + +### 8.1 为什么不直接扩展 `MeasurementDataService` + +因为原有 `MeasurementRecord` 只适合: + +- 单值统计 +- 简单的 pass/fail 汇总 + +它不适合承载: + +- 多节点 +- 多图像 +- 多指标 +- Pipeline 快照 +- 报告导出 + +所以当前设计中: + +- `MeasurementDataService` 继续保留给旧统计用途 +- `InspectionResultStore` 作为报告归档主通道 + +### 8.2 为什么图片不直接进 SQLite + +因为图片数据量大,直接入库会带来: + +- 数据库膨胀 +- 查询性能下降 +- 迁移和备份成本变高 + +因此使用: + +- SQLite 存索引 +- 文件系统存图片 + +这是更适合报告场景的折中方案。 + +### 8.3 为什么要保存 Pipeline 快照 + +因为报告要可追溯。 + +如果只保存 `PipelineName`,后续配方被修改后,历史报告就无法复原当时的真实算法链。 +因此需要保存: + +- `pipeline_definition_json` +- `pipeline_hash` + +--- + +## 9. 后续可扩展方向 + +后续可继续扩展: + +1. 增加 `manifest.json` 中的设备上下文 + - 运动位置 + - 射线源状态 + - 探测器状态 + +2. 增加中间图可选保留策略 + - 默认关闭 + - 调试模式开启 + +3. 增加结果导出包 + - ZIP 打包 + - 单份报告 PDF + +4. 增加报告模板字段映射 + - 将 `MetricKey` 映射到报告模板占位符 + +5. 增加数据清理策略 + - 保留天数 + - 自动清理旧图片 + - 保留数据库索引或同时删除 + +--- + +## 10. 结论 + +当前这套归档设计的核心特点是: + +- 以“检测实例”为主组织数据 +- 以“检测节点”为明细展开 +- 以“结构化指标 + 图片文件 + Pipeline 快照”支撑报告 +- 通过 SQLite 和文件系统混合存储兼顾查询效率和图片落盘 + +对于后续报告模块,这套结构已经可以直接支持: + +- 历史列表查询 +- 单次检测报告生成 +- 结果图展示 +- 节点级指标展示 +- 历史结果可追溯 diff --git a/XplorePlane/Views/Main/MainWindow.xaml b/XplorePlane/Views/Main/MainWindow.xaml index 33b6ec6..2e0f475 100644 --- a/XplorePlane/Views/Main/MainWindow.xaml +++ b/XplorePlane/Views/Main/MainWindow.xaml @@ -472,7 +472,7 @@ - + @@ -500,7 +500,7 @@ - + From 3f3820073fdd523f8b02de36fc378cddac05da90 Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 23 Apr 2026 16:12:55 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E9=85=8D=E6=96=B9=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=9A=84=E4=BA=A4=E4=BA=92=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XplorePlane/Models/PipelineModels.cs | 4 +- .../CncInspectionModulePipelineViewModel.cs | 61 ++++- .../IPipelineEditorHostViewModel.cs | 4 + .../PipelineEditorViewModel.cs | 40 ++- .../ImageProcessing/PipelineEditorView.xaml | 256 +++++++++++------- .../PipelineEditorView.xaml.cs | 248 +++++++++++++++-- 6 files changed, 482 insertions(+), 131 deletions(-) diff --git a/XplorePlane/Models/PipelineModels.cs b/XplorePlane/Models/PipelineModels.cs index 8b3ad26..0cf474e 100644 --- a/XplorePlane/Models/PipelineModels.cs +++ b/XplorePlane/Models/PipelineModels.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace XplorePlane.Models { - public class PipelineModel + public class PipelineModel //流程图 { public Guid Id { get; set; } = Guid.NewGuid(); public string Name { get; set; } = string.Empty; @@ -13,7 +13,7 @@ namespace XplorePlane.Models public List Nodes { get; set; } = new(); } - public class PipelineNodeModel + public class PipelineNodeModel //节点 { public Guid Id { get; set; } = Guid.NewGuid(); public string OperatorKey { get; set; } = string.Empty; diff --git a/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs b/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs index b6dc7d7..af75a44 100644 --- a/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs +++ b/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs @@ -1,4 +1,4 @@ -using Microsoft.Win32; +using Microsoft.Win32; using Prism.Commands; using Prism.Mvvm; using System; @@ -44,6 +44,8 @@ namespace XplorePlane.ViewModels.Cnc AddOperatorCommand = new DelegateCommand(AddOperator, _ => HasActiveModule); RemoveOperatorCommand = new DelegateCommand(RemoveOperator); + ReorderOperatorCommand = new DelegateCommand(ReorderOperator); + ToggleOperatorEnabledCommand = new DelegateCommand(ToggleOperatorEnabled); MoveNodeUpCommand = new DelegateCommand(MoveNodeUp); MoveNodeDownCommand = new DelegateCommand(MoveNodeDown); NewPipelineCommand = new DelegateCommand(NewPipeline); @@ -79,6 +81,10 @@ namespace XplorePlane.ViewModels.Cnc public ICommand RemoveOperatorCommand { get; } + public ICommand ReorderOperatorCommand { get; } + + public ICommand ToggleOperatorEnabledCommand { get; } + public ICommand MoveNodeUpCommand { get; } public ICommand MoveNodeDownCommand { get; } @@ -152,13 +158,10 @@ namespace XplorePlane.ViewModels.Cnc if (!HasActiveModule || node == null || !PipelineNodes.Contains(node)) return; + var removedIndex = PipelineNodes.IndexOf(node); PipelineNodes.Remove(node); RenumberNodes(); - - if (SelectedNode == node) - { - SelectedNode = PipelineNodes.LastOrDefault(); - } + SelectNeighborAfterRemoval(removedIndex); PersistActiveModule($"已移除算子:{node.DisplayName}"); } @@ -177,6 +180,26 @@ namespace XplorePlane.ViewModels.Cnc PersistActiveModule($"已上移算子:{node.DisplayName}"); } + private void ReorderOperator(PipelineReorderArgs args) + { + if (!HasActiveModule || args == null) + return; + + var oldIndex = args.OldIndex; + var newIndex = args.NewIndex; + if (oldIndex < 0 || oldIndex >= PipelineNodes.Count) + return; + + if (newIndex < 0 || newIndex >= PipelineNodes.Count || oldIndex == newIndex) + return; + + var node = PipelineNodes[oldIndex]; + PipelineNodes.Move(oldIndex, newIndex); + RenumberNodes(); + SelectedNode = node; + PersistActiveModule($"已调整算子顺序:{node.DisplayName}"); + } + private void MoveNodeDown(PipelineNodeViewModel node) { if (!HasActiveModule || node == null) @@ -191,6 +214,18 @@ namespace XplorePlane.ViewModels.Cnc PersistActiveModule($"已下移算子:{node.DisplayName}"); } + private void ToggleOperatorEnabled(PipelineNodeViewModel node) + { + if (!HasActiveModule || node == null || !PipelineNodes.Contains(node)) + return; + + node.IsEnabled = !node.IsEnabled; + SelectedNode = node; + PersistActiveModule(node.IsEnabled + ? $"已启用算子:{node.DisplayName}" + : $"已停用算子:{node.DisplayName}"); + } + private void NewPipeline() { if (!HasActiveModule) @@ -359,6 +394,20 @@ namespace XplorePlane.ViewModels.Cnc } } + private void SelectNeighborAfterRemoval(int removedIndex) + { + if (PipelineNodes.Count == 0) + { + SelectedNode = null; + return; + } + + var nextIndex = removedIndex < PipelineNodes.Count + ? removedIndex + : PipelineNodes.Count - 1; + SelectedNode = PipelineNodes[nextIndex]; + } + private void RaiseModuleVisibilityChanged() { RaisePropertyChanged(nameof(HasActiveModule)); diff --git a/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs index 6bdcc74..8460667 100644 --- a/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs @@ -15,6 +15,10 @@ namespace XplorePlane.ViewModels ICommand RemoveOperatorCommand { get; } + ICommand ReorderOperatorCommand { get; } + + ICommand ToggleOperatorEnabledCommand { get; } + ICommand MoveNodeUpCommand { get; } ICommand MoveNodeDownCommand { get; } diff --git a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs index 618f111..9730488 100644 --- a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs @@ -1,4 +1,4 @@ -using Microsoft.Win32; +using Microsoft.Win32; using Prism.Events; using Prism.Commands; using Prism.Mvvm; @@ -59,6 +59,7 @@ namespace XplorePlane.ViewModels AddOperatorCommand = new DelegateCommand(AddOperator, CanAddOperator); RemoveOperatorCommand = new DelegateCommand(RemoveOperator); ReorderOperatorCommand = new DelegateCommand(ReorderOperator); + ToggleOperatorEnabledCommand = new DelegateCommand(ToggleOperatorEnabled); ExecutePipelineCommand = new DelegateCommand(async () => await ExecutePipelineAsync(), () => !IsExecuting && SourceImage != null); CancelExecutionCommand = new DelegateCommand(CancelExecution, () => IsExecuting); NewPipelineCommand = new DelegateCommand(NewPipeline); @@ -152,6 +153,7 @@ namespace XplorePlane.ViewModels public DelegateCommand AddOperatorCommand { get; } public DelegateCommand RemoveOperatorCommand { get; } public DelegateCommand ReorderOperatorCommand { get; } + public DelegateCommand ToggleOperatorEnabledCommand { get; } public DelegateCommand ExecutePipelineCommand { get; } public DelegateCommand CancelExecutionCommand { get; } public DelegateCommand NewPipelineCommand { get; } @@ -168,6 +170,8 @@ namespace XplorePlane.ViewModels ICommand IPipelineEditorHostViewModel.AddOperatorCommand => AddOperatorCommand; ICommand IPipelineEditorHostViewModel.RemoveOperatorCommand => RemoveOperatorCommand; + ICommand IPipelineEditorHostViewModel.ReorderOperatorCommand => ReorderOperatorCommand; + ICommand IPipelineEditorHostViewModel.ToggleOperatorEnabledCommand => ToggleOperatorEnabledCommand; ICommand IPipelineEditorHostViewModel.MoveNodeUpCommand => MoveNodeUpCommand; ICommand IPipelineEditorHostViewModel.MoveNodeDownCommand => MoveNodeDownCommand; ICommand IPipelineEditorHostViewModel.NewPipelineCommand => NewPipelineCommand; @@ -217,6 +221,7 @@ namespace XplorePlane.ViewModels }; LoadNodeParameters(node); PipelineNodes.Add(node); + SelectedNode = node; _logger.Info("节点已添加到 PipelineNodes:{Key} ({DisplayName}),当前节点数={Count}", operatorKey, displayName, PipelineNodes.Count); StatusMessage = $"已添加算子:{displayName}"; @@ -227,11 +232,10 @@ namespace XplorePlane.ViewModels { if (node == null || !PipelineNodes.Contains(node)) return; + var removedIndex = PipelineNodes.IndexOf(node); PipelineNodes.Remove(node); RenumberNodes(); - - if (SelectedNode == node) - SelectedNode = null; + SelectNeighborAfterRemoval(removedIndex); StatusMessage = $"已移除算子:{node.DisplayName}"; TriggerDebouncedExecution(); @@ -271,6 +275,20 @@ namespace XplorePlane.ViewModels PipelineNodes.RemoveAt(oldIndex); PipelineNodes.Insert(newIndex, node); RenumberNodes(); + SelectedNode = node; + StatusMessage = $"已调整算子顺序:{node.DisplayName}"; + TriggerDebouncedExecution(); + } + + private void ToggleOperatorEnabled(PipelineNodeViewModel node) + { + if (node == null || !PipelineNodes.Contains(node)) return; + + node.IsEnabled = !node.IsEnabled; + SelectedNode = node; + StatusMessage = node.IsEnabled + ? $"已启用算子:{node.DisplayName}" + : $"已停用算子:{node.DisplayName}"; TriggerDebouncedExecution(); } @@ -280,6 +298,20 @@ namespace XplorePlane.ViewModels PipelineNodes[i].Order = i; } + private void SelectNeighborAfterRemoval(int removedIndex) + { + if (PipelineNodes.Count == 0) + { + SelectedNode = null; + return; + } + + var nextIndex = removedIndex < PipelineNodes.Count + ? removedIndex + : PipelineNodes.Count - 1; + SelectedNode = PipelineNodes[nextIndex]; + } + private void LoadNodeParameters(PipelineNodeViewModel node) { var paramDefs = _imageProcessingService.GetProcessorParameters(node.OperatorKey); diff --git a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml index 5f4d2f1..55dcb2c 100644 --- a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml +++ b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" d:DesignHeight="700" d:DesignWidth="350" mc:Ignorable="d"> @@ -13,13 +12,27 @@ - + + + + Microsoft YaHei UI + @@ -241,6 +251,7 @@ Text="{Binding DisplayName}" TextTrimming="CharacterEllipsis" /> + + + + @@ -261,6 +276,44 @@ + + + + + + + + + + From 5ae5963353ad642d47b51bb37c16318fdfb8d37d Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 23 Apr 2026 17:04:41 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E5=BD=93=E5=9B=A0=E4=B8=BA=E7=AE=97?= =?UTF-8?q?=E5=AD=90=E5=8F=82=E6=95=B0=E8=BE=93=E5=85=A5=E4=B8=8D=E5=90=88?= =?UTF-8?q?=E7=90=86=EF=BC=8C=E6=88=96=E8=80=85=E6=89=A7=E8=A1=8C=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=8C=E8=A6=81=E5=9C=A8=E7=8A=B6=E6=80=81=E6=A0=8F?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pipeline/PipelineExecutionService.cs | 25 ++++---- .../PipelineEditorViewModel.cs | 57 +++++++++++++++++-- .../ImageProcessing/ProcessorParameterVM.cs | 34 ++++++++++- .../ImageProcessing/PipelineEditorView.xaml | 32 +++++++++-- 4 files changed, 124 insertions(+), 24 deletions(-) diff --git a/XplorePlane/Services/Pipeline/PipelineExecutionService.cs b/XplorePlane/Services/Pipeline/PipelineExecutionService.cs index 6f5af09..648c42a 100644 --- a/XplorePlane/Services/Pipeline/PipelineExecutionService.cs +++ b/XplorePlane/Services/Pipeline/PipelineExecutionService.cs @@ -37,11 +37,10 @@ namespace XplorePlane.Services if (enabledNodes.Count == 0) return source; - // 大图像预览缩放 var current = ScaleForPreview(source); - int total = enabledNodes.Count; - for (int step = 0; step < total; step++) + var total = enabledNodes.Count; + for (var step = 0; step < total; step++) { cancellationToken.ThrowIfCancellationRequested(); @@ -53,15 +52,14 @@ namespace XplorePlane.Services if (invalidParameters.Count > 0) { + var invalidParameterText = string.Join("、", invalidParameters); throw new PipelineExecutionException( - $"算子 '{node.DisplayName}' 存在无效参数:{string.Join("、", invalidParameters)}", + $"算子 '{node.DisplayName}' 存在无效参数:{invalidParameterText}", node.Order, node.OperatorKey); } - var parameters = node.Parameters - .Where(p => p.IsValueValid) - .ToDictionary(p => p.Name, p => p.Value); + var parameters = node.Parameters.ToDictionary(p => p.Name, p => p.Value); try { @@ -69,9 +67,12 @@ namespace XplorePlane.Services current, node.OperatorKey, parameters, null, cancellationToken); if (current == null) + { throw new PipelineExecutionException( - $"算子 '{node.OperatorKey}' 返回了空图像", - node.Order, node.OperatorKey); + $"算子 '{node.DisplayName}' 返回了空图像", + node.Order, + node.OperatorKey); + } } catch (OperationCanceledException) { @@ -85,7 +86,9 @@ namespace XplorePlane.Services { throw new PipelineExecutionException( $"算子 '{node.DisplayName}' 执行失败:{ex.Message}", - node.Order, node.OperatorKey, ex); + node.Order, + node.OperatorKey, + ex); } progress?.Report(new PipelineProgress(step + 1, total, node.DisplayName)); @@ -102,7 +105,7 @@ namespace XplorePlane.Services if (source.PixelWidth <= UhdThreshold && source.PixelHeight <= UhdThreshold) return source; - double scale = (double)PreviewMaxHeight / source.PixelHeight; + var scale = (double)PreviewMaxHeight / source.PixelHeight; if (source.PixelWidth * scale > UhdThreshold) scale = (double)UhdThreshold / source.PixelWidth; diff --git a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs index f43cd33..e2aeb21 100644 --- a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs @@ -34,6 +34,7 @@ namespace XplorePlane.ViewModels private string _pipelineName = "新建流水线"; private string _selectedDevice = string.Empty; private bool _isExecuting; + private bool _isStatusError; private string _statusMessage = string.Empty; private string _currentFilePath; @@ -148,6 +149,12 @@ namespace XplorePlane.ViewModels set => SetProperty(ref _statusMessage, value); } + public bool IsStatusError + { + get => _isStatusError; + private set => SetProperty(ref _isStatusError, value); + } + // ── Commands ────────────────────────────────────────────────── public DelegateCommand AddOperatorCommand { get; } @@ -329,7 +336,12 @@ namespace XplorePlane.ViewModels vm.PropertyChanged += (_, e) => { if (e.PropertyName == nameof(ProcessorParameterVM.Value)) + { + if (TryReportInvalidParameters()) + return; + TriggerDebouncedExecution(); + } }; node.Parameters.Add(vm); } @@ -339,36 +351,39 @@ namespace XplorePlane.ViewModels { if (SourceImage == null || IsExecuting) return; + if (TryReportInvalidParameters()) + return; + _executionCts?.Cancel(); _executionCts = new CancellationTokenSource(); var token = _executionCts.Token; IsExecuting = true; - StatusMessage = "正在执行流水线..."; + SetInfoStatus("正在执行流水线..."); try { var progress = new Progress(p => - StatusMessage = $"执行中:{p.CurrentOperator} ({p.CurrentStep}/{p.TotalSteps})"); + SetInfoStatus($"执行中:{p.CurrentOperator} ({p.CurrentStep}/{p.TotalSteps})")); var result = await _executionService.ExecutePipelineAsync( PipelineNodes, SourceImage, progress, token); PreviewImage = result; - StatusMessage = "流水线执行完成"; + SetInfoStatus("流水线执行完成"); PublishPipelinePreviewUpdated(result, StatusMessage); } catch (OperationCanceledException) { - StatusMessage = "流水线执行已取消"; + SetInfoStatus("流水线执行已取消"); } catch (PipelineExecutionException ex) { - StatusMessage = $"节点 '{ex.FailedOperatorKey}' 执行失败:{ex.Message}"; + SetErrorStatus($"执行失败:{ex.Message}"); } catch (Exception ex) { - StatusMessage = $"执行错误:{ex.Message}"; + SetErrorStatus($"执行错误:{ex.Message}"); } finally { @@ -376,6 +391,36 @@ namespace XplorePlane.ViewModels } } + private bool TryReportInvalidParameters() + { + var firstInvalidNode = PipelineNodes + .Where(n => n.IsEnabled) + .OrderBy(n => n.Order) + .FirstOrDefault(n => n.Parameters.Any(p => !p.IsValueValid)); + + if (firstInvalidNode == null) + return false; + + var invalidNames = firstInvalidNode.Parameters + .Where(p => !p.IsValueValid) + .Select(p => p.DisplayName); + SetErrorStatus($"参数错误:算子 '{firstInvalidNode.DisplayName}' 的 {string.Join("、", invalidNames)} 输入不合理,请修正后重试。"); + return true; + } + + private void SetInfoStatus(string message) + { + IsStatusError = false; + StatusMessage = message; + } + + private void SetErrorStatus(string message) + { + IsStatusError = true; + StatusMessage = message; + PublishPipelinePreviewUpdated(PreviewImage ?? SourceImage, message); + } + private void LoadImage() { var dialog = new OpenFileDialog diff --git a/XplorePlane/ViewModels/ImageProcessing/ProcessorParameterVM.cs b/XplorePlane/ViewModels/ImageProcessing/ProcessorParameterVM.cs index dc807d0..019aaca 100644 --- a/XplorePlane/ViewModels/ImageProcessing/ProcessorParameterVM.cs +++ b/XplorePlane/ViewModels/ImageProcessing/ProcessorParameterVM.cs @@ -53,8 +53,40 @@ namespace XplorePlane.ViewModels set { var normalizedValue = NormalizeValue(value); - if (SetProperty(ref _value, normalizedValue)) + if (!Equals(_value, normalizedValue)) + { + _value = normalizedValue; ValidateValue(normalizedValue); + RaisePropertyChanged(nameof(Value)); + RaisePropertyChanged(nameof(BoolValue)); + RaisePropertyChanged(nameof(SelectedOption)); + } + } + } + + public bool BoolValue + { + get => ParameterType == "bool" && TryConvertToBool(_value, out var boolValue) && boolValue; + set + { + if (ParameterType == "bool") + { + Value = value; + } + } + } + + public string SelectedOption + { + get => HasOptions + ? Convert.ToString(_value, CultureInfo.InvariantCulture) ?? string.Empty + : string.Empty; + set + { + if (HasOptions) + { + Value = value; + } } } diff --git a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml index 35efed6..c54f6ad 100644 --- a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml +++ b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml @@ -285,7 +285,7 @@ FontFamily="Microsoft YaHei UI" FontSize="11" ItemsSource="{Binding Options}" - SelectedItem="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> + SelectedItem="{Binding SelectedOption, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> + + TextTrimming="CharacterEllipsis"> + + + + From 92ece60c01829486bf7294c33aa30be05381755f Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 23 Apr 2026 17:11:15 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=BB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20NavigationPanelView=20=E5=8C=BA=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- XplorePlane/Views/Main/MainWindow.xaml | 13 +++---------- XplorePlane/Views/Main/MainWindow.xaml.cs | 7 ------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/XplorePlane/Views/Main/MainWindow.xaml b/XplorePlane/Views/Main/MainWindow.xaml index 2e0f475..3a6da5b 100644 --- a/XplorePlane/Views/Main/MainWindow.xaml +++ b/XplorePlane/Views/Main/MainWindow.xaml @@ -469,21 +469,14 @@ Grid.ColumnSpan="3" Margin="0"> - - - - @@ -491,14 +484,14 @@ - + diff --git a/XplorePlane/Views/Main/MainWindow.xaml.cs b/XplorePlane/Views/Main/MainWindow.xaml.cs index a2bc49e..ba16191 100644 --- a/XplorePlane/Views/Main/MainWindow.xaml.cs +++ b/XplorePlane/Views/Main/MainWindow.xaml.cs @@ -13,12 +13,5 @@ namespace XplorePlane.Views InitializeComponent(); DataContext = viewModel; } - - private void AccountingNumberFormatButton_Click(object sender, RoutedEventArgs e) - { - bool show = NavigationPanel.Visibility != Visibility.Visible; - NavigationPanel.Visibility = show ? Visibility.Visible : Visibility.Collapsed; - NavColumn.Width = show ? new GridLength(180) : new GridLength(0); - } } } From 24e0489cdee1b47aad70c2427b10a72aea4447ff Mon Sep 17 00:00:00 2001 From: "zhengxuan.zhang" Date: Thu, 23 Apr 2026 17:29:25 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E6=98=BE=E7=A4=BAxmp=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=EF=BC=9B=E5=8F=96=E6=B6=88=E5=AE=9E=E6=97=B6=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E5=BA=95=E9=83=A8=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CncInspectionModulePipelineViewModel.cs | 31 +++++++++++++++++++ .../IPipelineEditorHostViewModel.cs | 4 +++ .../PipelineEditorViewModel.cs | 18 +++++++++++ .../ImageProcessing/PipelineEditorView.xaml | 28 +++++++++++++++-- .../Main/NavigationPropertyPanelView.xaml | 11 ++++--- XplorePlane/Views/Main/ViewportPanelView.xaml | 6 +--- 6 files changed, 86 insertions(+), 12 deletions(-) diff --git a/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs b/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs index 879bbb4..d119c0c 100644 --- a/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs +++ b/XplorePlane/ViewModels/Cnc/CncInspectionModulePipelineViewModel.cs @@ -26,6 +26,7 @@ namespace XplorePlane.ViewModels.Cnc private CncNodeViewModel _activeModuleNode; private PipelineNodeViewModel _selectedNode; private string _statusMessage = "请选择检测模块以编辑其流水线。"; + private string _pipelineFileDisplayName = "未命名模块.xpm"; private string _currentFilePath; private bool _isSynchronizing; @@ -71,6 +72,14 @@ namespace XplorePlane.ViewModels.Cnc private set => SetProperty(ref _statusMessage, value); } + public bool IsStatusError => false; + + public string PipelineFileDisplayName + { + get => _pipelineFileDisplayName; + private set => SetProperty(ref _pipelineFileDisplayName, value); + } + public bool HasActiveModule => _activeModuleNode?.IsInspectionModule == true; public Visibility EditorVisibility => HasActiveModule ? Visibility.Visible : Visibility.Collapsed; @@ -113,6 +122,7 @@ namespace XplorePlane.ViewModels.Cnc _activeModuleNode = null; PipelineNodes.Clear(); SelectedNode = null; + PipelineFileDisplayName = "未命名模块.xpm"; StatusMessage = "请选择检测模块以编辑其流水线。"; RaiseModuleVisibilityChanged(); RaiseCommandCanExecuteChanged(); @@ -120,6 +130,7 @@ namespace XplorePlane.ViewModels.Cnc } _activeModuleNode = selected; + _currentFilePath = null; LoadPipelineModel(_activeModuleNode.Pipeline ?? new PipelineModel { Name = _activeModuleNode.Name @@ -234,6 +245,7 @@ namespace XplorePlane.ViewModels.Cnc PipelineNodes.Clear(); SelectedNode = null; _currentFilePath = null; + PipelineFileDisplayName = GetActivePipelineFileDisplayName(); PersistActiveModule("已为当前检测模块新建空流水线。"); } @@ -264,6 +276,7 @@ namespace XplorePlane.ViewModels.Cnc var model = BuildPipelineModel(); await _persistenceService.SaveAsync(model, dialog.FileName); _currentFilePath = dialog.FileName; + PipelineFileDisplayName = FormatPipelinePath(dialog.FileName); StatusMessage = $"已导出模块流水线:{Path.GetFileName(dialog.FileName)}"; } @@ -283,6 +296,7 @@ namespace XplorePlane.ViewModels.Cnc var model = await _persistenceService.LoadAsync(dialog.FileName); _currentFilePath = dialog.FileName; + PipelineFileDisplayName = FormatPipelinePath(dialog.FileName); LoadPipelineModel(model); PersistActiveModule($"已加载模块流水线:{model.Name}"); } @@ -314,6 +328,8 @@ namespace XplorePlane.ViewModels.Cnc } SelectedNode = PipelineNodes.FirstOrDefault(); + if (string.IsNullOrEmpty(_currentFilePath)) + PipelineFileDisplayName = GetActivePipelineFileDisplayName(); StatusMessage = HasActiveModule ? $"正在编辑检测模块:{_activeModuleNode.Name}" : "请选择检测模块以编辑其流水线。"; @@ -389,6 +405,21 @@ namespace XplorePlane.ViewModels.Cnc : _activeModuleNode.Pipeline.Name; } + private string GetActivePipelineFileDisplayName() + { + var pipelineName = GetActivePipelineName(); + return pipelineName.EndsWith(".xpm", StringComparison.OrdinalIgnoreCase) + ? pipelineName + : $"{pipelineName}.xpm"; + } + + private static string FormatPipelinePath(string filePath) + { + return string.IsNullOrWhiteSpace(filePath) + ? "未命名模块.xpm" + : Path.GetFullPath(filePath).Replace('\\', '/'); + } + private void RenumberNodes() { for (var i = 0; i < PipelineNodes.Count; i++) diff --git a/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs index 8460667..9883ca8 100644 --- a/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/IPipelineEditorHostViewModel.cs @@ -11,6 +11,10 @@ namespace XplorePlane.ViewModels string StatusMessage { get; } + bool IsStatusError { get; } + + string PipelineFileDisplayName { get; } + ICommand AddOperatorCommand { get; } ICommand RemoveOperatorCommand { get; } diff --git a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs index e2aeb21..517e231 100644 --- a/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs +++ b/XplorePlane/ViewModels/ImageProcessing/PipelineEditorViewModel.cs @@ -21,6 +21,7 @@ namespace XplorePlane.ViewModels { private const int MaxPipelineLength = 20; private const int DebounceDelayMs = 300; + private const string DefaultPipelineFileDisplayName = "未命名模块.xpm"; private readonly IImageProcessingService _imageProcessingService; private readonly IPipelineExecutionService _executionService; @@ -36,6 +37,7 @@ namespace XplorePlane.ViewModels private bool _isExecuting; private bool _isStatusError; private string _statusMessage = string.Empty; + private string _pipelineFileDisplayName = DefaultPipelineFileDisplayName; private string _currentFilePath; private CancellationTokenSource _executionCts; @@ -155,6 +157,12 @@ namespace XplorePlane.ViewModels private set => SetProperty(ref _isStatusError, value); } + public string PipelineFileDisplayName + { + get => _pipelineFileDisplayName; + private set => SetProperty(ref _pipelineFileDisplayName, value); + } + // ── Commands ────────────────────────────────────────────────── public DelegateCommand AddOperatorCommand { get; } @@ -526,6 +534,7 @@ namespace XplorePlane.ViewModels PipelineName = "新建流水线"; PreviewImage = null; _currentFilePath = null; + PipelineFileDisplayName = DefaultPipelineFileDisplayName; StatusMessage = "已新建流水线"; } @@ -576,6 +585,7 @@ namespace XplorePlane.ViewModels { var model = BuildPipelineModel(); await _persistenceService.SaveAsync(model, filePath); + PipelineFileDisplayName = FormatPipelinePath(filePath); StatusMessage = $"流水线已保存:{Path.GetFileName(filePath)}"; } catch (IOException ex) @@ -624,6 +634,7 @@ namespace XplorePlane.ViewModels PipelineName = model.Name; SelectedDevice = model.DeviceId; _currentFilePath = dialog.FileName; + PipelineFileDisplayName = FormatPipelinePath(dialog.FileName); foreach (var nodeModel in model.Nodes) { @@ -702,5 +713,12 @@ namespace XplorePlane.ViewModels Directory.CreateDirectory(dir); return dir; } + + private static string FormatPipelinePath(string filePath) + { + return string.IsNullOrWhiteSpace(filePath) + ? DefaultPipelineFileDisplayName + : Path.GetFullPath(filePath).Replace('\\', '/'); + } } } diff --git a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml index c54f6ad..151340d 100644 --- a/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml +++ b/XplorePlane/Views/ImageProcessing/PipelineEditorView.xaml @@ -68,7 +68,14 @@ Background="#F5F5F5" BorderBrush="{StaticResource PanelBorder}" BorderThickness="0,1,0,1"> - + + + + + +