feat(V1.0.1): 泳道/轨道支持多动作(同执行器多条不重叠);圆周弧可拖拽端点;依赖标签沿弧避让
- 泳道模型:layer 兼作泳道/轨道编号,同一泳道可放多个互不重叠动作(角区间重叠校验) - 条形:上下拖拽换道;圆周:Shift+径向拖拽换轨;冲突时拒绝并提示 - 泳道标题合并显示(/ 分隔,≤2 行);左侧列表按泳道分组 - 圆周动作弧支持拖拽两端改起止角(弱吸附 + 径向虚线参考),整体拖拽旋转 - 圆周依赖标签沿圆弧切向排布,落入环间空隙,避免压住动作弧 - 版本 1.0.1+2;帮助/README 补充泳道说明;重新构建 dist
This commit is contained in:
+124
-5
@@ -968,7 +968,7 @@ class _AppShellState extends State<AppShell> {
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: _sectionLabel(t, bar ? '动作 / 工位泳道' : '动作列表(按层 L1→L${c.project.maxLayer + 1})'),
|
||||
child: _sectionLabel(t, bar ? '动作 / 执行器泳道' : '动作列表(按轨道 L1→L${c.project.laneCount})'),
|
||||
),
|
||||
const Spacer(),
|
||||
_headerAction(t, Icons.add, '新建', t.ok, t.onAccent, () => c.addAction(startAngle: 0)),
|
||||
@@ -984,7 +984,8 @@ class _AppShellState extends State<AppShell> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
for (int i = 0; i < actions.length; i++) _actionRow(t, actions[i], i, bar),
|
||||
// 按泳道 / 轨道分组:同一泳道内的多个动作合并显示(最多两行,/ 分隔)。
|
||||
..._laneRows(t, bar),
|
||||
const SizedBox(height: 12),
|
||||
_sectionLabel(t, '视图模式'),
|
||||
const SizedBox(height: 8),
|
||||
@@ -1080,6 +1081,124 @@ 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<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));
|
||||
// 单动作泳道沿用普通动作行;多动作泳道合并显示。
|
||||
out.add(acts.length == 1
|
||||
? _actionRow(t, acts.first, li, bar)
|
||||
: _laneRow(t, lane, li, acts, bar));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 单条泳道 / 轨道行:多个动作合并显示(≤2 行,/ 分隔)。
|
||||
Widget _laneRow(Tokens t, int lane, int li, List<Action> acts, bool bar) {
|
||||
if (acts.isEmpty) return const SizedBox.shrink();
|
||||
final Action primary =
|
||||
acts.firstWhere((Action a) => c.isSelected(a.id), orElse: () => acts.first);
|
||||
final bool sel = c.isSelected(primary.id);
|
||||
final Station? st = c.project.stationById(primary.stationId);
|
||||
final String joined = acts.map((Action a) => '${a.id} ${a.name}').join(' / ');
|
||||
double a0 = acts.first.startAngle;
|
||||
double a1 = acts.first.endAngle;
|
||||
for (final Action a in acts) {
|
||||
a0 = math.min(a0, a.startAngle);
|
||||
a1 = math.max(a1, a.endAngle);
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 6),
|
||||
child: InkWell(
|
||||
onTap: () => c.select(
|
||||
primary.id,
|
||||
toggle: HardwareKeyboard.instance.isControlPressed ||
|
||||
HardwareKeyboard.instance.isShiftPressed,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: sel ? t.sel : t.panel2,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: sel ? t.accent : t.line, width: sel ? 1.4 : 1),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: 22,
|
||||
height: 22,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(primary.color).withValues(alpha: 0.9),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text('${li + 1}', style: TextStyle(color: t.chip, fontSize: 11, fontWeight: FontWeight.w700)),
|
||||
),
|
||||
const SizedBox(width: 9),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
joined,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: sel ? t.text : t.text2,
|
||||
fontSize: 12.5,
|
||||
height: 1.25,
|
||||
fontWeight: sel ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${st?.name ?? primary.stationId} · ${primary.driver}'
|
||||
'${acts.length > 1 ? ' · 共 ${acts.length} 个' : ''}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.dim, fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
bar ? '${a0.toStringAsFixed(0)}° – ${math.min(a1, 360).toStringAsFixed(0)}°' : 'L${li + 1}',
|
||||
style: TextStyle(color: t.sub, fontSize: 11),
|
||||
),
|
||||
Text('${acts.length} 个动作', style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
InkWell(
|
||||
onTap: () => showDialog<void>(
|
||||
context: context, builder: (_) => ActionEditorDialog(controller: c, action: primary)),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
child: Container(
|
||||
width: 28,
|
||||
height: 24,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: Icon(Icons.edit, size: 13, color: sel ? t.accent : t.dim),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 左侧栏中的单条动作行:点击选中,右侧显示相位/层信息与编辑入口。
|
||||
Widget _actionRow(Tokens t, Action a, int i, bool bar) {
|
||||
final bool sel = c.isSelected(a.id);
|
||||
@@ -1367,7 +1486,7 @@ class _AppShellState extends State<AppShell> {
|
||||
else ...<Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Expanded(child: _wideBtn(t, Icons.add, '新增外层 L${c.project.maxLayer + 2}', t.accent2, Colors.white,
|
||||
Expanded(child: _wideBtn(t, Icons.add, '新增轨道 L${c.project.laneCount + 1}', t.accent2, Colors.white,
|
||||
() => c.changeLayer(a.id, 1))),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: _wideBtn(t, Icons.keyboard_arrow_up, '重排 / 合并层', t.panel2, t.sub,
|
||||
@@ -1882,8 +2001,8 @@ class _AppShellState extends State<AppShell> {
|
||||
'相位 360° = 100%',
|
||||
'动作 ${c.project.actions.length}',
|
||||
'依赖 ${_depCount()}',
|
||||
circular ? '层数 L1–L${c.project.maxLayer + 1}' : '工位 ${c.project.stations.length}',
|
||||
circular ? '同心圆 ${c.project.maxLayer + 1}' : '时间轴 0–${tfmt(c.project.cycle.durationMs, u)}',
|
||||
circular ? '轨道 L1–L${c.project.laneCount}' : '工位 ${c.project.stations.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)}',
|
||||
c.status,
|
||||
|
||||
+38
-13
@@ -7,6 +7,8 @@
|
||||
// · 点选、双击新建、拖拽移动相位、拖拽端点改持续角、Shift 拖拽改层;
|
||||
// · 空白区域拖拽平移、Ctrl + 滚轮缩放;
|
||||
// · 右键上下文菜单。
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -132,6 +134,14 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
if (next != _cursor) setState(() => _cursor = next);
|
||||
}
|
||||
|
||||
/// 判断两个角度是否足够接近(用于圆周视图命中弧端点)。
|
||||
bool _angleNear(double a, double b, double tolDeg) {
|
||||
double d = (a - b) % 360;
|
||||
if (d > 180) d -= 360;
|
||||
if (d < -180) d += 360;
|
||||
return d.abs() <= tolDeg;
|
||||
}
|
||||
|
||||
/// 动作端点弱吸附:贴合到整 5°、分区边界或其它动作端点(容差 2.5°)。
|
||||
double _snapActionAngle(double raw, String excludeId) {
|
||||
const double tol = 2.5;
|
||||
@@ -302,7 +312,14 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
final Action? hit = layout.hitTest(p);
|
||||
if (hit != null) {
|
||||
final double a = angleOf(layout.center, p);
|
||||
_mode = _DragMode.move;
|
||||
final double rad = (p - layout.center).distance;
|
||||
// 距端点约 9px 以内视为拖拽端点(改起止角),否则整体旋转。
|
||||
final double tolDeg = math.atan2(9, math.max(rad, 1)) * 180 / math.pi;
|
||||
final bool nearStart = _angleNear(a, hit.startAngle, tolDeg);
|
||||
final bool nearEnd = _angleNear(a, math.min(hit.endAngle, 360), tolDeg);
|
||||
_mode = nearStart
|
||||
? _DragMode.resizeStart
|
||||
: (nearEnd ? _DragMode.resize : _DragMode.move);
|
||||
_dragAction = hit;
|
||||
_startPointer = p;
|
||||
_startAngle = hit.startAngle;
|
||||
@@ -358,14 +375,9 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
(Action x) => x.copyWith(startAngle: ns, durationAngle: fixedEnd - ns),
|
||||
status: '调整起始角',
|
||||
);
|
||||
} else if (shift) {
|
||||
// Shift + 垂直拖拽:按每 26px 一层调整层号,并限制在 0–63。
|
||||
final int deltaLayer = (dy / 26).round();
|
||||
c.setLayer(_dragAction!.id, (_dragAction!.layer - deltaLayer).clamp(0, 63));
|
||||
} else if (dy.abs() > dx.abs() + 6 && dy.abs() > 12) {
|
||||
// 以垂直为主:上下拖拽调整行序,动作可自由换行(不再被相位锁死)。
|
||||
final int target = ((p.dy - BarLayout.topPad) / layout.pitch).round().clamp(0, layout.ordered.length - 1);
|
||||
c.moveActionRow(_dragAction!.id, target);
|
||||
// 以垂直为主:上下拖拽换泳道(同泳道可放多个不重叠动作)。
|
||||
c.moveActionLane(_dragAction!.id, layout.laneAt(p.dy));
|
||||
} else {
|
||||
c.setActionStart(_dragAction!.id, _startAngle + dx / layout.span * 360);
|
||||
}
|
||||
@@ -377,12 +389,24 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
if (delta > 180) delta -= 360;
|
||||
if (delta < -180) delta += 360;
|
||||
if (_mode == _DragMode.resize) {
|
||||
c.setActionDuration(_dragAction!.id, _startDuration + delta);
|
||||
// 拖弧末端:固定起始角,改结束角(弱吸附 + 径向虚线参考)。
|
||||
final double end = _snapActionAngle(_startAngle + _startDuration + delta, _dragAction!.id);
|
||||
_zoneGuideAngle = end;
|
||||
c.setActionDuration(_dragAction!.id, (end - _dragAction!.startAngle).clamp(5, 360));
|
||||
} else if (_mode == _DragMode.resizeStart) {
|
||||
// 拖弧起始端:固定结束角,改起始角。
|
||||
final double fixedEnd = _startAngle + _startDuration;
|
||||
final double ns = _snapActionAngle(_startAngle + delta, _dragAction!.id).clamp(0, fixedEnd - 5);
|
||||
_zoneGuideAngle = ns;
|
||||
c.updateAction(
|
||||
_dragAction!.id,
|
||||
(Action x) => x.copyWith(startAngle: ns, durationAngle: fixedEnd - ns),
|
||||
status: '调整起始角',
|
||||
);
|
||||
} else if (shift) {
|
||||
// Shift + 径向拖拽:按层间距 pitch 换算层号增量。
|
||||
final double dr = (p - layout.center).distance - (_startPointer - layout.center).distance;
|
||||
final int dl = (dr / layout.pitch).round();
|
||||
c.setLayer(_dragAction!.id, (_dragAction!.layer + dl).clamp(0, 63));
|
||||
// Shift + 径向拖拽:换轨道(同轨道可放多个不重叠动作)。
|
||||
final double rad = (p - layout.center).distance;
|
||||
c.moveActionLane(_dragAction!.id, layout.laneAtRadius(rad));
|
||||
} else {
|
||||
c.setActionStart(_dragAction!.id, _startAngle + delta);
|
||||
}
|
||||
@@ -556,6 +580,7 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
criticalActions: c.criticalActions,
|
||||
criticalDeps: c.criticalDeps,
|
||||
selectedIds: c.selectedIds.toSet(),
|
||||
guideAngle: _zoneGuideAngle,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
+2
-1
@@ -1291,6 +1291,7 @@ class HelpDialog extends StatelessWidget {
|
||||
<String>['我要删除动作', '选中后:左侧「删除」/ 行内删除图标 / 右侧删除 / Delete 键 / 右键菜单。'],
|
||||
<String>['我要改动作属性', '选中动作 → 右侧「编辑」,可改名称、工位、驱动与颜色。'],
|
||||
<String>['我要复制 / 对齐', '右侧「编辑操作」→「复制」/「对齐相位」;圆周视图还可改层。'],
|
||||
<String>['一条泳道放多个动作', '泳道/轨道=一个执行器:上下拖拽(条形)或 Shift+径向拖拽(圆周)换道;不重叠即可共存,标题合并显示(/ 分隔,≤2 行)。'],
|
||||
]),
|
||||
// 目标:调整时间轴与动作间的先后 / 并行关系。
|
||||
_section(t, <List<String>>[
|
||||
@@ -1335,7 +1336,7 @@ class HelpDialog extends StatelessWidget {
|
||||
_section(t, <List<String>>[
|
||||
<String>['软件名称', '时序图设计器 · Sequence Diagram Studio'],
|
||||
<String>['设计人', '呆头鹅'],
|
||||
<String>['版本', 'V1.0.0'],
|
||||
<String>['版本', 'V1.0.1'],
|
||||
<String>['版权声明', 'Copyright © 2026 呆头鹅。保留所有权利。'],
|
||||
<String>['用途', '面向 PLC 流程节拍 / 相位角设计;未经许可不得用于商业再分发。'],
|
||||
<String>['技术栈', 'Flutter Desktop · 自绘 Canvas · 纯 Dart 几何 · JSON 持久化 · SVG 导出。'],
|
||||
|
||||
Reference in New Issue
Block a user