Files
EasyDesignCollection/lib/export/export_fit.dart
T
admin fe5e0be131 feat(flow): 泳道拓宽计划(空泳道策略 + 多槽位泳道,三视图同步);发布 v1.3.4
- 空泳道策略(F2 文档设置 →「泳道」):动作全部移走的泳道可保留(默认,序号不变)
  或自动移除;条形空行 / 圆周空环 / 流程空列与左侧栏占位行同步
- 泳道加宽(1–5 槽):双击条形视图左侧泳道编号 / 右键空白泳道 / 左侧栏「N 槽」徽标;
  条形分子行(浅色虚线分隔)、圆周同色加宽环带 + 槽位虚线、流程图分子列且泳道带
  随内容智能加宽;拖拽动作同时换道 + 换槽位;旧数据零迁移(row 语义改为槽位并自动钳制)
- 流程图智能排开:同源同层扇出连线在空隙内均匀铺开;同层节点水平重叠自动推开
- 显示修复:画布左栏标题按真实行高排版(灰色副标题不再被换行标题压住,
  持续换行到泳道高度不足);多槽位采用「槽位紧凑 + 泳道间拉开」的间隔
- 「时序创建和编辑」更名为「文档设置」(含对话框标题/帮助/文档);新增自动保存
  (默认 10 分钟,可选 1/5/10/30 或关闭;写入文件并同步 .bak)
- 授权临时冻结(kLicenseRequired=false):桌面版导出无需 .lic;关于页授权状态
  「开放授权版本」、EDC 版权、开发者与交流群(邮箱 liuyu65@126.com、微信 online-goose)
- 更新体验:直接升级到最新版本提示、下载过程保持屏幕常亮提示、
  下载/上传统一限速 320KB/s(客户端限速 + 发布脚本 --limit-rate 320k)
- docs/HELP.md 与帮助中心同步更新;新增 docs/ROADMAP.md 开发路线图
- flutter analyze 0 问题、40 项测试全过;演示截图更新(含泳道加宽与拥挤场景验证图)
2026-10-10 09:21:45 +08:00

