b902fa06c4
- 新增共享走线模块 lib/layout/dep_routes.dart:条形 / 圆周的走线、标签 挂钩与外移判定、命中测试统一到同一份几何(绘制与命中不再各算一套); - 自动错开:同一走线分组(同泳道 / 相邻泳道对 / 跨行对)内的多条依赖 依次 ±6px 错开,解决“多条线完全重叠”; - 手动走线偏移:Dependency.routeOffset(随工程保存)—— · 条形 / 流程图:上下拖动平移横线,跨行走廊为左右拖动; · 圆周:沿半径方向(法线)拖动; · 直角拐点随平移保留,双击连线或右键「复位走线偏移」恢复自动位置; · 选中连线以强调色加粗高亮,状态栏给出操作提示; - 画布命中判定改用「按下位置」(此前用手势验收点,细目标会抓空), 端点把手与连线重叠时按“谁更近”判定优先级; - 帮助中心补充「连线重叠怎么办」;版本号 1.3.3+19; 更新说明 release/RELEASE_NOTES_v1.3.3.md。
100 lines
3.3 KiB
Dart
100 lines
3.3 KiB
Dart
// 依赖走线测试:自动错开、手动偏移、命中测试与 JSON 往返。
|
|
import 'dart:ui' show Size, Offset;
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:sequence_diagram/layout/dep_routes.dart';
|
|
import 'package:sequence_diagram/layout/layout.dart';
|
|
import 'package:sequence_diagram/model/models.dart';
|
|
|
|
/// 构造测试工程:A1/A2/A3 同属一条泳道(L0),A3 依赖 A1 与 A2,
|
|
/// 用于验证“同组依赖自动错开 + 手动偏移”。
|
|
Project _project({double offset = 0}) {
|
|
return Project(
|
|
name: 'test',
|
|
cycle: const Cycle(durationMs: 2400),
|
|
stations: const <Station>[
|
|
Station(id: 'ST1', name: '工位 1', order: 0, color: 0xFF4CC9F0),
|
|
],
|
|
actions: <Action>[
|
|
const Action(
|
|
id: 'A1',
|
|
name: 'A1',
|
|
stationId: 'ST1',
|
|
driver: 'x',
|
|
startAngle: 0,
|
|
durationAngle: 30,
|
|
layer: 0,
|
|
color: 0xFF4CC9F0),
|
|
const Action(
|
|
id: 'A2',
|
|
name: 'A2',
|
|
stationId: 'ST1',
|
|
driver: 'x',
|
|
startAngle: 40,
|
|
durationAngle: 30,
|
|
layer: 0,
|
|
color: 0xFF7BD88F),
|
|
Action(
|
|
id: 'A3',
|
|
name: 'A3',
|
|
stationId: 'ST1',
|
|
driver: 'x',
|
|
startAngle: 80,
|
|
durationAngle: 30,
|
|
layer: 0,
|
|
color: 0xFFFFD166,
|
|
deps: <Dependency>[
|
|
Dependency(fromId: 'A1', toId: 'A3', routeOffset: offset),
|
|
const Dependency(fromId: 'A2', toId: 'A3'),
|
|
]),
|
|
],
|
|
units: const UnitSettings(),
|
|
viewState: const ViewState(mode: ViewMode.bar),
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
const Size size = Size(1280, 800);
|
|
|
|
test('条形:同组依赖自动错开,手动偏移叠加', () {
|
|
final Project p = _project(offset: 20);
|
|
final BarLayout layout = BarLayout(p, size);
|
|
final List<BarDepRoute> routes = buildBarDepRoutes(p, layout);
|
|
expect(routes.length, 2);
|
|
final BarDepRoute r1 = routes.firstWhere((BarDepRoute r) => r.key == 'A1->A3');
|
|
final BarDepRoute r2 = routes.firstWhere((BarDepRoute r) => r.key == 'A2->A3');
|
|
// A1→A3 手动偏移 +20;A2→A3 自动错开 −6:两条线纵坐标相差 26。
|
|
final double y1 = r1.points.first.dy;
|
|
final double y2 = r2.points.first.dy;
|
|
expect(y1 - y2, closeTo(26, 0.001));
|
|
});
|
|
|
|
test('条形:命中测试选中最近的连线', () {
|
|
final Project p = _project();
|
|
final List<BarDepRoute> routes = buildBarDepRoutes(p, BarLayout(p, size));
|
|
final BarDepRoute r1 = routes.firstWhere((BarDepRoute r) => r.key == 'A1->A3');
|
|
final Offset mid = Offset(
|
|
(r1.points.first.dx + r1.points.last.dx) / 2,
|
|
r1.points.first.dy,
|
|
);
|
|
expect(hitBarDep(routes, mid, 7)?.key, 'A1->A3');
|
|
expect(hitBarDep(routes, mid + const Offset(0, 40), 7), isNull);
|
|
});
|
|
|
|
test('依赖 routeOffset JSON 往返', () {
|
|
const Dependency d =
|
|
Dependency(fromId: 'A1', toId: 'A2', offsetAngle: 10, routeOffset: 24);
|
|
final Dependency back = Dependency.fromJson(d.toJson());
|
|
expect(back.routeOffset, 24);
|
|
expect(back.offsetAngle, 10);
|
|
// 旧文件没有 routeOffset 字段时回退为 0。
|
|
final Dependency legacy = Dependency.fromJson(<String, dynamic>{
|
|
'fromId': 'A1',
|
|
'toId': 'A2',
|
|
'type': 'FS',
|
|
'offsetAngle': 5,
|
|
});
|
|
expect(legacy.routeOffset, 0);
|
|
});
|
|
}
|