diff --git a/src/UI/WPF/ViewModels/AliasNodeViewModel.cs b/src/UI/WPF/ViewModels/AliasNodeViewModel.cs index 7108813..d44a656 100644 --- a/src/UI/WPF/ViewModels/AliasNodeViewModel.cs +++ b/src/UI/WPF/ViewModels/AliasNodeViewModel.cs @@ -97,6 +97,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels set { _childCount = value; OnPropertyChanged(nameof(ChildCount)); OnPropertyChanged(nameof(HasChildren)); } } + /// 树深度(0=根) + public int Depth { get; set; } + /// 是否有子节点 public bool HasChildren => ChildCount > 0; diff --git a/src/UI/WPF/Views/AliasTreeControl.xaml.cs b/src/UI/WPF/Views/AliasTreeControl.xaml.cs index b7ccc2e..b8ba86b 100644 --- a/src/UI/WPF/Views/AliasTreeControl.xaml.cs +++ b/src/UI/WPF/Views/AliasTreeControl.xaml.cs @@ -33,6 +33,9 @@ namespace NavisworksTransport.UI.WPF.Views private Autodesk.Navisworks.Api.ModelItem _currentSelectionItem; private bool _built = false; + /// 完整展示的最大层级深度(默认2层) + public int MaxFullDisplayDepth { get; set; } = 2; + // ============================================================ // 生命周期 // ============================================================ @@ -278,7 +281,7 @@ namespace NavisworksTransport.UI.WPF.Views var rootItem = model.RootItem; if (rootItem != null) { - var node = BuildNode(rootItem, aliasMap); + var node = BuildNode(rootItem, aliasMap, 0); if (node != null) rootNodes.Add(node); } @@ -299,7 +302,7 @@ namespace NavisworksTransport.UI.WPF.Views /// 递归构建节点树(主线程调用) /// private AliasNodeViewModel BuildNode(Autodesk.Navisworks.Api.ModelItem modelItem, - Dictionary aliasMap) + Dictionary aliasMap, int depth) { if (modelItem == null) return null; @@ -321,13 +324,18 @@ namespace NavisworksTransport.UI.WPF.Views ModelItem = modelItem, OriginalName = modelItem.DisplayName ?? "?", Alias = alias, - ChildCount = modelItem.Children.Count() + ChildCount = modelItem.Children.Count(), + Depth = depth }; _nodeMap[key] = node; - // 第一层放占位节点以显示展开箭头 - if (node.ChildCount > 0) + // 深度限制:超过阈值且无别名 → 不展开子节点 + bool hasChildren = node.ChildCount > 0; + if (hasChildren && depth >= MaxFullDisplayDepth && string.IsNullOrEmpty(alias)) + hasChildren = false; + + if (hasChildren) { node.Children.Add(new AliasNodeViewModel { @@ -361,7 +369,7 @@ namespace NavisworksTransport.UI.WPF.Views foreach (var childItem in item.Children) { - var childNode = BuildNode(childItem, aliasMap); + var childNode = BuildNode(childItem, aliasMap, parentNode.Depth + 1); if (childNode != null) { childNode.Parent = parentNode;