v1.3.13: 模块化注册架构 + PDS流程设计套件更名 + 依赖/圆周交互修复
- 模块化:EdcModule 契约 + registry + 模块独立目录;发布包增加 modules/registry.json - 更名:PDS流程设计套件 / ProcessDesignSuite;同步构建、发布脚本与文档 - 时序图:依赖偏移以时间显示/编辑;紧贴依赖隐藏箭头并在接缝显示标签;动作条磁吸 - 圆周:依赖标签沿圆弧方向、环间空隙;动作旋转磁吸增强;短弧标签优先动作名 - 清理:release 移至源码同级(本地不入库);tool 合并到 tools;发布说明迁移 docs/release-notes
This commit is contained in:
@@ -0,0 +1,459 @@
|
||||
/// AI 生成时序图对话框。
|
||||
///
|
||||
/// 交互流程:填写 DeepSeek API Key → 选择模型(Flash / Pro)、推理强度
|
||||
/// (高 / 最高)与生成方式(新建工程 / 在当前工程上修改)→ 在较大的自然语言
|
||||
/// 输入框中描述工艺流程或修改要求 → 点击「生成」。
|
||||
///
|
||||
/// 生成过程为**流式**:实时显示已用时、思考与输出字符数,可随时取消;
|
||||
/// 输出无法解析时自动让模型修复重试(最多两次)。
|
||||
///
|
||||
/// 安全:API Key 仅保存在内存(静态字段,便于本次会话内复用),
|
||||
/// 不写入工程文件,也不会被日志输出。
|
||||
library;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/modules/sequence/ai/ai_client.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||||
|
||||
class AiGenerateDialog extends StatefulWidget {
|
||||
const AiGenerateDialog({super.key, required this.controller});
|
||||
|
||||
/// 全局应用控制器。
|
||||
final AppController controller;
|
||||
|
||||
@override
|
||||
State<AiGenerateDialog> createState() => _AiGenerateDialogState();
|
||||
}
|
||||
|
||||
class _AiGenerateDialogState extends State<AiGenerateDialog> {
|
||||
/// 会话内复用的 API Key(不持久化)。
|
||||
static String _sessionKey = '';
|
||||
|
||||
/// 示例描述:与输入框灰色占位一致,可一键填入后直接编辑。
|
||||
static const String _examplePrompt =
|
||||
'一条装配线,循环 2.4 秒。上料后定位夹紧,夹紧完成再伺服下压 0.6 秒;'
|
||||
'下压完成后并行进行超声波焊接与视觉检测;检测完成分选下料,最后清洁吹气。'
|
||||
'共 3 个工位,请给出动作、相位与依赖关系。';
|
||||
|
||||
late final TextEditingController _key;
|
||||
late final TextEditingController _prompt;
|
||||
|
||||
String _model = kAiModels.first.id;
|
||||
String _effort = 'high';
|
||||
bool _obscure = true;
|
||||
bool _busy = false;
|
||||
String? _error;
|
||||
|
||||
/// 生成方式:`new` = 新建工程(整图生成);`modify` = 在当前工程上修改。
|
||||
String _mode = 'new';
|
||||
|
||||
/// 当前生成用的取消令牌(每次生成重建)。
|
||||
AiCancelToken? _token;
|
||||
/// 生成计时器(每秒刷新已用时)。
|
||||
Timer? _ticker;
|
||||
/// 已用时(秒)。
|
||||
int _secs = 0;
|
||||
/// 已接收的思考字符数(推理模型)。
|
||||
int _thinkChars = 0;
|
||||
/// 已接收的 JSON 输出字符数。
|
||||
int _outChars = 0;
|
||||
/// 当前第几次尝试(>0 表示正在自动修复上一次的输出)。
|
||||
int _attempt = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_key = TextEditingController(text: _sessionKey);
|
||||
_prompt = TextEditingController();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ticker?.cancel();
|
||||
_key.dispose();
|
||||
_prompt.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _generate() async {
|
||||
final AiCancelToken token = AiCancelToken();
|
||||
setState(() {
|
||||
_busy = true;
|
||||
_error = null;
|
||||
_secs = 0;
|
||||
_thinkChars = 0;
|
||||
_outChars = 0;
|
||||
_attempt = 0;
|
||||
_token = token;
|
||||
});
|
||||
_ticker = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (mounted) setState(() => _secs++);
|
||||
});
|
||||
try {
|
||||
_sessionKey = _key.text.trim();
|
||||
final AiResult r = await AiClient.generate(
|
||||
prompt: _prompt.text,
|
||||
settings: AiSettings(apiKey: _sessionKey, model: _model, effort: _effort),
|
||||
base: _mode == 'modify' ? widget.controller.project : null,
|
||||
cancelToken: token,
|
||||
onProgress: (AiProgress p) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_thinkChars = p.reasoningChars;
|
||||
_outChars = p.contentChars;
|
||||
_attempt = p.attempt;
|
||||
});
|
||||
},
|
||||
);
|
||||
widget.controller.loadProject(r.project, dirty: true);
|
||||
final String extra = r.warnings.isEmpty ? '' : '(${r.warnings.join('、')})';
|
||||
widget.controller
|
||||
.setStatus('AI 已生成时序图(${r.project.actions.length} 个动作)$extra');
|
||||
if (mounted) Navigator.pop(context);
|
||||
} catch (e) {
|
||||
if (mounted) setState(() => _error = '$e');
|
||||
} finally {
|
||||
_ticker?.cancel();
|
||||
_ticker = null;
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
/// 取消正在进行的生成(中断 HTTP 请求)。
|
||||
void _cancel() {
|
||||
_token?.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
return Dialog(
|
||||
backgroundColor: t.dialog,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
child: scaledDialogBox(
|
||||
context,
|
||||
880,
|
||||
620,
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
// 标题
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.auto_awesome, size: 21, color: t.accent2),
|
||||
const SizedBox(width: 8),
|
||||
Text('AI 生成时序图', style: TextStyle(color: t.text, fontSize: 17, fontWeight: FontWeight.w700)),
|
||||
const Spacer(),
|
||||
Text('自然语言 → 时序图', style: TextStyle(color: t.dim, fontSize: 11.5)),
|
||||
],
|
||||
),
|
||||
const Divider(height: 22),
|
||||
|
||||
// API Key
|
||||
Text('DeepSeek API Key', style: TextStyle(color: t.sub, fontSize: 12.5)),
|
||||
const SizedBox(height: 6),
|
||||
TextField(
|
||||
controller: _key,
|
||||
obscureText: _obscure,
|
||||
style: TextStyle(color: t.text, fontSize: 12.5),
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
hintText: 'sk-...',
|
||||
hintStyle: TextStyle(color: t.dim, fontSize: 12.5),
|
||||
filled: true,
|
||||
fillColor: t.panel2,
|
||||
prefixIcon: Icon(Icons.key, size: 16, color: t.dim),
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () => setState(() => _obscure = !_obscure),
|
||||
icon: Icon(_obscure ? Icons.visibility_off : Icons.visibility, size: 16, color: t.dim),
|
||||
tooltip: _obscure ? '显示' : '隐藏',
|
||||
),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// 模型 + 推理强度
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('模型', style: TextStyle(color: t.sub, fontSize: 12.5)),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
height: 38,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: DropdownButton<String>(
|
||||
value: _model,
|
||||
isExpanded: true,
|
||||
underline: const SizedBox.shrink(),
|
||||
dropdownColor: t.dialog,
|
||||
style: TextStyle(color: t.text, fontSize: 12.5),
|
||||
icon: Icon(Icons.keyboard_arrow_down, size: 18, color: t.sub),
|
||||
items: kAiModels
|
||||
.map((AiModelOption m) =>
|
||||
DropdownMenuItem<String>(value: m.id, child: Text(m.label)))
|
||||
.toList(),
|
||||
onChanged: (String? v) {
|
||||
if (v != null) setState(() => _model = v);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('推理强度', style: TextStyle(color: t.sub, fontSize: 12.5)),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(child: _effortChip(t, '高', 'high')),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: _effortChip(t, '最高', 'max')),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// 生成方式:新建整图 / 在当前工程上修改(增量)。
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text('生成方式', style: TextStyle(color: t.sub, fontSize: 12.5)),
|
||||
const SizedBox(width: 12),
|
||||
SizedBox(width: 106, child: _modeChip(t, '新建工程', 'new')),
|
||||
const SizedBox(width: 8),
|
||||
SizedBox(width: 128, child: _modeChip(t, '修改当前工程', 'modify')),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_mode == 'modify'
|
||||
? '在现有工程上增删改,未涉及部分保持不变'
|
||||
: '重新生成整张时序图(替换当前工程)',
|
||||
style: TextStyle(color: t.dim, fontSize: 11),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// 自然语言输入(大输入框)
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text('用自然语言描述工艺流程', style: TextStyle(color: t.sub, fontSize: 12.5)),
|
||||
const Spacer(),
|
||||
// 一键把灰色示例填入输入框,便于直接修改后生成。
|
||||
TextButton.icon(
|
||||
onPressed: _busy
|
||||
? null
|
||||
: () => setState(() => _prompt.text = _examplePrompt),
|
||||
icon: const Icon(Icons.edit_note, size: 17),
|
||||
label: const Text('编辑示例', style: TextStyle(fontSize: 12)),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: t.accent,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
minimumSize: const Size(0, 28),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel2,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
child: TextField(
|
||||
controller: _prompt,
|
||||
maxLines: null,
|
||||
expands: true,
|
||||
textAlignVertical: TextAlignVertical.top,
|
||||
style: TextStyle(color: t.text, fontSize: 12.5, height: 1.6),
|
||||
decoration: InputDecoration.collapsed(
|
||||
hintText: '例如:$_examplePrompt',
|
||||
hintStyle: TextStyle(color: t.dim, fontSize: 12.5, height: 1.6),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_error != null) ...<Widget>[
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: _error == '已取消' ? t.panel2 : t.danger.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: _error == '已取消' ? t.line2 : t.danger.withValues(alpha: 0.5)),
|
||||
),
|
||||
child: Text(_error!,
|
||||
style: TextStyle(
|
||||
color: _error == '已取消' ? t.sub : t.danger,
|
||||
fontSize: 12,
|
||||
height: 1.5)),
|
||||
),
|
||||
],
|
||||
if (_busy) ...<Widget>[
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
SizedBox(
|
||||
width: 13,
|
||||
height: 13,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: t.accent),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_attempt > 0
|
||||
? '格式有误,正在自动修复(第 ${_attempt + 1} 次尝试)· 已用时 $_secs 秒'
|
||||
: '生成中… 已用时 $_secs 秒',
|
||||
style: TextStyle(color: t.sub, fontSize: 12),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
_thinkChars > 0 || _outChars > 0
|
||||
? '思考 $_thinkChars 字 · 输出 $_outChars 字'
|
||||
: '等待模型响应…',
|
||||
style: TextStyle(color: t.dim, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
child: LinearProgressIndicator(
|
||||
minHeight: 4,
|
||||
color: t.accent2,
|
||||
backgroundColor: t.line2,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// 操作按钮:生成 ↔ 取消生成(流式过程中可随时中断)。
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Text(
|
||||
'API Key 仅保存在本机内存,不写入工程文件。',
|
||||
style: TextStyle(color: t.dim, fontSize: 11),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (_busy) _cancel();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('取消'),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
_busy
|
||||
? FilledButton.icon(
|
||||
onPressed: _cancel,
|
||||
icon: const Icon(Icons.stop_circle_outlined, size: 16),
|
||||
label: const Text('取消生成'),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: t.danger,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
|
||||
),
|
||||
)
|
||||
: FilledButton.icon(
|
||||
onPressed: _generate,
|
||||
icon: const Icon(Icons.auto_awesome, size: 16),
|
||||
label: const Text('生成'),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: t.accent2,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(9)),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 推理强度分段按钮。
|
||||
Widget _effortChip(Tokens t, String label, String value) {
|
||||
final bool active = _effort == value;
|
||||
return InkWell(
|
||||
onTap: () => setState(() => _effort = value),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
height: 38,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: active ? t.accent.withValues(alpha: 0.18) : t.panel2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: active ? t.accent : t.line2),
|
||||
),
|
||||
child: Text(label, style: TextStyle(color: active ? t.accent : t.sub, fontSize: 12.5)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 生成方式分段按钮(新建工程 / 修改当前工程);生成中不可切换。
|
||||
Widget _modeChip(Tokens t, String label, String value) {
|
||||
final bool active = _mode == value;
|
||||
return InkWell(
|
||||
onTap: _busy ? null : () => setState(() => _mode = value),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
height: 34,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: active ? t.accent.withValues(alpha: 0.18) : t.panel2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: active ? t.accent : t.line2),
|
||||
),
|
||||
child: Text(label, style: TextStyle(color: active ? t.accent : t.sub, fontSize: 12)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,935 @@
|
||||
// 画布浮层:绘制在交互画布之上的固定信息面板,对应设计稿中的
|
||||
// 标题、图例、统计、实时预览与编辑工具等元素。
|
||||
//
|
||||
// 架构位置:属于纯展示层,叠加在 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;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user