commit a7cf1e3c26fd4d45448e289facf0acc73913aaad Author: admin Date: Thu Sep 17 23:00:08 2026 +0800 docs: 时序图设计器设计文档与双视图 2K 示例图 - docs/DESIGN.md: 需求、技术选型(Flutter + CustomPainter)、数据模型、圆周/条形布局算法、SVG 导出、里程碑与风险 - demo: 圆周节拍(同心圆·12点钟起始)与条形节拍(甘特+依赖箭头)2K 示例图(SVG 源 + PNG) - tools/demo-gen.mjs: 示例图生成脚本 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b0ab185 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Flutter / Dart +.dart_tool/ +.packages +.pub-cache/ +.pub/ +build/ +.flutter-plugins +.flutter-plugins-dependencies +*.iml +.idea/ +.vscode/ +*.lock + +# Node +node_modules/ + +# OS +Thumbs.db +desktop.ini +.DS_Store + +# 临时/导出 +*.tmp +*.bak +/out/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..271024b --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# 时序图设计器 · Sequence Diagram Studio + +面向 **PLC 流程节拍设计 / 相位角设计** 的桌面设计软件(Flutter Desktop)。 + +- **两种视图,一份数据**:条形节拍(甘特 / 流程图 + 依赖箭头) ⇄ 圆周节拍(同心圆相位图,12 点钟起始,一圈 = 一个循环,每新增一个动作在最外层加一层) +- **响应快**:自研 Canvas 渲染,双层缓存 + 脏区重绘 + 空间索引,1000 动作仍保持 60 fps +- **导出 SVG**:矢量、分层、带语义 `id` / `data-*` 元数据,可直接进工艺卡与 MES + +## 设计预览(2560 × 1440) + +| 圆周节拍视图 | 条形节拍视图 | +| --- | --- | +| ![圆周节拍](demo/circular-timing.png) | ![条形节拍](demo/bar-timing.png) | + +## 目录 + +| 路径 | 说明 | +| --- | --- | +| [`docs/DESIGN.md`](docs/DESIGN.md) | 完整设计文档:需求、技术选型、数据模型、布局算法、SVG 导出、里程碑、风险 | +| `demo/*.svg` | 设计示例图源文件(矢量,可直接编辑) | +| `demo/*.png` | 2K(2560×1440)预览图 | +| `tools/demo-gen.mjs` | 示例图生成脚本(Node,输出 SVG) | + +## 重新生成示例图 + +```bash +node tools/demo-gen.mjs +``` + +生成 `demo/circular-timing.svg` 与 `demo/bar-timing.svg`;用任意浏览器/Inkscape 可导出 2K PNG。 + +## 技术栈 + +Flutter 3.29+(Desktop) · CustomPainter 自绘 · Riverpod · 不可变模型 + Command 撤销栈 · 纯 Dart 几何算法 · 自研 SVG 序列化器 · JSON(`.seq.json`)持久化 + +## 路线图 + +- [ ] M1 数据模型 + JSON 存取 + 条形视图(渲染 / 缩放 / 平移) +- [ ] M2 圆周视图 + 双视图切换动画 + 拖拽吸附 + 属性面板 + 撤销重做 +- [ ] M3 SVG / PNG 导出 + 依赖编辑 + 关键路径与统计 + Golden 测试 +- [ ] M4 PLC 点位对接(OPC UA / 三菱 MC / Modbus)+ 工艺卡 PDF + 自动节拍优化 diff --git a/demo/bar-timing.png b/demo/bar-timing.png new file mode 100644 index 0000000..96061e3 Binary files /dev/null and b/demo/bar-timing.png differ diff --git a/demo/bar-timing.svg b/demo/bar-timing.svg new file mode 100644 index 0000000..d794b22 --- /dev/null +++ b/demo/bar-timing.svg @@ -0,0 +1 @@ +条形节拍视图(甘特 / 流程图 · 依赖箭头)时间轴与相位角双刻度联动;箭头表示动作间关联(FS 完成-启动 / SS 起始-起始);跨循环动作自动拆分并标注上料相位夹紧相位加工相位检测相位下料相位0°060°400120°800180°1200240°1600300°2000360°2400ms相位角循环开始 0° / 0 ms循环结束 360° / 2400 ms1A1 上料ST1 · 气缸 Y12A2 定位夹紧ST1 · 夹爪 M13A3 伺服下压ST2 · 伺服 Z 轴4A4 超声波焊接ST2 · 超声发生器5A5 保压冷却ST2 · 延时 T16A6 视觉检测ST3 · 相机 CAM17A7 分选下料ST3 · 气缸 Y28A8 清洁吹气ST3 · 电磁阀 V3上料467 msΔ70°定位夹紧400 msΔ60°伺服下压567 msΔ85°超声波焊接633 msΔ95°保压冷却300 msΔ45°视觉检测300 msΔ45°分选下料 167msΔ25°↩ 跨循环延续 25°清洁吹气 300msΔ45°SS +55°FSFSFSFSSS +35°SS +5°节拍统计循环周期2400 ms / 360°动作数量8(3 工位)关键路径A1 → A2 → A3 → A4 → A6 → A7最大并行度3 个动作同时执行(185°–190°)相位覆盖率100%(0°–360° 无空档 > 15°)瓶颈工位ST2 加工相位 105°–320°(215°)预估节拍2.400 s / 件 · 1500 件/小时圆周节拍预览(实时联动)360°1 循环 = 2400 ms12 点钟起始 · 顺时针 · 每层一环项目装装配线节拍设计装配线节拍.seq.json · v1.2循环 2.400 s = 360°动作 8 · 依赖 7动作 / 工位泳道1上料A1 · ST1 · 气缸 Y10° – 70°467 ms2定位夹紧A2 · ST1 · 夹爪 M155° – 115°400 ms3伺服下压A3 · ST2 · 伺服 Z 轴105° – 190°567 ms4超声波焊接A4 · ST2 · 超声发生器185° – 280°633 ms5保压冷却A5 · ST2 · 延时 T1275° – 320°300 ms6视觉检测A6 · ST3 · 相机 CAM1300° – 345°300 ms7分选下料A7 · ST3 · 气缸 Y2335° – 360°167 ms8清洁吹气A8 · ST3 · 电磁阀 V3340° – 360°300 ms视图模式条形节拍(甘特)圆周节拍(同心)显示选项时间轴 / 相位双刻度依赖箭头 FS / SS跨循环片段标记相位分区色带工位负载 / 相位占用ST1 上料 · 夹紧115° · 31.9%ST2 压装 · 焊接215° · 59.7%ST3 检测 · 下料85° · 23.6%操作提示拖拽动作块平移相位 · 拖端点改持续角Ctrl+滚轮缩放 · 双击空白新建动作关键路径A1 → A2 → A3 → A4 → A6 → A7累计 2400 ms(占满整圈,无空档)属性 · 选中动作A8清洁吹气ST3 · 电磁阀 V3 · 跨循环跨圈开始时刻2267 ms340.0°结束时刻2567 ms385.0° → 25.0°持续时间300 ms45.0°循环归属当前圈 + 下一圈跨圈片段依赖A7 → SS +5°起始-起始相位归属下料相位335°–360°/0°–25°时间 / 角度联动1° = 6.667 ms角度与时间线性映射,双向同步依赖关系(7)上料 → 定位夹紧SS +55°定位夹紧 → 伺服下压FS伺服下压 → 超声波焊接FS超声波焊接 → 保压冷却FS超声波焊接 → 视觉检测FS视觉检测 → 分选下料SS +35°分选下料 → 清洁吹气SS +5°导出SVG(矢量 · 可编辑 · 打印级)PNG / PDF / 工艺卡时序图设计器Sequence Diagram Studio新建打开保存撤销 ↶重做 ↷条形节拍圆周节拍导出 SVG导出 PNG− 100% +适应窗口文件: 装配线节拍.seq.json循环周期 2400 ms相位 360°动作 8依赖 7工位 3时间轴 0–2400 ms吸附 5°就绪● 已保存 \ No newline at end of file diff --git a/demo/circular-timing.png b/demo/circular-timing.png new file mode 100644 index 0000000..9aa98b6 Binary files /dev/null and b/demo/circular-timing.png differ diff --git a/demo/circular-timing.svg b/demo/circular-timing.svg new file mode 100644 index 0000000..8cf585b --- /dev/null +++ b/demo/circular-timing.svg @@ -0,0 +1 @@ +圆周节拍视图(同心圆 · 12 点钟起始 · 顺时针)每增加一个动作,在最外层新增一圈;每圈设置起始角与持续角,1 圈 = 1 循环 = 2400 ms0°30°60°90°120°150°180°210°240°270°300°330°A1 上料0°–70°A2 定位夹紧55°–115°A3 伺服下压105°–190°A4 超声波焊接185°–280°A5 保压冷却275°–320°A6 视觉检测300°–345°A7 分选下料335°–360°A8 清洁吹气340°–360°0° 起点 · 12 点钟方向顺时针 CW图层 / 相位图例A1 上料L1 · r=100 · 0°–70° · 467 msA2 定位夹紧L2 · r=150 · 55°–115° · 400 msA3 伺服下压L3 · r=200 · 105°–190° · 567 msA4 超声波焊接L4 · r=250 · 185°–280° · 633 msA5 保压冷却L5 · r=300 · 275°–320° · 300 msA6 视觉检测L6 · r=350 · 300°–345° · 300 msA7 分选下料L7 · r=400 · 335°–360° · 167 msA8 清洁吹气L8 · r=450 · 340°–360° · 300 ms选中动作A3 伺服下压起始角 105.0°结束角 190.0°持续角 85.0°Δ = 567 ms · 层 L3 · ST2条形节拍预览(实时联动)0 ms1200 ms2400 ms项目装装配线节拍设计装配线节拍.seq.json · v1.2循环 2.400 s = 360°动作 8 · 依赖 7动作列表(按层 L1→L8)1上料A1 · ST1 · 气缸 Y1L1 r=100467 ms2定位夹紧A2 · ST1 · 夹爪 M1L2 r=150400 ms3伺服下压A3 · ST2 · 伺服 Z 轴L3 r=200567 ms4超声波焊接A4 · ST2 · 超声发生器L4 r=250633 ms5保压冷却A5 · ST2 · 延时 T1L5 r=300300 ms6视觉检测A6 · ST3 · 相机 CAM1L6 r=350300 ms7分选下料A7 · ST3 · 气缸 Y2L7 r=400167 ms8清洁吹气A8 · ST3 · 电磁阀 V3L8 r=450300 ms视图模式条形节拍(甘特)圆周节拍(同心)显示选项相位角刻度环依赖连线层半径标注跨循环高亮工位负载 / 相位占用ST1 上料 · 夹紧115° · 31.9%ST2 压装 · 焊接215° · 59.7%ST3 检测 · 下料85° · 23.6%操作提示拖拽动作块平移相位 · 拖端点改持续角Ctrl+滚轮缩放 · 双击空白新建动作关键路径A1 → A2 → A3 → A4 → A6 → A7累计 2400 ms(占满整圈,无空档)属性 · 选中动作A3伺服下压ST2 · 伺服 Z 轴 · 层 L3选中起始角105.0°12 点钟起顺时针结束角190.0°持续角85.0°= 567 ms所在层L3半径 200 px依赖A2 → FS完成-启动相位归属加工相位105°–190°角度编辑起始角105°持续角85°层级操作新增外层 L9重排 / 合并层规则新增动作默认置于最外层同心圆,角度可吸附到 1°,自动检测相位重叠。依赖连线A2 定位夹紧→ A3 完成-启动 FSA3 伺服下压→ A4 完成-启动 FSA3 伺服下压→ A6 起始-起始 SS +195°时序图设计器Sequence Diagram Studio新建打开保存撤销 ↶重做 ↷条形节拍圆周节拍导出 SVG导出 PNG− 100% +适应窗口文件: 装配线节拍.seq.json循环周期 2400 ms相位 360°动作 8层数 L1–L8同心圆 8半径步距 50 px吸附 1°就绪● 已保存 \ No newline at end of file diff --git a/docs/DESIGN.md b/docs/DESIGN.md new file mode 100644 index 0000000..e7b9382 --- /dev/null +++ b/docs/DESIGN.md @@ -0,0 +1,411 @@ +# 时序图设计器(Sequence Diagram Studio)设计文档 + +> PLC 流程节拍设计 / 相位角设计软件 +> 版本 v0.1(设计草案) · 2026-09-17 +> 目标平台:Windows / macOS / Linux 桌面(Flutter Desktop),可扩展平板与车间 HMI 面板 + +--- + +## 1. 项目背景与目标 + +PLC 产线的节拍(Cycle Time)与相位角(Phase Angle)设计目前多依赖 Excel + 手绘甘特图, +存在三个痛点: + +1. **相位关系不直观**:一圈 360° 代表一个循环,各动作的角度重叠/空档难以一眼看出; +2. **修改后联动差**:改一个动作的角度,下游动作的依赖关系需要手工重算; +3. **交付物不可编辑**:导出的图片无法被工艺卡、CAD、MES 复用。 + +本软件要解决的问题: + +| 目标 | 指标 | +| --- | --- | +| 响应快 | 拖拽 60 fps(1000 动作规模),打开项目 < 300 ms | +| 两种视图 | 条形节拍(甘特/流程图)+ 圆周节拍(同心圆相位图),**同一份数据**可随时互切 | +| 相位角设计 | 12 点钟为 0° 起点、顺时针为正、1 圈 = 1 循环;每新增一个动作在**最外层**加一层同心圆 | +| 导出 | SVG(矢量、可编辑、分层、带元数据),另附 PNG / PDF / 工艺卡 | +| 可验证 | 动作依赖(FS/SS/FF/SF)、关键路径、瓶颈工位、相位覆盖率自动统计 | + +--- + +## 2. 术语定义 + +| 术语 | 含义 | +| --- | --- | +| 循环 Cycle | 一个完整的生产节拍,对应 360° 与 `cycleMs` 毫秒,二者线性等价 | +| 相位角 Phase Angle | 动作在循环中的位置,0° 位于 12 点钟方向,顺时针递增 | +| 动作 Action | 一个可执行的 PLC 动作(气缸、伺服、延时、检测…),占用一段角度区间 `[start, start+duration]` | +| 层 Layer | 圆周视图中的一个同心圆;**每新增一个动作默认落在最外层** | +| 依赖 Dependency | 动作之间的时序约束:FS(完成-启动)/ SS(起始-起始)/ FF / SF | +| 跨循环 Wrap | `start + duration > 360°` 的动作,跨越循环边界,显示时拆成两段 | +| 工位 Station | 动作所属的机械单元,条形视图中作为泳道分组 | + +--- + +## 3. 功能需求 + +### 3.1 视图 + +**A. 圆周节拍视图(同心圆)** + +- 圆心为基准,12 点钟方向为 0°,顺时针为正方向,一圈 = 一个循环; +- 每个动作渲染为一条圆弧,弧长 = 持续角,半径 = `R0 + layer × pitch`; +- **新增动作默认置于最外层**(符合"每增加一个动作就在外层加一层"的直觉); +- 支持手动改层、层重排、层合并、层显隐; +- 外圈相位角刻度环(5° 小刻度 / 30° 主刻度)、依赖连线、跨循环高亮; +- 半径自适应:层数过多时自动压缩 `pitch` 或切换"双环/分页"模式。 + +**B. 条形节拍视图(甘特 + 流程图)** + +- 双刻度轴:上轴时间 `ms`,下轴相位角 `°`,两者实时联动; +- 泳道按工位分组,行内重叠动作自动拆子行; +- 依赖箭头:FS/SS/FF/SF 四种类型,正交折线路由 + 通道避让 + 类型标签; +- 关键路径高亮、跨循环片段拆分标记(`↩ 跨循环延续`); +- 相位分区色带(上料/夹紧/加工/检测/下料…)。 + +**C. 双向切换** + +- 顶部 Segmented Control 一键切换,两视图共享同一 Model; +- 切换时对每个动作的几何做 300–400 ms 插值动画(矩形 ↔ 圆弧),角度/层号/依赖保持不变; +- 每个视图角落提供另一视图的实时缩略预览(Mini Map)。 + +### 3.2 编辑 + +- 拖拽动作块整体平移相位(改 `start`);拖两端手柄改 `duration`; +- 角度吸附:1° / 5° / 15° 可配,并磁吸到其他动作端点(±2° 内); +- 依赖编辑:从动作端点拖出连线到目标动作,自动判定 FS/SS 并生成 offset; +- 属性面板双向绑定(输入 `105` 立刻生效),支持角度 ↔ 时间单位切换显示; +- 撤销 / 重做(无限级),多选、框选、对齐、等距分布; +- 相位游标:一条可拖动的"当前角度"游标,两视图同步高亮; +- 冲突校验:同层重叠、依赖成环、超出 360° 未标跨循环、空档 > 阈值 —— 实时波浪线/角标提示。 + +### 3.3 统计与导出 + +- 节拍统计:循环周期、动作数、关键路径、最大并行度、相位覆盖率、瓶颈工位、预估产能; +- 导出 SVG:分层、带 `id` 与 `data-*` 元数据、真实 ``、可选 mm 单位(打印级); +- 导出 PNG(1x/2x/4x)、PDF、工艺卡(表格 + 相位图); +- 导出在 Isolate 中执行,不阻塞 UI。 + +--- + +## 4. 技术选型 + +### 4.1 结论 + +| 层 | 选型 | 理由 | +| --- | --- | --- | +| UI 框架 | **Flutter 3.29+(Desktop,Windows 优先)** | 声明式 UI 迭代快;Skia/Impeller GPU 直绘,自绘图形性能优于 Web Canvas;一套代码可延伸到车间平板/触屏 HMI | +| 画布渲染 | **自研 `CustomPainter`**(不引入图形库) | 时序图的图元是"圆弧/矩形/折线/文字",自绘可精确控制分层缓存与命中测试,避免第三方图库的抽象开销 | +| 状态管理 | **Riverpod 2.x + 不可变模型** | 细粒度依赖,拖动时只重建受影响部件;`select` 精准订阅 | +| 撤销重做 | **Command 模式** | 每个编辑动作 = 一个 `Command{do, undo}`,天然支持宏与协作 | +| 几何算法 | **纯 Dart**(角度/极坐标/区间/拓扑排序) | 零依赖、可单测;必要时 `Isolate` 并行 | +| 可选算力 | `flutter_rust_bridge` + Rust(M3 评估) | 仅在需要约束求解 / 万级图元 / 自动节拍优化时引入,非首选 | +| 持久化 | **JSON(`.seq.json`)+ schema 版本号** | 可 diff、可版本管理、可被 MES 读取;大项目可换 SQLite(drift) | +| SVG 导出 | **自研 SVG 序列化器** | `flutter_svg` 是渲染库不是生成库;自研才能产出"分层 + 语义 id + 可编辑"的工艺级 SVG | +| 测试 | 单元测试(角度换算/布局/校验)+ **Golden 测试**(同数据渲染截图比对) | 保证"屏幕所见 = 导出所得" | + +### 4.2 为什么不用 Web / 其他方案 + +- **Web(Canvas/SVG DOM)**:万级图元时 DOM 卡顿;车间离线环境、串口/OPC UA 对接困难; +- **Electron**:包体与内存开销大,触屏拖拽手感差; +- **Qt/C#**:开发效率与 UI 现代化程度不及 Flutter,且团队协作成本高; +- **纯 SVG 编辑器(Inkscape 二次开发)**:无法承载"数据模型 + 依赖求解 + 统计"的语义层。 + +### 4.3 性能设计("响应快"的具体做法) + +1. **双层画布**:`staticLayer`(网格、刻度、已完成图元)缓存为 `ui.Picture`,`dynamicLayer`(拖拽中/悬停/游标)每帧重绘;两层用 `RepaintBoundary` 隔离; +2. **脏区重绘**:拖动一个动作时只重绘该动作包围盒 + 依赖线,`canvas.clipRect` 限定; +3. **视图变换走矩阵**:缩放/平移只改 `Matrix4`,不重建 Widget 树; +4. **空间索引**:命中测试用均匀网格(Uniform Grid),1000 动作 O(1) 命中; +5. **增量布局**:改一个动作只重算其所在层/泳道的布局,依赖线只重算受影响的边; +6. **Isolate**:SVG/PNG 导出、自动布局、关键路径计算放后台 Isolate; +7. **文字度量缓存**:`TextPainter` 结果按 `(text, style)` 缓存,Canvas 与 SVG 共用同一度量,保证一致性。 + +--- + +## 5. 数据模型 + +### 5.1 领域模型(UML) + +```mermaid +classDiagram + class Project { + +String name + +String schemaVersion + +Cycle cycle + +List~Station~ stations + +List~Action~ actions + +ViewState viewState + } + class Cycle { + +double durationMs + +AngleUnit unit + +double startAngle + +Direction direction + +Origin origin + +int snapDeg + } + class Station { + +String id + +String name + +int order + +Color color + } + class Action { + +String id + +String name + +String stationId + +double startAngle + +double durationAngle + +int layer + +Color color + +String driver + +List~Dependency~ deps + +bool wrap + } + class Dependency { + +String fromId + +String toId + +DepType type + +double offsetAngle + } + class ViewState { + +ViewMode mode + +double zoom + +Offset pan + +bool showDeps + +bool showRuler + } + Project "1" *-- "1" Cycle + Project "1" *-- "*" Station + Project "1" *-- "*" Action + Action "1" *-- "*" Dependency + Project "1" *-- "1" ViewState +``` + +### 5.2 关键决策:角度与时间是同一维度的两种单位 + +``` +angle(deg) = ms / cycleMs × 360 ms = angle / 360 × cycleMs +``` + +- 模型**只持久化角度**(相位角设计是本软件的核心语义),时间由 `cycleMs` 实时换算; +- 修改 `cycleMs` 时,可选择"保持角度"(动作角度不变,实际时间整体缩放)或"保持时间"(反算新角度)——默认前者; +- 这样两视图切换只是**换一个 Layout 投影**,不产生任何数据转换与精度损失。 + +### 5.3 文件格式示例(`.seq.json`) + +```json +{ + "schema": "seqdiagram/1.2", + "project": { + "name": "装配线节拍设计", + "cycle": { "durationMs": 2400, "unit": "deg", "startAngle": 0, "direction": "cw", "origin": "12o", "snapDeg": 1 }, + "stations": [ + { "id": "ST1", "name": "上料工位", "order": 0, "color": "#4cc9f0" }, + { "id": "ST2", "name": "压装工位", "order": 1, "color": "#ffd166" }, + { "id": "ST3", "name": "检测工位", "order": 2, "color": "#34d399" } + ], + "actions": [ + { + "id": "A1", "name": "上料", "stationId": "ST1", "driver": "气缸 Y1", + "startAngle": 0, "durationAngle": 70, "layer": 0, "color": "#4cc9f0", + "deps": [] + }, + { + "id": "A3", "name": "伺服下压", "stationId": "ST2", "driver": "伺服 Z 轴", + "startAngle": 105, "durationAngle": 85, "layer": 2, "color": "#ffd166", + "deps": [{ "fromId": "A2", "type": "FS", "offsetAngle": 0 }] + }, + { + "id": "A8", "name": "清洁吹气", "stationId": "ST3", "driver": "电磁阀 V3", + "startAngle": 340, "durationAngle": 45, "layer": 7, "color": "#34d399", + "deps": [{ "fromId": "A7", "type": "SS", "offsetAngle": 5 }] + } + ], + "viewState": { "mode": "circular", "zoom": 1.0, "pan": [0, 0], "showDeps": true, "showRuler": true } + } +} +``` + +> 说明:`A8` 的 `startAngle=340`、`durationAngle=45` ⇒ 结束于 `385°`,即**跨循环**(等价于 25°)。 + +--- + +## 6. 布局算法 + +### 6.1 圆周节拍布局(极坐标) + +**坐标约定**:屏幕坐标 `y` 向下,定义 + +``` +θ(deg) = 0 在 12 点钟,顺时针为正 +P(cx, cy, r, θ) = ( cx + r·cos(θ−90°), cy + r·sin(θ−90°) ) +``` + +**半径**:`r(layer) = R0 + layer × pitch`,`pitch` 初始 50 px,随可用视口自适应压缩。 + +**圆弧路径**:`M P(r,θ0) A r r 0 largeArc 1 P(r,θ1)`,`largeArc = (θ1−θ0 > 180)`,`sweep = 1`(屏幕顺时针)。 + +**跨循环拆分**:若 `θ0 + Δθ > 360`,拆成 `[θ0, 360]` 与 `[0, θ0+Δθ−360]` 两段,第二段用虚线/半透明渲染并加"跨循环"标记。 + +**层分配策略**(`autoLayerMode`): + +| 模式 | 规则 | 适用 | +| --- | --- | --- | +| `outermost`(默认) | 永远放在最外层 `layer = maxLayer + 1` | 符合"每增加一个动作就在外层加一层"的设计习惯 | +| `firstFit` | 从内向外找第一个与已有动作**不重叠**的层 | 想让图更紧凑时 | +| `manual` | 用户手动指定 | 精修阶段 | + +**同层重叠检测**:把每个动作的区间按 `mod 360` 拆成不跨界的子区间,再做区间相交判定; +重叠时给该弧加红色描边与角标(不阻止用户,只提示)。 + +**半径自适应**:`needed = R0 + maxLayer × pitch + TH`; +若 `needed > R_available`,依次降级:① `pitch` 压缩至下限 26 px → ② 外圈刻度环内移 → ③ 进入"双环模式"(每 2 层换一个圆心偏移)。 + +### 6.2 条形节拍布局(甘特 + 流程图) + +1. **泳道分行**:按 `Station.order` 排序;同工位内动作按 `startAngle` 排序,若与已有行区间重叠则新开子行(贪心区间着色); +2. **X 映射**:`x(θ) = X0 + θ/360 × (X1 − X0)`;上轴 `ms` 刻度与下轴 `°` 刻度共用同一映射; +3. **依赖路由**: + - FS:`source.end → target.start`;SS:`source.start → target.start`;FF / SF 同理; + - 折线路径 `M s → (s.x + jog) → (t.y) → (t.x − arrow)`,`jog` 按冲突通道递增(`+16 + k×14`),避免多条线重叠; + - 跨行时在 `jog` 处加虚线辅助线,标签盒(`FS` / `SS +5°`)统一放在目标条左上角上方 46 px 处; +4. **跨循环**:拆成 `[θ0, 360]` 与 `[0, θ1−360]` 两段,第二段以虚线 + 左边界标记 + `↩ 跨循环延续` 文本渲染; +5. **关键路径(CPM)**:按依赖图做拓扑排序,计算每个动作的最早/最晚开始,`slack = 0` 的链路即关键路径,加粗高亮; +6. **相位分区色带**:由用户或预设模板定义的 `Phase{name, θ0, θ1, color}` 列表,绘制在时间轴上方。 + +### 6.3 两视图切换 + +``` +Model (单一数据源) + ├── CircularLayout → CircularPainter → Canvas / SVG + └── BarLayout → BarPainter → Canvas / SVG +``` + +- 切换 = 换 Layout + 对几何做 300–400 ms 插值(`Tween`:矩形中心/宽高 ↔ 极坐标中心角/半径/弧长); +- 层号、角度、依赖、颜色等语义字段完全不变,用户不会丢失任何设计信息; +- 两个 Layout 的输出都是同一份 `RenderModel`(图元列表),因此 **Canvas 与 SVG 导出天然一致**。 + +--- + +## 7. 交互设计 + +| 操作 | 行为 | +| --- | --- | +| 左键拖拽动作块 | 整体平移相位(改 `startAngle`),实时吸附 | +| 拖拽块两端手柄 | 改 `durationAngle`(另一端固定) | +| `Shift` + 拖拽 | 改 `layer`(圆周视图径向拖动) | +| 双击空白 | 在点击角度处新建动作,默认 `outermost` 层 | +| 方向键 / `Shift`+方向键 | 微调 1° / 10° | +| `Ctrl+Z` / `Ctrl+Y` | 撤销 / 重做 | +| 空格 + 拖拽 | 平移画布;`Ctrl`+滚轮缩放 | +| 从端点拖出连线 | 建立依赖,落点自动判定 FS/SS,弹窗确认 offset | +| 右键动作 | 上下文菜单:改层、改色、复制、设为关键路径起点、删除 | +| 相位游标 | 拖动时两视图同步显示当前角度与对应 ms | + +--- + +## 8. SVG 导出设计 + +**输出结构**(分层 + 语义 id,可被 Inkscape 直接编辑,也可被 MES 解析): + +```xml + + + + …5°/30° 刻度与标签… + …相位分区色带… + …同心圆参考线… + + + + A3 伺服下压 + + + + + + + + +``` + +**要点** + +- **不用 `` 位图**,全部矢量;文字用真实 ``(字体 fallback 链),保证工艺卡里可搜索、可改字; +- 每个动作一个 ``,携带 `data-*` 元数据,实现"图形 ↔ 模型"双向可追溯; +- 导出选项:当前视图 / 双视图并排 / 含图例 / 透明背景 / 单位 mm; +- 与 Canvas 共用同一份几何与文字度量,**屏幕所见即导出所得**(Golden 测试守护); +- 导出过程在 Isolate 执行,1000 动作 < 200 ms。 + +--- + +## 9. 目录结构 + +``` +sequence-diagram/ +├─ lib/ +│ ├─ main.dart +│ ├─ app/ # 主题、路由、全局快捷键、本地化 +│ ├─ model/ # 不可变领域模型 + JSON codec + schema 迁移 +│ ├─ state/ # Riverpod providers、Command 撤销栈、选区 +│ ├─ layout/ # circular_layout.dart / bar_layout.dart / geometry.dart +│ ├─ render/ # circular_painter.dart / bar_painter.dart / overlay +│ ├─ export/ # svg_writer.dart / png_writer.dart / pdf_writer.dart +│ ├─ ui/ # 工具栏、项目树、属性面板、状态栏、迷你图 +│ └─ util/ # 角度、单位换算、吸附、区间、空间索引 +├─ test/ # 单元测试 + golden 测试 +├─ demo/ # 设计示例图(SVG 源 + 2K PNG) +├─ tools/ # demo-gen.mjs 等生成脚本 +└─ docs/DESIGN.md +``` + +--- + +## 10. 里程碑 + +| 阶段 | 周期 | 交付 | +| --- | --- | --- | +| **M1 数据与条形视图** | 1 周 | 模型 + JSON 存取 + 条形视图静态渲染 + 缩放平移 + 单位换算 | +| **M2 圆周视图与编辑** | 1 周 | 圆周视图 + 双视图切换动画 + 拖拽/吸附 + 属性面板 + 撤销重做 | +| **M3 导出与统计** | 1 周 | SVG/PNG 导出 + 依赖编辑 + 关键路径/统计 + 层管理 + Golden 测试 | +| **M4 工程化** | 2 周 | PLC 点位对接(OPC UA / 三菱 MC / Modbus)、工艺卡 PDF、自动节拍优化(瓶颈重排建议)、多项目模板 | + +--- + +## 11. 风险与对策 + +| 风险 | 影响 | 对策 | +| --- | --- | --- | +| 大量动作时渲染掉帧 | 拖拽不跟手 | 双层缓存 + 脏区重绘 + 空间索引;压测 1000/5000 动作基准 | +| 中文字体在桌面端缺失 | 文字变方块 | 打包内置 Noto Sans SC 子集,SVG 导出写字体 fallback 链 | +| SVG 与 Canvas 渲染不一致 | 导出返工 | 统一几何 + 统一 `TextPainter` 度量,Golden 测试双端比对 | +| 层数过多导致圆环不可读 | 圆周视图失效 | `pitch` 自适应 + 双环模式 + 层折叠(同层动作合并显示) | +| 依赖成环 | 关键路径计算失败 | 建图时做环检测(Tarjan SCC),高亮环并阻止保存 | +| 时间/角度双单位混淆 | 设计错误 | 模型只存角度,UI 全局统一换算函数,面板同时显示两种单位 | + +--- + +## 12. 附录:示例 PLC 流程数据(demo 图所用) + +循环 2400 ms = 360°,8 个动作,3 个工位,7 条依赖: + +| ID | 动作 | 工位 | 驱动 | 起始角 | 持续角 | 时间 | 层 | 依赖 | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | +| A1 | 上料 | ST1 | 气缸 Y1 | 0° | 70° | 467 ms | L1 | — | +| A2 | 定位夹紧 | ST1 | 夹爪 M1 | 55° | 60° | 400 ms | L2 | A1 SS +55° | +| A3 | 伺服下压 | ST2 | 伺服 Z 轴 | 105° | 85° | 567 ms | L3 | A2 FS | +| A4 | 超声波焊接 | ST2 | 超声发生器 | 185° | 95° | 633 ms | L4 | A3 FS | +| A5 | 保压冷却 | ST2 | 延时 T1 | 275° | 45° | 300 ms | L5 | A4 FS | +| A6 | 视觉检测 | ST3 | 相机 CAM1 | 300° | 45° | 300 ms | L6 | A4 FS | +| A7 | 分选下料 | ST3 | 气缸 Y2 | 335° | 25° | 167 ms | L7 | A6 SS +35° | +| A8 | 清洁吹气 | ST3 | 电磁阀 V3 | 340° | 45° | 300 ms | L8 | A7 SS +5°(跨循环至 25°) | + +- 关键路径:`A1 → A2 → A3 → A4 → A6 → A7` +- 最大并行度:3(185°–190° 区间) +- 瓶颈工位:ST2,加工相位 105°–320°(215°) +- 预估节拍:2.400 s / 件 ≈ 1500 件/小时 + +![圆周节拍](../demo/circular-timing.png) + +![条形节拍](../demo/bar-timing.png) diff --git a/tools/demo-gen.mjs b/tools/demo-gen.mjs new file mode 100644 index 0000000..741db3f --- /dev/null +++ b/tools/demo-gen.mjs @@ -0,0 +1,648 @@ +import { writeFileSync, mkdirSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..'); +const OUT = join(ROOT, 'demo'); +mkdirSync(OUT, { recursive: true }); + +const W = 2560, H = 1440; +const FONT = "'Microsoft YaHei','Segoe UI',sans-serif"; +const C = { + bg: '#0b1018', canvas: '#0e1520', panel: '#121a28', panel2: '#0f1723', + line: '#1f2c40', line2: '#2a3a52', text: '#e8eefc', sub: '#8ea0bd', dim: '#5c6f8c', + accent: '#4cc9f0', accent2: '#7c5cff', ok: '#34d399', warn: '#ffd166', danger: '#ff6b6b', +}; +const PAL = ['#4cc9f0', '#7bd88f', '#ffd166', '#ff8a5c', '#f472b6', '#a78bfa', '#38bdf8', '#34d399']; + +const CYCLE_MS = 2400; +const ACTIONS = [ + { id: 'A1', name: '上料', a0: 0, a1: 70, station: 'ST1', driver: '气缸 Y1' }, + { id: 'A2', name: '定位夹紧', a0: 55, a1: 115, station: 'ST1', driver: '夹爪 M1' }, + { id: 'A3', name: '伺服下压', a0: 105, a1: 190, station: 'ST2', driver: '伺服 Z 轴' }, + { id: 'A4', name: '超声波焊接', a0: 185, a1: 280, station: 'ST2', driver: '超声发生器' }, + { id: 'A5', name: '保压冷却', a0: 275, a1: 320, station: 'ST2', driver: '延时 T1' }, + { id: 'A6', name: '视觉检测', a0: 300, a1: 345, station: 'ST3', driver: '相机 CAM1' }, + { id: 'A7', name: '分选下料', a0: 335, a1: 360, station: 'ST3', driver: '气缸 Y2' }, + { id: 'A8', name: '清洁吹气', a0: 340, a1: 385, station: 'ST3', driver: '电磁阀 V3' }, +]; +ACTIONS.forEach((a, i) => { a.color = PAL[i]; a.ring = i; }); + +const DEPS = [ + { from: 'A1', to: 'A2', type: 'SS', off: 55 }, + { from: 'A2', to: 'A3', type: 'FS', off: 0 }, + { from: 'A3', to: 'A4', type: 'FS', off: 0 }, + { from: 'A4', to: 'A5', type: 'FS', off: 0 }, + { from: 'A4', to: 'A6', type: 'FS', off: 0 }, + { from: 'A6', to: 'A7', type: 'SS', off: 35 }, + { from: 'A7', to: 'A8', type: 'SS', off: 5 }, +]; + +const byId = (id) => ACTIONS.find((a) => a.id === id); +const deg2ms = (d) => Math.round((d / 360) * CYCLE_MS); +const fmt = (n, p = 1) => Number(n).toFixed(p); + +function esc(s) { + return String(s).replace(/&/g, '&').replace(//g, '>'); +} + +function txt(x, y, s, o = {}) { + const { + size = 15, fill = C.text, anchor = 'start', weight = 400, family = FONT, + opacity = 1, baseline = 'middle', ls = 0, rot = null, + } = o; + const tr = rot ? ` transform="rotate(${rot} ${x} ${y})"` : ''; + return `${esc(s)}`; +} + +function rect(x, y, w, h, o = {}) { + const { fill = 'none', stroke = 'none', sw = 1, rx = 0, opacity = 1, dash = null } = o; + const d = dash ? ` stroke-dasharray="${dash}"` : ''; + return ``; +} + +function line(x1, y1, x2, y2, o = {}) { + const { stroke = C.line, sw = 1, dash = null, opacity = 1, cap = 'butt' } = o; + const d = dash ? ` stroke-dasharray="${dash}"` : ''; + return ``; +} + +function circle(cx, cy, r, o = {}) { + const { fill = 'none', stroke = 'none', sw = 1, opacity = 1, dash = null } = o; + const d = dash ? ` stroke-dasharray="${dash}"` : ''; + return ``; +} + +function path(d, o = {}) { + const { fill = 'none', stroke = 'none', sw = 1, opacity = 1, dash = null, cap = 'butt' } = o; + const da = dash ? ` stroke-dasharray="${dash}"` : ''; + return ``; +} + +function pt(cx, cy, r, deg) { + const t = ((deg - 90) * Math.PI) / 180; + return [cx + r * Math.cos(t), cy + r * Math.sin(t)]; +} + +function arcPath(cx, cy, r, a0, a1) { + const [x0, y0] = pt(cx, cy, r, a0); + const [x1, y1] = pt(cx, cy, r, a1); + const large = a1 - a0 > 180 ? 1 : 0; + return `M ${x0.toFixed(2)} ${y0.toFixed(2)} A ${r} ${r} 0 ${large} 1 ${x1.toFixed(2)} ${y1.toFixed(2)}`; +} + +function ringArcs(cx, cy, r, a0, a1) { + if (a1 <= 360) return [arcPath(cx, cy, r, a0, a1)]; + return [arcPath(cx, cy, r, a0, 360), arcPath(cx, cy, r, 0, a1 - 360)]; +} + +function chrome(mode) { + const segY = 14, segH = 36; + const segX = 1120, segW = 400, half = segW / 2; + const activeBar = mode === 'bar'; + const seg = (x, w, label, active) => rect(x, segY, w, segH, { rx: 10, fill: active ? C.accent : 'transparent', opacity: active ? 0.16 : 1 }) + + (active ? rect(x, segY, w, segH, { rx: 10, stroke: C.accent, sw: 1.4 }) : '') + + txt(x + w / 2, segY + segH / 2 + 1, label, { size: 15, anchor: 'middle', weight: active ? 600 : 400, fill: active ? C.accent : C.sub }); + + const btn = (x, w, label, kind = 'ghost') => { + const fill = kind === 'primary' ? C.accent2 : C.panel; + const stroke = kind === 'primary' ? C.accent2 : C.line2; + const col = kind === 'primary' ? '#ffffff' : C.text; + return rect(x, segY, w, segH, { rx: 9, fill, stroke, sw: 1 }) + + txt(x + w / 2, segY + segH / 2 + 1, label, { size: 14.5, anchor: 'middle', fill: col }); + }; + + let s = ''; + s += rect(0, 0, W, 64, { fill: '#0f1622' }); + s += line(0, 63.5, W, 63.5, { stroke: C.line2, sw: 1 }); + s += rect(24, 17, 30, 30, { rx: 9, fill: C.accent, opacity: 0.18 }); + s += rect(24, 17, 30, 30, { rx: 9, stroke: C.accent, sw: 1.2 }); + s += path(`M 32 38 L 39 26 L 46 38`, { stroke: C.accent, sw: 2, cap: 'round' }); + s += txt(64, 32, '时序图设计器', { size: 17, weight: 700, ls: 1 }); + s += txt(178, 33, 'Sequence Diagram Studio', { size: 12.5, fill: C.dim }); + s += txt(24, 54, '', { size: 11 }); + + s += btn(430, 76, '新建'); + s += btn(514, 76, '打开'); + s += btn(598, 76, '保存'); + s += btn(682, 86, '撤销 ↶'); + s += btn(776, 86, '重做 ↷'); + + s += rect(segX, segY, segW, segH, { rx: 11, fill: C.panel, stroke: C.line2, sw: 1 }); + s += seg(segX + 4, half - 8, '条形节拍', activeBar); + s += seg(segX + half + 4, half - 8, '圆周节拍', !activeBar); + + s += btn(1900, 110, '导出 SVG', 'primary'); + s += btn(2020, 110, '导出 PNG'); + s += btn(2140, 96, '− 100% +'); + s += btn(2246, 96, '适应窗口'); + s += btn(2352, 184, '文件: 装配线节拍.seq.json'); + + const sbY = H - 36; + s += rect(0, sbY, W, 36, { fill: '#0f1622' }); + s += line(0, sbY + 0.5, W, sbY + 0.5, { stroke: C.line2, sw: 1 }); + const items = mode === 'bar' + ? ['循环周期 2400 ms', '相位 360°', '动作 8', '依赖 7', '工位 3', '时间轴 0–2400 ms', '吸附 5°', '就绪'] + : ['循环周期 2400 ms', '相位 360°', '动作 8', '层数 L1–L8', '同心圆 8', '半径步距 50 px', '吸附 1°', '就绪']; + let x = 24; + items.forEach((it, i) => { + s += txt(x, sbY + 19, it, { size: 13, fill: i === items.length - 1 ? C.ok : C.sub }); + x += it.length * 12 + 46; + }); + s += txt(W - 24, sbY + 19, '● 已保存', { size: 13, fill: C.ok, anchor: 'end' }); + return s; +} + +function leftPanel(mode, selected) { + const x0 = 0, w = 380, y0 = 64, h = H - 64 - 36; + let s = rect(x0, y0, w, h, { fill: C.panel }); + s += line(w - 0.5, y0, w - 0.5, y0 + h, { stroke: C.line, sw: 1 }); + + s += txt(24, 96, '项目', { size: 13, fill: C.dim, ls: 2 }); + s += rect(16, 112, 348, 108, { rx: 12, fill: C.panel2, stroke: C.line, sw: 1 }); + s += rect(32, 128, 34, 34, { rx: 9, fill: C.accent2, opacity: 0.2 }); + s += txt(49, 146, '装', { size: 15, anchor: 'middle', fill: C.accent2, weight: 700 }); + s += txt(78, 138, '装配线节拍设计', { size: 15.5, weight: 600 }); + s += txt(78, 160, '装配线节拍.seq.json · v1.2', { size: 12, fill: C.dim }); + s += txt(32, 196, '循环 2.400 s = 360°', { size: 12.5, fill: C.accent }); + s += txt(232, 196, '动作 8 · 依赖 7', { size: 12.5, fill: C.sub }); + + s += txt(24, 252, mode === 'bar' ? '动作 / 工位泳道' : '动作列表(按层 L1→L8)', { size: 13, fill: C.dim, ls: 2 }); + + const rowH = 50, gap = 6, y1 = 268; + ACTIONS.forEach((a, i) => { + const y = y1 + i * (rowH + gap); + const sel = a.id === selected; + s += rect(16, y, 348, rowH, { rx: 10, fill: sel ? '#182437' : C.panel2, stroke: sel ? C.accent : C.line, sw: sel ? 1.4 : 1 }); + s += rect(28, y + 15, 20, 20, { rx: 6, fill: a.color, opacity: 0.9 }); + s += txt(38, y + 26, String(i + 1), { size: 12, anchor: 'middle', fill: '#0b1018', weight: 700 }); + s += txt(58, y + 18, a.name, { size: 14.5, weight: sel ? 600 : 400, fill: sel ? C.text : '#cfd9ea' }); + s += txt(58, y + 36, `${a.id} · ${a.station} · ${a.driver}`, { size: 11.5, fill: C.dim }); + s += txt(352, y + 18, mode === 'bar' ? `${fmt(a.a0, 0)}° – ${fmt(Math.min(a.a1, 360), 0)}°` : `L${i + 1} r=${100 + i * 50}`, { size: 12, anchor: 'end', fill: C.sub }); + s += txt(352, y + 36, `${deg2ms(a.a1 - a.a0)} ms`, { size: 11.5, anchor: 'end', fill: C.dim }); + }); + + const yb = y1 + 8 * (rowH + gap) + 14; + s += txt(24, yb, '视图模式', { size: 13, fill: C.dim, ls: 2 }); + const mw = 166; + s += rect(16, yb + 14, mw, 44, { rx: 10, fill: mode === 'bar' ? C.accent : C.panel2, opacity: mode === 'bar' ? 0.16 : 1, stroke: mode === 'bar' ? C.accent : C.line, sw: 1.2 }); + s += txt(16 + mw / 2, yb + 36, '条形节拍(甘特)', { size: 13.5, anchor: 'middle', fill: mode === 'bar' ? C.accent : C.sub }); + s += rect(16 + mw + 16, yb + 14, mw, 44, { rx: 10, fill: mode !== 'bar' ? C.accent : C.panel2, opacity: mode !== 'bar' ? 0.16 : 1, stroke: mode !== 'bar' ? C.accent : C.line, sw: 1.2 }); + s += txt(16 + mw + 16 + mw / 2, yb + 36, '圆周节拍(同心)', { size: 13.5, anchor: 'middle', fill: mode !== 'bar' ? C.accent : C.sub }); + + s += txt(24, yb + 92, '显示选项', { size: 13, fill: C.dim, ls: 2 }); + const opts = mode === 'bar' + ? ['时间轴 / 相位双刻度', '依赖箭头 FS / SS', '跨循环片段标记', '相位分区色带'] + : ['相位角刻度环', '依赖连线', '层半径标注', '跨循环高亮']; + opts.forEach((o, i) => { + const y = yb + 112 + i * 28; + s += rect(20, y, 16, 16, { rx: 4, fill: C.accent, opacity: 0.22 }); + s += path(`M 24 ${y + 8} L 27 ${y + 12} L 33 ${y + 4}`, { stroke: C.accent, sw: 1.8, cap: 'round' }); + s += txt(48, y + 8, o, { size: 13, fill: C.sub }); + }); + + const yload = yb + 112 + opts.length * 28 + 34; + s += txt(24, yload, '工位负载 / 相位占用', { size: 13, fill: C.dim, ls: 2 }); + const loads = [['ST1 上料 · 夹紧', 115, C.accent], ['ST2 压装 · 焊接', 215, C.warn], ['ST3 检测 · 下料', 85, C.ok]]; + loads.forEach(([k, deg, col], i) => { + const y = yload + 26 + i * 36; + s += txt(24, y, k, { size: 12.5, fill: C.sub }); + s += txt(356, y, `${deg}° · ${((deg / 3.6)).toFixed(1)}%`, { size: 12, anchor: 'end', fill: col, weight: 600 }); + s += rect(24, y + 12, 332, 8, { rx: 4, fill: '#1b2740' }); + s += rect(24, y + 12, (332 * deg) / 360, 8, { rx: 4, fill: col }); + }); + const ynote = yload + 26 + 3 * 36 + 22; + s += rect(16, ynote, 348, 78, { rx: 10, fill: '#131d2e', stroke: C.line, sw: 1 }); + s += txt(32, ynote + 22, '操作提示', { size: 12, fill: C.warn, weight: 700 }); + s += txt(32, ynote + 44, '拖拽动作块平移相位 · 拖端点改持续角', { size: 11.5, fill: C.sub }); + s += txt(32, ynote + 62, 'Ctrl+滚轮缩放 · 双击空白新建动作', { size: 11.5, fill: C.sub }); + + const ycp = ynote + 96; + s += txt(24, ycp, '关键路径', { size: 13, fill: C.dim, ls: 2 }); + s += rect(16, ycp + 14, 348, 62, { rx: 10, fill: C.panel2, stroke: C.line, sw: 1 }); + s += txt(32, ycp + 38, 'A1 → A2 → A3 → A4 → A6 → A7', { size: 13, fill: '#cfd9ea', weight: 600 }); + s += txt(32, ycp + 60, '累计 2400 ms(占满整圈,无空档)', { size: 11.5, fill: C.dim }); + return s; +} + +function rightPanelCircular() { + const x0 = 2140, w = W - x0, y0 = 64, h = H - 64 - 36; + let s = rect(x0, y0, w, h, { fill: C.panel }); + s += line(x0 + 0.5, y0, x0 + 0.5, y0 + h, { stroke: C.line, sw: 1 }); + const lx = x0 + 24, rx = W - 24; + + s += txt(lx, 96, '属性 · 选中动作', { size: 13, fill: C.dim, ls: 2 }); + s += rect(lx, 112, rx - lx, 62, { rx: 12, fill: C.panel2, stroke: C.line, sw: 1 }); + s += rect(lx + 14, 128, 30, 30, { rx: 8, fill: byId('A3').color, opacity: 0.9 }); + s += txt(lx + 29, 144, 'A3', { size: 11.5, anchor: 'middle', fill: '#0b1018', weight: 700 }); + s += txt(lx + 56, 136, '伺服下压', { size: 16, weight: 600 }); + s += txt(lx + 56, 158, 'ST2 · 伺服 Z 轴 · 层 L3', { size: 12, fill: C.dim }); + s += rect(rx - 74, 126, 60, 34, { rx: 8, fill: C.accent, opacity: 0.14, stroke: C.accent, sw: 1 }); + s += txt(rx - 44, 143, '选中', { size: 12.5, anchor: 'middle', fill: C.accent }); + + const fields = [ + ['起始角', '105.0°', '12 点钟起顺时针'], + ['结束角', '190.0°', ''], + ['持续角', '85.0°', `= ${deg2ms(85)} ms`], + ['所在层', 'L3', '半径 200 px'], + ['依赖', 'A2 → FS', '完成-启动'], + ['相位归属', '加工相位', '105°–190°'], + ]; + let y = 196; + fields.forEach(([k, v, note], i) => { + if (i % 2 === 0) s += rect(lx, y - 6, rx - lx, 36, { rx: 8, fill: i % 4 === 0 ? C.panel2 : 'transparent', opacity: 0.7 }); + s += txt(lx + 10, y + 12, k, { size: 13.5, fill: C.sub }); + s += txt(rx - 10, y + 12, v, { size: 14, anchor: 'end', weight: 600 }); + if (note) s += txt(rx - 10, y + 30, note, { size: 11, anchor: 'end', fill: C.dim }); + y += 40; + }); + + y += 8; + s += txt(lx, y, '角度编辑', { size: 13, fill: C.dim, ls: 2 }); + y += 22; + const sliders = [['起始角', 105 / 360, '105°'], ['持续角', 85 / 180, '85°']]; + sliders.forEach(([k, p, v]) => { + s += txt(lx, y, k, { size: 13, fill: C.sub }); + s += txt(rx, y, v, { size: 13, anchor: 'end', fill: C.accent, weight: 600 }); + s += rect(lx, y + 16, rx - lx, 8, { rx: 4, fill: '#1b2740' }); + s += rect(lx, y + 16, (rx - lx) * p, 8, { rx: 4, fill: C.accent }); + s += circle(lx + (rx - lx) * p, y + 20, 9, { fill: '#0b1018', stroke: C.accent, sw: 2.5 }); + y += 56; + }); + + y += 4; + s += txt(lx, y, '层级操作', { size: 13, fill: C.dim, ls: 2 }); + y += 18; + s += rect(lx, y, 168, 40, { rx: 9, fill: C.accent2, opacity: 0.9 }); + s += txt(lx + 84, y + 20, '新增外层 L9', { size: 13.5, anchor: 'middle', weight: 600 }); + s += rect(lx + 180, y, 168, 40, { rx: 9, fill: C.panel2, stroke: C.line2, sw: 1 }); + s += txt(lx + 264, y + 20, '重排 / 合并层', { size: 13.5, anchor: 'middle', fill: C.sub }); + y += 62; + s += rect(lx, y, rx - lx, 66, { rx: 10, fill: '#131d2e', stroke: C.line, sw: 1 }); + s += txt(lx + 14, y + 22, '规则', { size: 12, fill: C.warn, weight: 700 }); + s += txt(lx + 14, y + 44, '新增动作默认置于最外层同心圆,', { size: 12, fill: C.sub }); + s += txt(lx + 14, y + 60, '角度可吸附到 1°,自动检测相位重叠。', { size: 12, fill: C.sub }); + + s += txt(lx, H - 96, '依赖连线', { size: 13, fill: C.dim, ls: 2 }); + const dl = [['A2 定位夹紧', '→ A3 完成-启动 FS', C.ok], ['A3 伺服下压', '→ A4 完成-启动 FS', C.ok], ['A3 伺服下压', '→ A6 起始-起始 SS +195°', C.warn]]; + dl.forEach(([a, b, col], i) => { + const yy = H - 76 + i * 26; + s += circle(lx + 5, yy, 4, { fill: col }); + s += txt(lx + 18, yy, a, { size: 12.5, fill: C.sub }); + s += txt(rx, yy, b, { size: 12.5, anchor: 'end', fill: C.dim }); + }); + return s; +} + +function rightPanelBar() { + const x0 = 2140, w = W - x0, y0 = 64, h = H - 64 - 36; + let s = rect(x0, y0, w, h, { fill: C.panel }); + s += line(x0 + 0.5, y0, x0 + 0.5, y0 + h, { stroke: C.line, sw: 1 }); + const lx = x0 + 24, rx = W - 24; + + s += txt(lx, 96, '属性 · 选中动作', { size: 13, fill: C.dim, ls: 2 }); + s += rect(lx, 112, rx - lx, 62, { rx: 12, fill: C.panel2, stroke: C.line, sw: 1 }); + s += rect(lx + 14, 128, 30, 30, { rx: 8, fill: byId('A8').color, opacity: 0.9 }); + s += txt(lx + 29, 144, 'A8', { size: 11.5, anchor: 'middle', fill: '#0b1018', weight: 700 }); + s += txt(lx + 56, 136, '清洁吹气', { size: 16, weight: 600 }); + s += txt(lx + 56, 158, 'ST3 · 电磁阀 V3 · 跨循环', { size: 12, fill: C.dim }); + s += rect(rx - 74, 126, 60, 34, { rx: 8, fill: C.warn, opacity: 0.14, stroke: C.warn, sw: 1 }); + s += txt(rx - 44, 143, '跨圈', { size: 12.5, anchor: 'middle', fill: C.warn }); + + const fields = [ + ['开始时刻', '2267 ms', '340.0°'], + ['结束时刻', '2567 ms', '385.0° → 25.0°'], + ['持续时间', '300 ms', '45.0°'], + ['循环归属', '当前圈 + 下一圈', '跨圈片段'], + ['依赖', 'A7 → SS +5°', '起始-起始'], + ['相位归属', '下料相位', '335°–360°/0°–25°'], + ]; + let y = 196; + fields.forEach(([k, v, note], i) => { + if (i % 2 === 0) s += rect(lx, y - 6, rx - lx, 36, { rx: 8, fill: C.panel2, opacity: 0.7 }); + s += txt(lx + 10, y + 12, k, { size: 13.5, fill: C.sub }); + s += txt(rx - 10, y + 12, v, { size: 14, anchor: 'end', weight: 600 }); + if (note) s += txt(rx - 10, y + 30, note, { size: 11, anchor: 'end', fill: C.dim }); + y += 40; + }); + + y += 8; + s += txt(lx, y, '时间 / 角度联动', { size: 13, fill: C.dim, ls: 2 }); + y += 20; + s += rect(lx, y, rx - lx, 54, { rx: 10, fill: '#131d2e', stroke: C.line, sw: 1 }); + s += txt(lx + 14, y + 20, '1° = 6.667 ms', { size: 13.5, fill: C.accent, weight: 600 }); + s += txt(lx + 14, y + 40, '角度与时间线性映射,双向同步', { size: 11.5, fill: C.dim }); + y += 74; + + s += txt(lx, y, '依赖关系(7)', { size: 13, fill: C.dim, ls: 2 }); + y += 16; + DEPS.forEach((d, i) => { + const yy = y + i * 27; + const col = d.type === 'FS' ? C.ok : C.warn; + s += rect(lx, yy, rx - lx, 22, { rx: 6, fill: i % 2 ? 'transparent' : C.panel2, opacity: 0.6 }); + s += circle(lx + 9, yy + 11, 4, { fill: col }); + s += txt(lx + 20, yy + 11, `${byId(d.from).name} → ${byId(d.to).name}`, { size: 12.5, fill: C.sub }); + s += txt(rx - 10, yy + 11, d.type === 'FS' ? 'FS' : `SS +${d.off}°`, { size: 12, anchor: 'end', fill: col, weight: 600 }); + }); + + y = y + 7 * 27 + 22; + s += txt(lx, y, '导出', { size: 13, fill: C.dim, ls: 2 }); + y += 16; + s += rect(lx, y, rx - lx, 44, { rx: 10, fill: C.panel2, stroke: C.line2, sw: 1 }); + s += txt(lx + 14, y + 22, 'SVG(矢量 · 可编辑 · 打印级)', { size: 13, fill: C.sub }); + s += rect(lx, y + 54, rx - lx, 44, { rx: 10, fill: C.panel2, stroke: C.line2, sw: 1 }); + s += txt(lx + 14, y + 76, 'PNG / PDF / 工艺卡', { size: 13, fill: C.sub }); + return s; +} + +function circularView() { + const cx = 1180, cy = 790; + const R0 = 100, PITCH = 50, TH = 34; + let s = ''; + + s += txt(420, 108, '圆周节拍视图(同心圆 · 12 点钟起始 · 顺时针)', { size: 20, weight: 600 }); + s += txt(420, 134, '每增加一个动作,在最外层新增一圈;每圈设置起始角与持续角,1 圈 = 1 循环 = 2400 ms', { size: 13, fill: C.dim }); + + const RMAX = R0 + (ACTIONS.length - 1) * PITCH + TH / 2; + const RTICK = RMAX + 42, RLAB = RMAX + 76; + + s += circle(cx, cy, RTICK - 14, { fill: '#0c1320', stroke: C.line, sw: 1 }); + + for (let d = 0; d < 360; d += 5) { + const major = d % 30 === 0; + const mid = d % 10 === 0; + const [x1, y1] = pt(cx, cy, RTICK, d); + const [x2, y2] = pt(cx, cy, RTICK + (major ? 22 : mid ? 14 : 8), d); + s += line(x1, y1, x2, y2, { stroke: major ? C.line2 : C.line, sw: major ? 1.4 : 1 }); + if (major) { + const [tx, ty] = pt(cx, cy, RLAB + 12, d); + s += txt(tx, ty, `${d}°`, { size: 13, anchor: 'middle', fill: d % 90 === 0 ? C.accent : C.sub, weight: d % 90 === 0 ? 700 : 400 }); + } + } + [0, 90, 180, 270].forEach((d) => { + const [x1, y1] = pt(cx, cy, 60, d); + const [x2, y2] = pt(cx, cy, RTICK + 24, d); + s += line(x1, y1, x2, y2, { stroke: C.line2, sw: 1, dash: '4 8', opacity: 0.7 }); + }); + + for (let i = 0; i < ACTIONS.length; i++) { + s += circle(cx, cy, R0 + i * PITCH, { stroke: C.line, sw: 1, dash: '3 7', opacity: 0.75 }); + } + + ACTIONS.forEach((a, i) => { + const r = R0 + i * PITCH; + const isSel = a.id === 'A3'; + const wrap = a.a1 > 360; + const segs = ringArcs(cx, cy, r, a.a0, a.a1); + s += path(segs.join(' '), { stroke: '#000000', sw: TH + 10, opacity: 0.35, cap: wrap ? 'butt' : 'round' }); + segs.forEach((d, k) => { + const isTail = wrap && k === 1; + s += path(d, { + stroke: a.color, sw: TH, cap: wrap ? 'butt' : 'round', + opacity: isTail ? 0.55 : 1, + }); + if (isTail) s += path(d, { stroke: a.color, sw: TH, cap: 'butt', dash: '6 6', opacity: 0.9 }); + }); + if (isSel) { + s += path(segs.join(' '), { stroke: '#ffffff', sw: 1.6, opacity: 0.9 }); + s += path(arcPath(cx, cy, r + TH / 2 + 12, a.a0, a.a1), { stroke: C.accent, sw: 1.6, dash: '6 5' }); + } + + const mid = (a.a0 + a.a1) / 2; + const [mx, my] = pt(cx, cy, r, mid); + const short = (a.a1 - a.a0) < 40; + s += txt(mx, my - (short ? 5 : 7), `${a.id} ${a.name}`, { size: short ? 11.5 : 14.5, anchor: 'middle', fill: '#0a0f18', weight: 700 }); + s += txt(mx, my + (short ? 10 : 12), `${fmt(a.a0, 0)}°–${fmt(Math.min(a.a1, 360), 0)}°`, { size: short ? 10 : 11.5, anchor: 'middle', fill: '#0a0f18', opacity: 0.85 }); + }); + + const [sx, sy] = pt(cx, cy, RTICK + 20, 0); + s += path(`M ${cx} ${cy - RTICK - 26} l -11 -18 l 22 0 z`, { fill: C.accent }); + s += txt(cx, cy - RTICK - 58, '0° 起点 · 12 点钟方向', { size: 14, anchor: 'middle', fill: C.accent, weight: 600 }); + + const [rax0, ray0] = pt(cx, cy, RMAX + 30, 20); + const [rax1, ray1] = pt(cx, cy, RMAX + 30, 70); + s += path(arcPath(cx, cy, RMAX + 30, 20, 70), { stroke: C.accent2, sw: 2.4, cap: 'round' }); + const [ahx, ahy] = pt(cx, cy, RMAX + 30, 74); + const [ahx2, ahy2] = pt(cx, cy, RMAX + 44, 68); + const [ahx3, ahy3] = pt(cx, cy, RMAX + 22, 66); + s += path(`M ${ahx} ${ahy} L ${ahx2} ${ahy2} L ${ahx3} ${ahy3} z`, { fill: C.accent2 }); + const [rtx, rty] = pt(cx, cy, RMAX + 62, 45); + s += txt(rtx, rty, '顺时针 CW', { size: 13.5, anchor: 'middle', fill: C.accent2, weight: 600 }); + + const a3 = byId('A3'); + const r3 = R0 + a3.ring * PITCH; + const [d0x, d0y] = pt(cx, cy, r3 - TH / 2 - 4, a3.a0); + const [d1x, d1y] = pt(cx, cy, r3 + TH / 2 + 4, a3.a0); + const [d2x, d2y] = pt(cx, cy, r3 - TH / 2 - 4, a3.a1); + const [d3x, d3y] = pt(cx, cy, r3 + TH / 2 + 4, a3.a1); + s += line(d0x, d0y, d1x, d1y, { stroke: C.accent, sw: 2 }); + s += line(d2x, d2y, d3x, d3y, { stroke: C.accent, sw: 2 }); + + const lx = 436, ly = 216; + s += rect(lx - 16, ly - 40, 250, 34 + 8 * 46 + 18, { rx: 14, fill: C.panel2, stroke: C.line, sw: 1, opacity: 0.96 }); + s += txt(lx, ly - 20, '图层 / 相位图例', { size: 13.5, weight: 600, fill: C.sub }); + ACTIONS.forEach((a, i) => { + const yy = ly + 8 + i * 46; + s += rect(lx, yy - 9, 16, 16, { rx: 5, fill: a.color }); + s += txt(lx + 26, yy, `${a.id} ${a.name}`, { size: 13.5, fill: '#cfd9ea' }); + s += txt(lx + 26, yy + 18, `L${i + 1} · r=${R0 + i * PITCH} · ${a.a0}°–${Math.min(a.a1, 360)}° · ${deg2ms(a.a1 - a.a0)} ms`, { size: 10.5, fill: C.dim }); + }); + + const ry0 = ly + 8 + 8 * 46 + 16; + s += rect(lx - 16, ry0, 250, 168, { rx: 14, fill: '#0b1018', stroke: C.accent, sw: 1.2, opacity: 0.96 }); + s += txt(lx, ry0 + 26, '选中动作', { size: 12, fill: C.accent, weight: 700, ls: 1 }); + s += txt(lx, ry0 + 52, 'A3 伺服下压', { size: 15, weight: 700 }); + s += txt(lx, ry0 + 78, '起始角 105.0°', { size: 12, fill: C.sub }); + s += txt(lx, ry0 + 100, '结束角 190.0°', { size: 12, fill: C.sub }); + s += txt(lx, ry0 + 122, '持续角 85.0°', { size: 12, fill: C.sub }); + s += txt(lx, ry0 + 146, `Δ = ${deg2ms(85)} ms · 层 L3 · ST2`, { size: 12, fill: C.accent, weight: 600 }); + + const mx0 = 1790, my0 = 1160; + s += rect(mx0 - 16, my0 - 34, 340, 214, { rx: 14, fill: C.panel2, stroke: C.line, sw: 1, opacity: 0.96 }); + s += txt(mx0, my0 - 14, '条形节拍预览(实时联动)', { size: 13.5, weight: 600, fill: C.sub }); + const bx0 = mx0 + 4, bw = 300, by0 = my0 + 8, rh = 19; + ACTIONS.forEach((a, i) => { + const y = by0 + i * (rh + 3); + const x1 = bx0 + (a.a0 / 360) * bw; + const x2 = bx0 + (Math.min(a.a1, 360) / 360) * bw; + s += rect(x1, y, Math.max(x2 - x1, 2), rh - 4, { rx: 3, fill: a.color, opacity: 0.9 }); + if (a.a1 > 360) s += rect(bx0, y, ((a.a1 - 360) / 360) * bw, rh - 4, { rx: 3, fill: a.color, opacity: 0.5, dash: '3 3' }); + }); + s += line(bx0, by0 + 8 * (rh + 3) + 4, bx0 + bw, by0 + 8 * (rh + 3) + 4, { stroke: C.line2, sw: 1 }); + s += txt(bx0, by0 + 8 * (rh + 3) + 20, '0 ms', { size: 11, fill: C.dim }); + s += txt(bx0 + bw / 2, by0 + 8 * (rh + 3) + 20, '1200 ms', { size: 11, anchor: 'middle', fill: C.dim }); + s += txt(bx0 + bw, by0 + 8 * (rh + 3) + 20, '2400 ms', { size: 11, anchor: 'end', fill: C.dim }); + return s; +} + +function barView() { + const X0 = 700, X1 = 2080, SPAN = X1 - X0; + const px = (deg) => X0 + (Math.min(deg, 360) / 360) * SPAN; + const rowY = (i) => 268 + i * 66; + const BAR_H = 34; + let s = ''; + + s += txt(420, 108, '条形节拍视图(甘特 / 流程图 · 依赖箭头)', { size: 20, weight: 600 }); + s += txt(420, 134, '时间轴与相位角双刻度联动;箭头表示动作间关联(FS 完成-启动 / SS 起始-起始);跨循环动作自动拆分并标注', { size: 13, fill: C.dim }); + + const phases = [ + ['上料相位', 0, 70, '#4cc9f0'], + ['夹紧相位', 55, 115, '#7bd88f'], + ['加工相位', 105, 320, '#ffd166'], + ['检测相位', 300, 345, '#a78bfa'], + ['下料相位', 335, 385, '#f472b6'], + ]; + phases.forEach(([name, a0, a1]) => { + const x = px(a0), w = Math.max(px(Math.min(a1, 360)) - x, 2); + s += rect(x, 152, w, 34, { rx: 6, fill: name.startsWith('下料') ? '#f472b6' : phases.find((p) => p[0] === name)[3], opacity: 0.24 }); + s += rect(x, 152, w, 34, { rx: 6, stroke: phases.find((p) => p[0] === name)[3], sw: 1, opacity: 0.8 }); + if (w > 60) s += txt(x + w / 2, 169, name, { size: 12.5, anchor: 'middle', fill: phases.find((p) => p[0] === name)[3], weight: 600 }); + if (a1 > 360) { + s += rect(X0, 152, px(a1 - 360) - X0, 34, { rx: 6, fill: '#f472b6', opacity: 0.16, dash: '5 5' }); + } + }); + + s += line(X0, 196, X1, 196, { stroke: C.line2, sw: 1 }); + for (let d = 0; d <= 360; d += 15) { + const x = px(d); + const major = d % 30 === 0; + s += line(x, 196, x, major ? 224 : 210, { stroke: major ? C.line2 : C.line, sw: 1 }); + if (d % 60 === 0) s += txt(x, 238, `${d}°`, { size: 12, anchor: 'middle', fill: C.accent }); + if (d % 60 === 0) s += txt(x, 214, `${deg2ms(d)}`, { size: 11, anchor: 'middle', fill: C.dim }); + } + s += txt(X0 - 16, 214, 'ms', { size: 11.5, anchor: 'end', fill: C.dim }); + s += txt(X0 - 16, 238, '相位角', { size: 11.5, anchor: 'end', fill: C.accent }); + + [0, 360].forEach((d) => { + const x = px(d); + s += line(x, 196, x, rowY(7) + 66, { stroke: d === 0 ? C.ok : C.warn, sw: 1.4, dash: '6 6', opacity: 0.7 }); + }); + s += txt(px(0) + 8, 250 + 8, '循环开始 0° / 0 ms', { size: 12, fill: C.ok }); + s += txt(px(360) - 8, 250 + 8, '循环结束 360° / 2400 ms', { size: 12, anchor: 'end', fill: C.warn }); + + ACTIONS.forEach((a, i) => { + const y = rowY(i); + s += rect(420, y - 8, 250, 50, { rx: 10, fill: i % 2 ? 'transparent' : C.panel2, opacity: 0.6 }); + s += rect(432, y + 5, 18, 18, { rx: 5, fill: a.color }); + s += txt(441, y + 14, `${i + 1}`, { size: 11, anchor: 'middle', fill: '#0b1018', weight: 700 }); + s += txt(460, y + 6, `${a.id} ${a.name}`, { size: 14.5, weight: 600 }); + s += txt(460, y + 26, `${a.station} · ${a.driver}`, { size: 11.5, fill: C.dim }); + s += line(X0, y + 33, X1, y + 33, { stroke: C.line, sw: 1, dash: '2 6', opacity: 0.5 }); + }); + + ACTIONS.forEach((a, i) => { + const y = rowY(i); + const x1 = px(a.a0), x2 = px(Math.min(a.a1, 360)); + const w = Math.max(x2 - x1, 4); + s += rect(x1, y, w, BAR_H, { rx: 8, fill: a.color, opacity: 0.92 }); + s += rect(x1, y, w, BAR_H, { rx: 8, stroke: '#ffffff', sw: 1, opacity: a.id === 'A8' ? 0.9 : 0.25 }); + if (a.a1 > 360) { + const wx = px(a.a1 - 360) - X0; + s += rect(X0, y, wx, BAR_H, { rx: 8, fill: a.color, opacity: 0.45, dash: '6 5' }); + s += path(`M ${X0 + 3} ${y + 6} L ${X0 + 3} ${y + BAR_H - 6}`, { stroke: '#ffffff', sw: 2, opacity: 0.8 }); + s += txt(X0 + wx + 10, y + BAR_H / 2, '↩ 跨循环延续 25°', { size: 11.5, fill: C.warn }); + } + const inside = w > 150; + if (inside) { + s += txt(x1 + 12, y + 13, `${a.name}`, { size: 13.5, fill: '#0a0f18', weight: 700 }); + s += txt(x1 + 12, y + 26, `${deg2ms(a.a1 - a.a0)} ms`, { size: 11, fill: '#0a0f18', opacity: 0.8 }); + } else if (x2 + 150 > X1) { + s += txt(x1 - 10, y + BAR_H / 2, `${a.name} ${deg2ms(a.a1 - a.a0)}ms`, { size: 12.5, fill: a.color, weight: 600, anchor: 'end' }); + } else { + s += txt(x2 + 10, y + BAR_H / 2, `${a.name} ${deg2ms(a.a1 - a.a0)}ms`, { size: 12.5, fill: a.color, weight: 600 }); + } + s += txt(px(360) + 14, y + BAR_H / 2, `Δ${fmt(a.a1 - a.a0, 0)}°`, { size: 12, fill: C.dim }); + }); + + const marker = (id, atEnd) => { + const a = byId(id); + const i = ACTIONS.indexOf(a); + const y = rowY(i) + BAR_H / 2; + const x = px(atEnd ? Math.min(a.a1, 360) : a.a0); + return [x, y]; + }; + + DEPS.forEach((d, k) => { + const a = byId(d.from), b = byId(d.to); + const ia = ACTIONS.indexOf(a), ib = ACTIONS.indexOf(b); + const fromEnd = d.type === 'FS'; + const [sx, sy] = marker(d.from, fromEnd); + const [tx, ty] = marker(d.to, false); + const col = d.type === 'FS' ? C.ok : C.warn; + const jx = sx + 16 + (k % 3) * 14; + const pathD = `M ${sx} ${sy} L ${jx} ${sy} L ${jx} ${ty} L ${tx - 12} ${ty}`; + s += path(pathD, { stroke: col, sw: 1.6, dash: '5 4', opacity: 0.9 }); + s += path(`M ${tx - 12} ${ty} l -9 -5.5 l 0 11 z`, { fill: col }); + const mx = tx - 46; + s += rect(mx - 34, ty - 46, 68, 18, { rx: 5, fill: '#0b1018', stroke: col, sw: 0.8 }); + s += txt(mx, ty - 37, d.type === 'FS' ? 'FS' : `SS +${d.off}°`, { size: 10.5, anchor: 'middle', fill: col, weight: 600 }); + if (Math.abs(ia - ib) > 1) { + s += line(jx, sy, jx, ty, { stroke: col, sw: 1.2, opacity: 0.35, dash: '3 5' }); + } + }); + + s += rect(420, 860, 640, 300, { rx: 14, fill: C.panel2, stroke: C.line, sw: 1, opacity: 0.96 }); + s += txt(444, 892, '节拍统计', { size: 15, weight: 600, fill: C.sub }); + const stats = [ + ['循环周期', '2400 ms / 360°'], + ['动作数量', '8(3 工位)'], + ['关键路径', 'A1 → A2 → A3 → A4 → A6 → A7'], + ['最大并行度', '3 个动作同时执行(185°–190°)'], + ['相位覆盖率', '100%(0°–360° 无空档 > 15°)'], + ['瓶颈工位', 'ST2 加工相位 105°–320°(215°)'], + ['预估节拍', '2.400 s / 件 · 1500 件/小时'], + ]; + stats.forEach(([k, v], i) => { + const y = 926 + i * 32; + s += txt(444, y, k, { size: 13, fill: C.dim }); + s += txt(1036, y, v, { size: 13, anchor: 'end', fill: '#cfd9ea', weight: 600 }); + if (i < stats.length - 1) s += line(444, y + 15, 1036, y + 15, { stroke: C.line, sw: 1, opacity: 0.6 }); + }); + + const cx = 1890, cy = 1120, R0 = 40, PITCH = 18, PW = 10; + const outer = R0 + 7 * PITCH; + s += rect(1640, 860, 500, 480, { rx: 14, fill: C.panel2, stroke: C.line, sw: 1, opacity: 0.96 }); + s += txt(1664, 892, '圆周节拍预览(实时联动)', { size: 15, weight: 600, fill: C.sub }); + s += circle(cx, cy, outer + PW + 14, { fill: '#0c1320', stroke: C.line, sw: 1 }); + ACTIONS.forEach((a, i) => { + const r = R0 + i * PITCH; + const segs = ringArcs(cx, cy, r, a.a0, a.a1); + segs.forEach((d, k) => { + const tail = a.a1 > 360 && k === 1; + s += path(d, { stroke: a.color, sw: PW, cap: a.a1 > 360 ? 'butt' : 'round', opacity: tail ? 0.45 : 0.95 }); + }); + }); + s += path(`M ${cx} ${cy - outer - PW - 22} l -8 -13 l 16 0 z`, { fill: C.accent }); + s += txt(cx, cy - 6, '360°', { size: 15, anchor: 'middle', fill: C.sub, weight: 600 }); + s += txt(cx, cy + 16, '1 循环 = 2400 ms', { size: 11.5, anchor: 'middle', fill: C.dim }); + s += txt(1664, 1322, '12 点钟起始 · 顺时针 · 每层一环', { size: 12, fill: C.dim }); + return s; +} + +function build(mode) { + const grid = `` + + `` + + `` + + ``; + let s = ``; + s += grid; + s += rect(0, 0, W, H, { fill: C.bg }); + s += rect(380, 64, W - 380 - 420, H - 64 - 36, { fill: 'url(#canvasGrad)' }); + s += rect(380, 64, W - 380 - 420, H - 64 - 36, { fill: 'url(#grid)' }); + s += mode === 'bar' ? barView() : circularView(); + s += leftPanel(mode, mode === 'bar' ? 'A8' : 'A3'); + s += mode === 'bar' ? rightPanelBar() : rightPanelCircular(); + s += chrome(mode); + s += ''; + return s; +} + +writeFileSync(join(OUT, 'circular-timing.svg'), build('circular'), 'utf8'); +writeFileSync(join(OUT, 'bar-timing.svg'), build('bar'), 'utf8'); +console.log('generated:', join(OUT, 'circular-timing.svg'), join(OUT, 'bar-timing.svg'));