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 项测试全过;演示截图更新(含泳道加宽与拥挤场景验证图)
This commit is contained in:
@@ -53,7 +53,7 @@ ExportFit computeExportFit(Project project, ViewMode mode, Rect area) {
|
||||
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.yFor(n) + BarLayout.rowVisual + 8;
|
||||
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);
|
||||
|
||||
@@ -158,7 +158,7 @@ class SvgWriter {
|
||||
_b.write('<g id="labels">');
|
||||
for (int i = 0; i < ordered.length; i++) {
|
||||
final Action a = ordered[i];
|
||||
final double y = layout.yFor(i);
|
||||
final double y = layout.yForSlot(a.layer, layout.slotOf(a));
|
||||
_text(BarLayout.leftGutter + 6, y + 8, '${a.id} ${a.name}', color: _hex(tokens.text), size: 13, weight: '600');
|
||||
_text(BarLayout.leftGutter + 6, y + 24, '${a.stationId} · ${a.driver}', color: _hex(tokens.dim), size: 10.5);
|
||||
}
|
||||
|
||||
@@ -314,8 +314,8 @@ List<ArcDepRoute> buildArcDepRoutes(Project project, CircularLayout layout) {
|
||||
final Action? a = project.actionById(d.fromId);
|
||||
final Action? b = project.actionById(d.toId);
|
||||
if (a == null || b == null) continue;
|
||||
final double rA = layout.radiusFor(a.layer);
|
||||
final double rB = layout.radiusFor(b.layer);
|
||||
final double rA = layout.radiusFor(a.layer, layout.slotOf(a));
|
||||
final double rB = layout.radiusFor(b.layer, layout.slotOf(b));
|
||||
final double aEnd = math.min(a.endAngle, 360);
|
||||
final double aStart = b.startAngle;
|
||||
// 层差大于 1 时从最外圈绕行,避免穿过中间层弧线。
|
||||
|
||||
+143
-10
@@ -180,6 +180,40 @@ class FlowLayout {
|
||||
/// 内容范围(所有节点矩形并集再外扩,供适应视图使用)。
|
||||
Rect bounds = Rect.zero;
|
||||
|
||||
/// 泳道内两个槽位之间的横向间距(留出依赖连线的走线空间)。
|
||||
static const double slotGap = 26;
|
||||
|
||||
/// 各泳道左边缘 x(放置完成后按内容自适应填充)。
|
||||
final List<double> laneStarts = <double>[];
|
||||
|
||||
/// 各泳道宽度(基础 = 槽位数,放置后按内容自动加宽)。
|
||||
final List<double> laneWidths = <double>[];
|
||||
|
||||
/// 第 [li] 条泳道的宽度(优先取内容自适应结果;未计算时按槽位数)。
|
||||
double laneWidth(int li) {
|
||||
if (li >= 0 && li < laneWidths.length) return laneWidths[li];
|
||||
if (li < 0 || li >= lanes.length) return nodeW;
|
||||
final int s = project.slotsOf(lanes[li]);
|
||||
return s * nodeW + (s - 1) * slotGap;
|
||||
}
|
||||
|
||||
/// 第 [li] 条泳道左边缘 x(优先取内容自适应结果,其次按槽位宽度累加)。
|
||||
double laneStartX(int li) {
|
||||
if (li >= 0 && li < laneStarts.length) return laneStarts[li];
|
||||
double x = marginX;
|
||||
for (int i = 0; i < li && i < lanes.length; i++) {
|
||||
x += laneWidth(i) + laneGap;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
/// 第 [li] 条泳道第 [slot] 列的节点中心 x(槽位钳制到有效范围)。
|
||||
double slotCenterX(int li, int slot) {
|
||||
final int s = (li >= 0 && li < lanes.length) ? project.slotsOf(lanes[li]) : 1;
|
||||
final int k = slot < 0 ? 0 : (slot >= s ? s - 1 : slot);
|
||||
return laneStartX(li) + k * (nodeW + slotGap) + nodeW / 2;
|
||||
}
|
||||
|
||||
/// 按 id 查找节点。
|
||||
FlowNode? nodeById(String id) {
|
||||
for (final FlowNode n in nodes) {
|
||||
@@ -198,7 +232,7 @@ class FlowLayout {
|
||||
|
||||
/// 构建节点、连线并完成布局。
|
||||
void _build() {
|
||||
lanes = (<int>{for (final Action a in project.actions) a.layer}.toList())..sort();
|
||||
lanes = project.renderLanes;
|
||||
final Map<String, FlowNode> byId = <String, FlowNode>{};
|
||||
|
||||
// 1) 动作节点(序号与条形视图一致:项目动作列表顺序 + 1)。
|
||||
@@ -290,7 +324,18 @@ class FlowLayout {
|
||||
cellTotal[key] = (cellTotal[key] ?? 0) + 1;
|
||||
}
|
||||
final Map<String, int> cellSeen = <String, int>{};
|
||||
final double lanePitch = nodeW + laneGap;
|
||||
// 泳道基础几何:宽度按槽位数,左边缘按前一泳道宽度累加。
|
||||
laneStarts.clear();
|
||||
laneWidths.clear();
|
||||
{
|
||||
double x = marginX;
|
||||
for (int i = 0; i < lanes.length; i++) {
|
||||
final int s = project.slotsOf(lanes[i]);
|
||||
laneStarts.add(x);
|
||||
laneWidths.add(s * nodeW + (s - 1) * slotGap);
|
||||
x += laneWidths.last + laneGap;
|
||||
}
|
||||
}
|
||||
for (final FlowNode n in nodes) {
|
||||
final int li = laneIndex[n.lane] ?? 0;
|
||||
final String key = '${n.lane}:${n.rank}';
|
||||
@@ -299,15 +344,91 @@ class FlowLayout {
|
||||
cellSeen[key] = idx + 1;
|
||||
final double w = (n.isStart || n.isEnd) ? capW : nodeW;
|
||||
final double h = (n.isStart || n.isEnd) ? capH : nodeH;
|
||||
final double centerX = marginX + li * lanePitch + nodeW / 2 +
|
||||
(idx - (total - 1) / 2) * (nodeW * 0.62);
|
||||
// 开始 / 结束节点居中于泳道带;动作节点按(泳道, 槽位)分列,
|
||||
// 同格多节点再沿横向错开。
|
||||
final double centerX;
|
||||
if (n.isStart || n.isEnd) {
|
||||
centerX = laneStartX(li) + laneWidth(li) / 2;
|
||||
} else {
|
||||
final int slot = effectiveSlot(project, n.action!);
|
||||
centerX = slotCenterX(li, slot) + (idx - (total - 1) / 2) * (nodeW * 0.62);
|
||||
}
|
||||
final double top = marginY + n.rank * (nodeH + rankGap) + (nodeH - h) / 2;
|
||||
n.rect = Rect.fromLTWH(centerX - w / 2, top, w, h);
|
||||
}
|
||||
|
||||
// 同层智能排开:同一 rank 行内若有水平重叠(同格多节点 / 跨列挤出),
|
||||
// 从左到右依次推开,保证节点之间至少留 10px,避免“堆叠到一起看不清”。
|
||||
final Map<int, List<FlowNode>> byRank = <int, List<FlowNode>>{};
|
||||
for (final FlowNode n in nodes) {
|
||||
byRank.putIfAbsent(n.rank, () => <FlowNode>[]).add(n);
|
||||
}
|
||||
for (final List<FlowNode> row in byRank.values) {
|
||||
row.sort((FlowNode a, FlowNode b) => a.rect.left.compareTo(b.rect.left));
|
||||
for (int i = 1; i < row.length; i++) {
|
||||
final FlowNode prev = row[i - 1];
|
||||
final FlowNode cur = row[i];
|
||||
final double minLeft = prev.rect.right + 10;
|
||||
if (cur.rect.left < minLeft) {
|
||||
cur.rect = cur.rect.shift(Offset(minLeft - cur.rect.left, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 泳道带按内容**智能加宽**:若某泳道的节点被推到基础宽度之外,
|
||||
// 先按内容算出需要的加宽量,再把该泳道及其后所有泳道整体右移,
|
||||
// 保证底部泳道带完整覆盖自己的动作节点(与条形 / 圆周视图的观感一致)。
|
||||
final List<double> extra = List<double>.filled(lanes.length, 0);
|
||||
for (int i = 0; i < lanes.length; i++) {
|
||||
double contentRight = double.negativeInfinity;
|
||||
for (final FlowNode n in nodes) {
|
||||
if ((laneIndex[n.lane] ?? 0) == i) {
|
||||
contentRight = math.max(contentRight, n.rect.right);
|
||||
}
|
||||
}
|
||||
if (contentRight.isFinite) {
|
||||
final double need = contentRight + 26 - (laneStarts[i] + laneWidths[i]);
|
||||
if (need > 0) extra[i] = need;
|
||||
}
|
||||
}
|
||||
if (extra.any((double e) => e > 0)) {
|
||||
double delta = 0;
|
||||
for (int i = 0; i < lanes.length; i++) {
|
||||
if (delta != 0) {
|
||||
for (final FlowNode n in nodes) {
|
||||
if ((laneIndex[n.lane] ?? 0) == i) {
|
||||
n.rect = n.rect.shift(Offset(delta, 0));
|
||||
}
|
||||
}
|
||||
laneStarts[i] += delta;
|
||||
}
|
||||
laneWidths[i] += extra[i];
|
||||
// 泳道加宽后,开始 / 结束胶囊重新居中于泳道带。
|
||||
if (extra[i] > 0) {
|
||||
for (final FlowNode n in nodes) {
|
||||
if ((n.isStart || n.isEnd) && (laneIndex[n.lane] ?? 0) == i) {
|
||||
final double cx = laneStarts[i] + laneWidths[i] / 2;
|
||||
n.rect = Rect.fromLTWH(
|
||||
cx - n.rect.width / 2, n.rect.top, n.rect.width, n.rect.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
delta += extra[i];
|
||||
}
|
||||
}
|
||||
|
||||
// 6) 连线走线:画布绘制 / SVG / drawio 导出共用(同源同层分支扇形错位)。
|
||||
// 依赖上保存的手动走线偏移(routeOffset)在此叠加:
|
||||
// 向下流为竖直偏移(拖动横线),同层绕行为水平偏移(拖动纵向走廊)。
|
||||
// 同源同层的多条分支预先分组,横线在可用空隙内**均匀铺开**,
|
||||
// 分支多时不再全部挤在同一条线上(流程图“智能排开”)。
|
||||
final Map<String, List<FlowEdge>> fanGroups = <String, List<FlowEdge>>{};
|
||||
for (final FlowEdge e in edges) {
|
||||
final FlowNode? a = byId[e.fromId];
|
||||
final FlowNode? b = byId[e.toId];
|
||||
if (a == null || b == null || b.rank <= a.rank) continue;
|
||||
fanGroups.putIfAbsent('${e.fromId}:${b.rank}', () => <FlowEdge>[]).add(e);
|
||||
}
|
||||
final Map<String, int> fanIndex = <String, int>{};
|
||||
for (final FlowEdge e in edges) {
|
||||
final FlowNode? a = byId[e.fromId];
|
||||
@@ -325,14 +446,26 @@ class FlowLayout {
|
||||
}
|
||||
if (b.rank > a.rank) {
|
||||
final String key = '${e.fromId}:${b.rank}';
|
||||
final List<FlowEdge> group = fanGroups[key] ?? <FlowEdge>[e];
|
||||
final int idx = fanIndex[key] ?? 0;
|
||||
fanIndex[key] = idx + 1;
|
||||
// 横线高度:扇形错开 + 手动偏移,限制在源/目标两行之间的空隙内。
|
||||
double lane = math.min(
|
||||
(a.rect.bottom + b.rect.top) / 2 + idx * 14 + routeOffset,
|
||||
b.rect.top - 8,
|
||||
);
|
||||
if (lane < a.rect.bottom + 10) lane = a.rect.bottom + 10;
|
||||
// 横线高度:单条分支沿用“空隙中线”;多条分支在
|
||||
// [源底 + 10, 目标顶 - 8] 内均匀铺开(第 idx+1 / n+1 份),再叠加手动偏移。
|
||||
final double gapLow = a.rect.bottom + 10;
|
||||
double gapHigh = double.infinity;
|
||||
for (final FlowEdge ge in group) {
|
||||
final FlowNode? gb = byId[ge.toId];
|
||||
if (gb != null && gb.rect.top - 8 < gapHigh) gapHigh = gb.rect.top - 8;
|
||||
}
|
||||
double lane;
|
||||
if (group.length <= 1) {
|
||||
lane = math.min((a.rect.bottom + b.rect.top) / 2 + routeOffset, b.rect.top - 8);
|
||||
} else {
|
||||
final double span = math.max(gapHigh - gapLow, 8);
|
||||
lane = gapLow + span * (idx + 1) / (group.length + 1) + routeOffset;
|
||||
}
|
||||
if (lane < gapLow) lane = gapLow;
|
||||
if (lane > gapHigh) lane = gapHigh;
|
||||
final double x0 = a.rect.center.dx;
|
||||
final double x1 = b.rect.center.dx;
|
||||
routes.add(FlowEdgeRoute(
|
||||
|
||||
+166
-44
@@ -95,6 +95,16 @@ bool angleRangesOverlap(double s1, double e1, double s2, double e2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// 动作 [a] 在 [project] 中其泳道内的有效槽位(与泳道槽位数钳制一致)。
|
||||
///
|
||||
/// 1 槽泳道恒为 0;旧数据中的历史行序(超出范围 / -1)会被钳制到有效槽位。
|
||||
int effectiveSlot(Project project, Action a) {
|
||||
final int slots = project.slotsOf(a.layer);
|
||||
if (slots <= 1) return 0;
|
||||
final int r = a.row;
|
||||
return r < 0 ? 0 : (r >= slots ? slots - 1 : r);
|
||||
}
|
||||
|
||||
/// 条形(甘特)视图布局。
|
||||
///
|
||||
/// 横轴为相位角(0°–360°),纵轴为动作行。行顺序由 [ordered] 决定,
|
||||
@@ -105,14 +115,23 @@ class BarLayout {
|
||||
/// 参数 [project]:项目数据;[size]:可用画布尺寸。
|
||||
/// 副作用:初始化 [pitch]。
|
||||
BarLayout(this.project, this.size) {
|
||||
// 可用高度 = 总高 - 顶部留白 - 底部预留;按**泳道数**均分并夹取到 [44, 58],
|
||||
// 让相邻泳道之间的空隙能容纳依赖连线及其标签(上限定得高一些,
|
||||
// 泳道少时获得更多垂直间隙,减少标签相互压盖)。
|
||||
final int n = lanes.length;
|
||||
// 可用高度 = 总高 - 顶部留白 - 底部预留;按**总子行数**(各泳道槽位数之和)
|
||||
// 均分并夹取到 [44, 58];单槽泳道时与旧版行为完全一致。
|
||||
// 多槽位工程采用「组内紧凑 + 泳道间拉开」:子行更紧、泳道之间额外留白,
|
||||
// 一眼能看出哪些子行属于同一条泳道。
|
||||
final int n = subRowCount;
|
||||
final int laneN = lanes.length;
|
||||
final double extraTotal = _grouped && laneN > 1 ? (laneN - 1) * laneExtraGap : 0;
|
||||
final double usable = size.height - topPad - bottomReserve;
|
||||
pitch = n == 0 ? 58 : (usable / n).clamp(44, 58);
|
||||
pitch = n == 0 ? 58 : ((usable - extraTotal) / n).clamp(_grouped ? 36 : 44, 58);
|
||||
}
|
||||
|
||||
/// 是否启用「组内紧凑 + 泳道间拉开」的间隔分组(仅多槽位工程)。
|
||||
bool get _grouped => project.hasMultiSlotLanes;
|
||||
|
||||
/// 泳道之间的额外纵向留白(仅多槽位分组时生效,像素)。
|
||||
static const double laneExtraGap = 16;
|
||||
|
||||
/// 布局所依据的项目数据。
|
||||
final Project project;
|
||||
|
||||
@@ -149,12 +168,10 @@ class BarLayout {
|
||||
/// 决定行先后的动作列表;见顶层函数 [orderActions]。
|
||||
List<Action> get ordered => orderActions(project);
|
||||
|
||||
/// 泳道编号(= 物理执行器轨道):所有动作 `layer` 的去重升序列表。
|
||||
List<int> get lanes {
|
||||
final Set<int> s = <int>{for (final Action a in project.actions) a.layer};
|
||||
final List<int> l = s.toList()..sort();
|
||||
return l;
|
||||
}
|
||||
/// 泳道编号(= 物理执行器轨道):来自 [Project.renderLanes]。
|
||||
///
|
||||
/// 开启「保留空泳道」时包含动作已全部移走的空泳道(序号不变)。
|
||||
List<int> get lanes => project.renderLanes;
|
||||
|
||||
/// 泳道号在 [lanes] 中的序号。
|
||||
int laneIndexOf(int lane) => lanes.indexOf(lane);
|
||||
@@ -163,17 +180,65 @@ class BarLayout {
|
||||
List<Action> actionsInLane(int lane) =>
|
||||
ordered.where((Action a) => a.layer == lane).toList();
|
||||
|
||||
/// 泳道号转纵坐标(该泳道顶部 y)。
|
||||
double yForLane(int lane) => topPad + laneIndexOf(lane) * pitch;
|
||||
/// 泳道 [lane] 的槽位数(1–5)。
|
||||
int slotsOf(int lane) => project.slotsOf(lane);
|
||||
|
||||
/// 行索引转纵坐标(按泳道序号)。
|
||||
double yFor(int index) => topPad + index * pitch;
|
||||
/// 动作 [a] 的实际槽位(钳制到所属泳道的有效范围;1 槽泳道恒为 0)。
|
||||
int slotOf(Action a) => effectiveSlot(project, a);
|
||||
|
||||
/// 全部泳道的子行总数(Σ 槽位)。
|
||||
int get subRowCount {
|
||||
int n = 0;
|
||||
for (final int lane in lanes) {
|
||||
n += slotsOf(lane);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/// 泳道 [lane] 之前(不含)的纵向高度(子行 + 分组留白)。
|
||||
double _laneOffsetBefore(int lane) {
|
||||
double h = 0;
|
||||
for (final int l in lanes) {
|
||||
if (l == lane) break;
|
||||
h += slotsOf(l) * pitch + (_grouped ? laneExtraGap : 0);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
/// 泳道号转纵坐标(该泳道顶部 y)。
|
||||
double yForLane(int lane) => topPad + _laneOffsetBefore(lane);
|
||||
|
||||
/// 泳道内槽位转纵坐标(该槽位所在子行的顶部 y)。
|
||||
double yForSlot(int lane, int slot) => yForLane(lane) + slot * pitch;
|
||||
|
||||
/// 内容底部 y(最后一个子行之后)。
|
||||
double get plotBottom {
|
||||
double h = subRowCount * pitch;
|
||||
if (_grouped && lanes.length > 1) h += (lanes.length - 1) * laneExtraGap;
|
||||
return topPad + h;
|
||||
}
|
||||
|
||||
/// 由纵坐标反查最近的泳道号(用于拖拽换道)。
|
||||
int laneAt(double y) {
|
||||
if (lanes.isEmpty) return 0;
|
||||
final int i = ((y - topPad) / pitch).round().clamp(0, lanes.length - 1);
|
||||
return lanes[i];
|
||||
int laneAt(double y) => laneSlotAt(y).$1;
|
||||
|
||||
/// 由纵坐标反查(泳道号, 槽位)——拖拽换道 / 换槽位时使用。
|
||||
(int, int) laneSlotAt(double y) {
|
||||
if (lanes.isEmpty) return (0, 0);
|
||||
double top = topPad;
|
||||
for (int li = 0; li < lanes.length; li++) {
|
||||
final int lane = lanes[li];
|
||||
final int s = slotsOf(lane);
|
||||
final double h = s * pitch;
|
||||
// 泳道之间的额外留白按半份归属本道,保证指针落在空隙中也能命中相邻泳道。
|
||||
final double boundary =
|
||||
top + h + (_grouped && li < lanes.length - 1 ? laneExtraGap * 0.5 : 0);
|
||||
if (y < boundary || li == lanes.length - 1) {
|
||||
final int slot = ((y - top) / pitch).round().clamp(0, s - 1);
|
||||
return (lane, slot);
|
||||
}
|
||||
top += h + (_grouped ? laneExtraGap : 0);
|
||||
}
|
||||
return (lanes.last, slotsOf(lanes.last) - 1);
|
||||
}
|
||||
|
||||
/// 相位角(度)转横坐标;角度先钳制到 `[0, 360]`。
|
||||
@@ -183,7 +248,7 @@ class BarLayout {
|
||||
///
|
||||
/// 宽度至少为 3px,避免极短动作不可见;跨圈部分会被截断到 360°。
|
||||
Rect rectFor(Action a) {
|
||||
final double y = yForLane(a.layer);
|
||||
final double y = yForSlot(a.layer, slotOf(a));
|
||||
final double x0 = xFor(a.startAngle);
|
||||
final double x1 = xFor(math.min(a.endAngle, 360));
|
||||
return Rect.fromLTWH(x0, y, math.max(x1 - x0, 3), barH);
|
||||
@@ -217,18 +282,29 @@ class CircularLayout {
|
||||
CircularLayout(this.project, this.size) {
|
||||
// 圆心略微下移 18px 以平衡顶部刻度标签的视觉重心。
|
||||
center = Offset(size.width / 2, size.height / 2 + 18);
|
||||
// 轨道数 = 泳道数(layer 去重),同一轨道可放多个互不重叠的动作。
|
||||
final int layers = lanes.length;
|
||||
// 子环总数 = Σ 各轨道槽位数(泳道加宽后同一轨道可有多条并行子环);
|
||||
// 单槽时与旧版(按轨道数)完全一致。
|
||||
final int rings = subRingCount;
|
||||
final int laneN = lanes.length;
|
||||
// 多槽位工程采用「组内紧凑 + 轨道间拉开」:同一轨道的子环更紧、
|
||||
// 轨道之间额外留白,一眼能看出哪些子环属于同一轨道。
|
||||
final double extraTotal = _grouped && laneN > 1 ? (laneN - 1) * ringExtraGap : 0;
|
||||
// 最大半径受较短边约束,减去 74px 留给刻度与边距。
|
||||
final double maxR = math.min(size.width, size.height) / 2 - 74;
|
||||
// 在 r0 与 maxR 之间均分各轨道,环间距夹取到 [32, 52]:
|
||||
// 让相邻环之间留出足够空隙放置依赖箭头与图注。
|
||||
pitch = layers <= 1 ? 46 : ((maxR - r0) / (layers - 1)).clamp(32, 56);
|
||||
// 动作环带宽度:只求容纳文字(约 15–18px),环更窄、环间空隙更宽,
|
||||
// 便于在环间放置依赖标签(减少与动作名、其它标签的压盖)。
|
||||
ringWidth = (pitch * 0.42).clamp(14, 17);
|
||||
// 在 r0 与 maxR 之间均分各子环,环间距夹取(多槽位时允许更紧)。
|
||||
pitch = rings <= 1
|
||||
? 46
|
||||
: ((maxR - r0 - extraTotal) / (rings - 1)).clamp(_grouped ? 24 : 32, 56);
|
||||
// 动作环带宽度:只求容纳文字;多槽位分组时子环更窄,轨道间靠留白区分。
|
||||
ringWidth = (pitch * 0.42).clamp(_grouped ? 10 : 14, 17);
|
||||
}
|
||||
|
||||
/// 是否启用「组内紧凑 + 轨道间拉开」的间隔分组(仅多槽位工程)。
|
||||
bool get _grouped => project.hasMultiSlotLanes;
|
||||
|
||||
/// 轨道之间的额外径向留白(仅多槽位分组时生效,像素)。
|
||||
static const double ringExtraGap = 18;
|
||||
|
||||
/// 布局所依据的项目数据。
|
||||
final Project project;
|
||||
|
||||
@@ -247,31 +323,77 @@ class CircularLayout {
|
||||
/// 环的视觉宽度(像素)。
|
||||
late final double ringWidth;
|
||||
|
||||
/// 轨道编号(= 泳道):所有动作 `layer` 的去重升序列表。
|
||||
List<int> get lanes {
|
||||
final Set<int> s = <int>{for (final Action a in project.actions) a.layer};
|
||||
final List<int> l = s.toList()..sort();
|
||||
return l;
|
||||
}
|
||||
/// 轨道编号(= 泳道):来自 [Project.renderLanes](含保留的空轨道)。
|
||||
List<int> get lanes => project.renderLanes;
|
||||
|
||||
/// 轨道号在 [lanes] 中的序号。
|
||||
int laneIndexOf(int lane) => lanes.indexOf(lane);
|
||||
|
||||
/// 由半径反查最近的轨道号(用于拖拽换轨)。
|
||||
int laneAtRadius(double r) {
|
||||
if (lanes.isEmpty) return 0;
|
||||
final int i = ((r - r0) / pitch).round().clamp(0, lanes.length - 1);
|
||||
return lanes[i];
|
||||
/// 轨道 [lane] 的槽位数(1–5)。
|
||||
int slotsOf(int lane) => project.slotsOf(lane);
|
||||
|
||||
/// 动作 [a] 的实际槽位(钳制;1 槽轨道恒为 0)。
|
||||
int slotOf(Action a) => effectiveSlot(project, a);
|
||||
|
||||
/// 全部轨道的子环总数(Σ 槽位)。
|
||||
int get subRingCount {
|
||||
int n = 0;
|
||||
for (final int lane in lanes) {
|
||||
n += slotsOf(lane);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/// 第 [lane] 条轨道对应的环半径(未知轨道回退到最内圈)。
|
||||
double radiusFor(int lane) {
|
||||
/// 轨道 [lane] 之前(不含)的子环数。
|
||||
int subRingIndexOfLane(int lane) {
|
||||
int n = 0;
|
||||
for (final int l in lanes) {
|
||||
if (l == lane) break;
|
||||
n += slotsOf(l);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/// 由半径反查最近的轨道号(用于拖拽换轨)。
|
||||
int laneAtRadius(double r) => laneSlotAtRadius(r).$1;
|
||||
|
||||
/// 由半径反查(轨道号, 槽位)——拖拽换轨 / 换子环时使用。
|
||||
(int, int) laneSlotAtRadius(double r) {
|
||||
if (lanes.isEmpty) return (0, 0);
|
||||
double base = r0;
|
||||
for (int li = 0; li < lanes.length; li++) {
|
||||
final int lane = lanes[li];
|
||||
final int s = slotsOf(lane);
|
||||
final double h = s * pitch;
|
||||
// 轨道之间的额外留白按半份归属本道,落在空隙中也能命中相邻轨道。
|
||||
final double boundary =
|
||||
base + h + (_grouped && li < lanes.length - 1 ? ringExtraGap * 0.5 : 0);
|
||||
if (r < boundary || li == lanes.length - 1) {
|
||||
final int slot = ((r - base) / pitch).round().clamp(0, s - 1);
|
||||
return (lane, slot);
|
||||
}
|
||||
base += h + (_grouped ? ringExtraGap : 0);
|
||||
}
|
||||
return (lanes.last, slotsOf(lanes.last) - 1);
|
||||
}
|
||||
|
||||
/// 轨道 [lane] 第 [slot] 条子环的半径(未知轨道回退到最内圈)。
|
||||
double radiusFor(int lane, [int slot = 0]) {
|
||||
final int i = laneIndexOf(lane);
|
||||
return r0 + (i < 0 ? 0 : i) * pitch;
|
||||
if (i < 0) return r0;
|
||||
final int s = slotsOf(lane);
|
||||
final int k = slot < 0 ? 0 : (slot >= s ? s - 1 : slot);
|
||||
return r0 +
|
||||
(subRingIndexOfLane(lane) + k) * pitch +
|
||||
(_grouped ? i * ringExtraGap : 0);
|
||||
}
|
||||
|
||||
/// 最外层半径。
|
||||
double get rMax => lanes.isEmpty ? r0 : radiusFor(lanes.last);
|
||||
double get rMax {
|
||||
if (lanes.isEmpty) return r0;
|
||||
final double extra = _grouped && lanes.length > 1 ? (lanes.length - 1) * ringExtraGap : 0;
|
||||
return r0 + (subRingCount - 1) * pitch + extra;
|
||||
}
|
||||
|
||||
/// 刻度标签所在的半径(最外层再向外偏移)。
|
||||
/// 刻度环半径:在外层动作环之外留出足够间距,
|
||||
@@ -292,7 +414,7 @@ class CircularLayout {
|
||||
Action? best;
|
||||
double bestDelta = double.infinity;
|
||||
for (final Action a2 in project.actions) {
|
||||
final double r = radiusFor(a2.layer);
|
||||
final double r = radiusFor(a2.layer, slotOf(a2));
|
||||
if ((d - r).abs() > ringWidth / 2 + slop) continue;
|
||||
if (_inArc(a2, a)) {
|
||||
final double delta = (d - r).abs();
|
||||
|
||||
+84
-3
@@ -251,10 +251,10 @@ class Action {
|
||||
/// 动作颜色(ARGB)。
|
||||
final int color;
|
||||
|
||||
/// 条形视图中的行序(自上而下,从 0 开始)。
|
||||
/// 泳道内的槽位(0 起):泳道加宽(多槽位)后,同泳道的并列动作按槽位分行放置。
|
||||
///
|
||||
/// `-1` 表示“未指定”,此时由 [BarLayout] 按工位与起始角自动排序;
|
||||
/// 一旦用户上下拖拽过行,就写入显式行序,行位置不再随相位变化而跳动。
|
||||
/// `-1` 或超出范围的值在布局时会被钳制到有效槽位(1 槽泳道统一落在 0 槽),
|
||||
/// 因此旧数据(历史序号值)无需迁移即可正常显示。
|
||||
final int row;
|
||||
|
||||
/// 指向本动作的依赖集合(本动作作为后继)。
|
||||
@@ -785,6 +785,11 @@ class Project {
|
||||
required this.units,
|
||||
required this.viewState,
|
||||
this.phaseZones = PhaseZone.defaults,
|
||||
this.keepEmptyLanes = true,
|
||||
this.minLaneCount = 0,
|
||||
this.laneSlots = const <int, int>{},
|
||||
this.autoSaveEnabled = true,
|
||||
this.autoSaveMinutes = 10,
|
||||
});
|
||||
|
||||
/// 项目名称。
|
||||
@@ -811,6 +816,37 @@ class Project {
|
||||
/// 相位分区(命名角度区间),用于条形视图顶部工艺阶段标注。
|
||||
final List<PhaseZone> phaseZones;
|
||||
|
||||
/// 是否保留空泳道:动作全部移走后仍保留该泳道(行 / 环 / 列),序号不变。
|
||||
///
|
||||
/// 关闭时按动作实际使用的层号渲染(空泳道自动消失、序号顺延)。
|
||||
final bool keepEmptyLanes;
|
||||
|
||||
/// 保底泳道数:开启 [keepEmptyLanes] 时渲染至少这么多条泳道(0 = 自动)。
|
||||
final int minLaneCount;
|
||||
|
||||
/// 泳道槽位数:layer → 槽位数(1–5);无记录的泳道视为 1 槽。
|
||||
///
|
||||
/// 泳道加宽后,同一泳道内的动作可按 [Action.row](槽位)分成多条并排行,
|
||||
/// 实现“一个泳道容纳多个并列动作”。
|
||||
final Map<int, int> laneSlots;
|
||||
|
||||
/// 泳道 [lane] 的槽位数(1–5;未配置为 1)。
|
||||
int slotsOf(int lane) {
|
||||
final int n = laneSlots[lane] ?? 1;
|
||||
return n < 1 ? 1 : (n > 5 ? 5 : n);
|
||||
}
|
||||
|
||||
/// 是否有任何泳道被加宽(多槽位)。
|
||||
bool get hasMultiSlotLanes => laneSlots.values.any((int v) => v > 1);
|
||||
|
||||
/// 是否启用自动保存(定时把文档写入文件,默认启用)。
|
||||
final bool autoSaveEnabled;
|
||||
|
||||
/// 自动保存间隔(分钟,1–240,默认 10)。
|
||||
///
|
||||
/// 仅在文档已有保存路径(手动保存过一次)后生效;自动保存会同时更新 `.bak`。
|
||||
final int autoSaveMinutes;
|
||||
|
||||
/// 按 id 查找动作;[id] 为 null 或未找到时返回 null。
|
||||
Action? actionById(String? id) {
|
||||
if (id == null) return null;
|
||||
@@ -842,6 +878,27 @@ class Project {
|
||||
/// 同一泳道可容纳多个互不重叠的动作,对应一个物理执行器。
|
||||
int get laneCount => <int>{for (final Action a in actions) a.layer}.length;
|
||||
|
||||
/// 渲染用的泳道层号列表(升序):统一供条形 / 圆周 / 流程图与侧栏使用。
|
||||
///
|
||||
/// - [keepEmptyLanes] 为真:渲染 `0 .. max(minLaneCount, 最大层号 + 1) - 1`,
|
||||
/// 动作全部移走的泳道保留为空泳道(序号不变);
|
||||
/// - 否则按动作实际使用的层号渲染(空泳道自动消失、序号顺延)。
|
||||
List<int> get renderLanes {
|
||||
final Set<int> layers = <int>{for (final Action a in actions) a.layer};
|
||||
if (!keepEmptyLanes) {
|
||||
return layers.toList()..sort();
|
||||
}
|
||||
int maxLayer = -1;
|
||||
for (final int l in layers) {
|
||||
if (l > maxLayer) maxLayer = l;
|
||||
}
|
||||
final int n = minLaneCount > maxLayer + 1 ? minLaneCount : maxLayer + 1;
|
||||
return <int>[for (int i = 0; i < n; i++) i];
|
||||
}
|
||||
|
||||
/// 渲染的泳道数量(含保留的空泳道)。
|
||||
int get renderLaneCount => renderLanes.length;
|
||||
|
||||
/// 基于当前实例创建副本,未提供的参数保持原值。
|
||||
Project copyWith({
|
||||
String? name,
|
||||
@@ -852,6 +909,11 @@ class Project {
|
||||
UnitSettings? units,
|
||||
ViewState? viewState,
|
||||
List<PhaseZone>? phaseZones,
|
||||
bool? keepEmptyLanes,
|
||||
int? minLaneCount,
|
||||
Map<int, int>? laneSlots,
|
||||
bool? autoSaveEnabled,
|
||||
int? autoSaveMinutes,
|
||||
}) {
|
||||
return Project(
|
||||
name: name ?? this.name,
|
||||
@@ -862,6 +924,11 @@ class Project {
|
||||
units: units ?? this.units,
|
||||
viewState: viewState ?? this.viewState,
|
||||
phaseZones: phaseZones ?? this.phaseZones,
|
||||
keepEmptyLanes: keepEmptyLanes ?? this.keepEmptyLanes,
|
||||
minLaneCount: minLaneCount ?? this.minLaneCount,
|
||||
laneSlots: laneSlots ?? this.laneSlots,
|
||||
autoSaveEnabled: autoSaveEnabled ?? this.autoSaveEnabled,
|
||||
autoSaveMinutes: autoSaveMinutes ?? this.autoSaveMinutes,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -876,6 +943,13 @@ class Project {
|
||||
'actions': actions.map((Action a) => a.toJson()).toList(),
|
||||
'viewState': viewState.toJson(),
|
||||
'phaseZones': phaseZones.map((PhaseZone z) => z.toJson()).toList(),
|
||||
'keepEmptyLanes': keepEmptyLanes,
|
||||
'minLaneCount': minLaneCount,
|
||||
'laneSlots': <String, int>{
|
||||
for (final MapEntry<int, int> e in laneSlots.entries) '${e.key}': e.value,
|
||||
},
|
||||
'autoSaveEnabled': autoSaveEnabled,
|
||||
'autoSaveMinutes': autoSaveMinutes,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -903,6 +977,13 @@ class Project {
|
||||
phaseZones: pz.isEmpty
|
||||
? PhaseZone.defaults
|
||||
: pz.map((dynamic e) => PhaseZone.fromJson(e as Map<String, dynamic>)).toList(),
|
||||
keepEmptyLanes: p['keepEmptyLanes'] as bool? ?? true,
|
||||
minLaneCount: (p['minLaneCount'] as num?)?.toInt() ?? 0,
|
||||
laneSlots: ((p['laneSlots'] as Map<String, dynamic>?) ?? <String, dynamic>{})
|
||||
.map((String k, dynamic v) =>
|
||||
MapEntry<int, int>(int.tryParse(k) ?? 0, (v as num?)?.toInt() ?? 1)),
|
||||
autoSaveEnabled: p['autoSaveEnabled'] as bool? ?? true,
|
||||
autoSaveMinutes: (p['autoSaveMinutes'] as num?)?.toInt() ?? 10,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+63
-18
@@ -98,19 +98,21 @@ class BarPainter extends CustomPainter {
|
||||
|
||||
if (project.viewState.showPhaseBands) _phaseBands(canvas, layout);
|
||||
// 换泳道拖拽:高亮目标泳道(可放置=强调色,重叠=警示色)。
|
||||
// 泳道加宽(多槽位)后高亮覆盖该泳道的全部槽位。
|
||||
if (dropLane != null && layout.lanes.contains(dropLane)) {
|
||||
final double y = layout.yForLane(dropLane!);
|
||||
final double h = layout.slotsOf(dropLane!) * layout.pitch;
|
||||
final Color c = dropValid ? tokens.accent : tokens.danger;
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(20, y - 8, layout.plotRight - 20, BarLayout.rowVisual),
|
||||
Rect.fromLTWH(20, y - 8, layout.plotRight - 20, h),
|
||||
const Radius.circular(10),
|
||||
),
|
||||
Paint()..color = c.withValues(alpha: 0.12),
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(20, y - 8, layout.plotRight - 20, BarLayout.rowVisual),
|
||||
Rect.fromLTWH(20, y - 8, layout.plotRight - 20, h),
|
||||
const Radius.circular(10),
|
||||
),
|
||||
Paint()
|
||||
@@ -131,7 +133,7 @@ class BarPainter extends CustomPainter {
|
||||
void _guide(Canvas canvas, BarLayout layout, UnitSettings u) {
|
||||
final double deg = guideAngle!;
|
||||
final double x = layout.xFor(deg.clamp(0, 360));
|
||||
final double bottom = layout.yFor(layout.ordered.length) - 4;
|
||||
final double bottom = layout.plotBottom - 4;
|
||||
final Paint p = Paint()
|
||||
..color = tokens.accent
|
||||
..strokeWidth = 1.4;
|
||||
@@ -235,7 +237,7 @@ class BarPainter extends CustomPainter {
|
||||
final Paint p = Paint()
|
||||
..color = col.withValues(alpha: 0.7)
|
||||
..strokeWidth = 1.4;
|
||||
_dashedLine(canvas, Offset(x, axisTop + 28), Offset(x, layout.yFor(layout.ordered.length) - 4), p);
|
||||
_dashedLine(canvas, Offset(x, axisTop + 28), Offset(x, layout.plotBottom - 4), p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,37 +273,61 @@ class BarPainter extends CustomPainter {
|
||||
final List<int> lanes = layout.lanes;
|
||||
for (int li = 0; li < lanes.length; li++) {
|
||||
final int lane = lanes[li];
|
||||
final double y = layout.yFor(li);
|
||||
final double y = layout.yForLane(lane);
|
||||
final int slots = layout.slotsOf(lane);
|
||||
final double laneH = slots * layout.pitch;
|
||||
final List<Action> acts = layout.actionsInLane(lane);
|
||||
// 隔泳道背景色带,弱化边界。
|
||||
// 单槽泳道保持与旧版完全一致的背景带 / 底线几何;多槽位覆盖整个泳道带。
|
||||
final double bandH = slots == 1 ? BarLayout.rowVisual : laneH;
|
||||
// 隔泳道背景色带(覆盖该泳道全部槽位),弱化边界。
|
||||
if (li.isEven) {
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(20, y - 8, layout.plotRight - 20, BarLayout.rowVisual),
|
||||
Rect.fromLTWH(20, y - 8, layout.plotRight - 20, bandH),
|
||||
const Radius.circular(10),
|
||||
),
|
||||
Paint()..color = tokens.panel2.withValues(alpha: 0.5),
|
||||
);
|
||||
}
|
||||
// 泳道标题(合并显示,最多两行,用 / 分隔)。
|
||||
_laneHeader(canvas, layout, li, acts, y);
|
||||
// 泳道底分隔线。
|
||||
// 多槽位泳道:槽位之间用浅色虚线分隔,提示并列关系。
|
||||
if (slots > 1) {
|
||||
for (int s = 1; s < slots; s++) {
|
||||
final double sy = y + s * layout.pitch - 8;
|
||||
_dashedLine(
|
||||
canvas,
|
||||
Offset(layout.plotLeft, sy),
|
||||
Offset(layout.plotRight, sy),
|
||||
Paint()
|
||||
..color = tokens.line2.withValues(alpha: 0.5)
|
||||
..strokeWidth = 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
// 泳道标题(合并显示;单槽最多两行,多槽位按泳道高度持续换行)。
|
||||
_laneHeader(canvas, layout, li, acts,
|
||||
slots == 1 ? y : y + laneH / 2 - BarLayout.rowVisual / 2, slots, laneH);
|
||||
// 泳道底分隔线(单槽时与旧版一致)。
|
||||
canvas.drawLine(
|
||||
Offset(layout.plotLeft, y + BarLayout.rowVisual - 4),
|
||||
Offset(layout.plotRight, y + BarLayout.rowVisual - 4),
|
||||
Offset(layout.plotLeft, slots == 1 ? y + BarLayout.rowVisual - 4 : y + laneH - 4),
|
||||
Offset(layout.plotRight, slots == 1 ? y + BarLayout.rowVisual - 4 : y + laneH - 4),
|
||||
Paint()
|
||||
..color = tokens.line2.withValues(alpha: 0.6)
|
||||
..strokeWidth = 1,
|
||||
);
|
||||
// 该泳道内的所有动作条(互不重叠)。
|
||||
// 该泳道内的所有动作条(按槽位分行放置)。
|
||||
for (final Action a in acts) {
|
||||
_bar(canvas, layout, a, u, cycle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制一条泳道的标题:序号徽标 + 合并动作名(≤2 行,用 / 分隔)+ 副标题。
|
||||
void _laneHeader(Canvas canvas, BarLayout layout, int li, List<Action> acts, double y) {
|
||||
/// 绘制一条泳道的标题:序号徽标 + 合并动作名 + 副标题。
|
||||
///
|
||||
/// 合并动作名在宽度 [BarLayout.leftGutter]-68 内自动换行:单槽泳道最多两行
|
||||
/// (保持旧版外观);多槽位泳道按泳道高度**持续换行**直到放不下为止
|
||||
/// (副标题跟随实际行数下移)。
|
||||
void _laneHeader(Canvas canvas, BarLayout layout, int li, List<Action> acts, double y,
|
||||
int slots, double laneH) {
|
||||
final double labelMax = BarLayout.leftGutter - 68;
|
||||
final Color c0 = acts.isEmpty ? tokens.accent : Color(acts.first.color);
|
||||
canvas.drawRRect(
|
||||
@@ -312,7 +338,8 @@ class BarPainter extends CustomPainter {
|
||||
color: tokens.chip, size: 10, align: TextAlign.center, weight: FontWeight.w700);
|
||||
if (acts.isEmpty) return;
|
||||
|
||||
// 多个动作合并为「A1 上料 / A2 定位」,最多两行。
|
||||
// 先按足够大的行数测量“真实行高”(字体回退下行高可能大于字号,
|
||||
// 之前按固定 13px 估算导致标题换行多行后压住灰色副标题)。
|
||||
final String joined = acts.map((Action a) => '${a.id} ${a.name}').join(' / ');
|
||||
final TextPainter tp = TextPainter(
|
||||
text: TextSpan(
|
||||
@@ -325,15 +352,33 @@ class BarPainter extends CustomPainter {
|
||||
),
|
||||
),
|
||||
textDirection: ui.TextDirection.ltr,
|
||||
maxLines: 2,
|
||||
maxLines: 40,
|
||||
ellipsis: '…',
|
||||
)..layout(maxWidth: labelMax);
|
||||
final int totalLines = tp.computeLineMetrics().length;
|
||||
final double lineH = totalLines == 0 ? 14 : tp.height / totalLines;
|
||||
|
||||
// 行数上限:单槽保持两行(旧版外观);多槽位按泳道高度换算并给副标题留一行。
|
||||
final bool single = slots <= 1;
|
||||
final int maxLines =
|
||||
single ? 2 : ((laneH - lineH - 8) / lineH).floor().clamp(2, 40);
|
||||
if (tp.computeLineMetrics().length != maxLines && maxLines < totalLines) {
|
||||
tp.maxLines = maxLines;
|
||||
tp.ellipsis = '…';
|
||||
tp.layout(maxWidth: labelMax);
|
||||
}
|
||||
tp.paint(canvas, Offset(60, y + 2));
|
||||
|
||||
final Station? st = project.stationById(acts.first.stationId);
|
||||
final String sub = '${st?.name ?? acts.first.stationId} · ${acts.first.driver}'
|
||||
'${acts.length > 1 ? ' · 共 ${acts.length} 个' : ''}';
|
||||
_textMax(canvas, sub, Offset(60, y + 32), labelMax, color: tokens.dim, size: 10);
|
||||
// 副标题紧随实际标题高度;单槽保持旧版下边距(y+32)但绝不高于标题底部,
|
||||
// 多槽位下若剩余高度不足则不再绘制,避免压住标题文字。
|
||||
final double subY =
|
||||
single ? math.max(y + 32, y + 2 + tp.height + 2) : y + 2 + tp.height + 2;
|
||||
if (single || subY + 11 <= y + laneH) {
|
||||
_textMax(canvas, sub, Offset(60, subY), labelMax, color: tokens.dim, size: 10);
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制单个动作条块(投影 / 填充 / 描边 / 跨圈尾段 / 文字标注)。
|
||||
|
||||
@@ -92,18 +92,54 @@ class CircularPainter extends CustomPainter {
|
||||
final int layers = lanes.length;
|
||||
if (project.viewState.showRingBg) {
|
||||
for (int i = 0; i < layers; i++) {
|
||||
final double r = layout.radiusFor(lanes[i]);
|
||||
final int lane = lanes[i];
|
||||
final int slots = layout.slotsOf(lane);
|
||||
final Color band = i.isEven ? tokens.ringA : tokens.ringB;
|
||||
if (slots <= 1) {
|
||||
// 单槽轨道:与旧版完全一致(一条环带 + 内外沿细描边)。
|
||||
final double r = layout.radiusFor(lane, 0);
|
||||
canvas.drawCircle(
|
||||
c,
|
||||
r,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = th
|
||||
..color = band,
|
||||
);
|
||||
canvas.drawCircle(
|
||||
c,
|
||||
r - th / 2,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = tokens.ringEdge,
|
||||
);
|
||||
canvas.drawCircle(
|
||||
c,
|
||||
r + th / 2,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = tokens.ringEdge,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
// 多槽位轨道:整条轨道用一条加宽的色带(同一泳道同一颜色),
|
||||
// 槽位之间用浅色虚线分隔;不同轨道之间仍按奇偶交替(与现在一致)。
|
||||
final double rIn = layout.radiusFor(lane, 0);
|
||||
final double rOut = layout.radiusFor(lane, slots - 1);
|
||||
final double rc = (rIn + rOut) / 2;
|
||||
canvas.drawCircle(
|
||||
c,
|
||||
r,
|
||||
rc,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = th
|
||||
..color = i.isEven ? tokens.ringA : tokens.ringB,
|
||||
..strokeWidth = (rOut - rIn) + th
|
||||
..color = band,
|
||||
);
|
||||
canvas.drawCircle(
|
||||
c,
|
||||
r - th / 2,
|
||||
rIn - th / 2,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
@@ -111,12 +147,19 @@ class CircularPainter extends CustomPainter {
|
||||
);
|
||||
canvas.drawCircle(
|
||||
c,
|
||||
r + th / 2,
|
||||
rOut + th / 2,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = tokens.ringEdge,
|
||||
);
|
||||
final Paint dash = Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = tokens.ringEdge.withValues(alpha: 0.95);
|
||||
for (int s = 1; s < slots; s++) {
|
||||
_dashedCircle(canvas, c, rIn + (s - 0.5) * layout.pitch, dash);
|
||||
}
|
||||
}
|
||||
}
|
||||
canvas.drawCircle(c, math.max(CircularLayout.r0 - th / 2, 8), Paint()..color = tokens.dial);
|
||||
@@ -124,11 +167,14 @@ class CircularPainter extends CustomPainter {
|
||||
// 相位分区环:在最外动作环与刻度环之间画一圈分区色带并标注名称。
|
||||
if (project.viewState.showPhaseBands) _phaseRing(canvas, layout);
|
||||
|
||||
// 轨道标签:为每条轨道挑选一个空位角度,避免压住该轨道的动作弧。
|
||||
// 轨道标签:为每条轨道挑选一个空位角度,避免压住该轨道的动作弧;
|
||||
// 多槽位轨道把标签放在轨道带的垂直中心(半径方向)。
|
||||
if (project.viewState.showLayerLabels) {
|
||||
for (int i = 0; i < layers; i++) {
|
||||
final double r = layout.radiusFor(lanes[i]);
|
||||
final double free = _freeAngle(lanes[i]);
|
||||
final int lane = lanes[i];
|
||||
final int slots = layout.slotsOf(lane);
|
||||
final double r = layout.radiusFor(lane) + (slots - 1) * layout.pitch / 2;
|
||||
final double free = _freeAngle(lane);
|
||||
final Offset lp = polar(c, r, free);
|
||||
_text(canvas, 'L${i + 1}', lp, color: tokens.ringLabel, size: 10, align: TextAlign.center, weight: FontWeight.w700);
|
||||
}
|
||||
@@ -305,7 +351,7 @@ class CircularPainter extends CustomPainter {
|
||||
/// 参数 [u] 为当前单位设置(保留以对齐调用接口,当前未直接使用)。
|
||||
void _action(Canvas canvas, CircularLayout layout, Action a, UnitSettings u) {
|
||||
final Offset c = layout.center;
|
||||
final double r = layout.radiusFor(a.layer);
|
||||
final double r = layout.radiusFor(a.layer, layout.slotOf(a));
|
||||
final double th = layout.th;
|
||||
final Color col = Color(a.color);
|
||||
final bool sel = selectedIds.contains(a.id);
|
||||
@@ -511,6 +557,20 @@ class CircularPainter extends CustomPainter {
|
||||
canvas.drawPath(p, Paint()..color = col);
|
||||
}
|
||||
|
||||
/// 以虚线绘制圆周(用于多槽位轨道内部的槽位分隔线)。
|
||||
void _dashedCircle(Canvas canvas, Offset center, double r, Paint paint,
|
||||
{double dash = 6, double gap = 5}) {
|
||||
final Path path = Path()..addOval(Rect.fromCircle(center: center, radius: r));
|
||||
for (final ui.PathMetric metric in path.computeMetrics()) {
|
||||
double dist = 0;
|
||||
while (dist < metric.length) {
|
||||
final double end = math.min(dist + dash, metric.length);
|
||||
canvas.drawPath(metric.extractPath(dist, end), paint);
|
||||
dist = end + gap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制拖拽端点时的径向虚线参考与角度标注。
|
||||
void _guide(Canvas canvas, CircularLayout layout) {
|
||||
final Offset c = layout.center;
|
||||
|
||||
@@ -85,24 +85,19 @@ class FlowchartPainter extends CustomPainter {
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制泳道背景带与标题(泳道 = 轨道)。
|
||||
/// 绘制泳道背景带与标题(泳道 = 轨道;多槽位泳道按槽位数加宽带)。
|
||||
void _lanes(Canvas canvas, FlowLayout layout) {
|
||||
final double lanePitch = FlowLayout.nodeW + FlowLayout.laneGap;
|
||||
final double top = layout.bounds.top + 20;
|
||||
final double bottom = layout.bounds.bottom - 20;
|
||||
for (int i = 0; i < layout.lanes.length; i++) {
|
||||
final double cx = FlowLayout.marginX + i * lanePitch + FlowLayout.nodeW / 2;
|
||||
final Rect band = Rect.fromLTRB(
|
||||
cx - FlowLayout.nodeW / 2 - 26,
|
||||
top,
|
||||
cx + FlowLayout.nodeW / 2 + 26,
|
||||
bottom,
|
||||
);
|
||||
final double left = layout.laneStartX(i) - 26;
|
||||
final double right = layout.laneStartX(i) + layout.laneWidth(i) + 26;
|
||||
final Rect band = Rect.fromLTRB(left, top, right, bottom);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(band, const Radius.circular(14)),
|
||||
Paint()..color = (i.isEven ? tokens.ringA : tokens.ringB).withValues(alpha: 0.55),
|
||||
);
|
||||
_text(canvas, '轨道 L${i + 1}', Offset(cx, top + 16),
|
||||
_text(canvas, '轨道 L${i + 1}', Offset((left + right) / 2, top + 16),
|
||||
color: tokens.sub, size: 11, weight: FontWeight.w700, align: TextAlign.center);
|
||||
}
|
||||
}
|
||||
|
||||
+144
-16
@@ -9,10 +9,14 @@
|
||||
library;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math' as math;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../persistence/android_docs.dart';
|
||||
import '../version.dart';
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
@@ -27,7 +31,7 @@ class AppController extends ChangeNotifier {
|
||||
/// 参数 [project]:初始项目;为 null 时使用 [Project.demo] 并标记为已修改
|
||||
/// (因为演示数据尚未保存到文件)。
|
||||
AppController({Project? project})
|
||||
: _project = project ?? Project.demo(),
|
||||
: _project = _syncLaneFloor(project ?? Project.demo()),
|
||||
_dirty = project == null;
|
||||
|
||||
/// 当前项目数据(唯一可变引用,替换时整体赋值)。
|
||||
@@ -36,11 +40,14 @@ class AppController extends ChangeNotifier {
|
||||
/// 当前主题亮度(默认浅色 / 白底)。
|
||||
Brightness _brightness = Brightness.light;
|
||||
|
||||
/// 是否已获得有效授权(有效时才允许导出 SVG / PNG)。
|
||||
/// 是否已获得有效授权(有效时才允许导出 SVG / PNG / drawio)。
|
||||
///
|
||||
/// 1.3.4 起授权校验临时冻结([kLicenseRequired] = false):始终视为已授权,
|
||||
/// 待功能丰富后再恢复校验。
|
||||
bool _licensed = false;
|
||||
|
||||
/// 是否已授权。
|
||||
bool get licensed => _licensed;
|
||||
/// 是否已授权(授权冻结期间恒为 true)。
|
||||
bool get licensed => !kLicenseRequired || _licensed;
|
||||
|
||||
/// 设置授权状态并刷新(启动时校验 / 重新读取 .lic 后调用)。
|
||||
void setLicensed(bool value) {
|
||||
@@ -154,6 +161,10 @@ class AppController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
/// 自动保存当前项目(内部方法,异常静默忽略以避免打断编辑)。
|
||||
///
|
||||
/// 同时承担两件事:
|
||||
/// 1. 崩溃恢复快照(每 5 秒写入 Storage,与文档文件无关);
|
||||
/// 2. 文档自动保存(按 [Project.autoSaveMinutes] 的间隔把文档写回文件)。
|
||||
Future<void> _autosave() async {
|
||||
try {
|
||||
await Storage.instance.writeAutosave(
|
||||
@@ -162,6 +173,54 @@ class AppController extends ChangeNotifier {
|
||||
clean: !_dirty,
|
||||
);
|
||||
} catch (_) {}
|
||||
await _autoSaveDocument();
|
||||
}
|
||||
|
||||
/// 文档自动保存:启用、已保存过路径且有未保存修改时,按间隔写回文件。
|
||||
///
|
||||
/// - 间隔 = [Project.autoSaveMinutes](默认 10 分钟,1–240);
|
||||
/// - 以 [_lastSavedAt] 为基准:任何一次手动 / 自动保存都会重置计时;
|
||||
/// - 安卓写入公共 Documents,桌面写 `.seq.json` 并同步 `.bak` 备份。
|
||||
Future<void> _autoSaveDocument() async {
|
||||
final String? path = _filePath;
|
||||
if (!_project.autoSaveEnabled || !_dirty || path == null) return;
|
||||
final DateTime now = DateTime.now();
|
||||
// 从未保存过时间戳(如刚打开文件):以“现在”为基准,等满一个间隔再自动保存。
|
||||
if (_lastSavedAt == null) {
|
||||
_lastSavedAt = now;
|
||||
return;
|
||||
}
|
||||
final int minutes =
|
||||
_project.autoSaveMinutes < 1 ? 1 : (_project.autoSaveMinutes > 240 ? 240 : _project.autoSaveMinutes);
|
||||
if (now.difference(_lastSavedAt!).inSeconds < minutes * 60) return;
|
||||
_lastSavedAt = now;
|
||||
try {
|
||||
if (AndroidDocs.isAvailable) {
|
||||
await AndroidDocs.saveFile(
|
||||
_baseName(path),
|
||||
Uint8List.fromList(utf8.encode(_project.encode())),
|
||||
mime: 'application/json',
|
||||
);
|
||||
} else {
|
||||
await Storage.instance.saveProject(path, _project);
|
||||
}
|
||||
_dirty = false;
|
||||
_status = '已自动保存 ${_baseName(path)}';
|
||||
} catch (_) {
|
||||
_status = '自动保存失败(可手动 Ctrl+S 重试)';
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 设置自动保存(开关与间隔分钟;间隔钳制到 1–240)。
|
||||
void setAutoSave({bool? enabled, int? minutes}) {
|
||||
final bool e = enabled ?? _project.autoSaveEnabled;
|
||||
final int m = (minutes ?? _project.autoSaveMinutes).clamp(1, 240);
|
||||
if (e == _project.autoSaveEnabled && m == _project.autoSaveMinutes) return;
|
||||
_project = _project.copyWith(autoSaveEnabled: e, autoSaveMinutes: m);
|
||||
_dirty = true;
|
||||
_status = e ? '自动保存:每 $m 分钟' : '自动保存:已关闭';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 退出前将自动保存标记为“干净”,表示已正常关闭无需恢复。
|
||||
@@ -189,13 +248,28 @@ class AppController extends ChangeNotifier {
|
||||
_undo.add(_project);
|
||||
if (_undo.length > 200) _undo.removeAt(0);
|
||||
_redo.clear();
|
||||
_project = next;
|
||||
_project = _syncLaneFloor(next);
|
||||
_dirty = true;
|
||||
if (status != null) _status = status;
|
||||
_recomputeCritical();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 维护「保留空泳道」的保底泳道数 [Project.minLaneCount]:
|
||||
/// - 开启时只增不减(动作被全部移走的泳道保留、序号不变);
|
||||
/// - 关闭时收缩为当前实际使用的层数(空泳道自动移除)。
|
||||
static Project _syncLaneFloor(Project p) {
|
||||
int maxLayer = -1;
|
||||
for (final Action a in p.actions) {
|
||||
if (a.layer > maxLayer) maxLayer = a.layer;
|
||||
}
|
||||
final int want = p.keepEmptyLanes
|
||||
? (p.minLaneCount > maxLayer + 1 ? p.minLaneCount : maxLayer + 1)
|
||||
: maxLayer + 1;
|
||||
if (want < 0 || want == p.minLaneCount) return p;
|
||||
return p.copyWith(minLaneCount: want);
|
||||
}
|
||||
|
||||
/// 撤销:弹出 [_undo] 顶部的快照并压入 [_redo],重算关键路径后刷新。
|
||||
void undo() {
|
||||
if (_undo.isEmpty) return;
|
||||
@@ -258,6 +332,7 @@ class AppController extends ChangeNotifier {
|
||||
_filePath = null;
|
||||
_dirty = true;
|
||||
_status = '新建项目';
|
||||
_project = _syncLaneFloor(_project);
|
||||
_recomputeCritical();
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -269,7 +344,7 @@ class AppController extends ChangeNotifier {
|
||||
void loadProject(Project p, {String? path, bool dirty = false}) {
|
||||
_undo.clear();
|
||||
_redo.clear();
|
||||
_project = p;
|
||||
_project = _syncLaneFloor(p);
|
||||
_filePath = path;
|
||||
_dirty = dirty;
|
||||
_status = path == null ? '已载入' : '已打开 ${_baseName(path)}';
|
||||
@@ -422,6 +497,17 @@ class AppController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 设置「保留空泳道」策略:动作全部移走后,泳道保留(序号不变)还是自动移除。
|
||||
///
|
||||
/// 切换为开启时以当前使用中的泳道为保底,避免把历史收缩掉的泳道“补”出来。
|
||||
void setKeepEmptyLanes(bool value) {
|
||||
if (_project.keepEmptyLanes == value) return;
|
||||
_project = _syncLaneFloor(_project.copyWith(keepEmptyLanes: value));
|
||||
_dirty = true;
|
||||
_status = value ? '已开启:保留空泳道' : '已关闭:空泳道自动移除';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// 切换依赖连线的显示/隐藏。
|
||||
void toggleDeps() {
|
||||
_project = _project.copyWith(
|
||||
@@ -498,7 +584,7 @@ class AppController extends ChangeNotifier {
|
||||
final BarLayout l = BarLayout(_project, vp);
|
||||
// 内容逻辑范围:(0,0) → 右缘 + 60、最后一行底部 + 40。
|
||||
final double contentW = l.plotRight + 60;
|
||||
final double contentH = l.yFor(l.ordered.length) + 40;
|
||||
final double contentH = l.plotBottom + 40;
|
||||
z = math.min(vp.width / contentW, vp.height / contentH).clamp(0.25, 1.0);
|
||||
// 关键修复:内容被缩小时按内容范围居中显示;内容本来就能放下时保持默认位置。
|
||||
// (此前固定 pan = 0,缩小的画面会被钉在左上角。)
|
||||
@@ -595,8 +681,6 @@ class AppController extends ChangeNotifier {
|
||||
id = 'A$guard';
|
||||
}
|
||||
final int layer = _project.maxLayer + 1;
|
||||
// 新动作默认排在最后一行(显式行序),避免其相位变化导致行位置跳动。
|
||||
final int row = _project.actions.length;
|
||||
final double start = (startAngle ?? 0).clamp(0, 359);
|
||||
final Action a = Action(
|
||||
id: id,
|
||||
@@ -607,7 +691,7 @@ class AppController extends ChangeNotifier {
|
||||
durationAngle: 45,
|
||||
layer: layer,
|
||||
color: kActionPalette[(_project.actions.length) % kActionPalette.length],
|
||||
row: row,
|
||||
row: 0, // 新动作进入全新泳道(1 槽)的槽位 0
|
||||
);
|
||||
_mutate(
|
||||
_project.copyWith(
|
||||
@@ -667,7 +751,7 @@ class AppController extends ChangeNotifier {
|
||||
name: '${src.name} 副本',
|
||||
startAngle: (src.startAngle + 10).clamp(0, 359),
|
||||
layer: _project.maxLayer + 1,
|
||||
row: _project.actions.length,
|
||||
row: 0,
|
||||
deps: const <Dependency>[],
|
||||
);
|
||||
_mutate(
|
||||
@@ -750,28 +834,72 @@ class AppController extends ChangeNotifier {
|
||||
/// 不再因「目标泳道在该时间段已有动作」而拒绝:换道是高频拖拽操作,一旦拒绝,
|
||||
/// 动作会被“磁吸”回原泳道(表现为拖不动)。现允许放入并在状态栏提示时间重叠,
|
||||
/// 由用户自行调整相位;[canPlaceInLane] 仍用于拖拽时的可视化提示。
|
||||
/// 槽位保持原值(超出目标泳道槽位数时由布局钳制到末槽)。
|
||||
void moveActionLane(String id, int targetLane) {
|
||||
final Action? moving = _project.actionById(id);
|
||||
if (moving == null) return;
|
||||
final int lane = targetLane.clamp(0, 63);
|
||||
if (lane == moving.layer) return;
|
||||
updateAction(id, (Action x) => x.copyWith(layer: lane),
|
||||
status: '移至轨道 L${lane + 1}');
|
||||
}
|
||||
|
||||
/// 将动作 [id] 移动到([targetLane], [slot])——拖拽换道 / 换槽位。
|
||||
///
|
||||
/// 槽位钳制到目标泳道的槽位数范围;同槽时间重叠仅在状态栏提示,不阻止。
|
||||
void moveActionTo(String id, int targetLane, int slot) {
|
||||
final Action? moving = _project.actionById(id);
|
||||
if (moving == null) return;
|
||||
final int lane = targetLane.clamp(0, 63);
|
||||
final int slots = _project.slotsOf(lane);
|
||||
final int s = slot < 0 ? 0 : (slot >= slots ? slots - 1 : slot);
|
||||
if (lane == moving.layer && s == _effectiveSlot(moving)) return;
|
||||
final bool overlap = _project.actions.any((Action o) =>
|
||||
o.id != id &&
|
||||
o.layer == lane &&
|
||||
_effectiveSlot(o) == s &&
|
||||
angleRangesOverlap(moving.startAngle, moving.endAngle, o.startAngle, o.endAngle));
|
||||
updateAction(id, (Action x) => x.copyWith(layer: lane, row: lane),
|
||||
updateAction(id, (Action x) => x.copyWith(layer: lane, row: s),
|
||||
status: overlap
|
||||
? '移至轨道 L${lane + 1}(与该轨道动作时间重叠)'
|
||||
: '移至轨道 L${lane + 1}');
|
||||
? '移至 L${lane + 1} · 槽 ${s + 1}(有动作时间重叠)'
|
||||
: '移至 L${lane + 1} · 槽 ${s + 1}');
|
||||
}
|
||||
|
||||
/// 目标泳道 [lane] 是否能容纳动作 [id](不与其内动作时间重叠)。
|
||||
bool canPlaceInLane(String id, int lane) {
|
||||
/// 动作 [a] 在其泳道内的有效槽位(与布局层 [BarLayout.slotOf] 一致)。
|
||||
int _effectiveSlot(Action a) {
|
||||
final int slots = _project.slotsOf(a.layer);
|
||||
if (slots <= 1) return 0;
|
||||
final int r = a.row;
|
||||
return r < 0 ? 0 : (r >= slots ? slots - 1 : r);
|
||||
}
|
||||
|
||||
/// 设置泳道 [lane] 的槽位数(1–5)——「泳道加宽」:同一泳道可并列放置多个动作。
|
||||
///
|
||||
/// 缩窄时超出的动作不会被删除,其槽位在布局时钳制到末槽。
|
||||
void setLaneSlots(int lane, int slots) {
|
||||
final int n = slots.clamp(1, 5);
|
||||
if (_project.slotsOf(lane) == n) return;
|
||||
final Map<int, int> next = Map<int, int>.of(_project.laneSlots);
|
||||
if (n <= 1) {
|
||||
next.remove(lane);
|
||||
} else {
|
||||
next[lane] = n;
|
||||
}
|
||||
_mutate(
|
||||
_project.copyWith(laneSlots: next),
|
||||
status: n > 1 ? '泳道 L${lane + 1} 已加宽为 $n 槽(可并列 $n 个动作)' : '泳道 L${lane + 1} 恢复 1 槽',
|
||||
);
|
||||
}
|
||||
|
||||
/// 目标泳道 [lane](可选 [slot],默认取动作当前槽位)能否容纳动作 [id]。
|
||||
bool canPlaceInLane(String id, int lane, {int? slot}) {
|
||||
final Action? a = _project.actionById(id);
|
||||
if (a == null) return false;
|
||||
final int s = slot ?? _effectiveSlot(a);
|
||||
return !_project.actions.any((Action o) =>
|
||||
o.id != id &&
|
||||
o.layer == lane &&
|
||||
_effectiveSlot(o) == s &&
|
||||
angleRangesOverlap(a.startAngle, a.endAngle, o.startAngle, o.endAngle));
|
||||
}
|
||||
|
||||
|
||||
+86
-8
@@ -18,6 +18,7 @@ import 'package:flutter/services.dart';
|
||||
import '../export/drawio_writer.dart';
|
||||
import '../export/export_renderer.dart';
|
||||
import '../export/svg_writer.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../persistence/android_docs.dart';
|
||||
@@ -1179,7 +1180,7 @@ class _AppShellState extends State<AppShell> {
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
_sectionLabel(t, '时序创建和编辑'),
|
||||
_sectionLabel(t, '文档设置'),
|
||||
const Spacer(),
|
||||
_panelControls(t, true),
|
||||
],
|
||||
@@ -1188,14 +1189,14 @@ class _AppShellState extends State<AppShell> {
|
||||
_editEntry(
|
||||
t,
|
||||
icon: Icons.edit_note,
|
||||
label: '编辑时序与节拍参数',
|
||||
label: '文档设置',
|
||||
enabled: !flow,
|
||||
onTap: () => showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => SettingsDialog(controller: c),
|
||||
),
|
||||
),
|
||||
// 较浅的分隔横线,区分上方「时序创建和编辑」与下方「动作和执行编辑」。
|
||||
// 较浅的分隔横线,区分上方「文档设置」与下方「动作和执行编辑」。
|
||||
const SizedBox(height: 14),
|
||||
Divider(height: 1, thickness: 1, color: t.line),
|
||||
const SizedBox(height: 14),
|
||||
@@ -1358,6 +1359,35 @@ class _AppShellState extends State<AppShell> {
|
||||
return Tooltip(message: '流程图只读:修改请切回条形 / 圆周视图', child: card);
|
||||
}
|
||||
|
||||
/// 左侧栏的泳道槽位小徽标:显示当前槽位数,点击可调整(1–5 槽)。
|
||||
///
|
||||
/// 槽位数 > 1 时高亮显示(多槽位泳道内动作按子行并列放置)。
|
||||
Widget _laneSlotChip(Tokens t, int lane) {
|
||||
final int n = c.project.slotsOf(lane);
|
||||
return Builder(
|
||||
builder: (BuildContext ctx) => Tooltip(
|
||||
message: '泳道 L${lane + 1} 槽位数:$n(点击调整,最多 5)',
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
onTap: () async {
|
||||
final RenderBox box = ctx.findRenderObject()! as RenderBox;
|
||||
await showLaneSlotMenu(context, c, box.localToGlobal(Offset.zero), lane);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: n > 1 ? t.accent.withValues(alpha: 0.14) : t.panel2,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: n > 1 ? t.accent.withValues(alpha: 0.4) : t.line2),
|
||||
),
|
||||
child: Text('$n 槽',
|
||||
style: TextStyle(color: n > 1 ? t.accent : t.dim, fontSize: 10)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 动作列表小节标题右侧的紧凑按钮(新建 / 删除)。
|
||||
///
|
||||
/// [onTap] 为 null 时按钮呈禁用态(降低不透明度),用于「未选中动作时禁用删除」。
|
||||
@@ -1385,12 +1415,17 @@ class _AppShellState extends State<AppShell> {
|
||||
|
||||
/// 左侧栏:按泳道 / 轨道分组的行列表。
|
||||
List<Widget> _laneRows(Tokens t, bool bar) {
|
||||
final List<int> lanes = <int>{for (final Action a in c.project.actions) a.layer}.toList()..sort();
|
||||
final List<int> lanes = c.project.renderLanes;
|
||||
final List<Widget> out = <Widget>[];
|
||||
for (int li = 0; li < lanes.length; li++) {
|
||||
final int lane = lanes[li];
|
||||
final List<Action> acts = c.project.actions.where((Action a) => a.layer == lane).toList()
|
||||
..sort((Action a, Action b) => a.startAngle.compareTo(b.startAngle));
|
||||
// 空泳道(开启「保留空泳道」后动作被全部移走):显示占位行。
|
||||
if (acts.isEmpty) {
|
||||
out.add(_emptyLaneRow(t, lane, li));
|
||||
continue;
|
||||
}
|
||||
// 单动作泳道沿用普通动作行;多动作泳道合并显示。
|
||||
out.add(acts.length == 1
|
||||
? _actionRow(t, acts.first, li, bar)
|
||||
@@ -1399,6 +1434,42 @@ class _AppShellState extends State<AppShell> {
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 左侧栏中的空泳道占位行(开启「保留空泳道」后,动作被全部移走的泳道)。
|
||||
Widget _emptyLaneRow(Tokens t, int lane, int li) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: t.line),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 22,
|
||||
height: 22,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel2,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text('${li + 1}',
|
||||
style: TextStyle(color: t.dim, fontSize: 11, fontWeight: FontWeight.w700)),
|
||||
),
|
||||
const SizedBox(width: 9),
|
||||
Expanded(
|
||||
child: Text('空泳道(已保留,可拖入动作)',
|
||||
style: TextStyle(color: t.dim, fontSize: 11)),
|
||||
),
|
||||
_laneSlotChip(t, lane),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 单条泳道 / 轨道行:多个动作合并显示(≤2 行,/ 分隔)。
|
||||
Widget _laneRow(Tokens t, int lane, int li, List<Action> acts, bool bar) {
|
||||
if (acts.isEmpty) return const SizedBox.shrink();
|
||||
@@ -1454,7 +1525,8 @@ class _AppShellState extends State<AppShell> {
|
||||
children: <Widget>[
|
||||
Text(
|
||||
joined,
|
||||
maxLines: 2,
|
||||
// 多槽位泳道允许更多行(最多与槽位数一致),持续自动换行。
|
||||
maxLines: math.max(2, c.project.slotsOf(lane)),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: sel ? t.text : t.text2,
|
||||
@@ -1492,6 +1564,8 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
_laneSlotChip(t, lane),
|
||||
const SizedBox(width: 4),
|
||||
InkWell(
|
||||
onTap: flow
|
||||
? null
|
||||
@@ -1561,7 +1635,9 @@ class _AppShellState extends State<AppShell> {
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: sel ? t.text : t.text2, fontSize: 12, fontWeight: sel ? FontWeight.w600 : FontWeight.normal)),
|
||||
Text('${a.id} · ${st?.name ?? a.stationId} · ${a.driver}',
|
||||
Text(
|
||||
'${a.id} · ${st?.name ?? a.stationId} · ${a.driver}'
|
||||
'${c.project.slotsOf(a.layer) > 1 ? ' · 槽 ${effectiveSlot(c.project, a) + 1}' : ''}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
@@ -1589,6 +1665,8 @@ class _AppShellState extends State<AppShell> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
_laneSlotChip(t, a.layer),
|
||||
const SizedBox(width: 4),
|
||||
InkWell(
|
||||
onTap: flow
|
||||
? null
|
||||
@@ -2160,9 +2238,9 @@ class _AppShellState extends State<AppShell> {
|
||||
'相位 360° = 100%',
|
||||
'动作 ${c.project.actions.length}',
|
||||
'依赖 ${_depCount()}',
|
||||
circular ? '轨道 L1–L${c.project.laneCount}' : '工位 ${c.project.stations.length}',
|
||||
circular ? '轨道 L1–L${c.project.renderLaneCount}' : '工位 ${c.project.stations.length}',
|
||||
mode == ViewMode.flow
|
||||
? '泳道 L1–L${c.project.laneCount}(流程节点 ${c.project.actions.length})'
|
||||
? '泳道 L1–L${c.project.renderLaneCount}(流程节点 ${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)}',
|
||||
|
||||
@@ -318,7 +318,10 @@ class _SelectedCard extends StatelessWidget {
|
||||
_kv(t, '结束相位', pfmt(a.endAngle, u)),
|
||||
_kv(t, '持续相位', pfmt(a.durationAngle, u)),
|
||||
const SizedBox(height: 4),
|
||||
Text('Δ = $delta · 层 L${a.layer + 1} · ${st?.id ?? a.stationId}',
|
||||
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)),
|
||||
],
|
||||
),
|
||||
|
||||
+38
-15
@@ -204,7 +204,7 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
} else {
|
||||
final CircularLayout layout = CircularLayout(c.project, size);
|
||||
for (final Action a in c.project.actions) {
|
||||
final double r = layout.radiusFor(a.layer);
|
||||
final double r = layout.radiusFor(a.layer, layout.slotOf(a));
|
||||
final double ds = (p - polar(layout.center, r, a.startAngle)).distance;
|
||||
final double de = (p - polar(layout.center, r, math.min(a.endAngle, 360))).distance;
|
||||
if (ds < bestDist) {
|
||||
@@ -478,6 +478,14 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
_renameZone(zi);
|
||||
return;
|
||||
}
|
||||
// 双击左侧泳道编号区(图外空白):打开泳道槽位菜单(加宽 / 恢复)。
|
||||
if (p.dx < BarLayout.leftGutter) {
|
||||
final BarLayout layout = BarLayout(c.project, size);
|
||||
if (layout.lanes.isNotEmpty) {
|
||||
_laneSlotMenu(d.globalPosition, layout.laneAt(p.dy));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
final Action? hit = c.project.viewState.mode == ViewMode.bar
|
||||
? BarLayout(c.project, size).hitTest(p, slop: _hitSlop)
|
||||
@@ -688,17 +696,16 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
status: '调整起始角',
|
||||
);
|
||||
} else {
|
||||
// 整体移动:水平改起始相位 + 垂直跟随泳道,两者可同时进行。
|
||||
// (原先要求「垂直分量明显大于水平」才换道,斜向拖拽几乎换不了道,
|
||||
// 表现为“有一股磁吸力、拖不到别的泳道”。)
|
||||
// 整体移动:水平改起始相位 + 垂直跟随泳道 / 槽位,两者可同时进行。
|
||||
c.setActionStart(_dragAction!.id, _startAngle + dx / layout.span * 360);
|
||||
final int curLane =
|
||||
c.project.actionById(_dragAction!.id)?.layer ?? _dragAction!.layer;
|
||||
final int target = layout.laneAt(p.dy);
|
||||
if (target != curLane) {
|
||||
_dropLane = target;
|
||||
_dropValid = c.canPlaceInLane(_dragAction!.id, target);
|
||||
c.moveActionLane(_dragAction!.id, target);
|
||||
final Action? cur = c.project.actionById(_dragAction!.id);
|
||||
final int curLane = cur?.layer ?? _dragAction!.layer;
|
||||
final int curSlot = cur == null ? 0 : layout.slotOf(cur);
|
||||
final (int, int) target = layout.laneSlotAt(p.dy);
|
||||
if (target.$1 != curLane || target.$2 != curSlot) {
|
||||
_dropLane = target.$1;
|
||||
_dropValid = c.canPlaceInLane(_dragAction!.id, target.$1, slot: target.$2);
|
||||
c.moveActionTo(_dragAction!.id, target.$1, target.$2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -724,9 +731,10 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
status: '调整起始角',
|
||||
);
|
||||
} else if (shift) {
|
||||
// Shift + 径向拖拽:换轨道(同轨道可放多个不重叠动作)。
|
||||
// Shift + 径向拖拽:换轨道 / 换子环(槽位)。
|
||||
final double rad = (p - layout.center).distance;
|
||||
c.moveActionLane(_dragAction!.id, layout.laneAtRadius(rad));
|
||||
final (int, int) t = layout.laneSlotAtRadius(rad);
|
||||
c.moveActionTo(_dragAction!.id, t.$1, t.$2);
|
||||
} else {
|
||||
c.setActionStart(_dragAction!.id, _startAngle + delta);
|
||||
}
|
||||
@@ -866,8 +874,17 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
? BarLayout(c.project, size).hitTest(local)
|
||||
: CircularLayout(c.project, size).hitTest(local);
|
||||
if (hit == null) {
|
||||
// 未命中动作:若命中依赖连线,弹出连线菜单。
|
||||
if (depKey != null) await _depMenu(global, depKey);
|
||||
// 未命中动作:先看依赖连线,其次(条形视图)提供泳道槽位菜单。
|
||||
if (depKey != null) {
|
||||
await _depMenu(global, depKey);
|
||||
return;
|
||||
}
|
||||
if (c.project.viewState.mode == ViewMode.bar) {
|
||||
final BarLayout layout = BarLayout(c.project, size);
|
||||
if (layout.lanes.isNotEmpty) {
|
||||
await _laneSlotMenu(global, layout.laneAt(local.dy));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
c.select(hit.id);
|
||||
@@ -925,6 +942,12 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 泳道槽位菜单(实现见 [showLaneSlotMenu],画布与侧栏共用)。
|
||||
///
|
||||
/// 入口:双击条形视图左侧泳道编号区 / 右键空白泳道。
|
||||
Future<void> _laneSlotMenu(Offset global, int lane) =>
|
||||
showLaneSlotMenu(context, c, global, lane);
|
||||
|
||||
/// 相位分区右键菜单:重命名 / 插入 / 删除,实现任意增减。
|
||||
Future<void> _zoneMenu(Offset global, int index) async {
|
||||
final RenderBox box = context.findRenderObject()! as RenderBox;
|
||||
|
||||
+150
-53
@@ -5,7 +5,7 @@
|
||||
// 包含:
|
||||
// · 通用消息提示(showMessage);
|
||||
// · .seq.json 文件浏览/保存对话框(FileBrowserDialog / pickFile);
|
||||
// · 动作编辑、依赖编辑、工艺参数设置、帮助中心等业务对话框。
|
||||
// · 动作编辑、依赖编辑、文档设置、帮助中心等业务对话框。
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
@@ -18,6 +18,7 @@ import '../persistence/android_docs.dart';
|
||||
import '../persistence/storage.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../version.dart';
|
||||
import 'app_logo.dart';
|
||||
|
||||
// ===================== 对话框等比缩放 =====================
|
||||
@@ -876,7 +877,7 @@ class _ActionEditorDialogState extends State<ActionEditorDialog> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// 按时间输入:与角度实时双向换算(单位随工艺参数设置)。
|
||||
// 按时间输入:与角度实时双向换算(单位随文档设置)。
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
@@ -1045,22 +1046,57 @@ class _DependencyEditorDialogState extends State<DependencyEditorDialog> {
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== 工艺参数设置对话框 =====================
|
||||
// ===================== 文档设置对话框 =====================
|
||||
|
||||
/// 工艺参数对话框:设置项目名称、时间/相位单位、显示精度、
|
||||
/// 循环时长、换算表与编辑辅助选项。
|
||||
/// 泳道槽位菜单:把泳道加宽为 1–5 槽(同一泳道并列放置多个动作),或恢复 1 槽。
|
||||
///
|
||||
/// 入口:双击条形视图左侧泳道编号区 / 右键空白泳道 / 左侧栏「N 槽」徽标。
|
||||
/// 加宽后同一泳道的动作按 `Action.row`(槽位)分成多条并排行,
|
||||
/// 圆周视图与流程图同样按槽位分行 / 分环 / 分列。
|
||||
Future<void> showLaneSlotMenu(
|
||||
BuildContext context, AppController controller, Offset global, int lane) async {
|
||||
final RenderBox box = context.findRenderObject()! as RenderBox;
|
||||
final Offset pos = box.globalToLocal(global);
|
||||
final int cur = controller.project.slotsOf(lane);
|
||||
final String? result = await showMenu<String>(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(pos.dx, pos.dy, pos.dx, pos.dy),
|
||||
items: <PopupMenuEntry<String>>[
|
||||
const PopupMenuItem<String>(
|
||||
enabled: false,
|
||||
height: 34,
|
||||
child: Text('泳道槽位数(并列动作数)', style: TextStyle(fontSize: 11.5)),
|
||||
),
|
||||
for (int i = 1; i <= 5; i++)
|
||||
PopupMenuItem<String>(
|
||||
value: '$i',
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text(i == cur ? '✓' : '', style: const TextStyle(fontSize: 12)),
|
||||
const SizedBox(width: 6),
|
||||
Text('$i 槽${i == cur ? '(当前)' : ''}'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
if (result != null) controller.setLaneSlots(lane, int.tryParse(result) ?? 1);
|
||||
}
|
||||
|
||||
/// 文档设置对话框:设置项目名称、时间/相位单位、显示精度、
|
||||
/// 循环时长、泳道策略、换算表与编辑辅助选项。
|
||||
class SettingsDialog extends StatefulWidget {
|
||||
const SettingsDialog({super.key, required this.controller});
|
||||
|
||||
/// 全局应用控制器。
|
||||
final AppController controller;
|
||||
|
||||
/// 创建工艺参数对话框对应的状态对象。
|
||||
/// 创建文档设置对话框对应的状态对象。
|
||||
@override
|
||||
State<SettingsDialog> createState() => _SettingsDialogState();
|
||||
}
|
||||
|
||||
/// 工艺参数对话框状态:以副本形式编辑单位设置,点击“应用”后统一提交。
|
||||
/// 文档设置对话框状态:以副本形式编辑单位设置,点击“应用”后统一提交。
|
||||
class _SettingsDialogState extends State<SettingsDialog> {
|
||||
/// 正在编辑的单位设置副本。
|
||||
late UnitSettings _u;
|
||||
@@ -1081,7 +1117,7 @@ class _SettingsDialogState extends State<SettingsDialog> {
|
||||
_name = TextEditingController(text: widget.controller.project.name);
|
||||
}
|
||||
|
||||
/// 渲染工艺参数表单:项目名、单位、精度、循环、换算表与编辑辅助。
|
||||
/// 渲染文档设置表单:项目名、单位、精度、循环、泳道、换算表与编辑辅助。
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
@@ -1100,7 +1136,7 @@ class _SettingsDialogState extends State<SettingsDialog> {
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text('工艺参数', style: TextStyle(fontSize: 17, fontWeight: FontWeight.w700, color: t.text)),
|
||||
Text('文档设置', style: TextStyle(fontSize: 17, fontWeight: FontWeight.w700, color: t.text)),
|
||||
const SizedBox(width: 14),
|
||||
Text('单位与精度 / 循环与相位 / 编辑辅助',
|
||||
style: TextStyle(fontSize: 11, color: t.dim)),
|
||||
@@ -1254,6 +1290,61 @@ class _SettingsDialogState extends State<SettingsDialog> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
// 泳道策略:动作全部移走后,泳道保留还是自动移除。
|
||||
Text('泳道', style: TextStyle(color: t.sub, fontSize: 11)),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
children: <Widget>[
|
||||
FilterChip(
|
||||
label: const Text('保留空泳道'),
|
||||
selected: widget.controller.project.keepEmptyLanes,
|
||||
onSelected: (bool v) {
|
||||
widget.controller.setKeepEmptyLanes(v);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'开启:动作全部移走的泳道保留(条形行 / 圆周环 / 流程列,序号不变);关闭:空泳道自动移除、序号顺延。',
|
||||
style: TextStyle(color: t.dim, fontSize: 10.5, height: 1.5),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
// 自动保存:定时把文档写回文件(需已手动保存过一次路径)。
|
||||
Text('自动保存', style: TextStyle(color: t.sub, fontSize: 11)),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 6,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: <Widget>[
|
||||
FilterChip(
|
||||
label: const Text('启用自动保存'),
|
||||
selected: widget.controller.project.autoSaveEnabled,
|
||||
onSelected: (bool v) {
|
||||
widget.controller.setAutoSave(enabled: v);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
for (final int m in <int>[1, 5, 10, 30])
|
||||
ChoiceChip(
|
||||
label: Text('$m 分钟'),
|
||||
selected: widget.controller.project.autoSaveMinutes == m,
|
||||
onSelected: (_) {
|
||||
widget.controller.setAutoSave(minutes: m);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'默认每 10 分钟自动保存一次(可选 1 / 5 / 10 / 30 分钟);需先手动保存过一次(有文件路径)才生效,自动保存会同步更新 .bak 备份。',
|
||||
style: TextStyle(color: t.dim, fontSize: 10.5, height: 1.5),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
// 时间 / 相位换算表:以 90° 为步长展示对应关系。
|
||||
Text('时间 / 相位 换算', style: TextStyle(color: t.sub, fontSize: 11)),
|
||||
const SizedBox(height: 6),
|
||||
@@ -1363,7 +1454,7 @@ class _SettingsDialogState extends State<SettingsDialog> {
|
||||
final double? cv = double.tryParse(_cycle.text);
|
||||
final double ms = cv == null ? cycleMs : cv * kTimeDiv[_u.timeUnit]!;
|
||||
final AppController c = widget.controller;
|
||||
c.setUnits(_u, status: '工艺参数已应用');
|
||||
c.setUnits(_u, status: '文档设置已应用');
|
||||
c.setCycleDuration(ms);
|
||||
if (_name.text.trim().isNotEmpty && _name.text.trim() != c.project.name) {
|
||||
c.setProjectName(_name.text.trim());
|
||||
@@ -1999,12 +2090,15 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['我要删除动作', '选中后:左侧「删除」/ 行内删除图标 / Delete 键 / 右键菜单;至少保留一个动作 / 泳道。'],
|
||||
<String>['我要改动作属性', '双击画布色块(条形块 / 圆弧)或左侧动作行 → 打开动作编辑对话框;也可选中后点左侧行内编辑图标。'],
|
||||
<String>['我要复制 / 对齐', '画布左下角「编辑工具」→「复制」/「对齐」;圆周视图右侧浮动工具条同款。'],
|
||||
<String>['我要编辑工位', '左侧「动作和执行编辑」→「编辑工位」:可增删工位、改名称与颜色、上下调整顺序;删除工位后其动作自动改挂到第一个工位。'],
|
||||
<String>['我要编辑工位', '左侧「动作和执行编辑」→「编辑工位」:可增删工位、改名称与颜色、上下调整顺序;删除工位后其动作自动改挂到第一个工位。工位用于区分“谁在做”,是并行关系的首选维度(同工位并行时再用泳道加宽)。'],
|
||||
<String>['一条泳道放多个动作', '泳道/轨道=一个执行器:上下拖拽(条形)或 Shift+径向拖拽(圆周)换道;不重叠即可共存,标题合并显示(/ 分隔,≤2 行)。'],
|
||||
<String>['泳道加宽(并列动作)', '默认每条泳道 1 槽;并行动作优先用不同工位 / 泳道区分。需要同一泳道并行时:双击条形视图左侧泳道编号(或右键空白泳道 / 点左侧栏「N 槽」徽标)→ 选 1–5 槽(5 为上限);条形分子行、圆周分子环、流程图分子列,槽位间自动留出依赖箭头空间;拖拽动作可同时换道 + 换槽位。'],
|
||||
<String>['空泳道的保留 / 移除', 'F2 文档设置 →「泳道」→ 保留空泳道(默认开):动作全部移走的泳道保留,序号不变;关闭则自动移除、序号顺延。条形空行 / 圆周空环 / 流程图空列与左侧栏同步显示。'],
|
||||
<String>['工位与泳道的关系', '工位 = 物理工位(谁在做:上料 / 加工 / 检测…,可增删改与排序);泳道 = 执行器轨道(并行关系:同一泳道 = 同一执行器,可放多个不重叠动作,加宽后最多 5 个并列)。'],
|
||||
]),
|
||||
// 目标:调整时间轴与动作间的先后 / 并行关系。
|
||||
_section(t, <List<String>>[
|
||||
<String>['我要改时间轴长度', '左侧「时序创建和编辑」→「编辑时序与节拍参数」,或按 F2 →「循环与相位」→ 循环时长 → 应用。'],
|
||||
<String>['我要改时间轴长度', '左侧「文档设置」入口(或按 F2)→「循环与相位」→ 循环时长 → 应用。'],
|
||||
<String>['我要调相位 / 时长', '拖动动作块平移相位;拖条形右端改持续角;圆周视图拖弧两端改起止角;右侧滑杆可精调。'],
|
||||
<String>['我要让动作跨循环', '使「起始角 + 持续角 > 360°」,会自动拆分并以半透明虚线渲染尾段。'],
|
||||
<String>['我要加前置依赖(输入)', '右侧「前置依赖 · 输入」→「添加前置依赖」;或右键动作 →「添加依赖」。'],
|
||||
@@ -2015,7 +2109,7 @@ class HelpDialog extends StatelessWidget {
|
||||
]),
|
||||
// 目标:编辑相位分区并控制画布显示。
|
||||
_section(t, <List<String>>[
|
||||
<String>['相位分区是什么', '把一个循环按角度分成的命名工艺阶段(默认上料 / 加工 / 检测),条形图顶部标注带即它。'],
|
||||
<String>['相位分区是什么', '把一个循环按角度分成的命名工艺阶段(默认上料 / 加工 / 检测):条形图顶部为标注色带、圆周视图为最外圈相位环与径向边界、流程图左侧为竖排阶段栏。可重叠、可留空、>360° 表示跨圈。'],
|
||||
<String>['我要编辑相位分区', '左侧「动作和执行编辑」→「编辑相位分区」;或 F2 →「相位分区」→「编辑…」。增删分区、改名称与起止角;可重叠、可留空、>360° 表示跨圈。'],
|
||||
<String>['我要隐藏相位分区', '左侧「显示选项」取消勾选「相位分区标注」。'],
|
||||
<String>['刻度怎么读', '条形视图:分区带与刻度线之间上排为相位、下排为等价时间;圆周视图:每 30° 的度数外侧标注等价时间。'],
|
||||
@@ -2035,7 +2129,7 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['我要导出 SVG', '顶部「导出」下拉菜单 →「导出 SVG」:矢量、分层、带语义 id 与 data-*,可直接进工艺卡 / MES。'],
|
||||
<String>['我要导出 PNG', '顶部「导出」下拉菜单 →「导出 PNG」:按 2 倍像素比导出当前视图为位图。'],
|
||||
<String>['我要导出 drawio', '流程图视图专用:顶部「导出」→「导出 drawio」,输出 diagrams.net(draw.io)可继续编辑的工程文件。'],
|
||||
<String>['我要保存 / 恢复', '「保存」写入 .seq.json 并生成 .bak;每 5 秒自动快照,异常退出后启动可恢复。'],
|
||||
<String>['我要保存 / 恢复', '「保存」写入 .seq.json 并生成 .bak;每 5 秒自动快照(异常退出可恢复);F2 文档设置中可开启「自动保存」(默认每 10 分钟一次,需先手动保存过一次路径)。'],
|
||||
]),
|
||||
// 目标:调整界面与使用快捷键。
|
||||
_section(t, <List<String>>[
|
||||
@@ -2052,7 +2146,7 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['撤销 / 保存', 'Ctrl+Z / Ctrl+Y 撤销重做;Ctrl+S 保存;Ctrl+O / Ctrl+N 打开 / 新建。'],
|
||||
<String>['帮助入口', '顶部工具栏右侧「?」或 F1 打开帮助中心;画布编辑工具条不重复放置帮助按钮。'],
|
||||
<String>['导出入口', '导出统一放在顶部工具栏「导出」下拉菜单:SVG / PNG 三种视图通用;流程图另有 drawio。'],
|
||||
<String>['其它', 'F2 编辑时序与节拍参数(含单位与相位分区);F3 切换深/浅主题;Delete 删除选中动作。'],
|
||||
<String>['其它', 'F2 文档设置(含单位、循环、泳道与相位分区);F3 切换深/浅主题;Delete 删除选中动作。'],
|
||||
]),
|
||||
// 关于:设计人、版本、版权、授权信息与本机 MAC。
|
||||
_about(context, t),
|
||||
@@ -2096,9 +2190,11 @@ class HelpDialog extends StatelessWidget {
|
||||
Widget _about(BuildContext context, Tokens t) {
|
||||
final bool android = AndroidDocs.isAvailable;
|
||||
final LicenseInfo info = LicenseService.instance.info;
|
||||
final String lic = info.valid
|
||||
? '已授权(${info.filePath?.split(RegExp(r'[\\/]')).last ?? '.lic'})'
|
||||
: '未授权';
|
||||
final String lic = !kLicenseRequired
|
||||
? '已开放(临时免授权)'
|
||||
: (info.valid
|
||||
? '已授权(${info.filePath?.split(RegExp(r'[\\/]')).last ?? '.lic'})'
|
||||
: '未授权');
|
||||
Widget row(String k, String v, {Color? vc}) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Row(
|
||||
@@ -2129,7 +2225,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.3.3(${android ? '安卓版' : 'Windows 版'})',
|
||||
Text('V1.3.4(${android ? '安卓版' : 'Windows 版'})',
|
||||
style: TextStyle(color: t.dim, fontSize: 12)),
|
||||
],
|
||||
),
|
||||
@@ -2140,15 +2236,16 @@ class HelpDialog extends StatelessWidget {
|
||||
row('设计人', '呆头鹅'),
|
||||
row(
|
||||
'授权状态',
|
||||
android ? '已授权(安卓版免授权)' : lic,
|
||||
vc: (android || info.valid) ? t.ok : t.danger,
|
||||
!kLicenseRequired ? '开放授权版本' : (android ? '已授权(安卓版免授权)' : lic),
|
||||
vc: (android || !kLicenseRequired || info.valid) ? t.ok : t.danger,
|
||||
),
|
||||
if (!android)
|
||||
// 注意:绝不能展示「期望授权串」——它等同于 .lic 内容,公开即可被绕过授权。
|
||||
row('本机 MAC', info.mac ?? '读取失败'),
|
||||
row('版权声明', 'Copyright © 2026 呆头鹅。保留所有权利。'),
|
||||
row('产品简介', '面向 PLC 流程节拍 / 相位角设计的时序图工具:条形 / 圆周双视图、'
|
||||
'FS / SS 依赖与关键路径、SVG / PNG 导出,成果可直接进工艺卡与 MES。'),
|
||||
row('版权声明', 'Copyright © 2026 EDC(Easy Design Collection)呆头鹅。保留所有权利。'),
|
||||
row('产品简介', '面向 PLC 流程节拍 / 相位角设计的设计工具:条形 / 圆周 / 流程图三视图、'
|
||||
'FS / SS 依赖与关键路径、泳道加宽(多槽位)与空泳道策略、依赖走线可调、'
|
||||
'支持导出 SVG / PNG / drawio,成果可直接进工艺卡与 MES。'),
|
||||
const SizedBox(height: 6),
|
||||
// 官网入口(点击导航到 sincos.cc)。
|
||||
Row(
|
||||
@@ -2171,34 +2268,35 @@ class HelpDialog extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (!android)
|
||||
// 授权指南(桌面版:按本机 MAC 申请 .lic)。
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: t.info,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: t.line),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.menu_book_outlined, size: 16, color: t.accent),
|
||||
const SizedBox(width: 6),
|
||||
Text('授权指南', style: TextStyle(color: t.accent, fontSize: 12.5, fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
guideLine('1. 复制上方「本机 MAC」。'),
|
||||
guideLine('2. 访问官网 sincos.cc,或把 MAC 发送到邮箱 liuyu65@126.com 申请授权。'),
|
||||
guideLine('3. 收到 .lic 文件后,放入软件目录下的 license 文件夹,重启软件即可导出 SVG / PNG。'),
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
// 安卓版说明:免授权 + 保存位置 + 反馈方式。
|
||||
// 开发者与交流群(原「授权指南」位置;授权恢复后回补授权指南)。
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: t.info,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: t.line),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.groups_outlined, size: 16, color: t.accent),
|
||||
const SizedBox(width: 6),
|
||||
Text('开发者与交流群',
|
||||
style: TextStyle(color: t.accent, fontSize: 12.5, fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
guideLine('开发者邮箱:liuyu65@126.com'),
|
||||
guideLine('设计交流群:添加开发者微信 online-goose,加入「设计与制造业设计交流群」。'),
|
||||
guideLine('官网:sincos.cc'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (android)
|
||||
// 安卓版说明:免授权 + 保存位置。
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
@@ -2220,7 +2318,6 @@ class HelpDialog extends StatelessWidget {
|
||||
guideLine('本版面向应用商店分发,无需授权,全部功能可用。'),
|
||||
guideLine('保存 / 导出文件位于「文件管理」可见的公共目录(默认 Documents/SequenceDiagram,'
|
||||
'可在保存对话框中更改位置)。'),
|
||||
guideLine('帮助与反馈:官网 sincos.cc 或邮箱 liuyu65@126.com。'),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -207,6 +207,11 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'将直接升级到最新版本 v${info.version}(无需逐版本安装)',
|
||||
style: TextStyle(color: t.accent, fontSize: 11),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'安装包:${info.assetName}${sizeText.isEmpty ? '' : '($sizeText)'}',
|
||||
style: TextStyle(color: t.dim, fontSize: 11),
|
||||
@@ -256,7 +261,7 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
||||
),
|
||||
if (_busy && _progress >= 0)
|
||||
Text('${(_progress * 100).clamp(0, 100).toStringAsFixed(0)}% · '
|
||||
'${(_received / 1048576).toStringAsFixed(1)} MB',
|
||||
'${(_received / 1048576).toStringAsFixed(1)} MB · 限速 320KB/s',
|
||||
style: TextStyle(color: t.dim, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
@@ -279,6 +284,29 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
||||
height: 1.5)),
|
||||
),
|
||||
],
|
||||
// 下载提示:明确提醒保持屏幕常亮与网络连接,避免下载中断。
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: t.warn.withValues(alpha: 0.10),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: t.warn.withValues(alpha: 0.35)),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Icon(Icons.lightbulb_outline, size: 15, color: t.warn),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'下载更新过程中,请确保屏幕保持长亮、网络持续连接,避免更新包下载中断。',
|
||||
style: TextStyle(color: t.warn, fontSize: 11.5, height: 1.5),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// 操作按钮
|
||||
|
||||
@@ -80,6 +80,12 @@ bool isNewerVersion(String remote, String current) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// 客户端下载限速(字节/秒):更新包下载时主动限速,降低自建服务器带宽压力。
|
||||
///
|
||||
/// 实现方式:边收边按目标速率等待(TCP 反压会让服务端发送同步变慢),
|
||||
/// 因此即使多端并发,每端最多占用该速率,不会把服务器的带宽打满。
|
||||
const int kUpdateDownloadLimit = 320 * 1024;
|
||||
|
||||
/// 更新服务:检查 + 下载。
|
||||
class UpdateService {
|
||||
UpdateService._();
|
||||
@@ -165,10 +171,15 @@ class UpdateService {
|
||||
await f.parent.create(recursive: true);
|
||||
sink = f.openWrite();
|
||||
int received = 0;
|
||||
final Stopwatch sw = Stopwatch()..start();
|
||||
await for (final List<int> chunk in res) {
|
||||
if (isCancelled?.call() ?? false) throw Exception('已取消');
|
||||
sink.add(chunk);
|
||||
received += chunk.length;
|
||||
// 主动限速(默认 320KB/s):读得过快时按目标速率补齐等待。
|
||||
final int expectedMs = received * 1000 ~/ kUpdateDownloadLimit;
|
||||
final int aheadMs = expectedMs - sw.elapsedMilliseconds;
|
||||
if (aheadMs > 0) await Future<void>.delayed(Duration(milliseconds: aheadMs));
|
||||
onProgress?.call(total > 0 ? received / total : -1, received);
|
||||
}
|
||||
await sink.flush();
|
||||
|
||||
+7
-1
@@ -2,4 +2,10 @@
|
||||
///
|
||||
/// 应用内更新检查用它判断服务器发布的版本是否更新;
|
||||
/// **每次发版必须与 pubspec 同步更新**(见 BUILD-NOTES 的发布流程)。
|
||||
const String kAppVersion = '1.3.3';
|
||||
const String kAppVersion = '1.3.4';
|
||||
|
||||
/// 是否要求授权(License)才能导出。
|
||||
///
|
||||
/// 1.3.4 起**临时冻结授权校验**:桌面版导出不再要求 `.lic` 授权文件,
|
||||
/// 待功能进一步丰富后再恢复(恢复时改为 `true` 并把本注释删掉)。
|
||||
const bool kLicenseRequired = false;
|
||||
|
||||
Reference in New Issue
Block a user