基线:全量源码首提(D1 版本控制落地,含第一轮优化 B1-B4/A1/A4/缩放修复)
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
// ============================================================
|
||||
// PdfBridge:报价插件(Form3)与 PDF 查看器之间的桥
|
||||
// 与 cadbt 的 CadBridge 保持相同的 API 形状:
|
||||
// · 下行(Form3→查看器):SendPaCommand / ZoomToFrameHandle /
|
||||
// DeleteFramesByHandles / MergeMasks / ClearHighlight
|
||||
// · 上行(查看器→Form3):PaPicked / EntityErased / PaExited /
|
||||
// F1/F2/F3Requested
|
||||
// 扒图逻辑:用户在 PDF 上框选 → 裁剪 → OCR 工作进程识别 →
|
||||
// 按 CAD 版语义组装 results(正向逐条/反向合并) → PaPicked
|
||||
// → Form3 入表格;查看器在框选位置画彩色蒙版框。
|
||||
// ============================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace pdfbt
|
||||
{
|
||||
public static class PdfBridge
|
||||
{
|
||||
private static PdfViewerWindow _viewer;
|
||||
|
||||
/// <summary>PDF 查看器是否已挂载且打开了文档。</summary>
|
||||
public static bool IsViewerReady
|
||||
{
|
||||
get { return _viewer != null && _viewer.IsDocumentOpen; }
|
||||
}
|
||||
|
||||
/// <summary>扒图连续模式当前是否激活(供 ESC 全局过滤判断)。</summary>
|
||||
public static bool PickModeActive
|
||||
{
|
||||
get { return _viewer != null && _viewer.PickModeActive; }
|
||||
}
|
||||
|
||||
/// <summary>兼容 CadBridge:查看器中蒙版被外部删除(当前无触发源,保留事件形状)。</summary>
|
||||
public static event Action<string> EntityErased;
|
||||
|
||||
/// <summary>框选识别完成一批(图号/箱号/元件)。</summary>
|
||||
public static event Action<MyApp.PaMode, List<MyApp.PaTextResult>> PaPicked;
|
||||
|
||||
/// <summary>用户按 ESC 退出连续扒图模式。</summary>
|
||||
public static event Action PaExited;
|
||||
|
||||
/// <summary>用户按 F1 —— 元件两两合并。</summary>
|
||||
public static event Action F1Requested;
|
||||
|
||||
/// <summary>用户按 F2 —— 元件三个一组合并。</summary>
|
||||
public static event Action F2Requested;
|
||||
|
||||
/// <summary>用户按 F3 —— 元件四个一组合并。</summary>
|
||||
public static event Action F3Requested;
|
||||
|
||||
/// <summary>把 PDF 查看器挂到桥上(查看器构造时调用一次)。</summary>
|
||||
public static void Attach(PdfViewerWindow viewer)
|
||||
{
|
||||
_viewer = viewer;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// 查看器 → Form3 的上行事件触发(仅查看器调用)
|
||||
// ------------------------------------------------------------
|
||||
|
||||
public static void RaisePaPicked(MyApp.PaMode mode, List<MyApp.PaTextResult> results)
|
||||
{
|
||||
if (PaPicked != null) PaPicked(mode, results);
|
||||
}
|
||||
|
||||
public static void RaisePaExited()
|
||||
{
|
||||
if (PaExited != null) PaExited();
|
||||
}
|
||||
|
||||
public static void RaiseEntityErased(string handle)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(handle) && EntityErased != null)
|
||||
EntityErased(handle);
|
||||
}
|
||||
|
||||
public static void RaiseF1() { if (F1Requested != null) F1Requested(); }
|
||||
public static void RaiseF2() { if (F2Requested != null) F2Requested(); }
|
||||
public static void RaiseF3() { if (F3Requested != null) F3Requested(); }
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// Form3 → 查看器的下行命令
|
||||
// ------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// 发送扒图命令。接受原 CAD 命令名(CADPATU/CADPAXH/CADPAYJ/CADPACL)
|
||||
/// 或网页命令名(patu/paxh/payj/pacl)。
|
||||
/// </summary>
|
||||
public static void SendPaCommand(string cmd)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cmd)) return;
|
||||
string c = cmd.Trim().ToUpperInvariant();
|
||||
int mode = 0;
|
||||
if (c == "CADPATU" || c == "PATU") mode = 0;
|
||||
else if (c == "CADPAXH" || c == "PAXH") mode = 1;
|
||||
else if (c == "CADPAYJ" || c == "PAYJ") mode = 2;
|
||||
else if (c == "CADPACL" || c == "PACL")
|
||||
{
|
||||
ClearHighlight();
|
||||
return;
|
||||
}
|
||||
else return;
|
||||
|
||||
if (_viewer == null) return;
|
||||
_viewer.StartPick(mode);
|
||||
}
|
||||
|
||||
/// <summary>定位到指定 Handle 的蒙版框(点击表格行定位)。</summary>
|
||||
public static void ZoomToFrameHandle(string handle)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(handle) || _viewer == null) return;
|
||||
_viewer.ZoomToFrame(handle);
|
||||
}
|
||||
|
||||
/// <summary>批量删除指定 Handle 的蒙版(删表格行联动删框)。</summary>
|
||||
public static void DeleteFramesByHandles(IEnumerable<string> handles)
|
||||
{
|
||||
if (handles == null || _viewer == null) return;
|
||||
var list = new List<string>();
|
||||
foreach (string h in handles)
|
||||
if (!string.IsNullOrWhiteSpace(h)) list.Add(h);
|
||||
if (list.Count == 0) return;
|
||||
_viewer.DeleteFrames(list);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并蒙版:保留 keep 的蒙版并扩大到所有 removes 蒙版的并集,
|
||||
/// 被合并行的蒙版移除(元件合并时蒙版同步合并)。
|
||||
/// </summary>
|
||||
public static void MergeMasks(string keep, IEnumerable<string> removes)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(keep) || _viewer == null) return;
|
||||
var list = new List<string>();
|
||||
if (removes != null)
|
||||
foreach (string h in removes)
|
||||
if (!string.IsNullOrWhiteSpace(h) && h != keep) list.Add(h);
|
||||
if (list.Count == 0) return;
|
||||
_viewer.MergeMasks(keep, list);
|
||||
}
|
||||
|
||||
/// <summary>清除所有高亮。</summary>
|
||||
public static void ClearHighlight()
|
||||
{
|
||||
if (_viewer == null) return;
|
||||
_viewer.ClearHighlight();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user