v1.3.11: 全局更名为 EDC|易得; 更新下载屏幕常亮+防误触退出; 连线法向箭头+多线避让+平板拖动优化(线段拖动/磁吸虚线/抓取光标/实时预览)
This commit is contained in:
@@ -40,7 +40,7 @@ Future<Uint8List> renderArchPng({
|
||||
// 标题与副标题(固定左上角)。
|
||||
_text(canvas, '架构图设计', const Offset(48, 36),
|
||||
color: et.text, size: 34, weight: FontWeight.w700);
|
||||
_text(canvas, 'EDC|易得设计 · Easy Design Collection · 手绘识别架构图', const Offset(48, 88),
|
||||
_text(canvas, 'EDC|易得 · Easy Design Collection · 手绘识别架构图', const Offset(48, 88),
|
||||
color: et.sub, size: 16, weight: FontWeight.w400);
|
||||
|
||||
// 内容适配(白底令牌 + 关闭网格点阵)。
|
||||
@@ -56,7 +56,7 @@ Future<Uint8List> renderArchPng({
|
||||
|
||||
_text(
|
||||
canvas,
|
||||
'EDC|易得设计 · 架构图设计 · $projectName · 元件 ${doc.shapes.length} · 连线 '
|
||||
'EDC|易得 · 架构图设计 · $projectName · 元件 ${doc.shapes.length} · 连线 '
|
||||
'${doc.connectors.length} · 墨迹 ${doc.strokes.length}',
|
||||
Offset(48, h - 38),
|
||||
color: et.sub,
|
||||
|
||||
+192
-51
@@ -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<Offset> raw = <Offset>[a];
|
||||
if (c.mids.isNotEmpty) {
|
||||
final List<Offset> raw = orthoPolyline(<Offset>[a, ...c.mids, b]);
|
||||
final List<Offset> clean = <Offset>[];
|
||||
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<Offset> pts = horizontalFirst
|
||||
? <Offset>[a, Offset(b.dx, a.dy), b]
|
||||
: <Offset>[a, Offset(a.dx, b.dy), b];
|
||||
final List<Offset> clean = <Offset>[];
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user