From f32c367fd02c31d58860b773d99fd023b3ae62ef Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Sun, 7 Sep 2025 13:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=BA=86=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8C=89=E9=92=AE=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A3=80=E6=B5=8B=E6=8C=89=E9=92=AE=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/ModelSplitterManager.cs | 63 ----------- .../ViewModels/LayerManagementViewModel.cs | 66 ++++++++++- .../ViewModels/SystemManagementViewModel.cs | 106 ++++++++++++++++++ src/UI/WPF/Views/LayerManagementView.xaml | 10 -- src/UI/WPF/Views/SystemManagementView.xaml | 4 + 5 files changed, 175 insertions(+), 74 deletions(-) diff --git a/src/Core/ModelSplitterManager.cs b/src/Core/ModelSplitterManager.cs index 58107c1..5ff4368 100644 --- a/src/Core/ModelSplitterManager.cs +++ b/src/Core/ModelSplitterManager.cs @@ -2317,69 +2317,6 @@ namespace NavisworksTransport } } - /// - /// 简化的环境诊断方法 - 快速检查API是否可用 - /// - /// 诊断报告 - public string DiagnoseEnvironment() - { - var report = new System.Text.StringBuilder(); - report.AppendLine("=== Navisworks API环境诊断报告 ==="); - - try - { - // 1. 线程状态 - var apartmentState = System.Threading.Thread.CurrentThread.GetApartmentState(); - report.AppendLine($"线程状态: {apartmentState} {(apartmentState == System.Threading.ApartmentState.STA ? "✓" : "✗")}"); - - // 2. API可用性 - try - { - var app = NavisApplication.ActiveDocument; - report.AppendLine("API可用性: 可用 ✓"); - } - catch (Exception apiEx) - { - report.AppendLine($"API可用性: 异常 - {apiEx.Message} ✗"); - } - - // 3. 文档状态 - try - { - var document = NavisApplication.ActiveDocument; - if (document != null) - { - report.AppendLine($"活动文档: {document.FileName ?? "未命名"} ✓"); - report.AppendLine($"模型数量: {document.Models?.Count ?? 0}"); - } - else - { - report.AppendLine("活动文档: 无 ✗"); - } - } - catch (Exception docEx) - { - report.AppendLine($"活动文档: 异常 - {docEx.Message} ✗"); - } - - // 4. 内存状态 - long memoryMB = GC.GetTotalMemory(false) / 1024 / 1024; - report.AppendLine($"当前内存: {memoryMB} MB"); - - report.AppendLine("=== 诊断完成 ==="); - - string result = report.ToString(); - LogManager.Info($"[SimplifiedModelSplitter] 环境诊断报告:\n{result}"); - return result; - } - catch (Exception ex) - { - string error = $"诊断过程出错: {ex.Message}"; - report.AppendLine(error); - LogManager.Error($"[SimplifiedModelSplitter] {error}"); - return report.ToString(); - } - } /// /// 测试导出功能:导出少量模型项以验证基础功能 diff --git a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs index c8042ce..91538a4 100644 --- a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs @@ -2122,7 +2122,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels // 2. 纯业务逻辑执行(后台线程) string diagnosticReport = await Task.Run(() => { - return _modelSplitterManager.DiagnoseEnvironment(); + return CreateDiagnosticReport(); }); // 3. 结果UI更新 @@ -2160,6 +2160,70 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } + /// + /// 创建环境诊断报告 + /// + /// 诊断报告 + private string CreateDiagnosticReport() + { + var report = new System.Text.StringBuilder(); + report.AppendLine("=== Navisworks API环境诊断报告 ==="); + + try + { + // 1. 线程状态 + var apartmentState = System.Threading.Thread.CurrentThread.GetApartmentState(); + report.AppendLine($"线程状态: {apartmentState} {(apartmentState == System.Threading.ApartmentState.STA ? "✓" : "✗")}"); + + // 2. API可用性 + try + { + var app = Autodesk.Navisworks.Api.Application.ActiveDocument; + report.AppendLine("API可用性: 可用 ✓"); + } + catch (Exception apiEx) + { + report.AppendLine($"API可用性: 异常 - {apiEx.Message} ✗"); + } + + // 3. 文档状态 + try + { + var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + if (document != null) + { + report.AppendLine($"活动文档: {document.FileName ?? "未命名"} ✓"); + report.AppendLine($"模型数量: {document.Models?.Count ?? 0}"); + } + else + { + report.AppendLine("活动文档: 无 ✗"); + } + } + catch (Exception docEx) + { + report.AppendLine($"活动文档: 异常 - {docEx.Message} ✗"); + } + + // 4. 内存状态 + long memoryMB = GC.GetTotalMemory(false) / 1024 / 1024; + report.AppendLine($"当前内存: {memoryMB} MB"); + + report.AppendLine("=== 诊断完成 ==="); + + string result = report.ToString(); + LogManager.Info($"[LayerManagement] 环境诊断报告:\n{result}"); + return result; + } + catch (Exception ex) + { + string error = $"诊断过程出错: {ex.Message}"; + report.AppendLine(error); + LogManager.Error($"[LayerManagement] {error}"); + return report.ToString(); + } + } + /// /// 显示环境诊断结果对话框 /// diff --git a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs index c64adba..4da6258 100644 --- a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs @@ -224,6 +224,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels public ICommand ImportConfigCommand { get; private set; } public ICommand CheckUpdateCommand { get; private set; } public ICommand GeneratePerformanceReportCommand { get; private set; } + public ICommand DiagnosticCommand { get; private set; } #endregion @@ -284,6 +285,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels ImportConfigCommand = new RelayCommand(() => ExecuteImportConfig()); CheckUpdateCommand = new RelayCommand(() => ExecuteCheckUpdate()); GeneratePerformanceReportCommand = new RelayCommand(() => ExecuteGeneratePerformanceReport()); + DiagnosticCommand = new RelayCommand(() => ExecuteDiagnostic()); LogManager.Info("系统管理命令初始化完成"); } @@ -752,6 +754,110 @@ namespace NavisworksTransport.UI.WPF.ViewModels }, "生成性能报告"); } + /// + /// 执行环境诊断 + /// + private void ExecuteDiagnostic() + { + SafeExecute(() => + { + try + { + LogManager.Info("开始环境诊断"); + + // 直接调用本地的环境诊断方法 + string diagnosticReport = DiagnoseEnvironment(); + + // 显示诊断结果对话框 + System.Windows.MessageBox.Show( + diagnosticReport, + "环境诊断结果", + System.Windows.MessageBoxButton.OK, + System.Windows.MessageBoxImage.Information); + + LogManager.Info("环境诊断完成"); + } + catch (Exception ex) + { + LogManager.Error($"环境诊断失败: {ex.Message}", ex); + System.Windows.MessageBox.Show( + $"环境诊断失败: {ex.Message}", + "错误", + System.Windows.MessageBoxButton.OK, + System.Windows.MessageBoxImage.Error); + } + }, "环境诊断"); + } + + /// + /// 环境诊断方法 - 快速检查API是否可用 + /// + /// 诊断报告 + private string DiagnoseEnvironment() + { + var report = new System.Text.StringBuilder(); + report.AppendLine("=== Navisworks API环境诊断报告 ==="); + + try + { + // 1. 线程状态 + var apartmentState = System.Threading.Thread.CurrentThread.GetApartmentState(); + report.AppendLine($"线程状态: {apartmentState} {(apartmentState == System.Threading.ApartmentState.STA ? "✓" : "✗")}"); + + // 2. API可用性 + try + { + var app = Autodesk.Navisworks.Api.Application.ActiveDocument; + report.AppendLine("API可用性: 可用 ✓"); + } + catch (Exception apiEx) + { + report.AppendLine($"API可用性: 异常 - {apiEx.Message} ✗"); + } + + // 3. 文档状态 + try + { + var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + if (document != null) + { + report.AppendLine($"活动文档: {document.FileName ?? "未命名"} ✓"); + report.AppendLine($"模型数量: {document.Models?.Count ?? 0}"); + } + else + { + report.AppendLine("活动文档: 无 ✗"); + } + } + catch (Exception docEx) + { + report.AppendLine($"活动文档: 异常 - {docEx.Message} ✗"); + } + + // 4. 内存状态 + long memoryMB = GC.GetTotalMemory(false) / 1024 / 1024; + report.AppendLine($"当前内存: {memoryMB} MB"); + + // 5. 系统信息 + report.AppendLine($"插件版本: {PluginVersion}"); + report.AppendLine($"Navisworks版本: {NavisworksVersion}"); + report.AppendLine($"系统状态: {SystemStatus}"); + + report.AppendLine("=== 诊断完成 ==="); + + string result = report.ToString(); + LogManager.Info($"[SystemManagement] 环境诊断报告:\n{result}"); + return result; + } + catch (Exception ex) + { + string error = $"诊断过程出错: {ex.Message}"; + report.AppendLine(error); + LogManager.Error($"[SystemManagement] {error}"); + return report.ToString(); + } + } + #endregion #region 辅助方法 diff --git a/src/UI/WPF/Views/LayerManagementView.xaml b/src/UI/WPF/Views/LayerManagementView.xaml index 6719943..a4166ee 100644 --- a/src/UI/WPF/Views/LayerManagementView.xaml +++ b/src/UI/WPF/Views/LayerManagementView.xaml @@ -332,16 +332,6 @@ NavisworksTransport 分层管理页签视图 - 重构优化版本 Style="{StaticResource ActionButtonStyle}" Command="{Binding SaveSelectedItemsCommand}" IsEnabled="{Binding HasSelectedItems}"/> -