145 lines
5.2 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/// 导出适配:固定 1920×1080 画布下,把时序图内容缩放到内容区并居中,
/// 供 PNG 渲染器与 SVG 写入器共用,保证两种导出几何完全一致。
///
/// 约定:
/// - 画布固定 1920×1080;
/// - 标题固定在左上角(标题区 0–128px);
/// - 内容区 = (48, 128) → (1872, 1016),图例固定左下角;
/// - 内容按自身包围盒等比缩放并居中到内容区,不裁切、不溢出。
library;
import 'dart:math' as math;
import 'package:flutter/material.dart' hide Action;
import '../layout/layout.dart';
import '../layout/flow_layout.dart';
import '../model/models.dart';
import '../model/units.dart';
import '../render/bar_painter.dart';
import '../theme/tokens.dart';
/// 导出画布尺寸(固定,逻辑单位)。
const Size kExportSize = Size(1920, 1080);
/// 导出渲染像素比:按 2 倍像素渲染(3840×2160),保证高分辨率屏幕下清晰锐利。
const double kExportPixelRatio = 2.0;
/// 内容区(标题下方、图例上方)。
const Rect kExportContentArea = Rect.fromLTRB(48, 128, 1872, 1016);
/// 导出适配结果:内容变换 `scale` + `translate(tx, ty)`。
class ExportFit {
/// 构造适配结果。
const ExportFit(this.scale, this.tx, this.ty);
/// 缩放系数。
final double scale;
/// 水平平移。
final double tx;
/// 垂直平移。
final double ty;
/// SVG transform 属性值。
String get svgTransform =>
'translate(${tx.toStringAsFixed(1)} ${ty.toStringAsFixed(1)}) scale(${scale.toStringAsFixed(4)})';
}
/// 计算内容在 [area] 内的适配变换。
///
/// 先以 1920×1080 为参考画布求内容包围盒,再等比缩放并居中。
ExportFit computeExportFit(Project project, ViewMode mode, Rect area) {
Rect bounds;
if (mode == ViewMode.bar) {
final BarLayout l = BarLayout(project, kExportSize);
final int n = l.lanes.length;
final double bottom = n == 0 ? BarLayout.topPad + BarLayout.rowVisual : l.plotBottom + 8;
bounds = Rect.fromLTRB(12, BarPainter.phaseBandTop - 14, l.plotRight + 120, bottom);
} else if (mode == ViewMode.circular) {
final CircularLayout l = CircularLayout(project, kExportSize);
final double rExt = l.tickR + 100;
bounds = Rect.fromLTRB(l.center.dx - rExt, l.center.dy - rExt, l.center.dx + rExt, l.center.dy + rExt);
} else {
// 流程图:直接使用布局层给出的内容范围(含泳道、阶段栏与连线)。
final FlowLayout l = FlowLayout(project);
bounds = l.nodes.isEmpty ? const Rect.fromLTWH(0, 0, 800, 600) : l.bounds;
}
if (bounds.width <= 1 || bounds.height <= 1) {
return const ExportFit(1, 0, 0);
}
final double s = math.min(area.width / bounds.width, area.height / bounds.height).clamp(0.2, 1.6);
final double tx = area.left + (area.width - bounds.width * s) / 2 - bounds.left * s;
final double ty = area.top + (area.height - bounds.height * s) / 2 - bounds.top * s;
return ExportFit(s, tx, ty);
}
/// 导出标题(与画布浮层一致)。
String exportTitle(ViewMode mode) => switch (mode) {
ViewMode.bar => '条形时序视图',
ViewMode.circular => '圆周时序视图',
ViewMode.flow => '流程图视图',
};
/// 导出副标题:仅保留括号内的线型图例(与画布标题后方的说明一致)。
///
/// 更完整的视图语义(同心圆环 / 循环换算等)见应用内「帮助」。
String exportSubtitle(ViewMode mode) => switch (mode) {
ViewMode.bar => '(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)',
ViewMode.circular => '(绿色实线 FS 严格顺序 / 琥珀虚线 SS 并行重叠)',
// 流程图不重复线型说明,导出仅保留标题(与画布浮层一致)。
ViewMode.flow => '',
};
/// 导出图例(左下角固定)。
String exportLegend(Project project) =>
'时序图设计 · ${project.name} · 循环 ${tfmt(project.cycle.durationMs, project.units)} = 360°';
/// 导出专用令牌:始终使用浅色、**纯白背景**(印刷 / 工艺卡导向),
/// 文字、语义色与屏幕浅色主题保持一致。
///
/// 无论当前屏幕主题是深是浅,导出的 PNG / SVG 背景都是纯白、文字深色,
/// 避免「导出背景不是纯白」的问题。
Tokens exportTokens(Tokens base) {
return Tokens(
brightness: Brightness.light,
bg: Colors.white,
canvas1: Colors.white,
canvas2: Colors.white,
chrome: base.chrome,
panel: Colors.white,
panel2: Colors.white,
dialog: Colors.white,
line: base.line,
line2: base.line2,
text: base.text,
text2: base.text2,
sub: base.sub,
dim: base.dim,
accent: base.accent,
accent2: base.accent2,
ok: base.ok,
warn: base.warn,
danger: base.danger,
fs: base.fs,
ss: base.ss,
crit: base.crit,
chip: Colors.white,
dial: Colors.white,
arcText: base.arcText,
onAccent: base.onAccent,
ringA: base.ringA,
ringB: base.ringB,
ringEdge: base.ringEdge,
ringLabel: base.ringLabel,
info: Colors.white,
track: base.track,
sel: base.sel,
grid: base.grid,
shadow: base.shadow,
shadowOp: 0.10,
selOutline: base.selOutline,
overlay: base.overlay,
tailOp: base.tailOp,
);
}