diff --git a/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl b/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl index 4863a97..b152eb6 100644 Binary files a/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl and b/.serena/cache/csharp/document_symbols_cache_v23-06-25.pkl differ diff --git a/src/Core/FloorAttributeManager.cs b/src/Core/FloorAttributeManager.cs index 047cfea..c261ba8 100644 --- a/src/Core/FloorAttributeManager.cs +++ b/src/Core/FloorAttributeManager.cs @@ -143,6 +143,255 @@ namespace NavisworksTransport.Core } } + + /// + /// 设置单个分层属性,保留其他现有属性 + /// + /// 模型项 + /// 属性类型:楼层、区域、子系统 + /// 属性值 + /// 操作是否成功 + public bool SetSingleLayerAttribute(ModelItem item, string attributeType, string attributeValue) + { + if (item == null || string.IsNullOrEmpty(attributeType) || string.IsNullOrEmpty(attributeValue)) + { + LogManager.Error("[FloorAttributeManager] 设置单个分层属性失败:参数无效"); + return false; + } + + try + { + LogManager.Info($"[FloorAttributeManager] 开始设置模型 {item.DisplayName} 的{attributeType}属性: {attributeValue}"); + + return ExecuteWithUIThread(() => + { + // 获取COM API状态对象 + ComApi.InwOpState10 state = ComApiBridge.State; + + // 转换ModelItem为COM路径 + ComApi.InwOaPath comPath = ComApiBridge.ToInwOaPath(item); + + // 获取属性节点 + ComApi.InwGUIPropertyNode2 propertyNode = + (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(comPath, false); + + // 获取现有的所有分层属性值 + var existingFloorLevel = GetFloorLevelFromProperty(propertyNode); + var existingZone = GetZoneFromProperty(propertyNode); + var existingSubSystem = GetSubSystemFromProperty(propertyNode); + + // 根据属性类型更新对应的值 + string finalFloorLevel = existingFloorLevel; + string finalZone = existingZone; + string finalSubSystem = existingSubSystem; + + switch (attributeType) + { + case "楼层": + finalFloorLevel = attributeValue; + break; + case "区域": + finalZone = attributeValue; + break; + case "子系统": + finalSubSystem = attributeValue; + break; + default: + LogManager.Error($"[FloorAttributeManager] 不支持的属性类型: {attributeType}"); + return false; + } + + // 创建新的属性分类,包含所有属性(现有的+新设置的) + ComApi.InwOaPropertyVec propertyCategory = + (ComApi.InwOaPropertyVec)state.ObjectFactory( + ComApi.nwEObjectType.eObjectType_nwOaPropertyVec, null, null); + + // 添加楼层属性(如果有值) + if (!string.IsNullOrEmpty(finalFloorLevel)) + { + AddFloorProperty(state, propertyCategory, FLOOR_LEVEL_DISPLAY_NAME, + finalFloorLevel, FLOOR_LEVEL_PROPERTY); + } + + // 添加区域属性(如果有值) + if (!string.IsNullOrEmpty(finalZone)) + { + AddFloorProperty(state, propertyCategory, ZONE_DISPLAY_NAME, + finalZone, ZONE_PROPERTY); + } + + // 添加子系统属性(如果有值) + if (!string.IsNullOrEmpty(finalSubSystem)) + { + AddFloorProperty(state, propertyCategory, SUBSYSTEM_DISPLAY_NAME, + finalSubSystem, SUBSYSTEM_PROPERTY); + } + + // 检查是否已存在分层属性,获取正确的索引 + int existingFloorAttributeIndex = GetFloorAttributeIndex(propertyNode); + + if (existingFloorAttributeIndex >= 0) + { + // 存在分层属性时,使用正确的索引进行修改 + int updateIndex = existingFloorAttributeIndex + 1; + propertyNode.SetUserDefined(updateIndex, FLOOR_CATEGORY, FLOOR_CATEGORY_INTERNAL, propertyCategory); + LogManager.Info($"[FloorAttributeManager] ✅ 成功更新{attributeType}属性 (索引={updateIndex})"); + } + else + { + // 不存在分层属性时,使用索引0创建新属性 + propertyNode.SetUserDefined(0, FLOOR_CATEGORY, FLOOR_CATEGORY_INTERNAL, propertyCategory); + LogManager.Info($"[FloorAttributeManager] ✅ 成功创建{attributeType}属性 (索引=0)"); + } + + return true; + }); + } + catch (Exception ex) + { + LogManager.Error($"[FloorAttributeManager] ❌ 设置{attributeType}属性失败,错误: {ex.Message}", ex); + return false; + } + } + + + /// + /// 从属性节点获取楼层属性值 + /// + private string GetFloorLevelFromProperty(ComApi.InwGUIPropertyNode2 propertyNode) + { + try + { + foreach (ComApi.InwGUIAttribute2 attribute in propertyNode.GUIAttributes()) + { + if (attribute.ClassUserName == FLOOR_CATEGORY) + { + foreach (ComApi.InwOaProperty property in attribute.Properties()) + { + if (property.name == FLOOR_LEVEL_PROPERTY) + { + return property.value?.ToString(); + } + } + } + } + } + catch (Exception ex) + { + LogManager.Debug($"[FloorAttributeManager] 获取楼层属性异常: {ex.Message}"); + } + return null; + } + + /// + /// 从属性节点获取区域属性值 + /// + private string GetZoneFromProperty(ComApi.InwGUIPropertyNode2 propertyNode) + { + try + { + foreach (ComApi.InwGUIAttribute2 attribute in propertyNode.GUIAttributes()) + { + if (attribute.ClassUserName == FLOOR_CATEGORY) + { + foreach (ComApi.InwOaProperty property in attribute.Properties()) + { + if (property.name == ZONE_PROPERTY) + { + return property.value?.ToString(); + } + } + } + } + } + catch (Exception ex) + { + LogManager.Debug($"[FloorAttributeManager] 获取区域属性异常: {ex.Message}"); + } + return null; + } + + /// + /// 从属性节点获取子系统属性值 + /// + private string GetSubSystemFromProperty(ComApi.InwGUIPropertyNode2 propertyNode) + { + try + { + foreach (ComApi.InwGUIAttribute2 attribute in propertyNode.GUIAttributes()) + { + if (attribute.ClassUserName == FLOOR_CATEGORY) + { + foreach (ComApi.InwOaProperty property in attribute.Properties()) + { + if (property.name == SUBSYSTEM_PROPERTY) + { + return property.value?.ToString(); + } + } + } + } + } + catch (Exception ex) + { + LogManager.Debug($"[FloorAttributeManager] 获取子系统属性异常: {ex.Message}"); + } + return null; + } + + + /// + /// 获取模型项的区域属性值 + /// + public string GetZoneAttribute(ModelItem item) + { + if (item == null) return null; + + try + { + return ExecuteWithUIThread(() => + { + ComApi.InwOpState10 state = ComApiBridge.State; + ComApi.InwOaPath comPath = ComApiBridge.ToInwOaPath(item); + ComApi.InwGUIPropertyNode2 propertyNode = + (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(comPath, false); + + return GetZoneFromProperty(propertyNode); + }); + } + catch (Exception ex) + { + LogManager.Error($"[FloorAttributeManager] 获取区域属性失败:{ex.Message}", ex); + return null; + } + } + + /// + /// 获取模型项的子系统属性值 + /// + public string GetSubSystemAttribute(ModelItem item) + { + if (item == null) return null; + + try + { + return ExecuteWithUIThread(() => + { + ComApi.InwOpState10 state = ComApiBridge.State; + ComApi.InwOaPath comPath = ComApiBridge.ToInwOaPath(item); + ComApi.InwGUIPropertyNode2 propertyNode = + (ComApi.InwGUIPropertyNode2)state.GetGUIPropertyNode(comPath, false); + + return GetSubSystemFromProperty(propertyNode); + }); + } + catch (Exception ex) + { + LogManager.Error($"[FloorAttributeManager] 获取子系统属性失败:{ex.Message}", ex); + return null; + } + } + /// /// 获取对象的楼层标识,支持继承查询 /// diff --git a/src/Core/MainPlugin.cs b/src/Core/MainPlugin.cs index 1c61c0d..21c6fe4 100644 --- a/src/Core/MainPlugin.cs +++ b/src/Core/MainPlugin.cs @@ -2758,17 +2758,12 @@ namespace NavisworksTransport if (renderPlugin != null) { // 清空所有现有的路径点标记 - renderPlugin.ClearAllMarkers(); + renderPlugin.ClearAllPaths(); - // 绘制选中路径的所有路径点 - var sortedPoints = selectedPath.GetSortedPoints(); - for (int i = 0; i < sortedPoints.Count; i++) - { - var point = sortedPoints[i]; - renderPlugin.AddCircleMarker(point.Position, point.Type, i + 1); - } + // 使用新的统一路径可视化方法 + renderPlugin.RenderPath(selectedPath); - LogManager.Info($"已绘制路径: {selectedPath.Name},包含 {sortedPoints.Count} 个路径点和连线"); + LogManager.Info($"已绘制路径: {selectedPath.Name},包含 {selectedPath.Points.Count} 个路径点和连线"); } else { @@ -2851,7 +2846,7 @@ namespace NavisworksTransport var renderPlugin = PathPointRenderPlugin.Instance; if (renderPlugin != null) { - renderPlugin.ClearAllMarkers(); + renderPlugin.ClearAllPaths(); LogManager.Info("已清空所有路径可视化"); } } diff --git a/src/Core/PathPlanningManager.cs b/src/Core/PathPlanningManager.cs index a736067..5e97fa0 100644 --- a/src/Core/PathPlanningManager.cs +++ b/src/Core/PathPlanningManager.cs @@ -597,7 +597,6 @@ namespace NavisworksTransport if (marker != null) { _pathPointMarkers.Remove(marker); - _renderPlugin?.RemovePathPointMarker(marker); LogManager.Info($"已从3D中移除路径点标记: {point.Name}"); } } @@ -1164,14 +1163,11 @@ namespace NavisworksTransport { lastPoint.Type = PathPointType.EndPoint; lastPoint.Name = GeneratePointName(PathPointType.EndPoint); - + // 更新3D路径可视化 - if (_renderPlugin != null) - { - // 重新渲染整个路径以反映类型变更 - _renderPlugin.RenderPath(CurrentRoute); - } - + // 重新渲染整个路径以反映类型变更 + _renderPlugin?.RenderPath(CurrentRoute); + LogManager.Info($"已自动设置最后一个点为终点: {lastPoint.Name}"); } } @@ -2025,7 +2021,7 @@ namespace NavisworksTransport // 清理资源 if (_renderPlugin != null) { - _renderPlugin.CleanUp(); + _renderPlugin.ClearAllPaths(); _renderPlugin = null; } diff --git a/src/Core/PathPointRenderPlugin.cs b/src/Core/PathPointRenderPlugin.cs index 9710654..9da4063 100644 --- a/src/Core/PathPointRenderPlugin.cs +++ b/src/Core/PathPointRenderPlugin.cs @@ -890,58 +890,6 @@ namespace NavisworksTransport private static DateTime _lastRefreshTime = DateTime.MinValue; #endregion - - #region 兼容性方法 - - /// - /// 清除路径标记(兼容性方法) - /// - public void ClearPathMarkers() - { - ClearAllMarkers(); - } - - /// - /// 移除路径点标记(兼容性方法) - /// - /// 路径点 - /// 是否成功移除 - public bool RemovePathPointMarker(PathPoint pathPoint) - { - if (pathPoint?.Position != null) - { - return RemoveMarkerAt(pathPoint.Position, 1.0); - } - return false; - } - - /// - /// 移除路径点标记(兼容性方法) - /// - /// 路径点标记 - /// 是否成功移除 - public bool RemovePathPointMarker(PathPointMarker marker) - { - if (marker?.PathPoint?.Position != null) - { - return RemoveMarkerAt(marker.PathPoint.Position, 1.0); - } - return false; - } - - #endregion - - #region 清理资源 - - /// - /// 清理资源 - /// - public void CleanUp() - { - ClearAllMarkers(); - } - - #endregion } /// diff --git a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs index d390356..f9409a7 100644 --- a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs @@ -83,6 +83,11 @@ namespace NavisworksTransport.UI.WPF.ViewModels private string _selectedFloorLevel = "F1"; private string _selectedZone = ""; private string _selectedSubSystem = ""; + // 新的分层参数系统相关字段 + private string _selectedLayerParameter = "楼层"; + private string _selectedParameterValue = "F1"; + private bool _showLayerAttributeInfo = false; + private string _currentLayerAttributeInfo = string.Empty; private bool _showFloorAttributeInfo = false; private string _currentFloorAttributeInfo = ""; private bool _showCancelButton = false; @@ -326,6 +331,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels if (SetPropertyThreadSafe(ref _currentSelectionText, value)) { OnPropertyChanged(nameof(HasSelectedItems)); + OnPropertyChanged(nameof(CanSetLayerAttribute)); + OnPropertyChanged(nameof(CanClearLayerAttribute)); } } } @@ -442,6 +449,81 @@ namespace NavisworksTransport.UI.WPF.ViewModels get => _selectedSubSystem; set => SetPropertyThreadSafe(ref _selectedSubSystem, value); } + /// + /// 选中的分层参数类型(楼层、区域、子系统) + /// + public string SelectedLayerParameter + { + get => _selectedLayerParameter; + set + { + if (SetPropertyThreadSafe(ref _selectedLayerParameter, value)) + { + // 当分层参数类型改变时,自动更新参数值为合适的默认值 + switch (value) + { + case "楼层": + SelectedParameterValue = "F1"; + break; + case "区域": + SelectedParameterValue = "北区"; + break; + case "子系统": + SelectedParameterValue = "消防系统"; + break; + default: + SelectedParameterValue = "F1"; + break; + } + + // 通知相关属性更新 + OnPropertyChanged(nameof(CanSetLayerAttribute)); + } + } + } + + /// + /// 分层参数值 + /// + public string SelectedParameterValue + { + get => _selectedParameterValue; + set + { + if (SetPropertyThreadSafe(ref _selectedParameterValue, value)) + { + // 通知相关属性更新 + OnPropertyChanged(nameof(CanSetLayerAttribute)); + } + } + } + + /// + /// 是否显示分层属性信息 + /// + public bool ShowLayerAttributeInfo + { + get => _showLayerAttributeInfo; + set => SetPropertyThreadSafe(ref _showLayerAttributeInfo, value); + } + + /// + /// 当前分层属性信息 + /// + public string CurrentLayerAttributeInfo + { + get => _currentLayerAttributeInfo; + set => SetPropertyThreadSafe(ref _currentLayerAttributeInfo, value); + } + /// + /// 分层参数选项集合 + /// + public ObservableCollection LayerParameterOptions { get; } = new ObservableCollection + { + "楼层", + "区域", + "子系统" + }; /// /// 是否显示楼层属性信息 @@ -487,6 +569,50 @@ namespace NavisworksTransport.UI.WPF.ViewModels { get => HasSelectedModels && !string.IsNullOrEmpty(SelectedFloorLevel) && IsNotProcessing; } + + /// + /// 是否可以设置分层属性 + /// + public bool CanSetLayerAttribute => IsNotProcessing && !string.IsNullOrWhiteSpace(SelectedParameterValue) && HasSelectedItems; + + /// + /// 是否可以清除分层属性 + /// + public bool CanClearLayerAttribute + { + get + { + try + { + if (IsProcessing || !HasSelectedItems) + return false; + + // 检查选中的模型是否有任何分层属性 + var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + if (document?.CurrentSelection?.SelectedItems?.Count > 0) + { + var floorManager = new FloorAttributeManager(); + var selection = document.CurrentSelection.SelectedItems; + + foreach (var item in selection) + { + // 使用GetFloorLevel方法检查是否有楼层属性 + var floorLevel = floorManager.GetFloorLevel(item); + if (!string.IsNullOrEmpty(floorLevel)) + { + return true; + } + } + } + return false; + } + catch (Exception ex) + { + LogManager.Error($"[LayerManagementViewModel] 检查清除分层属性条件异常: {ex.Message}", ex); + return false; + } + } + } /// /// 是否可以清除楼层属性 @@ -553,6 +679,11 @@ namespace NavisworksTransport.UI.WPF.ViewModels public ICommand SetFloorAttributeCommand { get; private set; } public ICommand ClearFloorAttributeCommand { get; private set; } public ICommand ViewFloorAttributeCommand { get; private set; } + + // 新的分层属性命令 + public ICommand SetLayerAttributeCommand { get; private set; } + public ICommand ClearLayerAttributeCommand { get; private set; } + public ICommand ViewLayerAttributeCommand { get; private set; } #endregion @@ -672,6 +803,19 @@ namespace NavisworksTransport.UI.WPF.ViewModels async () => await ViewFloorAttributeAsync(), () => HasSelectedItems); + // 新的分层属性命令初始化 + SetLayerAttributeCommand = new RelayCommand( + async () => await SetLayerAttributeAsync(), + () => CanSetLayerAttribute); + + ClearLayerAttributeCommand = new RelayCommand( + async () => await ClearLayerAttributeAsync(), + () => CanClearLayerAttribute); + + ViewLayerAttributeCommand = new RelayCommand( + async () => await ViewLayerAttributeAsync(), + () => HasSelectedItems); + LogManager.Info("分层管理命令初始化完成 - 使用统一Command Pattern框架"); }, "初始化命令"); } @@ -2200,6 +2344,10 @@ namespace NavisworksTransport.UI.WPF.ViewModels OnPropertyChanged(nameof(CanPreviewSplit)); OnPropertyChanged(nameof(CanExecuteSplit)); OnPropertyChanged(nameof(HasSelectedItems)); + OnPropertyChanged(nameof(CanSetFloorAttribute)); + OnPropertyChanged(nameof(CanClearFloorAttribute)); + OnPropertyChanged(nameof(CanSetLayerAttribute)); + OnPropertyChanged(nameof(CanClearLayerAttribute)); } /// @@ -2667,6 +2815,245 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } + /// + /// 设置分层属性 + /// + private async Task SetLayerAttributeAsync() + { + await SafeExecuteAsync(async () => + { + if (string.IsNullOrWhiteSpace(SelectedParameterValue)) + { + CurrentOperationText = "请输入参数值"; + return; + } + + var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + if (document?.CurrentSelection?.SelectedItems?.Count == 0) + { + CurrentOperationText = "请先选择要设置属性的模型对象"; + return; + } + + IsProcessing = true; + ShowCancelButton = false; + CurrentOperationText = "正在设置分层属性..."; + var totalItems = document.CurrentSelection.SelectedItems.Count; + var processedItems = 0; + + try + { + var floorManager = new FloorAttributeManager(); + var selectedItems = document.CurrentSelection.SelectedItems.ToList(); + + foreach (var item in selectedItems) + { + // 使用新的SetSingleLayerAttribute方法,只设置指定的属性类型 + bool result = floorManager.SetSingleLayerAttribute(item, SelectedLayerParameter, SelectedParameterValue); + + if (result) + { + processedItems++; + } + + ProgressPercentage = (double)processedItems / totalItems * 100; + } + + CurrentOperationText = $"分层属性设置完成,成功设置 {processedItems}/{totalItems} 个对象的{SelectedLayerParameter}属性:{SelectedParameterValue}"; + LogManager.Info($"[LayerManagementViewModel] 成功设置分层属性: {SelectedLayerParameter}={SelectedParameterValue},影响对象数:{processedItems}"); + + // 刷新选中模型信息 + await RefreshSelectionAsync(); + } + catch (Exception ex) + { + LogManager.Error($"[LayerManagementViewModel] 设置分层属性异常: {ex.Message}", ex); + CurrentOperationText = $"设置分层属性时发生错误:{ex.Message}"; + } + finally + { + IsProcessing = false; + ProgressPercentage = 0; + } + }, "设置分层属性"); + } + + /// + /// 清除分层属性 + /// + private async Task ClearLayerAttributeAsync() + { + await SafeExecuteAsync(async () => + { + var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + if (document?.CurrentSelection?.SelectedItems?.Count == 0) + { + CurrentOperationText = "请先选择要清除属性的模型对象"; + return; + } + + IsProcessing = true; + ShowCancelButton = false; + CurrentOperationText = "正在清除分层属性..."; + var totalItems = document.CurrentSelection.SelectedItems.Count; + var processedItems = 0; + + try + { + var floorManager = new FloorAttributeManager(); + var selectedItems = document.CurrentSelection.SelectedItems.ToList(); + + foreach (var item in selectedItems) + { + try + { + bool result = floorManager.ClearFloorAttribute(item); + if (result) + { + processedItems++; + } + } + catch (Exception ex) + { + LogManager.Error($"清除模型 {item.DisplayName} 的分层属性失败:{ex.Message}"); + } + + ProgressPercentage = (double)(processedItems + 1) / totalItems * 100; + } + + CurrentOperationText = $"分层属性清除完成,成功清除 {processedItems}/{totalItems} 个对象的分层属性"; + LogManager.Info($"[LayerManagementViewModel] 成功清除分层属性,影响对象数:{processedItems}"); + + // 刷新选中模型信息 + await RefreshSelectionAsync(); + ShowLayerAttributeInfo = false; + } + catch (Exception ex) + { + LogManager.Error($"[LayerManagementViewModel] 清除分层属性异常: {ex.Message}", ex); + CurrentOperationText = $"清除分层属性时发生错误:{ex.Message}"; + } + finally + { + IsProcessing = false; + ProgressPercentage = 0; + } + }, "清除分层属性"); + } + + /// + /// 查看分层属性 + /// + private async Task ViewLayerAttributeAsync() + { + try + { + var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + if (document?.CurrentSelection?.SelectedItems == null || document.CurrentSelection.SelectedItems.Count == 0) + { + // 使用UI线程更新状态 + await _uiStateManager.ExecuteUIUpdateAsync(() => + { + ShowLayerAttributeInfo = true; + CurrentLayerAttributeInfo = "未选择任何模型项,请先选择要查看的模型"; + }); + return; + } + + // 在后台线程执行业务逻辑 + var result = await Task.Run(() => + { + try + { + var floorManager = new FloorAttributeManager(); + var selectedItems = document.CurrentSelection.SelectedItems.ToList(); + var totalItems = selectedItems.Count; + var attributeInfo = new System.Text.StringBuilder(); + + attributeInfo.AppendLine($"选中对象总数:{totalItems}"); + attributeInfo.AppendLine(); + + var hasAttributeCount = 0; + + foreach (var item in selectedItems.Take(30)) // 增加显示数量到30个 + { + try + { + string itemName = item.DisplayName ?? "未命名"; + var itemAttributes = new List(); + + // 获取楼层属性 + var floorLevel = floorManager.GetFloorLevel(item); + if (!string.IsNullOrEmpty(floorLevel)) + { + itemAttributes.Add($"楼层={floorLevel}"); + } + + // 获取区域属性 + var zone = floorManager.GetZoneAttribute(item); + if (!string.IsNullOrEmpty(zone)) + { + itemAttributes.Add($"区域={zone}"); + } + + // 获取子系统属性 + var subsystem = floorManager.GetSubSystemAttribute(item); + if (!string.IsNullOrEmpty(subsystem)) + { + itemAttributes.Add($"子系统={subsystem}"); + } + + if (itemAttributes.Count > 0) + { + hasAttributeCount++; + attributeInfo.AppendLine($"✅ {itemName}: {string.Join(", ", itemAttributes)}"); + } + else + { + attributeInfo.AppendLine($"❌ {itemName}: 无分层属性"); + } + } + catch (Exception ex) + { + attributeInfo.AppendLine($"⚠️ {item.DisplayName}: 查询失败 - {ex.Message}"); + } + } + + if (selectedItems.Count > 30) + { + attributeInfo.AppendLine($"... 还有 {selectedItems.Count - 30} 个模型项未显示"); + } + + return new { Success = true, Info = attributeInfo.ToString(), Count = totalItems, HasAttributeCount = hasAttributeCount }; + } + catch (Exception ex) + { + return new { Success = false, Info = $"查询失败: {ex.Message}", Count = 0, HasAttributeCount = 0 }; + } + }); + + // 在UI线程更新结果 + await _uiStateManager.ExecuteUIUpdateAsync(() => + { + CurrentLayerAttributeInfo = result.Info; + ShowLayerAttributeInfo = true; + }); + + LogManager.Info($"[LayerManagementViewModel] 分层属性查看完成,共 {result.Count} 个模型项,其中 {result.HasAttributeCount} 个有分层属性"); + } + catch (Exception ex) + { + LogManager.Error($"[LayerManagementViewModel] 查看分层属性异常: {ex.Message}", ex); + + // 在UI线程显示错误信息 + await _uiStateManager.ExecuteUIUpdateAsync(() => + { + CurrentLayerAttributeInfo = $"查看操作异常: {ex.Message}"; + ShowLayerAttributeInfo = true; + }); + } + } + #endregion } } \ No newline at end of file diff --git a/src/UI/WPF/Views/LayerManagementView.xaml b/src/UI/WPF/Views/LayerManagementView.xaml index ebd3e30..3cba131 100644 --- a/src/UI/WPF/Views/LayerManagementView.xaml +++ b/src/UI/WPF/Views/LayerManagementView.xaml @@ -33,10 +33,10 @@ NavisworksTransport 分层管理页签视图 - 重构优化版本 - + -