2 Commits

33 changed files with 193 additions and 1180 deletions
+8 -2
View File
@@ -26,8 +26,14 @@ android {
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // 应用身份(applicationId):
applicationId = "cc.sincos.sequence_diagram" // 由 `cc.sincos.sequence_diagram` 切换为 `cc.sincos.edc`(v1.3.10 起)。
// 原因:部分安卓桌面会长期保留旧包身份(cc.sincos.sequence_diagram)的
// 图标名缓存,导致应用更名后桌面仍显示旧名「时序图设计」。换新身份安装 =
// 系统当作全新应用处理,桌面必然按新包内的名称(EDC|易得设计)生成新图标。
// 注意:namespace 与 Kotlin 包名保持不变(仅 applicationId 变化),因此
// AndroidManifest 中组件类名需写全限定名(见 android:name)。
applicationId = "cc.sincos.edc"
// You can update the following values to match your application needs. // You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config. // For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion minSdk = flutter.minSdkVersion
+1 -1
View File
@@ -13,7 +13,7 @@
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"> android:icon="@mipmap/ic_launcher">
<activity <activity
android:name=".MainActivity" android:name="cc.sincos.sequence_diagram.MainActivity"
android:exported="true" android:exported="true"
android:launchMode="singleTop" android:launchMode="singleTop"
android:taskAffinity="" android:taskAffinity=""
Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 KiB

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 KiB

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 61 KiB

+13 -27
View File
@@ -44,23 +44,16 @@
矩形 / 圆角矩形 / 椭圆 / 圆 / 三角形 / 菱形 / 六边形 / 圆柱 / 云 / 矩形 / 圆角矩形 / 椭圆 / 圆 / 三角形 / 菱形 / 六边形 / 圆柱 / 云 /
箭头 / 直线 / 折线 / 曲线。 箭头 / 直线 / 折线 / 曲线。
- **多笔组合**:两笔画的矩形、圆柱(顶盖 + 柱体)自动拼接; - **多笔组合**:两笔画的矩形、圆柱(顶盖 + 柱体)自动拼接;
与上一笔刚生成的图形也能在 2.5 秒内合并成图元(如 圆 + 叉 = 指示灯)。 与上一笔刚生成的图形也能在 2.5 秒内合并。
- **图元库匹配**:内置识别不了的笔迹,会与图元库轮廓匹配——
**库里有什么,就能画什么**(含用户自定义 / 导入的图元)。
- 识别不了的笔迹保留为**墨迹**(可擦除或之后点「识别」重试)。 - 识别不了的笔迹保留为**墨迹**(可擦除或之后点「识别」重试)。
- **手动确认识别(平板推荐)**:左栏「手绘识别」关闭「松手自动识别」 - **手动确认识别(平板推荐)**:左栏「手绘识别」关闭「松手自动识别」
(安卓默认关闭)→ 笔迹先保留为墨迹,画完点顶部「识别(N)」按钮统一确认。 (安卓默认关闭)→ 笔迹先保留为墨迹,画完点顶部「识别(N)」按钮统一确认。
### 2.3 图元库(Visio 式可扩展) ### 2.3 图形库
- 左栏「图元库」按**分类折叠**(默认收起,只展开选中的库): - 左栏「图形库」内置标准图形(矩形 / 圆角矩形 / 椭圆 / 圆 / 三角 / 菱形 /
点击图元即插入画布(保持纵横比、自动吸附网格)。 六边形 / 圆柱 / 云…)与 IT 图元(服务器 / 客户端 / 移动端 / 防火墙 /
- 内置电气图元(断路器 / 熔断器 / 接触器线圈 / 常开常闭触点 / 按钮 / 交换机 / 消息队列),点一下即插入画布。
指示灯 / 电机 / 热继电器 / 端子 / 接地 / 电阻 / 继电器 / 直流电源…)与
IT 图元(服务器 / 客户端 / 移动端 / 防火墙 / 交换机 / 消息队列)。
- **导入图元…**:读取 `*.symbol.json`(可分享给同事)。
- **从选中图形存为图元**:把画布上的图形(可多选)保存进图元库;
用户图元卡片带 × 可删除(内置不可删)。
### 2.4 橡皮 ### 2.4 橡皮
@@ -100,22 +93,13 @@
新建架构图为 **A0 图纸**(1189 × 841 mm;**1 世界单位 = 1 mm**), 新建架构图为 **A0 图纸**(1189 × 841 mm;**1 世界单位 = 1 mm**),
自动适配视口居中;画布上绘制浅色 A0 边界。 自动适配视口居中;画布上绘制浅色 A0 边界。
### 2.10 尺寸标注(精确定位图形尺寸) ### 2.10 对齐 / 均布与编辑
选中图形 / 曲线 / 图元 → 右栏「**尺寸 · mm**」区:
- 按类型给出 **宽度 / 高度 / 长度 / 直径**;
- **点数值直接输入新值**:几何按比例缩放(中心保持),不走约束求解器;
- 右上角「**标注全部 / 清除标注**」:在画布上显示 W / H / L / ⌀ 标签;
- **双击画布上的尺寸标签**同样可改值。
### 2.11 对齐 / 均布与编辑
- 多选(框选 / Ctrl 点选)后右栏 8 个按钮:左 / 横向居中 / 右、 - 多选(框选 / Ctrl 点选)后右栏 8 个按钮:左 / 横向居中 / 右、
顶 / 纵向居中 / 底、横向均布、纵向均布(以选中范围为参照,均布需 ≥3 个)。 顶 / 纵向居中 / 底、横向均布、纵向均布(以选中范围为参照,均布需 ≥3 个)。
- 上移 / 下移一层、删除(Del)、Ctrl+A 全选。 - 上移 / 下移一层、删除(Del)、Ctrl+A 全选。
### 2.12 导出 ### 2.11 导出
| 格式 | 说明 | | 格式 | 说明 |
| --- | --- | | --- | --- |
@@ -186,8 +170,10 @@
**Q:为什么连线不能画斜线?** **Q:为什么连线不能画斜线?**
按产品约定连线**一律正交**(横平竖直);需要斜段请用「手绘」画直线图形。 按产品约定连线**一律正交**(横平竖直);需要斜段请用「手绘」画直线图形。
**Q:图元库里的图元能分享给别人吗?** **Q:升级后桌面出现两个图标 / 名称还是旧的?**
能。`library/symbols/*.symbol.json` 直接拷贝,对方「导入图元…」即可使用。 1.3.10 起应用换了新身份(`cc.sincos.edc`),系统会当作**全新应用**安装:
桌面新图标即 `EDC|易得设计`;旧图标(时序图设计)长按卸载即可。
项目文件保存在公共文档目录(`Documents/SequenceDiagram`),不受影响。
**Q:找不到尺寸编辑?** **Q:1.3.10 之后怎么更新?**
选中任意图形 / 曲线 / 图元,右栏属性卡片底部就是「尺寸 · mm」区。 仍从首页 / 工具栏「检查更新」下载安装,此后都在新身份上**原地覆盖更新**。
-204
View File
@@ -132,196 +132,6 @@ enum ArchShapeType {
symbol, symbol,
} }
/// 可编辑尺寸类型(识别后图形的直接尺寸;不走约束求解器)。
enum ArchDimKind {
/// 宽度(水平尺寸)。
width,
/// 高度(垂直尺寸)。
height,
/// 长度(线类图形的路径长度)。
length,
/// 直径(圆)。
diameter,
}
/// 尺寸类型 JSON 名称。
String archDimKindName(ArchDimKind k) => switch (k) {
ArchDimKind.width => 'width',
ArchDimKind.height => 'height',
ArchDimKind.length => 'length',
ArchDimKind.diameter => 'diameter',
};
/// JSON 名称 → 尺寸类型。
ArchDimKind archDimKindFrom(String s) => switch (s) {
'height' => ArchDimKind.height,
'length' => ArchDimKind.length,
'diameter' => ArchDimKind.diameter,
_ => ArchDimKind.width,
};
/// 尺寸类型中文名。
String archDimKindLabel(ArchDimKind k) => switch (k) {
ArchDimKind.width => '宽度',
ArchDimKind.height => '高度',
ArchDimKind.length => '长度',
ArchDimKind.diameter => '直径',
};
/// 图形适用的尺寸类型(右栏编辑 / 画布标注用)。
List<ArchDimKind> archShapeDimKinds(ArchShape s) {
if (s.isLinear) {
return const <ArchDimKind>[
ArchDimKind.length,
ArchDimKind.width,
ArchDimKind.height,
];
}
if (s.type == ArchShapeType.circle) {
return const <ArchDimKind>[ArchDimKind.diameter];
}
return const <ArchDimKind>[ArchDimKind.width, ArchDimKind.height];
}
/// 线类图形的外接矩形(pts / a-b)。
Rect archLinearBounds(ArchShape s) {
if (s.type == ArchShapeType.line && s.a != null && s.b != null) {
return Rect.fromPoints(s.a!, s.b!);
}
if (s.pts.isEmpty) return s.rect;
double l = s.pts.first.dx, r = l, t = s.pts.first.dy, b = t;
for (final Offset p in s.pts) {
if (p.dx < l) l = p.dx;
if (p.dx > r) r = p.dx;
if (p.dy < t) t = p.dy;
if (p.dy > b) b = p.dy;
}
return Rect.fromLTRB(l, t, r, b);
}
/// 线类图形的路径长度(直线 / 折线 / 曲线按顶点折线近似)。
double archShapeLength(ArchShape s) {
if (s.type == ArchShapeType.line && s.a != null && s.b != null) {
return (s.b! - s.a!).distance;
}
double len = 0;
for (int i = 1; i < s.pts.length; i++) {
len += (s.pts[i] - s.pts[i - 1]).distance;
}
return len;
}
/// 测量图形当前尺寸值。
double archShapeDimValue(ArchShape s, ArchDimKind k) {
switch (k) {
case ArchDimKind.length:
return archShapeLength(s);
case ArchDimKind.diameter:
return s.rect.width;
case ArchDimKind.width:
return s.isLinear ? archLinearBounds(s).width : s.rect.width;
case ArchDimKind.height:
return s.isLinear ? archLinearBounds(s).height : s.rect.height;
}
}
/// 线类图形按比例缩放(绕外接框中心;[fx]/[fy] 为横纵缩放系数)。
ArchShape _scaleLinear(ArchShape s, double fx, double fy) {
final Rect b = archLinearBounds(s);
final Offset c0 = b.center;
Offset map(Offset p) =>
Offset(c0.dx + (p.dx - c0.dx) * fx, c0.dy + (p.dy - c0.dy) * fy);
if (s.type == ArchShapeType.line && s.a != null && s.b != null) {
final Offset a2 = map(s.a!);
final Offset b2 = map(s.b!);
return s.copyWith(a: a2, b: b2, rect: Rect.fromPoints(a2, b2));
}
final List<Offset> pts = <Offset>[for (final Offset p in s.pts) map(p)];
if (pts.isEmpty) return s;
double l = pts.first.dx, r = l, t = pts.first.dy, bo = t;
for (final Offset p in pts) {
if (p.dx < l) l = p.dx;
if (p.dx > r) r = p.dx;
if (p.dy < t) t = p.dy;
if (p.dy > bo) bo = p.dy;
}
return s.copyWith(pts: pts, rect: Rect.fromLTRB(l, t, r, bo));
}
/// 应用尺寸(直接缩放几何,中心保持;值 <= 0.1 时按 0.1 处理)。
ArchShape archShapeApplyDim(ArchShape s, ArchDimKind k, double value) {
final double v = value <= 0.1 ? 0.1 : value;
switch (k) {
case ArchDimKind.width:
if (s.isLinear) {
final double w = archLinearBounds(s).width;
return _scaleLinear(s, w <= 1e-6 ? 1 : v / w, 1);
}
return s.copyWith(
rect: Rect.fromCenter(
center: s.rect.center, width: v, height: s.rect.height));
case ArchDimKind.height:
if (s.isLinear) {
final double h = archLinearBounds(s).height;
return _scaleLinear(s, 1, h <= 1e-6 ? 1 : v / h);
}
return s.copyWith(
rect: Rect.fromCenter(
center: s.rect.center, width: s.rect.width, height: v));
case ArchDimKind.diameter:
return s.copyWith(
rect: Rect.fromCenter(center: s.rect.center, width: v, height: v));
case ArchDimKind.length:
final double len = archShapeLength(s);
if (len <= 1e-6) return s;
final double f = v / len;
return _scaleLinear(s, f, f);
}
}
/// 尺寸标签锚点(世界坐标;屏幕恒定间距由 [zoom] 折算)。
Offset archShapeDimLabelPos(
ArchShape s,
ArchDimKind k,
int index,
double zoom,
) {
final double z = zoom <= 0.05 ? 1 : zoom;
final double gap = 17 / z;
final Rect b = s.isLinear ? archLinearBounds(s) : s.rect;
final bool wide =
s.type == ArchShapeType.line || s.type == ArchShapeType.curve;
return Offset(
b.center.dx + (wide ? gap * 0.9 : 0),
b.bottom + gap * (index + 0.8),
);
}
/// 命中的尺寸标签(双击编辑用);未命中返回 null。
(ArchShape, ArchDimKind)? archShapeDimHitAt(
ArchDoc doc,
Offset p,
double zoom,
) {
final double z = zoom <= 0.05 ? 1 : zoom;
final double tol = 14 / z + 6;
for (final ArchShape s in doc.shapes) {
if (!doc.isLayerVisible(s.layerId)) continue;
final List<ArchDimKind> kinds = <ArchDimKind>[
for (final ArchDimKind k in archShapeDimKinds(s))
if (s.dims.contains(k)) k,
];
for (int i = 0; i < kinds.length; i++) {
final Offset a = archShapeDimLabelPos(s, kinds[i], i, z);
if ((p - a).distance <= tol) return (s, kinds[i]);
}
}
return null;
}
/// 把折线正交化:保留顶点位置,但所有段强制「横平竖直」。 /// 把折线正交化:保留顶点位置,但所有段强制「横平竖直」。
/// ///
/// 用于手绘连线的轨迹:笔迹认出的折点仍被尊重,但不会出现斜线 /// 用于手绘连线的轨迹:笔迹认出的折点仍被尊重,但不会出现斜线
@@ -925,7 +735,6 @@ class ArchShape {
this.pts = const <Offset>[], this.pts = const <Offset>[],
this.layerId = kArchDefaultLayerId, this.layerId = kArchDefaultLayerId,
this.symbolId = '', this.symbolId = '',
this.dims = const <ArchDimKind>{},
}); });
/// 唯一标识(如 `S1`)。 /// 唯一标识(如 `S1`)。
@@ -973,9 +782,6 @@ class ArchShape {
/// 图元库符号 id(仅 [ArchShapeType.symbol] 使用;空串 = 未指定)。 /// 图元库符号 id(仅 [ArchShapeType.symbol] 使用;空串 = 未指定)。
final String symbolId; final String symbolId;
/// 画布上标注的尺寸类型(识别后图形可直接改值缩放,见 [archShapeApplyDim])。
final Set<ArchDimKind> dims;
/// 是否为「线类」图形(直线 / 箭头 / 折线 / 曲线)。 /// 是否为「线类」图形(直线 / 箭头 / 折线 / 曲线)。
bool get isLinear => bool get isLinear =>
type == ArchShapeType.line || type == ArchShapeType.line ||
@@ -1048,7 +854,6 @@ class ArchShape {
List<Offset>? pts, List<Offset>? pts,
String? layerId, String? layerId,
String? symbolId, String? symbolId,
Set<ArchDimKind>? dims,
}) { }) {
return ArchShape( return ArchShape(
id: id ?? this.id, id: id ?? this.id,
@@ -1066,7 +871,6 @@ class ArchShape {
pts: pts ?? this.pts, pts: pts ?? this.pts,
layerId: layerId ?? this.layerId, layerId: layerId ?? this.layerId,
symbolId: symbolId ?? this.symbolId, symbolId: symbolId ?? this.symbolId,
dims: dims ?? this.dims,
); );
} }
@@ -1107,10 +911,6 @@ class ArchShape {
'pts': <double>[for (final Offset p in pts) ...<double>[p.dx, p.dy]], 'pts': <double>[for (final Offset p in pts) ...<double>[p.dx, p.dy]],
if (layerId.isNotEmpty) 'ly': layerId, if (layerId.isNotEmpty) 'ly': layerId,
if (symbolId.isNotEmpty) 'sy': symbolId, if (symbolId.isNotEmpty) 'sy': symbolId,
if (dims.isNotEmpty)
'dim': <String>[
for (final ArchDimKind k in dims) archDimKindName(k),
],
}; };
/// 从 JSON 反序列化(字段缺失时使用安全默认值)。 /// 从 JSON 反序列化(字段缺失时使用安全默认值)。
@@ -1151,10 +951,6 @@ class ArchShape {
pts: pts, pts: pts,
layerId: j['ly'] as String? ?? kArchDefaultLayerId, layerId: j['ly'] as String? ?? kArchDefaultLayerId,
symbolId: j['sy'] as String? ?? '', symbolId: j['sy'] as String? ?? '',
dims: <ArchDimKind>{
for (final dynamic e in (j['dim'] as List<dynamic>?) ?? <dynamic>[])
archDimKindFrom(e.toString()),
},
); );
} }
} }
-63
View File
@@ -1030,71 +1030,8 @@ class ArchPainter extends CustomPainter {
: 12.5, : 12.5,
); );
} }
// 尺寸标注(识别后图形 / 曲线 / 图元可直接改值缩放;标签屏幕字号恒定)。
if (s.dims.isNotEmpty) {
final double z = doc.zoom < 0.05 ? 1 : doc.zoom;
final List<ArchDimKind> kinds = <ArchDimKind>[
for (final ArchDimKind k in archShapeDimKinds(s))
if (s.dims.contains(k)) k,
];
for (int i = 0; i < kinds.length; i++) {
final ArchDimKind k = kinds[i];
_dimBadge(canvas, s, k, archShapeDimLabelPos(s, k, i, z), z);
}
}
} }
/// 尺寸标签(小圆角底片 + 数值;屏幕尺寸恒定,双击可改值)。
void _dimBadge(
Canvas canvas,
ArchShape s,
ArchDimKind k,
Offset center,
double z,
) {
final double inv = 1 / z;
final double v = archShapeDimValue(s, k);
final String txt = switch (k) {
ArchDimKind.width => 'W ${_fmtDim(v)}',
ArchDimKind.height => 'H ${_fmtDim(v)}',
ArchDimKind.length => 'L ${_fmtDim(v)}',
ArchDimKind.diameter => '⌀ ${_fmtDim(v)}',
};
final TextPainter tp = TextPainter(
text: TextSpan(
text: txt,
style: TextStyle(
color: const Color(0xFF0F766E),
fontSize: 10 * inv,
fontWeight: FontWeight.w600,
fontFamily: 'Microsoft YaHei UI',
fontFamilyFallback: const <String>['Microsoft YaHei', 'Segoe UI'],
),
),
textDirection: TextDirection.ltr,
)..layout();
final Rect r = Rect.fromCenter(
center: center,
width: tp.width + 8 * inv,
height: tp.height + 3 * inv,
);
final RRect rr = RRect.fromRectAndRadius(r, Radius.circular(4 * inv));
canvas.drawRRect(rr, Paint()..color = t.panel.withValues(alpha: 0.94));
canvas.drawRRect(
rr,
Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1 * inv
..color = const Color(0xFF0F766E).withValues(alpha: 0.5),
);
tp.paint(canvas, r.center - Offset(tp.width / 2, tp.height / 2));
}
static String _fmtDim(double v) => (v - v.roundToDouble()).abs() < 0.05
? v.round().toString()
: v.toStringAsFixed(1);
/// 绘制连线(吸附端实时求边框交点;直线 / 正交折线;箭头 + 标签)。 /// 绘制连线(吸附端实时求边框交点;直线 / 正交折线;箭头 + 标签)。
void _connector(Canvas canvas, ArchConnector c) { void _connector(Canvas canvas, ArchConnector c) {
final ArchConnGeometry g = final ArchConnGeometry g =
+19 -102
View File
@@ -1,22 +1,15 @@
/// 图元库(电气符号 / 通用图元)数据层。 /// 图元库(内置图形图元)数据层。
/// ///
/// - 内置符号:[SymbolLibrary.builtin],随安装包发布(只读,代码内定义); /// - 内置符号:[SymbolLibrary.builtin],随安装包发布(只读,代码内定义);
/// - 用户符号:`library/symbols/*.symbol.json`(见 `app_paths.dart`),
/// 可新增 / 覆盖 / 删除,跨工程复用;
/// - 坐标约定:符号在 **100×100 归一化画布** 内绘制((0,0) 左上、(100,100) /// - 坐标约定:符号在 **100×100 归一化画布** 内绘制((0,0) 左上、(100,100)
/// 右下),引脚 [SymPin] 位于边界附近;实际绘制时按目标矩形等比换算; /// 右下),引脚 [SymPin] 位于边界附近;实际绘制时按目标矩形等比换算;
/// - 单位:与画布一致(1 世界单位 = 1 mm)。 /// - 单位:与画布一致(1 世界单位 = 1 mm)。
///
/// 供「电器原理图」等模块使用(P2:图元库先行;画布 / 布线后续接入)。
library; library;
import 'dart:convert'; import 'dart:convert';
import 'dart:io';
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:ui' show Offset, Path, Rect; import 'dart:ui' show Offset, Path, Rect;
import '../persistence/app_paths.dart';
// ===================== 模型 ===================== // ===================== 模型 =====================
/// 符号基元类型。 /// 符号基元类型。
@@ -332,46 +325,10 @@ Rect symbolNaturalBounds(LibSymbol s) {
return Rect.fromLTWH(l!, t!, w, h).inflate(2); return Rect.fromLTWH(l!, t!, w, h).inflate(2);
} }
/// 运行时图元缓存(内置 + 用户;启动与导入 / 保存 / 删除后刷新)。 /// 图元库:内置符号(随安装包发布,只读)。
///
/// 绘制与手绘识别需要同步访问图元列表,故在内存中保持一份。
class SymbolCache {
SymbolCache._();
static List<LibSymbol> _all = List<LibSymbol>.of(SymbolLibrary.builtin);
static Map<String, LibSymbol> _byId = <String, LibSymbol>{
for (final LibSymbol s in SymbolLibrary.builtin) s.id: s,
};
/// 全部图元(内置 + 用户)。
static List<LibSymbol> get all => _all;
/// 按 id 查找图元。
static LibSymbol? byId(String id) => _byId[id];
/// 重新加载(应用启动 / 导入 / 保存 / 删除后调用)。
static Future<void> refresh() async {
final List<LibSymbol> list = await SymbolLibrary.all();
_all = list;
_byId = <String, LibSymbol>{
for (final LibSymbol s in list) s.id: s,
};
}
}
// ===================== 库(内置 + 用户) =====================
/// 图元库:内置符号 + 用户目录加载 / 保存 / 删除。
class SymbolLibrary { class SymbolLibrary {
SymbolLibrary._(); SymbolLibrary._();
/// 用户符号文件名后缀。
static const String fileSuffix = '.symbol.json';
/// 是否为内置符号 id(内置图元不可删除)。
static bool isBuiltinId(String id) =>
builtin.any((LibSymbol s) => s.id == id);
// 垂直元件的通用引脚(上 / 下)。 // 垂直元件的通用引脚(上 / 下)。
static const List<SymPin> _vpins = <SymPin>[ static const List<SymPin> _vpins = <SymPin>[
SymPin(id: '1', x: 50, y: 0, dir: 't'), SymPin(id: '1', x: 50, y: 0, dir: 't'),
@@ -580,61 +537,21 @@ class SymbolLibrary {
], ],
), ),
]; ];
/// 文件名安全化。
static String _safeId(String id) =>
id.replaceAll(RegExp(r'[^A-Za-z0-9_-]'), '_');
/// 用户符号目录(可注入用于测试)。
static Future<Directory> _dir(Directory? custom) async =>
custom ?? await AppPaths.symbolsDir();
/// 读取用户符号(目录缺失 / 文件损坏时跳过,不抛异常)。
static Future<List<LibSymbol>> loadUser({Directory? dir}) async {
try {
final Directory d = await _dir(dir);
if (!await d.exists()) return <LibSymbol>[];
final List<LibSymbol> out = <LibSymbol>[];
await for (final FileSystemEntity e in d.list()) {
if (e is! File || !e.path.endsWith(fileSuffix)) continue;
try {
out.add(LibSymbol.fromJson(
jsonDecode(await e.readAsString()) as Map<String, dynamic>));
} catch (_) {}
}
return out;
} catch (_) {
return <LibSymbol>[];
}
}
/// 全部符号:内置 + 用户(同 id 时用户覆盖内置)。
static Future<List<LibSymbol>> all({Directory? dir}) async {
final List<LibSymbol> user = await loadUser(dir: dir);
final Set<String> userIds = <String>{
for (final LibSymbol s in user) s.id,
};
return <LibSymbol>[
for (final LibSymbol s in builtin)
if (!userIds.contains(s.id)) s,
...user,
];
}
/// 保存用户符号(已存在同 id 时覆盖)。
static Future<void> saveUser(LibSymbol s, {Directory? dir}) async {
final Directory d = await _dir(dir);
await d.create(recursive: true);
final File f =
File('${d.path}${Platform.pathSeparator}${_safeId(s.id)}$fileSuffix');
await f.writeAsString(s.encode(), flush: true);
}
/// 删除用户符号;不存在时静默。
static Future<void> deleteUser(String id, {Directory? dir}) async {
final Directory d = await _dir(dir);
final File f =
File('${d.path}${Platform.pathSeparator}${_safeId(id)}$fileSuffix');
if (await f.exists()) await f.delete();
}
} }
/// 运行时图元缓存(内置;绘制与手写识别共用)。
class SymbolCache {
SymbolCache._();
static final List<LibSymbol> _all =
List<LibSymbol>.unmodifiable(SymbolLibrary.builtin);
static final Map<String, LibSymbol> _byId = <String, LibSymbol>{
for (final LibSymbol s in SymbolLibrary.builtin) s.id: s,
};
/// 全部图元(内置)。
static List<LibSymbol> get all => _all;
/// 按 id 查找图元。
static LibSymbol? byId(String id) => _byId[id];
}
-3
View File
@@ -13,7 +13,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'license/license_service.dart'; import 'license/license_service.dart';
import 'library/symbol_library.dart';
import 'model/models.dart'; import 'model/models.dart';
import 'modules/module_registry.dart'; import 'modules/module_registry.dart';
import 'persistence/app_paths.dart'; import 'persistence/app_paths.dart';
@@ -65,8 +64,6 @@ class _SequenceDiagramAppState extends State<SequenceDiagramApp> {
_controller.goHome(); _controller.goHome();
// 素材库目录(library/symbols|images|templates):确保存在(失败静默)。 // 素材库目录(library/symbols|images|templates):确保存在(失败静默)。
AppPaths.ensureLibrary(); AppPaths.ensureLibrary();
// 图元库缓存(内置 + library/symbols/*.symbol.json):绘制与识别共用。
SymbolCache.refresh();
_controller.addListener(_updateWindowTitle); _controller.addListener(_updateWindowTitle);
// 启动即校验授权(读取可执行文件同级 license/*.lic)。 // 启动即校验授权(读取可执行文件同级 license/*.lic)。
LicenseService.instance.init().then((LicenseInfo info) { LicenseService.instance.init().then((LicenseInfo info) {
+1 -1
View File
@@ -63,7 +63,7 @@ const List<EdcModule> kModules = <EdcModule>[
suffix: '.arch.json', suffix: '.arch.json',
available: true, available: true,
defaultName: '未命名-架构图', defaultName: '未命名-架构图',
blurb: '手绘识别 · 图元库', blurb: '手绘识别 · 图形库',
), ),
EdcModule( EdcModule(
id: 'sequence', id: 'sequence',
-28
View File
@@ -895,34 +895,6 @@ class AppController extends ChangeNotifier {
]); ]);
} }
// ---- 识别后图形的尺寸编辑(不走约束求解器:直接缩放几何) ----
/// 修改图形尺寸(识别后图形 / 曲线 / 图元直接改值缩放)。
void setArchShapeDim(String id, ArchDimKind kind, double value) {
final ArchShape? s = arch.shapeById(id);
if (s == null || value <= 0) return;
updateArchShape(
archShapeApplyDim(s, kind, value),
status: '${s.text.isNotEmpty ? s.text : archShapeTypeLabel(s.type)}'
':${archDimKindLabel(kind)} → ${value.toStringAsFixed(1)} mm',
);
}
/// 切换画布尺寸标注(显示 / 隐藏;双击标签可改值)。
void toggleArchShapeDim(String id, ArchDimKind kind) {
final ArchShape? s = arch.shapeById(id);
if (s == null) return;
final Set<ArchDimKind> next = Set<ArchDimKind>.of(s.dims);
final bool removed = next.remove(kind);
if (!removed) next.add(kind);
updateArchShape(
s.copyWith(dims: next),
status: removed
? '已取消${archDimKindLabel(kind)}标注'
: '已标注${archDimKindLabel(kind)}(双击标签可改值)',
);
}
/// 删除选中的草图对象。 /// 删除选中的草图对象。
void deleteSketchSelection() { void deleteSketchSelection() {
if (_sketchSelIds.isEmpty) return; if (_sketchSelIds.isEmpty) return;
+1
View File
@@ -727,6 +727,7 @@ class _AppShellState extends State<AppShell> {
onOpenSettings: () => _handleBrandCommand('_settings'), onOpenSettings: () => _handleBrandCommand('_settings'),
onOpenHelp: () => onOpenHelp: () =>
showDialog<void>(context: context, builder: (_) => const HelpDialog()), showDialog<void>(context: context, builder: (_) => const HelpDialog()),
onCheckUpdate: _openUpdate,
), ),
); );
} }
+1 -507
View File
@@ -6,82 +6,15 @@
/// 外层容器(宽度 / 边框 / 标题栏)由 `app_shell.dart` 负责,本文件只提供主体。 /// 外层容器(宽度 / 边框 / 标题栏)由 `app_shell.dart` 负责,本文件只提供主体。
library; library;
import 'dart:convert';
import 'dart:io' show File;
import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui' show PathMetric, Tangent;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../arch/arch_models.dart'; import '../arch/arch_models.dart';
import '../arch/arch_painter.dart';
import '../library/symbol_library.dart';
import '../persistence/android_docs.dart';
import '../sketch/sketch_models.dart'; import '../sketch/sketch_models.dart';
import '../sketch/sketch_solver.dart'; import '../sketch/sketch_solver.dart';
import '../state/app_controller.dart'; import '../state/app_controller.dart';
import '../theme/tokens.dart'; import '../theme/tokens.dart';
import 'dialogs.dart'; import 'dialogs.dart';
/// 尺寸改值对话框(识别后图形 / 曲线 / 图元;右栏与画布标签共用逻辑)。
Future<void> _editShapeDim(
BuildContext context,
AppController c,
ArchShape s,
ArchDimKind k,
) async {
final double cur = archShapeDimValue(s, k);
final String? input = await showTextEditDialog(
context,
title: '编辑${archDimKindLabel(k)}(当前 ${cur.toStringAsFixed(1)} mm)',
initial: cur.toStringAsFixed(1),
);
if (input == null) return;
final double? v = double.tryParse(input.trim());
if (v == null || v <= 0) {
c.setStatus('数值无效:请输入正数');
return;
}
c.setArchShapeDim(s.id, k, v);
}
/// 图元预览画笔(100×100 归一化盒 → 控件尺寸;跳过文字保证小尺寸清晰)。
class _SymPreviewPainter extends CustomPainter {
/// 构造。
_SymPreviewPainter(this.symbol, this.color);
final LibSymbol symbol;
final Color color;
/// 绘制。
@override
void paint(Canvas canvas, Size size) {
if (size.width <= 0 || size.height <= 0) return;
canvas.save();
canvas.scale(size.width / 100, size.height / 100);
const Rect box = Rect.fromLTWH(0, 0, 100, 100);
final Paint stroke = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 100 / size.width * 0.9
..strokeCap = StrokeCap.round
..strokeJoin = StrokeJoin.round
..color = color;
for (final SymPrim p in symbol.prims) {
if (p.kind == SymPrimKind.text) continue;
final Path? path = symPrimPath(p, box);
if (path == null) continue;
canvas.drawPath(path, stroke);
}
canvas.restore();
}
/// 是否需要重绘。
@override
bool shouldRepaint(covariant _SymPreviewPainter old) =>
old.symbol.id != symbol.id || old.color != color;
}
/// 小节标题。 /// 小节标题。
Widget _sec(Tokens t, String s) => Text( Widget _sec(Tokens t, String s) => Text(
s, s,
@@ -116,8 +49,7 @@ class ArchLeftBody extends StatelessWidget {
const SizedBox(height: 8), const SizedBox(height: 8),
Text( Text(
'笔迹一律扶正为标准图形(矩形 / 圆 / 箭头 / 折线 / 曲线):支持两笔组合、' '笔迹一律扶正为标准图形(矩形 / 圆 / 箭头 / 折线 / 曲线):支持两笔组合、'
'圆柱拼接与图元库匹配(库里有什么就能画什么);识别不了的保留为墨迹,' '圆柱拼接;识别不了的保留为墨迹,可用「橡皮」擦除。文字请双击图形 / 空白处直接输入。',
'可用「橡皮」擦除。文字请双击图形 / 空白处直接输入。',
style: TextStyle(color: t.dim, fontSize: 10, height: 1.5), style: TextStyle(color: t.dim, fontSize: 10, height: 1.5),
), ),
const SizedBox(height: 6), const SizedBox(height: 6),
@@ -332,8 +264,6 @@ class ArchLeftBody extends StatelessWidget {
ArchShapeType.queue), ArchShapeType.queue),
], ],
), ),
const SizedBox(height: 10),
_SymbolLibPanel(controller: c),
const SizedBox(height: 14), const SizedBox(height: 14),
_sec(t, '颜色'), _sec(t, '颜色'),
const SizedBox(height: 8), const SizedBox(height: 8),
@@ -604,91 +534,6 @@ class ArchRightBody extends StatelessWidget {
style: TextStyle(color: t.sub, fontSize: 11), style: TextStyle(color: t.sub, fontSize: 11),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Row(
children: <Widget>[
Text('尺寸 · mm(点数值直接修改)',
style: TextStyle(color: t.dim, fontSize: 10)),
const Spacer(),
InkWell(
onTap: () {
final List<ArchDimKind> kinds = archShapeDimKinds(s);
final bool all = kinds.every(s.dims.contains);
for (final ArchDimKind k in kinds) {
if (all == s.dims.contains(k)) {
c.toggleArchShapeDim(s.id, k);
}
}
},
borderRadius: BorderRadius.circular(6),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 5, vertical: 2),
child: Text(
archShapeDimKinds(s)
.every(s.dims.contains)
? '清除标注'
: '标注全部',
style: TextStyle(
color: t.accent,
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
const SizedBox(height: 4),
for (final ArchDimKind k in archShapeDimKinds(s))
Padding(
padding: const EdgeInsets.only(bottom: 3),
child: Row(
children: <Widget>[
SizedBox(
width: 34,
child: Text(archDimKindLabel(k),
style: TextStyle(color: t.dim, fontSize: 11)),
),
InkWell(
onTap: () => _editShapeDim(context, c, s, k),
borderRadius: BorderRadius.circular(5),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: t.panel2,
borderRadius: BorderRadius.circular(5),
border: Border.all(color: t.line),
),
child: Text(
'${archShapeDimValue(s, k).toStringAsFixed(1)} mm',
style: TextStyle(
color: t.accent2,
fontSize: 11,
fontWeight: FontWeight.w600,
),
),
),
),
const Spacer(),
InkWell(
onTap: () => c.toggleArchShapeDim(s.id, k),
borderRadius: BorderRadius.circular(6),
child: Padding(
padding: const EdgeInsets.all(3),
child: Icon(
s.dims.contains(k)
? Icons.label
: Icons.label_outline,
size: 14,
color: s.dims.contains(k) ? t.accent : t.dim,
),
),
),
],
),
),
const SizedBox(height: 8),
Row( Row(
children: <Widget>[ children: <Widget>[
_mini(t, '编辑文字', () => _editText(context, c, s)), _mini(t, '编辑文字', () => _editText(context, c, s)),
@@ -1212,354 +1057,3 @@ class ArchRightBody extends StatelessWidget {
} }
} }
} }
// ===================== 图元库面板(可折叠 · Visio 式) =====================
/// 图元库面板:按分类折叠展示(默认全部收起,只展开选中的库),
/// 点图元即插入画布;用户图元可删除;支持导入与「从选中图形存为图元」。
class _SymbolLibPanel extends StatefulWidget {
/// 构造。
const _SymbolLibPanel({required this.controller});
/// 全局应用控制器。
final AppController controller;
/// 创建状态。
@override
State<_SymbolLibPanel> createState() => _SymbolLibPanelState();
}
/// 面板状态:记录当前展开的分类(同时只允许一个)。
class _SymbolLibPanelState extends State<_SymbolLibPanel> {
String? _openCategory;
/// 构建。
@override
Widget build(BuildContext context) {
final Tokens t = context.tok;
final AppController c = widget.controller;
final Map<String, List<LibSymbol>> groups = <String, List<LibSymbol>>{};
for (final LibSymbol s in SymbolCache.all) {
groups.putIfAbsent(s.category, () => <LibSymbol>[]).add(s);
}
final List<String> cats = groups.keys.toList();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text('图元库(可扩展)',
style: TextStyle(color: t.dim, fontSize: 10)),
const Spacer(),
InkWell(
onTap: () => _symImport(context, c),
borderRadius: BorderRadius.circular(6),
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
child: Text('导入图元…',
style: TextStyle(
color: t.accent,
fontSize: 10.5,
fontWeight: FontWeight.w600)),
),
),
],
),
const SizedBox(height: 4),
for (final String cat in cats) ...<Widget>[
InkWell(
onTap: () => setState(() =>
_openCategory = _openCategory == cat ? null : cat),
borderRadius: BorderRadius.circular(7),
child: Container(
padding:
const EdgeInsets.symmetric(horizontal: 8, vertical: 5),
margin: const EdgeInsets.only(bottom: 3),
decoration: BoxDecoration(
color: _openCategory == cat
? t.accent.withValues(alpha: 0.10)
: t.panel2,
borderRadius: BorderRadius.circular(7),
border: Border.all(
color: _openCategory == cat
? t.accent.withValues(alpha: 0.5)
: t.line,
),
),
child: Row(
children: <Widget>[
Icon(
_openCategory == cat
? Icons.expand_less
: Icons.expand_more,
size: 15,
color: _openCategory == cat ? t.accent : t.sub,
),
const SizedBox(width: 6),
Expanded(
child: Text(
'$cat(${groups[cat]!.length})',
style: TextStyle(
color: _openCategory == cat ? t.accent : t.sub,
fontSize: 11,
fontWeight: _openCategory == cat
? FontWeight.w700
: FontWeight.w500,
),
),
),
],
),
),
),
if (_openCategory == cat)
Padding(
padding: const EdgeInsets.only(left: 6, right: 2, bottom: 4),
child: Wrap(
spacing: 6,
runSpacing: 6,
children: <Widget>[
for (final LibSymbol sym in groups[cat]!) _symCard(t, c, sym),
],
),
),
],
const SizedBox(height: 4),
SizedBox(
width: double.infinity,
child: OutlinedButton.icon(
onPressed:
c.archSelIds.isEmpty ? null : () => _symFromSelection(context, c),
icon: const Icon(Icons.add_box_outlined, size: 15),
label: const Text('从选中图形存为图元'),
style: OutlinedButton.styleFrom(
visualDensity: VisualDensity.compact,
textStyle: const TextStyle(
fontSize: 11.5,
fontFamily: 'Microsoft YaHei UI',
fontFamilyFallback: <String>[
'Microsoft YaHei',
'Segoe UI',
'sans-serif',
],
),
),
),
),
],
);
}
}
/// 图元卡片(预览 + 名称;用户图元带删除角标)。
Widget _symCard(Tokens t, AppController c, LibSymbol sym) {
final bool user = !SymbolLibrary.isBuiltinId(sym.id);
return InkWell(
onTap: () => _insertSymbolShape(c, sym),
borderRadius: BorderRadius.circular(9),
child: Container(
width: 82,
height: 64,
decoration: BoxDecoration(
color: t.panel2,
borderRadius: BorderRadius.circular(9),
border: Border.all(color: t.line),
),
child: Stack(
children: <Widget>[
Positioned.fill(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: 34,
height: 30,
child: CustomPaint(
painter: _SymPreviewPainter(sym, t.sub),
),
),
const SizedBox(height: 2),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 3),
child: Text(
sym.name,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(color: t.sub, fontSize: 9.5),
),
),
],
),
),
if (user)
Positioned(
right: 0,
top: 0,
child: InkWell(
onTap: () => _symDelete(c, sym),
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.all(3),
child: Icon(Icons.close, size: 12, color: t.dim),
),
),
),
],
),
),
);
}
/// 插入图元库符号(保持图元纵横比,位置在视口中心、可吸附网格)。
void _insertSymbolShape(AppController c, LibSymbol sym) {
final ArchDoc doc = c.arch;
final Size vp = c.archViewport;
final Offset center = vp.width < 10 || vp.height < 10
? const Offset(400, 300)
: Offset(
(vp.width / 2 - doc.panX) / doc.zoom,
(vp.height / 2 - doc.panY) / doc.zoom,
);
final Rect nat = symbolNaturalBounds(sym);
final double scale = 140 / math.max(nat.width, nat.height);
Rect r = Rect.fromCenter(
center: center,
width: nat.width * scale,
height: nat.height * scale,
);
if (doc.gridSnap && doc.gridSize > 1) {
final Offset tl = archSnapPoint(doc, r.topLeft);
r = Rect.fromLTWH(tl.dx, tl.dy, r.width, r.height);
}
final int color = c.archColor;
final ArchShape s = ArchShape(
id: archNewId('S', doc.allIds),
type: ArchShapeType.symbol,
symbolId: sym.id,
rect: r,
fill: archFillOf(color),
stroke: color,
sw: 1.8,
);
c.addArchShape(s);
c.selectArch(s.id);
}
/// 删除用户图元(内置图元不可删)。
Future<void> _symDelete(AppController c, LibSymbol sym) async {
await SymbolLibrary.deleteUser(sym.id);
await SymbolCache.refresh();
c.setStatus('已删除图元「${sym.name}」');
}
/// 导入图元文件(`*.symbol.json`;桌面文件浏览器 / 安卓公共目录)。
Future<void> _symImport(BuildContext context, AppController c) async {
try {
String content;
if (AndroidDocs.isAvailable) {
final String? name = await showDialog<String>(
context: context,
builder: (_) => const AndroidFileDialog(
saveMode: false,
defaultName: '',
suffix: '.symbol.json',
),
);
if (name == null) return;
final Uint8List? bytes = await AndroidDocs.readFile(name);
if (bytes == null) {
c.setStatus('导入失败:未找到文件 $name');
return;
}
content = utf8.decode(bytes);
} else {
final String? path = await pickFile(
context,
save: false,
suffix: '.symbol.json',
);
if (path == null) return;
content = await File(path).readAsString();
}
final LibSymbol sym =
LibSymbol.fromJson(jsonDecode(content) as Map<String, dynamic>);
if (sym.id.isEmpty || sym.prims.isEmpty) {
c.setStatus('导入失败:不是有效的图元文件');
return;
}
await SymbolLibrary.saveUser(sym);
await SymbolCache.refresh();
c.setStatus('已导入图元「${sym.name}」(${sym.category})');
} catch (e) {
c.setStatus('导入失败:$e');
}
}
/// 把当前选中的图形保存为图元(可多选;几何按选中范围归一化到 100×100)。
Future<void> _symFromSelection(BuildContext context, AppController c) async {
final List<ArchShape> sel = <ArchShape>[
for (final String id in c.archSelIds)
if (c.arch.shapeById(id) != null) c.arch.shapeById(id)!,
];
if (sel.isEmpty) {
c.setStatus('先选中要保存为图元的图形(可多选)');
return;
}
final String? name = await showTextEditDialog(
context,
title: '保存为图元(名称)',
initial: '自定义图元',
);
if (name == null || name.trim().isEmpty) return;
final LibSymbol sym = _symbolFromShapes(sel, name.trim());
await SymbolLibrary.saveUser(sym);
await SymbolCache.refresh();
c.setStatus('已保存图元「${sym.name}」到图元库(可点击插入 / 手绘识别)');
}
/// 由图形集合生成图元(采样轮廓为折线 + 文本)。
LibSymbol _symbolFromShapes(List<ArchShape> shapes, String name) {
Rect union = shapes.first.bounds;
for (final ArchShape s in shapes) {
union = union.expandToInclude(s.bounds);
}
final double scale = 100 / math.max(union.width, union.height);
final Offset c0 = union.center;
Offset norm(Offset p) =>
Offset((p.dx - c0.dx) * scale + 50, (p.dy - c0.dy) * scale + 50);
final List<SymPrim> prims = <SymPrim>[];
for (final ArchShape s in shapes) {
final Path path = archShapePath(s);
for (final PathMetric m in path.computeMetrics()) {
final int count =
math.max(6, (m.length * scale / 5).ceil()).clamp(6, 160);
final List<double> flat = <double>[];
for (int i = 0; i <= count; i++) {
final Tangent? t = m.getTangentForOffset(m.length * i / count);
if (t == null) continue;
final Offset n2 = norm(t.position);
flat.add(n2.dx);
flat.add(n2.dy);
}
if (flat.length >= 4) {
prims.add(SymPrim(kind: SymPrimKind.polyline, pts: flat));
}
}
if (s.text.isNotEmpty) {
final Offset n2 = norm(s.rect.center);
prims.add(SymPrim(
kind: SymPrimKind.text,
pts: <double>[n2.dx - s.text.length * 2.5, n2.dy - 5],
label: s.text,
));
}
}
return LibSymbol(
id: 'user-${DateTime.now().millisecondsSinceEpoch}',
name: name,
category: '自定义',
prims: prims,
pins: const <SymPin>[],
);
}
-30
View File
@@ -998,19 +998,6 @@ class _ArchViewState extends State<ArchView>
} }
} }
} }
// 尺寸标签:双击进入改值(识别后图形 / 曲线 / 图元可直接编辑尺寸)。
final (ArchShape, ArchDimKind)? dimHit =
archShapeDimHitAt(c.arch, world, c.arch.zoom);
if (dimHit != null) {
final int now = DateTime.now().millisecondsSinceEpoch;
final bool dbl = now - _lastClickMs < 400 &&
(e.localPosition - _lastClickPos).distance < 28;
if (dbl) {
_lastClickMs = 0;
_editDimLabel(dimHit.$1, dimHit.$2);
return;
}
}
final (String?, ArchShape?) hit = _hitTest(world); final (String?, ArchShape?) hit = _hitTest(world);
final String? id = hit.$1; final String? id = hit.$1;
final ArchShape? shape = hit.$2; final ArchShape? shape = hit.$2;
@@ -1585,23 +1572,6 @@ class _ArchViewState extends State<ArchView>
_startConversion(pts, _symbolShapeFor(sym, b), removeIds: removeIds); _startConversion(pts, _symbolShapeFor(sym, b), removeIds: removeIds);
} }
/// 双击尺寸标签:输入数值直接缩放图形(识别后图形 / 曲线 / 图元)。
Future<void> _editDimLabel(ArchShape s, ArchDimKind k) async {
final double cur = archShapeDimValue(s, k);
final String? input = await showTextEditDialog(
context,
title: '编辑${archDimKindLabel(k)}(当前 ${cur.toStringAsFixed(1)} mm)',
initial: cur.toStringAsFixed(1),
);
if (input == null || !mounted) return;
final double? v = double.tryParse(input.trim());
if (v == null || v <= 0) {
c.setStatus('数值无效:请输入正数');
return;
}
c.setArchShapeDim(s.id, k, v);
}
/// 提交手绘:统一按图形识别处理(识别失败保留墨迹),并尝试两笔组合识别。 /// 提交手绘:统一按图形识别处理(识别失败保留墨迹),并尝试两笔组合识别。
void _commitInk(List<Offset> pts) { void _commitInk(List<Offset> pts) {
if (pts.length < 5) return; if (pts.length < 5) return;
+11 -16
View File
@@ -2503,7 +2503,7 @@ class _HelpDialogState extends State<HelpDialog> {
'时序图 · 动作', '时序图 · 动作',
'时序图 · 视图导出', '时序图 · 视图导出',
'架构图 · 绘制识别', '架构图 · 绘制识别',
'架构图 · 尺寸导出', '架构图 · 编辑导出',
'界面与快捷键', '界面与快捷键',
'关于', '关于',
]; ];
@@ -2591,13 +2591,13 @@ class _HelpDialogState extends State<HelpDialog> {
const SizedBox(width: 12), const SizedBox(width: 12),
Container(width: 1, color: t.line2), Container(width: 1, color: t.line2),
const SizedBox(width: 12), const SizedBox(width: 12),
// 右侧:当前分页内容(垂直滚动)。 // 右侧:当前分页内容。
// 每个分页自身就是可滚动列表(_section 返回 ListView),
// 这里不能再套 SingleChildScrollView——无界高度会把内容撑空。
Expanded( Expanded(
child: SingleChildScrollView( child: IndexedStack(
key: ValueKey<int>(_tab), index: _tab,
child: IndexedStack( children: <Widget>[
index: _tab,
children: <Widget>[
// 目标:从首页进入正确模块、理解文档与数据位置。 // 目标:从首页进入正确模块、理解文档与数据位置。
_section(t, <List<String>>[ _section(t, <List<String>>[
<String>['打开软件是空白首页', '软件采用「空白启动」:打开后进入首页(不再直接进时序图)。在首页选择要新建的文档类型,或打开已有文档。'], <String>['打开软件是空白首页', '软件采用「空白启动」:打开后进入首页(不再直接进时序图)。在首页选择要新建的文档类型,或打开已有文档。'],
@@ -2639,21 +2639,17 @@ class _HelpDialogState extends State<HelpDialog> {
_section(t, <List<String>>[ _section(t, <List<String>>[
<String>['工具条怎么用', '架构图顶部工具:选择 / 手绘 / 连线 / 橡皮,旁边是「识别 N」确认按钮(N = 待识别墨迹笔数)。'], <String>['工具条怎么用', '架构图顶部工具:选择 / 手绘 / 连线 / 橡皮,旁边是「识别 N」确认按钮(N = 待识别墨迹笔数)。'],
<String>['手绘识别', '「手绘」工具下按住拖动:松手自动把笔迹扶正为标准图形(矩形 / 圆 / 箭头 / 折线 / 曲线 / 云 / 圆柱……);识别不了的保留为墨迹,可用橡皮擦掉。'], <String>['手绘识别', '「手绘」工具下按住拖动:松手自动把笔迹扶正为标准图形(矩形 / 圆 / 箭头 / 折线 / 曲线 / 云 / 圆柱……);识别不了的保留为墨迹,可用橡皮擦掉。'],
<String>['多笔组合识别', '支持两笔组合(如两笔试画一个矩形)、圆柱拼接(顶盖 + 柱体);与上一笔刚生成的图形也能在 2.5 秒内合并成图元(如 圆 + 叉 = 指示灯)。'], <String>['多笔组合识别', '支持两笔组合(如两笔试画一个矩形)、圆柱拼接(顶盖 + 柱体);与上一笔刚生成的图形也能在 2.5 秒内合并。'],
<String>['平板手写总识别不准', '左栏「手绘识别」关闭「松手自动识别」(安卓默认关闭):笔迹先保留为墨迹,画完点顶部「识别(N)」按钮统一确认,识别更从容。'], <String>['平板手写总识别不准', '左栏「手绘识别」关闭「松手自动识别」(安卓默认关闭):笔迹先保留为墨迹,画完点顶部「识别(N)」按钮统一确认,识别更从容。'],
<String>['图元库(可扩展)', '左栏「图元库」按分类折叠(默认收起,只展开选中的库):点图元即插入画布(保持比例、自动吸附网格)。内置电气图元与 IT 图元(服务器 / 客户端 / 移动端 / 防火墙 / 交换机 / 消息队列)。'], <String>['图形库', '左栏「图形库」内置标准图形(矩形 / 圆角矩形 / 椭圆 / 圆 / 三角 / 菱形 / 六边形 / 圆柱 / 云)与 IT 图元(服务器 / 客户端 / 移动端 / 防火墙 / 交换机 / 消息队列),点一下即插入画布。'],
<String>['自定义图元', '「导入图元…」读取 *.symbol.json(可分享给同事);「从选中图形存为图元」把画布上的图形(可多选)保存进图元库;用户图元带 × 可删除。'],
<String>['手绘识别能用图元库吗', '能:内置识别不了的笔迹会与图元库轮廓匹配——库里有什么,就能手绘识别出什么。'],
<String>['橡皮', '「橡皮」工具:拖过图形 / 墨迹 / 连线即擦除;一次连续擦除算一步撤销(Ctrl+Z 可整段回退)。'], <String>['橡皮', '「橡皮」工具:拖过图形 / 墨迹 / 连线即擦除;一次连续擦除算一步撤销(Ctrl+Z 可整段回退)。'],
<String>['文字怎么输入', '双击图形 → 编辑图形文字;双击连线 → 编辑标签;双击空白 → 新建文本(输入法直接打字)。'], <String>['文字怎么输入', '双击图形 → 编辑图形文字;双击连线 → 编辑标签;双击空白 → 新建文本(输入法直接打字)。'],
<String>['图层', '左栏「图层」:新建 / 可见(眼睛)/ 锁定(锁)/ 颜色 / 双击改名。隐藏图层不绘制不可选;锁定图层可见但不可选(仍可作吸附参照)。'], <String>['图层', '左栏「图层」:新建 / 可见(眼睛)/ 锁定(锁)/ 颜色 / 双击改名。隐藏图层不绘制不可选;锁定图层可见但不可选(仍可作吸附参照)。'],
<String>['标尺与辅助', '四边标尺单位固定为 mm(垂直轴数值在右侧);F8 正交移动 / F10 极轴追踪(角度在左栏设置);支持网格吸附与磁力对齐线。'], <String>['标尺与辅助', '四边标尺单位固定为 mm(垂直轴数值在右侧);F8 正交移动 / F10 极轴追踪(角度在左栏设置);支持网格吸附与磁力对齐线。'],
<String>['默认图纸', '新建架构图的画布为 A0 图纸(1189×841 mm,1 世界单位 = 1 mm),自动适配视口;画布上绘制浅色 A0 边界。'], <String>['默认图纸', '新建架构图的画布为 A0 图纸(1189×841 mm,1 世界单位 = 1 mm),自动适配视口;画布上绘制浅色 A0 边界。'],
]), ]),
// 目标:架构图尺寸标注、编辑操作与导出。 // 目标:架构图编辑操作与导出。
_section(t, <List<String>>[ _section(t, <List<String>>[
<String>['给图形标尺寸(mm)', '选中图形 / 曲线 / 图元 → 右栏「尺寸 · mm」区:宽度 / 高度 / 长度 / 直径(按类型给出)点数值直接输入新值,几何按比例缩放(中心保持),无需草图约束。'],
<String>['画布上显示尺寸', '尺寸区右上角「标注全部 / 清除标注」一键开关;开启后画布上显示 W / H / L / ⌀ 标签(屏幕字号恒定),双击标签即可改值。'],
<String>['连线规则', '连线一律正交(横平竖直),不会出现斜线;端点自动吸附图形边框,选中后拖拽路径上的角点可调整走线位置;端点也可拖到别的图形重新吸附或脱离。'], <String>['连线规则', '连线一律正交(横平竖直),不会出现斜线;端点自动吸附图形边框,选中后拖拽路径上的角点可调整走线位置;端点也可拖到别的图形重新吸附或脱离。'],
<String>['对齐 / 均布', '框选或 Ctrl 多选后,右栏出现 8 个对齐按钮:左 / 横向居中 / 右、顶 / 纵向居中 / 底、横向均布、纵向均布(以选中范围为参照,均布需 ≥3 个)。'], <String>['对齐 / 均布', '框选或 Ctrl 多选后,右栏出现 8 个对齐按钮:左 / 横向居中 / 右、顶 / 纵向居中 / 底、横向均布、纵向均布(以选中范围为参照,均布需 ≥3 个)。'],
<String>['层级 / 复制 / 删除', '选中后右栏可「上移一层 / 下移一层」;拖拽移动、白色手柄缩放;Delete 删除选中;Ctrl+A 全选。'], <String>['层级 / 复制 / 删除', '选中后右栏可「上移一层 / 下移一层」;拖拽移动、白色手柄缩放;Delete 删除选中;Ctrl+A 全选。'],
@@ -2674,8 +2670,7 @@ class _HelpDialogState extends State<HelpDialog> {
]), ]),
// 关于:设计人、版本、版权、授权信息与本机 MAC。 // 关于:设计人、版本、版权、授权信息与本机 MAC。
_about(context, t), _about(context, t),
], ],
),
), ),
), ),
], ],
+17 -2
View File
@@ -25,6 +25,7 @@ class HomeView extends StatefulWidget {
required this.onOpenRecent, required this.onOpenRecent,
required this.onOpenSettings, required this.onOpenSettings,
required this.onOpenHelp, required this.onOpenHelp,
required this.onCheckUpdate,
}); });
/// 全局控制器(只读展示用)。 /// 全局控制器(只读展示用)。
@@ -45,6 +46,9 @@ class HomeView extends StatefulWidget {
/// 帮助中心。 /// 帮助中心。
final VoidCallback onOpenHelp; final VoidCallback onOpenHelp;
/// 检查更新(真实按钮:检查中 / 已是最新 / 发现新版本都有明确反馈)。
final VoidCallback onCheckUpdate;
/// 创建状态。 /// 创建状态。
@override @override
State<HomeView> createState() => _HomeViewState(); State<HomeView> createState() => _HomeViewState();
@@ -210,7 +214,12 @@ class _HomeViewState extends State<HomeView> {
const SizedBox(width: 8), const SizedBox(width: 8),
_iconAction(t, Icons.help_outline, '帮助中心', widget.onOpenHelp), _iconAction(t, Icons.help_outline, '帮助中心', widget.onOpenHelp),
const SizedBox(width: 8), const SizedBox(width: 8),
UpdateIcon(size: 36, color: t.sub), _iconActionIcon(
t,
'检查更新',
widget.onCheckUpdate,
UpdateIcon(size: 22, color: t.sub),
),
], ],
); );
} }
@@ -218,6 +227,12 @@ class _HomeViewState extends State<HomeView> {
/// 圆形图标按钮(触屏 ≥ 44px 点按区)。 /// 圆形图标按钮(触屏 ≥ 44px 点按区)。
Widget _iconAction( Widget _iconAction(
Tokens t, IconData icon, String tip, VoidCallback onTap) { Tokens t, IconData icon, String tip, VoidCallback onTap) {
return _iconActionIcon(t, tip, onTap, Icon(icon, size: 20, color: t.sub));
}
/// 圆形按钮(自定义内容):与 [_iconAction] 同尺寸同风格。
Widget _iconActionIcon(
Tokens t, String tip, VoidCallback onTap, Widget child) {
return Tooltip( return Tooltip(
message: tip, message: tip,
child: InkWell( child: InkWell(
@@ -232,7 +247,7 @@ class _HomeViewState extends State<HomeView> {
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
border: Border.all(color: t.line), border: Border.all(color: t.line),
), ),
child: Icon(icon, size: 20, color: t.sub), child: child,
), ),
), ),
); );
+5 -5
View File
@@ -120,11 +120,11 @@ class _UpdateDialogState extends State<UpdateDialog> {
// 兼容两种打包方式:zip 根目录即程序文件,或多包一层 dist/。 // 兼容两种打包方式:zip 根目录即程序文件,或多包一层 dist/。
String srcDir = extractDir; String srcDir = extractDir;
if (!File('$extractDir\\sequence_diagram.exe').existsSync()) { if (!File('$extractDir\\EasyDesignCollection.exe').existsSync()) {
if (File('$extractDir\\dist\\sequence_diagram.exe').existsSync()) { if (File('$extractDir\\dist\\EasyDesignCollection.exe').existsSync()) {
srcDir = '$extractDir\\dist'; srcDir = '$extractDir\\dist';
} else { } else {
throw Exception('更新包内容不完整(未找到 sequence_diagram.exe)'); throw Exception('更新包内容不完整(未找到 EasyDesignCollection.exe)');
} }
} }
@@ -137,13 +137,13 @@ class _UpdateDialogState extends State<UpdateDialog> {
File(batPath).writeAsStringSync( File(batPath).writeAsStringSync(
'@echo off\r\n' '@echo off\r\n'
':wait\r\n' ':wait\r\n'
'tasklist /fi "IMAGENAME eq sequence_diagram.exe" | find /i "sequence_diagram.exe" >nul\r\n' 'tasklist /fi "IMAGENAME eq EasyDesignCollection.exe" | find /i "EasyDesignCollection.exe" >nul\r\n'
'if not errorlevel 1 (\r\n' 'if not errorlevel 1 (\r\n'
' ping -n 1 -w 600 127.0.0.1 >nul\r\n' ' ping -n 1 -w 600 127.0.0.1 >nul\r\n'
' goto wait\r\n' ' goto wait\r\n'
')\r\n' ')\r\n'
'xcopy /e /i /y /q "%~1\\*" "%~2\\"\r\n' 'xcopy /e /i /y /q "%~1\\*" "%~2\\"\r\n'
'start "" "%~2\\sequence_diagram.exe"\r\n' 'start "" "%~2\\EasyDesignCollection.exe"\r\n'
'del "%~f0"\r\n', 'del "%~f0"\r\n',
flush: true, flush: true,
); );
+1 -1
View File
@@ -48,7 +48,7 @@ class UpdateInfo {
/// 更新说明(Markdown 文本)。 /// 更新说明(Markdown 文本)。
final String notes; final String notes;
/// 安装包文件名(如 `sequence_diagram_android_v1.2.1_release.apk`)。 /// 安装包文件名(如 `EasyDesignCollection_android_v1.3.10_release.apk`)。
final String assetName; final String assetName;
/// 安装包下载地址。 /// 安装包下载地址。
+1 -1
View File
@@ -2,7 +2,7 @@
/// ///
/// 应用内更新检查用它判断服务器发布的版本是否更新; /// 应用内更新检查用它判断服务器发布的版本是否更新;
/// **每次发版必须与 pubspec 同步更新**(见 BUILD-NOTES 的发布流程)。 /// **每次发版必须与 pubspec 同步更新**(见 BUILD-NOTES 的发布流程)。
const String kAppVersion = '1.3.8'; const String kAppVersion = '1.3.10';
/// 是否要求授权(License)才能导出。 /// 是否要求授权(License)才能导出。
/// ///
+1 -1
View File
@@ -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 # 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 # 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. # of the product and file versions while build-number is used as the build suffix.
version: 1.3.8+30 version: 1.3.10+32
environment: environment:
sdk: ^3.13.3 sdk: ^3.13.3
+45
View File
@@ -0,0 +1,45 @@
# V1.3.10 更新内容
> ⚠️ 本次为**应用身份切换版**(包名由 `cc.sincos.sequence_diagram` 换为 `cc.sincos.edc`)——
> 「桌面名称不变」问题的彻底方案。装完请按下方第 1 节操作。新功能仍可能存在较多 bug
> 或问题,欢迎反馈(开发者邮箱 liuyu65@126.com / 微信 online-goose)。
## 1. 「桌面名称不变」——彻底解决(本次核心)
之前版本的安装包内应用名称已多次实测确认为 **EDC|易得设计**,但部分手机桌面
会长期保留旧包身份的图标名(时序图设计)。本次直接**更换应用身份**:
- 安装 1.3.10 时,系统会当作**全新应用**安装 → 桌面出现名为
**EDC|易得设计** 的新图标(新条目,不存在任何旧缓存可继承);
- 旧的「时序图设计」图标:确认新图标可用后**长按卸载**即可
(安装后两个图标可能短暂并存,属正常);
- 你的项目文件保存在公共目录 `Documents/SequenceDiagram`,不受影响;
仅应用内设置(如最近列表)会重置;
- 从 1.3.10 起,之后每次更新都在新身份上**原地覆盖**,不再有名称问题。
## 2. 界面精简(按反馈做减法)
- 移除「尺寸标注 · mm」:右栏尺寸区、画布尺寸标签、双击改值全部去掉;
- 图元库取消自定义(导入 / 存为图元 / 删除)与电气图元条目;
左栏只保留架构图需要的「**图形库**」(标准图形 + IT 图元)。
## 3. 修复
- **帮助中心空白**:上一版改垂直导航时内容区被套了两层滚动容器,导致整页
空白,已修复(帮助内容同步更新为本版功能集);
- **Windows 应用内更新**:更新包校验仍按旧程序名 `sequence_diagram.exe`
查找,会误报「更新包内容不完整」,已改为 `EasyDesignCollection.exe`。
## 4. 更新方式
- 应用内:首页 / 工具栏「检查更新」→ 立即更新
(下载限速 320KB/s,请保持屏幕常亮、网络稳定);
- 手动:Release 页下载 `EasyDesignCollection_android_v1.3.10_release.apk`
或 `EasyDesignCollection_windows_v1.3.10.zip`。
## 5. 复验点
1. 装好后桌面出现 **EDC|易得设计** 新图标(可与旧图标并存,之后卸载旧图标);
2. 帮助中心(F1)左侧导航 7 页均可打开,内容不再空白;
3. 架构图左栏只有「图形库 / 图层 / 连线」等,右栏属性卡无「尺寸 · mm」;
4. 应用内「检查更新」应提示:当前已是最新版本(v1.3.10)。
+32
View File
@@ -0,0 +1,32 @@
# V1.3.9 更新内容
> ⚠️ 1.3.5 大版本的后续修复版。新功能仍可能存在较多 bug 与问题,欢迎反馈
> (开发者邮箱 liuyu65@126.com / 微信 online-goose)。
## 首页「检查更新」按钮修复
- 之前首页右上角是一个**纯图标**(不可点击)——看似"假按钮";现在它是
真正的更新按钮:
- 点击 → 显示「正在检查更新…」;
- 已是最新:弹出提示「当前已是最新版本(vX)」;
- 发现新版本:直接弹出升级对话框(下载 / 安装)。
- 工具栏的更新按钮行为不变(一致)。
## 关于「安卓桌面仍显示旧名称(时序图设计)」
经核查:安装包内应用名称已确认为 **EDC|易得设计**(APK 实测 application-label),
且包名 `cc.sincos.sequence_diagram` 从第一个安卓版本起从未变过——不存在新旧
两个应用并存的情况。如果桌面仍显示旧名,请按下面两步定位:
1. **先确认装的是哪一版**:打开应用 → 首页底部「工程总体设计合集… v1.3.x」,
或「关于」页。若显示的不是 1.3.7+,说明新安装包**实际没有被装上**
(应用内更新流程可能被"安装未知应用"权限拦截),请到 Release 页手动下载
`*.apk` 安装;
2. 若已显示 1.3.9 而桌面名称仍旧:属**桌面启动器标签缓存**——请查看
系统「设置 → 应用 → 找到该应用」确认系统层名称(系统直读安装包,不缓存),
或重启手机 / 卸载后重装一次刷新桌面。
## 其它(如未更新过请一并获取)
- 帮助中心垂直导航、连线端点捕捉稳定(1.3.8);
- 安卓 logo 按钮等高同形、「识别」只识别当前墨迹、「尺寸 · mm」置顶(1.3.7)。
+7 -16
View File
@@ -1,4 +1,4 @@
// 架构图属性面板回归:选中图形后「尺寸 · mm」可见、可改值驱动几何。 // 架构图属性面板回归:选中图元后显示基本信息;已移除的「尺寸标注」不再出现。
import 'package:flutter/material.dart' hide Action; import 'package:flutter/material.dart' hide Action;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:sequence_diagram/arch/arch_models.dart'; import 'package:sequence_diagram/arch/arch_models.dart';
@@ -8,7 +8,7 @@ import 'package:sequence_diagram/theme/tokens.dart';
import 'package:sequence_diagram/ui/arch_panel.dart'; import 'package:sequence_diagram/ui/arch_panel.dart';
void main() { void main() {
testWidgets('选中图元后右栏出现「尺寸 · mm」,改值直接缩放几何', testWidgets('选中图元:属性卡正常显示,且不再有「尺寸 · mm」区',
(WidgetTester tester) async { (WidgetTester tester) async {
final AppController c = AppController(project: Project.demo()); final AppController c = AppController(project: Project.demo());
c.addArchShape(const ArchShape( c.addArchShape(const ArchShape(
@@ -26,21 +26,12 @@ void main() {
)); ));
await tester.pump(); await tester.pump();
expect(find.textContaining('尺寸 · mm'), findsOneWidget); // 属性卡正常渲染(图元类型中文名)。
expect(find.textContaining('标注全部'), findsOneWidget); expect(find.textContaining('图元'), findsWidgets);
expect(find.text('80.0 mm'), findsOneWidget); // 已移除:尺寸标注区不存在。
expect(find.text('150.0 mm'), findsOneWidget); expect(find.textContaining('尺寸 · mm'), findsNothing);
// 点宽度值 → 弹出改值对话框 → 输入 160 → 几何宽变 160。 // 清理:先卸载组件树,再释放控制器。
await tester.tap(find.text('80.0 mm'));
await tester.pumpAndSettle();
expect(find.textContaining('编辑宽度'), findsOneWidget);
await tester.enterText(find.byType(TextField), '160');
await tester.tap(find.text('确定'));
await tester.pumpAndSettle();
expect(c.arch.shapeById('S1')!.rect.width, 160);
// 清理:先卸载组件树,再释放控制器(避免已释放断言)。
await tester.pumpWidget(const SizedBox()); await tester.pumpWidget(const SizedBox());
c.dispose(); c.dispose();
}); });
-36
View File
@@ -1,5 +1,4 @@
// 图元库手绘识别测试:内置符号笔迹命中、乱涂拒绝、自定义图元可识别。 // 图元库手绘识别测试:内置符号笔迹命中、乱涂拒绝、自定义图元可识别。
import 'dart:io';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -108,41 +107,6 @@ void main() {
); );
}); });
test('自定义图元:保存到用户目录后能被识别', () async {
final Directory tmp = await Directory.systemTemp.createTemp('edc-symr-');
addTearDown(() async => tmp.delete(recursive: true));
// 自定义三角形图元。
await SymbolLibrary.saveUser(
const LibSymbol(
id: 'my-tri',
name: '自定义三角',
category: '自定义',
prims: <SymPrim>[
SymPrim(
kind: SymPrimKind.polyline,
pts: <double>[50, 10, 90, 80, 10, 80, 50, 10],
),
],
pins: <SymPin>[],
),
dir: tmp,
);
final List<LibSymbol> catalog = await SymbolLibrary.all(dir: tmp);
final ArchSymbolMatch? m = recognizeArchSymbol(
<List<Offset>>[
<Offset>[
const Offset(50, 10),
const Offset(90, 80),
const Offset(10, 80),
const Offset(50, 10),
],
],
catalog,
);
expect(m, isNotNull, reason: '自定义图元应能被识别(图元库可扩展)');
expect(m!.symbol.id, 'my-tri');
});
test('空 / 过短笔迹:null', () { test('空 / 过短笔迹:null', () {
expect(recognizeArchSymbol(const <List<Offset>>[], SymbolLibrary.builtin), isNull); expect(recognizeArchSymbol(const <List<Offset>>[], SymbolLibrary.builtin), isNull);
expect( expect(
+1 -81
View File
@@ -658,87 +658,7 @@ void main() {
}); });
}); });
group('尺寸编辑(识别后图形)', () { group('默认画布', () {
test('矩形宽 / 圆直径:直接缩放且中心保持', () {
const ArchShape rect = ArchShape(
id: 'D1',
type: ArchShapeType.rect,
rect: Rect.fromLTWH(100, 100, 200, 120),
);
final ArchShape w = archShapeApplyDim(rect, ArchDimKind.width, 300);
expect(w.rect.width, 300);
expect(w.rect.center, rect.rect.center);
expect(w.rect.height, 120);
final ArchShape c = archShapeApplyDim(
const ArchShape(
id: 'D2',
type: ArchShapeType.circle,
rect: Rect.fromLTWH(0, 0, 80, 80),
),
ArchDimKind.diameter,
120,
);
expect(c.rect.width, 120);
expect(c.rect.height, 120);
});
test('直线 / 曲线长度:按比例缩放保持形状', () {
const ArchShape line = ArchShape(
id: 'L1',
type: ArchShapeType.line,
rect: Rect.fromLTWH(0, 0, 100, 0),
a: Offset(0, 0),
b: Offset(100, 0),
);
expect(archShapeDimValue(line, ArchDimKind.length), 100);
final ArchShape l2 = archShapeApplyDim(line, ArchDimKind.length, 250);
expect(archShapeDimValue(l2, ArchDimKind.length), closeTo(250, 0.01));
expect(l2.rect.center, line.rect.center);
const ArchShape curve = ArchShape(
id: 'C1',
type: ArchShapeType.curve,
rect: Rect.fromLTWH(0, 0, 100, 50),
pts: <Offset>[Offset(0, 0), Offset(100, 0), Offset(100, 50)],
);
expect(archShapeLength(curve), closeTo(150, 0.01));
final ArchShape c2 = archShapeApplyDim(curve, ArchDimKind.length, 300);
expect(archShapeLength(c2), closeTo(300, 0.5));
final Rect b2 = archLinearBounds(c2);
expect(b2.width / b2.height, closeTo(2.0, 0.01));
});
test('尺寸标注 JSON 往返', () {
const ArchShape s = ArchShape(
id: 'S1',
type: ArchShapeType.rect,
rect: Rect.fromLTWH(0, 0, 100, 80),
dims: <ArchDimKind>{ArchDimKind.width, ArchDimKind.height},
);
final ArchShape back = ArchShape.fromJson(
jsonDecode(jsonEncode(s.toJson())) as Map<String, dynamic>);
expect(back.dims.contains(ArchDimKind.width), isTrue);
expect(back.dims.contains(ArchDimKind.height), isTrue);
});
test('控制器:改值缩放 + 标注开关', () {
final AppController c = AppController(project: Project.demo());
addTearDown(c.dispose);
c.addArchShape(const ArchShape(
id: 'S1',
type: ArchShapeType.rect,
rect: Rect.fromLTWH(10, 10, 100, 60),
));
c.setArchShapeDim('S1', ArchDimKind.width, 260);
expect(c.arch.shapeById('S1')!.rect.width, 260);
c.toggleArchShapeDim('S1', ArchDimKind.width);
expect(
c.arch.shapeById('S1')!.dims.contains(ArchDimKind.width), isTrue);
c.toggleArchShapeDim('S1', ArchDimKind.width);
expect(
c.arch.shapeById('S1')!.dims.contains(ArchDimKind.width), isFalse);
});
test('默认画布 A0:空文档内容边界 1189×841', () { test('默认画布 A0:空文档内容边界 1189×841', () {
final Rect b = ArchDoc.empty.contentBounds(); final Rect b = ArchDoc.empty.contentBounds();
expect(b.width, 1189); expect(b.width, 1189);
+28
View File
@@ -0,0 +1,28 @@
// 帮助中心回归:垂直导航正常渲染、可切换分页,内容不为空。
import 'package:flutter/material.dart' hide Action;
import 'package:flutter_test/flutter_test.dart';
import 'package:sequence_diagram/theme/tokens.dart';
import 'package:sequence_diagram/ui/dialogs.dart';
void main() {
testWidgets('帮助中心:垂直导航 + 内容非空 + 可切到「关于」', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
theme: buildTheme(Tokens.light),
home: const Scaffold(body: HelpDialog()),
));
await tester.pump();
// 左侧垂直导航:分页标题可见。
expect(find.text('首页与模块'), findsOneWidget);
expect(find.text('架构图 · 绘制识别'), findsOneWidget);
expect(find.text('关于'), findsOneWidget);
// 内容区非空:首个分页的问答项存在(IndexedStack 全部子页在树中)。
expect(find.text('打开软件是空白首页'), findsOneWidget);
// 切到「关于」分页:不应抛异常,且关于页内容在树中。
await tester.tap(find.text('关于'));
await tester.pumpAndSettle();
expect(find.textContaining('EDC|易得设计'), findsWidgets);
});
}
-6
View File
@@ -126,12 +126,6 @@ ArchDoc makeArch() => ArchDoc(
symbolId: ArchShapeType.values[i] == ArchShapeType.symbol symbolId: ArchShapeType.values[i] == ArchShapeType.symbol
? 'pe-ground' ? 'pe-ground'
: '', : '',
dims: i == 0
? const <ArchDimKind>{
ArchDimKind.width,
ArchDimKind.height,
}
: const <ArchDimKind>{},
), ),
], ],
strokes: const <ArchStroke>[ strokes: const <ArchStroke>[
-47
View File
@@ -1,5 +1,4 @@
// 图元库测试:内置符号完整性、JSON 往返、用户目录存取与合并覆盖、坐标换算。 // 图元库测试:内置符号完整性、JSON 往返、用户目录存取与合并覆盖、坐标换算。
import 'dart:io';
import 'dart:ui' show Path, Rect; import 'dart:ui' show Path, Rect;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
@@ -57,50 +56,4 @@ void main() {
expect(b.top, closeTo(20, 0.01)); expect(b.top, closeTo(20, 0.01));
expect(b.bottom, closeTo(220, 0.01)); expect(b.bottom, closeTo(220, 0.01));
}); });
test('用户目录存取 / 删除 / all() 合并与覆盖', () async {
final Directory tmp = await Directory.systemTemp.createTemp('edc-sym-');
addTearDown(() async => tmp.delete(recursive: true));
expect(await SymbolLibrary.loadUser(dir: tmp), isEmpty);
const LibSymbol custom = LibSymbol(
id: 'my-sym',
name: '自定义符号',
category: '自定义',
prims: <SymPrim>[
SymPrim(kind: SymPrimKind.circle, pts: <double>[50, 50], r: 30),
],
pins: <SymPin>[SymPin(id: '1', x: 50, y: 0)],
);
await SymbolLibrary.saveUser(custom, dir: tmp);
final List<LibSymbol> loaded = await SymbolLibrary.loadUser(dir: tmp);
expect(loaded.single.id, 'my-sym');
final List<LibSymbol> merged = await SymbolLibrary.all(dir: tmp);
expect(merged.length, SymbolLibrary.builtin.length + 1);
// 用户符号覆盖同名内置 id。
await SymbolLibrary.saveUser(
const LibSymbol(
id: 'motor-m',
name: '电机(自定义)',
category: '自定义',
prims: <SymPrim>[
SymPrim(kind: SymPrimKind.rect, pts: <double>[20, 20, 60, 60]),
],
pins: <SymPin>[SymPin(id: '1', x: 50, y: 0)],
),
dir: tmp,
);
final List<LibSymbol> merged2 = await SymbolLibrary.all(dir: tmp);
expect(merged2.length, SymbolLibrary.builtin.length + 1);
expect(
merged2.firstWhere((LibSymbol s) => s.id == 'motor-m').name,
'电机(自定义)',
);
await SymbolLibrary.deleteUser('my-sym', dir: tmp);
await SymbolLibrary.deleteUser('motor-m', dir: tmp);
expect(await SymbolLibrary.loadUser(dir: tmp), isEmpty);
});
} }