feat(flow): 新增流程图视图(时序图自动生成);导出合并为菜单并支持 drawio;发布 v1.3.0

- 流程图视图:泳道 = 轨道、FS/SS 依赖连线、关键路径高亮、相位阶段栏
  (每个动作行归属覆盖占比最大的分区,重叠分区台阶错位)
- 无前置依赖的动作从「开始」并列引出(并行分支),无后继动作汇入「结束」
- 流程图只读:AI 生成 / 撤销重做 / 动作增删 / 属性与依赖编辑等入口自动置灰,
  左栏视图模式只保留条形 / 圆周(流程图入口在顶部工具栏)
- 导出升级:导出按钮合并为下拉菜单,SVG / PNG 三种视图通用;
  流程图额外支持 drawio(diagrams.net 可继续编辑泳道 / 相位 / 依赖)
- 连线走线统一收敛到 FlowLayout.routes,画布 / SVG / drawio 共用同一几何
- 默认示例升级为完整「装配线节拍」(8 动作 / 3 工位 / 4 相位分区)
- 版本号 1.3.0+16,更新说明 release/RELEASE_NOTES_v1.3.0.md
This commit is contained in:
2026-10-09 13:59:05 +08:00
parent fe2008b604
commit f4ef9b32a5
22 changed files with 1837 additions and 281 deletions
+305 -110
View File
@@ -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';
@@ -250,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。');
@@ -300,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。');
@@ -352,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');
}
}
// ===================== 主界面构建 =====================
/// 构建主界面:绑定全局快捷键,按“工具栏 / 中部(侧栏 + 画布) / 状态栏”
@@ -359,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()),
@@ -509,6 +569,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),
@@ -570,18 +631,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),
@@ -593,6 +655,8 @@ class _AppShellState extends State<AppShell> {
sideToggleRight,
_iconBtn(t, Icons.help_outline, () =>
showDialog<void>(context: context, builder: (_) => const HelpDialog()), tooltip: '帮助 F1'),
_iconBtn(t, Icons.account_tree_outlined, () => c.setViewMode(ViewMode.flow),
tooltip: '流程图(由时序图生成)'),
_updateBtn(t),
_themeToggle(t),
];
@@ -612,8 +676,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),
@@ -621,10 +688,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: '适应视图'),
@@ -633,6 +698,8 @@ class _AppShellState extends State<AppShell> {
sideToggleRight,
_iconBtn(t, Icons.help_outline, () =>
showDialog<void>(context: context, builder: (_) => const HelpDialog()), tooltip: '帮助 F1'),
_iconBtn(t, Icons.account_tree_outlined, () => c.setViewMode(ViewMode.flow),
tooltip: '流程图(由时序图生成)'),
_updateBtn(t),
_themeToggle(t),
];
@@ -654,17 +721,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(
@@ -691,8 +758,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)),
],
),
);
@@ -807,67 +875,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;
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: 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: FilledButton.icon(
onPressed: () => showDialog<void>(
context: context,
builder: (_) => AiGenerateDialog(controller: c),
),
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,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)),
padding: EdgeInsets.symmetric(horizontal: 10 * s, vertical: 8 * s),
minimumSize: Size(0, 34 * s),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
),
child: enabled ? btn : Tooltip(message: 'AI 生成仅针对时序图(条形 / 圆周视图)', child: btn),
);
}
@@ -1038,6 +1160,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(
@@ -1064,6 +1187,7 @@ class _AppShellState extends State<AppShell> {
t,
icon: Icons.edit_note,
label: '编辑时序与节拍参数',
enabled: !flow,
onTap: () => showDialog<void>(
context: context,
builder: (_) => SettingsDialog(controller: c),
@@ -1077,16 +1201,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!),
),
@@ -1103,18 +1228,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),
@@ -1123,11 +1250,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),
@@ -1151,9 +1280,16 @@ class _AppShellState extends State<AppShell> {
children: <Widget>[
Text('操作提示', style: TextStyle(color: t.warn, fontSize: 11, fontWeight: FontWeight.w700)),
const SizedBox(height: 6),
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)),
// 提示随视图模式切换:流程图是只读预览,给出交互方式说明。
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)),
],
],
),
),
@@ -1174,15 +1310,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),
@@ -1193,18 +1331,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),
],
@@ -1213,6 +1352,8 @@ class _AppShellState extends State<AppShell> {
),
),
);
if (enabled) return card;
return Tooltip(message: '流程图只读:修改请切回条形 / 圆周视图', child: card);
}
/// 动作列表小节标题右侧的紧凑按钮(新建 / 删除)。
@@ -1259,6 +1400,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);
@@ -1278,9 +1420,11 @@ class _AppShellState extends State<AppShell> {
toggle: HardwareKeyboard.instance.isControlPressed ||
HardwareKeyboard.instance.isShiftPressed,
),
// 双击泳道行直接编辑该泳道的主动作。
onDoubleTap: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)),
// 双击泳道行直接编辑该泳道的主动作(流程图只读时禁用)。
onDoubleTap: flow
? null
: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)),
borderRadius: BorderRadius.circular(10),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
@@ -1347,8 +1491,10 @@ class _AppShellState extends State<AppShell> {
),
const SizedBox(width: 6),
InkWell(
onTap: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)),
onTap: flow
? null
: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)),
borderRadius: BorderRadius.circular(7),
child: Container(
width: 28,
@@ -1358,7 +1504,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)),
),
),
],
@@ -1370,6 +1516,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(
@@ -1381,9 +1528,11 @@ class _AppShellState extends State<AppShell> {
toggle: HardwareKeyboard.instance.isControlPressed ||
HardwareKeyboard.instance.isShiftPressed,
),
// 双击动作行直接进入编辑。
onDoubleTap: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)),
// 双击动作行直接进入编辑(流程图只读时禁用)。
onDoubleTap: flow
? null
: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)),
borderRadius: BorderRadius.circular(10),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
@@ -1439,8 +1588,10 @@ class _AppShellState extends State<AppShell> {
),
const SizedBox(width: 6),
InkWell(
onTap: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)),
onTap: flow
? null
: () => showDialog<void>(
context: context, builder: (_) => ActionEditorDialog(controller: c, action: a)),
borderRadius: BorderRadius.circular(7),
child: Container(
width: 28,
@@ -1450,11 +1601,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),
@@ -1598,6 +1749,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(
@@ -1632,15 +1784,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),
_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)),
// 流程图只读:滑块仅展示数值,不可拖动。
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),
@@ -1650,11 +1836,13 @@ 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>(
context: context, builder: (_) => DependencyEditorDialog(controller: c, action: a)),
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)),
style: OutlinedButton.styleFrom(
@@ -1673,7 +1861,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),
],
@@ -1866,7 +2054,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),
@@ -1887,8 +2077,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),
),
],
),
@@ -1896,7 +2086,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),
@@ -1917,8 +2109,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),
),
],
),
@@ -1959,14 +2151,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,
+27 -15
View File
@@ -56,7 +56,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 +84,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, project: c.project)),
),
// 圆周视图左侧信息列:图例 + 选中卡片 + 依赖图例。
if (showPanels && showLeftColumn)
@@ -105,7 +107,8 @@ class CanvasOverlays extends StatelessWidget {
),
),
// 条形视图左下角:节拍统计 + 编辑工具。
if (showPanels && !circular && (showStats || showTools))
// (流程图只读,不显示编辑工具。)
if (showPanels && !circular && !flow && (showStats || showTools))
Positioned(
left: left,
bottom: 12,
@@ -122,7 +125,8 @@ class CanvasOverlays extends StatelessWidget {
),
),
// 右下角预览:圆周视图显示条形缩略,反之亦然;点击可切换视图。
if (showPanels && showPreview)
// 流程图是独立的载体,不显示时序视图的缩略预览。
if (showPanels && showPreview && !flow)
Positioned(
right: right,
bottom: 12,
@@ -174,29 +178,37 @@ 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, required this.project});
/// 主题令牌。
final Tokens t;
/// 是否处于圆周视图。
final bool circular;
/// 当前视图模式。
final ViewMode mode;
/// 当前项目,用于展示循环时长等文案。
final Project project;
@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 并行重叠)';
final String title = switch (mode) {
ViewMode.bar => '条形时序视图',
ViewMode.circular => '圆周时序视图',
ViewMode.flow => '流程图视图',
};
final String sub = switch (mode) {
ViewMode.bar => '箭头表示动作之间关联(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)',
ViewMode.circular =>
'同心圆环 = 动作层;箭头 = 执行顺序(绿色实线 FS 严格顺序,琥珀虚线 SS 并行重叠);1 圈 = 1 循环 = ${tfmt(project.cycle.durationMs, project.units)} = 360° = 100%',
// 流程图不重复时序视图的线型说明,仅保留标题。
ViewMode.flow => '',
};
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)),
if (sub.isNotEmpty) ...<Widget>[
const SizedBox(height: 4),
Text(sub, style: TextStyle(color: t.dim, fontSize: 11)),
],
],
);
}
+58 -25
View File
@@ -15,9 +15,11 @@ import 'package:flutter/material.dart' hide Action;
import 'package:flutter/services.dart';
import '../layout/layout.dart';
import '../layout/flow_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';
@@ -150,6 +152,8 @@ class _CanvasViewState extends State<CanvasView> {
/// 之外;精确指针(手写笔)直接点在把手上时,仅靠动作命中测试会落空,因此这里
/// 单独做一次把手邻近命中,半径与 [_grabRadius] 一致。
(Action, bool)? _hitHandle(Offset p, Size size) {
// 流程图只读:无端点把手。
if (c.project.viewState.mode == ViewMode.flow) return null;
Action? best;
bool bestStart = false;
double bestDist = _grabRadius;
@@ -316,14 +320,22 @@ class _CanvasViewState extends State<CanvasView> {
// ===================== 手势处理 =====================
/// 单击:命中最上层动作则选中,否则清空选中。
///
/// 流程图视图为只读:点击节点即选中对应动作(修改请回时序图)。
void _onTapDown(TapDownDetails d, Size size) {
final Offset p = _toLogical(d.localPosition, size);
// 端点把手优先命中:精确点在把手上时也选中该动作,避免误清空选中。
final (Action, bool)? handle = _hitHandle(p, size);
final Action? hit = handle?.$1 ??
(c.project.viewState.mode == ViewMode.bar
? BarLayout(c.project, size).hitTest(p, slop: _hitSlop)
: CircularLayout(c.project, size).hitTest(p, slop: _hitSlop));
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);
hit = handle?.$1 ??
(mode == ViewMode.bar
? BarLayout(c.project, size).hitTest(p, slop: _hitSlop)
: CircularLayout(c.project, size).hitTest(p, slop: _hitSlop));
}
// Ctrl(或 Shift)点击:切换该动作的选中状态,实现多选。
final bool toggle = HardwareKeyboard.instance.isControlPressed ||
HardwareKeyboard.instance.isShiftPressed;
@@ -333,6 +345,8 @@ class _CanvasViewState extends State<CanvasView> {
/// 双击空白处:按点击位置换算出的相位角新建动作;
/// 若双击在已有动作上则不处理。
void _onDoubleTapDown(TapDownDetails d, Size size) {
// 流程图只读:双击不新建动作、也不编辑。
if (c.project.viewState.mode == ViewMode.flow) return;
final Offset p = _toLogical(d.localPosition, size);
// 双击相位分区带:重命名该分区。
if (c.project.viewState.mode == ViewMode.bar) {
@@ -369,6 +383,12 @@ class _CanvasViewState extends State<CanvasView> {
/// - 桌面:进入画布平移模式;
/// - 触屏:不平移(单指只做选择 / 编辑,平移缩放交给双指)。
void _onPanStart(Offset p, Size size) {
// 流程图只读:不做时序编辑(空拖拽仍可按桌面习惯平移画布)。
if (c.project.viewState.mode == ViewMode.flow) {
_mode = _DragMode.none;
_dragAction = null;
return;
}
if (c.project.viewState.mode == ViewMode.bar) {
final BarLayout layout = BarLayout(c.project, size);
// 优先命中相位分区边界(位于图表顶部,不与动作条重叠)。
@@ -654,6 +674,11 @@ class _CanvasViewState extends State<CanvasView> {
/// 若右键落在相位分区带上,则弹出分区的增删改菜单。
Future<void> _contextMenu(Offset global, Size size) async {
final Offset local = _toLogical(global, size);
// 流程图只读:右键仅做选中联动。
if (c.project.viewState.mode == ViewMode.flow) {
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) {
@@ -791,25 +816,33 @@ class _CanvasViewState extends State<CanvasView> {
..setEntry(2, 2, c.project.viewState.zoom),
child: CustomPaint(
size: size,
painter: c.project.viewState.mode == ViewMode.bar
? BarPainter(
project: c.project,
tokens: t,
criticalActions: c.criticalActions,
criticalDeps: c.criticalDeps,
selectedIds: c.selectedIds.toSet(),
guideAngle: _zoneGuideAngle,
dropLane: _dropLane,
dropValid: _dropValid,
)
: CircularPainter(
project: c.project,
tokens: t,
criticalActions: c.criticalActions,
criticalDeps: c.criticalDeps,
selectedIds: c.selectedIds.toSet(),
guideAngle: _zoneGuideAngle,
),
painter: switch (c.project.viewState.mode) {
ViewMode.bar => BarPainter(
project: c.project,
tokens: t,
criticalActions: c.criticalActions,
criticalDeps: c.criticalDeps,
selectedIds: c.selectedIds.toSet(),
guideAngle: _zoneGuideAngle,
dropLane: _dropLane,
dropValid: _dropValid,
),
ViewMode.circular => CircularPainter(
project: c.project,
tokens: t,
criticalActions: c.criticalActions,
criticalDeps: c.criticalDeps,
selectedIds: c.selectedIds.toSet(),
guideAngle: _zoneGuideAngle,
),
ViewMode.flow => FlowchartPainter(
project: c.project,
tokens: t,
criticalActions: c.criticalActions,
criticalDeps: c.criticalDeps,
selectedIds: c.selectedIds.toSet(),
),
},
),
),
),
+1 -1
View File
@@ -2124,7 +2124,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.3(${android ? '安卓版' : 'Windows 版'})',
Text('V1.3.0(${android ? '安卓版' : 'Windows 版'})',
style: TextStyle(color: t.dim, fontSize: 12)),
],
),