0a3f2c5cc6
- 模块化:EdcModule 契约 + registry + 模块独立目录;发布包增加 modules/registry.json - 更名:PDS流程设计套件 / ProcessDesignSuite;同步构建、发布脚本与文档 - 时序图:依赖偏移以时间显示/编辑;紧贴依赖隐藏箭头并在接缝显示标签;动作条磁吸 - 圆周:依赖标签沿圆弧方向、环间空隙;动作旋转磁吸增强;短弧标签优先动作名 - 清理:release 移至源码同级(本地不入库);tool 合并到 tools;发布说明迁移 docs/release-notes
936 lines
34 KiB
Dart
936 lines
34 KiB
Dart
// 画布浮层:绘制在交互画布之上的固定信息面板,对应设计稿中的
|
||
// 标题、图例、统计、实时预览与编辑工具等元素。
|
||
//
|
||
// 架构位置:属于纯展示层,叠加在 CanvasView 之上,通过 AppController
|
||
// 读取项目数据;所有浮层均使用 IgnorePointer 或自身交互包裹,避免
|
||
// 遮挡画布手势。本文件通过 LayoutBuilder 依据窗口尺寸做响应式断点,
|
||
// 决定各面板是否显示。
|
||
import 'dart:math' as math;
|
||
|
||
import 'package:flutter/material.dart' hide Action;
|
||
|
||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||
import 'package:sequence_diagram/model/models.dart';
|
||
import 'package:sequence_diagram/model/units.dart';
|
||
import 'package:sequence_diagram/state/app_controller.dart';
|
||
import 'package:sequence_diagram/theme/tokens.dart';
|
||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||
|
||
/// 条形缩略预览的固定绘制区高度:卡片尺寸不随动作数量变化,
|
||
/// 动作越多只会在内部压缩行距、把色条画得更细。
|
||
const double _kMiniBarHeight = 84;
|
||
|
||
/// 画布浮层容器:按响应式断点组合并定位各信息面板。
|
||
class CanvasOverlays extends StatelessWidget {
|
||
/// 创建浮层容器,[controller] 为全局应用控制器。
|
||
///
|
||
/// [leftInset]/[rightInset]:侧栏收起后画布两侧的“把手”宽度,
|
||
/// 浮层据此内缩,避免被把手遮挡。
|
||
const CanvasOverlays({
|
||
super.key,
|
||
required this.controller,
|
||
this.leftInset = 0,
|
||
this.rightInset = 0,
|
||
this.showTitle = true,
|
||
this.showPanels = true,
|
||
});
|
||
|
||
/// 全局应用控制器,提供项目数据与编辑动作。
|
||
final AppController controller;
|
||
|
||
/// 左侧把手占用的宽度(0 表示无把手)。
|
||
final double leftInset;
|
||
|
||
/// 右侧把手占用的宽度(0 表示无把手)。
|
||
final double rightInset;
|
||
|
||
/// 是否显示顶部标题(导出 PNG 时把标题纳入导出边界)。
|
||
final bool showTitle;
|
||
|
||
/// 是否显示其余面板(图例 / 统计 / 工具 / 预览 / 浮动工具条)。
|
||
///
|
||
/// 这些属于**编辑辅助元素,不参与导出**。
|
||
final bool showPanels;
|
||
|
||
/// 控制器快捷访问器。
|
||
AppController get c => controller;
|
||
|
||
/// 使用 [LayoutBuilder] 获取可用尺寸,计算响应式断点后,
|
||
/// 通过 [Stack] + [Positioned] 摆放各浮层面板。
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final Tokens t = context.tok;
|
||
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;
|
||
final double h = constraints.maxHeight;
|
||
// ---- 响应式断点:不同尺寸下显示不同的浮层组合 ----
|
||
// 左右边距:在基础留白上叠加侧栏把手的宽度,避免被把手遮挡。
|
||
final double left = 18 + leftInset;
|
||
final double right = 18 + rightInset;
|
||
// 圆周视图左侧图例列:需要较宽较高的窗口。
|
||
final bool showLeftColumn = circular && w >= 1180 && h >= 760;
|
||
// 条形视图统计卡片:中等尺寸以上显示。
|
||
final bool showStats = !circular && w >= 820 && h >= 700;
|
||
// 编辑工具条:门槛最低,几乎始终显示。
|
||
final bool showTools = w >= 700;
|
||
// 预览卡片(已缩小):门槛放低,钉住侧栏后仍可见。
|
||
final bool showPreview = w >= 720 && h >= 560;
|
||
// 浮层整体使用 Stack 叠加,各面板按断点条件选择性插入。
|
||
return Stack(
|
||
children: <Widget>[
|
||
// 顶部标题与副标题,横跨整个画布宽度,不拦截手势。
|
||
if (showTitle)
|
||
Positioned(
|
||
left: left,
|
||
top: 12,
|
||
right: right,
|
||
child: IgnorePointer(child: _Title(t: t, mode: mode)),
|
||
),
|
||
// 圆周视图左侧信息列:图例 + 选中卡片 + 依赖图例。
|
||
if (showPanels && showLeftColumn)
|
||
Positioned(
|
||
left: left,
|
||
top: 70,
|
||
bottom: 12,
|
||
width: 268,
|
||
child: SingleChildScrollView(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: <Widget>[
|
||
IgnorePointer(child: _CircularLegend(t: t, project: c.project)),
|
||
const SizedBox(height: 12),
|
||
IgnorePointer(child: _SelectedCard(t: t, c: c, circular: true)),
|
||
const SizedBox(height: 12),
|
||
IgnorePointer(child: _DepTypeLegend(t: t)),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
// 条形视图左下角:节拍统计 + 编辑工具。
|
||
// (流程图只读,不显示编辑工具。)
|
||
if (showPanels && !circular && !flow && (showStats || showTools))
|
||
Positioned(
|
||
left: left,
|
||
bottom: 12,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: <Widget>[
|
||
if (showStats) ...<Widget>[
|
||
_StatsButton(t: t, c: c),
|
||
const SizedBox(height: 8),
|
||
],
|
||
_EditTools(t: t, c: c),
|
||
],
|
||
),
|
||
),
|
||
// 右下角预览:圆周视图显示条形缩略,反之亦然;点击可切换视图。
|
||
// 流程图是独立的载体,不显示时序视图的缩略预览。
|
||
if (showPanels && showPreview && !flow)
|
||
Positioned(
|
||
right: right,
|
||
bottom: 12,
|
||
child: circular
|
||
? _BarPreviewCard(t: t, c: c)
|
||
: _CircularPreviewCard(t: t, c: c),
|
||
),
|
||
// 圆周视图右上角浮动工具栏(与条形视图同一套工具与按钮尺寸)。
|
||
if (showPanels && circular)
|
||
Positioned(
|
||
right: right,
|
||
top: 70,
|
||
child: _EditTools(t: t, c: c, vertical: true),
|
||
),
|
||
],
|
||
);
|
||
},
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 通用卡片容器:统一浮层的背景、圆角与边框样式。
|
||
class _Card extends StatelessWidget {
|
||
const _Card({required this.t, required this.child, this.width, this.borderColor});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 卡片内容。
|
||
final Widget child;
|
||
/// 可选固定宽度。
|
||
final double? width;
|
||
/// 可选边框颜色,默认使用主题分隔线色。
|
||
final Color? borderColor;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Container(
|
||
width: width,
|
||
padding: const EdgeInsets.all(10),
|
||
decoration: BoxDecoration(
|
||
color: t.panel2.withValues(alpha: 0.96),
|
||
borderRadius: BorderRadius.circular(10),
|
||
border: Border.all(color: borderColor ?? t.line),
|
||
),
|
||
child: child,
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 顶部标题浮层:单行展示「视图名 +(线型图例)」。
|
||
///
|
||
/// 更完整的视图语义(同心圆环 / 循环换算 / 流程图读法)已收敛到「帮助」中,
|
||
/// 画布上只保留最精简的一句括号说明,节省纵向空间。
|
||
class _Title extends StatelessWidget {
|
||
const _Title({required this.t, required this.mode});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 当前视图模式。
|
||
final ViewMode mode;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
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,
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 圆周视图左侧图例:逐条列出动作的层号、相位区间与时长。
|
||
class _CircularLegend extends StatelessWidget {
|
||
const _CircularLegend({required this.t, required this.project});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 当前项目,用于枚举动作。
|
||
final Project project;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return _Card(
|
||
t: t,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Text('图层 / 相位图例', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
|
||
const SizedBox(height: 8),
|
||
for (int i = 0; i < project.actions.length; i++)
|
||
Padding(
|
||
padding: const EdgeInsets.only(bottom: 6),
|
||
child: Row(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Container(
|
||
width: 15,
|
||
height: 15,
|
||
margin: const EdgeInsets.only(top: 2),
|
||
decoration: BoxDecoration(
|
||
color: Color(project.actions[i].color),
|
||
borderRadius: BorderRadius.circular(5),
|
||
),
|
||
),
|
||
const SizedBox(width: 9),
|
||
Expanded(
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Text('${i + 1}. ${project.actions[i].id} ${project.actions[i].name}',
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(color: t.text2, fontSize: 11)),
|
||
Text(
|
||
'L${project.actions[i].layer + 1} · ${project.actions[i].startAngle.toStringAsFixed(0)}°–${math.min(project.actions[i].endAngle, 360).toStringAsFixed(0)}° · ${tfmt(project.actions[i].durationAngle / 360 * project.cycle.durationMs, project.units)}',
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(color: t.dim, fontSize: 10),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 选中动作信息卡:展示选中动作的起止/持续相位与所在层。
|
||
class _SelectedCard extends StatelessWidget {
|
||
const _SelectedCard({required this.t, required this.c, required this.circular});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 全局应用控制器。
|
||
final AppController c;
|
||
/// 是否处于圆周视图(用于文案微调)。
|
||
final bool circular;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final Action? a = c.selected;
|
||
if (a == null) {
|
||
return _Card(
|
||
t: t,
|
||
borderColor: t.accent,
|
||
child: Text('未选中动作\n点击画布或左侧列表选择', style: TextStyle(color: t.dim, fontSize: 11, height: 1.6)),
|
||
);
|
||
}
|
||
final UnitSettings u = c.project.units;
|
||
final double cycle = c.project.cycle.durationMs;
|
||
final Station? st = c.project.stationById(a.stationId);
|
||
final String delta = tfmt(a.durationAngle / 360 * cycle, u);
|
||
return _Card(
|
||
t: t,
|
||
borderColor: t.accent,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Text('选中动作', style: TextStyle(color: t.accent, fontSize: 10, fontWeight: FontWeight.w700, letterSpacing: 1)),
|
||
const SizedBox(height: 6),
|
||
Text('${a.id} ${a.name}', style: TextStyle(color: t.text, fontSize: 13, fontWeight: FontWeight.w700)),
|
||
const SizedBox(height: 8),
|
||
_kv(t, '起始相位', pfmt(a.startAngle, u)),
|
||
_kv(t, '结束相位', pfmt(a.endAngle, u)),
|
||
_kv(t, '持续相位', pfmt(a.durationAngle, u)),
|
||
const SizedBox(height: 4),
|
||
Text(
|
||
'Δ = $delta · 层 L${a.layer + 1}'
|
||
'${c.project.slotsOf(a.layer) > 1 ? ' · 槽 ${effectiveSlot(c.project, a) + 1}' : ''}'
|
||
' · ${st?.id ?? a.stationId}',
|
||
style: TextStyle(color: t.accent, fontSize: 11, fontWeight: FontWeight.w600)),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 渲染一行“标签 — 值”信息。
|
||
Widget _kv(Tokens t, String k, String v) => Padding(
|
||
padding: const EdgeInsets.only(bottom: 3),
|
||
child: Row(
|
||
children: <Widget>[
|
||
Text(k, style: TextStyle(color: t.sub, fontSize: 11)),
|
||
const Spacer(),
|
||
Flexible(
|
||
child: Text(v,
|
||
textAlign: TextAlign.right,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(color: t.text, fontSize: 11, fontWeight: FontWeight.w600)),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 依赖类型图例:说明 FS/SS 及关键路径的线条样式含义。
|
||
class _DepTypeLegend extends StatelessWidget {
|
||
const _DepTypeLegend({required this.t});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
Widget row(Widget sample, String label) => Padding(
|
||
padding: const EdgeInsets.only(bottom: 10),
|
||
child: Row(
|
||
children: <Widget>[
|
||
SizedBox(width: 48, child: sample),
|
||
const SizedBox(width: 8),
|
||
Expanded(child: Text(label, style: TextStyle(color: t.sub, fontSize: 10))),
|
||
],
|
||
),
|
||
);
|
||
return _Card(
|
||
t: t,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Text('执行顺序 / 依赖类型', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
|
||
const SizedBox(height: 10),
|
||
row(_SampleLine(color: t.fs, dash: false, arrow: true), 'FS 严格顺序(完成后启动)'),
|
||
row(_SampleLine(color: t.ss, dash: true, arrow: true), 'SS 并行重叠(可提前启动)'),
|
||
row(_SampleLine(color: t.fs, dash: false, arrow: false, glow: true), '关键路径(线条加粗光晕)'),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 图例中的示例线段:可组合实线/虚线、箭头与关键路径光晕。
|
||
class _SampleLine extends StatelessWidget {
|
||
const _SampleLine({required this.color, required this.dash, required this.arrow, this.glow = false});
|
||
|
||
/// 线条颜色。
|
||
final Color color;
|
||
/// 是否绘制为虚线。
|
||
final bool dash;
|
||
/// 是否绘制箭头。
|
||
final bool arrow;
|
||
/// 是否为关键路径样式(线条加粗光晕)。
|
||
final bool glow;
|
||
|
||
/// 用 [_SamplePainter] 绘制示例线段。
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return SizedBox(
|
||
height: 16,
|
||
child: CustomPaint(painter: _SamplePainter(color, dash, arrow, glow)),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 示例线段绘制器:按参数绘制实/虚线、箭头与关键路径光晕。
|
||
class _SamplePainter extends CustomPainter {
|
||
_SamplePainter(this.color, this.dash, this.arrow, this.glow);
|
||
|
||
/// 线条颜色。
|
||
final Color color;
|
||
/// 是否绘制为虚线。
|
||
final bool dash;
|
||
/// 是否绘制箭头。
|
||
final bool arrow;
|
||
/// 是否为关键路径样式(线条加粗光晕)。
|
||
final bool glow;
|
||
|
||
/// 绘制示例线段本体、箭头及可选光晕。
|
||
@override
|
||
void paint(Canvas canvas, Size size) {
|
||
final Paint p = Paint()
|
||
..color = color
|
||
..strokeWidth = 2.4
|
||
..strokeCap = StrokeCap.round;
|
||
final double y = size.height / 2;
|
||
// 关键路径:先铺一层加粗低透明度光晕,再画主线(与画布绘制一致)。
|
||
if (glow) {
|
||
canvas.drawLine(
|
||
Offset(0, y),
|
||
Offset(size.width - 10, y),
|
||
Paint()
|
||
..color = color.withValues(alpha: 0.2)
|
||
..strokeWidth = 7
|
||
..strokeCap = StrokeCap.round,
|
||
);
|
||
}
|
||
if (dash) {
|
||
for (double x = 0; x < size.width - 10; x += 8) {
|
||
canvas.drawLine(Offset(x, y), Offset(math.min(x + 4, size.width - 10), y), p);
|
||
}
|
||
} else {
|
||
canvas.drawLine(Offset(0, y), Offset(size.width - 10, y), p);
|
||
}
|
||
if (arrow) {
|
||
final Path a = Path()
|
||
..moveTo(size.width - 1, y)
|
||
..lineTo(size.width - 11, y - 4.5)
|
||
..lineTo(size.width - 11, y + 4.5)
|
||
..close();
|
||
canvas.drawPath(a, Paint()..color = color);
|
||
}
|
||
}
|
||
|
||
/// 示例线段始终重绘(开销极小)。
|
||
@override
|
||
bool shouldRepaint(covariant _SamplePainter old) => true;
|
||
}
|
||
|
||
/// 条形视图左下角的「节拍统计」按钮。
|
||
///
|
||
/// 统计内容改为**弹出窗口**展示(见 [_CycleStatsDialog]),
|
||
/// 避免固定面板长期遮挡画布。
|
||
class _StatsButton extends StatelessWidget {
|
||
const _StatsButton({required this.t, required this.c});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 全局应用控制器。
|
||
final AppController c;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return InkWell(
|
||
onTap: () => showDialog<void>(
|
||
context: context,
|
||
builder: (BuildContext ctx) => _CycleStatsDialog(t: t, c: c),
|
||
),
|
||
borderRadius: BorderRadius.circular(10),
|
||
child: Container(
|
||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 9),
|
||
decoration: BoxDecoration(
|
||
color: t.panel2.withValues(alpha: 0.96),
|
||
borderRadius: BorderRadius.circular(10),
|
||
border: Border.all(color: t.line2),
|
||
),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: <Widget>[
|
||
Icon(Icons.insights, size: 15, color: t.accent),
|
||
const SizedBox(width: 6),
|
||
Text('节拍统计', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 节拍统计弹窗:汇总循环周期、动作数、关键路径、并行度、
|
||
/// 相位覆盖率与瓶颈工位(仅展示可从当前项目数据推导的指标)。
|
||
class _CycleStatsDialog extends StatelessWidget {
|
||
const _CycleStatsDialog({required this.t, required this.c});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 全局应用控制器。
|
||
final AppController c;
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final Project p = c.project;
|
||
final UnitSettings u = p.units;
|
||
final List<Action> acts = p.actions;
|
||
final int stations = p.stations.length;
|
||
final List<List<String>> stats = <List<String>>[
|
||
<String>['循环周期', '${tfmt(p.cycle.durationMs, u)} / 360° / 100%'],
|
||
<String>['动作数量', '${acts.length}($stations 工位)'],
|
||
<String>['关键路径', _criticalChain()],
|
||
<String>['最大并行度', _maxParallel(acts)],
|
||
<String>['相位覆盖率', _coverage(acts)],
|
||
<String>['瓶颈工位', _bottleneck(p)],
|
||
];
|
||
return Dialog(
|
||
backgroundColor: t.dialog,
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||
child: SizedBox(
|
||
width: 460,
|
||
child: Padding(
|
||
padding: const EdgeInsets.fromLTRB(18, 16, 12, 14),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Row(
|
||
children: <Widget>[
|
||
Icon(Icons.insights, size: 18, color: t.accent),
|
||
const SizedBox(width: 8),
|
||
Text('节拍统计', style: TextStyle(color: t.text, fontSize: 14, fontWeight: FontWeight.w700)),
|
||
const Spacer(),
|
||
IconButton(
|
||
onPressed: () => Navigator.pop(context),
|
||
icon: Icon(Icons.close, size: 18, color: t.sub),
|
||
splashRadius: 16,
|
||
),
|
||
],
|
||
),
|
||
Divider(height: 14, color: t.line),
|
||
for (int i = 0; i < stats.length; i++) ...<Widget>[
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||
child: Row(
|
||
children: <Widget>[
|
||
Text(stats[i][0], style: TextStyle(color: t.dim, fontSize: 11)),
|
||
const Spacer(),
|
||
Flexible(
|
||
child: Text(stats[i][1],
|
||
textAlign: TextAlign.right,
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
style: TextStyle(color: t.text2, fontSize: 11, fontWeight: FontWeight.w600)),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
if (i < stats.length - 1) Divider(height: 1, color: t.line.withValues(alpha: 0.6)),
|
||
],
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 拼接关键路径上的动作 id 链。
|
||
String _criticalChain() {
|
||
final List<String> ids = <String>[];
|
||
for (final Action a in c.project.actions) {
|
||
if (c.criticalActions.contains(a.id)) ids.add(a.id);
|
||
}
|
||
if (ids.isEmpty) return '—';
|
||
return ids.join(' → ');
|
||
}
|
||
|
||
/// 扫描 0–360°,找出同时执行的动作数量峰值。
|
||
String _maxParallel(List<Action> acts) {
|
||
int best = 0;
|
||
double bestAt = 0;
|
||
for (int d = 0; d <= 360; d += 5) {
|
||
int n = 0;
|
||
for (final Action a in acts) {
|
||
if (d >= a.startAngle && d <= math.min(a.endAngle, 360)) n++;
|
||
}
|
||
if (n > best) {
|
||
best = n;
|
||
bestAt = d.toDouble();
|
||
}
|
||
}
|
||
return '$best 个动作同时执行(${bestAt.toStringAsFixed(0)}° 附近)';
|
||
}
|
||
|
||
/// 统计 0–360° 被动作覆盖的相位比例。
|
||
String _coverage(List<Action> acts) {
|
||
final List<bool> cover = List<bool>.filled(360, false);
|
||
for (final Action a in acts) {
|
||
for (int d = a.startAngle.floor(); d < math.min(a.endAngle, 360).ceil(); d++) {
|
||
if (d >= 0 && d < 360) cover[d] = true;
|
||
}
|
||
}
|
||
final int filled = cover.where((bool e) => e).length;
|
||
return '${(filled / 360 * 100).toStringAsFixed(0)}%(0°–360°)';
|
||
}
|
||
|
||
/// 找出累计相位占用最大的工位作为瓶颈。
|
||
String _bottleneck(Project p) {
|
||
final Map<String, double> load = <String, double>{};
|
||
for (final Action a in p.actions) {
|
||
load[a.stationId] = (load[a.stationId] ?? 0) + a.durationAngle;
|
||
}
|
||
String best = '—';
|
||
double bestV = -1;
|
||
for (final MapEntry<String, double> e in load.entries) {
|
||
if (e.value > bestV) {
|
||
bestV = e.value;
|
||
best = '${e.key} ${e.value.toStringAsFixed(0)}°';
|
||
}
|
||
}
|
||
return best;
|
||
}
|
||
}
|
||
|
||
/// 编辑工具栏(条形 / 圆周视图共用):
|
||
/// 添加 / 编辑 / 复制 / 删除 / 层+ / 层− / 对齐。
|
||
///
|
||
/// - [vertical] 为真时纵向排列(圆周视图右上角),否则横向排列(条形视图左下角);
|
||
/// - 按钮尺寸统一为原「编辑工具」条的 60%(约 40×34px),单手可点且尽量不遮挡画布。
|
||
class _EditTools extends StatelessWidget {
|
||
const _EditTools({required this.t, required this.c, this.vertical = false});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 全局应用控制器。
|
||
final AppController c;
|
||
/// 是否纵向排列(圆周视图用)。
|
||
final bool vertical;
|
||
|
||
/// 按钮宽度(像素)——原 66 的 60%。
|
||
static const double _bw = 40;
|
||
/// 按钮高度(像素)——原 56 的 60%。
|
||
static const double _bh = 34;
|
||
/// 按钮间距(像素)。
|
||
static const double _gap = 5;
|
||
|
||
/// 渲染工具栏;横向 ↔ 纵向由 [vertical] 决定。
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final List<Widget> buttons = <Widget>[
|
||
_tool(Icons.add, '添加', t.ok, t.onAccent, () => c.addAction(startAngle: 0)),
|
||
_tool(Icons.edit, '编辑', t.accent, t.onAccent, () {
|
||
final Action? a = c.selected;
|
||
if (a != null) showDialog<void>(context: context, builder: (_) => ActionEditorDialog(controller: c, action: a));
|
||
}),
|
||
_tool(Icons.copy, '复制', t.panel, t.sub, c.duplicateSelected, border: t.line2),
|
||
_tool(Icons.delete_outline, '删除', t.panel, t.sub,
|
||
() => c.selectedId != null ? c.deleteAction(c.selectedId!) : null, border: t.line2),
|
||
_tool(Icons.keyboard_arrow_up, '层+', t.panel, t.sub,
|
||
() => c.selectedId != null ? c.changeLayer(c.selectedId!, 1) : null, border: t.line2),
|
||
_tool(Icons.keyboard_arrow_down, '层−', t.panel, t.sub,
|
||
() => c.selectedId != null ? c.changeLayer(c.selectedId!, -1) : null, border: t.line2),
|
||
_tool(Icons.align_horizontal_left, '对齐', t.panel, t.sub, c.alignPhase, border: t.line2),
|
||
];
|
||
|
||
final List<Widget> spaced = <Widget>[];
|
||
for (int i = 0; i < buttons.length; i++) {
|
||
if (i > 0) {
|
||
spaced.add(SizedBox(width: vertical ? 0 : _gap, height: vertical ? _gap : 0));
|
||
}
|
||
spaced.add(buttons[i]);
|
||
}
|
||
|
||
return Container(
|
||
padding: const EdgeInsets.all(5),
|
||
decoration: BoxDecoration(
|
||
color: t.panel.withValues(alpha: 0.96),
|
||
borderRadius: BorderRadius.circular(vertical ? 12 : 10),
|
||
border: Border.all(color: t.line2),
|
||
),
|
||
child: vertical
|
||
? Column(mainAxisSize: MainAxisSize.min, children: spaced)
|
||
: Row(mainAxisSize: MainAxisSize.min, children: spaced),
|
||
);
|
||
}
|
||
|
||
/// 渲染单个工具按钮(图标 + 文字)。
|
||
Widget _tool(IconData icon, String label, Color bg, Color fg, VoidCallback onTap, {Color? border}) {
|
||
return InkWell(
|
||
onTap: onTap,
|
||
borderRadius: BorderRadius.circular(8),
|
||
child: Container(
|
||
width: _bw,
|
||
height: _bh,
|
||
decoration: BoxDecoration(
|
||
color: bg,
|
||
borderRadius: BorderRadius.circular(8),
|
||
border: Border.all(color: border ?? bg),
|
||
),
|
||
child: Column(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: <Widget>[
|
||
Icon(icon, size: 12, color: fg),
|
||
const SizedBox(height: 1),
|
||
Text(label,
|
||
style: TextStyle(color: fg, fontSize: 8.5, fontWeight: FontWeight.w600, height: 1.0)),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 条形节拍缩略预览卡(在圆周视图右下角显示);点击切换到条形视图。
|
||
class _BarPreviewCard extends StatelessWidget {
|
||
const _BarPreviewCard({required this.t, required this.c});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 全局应用控制器(用于切换视图)。
|
||
final AppController c;
|
||
|
||
/// 渲染紧凑的条形缩略预览,整卡可点击切换视图。
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final Project project = c.project;
|
||
return InkWell(
|
||
onTap: () => c.setViewMode(ViewMode.bar),
|
||
borderRadius: BorderRadius.circular(10),
|
||
child: _Card(
|
||
t: t,
|
||
width: 150,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Row(
|
||
children: <Widget>[
|
||
Icon(Icons.bar_chart, size: 13, color: t.accent),
|
||
const SizedBox(width: 5),
|
||
Text('条形预览', style: TextStyle(color: t.sub, fontSize: 10.5, fontWeight: FontWeight.w600)),
|
||
const Spacer(),
|
||
Icon(Icons.chevron_right, size: 14, color: t.dim),
|
||
],
|
||
),
|
||
const SizedBox(height: 6),
|
||
// 预览区固定高度(与动作数量无关):动作再多也不会撑大预览卡,
|
||
// 只会在内部压缩行距 / 缩小线条(见 _MiniBarPainter)。
|
||
SizedBox(
|
||
width: double.infinity,
|
||
height: _kMiniBarHeight,
|
||
child: CustomPaint(
|
||
size: Size.infinite,
|
||
painter: _MiniBarPainter(project, t),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 条形缩略预览绘制器:按相位比例绘制各动作的横向色条。
|
||
class _MiniBarPainter extends CustomPainter {
|
||
_MiniBarPainter(this.project, this.t);
|
||
|
||
/// 当前项目。
|
||
final Project project;
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
|
||
/// 逐行绘制动作色条、跨圈尾段与底部刻度。
|
||
@override
|
||
void paint(Canvas canvas, Size size) {
|
||
final int n = project.actions.length;
|
||
final double w = size.width - 4;
|
||
// 行高按可用高度自适应,保证小预览里也排得下。
|
||
final double pitch = n == 0 ? 12 : math.min(12, (size.height - 16) / n);
|
||
// 缩略图里的动作条是一条细线(约 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 + (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),
|
||
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), Radius.circular(rh / 2)),
|
||
Paint()..color = Color(a.color).withValues(alpha: t.tailOp),
|
||
);
|
||
}
|
||
}
|
||
final double baseY = n * pitch + 3;
|
||
canvas.drawLine(Offset(2, baseY), Offset(size.width - 2, baseY), Paint()..color = t.line2..strokeWidth = 1);
|
||
final TextPainter tp = TextPainter(
|
||
text: TextSpan(text: '0.0 ${timeUnitLabel(project.units.timeUnit)}', style: TextStyle(color: t.dim, fontSize: 9)),
|
||
textDirection: TextDirection.ltr,
|
||
)..layout();
|
||
tp.paint(canvas, Offset(2, baseY + 2));
|
||
final TextPainter tp2 = TextPainter(
|
||
text: TextSpan(text: tfmt(project.cycle.durationMs, project.units), style: TextStyle(color: t.dim, fontSize: 9)),
|
||
textDirection: TextDirection.ltr,
|
||
)..layout();
|
||
tp2.paint(canvas, Offset(size.width - 2 - tp2.width, baseY + 2));
|
||
}
|
||
|
||
/// 预览始终重绘(数据实时联动)。
|
||
@override
|
||
bool shouldRepaint(covariant _MiniBarPainter old) => true;
|
||
}
|
||
|
||
/// 圆周节拍缩略预览卡(在条形视图右下角显示);点击切换到圆周视图。
|
||
class _CircularPreviewCard extends StatelessWidget {
|
||
const _CircularPreviewCard({required this.t, required this.c});
|
||
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
/// 全局应用控制器(用于切换视图)。
|
||
final AppController c;
|
||
|
||
/// 渲染紧凑的圆周缩略预览,整卡可点击切换视图。
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final Project project = c.project;
|
||
return InkWell(
|
||
onTap: () => c.setViewMode(ViewMode.circular),
|
||
borderRadius: BorderRadius.circular(10),
|
||
child: _Card(
|
||
t: t,
|
||
width: 150,
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Row(
|
||
children: <Widget>[
|
||
Icon(Icons.donut_large, size: 13, color: t.accent),
|
||
const SizedBox(width: 5),
|
||
Text('圆周预览', style: TextStyle(color: t.sub, fontSize: 10.5, fontWeight: FontWeight.w600)),
|
||
const Spacer(),
|
||
Icon(Icons.chevron_right, size: 14, color: t.dim),
|
||
],
|
||
),
|
||
const SizedBox(height: 6),
|
||
SizedBox(
|
||
width: double.infinity,
|
||
height: 112,
|
||
child: CustomPaint(
|
||
size: Size.infinite,
|
||
painter: _MiniCircularPainter(project, t),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
/// 圆周缩略预览绘制器:每层一环,绘制同心圆与动作圆弧。
|
||
class _MiniCircularPainter extends CustomPainter {
|
||
_MiniCircularPainter(this.project, this.t);
|
||
|
||
/// 当前项目。
|
||
final Project project;
|
||
/// 主题令牌。
|
||
final Tokens t;
|
||
|
||
/// 绘制同心圆环、各动作圆弧、12 点钟箭头与“360°”标注。
|
||
@override
|
||
void paint(Canvas canvas, Size size) {
|
||
final Offset c = Offset(size.width / 2, size.height / 2);
|
||
final int n = project.actions.length;
|
||
// 自适应半径:把圆环铺满预览框(顶部为方向箭头预留约 26px)。
|
||
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 = 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];
|
||
final double r = r0 + i * pitch;
|
||
canvas.drawCircle(
|
||
c,
|
||
r,
|
||
Paint()
|
||
..style = PaintingStyle.stroke
|
||
..strokeWidth = pw
|
||
..color = i.isEven ? t.ringA : t.ringB,
|
||
);
|
||
for (final List<double> s in splitArcs(a.startAngle, a.endAngle)) {
|
||
canvas.drawPath(
|
||
arcPath(c, r, s[0], s[1]),
|
||
Paint()
|
||
..style = PaintingStyle.stroke
|
||
..strokeWidth = pw
|
||
..strokeCap = a.wrap ? StrokeCap.butt : StrokeCap.round
|
||
..color = Color(a.color).withValues(alpha: 0.95),
|
||
);
|
||
}
|
||
}
|
||
final double tip = r0 + (n - 1) * pitch + pw / 2;
|
||
final Path arrow = Path()
|
||
..moveTo(c.dx, c.dy - tip - 6)
|
||
..lineTo(c.dx - 7, c.dy - tip - 18)
|
||
..lineTo(c.dx + 7, c.dy - tip - 18)
|
||
..close();
|
||
canvas.drawPath(arrow, Paint()..color = t.accent);
|
||
final TextPainter tp = TextPainter(
|
||
text: TextSpan(text: '360°', style: TextStyle(color: t.sub, fontSize: 11, fontWeight: FontWeight.w600)),
|
||
textDirection: TextDirection.ltr,
|
||
)..layout();
|
||
tp.paint(canvas, Offset(c.dx - tp.width / 2, c.dy - 8));
|
||
}
|
||
|
||
/// 预览始终重绘(数据实时联动)。
|
||
@override
|
||
bool shouldRepaint(covariant _MiniCircularPainter old) => true;
|
||
}
|