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;