diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 6c8584c..f1bc253 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -30,7 +30,7 @@ android { // 由 `cc.sincos.sequence_diagram` 切换为 `cc.sincos.edc`(v1.3.10 起)。 // 原因:部分安卓桌面会长期保留旧包身份(cc.sincos.sequence_diagram)的 // 图标名缓存,导致应用更名后桌面仍显示旧名「时序图设计」。换新身份安装 = - // 系统当作全新应用处理,桌面必然按新包内的名称(EDC|易得设计)生成新图标。 + // 系统当作全新应用处理,桌面必然按新包内的名称(EDC|易得)生成新图标。 // 注意:namespace 与 Kotlin 包名保持不变(仅 applicationId 变化),因此 // AndroidManifest 中组件类名需写全限定名(见 android:name)。 applicationId = "cc.sincos.edc" diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 9257da8..4c00506 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ { + val on = call.argument("on") ?: true + runOnUiThread { + if (on) { + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } else { + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } + } + result.success(true) + } else -> result.notImplemented() } } diff --git a/demo/arch-done-dark.png b/demo/arch-done-dark.png index 087c37b..d02dadf 100644 Binary files a/demo/arch-done-dark.png and b/demo/arch-done-dark.png differ diff --git a/demo/arch-done-light.png b/demo/arch-done-light.png index 50d59b2..6bbf8d7 100644 Binary files a/demo/arch-done-light.png and b/demo/arch-done-light.png differ diff --git a/demo/arch-menu-light.png b/demo/arch-menu-light.png index a5f4219..2015f0a 100644 Binary files a/demo/arch-menu-light.png and b/demo/arch-menu-light.png differ diff --git a/demo/arch-symbols-light.png b/demo/arch-symbols-light.png index 69ea0f7..7e5899f 100644 Binary files a/demo/arch-symbols-light.png and b/demo/arch-symbols-light.png differ diff --git a/demo/home-light.png b/demo/home-light.png index 9b8779b..80c2f96 100644 Binary files a/demo/home-light.png and b/demo/home-light.png differ diff --git a/docs/ARCH-UPGRADE.md b/docs/ARCH-UPGRADE.md index 326298b..36c2090 100644 --- a/docs/ARCH-UPGRADE.md +++ b/docs/ARCH-UPGRADE.md @@ -1,4 +1,4 @@ -# EDC|易得设计 架构升级评估(1.3.5 大版本) +# EDC|易得 架构升级评估(1.3.5 大版本) > 状态:P0 已实施(空白启动首页 + 模块注册表 + 文件路由 + 测试适配,全量 106 项通过); > P1 部分完成(release/ 目录已按方案 B 重组并验证,运行时路径迁移与素材库目录待做)。 @@ -31,7 +31,7 @@ - `AppMode` 增加 `home`:**启动即进入首页**(无文档、无画布、无侧栏)。 - 首页内容(COMSOL Home 风格,单页即可): - 1. 顶部:品牌 EDC|易得设计 + 版本号; + 1. 顶部:品牌 EDC|易得 + 版本号; 2. 中央「新建文档」网格:6 个模块卡片(图标 + 名称 + 一句话); 未开放的模块灰显标注「未开放」(符合既定规则,无"规划中"字样); 3. 「打开文档…」按钮(按类型路由到对应模块的打开流程); diff --git a/docs/HELP.md b/docs/HELP.md index d884a06..b00aab6 100644 --- a/docs/HELP.md +++ b/docs/HELP.md @@ -1,6 +1,6 @@ -# EDC|易得设计 · 帮助手册(1.3.5) +# EDC|易得 · 帮助手册(1.3.5) -> 本手册对应 1.3.5 大版本(软件已更名 EDC|易得设计,仓库 EasyDesignCollection)。 +> 本手册对应 1.3.5 大版本(软件已更名 EDC|易得,仓库 EasyDesignCollection)。 > 本次更新变化较大,**新功能可能仍存在较多 bug 与问题**,欢迎反馈: > 开发者邮箱 liuyu65@126.com · 微信 online-goose。 @@ -63,10 +63,14 @@ ### 2.5 连线 - 画路径即出连线,**一律正交(横平竖直),不会出现斜线**。 -- 端点自动吸附图形边框(松手位置 / 按下位置命中)。 -- 选中连线后: - - 拖拽路径上的**角点**可调整走线位置(拖到哪,路就拐到哪,仍保持正交); - - 端点可拖到**别的图形重新吸附**,拖到空白则**脱离**为自由端点。 +- 两端**垂直出入图元边框**(沿法向):箭头始终垂直指向图元,不会贴着边乱指; + 同一图元同一条边上的多条连线**自动错开**(避让,不再重叠)。 +- 选中连线后(平板 / 手指已加大命中范围): + - 拖**端点**可换吸附目标、拖到别的图形重新吸附或脱离为自由端点(实时预览); + - 拖**折点**自由调整走线(自动物化台阶); + - 拖**线段**整体平移该段(直线会就地生成台阶); + - 拖动时有**磁力吸附**(对齐图元边 / 中心、其它连线、图纸中心)并显示 + **虚线导引**;鼠标悬停连线会显示抓取光标。 ### 2.6 文字 @@ -172,7 +176,7 @@ **Q:升级后桌面出现两个图标 / 名称还是旧的?** 1.3.10 起应用换了新身份(`cc.sincos.edc`),系统会当作**全新应用**安装: -桌面新图标即 `EDC|易得设计`;旧图标(时序图设计)长按卸载即可。 +桌面新图标即 `EDC|易得`;旧图标(时序图设计)长按卸载即可。 项目文件保存在公共文档目录(`Documents/SequenceDiagram`),不受影响。 **Q:1.3.10 之后怎么更新?** diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index e0e3141..5d6fd4f 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -39,9 +39,9 @@ ## 三、v1.3.5 更名与架构图(开发中) -- **软件更名**:`Easy Design Collection`(缩写 **EDC**),中文名 **EDC|易得设计** +- **软件更名**:`Easy Design Collection`(缩写 **EDC**),中文名 **EDC|易得** (窗口标题、Logo 菜单、关于页已替换;安装包命名与 README 随发布更新)。 -- **合集菜单**:左上角「EDC|易得设计」下拉**一次列全所有模块**(时序图 / 架构图已可用, +- **合集菜单**:左上角「EDC|易得」下拉**一次列全所有模块**(时序图 / 架构图已可用, 其余以「规划中」列出、按序点亮);后续模块只需在菜单中逐个开放,不再调整导航结构。 菜单在 logo 下方展开、不遮挡 logo,内容超高时内部滚动。 - **架构图设计(本轮已交付)**: diff --git a/lib/arch/arch_export.dart b/lib/arch/arch_export.dart index b23f5f3..ffcc849 100644 --- a/lib/arch/arch_export.dart +++ b/lib/arch/arch_export.dart @@ -40,7 +40,7 @@ Future 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, 'EDC|易得 · Easy Design Collection · 手绘识别架构图', const Offset(48, 88), color: et.sub, size: 16, weight: FontWeight.w400); // 内容适配(白底令牌 + 关闭网格点阵)。 @@ -56,7 +56,7 @@ Future renderArchPng({ _text( canvas, - 'EDC|易得设计 · 架构图设计 · $projectName · 元件 ${doc.shapes.length} · 连线 ' + 'EDC|易得 · 架构图设计 · $projectName · 元件 ${doc.shapes.length} · 连线 ' '${doc.connectors.length} · 墨迹 ${doc.strokes.length}', Offset(48, h - 38), color: et.sub, diff --git a/lib/arch/arch_models.dart b/lib/arch/arch_models.dart index 0c23b5b..a5b8dbc 100644 --- a/lib/arch/arch_models.dart +++ b/lib/arch/arch_models.dart @@ -483,9 +483,12 @@ Offset archNearestBorderPoint(ArchShape s, Offset p) { /// 计算连线几何:**一律正交走线**(横平竖直,无斜线)。 /// -/// - 有折点([ArchConnector.mids],手绘轨迹 / 拖拽过的角点)时:按折点走正交台阶; -/// - 无折点时:按两图形中心主方向自动生成单拐角正交折线(带圆角); -/// - 端点吸附图形时从相应方向边框射出。 +/// - 端点吸附图形时:贴边点取「保存的画线侧」边框点(多条连线贴在同一条边 +/// 时自动分配槽位错开);出入两端沿该边**法向**短桩——箭头始终垂直射入 +/// 图元边,不会贴着边乱指; +/// - 有折点([ArchConnector.mids],手绘轨迹 / 拖拽过的角点)时:按折点走 +/// 正交台阶,两端同样保证法向出入; +/// - 无折点时:自动生成带法向短桩的正交走线(转弯走台阶)。 ArchConnGeometry archConnectorGeometry( ArchDoc doc, ArchConnector c, { @@ -501,34 +504,48 @@ ArchConnGeometry archConnectorGeometry( final ArchShape? st = resolve(c.toId); final Offset cFrom = sf?.rect.center ?? c.from; final Offset cTo = st?.rect.center ?? c.to; - final (Offset a, Offset b) = - _orthoEnds(sf, st, cFrom, cTo, c.from, c.to); + final (Offset a, Offset b) = _orthoEnds(doc, c, sf, st, cFrom, cTo); - // 有折点:以折点顺序走正交台阶(角点即折点,可直接拖拽编辑)。 + // 端点法向(自由端点无方向约束)。 + final Offset na = + sf == null ? Offset.zero : _connNormal(_connSideOfPoint(sf, a)); + final Offset nb = + st == null ? Offset.zero : _connNormal(_connSideOfPoint(st, b)); + + /// 法向短桩长度(世界单位):保证箭头垂直入边、出口垂直离边。 + const double stub = 14; + final List raw = [a]; if (c.mids.isNotEmpty) { - final List raw = orthoPolyline([a, ...c.mids, b]); - final List clean = []; - for (final Offset p in raw) { - if (clean.isEmpty || (p - clean.last).distance > 0.5) clean.add(p); - } - if (clean.length >= 2) { - return ArchConnGeometry( - clean, - _roundedOrthoPath(clean, 8), - _labelPoint(clean), - ); + if (sf != null) raw.add(a + na * stub); + raw.addAll(c.mids); + if (st != null) raw.add(b + nb * stub); + raw.add(b); + } else { + final Offset? sA = sf == null ? null : a + na * stub; + final Offset? sB = st == null ? null : b + nb * stub; + if (sA != null) raw.add(sA); + final Offset p = sA ?? a; + final Offset q = sB ?? b; + if (sf != null || st != null) { + // 中段:先沿吸附端的主轴走,再拐到另一端(台阶转弯)。 + final Offset main = sf != null ? na : nb; + if (main.dx != 0) { + if ((p.dy - q.dy).abs() > 0.5) raw.add(Offset(q.dx, p.dy)); + } else if ((p.dx - q.dx).abs() > 0.5) { + raw.add(Offset(p.dx, q.dy)); + } + } else if ((p.dx - q.dx).abs() >= (p.dy - q.dy).abs()) { + // 双自由端点:单拐角(先横后竖 / 先竖后横按主方向)。 + raw.add(Offset(q.dx, p.dy)); + } else { + raw.add(Offset(p.dx, q.dy)); } + if (sB != null) raw.add(sB); + raw.add(b); } - // 无折点:自动单拐角(先横后竖 / 先竖后横按两端射出点的主方向决定, - // 端点位置稳定,不随中心方向抖动)。 - final bool horizontalFirst = - (b.dx - a.dx).abs() >= (b.dy - a.dy).abs(); - final List pts = horizontalFirst - ? [a, Offset(b.dx, a.dy), b] - : [a, Offset(a.dx, b.dy), b]; final List clean = []; - for (final Offset p in pts) { + for (final Offset p in orthoPolyline(raw)) { if (clean.isEmpty || (p - clean.last).distance > 0.5) clean.add(p); } return ArchConnGeometry( @@ -538,46 +555,170 @@ ArchConnGeometry archConnectorGeometry( ); } -/// 正交走线的两端射出点。 +/// 连线端点在图元边框上的贴边(正交走线的出入方向)。 +enum _ConnSide { + /// 上边(法向朝上)。 + top, + + /// 下边(法向朝下)。 + bottom, + + /// 左边(法向朝左)。 + left, + + /// 右边(法向朝右)。 + right, +} + +/// 边框点 [p] 所在边(矩形类按最近边判定;椭圆 / 圆按径向主方向判定)。 +_ConnSide _connSideOfPoint(ArchShape s, Offset p) { + final Rect r = s.rect; + if (s.type == ArchShapeType.ellipse || s.type == ArchShapeType.circle) { + final Offset d = p - r.center; + if (d.dx.abs() >= d.dy.abs()) { + return d.dx >= 0 ? _ConnSide.right : _ConnSide.left; + } + return d.dy >= 0 ? _ConnSide.bottom : _ConnSide.top; + } + final double dl = (p.dx - r.left).abs(); + final double dr = (r.right - p.dx).abs(); + final double dt = (p.dy - r.top).abs(); + final double db = (r.bottom - p.dy).abs(); + final double m = math.min(math.min(dl, dr), math.min(dt, db)); + if (m == dl) return _ConnSide.left; + if (m == dr) return _ConnSide.right; + if (m == dt) return _ConnSide.top; + return _ConnSide.bottom; +} + +/// 边的外侧法向(单位向量,正交轴对齐)。 +Offset _connNormal(_ConnSide s) { + switch (s) { + case _ConnSide.top: + return const Offset(0, -1); + case _ConnSide.bottom: + return const Offset(0, 1); + case _ConnSide.left: + return const Offset(-1, 0); + case _ConnSide.right: + return const Offset(1, 0); + } +} + +/// 用户保存的贴边点:优先取「离保存点最近的边框点」(画线 / 拖拽的一侧, +/// 稳定不随中心方向乱跳);保存点接近中心(程序化创建)时按朝向对方中心的 +/// 主轴方向自动取向。 +Offset _naturalAttach(ArchShape s, Offset free, Offset otherCenter) { + if ((free - s.rect.center).distance < 4) { + final Offset d = otherCenter - s.rect.center; + final Offset dir = d.dx.abs() >= d.dy.abs() + ? Offset(d.dx >= 0 ? 1 : -1, 0) + : Offset(0, d.dy >= 0 ? 1 : -1); + return archBorderPoint(s, s.rect.center + dir * 1e5); + } + return archNearestBorderPoint(s, free); +} + +/// 贴边点(含**同边多条连线的自动槽位避让**)。 +/// +/// 同一条边上的多条连线按自然到达顺序均匀错开,避免起点 / 箭头重叠; +/// 椭圆 / 圆收敛到 4 个正交点(保证法向进出)。 +Offset _attachWithSlots( + ArchDoc doc, + ArchConnector c, + ArchShape s, + Offset natural, { + required bool isFrom, +}) { + final _ConnSide side = _connSideOfPoint(s, natural); + final Rect r = s.rect; + if (s.type == ArchShapeType.ellipse || s.type == ArchShapeType.circle) { + switch (side) { + case _ConnSide.top: + return Offset(r.center.dx, r.top); + case _ConnSide.bottom: + return Offset(r.center.dx, r.bottom); + case _ConnSide.left: + return Offset(r.left, r.center.dy); + case _ConnSide.right: + return Offset(r.right, r.center.dy); + } + } + final bool onHorizontalEdge = + side == _ConnSide.top || side == _ConnSide.bottom; + // 收集该图元该边上的全部连线端点(含本连线的两端),按自然位置排序。 + final List<({double key, String order})> mates = + <({double key, String order})>[]; + void considerEndpoint(String? shapeId, Offset free, String? otherId, + Offset otherFree, String order) { + if (shapeId != s.id) return; + final Offset other = doc.shapeById(otherId ?? '')?.rect.center ?? otherFree; + final Offset nat = _naturalAttach(s, free, other); + if (_connSideOfPoint(s, nat) != side) return; + mates.add(( + key: onHorizontalEdge ? other.dx : other.dy, + order: order, + )); + } + + for (final ArchConnector o in doc.connectors) { + considerEndpoint(o.fromId, o.from, o.toId, o.to, '${o.id}#f'); + considerEndpoint(o.toId, o.to, o.fromId, o.from, '${o.id}#t'); + } + if (mates.length <= 1) return natural; + mates.sort((a, b) { + final int k = a.key.compareTo(b.key); + return k != 0 ? k : a.order.compareTo(b.order); + }); + final String selfOrder = '${c.id}#${isFrom ? 'f' : 't'}'; + final int index = mates.indexWhere((m) => m.order == selfOrder); + if (index < 0) return natural; + final double lo = onHorizontalEdge ? r.left : r.top; + final double hi = onHorizontalEdge ? r.right : r.bottom; + final double len = hi - lo; + double pad = math.min(24, len * 0.18); + if (len - 2 * pad < 24) pad = math.max(0, len * 0.1); + final double usable = math.max(1, len - 2 * pad); + final double pos = lo + pad + (index + 0.5) * usable / mates.length; + if (onHorizontalEdge) { + return Offset(pos, side == _ConnSide.top ? r.top : r.bottom); + } + return Offset(side == _ConnSide.left ? r.left : r.right, pos); +} + +/// 正交走线的两端贴边点。 /// /// 稳定优先:端点**朝「保存的端点位置」(用户画线 / 拖拽的一侧)**在边框取点—— /// 不会随两图形中心方向的微小变化而左右乱跳;仅当保存端点接近中心 -/// (程序化创建等)时,退回「朝向对方中心象限」的自动取向。 +/// (程序化创建等)时,退回「朝向对方中心」的自动取向。 +/// 多连线贴在同一条边时自动分配槽位(智能避让);椭圆 / 圆取正交点。 (Offset, Offset) _orthoEnds( + ArchDoc doc, + ArchConnector c, ArchShape? sf, ArchShape? st, Offset cFrom, Offset cTo, - Offset freeFrom, - Offset freeTo, ) { - Offset a; - if (sf == null) { - a = freeFrom; - } else if ((freeFrom - sf.rect.center).distance < 4) { - a = archBorderPoint( + Offset a = c.from; + if (sf != null) { + a = _attachWithSlots( + doc, + c, sf, - Offset( - cTo.dx >= cFrom.dx ? sf.rect.right + 1e5 : sf.rect.left - 1e5, - cTo.dy >= cFrom.dy ? sf.rect.bottom + 1e5 : sf.rect.top - 1e5, - ), + _naturalAttach(sf, c.from, cTo), + isFrom: true, ); - } else { - a = archNearestBorderPoint(sf, freeFrom); } - Offset b; - if (st == null) { - b = freeTo; - } else if ((freeTo - st.rect.center).distance < 4) { - b = archBorderPoint( + Offset b = c.to; + if (st != null) { + b = _attachWithSlots( + doc, + c, st, - Offset( - cFrom.dx >= cTo.dx ? st.rect.right + 1e5 : st.rect.left - 1e5, - cFrom.dy >= cTo.dy ? st.rect.bottom + 1e5 : st.rect.top - 1e5, - ), + _naturalAttach(st, c.to, cFrom), + isFrom: false, ); - } else { - b = archNearestBorderPoint(st, freeTo); } return (a, b); } diff --git a/lib/arch/arch_painter.dart b/lib/arch/arch_painter.dart index 1b8c5df..34456c0 100644 --- a/lib/arch/arch_painter.dart +++ b/lib/arch/arch_painter.dart @@ -430,9 +430,11 @@ class ArchPainter extends CustomPainter { ..color = t.line2, ); // 连线在底层(图形遮住线头,视觉更干净;隐藏图层不绘制)。 + // 拖拽编辑中的连线用预览对象绘制(实时反馈)。 for (final ArchConnector c in doc.connectors) { if (!doc.isLayerVisible(c.layerId)) continue; - _connector(canvas, c); + final ArchConnector? pc = previewConnector; + _connector(canvas, pc != null && pc.id == c.id ? pc : c); } for (final ArchShape s in doc.shapes) { if (!doc.isLayerVisible(s.layerId)) continue; @@ -1204,7 +1206,11 @@ class ArchPainter extends CustomPainter { } continue; } - final ArchConnector? c = doc.connectorById(id); + final ArchConnector? base = doc.connectorById(id); + final ArchConnector? pc = previewConnector; + final ArchConnector? c = (base != null && pc != null && pc.id == base.id) + ? pc + : base; if (c != null) { if (!doc.isLayerVisible(c.layerId)) continue; final ArchConnGeometry g = diff --git a/lib/main.dart b/lib/main.dart index 3a3b18a..9a20f67 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -94,7 +94,7 @@ class _SequenceDiagramAppState extends State { // 标题走模块注册表(首页显示品牌名,不带文件名)。 if (_controller.appMode == AppMode.home) { _windowChannel - .invokeMethod('setTitle', 'EDC|易得设计') + .invokeMethod('setTitle', 'EDC|易得') .catchError((Object _) {}); return; } @@ -177,7 +177,7 @@ class _SequenceDiagramAppState extends State { builder: (BuildContext context, Widget? child) { final Tokens tokens = Tokens.of(_controller.brightness); return MaterialApp( - title: 'EDC|易得设计 · Easy Design Collection', + title: 'EDC|易得 · Easy Design Collection', debugShowCheckedModeBanner: false, theme: buildTheme(tokens), // 固定文本缩放;系统栏图标随主题亮度自动切换(透明系统栏, diff --git a/lib/modules/module_registry.dart b/lib/modules/module_registry.dart index 21785c4..8c1859b 100644 --- a/lib/modules/module_registry.dart +++ b/lib/modules/module_registry.dart @@ -145,5 +145,5 @@ EdcModule? moduleOf(AppMode m) { /// AppMode → 窗口标题用模块名(首页用品牌名)。 String appModeLabel(AppMode m) { final EdcModule? mod = moduleOf(m); - return mod == null ? 'EDC|易得设计' : 'EDC|易得设计 · ${mod.name}设计'; + return mod == null ? 'EDC|易得' : 'EDC|易得 · ${mod.name}设计'; } diff --git a/lib/ui/app_shell.dart b/lib/ui/app_shell.dart index a12bc76..4008f29 100644 --- a/lib/ui/app_shell.dart +++ b/lib/ui/app_shell.dart @@ -929,6 +929,8 @@ class _AppShellState extends State { if (!mounted) return; await showDialog( context: context, + // 点对话框外灰色区域不关闭(下载中防误触退出)。 + barrierDismissible: false, builder: (_) => UpdateDialog(controller: c, info: info!), ); } diff --git a/lib/ui/arch_view.dart b/lib/ui/arch_view.dart index 0dfa8ce..79e24db 100644 --- a/lib/ui/arch_view.dart +++ b/lib/ui/arch_view.dart @@ -26,6 +26,9 @@ import '../state/app_controller.dart'; import '../theme/tokens.dart'; import 'dialogs.dart'; +/// 连线拖拽吸附结果:吸附后的坐标 + 对齐导引(null = 该轴无对齐)。 +typedef ConnSnap = ({double x, double y, double? gx, double? gy}); + /// 架构图画布组件。 class ArchView extends StatefulWidget { /// 构造画布;[controller] 为全局应用控制器。 @@ -56,15 +59,29 @@ class _ArchViewState extends State // ---- 连线草稿(按住左键画路径) ---- String? _connFromId; - // ---- 连线折点拖动 ---- + // ---- 连线拖拽编辑(端点 / 折点 / 线段三种模式) ---- ArchConnector? _connVertexOrigin; - int _connVertexIndex = 0; - List _connVertexPts = []; ArchConnector? _connVertexUpdated; - /// 端点拖拽中的候选吸附目标(松手时生效;null = 脱离为自由端点)。 + /// 拖动模式:endpoint(端点)/ corner(折点)/ segment(线段)。 + String? _connDragMode; + + /// 端点模式:几何端点序号(0 = 起点,末位 = 终点)。 + int _connVertexIndex = 0; + + /// 折点模式:折点序号([ArchConnector.mids] 下标)。 + int _connMidIndex = 0; + + /// 线段模式:拖动轴('x' / 'y')与初始坐标(同坐标折点一起移动)。 + String? _connSegAxis; + double? _connSegSeed; + + /// 端点拖拽中的候选吸附目标(实时预览;null = 脱离为自由端点)。 String? _connDragTargetId; + /// 鼠标悬停在连线上(显示抓取光标)。 + bool _hoverConn = false; + // ---- 平移 ---- bool _panning = false; Offset _panStartScreen = Offset.zero; @@ -356,8 +373,9 @@ class _ArchViewState extends State ); /// 命中测试:返回 (id, 图形?)。优先图形 → 连线 → 墨迹(后者在上层); - /// 隐藏图层与锁定图层的对象不可选中。 - (String?, ArchShape?) _hitTest(Offset world) { + /// 隐藏图层与锁定图层的对象不可选中。[connTol] > 0 时覆盖连线的命中宽容 + /// (平板 / 手指选中连线时放大)。 + (String?, ArchShape?) _hitTest(Offset world, {double connTol = 0}) { final ArchDoc doc = c.arch; for (int i = doc.shapes.length - 1; i >= 0; i--) { final ArchShape s = doc.shapes[i]; @@ -366,19 +384,11 @@ class _ArchViewState extends State } if (s.hitTest(world)) return (s.id, s); } - final double tol = 8 / c.arch.zoom + 4; - for (int i = doc.connectors.length - 1; i >= 0; i--) { - final ArchConnector cn = doc.connectors[i]; - if (!doc.isLayerVisible(cn.layerId) || doc.isLayerLocked(cn.layerId)) { - continue; - } - final ArchConnGeometry g = archConnectorGeometry(doc, cn); - for (int k = 0; k < g.pts.length - 1; k++) { - if (archDistToSegment(world, g.pts[k], g.pts[k + 1]) <= tol) { - return (cn.id, null); - } - } - } + final ArchConnector? cn = _connAt( + world, + connTol > 0 ? connTol : (8 / c.arch.zoom + 4), + ); + if (cn != null) return (cn.id, null); for (int i = doc.strokes.length - 1; i >= 0; i--) { final ArchStroke s = doc.strokes[i]; if (!doc.isLayerVisible(s.layerId) || doc.isLayerLocked(s.layerId)) { @@ -389,17 +399,199 @@ class _ArchViewState extends State return (null, null); } - /// 命中的图形(宽容 6px,用于手绘箭头端点与连线自动吸附; + /// 命中连线(最上层优先;隐藏 / 锁定图层跳过)。 + ArchConnector? _connAt(Offset world, double tol) { + final ArchDoc doc = c.arch; + for (int i = doc.connectors.length - 1; i >= 0; i--) { + final ArchConnector cn = doc.connectors[i]; + if (!doc.isLayerVisible(cn.layerId) || doc.isLayerLocked(cn.layerId)) { + continue; + } + final ArchConnGeometry g = archConnectorGeometry(doc, cn); + for (int k = 0; k < g.pts.length - 1; k++) { + if (archDistToSegment(world, g.pts[k], g.pts[k + 1]) <= tol) { + return cn; + } + } + } + return null; + } + + /// 命中的图形(宽容 [pad],用于手绘箭头端点与连线自动吸附; /// 锁定图层仍可作为吸附参照,隐藏图层不可)。 - ArchShape? _shapeAt(Offset world) { + ArchShape? _shapeAt(Offset world, {double pad = 6}) { final ArchDoc doc = c.arch; for (int i = doc.shapes.length - 1; i >= 0; i--) { if (!doc.isLayerVisible(doc.shapes[i].layerId)) continue; - if (doc.shapes[i].hitTest(world, pad: 6)) return doc.shapes[i]; + if (doc.shapes[i].hitTest(world, pad: pad)) return doc.shapes[i]; } return null; } + // ---- 连线拖拽辅助(端点 / 折点 / 线段 + 吸附导引) ---- + + /// 开始连线拖拽(端点 / 折点模式)。 + void _beginConnDrag(ArchConnector conn, String mode) { + _connVertexOrigin = conn; + _connVertexUpdated = null; + _connDragMode = mode; + _connDragTargetId = null; + _connSegAxis = null; + _connSegSeed = null; + _guideXs = const []; + _guideYs = const []; + setState(() {}); + } + + /// 开始连线线段拖动:把路径中间台阶物化为折点,整体平移该段。 + void _beginConnSegmentDrag( + ArchConnector conn, + ArchConnGeometry g, + Offset world, + int k, + bool hasA, + bool hasB, + ) { + final List pts = g.pts; + final int last = pts.length - 1; + final Offset d = pts[k + 1] - pts[k]; + final bool segH = d.dx.abs() >= d.dy.abs(); + List mids; + String axis; + double seed; + if (conn.mids.isNotEmpty) { + mids = List.of(conn.mids); + axis = segH ? 'y' : 'x'; + seed = segH ? pts[k].dy : pts[k].dx; + } else { + // 无折点:优先取路径中间的可移动台阶(其两端均为折点)。 + final int lo = hasA ? 2 : 1; + final int hi = hasB ? last - 2 : last - 1; + final List? found = lo < hi ? [pts[lo], pts[lo + 1]] : null; + if (found != null) { + mids = found; + final Offset fd = found[1] - found[0]; + final bool fh = fd.dx.abs() >= fd.dy.abs(); + axis = fh ? 'y' : 'x'; + seed = fh ? found[0].dy : found[0].dx; + } else if (segH) { + // 直线:在抓取处生成竖台阶(之后随手指左右平移)。 + axis = 'x'; + seed = world.dx; + mids = [ + Offset(seed, pts.first.dy), + Offset(seed, pts.last.dy), + ]; + } else { + // 直线:在抓取处生成横台阶(之后随手指上下平移)。 + axis = 'y'; + seed = world.dy; + mids = [ + Offset(pts.first.dx, seed), + Offset(pts.last.dx, seed), + ]; + } + } + _connVertexOrigin = conn.copyWith(mids: mids); + _connVertexUpdated = _connVertexOrigin; + _connDragMode = 'segment'; + _connDragTargetId = null; + _connSegAxis = axis; + _connSegSeed = seed; + _guideXs = const []; + _guideYs = const []; + setState(() {}); + } + + /// 连线拖拽吸附:磁力对齐(图元边 / 中心、其它连线折点、自身折点、 + /// 图纸中心)+ 网格回退;返回导引虚线坐标(虚线由画笔统一绘制)。 + ConnSnap _snapConnCoord( + Offset p, + ArchConnector? self, { + bool onlyX = false, + bool onlyY = false, + }) { + final double tol = 6 / c.arch.zoom; + double bx = p.dx; + double by = p.dy; + double? gx; + double? gy; + if (!onlyY) { + double best = tol + 0.0001; + double? val; + for (final double cx in _alignCandidates(self, x: true)) { + final double d = (cx - p.dx).abs(); + if (d < best) { + best = d; + val = cx; + } + } + if (val != null) { + bx = val; + gx = val; + } + } + if (!onlyX) { + double best = tol + 0.0001; + double? val; + for (final double cy in _alignCandidates(self, x: false)) { + final double d = (cy - p.dy).abs(); + if (d < best) { + best = d; + val = cy; + } + } + if (val != null) { + by = val; + gy = val; + } + } + if (c.arch.gridSnap) { + final Offset s = archSnapPoint(c.arch, Offset(bx, by)); + if (gx == null && !onlyY) bx = s.dx; + if (gy == null && !onlyX) by = s.dy; + } + return (x: bx, y: by, gx: gx, gy: gy); + } + + /// 对齐候补坐标:图元左 / 中 / 右(或上 / 中 / 下)、其它连线折点、 + /// 自身折点、图纸中心。 + Iterable _alignCandidates( + ArchConnector? self, { + required bool x, + }) sync* { + for (final ArchShape s in c.arch.shapes) { + if (!c.arch.isLayerVisible(s.layerId)) continue; + final Rect r = s.rect; + yield x ? r.left : r.top; + yield x ? r.center.dx : r.center.dy; + yield x ? r.right : r.bottom; + } + for (final ArchConnector o in c.arch.connectors) { + if (self != null && o.id == self.id) continue; + final ArchConnGeometry g = archConnectorGeometry(c.arch, o); + for (final Offset q in g.pts) { + yield x ? q.dx : q.dy; + } + } + if (self != null) { + for (final Offset m in self.mids) { + yield x ? m.dx : m.dy; + } + } + yield x ? kArchPageSize.width / 2 : kArchPageSize.height / 2; + } + + /// 鼠标样式:拖拽连线时抓取,手绘精确,悬停连线显示可抓取。 + MouseCursor _mouseCursor() { + if (_connVertexOrigin != null) return SystemMouseCursors.grabbing; + if (c.archTool == ArchTool.pen) return SystemMouseCursors.precise; + if (c.archTool == ArchTool.select && _hoverConn) { + return SystemMouseCursors.grab; + } + return SystemMouseCursors.basic; + } + // ===================== 参数化草图:交互 ===================== /// 草图按下:选择 / 拖拽(约束求解)/ 绘制 / 修剪。 @@ -948,7 +1140,7 @@ class _ArchViewState extends State if (soleSel != null && !soleSel.isLinear) { final List hs = archHandleRects(soleSel.rect, c.arch.zoom); for (int i = 0; i < hs.length; i++) { - if (hs[i].inflate(4 / c.arch.zoom).contains(world)) { + if (hs[i].inflate((touch ? 12 : 4) / c.arch.zoom).contains(world)) { _resizeHandle = i; _resizeOrigin = soleSel; _resizeRect = soleSel.rect; @@ -964,7 +1156,7 @@ class _ArchViewState extends State soleSel.b != null ? [soleSel.a!, soleSel.b!] : soleSel.pts; - final double tol = 10 / c.arch.zoom; + final double tol = (touch ? 20 : 10) / c.arch.zoom; for (int i = 0; i < vs.length; i++) { if ((vs[i] - world).distance <= tol) { _vertexIndex = i; @@ -975,30 +1167,56 @@ class _ArchViewState extends State } } } - // 连线折点拖动:所有折点可拖;端点拖到别的图形会重新吸附(松手生效)。 + // 连线拖拽编辑(选中单条连线时):端点 / 折点 / 线段三种拖动。 + // 针对平板 / 手指:命中半径加大;路径任意一段可整体平移。 final ArchConnector? soleConn = c.archSelIds.length == 1 ? c.arch.connectorById(c.archSelId) : null; - if (soleConn != null) { - final ArchConnGeometry g = archConnectorGeometry(c.arch, soleConn); - final double tol = 10 / c.arch.zoom; + if (soleConn != null && + c.arch.isLayerVisible(soleConn.layerId) && + !c.arch.isLayerLocked(soleConn.layerId)) { + final ArchDoc adoc = c.arch; + final bool hasA = adoc.shapeById(soleConn.fromId ?? '') != null; + final bool hasB = adoc.shapeById(soleConn.toId ?? '') != null; + final ArchConnGeometry g = archConnectorGeometry(adoc, soleConn); + final int last = g.pts.length - 1; + final double vTol = (touch ? 22 : 10) / c.arch.zoom; for (int i = 0; i < g.pts.length; i++) { - if ((g.pts[i] - world).distance <= tol) { - // 角点编辑:把当前正交路径的全部拐点物化为折点(拖拽自由, - // 路径仍按折点走横平竖直的正交台阶)。 - final List cornerList = g.pts.length > 2 - ? g.pts.sublist(1, g.pts.length - 1) - : const []; - _connVertexOrigin = soleConn.copyWith(mids: cornerList); + if ((g.pts[i] - world).distance > vTol) continue; + if (i == 0 || i == last) { + // 端点:拖拽换吸附目标 / 脱离为自由端点(实时预览)。 + _beginConnDrag(soleConn, 'endpoint'); _connVertexIndex = i; - _connVertexPts = List.of(g.pts); - _connDragTargetId = null; - setState(() {}); + return; + } + // 吸附端的固定短桩不单独拖动,交给线段拖动。 + if ((hasA && i == 1) || (hasB && i == last - 1)) break; + // 折点:把路径拐点物化为折点后自由拖动(跳过两端固定短桩)。 + final List mids = []; + int midIndex = 0; + for (int j = 1; j < last; j++) { + if (hasA && j == 1) continue; + if (hasB && j == last - 1) continue; + if (j < i) midIndex++; + mids.add(g.pts[j]); + } + _beginConnDrag(soleConn.copyWith(mids: mids), 'corner'); + _connMidIndex = midIndex; + return; + } + // 线段拖动:命中路径任意一段 → 整体平移该段(磁力吸附 + 导引虚线)。 + final double sTol = (touch ? 20 : 9) / c.arch.zoom; + for (int k = 0; k < last; k++) { + if (archDistToSegment(world, g.pts[k], g.pts[k + 1]) <= sTol) { + _beginConnSegmentDrag(soleConn, g, world, k, hasA, hasB); return; } } } - final (String?, ArchShape?) hit = _hitTest(world); + final (String?, ArchShape?) hit = _hitTest( + world, + connTol: touch ? 20 / c.arch.zoom : 0, + ); final String? id = hit.$1; final ArchShape? shape = hit.$2; if (id != null) { @@ -1124,26 +1342,69 @@ class _ArchViewState extends State return; } if (_connVertexOrigin != null) { - final int last = _connVertexPts.length - 1; - final bool isEndpoint = - _connVertexIndex == 0 || _connVertexIndex == last; - Offset p = world; - if (isEndpoint) { - // 端点:优先吸附到鼠标下的图形边框(可换目标重新吸附),无则脱离。 - final ArchShape? target = _shapeAt(world); + final ArchConnector origin = _connVertexOrigin!; + final String mode = _connDragMode ?? 'corner'; + if (mode == 'segment') { + // 线段拖动:沿垂直方向整体平移(磁力吸附 + 导引虚线)。 + final bool axisX = _connSegAxis == 'x'; + final ConnSnap snap = _snapConnCoord( + world, + origin, + onlyX: axisX, + onlyY: !axisX, + ); + _guideXs = snap.gx == null ? const [] : [snap.gx!]; + _guideYs = snap.gy == null ? const [] : [snap.gy!]; + final double v = axisX ? snap.x : snap.y; + final double seed = _connSegSeed ?? v; + final List mids = [ + for (final Offset m in origin.mids) + ((axisX ? m.dx : m.dy) - seed).abs() < 0.75 + ? (axisX ? Offset(v, m.dy) : Offset(m.dx, v)) + : m, + ]; + _connVertexUpdated = origin.copyWith(mids: mids); + setState(() {}); + return; + } + if (mode == 'endpoint') { + // 端点:实时预览吸附(可换目标 / 脱离);空白处磁力吸附 + 网格回退。 + final ArchShape? target = _shapeAt( + world, + pad: math.max(6, 10 / c.arch.zoom), + ); + final bool isFrom = _connVertexIndex == 0; + Offset p; + String? targetId; + ConnSnap? snap; if (target != null) { p = archNearestBorderPoint(target, world); - _connDragTargetId = target.id; + targetId = target.id; } else { - _connDragTargetId = null; - if (c.arch.gridSnap) p = archSnapPoint(c.arch, world); + snap = _snapConnCoord(world, origin); + p = Offset(snap.x, snap.y); + targetId = null; } - } else if (c.arch.gridSnap) { - p = archSnapPoint(c.arch, world); + _connDragTargetId = targetId; + _guideXs = + snap?.gx == null ? const [] : [snap!.gx!]; + _guideYs = + snap?.gy == null ? const [] : [snap!.gy!]; + _connVertexUpdated = isFrom + ? origin.copyWith(fromId: targetId, from: p) + : origin.copyWith(toId: targetId, to: p); + setState(() {}); + return; } - _connVertexPts[_connVertexIndex] = p; - _connVertexUpdated = - _applyConnVertices(_connVertexOrigin!, _connVertexIndex, _connVertexPts); + // 折点:磁力吸附(对齐虚线)+ 网格回退。 + final ConnSnap snap = _snapConnCoord(world, origin); + _guideXs = snap.gx == null ? const [] : [snap.gx!]; + _guideYs = snap.gy == null ? const [] : [snap.gy!]; + final List mids = List.of(origin.mids); + if (_connMidIndex >= 0 && _connMidIndex < mids.length) { + mids[_connMidIndex] = Offset(snap.x, snap.y); + } + _connVertexUpdated = origin.copyWith(mids: mids); setState(() {}); return; } @@ -1276,25 +1537,21 @@ class _ArchViewState extends State return; } if (_connVertexOrigin != null) { - final int index = _connVertexIndex; - final int last = _connVertexPts.length - 1; - final bool isEndpoint = index == 0 || index == last; - ArchConnector? done = _connVertexUpdated; + final ArchConnector? done = _connVertexUpdated; + final String mode = _connDragMode ?? 'corner'; final String? targetId = _connDragTargetId; _connVertexOrigin = null; - _connVertexPts = []; _connVertexUpdated = null; + _connDragMode = null; _connDragTargetId = null; - if (done != null && isEndpoint) { - // 端点松手:吸附到新图形(更新归属);空白处则脱离为自由端点。 - done = index == 0 - ? done.copyWith(fromId: targetId) - : done.copyWith(toId: targetId); - } + _connSegAxis = null; + _connSegSeed = null; + _guideXs = const []; + _guideYs = const []; if (done != null) { - final String st = !isEndpoint - ? '编辑连线折点' - : (targetId == null ? '连线端点:已脱离(自由端点)' : '连线端点:已吸附到图形'); + final String st = mode == 'endpoint' + ? (targetId == null ? '连线端点:已脱离(自由端点)' : '连线端点:已吸附到图形') + : (mode == 'segment' ? '拖动连线路径' : '编辑连线折点'); c.updateArchConnector(done, status: st); } setState(() {}); @@ -1419,8 +1676,11 @@ class _ArchViewState extends State _draft = null; _connFromId = null; _connVertexOrigin = null; - _connVertexPts = []; _connVertexUpdated = null; + _connDragMode = null; + _connDragTargetId = null; + _connSegAxis = null; + _connSegSeed = null; _moveIds = []; _moveDeltas = null; _guideXs = const []; @@ -1521,27 +1781,6 @@ class _ArchViewState extends State )); } - /// 把折点拖拽结果写回连线(中间折点 / 自由端点)。 - ArchConnector _applyConnVertices( - ArchConnector origin, - int index, - List pts, - ) { - final int last = pts.length - 1; - final List mids = List.of(origin.mids); - Offset from = origin.from; - Offset to = origin.to; - if (index == 0) { - from = pts.first; - } else if (index == last) { - to = pts.last; - } else { - final int mi = index - 1; - if (mi >= 0 && mi < mids.length) mids[mi] = pts[index]; - } - return origin.copyWith(from: from, to: to, mids: mids); - } - /// 按目标外接框生成图元图形(保持图元自然纵横比)。 ArchShape _symbolShapeFor(LibSymbol sym, Rect b) { final Rect nat = symbolNaturalBounds(sym); @@ -1867,14 +2106,20 @@ class _ArchViewState extends State autofocus: true, onKeyEvent: _onKey, child: MouseRegion( - cursor: c.archTool == ArchTool.pen - ? SystemMouseCursors.precise - : SystemMouseCursors.basic, + cursor: _mouseCursor(), onHover: (PointerHoverEvent e) { final Offset w = _toWorld(e.localPosition); + final bool hover = c.archTool == ArchTool.select && + _connVertexOrigin == null && + _connAt(w, 10 / c.arch.zoom) != null; final Offset? cur = _cursorWorld; - if (cur == null || (cur - w).distance > 0.4) { - setState(() => _cursorWorld = w); + if (hover != _hoverConn || + cur == null || + (cur - w).distance > 0.4) { + setState(() { + _cursorWorld = w; + _hoverConn = hover; + }); } }, onExit: (_) { diff --git a/lib/ui/brand_menu.dart b/lib/ui/brand_menu.dart index bf95529..7f26dcb 100644 --- a/lib/ui/brand_menu.dart +++ b/lib/ui/brand_menu.dart @@ -1,4 +1,4 @@ -/// 左上角品牌按钮 +「EDC|易得设计」设计合集菜单。 +/// 左上角品牌按钮 +「EDC|易得」设计合集菜单。 /// /// 点开左上角 logo:菜单从 logo **下方**下拉展开(不遮挡 logo)。 /// 菜单由模块注册表驱动:首页入口 + 已开放模块(可进入/新建)+ @@ -56,7 +56,7 @@ class BrandMenuButton extends StatelessWidget { final Tokens t = context.tok; final BorderRadius radius = BorderRadius.circular(10); return Tooltip( - message: 'EDC|易得设计:设计合集', + message: 'EDC|易得:设计合集', child: Material( color: t.panel, borderRadius: radius, @@ -238,7 +238,7 @@ class BrandMenuButton extends StatelessWidget { padding: const EdgeInsets.fromLTRB(12, 6, 12, 8), child: Row( children: [ - Text('EDC|易得设计', + Text('EDC|易得', style: TextStyle( color: t.text, fontSize: 12.5, diff --git a/lib/ui/dialogs.dart b/lib/ui/dialogs.dart index 4c956d0..3de3be0 100644 --- a/lib/ui/dialogs.dart +++ b/lib/ui/dialogs.dart @@ -2049,7 +2049,7 @@ class _StationRowState extends State<_StationRow> { /// 双视图说明以及单位与导出等信息。 /// 软件设置:集中设置入口(外观 / 文档默认 / 架构图网格 / 更新)。 /// -/// 从左上角「EDC|易得设计」菜单底部的「软件设置」打开;文档级的完整设置 +/// 从左上角「EDC|易得」菜单底部的「软件设置」打开;文档级的完整设置 /// (单位 / 循环 / 相位等)仍在「文档设置」(F2 / 左侧栏)里。 class SoftwareSettingsDialog extends StatefulWidget { /// 构造软件设置对话框。 @@ -2081,6 +2081,8 @@ class _SoftwareSettingsDialogState extends State { } await showDialog( context: context, + // 点对话框外灰色区域不关闭(下载中防误触退出)。 + barrierDismissible: false, builder: (_) => UpdateDialog(controller: c, info: info), ); } catch (e) { @@ -2650,7 +2652,7 @@ class _HelpDialogState extends State { ]), // 目标:架构图编辑操作与导出。 _section(t, >[ - ['连线规则', '连线一律正交(横平竖直),不会出现斜线;端点自动吸附图形边框,选中后拖拽路径上的角点可调整走线位置;端点也可拖到别的图形重新吸附或脱离。'], + ['连线规则', '连线一律正交(横平竖直):两端垂直出入图元边框(箭头不会乱指),同一图元多条连线自动错开;选中后可拖端点换吸附、拖折点或线段平移走线(平板已加大命中范围),拖动时有磁力对齐与虚线导引;鼠标悬停连线显示抓取光标。'], ['对齐 / 均布', '框选或 Ctrl 多选后,右栏出现 8 个对齐按钮:左 / 横向居中 / 右、顶 / 纵向居中 / 底、横向均布、纵向均布(以选中范围为参照,均布需 ≥3 个)。'], ['层级 / 复制 / 删除', '选中后右栏可「上移一层 / 下移一层」;拖拽移动、白色手柄缩放;Delete 删除选中;Ctrl+A 全选。'], ['我要导出 DXF', '顶部「导出」→「导出 DXF」:AutoCAD R12 格式(图层 / 图形 / 连线 / 文字),可直接在 AutoCAD / DraftSight / ZWCAD 打开继续编辑。'], @@ -2741,7 +2743,7 @@ class _HelpDialogState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('EDC|易得设计 · Easy Design Collection', + Text('EDC|易得 · Easy Design Collection', style: TextStyle(color: t.text, fontSize: 15, fontWeight: FontWeight.w700)), const SizedBox(height: 4), Text('V$kAppVersion(${android ? '安卓版' : 'Windows 版'})', diff --git a/lib/ui/home_view.dart b/lib/ui/home_view.dart index f9cdd16..542b952 100644 --- a/lib/ui/home_view.dart +++ b/lib/ui/home_view.dart @@ -195,7 +195,7 @@ class _HomeViewState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - 'EDC|易得设计', + 'EDC|易得', style: TextStyle( color: t.text, fontSize: 24, diff --git a/lib/ui/update_dialog.dart b/lib/ui/update_dialog.dart index 19ceebe..c77aef6 100644 --- a/lib/ui/update_dialog.dart +++ b/lib/ui/update_dialog.dart @@ -14,6 +14,7 @@ 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 'dialogs.dart'; @@ -57,6 +58,8 @@ class _UpdateDialogState extends State { _received = 0; _status = '正在下载更新包…'; }); + // 下载期间保持屏幕常亮:避免锁屏中断下载(Android / Windows)。 + await KeepAwake.enable(); try { if (Platform.isAndroid) { await _updateAndroid(); @@ -73,6 +76,8 @@ class _UpdateDialogState extends State { }); } return; + } finally { + await KeepAwake.disable(); } if (mounted) setState(() => _busy = false); } @@ -159,6 +164,7 @@ class _UpdateDialogState extends State { }); } await Future.delayed(const Duration(milliseconds: 900)); + await KeepAwake.forceOff(); exit(0); } @@ -176,6 +182,13 @@ class _UpdateDialogState extends State { _cancelled = true; } + @override + void dispose() { + // 兜底:对话框销毁后不再强制常亮。 + KeepAwake.forceOff(); + super.dispose(); + } + @override Widget build(BuildContext context) { final Tokens t = context.tok; @@ -183,10 +196,14 @@ class _UpdateDialogState extends State { final String sizeText = info.assetSize > 0 ? '${(info.assetSize / 1048576).toStringAsFixed(1)} MB' : ''; - return Dialog( - backgroundColor: t.dialog, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), - child: scaledDialogBox( + return PopScope( + // 下载中禁止返回键退出;未下载时可返回键关闭。 + // 点击对话框外的灰色区域始终无响应(barrierDismissible: false)。 + canPop: !_busy, + child: Dialog( + backgroundColor: t.dialog, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), + child: scaledDialogBox( context, 620, 560, @@ -300,7 +317,8 @@ class _UpdateDialogState extends State { const SizedBox(width: 8), Expanded( child: Text( - '下载更新过程中,请确保屏幕保持长亮、网络持续连接,避免更新包下载中断。', + '更新过程中软件会自动保持屏幕常亮;请保持界面打开、网络连接稳定,' + '不要退出软件,避免更新包下载中断。', style: TextStyle(color: t.warn, fontSize: 11.5, height: 1.5), ), ), @@ -343,6 +361,7 @@ class _UpdateDialogState extends State { ), ), ), + ), ); } } diff --git a/lib/update/keep_awake.dart b/lib/update/keep_awake.dart new file mode 100644 index 0000000..2681eb5 --- /dev/null +++ b/lib/update/keep_awake.dart @@ -0,0 +1,64 @@ +/// 应用内更新下载期间的「屏幕常亮」开关。 +/// +/// - Android:走原生通道 `seqstudio/docs` 的 `keepScreenOn`(窗口 flag); +/// - Windows:`SetThreadExecutionState`(FFI,禁止系统休眠与关屏); +/// - 其它平台:空操作。任何失败都不影响更新流程(静默)。 +library; + +import 'dart:ffi'; +import 'dart:io'; + +import 'package:flutter/services.dart'; + +/// 屏幕常亮(引用计数:enable / disable 配对;嵌套安全)。 +class KeepAwake { + KeepAwake._(); + + static const MethodChannel _channel = MethodChannel('seqstudio/docs'); + static int _count = 0; + + /// 开启(重复开启只生效一次)。 + static Future enable() async { + _count++; + if (_count != 1) return; + await _apply(true); + } + + /// 关闭(配对 [enable])。 + static Future disable() async { + if (_count > 0) _count--; + if (_count != 0) return; + await _apply(false); + } + + /// 强制关闭(对话框销毁等兜底场景)。 + static Future forceOff() async { + _count = 0; + await _apply(false); + } + + static Future _apply(bool on) async { + try { + if (Platform.isAndroid) { + await _channel.invokeMethod( + 'keepScreenOn', + {'on': on}, + ); + } else if (Platform.isWindows) { + _applyWindows(on); + } + } catch (_) { + // 保持常亮失败不应中断更新。 + } + } + + static void _applyWindows(bool on) { + final DynamicLibrary lib = DynamicLibrary.open('kernel32.dll'); + final int Function(int) setState = + lib.lookupFunction( + 'SetThreadExecutionState', + ); + // ES_CONTINUOUS |(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED) + setState(on ? 0x80000003 : 0x80000000); + } +} diff --git a/lib/version.dart b/lib/version.dart index 170a328..40d2f8c 100644 --- a/lib/version.dart +++ b/lib/version.dart @@ -2,7 +2,7 @@ /// /// 应用内更新检查用它判断服务器发布的版本是否更新; /// **每次发版必须与 pubspec 同步更新**(见 BUILD-NOTES 的发布流程)。 -const String kAppVersion = '1.3.10'; +const String kAppVersion = '1.3.11'; /// 是否要求授权(License)才能导出。 /// diff --git a/pubspec.yaml b/pubspec.yaml index c456df7..3d2e46e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sequence_diagram -description: "EDC|易得设计 · Easy Design Collection:面向 PLC 流程节拍 / 相位角、系统架构与电气设计的桌面软件。" +description: "EDC|易得 · Easy Design Collection:面向 PLC 流程节拍 / 相位角、系统架构与电气设计的桌面软件。" # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.3.10+32 +version: 1.3.11+33 environment: sdk: ^3.13.3 diff --git a/release/notes/RELEASE_NOTES_v1.3.11.md b/release/notes/RELEASE_NOTES_v1.3.11.md new file mode 100644 index 0000000..64206cc --- /dev/null +++ b/release/notes/RELEASE_NOTES_v1.3.11.md @@ -0,0 +1,50 @@ +# V1.3.11 更新内容 + +> ⚠️ 本次为修复 / 优化版:更新体验、连线编辑与全局更名。新功能仍可能存在较多 +> bug 或问题,欢迎反馈(开发者邮箱 liuyu65@126.com / 微信 online-goose)。 + +## 1. 名称统一为「EDC|易得」 + +- 桌面图标名(安卓)、窗口标题(Windows)、应用内品牌、导出图签、文件属性 + 全部改为 **EDC|易得**(不再带「设计」二字); +- 图标本身为纯图形(无文字),无需更换; +- 若你的设备已装 1.3.10:本次为**原地覆盖更新**,装好后桌面名称应直接刷新; + 个别桌面若未刷新,重启桌面或卸载重装一次即可。 +- 若从更早版本(1.3.9 及以前)直接装本次:系统会当作全新应用 + (`cc.sincos.edc`)建立图标,桌面即为 EDC|易得,旧图标卸载即可。 + +## 2. 更新体验(下载更安心) + +- 开始下载后软件**自动保持屏幕常亮**,不会锁屏中断下载(安卓 / Windows); +- 下载过程中点击对话框外的灰色区域**没有任何响应**、按返回键也**不会退出** + 更新界面,防止误触中断(需取消请点「取消下载」); +- 提示文案同步更新,下载进度、限速 320KB/s 照常显示。 + +## 3. 连线(架构图)大优化 + +- **箭头不再乱指**:连线两端沿图元边**法向**垂直出入,箭头始终垂直指向 + 图元边框(垂直边水平射入、水平边垂直射入); +- **多连线自动避让**:同一图元同一条边上的多条连线**自动错开**分布, + 起点与箭头不再重叠(拖动画布上的图形后同样自动重新分布); +- **平板 / 手指拖动优化**: + - 命中范围加大(手指 / 触控笔更容易选中端点和线段); + - 新增**线段拖动**:抓住连线任意一段可整体平移(直线会就地生成台阶); + - 端点拖拽实时预览:拖到别的图形即时吸附、拖到空白即时脱离; +- **磁力吸附 + 虚线导引**:拖动端点 / 折点 / 线段时,自动吸附对齐图元 + 边与中心、其它连线、图纸中心,并用**虚线**显示对齐位置; +- **鼠标光标**:悬停连线显示抓取光标,拖拽中显示抓取中光标。 + +## 4. 更新方式 + +- 应用内:首页 / 工具栏「检查更新」→ 立即更新(保持网络稳定即可, + 现在下载期间屏幕会自动常亮); +- 手动:Release 页下载 `EasyDesignCollection_android_v1.3.11_release.apk` + 或 `EasyDesignCollection_windows_v1.3.11.zip`。 + +## 5. 复验点 + +1. 桌面 / 窗口标题 / 应用内左上角品牌均显示 **EDC|易得**; +2. 点「检查更新」→ 立即更新:下载中不锁屏、点灰区不退出; +3. 架构图:新建两条从同一图形出发的连线 → 起点自动错开; + 箭头垂直指向目标边框;拖动端点 / 折点 / 线段时出现虚线对齐提示; +4. 鼠标悬停连线时光标变为抓取样式(桌面端)。 diff --git a/test/arch_test.dart b/test/arch_test.dart index a044161..c89b9cf 100644 --- a/test/arch_test.dart +++ b/test/arch_test.dart @@ -761,6 +761,153 @@ void main() { }); }); + group('连线法向与自动避让', () { + test('水平相邻:出口水平、箭头垂直射入目标左边', () { + const ArchShape a = ArchShape( + id: 'A', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(0, 0, 100, 80)); + const ArchShape b = ArchShape( + id: 'B', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(300, 40, 100, 80)); + final ArchDoc doc = + ArchDoc.empty.copyWith(shapes: [a, b]); + final ArchConnector conn = ArchConnector( + id: 'C1', + fromId: 'A', + from: a.rect.center, + toId: 'B', + to: b.rect.center, + ); + final ArchConnGeometry g = archConnectorGeometry(doc, conn); + expect(g.start.dx, closeTo(100, 0.5)); + expect(g.end.dx, closeTo(300, 0.5)); + expect((g.pts[1].dy - g.start.dy).abs(), lessThan(0.5), + reason: '出口应沿法向(水平)'); + final Offset lastD = g.end - g.pts[g.pts.length - 2]; + expect(lastD.dy.abs(), lessThan(0.5), reason: '箭头应水平射入'); + expect(lastD.dx, greaterThan(0)); + }); + + test('垂直相邻:出口垂直、箭头垂直射入目标上边', () { + const ArchShape a = ArchShape( + id: 'A', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(0, 0, 100, 80)); + const ArchShape b = ArchShape( + id: 'B', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(60, 300, 100, 80)); + final ArchDoc doc = + ArchDoc.empty.copyWith(shapes: [a, b]); + final ArchConnector conn = ArchConnector( + id: 'C1', + fromId: 'A', + from: a.rect.center, + toId: 'B', + to: b.rect.center, + ); + final ArchConnGeometry g = archConnectorGeometry(doc, conn); + expect(g.start.dy, closeTo(80, 0.5)); + expect(g.end.dy, closeTo(300, 0.5)); + expect((g.pts[1].dx - g.start.dx).abs(), lessThan(0.5), + reason: '出口应沿法向(垂直)'); + final Offset lastD = g.end - g.pts[g.pts.length - 2]; + expect(lastD.dx.abs(), lessThan(0.5), reason: '箭头应垂直射入'); + expect(lastD.dy, greaterThan(0)); + }); + + test('多条连线贴同一条边:自动错开(槽位避让)', () { + const ArchShape hub = ArchShape( + id: 'H', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(0, 0, 100, 240)); + const ArchShape b1 = ArchShape( + id: 'B1', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(320, 0, 80, 60)); + const ArchShape b2 = ArchShape( + id: 'B2', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(320, 90, 80, 60)); + const ArchShape b3 = ArchShape( + id: 'B3', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(320, 180, 80, 60)); + final List conns = [ + ArchConnector( + id: 'C1', + fromId: 'H', + from: hub.rect.center, + toId: 'B1', + to: b1.rect.center), + ArchConnector( + id: 'C2', + fromId: 'H', + from: hub.rect.center, + toId: 'B2', + to: b2.rect.center), + ArchConnector( + id: 'C3', + fromId: 'H', + from: hub.rect.center, + toId: 'B3', + to: b3.rect.center), + ]; + final ArchDoc doc = ArchDoc.empty.copyWith( + shapes: [hub, b1, b2, b3], + connectors: conns, + ); + final List ys = [ + for (final ArchConnector cn in conns) + archConnectorGeometry(doc, cn).start.dy, + ]; + // 起点互不相同、均落在 hub 右边框内,并保持自然顺序。 + expect(ys[0], lessThan(ys[1])); + expect(ys[1], lessThan(ys[2])); + for (final double y in ys) { + expect(y, greaterThan(0)); + expect(y, lessThan(240)); + } + for (final ArchConnector cn in conns) { + final ArchConnGeometry g = archConnectorGeometry(doc, cn); + expect(g.start.dx, closeTo(100, 0.5), reason: '起点应贴 hub 右边框'); + } + }); + + test('带折点:最后一段仍沿法向射入目标边', () { + const ArchShape a = ArchShape( + id: 'A', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(0, 0, 100, 80)); + const ArchShape b = ArchShape( + id: 'B', + type: ArchShapeType.rect, + rect: Rect.fromLTWH(300, 200, 100, 80)); + final ArchDoc doc = + ArchDoc.empty.copyWith(shapes: [a, b]); + final ArchConnector conn = ArchConnector( + id: 'C1', + fromId: 'A', + from: a.rect.center, + toId: 'B', + to: b.rect.center, + mids: const [Offset(150, 90)], + ); + final ArchConnGeometry g = archConnectorGeometry(doc, conn); + final Offset lastD = g.end - g.pts[g.pts.length - 2]; + expect(lastD.dx.abs() < 0.5 || lastD.dy.abs() < 0.5, isTrue, + reason: '最后一段应横平竖直(法向)'); + const Rect br = Rect.fromLTWH(300, 200, 100, 80); + final bool onBorder = (g.end.dx - br.left).abs() < 0.5 || + (g.end.dx - br.right).abs() < 0.5 || + (g.end.dy - br.top).abs() < 0.5 || + (g.end.dy - br.bottom).abs() < 0.5; + expect(onBorder, isTrue, reason: '终点应落在目标边框上'); + }); + }); + group('橡皮擦', () { test('连续擦除计入一次撤销', () { final AppController c = AppController(project: Project.demo()); diff --git a/test/help_dialog_test.dart b/test/help_dialog_test.dart index 942250a..94228a3 100644 --- a/test/help_dialog_test.dart +++ b/test/help_dialog_test.dart @@ -23,6 +23,6 @@ void main() { // 切到「关于」分页:不应抛异常,且关于页内容在树中。 await tester.tap(find.text('关于')); await tester.pumpAndSettle(); - expect(find.textContaining('EDC|易得设计'), findsWidgets); + expect(find.textContaining('EDC|易得'), findsWidgets); }); } diff --git a/test/home_test.dart b/test/home_test.dart index e7b91b1..c30f401 100644 --- a/test/home_test.dart +++ b/test/home_test.dart @@ -26,7 +26,7 @@ void main() { expect(moduleOf(AppMode.home), isNull); expect(moduleOf(AppMode.sequence)!.name, '时序图'); expect(moduleOf(AppMode.architecture)!.suffix, '.arch.json'); - expect(appModeLabel(AppMode.home), 'EDC|易得设计'); + expect(appModeLabel(AppMode.home), 'EDC|易得'); expect(appModeLabel(AppMode.sequence), contains('时序图')); }); }); diff --git a/windows/runner/Runner.rc b/windows/runner/Runner.rc index c87522b..02bd10b 100644 --- a/windows/runner/Runner.rc +++ b/windows/runner/Runner.rc @@ -90,7 +90,7 @@ BEGIN BLOCK "040904e4" BEGIN VALUE "CompanyName", "呆头鹅" "\0" - VALUE "FileDescription", "EDC|易得设计 Easy Design Collection" "\0" + VALUE "FileDescription", "EDC|易得 Easy Design Collection" "\0" VALUE "FileVersion", VERSION_AS_STRING "\0" VALUE "InternalName", "EasyDesignCollection" "\0" VALUE "LegalCopyright", "Copyright (C) 2026 呆头鹅. All rights reserved." "\0" diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index 1f01f62..41a66ca 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -38,7 +38,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, Win32Window::Size size( static_cast(screen_width / scale * 0.94), static_cast(screen_height / scale * 0.94)); - if (!window.Create(L"\u65F6\u5E8F\u56FE\u8BBE\u8BA1\u5668", origin, size)) { + if (!window.Create(L"EDC|\u6613\u5F97", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true);