From f38fba6506e13df1367c2e73d4c97bd2e7ae9b99 Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Sat, 6 Jun 2026 10:05:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20DisplayPath=20=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=B1=82=E7=BA=A7=E5=8A=A0#N=E5=8E=BB=E9=87=8D=20+=20=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E6=97=A7=E6=A0=BC=E5=BC=8F=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BuildNode 不再剥离父路径#N后缀 - FromModelItem 对每层祖先计算 siblingIndex 追加#N,与树加载一致 - 解决复制子树中节点别名泄露给其他子树的问题 - FromKey 移除纯 DisplayPath 旧格式兼容 --- src/Core/AliasTree/AliasNodeIdentity.cs | 37 ++++++++--------------- src/UI/WPF/Views/AliasTreeControl.xaml.cs | 8 ----- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src/Core/AliasTree/AliasNodeIdentity.cs b/src/Core/AliasTree/AliasNodeIdentity.cs index 7442ecf..2629728 100644 --- a/src/Core/AliasTree/AliasNodeIdentity.cs +++ b/src/Core/AliasTree/AliasNodeIdentity.cs @@ -17,9 +17,6 @@ namespace NavisworksTransport.Core.AliasTree /// 可读可调试,IndexPath 失效时作为降级定位手段。 /// /// 序列化格式(ToKey): "IndexPath||DisplayPath" - /// 示例: "0,2,5,1||模型/楼层/墙#0" - /// - /// 向后兼容:不含 "||" 的 key 按旧格式(纯 DisplayPath)解析。 /// public readonly struct AliasNodeIdentity : IEquatable { @@ -66,22 +63,17 @@ namespace NavisworksTransport.Core.AliasTree indexPath = string.Empty; } - // 2. DisplayPath — 父链 DisplayName + 同级索引 + // 2. DisplayPath — 父链 DisplayName + 每层同名去重索引 var parts = new List(); var current = item; while (current != null) { - parts.Insert(0, current.DisplayName ?? "?"); + int siblingIdx = ComputeSiblingIndex(current); + string name = current.DisplayName ?? "?"; + parts.Insert(0, siblingIdx > 0 ? $"{name}#{siblingIdx}" : name); current = current.Parent; } - string displayPath = string.Join("/", parts); - - // 3. 同级同名节点去重索引 - int siblingIndex = ComputeSiblingIndex(item); - - string displayPathWithIndex = siblingIndex > 0 - ? $"{displayPath}#{siblingIndex}" - : displayPath; + string displayPathWithIndex = string.Join("/", parts); return new AliasNodeIdentity(indexPath, displayPathWithIndex); } @@ -129,19 +121,16 @@ namespace NavisworksTransport.Core.AliasTree if (string.IsNullOrEmpty(key)) throw new ArgumentException("key 不能为空", nameof(key)); - // 检查是否有双字段分隔符 + // key 必须包含 "||" 分隔符 int separatorIndex = key.IndexOf("||", StringComparison.Ordinal); - if (separatorIndex >= 0) - { - string indexPath = key.Substring(0, separatorIndex); - string displayPath = key.Substring(separatorIndex + 2); - if (string.IsNullOrEmpty(displayPath)) - throw new FormatException($"DisplayPath 为空: {key}"); - return new AliasNodeIdentity(indexPath, displayPath); - } + if (separatorIndex < 0) + throw new FormatException($"key 缺少 || 分隔符: {key}"); - // 向后兼容:纯 DisplayPath 格式(旧数据) - return new AliasNodeIdentity(string.Empty, key); + string indexPath = key.Substring(0, separatorIndex); + string displayPath = key.Substring(separatorIndex + 2); + if (string.IsNullOrEmpty(displayPath)) + throw new FormatException($"DisplayPath 为空: {key}"); + return new AliasNodeIdentity(indexPath, displayPath); } /// diff --git a/src/UI/WPF/Views/AliasTreeControl.xaml.cs b/src/UI/WPF/Views/AliasTreeControl.xaml.cs index 337f27d..999ac38 100644 --- a/src/UI/WPF/Views/AliasTreeControl.xaml.cs +++ b/src/UI/WPF/Views/AliasTreeControl.xaml.cs @@ -355,14 +355,6 @@ namespace NavisworksTransport.UI.WPF.Views string parentPath = parentDisplayPath; int sepIdx = parentPath.IndexOf("||", StringComparison.Ordinal); if (sepIdx >= 0) parentPath = parentPath.Substring(sepIdx + 2); - // 去掉结尾的 #数字 后缀(中间层不加 siblingIndex) - int hashIdx = parentPath.LastIndexOf('#'); - if (hashIdx > 0) - { - string suffix = parentPath.Substring(hashIdx + 1); - bool isNumeric = suffix.Length > 0 && suffix.All(char.IsDigit); - if (isNumeric) parentPath = parentPath.Substring(0, hashIdx); - } string displayPath = string.IsNullOrEmpty(parentPath) ? displayName : parentPath + "/" + displayName;