v1.3.13: 模块化注册架构 + PDS流程设计套件更名 + 依赖/圆周交互修复
- 模块化:EdcModule 契约 + registry + 模块独立目录;发布包增加 modules/registry.json - 更名:PDS流程设计套件 / ProcessDesignSuite;同步构建、发布脚本与文档 - 时序图:依赖偏移以时间显示/编辑;紧贴依赖隐藏箭头并在接缝显示标签;动作条磁吸 - 圆周:依赖标签沿圆弧方向、环间空隙;动作旋转磁吸增强;短弧标签优先动作名 - 清理:release 移至源码同级(本地不入库);tool 合并到 tools;发布说明迁移 docs/release-notes
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
/// 导出画布的共享几何约束:固定 1920×1080、2 倍像素比、内容区与
|
||||
/// 缩放/平移结果 [ExportFit]。
|
||||
///
|
||||
/// 架构位置:`lib/export/` 为共享导出层,不依赖任何具体模块;时序图与
|
||||
/// 架构图模块各自的导出逻辑都复用这里的常量与 [ExportFit]。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
|
||||
/// 导出画布尺寸(固定逻辑尺寸)。
|
||||
const Size kExportSize = Size(1920, 1080);
|
||||
|
||||
/// 导出渲染像素比:按 2 倍渲染成 3840×2160,保证高分辨率打印清晰。
|
||||
const double kExportPixelRatio = 2.0;
|
||||
|
||||
/// 导出内容区域(标题/图例之外的内容区)。
|
||||
const Rect kExportContentArea = Rect.fromLTRB(48, 128, 1872, 1016);
|
||||
|
||||
/// 导出内容变换:`scale` + `translate(tx, ty)`。
|
||||
class ExportFit {
|
||||
/// 构造内容变换。
|
||||
const ExportFit(this.scale, this.tx, this.ty);
|
||||
|
||||
/// 缩放系数。
|
||||
final double scale;
|
||||
|
||||
/// 水平平移。
|
||||
final double tx;
|
||||
|
||||
/// 垂直平移。
|
||||
final double ty;
|
||||
|
||||
/// SVG transform 属性值。
|
||||
String get svgTransform =>
|
||||
'translate(${tx.toStringAsFixed(1)} ${ty.toStringAsFixed(1)}) scale(${scale.toStringAsFixed(4)})';
|
||||
}
|
||||
|
||||
/// 导出专用令牌:始终使用浅色、纯白背景(印刷 / 工艺卡导向),
|
||||
/// 文字、语义色与屏幕浅色主题保持一致。
|
||||
Tokens exportTokens(Tokens base) {
|
||||
return Tokens(
|
||||
brightness: Brightness.light,
|
||||
bg: Colors.white,
|
||||
canvas1: Colors.white,
|
||||
canvas2: Colors.white,
|
||||
chrome: base.chrome,
|
||||
panel: Colors.white,
|
||||
panel2: Colors.white,
|
||||
dialog: Colors.white,
|
||||
line: base.line,
|
||||
line2: base.line2,
|
||||
text: base.text,
|
||||
text2: base.text2,
|
||||
sub: base.sub,
|
||||
dim: base.dim,
|
||||
accent: base.accent,
|
||||
accent2: base.accent2,
|
||||
ok: base.ok,
|
||||
warn: base.warn,
|
||||
danger: base.danger,
|
||||
fs: base.fs,
|
||||
ss: base.ss,
|
||||
crit: base.crit,
|
||||
chip: Colors.white,
|
||||
dial: Colors.white,
|
||||
arcText: base.arcText,
|
||||
onAccent: base.onAccent,
|
||||
ringA: base.ringA,
|
||||
ringB: base.ringB,
|
||||
ringEdge: base.ringEdge,
|
||||
ringLabel: base.ringLabel,
|
||||
info: Colors.white,
|
||||
track: base.track,
|
||||
sel: base.sel,
|
||||
grid: base.grid,
|
||||
shadow: base.shadow,
|
||||
shadowOp: 0.10,
|
||||
selOutline: base.selOutline,
|
||||
overlay: base.overlay,
|
||||
tailOp: base.tailOp,
|
||||
);
|
||||
}
|
||||
@@ -1,360 +0,0 @@
|
||||
/// 依赖连线的共享走线计算。
|
||||
///
|
||||
/// 条形视图 / 圆周视图的**画布绘制、标签放置与命中测试**(点选连线、
|
||||
/// 沿法线拖拽调整走线)都使用这里的同一份几何,避免绘制与命中不一致:
|
||||
/// - 自动错开:同一走线分组内的多条依赖依次错开,先解决“完全重叠”;
|
||||
/// - 手动偏移:[Dependency.routeOffset] 叠加在自动错开之上(拖拽连线的结果)。
|
||||
library;
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../model/models.dart';
|
||||
import 'layout.dart';
|
||||
|
||||
// ===================== 通用工具 =====================
|
||||
|
||||
/// 点 [p] 到线段 [a]–[b] 的最短距离。
|
||||
double distanceToSegment(Offset p, Offset a, Offset b) {
|
||||
final Offset ab = b - a;
|
||||
final double len2 = ab.dx * ab.dx + ab.dy * ab.dy;
|
||||
if (len2 <= 0) return (p - a).distance;
|
||||
final double t = (((p - a).dx * ab.dx + (p - a).dy * ab.dy) / len2).clamp(0.0, 1.0);
|
||||
return (p - (a + ab * t)).distance;
|
||||
}
|
||||
|
||||
/// 点 [p] 到折线 [pts] 的最短距离。
|
||||
double distanceToPolyline(List<Offset> pts, Offset p) {
|
||||
double best = double.infinity;
|
||||
for (int i = 0; i + 1 < pts.length; i++) {
|
||||
final double d = distanceToSegment(p, pts[i], pts[i + 1]);
|
||||
if (d < best) best = d;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// 点 [p] 到路径 [path] 的近似最短距离(按弧长采样,步长 [step])。
|
||||
double distanceToPath(Path path, Offset p, {double step = 4}) {
|
||||
double best = double.infinity;
|
||||
for (final PathMetric m in path.computeMetrics()) {
|
||||
for (double d = 0; d < m.length; d += step) {
|
||||
final Tangent? t = m.getTangentForOffset(d);
|
||||
if (t == null) continue;
|
||||
final double dist = (t.position - p).distance;
|
||||
if (dist < best) best = dist;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// 第 [k] 档自动错开量(px):0、−6、+6、−12、+12 …
|
||||
///
|
||||
/// 同一走线分组内第二条起依次错开,避免多条依赖完全重叠。
|
||||
double staggerOffset(int k) {
|
||||
if (k <= 0) return 0;
|
||||
return (k.isOdd ? -1 : 1) * ((k + 1) ~/ 2) * 6.0;
|
||||
}
|
||||
|
||||
/// 拖拽调整走线时的移动轴(走线的“法线”方向)。
|
||||
///
|
||||
/// - [vertical]:上下拖动——平移水平走线段(条形 / 流程图的常见形态);
|
||||
/// - [horizontal]:左右拖动——平移纵向走线走廊(跨行绕行走廊 / 同层绕行)。
|
||||
enum RouteAxis { vertical, horizontal }
|
||||
|
||||
/// 拖拽走线时可用的最大手动偏移(px,双向)。
|
||||
const double kMaxRouteOffset = 200;
|
||||
|
||||
// ===================== 条形视图 =====================
|
||||
|
||||
/// 条形视图的一条依赖走线。
|
||||
class BarDepRoute {
|
||||
/// 构造。
|
||||
BarDepRoute(this.dep, this.points, this.arrowTip, this.arrowDir, this.chipCenter, this.axis,
|
||||
{this.chipRun = double.infinity,
|
||||
this.chipRunMargin = 0,
|
||||
this.chipAltAnchor = Offset.zero});
|
||||
|
||||
/// 对应依赖。
|
||||
final Dependency dep;
|
||||
/// 折线顶点(含起点与箭头端点)。
|
||||
final List<Offset> points;
|
||||
/// 箭头端点。
|
||||
final Offset arrowTip;
|
||||
/// 箭头方向(分量式)。
|
||||
final Offset arrowDir;
|
||||
/// 标签中心(默认位置,避让前)。
|
||||
final Offset chipCenter;
|
||||
/// 拖拽方向:vertical = 上下拖动平移横线;horizontal = 左右拖动平移纵向走廊。
|
||||
final RouteAxis axis;
|
||||
|
||||
/// 标签挂钩的水平行程长度(跑长时用于判断是否需要把标签移到箭头外侧)。
|
||||
///
|
||||
/// 默认 [double.infinity] 表示不做外移判断(跨行走廊等)。
|
||||
final double chipRun;
|
||||
|
||||
/// 外移判断余量:行程 `< 标签宽 + 余量` 时把标签移到 [chipAltAnchor]。
|
||||
final double chipRunMargin;
|
||||
|
||||
/// 外移时标签的锚点(绘制端会再加半个标签宽)。
|
||||
final Offset chipAltAnchor;
|
||||
|
||||
/// 依赖键 `from->to`。
|
||||
String get key => '${dep.fromId}->${dep.toId}';
|
||||
}
|
||||
|
||||
/// 计算条形视图的全部依赖走线(含自动错开与手动偏移)。
|
||||
///
|
||||
/// 走线分三种情形:同泳道(水平线)、相邻泳道(Z 形)、跨多行(外侧纵向走廊),
|
||||
/// 与绘制旧的实现保持一致;新增:同组自动错开 + [Dependency.routeOffset] 手动偏移。
|
||||
List<BarDepRoute> buildBarDepRoutes(Project project, BarLayout layout) {
|
||||
final Map<String, int> laneIndex = <String, int>{
|
||||
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
|
||||
};
|
||||
final Map<String, int> seen = <String, int>{};
|
||||
final List<BarDepRoute> out = <BarDepRoute>[];
|
||||
for (final Action to in layout.ordered) {
|
||||
for (final Dependency d in to.deps) {
|
||||
final Action? from = project.actionById(d.fromId);
|
||||
if (from == null) continue;
|
||||
final int ia = laneIndex[from.id] ?? 0;
|
||||
final int ib = laneIndex[to.id] ?? 0;
|
||||
final Rect ra = layout.rectFor(from);
|
||||
final Rect rb = layout.rectFor(to);
|
||||
const double barHalf = BarLayout.barH / 2;
|
||||
final double sy = ra.center.dy;
|
||||
final double ty = rb.center.dy;
|
||||
final double dir = ty > sy ? 1 : -1;
|
||||
final double tipY = ty - dir * (barHalf + 3);
|
||||
final bool sameLane = (ty - sy).abs() < 1;
|
||||
final bool fs = d.type == DepType.fs;
|
||||
|
||||
if (sameLane) {
|
||||
// 同泳道:一条水平线;同组多条依次上下错开。
|
||||
final int k = seen.putIfAbsent('S$ia', () => 0);
|
||||
seen['S$ia'] = k + 1;
|
||||
final double y = sy + staggerOffset(k) + d.routeOffset;
|
||||
final double startX = fs ? ra.right + 2 : ra.left - 2;
|
||||
double endX = rb.left - 2;
|
||||
if (endX < startX) endX = rb.right + 2;
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
<Offset>[Offset(startX, y), Offset(endX, y)],
|
||||
Offset(endX, y),
|
||||
Offset(endX >= startX ? 1 : -1, 0),
|
||||
Offset((startX + endX) / 2, y - (barHalf + 9)),
|
||||
RouteAxis.vertical,
|
||||
// 行程太短时标签移出到箭头右侧(宽度由绘制端精确测量)。
|
||||
chipRun: (endX - startX).abs(),
|
||||
chipRunMargin: 8,
|
||||
chipAltAnchor: Offset(endX + 6, y - (barHalf + 9)),
|
||||
));
|
||||
} else if ((ib - ia).abs() <= 1) {
|
||||
// 相邻泳道:在两泳道之间的空隙中线走水平线;同组错开 + 手动偏移。
|
||||
final int k = seen.putIfAbsent('A$ia→$ib', () => 0);
|
||||
seen['A$ia→$ib'] = k + 1;
|
||||
final double mid = (sy + ty) / 2 + staggerOffset(k) + d.routeOffset;
|
||||
final double sx = fs ? ra.right : ra.left;
|
||||
final double ex = fs ? sx - 9 : sx + 9;
|
||||
final double tx = rb.left + 14;
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
<Offset>[
|
||||
Offset(ex, sy + dir * (barHalf + 2)),
|
||||
Offset(ex, mid),
|
||||
Offset(tx, mid),
|
||||
Offset(tx, tipY),
|
||||
],
|
||||
Offset(tx, tipY),
|
||||
Offset(0, dir),
|
||||
Offset((ex + tx) / 2, mid),
|
||||
RouteAxis.vertical,
|
||||
chipRun: (tx - ex).abs(),
|
||||
chipRunMargin: 10,
|
||||
chipAltAnchor: Offset(tx + 6, mid),
|
||||
));
|
||||
} else {
|
||||
// 跨多行:扫描区间内所有条块边界,据此在外侧选一条纵向走廊;
|
||||
// 同组按 ±12px 错开走廊,手动偏移作用于走廊的横向位置。
|
||||
final int k = seen.putIfAbsent('M$ia→$ib', () => 0);
|
||||
seen['M$ia→$ib'] = k + 1;
|
||||
final double sx = fs ? ra.right : ra.left;
|
||||
final double ex = fs ? sx - 9 : sx + 9;
|
||||
final double tx = rb.left + 14;
|
||||
double maxRight = 0;
|
||||
double minLeft = double.infinity;
|
||||
final List<int> lanes = layout.lanes;
|
||||
for (int r = math.min(ia, ib) + 1; r < math.max(ia, ib); r++) {
|
||||
if (r < 0 || r >= lanes.length) continue;
|
||||
for (final Action aa in layout.actionsInLane(lanes[r])) {
|
||||
final Rect rr = layout.rectFor(aa);
|
||||
maxRight = math.max(maxRight, rr.right);
|
||||
minLeft = math.min(minLeft, rr.left);
|
||||
}
|
||||
}
|
||||
final double shift = staggerOffset(k) * 2 + d.routeOffset;
|
||||
double lane = math.max(math.max(sx, tx), maxRight) + 28 + shift;
|
||||
if (lane > layout.plotRight - 16) {
|
||||
lane = math.min(math.min(sx, tx), minLeft) - 28 - shift;
|
||||
}
|
||||
final double srcGapY = sy + dir * (barHalf + 14);
|
||||
final double gapY = ty - dir * (barHalf + 6);
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
<Offset>[
|
||||
Offset(ex, sy + dir * (barHalf + 2)),
|
||||
Offset(ex, srcGapY),
|
||||
Offset(lane, srcGapY),
|
||||
Offset(lane, gapY),
|
||||
Offset(tx, gapY),
|
||||
Offset(tx, tipY),
|
||||
],
|
||||
Offset(tx, tipY),
|
||||
Offset(0, dir),
|
||||
Offset((lane + tx) / 2, gapY - (barHalf + 1)),
|
||||
RouteAxis.horizontal,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 命中条形依赖走线:返回最近且距离小于 [maxDist] 的走线(无命中返回 null)。
|
||||
BarDepRoute? hitBarDep(List<BarDepRoute> routes, Offset p, double maxDist) {
|
||||
BarDepRoute? best;
|
||||
double bestD = maxDist;
|
||||
for (final BarDepRoute r in routes) {
|
||||
final double d = distanceToPolyline(r.points, p);
|
||||
if (d < bestD) {
|
||||
bestD = d;
|
||||
best = r;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// ===================== 圆周视图 =====================
|
||||
|
||||
/// 圆周视图的一条依赖走线(径向 → 圆弧 → 径向)。
|
||||
class ArcDepRoute {
|
||||
/// 构造。
|
||||
ArcDepRoute(this.dep, this.center, this.rA, this.rB, this.rC, this.rTip, this.aEnd, this.aStart,
|
||||
this.degenerate, this.cw, this.large, this.chipR, this.chipDeg);
|
||||
|
||||
/// 对应依赖。
|
||||
final Dependency dep;
|
||||
/// 圆心。
|
||||
final Offset center;
|
||||
/// 源环半径。
|
||||
final double rA;
|
||||
/// 目标环半径。
|
||||
final double rB;
|
||||
/// 绕行半径(自动错开 + 手动偏移作用于此)。
|
||||
final double rC;
|
||||
/// 箭头落点半径。
|
||||
final double rTip;
|
||||
/// 源弧末端角(度)。
|
||||
final double aEnd;
|
||||
/// 目标弧起点角(度)。
|
||||
final double aStart;
|
||||
/// 起止角几乎重合(退化)时改画短箭头。
|
||||
final bool degenerate;
|
||||
/// 圆弧是否顺时针。
|
||||
final bool cw;
|
||||
/// 是否大弧。
|
||||
final int large;
|
||||
/// 标签极径。
|
||||
final double chipR;
|
||||
/// 标签极角。
|
||||
final double chipDeg;
|
||||
|
||||
/// 依赖键 `from->to`。
|
||||
String get key => '${dep.fromId}->${dep.toId}';
|
||||
|
||||
/// 起点(源环上)。
|
||||
Offset get p0 => polar(center, rA, aEnd);
|
||||
/// 绕行起点(半径 rC 上)。
|
||||
Offset get p1 => polar(center, rC, aEnd);
|
||||
/// 绕行终点(半径 rC 上)。
|
||||
Offset get p2 => polar(center, rC, aStart);
|
||||
/// 箭头端点。
|
||||
Offset get p3 => polar(center, rTip, aStart);
|
||||
/// 退化短箭头的起点。
|
||||
Offset get q0 => polar(center, rTip - (rTip > rB ? 28 : -28), aStart);
|
||||
|
||||
/// 生成绘制路径(绘制与命中测试同源)。
|
||||
Path buildPath() {
|
||||
final Path p = Path();
|
||||
if (degenerate) {
|
||||
p.moveTo(q0.dx, q0.dy);
|
||||
p.lineTo(p3.dx, p3.dy);
|
||||
return p;
|
||||
}
|
||||
final Offset a0 = p0;
|
||||
final Offset a1 = p1;
|
||||
final Offset a2 = p2;
|
||||
final Offset a3 = p3;
|
||||
p.moveTo(a0.dx, a0.dy);
|
||||
p.lineTo(a1.dx, a1.dy);
|
||||
p.arcToPoint(a2, radius: Radius.circular(rC), largeArc: large == 1, clockwise: cw);
|
||||
p.lineTo(a3.dx, a3.dy);
|
||||
return p;
|
||||
}
|
||||
|
||||
/// 箭头方向(分量式)。
|
||||
Offset get tipDir => degenerate ? (p3 - q0) : (p3 - p2);
|
||||
}
|
||||
|
||||
/// 计算圆周视图的全部依赖走线(含自动错开与手动偏移)。
|
||||
List<ArcDepRoute> buildArcDepRoutes(Project project, CircularLayout layout) {
|
||||
final Map<String, int> seen = <String, int>{};
|
||||
final List<ArcDepRoute> out = <ArcDepRoute>[];
|
||||
for (final Action to in project.actions) {
|
||||
for (final Dependency d in to.deps) {
|
||||
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, 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 时从最外圈绕行,避免穿过中间层弧线。
|
||||
final bool skip = (a.layer - b.layer).abs() > 1;
|
||||
final String groupKey = '${skip ? 'K' : 'N'}${a.layer}→${b.layer}';
|
||||
final int k = seen.putIfAbsent(groupKey, () => 0);
|
||||
seen[groupKey] = k + 1;
|
||||
// 自动错开(步长 9px)+ 手动径向偏移(圆周视图的“法线”即半径方向)。
|
||||
double rC = (skip ? layout.rMax + 24 : (rA + rB) / 2) + staggerOffset(k) * 1.5 + d.routeOffset;
|
||||
rC = rC.clamp(18.0, layout.rMax + 170);
|
||||
final double rTip = rC < rB ? rB - layout.th / 2 - 4 : rB + layout.th / 2 + 4;
|
||||
final bool cw = aStart >= aEnd;
|
||||
final int large = (aStart - aEnd).abs() > 180 ? 1 : 0;
|
||||
final bool degenerate = (aStart - aEnd).abs() < 0.5;
|
||||
final double chipDeg = degenerate ? aStart : (aEnd + aStart) / 2;
|
||||
double chipR;
|
||||
if (degenerate) {
|
||||
chipR = (rA + rB) / 2;
|
||||
} else {
|
||||
final double span = (aStart - aEnd).abs();
|
||||
chipR = skip ? rC : (span < 30 ? rB + layout.th / 2 + 10 : rC);
|
||||
}
|
||||
out.add(ArcDepRoute(
|
||||
d, layout.center, rA, rB, rC, rTip, aEnd, aStart, degenerate, cw, large, chipR, chipDeg));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 命中圆周依赖走线:返回最近且距离小于 [maxDist] 的走线(无命中返回 null)。
|
||||
ArcDepRoute? hitArcDep(List<ArcDepRoute> routes, Offset p, double maxDist) {
|
||||
ArcDepRoute? best;
|
||||
double bestD = maxDist;
|
||||
for (final ArcDepRoute r in routes) {
|
||||
final double d = distanceToPath(r.buildPath(), p);
|
||||
if (d < bestD) {
|
||||
bestD = d;
|
||||
best = r;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
+13
-11
@@ -14,7 +14,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import 'license/license_service.dart';
|
||||
import 'model/models.dart';
|
||||
import 'modules/module_registry.dart';
|
||||
import 'modules/registry.dart';
|
||||
import 'persistence/app_paths.dart';
|
||||
import 'persistence/storage.dart';
|
||||
import 'state/app_controller.dart';
|
||||
@@ -32,6 +32,7 @@ Future<void> main() async {
|
||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
}
|
||||
await Storage.instance.init();
|
||||
await initModuleRegistry();
|
||||
runApp(const SequenceDiagramApp());
|
||||
}
|
||||
|
||||
@@ -87,18 +88,19 @@ class _SequenceDiagramAppState extends State<SequenceDiagramApp> {
|
||||
/// 更新原生窗口标题为「模块名 - <文件名 | 未命名文件>」,
|
||||
/// 有未保存修改时追加 ` *`。
|
||||
void _updateWindowTitle() {
|
||||
final String name = _controller.currentFilePath == null
|
||||
? '未命名文件'
|
||||
: _controller.currentFilePath!.split(RegExp(r'[\\/]')).last;
|
||||
final String dirty = _controller.dirty ? ' *' : '';
|
||||
// 标题走模块注册表(首页显示品牌名,不带文件名)。
|
||||
if (_controller.appMode == AppMode.home) {
|
||||
// 标题走模块注册表:文件路径也由当前模块提供,新增模块无需改这里。
|
||||
if (_controller.isHome) {
|
||||
_windowChannel
|
||||
.invokeMethod<void>('setTitle', 'EDC易得')
|
||||
.invokeMethod<void>('setTitle', kBrandName)
|
||||
.catchError((Object _) {});
|
||||
return;
|
||||
}
|
||||
final String brand = appModeLabel(_controller.appMode);
|
||||
final EdcModule? module = moduleById(_controller.activeModuleId);
|
||||
final String? path = module?.filePath(_controller) ?? _controller.currentFilePath;
|
||||
final String name =
|
||||
path == null ? '未命名文件' : path.split(RegExp(r'[\\/]')).last;
|
||||
final String dirty = _controller.dirty ? ' *' : '';
|
||||
final String brand = moduleTitle(_controller.activeModuleId);
|
||||
_windowChannel
|
||||
.invokeMethod<void>('setTitle', '$brand - $name$dirty')
|
||||
.catchError((Object _) {});
|
||||
@@ -158,7 +160,7 @@ class _SequenceDiagramAppState extends State<SequenceDiagramApp> {
|
||||
// 恢复流程:choice == 1 走 .bak 备份,否则走自动快照;解码失败时静默忽略。
|
||||
// 当前快照仅为时序图文档:恢复前先切到对应模块(避免停留在首页看不到内容)。
|
||||
try {
|
||||
_controller.setAppMode(AppMode.sequence);
|
||||
_controller.setModuleId('sequence', status: '时序图设计');
|
||||
if (choice == 1 && info.bakContent != null) {
|
||||
_controller.loadProject(Project.decode(info.bakContent!), path: info.projectPath, dirty: true);
|
||||
} else {
|
||||
@@ -177,7 +179,7 @@ class _SequenceDiagramAppState extends State<SequenceDiagramApp> {
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
final Tokens tokens = Tokens.of(_controller.brightness);
|
||||
return MaterialApp(
|
||||
title: 'EDC易得 · Easy Design Collection',
|
||||
title: 'PDS流程设计套件 · Process Design Suite',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: buildTheme(tokens),
|
||||
// 固定文本缩放;系统栏图标随主题亮度自动切换(透明系统栏,
|
||||
|
||||
+1
-13
@@ -10,7 +10,7 @@ library;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import '../arch/arch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_models.dart';
|
||||
|
||||
/// 主视图模式。
|
||||
enum ViewMode {
|
||||
@@ -24,18 +24,6 @@ enum ViewMode {
|
||||
flow,
|
||||
}
|
||||
|
||||
/// 顶层设计模块(左上角 logo「设计合集」菜单切换的对象)。
|
||||
enum AppMode {
|
||||
/// 首页(空白启动:新建 / 打开文档前的工作台)。
|
||||
home,
|
||||
|
||||
/// 时序图设计(条形 / 圆周 / 流程图)。
|
||||
sequence,
|
||||
|
||||
/// 架构图设计(手绘识别 / 系统架构)。
|
||||
architecture,
|
||||
}
|
||||
|
||||
/// 时间单位。
|
||||
enum TimeUnit {
|
||||
/// 毫秒。
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
# 模块开发速查
|
||||
|
||||
> 本目录下每个子目录 = 一个功能模块。模块入口实现 `EdcModule`,然后在
|
||||
> `registry.dart` 注册。**不要修改 `lib/ui/app_shell.dart` 来加入模块专属逻辑。**
|
||||
|
||||
## 目录约定
|
||||
|
||||
```text
|
||||
modules/
|
||||
├── module.dart # 契约:EdcModule / ModuleUiContext / PlannedModule
|
||||
├── registry.dart # ★ 唯一注册表
|
||||
├── <id>/
|
||||
│ ├── <id>_module.dart # 模块入口(元数据 / 文档生命周期 / UI 委托)
|
||||
│ ├── domain/ # 可选:模块领域模型
|
||||
│ ├── layout/ # 可选:几何布局
|
||||
│ ├── render/ # 可选:绘制
|
||||
│ ├── export/ # 可选:导出
|
||||
│ └── ui/ # 可选:模块 UI(工作区 / 工具栏 / 侧栏 / 状态栏)
|
||||
```
|
||||
|
||||
## 最小模块模板
|
||||
|
||||
```dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
|
||||
const FooModule fooModule = FooModule();
|
||||
|
||||
class FooModule extends EdcModule {
|
||||
const FooModule();
|
||||
|
||||
@override
|
||||
String get id => 'foo';
|
||||
@override
|
||||
String get name => '示例图';
|
||||
@override
|
||||
String get shortName => '示例';
|
||||
@override
|
||||
IconData get icon => Icons.widgets_outlined;
|
||||
@override
|
||||
int get accent => 0xFF38BDF8;
|
||||
@override
|
||||
String get suffix => '.foo.json';
|
||||
@override
|
||||
bool get available => true;
|
||||
@override
|
||||
String get defaultName => '未命名-示例图';
|
||||
@override
|
||||
String get blurb => '一句话简介';
|
||||
|
||||
@override
|
||||
void newDocument(AppController c) {}
|
||||
@override
|
||||
void loadDocument(AppController c, String source, {String? path}) {}
|
||||
@override
|
||||
String encodeDocument(AppController c) => '{}';
|
||||
@override
|
||||
String documentName(AppController c) => '示例图';
|
||||
@override
|
||||
String? filePath(AppController c) => null;
|
||||
@override
|
||||
bool isDirty(AppController c) => false;
|
||||
@override
|
||||
Future<void> saveTo(AppController c, String path) async {}
|
||||
@override
|
||||
Future<void> markSaved(AppController c, String displayPath) async {}
|
||||
|
||||
@override
|
||||
Widget buildWorkspace(ModuleUiContext ui) =>
|
||||
const Center(child: Text('Foo module'));
|
||||
|
||||
@override
|
||||
Widget buildStatusBar(ModuleUiContext ui) =>
|
||||
Text('示例图', style: TextStyle(color: ui.tokens.dim, fontSize: 11));
|
||||
}
|
||||
```
|
||||
|
||||
注册:
|
||||
|
||||
```dart
|
||||
// registry.dart
|
||||
import 'package:sequence_diagram/modules/foo/foo_module.dart';
|
||||
|
||||
const List<EdcModule> kModules = <EdcModule>[
|
||||
architectureModule,
|
||||
sequenceModule,
|
||||
fooModule,
|
||||
...
|
||||
];
|
||||
```
|
||||
|
||||
## 可选扩展点
|
||||
|
||||
| 方法 / 属性 | 作用 |
|
||||
| --- | --- |
|
||||
| `buildToolbarCenter(ui, compact:)` | 工具栏中段工具(视图切换 / 模块工具) |
|
||||
| `buildToolbarRight(ui)` | 工具栏右侧工具(导出 / 缩放 / 适应视图 / 单位) |
|
||||
| `buildLeftPanel(ui, floating:)` | 左侧栏;`hasLeftPanel` 控制外壳是否显示停靠 / 轨道 |
|
||||
| `buildRightPanel(ui, floating:)` | 右侧栏;`hasRightPanel` 同上 |
|
||||
| `buildStatusBar(ui)` | 底部状态栏 |
|
||||
| `buildShortcuts(ui)` | 模块快捷键,与外壳公共快捷键合并 |
|
||||
| `isReadOnly(c)` | 只读视图(撤销 / 重做置灰) |
|
||||
| `enterStatus` | 进入模块时的状态栏提示 |
|
||||
|
||||
`ModuleUiContext` 提供:
|
||||
|
||||
- `context / controller / tokens`
|
||||
- `compact / toolScale / toolFont`
|
||||
- `leftRail / rightRail / leftPanelWidth / rightPanelWidth`
|
||||
- `panelControls(left)`(外壳的钉住 / 收起按钮)
|
||||
|
||||
## 规范
|
||||
|
||||
1. 模块内使用 `package:sequence_diagram/...` 绝对导入。
|
||||
2. 模块之间禁止互相 import;共享代码上移到 `lib/` 公共层或 `lib/export/`。
|
||||
3. 不要在模块 UI 里硬编码品牌名 / 模块名;使用 `ui.controller.activeModuleId` +
|
||||
`registry` 或模块元数据。
|
||||
4. 文档新增字段必须可缺省,保证旧 JSON 可打开。
|
||||
5. 新增模块必须补测试:注册表唯一性、打开 / 保存、首页与品牌菜单。
|
||||
6. 只改 `registry.dart` 一处全局文件;如果发现必须改 `AppShell`,说明契约缺少
|
||||
扩展点,应优先扩展契约而不是加分支。
|
||||
|
||||
## 发布级模块清单
|
||||
|
||||
发布包内包含:
|
||||
|
||||
```text
|
||||
ProcessDesignSuite/modules/
|
||||
├── registry.json # 顺序 / 显示名 / 颜色 / 启用状态
|
||||
├── architecture/module.json
|
||||
├── sequence/module.json
|
||||
└── elec/io/topo/pid/module.json
|
||||
```
|
||||
|
||||
- 源码模板在 `assets/modules/`,构建时复制到发布包 `modules/`。
|
||||
- 启动时桌面优先读取 exe 同级 `modules/registry.json`,安卓读取内置
|
||||
`assets/modules/registry.json`;失败回退 `registry.dart`。
|
||||
- 清单可以调整顺序 / 名称 / 颜色 / 启用状态;未编译进应用的模块显示为
|
||||
「组件未安装」。**新增 UI 代码仍需重新构建应用(Flutter AOT 限制)**。
|
||||
|
||||
## 规划中模块
|
||||
|
||||
`elec` / `io` / `topo` / `pid` 已用 `PlannedModule` 占位并注册,首页灰显。
|
||||
实现时:
|
||||
|
||||
1. 在对应目录新增领域模型与 UI;
|
||||
2. 把 `extends PlannedModule` 改为 `extends EdcModule`(或继承新的真实模块类);
|
||||
3. 补齐文档生命周期与 `available => true`;
|
||||
4. 注册表无需变动(已经登记)。
|
||||
@@ -0,0 +1,130 @@
|
||||
/// 架构图设计模块:手绘识别、系统架构图与参数化草图。
|
||||
///
|
||||
/// 模块入口:`lib/modules/architecture/`。新增模块请参考本文件与
|
||||
/// `lib/modules/README.md`,然后在 `lib/modules/registry.dart` 注册。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/ui/architecture_ui.dart';
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
|
||||
/// 架构图模块单例。
|
||||
const ArchitectureModule architectureModule = ArchitectureModule();
|
||||
|
||||
/// 架构图设计模块。
|
||||
class ArchitectureModule extends EdcModule {
|
||||
/// 构造模块。
|
||||
const ArchitectureModule();
|
||||
|
||||
/// 稳定 id。
|
||||
static const String moduleId = 'architecture';
|
||||
|
||||
@override
|
||||
String get id => moduleId;
|
||||
@override
|
||||
String get name => '架构图';
|
||||
@override
|
||||
String get shortName => '架构图';
|
||||
@override
|
||||
IconData get icon => Icons.account_tree_outlined;
|
||||
@override
|
||||
int get accent => 0xFF34D399;
|
||||
@override
|
||||
String get suffix => '.arch.json';
|
||||
@override
|
||||
bool get available => true;
|
||||
@override
|
||||
String get defaultName => '未命名-架构图';
|
||||
@override
|
||||
String get blurb => '手绘识别 · 图形库';
|
||||
|
||||
@override
|
||||
String get enterStatus => '架构图设计 · 手绘识别';
|
||||
|
||||
@override
|
||||
void newDocument(AppController controller) {
|
||||
controller.newArchProject();
|
||||
}
|
||||
|
||||
@override
|
||||
void loadDocument(AppController controller, String source, {String? path}) {
|
||||
controller.loadArchDoc(ArchDoc.decode(source), path: path);
|
||||
}
|
||||
|
||||
@override
|
||||
String encodeDocument(AppController controller) => controller.arch.encode();
|
||||
|
||||
@override
|
||||
String documentName(AppController controller) => controller.project.name;
|
||||
|
||||
@override
|
||||
String? filePath(AppController controller) => controller.archFilePath;
|
||||
|
||||
@override
|
||||
bool isDirty(AppController controller) => controller.dirty;
|
||||
|
||||
@override
|
||||
Future<void> saveTo(AppController controller, String path) =>
|
||||
controller.saveArchAs(path);
|
||||
|
||||
@override
|
||||
Future<void> markSaved(AppController controller, String displayPath) =>
|
||||
controller.markArchSaved(displayPath);
|
||||
|
||||
@override
|
||||
bool isReadOnly(AppController controller) => false;
|
||||
|
||||
@override
|
||||
Map<ShortcutActivator, VoidCallback> buildShortcuts(ModuleUiContext ui) {
|
||||
final AppController c = ui.controller;
|
||||
return <ShortcutActivator, VoidCallback>{
|
||||
const SingleActivator(LogicalKeyboardKey.keyA, control: true): () {
|
||||
if (c.sketchMode) {
|
||||
c.selectAllSketch();
|
||||
} else {
|
||||
c.selectAllArch();
|
||||
}
|
||||
},
|
||||
const SingleActivator(LogicalKeyboardKey.delete): () {
|
||||
if (c.sketchMode) {
|
||||
c.deleteSketchSelection();
|
||||
} else {
|
||||
c.removeArchSelection();
|
||||
}
|
||||
},
|
||||
const SingleActivator(LogicalKeyboardKey.escape): () {
|
||||
if (c.sketchMode &&
|
||||
(c.sketchPendingCons != null || c.sketchPendingDim != null)) {
|
||||
c.cancelSketchCommand();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildWorkspace(ModuleUiContext ui) => ArchitectureUi(ui).buildWorkspace();
|
||||
|
||||
@override
|
||||
Widget? buildLeftPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||||
ArchitectureUi(ui).buildLeftPanel(ui.tokens, floating: floating);
|
||||
|
||||
@override
|
||||
Widget? buildRightPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||||
ArchitectureUi(ui).buildRightPanel(ui.tokens, floating: floating);
|
||||
|
||||
@override
|
||||
List<Widget> buildToolbarCenter(ModuleUiContext ui, {required bool compact}) =>
|
||||
ArchitectureUi(ui).buildToolbarCenter(ui.tokens, compact: compact);
|
||||
|
||||
@override
|
||||
List<Widget> buildToolbarRight(ModuleUiContext ui) =>
|
||||
ArchitectureUi(ui).buildToolbarRight(ui.tokens, compact: ui.compact);
|
||||
|
||||
@override
|
||||
Widget buildStatusBar(ModuleUiContext ui) =>
|
||||
ArchitectureUi(ui).buildStatusBar(ui.tokens);
|
||||
}
|
||||
@@ -11,7 +11,7 @@ library;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../library/symbol_library.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/library/symbol_library.dart';
|
||||
import 'arch_models.dart';
|
||||
import 'arch_painter.dart';
|
||||
|
||||
@@ -12,9 +12,9 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../export/export_fit.dart';
|
||||
import '../library/symbol_library.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/export/export_geometry.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/library/symbol_library.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'arch_models.dart';
|
||||
import 'arch_painter.dart';
|
||||
|
||||
@@ -40,7 +40,7 @@ Future<Uint8List> renderArchPng({
|
||||
// 标题与副标题(固定左上角)。
|
||||
_text(canvas, '架构图设计', const Offset(48, 36),
|
||||
color: et.text, size: 34, weight: FontWeight.w700);
|
||||
_text(canvas, 'EDC易得 · Easy Design Collection · 手绘识别架构图', const Offset(48, 88),
|
||||
_text(canvas, 'PDS流程设计套件 · Process Design Suite · 手绘识别架构图', const Offset(48, 88),
|
||||
color: et.sub, size: 16, weight: FontWeight.w400);
|
||||
|
||||
// 内容适配(白底令牌 + 关闭网格点阵)。
|
||||
@@ -56,7 +56,7 @@ Future<Uint8List> renderArchPng({
|
||||
|
||||
_text(
|
||||
canvas,
|
||||
'EDC易得 · 架构图设计 · $projectName · 元件 ${doc.shapes.length} · 连线 '
|
||||
'PDS流程设计套件 · 架构图设计 · $projectName · 元件 ${doc.shapes.length} · 连线 '
|
||||
'${doc.connectors.length} · 墨迹 ${doc.strokes.length}',
|
||||
Offset(48, h - 38),
|
||||
color: et.sub,
|
||||
@@ -16,7 +16,7 @@ import 'dart:convert';
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' show Offset, Path, Rect, Size;
|
||||
|
||||
import '../sketch/sketch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_models.dart';
|
||||
|
||||
/// 架构图画布当前工具。
|
||||
enum ArchTool {
|
||||
@@ -11,9 +11,9 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../library/symbol_library.dart';
|
||||
import '../sketch/sketch_painter.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/library/symbol_library.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_painter.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'arch_models.dart';
|
||||
|
||||
/// 一次「墨迹 → 标准图形」的转化动画记录。
|
||||
+1
-1
@@ -11,7 +11,7 @@ library;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' show Offset, Path, PathMetric, Rect, Tangent;
|
||||
|
||||
import '../library/symbol_library.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/library/symbol_library.dart';
|
||||
|
||||
/// 图元匹配结果。
|
||||
class ArchSymbolMatch {
|
||||
+1
-1
@@ -9,7 +9,7 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'sketch_models.dart';
|
||||
|
||||
/// 草图配色(浅 / 深色主题下都可读)。
|
||||
@@ -8,12 +8,12 @@ library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../arch/arch_models.dart';
|
||||
import '../sketch/sketch_models.dart';
|
||||
import '../sketch/sketch_solver.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_solver.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||||
|
||||
/// 小节标题。
|
||||
Widget _sec(Tokens t, String s) => Text(
|
||||
@@ -14,17 +14,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../arch/arch_models.dart';
|
||||
import '../arch/arch_painter.dart';
|
||||
import '../arch/arch_recognizer.dart';
|
||||
import '../arch/arch_symbol_recognizer.dart';
|
||||
import '../library/symbol_library.dart';
|
||||
import '../sketch/sketch_models.dart';
|
||||
import '../sketch/sketch_painter.dart';
|
||||
import '../sketch/sketch_solver.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_painter.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_recognizer.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_symbol_recognizer.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/library/symbol_library.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_painter.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_solver.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||||
|
||||
/// 连线拖拽吸附结果:吸附后的坐标 + 对齐导引(null = 该轴无对齐)。
|
||||
typedef ConnSnap = ({double x, double y, double? gx, double? gy});
|
||||
@@ -0,0 +1,617 @@
|
||||
/// 架构图模块 UI:工具栏中段 / 右侧工具、左右侧栏、状态栏。
|
||||
///
|
||||
/// 由 `ArchitectureModule` 通过 `lib/modules/registry.dart` 注册后由外壳调用。
|
||||
library;
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_dxf.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_export.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_solver.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/ui/arch_panel.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/ui/arch_view.dart';
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
import 'package:sequence_diagram/persistence/android_docs.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||||
|
||||
/// 架构图模块 UI 构建器。
|
||||
class ArchitectureUi {
|
||||
/// 构造 UI 构建器。
|
||||
const ArchitectureUi(this.ui);
|
||||
|
||||
/// 外壳上下文。
|
||||
final ModuleUiContext ui;
|
||||
|
||||
AppController get c => ui.controller;
|
||||
BuildContext get context => ui.context;
|
||||
Tokens get t => ui.tokens;
|
||||
double get _toolScale => ui.toolScale;
|
||||
double _toolFont(double size) => ui.toolFont(size);
|
||||
double get _leftPanelWidth => ui.leftPanelWidth;
|
||||
double get _rightPanelWidth => ui.rightPanelWidth;
|
||||
Widget _panelControls(Tokens t, bool left) => ui.panelControls(left);
|
||||
|
||||
/// 工具栏中段:选择 / 手绘 / 连线 / 橡皮 + 识别。
|
||||
List<Widget> buildToolbarCenter(Tokens t, {required bool compact}) =>
|
||||
<Widget>[_archTools(t, compact)];
|
||||
|
||||
/// 工具栏右侧:导出 / 缩放 / 适应视图。
|
||||
List<Widget> buildToolbarRight(Tokens t, {required bool compact}) => <Widget>[
|
||||
_exportMenu(t),
|
||||
SizedBox(width: (compact ? 4 : 6) * _toolScale),
|
||||
_zoomBox(t),
|
||||
SizedBox(width: (compact ? 4 : 6) * _toolScale),
|
||||
_iconBtn(t, Icons.crop_free, c.archFit, tooltip: '适应视图'),
|
||||
];
|
||||
|
||||
/// 左侧栏。
|
||||
Widget buildLeftPanel(Tokens t, {bool floating = false}) =>
|
||||
_archLeftPanel(t, floating: floating);
|
||||
|
||||
/// 右侧栏。
|
||||
Widget buildRightPanel(Tokens t, {bool floating = false}) =>
|
||||
_archRightPanel(t, floating: floating);
|
||||
|
||||
/// 底部状态栏。
|
||||
Widget buildStatusBar(Tokens t) => _archStatusBar(t);
|
||||
|
||||
/// 工作区:架构图画布。
|
||||
Widget buildWorkspace() => Container(
|
||||
color: t.canvas2,
|
||||
child: ArchView(controller: c),
|
||||
);
|
||||
|
||||
|
||||
/// 缩放控件:显示当前百分比并提供缩小 / 放大按钮。
|
||||
Widget _zoomBox(Tokens t) {
|
||||
final double s = _toolScale;
|
||||
final double zoom = c.arch.zoom;
|
||||
final String pct = '${(zoom * 100).round()}%';
|
||||
return Container(
|
||||
height: 34 * s,
|
||||
padding: EdgeInsets.symmetric(horizontal: 4 * s),
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
_miniIcon(t, Icons.remove, () => c.archZoomBy(0.9)),
|
||||
SizedBox(
|
||||
width: 52 * s,
|
||||
child: Text(pct,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: t.text, fontSize: _toolFont(11))),
|
||||
),
|
||||
_miniIcon(t, Icons.add, () => c.archZoomBy(1.1)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 导出菜单:SVG / PNG / DXF。
|
||||
Widget _exportMenu(Tokens t) {
|
||||
final double s = _toolScale;
|
||||
final bool licensed = c.licensed;
|
||||
final Color fg = licensed ? Colors.white : t.dim;
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 3 * s),
|
||||
child: PopupMenuButton<String>(
|
||||
tooltip: '导出(SVG / PNG / DXF)· 架构图',
|
||||
color: t.panel2,
|
||||
position: PopupMenuPosition.under,
|
||||
onSelected: (String v) {
|
||||
if (v == 'svg') _exportArchSvg();
|
||||
if (v == 'png') _exportArchPng();
|
||||
if (v == 'dxf') _exportArchDxf();
|
||||
},
|
||||
itemBuilder: (BuildContext ctx) => <PopupMenuEntry<String>>[
|
||||
_exportItem(t, 'svg', Icons.code, '导出 SVG',
|
||||
'矢量图:架构图无损缩放 / 二次编辑', licensed),
|
||||
_exportItem(t, 'png', Icons.image_outlined, '导出 PNG',
|
||||
'位图(3840×2160):分享 / 汇报', licensed),
|
||||
_exportItem(t, 'dxf', Icons.architecture, '导出 DXF',
|
||||
'AutoCAD / DraftSight 等可编辑的 CAD 图纸', licensed),
|
||||
],
|
||||
child: Container(
|
||||
height: 34 * s,
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * s),
|
||||
decoration: BoxDecoration(
|
||||
color: licensed ? t.accent2 : t.panel2,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Icon(Icons.ios_share, size: 15 * s, color: fg),
|
||||
SizedBox(width: 6 * s),
|
||||
Text('导出',
|
||||
style: TextStyle(
|
||||
fontSize: _toolFont(11),
|
||||
fontWeight: FontWeight.w600,
|
||||
color: fg)),
|
||||
Icon(Icons.arrow_drop_down, size: 18 * s, color: fg),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _archTools(Tokens t, bool compact) {
|
||||
// 草图模式:工具在左侧栏,这里显示状态与快捷退出。
|
||||
if (c.sketchMode) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * _toolScale),
|
||||
height: 34 * _toolScale,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: t.accent),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Icon(Icons.edit_note, size: 15 * _toolScale, color: t.accent),
|
||||
SizedBox(width: 6 * _toolScale),
|
||||
Text(
|
||||
'参数化草图 · ${sketchToolLabel(c.sketchTool)}',
|
||||
style: TextStyle(
|
||||
color: t.accent,
|
||||
fontSize: _toolFont(11),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10 * _toolScale),
|
||||
InkWell(
|
||||
onTap: () => c.setSketchMode(false),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 8 * _toolScale, vertical: 3 * _toolScale),
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel2,
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
border: Border.all(color: t.line),
|
||||
),
|
||||
child: Text('退出草图',
|
||||
style:
|
||||
TextStyle(color: t.sub, fontSize: _toolFont(10.5))),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
final ArchTool tool = c.archTool;
|
||||
Widget seg(String label, IconData icon, ArchTool value, String tip) {
|
||||
final bool active = tool == value;
|
||||
return Tooltip(
|
||||
message: tip,
|
||||
child: InkWell(
|
||||
onTap: () => c.setArchTool(value),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Container(
|
||||
width: (compact ? 74 : 90) * _toolScale,
|
||||
height: 34 * _toolScale,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: active ? t.accent.withValues(alpha: 0.16) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: active ? Border.all(color: t.accent, width: 1.4) : null,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Icon(icon, size: 15 * _toolScale, color: active ? t.accent : t.sub),
|
||||
SizedBox(width: 4 * _toolScale),
|
||||
Text(label,
|
||||
style: TextStyle(
|
||||
color: active ? t.accent : t.sub,
|
||||
fontWeight: active ? FontWeight.w600 : FontWeight.normal,
|
||||
fontSize: _toolFont(12),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.all(3 * _toolScale),
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
seg('选择', Icons.near_me_outlined, ArchTool.select, '选择 / 移动 / 缩放'),
|
||||
seg('手绘', Icons.gesture, ArchTool.pen,
|
||||
c.archAutoRecognize ? '按住拖动绘制,松手自动识别' : '按住拖动绘制;画完点「识别」确认识别'),
|
||||
seg('连线', Icons.arrow_right_alt, ArchTool.connect,
|
||||
'从图形拖到另一个图形(横平竖直正交走线,角点可拖拽)'),
|
||||
seg('橡皮', Icons.cleaning_services_outlined, ArchTool.eraser,
|
||||
'擦除图形 / 墨迹 / 连线(拖动连擦,一次撤销可整体回退)'),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(width: 6 * _toolScale),
|
||||
// 「识别」确认按钮:手动模式下把待识别墨迹统一识别(自动模式下也可用)。
|
||||
Container(
|
||||
padding: EdgeInsets.all(3 * _toolScale),
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: t.line2),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: c.arch.strokes.isEmpty ? null : c.archRecognizeInk,
|
||||
borderRadius: BorderRadius.circular(9),
|
||||
child: Container(
|
||||
height: 34 * _toolScale,
|
||||
padding: EdgeInsets.symmetric(horizontal: 12 * _toolScale),
|
||||
alignment: Alignment.center,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Icon(Icons.auto_fix_high,
|
||||
size: 15 * _toolScale,
|
||||
color: c.arch.strokes.isEmpty ? t.dim : t.accent),
|
||||
SizedBox(width: 5 * _toolScale),
|
||||
Text(
|
||||
'识别(${c.arch.strokes.length})',
|
||||
style: TextStyle(
|
||||
color: c.arch.strokes.isEmpty ? t.dim : t.accent,
|
||||
fontSize: _toolFont(11),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _miniIcon(Tokens t, IconData icon, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(6 * _toolScale),
|
||||
child: Icon(icon, size: 15 * _toolScale, color: t.sub),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
PopupMenuItem<String> _exportItem(
|
||||
Tokens t, String value, IconData icon, String label, String hint, bool enabled) {
|
||||
final Color main = enabled ? t.text : t.dim;
|
||||
return PopupMenuItem<String>(
|
||||
value: value,
|
||||
enabled: enabled,
|
||||
height: 46,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(icon, size: 17, color: enabled ? t.accent : t.dim),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(label,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: main, fontSize: 12.5, fontWeight: FontWeight.w600)),
|
||||
Text(hint,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: enabled ? t.dim : t.dim.withValues(alpha: 0.6), fontSize: 10)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _iconBtn(Tokens t, IconData icon, VoidCallback? onTap, {String? tooltip, Color? color}) {
|
||||
final double s = _toolScale;
|
||||
return IconButton(
|
||||
onPressed: onTap,
|
||||
icon: Icon(icon, size: 18 * s, color: onTap == null ? t.dim : (color ?? t.text)),
|
||||
tooltip: tooltip,
|
||||
splashRadius: 16 * s,
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: BoxConstraints(minWidth: 34 * s, minHeight: 34 * s),
|
||||
// 新版 Flutter 的 IconButton 已移除 tapTargetSize 形参,改由 style 提供。
|
||||
style: IconButton.styleFrom(tapTargetSize: s < 1 ? MaterialTapTargetSize.shrinkWrap : null),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _exportArchSvg() async {
|
||||
if (!c.licensed) {
|
||||
if (context.mounted) {
|
||||
await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 SVG。');
|
||||
}
|
||||
return;
|
||||
}
|
||||
final String svg = buildArchSvg(doc: c.arch, baseTokens: Tokens.of(c.brightness));
|
||||
if (AndroidDocs.isAvailable) {
|
||||
final String? name = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => AndroidFileDialog(
|
||||
saveMode: true,
|
||||
defaultName: '${c.project.name}-架构图.svg',
|
||||
suffix: '.svg',
|
||||
),
|
||||
);
|
||||
if (name == null) return;
|
||||
try {
|
||||
await AndroidDocs.saveFile(name, Uint8List.fromList(utf8.encode(svg)),
|
||||
mime: 'image/svg+xml');
|
||||
if (context.mounted) c.setStatus('已导出 ${AndroidDocs.location()}/$name');
|
||||
} catch (e) {
|
||||
if (context.mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
return;
|
||||
}
|
||||
final String? path = await pickFile(
|
||||
context,
|
||||
save: true,
|
||||
defaultName: '${c.project.name}-架构图.svg',
|
||||
suffix: '.svg',
|
||||
);
|
||||
if (path == null) return;
|
||||
try {
|
||||
await File(path).writeAsString(svg, flush: true);
|
||||
if (context.mounted) c.setStatus('已导出 $path');
|
||||
} catch (e) {
|
||||
if (context.mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _exportArchPng() async {
|
||||
if (!c.licensed) {
|
||||
if (context.mounted) {
|
||||
await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 PNG。');
|
||||
}
|
||||
return;
|
||||
}
|
||||
final Uint8List bytes;
|
||||
try {
|
||||
bytes = await renderArchPng(
|
||||
doc: c.arch,
|
||||
baseTokens: Tokens.of(c.brightness),
|
||||
projectName: c.project.name,
|
||||
);
|
||||
} catch (e) {
|
||||
if (context.mounted) await showMessage(context, '导出失败', '$e');
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
if (AndroidDocs.isAvailable) {
|
||||
final String? name = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => AndroidFileDialog(
|
||||
saveMode: true,
|
||||
defaultName: '${c.project.name}-架构图.png',
|
||||
suffix: '.png',
|
||||
),
|
||||
);
|
||||
if (name == null) return;
|
||||
try {
|
||||
await AndroidDocs.saveFile(name, bytes, mime: 'image/png');
|
||||
if (context.mounted) c.setStatus('已导出 ${AndroidDocs.location()}/$name');
|
||||
} catch (e) {
|
||||
if (context.mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
return;
|
||||
}
|
||||
final String? path = await pickFile(
|
||||
context,
|
||||
save: true,
|
||||
defaultName: '${c.project.name}-架构图.png',
|
||||
suffix: '.png',
|
||||
);
|
||||
if (path == null) return;
|
||||
try {
|
||||
await File(path).writeAsBytes(bytes, flush: true);
|
||||
if (context.mounted) c.setStatus('已导出 $path');
|
||||
} catch (e) {
|
||||
if (context.mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _exportArchDxf() async {
|
||||
if (!c.licensed) {
|
||||
if (context.mounted) {
|
||||
await showMessage(context, '未授权', '未检测到有效授权(license/*.lic),无法导出 DXF。');
|
||||
}
|
||||
return;
|
||||
}
|
||||
final String dxf = buildArchDxf(doc: c.arch);
|
||||
if (AndroidDocs.isAvailable) {
|
||||
final String? name = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (_) => AndroidFileDialog(
|
||||
saveMode: true,
|
||||
defaultName: '${c.project.name}-架构图.dxf',
|
||||
suffix: '.dxf',
|
||||
),
|
||||
);
|
||||
if (name == null) return;
|
||||
try {
|
||||
await AndroidDocs.saveFile(name, Uint8List.fromList(utf8.encode(dxf)),
|
||||
mime: 'application/dxf');
|
||||
if (context.mounted) c.setStatus('已导出 ${AndroidDocs.location()}/$name');
|
||||
} catch (e) {
|
||||
if (context.mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
return;
|
||||
}
|
||||
final String? path = await pickFile(
|
||||
context,
|
||||
save: true,
|
||||
defaultName: '${c.project.name}-架构图.dxf',
|
||||
suffix: '.dxf',
|
||||
);
|
||||
if (path == null) return;
|
||||
try {
|
||||
await File(path).writeAsString(dxf, flush: true);
|
||||
if (context.mounted) c.setStatus('已导出 $path');
|
||||
} catch (e) {
|
||||
if (context.mounted) await showMessage(context, '导出失败', '$e');
|
||||
}
|
||||
}
|
||||
|
||||
Widget _archLeftPanel(Tokens t, {bool floating = false}) {
|
||||
return Container(
|
||||
width: _leftPanelWidth,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
border: floating ? Border.all(color: t.line2) : Border(right: BorderSide(color: t.line)),
|
||||
boxShadow: floating
|
||||
? <BoxShadow>[BoxShadow(color: Colors.black.withValues(alpha: 0.4), blurRadius: 20, offset: const Offset(4, 0))]
|
||||
: null,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(12, 10, 12, 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
children: <Widget>[
|
||||
_sectionLabel(t, '架构图 · 设计工具'),
|
||||
const Spacer(),
|
||||
_panelControls(t, true),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ArchLeftBody(controller: c),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _archRightPanel(Tokens t, {bool floating = false}) {
|
||||
return Container(
|
||||
width: _rightPanelWidth,
|
||||
decoration: BoxDecoration(
|
||||
color: t.panel,
|
||||
border: floating ? Border.all(color: t.line2) : Border(left: BorderSide(color: t.line)),
|
||||
boxShadow: floating
|
||||
? <BoxShadow>[BoxShadow(color: Colors.black.withValues(alpha: 0.4), blurRadius: 20, offset: const Offset(-4, 0))]
|
||||
: null,
|
||||
),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 10, 0),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
_sectionLabel(t, '属性 · 架构图'),
|
||||
const Spacer(),
|
||||
_panelControls(t, false),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(14, 8, 14, 16),
|
||||
child: ArchRightBody(controller: c),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _sectionLabel(Tokens t, String s) => Text(
|
||||
s,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(color: t.text2, fontSize: 11.5, letterSpacing: 1.2, fontWeight: FontWeight.w600),
|
||||
);
|
||||
|
||||
Widget _archStatusBar(Tokens t) {
|
||||
final ArchDoc doc = c.arch;
|
||||
final String toolLabel = c.sketchMode
|
||||
? '草图·${sketchToolLabel(c.sketchTool)}'
|
||||
: switch (c.archTool) {
|
||||
ArchTool.select => '选择',
|
||||
ArchTool.pen => c.archAutoRecognize ? '手绘识别' : '手绘(待确认)',
|
||||
ArchTool.connect => '连线',
|
||||
ArchTool.eraser => '橡皮',
|
||||
};
|
||||
final List<String> items = <String>[
|
||||
c.sketchMode ? '参数化草图' : '架构图模式',
|
||||
if (c.sketchMode) ...<String>[
|
||||
'实体 ${doc.sketch.entities.length}',
|
||||
'约束 ${doc.sketch.constraints.where((SketchConstraint k) => !k.internal).length}',
|
||||
'尺寸 ${doc.sketch.dims.length}',
|
||||
'自由度 ${sketchDofCount(doc.sketch)}',
|
||||
] else ...<String>[
|
||||
'元件 ${doc.shapes.length}',
|
||||
'连线 ${doc.connectors.length}',
|
||||
'墨迹 ${doc.strokes.length}',
|
||||
'图层 ${doc.layerById(doc.activeLayer).name}',
|
||||
],
|
||||
'工具 $toolLabel',
|
||||
if (!c.sketchMode && c.archOrtho) '正交 开',
|
||||
if (!c.sketchMode && c.archPolar) '极轴 ${c.archPolarDeg.round()}°',
|
||||
'缩放 ${(doc.zoom * 100).round()}%',
|
||||
c.status,
|
||||
];
|
||||
return Container(
|
||||
height: 32,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: t.chrome,
|
||||
border: Border(top: BorderSide(color: t.line2)),
|
||||
),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: items.map((String s) {
|
||||
final bool last = s == items.last;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 22),
|
||||
child: Text(s, style: TextStyle(color: last ? t.ok : t.sub, fontSize: 11)),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (c.dirty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 14),
|
||||
child: Text('● 未保存', style: TextStyle(color: t.warn, fontSize: 11)),
|
||||
),
|
||||
Text('F1 帮助 · Ctrl+Z 撤销 · Ctrl+S 保存', style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/// 电器原理图模块(规划中)。
|
||||
///
|
||||
/// 当前仅注册元数据与占位实现;实现时在 `lib/modules/elec/` 下补齐文档模型
|
||||
/// 与 UI,并在本类中替换 `PlannedModule` 为真实 [EdcModule] 实现即可。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
|
||||
/// 电器原理图模块单例(未开放)。
|
||||
const ElecModule elecModule = ElecModule();
|
||||
|
||||
/// 电器原理图模块。
|
||||
class ElecModule extends PlannedModule {
|
||||
/// 构造模块。
|
||||
const ElecModule()
|
||||
: super(
|
||||
id: 'elec',
|
||||
name: '电器原理图',
|
||||
shortName: '电气',
|
||||
icon: Icons.electric_bolt,
|
||||
accent: 0xFFFFB020,
|
||||
suffix: '.elec.json',
|
||||
defaultName: '未命名-电器原理图',
|
||||
blurb: '回路 · 元件 · 线号',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/// IO 表模块(规划中)。
|
||||
///
|
||||
/// 当前仅注册元数据与占位实现;实现时在 `lib/modules/io/` 下补齐文档模型
|
||||
/// 与 UI,并在本类中替换 `PlannedModule` 为真实 [EdcModule] 实现即可。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
|
||||
/// IO 表模块单例(未开放)。
|
||||
const IoModule ioModule = IoModule();
|
||||
|
||||
/// IO 表模块。
|
||||
class IoModule extends PlannedModule {
|
||||
/// 构造模块。
|
||||
const IoModule()
|
||||
: super(
|
||||
id: 'io',
|
||||
name: 'IO 表',
|
||||
shortName: 'IO表',
|
||||
icon: Icons.grid_on,
|
||||
accent: 0xFFA78BFA,
|
||||
suffix: '.io.json',
|
||||
defaultName: '未命名-IO表',
|
||||
blurb: '点位 · 符号 · 注释',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
/// 发布级模块清单:`modules/registry.json` + 每模块 `module.json` 的解析与合并。
|
||||
///
|
||||
/// 源码注册表(`lib/modules/registry.dart`)决定**编译进应用**的模块实现;
|
||||
/// 发布清单决定**发布包**里的模块顺序、显示名、启用状态与元数据。应用启动时:
|
||||
///
|
||||
/// 1. 桌面优先读取 exe 同级 `modules/registry.json`(发布包可见、可编辑);
|
||||
/// 2. 安卓 / 开发环境回退到内置资源 `assets/modules/registry.json`;
|
||||
/// 3. 清单缺失或损坏时回退到编译期注册表。
|
||||
///
|
||||
/// 注意:Flutter release 的 Dart 代码是 AOT 编译的,清单不能动态加载新的
|
||||
/// Dart 实现;清单中未编译的模块会显示为「组件未安装」(未开放)。
|
||||
library;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
|
||||
/// 发布清单中的单个模块配置。
|
||||
class ModuleManifestEntry {
|
||||
/// 构造模块清单项。
|
||||
const ModuleManifestEntry({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.shortName,
|
||||
required this.icon,
|
||||
required this.accent,
|
||||
required this.suffix,
|
||||
required this.available,
|
||||
required this.defaultName,
|
||||
required this.blurb,
|
||||
this.enterStatus = '',
|
||||
this.version = '',
|
||||
});
|
||||
|
||||
/// 模块稳定 id。
|
||||
final String id;
|
||||
/// 模块显示名。
|
||||
final String name;
|
||||
/// 短名。
|
||||
final String shortName;
|
||||
/// 图标名称(见 [moduleIconFromName])。
|
||||
final String icon;
|
||||
/// 品牌色(ARGB int)。
|
||||
final int accent;
|
||||
/// 文档后缀。
|
||||
final String suffix;
|
||||
/// 是否启用。
|
||||
final bool available;
|
||||
/// 新建文档默认文件名。
|
||||
final String defaultName;
|
||||
/// 一句话简介。
|
||||
final String blurb;
|
||||
/// 进入模块状态提示。
|
||||
final String enterStatus;
|
||||
/// 模块版本(发布包展示 / 升级判断用)。
|
||||
final String version;
|
||||
|
||||
/// 从 JSON 解析;缺失字段使用安全默认值。
|
||||
static ModuleManifestEntry fromJson(Map<String, dynamic> j) {
|
||||
return ModuleManifestEntry(
|
||||
id: (j['id'] as String?)?.trim() ?? '',
|
||||
name: (j['name'] as String?)?.trim() ?? '',
|
||||
shortName: (j['shortName'] as String?)?.trim() ?? '',
|
||||
icon: (j['icon'] as String?)?.trim() ?? '',
|
||||
accent: parseModuleAccent(j['accent']),
|
||||
suffix: (j['suffix'] as String?)?.trim() ?? '',
|
||||
available: j['available'] as bool? ?? true,
|
||||
defaultName: (j['defaultName'] as String?)?.trim() ?? '',
|
||||
blurb: (j['blurb'] as String?)?.trim() ?? '',
|
||||
enterStatus: (j['enterStatus'] as String?)?.trim() ?? '',
|
||||
version: (j['version'] as String?)?.trim() ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 发布清单根对象。
|
||||
class ModuleManifest {
|
||||
/// 构造清单。
|
||||
const ModuleManifest({
|
||||
required this.schema,
|
||||
required this.version,
|
||||
required this.modules,
|
||||
});
|
||||
|
||||
/// 协议标识(`pds.modules/1`)。
|
||||
final String schema;
|
||||
/// 发布版本。
|
||||
final String version;
|
||||
/// 模块列表(顺序即首页 / 菜单顺序)。
|
||||
final List<ModuleManifestEntry> modules;
|
||||
|
||||
/// 从 JSON 解析清单。
|
||||
///
|
||||
/// 支持两种写法:`{"modules":[...]}` 或直接数组 `[...]`。
|
||||
static ModuleManifest parse(String source) {
|
||||
final Object? decoded = jsonDecode(source);
|
||||
final Map<String, dynamic>? root =
|
||||
decoded is Map<String, dynamic> ? decoded : null;
|
||||
final List<dynamic> raw = root != null
|
||||
? (root['modules'] as List<dynamic>? ?? const <dynamic>[])
|
||||
: (decoded is List<dynamic> ? decoded : const <dynamic>[]);
|
||||
final List<ModuleManifestEntry> modules = <ModuleManifestEntry>[
|
||||
for (final dynamic e in raw)
|
||||
if (e is Map<String, dynamic>)
|
||||
ModuleManifestEntry.fromJson(e),
|
||||
]..removeWhere((ModuleManifestEntry e) => e.id.isEmpty);
|
||||
return ModuleManifest(
|
||||
schema: (root?['schema'] as String?) ?? 'pds.modules/1',
|
||||
version: (root?['version'] as String?) ?? '',
|
||||
modules: modules,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 把发布清单与编译期模块合并为实际可用的模块列表。
|
||||
///
|
||||
/// - 清单顺序决定展示顺序;
|
||||
/// - 编译期存在的模块使用清单元数据覆盖显示名 / 颜色 / 启用状态;
|
||||
/// - 清单中有、但未编译进应用的模块生成为「组件未安装」占位;
|
||||
/// - 清单为空时回退编译期列表。
|
||||
List<EdcModule> resolveModulesFromManifest(
|
||||
ModuleManifest manifest,
|
||||
List<EdcModule> compiled,
|
||||
) {
|
||||
if (manifest.modules.isEmpty) return compiled;
|
||||
final Map<String, EdcModule> byId = <String, EdcModule>{
|
||||
for (final EdcModule m in compiled) m.id: m,
|
||||
};
|
||||
final List<EdcModule> out = <EdcModule>[];
|
||||
for (final ModuleManifestEntry entry in manifest.modules) {
|
||||
final EdcModule? base = byId.remove(entry.id);
|
||||
if (base == null) {
|
||||
out.add(ManifestOnlyModule(entry));
|
||||
} else {
|
||||
out.add(ConfiguredModule(base: base, entry: entry));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 编译期模块 + 发布清单元数据的包装。
|
||||
class ConfiguredModule extends EdcModule {
|
||||
/// 构造包装。
|
||||
const ConfiguredModule({required this.base, required this.entry});
|
||||
|
||||
/// 编译期实现。
|
||||
final EdcModule base;
|
||||
|
||||
/// 发布清单配置。
|
||||
final ModuleManifestEntry entry;
|
||||
|
||||
@override
|
||||
String get id => base.id;
|
||||
@override
|
||||
String get name => entry.name.isEmpty ? base.name : entry.name;
|
||||
@override
|
||||
String get shortName => entry.shortName.isEmpty ? base.shortName : entry.shortName;
|
||||
@override
|
||||
IconData get icon => moduleIconFromName(entry.icon) ?? base.icon;
|
||||
@override
|
||||
int get accent => entry.accent == 0 ? base.accent : entry.accent;
|
||||
@override
|
||||
String get suffix => entry.suffix.isEmpty ? base.suffix : entry.suffix;
|
||||
@override
|
||||
bool get available => entry.available && base.available;
|
||||
@override
|
||||
String get defaultName => entry.defaultName.isEmpty ? base.defaultName : entry.defaultName;
|
||||
@override
|
||||
String get blurb => entry.blurb.isEmpty ? base.blurb : entry.blurb;
|
||||
@override
|
||||
String get enterStatus =>
|
||||
entry.enterStatus.isEmpty ? base.enterStatus : entry.enterStatus;
|
||||
|
||||
@override
|
||||
bool get hasLeftPanel => base.hasLeftPanel;
|
||||
@override
|
||||
bool get hasRightPanel => base.hasRightPanel;
|
||||
|
||||
@override
|
||||
void newDocument(AppController controller) => base.newDocument(controller);
|
||||
@override
|
||||
void loadDocument(AppController controller, String source, {String? path}) =>
|
||||
base.loadDocument(controller, source, path: path);
|
||||
@override
|
||||
String encodeDocument(AppController controller) => base.encodeDocument(controller);
|
||||
@override
|
||||
String documentName(AppController controller) => base.documentName(controller);
|
||||
@override
|
||||
String? filePath(AppController controller) => base.filePath(controller);
|
||||
@override
|
||||
bool isDirty(AppController controller) => base.isDirty(controller);
|
||||
@override
|
||||
Future<void> saveTo(AppController controller, String path) =>
|
||||
base.saveTo(controller, path);
|
||||
@override
|
||||
Future<void> markSaved(AppController controller, String displayPath) =>
|
||||
base.markSaved(controller, displayPath);
|
||||
@override
|
||||
bool isReadOnly(AppController controller) => base.isReadOnly(controller);
|
||||
@override
|
||||
Map<ShortcutActivator, VoidCallback> buildShortcuts(ModuleUiContext ui) =>
|
||||
base.buildShortcuts(ui);
|
||||
@override
|
||||
Widget buildWorkspace(ModuleUiContext ui) => base.buildWorkspace(ui);
|
||||
@override
|
||||
Widget? buildLeftPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||||
base.buildLeftPanel(ui, floating: floating);
|
||||
@override
|
||||
Widget? buildRightPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||||
base.buildRightPanel(ui, floating: floating);
|
||||
@override
|
||||
Widget buildStatusBar(ModuleUiContext ui) => base.buildStatusBar(ui);
|
||||
@override
|
||||
List<Widget> buildToolbarCenter(ModuleUiContext ui, {required bool compact}) =>
|
||||
base.buildToolbarCenter(ui, compact: compact);
|
||||
@override
|
||||
List<Widget> buildToolbarRight(ModuleUiContext ui) =>
|
||||
base.buildToolbarRight(ui);
|
||||
}
|
||||
|
||||
/// 发布清单中存在、但应用未编译该模块实现时的占位。
|
||||
class ManifestOnlyModule extends PlannedModule {
|
||||
/// 构造未安装模块。
|
||||
ManifestOnlyModule(ModuleManifestEntry entry)
|
||||
: super(
|
||||
id: entry.id,
|
||||
name: entry.name.isEmpty ? entry.id : entry.name,
|
||||
shortName: entry.shortName.isEmpty ? entry.id : entry.shortName,
|
||||
icon: moduleIconFromName(entry.icon) ?? Icons.widgets_outlined,
|
||||
accent: entry.accent == 0 ? 0xFF94A3B8 : entry.accent,
|
||||
suffix: entry.suffix,
|
||||
defaultName: entry.defaultName,
|
||||
blurb: entry.blurb.isEmpty ? '组件未安装' : '${entry.blurb} · 组件未安装',
|
||||
);
|
||||
}
|
||||
|
||||
/// 清单图标名称 → Material 图标。
|
||||
IconData? moduleIconFromName(String name) {
|
||||
return switch (name) {
|
||||
'account_tree_outlined' => Icons.account_tree_outlined,
|
||||
'waterfall_chart' => Icons.waterfall_chart,
|
||||
'electric_bolt' => Icons.electric_bolt,
|
||||
'grid_on' => Icons.grid_on,
|
||||
'hub_outlined' => Icons.hub_outlined,
|
||||
'plumbing' => Icons.plumbing,
|
||||
'widgets_outlined' => Icons.widgets_outlined,
|
||||
'dashboard_outlined' => Icons.dashboard_outlined,
|
||||
'schema_outlined' => Icons.schema_outlined,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
/// 解析清单颜色:`#RRGGBB` / `#AARRGGBB` / `0xAARRGGBB` / 十进制整数。
|
||||
int parseModuleAccent(Object? value) {
|
||||
if (value is int) return value;
|
||||
if (value is! String) return 0;
|
||||
String s = value.trim();
|
||||
if (s.isEmpty) return 0;
|
||||
if (s.startsWith('#')) s = s.substring(1);
|
||||
if (s.startsWith('0x') || s.startsWith('0X')) s = s.substring(2);
|
||||
if (s.length == 6) s = 'FF$s';
|
||||
final int? v = int.tryParse(s, radix: 16);
|
||||
return v ?? 0;
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
/// 模块契约:所有功能模块(时序图、架构图、后续电气 / IO / 拓扑 / PID 等)
|
||||
/// 都实现 [EdcModule],并在 `lib/modules/registry.dart` 的注册表中登记。
|
||||
///
|
||||
/// 设计目标:
|
||||
/// - **新增模块只改注册表**:应用外壳只依赖本契约,不出现具体模块的
|
||||
/// `if / switch`;新模块在独立目录实现后加入注册表即可出现首页卡片、
|
||||
/// 品牌菜单、窗口标题、文件打开 / 保存与工作区。
|
||||
/// - **模块自治**:模块拥有自己的文档读写、工作区 UI、工具栏、左右侧栏、
|
||||
/// 状态栏与快捷键;外壳只负责公共窗口框架、主题、文件对话框与侧栏停靠。
|
||||
/// - **共享内核**:主题、持久化、更新、授权、通用对话框仍由 `lib/` 公共层
|
||||
/// 提供;模块通过 [ModuleUiContext] 获取当前上下文。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
|
||||
/// 模块 UI 构建上下文:外壳传给模块的共享服务与布局信息。
|
||||
class ModuleUiContext {
|
||||
/// 构造上下文。
|
||||
const ModuleUiContext({
|
||||
required this.context,
|
||||
required this.controller,
|
||||
required this.tokens,
|
||||
required this.compact,
|
||||
required this.leftRail,
|
||||
required this.rightRail,
|
||||
required this.leftPanelWidth,
|
||||
required this.rightPanelWidth,
|
||||
required this.toolScale,
|
||||
required this.toolFont,
|
||||
required this.panelControls,
|
||||
});
|
||||
|
||||
/// Flutter 构建上下文。
|
||||
final BuildContext context;
|
||||
|
||||
/// 全局应用控制器(共享文档 / 撤销 / 状态)。
|
||||
final AppController controller;
|
||||
|
||||
/// 当前主题令牌。
|
||||
final Tokens tokens;
|
||||
|
||||
/// 是否为紧凑工具栏布局。
|
||||
final bool compact;
|
||||
|
||||
/// 左侧栏是否收起为贴边轨道。
|
||||
final bool leftRail;
|
||||
|
||||
/// 右侧栏是否收起为贴边轨道。
|
||||
final bool rightRail;
|
||||
|
||||
/// 左侧栏宽度。
|
||||
final double leftPanelWidth;
|
||||
|
||||
/// 右侧栏宽度。
|
||||
final double rightPanelWidth;
|
||||
|
||||
/// 工具栏缩放系数(触屏平台更紧凑)。
|
||||
final double toolScale;
|
||||
|
||||
/// 工具栏字号换算。
|
||||
final double Function(double base) toolFont;
|
||||
|
||||
/// 侧栏「钉住 / 收起」按钮(外壳维护)。
|
||||
final Widget Function(bool left) panelControls;
|
||||
}
|
||||
|
||||
/// 功能模块契约。
|
||||
///
|
||||
/// 模块 id 是稳定标识(保存到文档 / 最近列表 / 窗口标题),不要复用。
|
||||
abstract class EdcModule {
|
||||
/// 构造模块。
|
||||
const EdcModule();
|
||||
|
||||
// ===================== 元数据 =====================
|
||||
|
||||
/// 稳定 id(如 `sequence` / `architecture`)。
|
||||
String get id;
|
||||
|
||||
/// 模块全名(首页卡片、菜单、窗口标题)。
|
||||
String get name;
|
||||
|
||||
/// 模块短名(状态栏、紧凑菜单)。
|
||||
String get shortName;
|
||||
|
||||
/// 首页 / 菜单图标。
|
||||
IconData get icon;
|
||||
|
||||
/// 品牌色(ARGB)。
|
||||
int get accent;
|
||||
|
||||
/// 文档后缀(如 `.seq.json`)。
|
||||
String get suffix;
|
||||
|
||||
/// 是否已开放;false 时首页卡片灰显,不可进入。
|
||||
bool get available;
|
||||
|
||||
/// 新建文档默认文件名(含后缀)。
|
||||
String get defaultName;
|
||||
|
||||
/// 一句话简介(首页卡片)。
|
||||
String get blurb;
|
||||
|
||||
/// 进入模块时的状态栏提示。
|
||||
String get enterStatus => '$name设计';
|
||||
|
||||
// ===================== 文档生命周期 =====================
|
||||
|
||||
/// 在控制器上新建模块文档。
|
||||
void newDocument(AppController controller);
|
||||
|
||||
/// 从 JSON 文本加载模块文档;[path] 为源文件路径(Android 可为 null)。
|
||||
void loadDocument(AppController controller, String source, {String? path});
|
||||
|
||||
/// 把当前模块文档编码为 JSON 文本。
|
||||
String encodeDocument(AppController controller);
|
||||
|
||||
/// 当前文档名(用于保存默认文件名)。
|
||||
String documentName(AppController controller);
|
||||
|
||||
/// 当前文档路径(未保存时为 null)。
|
||||
String? filePath(AppController controller);
|
||||
|
||||
/// 是否有未保存修改。
|
||||
bool isDirty(AppController controller);
|
||||
|
||||
/// 保存到桌面路径(模块可写入自己的文档段 / .bak)。
|
||||
Future<void> saveTo(AppController controller, String path);
|
||||
|
||||
/// 外部通道保存成功后回写路径与干净状态(Android 公共目录)。
|
||||
Future<void> markSaved(AppController controller, String displayPath);
|
||||
|
||||
/// 当前视图是否只读(如时序图流程图视图)。
|
||||
bool isReadOnly(AppController controller) => false;
|
||||
|
||||
/// 模块级快捷键:与外壳公共快捷键合并,模块可覆盖同名组合。
|
||||
Map<ShortcutActivator, VoidCallback> buildShortcuts(ModuleUiContext ui) =>
|
||||
const <ShortcutActivator, VoidCallback>{};
|
||||
|
||||
// ===================== UI 扩展点 =====================
|
||||
|
||||
/// 工作区(画布)内容;外壳负责在外层叠加侧栏轨道 / 浮动面板。
|
||||
Widget buildWorkspace(ModuleUiContext ui);
|
||||
|
||||
/// 是否提供左侧栏(外壳据此显示停靠 / 轨道按钮)。
|
||||
bool get hasLeftPanel => true;
|
||||
|
||||
/// 是否提供右侧栏。
|
||||
bool get hasRightPanel => true;
|
||||
|
||||
/// 左侧栏内容;返回 null 表示该模块不需要左侧栏。
|
||||
Widget? buildLeftPanel(ModuleUiContext ui, {bool floating = false}) => null;
|
||||
|
||||
/// 右侧栏内容;返回 null 表示该模块不需要右侧栏。
|
||||
Widget? buildRightPanel(ModuleUiContext ui, {bool floating = false}) => null;
|
||||
|
||||
/// 底部状态栏内容。
|
||||
Widget buildStatusBar(ModuleUiContext ui);
|
||||
|
||||
/// 工具栏中段(模块专属工具:视图切换 / AI / 架构工具等)。
|
||||
List<Widget> buildToolbarCenter(ModuleUiContext ui, {required bool compact}) =>
|
||||
const <Widget>[];
|
||||
|
||||
/// 工具栏右侧的模块专属工具(导出菜单 / 缩放 / 适应视图 / 单位等)。
|
||||
List<Widget> buildToolbarRight(ModuleUiContext ui) => const <Widget>[];
|
||||
}
|
||||
|
||||
/// 未开放模块占位实现:目录与注册项先建好,后续实现时替换为真实模块。
|
||||
///
|
||||
/// 这样规划中的模块(电气 / IO / 拓扑 / PID)从第一天起就拥有独立路径与
|
||||
/// 稳定 id,首页和菜单由注册表自动生成;实现时只需补全文档与 UI 方法。
|
||||
class PlannedModule extends EdcModule {
|
||||
/// 构造占位模块。
|
||||
const PlannedModule({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.shortName,
|
||||
required this.icon,
|
||||
required this.accent,
|
||||
required this.suffix,
|
||||
required this.defaultName,
|
||||
required this.blurb,
|
||||
});
|
||||
|
||||
@override
|
||||
final String id;
|
||||
@override
|
||||
final String name;
|
||||
@override
|
||||
final String shortName;
|
||||
@override
|
||||
final IconData icon;
|
||||
@override
|
||||
final int accent;
|
||||
@override
|
||||
final String suffix;
|
||||
@override
|
||||
final String defaultName;
|
||||
@override
|
||||
final String blurb;
|
||||
|
||||
@override
|
||||
bool get available => false;
|
||||
|
||||
@override
|
||||
void newDocument(AppController controller) {}
|
||||
|
||||
@override
|
||||
void loadDocument(AppController controller, String source, {String? path}) {}
|
||||
|
||||
@override
|
||||
String encodeDocument(AppController controller) => '';
|
||||
|
||||
@override
|
||||
String documentName(AppController controller) => name;
|
||||
|
||||
@override
|
||||
String? filePath(AppController controller) => null;
|
||||
|
||||
@override
|
||||
bool isDirty(AppController controller) => false;
|
||||
|
||||
@override
|
||||
Future<void> saveTo(AppController controller, String path) async {}
|
||||
|
||||
@override
|
||||
Future<void> markSaved(AppController controller, String displayPath) async {}
|
||||
|
||||
@override
|
||||
Widget buildWorkspace(ModuleUiContext ui) => const SizedBox.shrink();
|
||||
|
||||
@override
|
||||
Widget buildStatusBar(ModuleUiContext ui) => const SizedBox.shrink();
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/// 设计模块注册表:模块元数据的唯一事实来源。
|
||||
///
|
||||
/// 首页「新建文档」网格、品牌菜单、窗口标题、文档后缀与导出能力
|
||||
/// 全部从这里读取;新增模块只需注册一条记录(未完成的模块
|
||||
/// [EdcModule.available] 为 false,界面统一灰显「未开放」)。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart' show IconData, Icons;
|
||||
|
||||
import '../model/models.dart' show AppMode;
|
||||
|
||||
/// 设计模块元数据。
|
||||
class EdcModule {
|
||||
/// 构造模块记录。
|
||||
const EdcModule({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.shortName,
|
||||
required this.icon,
|
||||
required this.accent,
|
||||
required this.suffix,
|
||||
required this.available,
|
||||
required this.defaultName,
|
||||
required this.blurb,
|
||||
});
|
||||
|
||||
/// 模块 id(稳定标识;文档 meta.docType 使用该值)。
|
||||
final String id;
|
||||
|
||||
/// 完整中文名(首页 / 标题)。
|
||||
final String name;
|
||||
|
||||
/// 短名(状态栏 / 菜单)。
|
||||
final String shortName;
|
||||
|
||||
/// 图标。
|
||||
final IconData icon;
|
||||
|
||||
/// 品牌色(ARGB)。
|
||||
final int accent;
|
||||
|
||||
/// 文档后缀(如 `.seq.json`)。
|
||||
final String suffix;
|
||||
|
||||
/// 是否已开放(false 时界面灰显「未开放」且不可进入)。
|
||||
final bool available;
|
||||
|
||||
/// 新建文档的默认文件名(不含后缀)。
|
||||
final String defaultName;
|
||||
|
||||
/// 一句话介绍(首页卡片)。
|
||||
final String blurb;
|
||||
}
|
||||
|
||||
/// 全部设计模块(顺序即首页与菜单的展示顺序:架构图在前,时序图第二)。
|
||||
const List<EdcModule> kModules = <EdcModule>[
|
||||
EdcModule(
|
||||
id: 'architecture',
|
||||
name: '架构图',
|
||||
shortName: '架构图',
|
||||
icon: Icons.account_tree_outlined,
|
||||
accent: 0xFF34D399,
|
||||
suffix: '.arch.json',
|
||||
available: true,
|
||||
defaultName: '未命名-架构图',
|
||||
blurb: '手绘识别 · 图形库',
|
||||
),
|
||||
EdcModule(
|
||||
id: 'sequence',
|
||||
name: '时序图',
|
||||
shortName: '时序图',
|
||||
icon: Icons.waterfall_chart,
|
||||
accent: 0xFF4CC9F0,
|
||||
suffix: '.seq.json',
|
||||
available: true,
|
||||
defaultName: '未命名-时序图',
|
||||
blurb: 'PLC 节拍 · 三视图',
|
||||
),
|
||||
EdcModule(
|
||||
id: 'elec',
|
||||
name: '电器原理图',
|
||||
shortName: '电气',
|
||||
icon: Icons.electric_bolt,
|
||||
accent: 0xFFFFB020,
|
||||
suffix: '.elec.json',
|
||||
available: false,
|
||||
defaultName: '未命名-电气原理图',
|
||||
blurb: '符号 · 连线 · 线号',
|
||||
),
|
||||
EdcModule(
|
||||
id: 'io',
|
||||
name: 'IO 表',
|
||||
shortName: 'IO表',
|
||||
icon: Icons.grid_on,
|
||||
accent: 0xFFA78BFA,
|
||||
suffix: '.io.json',
|
||||
available: false,
|
||||
defaultName: '未命名-IO表',
|
||||
blurb: '点位 · 符号 · 注释',
|
||||
),
|
||||
EdcModule(
|
||||
id: 'topo',
|
||||
name: '拓扑图',
|
||||
shortName: '拓扑',
|
||||
icon: Icons.hub_outlined,
|
||||
accent: 0xFFF472B6,
|
||||
suffix: '.topo.json',
|
||||
available: false,
|
||||
defaultName: '未命名-拓扑图',
|
||||
blurb: '网络设备 · 链路',
|
||||
),
|
||||
EdcModule(
|
||||
id: 'pid',
|
||||
name: 'PID 图',
|
||||
shortName: 'PID',
|
||||
icon: Icons.plumbing,
|
||||
accent: 0xFFFF8A5C,
|
||||
suffix: '.pid.json',
|
||||
available: false,
|
||||
defaultName: '未命名-PID图',
|
||||
blurb: '管道 · 仪表 · 回路',
|
||||
),
|
||||
];
|
||||
|
||||
/// 按 id 查找模块;找不到返回 null。
|
||||
EdcModule? moduleById(String id) {
|
||||
for (final EdcModule m in kModules) {
|
||||
if (m.id == id) return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// AppMode → 模块(home 或未映射值返回 null)。
|
||||
EdcModule? moduleOf(AppMode m) {
|
||||
switch (m) {
|
||||
case AppMode.sequence:
|
||||
return moduleById('sequence');
|
||||
case AppMode.architecture:
|
||||
return moduleById('architecture');
|
||||
case AppMode.home:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// AppMode → 窗口标题用模块名(首页用品牌名)。
|
||||
String appModeLabel(AppMode m) {
|
||||
final EdcModule? mod = moduleOf(m);
|
||||
return mod == null ? 'EDC易得' : 'EDC易得 · ${mod.name}设计';
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/// PID 图模块(规划中)。
|
||||
///
|
||||
/// 当前仅注册元数据与占位实现;实现时在 `lib/modules/pid/` 下补齐文档模型
|
||||
/// 与 UI,并在本类中替换 `PlannedModule` 为真实 [EdcModule] 实现即可。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
|
||||
/// PID 图模块单例(未开放)。
|
||||
const PidModule pidModule = PidModule();
|
||||
|
||||
/// PID 图模块。
|
||||
class PidModule extends PlannedModule {
|
||||
/// 构造模块。
|
||||
const PidModule()
|
||||
: super(
|
||||
id: 'pid',
|
||||
name: 'PID 图',
|
||||
shortName: 'PID',
|
||||
icon: Icons.plumbing,
|
||||
accent: 0xFFFF8A5C,
|
||||
suffix: '.pid.json',
|
||||
defaultName: '未命名-PID图',
|
||||
blurb: '管道 · 仪表 · 回路',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/// 模块注册表:**唯一**需要修改的模块清单文件。
|
||||
///
|
||||
/// 新增模块步骤:
|
||||
/// 1. 在 `lib/modules/<id>/` 下实现 `EdcModule`(或先用 `PlannedModule` 占位);
|
||||
/// 2. 在本文件顶部 import 模块单例;
|
||||
/// 3. 加入下方 [kModules] 列表。
|
||||
///
|
||||
/// 首页卡片、品牌菜单、窗口标题、文档打开 / 保存后缀、最近列表与工作区
|
||||
/// 都会自动跟随注册表,不需要修改 `AppShell` / `HomeView`。
|
||||
///
|
||||
/// 发布级注册:`assets/modules/registry.json`(构建时复制到发布包 `modules/`)
|
||||
/// 可覆盖模块顺序 / 显示名 / 颜色 / 启用状态;应用启动时优先读取发布清单,
|
||||
/// 失败回退本文件。Flutter AOT 不能动态加载新的 Dart UI 代码,新增实现仍需
|
||||
/// 重新构建;清单只负责发布装配与可见结构。
|
||||
library;
|
||||
|
||||
import 'dart:io' show File, Platform;
|
||||
|
||||
import 'package:flutter/services.dart' show rootBundle;
|
||||
|
||||
import 'package:sequence_diagram/modules/architecture/architecture_module.dart';
|
||||
import 'package:sequence_diagram/modules/elec/elec_module.dart';
|
||||
import 'package:sequence_diagram/modules/io/io_module.dart';
|
||||
import 'package:sequence_diagram/modules/manifest.dart';
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
import 'package:sequence_diagram/modules/pid/pid_module.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/sequence_module.dart';
|
||||
import 'package:sequence_diagram/modules/topo/topo_module.dart';
|
||||
|
||||
export 'package:sequence_diagram/modules/module.dart';
|
||||
|
||||
/// 编译进应用的模块(顺序 = 默认首页 / 菜单展示顺序)。
|
||||
///
|
||||
/// 发布包可通过 `modules/registry.json` 覆盖顺序 / 显示名 / 启用状态;
|
||||
/// 未在清单中出现的编译期模块会被隐藏。
|
||||
const List<EdcModule> kCompiledModules = <EdcModule>[
|
||||
architectureModule,
|
||||
sequenceModule,
|
||||
elecModule,
|
||||
ioModule,
|
||||
topoModule,
|
||||
pidModule,
|
||||
];
|
||||
|
||||
List<EdcModule> _modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||||
String _moduleRegistrySource = 'compiled';
|
||||
|
||||
/// 当前生效的模块列表(发布清单已合并)。
|
||||
List<EdcModule> get kModules => _modules;
|
||||
|
||||
/// 当前模块清单来源(排查发布包问题用)。
|
||||
String get moduleRegistrySource => _moduleRegistrySource;
|
||||
|
||||
/// 初始化发布级模块清单。
|
||||
///
|
||||
/// 桌面优先读取 exe 同级 `modules/registry.json`;安卓 / 开发环境回退到
|
||||
/// `assets/modules/registry.json`;失败时回退 [kCompiledModules]。
|
||||
/// 必须在 `runApp` 前调用;运行中修改清单需要重启应用。
|
||||
Future<void> initModuleRegistry({
|
||||
String? manifestText,
|
||||
String? manifestPath,
|
||||
}) async {
|
||||
String? text = manifestText;
|
||||
String source = manifestText != null ? 'override' : '';
|
||||
if (text == null && manifestPath != null) {
|
||||
try {
|
||||
final File f = File(manifestPath);
|
||||
if (await f.exists()) {
|
||||
text = await f.readAsString();
|
||||
source = manifestPath;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
if (text == null &&
|
||||
(Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
|
||||
try {
|
||||
final String exeDir = File(Platform.resolvedExecutable).parent.path;
|
||||
final File external = File(
|
||||
'$exeDir${Platform.pathSeparator}modules${Platform.pathSeparator}registry.json',
|
||||
);
|
||||
if (await external.exists()) {
|
||||
text = await external.readAsString();
|
||||
source = external.path;
|
||||
}
|
||||
} catch (_) {}
|
||||
}
|
||||
if (text == null) {
|
||||
try {
|
||||
text = await rootBundle.loadString('assets/modules/registry.json');
|
||||
source = 'assets/modules/registry.json';
|
||||
} catch (_) {}
|
||||
}
|
||||
if (text == null) {
|
||||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||||
_moduleRegistrySource = 'compiled';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final ModuleManifest manifest = ModuleManifest.parse(text);
|
||||
final List<EdcModule> resolved =
|
||||
resolveModulesFromManifest(manifest, kCompiledModules);
|
||||
if (resolved.isEmpty) {
|
||||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||||
_moduleRegistrySource = 'compiled (empty manifest)';
|
||||
} else {
|
||||
_modules = List<EdcModule>.unmodifiable(resolved);
|
||||
_moduleRegistrySource = source;
|
||||
}
|
||||
} catch (_) {
|
||||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||||
_moduleRegistrySource = 'compiled (invalid manifest)';
|
||||
}
|
||||
}
|
||||
|
||||
/// 恢复编译期注册表(测试 / 重置用)。
|
||||
void resetModuleRegistry() {
|
||||
_modules = List<EdcModule>.unmodifiable(kCompiledModules);
|
||||
_moduleRegistrySource = 'compiled';
|
||||
}
|
||||
|
||||
/// 按 id 查找模块;id 为 null / 未注册时返回 null(首页)。
|
||||
EdcModule? moduleById(String? id) {
|
||||
if (id == null || id.isEmpty) return null;
|
||||
for (final EdcModule m in kModules) {
|
||||
if (m.id == id) return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// 已开放模块(首页可进入)。
|
||||
Iterable<EdcModule> get availableModules =>
|
||||
kModules.where((EdcModule m) => m.available);
|
||||
|
||||
/// 品牌名(首页 / 窗口标题)。
|
||||
const String kBrandName = 'PDS流程设计套件';
|
||||
|
||||
/// 窗口标题:首页显示品牌,模块显示「品牌 · 模块设计」。
|
||||
String moduleTitle(String? moduleId) {
|
||||
final EdcModule? m = moduleById(moduleId);
|
||||
return m == null ? kBrandName : '$kBrandName · ${m.name}设计';
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import '../model/models.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// AI 请求参数。
|
||||
class AiSettings {
|
||||
@@ -53,9 +53,13 @@ class AiModelOption {
|
||||
}
|
||||
|
||||
/// 预设模型列表:Flash(快速)与 Pro(深度推理)。
|
||||
///
|
||||
/// 模型 id 必须与 DeepSeek 当前 API 保持一致(`deepseek-flash` /
|
||||
/// `deepseek-v4-pro`);旧 id(`deepseek-chat` / `deepseek-reasoner`)
|
||||
/// 已下线,继续使用会直接返回 400 Model Not Exist。
|
||||
const List<AiModelOption> kAiModels = <AiModelOption>[
|
||||
AiModelOption('deepseek-chat', 'Flash · 快速'),
|
||||
AiModelOption('deepseek-reasoner', 'Pro · 深度推理'),
|
||||
AiModelOption('deepseek-flash', 'Flash · 快速'),
|
||||
AiModelOption('deepseek-v4-pro', 'Pro · 深度推理'),
|
||||
];
|
||||
|
||||
/// AI 调用异常(携带可读信息,便于界面直接展示)。
|
||||
@@ -130,9 +134,9 @@ class AiClient {
|
||||
static const String _systemPrompt = '''
|
||||
你是工业节拍 / 相位角设计助手。请把用户的自然语言描述转换成严格的 JSON,且**只能输出 JSON**,不要输出解释、注释或 Markdown 代码块。
|
||||
|
||||
JSON 结构(协议 seqdiagram/1.2):
|
||||
JSON 结构(协议 edc/1.3):
|
||||
{
|
||||
"schema": "seqdiagram/1.2",
|
||||
"schema": "edc/1.3",
|
||||
"project": {
|
||||
"name": "项目名称",
|
||||
"units": { "timeUnit": "s", "phaseUnit": "deg", "precision": -1, "snapAngle": 1, "snapTime": 0.1, "cycleInputPolicy": "keepAngle" },
|
||||
@@ -162,6 +166,8 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
6. 相位分区 phaseZones 用于标注工艺阶段,可重叠,允许结束角 > 360°。
|
||||
7. 动作命名简洁(不超过 8 个汉字);不要编造不存在的工位,stationId 必须引用 stations 中已有的 id。
|
||||
8. 只输出 JSON 本体,且必须是单个可直接 JSON 解析的对象。
|
||||
9. 只需要输出时序图数据(name / units / cycle / stations / actions / viewState / phaseZones),
|
||||
不需要也没有 `arch`、`keepEmptyLanes`、`laneSlots` 等字段;修改模式由程序负责保留原有架构图数据。
|
||||
''';
|
||||
|
||||
/// 根据自然语言 [prompt] 生成或修改项目(流式、可取消、带自动纠错)。
|
||||
@@ -189,7 +195,9 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
throw AiException('请输入自然语言描述');
|
||||
}
|
||||
|
||||
final String baseJson = base == null ? '' : jsonEncode(base.toJson());
|
||||
// 修改模式只发送时序部分:架构图 / 画布设置(arch、泳道、自动保存)
|
||||
// 体积大且与本次修改无关,不回传给模型,也能避免模型丢掉原有架构图。
|
||||
final String baseJson = base == null ? '' : jsonEncode(base.toJson(includeArch: false));
|
||||
final String firstUser = base == null
|
||||
? prompt.trim()
|
||||
: '现有工程 JSON:\n$baseJson\n\n'
|
||||
@@ -232,7 +240,20 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
if (fixed.actions.isEmpty) {
|
||||
throw const FormatException('没有任何动作');
|
||||
}
|
||||
return AiResult(fixed, warnings);
|
||||
// 修改模式:只采纳 AI 返回的时序内容,架构图 / 画布设置 / 泳道设置
|
||||
// 一律沿用原工程,避免一次 AI 修改把架构图或用户视图状态清空。
|
||||
final Project result = base == null
|
||||
? fixed
|
||||
: base.copyWith(
|
||||
name: fixed.name,
|
||||
schema: fixed.schema,
|
||||
cycle: fixed.cycle,
|
||||
stations: fixed.stations,
|
||||
actions: fixed.actions,
|
||||
units: fixed.units,
|
||||
phaseZones: fixed.phaseZones,
|
||||
);
|
||||
return AiResult(result, warnings);
|
||||
} on AiException {
|
||||
rethrow; // 网络 / 鉴权 / 超时 / 取消等错误不重试
|
||||
} on FormatException catch (e) {
|
||||
@@ -270,14 +291,16 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
'messages': messages,
|
||||
'stream': true,
|
||||
'temperature': 0.2,
|
||||
'max_tokens': 131072,
|
||||
'response_format': <String, String>{'type': 'json_object'},
|
||||
// 兼容支持推理强度的接口;不支持时会被忽略。
|
||||
// 当前 DeepSeek 模型默认开启思考,这里显式开启并按 UI 选择传推理强度。
|
||||
'thinking': <String, String>{'type': 'enabled'},
|
||||
'reasoning_effort': settings.effort,
|
||||
}));
|
||||
final HttpClientResponse res = await req.close();
|
||||
if (res.statusCode != 200) {
|
||||
final String text = await res.transform(utf8.decoder).join();
|
||||
throw AiException('接口返回 ${res.statusCode}:${_brief(text)}');
|
||||
throw AiException(_apiError(res.statusCode, text));
|
||||
}
|
||||
final StringBuffer content = StringBuffer();
|
||||
final StringBuffer reasoning = StringBuffer();
|
||||
@@ -332,10 +355,21 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
}
|
||||
}
|
||||
|
||||
/// 结果清洗:修正非法时长与越界角度、剔除指向不存在动作的依赖、归一化层号。
|
||||
/// 结果清洗:补齐工位、修正非法时长与越界角度、剔除指向不存在动作的
|
||||
/// 依赖、归一化层号。
|
||||
///
|
||||
/// 返回修正后的项目与人类可读的修正说明(供状态栏提示)。
|
||||
static (Project, List<String>) _sanitize(Project p) {
|
||||
// 工位是动作的归属单元:模型偶发漏写 stations 或编造 stationId 时,
|
||||
// 直接引用会让条形视图整组动作消失,这里兜底并提示。
|
||||
final List<Station> stations = p.stations.isEmpty
|
||||
? const <Station>[
|
||||
Station(id: 'ST1', name: '工位1', order: 0, color: 0xFF4CC9F0),
|
||||
]
|
||||
: p.stations;
|
||||
final Set<String> stationIds = <String>{for (final Station s in stations) s.id};
|
||||
final String fallbackStation = stations.first.id;
|
||||
int fixedStation = 0;
|
||||
final Set<String> ids = <String>{for (final Action a in p.actions) a.id};
|
||||
int fixedDur = 0;
|
||||
int droppedDeps = 0;
|
||||
@@ -353,6 +387,11 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
dur = 720;
|
||||
fixedDur++;
|
||||
}
|
||||
String stationId = a.stationId;
|
||||
if (!stationIds.contains(stationId)) {
|
||||
stationId = fallbackStation;
|
||||
fixedStation++;
|
||||
}
|
||||
final List<Dependency> deps = <Dependency>[];
|
||||
for (final Dependency d in a.deps) {
|
||||
if (d.fromId == a.id || !ids.contains(d.fromId) || !ids.contains(d.toId)) {
|
||||
@@ -361,7 +400,12 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
}
|
||||
deps.add(d);
|
||||
}
|
||||
actions.add(a.copyWith(startAngle: start, durationAngle: dur, deps: deps));
|
||||
actions.add(a.copyWith(
|
||||
stationId: stationId,
|
||||
startAngle: start,
|
||||
durationAngle: dur,
|
||||
deps: deps,
|
||||
));
|
||||
}
|
||||
// 层号归一化为连续的 0..N-1(保持相对顺序),避免稀疏层号造成空白轨道。
|
||||
final List<int> layers = <int>{for (final Action a in actions) a.layer}.toList()..sort();
|
||||
@@ -373,8 +417,36 @@ JSON 结构(协议 seqdiagram/1.2):
|
||||
];
|
||||
final List<String> warnings = <String>[];
|
||||
if (fixedDur > 0) warnings.add('修正 $fixedDur 处非法时长');
|
||||
if (fixedStation > 0) warnings.add('修正 $fixedStation 处无效工位');
|
||||
if (droppedDeps > 0) warnings.add('剔除 $droppedDeps 条无效依赖');
|
||||
return (p.copyWith(actions: normalized), warnings);
|
||||
return (p.copyWith(stations: stations, actions: normalized), warnings);
|
||||
}
|
||||
|
||||
/// 把非 200 响应转换为可读错误:优先取 DeepSeek 的 `error.message`,
|
||||
/// 并对常见状态码给出排查提示(模型下线 / Key 无效 / 余额不足)。
|
||||
static String _apiError(int code, String raw) {
|
||||
String detail = _brief(raw);
|
||||
try {
|
||||
final Object? j = jsonDecode(raw);
|
||||
if (j is Map<String, dynamic>) {
|
||||
final Object? err = j['error'];
|
||||
if (err is Map<String, dynamic> && err['message'] is String) {
|
||||
detail = _brief(err['message'] as String);
|
||||
} else if (j['message'] is String) {
|
||||
detail = _brief(j['message'] as String);
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
switch (code) {
|
||||
case 401:
|
||||
return 'API Key 无效或已过期(401):$detail';
|
||||
case 402:
|
||||
return 'DeepSeek 账户余额不足(402):$detail';
|
||||
case 429:
|
||||
return '请求过于频繁(429):$detail';
|
||||
default:
|
||||
return '接口返回 $code:$detail';
|
||||
}
|
||||
}
|
||||
|
||||
/// 从模型输出中剥离 Markdown 代码围栏并截取首个 JSON 对象。
|
||||
@@ -5,7 +5,7 @@
|
||||
/// - 几何完全复用 [FlowLayout](与屏幕画布、SVG 导出同一套坐标与走线),
|
||||
/// 保证三种载体(画布 / drawio / SVG)内容一致;
|
||||
/// - 输出标准 `<mxfile>` 文档:节点保留动作颜色与「时长 · 工位」语义,
|
||||
/// 连线保留 FS / SS 类型与偏移角标签,泳道为背景带、相位为竖排文字带,
|
||||
/// 连线保留 FS / SS 类型与偏移时间标签,泳道为背景带、相位为竖排文字带,
|
||||
/// 导入 draw.io 后可直接继续排布与编辑。
|
||||
///
|
||||
/// 输出约定:
|
||||
@@ -16,9 +16,10 @@ library;
|
||||
|
||||
import 'dart:ui';
|
||||
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
/// drawio 文档写入器。
|
||||
@@ -163,7 +164,7 @@ class DrawioWriter {
|
||||
|
||||
/// 写入依赖连线:以 source / target 引用节点,drawio 自动正交布线并可再编辑。
|
||||
///
|
||||
/// 样式与画布一致:FS 绿实线、SS 琥珀虚线(标签标注偏移角)、关键路径加粗。
|
||||
/// 样式与画布一致:FS 绿实线、SS 琥珀虚线(标签标注偏移时间)、关键路径加粗。
|
||||
void _edges(FlowLayout layout) {
|
||||
int i = 0;
|
||||
for (final FlowEdge e in layout.edges) {
|
||||
@@ -174,7 +175,9 @@ class DrawioWriter {
|
||||
final String label = switch (e.type) {
|
||||
null => '',
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
|
||||
DepType.ss => e.offset == 0
|
||||
? 'SS'
|
||||
: 'SS+${deg2msStr(e.offset, project.units, project.cycle.durationMs, dec: 2)}',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
@@ -12,38 +12,14 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/export/export_geometry.dart';
|
||||
|
||||
/// 导出画布尺寸(固定,逻辑单位)。
|
||||
const Size kExportSize = Size(1920, 1080);
|
||||
|
||||
/// 导出渲染像素比:按 2 倍像素渲染(3840×2160),保证高分辨率屏幕下清晰锐利。
|
||||
const double kExportPixelRatio = 2.0;
|
||||
|
||||
/// 内容区(标题下方、图例上方)。
|
||||
const Rect kExportContentArea = Rect.fromLTRB(48, 128, 1872, 1016);
|
||||
|
||||
/// 导出适配结果:内容变换 `scale` + `translate(tx, ty)`。
|
||||
class ExportFit {
|
||||
/// 构造适配结果。
|
||||
const ExportFit(this.scale, this.tx, this.ty);
|
||||
|
||||
/// 缩放系数。
|
||||
final double scale;
|
||||
/// 水平平移。
|
||||
final double tx;
|
||||
/// 垂直平移。
|
||||
final double ty;
|
||||
|
||||
/// SVG transform 属性值。
|
||||
String get svgTransform =>
|
||||
'translate(${tx.toStringAsFixed(1)} ${ty.toStringAsFixed(1)}) scale(${scale.toStringAsFixed(4)})';
|
||||
}
|
||||
export 'package:sequence_diagram/export/export_geometry.dart' show ExportFit, kExportContentArea, kExportPixelRatio, kExportSize, exportTokens;
|
||||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/render/bar_painter.dart';
|
||||
|
||||
/// 计算内容在 [area] 内的适配变换。
|
||||
///
|
||||
@@ -94,51 +70,3 @@ String exportSubtitle(ViewMode mode) => switch (mode) {
|
||||
String exportLegend(Project project) =>
|
||||
'时序图设计 · ${project.name} · 循环 ${tfmt(project.cycle.durationMs, project.units)} = 360°';
|
||||
|
||||
/// 导出专用令牌:始终使用浅色、**纯白背景**(印刷 / 工艺卡导向),
|
||||
/// 文字、语义色与屏幕浅色主题保持一致。
|
||||
///
|
||||
/// 无论当前屏幕主题是深是浅,导出的 PNG / SVG 背景都是纯白、文字深色,
|
||||
/// 避免「导出背景不是纯白」的问题。
|
||||
Tokens exportTokens(Tokens base) {
|
||||
return Tokens(
|
||||
brightness: Brightness.light,
|
||||
bg: Colors.white,
|
||||
canvas1: Colors.white,
|
||||
canvas2: Colors.white,
|
||||
chrome: base.chrome,
|
||||
panel: Colors.white,
|
||||
panel2: Colors.white,
|
||||
dialog: Colors.white,
|
||||
line: base.line,
|
||||
line2: base.line2,
|
||||
text: base.text,
|
||||
text2: base.text2,
|
||||
sub: base.sub,
|
||||
dim: base.dim,
|
||||
accent: base.accent,
|
||||
accent2: base.accent2,
|
||||
ok: base.ok,
|
||||
warn: base.warn,
|
||||
danger: base.danger,
|
||||
fs: base.fs,
|
||||
ss: base.ss,
|
||||
crit: base.crit,
|
||||
chip: Colors.white,
|
||||
dial: Colors.white,
|
||||
arcText: base.arcText,
|
||||
onAccent: base.onAccent,
|
||||
ringA: base.ringA,
|
||||
ringB: base.ringB,
|
||||
ringEdge: base.ringEdge,
|
||||
ringLabel: base.ringLabel,
|
||||
info: Colors.white,
|
||||
track: base.track,
|
||||
sel: base.sel,
|
||||
grid: base.grid,
|
||||
shadow: base.shadow,
|
||||
shadowOp: 0.10,
|
||||
selOutline: base.selOutline,
|
||||
overlay: base.overlay,
|
||||
tailOp: base.tailOp,
|
||||
);
|
||||
}
|
||||
@@ -11,11 +11,11 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../model/models.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../render/circular_painter.dart';
|
||||
import '../render/flow_painter.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/render/bar_painter.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/render/circular_painter.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/render/flow_painter.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
/// 渲染导出 PNG 并返回字节。
|
||||
@@ -20,11 +20,11 @@ library;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'export_fit.dart';
|
||||
|
||||
/// SVG 文档写入器。
|
||||
@@ -164,7 +164,7 @@ class SvgWriter {
|
||||
}
|
||||
_b.write('</g>');
|
||||
|
||||
// 依赖分组:正交折线;FS 为实线,SS 为虚线并带偏移角语义。
|
||||
// 依赖分组:正交折线;FS 为实线,SS 为虚线并带偏移时间语义。
|
||||
if (project.viewState.showDeps) {
|
||||
_b.write('<g id="dependencies">');
|
||||
final Map<String, int> index = <String, int>{};
|
||||
@@ -339,7 +339,9 @@ class SvgWriter {
|
||||
if (e.type != null) {
|
||||
final String text = switch (e.type!) {
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
|
||||
DepType.ss => e.offset == 0
|
||||
? 'SS'
|
||||
: 'SS+${deg2msStr(e.offset, project.units, project.cycle.durationMs, dec: 2)}',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
@@ -0,0 +1,565 @@
|
||||
/// 依赖连线的共享走线计算。
|
||||
///
|
||||
/// 条形视图 / 圆周视图的**画布绘制、标签放置与命中测试**(点选连线、
|
||||
/// 沿法线拖拽调整走线)都使用这里的同一份几何,避免绘制与命中不一致:
|
||||
/// - 自动错开:同一走线分组内的多条依赖依次错开,先解决“完全重叠”;
|
||||
/// - 手动偏移:[Dependency.routeOffset] 叠加在自动错开之上(拖拽连线的结果)。
|
||||
library;
|
||||
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'layout.dart';
|
||||
|
||||
// ===================== 通用工具 =====================
|
||||
|
||||
/// 点 [p] 到线段 [a]–[b] 的最短距离。
|
||||
double distanceToSegment(Offset p, Offset a, Offset b) {
|
||||
final Offset ab = b - a;
|
||||
final double len2 = ab.dx * ab.dx + ab.dy * ab.dy;
|
||||
if (len2 <= 0) return (p - a).distance;
|
||||
final double t = (((p - a).dx * ab.dx + (p - a).dy * ab.dy) / len2).clamp(0.0, 1.0);
|
||||
return (p - (a + ab * t)).distance;
|
||||
}
|
||||
|
||||
/// 点 [p] 到折线 [pts] 的最短距离。
|
||||
double distanceToPolyline(List<Offset> pts, Offset p) {
|
||||
double best = double.infinity;
|
||||
for (int i = 0; i + 1 < pts.length; i++) {
|
||||
final double d = distanceToSegment(p, pts[i], pts[i + 1]);
|
||||
if (d < best) best = d;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// 点 [p] 到路径 [path] 的近似最短距离(按弧长采样,步长 [step])。
|
||||
double distanceToPath(Path path, Offset p, {double step = 4}) {
|
||||
double best = double.infinity;
|
||||
for (final PathMetric m in path.computeMetrics()) {
|
||||
for (double d = 0; d < m.length; d += step) {
|
||||
final Tangent? t = m.getTangentForOffset(d);
|
||||
if (t == null) continue;
|
||||
final double dist = (t.position - p).distance;
|
||||
if (dist < best) best = dist;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// 第 [k] 档自动错开量(px):0、−6、+6、−12、+12 …
|
||||
///
|
||||
/// 同一走线分组内第二条起依次错开,避免多条依赖完全重叠。
|
||||
double staggerOffset(int k) {
|
||||
if (k <= 0) return 0;
|
||||
return (k.isOdd ? -1 : 1) * ((k + 1) ~/ 2) * 6.0;
|
||||
}
|
||||
|
||||
/// 拖拽调整走线时的移动轴(走线的“法线”方向)。
|
||||
///
|
||||
/// - [vertical]:上下拖动——平移水平走线段(条形 / 流程图的常见形态);
|
||||
/// - [horizontal]:左右拖动——平移纵向走线走廊(跨行绕行走廊 / 同层绕行)。
|
||||
enum RouteAxis { vertical, horizontal }
|
||||
|
||||
/// 拖拽走线时可用的最大手动偏移(px,双向)。
|
||||
const double kMaxRouteOffset = 200;
|
||||
|
||||
// ===================== 条形视图 =====================
|
||||
|
||||
/// 条形视图的一条依赖走线。
|
||||
class BarDepRoute {
|
||||
/// 构造。
|
||||
BarDepRoute(this.dep, this.points, this.arrowTip, this.arrowDir, this.chipCenter, this.axis,
|
||||
{this.chipRun = double.infinity,
|
||||
this.chipRunMargin = 0,
|
||||
this.chipAltAnchor = Offset.zero,
|
||||
this.junctionOnly = false});
|
||||
|
||||
/// 对应依赖。
|
||||
final Dependency dep;
|
||||
/// 折线顶点(含起点与箭头端点)。
|
||||
final List<Offset> points;
|
||||
/// 箭头端点。
|
||||
final Offset arrowTip;
|
||||
/// 箭头方向(分量式)。
|
||||
final Offset arrowDir;
|
||||
/// 标签中心(默认位置,避让前)。
|
||||
final Offset chipCenter;
|
||||
/// 拖拽方向:vertical = 上下拖动平移横线;horizontal = 左右拖动平移纵向走廊。
|
||||
final RouteAxis axis;
|
||||
|
||||
/// 标签挂钩的水平行程长度(跑长时用于判断是否需要把标签移到箭头外侧)。
|
||||
///
|
||||
/// 默认 [double.infinity] 表示不做外移判断(跨行走廊等)。
|
||||
final double chipRun;
|
||||
|
||||
/// 外移判断余量:行程 `< 标签宽 + 余量` 时把标签移到 [chipAltAnchor]。
|
||||
final double chipRunMargin;
|
||||
|
||||
/// 外移时标签的锚点(绘制端会再加半个标签宽)。
|
||||
final Offset chipAltAnchor;
|
||||
|
||||
/// 动作紧贴时只显示连接点标签,隐藏连线与箭头(由绘制层处理)。
|
||||
final bool junctionOnly;
|
||||
|
||||
/// 依赖键 `from->to`。
|
||||
String get key => '${dep.fromId}->${dep.toId}';
|
||||
}
|
||||
|
||||
/// 条形依赖在动作条一端的锚点。
|
||||
///
|
||||
/// [point] 为线条端点(目标端为箭头尖端);[dir] 为箭头进入方向(源端为
|
||||
/// 离开方向);[corner] 表示端点已退到条块的上/下角;[vSide] 为角点所在
|
||||
/// 一侧(-1 上、+1 下)。
|
||||
class _BarEnd {
|
||||
const _BarEnd(this.point, this.dir, this.corner, this.vSide);
|
||||
|
||||
final Offset point;
|
||||
final Offset dir;
|
||||
final bool corner;
|
||||
final int vSide;
|
||||
}
|
||||
|
||||
/// 判断端点前的水平通道是否被其它动作条遮挡(宽 8px,条高中间 ±3px)。
|
||||
///
|
||||
/// 遮挡时把端点退到端部的上/下角,保证线条从角上引出而不是贴着邻条走。
|
||||
bool _barEndBlocked(double edge, double outward, double centerY, Iterable<Rect> obstacles) {
|
||||
const double clearance = 9;
|
||||
final Rect probe = Rect.fromLTRB(
|
||||
math.min(edge, edge + outward * clearance),
|
||||
centerY - 3,
|
||||
math.max(edge, edge + outward * clearance),
|
||||
centerY + 3,
|
||||
);
|
||||
for (final Rect r in obstacles) {
|
||||
if (r.overlaps(probe)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// 源端锚点:默认取条块左/右端点中心;端部有遮挡时取朝向目标一侧的上下角。
|
||||
_BarEnd _startEnd(Rect bar, int side, int cornerSide, Iterable<Rect> obstacles,
|
||||
{bool forceCorner = false}) {
|
||||
final double edge = side > 0 ? bar.right : bar.left;
|
||||
final double outward = side > 0 ? 1 : -1;
|
||||
final double cy = bar.center.dy;
|
||||
if (!forceCorner && !_barEndBlocked(edge, outward, cy, obstacles)) {
|
||||
return _BarEnd(Offset(edge + outward * 2, cy), Offset(outward, 0), false, 0);
|
||||
}
|
||||
final int vs = cornerSide == 0 ? 1 : cornerSide;
|
||||
final double y = vs > 0 ? bar.bottom - 2 : bar.top + 2;
|
||||
return _BarEnd(Offset(edge + outward * 1.5, y), Offset(0, vs.toDouble()), true, vs);
|
||||
}
|
||||
|
||||
/// 目标端锚点:默认取条块左/右端点中心(箭头停在端点外 2px);端部有遮挡
|
||||
/// 时取朝向源条一侧的上下角,箭头从角外垂直指向条块。
|
||||
_BarEnd _targetEnd(Rect bar, int side, int cornerSide, Iterable<Rect> obstacles,
|
||||
{bool forceCorner = false}) {
|
||||
final double edge = side > 0 ? bar.right : bar.left;
|
||||
final double outward = side > 0 ? 1 : -1;
|
||||
final double cy = bar.center.dy;
|
||||
if (!forceCorner && !_barEndBlocked(edge, outward, cy, obstacles)) {
|
||||
return _BarEnd(Offset(edge + outward * 2, cy), Offset(-outward, 0), false, 0);
|
||||
}
|
||||
final int vs = cornerSide == 0 ? 1 : cornerSide;
|
||||
final double y = vs > 0 ? bar.bottom + 2 : bar.top - 2;
|
||||
return _BarEnd(
|
||||
Offset(edge + outward * 1.5, y), Offset(0, -vs.toDouble()), true, vs);
|
||||
}
|
||||
|
||||
/// 计算条形视图的全部依赖走线(含自动错开与手动偏移)。
|
||||
///
|
||||
/// 端点规则(FS / SS / FF / SF 均按语义取条块前端或后端):
|
||||
/// 1. 默认从条块的左/右端点中心引出;FS/FF 从后端(右端)出发,
|
||||
/// SS/SF 从前端(左端)出发;目标端按 FS/SS 取前端、FF/SF 取后端;
|
||||
/// 2. 当端点临近被其它动作条遮挡(或同泳道走线会穿过条块)时,退到该端部
|
||||
/// 的上/下角引出,再从角外绕行。
|
||||
///
|
||||
/// 走线分三种情形:同泳道(水平线或上下绕行)、相邻泳道(Z 形)、跨多行
|
||||
/// (外侧纵向走廊);同组自动错开 + [Dependency.routeOffset] 手动偏移。
|
||||
List<BarDepRoute> buildBarDepRoutes(Project project, BarLayout layout) {
|
||||
final Map<String, Rect> rectById = <String, Rect>{
|
||||
for (final Action a in project.actions) a.id: layout.rectFor(a),
|
||||
};
|
||||
final Map<String, int> laneIndex = <String, int>{
|
||||
for (final Action a in project.actions) a.id: layout.laneIndexOf(a.layer),
|
||||
};
|
||||
final Map<String, int> seen = <String, int>{};
|
||||
final List<BarDepRoute> out = <BarDepRoute>[];
|
||||
for (final Action to in layout.ordered) {
|
||||
for (final Dependency d in to.deps) {
|
||||
final Action? from = project.actionById(d.fromId);
|
||||
if (from == null) continue;
|
||||
final Rect? ra = rectById[from.id];
|
||||
final Rect? rb = rectById[to.id];
|
||||
if (ra == null || rb == null) continue;
|
||||
// 端点遮挡检查要包含“对方条块”:动作前后贴紧时,源端被目标条块
|
||||
// 挡住、目标端被源条块挡住,此时应退到上下角并从条块外侧绕行。
|
||||
final List<Rect> obstaclesForStart = <Rect>[
|
||||
for (final MapEntry<String, Rect> e in rectById.entries)
|
||||
if (e.key != from.id) e.value,
|
||||
];
|
||||
final List<Rect> obstaclesForEnd = <Rect>[
|
||||
for (final MapEntry<String, Rect> e in rectById.entries)
|
||||
if (e.key != to.id) e.value,
|
||||
];
|
||||
final int ia = laneIndex[from.id] ?? 0;
|
||||
final int ib = laneIndex[to.id] ?? 0;
|
||||
const double barHalf = BarLayout.barH / 2;
|
||||
final double sy = ra.center.dy;
|
||||
final double ty = rb.center.dy;
|
||||
final int dirY = ty > sy ? 1 : (ty < sy ? -1 : 0);
|
||||
final bool sameRow = dirY == 0;
|
||||
final bool adjacentLane = (ib - ia).abs() <= 1;
|
||||
// 端点语义:FS/FF 从后端出发,SS/SF 从前端出发;目标端 FS/SS 为前端,
|
||||
// FF/SF 为后端。
|
||||
final int fromSide =
|
||||
(d.type == DepType.fs || d.type == DepType.ff) ? 1 : -1;
|
||||
final int toSide =
|
||||
(d.type == DepType.fs || d.type == DepType.ss) ? -1 : 1;
|
||||
final String groupKey =
|
||||
sameRow ? 'S$ia' : (adjacentLane ? 'A$ia→$ib' : 'M$ia→$ib');
|
||||
final int k = seen.putIfAbsent(groupKey, () => 0);
|
||||
seen[groupKey] = k + 1;
|
||||
final double stagger = staggerOffset(k);
|
||||
// 同泳道无上下方向时,按走线偏移/错开量决定绕上还是绕下。
|
||||
final int cornerSide = dirY != 0
|
||||
? dirY
|
||||
: (stagger + d.routeOffset >= 0 ? 1 : -1);
|
||||
|
||||
if (sameRow) {
|
||||
// 前后动作紧贴(首尾相接)时,连线/箭头会挤在接缝处且不可读:
|
||||
// 隐藏走线,只在接缝处显示依赖标签。
|
||||
final bool tight =
|
||||
(rb.left - ra.right).abs() <= 4 || (ra.left - rb.right).abs() <= 4;
|
||||
if (tight) {
|
||||
final bool toRight = rb.center.dx >= ra.center.dx;
|
||||
final double junctionX =
|
||||
toRight ? (ra.right + rb.left) / 2 : (ra.left + rb.right) / 2;
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
const <Offset>[],
|
||||
Offset.zero,
|
||||
const Offset(1, 0),
|
||||
Offset(junctionX, ra.top - 10),
|
||||
RouteAxis.vertical,
|
||||
junctionOnly: true,
|
||||
));
|
||||
continue;
|
||||
}
|
||||
// 同泳道:默认一条水平线;端点被遮挡或语义端点背向对方时,从
|
||||
// 端部上/下角绕行(避免线穿过两个条块)。
|
||||
final bool sourceFaces =
|
||||
(rb.center.dx - ra.center.dx) * fromSide >= 0;
|
||||
final bool targetFaces =
|
||||
(ra.center.dx - rb.center.dx) * toSide >= 0;
|
||||
_BarEnd s = _startEnd(ra, fromSide, cornerSide, obstaclesForStart);
|
||||
_BarEnd t = _targetEnd(rb, toSide, cornerSide, obstaclesForEnd);
|
||||
final bool straight = !s.corner && !t.corner && sourceFaces && targetFaces;
|
||||
if (straight) {
|
||||
final double y = sy + stagger + d.routeOffset;
|
||||
final Offset sp = Offset(s.point.dx, y);
|
||||
final Offset tp = Offset(t.point.dx, y);
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
<Offset>[sp, tp],
|
||||
tp,
|
||||
t.dir,
|
||||
Offset((sp.dx + tp.dx) / 2, y - (barHalf + 9)),
|
||||
RouteAxis.vertical,
|
||||
chipRun: (tp.dx - sp.dx).abs(),
|
||||
chipRunMargin: 8,
|
||||
chipAltAnchor: Offset(tp.dx + 6, y - (barHalf + 9)),
|
||||
));
|
||||
} else {
|
||||
// 只对背向对方 / 被遮挡的那一端退角,另一端仍从端点中心进出。
|
||||
if (!sourceFaces || s.corner) {
|
||||
s = _startEnd(ra, fromSide, cornerSide, obstaclesForStart, forceCorner: true);
|
||||
}
|
||||
if (!targetFaces || t.corner) {
|
||||
t = _targetEnd(rb, toSide, cornerSide, obstaclesForEnd, forceCorner: true);
|
||||
}
|
||||
final int side = s.corner
|
||||
? s.vSide
|
||||
: (t.corner ? t.vSide : cornerSide);
|
||||
double runY = sy + side * (barHalf + 10) + stagger + d.routeOffset;
|
||||
runY = side > 0
|
||||
? math.max(runY, ra.bottom + 6)
|
||||
: math.min(runY, ra.top - 6);
|
||||
final double tx =
|
||||
t.corner ? t.point.dx : t.point.dx - t.dir.dx * 10;
|
||||
final List<Offset> pts = <Offset>[s.point, Offset(s.point.dx, runY), Offset(tx, runY)];
|
||||
if (t.corner) {
|
||||
pts.add(t.point);
|
||||
} else {
|
||||
pts.add(Offset(tx, t.point.dy));
|
||||
pts.add(t.point);
|
||||
}
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
pts,
|
||||
t.point,
|
||||
t.dir,
|
||||
// 绕行线在条块外侧,标签也放到线外侧,避免压住动作条。
|
||||
Offset((ra.center.dx + rb.center.dx) / 2, runY + side * (barHalf + 9)),
|
||||
RouteAxis.vertical,
|
||||
chipRun: (tx - s.point.dx).abs(),
|
||||
chipRunMargin: 8,
|
||||
chipAltAnchor: Offset(
|
||||
t.point.dx + 6,
|
||||
t.corner ? t.point.dy + side * 10 : t.point.dy - 12,
|
||||
),
|
||||
));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
final _BarEnd s = _startEnd(ra, fromSide, cornerSide, obstaclesForStart);
|
||||
final _BarEnd t = _targetEnd(rb, toSide, -cornerSide, obstaclesForEnd);
|
||||
if (adjacentLane) {
|
||||
// 相邻泳道:端部引出后在两泳道之间的中线走水平段;同组错开 + 手动偏移。
|
||||
final double mid = (sy + ty) / 2 + stagger + d.routeOffset;
|
||||
final List<Offset> pts = <Offset>[s.point];
|
||||
if (!s.corner) {
|
||||
final double sx2 = s.point.dx + s.dir.dx * 10;
|
||||
pts.add(Offset(sx2, s.point.dy));
|
||||
pts.add(Offset(sx2, mid));
|
||||
} else {
|
||||
pts.add(Offset(s.point.dx, mid));
|
||||
}
|
||||
final double tx2 = t.corner ? t.point.dx : t.point.dx - t.dir.dx * 10;
|
||||
pts.add(Offset(tx2, mid));
|
||||
if (t.corner) {
|
||||
pts.add(t.point);
|
||||
} else {
|
||||
pts.add(Offset(tx2, t.point.dy));
|
||||
pts.add(t.point);
|
||||
}
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
pts,
|
||||
t.point,
|
||||
t.dir,
|
||||
Offset((ra.center.dx + rb.center.dx) / 2, mid),
|
||||
RouteAxis.vertical,
|
||||
chipRun: (tx2 - s.point.dx).abs(),
|
||||
chipRunMargin: 10,
|
||||
chipAltAnchor: Offset(
|
||||
t.point.dx + 6,
|
||||
t.point.dy + (t.corner ? t.dir.dy * 10 : -12),
|
||||
),
|
||||
));
|
||||
} else {
|
||||
// 跨多行:扫描区间内所有条块边界,在外侧选一条纵向走廊;同组按
|
||||
// ±12px 错开走廊,手动偏移作用于走廊横向位置。
|
||||
final double sx = s.point.dx;
|
||||
final double tx = t.point.dx;
|
||||
double maxRight = 0;
|
||||
double minLeft = double.infinity;
|
||||
final List<int> lanes = layout.lanes;
|
||||
for (int r = math.min(ia, ib) + 1; r < math.max(ia, ib); r++) {
|
||||
if (r < 0 || r >= lanes.length) continue;
|
||||
for (final Action aa in layout.actionsInLane(lanes[r])) {
|
||||
final Rect rr = layout.rectFor(aa);
|
||||
maxRight = math.max(maxRight, rr.right);
|
||||
minLeft = math.min(minLeft, rr.left);
|
||||
}
|
||||
}
|
||||
final double shift = stagger * 2 + d.routeOffset;
|
||||
double lane = math.max(math.max(sx, tx), maxRight) + 28 + shift;
|
||||
if (lane > layout.plotRight - 16) {
|
||||
lane = math.min(math.min(sx, tx), minLeft) - 28 - shift;
|
||||
}
|
||||
final double srcGapY = sy + dirY * (barHalf + 14);
|
||||
final double gapY = ty - dirY * (barHalf + 6);
|
||||
final List<Offset> pts = <Offset>[s.point];
|
||||
if (!s.corner) {
|
||||
final double sx2 = s.point.dx + s.dir.dx * 10;
|
||||
pts.add(Offset(sx2, s.point.dy));
|
||||
pts.add(Offset(sx2, srcGapY));
|
||||
} else {
|
||||
pts.add(Offset(s.point.dx, srcGapY));
|
||||
}
|
||||
pts.add(Offset(lane, srcGapY));
|
||||
pts.add(Offset(lane, gapY));
|
||||
if (t.corner) {
|
||||
pts.add(Offset(t.point.dx, gapY));
|
||||
pts.add(t.point);
|
||||
} else {
|
||||
final double tx2 = t.point.dx - t.dir.dx * 10;
|
||||
pts.add(Offset(tx2, gapY));
|
||||
pts.add(Offset(tx2, t.point.dy));
|
||||
pts.add(t.point);
|
||||
}
|
||||
out.add(BarDepRoute(
|
||||
d,
|
||||
pts,
|
||||
t.point,
|
||||
t.dir,
|
||||
Offset((lane + tx) / 2, gapY - (barHalf + 1)),
|
||||
RouteAxis.horizontal,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 命中条形依赖走线:返回最近且距离小于 [maxDist] 的走线(无命中返回 null)。
|
||||
BarDepRoute? hitBarDep(List<BarDepRoute> routes, Offset p, double maxDist) {
|
||||
BarDepRoute? best;
|
||||
double bestD = maxDist;
|
||||
for (final BarDepRoute r in routes) {
|
||||
final double d = distanceToPolyline(r.points, p);
|
||||
if (d < bestD) {
|
||||
bestD = d;
|
||||
best = r;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
// ===================== 圆周视图 =====================
|
||||
|
||||
/// 圆周视图的一条依赖走线(径向 → 圆弧 → 径向)。
|
||||
class ArcDepRoute {
|
||||
/// 构造。
|
||||
ArcDepRoute(this.dep, this.center, this.rA, this.rB, this.rC, this.rTip, this.aEnd, this.aStart,
|
||||
this.degenerate, this.cw, this.large, this.chipR, this.chipDeg,
|
||||
{this.junctionOnly = false});
|
||||
|
||||
/// 对应依赖。
|
||||
final Dependency dep;
|
||||
/// 圆心。
|
||||
final Offset center;
|
||||
/// 源环半径。
|
||||
final double rA;
|
||||
/// 目标环半径。
|
||||
final double rB;
|
||||
/// 绕行半径(自动错开 + 手动偏移作用于此)。
|
||||
final double rC;
|
||||
/// 箭头落点半径。
|
||||
final double rTip;
|
||||
/// 源弧末端角(度)。
|
||||
final double aEnd;
|
||||
/// 目标弧起点角(度)。
|
||||
final double aStart;
|
||||
/// 起止角几乎重合(退化)时改画短箭头。
|
||||
final bool degenerate;
|
||||
/// 圆弧是否顺时针。
|
||||
final bool cw;
|
||||
/// 是否大弧。
|
||||
final int large;
|
||||
/// 标签极径。
|
||||
final double chipR;
|
||||
/// 标签极角。
|
||||
final double chipDeg;
|
||||
|
||||
/// 动作紧贴时只显示连接点标签,隐藏圆弧与箭头。
|
||||
final bool junctionOnly;
|
||||
|
||||
/// 依赖键 `from->to`。
|
||||
String get key => '${dep.fromId}->${dep.toId}';
|
||||
|
||||
/// 起点(源环上)。
|
||||
Offset get p0 => polar(center, rA, aEnd);
|
||||
/// 绕行起点(半径 rC 上)。
|
||||
Offset get p1 => polar(center, rC, aEnd);
|
||||
/// 绕行终点(半径 rC 上)。
|
||||
Offset get p2 => polar(center, rC, aStart);
|
||||
/// 箭头端点。
|
||||
Offset get p3 => polar(center, rTip, aStart);
|
||||
/// 退化短箭头的起点。
|
||||
Offset get q0 => polar(center, rTip - (rTip > rB ? 28 : -28), aStart);
|
||||
|
||||
/// 生成绘制路径(绘制与命中测试同源)。
|
||||
Path buildPath() {
|
||||
final Path p = Path();
|
||||
if (degenerate) {
|
||||
p.moveTo(q0.dx, q0.dy);
|
||||
p.lineTo(p3.dx, p3.dy);
|
||||
return p;
|
||||
}
|
||||
final Offset a0 = p0;
|
||||
final Offset a1 = p1;
|
||||
final Offset a2 = p2;
|
||||
final Offset a3 = p3;
|
||||
p.moveTo(a0.dx, a0.dy);
|
||||
p.lineTo(a1.dx, a1.dy);
|
||||
p.arcToPoint(a2, radius: Radius.circular(rC), largeArc: large == 1, clockwise: cw);
|
||||
p.lineTo(a3.dx, a3.dy);
|
||||
return p;
|
||||
}
|
||||
|
||||
/// 箭头方向(分量式)。
|
||||
Offset get tipDir => degenerate ? (p3 - q0) : (p3 - p2);
|
||||
}
|
||||
|
||||
/// 计算圆周视图的全部依赖走线(含自动错开与手动偏移)。
|
||||
List<ArcDepRoute> buildArcDepRoutes(Project project, CircularLayout layout) {
|
||||
final Map<String, int> seen = <String, int>{};
|
||||
final List<ArcDepRoute> out = <ArcDepRoute>[];
|
||||
for (final Action to in project.actions) {
|
||||
for (final Dependency d in to.deps) {
|
||||
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, 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 时从最外圈绕行,避免穿过中间层弧线。
|
||||
final bool skip = (a.layer - b.layer).abs() > 1;
|
||||
final String groupKey = '${skip ? 'K' : 'N'}${a.layer}→${b.layer}';
|
||||
final int k = seen.putIfAbsent(groupKey, () => 0);
|
||||
seen[groupKey] = k + 1;
|
||||
// 同一环 / 相邻环的依赖如果画在环半径上会压住动作弧:把绕行半径
|
||||
// 放到环间空隙(同一环时即为外侧空隙),标签也跟随到空隙里。
|
||||
final double ringGap = math.max(layout.pitch - layout.th, 8);
|
||||
final bool sameRing = (rA - rB).abs() < layout.pitch * 0.35;
|
||||
final double baseC = skip
|
||||
? layout.rMax + 24
|
||||
: (sameRing ? rA + ringGap * 0.55 : (rA + rB) / 2);
|
||||
// 自动错开(步长 9px)+ 手动径向偏移(圆周视图的“法线”即半径方向)。
|
||||
double rC = baseC + staggerOffset(k) * 1.5 + d.routeOffset;
|
||||
rC = rC.clamp(18.0, layout.rMax + 170);
|
||||
final double rTip = rC < rB ? rB - layout.th / 2 - 4 : rB + layout.th / 2 + 4;
|
||||
final bool cw = aStart >= aEnd;
|
||||
final int large = (aStart - aEnd).abs() > 180 ? 1 : 0;
|
||||
final bool degenerate = (aStart - aEnd).abs() < 0.5;
|
||||
final bool junctionOnly = (aStart - aEnd).abs() <= 2.0;
|
||||
final double chipDeg = degenerate ? aStart : (aEnd + aStart) / 2;
|
||||
final double chipR = rC;
|
||||
out.add(ArcDepRoute(
|
||||
d,
|
||||
layout.center,
|
||||
rA,
|
||||
rB,
|
||||
rC,
|
||||
rTip,
|
||||
aEnd,
|
||||
aStart,
|
||||
degenerate,
|
||||
cw,
|
||||
large,
|
||||
chipR,
|
||||
chipDeg,
|
||||
junctionOnly: junctionOnly));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// 命中圆周依赖走线:返回最近且距离小于 [maxDist] 的走线(无命中返回 null)。
|
||||
ArcDepRoute? hitArcDep(List<ArcDepRoute> routes, Offset p, double maxDist) {
|
||||
ArcDepRoute? best;
|
||||
double bestD = maxDist;
|
||||
for (final ArcDepRoute r in routes) {
|
||||
final double d = distanceToPath(r.buildPath(), p);
|
||||
if (d < bestD) {
|
||||
bestD = d;
|
||||
best = r;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
@@ -12,8 +12,8 @@ library;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'dep_routes.dart';
|
||||
import 'layout.dart';
|
||||
|
||||
@@ -10,7 +10,7 @@ library;
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui';
|
||||
|
||||
import '../model/models.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// 极坐标转直角坐标:以 [c] 为圆心、[r] 为半径、[deg] 为角度(0° 指向正上方)。
|
||||
Offset polar(Offset c, double r, double deg) {
|
||||
@@ -0,0 +1,61 @@
|
||||
/// 动作条拖拽吸附:把整体拖动的水平位移吸附到最近的动作条端点、整 5°、
|
||||
/// 0/360 或相位分区边界。
|
||||
///
|
||||
/// 架构位置:布局层纯函数,不依赖 UI 状态;`CanvasView` 在整体拖动时调用,
|
||||
/// 单元测试可直接验证吸附结果。
|
||||
library;
|
||||
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// 计算整体拖动后的动作起始角。
|
||||
///
|
||||
/// - [project]:当前工程;
|
||||
/// - [excludeId]:正在拖动的动作 id(不参与吸附,避免自吸附);
|
||||
/// - [rawStart]:未吸附的起始角;
|
||||
/// - [duration]:动作持续角(整体拖动不改变长度);
|
||||
/// - [toleranceDeg]:吸附容差(度)。
|
||||
///
|
||||
/// 返回 `(吸附后的起始角, 参考角度)`;参考角度用于绘制竖向虚线,
|
||||
/// 未吸附时为 null。
|
||||
(double, double?) snapActionStart({
|
||||
required Project project,
|
||||
required String excludeId,
|
||||
required double rawStart,
|
||||
required double duration,
|
||||
required double toleranceDeg,
|
||||
}) {
|
||||
final double tol = toleranceDeg <= 0 ? 0 : toleranceDeg;
|
||||
final List<double> candidates = <double>[0, 360];
|
||||
for (int d = 0; d <= 360; d += 5) {
|
||||
candidates.add(d.toDouble());
|
||||
}
|
||||
for (final Action a in project.actions) {
|
||||
if (a.id == excludeId) continue;
|
||||
candidates.add(a.startAngle);
|
||||
candidates.add(a.endAngle);
|
||||
}
|
||||
for (final PhaseZone z in project.phaseZones) {
|
||||
candidates.add(z.startAngle);
|
||||
candidates.add(z.endAngle);
|
||||
}
|
||||
final double end = rawStart + duration;
|
||||
double best = rawStart;
|
||||
double bestD = tol;
|
||||
double? guide;
|
||||
// 起点与终点同时参与匹配:取绝对调整量最小的一条候选。
|
||||
for (final double cand in candidates) {
|
||||
final double ds = (cand - rawStart).abs();
|
||||
if (ds < bestD) {
|
||||
bestD = ds;
|
||||
best = cand;
|
||||
guide = cand;
|
||||
}
|
||||
final double de = (cand - end).abs();
|
||||
if (de < bestD) {
|
||||
bestD = de;
|
||||
best = cand - duration;
|
||||
guide = cand;
|
||||
}
|
||||
}
|
||||
return (best.clamp(0, 360 - duration), guide);
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
/// 横轴同时表达相位角度与等价的绝对时间,纵轴按工位顺序排列动作行。
|
||||
///
|
||||
/// 架构位置:
|
||||
/// - 全部几何计算委托给 [BarLayout](`lib/layout/layout.dart`),
|
||||
/// - 全部几何计算委托给 [BarLayout](`modules/sequence/layout/layout.dart`),
|
||||
/// 本绘制器只负责取几何结果并落笔,不自行推导坐标。
|
||||
/// - 颜色一律取自 [Tokens],因此与圆形视图及 SVG 导出保持同一视觉体系。
|
||||
/// - 关键路径信息([criticalActions]、[criticalDeps])由上层分析后传入,
|
||||
@@ -19,11 +19,11 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/dep_routes.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
|
||||
/// 条形时间轴视图的 [CustomPainter] 实现。
|
||||
///
|
||||
@@ -298,7 +298,7 @@ class BarPainter extends CustomPainter {
|
||||
Offset(layout.plotLeft, sy),
|
||||
Offset(layout.plotRight, sy),
|
||||
Paint()
|
||||
..color = tokens.line2.withValues(alpha: 0.5)
|
||||
..color = tokens.line2.withValues(alpha: 0.75)
|
||||
..strokeWidth = 1,
|
||||
);
|
||||
}
|
||||
@@ -306,13 +306,13 @@ class BarPainter extends CustomPainter {
|
||||
// 泳道标题(合并显示;单槽最多两行,多槽位按泳道高度持续换行)。
|
||||
_laneHeader(canvas, layout, li, acts,
|
||||
slots == 1 ? y : y + laneH / 2 - BarLayout.rowVisual / 2, slots, laneH);
|
||||
// 泳道底分隔线(单槽时与旧版一致)。
|
||||
// 泳道底分隔线(单槽时与旧版一致;加深颜色便于区分泳道)。
|
||||
canvas.drawLine(
|
||||
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,
|
||||
..color = tokens.line2
|
||||
..strokeWidth = 1.3,
|
||||
);
|
||||
// 该泳道内的所有动作条(按槽位分行放置)。
|
||||
for (final Action a in acts) {
|
||||
@@ -374,8 +374,9 @@ class BarPainter extends CustomPainter {
|
||||
'${acts.length > 1 ? ' · 共 ${acts.length} 个' : ''}';
|
||||
// 副标题紧随实际标题高度;单槽保持旧版下边距(y+32)但绝不高于标题底部,
|
||||
// 多槽位下若剩余高度不足则不再绘制,避免压住标题文字。
|
||||
final double subY =
|
||||
single ? math.max(y + 32, y + 2 + tp.height + 2) : y + 2 + tp.height + 2;
|
||||
final double subY = single
|
||||
? math.max(y + 36, y + 2 + tp.height + 6)
|
||||
: y + 2 + tp.height + 6;
|
||||
if (single || subY + 11 <= y + laneH) {
|
||||
_textMax(canvas, sub, Offset(60, subY), labelMax, color: tokens.dim, size: 10);
|
||||
}
|
||||
@@ -467,7 +468,7 @@ class BarPainter extends CustomPainter {
|
||||
/// 作为竖直通道,泳道位置按区间内条块的最右/最左边界外扩,
|
||||
/// 并叠加 `(k % 3) * 16` 的错位,避免多条线完全重叠。
|
||||
/// - 关键路径依赖先画一层加粗低透明度的“光晕”,再画主线。
|
||||
/// - 末端绘制箭头与类型标签(FS 顺序 / SS +偏移角)。
|
||||
/// - 末端绘制箭头与类型标签(FS 顺序 / SS +偏移时间)。
|
||||
///
|
||||
/// 参数 [layout] 提供条块矩形;[u] 当前未直接使用,保留以对齐调用接口。
|
||||
void _deps(Canvas canvas, BarLayout layout, UnitSettings u) {
|
||||
@@ -482,46 +483,46 @@ class BarPainter extends CustomPainter {
|
||||
final bool crit = criticalDeps.contains(r.key);
|
||||
final bool sel = selectedDep == r.key;
|
||||
final Color draw = sel ? tokens.accent : col;
|
||||
final Path p = Path()
|
||||
..moveTo(r.points.first.dx, r.points.first.dy);
|
||||
for (int i = 1; i < r.points.length; i++) {
|
||||
p.lineTo(r.points[i].dx, r.points[i].dy);
|
||||
}
|
||||
// 关键路径依赖:先铺一层加粗低透明度光晕,再画主线。
|
||||
if (crit) {
|
||||
if (!r.junctionOnly) {
|
||||
final Path p = Path()
|
||||
..moveTo(r.points.first.dx, r.points.first.dy);
|
||||
for (int i = 1; i < r.points.length; i++) {
|
||||
p.lineTo(r.points[i].dx, r.points[i].dy);
|
||||
}
|
||||
// 关键路径依赖:先铺一层加粗低透明度光晕,再画主线。
|
||||
if (crit) {
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 5
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = col.withValues(alpha: 0.18),
|
||||
);
|
||||
}
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 5
|
||||
..strokeWidth = sel ? 2.0 : (crit ? 1.1 : 0.85)
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = col.withValues(alpha: 0.18),
|
||||
..color = sel ? draw : draw.withValues(alpha: 0.95),
|
||||
);
|
||||
_arrow(canvas, r.arrowTip, r.arrowDir, draw);
|
||||
}
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = sel ? 2.0 : (crit ? 1.1 : 0.85)
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = sel ? draw : draw.withValues(alpha: 0.95),
|
||||
);
|
||||
_arrow(canvas, r.arrowTip, r.arrowDir, draw);
|
||||
final String label = switch (d.type) {
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${d.offsetAngle.toStringAsFixed(0)}°',
|
||||
DepType.ss => d.offsetAngle == 0
|
||||
? 'SS'
|
||||
: 'SS+${deg2msStr(d.offsetAngle, project.units, project.cycle.durationMs, dec: 2)}',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
// 行程太短的连线:标签移到箭头外侧(宽度按真实字号精确测量)。
|
||||
final double chipW = _tp(label, 8.5, draw, FontWeight.w600).width + 12;
|
||||
final Offset chipCenter = r.chipRun < chipW + r.chipRunMargin
|
||||
? Offset(r.chipAltAnchor.dx + chipW / 2, r.chipAltAnchor.dy)
|
||||
: r.chipCenter;
|
||||
// 先记录标签位置,所有依赖线画完后统一避让放置(避免标签互相重叠)。
|
||||
chips.add(_ChipSpec(chipCenter, label, draw));
|
||||
// 标签固定在两端动作之间的走线中点;不再因为行程短而横向挪到
|
||||
// 目标条块上方。统一避让时会同时避开动作条与其它标签。
|
||||
chips.add(_ChipSpec(r.chipCenter, label, draw));
|
||||
}
|
||||
_placeChips(canvas, chips);
|
||||
_placeChips(canvas, layout, chips);
|
||||
}
|
||||
|
||||
/// 在 [tip] 处绘制指向 [dir] 方向的实心三角箭头。
|
||||
@@ -544,8 +545,11 @@ class BarPainter extends CustomPainter {
|
||||
/// 对每个标签依次尝试:原位 → 上下错开 → 上下再错开 → 左右错开 → 斜向错开,
|
||||
/// 取第一个不与已放置标签相交的位置,实现“智能避让”。标签内不再绘制五角星
|
||||
/// (关键路径改用线条光晕表示),字号与色块同时收小,画面更干净。
|
||||
void _placeChips(Canvas canvas, List<_ChipSpec> chips) {
|
||||
void _placeChips(Canvas canvas, BarLayout layout, List<_ChipSpec> chips) {
|
||||
final List<Rect> placed = <Rect>[];
|
||||
final List<Rect> bars = <Rect>[
|
||||
for (final Action a in project.actions) layout.rectFor(a).inflate(1),
|
||||
];
|
||||
for (final _ChipSpec chip in chips) {
|
||||
final TextPainter tp = _tp(chip.label, 8.5, chip.color, FontWeight.w600);
|
||||
final double w = tp.width + 12;
|
||||
@@ -562,7 +566,10 @@ class BarPainter extends CustomPainter {
|
||||
Rect r = Rect.fromCenter(center: chip.center, width: w, height: h);
|
||||
for (final Offset t in trials) {
|
||||
final Rect cand = r.shift(t);
|
||||
if (!placed.any((Rect o) => o.inflate(1.5).overlaps(cand))) {
|
||||
final bool hitChip =
|
||||
placed.any((Rect o) => o.inflate(1.5).overlaps(cand));
|
||||
final bool hitBar = bars.any((Rect o) => o.overlaps(cand));
|
||||
if (!hitChip && !hitBar) {
|
||||
r = cand;
|
||||
break;
|
||||
}
|
||||
@@ -665,7 +672,7 @@ class _ChipSpec {
|
||||
|
||||
/// 期望的标签中心(逻辑坐标)。
|
||||
final Offset center;
|
||||
/// 标签文本(如 `FS` / `SS+30°`)。
|
||||
/// 标签文本(如 `FS` / `SS+0.20 s`)。
|
||||
final String label;
|
||||
/// 边框与文字颜色(按依赖类型区分)。
|
||||
final Color color;
|
||||
+79
-27
@@ -15,11 +15,11 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/dep_routes.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
|
||||
/// 圆形视图的 [CustomPainter] 实现。
|
||||
///
|
||||
@@ -409,12 +409,35 @@ class CircularPainter extends CustomPainter {
|
||||
}
|
||||
}
|
||||
|
||||
// 文字沿圆弧排列并按弧长截断,保证始终位于动作色带之内。
|
||||
// 文字沿圆弧排列并按弧长截断;短弧优先保留动作名,避免只剩
|
||||
// “1. A1 动…” 这类难以辨认的省略文本。
|
||||
final double mid = (a.startAngle + a.endAngle) / 2;
|
||||
final int step = project.actions.indexOf(a) + 1;
|
||||
final double span = a.wrap ? (360 - a.startAngle) : a.durationAngle;
|
||||
final double arcLen = 2 * math.pi * r * (span.clamp(0, 360) / 360);
|
||||
_arcLabel(canvas, c, r, mid, '$step. ${a.id} ${a.name}', tokens.arcText, 11, math.max(arcLen - 12, 20));
|
||||
final double maxW = math.max(arcLen - 12, 20);
|
||||
double widthOf(String text) {
|
||||
final TextPainter tp = TextPainter(
|
||||
text: TextSpan(
|
||||
text: text,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontFamily: 'Microsoft YaHei UI',
|
||||
),
|
||||
),
|
||||
textDirection: ui.TextDirection.ltr,
|
||||
maxLines: 1,
|
||||
)..layout();
|
||||
final double w = tp.width;
|
||||
tp.dispose();
|
||||
return w;
|
||||
}
|
||||
String label = '$step. ${a.id} ${a.name}';
|
||||
if (widthOf(label) > maxW) label = '$step. ${a.name}';
|
||||
if (widthOf(label) > maxW) label = a.name;
|
||||
if (widthOf(label) > maxW) label = '$step. ${a.id}';
|
||||
_arcLabel(canvas, c, r, mid, label, tokens.arcText, 11, maxW);
|
||||
}
|
||||
|
||||
/// 构造「方头 + 小圆角」的圆环动作带(填充路径)。
|
||||
@@ -486,28 +509,34 @@ class CircularPainter extends CustomPainter {
|
||||
final bool sel = selectedDep == r.key;
|
||||
final Color draw = sel ? tokens.accent : col;
|
||||
|
||||
final Path p = r.buildPath();
|
||||
if (crit) {
|
||||
if (!r.junctionOnly) {
|
||||
final Path p = r.buildPath();
|
||||
if (crit) {
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 5
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = col.withValues(alpha: 0.2),
|
||||
);
|
||||
}
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 5
|
||||
..strokeWidth = sel ? 2.2 : (crit ? 1.2 : (d.type == DepType.fs ? 1.0 : 0.9))
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = col.withValues(alpha: 0.2),
|
||||
..color = draw,
|
||||
);
|
||||
_arrow(canvas, r.p3, r.tipDir, draw);
|
||||
}
|
||||
canvas.drawPath(
|
||||
p,
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = sel ? 2.2 : (crit ? 1.2 : (d.type == DepType.fs ? 1.0 : 0.9))
|
||||
..strokeCap = StrokeCap.round
|
||||
..color = draw,
|
||||
);
|
||||
_arrow(canvas, r.p3, r.tipDir, draw);
|
||||
|
||||
String label = d.type == DepType.fs ? 'FS' : 'SS+${d.offsetAngle.toStringAsFixed(0)}°';
|
||||
String label = d.type == DepType.fs
|
||||
? 'FS'
|
||||
: (d.offsetAngle == 0
|
||||
? 'SS'
|
||||
: 'SS+${deg2msStr(d.offsetAngle, project.units, project.cycle.durationMs, dec: 2)}');
|
||||
if (d.type == DepType.ff) label = 'FF';
|
||||
if (d.type == DepType.sf) label = 'SF';
|
||||
return _ArcChip(r.chipR, r.chipDeg, '${d.fromId}→${d.toId} $label', draw);
|
||||
@@ -522,8 +551,9 @@ class CircularPainter extends CustomPainter {
|
||||
final List<Rect> placed = <Rect>[];
|
||||
const double size = 8.5;
|
||||
for (final _ArcChip chip in chips) {
|
||||
final double w = chip.text.runes.length * size * 0.62 + 8;
|
||||
final double h = size * 1.7;
|
||||
final TextPainter tp = _tp(chip.text, size, chip.color, FontWeight.w600);
|
||||
final double w = tp.width + 10;
|
||||
const double h = 14;
|
||||
double r = chip.r;
|
||||
Rect rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h);
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
@@ -533,9 +563,31 @@ class CircularPainter extends CustomPainter {
|
||||
rect = Rect.fromCenter(center: polar(c, r, chip.deg), width: w, height: h);
|
||||
}
|
||||
placed.add(rect);
|
||||
final double arcLen = 2 * math.pi * r * 0.9;
|
||||
_arcLabel(canvas, c, r, chip.deg, chip.text, chip.color, size,
|
||||
math.max(math.min(arcLen, 200), 40));
|
||||
// 标签沿圆弧切线方向旋转(与动作弧同向),放在环间空隙中。
|
||||
final Offset pos = polar(c, r, chip.deg);
|
||||
final double rad = chip.deg * math.pi / 180;
|
||||
final bool flip = chip.deg > 90 && chip.deg < 270;
|
||||
canvas.save();
|
||||
canvas.translate(pos.dx, pos.dy);
|
||||
canvas.rotate(flip ? rad + math.pi : rad);
|
||||
final Rect local = Rect.fromCenter(
|
||||
center: Offset.zero,
|
||||
width: w,
|
||||
height: h,
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(local, const Radius.circular(5)),
|
||||
Paint()..color = tokens.chip,
|
||||
);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(local, const Radius.circular(5)),
|
||||
Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1
|
||||
..color = chip.color,
|
||||
);
|
||||
tp.paint(canvas, Offset(-tp.width / 2, -tp.height / 2));
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -724,7 +776,7 @@ class _ArcChip {
|
||||
final double r;
|
||||
/// 期望的标签角度(度,0° = 12 点钟、顺时针)。
|
||||
final double deg;
|
||||
/// 标签文本(如 `A1→A2 SS+30°`)。
|
||||
/// 标签文本(如 `A1→A2 SS+0.20 s`)。
|
||||
final String text;
|
||||
/// 文本颜色(按依赖类型区分)。
|
||||
final Color color;
|
||||
@@ -9,9 +9,10 @@ import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
|
||||
/// 流程图 [CustomPainter] 实现。
|
||||
class FlowchartPainter extends CustomPainter {
|
||||
@@ -102,7 +103,7 @@ class FlowchartPainter extends CustomPainter {
|
||||
}
|
||||
}
|
||||
|
||||
/// 绘制连线:FS 实线、SS 虚线(带偏移角标注)、关键路径加粗光晕。
|
||||
/// 绘制连线:FS 实线、SS 虚线(带偏移时间标注)、关键路径加粗光晕。
|
||||
///
|
||||
/// 走线由 [FlowLayout.routes] 统一计算(与 SVG / drawio 导出共用同一几何)。
|
||||
void _edges(Canvas canvas, FlowLayout layout) {
|
||||
@@ -145,7 +146,9 @@ class FlowchartPainter extends CustomPainter {
|
||||
if (e.type != null) {
|
||||
final String text = switch (e.type!) {
|
||||
DepType.fs => 'FS',
|
||||
DepType.ss => 'SS+${e.offset.toStringAsFixed(0)}°',
|
||||
DepType.ss => e.offset == 0
|
||||
? 'SS'
|
||||
: 'SS+${deg2msStr(e.offset, project.units, project.cycle.durationMs, dec: 2)}',
|
||||
DepType.ff => 'FF',
|
||||
DepType.sf => 'SF',
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
/// 时序图设计模块:PLC 流程节拍 / 相位角、条形 / 圆周 / 流程图三视图。
|
||||
///
|
||||
/// 模块入口:`lib/modules/sequence/`。新增模块请参考本文件与
|
||||
/// `lib/modules/README.md`,然后在 `lib/modules/registry.dart` 注册。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/ui/sequence_ui.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
|
||||
/// 时序图模块单例。
|
||||
const SequenceModule sequenceModule = SequenceModule();
|
||||
|
||||
/// 时序图设计模块。
|
||||
class SequenceModule extends EdcModule {
|
||||
/// 构造模块。
|
||||
const SequenceModule();
|
||||
|
||||
/// 稳定 id。
|
||||
static const String moduleId = 'sequence';
|
||||
|
||||
@override
|
||||
String get id => moduleId;
|
||||
@override
|
||||
String get name => '时序图';
|
||||
@override
|
||||
String get shortName => '时序图';
|
||||
@override
|
||||
IconData get icon => Icons.waterfall_chart;
|
||||
@override
|
||||
int get accent => 0xFF4CC9F0;
|
||||
@override
|
||||
String get suffix => '.seq.json';
|
||||
@override
|
||||
bool get available => true;
|
||||
@override
|
||||
String get defaultName => '未命名-时序图';
|
||||
@override
|
||||
String get blurb => 'PLC 节拍 · 三视图';
|
||||
|
||||
@override
|
||||
void newDocument(AppController controller) {
|
||||
controller.newProject();
|
||||
}
|
||||
|
||||
@override
|
||||
void loadDocument(AppController controller, String source, {String? path}) {
|
||||
controller.loadProject(Project.decode(source), path: path);
|
||||
}
|
||||
|
||||
@override
|
||||
String encodeDocument(AppController controller) =>
|
||||
controller.project.encode(includeArch: false);
|
||||
|
||||
@override
|
||||
String documentName(AppController controller) => controller.project.name;
|
||||
|
||||
@override
|
||||
String? filePath(AppController controller) => controller.filePath;
|
||||
|
||||
@override
|
||||
bool isDirty(AppController controller) => controller.dirty;
|
||||
|
||||
@override
|
||||
Future<void> saveTo(AppController controller, String path) =>
|
||||
controller.saveAs(path);
|
||||
|
||||
@override
|
||||
Future<void> markSaved(AppController controller, String displayPath) =>
|
||||
controller.markSaved(displayPath);
|
||||
|
||||
@override
|
||||
bool isReadOnly(AppController controller) =>
|
||||
controller.project.viewState.mode == ViewMode.flow;
|
||||
|
||||
@override
|
||||
Map<ShortcutActivator, VoidCallback> buildShortcuts(ModuleUiContext ui) {
|
||||
return <ShortcutActivator, VoidCallback>{
|
||||
const SingleActivator(LogicalKeyboardKey.delete): () {
|
||||
if (!isReadOnly(ui.controller) && ui.controller.selectedId != null) {
|
||||
ui.controller.deleteAction(ui.controller.selectedId!);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildWorkspace(ModuleUiContext ui) => SequenceUi(ui).buildWorkspace();
|
||||
|
||||
@override
|
||||
Widget? buildLeftPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||||
SequenceUi(ui).buildLeftPanel(ui.tokens, floating: floating);
|
||||
|
||||
@override
|
||||
Widget? buildRightPanel(ModuleUiContext ui, {bool floating = false}) =>
|
||||
SequenceUi(ui).buildRightPanel(ui.tokens, floating: floating);
|
||||
|
||||
@override
|
||||
List<Widget> buildToolbarCenter(ModuleUiContext ui, {required bool compact}) =>
|
||||
SequenceUi(ui).buildToolbarCenter(ui.tokens, compact: compact);
|
||||
|
||||
@override
|
||||
List<Widget> buildToolbarRight(ModuleUiContext ui) =>
|
||||
SequenceUi(ui).buildToolbarRight(ui.tokens, compact: ui.compact);
|
||||
|
||||
@override
|
||||
Widget buildStatusBar(ModuleUiContext ui) =>
|
||||
SequenceUi(ui).buildStatusBar(ui.tokens);
|
||||
}
|
||||
@@ -15,10 +15,10 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../ai/ai_client.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/ai/ai_client.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||||
|
||||
class AiGenerateDialog extends StatefulWidget {
|
||||
const AiGenerateDialog({super.key, required this.controller});
|
||||
@@ -9,12 +9,12 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||||
|
||||
/// 条形缩略预览的固定绘制区高度:卡片尺寸不随动作数量变化,
|
||||
/// 动作越多只会在内部压缩行距、把色条画得更细。
|
||||
@@ -15,16 +15,17 @@ import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../render/bar_painter.dart';
|
||||
import '../render/circular_painter.dart';
|
||||
import '../render/flow_painter.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/dep_routes.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/snap.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/render/bar_painter.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/render/circular_painter.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/render/flow_painter.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/ui/dialogs.dart';
|
||||
|
||||
/// 当前拖拽行为类型:无操作 / 平移相位 / 拖右端改时长 / 拖左端改起始 /
|
||||
/// 拖拽依赖走线(沿法线平移整条线)。
|
||||
@@ -697,7 +698,19 @@ class _CanvasViewState extends State<CanvasView> {
|
||||
);
|
||||
} else {
|
||||
// 整体移动:水平改起始相位 + 垂直跟随泳道 / 槽位,两者可同时进行。
|
||||
c.setActionStart(_dragAction!.id, _startAngle + dx / layout.span * 360);
|
||||
// 起点/终点同时参与磁吸:靠近上下游动作条端点、整 5° 或分区边界时
|
||||
// 自动贴合,并显示竖向参考虚线(与改时长的手感一致)。
|
||||
final double rawStart = _startAngle + dx / layout.span * 360;
|
||||
final double tolDeg = math.max(2.5, 10 / layout.span * 360);
|
||||
final (double ns, double? guide) = snapActionStart(
|
||||
project: c.project,
|
||||
excludeId: _dragAction!.id,
|
||||
rawStart: rawStart,
|
||||
duration: _startDuration,
|
||||
toleranceDeg: tolDeg,
|
||||
);
|
||||
_zoneGuideAngle = guide;
|
||||
c.setActionStart(_dragAction!.id, ns, snap: false);
|
||||
final Action? cur = c.project.actionById(_dragAction!.id);
|
||||
final int curLane = cur?.layer ?? _dragAction!.layer;
|
||||
final int curSlot = cur == null ? 0 : layout.slotOf(cur);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
/// 拓扑图模块(规划中)。
|
||||
///
|
||||
/// 当前仅注册元数据与占位实现;实现时在 `lib/modules/topo/` 下补齐文档模型
|
||||
/// 与 UI,并在本类中替换 `PlannedModule` 为真实 [EdcModule] 实现即可。
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:sequence_diagram/modules/module.dart';
|
||||
|
||||
/// 拓扑图模块单例(未开放)。
|
||||
const TopoModule topoModule = TopoModule();
|
||||
|
||||
/// 拓扑图模块。
|
||||
class TopoModule extends PlannedModule {
|
||||
/// 构造模块。
|
||||
const TopoModule()
|
||||
: super(
|
||||
id: 'topo',
|
||||
name: '拓扑图',
|
||||
shortName: '拓扑',
|
||||
icon: Icons.hub_outlined,
|
||||
accent: 0xFFF472B6,
|
||||
suffix: '.topo.json',
|
||||
defaultName: '未命名-拓扑图',
|
||||
blurb: '网络设备 · 链路',
|
||||
);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ library;
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import '../model/models.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
|
||||
/// 崩溃恢复信息:描述一次可恢复的自动保存会话。
|
||||
class RecoveryInfo {
|
||||
|
||||
@@ -16,18 +16,18 @@ import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../arch/arch_models.dart';
|
||||
import '../arch/arch_samples.dart';
|
||||
import '../persistence/android_docs.dart';
|
||||
import '../sketch/sketch_models.dart';
|
||||
import '../sketch/sketch_solver.dart';
|
||||
import '../version.dart';
|
||||
import '../layout/dep_routes.dart';
|
||||
import '../layout/layout.dart';
|
||||
import '../layout/flow_layout.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../persistence/storage.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/domain/arch_samples.dart';
|
||||
import 'package:sequence_diagram/persistence/android_docs.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_models.dart';
|
||||
import 'package:sequence_diagram/modules/architecture/sketch/sketch_solver.dart';
|
||||
import 'package:sequence_diagram/version.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/dep_routes.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/layout.dart';
|
||||
import 'package:sequence_diagram/modules/sequence/layout/flow_layout.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/persistence/storage.dart';
|
||||
|
||||
/// 全局应用控制器(继承 [ChangeNotifier])。
|
||||
class AppController extends ChangeNotifier {
|
||||
@@ -45,8 +45,9 @@ class AppController extends ChangeNotifier {
|
||||
/// 当前主题亮度(默认浅色 / 白底)。
|
||||
Brightness _brightness = Brightness.light;
|
||||
|
||||
/// 当前顶层设计模块(时序图 / 架构图);仅运行时状态,不随文件保存。
|
||||
AppMode _appMode = AppMode.sequence;
|
||||
/// 当前顶层设计模块 id;null = 首页。模块由 `lib/modules/registry.dart`
|
||||
/// 注册,控制器不依赖具体模块枚举,新增模块无需修改此处。
|
||||
String? _activeModuleId = 'sequence';
|
||||
|
||||
/// 架构图当前工具。
|
||||
ArchTool _archTool = ArchTool.select;
|
||||
@@ -124,7 +125,7 @@ class AppController extends ChangeNotifier {
|
||||
|
||||
/// 当前模块对应的文件路径(标题 / 状态显示用)。
|
||||
String? get currentFilePath =>
|
||||
_appMode == AppMode.architecture ? _archFilePath : _filePath;
|
||||
_activeModuleId == 'architecture' ? _archFilePath : _filePath;
|
||||
|
||||
/// 架构图文档文件路径。
|
||||
String? get archFilePath => _archFilePath;
|
||||
@@ -254,7 +255,7 @@ class AppController extends ChangeNotifier {
|
||||
/// 安卓写入公共 Documents,桌面写文件并同步 `.bak` 备份。
|
||||
Future<void> _autoSaveDocument() async {
|
||||
final String? path =
|
||||
_appMode == AppMode.architecture ? _archFilePath : _filePath;
|
||||
_activeModuleId == 'architecture' ? _archFilePath : _filePath;
|
||||
if (!_project.autoSaveEnabled || !_dirty || path == null) return;
|
||||
final DateTime now = DateTime.now();
|
||||
// 从未保存过时间戳(如刚打开文件):以“现在”为基准,等满一个间隔再自动保存。
|
||||
@@ -267,7 +268,7 @@ class AppController extends ChangeNotifier {
|
||||
if (now.difference(_lastSavedAt!).inSeconds < minutes * 60) return;
|
||||
_lastSavedAt = now;
|
||||
try {
|
||||
if (_appMode == AppMode.architecture) {
|
||||
if (_activeModuleId == 'architecture') {
|
||||
final String json = _project.arch.encode();
|
||||
if (AndroidDocs.isAvailable) {
|
||||
await AndroidDocs.saveFile(
|
||||
@@ -391,18 +392,19 @@ class AppController extends ChangeNotifier {
|
||||
|
||||
// ============ 设计合集(模块切换)与架构图 ============
|
||||
|
||||
/// 当前顶层设计模块(时序图 / 架构图)。
|
||||
AppMode get appMode => _appMode;
|
||||
/// 当前顶层设计模块 id;null = 首页。
|
||||
String? get activeModuleId => _activeModuleId;
|
||||
|
||||
/// 是否处于首页。
|
||||
bool get isHome => _activeModuleId == null;
|
||||
|
||||
/// 切换顶层设计模块并刷新界面(品牌菜单 / 首页调用)。
|
||||
void setAppMode(AppMode m) {
|
||||
if (_appMode == m) return;
|
||||
_appMode = m;
|
||||
_status = switch (m) {
|
||||
AppMode.home => '首页',
|
||||
AppMode.sequence => '时序图设计',
|
||||
AppMode.architecture => '架构图设计 · 手绘识别',
|
||||
};
|
||||
///
|
||||
/// [status] 由模块提供进入提示;不传时使用通用文案。
|
||||
void setModuleId(String? id, {String? status}) {
|
||||
if (_activeModuleId == id) return;
|
||||
_activeModuleId = id;
|
||||
_status = status ?? (id == null ? '首页' : '已进入模块 $id');
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -412,11 +414,11 @@ class AppController extends ChangeNotifier {
|
||||
/// (当前文档数据在进入新模块时会由新建文档替换)。
|
||||
/// 外壳在离开「有未保存修改的文档」前负责弹窗确认。
|
||||
void goHome() {
|
||||
final bool changed = _appMode != AppMode.home ||
|
||||
final bool changed = _activeModuleId != null ||
|
||||
_dirty ||
|
||||
_filePath != null ||
|
||||
_archFilePath != null;
|
||||
_appMode = AppMode.home;
|
||||
_activeModuleId = null;
|
||||
_dirty = false;
|
||||
_filePath = null;
|
||||
_archFilePath = null;
|
||||
@@ -1954,19 +1956,29 @@ class AppController extends ChangeNotifier {
|
||||
///
|
||||
/// 参数 [keepAngle]:为 true 时保持各动作角度不变;为 false 时按
|
||||
/// `旧时长 / 新时长` 缩放所有动作的起始角与持续角,从而保持其时间不变。
|
||||
/// 依赖偏移始终按时间不变换算(界面以时间为主,角度仅内部存储)。
|
||||
/// 副作用:通过 [_mutate] 记录历史并重算关键路径。
|
||||
void setCycleDuration(double ms, {bool keepAngle = true}) {
|
||||
// 计算角度缩放比例:keepAngle 时保持 1;否则按旧/新时长比例缩放。
|
||||
// 动作角度按策略缩放;依赖偏移始终按“时间不变”换算(界面以时间为主)。
|
||||
final double oldMs = _project.cycle.durationMs;
|
||||
double angleScale = 1;
|
||||
if (!keepAngle && _project.cycle.durationMs > 0) {
|
||||
angleScale = _project.cycle.durationMs / ms;
|
||||
if (!keepAngle && oldMs > 0) {
|
||||
angleScale = oldMs / ms;
|
||||
}
|
||||
final double depScale = oldMs > 0 && ms > 0 ? oldMs / ms : 1;
|
||||
List<Action> actions = _project.actions;
|
||||
if (angleScale != 1) {
|
||||
if (angleScale != 1 || depScale != 1) {
|
||||
actions = actions
|
||||
.map((Action a) => a.copyWith(
|
||||
startAngle: a.startAngle * angleScale,
|
||||
durationAngle: a.durationAngle * angleScale,
|
||||
startAngle: angleScale == 1 ? a.startAngle : a.startAngle * angleScale,
|
||||
durationAngle:
|
||||
angleScale == 1 ? a.durationAngle : a.durationAngle * angleScale,
|
||||
deps: depScale == 1
|
||||
? a.deps
|
||||
: a.deps
|
||||
.map((Dependency d) =>
|
||||
d.copyWith(offsetAngle: d.offsetAngle * depScale))
|
||||
.toList(),
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
@@ -2262,6 +2274,45 @@ class AppController extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
/// 修改一条已有依赖(保留手动拖拽的走线偏移)。
|
||||
///
|
||||
/// [oldFromId] 为原前置动作;[fromId] 为修改后的前置动作(可保持不变);
|
||||
/// [type] / [offset] 为新的依赖类型与偏移角。若目标动作已存在来自
|
||||
/// [fromId] 的另一条依赖,则合并为本条,避免重复。
|
||||
void updateDependency(
|
||||
String oldFromId,
|
||||
String toId, {
|
||||
required String fromId,
|
||||
required DepType type,
|
||||
required double offset,
|
||||
}) {
|
||||
if (fromId == toId) return;
|
||||
if (_project.actionById(fromId) == null) return;
|
||||
final Action? to = _project.actionById(toId);
|
||||
if (to == null) return;
|
||||
final int index = to.deps.indexWhere((Dependency d) => d.fromId == oldFromId);
|
||||
if (index < 0) return;
|
||||
final Dependency old = to.deps[index];
|
||||
final List<Dependency> deps = <Dependency>[
|
||||
for (int i = 0; i < to.deps.length; i++)
|
||||
if (i != index && to.deps[i].fromId != fromId) to.deps[i],
|
||||
];
|
||||
deps.insert(
|
||||
index > deps.length ? deps.length : index,
|
||||
old.copyWith(
|
||||
fromId: fromId,
|
||||
toId: toId,
|
||||
type: type,
|
||||
offsetAngle: offset,
|
||||
),
|
||||
);
|
||||
updateAction(
|
||||
toId,
|
||||
(Action x) => x.copyWith(deps: deps),
|
||||
status: '已修改依赖 $fromId→$toId',
|
||||
);
|
||||
}
|
||||
|
||||
/// 移除 [toId] 上来自 [fromId] 的依赖。
|
||||
void removeDependency(String fromId, String toId) {
|
||||
updateAction(
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/// 并把它们接入 Flutter 的主题扩展机制,供界面、画布渲染与 SVG 导出共用。
|
||||
///
|
||||
/// 架构位置:
|
||||
/// - 渲染层(`lib/render/`)与导出层(`lib/export/`)都通过 [Tokens] 读取颜色,
|
||||
/// - 各模块渲染层(`lib/modules/*/render|domain`)与共享导出层(`lib/export/`)都通过 [Tokens] 读取颜色,
|
||||
/// 从而保证画布绘制、SVG 导出与 Material 界面三者配色完全一致。
|
||||
/// - 深色与浅色两套令牌分别以 [Tokens.dark]、[Tokens.light] 常量提供,
|
||||
/// 由 [Tokens.of] 按 [Brightness] 选择。
|
||||
|
||||
+144
-2206
File diff suppressed because it is too large
Load Diff
+24
-21
@@ -1,4 +1,4 @@
|
||||
/// 左上角品牌按钮 +「EDC易得」设计合集菜单。
|
||||
/// 左上角品牌按钮 +「PDS流程设计套件」品牌菜单。
|
||||
///
|
||||
/// 点开左上角 logo:菜单从 logo **下方**下拉展开(不遮挡 logo)。
|
||||
/// 菜单由模块注册表驱动:首页入口 + 已开放模块(可进入/新建)+
|
||||
@@ -11,11 +11,10 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../model/models.dart';
|
||||
import '../modules/module_registry.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../version.dart';
|
||||
import 'package:sequence_diagram/modules/registry.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/version.dart';
|
||||
import 'app_logo.dart';
|
||||
|
||||
/// 品牌按钮:logo + 当前模块名,点击在下方弹出合集菜单。
|
||||
@@ -41,10 +40,10 @@ class BrandMenuButton extends StatelessWidget {
|
||||
/// 紧凑布局(隐藏副标题)。
|
||||
final bool compact;
|
||||
|
||||
/// 当前模块名(首页显示「设计合集」)。
|
||||
/// 当前模块名(首页显示「流程设计套件」)。
|
||||
String get _label {
|
||||
final EdcModule? m = moduleOf(controller.appMode);
|
||||
return m == null ? '设计合集' : '${m.name}设计';
|
||||
final EdcModule? m = moduleById(controller.activeModuleId);
|
||||
return m == null ? '流程设计套件' : '${m.name}设计';
|
||||
}
|
||||
|
||||
/// 构建按钮。
|
||||
@@ -56,7 +55,7 @@ class BrandMenuButton extends StatelessWidget {
|
||||
final Tokens t = context.tok;
|
||||
final BorderRadius radius = BorderRadius.circular(10);
|
||||
return Tooltip(
|
||||
message: 'EDC易得:设计合集',
|
||||
message: 'PDS流程设计套件',
|
||||
child: Material(
|
||||
color: t.panel,
|
||||
borderRadius: radius,
|
||||
@@ -94,7 +93,7 @@ class BrandMenuButton extends StatelessWidget {
|
||||
),
|
||||
if (!compact)
|
||||
Text(
|
||||
'Easy Design Collection',
|
||||
'Process Design Suite',
|
||||
style: TextStyle(
|
||||
color: t.dim,
|
||||
fontSize: 9.5 * scale,
|
||||
@@ -211,8 +210,8 @@ class BrandMenuButton extends StatelessWidget {
|
||||
/// 菜单面板(品牌头部 + 首页 + 模块注册表 + 未开放模块 + 软件设置)。
|
||||
Widget _panel(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
final bool atHome = controller.appMode == AppMode.home;
|
||||
final String? curId = moduleOf(controller.appMode)?.id;
|
||||
final bool atHome = controller.isHome;
|
||||
final String? curId = moduleById(controller.activeModuleId)?.id;
|
||||
final double maxH = math.max(
|
||||
180,
|
||||
MediaQuery.sizeOf(context).height - 120,
|
||||
@@ -238,13 +237,17 @@ class BrandMenuButton extends StatelessWidget {
|
||||
padding: const EdgeInsets.fromLTRB(12, 6, 12, 8),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Text('EDC易得',
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
)),
|
||||
const Spacer(),
|
||||
Expanded(
|
||||
child: Text('PDS流程设计套件',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
)),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text('v$kAppVersion',
|
||||
style: TextStyle(color: t.dim, fontSize: 10)),
|
||||
],
|
||||
@@ -257,7 +260,7 @@ class BrandMenuButton extends StatelessWidget {
|
||||
const SizedBox(height: 6),
|
||||
Divider(height: 1, thickness: 1, color: t.line),
|
||||
const SizedBox(height: 4),
|
||||
// 已开放模块(可通过「设计合集」进入并新建文档)。
|
||||
// 已开放模块(可通过「品牌菜单」进入并新建文档)。
|
||||
for (final EdcModule m in kModules)
|
||||
if (m.available) _item(context, m, current: curId == m.id),
|
||||
const SizedBox(height: 6),
|
||||
|
||||
+83
-31
@@ -11,16 +11,16 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart' hide Action;
|
||||
|
||||
import '../license/license_service.dart';
|
||||
import '../model/models.dart';
|
||||
import '../model/units.dart';
|
||||
import '../modules/module_registry.dart';
|
||||
import '../persistence/android_docs.dart';
|
||||
import '../persistence/storage.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../update/update_service.dart';
|
||||
import '../version.dart';
|
||||
import 'package:sequence_diagram/license/license_service.dart';
|
||||
import 'package:sequence_diagram/model/models.dart';
|
||||
import 'package:sequence_diagram/model/units.dart';
|
||||
import 'package:sequence_diagram/modules/registry.dart';
|
||||
import 'package:sequence_diagram/persistence/android_docs.dart';
|
||||
import 'package:sequence_diagram/persistence/storage.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/update/update_service.dart';
|
||||
import 'package:sequence_diagram/version.dart';
|
||||
import 'app_logo.dart';
|
||||
import 'update_dialog.dart';
|
||||
|
||||
@@ -970,38 +970,70 @@ class _ActionEditorDialogState extends State<ActionEditorDialog> {
|
||||
|
||||
// ===================== 依赖编辑对话框 =====================
|
||||
|
||||
/// 依赖编辑对话框:为指定动作添加一条前置依赖。
|
||||
/// 依赖编辑对话框:为指定动作添加或修改一条前置依赖。
|
||||
class DependencyEditorDialog extends StatefulWidget {
|
||||
const DependencyEditorDialog({super.key, required this.controller, required this.action});
|
||||
const DependencyEditorDialog({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.action,
|
||||
this.initial,
|
||||
});
|
||||
|
||||
/// 全局应用控制器。
|
||||
final AppController controller;
|
||||
/// 目标动作(依赖的“后置”端)。
|
||||
final Action action;
|
||||
/// 要编辑的已有依赖;为 null 时是新增模式。
|
||||
final Dependency? initial;
|
||||
|
||||
/// 创建依赖编辑对话框对应的状态对象。
|
||||
@override
|
||||
State<DependencyEditorDialog> createState() => _DependencyEditorDialogState();
|
||||
}
|
||||
|
||||
/// 依赖编辑对话框状态:维护前置动作、依赖类型与偏移角。
|
||||
/// 依赖编辑对话框状态:维护前置动作、依赖类型与偏移时间。
|
||||
class _DependencyEditorDialogState extends State<DependencyEditorDialog> {
|
||||
/// 选择的前置动作 id。
|
||||
String? _from;
|
||||
/// 依赖类型,默认 FS(完成-启动)。
|
||||
DepType _type = DepType.fs;
|
||||
/// 偏移角输入控制器。
|
||||
final TextEditingController _offset = TextEditingController(text: '0');
|
||||
/// 偏移时间输入控制器(按当前时间单位输入,内部换算为角度)。
|
||||
late final TextEditingController _offset;
|
||||
|
||||
/// 渲染依赖表单:前置动作、依赖类型与偏移角。
|
||||
bool get _editing => widget.initial != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final Dependency? d = widget.initial;
|
||||
_from = d?.fromId;
|
||||
_type = d?.type ?? DepType.fs;
|
||||
final UnitSettings u = widget.controller.project.units;
|
||||
final double cycleMs = widget.controller.project.cycle.durationMs;
|
||||
final double offsetMs = cycleMs <= 0 ? 0 : (d?.offsetAngle ?? 0) / 360 * cycleMs;
|
||||
_offset = TextEditingController(
|
||||
text: offsetMs == 0 ? '0' : timeValue(offsetMs, u.timeUnit).toStringAsFixed(3),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_offset.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 渲染依赖表单:前置动作、依赖类型与偏移时间。
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Tokens t = context.tok;
|
||||
final UnitSettings u = widget.controller.project.units;
|
||||
final List<Action> others =
|
||||
widget.controller.project.actions.where((Action a) => a.id != widget.action.id).toList();
|
||||
return AlertDialog(
|
||||
backgroundColor: t.dialog,
|
||||
title: Text('为 ${widget.action.id} 添加前置依赖'),
|
||||
title: Text(_editing
|
||||
? '编辑依赖 ${widget.initial!.fromId} → ${widget.action.id}'
|
||||
: '为 ${widget.action.id} 添加前置依赖'),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
child: Column(
|
||||
@@ -1030,8 +1062,11 @@ class _DependencyEditorDialogState extends State<DependencyEditorDialog> {
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _offset,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(labelText: '偏移角 offset (°)'),
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: InputDecoration(
|
||||
labelText: '偏移时间 offset (${timeUnitLabel(u.timeUnit)})',
|
||||
helperText: '以时间为主:可直接输入 120ms / 0.5s / 1min;内部自动换算',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1042,15 +1077,32 @@ class _DependencyEditorDialogState extends State<DependencyEditorDialog> {
|
||||
onPressed: () {
|
||||
// 未选择前置动作时不提交。
|
||||
if (_from == null) return;
|
||||
widget.controller.addDependency(
|
||||
_from!,
|
||||
widget.action.id,
|
||||
_type,
|
||||
double.tryParse(_offset.text) ?? 0,
|
||||
);
|
||||
final UnitSettings unit = widget.controller.project.units;
|
||||
final double cycleMs = widget.controller.project.cycle.durationMs;
|
||||
final double? offsetMs = parseDuration(_offset.text, unit);
|
||||
final double offset = (offsetMs == null || cycleMs <= 0)
|
||||
? 0
|
||||
: offsetMs / cycleMs * 360;
|
||||
final Dependency? old = widget.initial;
|
||||
if (old == null) {
|
||||
widget.controller.addDependency(
|
||||
_from!,
|
||||
widget.action.id,
|
||||
_type,
|
||||
offset,
|
||||
);
|
||||
} else {
|
||||
widget.controller.updateDependency(
|
||||
old.fromId,
|
||||
widget.action.id,
|
||||
fromId: _from!,
|
||||
type: _type,
|
||||
offset: offset,
|
||||
);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('添加'),
|
||||
child: Text(_editing ? '保存' : '添加'),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -2049,7 +2101,7 @@ class _StationRowState extends State<_StationRow> {
|
||||
/// 双视图说明以及单位与导出等信息。
|
||||
/// 软件设置:集中设置入口(外观 / 文档默认 / 架构图网格 / 更新)。
|
||||
///
|
||||
/// 从左上角「EDC易得」菜单底部的「软件设置」打开;文档级的完整设置
|
||||
/// 从左上角「PDS流程设计套件」菜单底部的「软件设置」打开;文档级的完整设置
|
||||
/// (单位 / 循环 / 相位等)仍在「文档设置」(F2 / 左侧栏)里。
|
||||
class SoftwareSettingsDialog extends StatefulWidget {
|
||||
/// 构造软件设置对话框。
|
||||
@@ -2621,7 +2673,7 @@ class _HelpDialogState extends State<HelpDialog> {
|
||||
<String>['我要调相位 / 时长', '拖动动作块平移相位;拖条形右端改持续角;圆周视图拖弧两端改起止角;右侧滑杆可精调。'],
|
||||
<String>['泳道加宽(并列动作)', '双击条形视图左侧泳道编号(或点左侧栏「N 槽」徽标)→ 选 1–5 槽;拖拽动作可同时换道 + 换槽位。'],
|
||||
<String>['空泳道的保留 / 移除', 'F2 文档设置 →「泳道」→ 保留空泳道(默认开):动作全部移走的泳道保留,序号不变;关闭则自动移除。'],
|
||||
<String>['我要加前置依赖(输入)', '右侧「前置依赖 · 输入」→「添加前置依赖」;或右键动作 →「添加依赖」。FS 绿色实线=完成后启动;SS 琥珀虚线=可提前启动(带 +n°)。'],
|
||||
<String>['我要加前置依赖(输入)', '右侧「前置依赖 · 输入」→「添加前置依赖」;或右键动作 →「添加依赖」。FS 绿色实线=完成后启动;SS 琥珀虚线=可提前启动(带偏移时间,如 +0.33s)。'],
|
||||
<String>['连线重叠怎么办', '点选连线后拖动可沿法线方向平移整条线(圆周沿半径方向);双击连线或右键「复位走线偏移」恢复;同一组连线会自动错开。'],
|
||||
<String>['我要编辑相位分区', '左侧「文档设置」→「编辑相位分区」;增删分区、改名称与起止角;可重叠、可留空、>360° 表示跨圈。'],
|
||||
]),
|
||||
@@ -2743,7 +2795,7 @@ class _HelpDialogState extends State<HelpDialog> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text('EDC易得 · Easy Design Collection',
|
||||
Text('PDS流程设计套件 · Process Design Suite',
|
||||
style: TextStyle(color: t.text, fontSize: 15, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 4),
|
||||
Text('V$kAppVersion(${android ? '安卓版' : 'Windows 版'})',
|
||||
@@ -2763,8 +2815,8 @@ class _HelpDialogState extends State<HelpDialog> {
|
||||
if (!android)
|
||||
// 注意:绝不能展示「期望授权串」——它等同于 .lic 内容,公开即可被绕过授权。
|
||||
row('本机 MAC', info.mac ?? '读取失败'),
|
||||
row('版权声明', 'Copyright © 2026 EDC(Easy Design Collection)呆头鹅。保留所有权利。'),
|
||||
row('产品简介', '设计合集(Easy Design Collection):时序图设计面向 PLC 流程节拍 / '
|
||||
row('版权声明', 'Copyright © 2026 PDS流程设计套件(Process Design Suite)呆头鹅。保留所有权利。'),
|
||||
row('产品简介', '流程设计套件(Process Design Suite):时序图设计面向 PLC 流程节拍 / '
|
||||
'相位角设计(条形 / 圆周 / 流程图三视图、FS / SS 依赖与关键路径、泳道加宽);'
|
||||
'架构图设计支持手绘识别标准图形、正交连线与标签;支持导出 SVG / PNG / drawio。'),
|
||||
const SizedBox(height: 6),
|
||||
|
||||
@@ -6,11 +6,11 @@ library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../modules/module_registry.dart';
|
||||
import '../persistence/recent_store.dart';
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../version.dart';
|
||||
import 'package:sequence_diagram/modules/registry.dart';
|
||||
import 'package:sequence_diagram/persistence/recent_store.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/version.dart';
|
||||
import 'app_logo.dart';
|
||||
import 'update_icon.dart';
|
||||
|
||||
@@ -195,7 +195,7 @@ class _HomeViewState extends State<HomeView> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'EDC易得',
|
||||
'PDS流程设计套件',
|
||||
style: TextStyle(
|
||||
color: t.text,
|
||||
fontSize: 24,
|
||||
@@ -204,7 +204,7 @@ class _HomeViewState extends State<HomeView> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'工程总体设计合集(Easy Design Collection) v$kAppVersion',
|
||||
'Process Design Suite v$kAppVersion',
|
||||
style: TextStyle(color: t.dim, fontSize: 11.5),
|
||||
),
|
||||
],
|
||||
|
||||
+35
-12
@@ -12,11 +12,11 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../state/app_controller.dart';
|
||||
import '../theme/tokens.dart';
|
||||
import '../update/keep_awake.dart';
|
||||
import '../update/update_service.dart';
|
||||
import '../version.dart';
|
||||
import 'package:sequence_diagram/state/app_controller.dart';
|
||||
import 'package:sequence_diagram/theme/tokens.dart';
|
||||
import 'package:sequence_diagram/update/keep_awake.dart';
|
||||
import 'package:sequence_diagram/update/update_service.dart';
|
||||
import 'package:sequence_diagram/version.dart';
|
||||
import 'dialogs.dart';
|
||||
import 'update_icon.dart';
|
||||
|
||||
@@ -124,31 +124,54 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
||||
if (r.exitCode != 0) throw Exception('解压失败:${r.stderr}');
|
||||
|
||||
// 兼容两种打包方式:zip 根目录即程序文件,或多包一层 dist/。
|
||||
String srcDir = extractDir;
|
||||
if (!File('$extractDir\\EasyDesignCollection.exe').existsSync()) {
|
||||
if (File('$extractDir\\dist\\EasyDesignCollection.exe').existsSync()) {
|
||||
srcDir = '$extractDir\\dist';
|
||||
} else {
|
||||
throw Exception('更新包内容不完整(未找到 EasyDesignCollection.exe)');
|
||||
// 同时识别新版 ProcessDesignSuite.exe 与旧版 EasyDesignCollection.exe。
|
||||
const List<String> exeNames = <String>[
|
||||
'ProcessDesignSuite.exe',
|
||||
'EasyDesignCollection.exe',
|
||||
];
|
||||
String? srcDir;
|
||||
String? exeName;
|
||||
for (final String base in <String>[extractDir, '$extractDir\\dist']) {
|
||||
for (final String name in exeNames) {
|
||||
if (File('$base\\$name').existsSync()) {
|
||||
srcDir = base;
|
||||
exeName = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (srcDir != null) break;
|
||||
}
|
||||
if (srcDir == null || exeName == null) {
|
||||
throw Exception('更新包内容不完整(未找到 ProcessDesignSuite.exe)');
|
||||
}
|
||||
|
||||
if (mounted) setState(() => _status = '正在准备覆盖更新…');
|
||||
final String appDir = File(Platform.resolvedExecutable).parent.path;
|
||||
final String batPath = '${tmp.path}\\apply_update.bat';
|
||||
// 升级过渡期可能残留旧版 exe:换成新名字时顺手清理旧文件。
|
||||
final String cleanup = exeName == 'ProcessDesignSuite.exe'
|
||||
? 'if exist "%~2\\EasyDesignCollection.exe" del /q "%~2\\EasyDesignCollection.exe"\r\n'
|
||||
'if exist "%~2\\EasyDesignCollection.exe.manifest" del /q "%~2\\EasyDesignCollection.exe.manifest"\r\n'
|
||||
: '';
|
||||
// 生成替换脚本:等待本程序退出 → 原地覆盖 → 重新启动。
|
||||
// 内容保持纯 ASCII,源/目标路径通过参数传入(cmd 以 UTF-16 接收参数,
|
||||
// 中文安装路径也能正确处理);脚本文件本身不包含路径,避免编码问题。
|
||||
File(batPath).writeAsStringSync(
|
||||
'@echo off\r\n'
|
||||
':wait\r\n'
|
||||
'tasklist /fi "IMAGENAME eq ProcessDesignSuite.exe" | find /i "ProcessDesignSuite.exe" >nul\r\n'
|
||||
'if not errorlevel 1 (\r\n'
|
||||
' ping -n 1 -w 600 127.0.0.1 >nul\r\n'
|
||||
' goto wait\r\n'
|
||||
')\r\n'
|
||||
'tasklist /fi "IMAGENAME eq EasyDesignCollection.exe" | find /i "EasyDesignCollection.exe" >nul\r\n'
|
||||
'if not errorlevel 1 (\r\n'
|
||||
' ping -n 1 -w 600 127.0.0.1 >nul\r\n'
|
||||
' goto wait\r\n'
|
||||
')\r\n'
|
||||
'xcopy /e /i /y /q "%~1\\*" "%~2\\"\r\n'
|
||||
'start "" "%~2\\EasyDesignCollection.exe"\r\n'
|
||||
'$cleanup'
|
||||
'start "" "%~2\\$exeName"\r\n'
|
||||
'del "%~f0"\r\n',
|
||||
flush: true,
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ library;
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import '../version.dart';
|
||||
import 'package:sequence_diagram/version.dart';
|
||||
|
||||
/// Gitea 服务器与仓库定位。
|
||||
class UpdateServer {
|
||||
@@ -22,8 +22,8 @@ class UpdateServer {
|
||||
static const String host = 'http://124.220.63.9:30000';
|
||||
/// 仓库拥有者。
|
||||
static const String owner = 'admin';
|
||||
/// 仓库名称(2026-10 由 Sequence-Diagram 改名;
|
||||
/// 旧名在服务器保留 301 重定向,老客户端查更新不受影响)。
|
||||
/// 仓库名称(服务器仓库名保持不变;客户端更新地址依赖它,
|
||||
/// 软件品牌更名不影响该常量)。
|
||||
static const String repo = 'EasyDesignCollection';
|
||||
|
||||
/// 版本检查接口(最新正式发布)。
|
||||
@@ -48,7 +48,7 @@ class UpdateInfo {
|
||||
/// 更新说明(Markdown 文本)。
|
||||
final String notes;
|
||||
|
||||
/// 安装包文件名(如 `EasyDesignCollection_android_v1.3.10_release.apk`)。
|
||||
/// 安装包文件名(如 `ProcessDesignSuite_android_v1.3.13_release.apk`)。
|
||||
final String assetName;
|
||||
|
||||
/// 安装包下载地址。
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
///
|
||||
/// 应用内更新检查用它判断服务器发布的版本是否更新;
|
||||
/// **每次发版必须与 pubspec 同步更新**(见 BUILD-NOTES 的发布流程)。
|
||||
const String kAppVersion = '1.3.12';
|
||||
const String kAppVersion = '1.3.13';
|
||||
|
||||
/// 是否要求授权(License)才能导出。
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user