feat(V1.0.1): 泳道/轨道支持多动作(同执行器多条不重叠);圆周弧可拖拽端点;依赖标签沿弧避让

- 泳道模型:layer 兼作泳道/轨道编号,同一泳道可放多个互不重叠动作(角区间重叠校验)
- 条形:上下拖拽换道;圆周:Shift+径向拖拽换轨;冲突时拒绝并提示
- 泳道标题合并显示(/ 分隔,≤2 行);左侧列表按泳道分组
- 圆周动作弧支持拖拽两端改起止角(弱吸附 + 径向虚线参考),整体拖拽旋转
- 圆周依赖标签沿圆弧切向排布,落入环间空隙,避免压住动作弧
- 版本 1.0.1+2;帮助/README 补充泳道说明;重新构建 dist
This commit is contained in:
呆头鹅
2026-09-18 17:54:35 +08:00
parent 279cc2318f
commit 339b96c73f
11 changed files with 483 additions and 196 deletions
+84 -32
View File
@@ -58,35 +58,43 @@ List<List<double>> splitArcs(double a0, double a1) {
/// 计算动作在条形视图中的行顺序。
///
/// 规则:
/// 1. 先按「工位 order → 起始角 → id」得到**自动顺序**;
/// 2. 若存在显式行序(`Action.row >= 0`),则显式行序优先,其余按自动顺序追加。
///
/// 这样一旦用户上下拖拽过行,行位置就固定下来,**不会再随相位变化而跳动**,
/// 依赖箭头也就不会在水平拖动时乱跳。
/// **泳道模型**:`Action.layer` 同时作为「泳道 / 圆周轨道」编号,
/// 对应一个物理执行器;同一泳道可容纳**多个互不重叠**的动作。
/// 排序规则:先按泳道号,再按起始角,最后按 id。
List<Action> orderActions(Project project) {
final List<Action> list = List<Action>.of(project.actions);
list.sort((Action a, Action b) {
final int sa = project.stationById(a.stationId)?.order ?? 0;
final int sb = project.stationById(b.stationId)?.order ?? 0;
if (sa != sb) return sa.compareTo(sb);
if (a.layer != b.layer) return a.layer.compareTo(b.layer);
final int c = a.startAngle.compareTo(b.startAngle);
if (c != 0) return c;
return a.id.compareTo(b.id);
});
final bool hasExplicit = list.any((Action a) => a.row >= 0);
if (hasExplicit) {
final List<Action> explicit = list.where((Action a) => a.row >= 0).toList()
..sort((Action a, Action b) => a.row.compareTo(b.row));
final List<Action> auto = list.where((Action a) => a.row < 0).toList();
list
..clear()
..addAll(explicit)
..addAll(auto);
}
return list;
}
/// 判断两条角度区间是否重叠(用于同一泳道内“动作不可重叠”的约束)。
///
/// 参数均为角度区间 `[start, end]`;跨圈(end > 360)按模 360 归一后判断。
bool angleRangesOverlap(double s1, double e1, double s2, double e2) {
// 归一到 [0,360),并把跨圈区间拆成两段后逐一比较。
List<List<double>> seg(double s, double e) {
double a = s % 360;
if (a < 0) a += 360;
double b = e % 360;
if (b < 0) b += 360;
if (e - s >= 360) return <List<double>>[<double>[0, 360]];
if (b >= a) return <List<double>>[<double>[a, b]];
return <List<double>>[<double>[a, 360], <double>[0, b]];
}
for (final List<double> x in seg(s1, e1)) {
for (final List<double> y in seg(s2, e2)) {
if (x[0] < y[1] - 0.001 && y[0] < x[1] - 0.001) return true;
}
}
return false;
}
/// 条形(甘特)视图布局。
///
/// 横轴为相位角(0°–360°),纵轴为动作行。行顺序由 [ordered] 决定,
@@ -97,8 +105,8 @@ class BarLayout {
/// 参数 [project]:项目数据;[size]:可用画布尺寸。
/// 副作用:初始化 [pitch]。
BarLayout(this.project, this.size) {
// 可用高度 = 总高 - 顶部留白 - 底部预留;按动作数均分并夹取到 [46, 66]。
final int n = project.actions.length;
// 可用高度 = 总高 - 顶部留白 - 底部预留;按**泳道数**均分并夹取到 [46, 66]。
final int n = lanes.length;
final double usable = size.height - topPad - bottomReserve;
pitch = n == 0 ? 66 : (usable / n).clamp(46, 66);
}
@@ -139,18 +147,41 @@ 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;
}
/// 泳道号在 [lanes] 中的序号。
int laneIndexOf(int lane) => lanes.indexOf(lane);
/// 泳道内包含的动作(按起始角排序)。
List<Action> actionsInLane(int lane) =>
ordered.where((Action a) => a.layer == lane).toList();
/// 泳道号转纵坐标(该泳道顶部 y)。
double yForLane(int lane) => topPad + laneIndexOf(lane) * pitch;
/// 行索引转纵坐标(按泳道序号)。
double yFor(int index) => topPad + index * pitch;
/// 由纵坐标反查最近的泳道号(用于拖拽换道)。
int laneAt(double y) {
if (lanes.isEmpty) return 0;
final int i = ((y - topPad) / pitch).round().clamp(0, lanes.length - 1);
return lanes[i];
}
/// 相位角(度)转横坐标;角度先钳制到 `[0, 360]`。
double xFor(double deg) => plotLeft + (deg.clamp(0, 360) / 360) * span;
/// 行索引转纵坐标(该行顶部 y)。
double yFor(int index) => topPad + index * pitch;
/// 计算动作 [a] 的条形矩形。
/// 计算动作 [a] 的条形矩形(按所属泳道的 y)。
///
/// 宽度至少为 3px,避免极短动作不可见;跨圈部分会被截断到 360°。
Rect rectFor(Action a) {
final int i = ordered.indexOf(a);
final double y = yFor(i);
final double y = yForLane(a.layer);
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);
@@ -183,10 +214,11 @@ class CircularLayout {
CircularLayout(this.project, this.size) {
// 圆心略微下移 18px 以平衡顶部刻度标签的视觉重心。
center = Offset(size.width / 2, size.height / 2 + 18);
final int layers = project.maxLayer + 1;
// 轨道数 = 泳道数(layer 去重),同一轨道可放多个互不重叠的动作。
final int layers = lanes.length;
// 最大半径受较短边约束,减去 74px 留给刻度与边距。
final double maxR = math.min(size.width, size.height) / 2 - 74;
// 在 r0 与 maxR 之间均分各层,环间距夹取到 [24, 46]。
// 在 r0 与 maxR 之间均分各轨道,环间距夹取到 [24, 46]。
pitch = layers <= 1 ? 40 : ((maxR - r0) / (layers - 1)).clamp(24, 46);
// 动作环带宽度:相对行距收窄(约 0.56),并夹取到 [12, 26],
// 让环与环之间留出呼吸空间、文字仍能容纳。
@@ -211,11 +243,31 @@ class CircularLayout {
/// 环的视觉宽度(像素)。
late final double ringWidth;
/// 第 [layer] 层对应的环半径。
double radiusFor(int layer) => r0 + layer * pitch;
/// 轨道编号(= 泳道):所有动作 `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;
}
/// 轨道号在 [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] 条轨道对应的环半径(未知轨道回退到最内圈)。
double radiusFor(int lane) {
final int i = laneIndexOf(lane);
return r0 + (i < 0 ? 0 : i) * pitch;
}
/// 最外层半径。
double get rMax => radiusFor(project.maxLayer);
double get rMax => lanes.isEmpty ? r0 : radiusFor(lanes.last);
/// 刻度标签所在的半径(最外层再向外偏移)。
/// 刻度环半径:在外层动作环之外留出足够间距,