Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b902fa06c4 | |||
| c352af2359 | |||
| 7dcb95db4a | |||
| d0e6ce457e | |||
| 233a329c0a | |||
| f4ef9b32a5 | |||
| fe2008b604 | |||
| 440e017203 | |||
| 81d0d1768a | |||
| c32be46adb |
@@ -36,3 +36,6 @@ desktop.ini
|
||||
/release/*.apk
|
||||
/sequence_diagram/
|
||||
/*.7z
|
||||
|
||||
# 截图比对失败产物(flutter test 自动生成)
|
||||
test/failures/
|
||||
|
||||
+1
-1
@@ -127,7 +127,7 @@ flutter pub get
|
||||
flutter build apk --release # 产物:build\app\outputs\flutter-apk\app-release.apk
|
||||
```
|
||||
|
||||
- 发布包归档:`release\sequence_diagram_android_v1.2.0_release.apk`(**本地保留,不入库**;exe 的 `dist\` 同理)。
|
||||
- 发布包归档:`release\sequence_diagram_android_v1.2.3_release.apk`(**本地保留,不入库**;exe 的 `dist\` 同理)。
|
||||
- 上架应用商店时建议在 `android\app\build.gradle.kts` 配置正式签名后再构建 AAB:
|
||||
`flutter build appbundle --release`。
|
||||
- 应用名「时序图设计」、包名 `cc.sincos.sequence_diagram`、launcher 图标由
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
- **深色 / 浅色双主题**:右上角 ☀ / ☾ 一键切换,语义颜色不变,导出 SVG 与屏幕一致
|
||||
- **导出 SVG**:矢量、分层、带语义 `id` / `data-*` 元数据,可直接进工艺卡与 MES
|
||||
|
||||
## 正式版 V1.2.0
|
||||
## 正式版 V1.2.3
|
||||
|
||||
**可运行的 Flutter Windows 桌面正式版**(源码在 `lib/`),设计人:呆头鹅。
|
||||
|
||||
@@ -97,7 +97,7 @@ Flutter 3.29+(Desktop) · CustomPainter 自绘 · Riverpod · 不可变模
|
||||
- **正式签名**:release 用独立 keystore 签名(`android/key/release.jks`,见 `BUILD-NOTES.md`),更新安装无需卸载重装;
|
||||
- **构建**:JDK 17 + Android SDK 36(详见 `BUILD-NOTES.md`),Gradle 与 Maven 已配置国内镜像:
|
||||
```bash
|
||||
flutter build apk --release # 产物 → release/sequence_diagram_android_v1.2.0_release.apk
|
||||
flutter build apk --release # 产物 → release/sequence_diagram_android_v1.2.3_release.apk
|
||||
```
|
||||
- **自测**:`test/tablet_layout_test.dart` 覆盖 1280×800、2560×1600、960×600、800×480、竖屏 800×1280、600×960 等 7 种分辨率的无溢出回归;
|
||||
- **demo 图**:`demo/tablet-*.png`(由 `test/tablet_screenshots_test.dart` 生成)。
|
||||
@@ -113,6 +113,6 @@ Flutter 3.29+(Desktop) · CustomPainter 自绘 · Riverpod · 不可变模
|
||||
|
||||
- **软件**:时序图设计 · Sequence Diagram Studio
|
||||
- **设计人**:呆头鹅
|
||||
- **版本**:V1.2.0
|
||||
- **版本**:V1.2.3
|
||||
- **版权**:Copyright © 2026 呆头鹅。保留所有权利。
|
||||
- **架构文档**:[`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) · **使用帮助**:[`docs/HELP.md`](docs/HELP.md)
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
android:maxSdkVersion="28" />
|
||||
<!-- 应用内更新 / AI 生成:网络访问(release 包必须显式声明,否则无法联网)。 -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!-- 应用内更新:允许拉起系统安装器安装新版本 APK(Android 8.0+)。 -->
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<application
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:label="时序图设计"
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 应用内更新:仅对本项目更新服务器的明文 HTTP 放行(其余域名仍禁止明文)。 -->
|
||||
<network-security-config>
|
||||
<domain-config cleartextTrafficPermitted="true">
|
||||
<domain includeSubdomains="false">124.220.63.9</domain>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1791509219509" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6625" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M512 66c246.319 0 446 199.681 446 446S758.319 958 512 958 66 758.319 66 512 265.681 66 512 66z m0 59.773c-213.307 0-386.227 172.92-386.227 386.227S298.693 898.227 512 898.227 898.227 725.307 898.227 512 725.307 125.773 512 125.773z m128.12 636.815c16.506 0 29.887 13.38 29.887 29.886 0 16.27-13.001 29.504-29.181 29.879l-0.705 0.008H390.156c-16.506 0-29.887-13.38-29.887-29.887 0-16.27 13.001-29.503 29.181-29.878l0.706-0.008H640.12z m0-92.135c16.506 0 29.887 13.381 29.887 29.887 0 16.27-13.001 29.504-29.181 29.878l-0.705 0.008H390.156c-16.506 0-29.887-13.38-29.887-29.886 0-16.27 13.001-29.504 29.181-29.879l0.706-0.008H640.12zM494.114 207.261c11.503-10.613 29.245-10.554 40.677 0.135l247.338 231.266c19.804 18.517 6.7 51.717-20.412 51.717H658.61v118.087c0 16.27-13 29.503-29.18 29.878l-0.706 0.008H398.532c-16.506 0-29.887-13.38-29.887-29.886l-0.002-118.088H263.711c-26.937 0-40.002-32.737-20.856-51.294l0.59-0.558z m20.128 62.752L340.177 430.605h58.355c16.27 0 29.504 13.001 29.878 29.182l0.008 0.705-0.002 118.086h170.42l0.002-118.086c0-16.27 13-29.504 29.18-29.878l0.706-0.009h57.269L514.24 270.013z" fill="#333333" p-id="6626"></path></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,225 @@
|
||||
/// drawio 导出写入器:把流程图序列化为 diagrams.net(draw.io)可编辑的 `.drawio` 文件。
|
||||
///
|
||||
/// 架构位置:
|
||||
/// - 仅流程图视图支持(条形 / 圆周视图只有 SVG / PNG 两种导出);
|
||||
/// - 几何完全复用 [FlowLayout](与屏幕画布、SVG 导出同一套坐标与走线),
|
||||
/// 保证三种载体(画布 / drawio / SVG)内容一致;
|
||||
/// - 输出标准 `<mxfile>` 文档:节点保留动作颜色与「时长 · 工位」语义,
|
||||
/// 连线保留 FS / SS 类型与偏移角标签,泳道为背景带、相位为竖排文字带,
|
||||
/// 导入 draw.io 后可直接继续排布与编辑。
|
||||
///
|
||||
/// 输出约定:
|
||||
/// - 坐标与原画布 1:1(不缩放),原点同样在左上角;
|
||||
/// - 页面尺寸按内容范围自动设置,四边各留 [_pad] 留白,整体平移到页内;
|
||||
/// - 不写入时间戳等易变字段,保证同一工程多次导出结果稳定(便于测试与归档)。
|
||||
library;
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
/// drawio 文档写入器。
|
||||
///
|
||||
/// 通过内部 [StringBuffer] 逐段拼接 XML,最终由 [build] 返回完整文档。
|
||||
class DrawioWriter {
|
||||
/// 创建写入器。
|
||||
///
|
||||
/// 参数:
|
||||
/// - [project]:数据源(动作、依赖、相位分区、单位);
|
||||
/// - [tokens]:配色令牌(内部转为导出专用纯白主题,与 SVG / PNG 一致)。
|
||||
///
|
||||
/// 构造时不生成任何内容;调用 [build] 才写出文档。
|
||||
DrawioWriter({required this.project, required Tokens tokens})
|
||||
: tokens = exportTokens(tokens);
|
||||
|
||||
/// 数据源工程。
|
||||
final Project project;
|
||||
/// 导出专用配色令牌。
|
||||
final Tokens tokens;
|
||||
|
||||
/// 页内留白(四周各留的空白,逻辑像素)。
|
||||
static const double _pad = 40;
|
||||
|
||||
/// 输出缓冲区,累积 XML 文本片段。
|
||||
final StringBuffer _b = StringBuffer();
|
||||
|
||||
/// 生成完整 drawio 文档字符串。
|
||||
///
|
||||
/// 返回:以 `<mxfile>` 开头、`</mxfile>` 结尾的字符串。
|
||||
/// 副作用:会持续向内部缓冲区追加内容;约定每次导出新建实例。
|
||||
String build() {
|
||||
final FlowLayout layout = FlowLayout(project);
|
||||
if (layout.nodes.isEmpty) {
|
||||
return '<mxfile host="app.diagrams.net"><diagram id="flow" name="流程图">'
|
||||
'<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root>'
|
||||
'</mxGraphModel></diagram></mxfile>';
|
||||
}
|
||||
// 平移到页内:原点统一挪到 (pad, pad),页面尺寸随内容自适应。
|
||||
final double ox = _pad - layout.bounds.left;
|
||||
final double oy = _pad - layout.bounds.top;
|
||||
final int pageW = (layout.bounds.width + _pad * 2).ceil();
|
||||
final int pageH = (layout.bounds.height + _pad * 2).ceil();
|
||||
|
||||
_b.write('<mxfile host="app.diagrams.net" agent="Sequence Diagram Studio" '
|
||||
'version="24.7.8" type="device">');
|
||||
_b.write('<diagram id="flow" name="${_esc(project.name.isEmpty ? '流程图' : project.name)}">');
|
||||
_b.write('<mxGraphModel dx="1600" dy="900" grid="1" gridSize="10" guides="1" '
|
||||
'tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" '
|
||||
'pageWidth="$pageW" pageHeight="$pageH" math="0" shadow="0">');
|
||||
_b.write('<root>');
|
||||
_b.write('<mxCell id="0"/>');
|
||||
_b.write('<mxCell id="1" parent="0"/>');
|
||||
|
||||
_lanes(layout, ox, oy);
|
||||
_phases(layout, ox, oy);
|
||||
_edges(layout);
|
||||
_nodes(layout, ox, oy);
|
||||
|
||||
_b.write('</root></mxGraphModel></diagram></mxfile>');
|
||||
return _b.toString();
|
||||
}
|
||||
|
||||
/// 写入泳道背景带与轨道标题(原样平移)。
|
||||
void _lanes(FlowLayout layout, double ox, double oy) {
|
||||
final double lanePitch = FlowLayout.nodeW + FlowLayout.laneGap;
|
||||
final double top = layout.bounds.top + 20 + oy;
|
||||
final double bottom = layout.bounds.bottom - 20 + oy;
|
||||
for (int i = 0; i < layout.lanes.length; i++) {
|
||||
final double cx = FlowLayout.marginX + i * lanePitch + FlowLayout.nodeW / 2 + ox;
|
||||
_rectCell(
|
||||
'lane-${layout.lanes[i]}',
|
||||
'轨道 L${i + 1}',
|
||||
cx - FlowLayout.nodeW / 2 - 26,
|
||||
top,
|
||||
FlowLayout.nodeW + 52,
|
||||
bottom - top,
|
||||
'rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;fontSize=11;fontStyle=1;'
|
||||
'fillColor=${_hex(i.isEven ? tokens.ringA : tokens.ringB)};fillOpacity=55;'
|
||||
'strokeColor=none;fontColor=${_hex(tokens.sub)};',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入相位竖带:竖排文字(`horizontal=0`)+ 低透明度填充,台阶错位保持一致。
|
||||
void _phases(FlowLayout layout, double ox, double oy) {
|
||||
final double rowPitch = FlowLayout.nodeH + FlowLayout.rankGap;
|
||||
for (int i = 0; i < layout.spans.length; i++) {
|
||||
final FlowPhaseSpan s = layout.spans[i];
|
||||
final double top = FlowLayout.marginY + s.rankTop * rowPitch - 6 + oy;
|
||||
final double bottom =
|
||||
FlowLayout.marginY + s.rankBottom * rowPitch + FlowLayout.nodeH + 6 + oy;
|
||||
final double left = FlowLayout.railX + s.slot * FlowLayout.railStep + ox;
|
||||
_rectCell(
|
||||
'phase-$i',
|
||||
s.zone.name,
|
||||
left,
|
||||
top,
|
||||
FlowLayout.railW,
|
||||
bottom - top,
|
||||
'rounded=1;whiteSpace=wrap;html=1;horizontal=0;fontSize=10;fontStyle=1;'
|
||||
'fillColor=${_hex(tokens.accent)};fillOpacity=10;'
|
||||
'strokeColor=${_hex(tokens.accent)};strokeOpacity=45;fontColor=${_hex(tokens.sub)};',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入动作节点与开始 / 结束胶囊。
|
||||
void _nodes(FlowLayout layout, double ox, double oy) {
|
||||
for (final FlowNode n in layout.nodes) {
|
||||
final Rect r = n.rect;
|
||||
if (n.isStart || n.isEnd) {
|
||||
_rectCell(
|
||||
_cellId(n.id),
|
||||
n.title,
|
||||
r.left + ox,
|
||||
r.top + oy,
|
||||
r.width,
|
||||
r.height,
|
||||
'ellipse;whiteSpace=wrap;html=1;fontSize=13;fontStyle=1;'
|
||||
'fillColor=${_hex(tokens.panel2)};strokeColor=${_hex(tokens.accent)};'
|
||||
'fontColor=${_hex(tokens.accent)};',
|
||||
);
|
||||
continue;
|
||||
}
|
||||
final Action a = n.action!;
|
||||
// 节点两行文字:标题(序号. 名称)+ 副标题(时长 · 工位)。
|
||||
_rectCell(
|
||||
_cellId(n.id),
|
||||
'${n.title}\n${n.subtitle}',
|
||||
r.left + ox,
|
||||
r.top + oy,
|
||||
r.width,
|
||||
r.height,
|
||||
'rounded=1;absoluteArcSize=1;arcSize=10;whiteSpace=wrap;html=1;fontSize=12;fontStyle=1;'
|
||||
'fillColor=${_hex(Color(a.color))};fillOpacity=92;'
|
||||
'strokeColor=${_hex(tokens.selOutline)};strokeOpacity=25;'
|
||||
'fontColor=${_hex(tokens.arcText)};',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入依赖连线:以 source / target 引用节点,drawio 自动正交布线并可再编辑。
|
||||
///
|
||||
/// 样式与画布一致:FS 绿实线、SS 琥珀虚线(标签标注偏移角)、关键路径加粗。
|
||||
void _edges(FlowLayout layout) {
|
||||
int i = 0;
|
||||
for (final FlowEdge e in layout.edges) {
|
||||
i++;
|
||||
final bool fs = e.type == DepType.fs;
|
||||
final String col =
|
||||
_hex(e.type == null ? tokens.sub : (fs ? tokens.fs : tokens.ss));
|
||||
final String label = switch (e.type) {
|
||||
null => '',
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
_b.write('<mxCell id="edge-$i-${_cellId(e.fromId)}-${_cellId(e.toId)}" '
|
||||
'value="${_esc(label)}" '
|
||||
'style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;jettySize=auto;'
|
||||
'orthogonalLoop=1;endArrow=block;endFill=1;'
|
||||
'strokeWidth=${e.critical ? 2.4 : 1.3};strokeColor=$col;'
|
||||
'${e.type == DepType.ss ? 'dashed=1;dashPattern=6 4;' : ''}'
|
||||
'fontSize=9;fontColor=$col;labelBackgroundColor=${_hex(tokens.bg)};" '
|
||||
'edge="1" parent="1" source="${_cellId(e.fromId)}" target="${_cellId(e.toId)}">'
|
||||
'<mxGeometry relative="1" as="geometry"/></mxCell>');
|
||||
}
|
||||
}
|
||||
|
||||
/// 写入一个顶点(矩形 / 胶囊 / 竖带)单元格。
|
||||
void _rectCell(String id, String value, double x, double y, double w, double h,
|
||||
String style) {
|
||||
_b.write('<mxCell id="$id" value="${_esc(value)}" '
|
||||
'style="$style" vertex="1" parent="1">'
|
||||
'<mxGeometry x="${x.toStringAsFixed(1)}" y="${y.toStringAsFixed(1)}" '
|
||||
'width="${w.toStringAsFixed(1)}" height="${h.toStringAsFixed(1)}" as="geometry"/>'
|
||||
'</mxCell>');
|
||||
}
|
||||
|
||||
/// 节点 id → drawio 单元格 id:开始 / 结束用可读短名,其余原样保留。
|
||||
static String _cellId(String nodeId) {
|
||||
if (nodeId == FlowNode.startId) return 'flow-start';
|
||||
if (nodeId == FlowNode.endId) return 'flow-end';
|
||||
return nodeId.replaceAll(RegExp(r'[^A-Za-z0-9_-]'), '_');
|
||||
}
|
||||
|
||||
/// 转义 XML 文本 / 属性中的特殊字符;换行转为 ` `(drawio 多行标签约定)。
|
||||
static String _esc(String s) => s
|
||||
.replaceAll('&', '&')
|
||||
.replaceAll('<', '<')
|
||||
.replaceAll('>', '>')
|
||||
.replaceAll('"', '"')
|
||||
.replaceAll('\n', ' ');
|
||||
|
||||
/// 把 Flutter [Color] 转为 `#rrggbb` 字符串(忽略 alpha)。
|
||||
static String _hex(Color c) {
|
||||
final int r = (c.r * 255).round();
|
||||
final int g = (c.g * 255).round();
|
||||
final int b = (c.b * 255).round();
|
||||
return '#${r.toRadixString(16).padLeft(2, '0')}${g.toRadixString(16).padLeft(2, '0')}${b.toRadixString(16).padLeft(2, '0')}';
|
||||
}
|
||||
}
|
||||
+20
-10
@@ -13,6 +13,7 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
@@ -54,10 +55,14 @@ ExportFit computeExportFit(Project project, ViewMode mode, Rect area) {
|
||||
final int n = l.lanes.length;
|
||||
final double bottom = n == 0 ? BarLayout.topPad + BarLayout.rowVisual : l.yFor(n) + BarLayout.rowVisual + 8;
|
||||
bounds = Rect.fromLTRB(12, BarPainter.phaseBandTop - 14, l.plotRight + 120, bottom);
|
||||
} else {
|
||||
} else if (mode == ViewMode.circular) {
|
||||
final CircularLayout l = CircularLayout(project, kExportSize);
|
||||
final double rExt = l.tickR + 100;
|
||||
bounds = Rect.fromLTRB(l.center.dx - rExt, l.center.dy - rExt, l.center.dx + rExt, l.center.dy + rExt);
|
||||
} else {
|
||||
// 流程图:直接使用布局层给出的内容范围(含泳道、阶段栏与连线)。
|
||||
final FlowLayout l = FlowLayout(project);
|
||||
bounds = l.nodes.isEmpty ? const Rect.fromLTWH(0, 0, 800, 600) : l.bounds;
|
||||
}
|
||||
if (bounds.width <= 1 || bounds.height <= 1) {
|
||||
return const ExportFit(1, 0, 0);
|
||||
@@ -69,16 +74,21 @@ ExportFit computeExportFit(Project project, ViewMode mode, Rect area) {
|
||||
}
|
||||
|
||||
/// 导出标题(与画布浮层一致)。
|
||||
String exportTitle(ViewMode mode) =>
|
||||
mode == ViewMode.bar ? '条形时序视图' : '圆周时序视图';
|
||||
String exportTitle(ViewMode mode) => switch (mode) {
|
||||
ViewMode.bar => '条形时序视图',
|
||||
ViewMode.circular => '圆周时序视图',
|
||||
ViewMode.flow => '流程图视图',
|
||||
};
|
||||
|
||||
/// 导出副标题(与画布浮层一致)。
|
||||
String exportSubtitle(Project project, ViewMode mode) {
|
||||
if (mode == ViewMode.bar) {
|
||||
return '箭头表示动作之间关联(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)';
|
||||
}
|
||||
return '同心圆环 = 动作层 · 1 圈 = 1 循环 = ${tfmt(project.cycle.durationMs, project.units)} = 360° = 100%';
|
||||
}
|
||||
/// 导出副标题:仅保留括号内的线型图例(与画布标题后方的说明一致)。
|
||||
///
|
||||
/// 更完整的视图语义(同心圆环 / 循环换算等)见应用内「帮助」。
|
||||
String exportSubtitle(ViewMode mode) => switch (mode) {
|
||||
ViewMode.bar => '(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)',
|
||||
ViewMode.circular => '(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)',
|
||||
// 流程图不重复线型说明,导出仅保留标题(与画布浮层一致)。
|
||||
ViewMode.flow => '',
|
||||
};
|
||||
|
||||
/// 导出图例(左下角固定)。
|
||||
String exportLegend(Project project) =>
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:flutter/material.dart' hide Action;
|
||||
import '../model/models.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../render/circular_painter.dart';
|
||||
import '../render/flow_painter.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
@@ -48,7 +49,7 @@ Future<Uint8List> renderExportPng({
|
||||
final ViewMode mode = project.viewState.mode;
|
||||
_text(canvas, exportTitle(mode), const Offset(48, 36),
|
||||
color: et.text, size: 34, weight: FontWeight.w700);
|
||||
_text(canvas, exportSubtitle(project, mode), const Offset(48, 88),
|
||||
_text(canvas, exportSubtitle(mode), const Offset(48, 88),
|
||||
color: et.sub, size: 16, weight: FontWeight.w400);
|
||||
|
||||
// 内容:适配缩放并居中到内容区。
|
||||
@@ -64,6 +65,14 @@ Future<Uint8List> renderExportPng({
|
||||
criticalDeps: criticalDeps,
|
||||
selectedIds: const <String>{},
|
||||
).paint(canvas, kExportSize);
|
||||
} else if (mode == ViewMode.flow) {
|
||||
FlowchartPainter(
|
||||
project: project,
|
||||
tokens: et,
|
||||
criticalActions: criticalActions,
|
||||
criticalDeps: criticalDeps,
|
||||
selectedIds: const <String>{},
|
||||
).paint(canvas, kExportSize);
|
||||
} else {
|
||||
CircularPainter(
|
||||
project: project,
|
||||
|
||||
+109
-6
@@ -21,6 +21,7 @@ import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../theme/tokens.dart';
|
||||
@@ -78,15 +79,17 @@ class SvgWriter {
|
||||
// 标题:固定左上角。
|
||||
_b.write('<g id="title">');
|
||||
_text(48, 60, exportTitle(mode), color: _hex(tokens.text), size: 34, weight: '700');
|
||||
_text(48, 104, exportSubtitle(project, mode), color: _hex(tokens.sub), size: 16);
|
||||
_text(48, 104, exportSubtitle(mode), color: _hex(tokens.sub), size: 16);
|
||||
_b.write('</g>');
|
||||
// 内容:适配缩放并居中到内容区。
|
||||
final ExportFit fit = computeExportFit(project, mode, kExportContentArea);
|
||||
_b.write('<g id="content" transform="${fit.svgTransform}">');
|
||||
if (mode == ViewMode.bar) {
|
||||
_barView(const Size(w, h));
|
||||
} else {
|
||||
} else if (mode == ViewMode.circular) {
|
||||
_circularView(const Size(w, h));
|
||||
} else {
|
||||
_flowView();
|
||||
}
|
||||
_b.write('</g>');
|
||||
// 图例:固定左下角。
|
||||
@@ -144,7 +147,7 @@ class SvgWriter {
|
||||
final Color c = Color(a.color);
|
||||
_b.write('<g id="${_esc(a.id)}" data-action="${_esc(a.id)}" data-start="${a.startAngle}" '
|
||||
'data-duration="${a.durationAngle}" data-layer="${a.layer}" data-station="${_esc(a.stationId)}">');
|
||||
_rect(r.left, r.top, r.width, r.height, fill: _hex(c), rx: 7, opacity: 0.92);
|
||||
_rect(r.left, r.top, r.width, r.height, fill: _hex(c), rx: 3, opacity: 0.92);
|
||||
_text(r.left + 8, r.center.dy + 4, '${a.name} ${tfmt(a.durationAngle / 360 * cycle, u)}',
|
||||
color: _hex(tokens.arcText), size: 12, weight: '700');
|
||||
_b.write('</g>');
|
||||
@@ -231,7 +234,7 @@ class SvgWriter {
|
||||
'data-duration="${a.durationAngle}" data-layer="${a.layer}" data-station="${_esc(a.stationId)}">');
|
||||
for (final List<double> s in splitArcs(a.startAngle, a.endAngle)) {
|
||||
final String d = _arc(c, r, s[0], s[1]);
|
||||
_b.write('<path d="$d" fill="none" stroke="${_hex(col)}" stroke-width="$th" stroke-linecap="round"/>');
|
||||
_b.write('<path d="$d" fill="none" stroke="${_hex(col)}" stroke-width="$th" stroke-linecap="butt"/>');
|
||||
}
|
||||
final Offset mp = polar(c, r, (a.startAngle + a.endAngle) / 2);
|
||||
_text(mp.dx, mp.dy, '${a.id} ${a.name}', color: _hex(tokens.arcText), size: 12, anchor: 'middle', weight: '700');
|
||||
@@ -273,6 +276,104 @@ class SvgWriter {
|
||||
}
|
||||
}
|
||||
|
||||
/// 生成流程图视图的 SVG 内容。
|
||||
///
|
||||
/// 几何完全复用 [FlowLayout](与屏幕画布、drawio 导出共用同一套走线),
|
||||
/// 依次输出:
|
||||
/// - `g#lanes`:泳道背景带与轨道标题;
|
||||
/// - `g#phases`:左侧相位竖带(分区名旋转 90°,重叠分区台阶错位);
|
||||
/// - `g#edges`:依赖折线(FS 实线 / SS 虚线,带箭头与 FS/SS 标签);
|
||||
/// - `g#actions`:动作节点与开始 / 结束胶囊(带 data-* 语义属性)。
|
||||
void _flowView() {
|
||||
final FlowLayout layout = FlowLayout(project);
|
||||
if (layout.nodes.isEmpty) return;
|
||||
|
||||
// 泳道背景带(与画布一致:环带色 55% 透明度 + 轨道标题)。
|
||||
_b.write('<g id="lanes">');
|
||||
final double lanePitch = FlowLayout.nodeW + FlowLayout.laneGap;
|
||||
final double top = layout.bounds.top + 20;
|
||||
final double bottom = layout.bounds.bottom - 20;
|
||||
for (int i = 0; i < layout.lanes.length; i++) {
|
||||
final double cx = FlowLayout.marginX + i * lanePitch + FlowLayout.nodeW / 2;
|
||||
_rect(cx - FlowLayout.nodeW / 2 - 26, top, FlowLayout.nodeW + 52, bottom - top,
|
||||
fill: _hex(i.isEven ? tokens.ringA : tokens.ringB), rx: 14, opacity: 0.55);
|
||||
_text(cx, top + 16, '轨道 L${i + 1}',
|
||||
color: _hex(tokens.sub), size: 11, anchor: 'middle', weight: '700');
|
||||
}
|
||||
_b.write('</g>');
|
||||
|
||||
// 相位竖带:窄带 + 旋转 90° 分区名,纵向对齐流程行、重叠分区台阶错位。
|
||||
_b.write('<g id="phases">');
|
||||
final double rowPitch = FlowLayout.nodeH + FlowLayout.rankGap;
|
||||
for (final FlowPhaseSpan s in layout.spans) {
|
||||
final double pTop = FlowLayout.marginY + s.rankTop * rowPitch - 6;
|
||||
final double pBottom =
|
||||
FlowLayout.marginY + s.rankBottom * rowPitch + FlowLayout.nodeH + 6;
|
||||
final double left = FlowLayout.railX + s.slot * FlowLayout.railStep;
|
||||
_rect(left, pTop, FlowLayout.railW, pBottom - pTop,
|
||||
fill: _hex(tokens.accent), rx: 9, opacity: 0.10);
|
||||
_rect(left, pTop, FlowLayout.railW, pBottom - pTop,
|
||||
fill: 'none', rx: 9, stroke: _hex(tokens.accent), sw: 1, opacity: 0.45);
|
||||
final double tx = left + FlowLayout.railW / 2;
|
||||
final double ty = (pTop + pBottom) / 2;
|
||||
_b.write('<text transform="translate(${tx.toStringAsFixed(1)} ${ty.toStringAsFixed(1)}) rotate(-90)" '
|
||||
'font-family="$_font" font-size="10.5" fill="${_hex(tokens.sub)}" text-anchor="middle" '
|
||||
'dominant-baseline="middle" font-weight="700">${_esc(s.zone.name)}</text>');
|
||||
}
|
||||
_b.write('</g>');
|
||||
|
||||
// 依赖折线:FS 实线 / SS 虚线,带箭头与 FS/SS 标签。
|
||||
_b.write('<g id="edges">');
|
||||
for (final FlowEdgeRoute r in layout.routes) {
|
||||
final FlowEdge e = r.edge;
|
||||
final bool fs = e.type == DepType.fs;
|
||||
final String col = _hex(e.type == null ? tokens.sub : (fs ? tokens.fs : tokens.ss));
|
||||
final String d = <String>[
|
||||
for (int i = 0; i < r.points.length; i++)
|
||||
'${i == 0 ? 'M' : 'L'} ${r.points[i].dx.toStringAsFixed(1)} ${r.points[i].dy.toStringAsFixed(1)}',
|
||||
].join(' ');
|
||||
final String marker = e.type == null ? '' : ' marker-end="url(#arrow-${fs ? 'fs' : 'ss'})"';
|
||||
final String dash = r.dashed ? ' stroke-dasharray="6 4"' : '';
|
||||
_b.write('<path d="$d" fill="none" stroke="$col" stroke-width="${e.critical ? 2 : 1.3}"'
|
||||
'$dash$marker/>');
|
||||
if (e.type != null) {
|
||||
final String text = switch (e.type!) {
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
_text(r.labelAt.dx, r.labelAt.dy, text,
|
||||
color: col, size: 9, anchor: 'middle', weight: '600');
|
||||
}
|
||||
}
|
||||
_b.write('</g>');
|
||||
|
||||
// 动作节点与开始 / 结束胶囊。
|
||||
_b.write('<g id="actions">');
|
||||
for (final FlowNode n in layout.nodes) {
|
||||
final Rect r = n.rect;
|
||||
if (n.isStart || n.isEnd) {
|
||||
_rect(r.left, r.top, r.width, r.height,
|
||||
fill: _hex(tokens.panel2), rx: r.height / 2, stroke: _hex(tokens.accent), sw: 1.2);
|
||||
_text(r.center.dx, r.center.dy, n.title,
|
||||
color: _hex(tokens.accent), size: 13, anchor: 'middle', weight: '700');
|
||||
continue;
|
||||
}
|
||||
final Action a = n.action!;
|
||||
final Color c = Color(a.color);
|
||||
_b.write('<g id="${_esc(n.id)}" data-action="${_esc(n.id)}" data-start="${a.startAngle}" '
|
||||
'data-duration="${a.durationAngle}" data-layer="${a.layer}" data-station="${_esc(a.stationId)}">');
|
||||
_rect(r.left, r.top, r.width, r.height, fill: _hex(c), rx: 10, opacity: 0.92);
|
||||
_text(r.center.dx, r.top + 21, n.title,
|
||||
color: _hex(tokens.arcText), size: 12, anchor: 'middle', weight: '700');
|
||||
_text(r.center.dx, r.top + 41, n.subtitle,
|
||||
color: _hex(tokens.arcText), size: 10, anchor: 'middle');
|
||||
_b.write('</g>');
|
||||
}
|
||||
_b.write('</g>');
|
||||
}
|
||||
|
||||
/// 生成一段圆弧的 SVG `d` 路径字符串。
|
||||
///
|
||||
/// 参数 [c] 圆心、[r] 半径、[a0]/[a1] 起止角度(度)。
|
||||
@@ -290,9 +391,11 @@ class SvgWriter {
|
||||
///
|
||||
/// 参数为位置与尺寸;可选 [fill] 填充色、[rx] 圆角半径、[opacity] 透明度。
|
||||
void _rect(double x, double y, double w, double h,
|
||||
{String? fill, double rx = 0, double opacity = 1}) {
|
||||
{String? fill, double rx = 0, double opacity = 1, String? stroke, double sw = 1}) {
|
||||
_b.write('<rect x="${x.toStringAsFixed(1)}" y="${y.toStringAsFixed(1)}" width="${w.toStringAsFixed(1)}" '
|
||||
'height="${h.toStringAsFixed(1)}" rx="$rx" fill="${fill ?? 'none'}" opacity="$opacity"/>');
|
||||
'height="${h.toStringAsFixed(1)}" rx="$rx" fill="${fill ?? 'none'}" opacity="$opacity"'
|
||||
'${stroke == null ? '' : ' stroke="$stroke" stroke-width="$sw"'}'
|
||||
'/>');
|
||||
}
|
||||
|
||||
/// 写入一个 `<circle>` 元素。
|
||||
|
||||
@@ -0,0 +1,360 @@
|
||||
/// 依赖连线的共享走线计算。
|
||||
///
|
||||
/// 条形视图 / 圆周视图的**画布绘制、标签放置与命中测试**(点选连线、
|
||||
/// 沿法线拖拽调整走线)都使用这里的同一份几何,避免绘制与命中不一致:
|
||||
/// - 自动错开:同一走线分组内的多条依赖依次错开,先解决“完全重叠”;
|
||||
/// - 手动偏移:[Dependency.routeOffset] 叠加在自动错开之上(拖拽连线的结果)。
|
||||
library;
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../model/models.dart';
|
||||
import 'layout.dart';
|
||||
|
||||
// ===================== 通用工具 =====================
|
||||
|
||||
/// 点 [p] 到线段 [a]–[b] 的最短距离。
|
||||
double distanceToSegment(Offset p, Offset a, Offset b) {
|
||||
final Offset ab = b - a;
|
||||
final double len2 = ab.dx * ab.dx + ab.dy * ab.dy;
|
||||
if (len2 <= 0) return (p - a).distance;
|
||||
final double t = (((p - a).dx * ab.dx + (p - a).dy * ab.dy) / len2).clamp(0.0, 1.0);
|
||||
return (p - (a + ab * t)).distance;
|
||||
}
|
||||
|
||||
/// 点 [p] 到折线 [pts] 的最短距离。
|
||||
double distanceToPolyline(List<Offset> pts, Offset p) {
|
||||
double best = double.infinity;
|
||||
for (int i = 0; i + 1 < pts.length; i++) {
|
||||
final double d = distanceToSegment(p, pts[i], pts[i + 1]);
|
||||
if (d < best) best = d;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// 点 [p] 到路径 [path] 的近似最短距离(按弧长采样,步长 [step])。
|
||||
double distanceToPath(Path path, Offset p, {double step = 4}) {
|
||||
double best = double.infinity;
|
||||
for (final PathMetric m in path.computeMetrics()) {
|
||||
for (double d = 0; d < m.length; d += step) {
|
||||
final Tangent? t = m.getTangentForOffset(d);
|
||||
if (t == null) continue;
|
||||
final double dist = (t.position - p).distance;
|
||||
if (dist < best) best = dist;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// 第 [k] 档自动错开量(px):0、−6、+6、−12、+12 …
|
||||
///
|
||||
/// 同一走线分组内第二条起依次错开,避免多条依赖完全重叠。
|
||||
double staggerOffset(int k) {
|
||||
if (k <= 0) return 0;
|
||||
return (k.isOdd ? -1 : 1) * ((k + 1) ~/ 2) * 6.0;
|
||||
}
|
||||
|
||||
/// 拖拽调整走线时的移动轴(走线的“法线”方向)。
|
||||
///
|
||||
/// - [vertical]:上下拖动——平移水平走线段(条形 / 流程图的常见形态);
|
||||
/// - [horizontal]:左右拖动——平移纵向走线走廊(跨行绕行走廊 / 同层绕行)。
|
||||
enum RouteAxis { vertical, horizontal }
|
||||
|
||||
/// 拖拽走线时可用的最大手动偏移(px,双向)。
|
||||
const double kMaxRouteOffset = 200;
|
||||
|
||||
// ===================== 条形视图 =====================
|
||||
|
||||
/// 条形视图的一条依赖走线。
|
||||
class BarDepRoute {
|
||||
/// 构造。
|
||||
BarDepRoute(this.dep, this.points, this.arrowTip, this.arrowDir, this.chipCenter, this.axis,
|
||||
{this.chipRun = double.infinity,
|
||||
this.chipRunMargin = 0,
|
||||
this.chipAltAnchor = Offset.zero});
|
||||
|
||||
/// 对应依赖。
|
||||
final Dependency dep;
|
||||
/// 折线顶点(含起点与箭头端点)。
|
||||
final List<Offset> points;
|
||||
/// 箭头端点。
|
||||
final Offset arrowTip;
|
||||
/// 箭头方向(分量式)。
|
||||
final Offset arrowDir;
|
||||
/// 标签中心(默认位置,避让前)。
|
||||
final Offset chipCenter;
|
||||
/// 拖拽方向:vertical = 上下拖动平移横线;horizontal = 左右拖动平移纵向走廊。
|
||||
final RouteAxis axis;
|
||||
|
||||
/// 标签挂钩的水平行程长度(跑长时用于判断是否需要把标签移到箭头外侧)。
|
||||
///
|
||||
/// 默认 [double.infinity] 表示不做外移判断(跨行走廊等)。
|
||||
final double chipRun;
|
||||
|
||||
/// 外移判断余量:行程 `< 标签宽 + 余量` 时把标签移到 [chipAltAnchor]。
|
||||
final double chipRunMargin;
|
||||
|
||||
/// 外移时标签的锚点(绘制端会再加半个标签宽)。
|
||||
final Offset chipAltAnchor;
|
||||
|
||||
/// 依赖键 `from->to`。
|
||||
String get key => '${dep.fromId}->${dep.toId}';
|
||||
}
|
||||
|
||||
/// 计算条形视图的全部依赖走线(含自动错开与手动偏移)。
|
||||
///
|
||||
/// 走线分三种情形:同泳道(水平线)、相邻泳道(Z 形)、跨多行(外侧纵向走廊),
|
||||
/// 与绘制旧的实现保持一致;新增:同组自动错开 + [Dependency.routeOffset] 手动偏移。
|
||||
List<BarDepRoute> buildBarDepRoutes(Project project, BarLayout layout) {
|
||||
final Map<String, int> laneIndex = <String, int>{
|
||||
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
|
||||
};
|
||||
final Map<String, int> seen = <String, int>{};
|
||||
final List<BarDepRoute> out = <BarDepRoute>[];
|
||||
for (final Action to in layout.ordered) {
|
||||
for (final Dependency d in to.deps) {
|
||||
final Action? from = project.actionById(d.fromId);
|
||||
if (from == null) continue;
|
||||
final int ia = laneIndex[from.id] ?? 0;
|
||||
final int ib = laneIndex[to.id] ?? 0;
|
||||
final Rect ra = layout.rectFor(from);
|
||||
final Rect rb = layout.rectFor(to);
|
||||
const double barHalf = BarLayout.barH / 2;
|
||||
final double sy = ra.center.dy;
|
||||
final double ty = rb.center.dy;
|
||||
final double dir = ty > sy ? 1 : -1;
|
||||
final double tipY = ty - dir * (barHalf + 3);
|
||||
final bool sameLane = (ty - sy).abs() < 1;
|
||||
final bool fs = d.type == DepType.fs;
|
||||
|
||||
if (sameLane) {
|
||||
// 同泳道:一条水平线;同组多条依次上下错开。
|
||||
final int k = seen.putIfAbsent('S$ia', () => 0);
|
||||
seen['S$ia'] = k + 1;
|
||||
final double y = sy + staggerOffset(k) + d.routeOffset;
|
||||
final double startX = fs ? ra.right + 2 : ra.left - 2;
|
||||
double endX = rb.left - 2;
|
||||
if (endX < startX) endX = rb.right + 2;
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
<Offset>[Offset(startX, y), Offset(endX, y)],
|
||||
Offset(endX, y),
|
||||
Offset(endX >= startX ? 1 : -1, 0),
|
||||
Offset((startX + endX) / 2, y - (barHalf + 9)),
|
||||
RouteAxis.vertical,
|
||||
// 行程太短时标签移出到箭头右侧(宽度由绘制端精确测量)。
|
||||
chipRun: (endX - startX).abs(),
|
||||
chipRunMargin: 8,
|
||||
chipAltAnchor: Offset(endX + 6, y - (barHalf + 9)),
|
||||
));
|
||||
} else if ((ib - ia).abs() <= 1) {
|
||||
// 相邻泳道:在两泳道之间的空隙中线走水平线;同组错开 + 手动偏移。
|
||||
final int k = seen.putIfAbsent('A$ia→$ib', () => 0);
|
||||
seen['A$ia→$ib'] = k + 1;
|
||||
final double mid = (sy + ty) / 2 + staggerOffset(k) + d.routeOffset;
|
||||
final double sx = fs ? ra.right : ra.left;
|
||||
final double ex = fs ? sx - 9 : sx + 9;
|
||||
final double tx = rb.left + 14;
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
<Offset>[
|
||||
Offset(ex, sy + dir * (barHalf + 2)),
|
||||
Offset(ex, mid),
|
||||
Offset(tx, mid),
|
||||
Offset(tx, tipY),
|
||||
],
|
||||
Offset(tx, tipY),
|
||||
Offset(0, dir),
|
||||
Offset((ex + tx) / 2, mid),
|
||||
RouteAxis.vertical,
|
||||
chipRun: (tx - ex).abs(),
|
||||
chipRunMargin: 10,
|
||||
chipAltAnchor: Offset(tx + 6, mid),
|
||||
));
|
||||
} else {
|
||||
// 跨多行:扫描区间内所有条块边界,据此在外侧选一条纵向走廊;
|
||||
// 同组按 ±12px 错开走廊,手动偏移作用于走廊的横向位置。
|
||||
final int k = seen.putIfAbsent('M$ia→$ib', () => 0);
|
||||
seen['M$ia→$ib'] = k + 1;
|
||||
final double sx = fs ? ra.right : ra.left;
|
||||
final double ex = fs ? sx - 9 : sx + 9;
|
||||
final double tx = rb.left + 14;
|
||||
double maxRight = 0;
|
||||
double minLeft = double.infinity;
|
||||
final List<int> lanes = layout.lanes;
|
||||
for (int r = math.min(ia, ib) + 1; r < math.max(ia, ib); r++) {
|
||||
if (r < 0 || r >= lanes.length) continue;
|
||||
for (final Action aa in layout.actionsInLane(lanes[r])) {
|
||||
final Rect rr = layout.rectFor(aa);
|
||||
maxRight = math.max(maxRight, rr.right);
|
||||
minLeft = math.min(minLeft, rr.left);
|
||||
}
|
||||
}
|
||||
final double shift = staggerOffset(k) * 2 + d.routeOffset;
|
||||
double lane = math.max(math.max(sx, tx), maxRight) + 28 + shift;
|
||||
if (lane > layout.plotRight - 16) {
|
||||
lane = math.min(math.min(sx, tx), minLeft) - 28 - shift;
|
||||
}
|
||||
final double srcGapY = sy + dir * (barHalf + 14);
|
||||
final double gapY = ty - dir * (barHalf + 6);
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
<Offset>[
|
||||
Offset(ex, sy + dir * (barHalf + 2)),
|
||||
Offset(ex, srcGapY),
|
||||
Offset(lane, srcGapY),
|
||||
Offset(lane, gapY),
|
||||
Offset(tx, gapY),
|
||||
Offset(tx, tipY),
|
||||
],
|
||||
Offset(tx, tipY),
|
||||
Offset(0, dir),
|
||||
Offset((lane + tx) / 2, gapY - (barHalf + 1)),
|
||||
RouteAxis.horizontal,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 命中条形依赖走线:返回最近且距离小于 [maxDist] 的走线(无命中返回 null)。
|
||||
BarDepRoute? hitBarDep(List<BarDepRoute> routes, Offset p, double maxDist) {
|
||||
BarDepRoute? best;
|
||||
double bestD = maxDist;
|
||||
for (final BarDepRoute r in routes) {
|
||||
final double d = distanceToPolyline(r.points, p);
|
||||
if (d < bestD) {
|
||||
bestD = d;
|
||||
best = r;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// ===================== 圆周视图 =====================
|
||||
|
||||
/// 圆周视图的一条依赖走线(径向 → 圆弧 → 径向)。
|
||||
class ArcDepRoute {
|
||||
/// 构造。
|
||||
ArcDepRoute(this.dep, this.center, this.rA, this.rB, this.rC, this.rTip, this.aEnd, this.aStart,
|
||||
this.degenerate, this.cw, this.large, this.chipR, this.chipDeg);
|
||||
|
||||
/// 对应依赖。
|
||||
final Dependency dep;
|
||||
/// 圆心。
|
||||
final Offset center;
|
||||
/// 源环半径。
|
||||
final double rA;
|
||||
/// 目标环半径。
|
||||
final double rB;
|
||||
/// 绕行半径(自动错开 + 手动偏移作用于此)。
|
||||
final double rC;
|
||||
/// 箭头落点半径。
|
||||
final double rTip;
|
||||
/// 源弧末端角(度)。
|
||||
final double aEnd;
|
||||
/// 目标弧起点角(度)。
|
||||
final double aStart;
|
||||
/// 起止角几乎重合(退化)时改画短箭头。
|
||||
final bool degenerate;
|
||||
/// 圆弧是否顺时针。
|
||||
final bool cw;
|
||||
/// 是否大弧。
|
||||
final int large;
|
||||
/// 标签极径。
|
||||
final double chipR;
|
||||
/// 标签极角。
|
||||
final double chipDeg;
|
||||
|
||||
/// 依赖键 `from->to`。
|
||||
String get key => '${dep.fromId}->${dep.toId}';
|
||||
|
||||
/// 起点(源环上)。
|
||||
Offset get p0 => polar(center, rA, aEnd);
|
||||
/// 绕行起点(半径 rC 上)。
|
||||
Offset get p1 => polar(center, rC, aEnd);
|
||||
/// 绕行终点(半径 rC 上)。
|
||||
Offset get p2 => polar(center, rC, aStart);
|
||||
/// 箭头端点。
|
||||
Offset get p3 => polar(center, rTip, aStart);
|
||||
/// 退化短箭头的起点。
|
||||
Offset get q0 => polar(center, rTip - (rTip > rB ? 28 : -28), aStart);
|
||||
|
||||
/// 生成绘制路径(绘制与命中测试同源)。
|
||||
Path buildPath() {
|
||||
final Path p = Path();
|
||||
if (degenerate) {
|
||||
p.moveTo(q0.dx, q0.dy);
|
||||
p.lineTo(p3.dx, p3.dy);
|
||||
return p;
|
||||
}
|
||||
final Offset a0 = p0;
|
||||
final Offset a1 = p1;
|
||||
final Offset a2 = p2;
|
||||
final Offset a3 = p3;
|
||||
p.moveTo(a0.dx, a0.dy);
|
||||
p.lineTo(a1.dx, a1.dy);
|
||||
p.arcToPoint(a2, radius: Radius.circular(rC), largeArc: large == 1, clockwise: cw);
|
||||
p.lineTo(a3.dx, a3.dy);
|
||||
return p;
|
||||
}
|
||||
|
||||
/// 箭头方向(分量式)。
|
||||
Offset get tipDir => degenerate ? (p3 - q0) : (p3 - p2);
|
||||
}
|
||||
|
||||
/// 计算圆周视图的全部依赖走线(含自动错开与手动偏移)。
|
||||
List<ArcDepRoute> buildArcDepRoutes(Project project, CircularLayout layout) {
|
||||
final Map<String, int> seen = <String, int>{};
|
||||
final List<ArcDepRoute> out = <ArcDepRoute>[];
|
||||
for (final Action to in project.actions) {
|
||||
for (final Dependency d in to.deps) {
|
||||
final Action? a = project.actionById(d.fromId);
|
||||
final Action? b = project.actionById(d.toId);
|
||||
if (a == null || b == null) continue;
|
||||
final double rA = layout.radiusFor(a.layer);
|
||||
final double rB = layout.radiusFor(b.layer);
|
||||
final double aEnd = math.min(a.endAngle, 360);
|
||||
final double aStart = b.startAngle;
|
||||
// 层差大于 1 时从最外圈绕行,避免穿过中间层弧线。
|
||||
final bool skip = (a.layer - b.layer).abs() > 1;
|
||||
final String groupKey = '${skip ? 'K' : 'N'}${a.layer}→${b.layer}';
|
||||
final int k = seen.putIfAbsent(groupKey, () => 0);
|
||||
seen[groupKey] = k + 1;
|
||||
// 自动错开(步长 9px)+ 手动径向偏移(圆周视图的“法线”即半径方向)。
|
||||
double rC = (skip ? layout.rMax + 24 : (rA + rB) / 2) + staggerOffset(k) * 1.5 + d.routeOffset;
|
||||
rC = rC.clamp(18.0, layout.rMax + 170);
|
||||
final double rTip = rC < rB ? rB - layout.th / 2 - 4 : rB + layout.th / 2 + 4;
|
||||
final bool cw = aStart >= aEnd;
|
||||
final int large = (aStart - aEnd).abs() > 180 ? 1 : 0;
|
||||
final bool degenerate = (aStart - aEnd).abs() < 0.5;
|
||||
final double chipDeg = degenerate ? aStart : (aEnd + aStart) / 2;
|
||||
double chipR;
|
||||
if (degenerate) {
|
||||
chipR = (rA + rB) / 2;
|
||||
} else {
|
||||
final double span = (aStart - aEnd).abs();
|
||||
chipR = skip ? rC : (span < 30 ? rB + layout.th / 2 + 10 : rC);
|
||||
}
|
||||
out.add(ArcDepRoute(
|
||||
d, layout.center, rA, rB, rC, rTip, aEnd, aStart, degenerate, cw, large, chipR, chipDeg));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 命中圆周依赖走线:返回最近且距离小于 [maxDist] 的走线(无命中返回 null)。
|
||||
ArcDepRoute? hitArcDep(List<ArcDepRoute> routes, Offset p, double maxDist) {
|
||||
ArcDepRoute? best;
|
||||
double bestD = maxDist;
|
||||
for (final ArcDepRoute r in routes) {
|
||||
final double d = distanceToPath(r.buildPath(), p);
|
||||
if (d < bestD) {
|
||||
bestD = d;
|
||||
best = r;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
/// 流程图布局:把时序图中的动作与依赖转换为纵向流程图(泳道 = 轨道)。
|
||||
///
|
||||
/// 产品规则(1.3 大版本,经需求确认):
|
||||
/// - 每个动作 = 一个工序节点,节点内显示「序号. 名称」与时长(含工位);
|
||||
/// - 泳道 = 动作的轨道(layer),横向并列,一眼看出哪些步骤在并行;
|
||||
/// - 依赖:FS 实线、SS 虚线(带偏移角标注);关键路径加粗高亮;
|
||||
/// - 自动补「开始 / 结束」节点:开始 → 时间最早的动作(动作1),
|
||||
/// 其余无前置的动作作为并行起点同样从开始引出;无后继的动作 → 结束;
|
||||
/// - 只读视图:交互仅支持点选联动与平移缩放,内容修改请回时序图。
|
||||
library;
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import 'dep_routes.dart';
|
||||
import 'layout.dart';
|
||||
|
||||
/// 流程图节点(动作节点或开始 / 结束节点)。
|
||||
class FlowNode {
|
||||
/// 动作节点。
|
||||
FlowNode.action(Action this.action)
|
||||
: id = action.id,
|
||||
isStart = false,
|
||||
isEnd = false;
|
||||
|
||||
/// 开始节点。
|
||||
FlowNode.start()
|
||||
: action = null,
|
||||
id = startId,
|
||||
isStart = true,
|
||||
isEnd = false;
|
||||
|
||||
/// 结束节点。
|
||||
FlowNode.end()
|
||||
: action = null,
|
||||
id = endId,
|
||||
isStart = false,
|
||||
isEnd = true;
|
||||
|
||||
/// 开始节点的保留 id。
|
||||
static const String startId = '__flow_start__';
|
||||
/// 结束节点的保留 id。
|
||||
static const String endId = '__flow_end__';
|
||||
|
||||
/// 对应动作;开始 / 结束节点为 null。
|
||||
final Action? action;
|
||||
/// 节点 id(开始 / 结束使用保留 id)。
|
||||
final String id;
|
||||
/// 是否开始节点。
|
||||
final bool isStart;
|
||||
/// 是否结束节点。
|
||||
final bool isEnd;
|
||||
|
||||
/// 所属泳道(轨道号 layer)。
|
||||
int lane = 0;
|
||||
/// 纵向层级(0 = 开始节点所在层)。
|
||||
int rank = 0;
|
||||
/// 布局后的节点矩形(逻辑坐标)。
|
||||
Rect rect = Rect.zero;
|
||||
/// 主标题(动作节点为「序号. 名称」)。
|
||||
String title = '';
|
||||
/// 副标题(时长 · 工位)。
|
||||
String subtitle = '';
|
||||
}
|
||||
|
||||
/// 流程图连线。
|
||||
class FlowEdge {
|
||||
/// 构造;[type] 为依赖类型(开始 / 结束相关连线为 null)。
|
||||
FlowEdge(this.fromId, this.toId,
|
||||
{this.type, this.offset = 0, this.critical = false});
|
||||
|
||||
/// 起点节点 id。
|
||||
final String fromId;
|
||||
/// 终点节点 id。
|
||||
final String toId;
|
||||
/// 依赖类型;null 表示开始 / 结束的流程连线。
|
||||
final DepType? type;
|
||||
/// SS 等依赖的偏移角(度)。
|
||||
final double offset;
|
||||
/// 是否属于关键路径。
|
||||
final bool critical;
|
||||
}
|
||||
|
||||
/// 连线走线结果(供画布绘制 / SVG / drawio 导出共用)。
|
||||
class FlowEdgeRoute {
|
||||
/// 构造。
|
||||
FlowEdgeRoute(this.edge, this.points, this.tip, this.dir, this.labelAt, this.axis);
|
||||
|
||||
/// 对应的连线。
|
||||
final FlowEdge edge;
|
||||
/// 折线顶点序列(含起点与箭头端点)。
|
||||
final List<Offset> points;
|
||||
/// 箭头端点。
|
||||
final Offset tip;
|
||||
/// 箭头方向(分量式单位方向)。
|
||||
final Offset dir;
|
||||
/// FS / SS 标签位置。
|
||||
final Offset labelAt;
|
||||
/// 拖拽调整走线的方向:向下流为竖直(上下拖动),同层绕行为水平(左右拖动)。
|
||||
final RouteAxis axis;
|
||||
|
||||
/// 依赖键 `from->to`。
|
||||
String get key => '${edge.fromId}->${edge.toId}';
|
||||
|
||||
/// 是否虚线(SS 依赖)。
|
||||
bool get dashed => edge.type == DepType.ss;
|
||||
}
|
||||
|
||||
/// 相位分区在流程图中的纵向跨度(左侧阶段栏用)。
|
||||
class FlowPhaseSpan {
|
||||
/// 构造。
|
||||
FlowPhaseSpan(this.zone, this.rankTop, this.rankBottom);
|
||||
|
||||
/// 相位分区。
|
||||
final PhaseZone zone;
|
||||
/// 覆盖的最上层级。
|
||||
final int rankTop;
|
||||
/// 覆盖的最下层级。
|
||||
final int rankBottom;
|
||||
/// 与其它阶段纵向重叠时的横向错位档位(0 起,每档向右 [FlowLayout.railStep] px,
|
||||
/// 仅轻微错开以免重叠处看不清;纵向仍严格对齐流程行)。
|
||||
int slot = 0;
|
||||
}
|
||||
|
||||
/// 流程图布局结果:节点、连线、泳道与内容范围。
|
||||
class FlowLayout {
|
||||
/// 构造并从 [project] 生成流程图。
|
||||
///
|
||||
/// [criticalActions] / [criticalDeps] 用于标记关键路径(与其它视图一致)。
|
||||
FlowLayout(
|
||||
this.project, {
|
||||
this.criticalActions = const <String>{},
|
||||
this.criticalDeps = const <String>{},
|
||||
}) {
|
||||
_build();
|
||||
}
|
||||
|
||||
/// 数据源项目。
|
||||
final Project project;
|
||||
/// 关键路径上的动作 id。
|
||||
final Set<String> criticalActions;
|
||||
/// 关键路径上的依赖(`from->to`)。
|
||||
final Set<String> criticalDeps;
|
||||
|
||||
/// 动作节点尺寸(流程图与条形 / 圆周不同:横向更宽,给连线与箭头留出空间)。
|
||||
static const double nodeW = 216;
|
||||
/// 动作节点高度。
|
||||
static const double nodeH = 58;
|
||||
/// 开始 / 结束节点尺寸。
|
||||
static const double capW = 116;
|
||||
/// 开始 / 结束节点高度。
|
||||
static const double capH = 46;
|
||||
/// 层级(纵向)间距。
|
||||
static const double rankGap = 48;
|
||||
/// 泳道(横向)间距(加大给扇出连线让位,避免看起来拥挤)。
|
||||
static const double laneGap = 64;
|
||||
/// 左边距(左侧留出相位阶段栏 + 泳道间距)。
|
||||
static const double marginX = 150;
|
||||
/// 上边距(含泳道标题)。
|
||||
static const double marginY = 92;
|
||||
/// 相位阶段栏起始 x。
|
||||
static const double railX = 24;
|
||||
/// 相位竖带宽度(窄带,相当于把条形视图的相位色带竖起来)。
|
||||
static const double railW = 24;
|
||||
/// 相位台阶错位宽度(重叠的分区逐级向右错开,形成台阶)。
|
||||
static const double railStep = 24;
|
||||
|
||||
/// 全部节点(按创建顺序:动作 → 开始 → 结束)。
|
||||
final List<FlowNode> nodes = <FlowNode>[];
|
||||
/// 全部连线。
|
||||
final List<FlowEdge> edges = <FlowEdge>[];
|
||||
/// 泳道列表(轨道号,升序)。
|
||||
List<int> lanes = <int>[];
|
||||
/// 相位分区跨度(左侧阶段栏,按项目分区顺序)。
|
||||
final List<FlowPhaseSpan> spans = <FlowPhaseSpan>[];
|
||||
/// 连线走线结果(画布 / SVG / drawio 导出共用)。
|
||||
final List<FlowEdgeRoute> routes = <FlowEdgeRoute>[];
|
||||
/// 内容范围(所有节点矩形并集再外扩,供适应视图使用)。
|
||||
Rect bounds = Rect.zero;
|
||||
|
||||
/// 按 id 查找节点。
|
||||
FlowNode? nodeById(String id) {
|
||||
for (final FlowNode n in nodes) {
|
||||
if (n.id == id) return n;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 命中测试:返回坐标 [p] 下的动作(开始 / 结束节点不返回)。
|
||||
Action? hitTest(Offset p) {
|
||||
for (final FlowNode n in nodes) {
|
||||
if (n.action != null && n.rect.contains(p)) return n.action;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 构建节点、连线并完成布局。
|
||||
void _build() {
|
||||
lanes = (<int>{for (final Action a in project.actions) a.layer}.toList())..sort();
|
||||
final Map<String, FlowNode> byId = <String, FlowNode>{};
|
||||
|
||||
// 1) 动作节点(序号与条形视图一致:项目动作列表顺序 + 1)。
|
||||
for (int i = 0; i < project.actions.length; i++) {
|
||||
final Action a = project.actions[i];
|
||||
final String dur = tfmt(a.durationAngle / 360 * project.cycle.durationMs, project.units);
|
||||
final String st = project.stationById(a.stationId)?.name ?? a.stationId;
|
||||
final FlowNode n = FlowNode.action(a)
|
||||
..lane = a.layer
|
||||
..title = '${i + 1}. ${a.name}'
|
||||
..subtitle = '$dur · $st';
|
||||
nodes.add(n);
|
||||
byId[n.id] = n;
|
||||
}
|
||||
if (nodes.isEmpty) {
|
||||
bounds = Rect.zero;
|
||||
return;
|
||||
}
|
||||
|
||||
// 2) 依赖连线(FS 实线 / SS 虚线等)。
|
||||
for (final Action to in project.actions) {
|
||||
for (final Dependency d in to.deps) {
|
||||
if (d.fromId == to.id || !byId.containsKey(d.fromId)) continue;
|
||||
edges.add(FlowEdge(d.fromId, to.id,
|
||||
type: d.type,
|
||||
offset: d.offsetAngle,
|
||||
critical: criticalDeps.contains('${d.fromId}->${to.id}')));
|
||||
}
|
||||
}
|
||||
|
||||
// 3) 开始 / 结束节点。
|
||||
// 「动作1」= 时间上最早开始的动作(并列时取 id 较小者)。
|
||||
final List<Action> ordered = List<Action>.of(project.actions)
|
||||
..sort((Action a, Action b) {
|
||||
final int c = a.startAngle.compareTo(b.startAngle);
|
||||
return c != 0 ? c : a.id.compareTo(b.id);
|
||||
});
|
||||
final Action first = ordered.first;
|
||||
Action last = ordered.first;
|
||||
for (final Action a in ordered) {
|
||||
if (a.endAngle > last.endAngle) last = a;
|
||||
}
|
||||
final FlowNode start = FlowNode.start()..lane = first.layer;
|
||||
final FlowNode end = FlowNode.end()..lane = last.layer;
|
||||
start.title = '开始';
|
||||
end.title = '结束';
|
||||
nodes.add(start);
|
||||
nodes.add(end);
|
||||
byId[start.id] = start;
|
||||
byId[end.id] = end;
|
||||
|
||||
final Set<String> hasPred = <String>{for (final FlowEdge e in edges) e.toId};
|
||||
final Set<String> hasSucc = <String>{for (final FlowEdge e in edges) e.fromId};
|
||||
// 开始 → 无前置的动作(含「动作1」;其它无前置动作视为并行起点)。
|
||||
for (final Action a in project.actions) {
|
||||
if (!hasPred.contains(a.id)) edges.add(FlowEdge(start.id, a.id));
|
||||
}
|
||||
// 无后继的动作 → 结束。
|
||||
for (final Action a in project.actions) {
|
||||
if (!hasSucc.contains(a.id)) edges.add(FlowEdge(a.id, end.id));
|
||||
}
|
||||
|
||||
// 4) 层级:从开始节点做最长路径(带迭代上限,兼容异常环)。
|
||||
final Map<String, int> rank = <String, int>{for (final FlowNode n in nodes) n.id: 0};
|
||||
bool changed = true;
|
||||
int guard = 0;
|
||||
while (changed && guard < nodes.length * 4 + 8) {
|
||||
changed = false;
|
||||
guard++;
|
||||
for (final FlowEdge e in edges) {
|
||||
final int nr = (rank[e.fromId] ?? 0) + 1;
|
||||
if (nr > (rank[e.toId] ?? 0)) {
|
||||
rank[e.toId] = nr;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final FlowNode n in nodes) {
|
||||
n.rank = rank[n.id] ?? 0;
|
||||
}
|
||||
|
||||
// 5) 坐标:泳道 → 横列(居中于列),层级 → 纵行;同格多节点横向错开。
|
||||
final Map<int, int> laneIndex = <int, int>{
|
||||
for (int i = 0; i < lanes.length; i++) lanes[i]: i,
|
||||
};
|
||||
final Map<String, int> cellTotal = <String, int>{};
|
||||
for (final FlowNode n in nodes) {
|
||||
final String key = '${n.lane}:${n.rank}';
|
||||
cellTotal[key] = (cellTotal[key] ?? 0) + 1;
|
||||
}
|
||||
final Map<String, int> cellSeen = <String, int>{};
|
||||
final double lanePitch = nodeW + laneGap;
|
||||
for (final FlowNode n in nodes) {
|
||||
final int li = laneIndex[n.lane] ?? 0;
|
||||
final String key = '${n.lane}:${n.rank}';
|
||||
final int total = cellTotal[key] ?? 1;
|
||||
final int idx = cellSeen[key] ?? 0;
|
||||
cellSeen[key] = idx + 1;
|
||||
final double w = (n.isStart || n.isEnd) ? capW : nodeW;
|
||||
final double h = (n.isStart || n.isEnd) ? capH : nodeH;
|
||||
final double centerX = marginX + li * lanePitch + nodeW / 2 +
|
||||
(idx - (total - 1) / 2) * (nodeW * 0.62);
|
||||
final double top = marginY + n.rank * (nodeH + rankGap) + (nodeH - h) / 2;
|
||||
n.rect = Rect.fromLTWH(centerX - w / 2, top, w, h);
|
||||
}
|
||||
|
||||
// 6) 连线走线:画布绘制 / SVG / drawio 导出共用(同源同层分支扇形错位)。
|
||||
// 依赖上保存的手动走线偏移(routeOffset)在此叠加:
|
||||
// 向下流为竖直偏移(拖动横线),同层绕行为水平偏移(拖动纵向走廊)。
|
||||
final Map<String, int> fanIndex = <String, int>{};
|
||||
for (final FlowEdge e in edges) {
|
||||
final FlowNode? a = byId[e.fromId];
|
||||
final FlowNode? b = byId[e.toId];
|
||||
if (a == null || b == null) continue;
|
||||
double routeOffset = 0;
|
||||
if (e.type != null) {
|
||||
final Action? to = project.actionById(e.toId);
|
||||
for (final Dependency d in to?.deps ?? const <Dependency>[]) {
|
||||
if (d.fromId == e.fromId) {
|
||||
routeOffset = d.routeOffset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b.rank > a.rank) {
|
||||
final String key = '${e.fromId}:${b.rank}';
|
||||
final int idx = fanIndex[key] ?? 0;
|
||||
fanIndex[key] = idx + 1;
|
||||
// 横线高度:扇形错开 + 手动偏移,限制在源/目标两行之间的空隙内。
|
||||
double lane = math.min(
|
||||
(a.rect.bottom + b.rect.top) / 2 + idx * 14 + routeOffset,
|
||||
b.rect.top - 8,
|
||||
);
|
||||
if (lane < a.rect.bottom + 10) lane = a.rect.bottom + 10;
|
||||
final double x0 = a.rect.center.dx;
|
||||
final double x1 = b.rect.center.dx;
|
||||
routes.add(FlowEdgeRoute(
|
||||
e,
|
||||
<Offset>[
|
||||
Offset(x0, a.rect.bottom),
|
||||
Offset(x0, lane),
|
||||
Offset(x1, lane),
|
||||
Offset(x1, b.rect.top),
|
||||
],
|
||||
Offset(x1, b.rect.top),
|
||||
const Offset(0, 1),
|
||||
Offset((x0 + x1) / 2, lane - 11),
|
||||
RouteAxis.vertical,
|
||||
));
|
||||
} else {
|
||||
// 同层 / 回连:右侧绕行;手动偏移作用于绕行走廊的横向位置。
|
||||
final double x = math.max(a.rect.right, b.rect.right) + 22 + routeOffset;
|
||||
routes.add(FlowEdgeRoute(
|
||||
e,
|
||||
<Offset>[
|
||||
Offset(a.rect.right, a.rect.center.dy),
|
||||
Offset(x, a.rect.center.dy),
|
||||
Offset(x, b.rect.center.dy),
|
||||
Offset(b.rect.right, b.rect.center.dy),
|
||||
],
|
||||
Offset(b.rect.right, b.rect.center.dy),
|
||||
const Offset(-1, 0),
|
||||
Offset(x + 16, (a.rect.center.dy + b.rect.center.dy) / 2),
|
||||
RouteAxis.horizontal,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// 7) 相位分区跨度:每个动作行归属到“覆盖角度占比最大”的分区(并列取靠前分区)。
|
||||
// 这样阶段栏的每一段都真实对应分区归属,不会出现两个分区同时压住同一行、
|
||||
// 看起来“对不上号”的情况。
|
||||
final List<PhaseZone> zones = project.phaseZones;
|
||||
final Map<String, int> dominant = <String, int>{};
|
||||
for (final Action a in project.actions) {
|
||||
int best = -1;
|
||||
double bestSpan = 0;
|
||||
for (int i = 0; i < zones.length; i++) {
|
||||
final double span = _angleOverlapSpan(
|
||||
a.startAngle, a.endAngle, zones[i].startAngle, zones[i].endAngle);
|
||||
if (span > bestSpan + 0.001) {
|
||||
bestSpan = span;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
dominant[a.id] = best;
|
||||
}
|
||||
for (int i = 0; i < zones.length; i++) {
|
||||
final PhaseZone z = zones[i];
|
||||
int top = -1;
|
||||
int bottom = -1;
|
||||
for (final FlowNode n in nodes) {
|
||||
final Action? a = n.action;
|
||||
if (a == null || dominant[a.id] != i) continue;
|
||||
if (top < 0 || n.rank < top) top = n.rank;
|
||||
if (n.rank > bottom) bottom = n.rank;
|
||||
}
|
||||
if (top >= 0) spans.add(FlowPhaseSpan(z, top, bottom));
|
||||
}
|
||||
// 回退:没有任何主导行的分区,按“与动作行有角度重叠即覆盖”补上,
|
||||
// 避免分区(如仅少量跨界的下料相位)在阶段栏中缺失。
|
||||
for (int i = 0; i < zones.length; i++) {
|
||||
if (spans.any((FlowPhaseSpan s) => identical(s.zone, zones[i]))) continue;
|
||||
int top = -1;
|
||||
int bottom = -1;
|
||||
for (final FlowNode n in nodes) {
|
||||
final Action? a = n.action;
|
||||
if (a == null) continue;
|
||||
if (!angleRangesOverlap(a.startAngle, a.endAngle, zones[i].startAngle, zones[i].endAngle)) {
|
||||
continue;
|
||||
}
|
||||
if (top < 0 || n.rank < top) top = n.rank;
|
||||
if (n.rank > bottom) bottom = n.rank;
|
||||
}
|
||||
if (top >= 0) spans.add(FlowPhaseSpan(zones[i], top, bottom));
|
||||
}
|
||||
// 纵向仍重叠的相位:轻微向右错位(每档 [railStep] px)。采用贪心图着色,
|
||||
// 保证互相重叠的两个相位一定拿到不同档位(同档的必定不重叠)。
|
||||
for (int i = 0; i < spans.length; i++) {
|
||||
final Set<int> used = <int>{};
|
||||
for (int j = 0; j < i; j++) {
|
||||
final bool overlap = spans[i].rankTop <= spans[j].rankBottom &&
|
||||
spans[j].rankTop <= spans[i].rankBottom;
|
||||
if (overlap) used.add(spans[j].slot);
|
||||
}
|
||||
int slot = 0;
|
||||
while (used.contains(slot)) {
|
||||
slot++;
|
||||
}
|
||||
spans[i].slot = slot;
|
||||
}
|
||||
|
||||
// 8) 内容范围:节点 + 连线走线 + 左侧阶段栏(按实际错位档数计算宽度,
|
||||
// 保证「适应窗口」不裁切)。
|
||||
Rect b = nodes.first.rect;
|
||||
for (final FlowNode n in nodes) {
|
||||
b = b.expandToInclude(n.rect);
|
||||
}
|
||||
for (final FlowEdgeRoute r in routes) {
|
||||
for (final Offset p in r.points) {
|
||||
b = b.expandToInclude(Rect.fromCenter(center: p, width: 30, height: 30));
|
||||
}
|
||||
b = b.expandToInclude(Rect.fromCenter(center: r.labelAt, width: 70, height: 26));
|
||||
}
|
||||
bounds = b.inflate(math.max(60, laneGap));
|
||||
int maxSlot = 0;
|
||||
for (final FlowPhaseSpan s in spans) {
|
||||
if (s.slot > maxSlot) maxSlot = s.slot;
|
||||
}
|
||||
bounds = bounds.expandToInclude(
|
||||
Rect.fromLTRB(
|
||||
railX - 10,
|
||||
bounds.top,
|
||||
railX + maxSlot * railStep + railW + 24,
|
||||
bounds.bottom,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 两个角度区间(允许超过 360° 表示跨圈)的重叠跨度(度);无重叠返回 0。
|
||||
double _angleOverlapSpan(double a0, double a1, double b0, double b1) {
|
||||
double best = 0;
|
||||
for (final double shift in <double>[-360, 0, 360]) {
|
||||
final double lo = math.max(a0, b0 + shift);
|
||||
final double hi = math.min(a1, b1 + shift);
|
||||
if (hi > lo) best = math.max(best, hi - lo);
|
||||
}
|
||||
return best;
|
||||
}
|
||||
+83
-33
@@ -17,6 +17,9 @@ enum ViewMode {
|
||||
|
||||
/// 圆周(环形)节拍视图。
|
||||
circular,
|
||||
|
||||
/// 流程图视图(由时序图自动生成,只读)。
|
||||
flow,
|
||||
}
|
||||
|
||||
/// 时间单位。
|
||||
@@ -121,12 +124,15 @@ class Dependency {
|
||||
/// 构造一条依赖。
|
||||
///
|
||||
/// 参数 [fromId]:前驱动作 id;[toId]:后继动作 id;
|
||||
/// [type]:依赖类型,默认 [DepType.fs];[offsetAngle]:附加相位偏移(度)。
|
||||
/// [type]:依赖类型,默认 [DepType.fs];[offsetAngle]:附加相位偏移(度);
|
||||
/// [routeOffset]:手动走线偏移(px)——条形 / 流程图作用于横向走线的纵向偏移,
|
||||
/// 圆周视图作用于绕行圆弧的半径偏移,用于拉开重叠的连线。
|
||||
const Dependency({
|
||||
required this.fromId,
|
||||
required this.toId,
|
||||
this.type = DepType.fs,
|
||||
this.offsetAngle = 0,
|
||||
this.routeOffset = 0,
|
||||
});
|
||||
|
||||
/// 前驱动作 id。
|
||||
@@ -141,18 +147,23 @@ class Dependency {
|
||||
/// 依赖的附加角度偏移,单位:度。
|
||||
final double offsetAngle;
|
||||
|
||||
/// 手动走线偏移(px,默认 0):拖拽连线调整,见 `dep_routes.dart`。
|
||||
final double routeOffset;
|
||||
|
||||
/// 基于当前实例创建副本,未提供的参数保持原值。
|
||||
Dependency copyWith({
|
||||
String? fromId,
|
||||
String? toId,
|
||||
DepType? type,
|
||||
double? offsetAngle,
|
||||
double? routeOffset,
|
||||
}) {
|
||||
return Dependency(
|
||||
fromId: fromId ?? this.fromId,
|
||||
toId: toId ?? this.toId,
|
||||
type: type ?? this.type,
|
||||
offsetAngle: offsetAngle ?? this.offsetAngle,
|
||||
routeOffset: routeOffset ?? this.routeOffset,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -162,6 +173,7 @@ class Dependency {
|
||||
'toId': toId,
|
||||
'type': type.name.toUpperCase(),
|
||||
'offsetAngle': offsetAngle,
|
||||
if (routeOffset != 0) 'routeOffset': routeOffset,
|
||||
};
|
||||
|
||||
/// 从 JSON 反序列化;缺失字段使用安全默认值,保证旧文件可加载。
|
||||
@@ -171,6 +183,7 @@ class Dependency {
|
||||
toId: j['toId'] as String? ?? '',
|
||||
type: _depTypeFrom(j['type'] as String?),
|
||||
offsetAngle: (j['offsetAngle'] as num?)?.toDouble() ?? 0,
|
||||
routeOffset: (j['routeOffset'] as num?)?.toDouble() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -666,7 +679,11 @@ class ViewState {
|
||||
final List<dynamic> pan = (j['pan'] as List<dynamic>?) ?? <dynamic>[0, 0];
|
||||
final List<dynamic> sel = (j['selectedIds'] as List<dynamic>?) ?? <dynamic>[];
|
||||
return ViewState(
|
||||
mode: (j['mode'] as String?) == 'circular' ? ViewMode.circular : ViewMode.bar,
|
||||
mode: switch (j['mode'] as String?) {
|
||||
'circular' => ViewMode.circular,
|
||||
'flow' => ViewMode.flow,
|
||||
_ => ViewMode.bar,
|
||||
},
|
||||
zoom: (j['zoom'] as num?)?.toDouble() ?? 1,
|
||||
panX: (pan.isNotEmpty ? (pan[0] as num?)?.toDouble() : 0) ?? 0,
|
||||
panY: (pan.length > 1 ? (pan[1] as num?)?.toDouble() : 0) ?? 0,
|
||||
@@ -896,47 +913,80 @@ class Project {
|
||||
|
||||
/// 构造内置演示项目(装配线节拍方案)。
|
||||
///
|
||||
/// 返回一个包含 2 个工位、2 个动作(动作 1 / 动作 2)的示例 [Project],
|
||||
/// 用于首次启动展示。刻意保持精简,避免预设内容过多干扰用户。
|
||||
/// 首次启动展示用的精简示例:3 个工位、5 个动作(上料 → 定位夹紧 →
|
||||
/// 伺服下压 → 超声焊接(SS 并行)→ 视觉检测)、3 个相位分区。
|
||||
/// 保留 FS / SS 两种依赖与多泳道结构,足以展示条形 / 圆周 / 流程图三种视图,
|
||||
/// 又不会让默认数据显得臃肿。测试助手 `demoTiming()` 直接引用本方法,
|
||||
/// 保证「本地构建 == 演示截图」。
|
||||
static Project demo() {
|
||||
final List<Station> stations = <Station>[
|
||||
const Station(id: 'ST1', name: '工位 1', order: 0, color: 0xFF4CC9F0),
|
||||
const Station(id: 'ST2', name: '工位 2', order: 1, color: 0xFFFFD166),
|
||||
];
|
||||
final List<Action> actions = <Action>[
|
||||
Action(
|
||||
return Project(
|
||||
name: '装配线节拍',
|
||||
cycle: const Cycle(durationMs: 2400),
|
||||
stations: const <Station>[
|
||||
Station(id: 'ST1', name: '上料工位', order: 0, color: 0xFF4CC9F0),
|
||||
Station(id: 'ST2', name: '加工工位', order: 1, color: 0xFFFFD166),
|
||||
Station(id: 'ST3', name: '检测工位', order: 2, color: 0xFF34D399),
|
||||
],
|
||||
actions: <Action>[
|
||||
const Action(
|
||||
id: 'A1',
|
||||
name: '动作 1',
|
||||
name: '上料',
|
||||
stationId: 'ST1',
|
||||
driver: '气缸 Y1',
|
||||
startAngle: 0,
|
||||
durationAngle: 70,
|
||||
durationAngle: 45,
|
||||
layer: 0,
|
||||
row: 0,
|
||||
color: kActionPalette[0],
|
||||
),
|
||||
Action(
|
||||
color: 0xFF4CC9F0),
|
||||
const Action(
|
||||
id: 'A2',
|
||||
name: '动作 2',
|
||||
stationId: 'ST2',
|
||||
name: '定位夹紧',
|
||||
stationId: 'ST1',
|
||||
driver: '气缸 Y2',
|
||||
startAngle: 80,
|
||||
durationAngle: 60,
|
||||
startAngle: 50,
|
||||
durationAngle: 55,
|
||||
layer: 0,
|
||||
color: 0xFF7BD88F,
|
||||
deps: <Dependency>[Dependency(fromId: 'A1', toId: 'A2', type: DepType.fs)]),
|
||||
const Action(
|
||||
id: 'A3',
|
||||
name: '伺服下压',
|
||||
stationId: 'ST2',
|
||||
driver: '伺服 M1',
|
||||
startAngle: 90,
|
||||
durationAngle: 70,
|
||||
layer: 1,
|
||||
row: 1,
|
||||
color: kActionPalette[1],
|
||||
deps: const <Dependency>[
|
||||
Dependency(fromId: 'A1', toId: 'A2', type: DepType.fs),
|
||||
color: 0xFFFFD166,
|
||||
deps: <Dependency>[Dependency(fromId: 'A2', toId: 'A3', type: DepType.fs)]),
|
||||
const Action(
|
||||
id: 'A4',
|
||||
name: '超声焊接',
|
||||
stationId: 'ST2',
|
||||
driver: '超声 U1',
|
||||
startAngle: 100,
|
||||
durationAngle: 50,
|
||||
layer: 2,
|
||||
color: 0xFFF472B6,
|
||||
deps: <Dependency>[
|
||||
Dependency(fromId: 'A3', toId: 'A4', type: DepType.ss, offsetAngle: 10)
|
||||
]),
|
||||
const Action(
|
||||
id: 'A5',
|
||||
name: '视觉检测',
|
||||
stationId: 'ST3',
|
||||
driver: '相机 C1',
|
||||
startAngle: 200,
|
||||
durationAngle: 70,
|
||||
layer: 1,
|
||||
color: 0xFF7C5CFF,
|
||||
deps: <Dependency>[Dependency(fromId: 'A4', toId: 'A5', type: DepType.fs)]),
|
||||
],
|
||||
units: const UnitSettings(timeUnit: TimeUnit.s),
|
||||
viewState: const ViewState(mode: ViewMode.bar),
|
||||
phaseZones: const <PhaseZone>[
|
||||
PhaseZone(name: '上料相位', startAngle: 0, endAngle: 70),
|
||||
PhaseZone(name: '加工相位', startAngle: 70, endAngle: 200),
|
||||
PhaseZone(name: '检测相位', startAngle: 200, endAngle: 360),
|
||||
],
|
||||
),
|
||||
];
|
||||
return Project(
|
||||
name: '未命名节拍',
|
||||
cycle: const Cycle(durationMs: 3600),
|
||||
stations: stations,
|
||||
actions: actions,
|
||||
units: const UnitSettings(),
|
||||
viewState: const ViewState(mode: ViewMode.bar, selectedIds: <String>['A1']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+38
-108
@@ -19,6 +19,7 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
@@ -37,6 +38,7 @@ class BarPainter extends CustomPainter {
|
||||
/// - [criticalActions]:关键路径上的动作 id 集合,用于描边高亮。
|
||||
/// - [criticalDeps]:关键路径上的依赖集合,键格式 `fromId->toId`。
|
||||
/// - [selectedId]:当前选中动作 id,可为空。
|
||||
/// - [selectedDep]:当前选中的依赖连线键(`from->to`),用于高亮。
|
||||
///
|
||||
/// 无副作用;实例不缓存布局,每次 [paint] 都重新计算。
|
||||
BarPainter({
|
||||
@@ -45,6 +47,7 @@ class BarPainter extends CustomPainter {
|
||||
required this.criticalActions,
|
||||
required this.criticalDeps,
|
||||
required this.selectedIds,
|
||||
this.selectedDep,
|
||||
this.guideAngle,
|
||||
this.dropLane,
|
||||
this.dropValid = true,
|
||||
@@ -61,6 +64,9 @@ class BarPainter extends CustomPainter {
|
||||
/// 当前选中的动作 id 集合(支持多选)。
|
||||
final Set<String> selectedIds;
|
||||
|
||||
/// 当前选中的依赖连线键(`from->to`);非空时该走线以强调色高亮。
|
||||
final String? selectedDep;
|
||||
|
||||
/// 拖拽相位分区边界时的参考角(度);非空时绘制一条竖直虚线参考。
|
||||
final double? guideAngle;
|
||||
|
||||
@@ -337,15 +343,15 @@ class BarPainter extends CustomPainter {
|
||||
final bool sel = selectedIds.contains(a.id);
|
||||
final bool crit = criticalActions.contains(a.id);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r.shift(const Offset(1.5, 2)), const Radius.circular(8)),
|
||||
RRect.fromRectAndRadius(r.shift(const Offset(1.5, 2)), const Radius.circular(3)),
|
||||
Paint()..color = tokens.shadow.withValues(alpha: tokens.shadowOp),
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(3)),
|
||||
Paint()..color = c.withValues(alpha: 0.92),
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(3)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
@@ -353,7 +359,7 @@ class BarPainter extends CustomPainter {
|
||||
);
|
||||
if (crit) {
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(8)),
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(3)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2
|
||||
@@ -369,7 +375,7 @@ class BarPainter extends CustomPainter {
|
||||
final double wx = layout.xFor(a.endAngle - 360) - layout.plotLeft;
|
||||
final Rect tail = Rect.fromLTWH(layout.plotLeft, r.top, math.max(wx, 2), r.height);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(tail, const Radius.circular(8)),
|
||||
RRect.fromRectAndRadius(tail, const Radius.circular(3)),
|
||||
Paint()..color = c.withValues(alpha: tokens.tailOp),
|
||||
);
|
||||
_text(canvas, '跨循环延续 ${(a.endAngle - 360).toStringAsFixed(0)}°',
|
||||
@@ -420,106 +426,21 @@ class BarPainter extends CustomPainter {
|
||||
///
|
||||
/// 参数 [layout] 提供条块矩形;[u] 当前未直接使用,保留以对齐调用接口。
|
||||
void _deps(Canvas canvas, BarLayout layout, UnitSettings u) {
|
||||
final List<Action> ordered = layout.ordered;
|
||||
// 以「泳道序号」判断依赖的相邻关系(同泳道多个动作不再误判)。
|
||||
final Map<String, int> index = <String, int>{
|
||||
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
|
||||
};
|
||||
int k = 0;
|
||||
// 走线统一由 [buildBarDepRoutes] 计算:同组自动错开 + 手动偏移,
|
||||
// 与画布的命中测试 / 拖拽调整共用同一份几何。
|
||||
final List<BarDepRoute> routes = buildBarDepRoutes(project, layout);
|
||||
// 依赖标签先收集、后统一避让放置(见方法末尾 _placeChips)。
|
||||
final List<_ChipSpec> chips = <_ChipSpec>[];
|
||||
for (final Action to in ordered) {
|
||||
for (final Dependency d in to.deps) {
|
||||
final Action? from = project.actionById(d.fromId);
|
||||
if (from == null) continue;
|
||||
final int ia = index[from.id] ?? 0;
|
||||
final int ib = index[to.id] ?? 0;
|
||||
for (final BarDepRoute r in routes) {
|
||||
final Dependency d = r.dep;
|
||||
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
|
||||
final bool crit = criticalDeps.contains('${d.fromId}->${d.toId}');
|
||||
// 标签缩短 + 字号收小,减少占位与相互遮挡(关键路径已由线条光晕表示)。
|
||||
final String label = switch (d.type) {
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${d.offsetAngle.toStringAsFixed(0)}°',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
final double chipW = _tp(label, 8.5, col, FontWeight.w600).width + 12;
|
||||
final Rect ra = layout.rectFor(from);
|
||||
final Rect rb = layout.rectFor(to);
|
||||
const double barHalf = BarLayout.barH / 2;
|
||||
final double sy = ra.center.dy;
|
||||
final double ty = rb.center.dy;
|
||||
final double dir = ty > sy ? 1 : -1;
|
||||
// 箭头落点:目标条块靠源一侧外缘再留 3px。
|
||||
final double tipY = ty - dir * (barHalf + 3);
|
||||
|
||||
final Path p = Path();
|
||||
double chipX;
|
||||
double chipY;
|
||||
Offset arrowTip;
|
||||
Offset arrowDir;
|
||||
// 同一泳道内的依赖(源/目标同 y):箭头连接两色块的外侧边缘。
|
||||
final bool sameLane = (ty - sy).abs() < 1;
|
||||
if (sameLane) {
|
||||
final bool fs = d.type == DepType.fs;
|
||||
final double startX = fs ? ra.right + 2 : ra.left - 2;
|
||||
double endX = rb.left - 2;
|
||||
if (endX < startX) endX = rb.right + 2;
|
||||
p.moveTo(startX, sy);
|
||||
p.lineTo(endX, sy);
|
||||
arrowTip = Offset(endX, sy);
|
||||
arrowDir = Offset(endX >= startX ? 1 : -1, 0);
|
||||
chipX = (startX + endX) / 2;
|
||||
chipY = sy - (barHalf + 9);
|
||||
// 两动作间距太短、图注放不下时,自动移到箭头右侧。
|
||||
if ((endX - startX).abs() < chipW + 8) chipX = endX + chipW / 2 + 6;
|
||||
} else if ((ib - ia).abs() <= 1) {
|
||||
// 相邻泳道:在两泳道之间的空隙中线走水平线,箭头指向目标条块。
|
||||
final double mid = (sy + ty) / 2;
|
||||
final double sx = d.type == DepType.fs ? ra.right : ra.left;
|
||||
final double ex = d.type == DepType.fs ? sx - 9 : sx + 9;
|
||||
final double tx = rb.left + 14;
|
||||
p.moveTo(ex, sy + dir * (barHalf + 2));
|
||||
p.lineTo(ex, mid);
|
||||
p.lineTo(tx, mid);
|
||||
p.lineTo(tx, tipY);
|
||||
arrowTip = Offset(tx, tipY);
|
||||
arrowDir = Offset(0, dir);
|
||||
chipX = (ex + tx) / 2;
|
||||
chipY = mid;
|
||||
if ((tx - ex).abs() < chipW + 10) chipX = tx + chipW / 2 + 6;
|
||||
} else {
|
||||
// 跨多行:扫描区间内所有条块边界,据此在外侧选一条竖直泳道。
|
||||
final double sx = d.type == DepType.fs ? ra.right : ra.left;
|
||||
final double ex = d.type == DepType.fs ? sx - 9 : sx + 9;
|
||||
final double tx = rb.left + 14;
|
||||
double maxRight = 0;
|
||||
double minLeft = double.infinity;
|
||||
final List<int> lanes = layout.lanes;
|
||||
for (int r = math.min(ia, ib) + 1; r < math.max(ia, ib); r++) {
|
||||
if (r < 0 || r >= lanes.length) continue;
|
||||
for (final Action aa in layout.actionsInLane(lanes[r])) {
|
||||
final Rect rr = layout.rectFor(aa);
|
||||
maxRight = math.max(maxRight, rr.right);
|
||||
minLeft = math.min(minLeft, rr.left);
|
||||
}
|
||||
}
|
||||
double lane = math.max(math.max(sx, tx), maxRight) + 28 + (k % 3) * 16;
|
||||
if (lane > layout.plotRight - 16) {
|
||||
lane = math.min(math.min(sx, tx), minLeft) - 28 - (k % 3) * 16;
|
||||
}
|
||||
final double srcGapY = sy + dir * (barHalf + 14);
|
||||
final double gapY = ty - dir * (barHalf + 6);
|
||||
p.moveTo(ex, sy + dir * (barHalf + 2));
|
||||
p.lineTo(ex, srcGapY);
|
||||
p.lineTo(lane, srcGapY);
|
||||
p.lineTo(lane, gapY);
|
||||
p.lineTo(tx, gapY);
|
||||
p.lineTo(tx, tipY);
|
||||
arrowTip = Offset(tx, tipY);
|
||||
arrowDir = Offset(0, dir);
|
||||
chipX = (lane + tx) / 2;
|
||||
chipY = gapY - (barHalf + 1);
|
||||
final bool crit = criticalDeps.contains(r.key);
|
||||
final bool sel = selectedDep == r.key;
|
||||
final Color draw = sel ? tokens.accent : col;
|
||||
final Path p = Path()
|
||||
..moveTo(r.points.first.dx, r.points.first.dy);
|
||||
for (int i = 1; i < r.points.length; i++) {
|
||||
p.lineTo(r.points[i].dx, r.points[i].dy);
|
||||
}
|
||||
// 关键路径依赖:先铺一层加粗低透明度光晕,再画主线。
|
||||
if (crit) {
|
||||
@@ -536,15 +457,24 @@ class BarPainter extends CustomPainter {
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = crit ? 1.1 : 0.85
|
||||
..strokeWidth = sel ? 2.0 : (crit ? 1.1 : 0.85)
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = col.withValues(alpha: 0.95),
|
||||
..color = sel ? draw : draw.withValues(alpha: 0.95),
|
||||
);
|
||||
_arrow(canvas, arrowTip, arrowDir, col);
|
||||
_arrow(canvas, r.arrowTip, r.arrowDir, draw);
|
||||
final String label = switch (d.type) {
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${d.offsetAngle.toStringAsFixed(0)}°',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
// 行程太短的连线:标签移到箭头外侧(宽度按真实字号精确测量)。
|
||||
final double chipW = _tp(label, 8.5, draw, FontWeight.w600).width + 12;
|
||||
final Offset chipCenter = r.chipRun < chipW + r.chipRunMargin
|
||||
? Offset(r.chipAltAnchor.dx + chipW / 2, r.chipAltAnchor.dy)
|
||||
: r.chipCenter;
|
||||
// 先记录标签位置,所有依赖线画完后统一避让放置(避免标签互相重叠)。
|
||||
chips.add(_ChipSpec(Offset(chipX, chipY), label, col));
|
||||
k++;
|
||||
}
|
||||
chips.add(_ChipSpec(chipCenter, label, draw));
|
||||
}
|
||||
_placeChips(canvas, chips);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
@@ -40,6 +41,7 @@ class CircularPainter extends CustomPainter {
|
||||
required this.criticalActions,
|
||||
required this.criticalDeps,
|
||||
required this.selectedIds,
|
||||
this.selectedDep,
|
||||
this.guideAngle,
|
||||
});
|
||||
|
||||
@@ -54,6 +56,9 @@ class CircularPainter extends CustomPainter {
|
||||
/// 当前选中的动作 id 集合(支持多选)。
|
||||
final Set<String> selectedIds;
|
||||
|
||||
/// 当前选中的依赖连线键(`from->to`);非空时该走线以强调色高亮。
|
||||
final String? selectedDep;
|
||||
|
||||
/// 拖拽动作弧端点时的参考角(度);非空时绘制一条径向虚线参考。
|
||||
final double? guideAngle;
|
||||
|
||||
@@ -131,13 +136,14 @@ class CircularPainter extends CustomPainter {
|
||||
|
||||
// 依赖连线先于动作弧绘制,使其位于弧之下、不被遮挡。
|
||||
if (project.viewState.showDeps) {
|
||||
// 走线统一由 [buildArcDepRoutes] 计算(同组自动错开 + 手动径向偏移),
|
||||
// 与画布命中测试 / 拖拽调整共用同一份几何。
|
||||
final List<ArcDepRoute> routes = buildArcDepRoutes(project, layout);
|
||||
final List<_ArcChip> chips = <_ArcChip>[];
|
||||
for (final Action to in project.actions) {
|
||||
for (final Dependency d in to.deps) {
|
||||
final _ArcChip? chip = _dep(canvas, layout, d);
|
||||
for (final ArcDepRoute r in routes) {
|
||||
final _ArcChip? chip = _drawDepRoute(canvas, layout, r);
|
||||
if (chip != null) chips.add(chip);
|
||||
}
|
||||
}
|
||||
_placeArcChips(canvas, layout, chips);
|
||||
}
|
||||
|
||||
@@ -310,25 +316,13 @@ class CircularPainter extends CustomPainter {
|
||||
for (int k = 0; k < segs.length; k++) {
|
||||
// 第二段且为跨循环时视为“尾巴”,需淡化处理。
|
||||
final bool tail = a.wrap && k == 1;
|
||||
final Path p = arcPath(c, r, segs[k][0], segs[k][1]);
|
||||
// 方头 + 小圆角:路径角度严格等于真实起止角,弧带长度即真实时长
|
||||
//(原来的圆头端帽会在两端各多出半个环宽,造成长度误读)。
|
||||
final Path p = _bandPath(c, r, th, segs[k][0], segs[k][1], 3);
|
||||
// 圆周色块不加描边 / 阴影,保持干净。
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = th
|
||||
..strokeCap = a.wrap ? StrokeCap.butt : StrokeCap.round
|
||||
..color = col.withValues(alpha: tail ? tokens.tailOp : 1),
|
||||
);
|
||||
canvas.drawPath(p, Paint()..color = col.withValues(alpha: tail ? tokens.tailOp : 1));
|
||||
if (tail) {
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = th
|
||||
..strokeCap = StrokeCap.butt
|
||||
..color = col.withValues(alpha: 0.9),
|
||||
);
|
||||
canvas.drawPath(p, Paint()..color = col.withValues(alpha: 0.9));
|
||||
}
|
||||
}
|
||||
if (crit) {
|
||||
@@ -377,64 +371,76 @@ class CircularPainter extends CustomPainter {
|
||||
_arcLabel(canvas, c, r, mid, '$step. ${a.id} ${a.name}', tokens.arcText, 11, math.max(arcLen - 12, 20));
|
||||
}
|
||||
|
||||
/// 绘制圆形视图中的依赖连线。
|
||||
/// 构造「方头 + 小圆角」的圆环动作带(填充路径)。
|
||||
///
|
||||
/// 路径由四段组成:从源弧末端沿半径到中间半径 [rC] → 沿圆弧走到目标弧
|
||||
/// 起点角度 → 再沿半径落到目标弧表面([rTip])→ 末端加箭头。
|
||||
/// - 相邻层取两层半径均值作为 [rC];层差大于 1 时改用最外圈 `rMax+24` 绕行。
|
||||
/// - [large]/[cw] 决定圆弧走大弧还是小弧、顺时针还是逆时针。
|
||||
/// - 关键依赖先画低透明度粗描边,再画主线,最后放置 `A→B 类型` 胶囊。
|
||||
_ArcChip? _dep(Canvas canvas, CircularLayout layout, Dependency d) {
|
||||
final Action? A = project.actionById(d.fromId);
|
||||
final Action? B = project.actionById(d.toId);
|
||||
if (A == null || B == null) return null;
|
||||
final Offset c = layout.center;
|
||||
final double rA = layout.radiusFor(A.layer);
|
||||
final double rB = layout.radiusFor(B.layer);
|
||||
final double aEnd = math.min(A.endAngle, 360);
|
||||
final double aStart = B.startAngle;
|
||||
// 层差大于 1 时从最外圈绕行,避免穿过中间层弧线。
|
||||
final bool skip = (A.layer - B.layer).abs() > 1;
|
||||
final double rC = skip ? layout.rMax + 24 : (rA + rB) / 2;
|
||||
final bool cw = aStart >= aEnd;
|
||||
final int large = (aStart - aEnd).abs() > 180 ? 1 : 0;
|
||||
final Offset p0 = polar(c, rA, aEnd);
|
||||
final Offset p1 = polar(c, rC, aEnd);
|
||||
final Offset p2 = polar(c, rC, aStart);
|
||||
final double rTip = rC < rB ? rB - layout.th / 2 - 4 : rB + layout.th / 2 + 4;
|
||||
final Offset p3 = polar(c, rTip, aStart);
|
||||
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
|
||||
final bool crit = criticalDeps.contains('${d.fromId}->${d.toId}');
|
||||
|
||||
// 起止角相同(FS 紧随其后)时路径会退化为一条从圆心附近拉出的径向直线,
|
||||
// 看起来像“杂线”。此时改为贴近目标环的**短箭头**,并让标签旁移。
|
||||
final bool degenerate = (aStart - aEnd).abs() < 0.5;
|
||||
final Path p;
|
||||
final Offset tipDir;
|
||||
final double chipR;
|
||||
final double chipDeg;
|
||||
if (degenerate) {
|
||||
final double r0 = rTip - (rTip > rB ? 28 : -28);
|
||||
final Offset q0 = polar(c, r0, aStart);
|
||||
p = Path()
|
||||
..moveTo(q0.dx, q0.dy)
|
||||
..lineTo(p3.dx, p3.dy);
|
||||
tipDir = p3 - q0;
|
||||
// 标签放在源环与目标环之间的径向空隙中,沿切向排布。
|
||||
chipR = (rA + rB) / 2;
|
||||
chipDeg = aStart;
|
||||
} else {
|
||||
p = Path()
|
||||
..moveTo(p0.dx, p0.dy)
|
||||
..lineTo(p1.dx, p1.dy)
|
||||
..arcToPoint(p2, radius: Radius.circular(rC), largeArc: large == 1, clockwise: cw)
|
||||
..lineTo(p3.dx, p3.dy);
|
||||
tipDir = p3 - p2;
|
||||
final double span = (aStart - aEnd).abs();
|
||||
chipR = skip ? rC : (span < 30 ? rB + layout.th / 2 + 10 : rC);
|
||||
chipDeg = (aEnd + aStart) / 2;
|
||||
/// 与「圆头描边」不同,路径覆盖的角度范围严格等于 [a0] → [a1](顺时针):
|
||||
/// 两端为径向直边、四角带 [cornerR] 的小圆角,因此弧带的长度就是动作的
|
||||
/// 真实时长,不会再像圆头端帽那样在两端各多出半个环宽造成长度误读。
|
||||
Path _bandPath(Offset c, double r, double w, double a0, double a1, double cornerR) {
|
||||
final double ro = r + w / 2;
|
||||
final double ri = r - w / 2;
|
||||
final double rc = math.min(cornerR, w / 2 - 0.5);
|
||||
final double span = a1 - a0;
|
||||
final Path p = Path();
|
||||
if (rc <= 0.5 || span <= 0.5) {
|
||||
// 退化情形:直接方头四边形。
|
||||
final Offset a = polar(c, ro, a0);
|
||||
p.moveTo(a.dx, a.dy);
|
||||
final Offset b = polar(c, ro, a1);
|
||||
p.lineTo(b.dx, b.dy);
|
||||
final Offset d = polar(c, ri, a1);
|
||||
p.lineTo(d.dx, d.dy);
|
||||
final Offset e = polar(c, ri, a0);
|
||||
p.lineTo(e.dx, e.dy);
|
||||
p.close();
|
||||
return p;
|
||||
}
|
||||
// 小圆角在内 / 外缘占用的角向宽度(度),不超过跨度的 40%。
|
||||
final double dOut = math.min(rc / ro * 180 / math.pi, span * 0.4);
|
||||
final double dIn = math.min(rc / ri * 180 / math.pi, span * 0.4);
|
||||
final Offset oStart = polar(c, ro, a0 + dOut);
|
||||
final Offset oEnd = polar(c, ro, a1 - dOut);
|
||||
final Offset iEnd = polar(c, ri, a1 - dIn);
|
||||
final Offset iStart = polar(c, ri, a0 + dIn);
|
||||
p.moveTo(oStart.dx, oStart.dy);
|
||||
// 外缘弧(顺时针)
|
||||
p.arcToPoint(oEnd,
|
||||
radius: Radius.circular(ro), largeArc: span - 2 * dOut > 180, clockwise: true);
|
||||
// 尾端:外角 → 小圆角 → 端面 → 小圆角 → 内缘
|
||||
final Offset co = polar(c, ro, a1);
|
||||
final Offset fo = polar(c, ro - rc, a1);
|
||||
p.quadraticBezierTo(co.dx, co.dy, fo.dx, fo.dy);
|
||||
final Offset fi = polar(c, ri + rc, a1);
|
||||
p.lineTo(fi.dx, fi.dy);
|
||||
final Offset ci = polar(c, ri, a1);
|
||||
p.quadraticBezierTo(ci.dx, ci.dy, iEnd.dx, iEnd.dy);
|
||||
// 内缘弧(逆时针返回)
|
||||
p.arcToPoint(iStart,
|
||||
radius: Radius.circular(ri), largeArc: span - 2 * dIn > 180, clockwise: false);
|
||||
// 起始端:内角 → 小圆角 → 端面 → 小圆角 → 外角
|
||||
final Offset ci0 = polar(c, ri, a0);
|
||||
final Offset fi0 = polar(c, ri + rc, a0);
|
||||
p.quadraticBezierTo(ci0.dx, ci0.dy, fi0.dx, fi0.dy);
|
||||
final Offset fo0 = polar(c, ro - rc, a0);
|
||||
p.lineTo(fo0.dx, fo0.dy);
|
||||
final Offset co0 = polar(c, ro, a0);
|
||||
p.quadraticBezierTo(co0.dx, co0.dy, oStart.dx, oStart.dy);
|
||||
p.close();
|
||||
return p;
|
||||
}
|
||||
|
||||
/// 绘制一条圆周依赖走线(几何来自 [ArcDepRoute],与命中测试 / 拖拽共用)。
|
||||
///
|
||||
/// 关键依赖先画低透明度粗描边、再画主线;选中的连线以强调色加粗高亮。
|
||||
/// 标签不在此处直接绘制:收集后统一避让放置(见 [_placeArcChips])。
|
||||
_ArcChip? _drawDepRoute(Canvas canvas, CircularLayout layout, ArcDepRoute r) {
|
||||
final Dependency d = r.dep;
|
||||
final Color col = d.type == DepType.fs ? tokens.fs : tokens.ss;
|
||||
final bool crit = criticalDeps.contains(r.key);
|
||||
final bool sel = selectedDep == r.key;
|
||||
final Color draw = sel ? tokens.accent : col;
|
||||
|
||||
final Path p = r.buildPath();
|
||||
if (crit) {
|
||||
canvas.drawPath(
|
||||
p,
|
||||
@@ -449,18 +455,16 @@ class CircularPainter extends CustomPainter {
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = crit ? 1.2 : (d.type == DepType.fs ? 1.0 : 0.9)
|
||||
..strokeWidth = sel ? 2.2 : (crit ? 1.2 : (d.type == DepType.fs ? 1.0 : 0.9))
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = col,
|
||||
..color = draw,
|
||||
);
|
||||
_arrow(canvas, p3, tipDir, col);
|
||||
_arrow(canvas, r.p3, r.tipDir, draw);
|
||||
|
||||
String label = d.type == DepType.fs ? 'FS' : 'SS+${d.offsetAngle.toStringAsFixed(0)}°';
|
||||
if (d.type == DepType.ff) label = 'FF';
|
||||
if (d.type == DepType.sf) label = 'SF';
|
||||
// 标签不在此处直接绘制:收集后统一避让放置(见 [_placeArcChips]),
|
||||
// 字号收小、取消五角星,避免多个依赖(尤其 FS 与 SS 并存)互相压盖。
|
||||
return _ArcChip(chipR, chipDeg, '${A.id}→${B.id} $label', col);
|
||||
return _ArcChip(r.chipR, r.chipDeg, '${d.fromId}→${d.toId} $label', draw);
|
||||
}
|
||||
|
||||
/// 统一绘制圆周视图的依赖标签:沿半径方向逐级外移 / 内移避让,避免相互重叠。
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
/// 流程图绘制器:把时序图渲染为纵向泳道流程图(只读视图)。
|
||||
///
|
||||
/// 视觉体系与条形 / 圆周视图一致:泳道背景用环带色、依赖用 FS 绿 / SS 琥珀、
|
||||
/// 关键路径加粗带光晕、选中节点高亮描边。
|
||||
library;
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../theme/tokens.dart';
|
||||
|
||||
/// 流程图 [CustomPainter] 实现。
|
||||
class FlowchartPainter extends CustomPainter {
|
||||
/// 构造。
|
||||
const FlowchartPainter({
|
||||
required this.project,
|
||||
required this.tokens,
|
||||
required this.criticalActions,
|
||||
required this.criticalDeps,
|
||||
required this.selectedIds,
|
||||
this.selectedDep,
|
||||
});
|
||||
|
||||
/// 项目数据。
|
||||
final Project project;
|
||||
/// 主题令牌。
|
||||
final Tokens tokens;
|
||||
/// 关键路径动作 id。
|
||||
final Set<String> criticalActions;
|
||||
/// 关键路径依赖(`from->to`)。
|
||||
final Set<String> criticalDeps;
|
||||
/// 选中动作 id。
|
||||
final Set<String> selectedIds;
|
||||
|
||||
/// 当前选中的依赖连线键(`from->to`);非空时该走线以强调色高亮。
|
||||
final String? selectedDep;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final FlowLayout layout = FlowLayout(
|
||||
project,
|
||||
criticalActions: criticalActions,
|
||||
criticalDeps: criticalDeps,
|
||||
);
|
||||
if (layout.nodes.isEmpty) return;
|
||||
_phaseRail(canvas, layout);
|
||||
_lanes(canvas, layout);
|
||||
_edges(canvas, layout);
|
||||
_nodes(canvas, layout);
|
||||
}
|
||||
|
||||
/// 绘制左侧相位阶段栏:把相位色带「竖起来」——窄竖带 + 旋转 90° 的分区名,
|
||||
/// 纵向与流程行严格对齐;重叠的分区台阶式向右错位(每级 20px)。
|
||||
void _phaseRail(Canvas canvas, FlowLayout layout) {
|
||||
if (layout.spans.isEmpty) return;
|
||||
final double rowPitch = FlowLayout.nodeH + FlowLayout.rankGap;
|
||||
for (final FlowPhaseSpan s in layout.spans) {
|
||||
// 上下边界对齐到动作行边缘(统一 6px 内缩)。
|
||||
final double top = FlowLayout.marginY + s.rankTop * rowPitch - 6;
|
||||
final double bottom =
|
||||
FlowLayout.marginY + s.rankBottom * rowPitch + FlowLayout.nodeH + 6;
|
||||
final double left = FlowLayout.railX + s.slot * FlowLayout.railStep;
|
||||
final Rect r = Rect.fromLTRB(left, top, left + FlowLayout.railW, bottom);
|
||||
final RRect rr = RRect.fromRectAndRadius(r, const Radius.circular(9));
|
||||
// 视觉语言与条形视图的相位色带一致(强调色低透明度 + 细描边)。
|
||||
canvas.drawRRect(rr, Paint()..color = tokens.accent.withValues(alpha: 0.10));
|
||||
canvas.drawRRect(
|
||||
rr,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = tokens.accent.withValues(alpha: 0.45),
|
||||
);
|
||||
// 分区名:旋转 90° 竖排(从下往上读),居中于竖带。
|
||||
final TextPainter tp = _tp(s.zone.name, 10.5, tokens.sub, FontWeight.w700);
|
||||
canvas.save();
|
||||
canvas.translate(r.center.dx, r.center.dy);
|
||||
canvas.rotate(-math.pi / 2);
|
||||
tp.paint(canvas, Offset(-tp.width / 2, -tp.height / 2));
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制泳道背景带与标题(泳道 = 轨道)。
|
||||
void _lanes(Canvas canvas, FlowLayout layout) {
|
||||
final double lanePitch = FlowLayout.nodeW + FlowLayout.laneGap;
|
||||
final double top = layout.bounds.top + 20;
|
||||
final double bottom = layout.bounds.bottom - 20;
|
||||
for (int i = 0; i < layout.lanes.length; i++) {
|
||||
final double cx = FlowLayout.marginX + i * lanePitch + FlowLayout.nodeW / 2;
|
||||
final Rect band = Rect.fromLTRB(
|
||||
cx - FlowLayout.nodeW / 2 - 26,
|
||||
top,
|
||||
cx + FlowLayout.nodeW / 2 + 26,
|
||||
bottom,
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(band, const Radius.circular(14)),
|
||||
Paint()..color = (i.isEven ? tokens.ringA : tokens.ringB).withValues(alpha: 0.55),
|
||||
);
|
||||
_text(canvas, '轨道 L${i + 1}', Offset(cx, top + 16),
|
||||
color: tokens.sub, size: 11, weight: FontWeight.w700, align: TextAlign.center);
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制连线:FS 实线、SS 虚线(带偏移角标注)、关键路径加粗光晕。
|
||||
///
|
||||
/// 走线由 [FlowLayout.routes] 统一计算(与 SVG / drawio 导出共用同一几何)。
|
||||
void _edges(Canvas canvas, FlowLayout layout) {
|
||||
for (final FlowEdgeRoute r in layout.routes) {
|
||||
final FlowEdge e = r.edge;
|
||||
final Color col = e.type == null
|
||||
? tokens.sub
|
||||
: (e.type == DepType.fs ? tokens.fs : tokens.ss);
|
||||
// 选中的依赖连线以强调色加粗高亮(拖拽调整走线时可见)。
|
||||
final bool sel = selectedDep == r.key;
|
||||
final Color draw = sel ? tokens.accent : col;
|
||||
final Path p = Path()..moveTo(r.points.first.dx, r.points.first.dy);
|
||||
for (int i = 1; i < r.points.length; i++) {
|
||||
p.lineTo(r.points[i].dx, r.points[i].dy);
|
||||
}
|
||||
if (e.critical) {
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 5
|
||||
..strokeJoin = StrokeJoin.round
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = col.withValues(alpha: 0.18),
|
||||
);
|
||||
}
|
||||
final Paint line = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = sel ? 2.4 : (e.critical ? 1.8 : 1.2)
|
||||
..strokeJoin = StrokeJoin.round
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = sel ? draw : draw.withValues(alpha: e.type == null ? 0.7 : 0.95);
|
||||
if (r.dashed) {
|
||||
_dashPath(canvas, p, line);
|
||||
} else {
|
||||
canvas.drawPath(p, line);
|
||||
}
|
||||
_arrow(canvas, r.tip, r.dir, draw);
|
||||
// FS / SS+偏移 标签
|
||||
if (e.type != null) {
|
||||
final String text = switch (e.type!) {
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
_chip(canvas, r.labelAt, text, draw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制节点:动作 = 圆角矩形(标题 + 时长/工位),开始 / 结束 = 胶囊。
|
||||
void _nodes(Canvas canvas, FlowLayout layout) {
|
||||
for (final FlowNode n in layout.nodes) {
|
||||
final bool sel = n.action != null && selectedIds.contains(n.id);
|
||||
final bool crit = n.action != null && criticalActions.contains(n.id);
|
||||
if (n.isStart || n.isEnd) {
|
||||
final RRect rr = RRect.fromRectAndRadius(n.rect, Radius.circular(n.rect.height / 2));
|
||||
canvas.drawRRect(rr, Paint()..color = tokens.panel2);
|
||||
canvas.drawRRect(
|
||||
rr,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.2
|
||||
..color = tokens.accent,
|
||||
);
|
||||
_text(canvas, n.title, n.rect.center,
|
||||
color: tokens.accent, size: 13, weight: FontWeight.w700, align: TextAlign.center);
|
||||
continue;
|
||||
}
|
||||
final Color c = Color(n.action!.color);
|
||||
final RRect rr = RRect.fromRectAndRadius(n.rect, const Radius.circular(10));
|
||||
canvas.drawRRect(
|
||||
rr.shift(const Offset(1.5, 2)),
|
||||
Paint()..color = tokens.shadow.withValues(alpha: tokens.shadowOp),
|
||||
);
|
||||
canvas.drawRRect(rr, Paint()..color = c.withValues(alpha: 0.92));
|
||||
canvas.drawRRect(
|
||||
rr,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = sel ? 1.8 : 1
|
||||
..color = sel ? tokens.accent : tokens.selOutline.withValues(alpha: 0.25),
|
||||
);
|
||||
if (crit) {
|
||||
canvas.drawRRect(
|
||||
rr,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 2
|
||||
..color = tokens.crit,
|
||||
);
|
||||
}
|
||||
_text(canvas, n.title, Offset(n.rect.center.dx, n.rect.top + 21),
|
||||
color: tokens.arcText, size: 12, weight: FontWeight.w700, align: TextAlign.center);
|
||||
_text(canvas, n.subtitle, Offset(n.rect.center.dx, n.rect.top + 41),
|
||||
color: tokens.arcText.withValues(alpha: 0.85), size: 10, align: TextAlign.center);
|
||||
}
|
||||
}
|
||||
|
||||
/// 按虚线绘制路径(SS 依赖)。
|
||||
void _dashPath(Canvas canvas, Path path, Paint paint, {double dash = 6, double gap = 4}) {
|
||||
for (final ui.PathMetric metric in path.computeMetrics()) {
|
||||
double dist = 0;
|
||||
while (dist < metric.length) {
|
||||
final double end = math.min(dist + dash, metric.length);
|
||||
canvas.drawPath(metric.extractPath(dist, end), paint);
|
||||
dist = end + gap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 在 [tip] 处绘制指向 [dir] 方向的实心三角箭头。
|
||||
void _arrow(Canvas canvas, Offset tip, Offset dir, Color col) {
|
||||
const double s = 7;
|
||||
final Offset b = tip - dir * s;
|
||||
final Offset n = Offset(-dir.dy, dir.dx) * s * 0.5;
|
||||
final Path p = Path()
|
||||
..moveTo(tip.dx, tip.dy)
|
||||
..lineTo(b.dx + n.dx, b.dy + n.dy)
|
||||
..lineTo(b.dx - n.dx, b.dy - n.dy)
|
||||
..close();
|
||||
canvas.drawPath(p, Paint()..color = col);
|
||||
}
|
||||
|
||||
/// 绘制 FS / SS 标签胶囊(与条形视图风格一致,字号略小)。
|
||||
void _chip(Canvas canvas, Offset center, String text, Color col) {
|
||||
final TextPainter tp = _tp(text, 8.5, col, FontWeight.w600);
|
||||
final double w = tp.width + 12;
|
||||
const double h = 14;
|
||||
final Rect r = Rect.fromCenter(center: center, width: w, height: h);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(5)),
|
||||
Paint()..color = tokens.chip,
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(r, const Radius.circular(5)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = col,
|
||||
);
|
||||
tp.paint(canvas, Offset(r.left + 6, r.center.dy - tp.height / 2));
|
||||
}
|
||||
|
||||
/// 构造并布局一个 [TextPainter](与其它视图一致的字体设置)。
|
||||
TextPainter _tp(String s, double size, Color color, FontWeight weight,
|
||||
{TextAlign align = TextAlign.left}) {
|
||||
return TextPainter(
|
||||
text: TextSpan(
|
||||
text: s,
|
||||
style: TextStyle(
|
||||
color: color, fontSize: size, fontWeight: weight, fontFamily: 'Microsoft YaHei UI'),
|
||||
),
|
||||
textDirection: ui.TextDirection.ltr,
|
||||
textAlign: align,
|
||||
)..layout();
|
||||
}
|
||||
|
||||
/// 便捷文本绘制(按 [align] 相对 [at] 对齐,垂直居中)。
|
||||
void _text(Canvas canvas, String s, Offset at,
|
||||
{required Color color,
|
||||
double size = 12,
|
||||
FontWeight weight = FontWeight.normal,
|
||||
TextAlign align = TextAlign.left}) {
|
||||
final TextPainter tp = _tp(s, size, color, weight, align: align);
|
||||
double dx = at.dx;
|
||||
if (align == TextAlign.center) dx -= tp.width / 2;
|
||||
if (align == TextAlign.right) dx -= tp.width;
|
||||
tp.paint(canvas, Offset(dx, at.dy - tp.height / 2));
|
||||
}
|
||||
|
||||
/// 视图数据实时联动,始终重绘。
|
||||
@override
|
||||
bool shouldRepaint(covariant FlowchartPainter old) => true;
|
||||
}
|
||||
@@ -13,7 +13,9 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../persistence/storage.dart';
|
||||
@@ -79,6 +81,9 @@ class AppController extends ChangeNotifier {
|
||||
/// 状态栏文本。
|
||||
String _status = '就绪';
|
||||
|
||||
/// 控制器是否已释放([dispose] 之后置真,用于拦截迟到的回调)。
|
||||
bool _disposed = false;
|
||||
|
||||
/// 最近一次保存时间。
|
||||
DateTime? _lastSavedAt;
|
||||
|
||||
@@ -143,6 +148,7 @@ class AppController extends ChangeNotifier {
|
||||
/// 释放资源:取消自动保存定时器并调用父类 dispose。
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_autosaveTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -304,11 +310,27 @@ class AppController extends ChangeNotifier {
|
||||
/// 从完整路径中提取文件名(兼容 `\` 与 `/` 分隔符)。
|
||||
static String _baseName(String p) => p.split(RegExp(r'[\\/]')).last;
|
||||
|
||||
/// 切换视图模式并更新状态栏文本。
|
||||
/// 切换视图模式(条形 / 圆周 / 流程图)并更新状态栏文本。
|
||||
///
|
||||
/// 三种视图共用同一套缩放 / 平移状态,切换后自动适配一次视图
|
||||
/// (各视图坐标系与内容范围不同,避免出现「看不到内容」)。
|
||||
void setViewMode(ViewMode mode) {
|
||||
_project = _project.copyWith(viewState: _project.viewState.copyWith(mode: mode));
|
||||
_status = mode == ViewMode.bar ? '条形节拍视图' : '圆周节拍视图';
|
||||
_status = switch (mode) {
|
||||
ViewMode.bar => '条形节拍视图',
|
||||
ViewMode.circular => '圆周节拍视图',
|
||||
ViewMode.flow => '流程图视图(只读)',
|
||||
};
|
||||
notifyListeners();
|
||||
// 每次切换视图都自动执行一次「适应窗口」:三个视图的内容范围不同,
|
||||
// 不重置就会沿用上一个视图的缩放 / 平移,画面看起来就「跑了」。
|
||||
fitView(silent: true);
|
||||
// 再补一帧:画布可能因侧栏开合 / 窗口尺寸在同一批布局中变化,
|
||||
// 等该帧结束后按最新视口再适配一次,确保切换后必定处于适配状态。
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_disposed || _project.viewState.mode != mode) return;
|
||||
fitView(silent: true);
|
||||
});
|
||||
}
|
||||
|
||||
/// 选中指定动作([id] 为 null 表示清空选中)并刷新。
|
||||
@@ -432,8 +454,11 @@ class AppController extends ChangeNotifier {
|
||||
///
|
||||
/// - 圆周视图:内容为「最外环 + 刻度环 + 文字」的圆,按直径求缩放,
|
||||
/// 并把圆心平移到视口中心;层数很多导致布局溢出时自动缩小。
|
||||
/// - 条形视图:布局本身按视口高度自适应,直接回到 `zoom = 1`。
|
||||
void fitView() {
|
||||
/// - 条形视图:布局本身按视口高度自适应,动作较多触发缩小时内容居中。
|
||||
/// - 流程图:按节点内容范围适配并居中。
|
||||
///
|
||||
/// [silent] 为真时不改写状态栏文案(供视图切换时自动调用)。
|
||||
void fitView({bool silent = false}) {
|
||||
final Size vp = _viewport;
|
||||
if (vp.width <= 0 || vp.height <= 0) {
|
||||
resetView();
|
||||
@@ -442,7 +467,22 @@ class AppController extends ChangeNotifier {
|
||||
double z = 1;
|
||||
double px = 0;
|
||||
double py = 0;
|
||||
if (_project.viewState.mode == ViewMode.circular) {
|
||||
if (_project.viewState.mode == ViewMode.flow) {
|
||||
// 流程图:按内容范围等比适配并居中;顶部只需为单行标题浮层留白。
|
||||
final FlowLayout l = FlowLayout(
|
||||
_project,
|
||||
criticalActions: criticalActions,
|
||||
criticalDeps: criticalDeps,
|
||||
);
|
||||
final Rect b = l.nodes.isEmpty ? const Rect.fromLTWH(0, 0, 420, 300) : l.bounds;
|
||||
const double topPad = 72;
|
||||
const double bottomPad = 28;
|
||||
final double availW = vp.width - 96;
|
||||
final double availH = vp.height - topPad - bottomPad;
|
||||
z = math.min(availW / b.width, availH / b.height).clamp(0.25, 1.5);
|
||||
px = vp.width / 2 - b.center.dx * z;
|
||||
py = topPad + availH / 2 - b.center.dy * z;
|
||||
} else if (_project.viewState.mode == ViewMode.circular) {
|
||||
final CircularLayout l = CircularLayout(_project, vp);
|
||||
// 半径需覆盖:刻度文字(tickR + ~50)、顺时针箭头(rMax + ~70)、
|
||||
// 12 点钟起点标记(tickR + ~70),再留 20px 余量,避免任何标注被裁掉。
|
||||
@@ -456,16 +496,19 @@ class AppController extends ChangeNotifier {
|
||||
py = vp.height / 2 - center.dy * z;
|
||||
} else {
|
||||
final BarLayout l = BarLayout(_project, vp);
|
||||
// 内容逻辑范围:(0,0) → 右缘 + 60、最后一行底部 + 40。
|
||||
final double contentW = l.plotRight + 60;
|
||||
final double contentH = l.yFor(l.ordered.length) + 40;
|
||||
z = math.min(vp.width / contentW, vp.height / contentH).clamp(0.25, 1.0);
|
||||
px = 0;
|
||||
py = 0;
|
||||
// 关键修复:内容被缩小时按内容范围居中显示;内容本来就能放下时保持默认位置。
|
||||
// (此前固定 pan = 0,缩小的画面会被钉在左上角。)
|
||||
px = z < 1 ? (vp.width - contentW * z) / 2 : 0;
|
||||
py = z < 1 ? (vp.height - contentH * z) / 2 : 0;
|
||||
}
|
||||
_project = _project.copyWith(
|
||||
viewState: _project.viewState.copyWith(zoom: z, panX: px, panY: py),
|
||||
);
|
||||
_status = '适应窗口';
|
||||
if (!silent) _status = '适应窗口';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -794,6 +837,27 @@ class AppController extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
/// 设置依赖走线的手动偏移(拖拽连线时调用;单位 px,限制 ±200)。
|
||||
///
|
||||
/// 条形 / 流程图为横向走线的纵向偏移(跨行走廊为水平偏移),
|
||||
/// 圆周为绕行圆弧的半径偏移;传入 0 即恢复自动位置。
|
||||
/// 拖动过程中可高频调用,撤销历史与其它拖拽编辑保持一致(每次压栈)。
|
||||
void setDependencyOffset(String fromId, String toId, double value, {String? status}) {
|
||||
final Action? to = _project.actionById(toId);
|
||||
if (to == null) return;
|
||||
if (!to.deps.any((Dependency d) => d.fromId == fromId)) return;
|
||||
final double v = value.clamp(-kMaxRouteOffset, kMaxRouteOffset);
|
||||
final List<Dependency> deps = to.deps
|
||||
.map((Dependency d) => d.fromId == fromId ? d.copyWith(routeOffset: v) : d)
|
||||
.toList();
|
||||
updateAction(toId, (Action x) => x.copyWith(deps: deps), status: status);
|
||||
}
|
||||
|
||||
/// 复位依赖走线的手动偏移(双击连线 / 右键菜单调用)。
|
||||
void resetDependencyOffset(String fromId, String toId) {
|
||||
setDependencyOffset(fromId, toId, 0, status: '已复位依赖走线 $fromId→$toId');
|
||||
}
|
||||
|
||||
/// 计算关键路径并更新 [_criticalActions] / [_criticalDeps]。
|
||||
///
|
||||
/// 采用“最早开始时间(EST)+ 拓扑排序 + 反向回溯”的经典方法:
|
||||
|
||||
+308
-98
@@ -15,6 +15,7 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../export/drawio_writer.dart';
|
||||
import '../export/export_renderer.dart';
|
||||
import '../export/svg_writer.dart';
|
||||
import '../model/models.dart';
|
||||
@@ -30,6 +31,7 @@ import 'canvas_overlays.dart';
|
||||
import 'canvas_view.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'update_dialog.dart';
|
||||
import 'update_icon.dart';
|
||||
|
||||
/// 应用外壳组件:承载主界面布局与文件/侧栏等交互逻辑。
|
||||
class AppShell extends StatefulWidget {
|
||||
@@ -249,6 +251,8 @@ class _AppShellState extends State<AppShell> {
|
||||
}
|
||||
|
||||
/// 导出 SVG:将当前视图交给 [SvgWriter] 生成矢量内容并写入文件。
|
||||
///
|
||||
/// 三种视图均支持(流程图由 [FlowLayout] 几何直接生成)。
|
||||
Future<void> _exportSvg() async {
|
||||
if (!c.licensed) {
|
||||
if (mounted) await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 SVG。');
|
||||
@@ -299,6 +303,8 @@ class _AppShellState extends State<AppShell> {
|
||||
}
|
||||
|
||||
/// 导出 PNG:以固定 1920×1080 画布离屏渲染(标题固定左上、内容自适应缩放)。
|
||||
///
|
||||
/// 三种视图均支持(流程图走 [FlowchartPainter] 离屏渲染)。
|
||||
Future<void> _exportPng() async {
|
||||
if (!c.licensed) {
|
||||
if (mounted) await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 PNG。');
|
||||
@@ -351,6 +357,55 @@ class _AppShellState extends State<AppShell> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 导出 drawio:仅流程图视图提供,输出 diagrams.net 可直接打开并继续编辑的 XML。
|
||||
///
|
||||
/// 条形 / 圆周视图调用时给出明确提示(不做静默失败)。
|
||||
Future<void> _exportDrawio() async {
|
||||
if (c.project.viewState.mode != ViewMode.flow) {
|
||||
if (mounted) {
|
||||
await showMessage(context, '导出 drawio', '仅流程图视图支持导出 drawio;条形 / 圆周视图请导出 SVG 或 PNG。');
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!c.licensed) {
|
||||
if (mounted) await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 drawio。');
|
||||
return;
|
||||
}
|
||||
final String xml = DrawioWriter(project: c.project, tokens: Tokens.of(c.brightness)).build();
|
||||
// 安卓版:写入公共 Documents 目录。
|
||||
if (AndroidDocs.isAvailable) {
|
||||
final String? name = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => AndroidFileDialog(
|
||||
saveMode: true,
|
||||
defaultName: '${c.project.name}.drawio',
|
||||
suffix: '.drawio',
|
||||
),
|
||||
);
|
||||
if (name == null) return;
|
||||
try {
|
||||
await AndroidDocs.saveFile(name, Uint8List.fromList(utf8.encode(xml)), mime: 'application/xml');
|
||||
if (mounted) c.setStatus('已导出 ${AndroidDocs.location()}/$name');
|
||||
} catch (e) {
|
||||
if (mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
return;
|
||||
}
|
||||
final String? path = await pickFile(
|
||||
context,
|
||||
save: true,
|
||||
defaultName: '${c.project.name}.drawio',
|
||||
suffix: '.drawio',
|
||||
);
|
||||
if (path == null) return;
|
||||
try {
|
||||
await File(path).writeAsString(xml, flush: true);
|
||||
if (mounted) c.setStatus('已导出 $path');
|
||||
} catch (e) {
|
||||
if (mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== 主界面构建 =====================
|
||||
|
||||
/// 构建主界面:绑定全局快捷键,按“工具栏 / 中部(侧栏 + 画布) / 状态栏”
|
||||
@@ -358,16 +413,22 @@ class _AppShellState extends State<AppShell> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
// 流程图视图只读:撤销 / 重做 / 删除等编辑操作统一停用(与置灰按钮一致)。
|
||||
final bool flow = c.project.viewState.mode == ViewMode.flow;
|
||||
// 全局快捷键绑定:编辑、文件、帮助、主题等。
|
||||
return CallbackShortcuts(
|
||||
bindings: <ShortcutActivator, VoidCallback>{
|
||||
const SingleActivator(LogicalKeyboardKey.keyZ, control: true): c.undo,
|
||||
const SingleActivator(LogicalKeyboardKey.keyY, control: true): c.redo,
|
||||
const SingleActivator(LogicalKeyboardKey.keyZ, control: true): () {
|
||||
if (!flow) c.undo();
|
||||
},
|
||||
const SingleActivator(LogicalKeyboardKey.keyY, control: true): () {
|
||||
if (!flow) c.redo();
|
||||
},
|
||||
const SingleActivator(LogicalKeyboardKey.keyS, control: true): _save,
|
||||
const SingleActivator(LogicalKeyboardKey.keyO, control: true): _open,
|
||||
const SingleActivator(LogicalKeyboardKey.keyN, control: true): _newProject,
|
||||
const SingleActivator(LogicalKeyboardKey.delete): () {
|
||||
if (c.selectedId != null) c.deleteAction(c.selectedId!);
|
||||
if (!flow && c.selectedId != null) c.deleteAction(c.selectedId!);
|
||||
},
|
||||
const SingleActivator(LogicalKeyboardKey.f1): () =>
|
||||
showDialog<void>(context: context, builder: (_) => const HelpDialog()),
|
||||
@@ -458,20 +519,23 @@ class _AppShellState extends State<AppShell> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新检查按钮。
|
||||
///
|
||||
/// 空闲态用环形箭头(检查更新,中文软件的通用语义);
|
||||
/// 检测到新版本时换成下载图标并叠加红色角标,一眼可辨「有新版本可下载」。
|
||||
/// 更新检查按钮:圆环 + 上箭头 + 底座(按 docs/更新.png 的设计绘制);
|
||||
/// 检测到新版本时叠加红色角标。
|
||||
Widget _updateBtn(Tokens t) {
|
||||
final UpdateInfo? info = _update;
|
||||
final Widget btn = _iconBtn(
|
||||
t,
|
||||
info == null ? Icons.refresh : Icons.download,
|
||||
final Widget btn = _iconWidgetBtn(
|
||||
UpdateIcon(size: 18 * _toolScale, color: t.text),
|
||||
_openUpdate,
|
||||
tooltip: info == null ? '检查更新' : '发现新版本 v${info.version}',
|
||||
);
|
||||
if (info == null) return btn;
|
||||
return Badge(backgroundColor: t.danger, smallSize: 8, child: btn);
|
||||
// 红点固定放在按钮左上角(默认是右上角,更醒目也符合「有更新」的提示习惯)。
|
||||
return Badge(
|
||||
backgroundColor: t.danger,
|
||||
smallSize: 8,
|
||||
alignment: Alignment.topLeft,
|
||||
child: btn,
|
||||
);
|
||||
}
|
||||
|
||||
/// 打开更新对话框:已有检测结果时直接弹出,否则先检查一次。
|
||||
@@ -511,6 +575,7 @@ class _AppShellState extends State<AppShell> {
|
||||
/// 触屏平台(安卓)整体缩放 [_toolScale],一排放下全部操作。
|
||||
Widget _toolbar(Tokens t) {
|
||||
final double s = _toolScale;
|
||||
final bool flow = c.project.viewState.mode == ViewMode.flow;
|
||||
return Container(
|
||||
height: 54 * s,
|
||||
padding: EdgeInsets.symmetric(horizontal: 6 * s),
|
||||
@@ -572,18 +637,19 @@ class _AppShellState extends State<AppShell> {
|
||||
_iconBtn(t, Icons.folder_open_outlined, _open, tooltip: '打开 Ctrl+O'),
|
||||
_iconBtn(t, Icons.save_outlined, _save, tooltip: '保存 Ctrl+S'),
|
||||
SizedBox(width: 6 * s),
|
||||
_iconBtn(t, Icons.undo, c.canUndo ? c.undo : null, tooltip: '撤销 Ctrl+Z'),
|
||||
_iconBtn(t, Icons.redo, c.canRedo ? c.redo : null, tooltip: '重做 Ctrl+Y'),
|
||||
// 流程图只读:撤销 / 重做置灰(修改请回时序图)。
|
||||
_iconBtn(t, Icons.undo, !flow && c.canUndo ? c.undo : null,
|
||||
tooltip: flow ? '撤销(流程图只读)' : '撤销 Ctrl+Z'),
|
||||
_iconBtn(t, Icons.redo, !flow && c.canRedo ? c.redo : null,
|
||||
tooltip: flow ? '重做(流程图只读)' : '重做 Ctrl+Y'),
|
||||
SizedBox(width: 6 * s),
|
||||
_aiBtn(t),
|
||||
SizedBox(width: 12 * s),
|
||||
_segmented(t),
|
||||
];
|
||||
right = <Widget>[
|
||||
// 未授权时导出按钮置灰(授权有效才允许导出)。
|
||||
_primaryBtn(t, '导出 SVG', c.licensed ? _exportSvg : null),
|
||||
SizedBox(width: 6 * s),
|
||||
_ghost(t, '导出 PNG', c.licensed ? _exportPng : null),
|
||||
// 导出合并为下拉菜单:SVG / PNG 三种视图通用;drawio 仅流程图提供。
|
||||
_exportMenu(t),
|
||||
SizedBox(width: 6 * s),
|
||||
_zoomBox(t),
|
||||
SizedBox(width: 6 * s),
|
||||
@@ -614,8 +680,11 @@ class _AppShellState extends State<AppShell> {
|
||||
_iconBtn(t, Icons.folder_open_outlined, _open, tooltip: '打开 Ctrl+O'),
|
||||
_iconBtn(t, Icons.save_outlined, _save, tooltip: '保存 Ctrl+S'),
|
||||
SizedBox(width: 4 * s),
|
||||
_iconBtn(t, Icons.undo, c.canUndo ? c.undo : null, tooltip: '撤销 Ctrl+Z'),
|
||||
_iconBtn(t, Icons.redo, c.canRedo ? c.redo : null, tooltip: '重做 Ctrl+Y'),
|
||||
// 流程图只读:撤销 / 重做置灰(修改请回时序图)。
|
||||
_iconBtn(t, Icons.undo, !flow && c.canUndo ? c.undo : null,
|
||||
tooltip: flow ? '撤销(流程图只读)' : '撤销 Ctrl+Z'),
|
||||
_iconBtn(t, Icons.redo, !flow && c.canRedo ? c.redo : null,
|
||||
tooltip: flow ? '重做(流程图只读)' : '重做 Ctrl+Y'),
|
||||
SizedBox(width: 4 * s),
|
||||
// AI 是核心卖点,紧凑布局下也保留「AI 生成」文字,避免认不出。
|
||||
_aiBtn(t),
|
||||
@@ -623,10 +692,8 @@ class _AppShellState extends State<AppShell> {
|
||||
_segmented(t, compact: true),
|
||||
];
|
||||
right = <Widget>[
|
||||
// 导出保持两个独立按钮;未授权时置灰。
|
||||
_ghost(t, '导出 SVG', c.licensed ? _exportSvg : null),
|
||||
SizedBox(width: 4 * s),
|
||||
_ghost(t, '导出 PNG', c.licensed ? _exportPng : null),
|
||||
// 导出合并为下拉菜单:SVG / PNG 三种视图通用;drawio 仅流程图提供。
|
||||
_exportMenu(t),
|
||||
SizedBox(width: 4 * s),
|
||||
_zoomBox(t),
|
||||
_iconBtn(t, Icons.crop_free, c.fitView, tooltip: '适应视图'),
|
||||
@@ -656,17 +723,17 @@ class _AppShellState extends State<AppShell> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 视图模式分段控件:条形节拍 / 圆周节拍一键切换。
|
||||
/// 视图模式分段控件:条形节拍 / 圆周节拍 / 流程图 一键切换。
|
||||
///
|
||||
/// [compact] 为真时使用更窄的宽度,适配 1920×1080 等较小窗口。
|
||||
Widget _segmented(Tokens t, {bool compact = false}) {
|
||||
final bool bar = c.project.viewState.mode == ViewMode.bar;
|
||||
final ViewMode mode = c.project.viewState.mode;
|
||||
Widget seg(String label, bool active, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
width: (compact ? 96 : 140) * _toolScale,
|
||||
width: (compact ? 84 : 118) * _toolScale,
|
||||
height: 34 * _toolScale,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
@@ -693,8 +760,9 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
seg('条形节拍', bar, () => c.setViewMode(ViewMode.bar)),
|
||||
seg('圆周节拍', !bar, () => c.setViewMode(ViewMode.circular)),
|
||||
seg('条形节拍', mode == ViewMode.bar, () => c.setViewMode(ViewMode.bar)),
|
||||
seg('圆周节拍', mode == ViewMode.circular, () => c.setViewMode(ViewMode.circular)),
|
||||
seg('流程图', mode == ViewMode.flow, () => c.setViewMode(ViewMode.flow)),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -809,67 +877,121 @@ class _AppShellState extends State<AppShell> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 次要(幽灵)样式按钮;[onTap] 为 null 时呈禁用态;尺寸随 [_toolScale] 缩放。
|
||||
Widget _ghost(Tokens t, String label, VoidCallback? onTap, {IconData? icon}) {
|
||||
/// 导出下拉菜单:合并原「导出 SVG / 导出 PNG」两个按钮。
|
||||
///
|
||||
/// 选项规则(1.3 产品约定):
|
||||
/// - 「导出 SVG」「导出 PNG」三种视图(条形 / 圆周 / 流程图)均可用;
|
||||
/// - 「导出 drawio」仅在流程图视图出现(条形 / 圆周视图不提供);
|
||||
/// - 未授权时各项置灰(桌面无 license 不允许导出)。
|
||||
Widget _exportMenu(Tokens t) {
|
||||
final double s = _toolScale;
|
||||
final bool licensed = c.licensed;
|
||||
final bool flow = c.project.viewState.mode == ViewMode.flow;
|
||||
final Color fg = licensed ? Colors.white : t.dim;
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 3 * s),
|
||||
child: TextButton.icon(
|
||||
onPressed: onTap,
|
||||
icon: icon == null ? null : Icon(icon, size: 16 * s, color: onTap == null ? t.dim : t.text),
|
||||
label: Text(label, style: TextStyle(fontSize: _toolFont(11), color: onTap == null ? t.dim : t.text)),
|
||||
style: TextButton.styleFrom(
|
||||
backgroundColor: t.panel,
|
||||
side: BorderSide(color: t.line2),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * s, vertical: 10 * s),
|
||||
minimumSize: Size(0, 34 * s),
|
||||
tapTargetSize: s < 1 ? MaterialTapTargetSize.shrinkWrap : null,
|
||||
child: PopupMenuButton<String>(
|
||||
tooltip: '导出(SVG / PNG${flow ? ' / drawio' : ''})',
|
||||
color: t.panel2,
|
||||
position: PopupMenuPosition.under,
|
||||
onSelected: (String v) {
|
||||
if (v == 'svg') _exportSvg();
|
||||
if (v == 'png') _exportPng();
|
||||
if (v == 'drawio') _exportDrawio();
|
||||
},
|
||||
itemBuilder: (BuildContext ctx) => <PopupMenuEntry<String>>[
|
||||
_exportItem(t, 'svg', Icons.code, '导出 SVG', '矢量图:无损缩放 / 打印 / 二次编辑', licensed),
|
||||
_exportItem(t, 'png', Icons.image_outlined, '导出 PNG', '位图(3840×2160):分享 / 汇报', licensed),
|
||||
// drawio 仅在流程图视图提供;其余视图不出现该项目。
|
||||
if (flow)
|
||||
_exportItem(t, 'drawio', Icons.account_tree_outlined, '导出 drawio',
|
||||
'diagrams.net 可编辑工程', licensed),
|
||||
],
|
||||
child: Container(
|
||||
height: 34 * s,
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * s),
|
||||
decoration: BoxDecoration(
|
||||
color: licensed ? t.accent2 : t.panel2,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Icon(Icons.ios_share, size: 15 * s, color: fg),
|
||||
SizedBox(width: 6 * s),
|
||||
Text('导出',
|
||||
style: TextStyle(fontSize: _toolFont(11), fontWeight: FontWeight.w600, color: fg)),
|
||||
Icon(Icons.arrow_drop_down, size: 18 * s, color: fg),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 主色填充按钮(用于导出等主要动作);[onTap] 为 null 时禁用(置灰);
|
||||
/// 尺寸随 [_toolScale] 缩放。
|
||||
Widget _primaryBtn(Tokens t, String label, VoidCallback? onTap) {
|
||||
final bool enabled = onTap != null;
|
||||
final double s = _toolScale;
|
||||
return FilledButton(
|
||||
onPressed: onTap,
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: enabled ? t.accent2 : t.panel2,
|
||||
foregroundColor: enabled ? Colors.white : t.dim,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16 * s, vertical: 10 * s),
|
||||
minimumSize: Size(0, 34 * s),
|
||||
tapTargetSize: s < 1 ? MaterialTapTargetSize.shrinkWrap : null,
|
||||
/// 导出菜单单项:图标 + 名称 + 一句说明;[enabled] 为 false 时整体置灰。
|
||||
///
|
||||
/// 菜单宽度有限(PopupMenu 默认上限约 256px),文本统一单行省略,
|
||||
/// 避免窄窗口 / 紧凑布局下溢出。
|
||||
PopupMenuItem<String> _exportItem(
|
||||
Tokens t, String value, IconData icon, String label, String hint, bool enabled) {
|
||||
final Color main = enabled ? t.text : t.dim;
|
||||
return PopupMenuItem<String>(
|
||||
value: value,
|
||||
enabled: enabled,
|
||||
height: 46,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(icon, size: 17, color: enabled ? t.accent : t.dim),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: main, fontSize: 12.5, fontWeight: FontWeight.w600)),
|
||||
Text(hint,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: enabled ? t.dim : t.dim.withValues(alpha: 0.6), fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Text(label, style: TextStyle(fontSize: _toolFont(11), fontWeight: FontWeight.w600)),
|
||||
);
|
||||
}
|
||||
|
||||
/// AI 生成按钮:打开「自然语言 → 时序图」对话框;尺寸随 [_toolScale] 缩放。
|
||||
///
|
||||
/// AI 只服务时序图(生成条形 / 圆周视图的底层数据),流程图页置灰禁用。
|
||||
Widget _aiBtn(Tokens t) {
|
||||
final double s = _toolScale;
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 3 * s),
|
||||
child: FilledButton.icon(
|
||||
onPressed: () => showDialog<void>(
|
||||
final bool enabled = c.project.viewState.mode != ViewMode.flow;
|
||||
final Widget btn = FilledButton.icon(
|
||||
onPressed: enabled
|
||||
? () => showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => AiGenerateDialog(controller: c),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
icon: Icon(Icons.auto_awesome, size: 16 * s),
|
||||
label: Text('AI 生成', style: TextStyle(fontSize: _toolFont(12), fontWeight: FontWeight.w700)),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: t.accent2,
|
||||
foregroundColor: Colors.white,
|
||||
backgroundColor: enabled ? t.accent2 : t.panel2,
|
||||
foregroundColor: enabled ? Colors.white : t.dim,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)),
|
||||
padding: EdgeInsets.symmetric(horizontal: 10 * s, vertical: 8 * s),
|
||||
minimumSize: Size(0, 34 * s),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
);
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 3 * s),
|
||||
child: enabled ? btn : Tooltip(message: 'AI 生成仅针对时序图(条形 / 圆周视图)', child: btn),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -889,6 +1011,21 @@ class _AppShellState extends State<AppShell> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 自定义图标组件版按钮(用于更新按钮的矢量图标):
|
||||
/// 尺寸与点按区域与 [_iconBtn] 完全一致。
|
||||
Widget _iconWidgetBtn(Widget icon, VoidCallback? onTap, {String? tooltip}) {
|
||||
final double s = _toolScale;
|
||||
return IconButton(
|
||||
onPressed: onTap,
|
||||
icon: icon,
|
||||
tooltip: tooltip,
|
||||
splashRadius: 16 * s,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: BoxConstraints(minWidth: 34 * s, minHeight: 34 * s),
|
||||
style: IconButton.styleFrom(tapTargetSize: s < 1 ? MaterialTapTargetSize.shrinkWrap : null),
|
||||
);
|
||||
}
|
||||
|
||||
// ===================== 侧栏停靠状态机(钉住 / 悬浮 / 轨道) =====================
|
||||
|
||||
/// 侧栏标题栏控制按钮:切换钉住状态与隐藏侧栏。
|
||||
@@ -1025,6 +1162,7 @@ class _AppShellState extends State<AppShell> {
|
||||
/// 工位负载与操作提示。[floating] 为 true 时以悬浮卡片样式呈现。
|
||||
Widget _leftPanel(Tokens t, {bool floating = false}) {
|
||||
final bool bar = c.project.viewState.mode == ViewMode.bar;
|
||||
final bool flow = c.project.viewState.mode == ViewMode.flow;
|
||||
return Container(
|
||||
width: _leftPanelWidth,
|
||||
decoration: BoxDecoration(
|
||||
@@ -1051,6 +1189,7 @@ class _AppShellState extends State<AppShell> {
|
||||
t,
|
||||
icon: Icons.edit_note,
|
||||
label: '编辑时序与节拍参数',
|
||||
enabled: !flow,
|
||||
onTap: () => showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => SettingsDialog(controller: c),
|
||||
@@ -1064,16 +1203,17 @@ class _AppShellState extends State<AppShell> {
|
||||
children: <Widget>[
|
||||
// 用 Expanded 占满剩余空间,标题不会被无谓地省略成「…」。
|
||||
Expanded(child: _sectionLabel(t, '动作和执行编辑')),
|
||||
_headerAction(t, Icons.add, '新建', t.ok, t.onAccent, () => c.addAction(startAngle: 0)),
|
||||
_headerAction(t, Icons.add, '新建', t.ok, t.onAccent,
|
||||
flow ? null : () => c.addAction(startAngle: 0)),
|
||||
const SizedBox(width: 6),
|
||||
// 至少保留一个动作 / 泳道:只剩一个时禁用删除。
|
||||
// 至少保留一个动作 / 泳道:只剩一个时禁用删除;流程图只读时禁用。
|
||||
_headerAction(
|
||||
t,
|
||||
Icons.delete_outline,
|
||||
'删除',
|
||||
t.danger,
|
||||
Colors.white,
|
||||
(c.selectedId == null || c.project.actions.length <= 1)
|
||||
(flow || c.selectedId == null || c.project.actions.length <= 1)
|
||||
? null
|
||||
: () => c.deleteAction(c.selectedId!),
|
||||
),
|
||||
@@ -1090,18 +1230,20 @@ class _AppShellState extends State<AppShell> {
|
||||
icon: Icons.precision_manufacturing_outlined,
|
||||
label: '编辑工位',
|
||||
badge: c.project.stations.length,
|
||||
enabled: !flow,
|
||||
onTap: () => showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => StationDialog(controller: c),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// 相位分区:可任意增删、改名、改起止角。
|
||||
// 相位分区:可任意增删、改名、改起止角;流程图只读时置灰。
|
||||
_editEntry(
|
||||
t,
|
||||
icon: Icons.tune,
|
||||
label: '编辑相位分区',
|
||||
badge: c.project.phaseZones.length,
|
||||
enabled: !flow,
|
||||
onTap: () => showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => PhaseZoneDialog(controller: c),
|
||||
@@ -1110,11 +1252,13 @@ class _AppShellState extends State<AppShell> {
|
||||
const SizedBox(height: 12),
|
||||
_sectionLabel(t, '视图模式'),
|
||||
const SizedBox(height: 8),
|
||||
// 该栏永久只保留条形 / 圆周两个时序视图的切换;
|
||||
// 流程图由时序图生成、属独立载体,入口在顶部工具栏(不在本栏混排)。
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(child: _modeButton(t, '条形节拍(甘特)', bar, () => c.setViewMode(ViewMode.bar))),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(child: _modeButton(t, '圆周节拍(同心)', !bar, () => c.setViewMode(ViewMode.circular))),
|
||||
Expanded(child: _modeButton(t, '条形节拍(甘特)', c.project.viewState.mode == ViewMode.bar, () => c.setViewMode(ViewMode.bar))),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: _modeButton(t, '圆周节拍(同心)', c.project.viewState.mode == ViewMode.circular, () => c.setViewMode(ViewMode.circular))),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -1138,10 +1282,17 @@ class _AppShellState extends State<AppShell> {
|
||||
children: <Widget>[
|
||||
Text('操作提示', style: TextStyle(color: t.warn, fontSize: 11, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 6),
|
||||
// 提示随视图模式切换:流程图是只读预览,给出交互方式说明。
|
||||
if (flow) ...<Widget>[
|
||||
Text('流程图只读:点击节点可选中对应动作', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)),
|
||||
Text('滚轮缩放 · 拖拽平移 · Ctrl+滚轮连续缩放', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)),
|
||||
Text('需要修改请切回条形 / 圆周视图', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)),
|
||||
] else ...<Widget>[
|
||||
Text('拖拽动作块平移相位 · 拖端点改持续角', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)),
|
||||
Text('Shift+拖拽改层 · Ctrl+滚轮缩放', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)),
|
||||
Text('双击空白新建动作 · F1 打开帮助', style: TextStyle(color: t.sub, fontSize: 10, height: 1.6)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -1161,15 +1312,17 @@ class _AppShellState extends State<AppShell> {
|
||||
/// 侧栏中的“单行编辑入口”卡片:图标 + 文案 + 可选计数徽标 + 右箭头。
|
||||
///
|
||||
/// 用于把复杂的设置模块收敛为一个点击即可进入的入口。
|
||||
/// [enabled] 为 false 时整体置灰(流程图只读视图下禁用编辑入口)。
|
||||
Widget _editEntry(
|
||||
Tokens t, {
|
||||
required IconData icon,
|
||||
required String label,
|
||||
required VoidCallback onTap,
|
||||
int? badge,
|
||||
bool enabled = true,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
final Widget card = InkWell(
|
||||
onTap: enabled ? onTap : null,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 11),
|
||||
@@ -1180,18 +1333,19 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(icon, size: 16, color: t.accent),
|
||||
Icon(icon, size: 16, color: enabled ? t.accent : t.dim),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(label, style: TextStyle(color: t.text2, fontSize: 12))),
|
||||
Expanded(child: Text(label, style: TextStyle(color: enabled ? t.text2 : t.dim, fontSize: 12))),
|
||||
if (badge != null) ...<Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: t.accent.withValues(alpha: 0.14),
|
||||
color: enabled ? t.accent.withValues(alpha: 0.14) : t.line.withValues(alpha: 0.35),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text('$badge',
|
||||
style: TextStyle(color: t.accent, fontSize: 10.5, fontWeight: FontWeight.w700)),
|
||||
style: TextStyle(
|
||||
color: enabled ? t.accent : t.dim, fontSize: 10.5, fontWeight: FontWeight.w700)),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
@@ -1200,6 +1354,8 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
),
|
||||
);
|
||||
if (enabled) return card;
|
||||
return Tooltip(message: '流程图只读:修改请切回条形 / 圆周视图', child: card);
|
||||
}
|
||||
|
||||
/// 动作列表小节标题右侧的紧凑按钮(新建 / 删除)。
|
||||
@@ -1246,6 +1402,7 @@ class _AppShellState extends State<AppShell> {
|
||||
/// 单条泳道 / 轨道行:多个动作合并显示(≤2 行,/ 分隔)。
|
||||
Widget _laneRow(Tokens t, int lane, int li, List<Action> acts, bool bar) {
|
||||
if (acts.isEmpty) return const SizedBox.shrink();
|
||||
final bool flow = c.project.viewState.mode == ViewMode.flow;
|
||||
final Action primary =
|
||||
acts.firstWhere((Action a) => c.isSelected(a.id), orElse: () => acts.first);
|
||||
final bool sel = c.isSelected(primary.id);
|
||||
@@ -1265,8 +1422,10 @@ class _AppShellState extends State<AppShell> {
|
||||
toggle: HardwareKeyboard.instance.isControlPressed ||
|
||||
HardwareKeyboard.instance.isShiftPressed,
|
||||
),
|
||||
// 双击泳道行直接编辑该泳道的主动作。
|
||||
onDoubleTap: () => showDialog<void>(
|
||||
// 双击泳道行直接编辑该泳道的主动作(流程图只读时禁用)。
|
||||
onDoubleTap: flow
|
||||
? null
|
||||
: () => showDialog<void>(
|
||||
context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
@@ -1334,7 +1493,9 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
InkWell(
|
||||
onTap: () => showDialog<void>(
|
||||
onTap: flow
|
||||
? null
|
||||
: () => showDialog<void>(
|
||||
context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
child: Container(
|
||||
@@ -1345,7 +1506,7 @@ class _AppShellState extends State<AppShell> {
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: Icon(Icons.edit, size: 13, color: sel ? t.accent : t.dim),
|
||||
child: Icon(Icons.edit, size: 13, color: flow ? t.line2 : (sel ? t.accent : t.dim)),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -1357,6 +1518,7 @@ class _AppShellState extends State<AppShell> {
|
||||
|
||||
/// 左侧栏中的单条动作行:点击选中,右侧显示相位/层信息与编辑入口。
|
||||
Widget _actionRow(Tokens t, Action a, int i, bool bar) {
|
||||
final bool flow = c.project.viewState.mode == ViewMode.flow;
|
||||
final bool sel = c.isSelected(a.id);
|
||||
final Station? st = c.project.stationById(a.stationId);
|
||||
return Padding(
|
||||
@@ -1368,8 +1530,10 @@ class _AppShellState extends State<AppShell> {
|
||||
toggle: HardwareKeyboard.instance.isControlPressed ||
|
||||
HardwareKeyboard.instance.isShiftPressed,
|
||||
),
|
||||
// 双击动作行直接进入编辑。
|
||||
onDoubleTap: () => showDialog<void>(
|
||||
// 双击动作行直接进入编辑(流程图只读时禁用)。
|
||||
onDoubleTap: flow
|
||||
? null
|
||||
: () => showDialog<void>(
|
||||
context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
@@ -1426,7 +1590,9 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
InkWell(
|
||||
onTap: () => showDialog<void>(
|
||||
onTap: flow
|
||||
? null
|
||||
: () => showDialog<void>(
|
||||
context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
child: Container(
|
||||
@@ -1437,11 +1603,11 @@ class _AppShellState extends State<AppShell> {
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: Icon(Icons.edit, size: 13, color: sel ? t.accent : t.dim),
|
||||
child: Icon(Icons.edit, size: 13, color: flow ? t.line2 : (sel ? t.accent : t.dim)),
|
||||
),
|
||||
),
|
||||
// 选中该动作时才出现删除入口;至少保留一个动作 / 泳道。
|
||||
if (sel && c.project.actions.length > 1) ...<Widget>[
|
||||
// 选中该动作时才出现删除入口;至少保留一个动作 / 泳道;流程图只读时隐藏。
|
||||
if (sel && !flow && c.project.actions.length > 1) ...<Widget>[
|
||||
const SizedBox(width: 4),
|
||||
InkWell(
|
||||
onTap: () => c.deleteAction(a.id),
|
||||
@@ -1585,6 +1751,7 @@ class _AppShellState extends State<AppShell> {
|
||||
Widget _rightPanel(Tokens t, {bool floating = false}) {
|
||||
final Action? a = c.selected;
|
||||
final bool bar = c.project.viewState.mode == ViewMode.bar;
|
||||
final bool flow = c.project.viewState.mode == ViewMode.flow;
|
||||
return Container(
|
||||
width: _rightPanelWidth,
|
||||
decoration: BoxDecoration(
|
||||
@@ -1619,15 +1786,49 @@ class _AppShellState extends State<AppShell> {
|
||||
children: <Widget>[
|
||||
_selectedHeader(t, a, bar),
|
||||
const SizedBox(height: 14),
|
||||
// 流程图只读提示:节点与连线自动生成,编辑请回时序视图。
|
||||
if (flow) ...<Widget>[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: t.info,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: t.line),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Icon(Icons.lock_outline, size: 15, color: t.warn),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text('流程图只读:节点与连线由时序图自动生成,修改请切回条形 / 圆周视图。',
|
||||
style: TextStyle(color: t.sub, fontSize: 10.5, height: 1.55)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
..._propertyFields(t, a, bar),
|
||||
const SizedBox(height: 10),
|
||||
if (!bar) ...<Widget>[
|
||||
_sectionLabel(t, '角度编辑'),
|
||||
const SizedBox(height: 8),
|
||||
// 流程图只读:滑块仅展示数值,不可拖动。
|
||||
Opacity(
|
||||
opacity: flow ? 0.45 : 1,
|
||||
child: IgnorePointer(
|
||||
ignoring: flow,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
_slider(t, '起始角', (a.startAngle / 360).clamp(0, 1), pfmt(a.startAngle, c.project.units),
|
||||
(double v) => c.setActionStart(a.id, v * 360)),
|
||||
_slider(t, '持续角', (a.durationAngle / 180).clamp(0, 1), pfmt(a.durationAngle, c.project.units),
|
||||
(double v) => c.setActionDuration(a.id, v * 180)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
@@ -1637,10 +1838,12 @@ class _AppShellState extends State<AppShell> {
|
||||
if (a.deps.isEmpty)
|
||||
Text('暂无前置依赖', style: TextStyle(color: t.dim, fontSize: 11))
|
||||
else
|
||||
for (final Dependency d in a.deps) _depRow(t, a, d),
|
||||
for (final Dependency d in a.deps) _depRow(t, a, d, enabled: !flow),
|
||||
const SizedBox(height: 6),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => showDialog<void>(
|
||||
onPressed: flow
|
||||
? null
|
||||
: () => showDialog<void>(
|
||||
context: context, builder: (_) => DependencyEditorDialog(controller: c, action: a)),
|
||||
icon: const Icon(Icons.add_link, size: 15),
|
||||
label: const Text('添加前置依赖', style: TextStyle(fontSize: 11)),
|
||||
@@ -1660,7 +1863,7 @@ class _AppShellState extends State<AppShell> {
|
||||
Text('暂无后续动作引用本动作', style: TextStyle(color: t.dim, fontSize: 11))
|
||||
else
|
||||
for (final (Action target, Dependency d) in _outgoingDeps(a))
|
||||
_outDepRow(t, a, target, d),
|
||||
_outDepRow(t, a, target, d, enabled: !flow),
|
||||
const SizedBox(height: 12),
|
||||
_helpCard(t),
|
||||
],
|
||||
@@ -1853,7 +2056,9 @@ class _AppShellState extends State<AppShell> {
|
||||
}
|
||||
|
||||
/// 单条依赖展示行:显示前后动作、类型与偏移角,并可删除。
|
||||
Widget _depRow(Tokens t, Action a, Dependency d) {
|
||||
///
|
||||
/// [enabled] 为 false 时删除按钮置灰禁用(流程图只读视图)。
|
||||
Widget _depRow(Tokens t, Action a, Dependency d, {bool enabled = true}) {
|
||||
final Color col = d.type == DepType.fs ? t.fs : t.ss;
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 5),
|
||||
@@ -1874,8 +2079,8 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => c.removeDependency(d.fromId, a.id),
|
||||
child: Icon(Icons.close, size: 14, color: t.dim),
|
||||
onTap: enabled ? () => c.removeDependency(d.fromId, a.id) : null,
|
||||
child: Icon(Icons.close, size: 14, color: enabled ? t.dim : t.line2),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1883,7 +2088,9 @@ class _AppShellState extends State<AppShell> {
|
||||
}
|
||||
|
||||
/// 输出依赖展示行:本动作 [a] 作为前置指向 [target],可删除。
|
||||
Widget _outDepRow(Tokens t, Action a, Action target, Dependency d) {
|
||||
///
|
||||
/// [enabled] 为 false 时删除按钮置灰禁用(流程图只读视图)。
|
||||
Widget _outDepRow(Tokens t, Action a, Action target, Dependency d, {bool enabled = true}) {
|
||||
final Color col = d.type == DepType.fs ? t.fs : t.ss;
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 5),
|
||||
@@ -1904,8 +2111,8 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => c.removeDependency(a.id, target.id),
|
||||
child: Icon(Icons.close, size: 14, color: t.dim),
|
||||
onTap: enabled ? () => c.removeDependency(a.id, target.id) : null,
|
||||
child: Icon(Icons.close, size: 14, color: enabled ? t.dim : t.line2),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1946,14 +2153,17 @@ class _AppShellState extends State<AppShell> {
|
||||
/// 当前状态消息,右侧提示未保存状态与常用快捷键。
|
||||
Widget _statusBar(Tokens t) {
|
||||
final UnitSettings u = c.project.units;
|
||||
final bool circular = c.project.viewState.mode == ViewMode.circular;
|
||||
final ViewMode mode = c.project.viewState.mode;
|
||||
final bool circular = mode == ViewMode.circular;
|
||||
final List<String> items = <String>[
|
||||
'循环周期 ${tfmt(c.project.cycle.durationMs, u)}',
|
||||
'相位 360° = 100%',
|
||||
'动作 ${c.project.actions.length}',
|
||||
'依赖 ${_depCount()}',
|
||||
circular ? '轨道 L1–L${c.project.laneCount}' : '工位 ${c.project.stations.length}',
|
||||
circular ? '同心圆 ${c.project.laneCount}' : '时间轴 0–${tfmt(c.project.cycle.durationMs, u)}',
|
||||
mode == ViewMode.flow
|
||||
? '泳道 L1–L${c.project.laneCount}(流程节点 ${c.project.actions.length})'
|
||||
: (circular ? '同心圆 ${c.project.laneCount}' : '时间轴 0–${tfmt(c.project.cycle.durationMs, u)}'),
|
||||
'单位 ${timeUnitLabel(u.timeUnit)} / ${phaseUnitLabel(u.phaseUnit)}',
|
||||
'1° = ${tfmtAuto(c.project.cycle.durationMs / 360)}',
|
||||
c.status,
|
||||
|
||||
+52
-29
@@ -16,6 +16,10 @@ import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'dialogs.dart';
|
||||
|
||||
/// 条形缩略预览的固定绘制区高度:卡片尺寸不随动作数量变化,
|
||||
/// 动作越多只会在内部压缩行距、把色条画得更细。
|
||||
const double _kMiniBarHeight = 84;
|
||||
|
||||
/// 画布浮层容器:按响应式断点组合并定位各信息面板。
|
||||
class CanvasOverlays extends StatelessWidget {
|
||||
/// 创建浮层容器,[controller] 为全局应用控制器。
|
||||
@@ -56,7 +60,9 @@ class CanvasOverlays extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
final bool circular = c.project.viewState.mode == ViewMode.circular;
|
||||
final ViewMode mode = c.project.viewState.mode;
|
||||
final bool circular = mode == ViewMode.circular;
|
||||
final bool flow = mode == ViewMode.flow;
|
||||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
final double w = constraints.maxWidth;
|
||||
@@ -82,7 +88,7 @@ class CanvasOverlays extends StatelessWidget {
|
||||
left: left,
|
||||
top: 12,
|
||||
right: right,
|
||||
child: IgnorePointer(child: _Title(t: t, circular: circular, project: c.project)),
|
||||
child: IgnorePointer(child: _Title(t: t, mode: mode)),
|
||||
),
|
||||
// 圆周视图左侧信息列:图例 + 选中卡片 + 依赖图例。
|
||||
if (showPanels && showLeftColumn)
|
||||
@@ -105,7 +111,8 @@ class CanvasOverlays extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
// 条形视图左下角:节拍统计 + 编辑工具。
|
||||
if (showPanels && !circular && (showStats || showTools))
|
||||
// (流程图只读,不显示编辑工具。)
|
||||
if (showPanels && !circular && !flow && (showStats || showTools))
|
||||
Positioned(
|
||||
left: left,
|
||||
bottom: 12,
|
||||
@@ -122,7 +129,8 @@ class CanvasOverlays extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
// 右下角预览:圆周视图显示条形缩略,反之亦然;点击可切换视图。
|
||||
if (showPanels && showPreview)
|
||||
// 流程图是独立的载体,不显示时序视图的缩略预览。
|
||||
if (showPanels && showPreview && !flow)
|
||||
Positioned(
|
||||
right: right,
|
||||
bottom: 12,
|
||||
@@ -172,32 +180,41 @@ class _Card extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// 顶部标题浮层:显示当前视图名称与双刻度/图例说明。
|
||||
/// 顶部标题浮层:单行展示「视图名 +(线型图例)」。
|
||||
///
|
||||
/// 更完整的视图语义(同心圆环 / 循环换算 / 流程图读法)已收敛到「帮助」中,
|
||||
/// 画布上只保留最精简的一句括号说明,节省纵向空间。
|
||||
class _Title extends StatelessWidget {
|
||||
const _Title({required this.t, required this.circular, required this.project});
|
||||
const _Title({required this.t, required this.mode});
|
||||
|
||||
/// 主题令牌。
|
||||
final Tokens t;
|
||||
/// 是否处于圆周视图。
|
||||
final bool circular;
|
||||
/// 当前项目,用于展示循环时长等文案。
|
||||
final Project project;
|
||||
/// 当前视图模式。
|
||||
final ViewMode mode;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String title = circular
|
||||
? '圆周时序视图'
|
||||
: '条形时序视图';
|
||||
final String sub = circular
|
||||
? '同心圆环 = 动作层;箭头 = 执行顺序(绿色实线 FS 严格顺序,琥珀虚线 SS 并行重叠);1 圈 = 1 循环 = ${tfmt(project.cycle.durationMs, project.units)} = 360° = 100%'
|
||||
: '箭头表示动作之间关联(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)';
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(title, style: TextStyle(color: t.text, fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
const SizedBox(height: 4),
|
||||
Text(sub, style: TextStyle(color: t.dim, fontSize: 11)),
|
||||
],
|
||||
final String title = switch (mode) {
|
||||
ViewMode.bar => '条形时序视图',
|
||||
ViewMode.circular => '圆周时序视图',
|
||||
ViewMode.flow => '流程图视图',
|
||||
};
|
||||
// 括号说明:仅保留线型图例(流程图不重复时序视图的说明)。
|
||||
final String suffix = switch (mode) {
|
||||
ViewMode.bar => '(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)',
|
||||
ViewMode.circular => '(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)',
|
||||
ViewMode.flow => '',
|
||||
};
|
||||
return Text.rich(
|
||||
TextSpan(children: <InlineSpan>[
|
||||
TextSpan(
|
||||
text: title,
|
||||
style: TextStyle(color: t.text, fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
if (suffix.isNotEmpty)
|
||||
TextSpan(text: ' $suffix', style: TextStyle(color: t.dim, fontSize: 11)),
|
||||
]),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -732,9 +749,11 @@ class _BarPreviewCard extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
// 预览区固定高度(与动作数量无关):动作再多也不会撑大预览卡,
|
||||
// 只会在内部压缩行距 / 缩小线条(见 _MiniBarPainter)。
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: project.actions.length * 9.0 + 12,
|
||||
height: _kMiniBarHeight,
|
||||
child: CustomPaint(
|
||||
size: Size.infinite,
|
||||
painter: _MiniBarPainter(project, t),
|
||||
@@ -763,20 +782,22 @@ class _MiniBarPainter extends CustomPainter {
|
||||
final double w = size.width - 4;
|
||||
// 行高按可用高度自适应,保证小预览里也排得下。
|
||||
final double pitch = n == 0 ? 12 : math.min(12, (size.height - 16) / n);
|
||||
final double rh = math.max(pitch - 3, 4);
|
||||
// 缩略图里的动作条是一条细线(约 2px);动作越多行距越紧、线越细,
|
||||
// 下限 0.5px,保证固定高度的预览区内不重叠、不溢出。
|
||||
final double rh = math.min(2.0, math.max(pitch * 0.6, 0.5));
|
||||
for (int i = 0; i < n; i++) {
|
||||
final Action a = project.actions[i];
|
||||
final double y = i * pitch;
|
||||
final double y = i * pitch + (pitch - rh) / 2;
|
||||
final double x1 = 2 + a.startAngle / 360 * w;
|
||||
final double x2 = 2 + math.min(a.endAngle, 360) / 360 * w;
|
||||
final RRect r = RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(x1, y, math.max(x2 - x1, 2), rh),
|
||||
const Radius.circular(2),
|
||||
Radius.circular(rh / 2),
|
||||
);
|
||||
canvas.drawRRect(r, Paint()..color = Color(a.color).withValues(alpha: 0.9));
|
||||
if (a.wrap) {
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(Rect.fromLTWH(2, y, (a.endAngle - 360) / 360 * w, rh), const Radius.circular(2)),
|
||||
RRect.fromRectAndRadius(Rect.fromLTWH(2, y, (a.endAngle - 360) / 360 * w, rh), Radius.circular(rh / 2)),
|
||||
Paint()..color = Color(a.color).withValues(alpha: t.tailOp),
|
||||
);
|
||||
}
|
||||
@@ -865,7 +886,9 @@ class _MiniCircularPainter extends CustomPainter {
|
||||
final double maxR = math.max(math.min(size.width, size.height) / 2 - 24, 24);
|
||||
final double r0 = n <= 1 ? maxR * 0.6 : maxR * 0.34;
|
||||
final double pitch = n <= 1 ? 0 : (maxR - r0) / (n - 1);
|
||||
final double pw = (pitch == 0 ? 10.0 : pitch * 0.5).clamp(6.0, 13.0);
|
||||
// 缩略图里的环与动作弧是一条细线;层数越多环距越紧、线宽随之收细,
|
||||
// 避免在固定大小的预览框里叠成一团。
|
||||
final double pw = math.min(2.0, math.max(pitch <= 0 ? 2.0 : pitch * 0.7, 0.5));
|
||||
canvas.drawCircle(c, r0 + (n - 1) * pitch + pw / 2, Paint()..color = t.dial);
|
||||
for (int i = 0; i < n; i++) {
|
||||
final Action a = project.actions[i];
|
||||
|
||||
+264
-27
@@ -1,10 +1,11 @@
|
||||
// 画布交互视图:承载条形 / 圆周两种节拍视图的绘制与全部手势操作。
|
||||
// 画布交互视图:承载条形 / 圆周 / 流程图三种节拍视图的绘制与全部手势操作。
|
||||
//
|
||||
// 架构位置:位于 UI 层核心,向下调用布局(BarLayout / CircularLayout)
|
||||
// 与渲染器(BarPainter / CircularPainter),向上通过 AppController 修改
|
||||
// 项目状态。本文件负责:
|
||||
// 架构位置:位于 UI 层核心,向下调用布局(BarLayout / CircularLayout /
|
||||
// FlowLayout / dep_routes)与渲染器(BarPainter / CircularPainter /
|
||||
// FlowchartPainter),向上通过 AppController 修改项目状态。本文件负责:
|
||||
// · 屏幕坐标 → 逻辑坐标的变换(考虑平移与缩放);
|
||||
// · 点选、双击新建、拖拽移动相位、拖拽端点改持续角、Shift 拖拽改层;
|
||||
// · 点选依赖连线并沿法线方向拖拽调整走线(双击复位);
|
||||
// · 空白区域拖拽平移、Ctrl + 滚轮缩放;
|
||||
// · 右键上下文菜单。
|
||||
import 'dart:io' show Platform;
|
||||
@@ -14,16 +15,20 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../render/circular_painter.dart';
|
||||
import '../render/flow_painter.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'dialogs.dart';
|
||||
|
||||
/// 当前拖拽行为类型:无操作 / 平移相位 / 拖右端改时长 / 拖左端改起始。
|
||||
enum _DragMode { none, move, resize, resizeStart }
|
||||
/// 当前拖拽行为类型:无操作 / 平移相位 / 拖右端改时长 / 拖左端改起始 /
|
||||
/// 拖拽依赖走线(沿法线平移整条线)。
|
||||
enum _DragMode { none, move, resize, resizeStart, dep }
|
||||
|
||||
/// 画布视图组件:根据视图模式渲染图形并处理所有画布手势。
|
||||
class CanvasView extends StatefulWidget {
|
||||
@@ -68,6 +73,30 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
/// 拖拽分区边界或动作端点时的参考角(用于绘制虚线坐标参考);否则为 null。
|
||||
double? _zoneGuideAngle;
|
||||
|
||||
// ---- 依赖连线选中与拖拽会话状态 ----
|
||||
/// 当前选中的依赖连线键(`from->to`);非空时高亮显示。
|
||||
String? _selDep;
|
||||
|
||||
/// 拖拽依赖时的起止动作 id 与按下时的走线偏移。
|
||||
String _depFrom = '';
|
||||
String _depTo = '';
|
||||
double _depStartOffset = 0;
|
||||
|
||||
/// 拖拽依赖时指针按下位置(逻辑坐标)。
|
||||
Offset _depStartPointer = Offset.zero;
|
||||
|
||||
/// 依赖拖拽方向:竖直(上下平移横线)或水平(左右平移纵向走廊)。
|
||||
RouteAxis _depAxis = RouteAxis.vertical;
|
||||
|
||||
/// 圆周视图下依赖拖拽的径向单位向量(拖拽沿半径方向);其它视图为零向量。
|
||||
Offset _depRadial = Offset.zero;
|
||||
|
||||
/// 最近一次指针按下的逻辑坐标(用于拖拽命中判定)。
|
||||
///
|
||||
/// 桌面 / 触屏的缩放手势在移动若干像素后才“验收”,验收点会偏离按下点;
|
||||
/// 命中判定改用按下点,保证“按在哪就抓哪”(对细目标如依赖连线尤其重要)。
|
||||
Offset _downLogical = Offset.zero;
|
||||
|
||||
/// 当前鼠标指针样式(靠近可拖拽端点时显示左右箭头)。
|
||||
MouseCursor _cursor = SystemMouseCursors.basic;
|
||||
|
||||
@@ -149,7 +178,9 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
/// 把手绘制在动作端点(条形 = 条带左右两端、圆周 = 弧两端),可能略在动作本体
|
||||
/// 之外;精确指针(手写笔)直接点在把手上时,仅靠动作命中测试会落空,因此这里
|
||||
/// 单独做一次把手邻近命中,半径与 [_grabRadius] 一致。
|
||||
(Action, bool)? _hitHandle(Offset p, Size size) {
|
||||
(Action, bool, double)? _hitHandle(Offset p, Size size) {
|
||||
// 流程图只读:无端点把手。
|
||||
if (c.project.viewState.mode == ViewMode.flow) return null;
|
||||
Action? best;
|
||||
bool bestStart = false;
|
||||
double bestDist = _grabRadius;
|
||||
@@ -188,7 +219,83 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return best == null ? null : (best, bestStart);
|
||||
return best == null ? null : (best, bestStart, bestDist);
|
||||
}
|
||||
|
||||
// ---- 依赖连线:命中测试 / 选中 / 拖拽 ----
|
||||
|
||||
/// 命中依赖连线(条形 / 圆周 / 流程图通用):返回最近一条的 `from->to` 键。
|
||||
///
|
||||
/// 命中几何与各视图的绘制共用([buildBarDepRoutes] / [buildArcDepRoutes] /
|
||||
/// `FlowLayout.routes`),保证“看到哪条线就能选中哪条线”。
|
||||
String? _hitDepKey(Offset p, Size size) {
|
||||
const double tol = 7;
|
||||
switch (c.project.viewState.mode) {
|
||||
case ViewMode.bar:
|
||||
final BarDepRoute? r = hitBarDep(
|
||||
buildBarDepRoutes(c.project, BarLayout(c.project, size)), p, tol);
|
||||
return r?.key;
|
||||
case ViewMode.circular:
|
||||
final ArcDepRoute? r = hitArcDep(
|
||||
buildArcDepRoutes(c.project, CircularLayout(c.project, size)), p, tol);
|
||||
return r?.key;
|
||||
case ViewMode.flow:
|
||||
for (final FlowEdgeRoute r in FlowLayout(c.project).routes) {
|
||||
if (r.edge.type == null) continue; // 开始 / 结束流程连线不参与
|
||||
if (distanceToPolyline(r.points, p) < tol) return r.key;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 选中一条依赖连线并给出操作提示(状态栏)。
|
||||
void _selectDep(String key) {
|
||||
if (_selDep != key) setState(() => _selDep = key);
|
||||
c.setStatus('已选中依赖 $key:拖动可沿法线平移走线,双击复位');
|
||||
}
|
||||
|
||||
/// 开始拖拽依赖走线:记录起点、当前偏移、拖拽轴与(圆周的)径向方向。
|
||||
void _beginDepDrag(String key, Offset p, Size size) {
|
||||
final int sep = key.indexOf('->');
|
||||
if (sep <= 0) return;
|
||||
final String from = key.substring(0, sep);
|
||||
final String to = key.substring(sep + 2);
|
||||
final Action? toAction = c.project.actionById(to);
|
||||
Dependency? dep;
|
||||
for (final Dependency d in toAction?.deps ?? const <Dependency>[]) {
|
||||
if (d.fromId == from) {
|
||||
dep = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dep == null) return;
|
||||
setState(() => _selDep = key);
|
||||
_mode = _DragMode.dep;
|
||||
_dragAction = null;
|
||||
_depFrom = from;
|
||||
_depTo = to;
|
||||
_depStartPointer = p;
|
||||
_depStartOffset = dep.routeOffset;
|
||||
_depAxis = RouteAxis.vertical;
|
||||
_depRadial = Offset.zero;
|
||||
if (c.project.viewState.mode == ViewMode.circular) {
|
||||
// 圆周:沿半径方向(走线的法线)。
|
||||
final CircularLayout layout = CircularLayout(c.project, size);
|
||||
final Offset v = p - layout.center;
|
||||
if (v.distance > 0.001) _depRadial = v / v.distance;
|
||||
} else if (c.project.viewState.mode == ViewMode.bar) {
|
||||
final BarDepRoute? r =
|
||||
hitBarDep(buildBarDepRoutes(c.project, BarLayout(c.project, size)), p, 12);
|
||||
if (r != null) _depAxis = r.axis;
|
||||
} else {
|
||||
for (final FlowEdgeRoute r in FlowLayout(c.project).routes) {
|
||||
if (r.key == key) {
|
||||
_depAxis = r.axis;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
c.setStatus('已选中依赖 $key:拖动可沿法线平移走线,双击复位');
|
||||
}
|
||||
|
||||
/// 更新鼠标指针样式:靠近分区边界或动作端点时显示左右拖拽箭头。
|
||||
@@ -316,23 +423,53 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
// ===================== 手势处理 =====================
|
||||
|
||||
/// 单击:命中最上层动作则选中,否则清空选中。
|
||||
///
|
||||
/// 流程图视图为只读:点击节点即选中对应动作(修改请回时序图)。
|
||||
void _onTapDown(TapDownDetails d, Size size) {
|
||||
final Offset p = _toLogical(d.localPosition, size);
|
||||
final ViewMode mode = c.project.viewState.mode;
|
||||
final Action? hit;
|
||||
if (mode == ViewMode.flow) {
|
||||
hit = FlowLayout(c.project).hitTest(p);
|
||||
} else {
|
||||
// 端点把手优先命中:精确点在把手上时也选中该动作,避免误清空选中。
|
||||
final (Action, bool)? handle = _hitHandle(p, size);
|
||||
final Action? hit = handle?.$1 ??
|
||||
(c.project.viewState.mode == ViewMode.bar
|
||||
final (Action, bool, double)? handle = _hitHandle(p, size);
|
||||
hit = handle?.$1 ??
|
||||
(mode == ViewMode.bar
|
||||
? BarLayout(c.project, size).hitTest(p, slop: _hitSlop)
|
||||
: CircularLayout(c.project, size).hitTest(p, slop: _hitSlop));
|
||||
}
|
||||
// 未命中动作时优先尝试选中依赖连线(点击线条即选中)。
|
||||
if (hit == null) {
|
||||
final String? depKey = _hitDepKey(p, size);
|
||||
if (depKey != null) {
|
||||
_selectDep(depKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Ctrl(或 Shift)点击:切换该动作的选中状态,实现多选。
|
||||
final bool toggle = HardwareKeyboard.instance.isControlPressed ||
|
||||
HardwareKeyboard.instance.isShiftPressed;
|
||||
c.select(hit?.id, toggle: toggle && hit != null);
|
||||
// 点击空白:清除依赖连线选中。
|
||||
if (_selDep != null) setState(() => _selDep = null);
|
||||
}
|
||||
|
||||
/// 双击空白处:按点击位置换算出的相位角新建动作;
|
||||
/// 若双击在已有动作上则不处理。
|
||||
void _onDoubleTapDown(TapDownDetails d, Size size) {
|
||||
// 双击依赖连线:复位该连线的手动走线偏移(三种视图通用)。
|
||||
final String? depKey = _hitDepKey(_toLogical(d.localPosition, size), size);
|
||||
if (depKey != null) {
|
||||
final int sep = depKey.indexOf('->');
|
||||
if (sep > 0) {
|
||||
setState(() => _selDep = depKey);
|
||||
c.resetDependencyOffset(depKey.substring(0, sep), depKey.substring(sep + 2));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 流程图只读:双击不新建动作、也不编辑。
|
||||
if (c.project.viewState.mode == ViewMode.flow) return;
|
||||
final Offset p = _toLogical(d.localPosition, size);
|
||||
// 双击相位分区带:重命名该分区。
|
||||
if (c.project.viewState.mode == ViewMode.bar) {
|
||||
@@ -369,10 +506,24 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
/// - 桌面:进入画布平移模式;
|
||||
/// - 触屏:不平移(单指只做选择 / 编辑,平移缩放交给双指)。
|
||||
void _onPanStart(Offset p, Size size) {
|
||||
// 命中判定使用“按下时的位置”:手势验收点([p])在移动若干像素之后,
|
||||
// 细目标(依赖连线等)会因此抓空;拖拽增量仍从验收点 [p] 起算。
|
||||
final Offset hitP = _downLogical;
|
||||
// 流程图只读:点中依赖连线仍可拖拽调整走线;空拖拽按桌面习惯平移画布。
|
||||
if (c.project.viewState.mode == ViewMode.flow) {
|
||||
final String? depKey = _hitDepKey(hitP, size);
|
||||
if (depKey != null) {
|
||||
_beginDepDrag(depKey, p, size);
|
||||
return;
|
||||
}
|
||||
_mode = _DragMode.none;
|
||||
_dragAction = null;
|
||||
return;
|
||||
}
|
||||
if (c.project.viewState.mode == ViewMode.bar) {
|
||||
final BarLayout layout = BarLayout(c.project, size);
|
||||
// 优先命中相位分区边界(位于图表顶部,不与动作条重叠)。
|
||||
final (int, bool)? zone = _hitZoneBoundary(p, layout);
|
||||
final (int, bool)? zone = _hitZoneBoundary(hitP, layout);
|
||||
if (zone != null) {
|
||||
_zoneIndex = zone.$1;
|
||||
_zoneIsStart = zone.$2;
|
||||
@@ -383,8 +534,15 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
}
|
||||
// 端点把手优先:精确指针(手写笔)点在把手上时可能略在动作体之外,
|
||||
// 先按把手邻近命中,直接进入「改时长 / 改起始角」模式。
|
||||
final (Action, bool)? handle = _hitHandle(p, size);
|
||||
final (Action, bool, double)? handle = _hitHandle(hitP, size);
|
||||
if (handle != null) {
|
||||
// 端点把手与依赖连线可能重叠(同泳道短线尤其明显):取更近者——
|
||||
// 「点在线上」优先拖线,「点在把手上」优先改时长。
|
||||
final BarDepRoute? depNear =
|
||||
hitBarDep(buildBarDepRoutes(c.project, layout), hitP, _grabRadius);
|
||||
final bool depCloser = depNear != null &&
|
||||
distanceToPolyline(depNear.points, hitP) + 1.5 < handle.$3;
|
||||
if (!depCloser) {
|
||||
_mode = handle.$2 ? _DragMode.resizeStart : _DragMode.resize;
|
||||
_dragAction = handle.$1;
|
||||
_startPointer = p;
|
||||
@@ -393,11 +551,12 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
c.select(handle.$1.id);
|
||||
return;
|
||||
}
|
||||
final Action? hit = layout.hitTest(p, slop: _hitSlop);
|
||||
}
|
||||
final Action? hit = layout.hitTest(hitP, slop: _hitSlop);
|
||||
if (hit != null) {
|
||||
final Rect r = layout.rectFor(hit);
|
||||
final double dr = (p.dx - r.right).abs();
|
||||
final double dl = (p.dx - r.left).abs();
|
||||
final double dr = (hitP.dx - r.right).abs();
|
||||
final double dl = (hitP.dx - r.left).abs();
|
||||
final bool nearRight = dr <= _grabRadius;
|
||||
final bool nearLeft = dl <= _grabRadius;
|
||||
if (nearRight && nearLeft) {
|
||||
@@ -422,21 +581,28 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
} else {
|
||||
final CircularLayout layout = CircularLayout(c.project, size);
|
||||
// 弧端点把手优先命中(同条形视图)。
|
||||
final (Action, bool)? handle = _hitHandle(p, size);
|
||||
final (Action, bool, double)? handle = _hitHandle(hitP, size);
|
||||
if (handle != null) {
|
||||
// 与条形视图同理:连线比把手更近时优先拖线。
|
||||
final ArcDepRoute? depNear =
|
||||
hitArcDep(buildArcDepRoutes(c.project, layout), hitP, _grabRadius);
|
||||
final bool depCloser = depNear != null &&
|
||||
distanceToPath(depNear.buildPath(), hitP) + 1.5 < handle.$3;
|
||||
if (!depCloser) {
|
||||
_mode = handle.$2 ? _DragMode.resizeStart : _DragMode.resize;
|
||||
_dragAction = handle.$1;
|
||||
_startPointer = p;
|
||||
_startAngle = handle.$1.startAngle;
|
||||
_startDuration = handle.$1.durationAngle;
|
||||
_startAnglePointer = angleOf(layout.center, p);
|
||||
_startAnglePointer = angleOf(layout.center, hitP);
|
||||
c.select(handle.$1.id);
|
||||
return;
|
||||
}
|
||||
final Action? hit = layout.hitTest(p, slop: _hitSlop);
|
||||
}
|
||||
final Action? hit = layout.hitTest(hitP, slop: _hitSlop);
|
||||
if (hit != null) {
|
||||
final double a = angleOf(layout.center, p);
|
||||
final double rad = (p - layout.center).distance;
|
||||
final double a = angleOf(layout.center, hitP);
|
||||
final double rad = (hitP - layout.center).distance;
|
||||
// 距端点 [grabRadius] 以内视为拖拽端点(改起止角),否则整体旋转。
|
||||
final double tolDeg = math.atan2(_grabRadius, math.max(rad, 1)) * 180 / math.pi;
|
||||
final bool nearStart = _angleNear(a, hit.startAngle, tolDeg);
|
||||
@@ -453,6 +619,12 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 未命中动作与端点:尝试拖拽依赖走线(沿法线平移整条线)。
|
||||
final String? depKey = _hitDepKey(hitP, size);
|
||||
if (depKey != null) {
|
||||
_beginDepDrag(depKey, p, size);
|
||||
return;
|
||||
}
|
||||
_mode = _DragMode.none;
|
||||
_dragAction = null;
|
||||
}
|
||||
@@ -461,6 +633,22 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
/// 计算增量并写回控制器(调整持续角 / 改层 / 平移相位)。
|
||||
/// [p] 为指针逻辑坐标,[screenDelta] 为指针在屏幕(未变换)空间的位移。
|
||||
void _onPanUpdate(Offset p, Offset screenDelta, Size size) {
|
||||
// 拖拽依赖走线:沿法线方向平移整条线(直角拐点随平移保留)。
|
||||
if (_mode == _DragMode.dep) {
|
||||
final Offset move = p - _depStartPointer;
|
||||
double delta;
|
||||
if (_depRadial != Offset.zero) {
|
||||
// 圆周视图:沿半径方向(法线)投影。
|
||||
delta = move.dx * _depRadial.dx + move.dy * _depRadial.dy;
|
||||
} else if (_depAxis == RouteAxis.vertical) {
|
||||
delta = move.dy;
|
||||
} else {
|
||||
delta = move.dx;
|
||||
}
|
||||
c.setDependencyOffset(_depFrom, _depTo, _depStartOffset + delta,
|
||||
status: '调整依赖走线 $_depFrom→$_depTo');
|
||||
return;
|
||||
}
|
||||
// 拖拽相位分区边界:按横坐标换算角度(结束角允许超过 360° 表示跨圈),
|
||||
// 并做「弱吸附」——靠近整 5°、动作端点或其它分区边界时自动贴合。
|
||||
if (_zoneIndex >= 0) {
|
||||
@@ -561,6 +749,8 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
/// 与手势体系解耦,手写笔(精确指针)与手指行为一致;若已有指针在拖拽时
|
||||
/// 又落下第二根手指,则放弃单指拖拽,交回缩放手势做双指捏合。
|
||||
void _onRawDown(PointerDownEvent e, Size size) {
|
||||
// 记录按下位置:拖拽命中判定统一使用按下点(见 [_downLogical])。
|
||||
_downLogical = _toLogical(e.localPosition, size);
|
||||
if (!_touch) return;
|
||||
if (_rawPointer == -1) {
|
||||
_rawPointer = e.pointer;
|
||||
@@ -651,9 +841,20 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
// ===================== 右键上下文菜单 =====================
|
||||
|
||||
/// 在命中动作处弹出右键菜单,提供添加依赖、改层、复制、删除等操作;
|
||||
/// 若右键落在相位分区带上,则弹出分区的增删改菜单。
|
||||
/// 若右键落在相位分区带上,则弹出分区的增删改菜单;
|
||||
/// 若命中依赖连线,则提供「复位走线偏移 / 取消选中连线」。
|
||||
Future<void> _contextMenu(Offset global, Size size) async {
|
||||
final Offset local = _toLogical(global, size);
|
||||
final String? depKey = _hitDepKey(local, size);
|
||||
// 流程图只读:右键命中连线时可调整走线;否则仅做选中联动。
|
||||
if (c.project.viewState.mode == ViewMode.flow) {
|
||||
if (depKey != null) {
|
||||
await _depMenu(global, depKey);
|
||||
return;
|
||||
}
|
||||
c.select(FlowLayout(c.project).hitTest(local)?.id);
|
||||
return;
|
||||
}
|
||||
if (c.project.viewState.mode == ViewMode.bar) {
|
||||
final int zi = _hitZoneAt(local, BarLayout(c.project, size));
|
||||
if (zi >= 0) {
|
||||
@@ -664,7 +865,11 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
final Action? hit = c.project.viewState.mode == ViewMode.bar
|
||||
? BarLayout(c.project, size).hitTest(local)
|
||||
: CircularLayout(c.project, size).hitTest(local);
|
||||
if (hit == null) return;
|
||||
if (hit == null) {
|
||||
// 未命中动作:若命中依赖连线,弹出连线菜单。
|
||||
if (depKey != null) await _depMenu(global, depKey);
|
||||
return;
|
||||
}
|
||||
c.select(hit.id);
|
||||
final RenderBox box = context.findRenderObject()! as RenderBox;
|
||||
final Offset pos = box.globalToLocal(global);
|
||||
@@ -699,6 +904,27 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 依赖连线右键菜单:复位走线偏移 / 取消选中。
|
||||
Future<void> _depMenu(Offset global, String key) async {
|
||||
setState(() => _selDep = key);
|
||||
final RenderBox box = context.findRenderObject()! as RenderBox;
|
||||
final Offset pos = box.globalToLocal(global);
|
||||
final String? result = await showMenu<String>(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(pos.dx, pos.dy, pos.dx, pos.dy),
|
||||
items: const <PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(value: 'reset', child: Text('复位走线偏移')),
|
||||
PopupMenuItem<String>(value: 'deselect', child: Text('取消选中连线')),
|
||||
],
|
||||
);
|
||||
if (result == 'reset') {
|
||||
final int sep = key.indexOf('->');
|
||||
if (sep > 0) c.resetDependencyOffset(key.substring(0, sep), key.substring(sep + 2));
|
||||
} else if (result == 'deselect') {
|
||||
if (mounted) setState(() => _selDep = null);
|
||||
}
|
||||
}
|
||||
|
||||
/// 相位分区右键菜单:重命名 / 插入 / 删除,实现任意增减。
|
||||
Future<void> _zoneMenu(Offset global, int index) async {
|
||||
final RenderBox box = context.findRenderObject()! as RenderBox;
|
||||
@@ -791,25 +1017,36 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
..setEntry(2, 2, c.project.viewState.zoom),
|
||||
child: CustomPaint(
|
||||
size: size,
|
||||
painter: c.project.viewState.mode == ViewMode.bar
|
||||
? BarPainter(
|
||||
painter: switch (c.project.viewState.mode) {
|
||||
ViewMode.bar => BarPainter(
|
||||
project: c.project,
|
||||
tokens: t,
|
||||
criticalActions: c.criticalActions,
|
||||
criticalDeps: c.criticalDeps,
|
||||
selectedIds: c.selectedIds.toSet(),
|
||||
selectedDep: _selDep,
|
||||
guideAngle: _zoneGuideAngle,
|
||||
dropLane: _dropLane,
|
||||
dropValid: _dropValid,
|
||||
)
|
||||
: CircularPainter(
|
||||
),
|
||||
ViewMode.circular => CircularPainter(
|
||||
project: c.project,
|
||||
tokens: t,
|
||||
criticalActions: c.criticalActions,
|
||||
criticalDeps: c.criticalDeps,
|
||||
selectedIds: c.selectedIds.toSet(),
|
||||
selectedDep: _selDep,
|
||||
guideAngle: _zoneGuideAngle,
|
||||
),
|
||||
ViewMode.flow => FlowchartPainter(
|
||||
project: c.project,
|
||||
tokens: t,
|
||||
criticalActions: c.criticalActions,
|
||||
criticalDeps: c.criticalDeps,
|
||||
selectedIds: c.selectedIds.toSet(),
|
||||
selectedDep: _selDep,
|
||||
),
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
+12
-7
@@ -1994,7 +1994,7 @@ class HelpDialog extends StatelessWidget {
|
||||
// 目标:完成方案的搭建与动作的增删改。
|
||||
_section(t, <List<String>>[
|
||||
<String>['我要新建方案', '顶部「新建」创建空白节拍;「打开」载入 .seq.json。'],
|
||||
<String>['我要先看看示例', '首次启动载入 2 个动作的示例节拍,可直接修改。'],
|
||||
<String>['我要先看看示例', '首次启动载入 5 个动作的示例节拍(装配线节拍),可直接修改。'],
|
||||
<String>['我要新增动作', '双击画布空白处在点击相位新增;或左侧「新建」在 0° 新增(默认最外层)。'],
|
||||
<String>['我要删除动作', '选中后:左侧「删除」/ 行内删除图标 / Delete 键 / 右键菜单;至少保留一个动作 / 泳道。'],
|
||||
<String>['我要改动作属性', '双击画布色块(条形块 / 圆弧)或左侧动作行 → 打开动作编辑对话框;也可选中后点左侧行内编辑图标。'],
|
||||
@@ -2011,14 +2011,18 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['一个动作多输入', '可重复添加多条前置依赖,逐条列出、逐条可删。'],
|
||||
<String>['一个动作多输出', '在「输出依赖 · 结果」查看本动作指向的后续动作,并可逐条删除。'],
|
||||
<String>['FS / SS 是什么', 'FS 绿色实线=完成后启动;SS 琥珀虚线=可提前启动(并行重叠,带 +n°)。'],
|
||||
<String>['连线重叠怎么办', '点选连线后拖动可沿法线方向平移整条线(圆周沿半径方向;跨行走廊为左右拖动);双击连线或右键「复位走线偏移」恢复;同一组连线会自动错开。'],
|
||||
]),
|
||||
// 目标:编辑相位分区并控制画布显示。
|
||||
_section(t, <List<String>>[
|
||||
<String>['相位分区是什么', '把一个循环按角度分成的命名工艺阶段(默认上料/夹紧/加工/检测/下料),条形图顶部标注带即它。'],
|
||||
<String>['相位分区是什么', '把一个循环按角度分成的命名工艺阶段(默认上料 / 加工 / 检测),条形图顶部标注带即它。'],
|
||||
<String>['我要编辑相位分区', '左侧「动作和执行编辑」→「编辑相位分区」;或 F2 →「相位分区」→「编辑…」。增删分区、改名称与起止角;可重叠、可留空、>360° 表示跨圈。'],
|
||||
<String>['我要隐藏相位分区', '左侧「显示选项」取消勾选「相位分区标注」。'],
|
||||
<String>['刻度怎么读', '条形视图:分区带与刻度线之间上排为相位、下排为等价时间;圆周视图:每 30° 的度数外侧标注等价时间。'],
|
||||
<String>['我要切换视图', '顶部「条形节拍 / 圆周节拍」分段开关,两种视图共享同一份数据;标题分别为「条形时序视图」「圆周时序视图」。'],
|
||||
<String>['我要切换视图', '顶部「条形节拍 / 圆周节拍 / 流程图」分段开关,三种视图共享同一份数据;流程图由时序图自动生成(只读)。每次切换都会自动「适应窗口」。'],
|
||||
<String>['条形视图怎么看', '箭头表示动作之间关联:绿色实线 FS 严格顺序;琥珀虚线 SS 并行重叠。'],
|
||||
<String>['圆周视图怎么看', '同心圆环 = 动作层;箭头 = 执行顺序(绿色实线 FS 严格顺序,琥珀虚线 SS 并行重叠);1 圈 = 1 循环 = 360° = 100%。'],
|
||||
<String>['流程图怎么看', '泳道 = 轨道;实线 = FS 顺序,虚线 = SS 并行(含偏移角);加粗光晕 = 关键路径;点击节点选中动作(修改请回时序图)。'],
|
||||
<String>['我要缩放 / 平移', 'Ctrl+滚轮 以光标为锚点缩放;普通滚轮或拖拽空白平移。'],
|
||||
<String>['我要完整显示', '顶部「适应视图」:自动按内容(含刻度、箭头、跨圈标注)计算缩放与居中,编辑后也不会被裁切。'],
|
||||
<String>['我要开关标注', '左侧「显示选项」逐项开关双刻度、依赖箭头、圆环背景、层标注、跨循环高亮等。'],
|
||||
@@ -2028,8 +2032,9 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['我要 AI 生成', '顶部「AI 生成」→ 填 DeepSeek API Key → 选模型(Flash / Pro)→ 选强度(高 / 最高)→ 用自然语言描述 → 生成。'],
|
||||
<String>['生成效果不好', '描述里写清:循环时长、工位数、各动作时长、哪些顺序(完成后启动)、哪些并行。'],
|
||||
<String>['我要看节拍统计', '画布左下角「节拍统计」按钮 → 弹窗查看循环周期、动作数、关键路径、最大并行度、相位覆盖率与瓶颈工位(仅展示可从项目数据推导的指标)。'],
|
||||
<String>['我要导出 SVG', '顶部「导出 SVG」:矢量、分层、带语义 id 与 data-*,可直接进工艺卡 / MES。'],
|
||||
<String>['我要导出 PNG', '顶部「导出 PNG」:按 2 倍像素比导出当前画布为位图。'],
|
||||
<String>['我要导出 SVG', '顶部「导出」下拉菜单 →「导出 SVG」:矢量、分层、带语义 id 与 data-*,可直接进工艺卡 / MES。'],
|
||||
<String>['我要导出 PNG', '顶部「导出」下拉菜单 →「导出 PNG」:按 2 倍像素比导出当前视图为位图。'],
|
||||
<String>['我要导出 drawio', '流程图视图专用:顶部「导出」→「导出 drawio」,输出 diagrams.net(draw.io)可继续编辑的工程文件。'],
|
||||
<String>['我要保存 / 恢复', '「保存」写入 .seq.json 并生成 .bak;每 5 秒自动快照,异常退出后启动可恢复。'],
|
||||
]),
|
||||
// 目标:调整界面与使用快捷键。
|
||||
@@ -2046,7 +2051,7 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['右键动作', '菜单:添加依赖 / 改层 / 复制 / 删除。'],
|
||||
<String>['撤销 / 保存', 'Ctrl+Z / Ctrl+Y 撤销重做;Ctrl+S 保存;Ctrl+O / Ctrl+N 打开 / 新建。'],
|
||||
<String>['帮助入口', '顶部工具栏右侧「?」或 F1 打开帮助中心;画布编辑工具条不重复放置帮助按钮。'],
|
||||
<String>['导出入口', '导出 SVG / PNG 统一放在顶部工具栏右侧,避免多处重复。'],
|
||||
<String>['导出入口', '导出统一放在顶部工具栏「导出」下拉菜单:SVG / PNG 三种视图通用;流程图另有 drawio。'],
|
||||
<String>['其它', 'F2 编辑时序与节拍参数(含单位与相位分区);F3 切换深/浅主题;Delete 删除选中动作。'],
|
||||
]),
|
||||
// 关于:设计人、版本、版权、授权信息与本机 MAC。
|
||||
@@ -2124,7 +2129,7 @@ class HelpDialog extends StatelessWidget {
|
||||
Text('时序图设计 · Sequence Diagram Studio',
|
||||
style: TextStyle(color: t.text, fontSize: 15, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 4),
|
||||
Text('V1.2.0(${android ? '安卓版' : 'Windows 版'})',
|
||||
Text('V1.3.3(${android ? '安卓版' : 'Windows 版'})',
|
||||
style: TextStyle(color: t.dim, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -17,6 +17,7 @@ import '../theme/tokens.dart';
|
||||
import '../update/update_service.dart';
|
||||
import '../version.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'update_icon.dart';
|
||||
|
||||
/// 应用内更新对话框。
|
||||
class UpdateDialog extends StatefulWidget {
|
||||
@@ -197,7 +198,7 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
||||
// 标题
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.download, size: 21, color: t.accent),
|
||||
UpdateIcon(size: 21, color: t.accent),
|
||||
const SizedBox(width: 8),
|
||||
Text('发现新版本 v${info.version}',
|
||||
style: TextStyle(color: t.text, fontSize: 17, fontWeight: FontWeight.w700)),
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/// 应用内更新按钮矢量图标。
|
||||
///
|
||||
/// 造型与设计稿(docs/更新.svg,viewBox 1024)严格对应:
|
||||
/// 圆环(外径 446 / 内径 386.2)+ 空心向上的箭头 + 底部两条圆头横杠。
|
||||
/// 采用归一化坐标矢量绘制,可任意缩放、随主题变色,小尺寸下保持清晰。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 更新图标:圆环 + 空心上箭头 + 底座横杠。
|
||||
class UpdateIcon extends StatelessWidget {
|
||||
/// 构造;[size] 为正方形边长,[color] 为线条颜色。
|
||||
const UpdateIcon({super.key, required this.size, required this.color});
|
||||
|
||||
/// 图标边长(逻辑像素)。
|
||||
final double size;
|
||||
|
||||
/// 线条颜色(随主题传入)。
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CustomPaint(
|
||||
size: Size.square(size),
|
||||
painter: _UpdateIconPainter(color),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 更新图标绘制器:按设计稿坐标换算为归一化路径。
|
||||
class _UpdateIconPainter extends CustomPainter {
|
||||
/// 构造;[color] 线条颜色。
|
||||
_UpdateIconPainter(this.color);
|
||||
|
||||
/// 线条颜色。
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final double s = size.shortestSide;
|
||||
Offset p(double x, double y) => Offset(x * s, y * s);
|
||||
final Paint stroke = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeCap = StrokeCap.round
|
||||
..strokeJoin = StrokeJoin.round
|
||||
..color = color;
|
||||
|
||||
// 1) 外圈圆环:中线半径 0.4064、线宽 0.0584(对应外径 446 / 内径 386.2)。
|
||||
stroke.strokeWidth = 0.0584 * s;
|
||||
canvas.drawCircle(Offset(s / 2, s / 2), 0.4064 * s, stroke);
|
||||
|
||||
// 2) 空心向上的箭头:外轮廓 + 内轮廓(evenOdd 挖空,得到等宽描边效果)。
|
||||
final Path arrow = Path()..fillType = PathFillType.evenOdd;
|
||||
// 外轮廓(顶点 → 右翼尖 → 箭杆 → 左翼尖,坐标取自设计稿 / 1024)。
|
||||
arrow.moveTo(0.5 * s, 0.202 * s);
|
||||
arrow.lineTo(0.7638 * s, 0.4284 * s);
|
||||
arrow.lineTo(0.7439 * s, 0.4789 * s);
|
||||
arrow.lineTo(0.6432 * s, 0.4789 * s);
|
||||
arrow.lineTo(0.6432 * s, 0.5942 * s);
|
||||
arrow.lineTo(0.6146 * s, 0.6234 * s);
|
||||
arrow.lineTo(0.3892 * s, 0.6234 * s);
|
||||
arrow.lineTo(0.36 * s, 0.5942 * s);
|
||||
arrow.lineTo(0.36 * s, 0.4789 * s);
|
||||
arrow.lineTo(0.2575 * s, 0.4789 * s);
|
||||
arrow.lineTo(0.2377 * s, 0.4283 * s);
|
||||
arrow.close();
|
||||
// 内轮廓(挖空)。
|
||||
arrow.moveTo(0.5022 * s, 0.2637 * s);
|
||||
arrow.lineTo(0.3322 * s, 0.4205 * s);
|
||||
arrow.lineTo(0.3892 * s, 0.4205 * s);
|
||||
arrow.lineTo(0.4184 * s, 0.4497 * s);
|
||||
arrow.lineTo(0.4184 * s, 0.565 * s);
|
||||
arrow.lineTo(0.5848 * s, 0.565 * s);
|
||||
arrow.lineTo(0.5848 * s, 0.4497 * s);
|
||||
arrow.lineTo(0.6146 * s, 0.4205 * s);
|
||||
arrow.lineTo(0.6706 * s, 0.4205 * s);
|
||||
arrow.close();
|
||||
canvas.drawPath(arrow, Paint()..color = color);
|
||||
|
||||
// 3) 底座两条圆头横杠(中线 y=0.6839 / 0.7739,线宽同圆环)。
|
||||
canvas.drawLine(p(0.381, 0.6839), p(0.625, 0.6839), stroke);
|
||||
canvas.drawLine(p(0.381, 0.7739), p(0.625, 0.7739), stroke);
|
||||
}
|
||||
|
||||
/// 线条颜色变化时需要重绘。
|
||||
@override
|
||||
bool shouldRepaint(covariant _UpdateIconPainter old) => old.color != color;
|
||||
}
|
||||
@@ -86,10 +86,12 @@ class UpdateService {
|
||||
|
||||
/// 检查更新。
|
||||
///
|
||||
/// 远端版本高于 [kAppVersion] 且存在当前平台的安装包时返回 [UpdateInfo];
|
||||
/// [currentVersion] 为当前版本(缺省用 [kAppVersion];自检工具可传入模拟值)。
|
||||
/// 远端版本高于当前版本且存在当前平台的安装包时返回 [UpdateInfo];
|
||||
/// 无更新(或尚未发布任何版本)返回 null;网络 / 服务器异常抛出 [Exception],
|
||||
/// 由调用方决定是否静默。
|
||||
static Future<UpdateInfo?> check() async {
|
||||
static Future<UpdateInfo?> check({String? currentVersion}) async {
|
||||
final String current = currentVersion ?? kAppVersion;
|
||||
final HttpClient client = HttpClient()
|
||||
..connectionTimeout = const Duration(seconds: 8);
|
||||
try {
|
||||
@@ -103,7 +105,7 @@ class UpdateService {
|
||||
}
|
||||
final Map<String, dynamic> j = jsonDecode(text) as Map<String, dynamic>;
|
||||
final String tag = (j['tag_name'] as String?) ?? '';
|
||||
if (!isNewerVersion(tag, kAppVersion)) return null;
|
||||
if (!isNewerVersion(tag, current)) return null;
|
||||
final String notes = (j['body'] as String?) ?? '';
|
||||
// 选择当前平台的安装包:安卓取 .apk;Windows 优先 .zip(绿色版整包)。
|
||||
bool isTarget(String n) {
|
||||
|
||||
+1
-1
@@ -2,4 +2,4 @@
|
||||
///
|
||||
/// 应用内更新检查用它判断服务器发布的版本是否更新;
|
||||
/// **每次发版必须与 pubspec 同步更新**(见 BUILD-NOTES 的发布流程)。
|
||||
const String kAppVersion = '1.2.0';
|
||||
const String kAppVersion = '1.3.3';
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.2.0+12
|
||||
version: 1.3.3+19
|
||||
|
||||
environment:
|
||||
sdk: ^3.13.3
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# V1.2.1 更新内容
|
||||
|
||||
- 更新按钮图标改为全新设计的「升级」样式(圆环 + 上箭头 + 底座横杠),
|
||||
与界面整体风格统一,一眼可辨是「检查更新」
|
||||
- 更新对话框标题图标同步更新
|
||||
- 右下角缩略预览(条形 / 圆周)中的动作线条改细到约 2px,更符合缩略图观感
|
||||
- **动作两端改为方头**(带小圆角):条形与圆周视图中的动作长度严格等于
|
||||
真实时长,不再因圆头端帽向外多出而误读;SVG / PNG 导出同步
|
||||
@@ -0,0 +1,5 @@
|
||||
# V1.2.2 更新内容
|
||||
|
||||
- **修复发布版无法联网的问题**:补充网络访问权限(INTERNET),并为更新服务器
|
||||
配置明文 HTTP 白名单——应用内「检查更新」恢复正常(此前 release 版收不到更新提示)
|
||||
- AI 自然语言生成在发布版中同样恢复可用
|
||||
@@ -0,0 +1,5 @@
|
||||
# V1.2.3 更新内容
|
||||
|
||||
- 修复「适应视图」在条形视图动作较多时的显示问题:画面被缩小后现在会**居中显示**,
|
||||
不再偏移到左上角(此前固定 pan=0 导致缩小的内容钉在左上角)
|
||||
- 圆周视图的适应视图行为保持不变(本来就是居中计算)
|
||||
@@ -0,0 +1,19 @@
|
||||
# V1.3.0 更新内容
|
||||
|
||||
## 全新:流程图视图(第三个视图模式)
|
||||
- 由时序图**自动生成**:泳道 = 轨道;动作节点显示「序号. 名称 + 时长 · 工位」
|
||||
- 依赖连线:绿色实线 FS 顺序 / 琥珀虚线 SS 并行(含偏移角标注)
|
||||
- 关键路径加粗光晕;无前置依赖的动作自动从「开始」并列引出,形成并行分支
|
||||
- 左侧相位阶段栏:相位分区按动作归属竖排显示(每个动作行归属覆盖占比最大的分区)
|
||||
- 只读预览:点击节点可选中联动动作,修改请回条形 / 圆周视图
|
||||
(流程图页的 AI 生成、撤销 / 重做、动作增删、属性编辑等入口会自动置灰)
|
||||
|
||||
## 导出升级
|
||||
- 导出按钮合并为下拉菜单:**SVG / PNG 三种视图通用**
|
||||
- 流程图额外支持导出 **drawio**:可在 diagrams.net(draw.io)中继续编辑,
|
||||
泳道、相位分区、依赖关系都保留,方便二次加工
|
||||
|
||||
## 其他
|
||||
- 首次启动的默认示例升级为完整「装配线节拍」(8 个动作 / 3 个工位 / 4 个相位分区)
|
||||
- 左侧栏「视图模式」只保留条形 / 圆周节拍切换(流程图入口在顶部工具栏)
|
||||
- 修复若干界面细节与截图工具问题
|
||||
@@ -0,0 +1,8 @@
|
||||
# V1.3.1 更新内容
|
||||
|
||||
- 视图切换强化:每次切换条形 / 圆周 / 流程图都会自动「适应窗口」,
|
||||
不会再沿用上一个视图的缩放与平移(此前切换后画面可能跑偏)
|
||||
- 预览缩略图区域固定尺寸:动作再多也不会撑大「条形预览 / 圆周预览」卡片,
|
||||
只会在内部自动缩小缩略图、把线条画得更细
|
||||
- 更新按钮的「有新版本」红点改为显示在按钮**左上角**
|
||||
- 默认示例数据精简:首次启动为 5 个动作 / 3 个工位 / 3 个相位分区,更清爽
|
||||
@@ -0,0 +1,9 @@
|
||||
# V1.3.2 更新内容
|
||||
|
||||
- 移除顶部工具栏右上角多余的「流程图」快捷按钮
|
||||
(流程图入口保留在「条形节拍 / 圆周节拍 / 流程图」分段切换中)
|
||||
- 画布标题精简:条形 / 圆周视图改为「标题 +(线型说明)」单行展示,
|
||||
不再单独占一行,节省纵向显示空间
|
||||
- 视图的完整说明(同心圆环含义、循环换算、流程图读法等)统一移入
|
||||
「帮助」(F1)→「相位分区与视图」中查阅
|
||||
- 默认示例保持精简:5 个动作 / 3 个工位 / 3 个相位分区
|
||||
@@ -0,0 +1,11 @@
|
||||
# V1.3.3 更新内容
|
||||
|
||||
- **依赖连线自动错开**:同一走线分组内的多条依赖(同泳道 / 相邻泳道 /
|
||||
跨行绕行)不再完全重叠,依次自动错开
|
||||
- **新增「拖动调整走线」**:点选连线后可拖动整条线
|
||||
- 条形 / 流程图:上下拖动平移横线;跨行走廊为左右拖动
|
||||
- 圆周视图:沿半径方向(法线)拖动
|
||||
- 直角拐点随平移保留,走线始终保持正交;双击连线或
|
||||
右键「复位走线偏移」即可恢复自动位置
|
||||
- 三种视图(条形 / 圆周 / 流程图)均支持;偏移随工程保存
|
||||
- 默认示例保持精简:5 个动作 / 3 个工位 / 3 个相位分区
|
||||
@@ -1,4 +1,4 @@
|
||||
# ============================================================
|
||||
# ============================================================
|
||||
# 发布新版本到 Gitea Releases(更新说明 + 安装包附件)
|
||||
#
|
||||
# 用法(在仓库根目录或任意位置):
|
||||
@@ -9,7 +9,9 @@
|
||||
# - 更新说明写入 Release 正文(Markdown),客户端「检查更新」时读取展示;
|
||||
# - 安卓 APK:默认取 release\sequence_diagram_android_v<版本>_release.apk;
|
||||
# - Windows 绿色版:默认把 dist\ 打包为 zip 后上传(客户端下载后原地覆盖);
|
||||
# - 安装包作为 Release 附件保存,不进入 git 历史,仓库保持精简。
|
||||
# - 安装包作为 Release 附件保存,不进入 git 历史,仓库保持精简;
|
||||
# - 发布完成后自动清理历史附件:只保留最近 2 个版本的安装包
|
||||
# (Release 记录与更新说明保留,仅删除更早版本的附件,释放服务器空间)。
|
||||
# ============================================================
|
||||
param(
|
||||
[Parameter(Mandatory = $true)][string]$Version,
|
||||
@@ -78,5 +80,39 @@ function Upload-Asset([string]$path) {
|
||||
Upload-Asset $ApkPath
|
||||
Upload-Asset $WindowsZipPath
|
||||
|
||||
# ---- 4) 清理历史版本附件:只保留最近 2 个版本的安装包 ----
|
||||
# 客户端更新只使用「最新版本」的附件,更早版本的安装包可安全删除以释放空间;
|
||||
# Release 记录与更新说明保留,历史版本页面仍可查阅。
|
||||
# 该步骤失败不影响本次发布(仅打印警告)。
|
||||
$keepVersions = 2
|
||||
try {
|
||||
Write-Host ""
|
||||
Write-Host "清理历史版本附件(只保留最近 $keepVersions 个版本)..."
|
||||
$listFile = Join-Path $env:TEMP "seq_releases_list.json"
|
||||
curl.exe -s -o $listFile "$Server/api/v1/repos/$Owner/$Repo/releases?limit=50" | Out-Null
|
||||
$all = [System.IO.File]::ReadAllText($listFile, [System.Text.Encoding]::UTF8) | ConvertFrom-Json
|
||||
$ordered = @($all | Sort-Object -Property created_at -Descending)
|
||||
$freed = 0
|
||||
for ($i = $keepVersions; $i -lt $ordered.Count; $i++) {
|
||||
$r = $ordered[$i]
|
||||
foreach ($a in $r.assets) {
|
||||
$code = curl.exe -s -o NUL -w "%{http_code}" -X DELETE -u $Auth "$Server/api/v1/repos/$Owner/$Repo/releases/$($r.id)/assets/$($a.id)"
|
||||
if ($code -eq "204") {
|
||||
$freed += $a.size
|
||||
Write-Host " 已清理 $($r.tag_name) / $($a.name)"
|
||||
} else {
|
||||
Write-Host " [warn] 清理失败 $($r.tag_name) / $($a.name):HTTP $code"
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($freed -gt 0) {
|
||||
Write-Host " 共释放 $([math]::Round($freed / 1MB, 1)) MB"
|
||||
} else {
|
||||
Write-Host " 无需清理(仅最近 $keepVersions 个版本带有附件)"
|
||||
}
|
||||
} catch {
|
||||
Write-Host " [warn] 历史附件清理失败(不影响本次发布):$_"
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "发布完成!客户端下次启动即可检查到 v$Version($Server/$Owner/$Repo/releases)"
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
// 依赖走线测试:自动错开、手动偏移、命中测试与 JSON 往返。
|
||||
import 'dart:ui' show Size, Offset;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sequence_diagram/layout/dep_routes.dart';
|
||||
import 'package:sequence_diagram/layout/layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// 构造测试工程:A1/A2/A3 同属一条泳道(L0),A3 依赖 A1 与 A2,
|
||||
/// 用于验证“同组依赖自动错开 + 手动偏移”。
|
||||
Project _project({double offset = 0}) {
|
||||
return Project(
|
||||
name: 'test',
|
||||
cycle: const Cycle(durationMs: 2400),
|
||||
stations: const <Station>[
|
||||
Station(id: 'ST1', name: '工位 1', order: 0, color: 0xFF4CC9F0),
|
||||
],
|
||||
actions: <Action>[
|
||||
const Action(
|
||||
id: 'A1',
|
||||
name: 'A1',
|
||||
stationId: 'ST1',
|
||||
driver: 'x',
|
||||
startAngle: 0,
|
||||
durationAngle: 30,
|
||||
layer: 0,
|
||||
color: 0xFF4CC9F0),
|
||||
const Action(
|
||||
id: 'A2',
|
||||
name: 'A2',
|
||||
stationId: 'ST1',
|
||||
driver: 'x',
|
||||
startAngle: 40,
|
||||
durationAngle: 30,
|
||||
layer: 0,
|
||||
color: 0xFF7BD88F),
|
||||
Action(
|
||||
id: 'A3',
|
||||
name: 'A3',
|
||||
stationId: 'ST1',
|
||||
driver: 'x',
|
||||
startAngle: 80,
|
||||
durationAngle: 30,
|
||||
layer: 0,
|
||||
color: 0xFFFFD166,
|
||||
deps: <Dependency>[
|
||||
Dependency(fromId: 'A1', toId: 'A3', routeOffset: offset),
|
||||
const Dependency(fromId: 'A2', toId: 'A3'),
|
||||
]),
|
||||
],
|
||||
units: const UnitSettings(),
|
||||
viewState: const ViewState(mode: ViewMode.bar),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
const Size size = Size(1280, 800);
|
||||
|
||||
test('条形:同组依赖自动错开,手动偏移叠加', () {
|
||||
final Project p = _project(offset: 20);
|
||||
final BarLayout layout = BarLayout(p, size);
|
||||
final List<BarDepRoute> routes = buildBarDepRoutes(p, layout);
|
||||
expect(routes.length, 2);
|
||||
final BarDepRoute r1 = routes.firstWhere((BarDepRoute r) => r.key == 'A1->A3');
|
||||
final BarDepRoute r2 = routes.firstWhere((BarDepRoute r) => r.key == 'A2->A3');
|
||||
// A1→A3 手动偏移 +20;A2→A3 自动错开 −6:两条线纵坐标相差 26。
|
||||
final double y1 = r1.points.first.dy;
|
||||
final double y2 = r2.points.first.dy;
|
||||
expect(y1 - y2, closeTo(26, 0.001));
|
||||
});
|
||||
|
||||
test('条形:命中测试选中最近的连线', () {
|
||||
final Project p = _project();
|
||||
final List<BarDepRoute> routes = buildBarDepRoutes(p, BarLayout(p, size));
|
||||
final BarDepRoute r1 = routes.firstWhere((BarDepRoute r) => r.key == 'A1->A3');
|
||||
final Offset mid = Offset(
|
||||
(r1.points.first.dx + r1.points.last.dx) / 2,
|
||||
r1.points.first.dy,
|
||||
);
|
||||
expect(hitBarDep(routes, mid, 7)?.key, 'A1->A3');
|
||||
expect(hitBarDep(routes, mid + const Offset(0, 40), 7), isNull);
|
||||
});
|
||||
|
||||
test('依赖 routeOffset JSON 往返', () {
|
||||
const Dependency d =
|
||||
Dependency(fromId: 'A1', toId: 'A2', offsetAngle: 10, routeOffset: 24);
|
||||
final Dependency back = Dependency.fromJson(d.toJson());
|
||||
expect(back.routeOffset, 24);
|
||||
expect(back.offsetAngle, 10);
|
||||
// 旧文件没有 routeOffset 字段时回退为 0。
|
||||
final Dependency legacy = Dependency.fromJson(<String, dynamic>{
|
||||
'fromId': 'A1',
|
||||
'toId': 'A2',
|
||||
'type': 'FS',
|
||||
'offsetAngle': 5,
|
||||
});
|
||||
expect(legacy.routeOffset, 0);
|
||||
});
|
||||
}
|
||||
@@ -4,8 +4,10 @@ import 'dart:typed_data';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sequence_diagram/export/drawio_writer.dart';
|
||||
import 'package:sequence_diagram/export/export_renderer.dart';
|
||||
import 'package:sequence_diagram/export/svg_writer.dart';
|
||||
import 'package:sequence_diagram/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
|
||||
@@ -50,4 +52,75 @@ void main() {
|
||||
expect(first & 0xFFFFFF, 0xFFFFFF);
|
||||
File('build/export_preview.png').writeAsBytesSync(bytes);
|
||||
});
|
||||
|
||||
test('svg export: flowchart view (lanes / phases / edges / actions / start-end)', () {
|
||||
final Project p = demoTiming();
|
||||
final String svg = SvgWriter(project: p, tokens: Tokens.light, mode: ViewMode.flow).build();
|
||||
expect(svg, contains('流程图视图'));
|
||||
expect(svg, contains('<g id="lanes">'));
|
||||
expect(svg, contains('轨道 L1'));
|
||||
expect(svg, contains('<g id="phases">'));
|
||||
expect(svg, contains('上料相位'));
|
||||
expect(svg, contains('rotate(-90)'));
|
||||
expect(svg, contains('<g id="edges">'));
|
||||
expect(svg, contains('marker-end="url(#arrow-fs)"'));
|
||||
expect(svg, contains('marker-end="url(#arrow-ss)"'));
|
||||
expect(svg, contains('stroke-dasharray="6 4"'));
|
||||
expect(svg, contains('>SS+10°</text>'));
|
||||
expect(svg, contains('<g id="actions">'));
|
||||
expect(svg, contains('data-action="A1"'));
|
||||
// 每个节点都在(标题 / 副标题取自布局,避免硬编码格式)。
|
||||
final FlowLayout layout = FlowLayout(p);
|
||||
for (final FlowNode n in layout.nodes) {
|
||||
expect(svg, contains(n.title), reason: '缺少节点标题 ${n.title}');
|
||||
if (n.action != null) {
|
||||
expect(svg, contains(n.subtitle), reason: '缺少节点副标题 ${n.subtitle}');
|
||||
}
|
||||
}
|
||||
expect(svg, contains('开始'));
|
||||
expect(svg, contains('结束'));
|
||||
});
|
||||
|
||||
test('png export: flowchart view renders on 1920x1080 canvas (2x bitmap)', () async {
|
||||
final Project p = demoTiming().copyWith(viewState: const ViewState(mode: ViewMode.flow));
|
||||
final Uint8List bytes = await renderExportPng(
|
||||
project: p,
|
||||
tokens: Tokens.light,
|
||||
criticalActions: const <String>{'A1', 'A2', 'A3'},
|
||||
criticalDeps: const <String>{'A1->A2', 'A2->A3'},
|
||||
);
|
||||
final ui.ImmutableBuffer buf = await ui.ImmutableBuffer.fromUint8List(bytes);
|
||||
final ui.ImageDescriptor desc = await ui.ImageDescriptor.encoded(buf);
|
||||
expect(desc.width, 3840);
|
||||
expect(desc.height, 2160);
|
||||
final ui.Codec codec = await desc.instantiateCodec();
|
||||
final ui.FrameInfo frame = await codec.getNextFrame();
|
||||
final ByteData? rgba = await frame.image.toByteData(format: ui.ImageByteFormat.rawRgba);
|
||||
expect(rgba!.getUint32(0) & 0xFFFFFF, 0xFFFFFF);
|
||||
File('build/export_flow_preview.png').writeAsBytesSync(bytes);
|
||||
});
|
||||
|
||||
test('drawio export: mxfile with lanes / phases / nodes / edges', () {
|
||||
final Project p = demoTiming();
|
||||
final String xml = DrawioWriter(project: p, tokens: Tokens.light).build();
|
||||
expect(xml, startsWith('<mxfile'));
|
||||
expect(xml, endsWith('</mxfile>'));
|
||||
expect(xml, contains('<mxGraphModel'));
|
||||
expect(xml, contains('<mxCell id="0"/>'));
|
||||
expect(xml, contains('<mxCell id="1" parent="0"/>'));
|
||||
expect(xml, contains('value="轨道 L1"'));
|
||||
expect(xml, contains('value="上料相位"'));
|
||||
expect(xml, contains('horizontal=0'));
|
||||
// 动作节点:两行文本( 换行)+ 依赖以 source / target 引用。
|
||||
expect(xml, contains(' '));
|
||||
expect(xml, contains('source="A1" target="A2"'));
|
||||
expect(xml, contains('value="SS+10°"'));
|
||||
expect(xml, contains('edge="1"'));
|
||||
expect(xml, contains('value="开始"'));
|
||||
expect(xml, contains('value="结束"'));
|
||||
// 保留 id 映射为可读短名,避免出现下划线开头的内部 id。
|
||||
expect(xml, contains('id="flow-start"'));
|
||||
expect(xml, contains('id="flow-end"'));
|
||||
expect(xml, isNot(contains('__flow_start__')));
|
||||
});
|
||||
}
|
||||
|
||||
+15
-34
@@ -5,40 +5,9 @@ import 'package:flutter/services.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// 构造一个动作较多、含依赖与相位分区的演示工程。
|
||||
Project demoTiming() {
|
||||
return Project(
|
||||
name: '装配线节拍',
|
||||
cycle: const Cycle(durationMs: 2400),
|
||||
stations: const <Station>[
|
||||
Station(id: 'ST1', name: '上料工位', order: 0, color: 0xFF4CC9F0),
|
||||
Station(id: 'ST2', name: '加工工位', order: 1, color: 0xFFFFD166),
|
||||
Station(id: 'ST3', name: '检测工位', order: 2, color: 0xFF34D399),
|
||||
],
|
||||
actions: <Action>[
|
||||
const Action(id: 'A1', name: '上料', stationId: 'ST1', driver: '气缸 Y1', startAngle: 0, durationAngle: 45, layer: 0, color: 0xFF4CC9F0),
|
||||
const Action(id: 'A2', name: '定位夹紧', stationId: 'ST1', driver: '气缸 Y2', startAngle: 50, durationAngle: 55, layer: 0, color: 0xFF7BD88F,
|
||||
deps: <Dependency>[Dependency(fromId: 'A1', toId: 'A2', type: DepType.fs)]),
|
||||
const Action(id: 'A3', name: '伺服下压', stationId: 'ST2', driver: '伺服 M1', startAngle: 90, durationAngle: 70, layer: 1, color: 0xFFFFD166,
|
||||
deps: <Dependency>[Dependency(fromId: 'A2', toId: 'A3', type: DepType.fs)]),
|
||||
const Action(id: 'A4', name: '超声焊接', stationId: 'ST2', driver: '超声 U1', startAngle: 100, durationAngle: 50, layer: 2, color: 0xFFF472B6,
|
||||
deps: <Dependency>[Dependency(fromId: 'A3', toId: 'A4', type: DepType.ss, offsetAngle: 10)]),
|
||||
const Action(id: 'A5', name: '视觉检测', stationId: 'ST3', driver: '相机 C1', startAngle: 160, durationAngle: 70, layer: 1, color: 0xFF7C5CFF,
|
||||
deps: <Dependency>[Dependency(fromId: 'A4', toId: 'A5', type: DepType.fs)]),
|
||||
const Action(id: 'A6', name: '分选下料', stationId: 'ST3', driver: '气缸 Y3', startAngle: 200, durationAngle: 70, layer: 2, color: 0xFFFF9F7C,
|
||||
deps: <Dependency>[Dependency(fromId: 'A5', toId: 'A6', type: DepType.fs)]),
|
||||
const Action(id: 'A7', name: '清洁吹气', stationId: 'ST1', driver: '电磁阀 V1', startAngle: 240, durationAngle: 80, layer: 3, color: 0xFF34D399,
|
||||
deps: <Dependency>[Dependency(fromId: 'A6', toId: 'A7', type: DepType.fs)]),
|
||||
],
|
||||
units: const UnitSettings(timeUnit: TimeUnit.s),
|
||||
viewState: const ViewState(mode: ViewMode.bar),
|
||||
phaseZones: const <PhaseZone>[
|
||||
PhaseZone(name: '上料相位', startAngle: 0, endAngle: 70),
|
||||
PhaseZone(name: '加工相位', startAngle: 70, endAngle: 200),
|
||||
PhaseZone(name: '检测相位', startAngle: 200, endAngle: 300),
|
||||
PhaseZone(name: '下料相位', startAngle: 300, endAngle: 360),
|
||||
],
|
||||
);
|
||||
}
|
||||
/// 演示工程:与内置默认工程完全一致(`Project.demo()`),
|
||||
/// 保证「本地构建启动即所见」与演示截图的数据永远同步。
|
||||
Project demoTiming() => Project.demo();
|
||||
|
||||
/// 从系统字体加载中文字体,使测试截图中的中文正常渲染。
|
||||
Future<void> loadZhFonts() async {
|
||||
@@ -57,3 +26,15 @@ Future<void> loadZhFonts() async {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// 从 Flutter SDK 加载 Material 图标字体,使测试截图中的图标正常渲染
|
||||
/// (否则所有 Icon 会显示为空心方框)。
|
||||
Future<void> loadMaterialIcons() async {
|
||||
final String root = Platform.environment['FLUTTER_ROOT'] ?? '';
|
||||
if (root.isEmpty) return;
|
||||
final File f = File('$root/bin/cache/artifacts/material_fonts/MaterialIcons-Regular.otf');
|
||||
if (!f.existsSync()) return;
|
||||
final ByteData bytes = ByteData.sublistView(await f.readAsBytes());
|
||||
final FontLoader loader = FontLoader('MaterialIcons')..addFont(Future<ByteData>.value(bytes));
|
||||
await loader.load();
|
||||
}
|
||||
|
||||
@@ -52,8 +52,9 @@ void main() {
|
||||
expect(decoded.actions.length, p.actions.length);
|
||||
expect(decoded.stations.length, p.stations.length);
|
||||
expect(decoded.phaseZones.length, p.phaseZones.length);
|
||||
expect(decoded.actions.last.deps.first.type, DepType.fs);
|
||||
expect(decoded.cycle.durationMs, 3600);
|
||||
final Action withDeps = decoded.actions.firstWhere((Action a) => a.deps.isNotEmpty);
|
||||
expect(withDeps.deps.first.type, DepType.fs);
|
||||
expect(decoded.cycle.durationMs, 2400);
|
||||
expect(decoded.actions.last.color, p.actions.last.color);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,8 @@ void main() {
|
||||
group('station management', () {
|
||||
test('setStations reassigns actions of a removed station', () {
|
||||
final AppController c = AppController(project: Project.demo());
|
||||
expect(c.project.stations.length, 2);
|
||||
// 演示工程至少包含两个工位;移除第二个工位后其动作应被重新分配。
|
||||
expect(c.project.stations.length, greaterThan(1));
|
||||
final String removed = c.project.stations[1].id;
|
||||
expect(c.project.actions.any((Action a) => a.stationId == removed), isTrue);
|
||||
|
||||
@@ -26,13 +27,14 @@ void main() {
|
||||
|
||||
test('setStations can add and rename stations', () {
|
||||
final AppController c = AppController(project: Project.demo());
|
||||
final int before = c.project.stations.length;
|
||||
final List<Station> next = <Station>[
|
||||
...c.project.stations,
|
||||
const Station(id: 'ST3', name: '工位 3', order: 2, color: 0xFF4ADE80),
|
||||
const Station(id: 'ST9', name: '工位 9', order: 9, color: 0xFF4ADE80),
|
||||
];
|
||||
c.setStations(next);
|
||||
expect(c.project.stations.length, 3);
|
||||
expect(c.project.stationById('ST3')?.name, '工位 3');
|
||||
expect(c.project.stations.length, before + 1);
|
||||
expect(c.project.stationById('ST9')?.name, '工位 9');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'helpers.dart';
|
||||
void main() {
|
||||
testWidgets('generate tablet demo screenshots', (WidgetTester tester) async {
|
||||
await tester.runAsync(() => loadZhFonts());
|
||||
await tester.runAsync(() => loadMaterialIcons());
|
||||
|
||||
tester.view.physicalSize = const Size(1280, 800);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
@@ -25,6 +26,7 @@ void main() {
|
||||
key: const ValueKey<String>('shot'),
|
||||
child: MaterialApp(
|
||||
theme: buildTheme(t),
|
||||
debugShowCheckedModeBanner: false,
|
||||
home: AppShell(controller: c),
|
||||
),
|
||||
);
|
||||
@@ -38,13 +40,15 @@ void main() {
|
||||
await shot('../demo/tablet-bar-light.png');
|
||||
|
||||
// 展开左右侧栏(浮层)并钉住,展示停靠布局。
|
||||
await tester.tap(find.byIcon(Icons.chevron_right).first);
|
||||
// 注意:不能用 find.byIcon(Icons.chevron_right)——画布右下角的预览卡里
|
||||
// 也有同类图标且更早出现在组件树中,会误触「切换视图」;改为按坐标点贴边轨道。
|
||||
await tester.tapAt(const Offset(10, 300));
|
||||
await tester.pump();
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
await tester.pump();
|
||||
}
|
||||
await tester.tap(find.byIcon(Icons.chevron_left).first);
|
||||
await tester.tapAt(const Offset(1270, 300));
|
||||
await tester.pump();
|
||||
if (tester.any(find.byIcon(Icons.push_pin_outlined))) {
|
||||
await tester.tap(find.byIcon(Icons.push_pin_outlined).first);
|
||||
@@ -56,12 +60,33 @@ void main() {
|
||||
c.setViewMode(ViewMode.circular);
|
||||
await shot('../demo/tablet-circular-light.png');
|
||||
|
||||
// 深色主题:条形与圆周。
|
||||
// 流程图视图(浅色):由时序图自动生成(泳道 = 轨道,只读)。
|
||||
c.setViewMode(ViewMode.flow);
|
||||
await shot('../demo/tablet-flow-light.png');
|
||||
|
||||
// 流程图导出菜单:SVG / PNG 之外额外提供 drawio 入口(仅流程图)。
|
||||
await tester.tap(find.text('导出'));
|
||||
await tester.pumpAndSettle();
|
||||
await shot('../demo/tablet-flow-export-menu-light.png');
|
||||
await tester.tapAt(const Offset(5, 5));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 选中动作:右侧属性面板进入只读态(滑块 / 依赖编辑置灰)。
|
||||
c.select('A2');
|
||||
await shot('../demo/tablet-flow-selected-light.png');
|
||||
c.select(null);
|
||||
|
||||
// 深色主题:条形、圆周与流程图。
|
||||
// 注意:MaterialApp 的主题切换带 200ms 过渡动画,必须等动画结束再截图,
|
||||
// 否则截到的是过渡起点(仍然是浅色)。
|
||||
c.toggleTheme();
|
||||
await tester.pumpWidget(shell(Tokens.dark));
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
c.setViewMode(ViewMode.bar);
|
||||
await shot('../demo/tablet-bar-dark.png');
|
||||
c.setViewMode(ViewMode.circular);
|
||||
await shot('../demo/tablet-circular-dark.png');
|
||||
c.setViewMode(ViewMode.flow);
|
||||
await shot('../demo/tablet-flow-dark.png');
|
||||
});
|
||||
}
|
||||
|
||||
+141
-1
@@ -1,9 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sequence_diagram/layout/dep_routes.dart';
|
||||
import 'package:sequence_diagram/layout/layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/app_shell.dart';
|
||||
import 'package:sequence_diagram/ui/canvas_view.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('renders bar and circular views without errors', (WidgetTester tester) async {
|
||||
@@ -25,9 +28,10 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(controller.project.viewState.mode, ViewMode.circular);
|
||||
|
||||
final int before = controller.project.actions.length;
|
||||
controller.addAction(startAngle: 30);
|
||||
await tester.pump();
|
||||
expect(controller.project.actions.length, 3);
|
||||
expect(controller.project.actions.length, before + 1);
|
||||
|
||||
controller.setViewMode(ViewMode.bar);
|
||||
await tester.pump();
|
||||
@@ -56,4 +60,140 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(controller.brightness, Brightness.dark);
|
||||
});
|
||||
|
||||
testWidgets('export menu: drawio only in flow view; AI disabled in flow', (WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(1920, 1080);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final AppController controller = AppController();
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: buildTheme(Tokens.light),
|
||||
home: AppShell(controller: controller),
|
||||
));
|
||||
await tester.pump();
|
||||
|
||||
// 条形视图:导出菜单只有 SVG / PNG,不含 drawio;AI 生成可用。
|
||||
expect(tester.widget<FilledButton>(find.widgetWithText(FilledButton, 'AI 生成')).onPressed, isNotNull);
|
||||
await tester.tap(find.text('导出'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('导出 SVG'), findsOneWidget);
|
||||
expect(find.text('导出 PNG'), findsOneWidget);
|
||||
expect(find.text('导出 drawio'), findsNothing);
|
||||
await tester.tapAt(const Offset(5, 5));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// 流程图视图:导出菜单额外出现 drawio;AI 生成 / 撤销 / 重做置灰。
|
||||
controller.setViewMode(ViewMode.flow);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.widget<FilledButton>(find.widgetWithText(FilledButton, 'AI 生成')).onPressed, isNull);
|
||||
expect(
|
||||
tester.widget<IconButton>(find.widgetWithIcon(IconButton, Icons.undo)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
tester.widget<IconButton>(find.widgetWithIcon(IconButton, Icons.redo)).onPressed,
|
||||
isNull,
|
||||
);
|
||||
await tester.tap(find.text('导出'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('导出 drawio'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('switching views via toolbar auto-fits each view', (WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(1920, 1080);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final AppController controller = AppController(project: Project.demo());
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: buildTheme(Tokens.light),
|
||||
home: AppShell(controller: controller),
|
||||
));
|
||||
await tester.pump();
|
||||
|
||||
// 先把视图手动缩放 / 平移(模拟用户调过画面)。
|
||||
controller.setZoom(0.5);
|
||||
controller.panBy(const Offset(400, 300));
|
||||
await tester.pump();
|
||||
|
||||
// 经工具栏三段切换:每次切换后都应自动回到「适应窗口」状态
|
||||
//(与显式执行 fitView 的结果一致),而不是沿用上一个视图的缩放 / 平移。
|
||||
Future<void> expectFittedAfterSwitch(String label) async {
|
||||
await tester.tap(find.text(label).first);
|
||||
await tester.pump();
|
||||
final double z = controller.project.viewState.zoom;
|
||||
final double px = controller.project.viewState.panX;
|
||||
final double py = controller.project.viewState.panY;
|
||||
controller.fitView();
|
||||
expect(controller.project.viewState.zoom, closeTo(z, 0.0001), reason: '$label 切换后缩放应为适配值');
|
||||
expect(controller.project.viewState.panX, closeTo(px, 0.001), reason: '$label 切换后平移应为适配值');
|
||||
expect(controller.project.viewState.panY, closeTo(py, 0.001), reason: '$label 切换后平移应为适配值');
|
||||
}
|
||||
|
||||
await expectFittedAfterSwitch('圆周节拍');
|
||||
await expectFittedAfterSwitch('流程图');
|
||||
await expectFittedAfterSwitch('条形节拍');
|
||||
});
|
||||
|
||||
testWidgets('dependency line: drag to offset and double-click to reset', (WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(1920, 1080);
|
||||
tester.view.devicePixelRatio = 1.0;
|
||||
addTearDown(tester.view.reset);
|
||||
|
||||
final AppController controller = AppController(project: Project.demo());
|
||||
addTearDown(controller.dispose);
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
theme: buildTheme(Tokens.light),
|
||||
home: AppShell(controller: controller),
|
||||
));
|
||||
await tester.pump();
|
||||
|
||||
// 与画布同源计算 A1→A2 的走线,取线上一点(初始 zoom=1 / pan=0,
|
||||
// 屏幕坐标 = 画布左上角 + 逻辑坐标)。
|
||||
final Size vp = controller.viewport;
|
||||
final Offset canvasTopLeft = tester.getTopLeft(find.byType(CanvasView));
|
||||
|
||||
Offset screenMid() {
|
||||
final BarLayout layout = BarLayout(controller.project, vp);
|
||||
final BarDepRoute route = buildBarDepRoutes(controller.project, layout)
|
||||
.firstWhere((BarDepRoute r) => r.key == 'A1->A2');
|
||||
final Offset mid = Offset(
|
||||
(route.points.first.dx + route.points.last.dx) / 2,
|
||||
route.points.first.dy,
|
||||
);
|
||||
return canvasTopLeft + mid;
|
||||
}
|
||||
|
||||
// 拖拽:先移动 40px 触发手势验收,再移动 24px 产生实际位移,
|
||||
// 应写入 routeOffset。
|
||||
final TestGesture g = await tester.startGesture(screenMid());
|
||||
await tester.pump();
|
||||
await g.moveBy(const Offset(0, 40));
|
||||
await tester.pump();
|
||||
await g.moveBy(const Offset(0, 24));
|
||||
await tester.pump();
|
||||
await g.up();
|
||||
// 等待双击判定窗口结束,避免残留定时器影响测试结束。
|
||||
await tester.pump(const Duration(milliseconds: 400));
|
||||
Dependency dep = controller.project
|
||||
.actionById('A2')!
|
||||
.deps
|
||||
.firstWhere((Dependency d) => d.fromId == 'A1');
|
||||
expect(dep.routeOffset, greaterThan(0));
|
||||
|
||||
// 双击:复位偏移。
|
||||
final Offset pos = screenMid();
|
||||
await tester.tapAt(pos);
|
||||
await tester.pump(const Duration(milliseconds: 80));
|
||||
await tester.tapAt(pos);
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
dep = controller.project.actionById('A2')!.deps.firstWhere((Dependency d) => d.fromId == 'A1');
|
||||
expect(dep.routeOffset, 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// 开发自检工具:直接调用应用内更新服务,检查服务器上的最新版本。
|
||||
//
|
||||
// 用途:验证更新链路(网络可达 / 接口解析 / 版本判定 / 附件匹配)。
|
||||
// 运行:
|
||||
// dart run tool\check_update.dart # 用当前版本检查
|
||||
// dart run tool\check_update.dart 1.2.1 # 模拟旧版本,验证「发现更新」路径
|
||||
//
|
||||
// 说明:使用的是与客户端完全相同的 lib/update/update_service.dart;
|
||||
// 本文件是命令行工具,直接向控制台打印结果属预期用法。
|
||||
//
|
||||
// ignore_for_file: avoid_print
|
||||
import 'package:sequence_diagram/update/update_service.dart';
|
||||
import 'package:sequence_diagram/version.dart';
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
// 可传入一个版本号模拟旧安装(如 `dart run tool\check_update.dart 1.2.1`)。
|
||||
final String current = args.isNotEmpty ? args.first : kAppVersion;
|
||||
print('当前版本(模拟): $current');
|
||||
try {
|
||||
final UpdateInfo? info = await UpdateService.check(currentVersion: current);
|
||||
if (info == null) {
|
||||
print('结果: 已是最新版本(服务器无更高版本或缺少当前平台的安装包)');
|
||||
return;
|
||||
}
|
||||
print('结果: 发现新版本 v${info.version}');
|
||||
print('安装包: ${info.assetName} ${(info.assetSize / 1048576).toStringAsFixed(1)} MB');
|
||||
print('下载地址: ${info.assetUrl}');
|
||||
print('---- 更新说明 ----');
|
||||
print(info.notes.trim());
|
||||
} catch (e) {
|
||||
print('检查失败: $e');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user