feat: depth-limited tree display for performance
- MaxFullDisplayDepth=2: only show full tree up to level 2 - Beyond max depth, nodes only expand if they have an alias - AliasNodeViewModel.Depth tracks tree depth - Reduces loaded nodes for large models with deep unaliased branches
This commit is contained in:
parent
7418fe28aa
commit
cba8e3f3b7
@ -97,6 +97,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
set { _childCount = value; OnPropertyChanged(nameof(ChildCount)); OnPropertyChanged(nameof(HasChildren)); }
|
||||
}
|
||||
|
||||
/// <summary>树深度(0=根)</summary>
|
||||
public int Depth { get; set; }
|
||||
|
||||
/// <summary>是否有子节点</summary>
|
||||
public bool HasChildren => ChildCount > 0;
|
||||
|
||||
|
||||
@ -33,6 +33,9 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
private Autodesk.Navisworks.Api.ModelItem _currentSelectionItem;
|
||||
private bool _built = false;
|
||||
|
||||
/// <summary>完整展示的最大层级深度(默认2层)</summary>
|
||||
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
|
||||
/// 递归构建节点树(主线程调用)
|
||||
/// </summary>
|
||||
private AliasNodeViewModel BuildNode(Autodesk.Navisworks.Api.ModelItem modelItem,
|
||||
Dictionary<string, string> aliasMap)
|
||||
Dictionary<string, string> 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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user