优化分层属性读取,优化单独显示性能(可见性管理器)
This commit is contained in:
parent
f131d0f8b7
commit
6c5400f172
@ -162,11 +162,6 @@
|
||||
<Compile Include="src\PathPlanning\VerticalScanProcessor.cs" />
|
||||
<Compile Include="src\PathPlanning\PathOptimizer.cs" />
|
||||
|
||||
<!-- UI - Forms -->
|
||||
<Compile Include="src\UI\Forms\SimpleDockPaneControl.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
||||
<!-- UI - WPF -->
|
||||
<Compile Include="src\UI\WPF\LogisticsControlPanel.xaml.cs">
|
||||
<DependentUpon>LogisticsControlPanel.xaml</DependentUpon>
|
||||
@ -208,7 +203,6 @@
|
||||
<!-- UI - WPF ViewModels -->
|
||||
<Compile Include="src\UI\WPF\ViewModels\ViewModelBase.cs" />
|
||||
<Compile Include="src\UI\WPF\ViewModels\LogisticsControlViewModel.cs" />
|
||||
<Compile Include="src\UI\WPF\ViewModels\SimpleLogisticsControlViewModel.cs" />
|
||||
<Compile Include="src\UI\WPF\ViewModels\LayerManagementViewModel.cs" />
|
||||
<Compile Include="src\UI\WPF\ViewModels\ModelSettingsViewModel.cs" />
|
||||
<Compile Include="src\UI\WPF\ViewModels\AnimationControlViewModel.cs" />
|
||||
@ -218,9 +212,6 @@
|
||||
<Compile Include="src\UI\WPF\ViewModels\PathAnalysisViewModel.cs" />
|
||||
<Compile Include="src\UI\WPF\ViewModels\TimeTagViewModel.cs" />
|
||||
|
||||
<!-- UI - WPF Simplified Controls -->
|
||||
<Compile Include="src\UI\WPF\SimpleLogisticsControlPanel.cs" />
|
||||
|
||||
<!-- UI - WPF Collections -->
|
||||
<Compile Include="src\UI\WPF\Collections\ThreadSafeObservableCollection.cs" />
|
||||
<Compile Include="src\UI\WPF\Collections\VirtualizedObservableCollection.cs" />
|
||||
@ -257,9 +248,6 @@
|
||||
<Compile Include="src\Utils\NavisworksSelectionHelper.cs" />
|
||||
<Compile Include="src\Utils\UnitsConverter.cs" />
|
||||
|
||||
<!-- Legacy (2017 compatibility - can be removed in 2026-only branch) -->
|
||||
<!-- <Compile Include="src\Legacy\PathAnimationManager.cs" /> 已移至 Core/Animation -->
|
||||
|
||||
<!-- Assembly Info -->
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -1774,3 +1774,56 @@ public class PathClickToolPlugin : ToolPlugin
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 只显示选中项
|
||||
|
||||
```csharp
|
||||
Examples
|
||||
CopyHide the unselected ModelItems
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using System.Text;
|
||||
|
||||
using Autodesk.Navisworks.Api.Controls;
|
||||
|
||||
static public void HideUnselected()
|
||||
{
|
||||
//Create hidden collection
|
||||
ModelItemCollection hidden = new ModelItemCollection();
|
||||
|
||||
//create a store for the visible items
|
||||
ModelItemCollection visible = new ModelItemCollection();
|
||||
|
||||
//Add all the items that are visible to the visible collection
|
||||
foreach (ModelItem item in Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems)
|
||||
{
|
||||
if (item.AncestorsAndSelf != null)
|
||||
visible.AddRange(item.AncestorsAndSelf);
|
||||
if (item.Descendants != null)
|
||||
visible.AddRange(item.Descendants);
|
||||
}
|
||||
|
||||
//mark as invisible all the siblings of the visible items as well as the visible items
|
||||
foreach (ModelItem toShow in visible)
|
||||
{
|
||||
if (toShow.Parent != null)
|
||||
{
|
||||
hidden.AddRange(toShow.Parent.Children);
|
||||
}
|
||||
}
|
||||
|
||||
//remove the visible items from the collection
|
||||
foreach (ModelItem toShow in visible)
|
||||
{
|
||||
hidden.Remove(toShow);
|
||||
}
|
||||
|
||||
//hide the remaining items
|
||||
Autodesk.Navisworks.Api.Application.ActiveDocument.Models.
|
||||
SetHidden(hidden, true);
|
||||
}
|
||||
```
|
||||
@ -16,9 +16,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
private static ClashDetectiveIntegration _instance;
|
||||
private DocumentClash _documentClash;
|
||||
private ClashTest _dynamicClashTest;
|
||||
private List<ClashResult> _currentCollisions;
|
||||
private bool _isInitialized = false;
|
||||
// 通道对象缓存,用于优化碰撞检测性能
|
||||
private static HashSet<ModelItem> _channelObjectsCache = null;
|
||||
private static readonly object _cacheLock = new object();
|
||||
@ -94,19 +92,16 @@ namespace NavisworksTransport
|
||||
if (_documentClash != null)
|
||||
{
|
||||
LogManager.Info("成功获取.NET API Clash文档");
|
||||
_isInitialized = true;
|
||||
LogManager.Info("Clash Detective集成初始化成功(.NET API模式)");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Warning("无法获取Clash文档,Clash Detective可能未安装");
|
||||
_isInitialized = false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"初始化Clash Detective集成失败: {ex.Message}");
|
||||
_isInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1675,11 +1670,8 @@ namespace NavisworksTransport
|
||||
}
|
||||
|
||||
// 清理.NET API引用
|
||||
_dynamicClashTest = null;
|
||||
_documentClash = null;
|
||||
|
||||
_isInitialized = false;
|
||||
|
||||
LogManager.Info("Clash Detective集成资源清理完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@ -188,84 +188,96 @@ namespace NavisworksTransport.Core
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 直接获取对象的楼层属性
|
||||
/// 获取楼层属性值(使用 Native API,性能最优)
|
||||
/// </summary>
|
||||
/// <param name="item">目标模型项</param>
|
||||
/// <returns>楼层标识,未找到返回null</returns>
|
||||
public string GetFloorLevel(ModelItem item)
|
||||
/// <param name="item">模型项</param>
|
||||
/// <param name="propertyName">属性显示名称,如 "楼层"、"区域"、"子系统"</param>
|
||||
/// <returns>属性值,不存在返回 null</returns>
|
||||
public string GetFloorProperty(ModelItem item, string propertyName)
|
||||
{
|
||||
if (item == null) return null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
return ExecuteWithUIThread(() =>
|
||||
foreach (PropertyCategory category in item.PropertyCategories)
|
||||
{
|
||||
return NavisworksComPropertyManager.GetFloorPropertyValue(
|
||||
item,
|
||||
FLOOR_CATEGORY,
|
||||
FLOOR_LEVEL_PROPERTY);
|
||||
});
|
||||
if (category.DisplayName == FLOOR_CATEGORY)
|
||||
{
|
||||
foreach (DataProperty property in category.Properties)
|
||||
{
|
||||
if (property.DisplayName == propertyName)
|
||||
{
|
||||
return property.Value.ToDisplayString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[FloorAttributeManager] 直接获取楼层属性失败:{ex.Message}");
|
||||
return null;
|
||||
LogManager.Debug($"[FloorAttributeManager] 获取楼层属性 '{propertyName}' 失败: {ex.Message}");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接获取对象的区域属性
|
||||
/// 检查模型项是否有楼层属性(性能优化版本)
|
||||
/// </summary>
|
||||
/// <param name="item">目标模型项</param>
|
||||
/// <returns>区域属性值,未找到返回null</returns>
|
||||
public string GetZoneAttribute(ModelItem item)
|
||||
public bool HasFloorAttributes(ModelItem item)
|
||||
{
|
||||
if (item == null) return null;
|
||||
|
||||
if (item == null) return false;
|
||||
|
||||
try
|
||||
{
|
||||
return ExecuteWithUIThread(() =>
|
||||
foreach (PropertyCategory category in item.PropertyCategories)
|
||||
{
|
||||
return NavisworksComPropertyManager.GetFloorPropertyValue(
|
||||
item,
|
||||
FLOOR_CATEGORY,
|
||||
ZONE_PROPERTY);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[FloorAttributeManager] 直接获取区域属性失败:{ex.Message}");
|
||||
return null;
|
||||
if (category.DisplayName == FLOOR_CATEGORY)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接获取对象的子系统属性
|
||||
/// 通过 COM API 获取楼层属性值(特殊场景使用)
|
||||
/// 仅在以下情况使用:
|
||||
/// 1. 刚通过 COM API 更新属性后需要立即读取
|
||||
/// 2. 遇到 Native API 缓存不同步问题时
|
||||
/// 注意:性能较差,需要 UI 线程同步
|
||||
/// </summary>
|
||||
/// <param name="item">目标模型项</param>
|
||||
/// <returns>子系统属性值,未找到返回null</returns>
|
||||
public string GetSubSystemAttribute(ModelItem item)
|
||||
public string GetFloorPropertyViaCom(ModelItem item, string propertyName)
|
||||
{
|
||||
if (item == null) return null;
|
||||
|
||||
// 将显示名称转换为内部名称
|
||||
string internalName = ConvertToInternalName(propertyName);
|
||||
|
||||
return ExecuteWithUIThread(() =>
|
||||
{
|
||||
return NavisworksComPropertyManager.GetFloorPropertyValue(
|
||||
item, FLOOR_CATEGORY, internalName);
|
||||
});
|
||||
}
|
||||
|
||||
try
|
||||
/// <summary>
|
||||
/// 将显示名称转换为内部名称
|
||||
/// </summary>
|
||||
private string ConvertToInternalName(string displayName)
|
||||
{
|
||||
switch (displayName)
|
||||
{
|
||||
return ExecuteWithUIThread(() =>
|
||||
{
|
||||
return NavisworksComPropertyManager.GetFloorPropertyValue(
|
||||
item,
|
||||
FLOOR_CATEGORY,
|
||||
SUBSYSTEM_PROPERTY);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[FloorAttributeManager] 直接获取子系统属性失败:{ex.Message}");
|
||||
return null;
|
||||
case "楼层": return FLOOR_LEVEL_PROPERTY;
|
||||
case "区域": return ZONE_PROPERTY;
|
||||
case "子系统": return SUBSYSTEM_PROPERTY;
|
||||
default: return displayName + "_Internal";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 批量设置楼层属性
|
||||
/// </summary>
|
||||
@ -330,7 +342,7 @@ namespace NavisworksTransport.Core
|
||||
{
|
||||
try
|
||||
{
|
||||
string floorLevel = GetFloorLevel(item);
|
||||
string floorLevel = GetFloorProperty(item, "楼层");
|
||||
if (!string.IsNullOrEmpty(floorLevel))
|
||||
{
|
||||
if (!floorGroups.ContainsKey(floorLevel))
|
||||
|
||||
@ -308,7 +308,7 @@ namespace NavisworksTransport
|
||||
|
||||
protected override string GetAttributeValue(ModelItem item)
|
||||
{
|
||||
return _floorManager.GetFloorLevel(item);
|
||||
return _floorManager.GetFloorProperty(item, "楼层");
|
||||
}
|
||||
}
|
||||
|
||||
@ -322,7 +322,7 @@ namespace NavisworksTransport
|
||||
|
||||
protected override string GetAttributeValue(ModelItem item)
|
||||
{
|
||||
return _floorManager.GetZoneAttribute(item);
|
||||
return _floorManager.GetFloorProperty(item, "区域");
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,7 +336,7 @@ namespace NavisworksTransport
|
||||
|
||||
protected override string GetAttributeValue(ModelItem item)
|
||||
{
|
||||
return _floorManager.GetSubSystemAttribute(item);
|
||||
return _floorManager.GetFloorProperty(item, "子系统");
|
||||
}
|
||||
}
|
||||
|
||||
@ -467,7 +467,7 @@ namespace NavisworksTransport
|
||||
|
||||
// 1. 检查线程模型 - 必须在STA线程中
|
||||
var apartmentState = System.Threading.Thread.CurrentThread.GetApartmentState();
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 当前线程状态: {apartmentState}");
|
||||
LogManager.Info($"[分层管理器] 当前线程状态: {apartmentState}");
|
||||
if (apartmentState != System.Threading.ApartmentState.STA)
|
||||
{
|
||||
LogManager.Warning("[SimplifiedModelSplitter] 警告:当前不在STA线程中,这可能导致API调用失败");
|
||||
@ -483,7 +483,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception apiEx)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] Navisworks API不可用: {apiEx.Message}");
|
||||
LogManager.Error($"[分层管理器] Navisworks API不可用: {apiEx.Message}");
|
||||
LogManager.Error("[SimplifiedModelSplitter] 解决方案:确保在Navisworks环境中运行此插件");
|
||||
}
|
||||
|
||||
@ -493,8 +493,8 @@ namespace NavisworksTransport
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document != null)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 活动文档: {document.FileName ?? "未命名"}");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 文档模型数量: {document.Models?.Count ?? 0}");
|
||||
LogManager.Info($"[分层管理器] 活动文档: {document.FileName ?? "未命名"}");
|
||||
LogManager.Info($"[分层管理器] 文档模型数量: {document.Models?.Count ?? 0}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -503,18 +503,18 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception docEx)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 检查文档状态时出错: {docEx.Message}");
|
||||
LogManager.Warning($"[分层管理器] 检查文档状态时出错: {docEx.Message}");
|
||||
}
|
||||
|
||||
// 4. 内存状态检查
|
||||
long memoryMB = GC.GetTotalMemory(false) / 1024 / 1024;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 当前内存使用: {memoryMB} MB");
|
||||
LogManager.Info($"[分层管理器] 当前内存使用: {memoryMB} MB");
|
||||
|
||||
LogManager.Info("[SimplifiedModelSplitter] Navisworks运行时环境验证完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 运行时环境验证失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 运行时环境验证失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -541,7 +541,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始智能遍历分层预览,策略: {config.Strategy},深度限制: {config.MaxDepth}");
|
||||
LogManager.Info($"[分层管理器] 开始智能遍历分层预览,策略: {config.Strategy},深度限制: {config.MaxDepth}");
|
||||
|
||||
// 步骤1:初始化和缓存检查 (0-10%)
|
||||
OnStatusChanged("正在初始化智能分层预览...");
|
||||
@ -549,7 +549,7 @@ namespace NavisworksTransport
|
||||
|
||||
// 生成缓存键(注意:智能遍历的缓存键需要区别于原有方式)
|
||||
string cacheKey = GenerateSmartTraversalCacheKey(config);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 生成智能遍历缓存键: {cacheKey}");
|
||||
LogManager.Info($"[分层管理器] 生成智能遍历缓存键: {cacheKey}");
|
||||
|
||||
OnProgressChanged(new ProgressChangedEventArgs(5, "检查缓存"));
|
||||
|
||||
@ -557,7 +557,7 @@ namespace NavisworksTransport
|
||||
List<SplitPreviewResult> cachedResults = GetFromCache(config.Strategy, cacheKey);
|
||||
if (cachedResults != null && cachedResults.Count > 0)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 使用缓存结果,共 {cachedResults.Count} 个分层");
|
||||
LogManager.Info($"[分层管理器] 使用缓存结果,共 {cachedResults.Count} 个分层");
|
||||
OnStatusChanged($"使用缓存结果,识别到 {cachedResults.Count} 个分层");
|
||||
OnProgressChanged(new ProgressChangedEventArgs(100, $"从缓存加载 {cachedResults.Count} 个分层"));
|
||||
return cachedResults;
|
||||
@ -574,7 +574,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
|
||||
OnProgressChanged(new ProgressChangedEventArgs(15, $"文档验证完成,包含 {document.Models.Count} 个模型"));
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 文档验证完成,包含 {document.Models.Count} 个模型");
|
||||
LogManager.Info($"[分层管理器] 文档验证完成,包含 {document.Models.Count} 个模型");
|
||||
|
||||
// 步骤3:执行智能遍历分层分析 (15-90%)
|
||||
OnStatusChanged($"正在执行{GetStrategyDisplayName(config.Strategy)}...");
|
||||
@ -584,7 +584,7 @@ namespace NavisworksTransport
|
||||
var strategy = CreateStrategy(config.Strategy);
|
||||
|
||||
// 关键改变:直接使用智能遍历,不再预收集所有节点
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 使用智能遍历算法,策略: {strategy.GroupTypeName}");
|
||||
LogManager.Info($"[分层管理器] 使用智能遍历算法,策略: {strategy.GroupTypeName}");
|
||||
previewResults = PreviewSplitWithSmartTraversal(config, strategy);
|
||||
|
||||
OnProgressChanged(new ProgressChangedEventArgs(90, $"智能分析完成,识别到 {previewResults.Count} 个分层"));
|
||||
@ -600,13 +600,13 @@ namespace NavisworksTransport
|
||||
OnStatusChanged($"智能预览完成,识别到 {previewResults.Count} 个分层");
|
||||
OnProgressChanged(new ProgressChangedEventArgs(100, $"预览完成,共 {previewResults.Count} 个分层"));
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 智能遍历预览完成,共识别 {previewResults.Count} 个分层(深度: {config.MaxDepth}级),已缓存");
|
||||
LogManager.Info($"[分层管理器] 智能遍历预览完成,共识别 {previewResults.Count} 个分层(深度: {config.MaxDepth}级),已缓存");
|
||||
|
||||
return previewResults;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 智能遍历预览失败: {ex.Message}", ex);
|
||||
LogManager.Error($"[分层管理器] 智能遍历预览失败: {ex.Message}", ex);
|
||||
OnStatusChanged($"预览失败: {ex.Message}");
|
||||
OnProgressChanged(new ProgressChangedEventArgs(0, $"预览失败: {ex.Message}"));
|
||||
throw;
|
||||
@ -675,7 +675,7 @@ namespace NavisworksTransport
|
||||
// 只支持楼层缓存和自定义楼层缓存
|
||||
var cache = _floorCache;
|
||||
cache[cacheKey] = results;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 结果已缓存: {strategy}, 键: {cacheKey}, 数量: {results.Count}");
|
||||
LogManager.Info($"[分层管理器] 结果已缓存: {strategy}, 键: {cacheKey}, 数量: {results.Count}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -686,7 +686,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始执行分层,策略: {config.Strategy}");
|
||||
LogManager.Info($"[分层管理器] 开始执行分层,策略: {config.Strategy}");
|
||||
OnStatusChanged("正在准备分层...");
|
||||
|
||||
// 优先从缓存获取分层结果,避免重复检测
|
||||
@ -695,7 +695,7 @@ namespace NavisworksTransport
|
||||
|
||||
if (previewResults == null || previewResults.Count == 0)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 缓存中没有结果,重新预览分层");
|
||||
LogManager.Info($"[分层管理器] 缓存中没有结果,重新预览分层");
|
||||
previewResults = PreviewSplit(config);
|
||||
if (previewResults.Count == 0)
|
||||
{
|
||||
@ -704,7 +704,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 使用缓存的分层结果,共 {previewResults.Count} 个分层");
|
||||
LogManager.Info($"[分层管理器] 使用缓存的分层结果,共 {previewResults.Count} 个分层");
|
||||
}
|
||||
|
||||
// 过滤出需要保存的分层
|
||||
@ -716,7 +716,7 @@ namespace NavisworksTransport
|
||||
return;
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 将保存 {layersToSave.Count}/{previewResults.Count} 个选中的分层");
|
||||
LogManager.Info($"[分层管理器] 将保存 {layersToSave.Count}/{previewResults.Count} 个选中的分层");
|
||||
|
||||
// 确保输出目录存在
|
||||
EnsureOutputDirectory(config.OutputDirectory);
|
||||
@ -729,7 +729,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 用户取消分层操作,已处理 {successCount}/{layersToSave.Count} 个分层");
|
||||
LogManager.Info($"[分层管理器] 用户取消分层操作,已处理 {successCount}/{layersToSave.Count} 个分层");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -743,12 +743,12 @@ namespace NavisworksTransport
|
||||
// 实现具体的分层保存逻辑
|
||||
await ProcessSingleLayerAsync(preview, config, cancellationToken);
|
||||
successCount++;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层 {preview.LayerName} 处理成功 ({successCount}/{layersToSave.Count})");
|
||||
LogManager.Info($"[分层管理器] 分层 {preview.LayerName} 处理成功 ({successCount}/{layersToSave.Count})");
|
||||
}
|
||||
catch (Exception layerEx)
|
||||
{
|
||||
string errorMsg = $"分层 {preview.LayerName} 处理失败: {layerEx.Message}";
|
||||
LogManager.Error($"[SimplifiedModelSplitter] {errorMsg}");
|
||||
LogManager.Error($"[分层管理器] {errorMsg}");
|
||||
failedLayers.Add(preview.LayerName);
|
||||
|
||||
// 继续处理其他分层,不因单个失败而中断整个进程
|
||||
@ -766,11 +766,11 @@ namespace NavisworksTransport
|
||||
if (failedLayers.Count > 0)
|
||||
{
|
||||
finalMessage += $"\n失败列表: {string.Join(", ", failedLayers)}";
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] {finalMessage}");
|
||||
LogManager.Warning($"[分层管理器] {finalMessage}");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] {finalMessage}");
|
||||
LogManager.Info($"[分层管理器] {finalMessage}");
|
||||
}
|
||||
|
||||
OnStatusChanged(finalMessage);
|
||||
@ -781,11 +781,11 @@ namespace NavisworksTransport
|
||||
throw new InvalidOperationException($"所有选中的分层处理都失败了,共 {layersToSave.Count} 个分层");
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层执行完成:成功 {successCount}/{layersToSave.Count}");
|
||||
LogManager.Info($"[分层管理器] 分层执行完成:成功 {successCount}/{layersToSave.Count}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 分层执行失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 分层执行失败: {ex.Message}");
|
||||
OnStatusChanged($"分层失败: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
@ -798,7 +798,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始执行分层,策略: {config.Strategy}");
|
||||
LogManager.Info($"[分层管理器] 开始执行分层,策略: {config.Strategy}");
|
||||
OnStatusChanged("正在准备分层...");
|
||||
|
||||
// 优先从缓存获取分层结果,避免重复检测
|
||||
@ -807,7 +807,7 @@ namespace NavisworksTransport
|
||||
|
||||
if (previewResults == null || previewResults.Count == 0)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 缓存中没有结果,重新预览分层");
|
||||
LogManager.Info($"[分层管理器] 缓存中没有结果,重新预览分层");
|
||||
previewResults = PreviewSplit(config);
|
||||
if (previewResults.Count == 0)
|
||||
{
|
||||
@ -816,7 +816,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 使用缓存的分层结果,共 {previewResults.Count} 个分层");
|
||||
LogManager.Info($"[分层管理器] 使用缓存的分层结果,共 {previewResults.Count} 个分层");
|
||||
}
|
||||
|
||||
// 过滤出需要保存的分层
|
||||
@ -828,7 +828,7 @@ namespace NavisworksTransport
|
||||
return;
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 将保存 {layersToSave.Count}/{previewResults.Count} 个选中的分层");
|
||||
LogManager.Info($"[分层管理器] 将保存 {layersToSave.Count}/{previewResults.Count} 个选中的分层");
|
||||
|
||||
// 确保输出目录存在
|
||||
EnsureOutputDirectory(config.OutputDirectory);
|
||||
@ -849,12 +849,12 @@ namespace NavisworksTransport
|
||||
// 同步处理单个分层
|
||||
ProcessSingleLayer(preview, config);
|
||||
successCount++;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层 {preview.LayerName} 处理成功 ({successCount}/{layersToSave.Count})");
|
||||
LogManager.Info($"[分层管理器] 分层 {preview.LayerName} 处理成功 ({successCount}/{layersToSave.Count})");
|
||||
}
|
||||
catch (Exception layerEx)
|
||||
{
|
||||
string errorMsg = $"分层 {preview.LayerName} 处理失败: {layerEx.Message}";
|
||||
LogManager.Error($"[SimplifiedModelSplitter] {errorMsg}");
|
||||
LogManager.Error($"[分层管理器] {errorMsg}");
|
||||
failedLayers.Add(preview.LayerName);
|
||||
|
||||
// 继续处理其他分层,不因单个失败而中断整个进程
|
||||
@ -872,11 +872,11 @@ namespace NavisworksTransport
|
||||
if (failedLayers.Count > 0)
|
||||
{
|
||||
finalMessage += $"\n失败列表: {string.Join(", ", failedLayers)}";
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] {finalMessage}");
|
||||
LogManager.Warning($"[分层管理器] {finalMessage}");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] {finalMessage}");
|
||||
LogManager.Info($"[分层管理器] {finalMessage}");
|
||||
}
|
||||
|
||||
OnStatusChanged(finalMessage);
|
||||
@ -887,11 +887,11 @@ namespace NavisworksTransport
|
||||
throw new InvalidOperationException($"所有选中的分层处理都失败了,共 {layersToSave.Count} 个分层");
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层执行完成:成功 {successCount}/{layersToSave.Count}");
|
||||
LogManager.Info($"[分层管理器] 分层执行完成:成功 {successCount}/{layersToSave.Count}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 分层执行失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 分层执行失败: {ex.Message}");
|
||||
OnStatusChanged($"分层失败: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
@ -910,7 +910,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ===== GetItemsByDepthUnified开始 ===== maxDepth={maxDepth}");
|
||||
LogManager.Info($"[分层管理器] ===== GetItemsByDepthUnified开始 ===== maxDepth={maxDepth}");
|
||||
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models?.Count == 0)
|
||||
@ -925,7 +925,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
// 深度为0表示包含所有级别
|
||||
result.AddRange(document.Models.RootItemDescendantsAndSelf);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] maxDepth=0,返回所有级别的项,共{result.Count}个");
|
||||
LogManager.Info($"[分层管理器] maxDepth=0,返回所有级别的项,共{result.Count}个");
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -948,12 +948,12 @@ namespace NavisworksTransport
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ===== GetItemsByDepthUnified完成 ===== 返回{result.Count}个模型项(深度:{maxDepth}级)");
|
||||
LogManager.Info($"[分层管理器] ===== GetItemsByDepthUnified完成 ===== 返回{result.Count}个模型项(深度:{maxDepth}级)");
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] GetItemsByDepthUnified异常: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] GetItemsByDepthUnified异常: {ex.Message}");
|
||||
return new ModelItemCollection();
|
||||
}
|
||||
}
|
||||
@ -1004,7 +1004,7 @@ namespace NavisworksTransport
|
||||
OnProgressChanged(new ProgressChangedEventArgs(40, $"正在分析 {items.Count} 个模型元素的{strategy.GroupTypeName}信息"));
|
||||
|
||||
var groups = strategy.GroupItems(items, config);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] {strategy.GroupTypeName}属性检测完成,发现 {groups?.Count ?? 0} 个{strategy.GroupTypeName}分组");
|
||||
LogManager.Info($"[分层管理器] {strategy.GroupTypeName}属性检测完成,发现 {groups?.Count ?? 0} 个{strategy.GroupTypeName}分组");
|
||||
|
||||
OnProgressChanged(new ProgressChangedEventArgs(70, $"{strategy.GroupTypeName}分组完成,发现 {groups?.Count ?? 0} 个{strategy.GroupTypeName}"));
|
||||
|
||||
@ -1027,11 +1027,11 @@ namespace NavisworksTransport
|
||||
if (group.Items != null && group.Items.Count > 0)
|
||||
{
|
||||
previewResult.Items.AddRange(group.Items);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] {strategy.GroupTypeName}预览结果已缓存模型项: {strategy.GroupTypeName}='{previewResult.LayerName}', 模型项数量={previewResult.Items.Count}");
|
||||
LogManager.Info($"[分层管理器] {strategy.GroupTypeName}预览结果已缓存模型项: {strategy.GroupTypeName}='{previewResult.LayerName}', 模型项数量={previewResult.Items.Count}");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] {strategy.GroupTypeName}预览结果没有模型项: {strategy.GroupTypeName}='{previewResult.LayerName}'");
|
||||
LogManager.Warning($"[分层管理器] {strategy.GroupTypeName}预览结果没有模型项: {strategy.GroupTypeName}='{previewResult.LayerName}'");
|
||||
}
|
||||
|
||||
// 添加元数据
|
||||
@ -1059,12 +1059,12 @@ namespace NavisworksTransport
|
||||
else
|
||||
{
|
||||
OnProgressChanged(new ProgressChangedEventArgs(85, $"未检测到{strategy.GroupTypeName}信息"));
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 未检测到任何{strategy.GroupTypeName}信息");
|
||||
LogManager.Warning($"[分层管理器] 未检测到任何{strategy.GroupTypeName}信息");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 按{strategy.GroupTypeName}属性预览失败: {ex.Message}", ex);
|
||||
LogManager.Error($"[分层管理器] 按{strategy.GroupTypeName}属性预览失败: {ex.Message}", ex);
|
||||
OnProgressChanged(new ProgressChangedEventArgs(35, $"{strategy.GroupTypeName}分析失败: {ex.Message}"));
|
||||
throw;
|
||||
}
|
||||
@ -1082,8 +1082,8 @@ namespace NavisworksTransport
|
||||
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== 开始智能遍历分层预览 ==========");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 策略: {strategy.GroupTypeName}, 深度限制: {config.MaxDepth}");
|
||||
LogManager.Info($"[分层管理器] ========== 开始智能遍历分层预览 ==========");
|
||||
LogManager.Info($"[分层管理器] 策略: {strategy.GroupTypeName}, 深度限制: {config.MaxDepth}");
|
||||
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models?.Count == 0)
|
||||
@ -1106,18 +1106,18 @@ namespace NavisworksTransport
|
||||
// 每处理10个顶级节点记录一次进度
|
||||
if (processedTopNodes % 10 == 0)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 已处理 {processedTopNodes} 个顶级节点,找到 {results.Count} 个分层");
|
||||
LogManager.Info($"[分层管理器] 已处理 {processedTopNodes} 个顶级节点,找到 {results.Count} 个分层");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== 智能遍历完成 ==========");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 处理了 {processedTopNodes} 个顶级节点,识别到 {results.Count} 个{strategy.GroupTypeName}分层");
|
||||
LogManager.Info($"[分层管理器] ========== 智能遍历完成 ==========");
|
||||
LogManager.Info($"[分层管理器] 处理了 {processedTopNodes} 个顶级节点,识别到 {results.Count} 个{strategy.GroupTypeName}分层");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 智能遍历失败: {ex.Message}", ex);
|
||||
LogManager.Error($"[分层管理器] 智能遍历失败: {ex.Message}", ex);
|
||||
throw;
|
||||
}
|
||||
|
||||
@ -1143,14 +1143,14 @@ namespace NavisworksTransport
|
||||
{
|
||||
var (attributeName, attributeValue) = floorStrategy.ExtractAttributeInfo(node);
|
||||
detectedAttributeName = attributeName;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 智能检测到属性类型: '{attributeName}', 值: '{attributeValue}'");
|
||||
LogManager.Info($"[分层管理器] 智能检测到属性类型: '{attributeName}', 值: '{attributeValue}'");
|
||||
}
|
||||
|
||||
// 创建轻量化预览结果,停止该分支遍历
|
||||
var layerResult = CreateLayerResult(layerValue, node, strategy.GroupTypeName, config.Strategy, detectedAttributeName);
|
||||
results.Add(layerResult);
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 找到{strategy.GroupTypeName}分层: '{layerValue}' 于节点 '{node.DisplayName}' (深度{currentDepth})");
|
||||
LogManager.Info($"[分层管理器] 找到{strategy.GroupTypeName}分层: '{layerValue}' 于节点 '{node.DisplayName}' (深度{currentDepth})");
|
||||
return; // 关键:停止遍历该分支
|
||||
}
|
||||
|
||||
@ -1165,7 +1165,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 遍历节点失败: {node?.DisplayName ?? "null"}, 错误: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 遍历节点失败: {node?.DisplayName ?? "null"}, 错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1207,7 +1207,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始处理分层: {preview.LayerName}, 类型: {preview.LayerAttribute}");
|
||||
LogManager.Info($"[分层管理器] 开始处理分层: {preview.LayerName}, 类型: {preview.LayerAttribute}");
|
||||
|
||||
// 检查取消请求
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
@ -1216,24 +1216,24 @@ namespace NavisworksTransport
|
||||
string fileName = GenerateFileName(preview.LayerName, config.Strategy, config);
|
||||
string outputPath = Path.Combine(config.OutputDirectory, fileName);
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层文件路径: {outputPath}");
|
||||
LogManager.Info($"[分层管理器] 分层文件路径: {outputPath}");
|
||||
|
||||
// 直接在UI线程调用,不使用Task.Run包装
|
||||
bool success = ExportLayerToNwd(preview, outputPath, config);
|
||||
|
||||
if (success)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层 {preview.LayerName} 导出成功: {outputPath}");
|
||||
LogManager.Info($"[分层管理器] 分层 {preview.LayerName} 导出成功: {outputPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 分层 {preview.LayerName} 导出失败");
|
||||
LogManager.Error($"[分层管理器] 分层 {preview.LayerName} 导出失败");
|
||||
throw new InvalidOperationException($"分层 {preview.LayerName} 导出失败");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 处理分层失败 {preview.LayerName}: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 处理分层失败 {preview.LayerName}: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -1245,11 +1245,11 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始同步处理分层: {preview.LayerName}, 类型: {preview.LayerAttribute}");
|
||||
LogManager.Info($"[分层管理器] 开始同步处理分层: {preview.LayerName}, 类型: {preview.LayerAttribute}");
|
||||
|
||||
if (preview.Items == null || preview.Items.Count == 0)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 分层 {preview.LayerName} 没有包含模型元素,跳过导出");
|
||||
LogManager.Warning($"[分层管理器] 分层 {preview.LayerName} 没有包含模型元素,跳过导出");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1257,19 +1257,19 @@ namespace NavisworksTransport
|
||||
string fileName = GenerateFileName(preview.LayerName, config.Strategy, config);
|
||||
string outputPath = Path.Combine(config.OutputDirectory, fileName);
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层文件路径: {outputPath}");
|
||||
LogManager.Info($"[分层管理器] 分层文件路径: {outputPath}");
|
||||
|
||||
// 检查模型项数量,对大量模型项进行特殊处理
|
||||
if (preview.Items != null && preview.Items.Count > 100)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 大量模型项检测:{preview.Items.Count}个,可能需要更多内存和时间");
|
||||
LogManager.Warning($"[分层管理器] 大量模型项检测:{preview.Items.Count}个,可能需要更多内存和时间");
|
||||
|
||||
// 强制垃圾回收,释放内存
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 垃圾回收完成,当前内存: {GC.GetTotalMemory(false) / 1024 / 1024} MB");
|
||||
LogManager.Info($"[分层管理器] 垃圾回收完成,当前内存: {GC.GetTotalMemory(false) / 1024 / 1024} MB");
|
||||
}
|
||||
|
||||
// 使用TryExportToNwd API导出分层
|
||||
@ -1277,17 +1277,17 @@ namespace NavisworksTransport
|
||||
|
||||
if (success)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 分层 {preview.LayerName} 导出成功: {outputPath}");
|
||||
LogManager.Info($"[分层管理器] 分层 {preview.LayerName} 导出成功: {outputPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 分层 {preview.LayerName} 导出失败");
|
||||
LogManager.Error($"[分层管理器] 分层 {preview.LayerName} 导出失败");
|
||||
throw new InvalidOperationException($"分层 {preview.LayerName} 导出失败");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 同步处理分层失败 {preview.LayerName}: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 同步处理分层失败 {preview.LayerName}: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@ -1303,7 +1303,7 @@ namespace NavisworksTransport
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 创建输出目录: {directory}");
|
||||
LogManager.Info($"[分层管理器] 创建输出目录: {directory}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1465,17 +1465,17 @@ namespace NavisworksTransport
|
||||
// 确保文件名唯一性
|
||||
fileName = EnsureUniqueFileName(fileName, config.OutputDirectory);
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 生成智能文件名: {fileName}");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 文件名组成: 根节点='{rootNodeName}', 属性类型='{attributeTypeName}', 属性值='{sanitizedAttributeValue}', 时间戳='{timestamp}'");
|
||||
LogManager.Info($"[分层管理器] 生成智能文件名: {fileName}");
|
||||
LogManager.Info($"[分层管理器] 文件名组成: 根节点='{rootNodeName}', 属性类型='{attributeTypeName}', 属性值='{sanitizedAttributeValue}', 时间戳='{timestamp}'");
|
||||
|
||||
return fileName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 生成智能文件名失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 生成智能文件名失败: {ex.Message}");
|
||||
// 失败时使用后备命名方式
|
||||
string fallbackName = $"NavisworksModel_分层_{SanitizeLayerName(attributeValue)}_{DateTime.Now:yyyyMMdd_HHmmss}.nwd";
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 使用后备文件名: {fallbackName}");
|
||||
LogManager.Warning($"[分层管理器] 使用后备文件名: {fallbackName}");
|
||||
return fallbackName;
|
||||
}
|
||||
}
|
||||
@ -1530,7 +1530,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 获取根节点名称失败: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 获取根节点名称失败: {ex.Message}");
|
||||
return "NavisworksModel";
|
||||
}
|
||||
}
|
||||
@ -1597,12 +1597,12 @@ namespace NavisworksTransport
|
||||
counter++;
|
||||
} while (File.Exists(filePath) && counter < 100);
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 文件名冲突,重命名为: {newFileName}");
|
||||
LogManager.Info($"[分层管理器] 文件名冲突,重命名为: {newFileName}");
|
||||
return newFileName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 检查文件名唯一性失败: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 检查文件名唯一性失败: {ex.Message}");
|
||||
return originalFileName;
|
||||
}
|
||||
}
|
||||
@ -1614,30 +1614,30 @@ namespace NavisworksTransport
|
||||
{
|
||||
if (preview == null)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 预览结果为null");
|
||||
LogManager.Error($"[分层管理器] 预览结果为null");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== ExportLayerToNwd开始 ==========");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 导出层: {preview.LayerName}");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 预览项数量: {preview.Items?.Count ?? 0}");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 输出路径: {outputPath}");
|
||||
LogManager.Info($"[分层管理器] ========== ExportLayerToNwd开始 ==========");
|
||||
LogManager.Info($"[分层管理器] 导出层: {preview.LayerName}");
|
||||
LogManager.Info($"[分层管理器] 预览项数量: {preview.Items?.Count ?? 0}");
|
||||
LogManager.Info($"[分层管理器] 输出路径: {outputPath}");
|
||||
|
||||
// 直接使用预览结果中的项目
|
||||
if (preview.Items == null || preview.Items.Count == 0)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 预览结果中没有模型项");
|
||||
LogManager.Warning($"[分层管理器] 预览结果中没有模型项");
|
||||
return false;
|
||||
}
|
||||
|
||||
var itemsToExport = preview.Items;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 将导出 {itemsToExport.Count} 个模型项");
|
||||
LogManager.Info($"[分层管理器] 将导出 {itemsToExport.Count} 个模型项");
|
||||
|
||||
// 检查线程状态
|
||||
var apartmentState = System.Threading.Thread.CurrentThread.GetApartmentState();
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 当前线程状态: {apartmentState}");
|
||||
LogManager.Info($"[分层管理器] 当前线程状态: {apartmentState}");
|
||||
|
||||
// 核心修复:确保在主 UI 线程中执行 Navisworks API 调用
|
||||
bool exportResult = false;
|
||||
@ -1648,13 +1648,13 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 在主线程中执行导出操作");
|
||||
LogManager.Info($"[分层管理器] 在主线程中执行导出操作");
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
|
||||
// 保存当前可见性状态(在主线程中)
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始保存当前可见性状态");
|
||||
LogManager.Info($"[分层管理器] 开始保存当前可见性状态");
|
||||
var originalVisibilityState = SaveCurrentVisibilityState(document);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 已保存 {originalVisibilityState.Count} 个项目的可见性状态");
|
||||
LogManager.Info($"[分层管理器] 已保存 {originalVisibilityState.Count} 个项目的可见性状态");
|
||||
|
||||
try
|
||||
{
|
||||
@ -1670,7 +1670,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 收集到 {allTopLevelItems.Count} 个顶级节点");
|
||||
LogManager.Info($"[分层管理器] 收集到 {allTopLevelItems.Count} 个顶级节点");
|
||||
|
||||
// 智能隐藏策略:如果顶级节点包含要导出的项目,则保持可见;否则隐藏整个顶级分支
|
||||
var itemsToHide = new ModelItemCollection();
|
||||
@ -1686,7 +1686,7 @@ namespace NavisworksTransport
|
||||
if (topLevelItem.Equals(exportItem))
|
||||
{
|
||||
shouldKeepTopLevel = true;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 顶级节点 {topLevelItem.DisplayName} 本身被选中,保持可见");
|
||||
LogManager.Info($"[分层管理器] 顶级节点 {topLevelItem.DisplayName} 本身被选中,保持可见");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1702,7 +1702,7 @@ namespace NavisworksTransport
|
||||
if (current == topLevelItem)
|
||||
{
|
||||
shouldKeepTopLevel = true;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 顶级节点 {topLevelItem.DisplayName} 包含导出项目,保持可见");
|
||||
LogManager.Info($"[分层管理器] 顶级节点 {topLevelItem.DisplayName} 包含导出项目,保持可见");
|
||||
break;
|
||||
}
|
||||
current = current.Parent;
|
||||
@ -1718,11 +1718,11 @@ namespace NavisworksTransport
|
||||
{
|
||||
itemsToHide.Add(topLevelItem);
|
||||
hiddenCount++;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 隐藏顶级节点: {topLevelItem.DisplayName}");
|
||||
LogManager.Info($"[分层管理器] 隐藏顶级节点: {topLevelItem.DisplayName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 添加隐藏项目失败: {topLevelItem.DisplayName} - {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 添加隐藏项目失败: {topLevelItem.DisplayName} - {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1733,11 +1733,11 @@ namespace NavisworksTransport
|
||||
try
|
||||
{
|
||||
document.Models.SetHidden(itemsToHide, true);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 成功隐藏 {hiddenCount} 个顶级节点,保留导出项目可见");
|
||||
LogManager.Info($"[分层管理器] 成功隐藏 {hiddenCount} 个顶级节点,保留导出项目可见");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 隐藏操作失败: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 隐藏操作失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1749,12 +1749,12 @@ namespace NavisworksTransport
|
||||
PreventObjectPropertyExport = false
|
||||
};
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始调用ExportToNwd API(主线程)");
|
||||
LogManager.Info($"[分层管理器] 开始调用ExportToNwd API(主线程)");
|
||||
|
||||
// 在主线程中执行导出
|
||||
document.ExportToNwd(outputPath, exportOptions);
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ExportToNwd API调用完成(主线程)");
|
||||
LogManager.Info($"[分层管理器] ExportToNwd API调用完成(主线程)");
|
||||
exportResult = true;
|
||||
}
|
||||
finally
|
||||
@ -1763,11 +1763,11 @@ namespace NavisworksTransport
|
||||
try
|
||||
{
|
||||
RestoreVisibilityState(document, originalVisibilityState);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 已恢复原始可见性状态");
|
||||
LogManager.Info($"[分层管理器] 已恢复原始可见性状态");
|
||||
}
|
||||
catch (Exception restoreEx)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 恢复可见性失败: {restoreEx.Message}");
|
||||
LogManager.Error($"[分层管理器] 恢复可见性失败: {restoreEx.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1780,18 +1780,18 @@ namespace NavisworksTransport
|
||||
// 检查导出结果
|
||||
if (exportException != null)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 主线程导出异常: {exportException.Message}");
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 异常堆栈: {exportException.StackTrace}");
|
||||
LogManager.Error($"[分层管理器] 主线程导出异常: {exportException.Message}");
|
||||
LogManager.Error($"[分层管理器] 异常堆栈: {exportException.StackTrace}");
|
||||
return false;
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== ExportLayerToNwd完成 ========== 成功导出到: {outputPath}");
|
||||
LogManager.Info($"[分层管理器] ========== ExportLayerToNwd完成 ========== 成功导出到: {outputPath}");
|
||||
return exportResult;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] ExportLayerToNwd异常: {ex.Message}");
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 异常堆栈: {ex.StackTrace}");
|
||||
LogManager.Error($"[分层管理器] ExportLayerToNwd异常: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 异常堆栈: {ex.StackTrace}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1823,11 +1823,11 @@ namespace NavisworksTransport
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 保存可见性状态完成,记录了 {visibilityState.Count} 个顶级项目");
|
||||
LogManager.Info($"[分层管理器] 保存可见性状态完成,记录了 {visibilityState.Count} 个顶级项目");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 保存可见性状态失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 保存可见性状态失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return visibilityState;
|
||||
@ -1910,8 +1910,8 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== ExpandFloorItems开始 ==========");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 输入顶层节点数量: {floorTopLevelItems.Count}");
|
||||
LogManager.Info($"[分层管理器] ========== ExpandFloorItems开始 ==========");
|
||||
LogManager.Info($"[分层管理器] 输入顶层节点数量: {floorTopLevelItems.Count}");
|
||||
|
||||
var expandedItems = new ModelItemCollection();
|
||||
int totalCollected = 0;
|
||||
@ -1920,7 +1920,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始展开顶层节点: '{topLevelItem.DisplayName}'");
|
||||
LogManager.Info($"[分层管理器] 开始展开顶层节点: '{topLevelItem.DisplayName}'");
|
||||
|
||||
// 添加顶层节点本身(如果它是具体的构件)
|
||||
if (IsActualComponent(topLevelItem))
|
||||
@ -1937,21 +1937,21 @@ namespace NavisworksTransport
|
||||
expandedItems.AddRange(validChildItems);
|
||||
totalCollected += validChildItems.Count;
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 顶层节点 '{topLevelItem.DisplayName}' 展开完成: 收集到{childItems.Count}个子项,有效{validChildItems.Count}个");
|
||||
LogManager.Info($"[分层管理器] 顶层节点 '{topLevelItem.DisplayName}' 展开完成: 收集到{childItems.Count}个子项,有效{validChildItems.Count}个");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 展开顶层节点失败: {topLevelItem?.DisplayName ?? "null"}, 错误: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 展开顶层节点失败: {topLevelItem?.DisplayName ?? "null"}, 错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== ExpandFloorItems完成 ========== 总计收集: {totalCollected}个模型项");
|
||||
LogManager.Info($"[分层管理器] ========== ExpandFloorItems完成 ========== 总计收集: {totalCollected}个模型项");
|
||||
return expandedItems;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] ExpandFloorItems异常: {ex.Message}");
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 异常堆栈: {ex.StackTrace}");
|
||||
LogManager.Error($"[分层管理器] ExpandFloorItems异常: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 异常堆栈: {ex.StackTrace}");
|
||||
return new ModelItemCollection();
|
||||
}
|
||||
}
|
||||
@ -1972,7 +1972,7 @@ namespace NavisworksTransport
|
||||
// 防止递归过深
|
||||
if (currentDepth >= maxDepth)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 达到最大递归深度 {maxDepth},停止展开: {parentItem?.DisplayName}");
|
||||
LogManager.Warning($"[分层管理器] 达到最大递归深度 {maxDepth},停止展开: {parentItem?.DisplayName}");
|
||||
return childItems;
|
||||
}
|
||||
|
||||
@ -1998,18 +1998,18 @@ namespace NavisworksTransport
|
||||
// 每收集100个项目记录一次进度(只在顶层记录)
|
||||
if (currentDepth == 0 && childItems.Count % 100 == 0)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 已收集 {childItems.Count} 个子项...");
|
||||
LogManager.Info($"[分层管理器] 已收集 {childItems.Count} 个子项...");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 收集子项失败: {child?.DisplayName ?? "null"}, 错误: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 收集子项失败: {child?.DisplayName ?? "null"}, 错误: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] CollectAllChildItems异常: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] CollectAllChildItems异常: {ex.Message}");
|
||||
}
|
||||
|
||||
return childItems;
|
||||
@ -2028,7 +2028,7 @@ namespace NavisworksTransport
|
||||
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 开始验证 {items.Count} 个模型项的有效性...");
|
||||
LogManager.Info($"[分层管理器] 开始验证 {items.Count} 个模型项的有效性...");
|
||||
|
||||
foreach (ModelItem item in items)
|
||||
{
|
||||
@ -2051,17 +2051,17 @@ namespace NavisworksTransport
|
||||
catch (Exception ex)
|
||||
{
|
||||
invalidCount++;
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 发现无效模型项: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 发现无效模型项: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 模型项验证完成: 总数{items.Count}, 有效{validItems.Count}, 空项{nullCount}, 无效{invalidCount}");
|
||||
LogManager.Info($"[分层管理器] 模型项验证完成: 总数{items.Count}, 有效{validItems.Count}, 空项{nullCount}, 无效{invalidCount}");
|
||||
|
||||
return validItems;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 验证模型项时发生异常: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 验证模型项时发生异常: {ex.Message}");
|
||||
// 异常时返回原始集合,避免完全失败
|
||||
return items;
|
||||
}
|
||||
@ -2099,7 +2099,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 判断构件类型失败: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 判断构件类型失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -2113,9 +2113,9 @@ namespace NavisworksTransport
|
||||
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ===== GetFloorItems开始 =====");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 目标楼层名称: '{floorName}'");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 输入模型项数: {allItems.Count}");
|
||||
LogManager.Info($"[分层管理器] ===== GetFloorItems开始 =====");
|
||||
LogManager.Info($"[分层管理器] 目标楼层名称: '{floorName}'");
|
||||
LogManager.Info($"[分层管理器] 输入模型项数: {allItems.Count}");
|
||||
|
||||
int checkedCount = 0;
|
||||
int matchedCount = 0;
|
||||
@ -2138,27 +2138,27 @@ namespace NavisworksTransport
|
||||
|
||||
if (matchedCount <= 5) // 只记录前5个匹配的详细信息
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 找到匹配模型项 #{matchedCount}: {item.DisplayName}");
|
||||
LogManager.Info($"[分层管理器] 找到匹配模型项 #{matchedCount}: {item.DisplayName}");
|
||||
}
|
||||
}
|
||||
|
||||
// 每处理1000个项记录进度
|
||||
if (checkedCount % 1000 == 0)
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 已检查 {checkedCount}/{allItems.Count} 个模型项,找到 {matchedCount} 个匹配");
|
||||
LogManager.Info($"[分层管理器] 已检查 {checkedCount}/{allItems.Count} 个模型项,找到 {matchedCount} 个匹配");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 检查模型项楼层属性时出错: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 检查模型项楼层属性时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ===== GetFloorItems完成 ===== 检查了 {checkedCount} 个模型项,找到 {matchedCount} 个匹配的楼层项目");
|
||||
LogManager.Info($"[分层管理器] ===== GetFloorItems完成 ===== 检查了 {checkedCount} 个模型项,找到 {matchedCount} 个匹配的楼层项目");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 获取楼层项目失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 获取楼层项目失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return floorItems;
|
||||
@ -2194,7 +2194,7 @@ namespace NavisworksTransport
|
||||
// 详细调试日志 - 当找到楼层相关属性时
|
||||
if (!string.IsNullOrEmpty(propValue))
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 楼层属性检查: 项目='{item.DisplayName}', 属性='{property.DisplayName}', 值='{propValue}', 目标='{floorName}', 匹配={isMatch}");
|
||||
LogManager.Info($"[分层管理器] 楼层属性检查: 项目='{item.DisplayName}', 属性='{property.DisplayName}', 值='{propValue}', 目标='{floorName}', 匹配={isMatch}");
|
||||
}
|
||||
|
||||
if (isMatch)
|
||||
@ -2209,7 +2209,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 检查楼层属性时出错: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 检查楼层属性时出错: {ex.Message}");
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -2244,7 +2244,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 检查属性值时出错: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 检查属性值时出错: {ex.Message}");
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -2285,7 +2285,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 处理项目可见性状态时出错: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 处理项目可见性状态时出错: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2296,14 +2296,14 @@ namespace NavisworksTransport
|
||||
if (itemsToHide.Count > 0)
|
||||
{
|
||||
document.Models.SetHidden(itemsToHide, true);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 恢复隐藏 {itemsToHide.Count} 个项目");
|
||||
LogManager.Info($"[分层管理器] 恢复隐藏 {itemsToHide.Count} 个项目");
|
||||
}
|
||||
|
||||
LogManager.Info("[SimplifiedModelSplitter] 可见性状态恢复完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 恢复可见性状态失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 恢复可见性状态失败: {ex.Message}");
|
||||
// 失败时至少确保模型处于可见状态
|
||||
try
|
||||
{
|
||||
@ -2312,7 +2312,7 @@ namespace NavisworksTransport
|
||||
}
|
||||
catch (Exception resetEx)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 重置可见性也失败: {resetEx.Message}");
|
||||
LogManager.Error($"[分层管理器] 重置可见性也失败: {resetEx.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2328,9 +2328,9 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== 开始基础导出测试 ==========");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 测试文件路径: {outputPath}");
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 最大测试项目数: {maxItems}");
|
||||
LogManager.Info($"[分层管理器] ========== 开始基础导出测试 ==========");
|
||||
LogManager.Info($"[分层管理器] 测试文件路径: {outputPath}");
|
||||
LogManager.Info($"[分层管理器] 最大测试项目数: {maxItems}");
|
||||
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models?.Count == 0)
|
||||
@ -2360,11 +2360,11 @@ namespace NavisworksTransport
|
||||
string displayName = item.DisplayName;
|
||||
testItems.Add(item);
|
||||
addedCount++;
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 添加测试项目 #{addedCount}: {displayName}");
|
||||
LogManager.Info($"[分层管理器] 添加测试项目 #{addedCount}: {displayName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Warning($"[SimplifiedModelSplitter] 跳过无效测试项目: {ex.Message}");
|
||||
LogManager.Warning($"[分层管理器] 跳过无效测试项目: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2374,14 +2374,14 @@ namespace NavisworksTransport
|
||||
return false;
|
||||
}
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 准备测试导出 {testItems.Count} 个模型项");
|
||||
LogManager.Info($"[分层管理器] 准备测试导出 {testItems.Count} 个模型项");
|
||||
|
||||
// 确保输出目录存在
|
||||
string directory = Path.GetDirectoryName(outputPath);
|
||||
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 创建测试输出目录: {directory}");
|
||||
LogManager.Info($"[分层管理器] 创建测试输出目录: {directory}");
|
||||
}
|
||||
|
||||
// 创建测试预览结果
|
||||
@ -2403,20 +2403,20 @@ namespace NavisworksTransport
|
||||
// 执行测试导出
|
||||
bool testResult = ExportLayerToNwd(testPreview, outputPath, testConfig);
|
||||
|
||||
LogManager.Info($"[SimplifiedModelSplitter] ========== 基础导出测试完成 ========== 结果: {testResult}");
|
||||
LogManager.Info($"[分层管理器] ========== 基础导出测试完成 ========== 结果: {testResult}");
|
||||
|
||||
if (testResult && File.Exists(outputPath))
|
||||
{
|
||||
var fileInfo = new FileInfo(outputPath);
|
||||
LogManager.Info($"[SimplifiedModelSplitter] 测试文件生成成功,大小: {fileInfo.Length / 1024} KB");
|
||||
LogManager.Info($"[分层管理器] 测试文件生成成功,大小: {fileInfo.Length / 1024} KB");
|
||||
}
|
||||
|
||||
return testResult;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 基础导出测试失败: {ex.Message}");
|
||||
LogManager.Error($"[SimplifiedModelSplitter] 测试异常堆栈: {ex.StackTrace}");
|
||||
LogManager.Error($"[分层管理器] 基础导出测试失败: {ex.Message}");
|
||||
LogManager.Error($"[分层管理器] 测试异常堆栈: {ex.StackTrace}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,206 @@ using NavisApplication = Autodesk.Navisworks.Api.Application;
|
||||
|
||||
namespace NavisworksTransport
|
||||
{
|
||||
/// <summary>
|
||||
/// 模型结构缓存 - 优化重复遍历性能
|
||||
/// </summary>
|
||||
internal static class ModelStructureCache
|
||||
{
|
||||
// 缓存数据
|
||||
private static Dictionary<ModelItem, HashSet<ModelItem>> _siblingsCache;
|
||||
private static Dictionary<ModelItem, ModelItem> _parentCache;
|
||||
private static Dictionary<ModelItem, HashSet<ModelItem>> _childrenCache;
|
||||
private static HashSet<ModelItem> _allModelItems;
|
||||
|
||||
// 缓存验证
|
||||
private static string _documentIdentifier;
|
||||
private static DateTime _cacheTime;
|
||||
private static readonly object _cacheLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 检查缓存是否有效,无效则清除
|
||||
/// </summary>
|
||||
public static void InvalidateIfDocumentChanged(Document document)
|
||||
{
|
||||
lock (_cacheLock)
|
||||
{
|
||||
string currentId = GenerateDocumentId(document);
|
||||
if (currentId != _documentIdentifier)
|
||||
{
|
||||
LogManager.Debug($"[ModelStructureCache] 文档已改变,清除缓存");
|
||||
ClearCache();
|
||||
_documentIdentifier = currentId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有需要隐藏的兄弟节点(批量优化版)
|
||||
/// </summary>
|
||||
public static HashSet<ModelItem> GetSiblingsToHide(HashSet<ModelItem> visibleItems)
|
||||
{
|
||||
lock (_cacheLock)
|
||||
{
|
||||
EnsureCacheBuilt();
|
||||
|
||||
var siblingsToHide = new HashSet<ModelItem>();
|
||||
var processedParents = new HashSet<ModelItem>();
|
||||
|
||||
foreach (var item in visibleItems)
|
||||
{
|
||||
if (_parentCache.TryGetValue(item, out var parent) && parent != null)
|
||||
{
|
||||
if (!processedParents.Contains(parent))
|
||||
{
|
||||
processedParents.Add(parent);
|
||||
|
||||
// 获取缓存的兄弟节点
|
||||
if (_siblingsCache.TryGetValue(item, out var siblings))
|
||||
{
|
||||
foreach (var sibling in siblings)
|
||||
{
|
||||
if (!visibleItems.Contains(sibling))
|
||||
{
|
||||
siblingsToHide.Add(sibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogManager.Debug($"[ModelStructureCache] 从缓存获取兄弟节点: 处理了{processedParents.Count}个父节点,找到{siblingsToHide.Count}个需隐藏项");
|
||||
return siblingsToHide;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建缓存
|
||||
/// </summary>
|
||||
private static void EnsureCacheBuilt()
|
||||
{
|
||||
if (_siblingsCache != null && _parentCache != null)
|
||||
return;
|
||||
|
||||
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
LogManager.Info("[ModelStructureCache] 开始构建模型结构缓存...");
|
||||
|
||||
_siblingsCache = new Dictionary<ModelItem, HashSet<ModelItem>>();
|
||||
_parentCache = new Dictionary<ModelItem, ModelItem>();
|
||||
_childrenCache = new Dictionary<ModelItem, HashSet<ModelItem>>();
|
||||
_allModelItems = new HashSet<ModelItem>();
|
||||
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models == null) return;
|
||||
|
||||
// 遍历一次,建立所有关系
|
||||
foreach (Model model in document.Models)
|
||||
{
|
||||
if (model.RootItem != null)
|
||||
{
|
||||
BuildCacheRecursive(model.RootItem, null);
|
||||
}
|
||||
}
|
||||
|
||||
// 构建兄弟节点缓存
|
||||
foreach (var kvp in _childrenCache)
|
||||
{
|
||||
var parent = kvp.Key;
|
||||
var children = kvp.Value;
|
||||
|
||||
// 为每个子节点建立兄弟关系
|
||||
foreach (var child in children)
|
||||
{
|
||||
_siblingsCache[child] = new HashSet<ModelItem>(children);
|
||||
}
|
||||
}
|
||||
|
||||
_cacheTime = DateTime.Now;
|
||||
stopwatch.Stop();
|
||||
|
||||
LogManager.Info($"[ModelStructureCache] 缓存构建完成: {_allModelItems.Count}个节点, " +
|
||||
$"{_parentCache.Count}个父子关系, {_siblingsCache.Count}个兄弟关系, " +
|
||||
$"耗时{stopwatch.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归构建缓存
|
||||
/// </summary>
|
||||
private static void BuildCacheRecursive(ModelItem item, ModelItem parent)
|
||||
{
|
||||
if (item == null) return;
|
||||
|
||||
_allModelItems.Add(item);
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
_parentCache[item] = parent;
|
||||
|
||||
if (!_childrenCache.ContainsKey(parent))
|
||||
_childrenCache[parent] = new HashSet<ModelItem>();
|
||||
_childrenCache[parent].Add(item);
|
||||
}
|
||||
|
||||
// 递归处理子节点
|
||||
if (item.Children != null && item.Children.Count() > 0)
|
||||
{
|
||||
foreach (ModelItem child in item.Children)
|
||||
{
|
||||
BuildCacheRecursive(child, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清除缓存
|
||||
/// </summary>
|
||||
public static void ClearCache()
|
||||
{
|
||||
_siblingsCache?.Clear();
|
||||
_parentCache?.Clear();
|
||||
_childrenCache?.Clear();
|
||||
_allModelItems?.Clear();
|
||||
|
||||
_siblingsCache = null;
|
||||
_parentCache = null;
|
||||
_childrenCache = null;
|
||||
_allModelItems = null;
|
||||
|
||||
// 强制垃圾回收
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
|
||||
LogManager.Debug("[ModelStructureCache] 缓存已清除");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成文档唯一标识
|
||||
/// </summary>
|
||||
private static string GenerateDocumentId(Document document)
|
||||
{
|
||||
if (document == null) return "empty";
|
||||
return $"{document.FileName}_{document.Models?.Count ?? 0}_{document.CurrentSelection?.SelectedItems?.Count ?? 0}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存统计信息
|
||||
/// </summary>
|
||||
public static string GetCacheStatistics()
|
||||
{
|
||||
lock (_cacheLock)
|
||||
{
|
||||
if (_siblingsCache == null) return "缓存未建立";
|
||||
|
||||
var age = DateTime.Now - _cacheTime;
|
||||
return $"缓存统计: {_allModelItems?.Count ?? 0}个节点, " +
|
||||
$"{_parentCache?.Count ?? 0}个父子关系, " +
|
||||
$"{_siblingsCache?.Count ?? 0}个兄弟关系, " +
|
||||
$"缓存年龄: {age.TotalSeconds:F1}秒";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可见性操作结果
|
||||
/// </summary>
|
||||
@ -247,6 +447,7 @@ namespace NavisworksTransport
|
||||
|
||||
/// <summary>
|
||||
/// 仅显示指定的模型项集合,隐藏其他所有项
|
||||
/// 使用缓存优化:避免重复遍历模型结构
|
||||
/// </summary>
|
||||
/// <param name="itemsToShow">要显示的模型项集合</param>
|
||||
/// <returns>操作结果</returns>
|
||||
@ -254,6 +455,8 @@ namespace NavisworksTransport
|
||||
{
|
||||
try
|
||||
{
|
||||
var stopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document == null || document.Models.Count == 0)
|
||||
{
|
||||
@ -273,47 +476,102 @@ namespace NavisworksTransport
|
||||
};
|
||||
}
|
||||
|
||||
LogManager.Debug($"[VisibilityManager] 开始隔离显示 {itemsToShow.Count} 个项目");
|
||||
|
||||
// 检查并更新缓存
|
||||
ModelStructureCache.InvalidateIfDocumentChanged(document);
|
||||
|
||||
// 记录内存使用情况
|
||||
long memoryBefore = GC.GetTotalMemory(false) / 1024 / 1024;
|
||||
LogManager.Debug($"[VisibilityManager] 操作前内存: {memoryBefore}MB");
|
||||
|
||||
// 首先重置所有隐藏状态
|
||||
document.Models.ResetAllHidden();
|
||||
|
||||
// 使用新的智能保护算法构建完整的可见性保护集合
|
||||
var protectionSet = BuildProtectionSet(itemsToShow);
|
||||
// 使用HashSet提高性能(预设容量)
|
||||
var visibleSet = new HashSet<ModelItem>(itemsToShow.Count * 10);
|
||||
|
||||
// 获取所有项目
|
||||
var allItems = document.Models.SelectMany(model =>
|
||||
model.RootItem.DescendantsAndSelf).ToList();
|
||||
|
||||
// 创建需要隐藏的项目集合(所有项目除了保护集合中的)
|
||||
var itemsToHide = new ModelItemCollection();
|
||||
foreach (var item in allItems)
|
||||
// 步骤1:收集所有需要显示的项目(包括祖先和后代)
|
||||
var collectStopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
foreach (ModelItem item in itemsToShow)
|
||||
{
|
||||
if (!protectionSet.Contains(item))
|
||||
// 添加祖先路径(确保父节点可见)
|
||||
if (item.AncestorsAndSelf != null)
|
||||
{
|
||||
itemsToHide.Add(item);
|
||||
foreach (ModelItem ancestor in item.AncestorsAndSelf)
|
||||
{
|
||||
visibleSet.Add(ancestor);
|
||||
}
|
||||
}
|
||||
// 添加所有后代(确保子节点可见)
|
||||
if (item.Descendants != null)
|
||||
{
|
||||
foreach (ModelItem descendant in item.Descendants)
|
||||
{
|
||||
visibleSet.Add(descendant);
|
||||
}
|
||||
}
|
||||
}
|
||||
collectStopwatch.Stop();
|
||||
LogManager.Debug($"[VisibilityManager] 收集可见项完成,共 {visibleSet.Count} 个,耗时 {collectStopwatch.ElapsedMilliseconds}ms");
|
||||
|
||||
// 隐藏不在保护集合中的项目
|
||||
if (itemsToHide.Any())
|
||||
// 步骤2:使用缓存获取需要隐藏的兄弟节点
|
||||
var cacheStopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
var siblingsToHide = ModelStructureCache.GetSiblingsToHide(visibleSet);
|
||||
cacheStopwatch.Stop();
|
||||
LogManager.Debug($"[VisibilityManager] 从缓存获取兄弟节点,耗时 {cacheStopwatch.ElapsedMilliseconds}ms");
|
||||
|
||||
// 步骤3:构建最终的隐藏集合
|
||||
var finalHidden = new ModelItemCollection();
|
||||
foreach (var item in siblingsToHide)
|
||||
{
|
||||
document.Models.SetHidden(itemsToHide, true);
|
||||
finalHidden.Add(item);
|
||||
}
|
||||
|
||||
LogManager.Debug($"[VisibilityManager] 过滤完成,需要隐藏 {finalHidden.Count} 个项目");
|
||||
|
||||
// 步骤4:执行隐藏操作
|
||||
if (finalHidden.Any())
|
||||
{
|
||||
var hideStopwatch = System.Diagnostics.Stopwatch.StartNew();
|
||||
document.Models.SetHidden(finalHidden, true);
|
||||
hideStopwatch.Stop();
|
||||
LogManager.Debug($"[VisibilityManager] 执行隐藏操作,耗时 {hideStopwatch.ElapsedMilliseconds}ms");
|
||||
}
|
||||
|
||||
stopwatch.Stop();
|
||||
|
||||
// 计算结果统计
|
||||
int totalItemsCount = allItems.Count;
|
||||
int hiddenCount = itemsToHide.Count;
|
||||
int visibleCount = protectionSet.Count;
|
||||
int hiddenCount = finalHidden.Count;
|
||||
int visibleCount = visibleSet.Count;
|
||||
|
||||
// 记录内存和缓存信息
|
||||
long memoryAfter = GC.GetTotalMemory(false) / 1024 / 1024;
|
||||
LogManager.Debug($"[VisibilityManager] 操作后内存: {memoryAfter}MB (增加 {memoryAfter - memoryBefore}MB)");
|
||||
LogManager.Debug($"[VisibilityManager] {ModelStructureCache.GetCacheStatistics()}");
|
||||
|
||||
LogManager.Info($"[VisibilityManager] 隔离显示完成,总耗时 {stopwatch.ElapsedMilliseconds}ms");
|
||||
|
||||
// 如果内存增长过多,考虑触发GC
|
||||
if (memoryAfter - memoryBefore > 50) // 增长超过50MB
|
||||
{
|
||||
LogManager.Debug("[VisibilityManager] 内存增长较多,触发垃圾回收");
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
return new VisibilityOperationResult
|
||||
{
|
||||
Success = true,
|
||||
Message = $"已隔离显示 {itemsToShow.Count} 个核心项目(含路径 {visibleCount} 个可见项),隐藏了 {hiddenCount} 个项目",
|
||||
HiddenCount = hiddenCount,
|
||||
TotalCount = totalItemsCount
|
||||
TotalCount = hiddenCount + visibleCount
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"[VisibilityManager] 隔离显示失败: {ex.Message}");
|
||||
return new VisibilityOperationResult
|
||||
{
|
||||
Success = false,
|
||||
|
||||
@ -250,7 +250,6 @@ namespace NavisworksTransport.PathPlanning
|
||||
|
||||
// 检查基本可通行性和高度约束
|
||||
bool isPassable = cell.IsWalkable;
|
||||
bool heightRestricted = false;
|
||||
|
||||
if (isPassable && cell.PassableHeights != null && cell.PassableHeights.Any())
|
||||
{
|
||||
@ -258,7 +257,6 @@ namespace NavisworksTransport.PathPlanning
|
||||
if (!heightOk)
|
||||
{
|
||||
heightConstrainedCells++;
|
||||
heightRestricted = true;
|
||||
|
||||
// 详细日志:记录被高度约束排除的单元格(仅记录前10个避免日志过多)
|
||||
if (heightConstrainedCells <= 10)
|
||||
|
||||
@ -1,205 +0,0 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using Autodesk.Navisworks.Api;
|
||||
using NavisApplication = Autodesk.Navisworks.Api.Application;
|
||||
|
||||
namespace NavisworksTransport.UI.Forms
|
||||
{
|
||||
/// <summary>
|
||||
/// 简单的DockPane控件,用于验证DockPanePlugin基础功能
|
||||
/// </summary>
|
||||
public partial class SimpleDockPaneControl : UserControl
|
||||
{
|
||||
private Label _statusLabel;
|
||||
private Button _testButton;
|
||||
private ListView _infoListView;
|
||||
|
||||
public SimpleDockPaneControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
InitializeSession();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.SuspendLayout();
|
||||
|
||||
// 设置控件基本属性
|
||||
this.Size = new Size(400, 600);
|
||||
this.BackColor = SystemColors.Control;
|
||||
this.Padding = new Padding(10);
|
||||
|
||||
// 创建状态标签
|
||||
_statusLabel = new Label
|
||||
{
|
||||
Text = "物流路径规划插件 - DockPane模式",
|
||||
Font = new Font("微软雅黑", 10, FontStyle.Bold),
|
||||
ForeColor = System.Drawing.Color.DarkBlue,
|
||||
AutoSize = true,
|
||||
Location = new Point(10, 10)
|
||||
};
|
||||
this.Controls.Add(_statusLabel);
|
||||
|
||||
// 创建测试按钮
|
||||
_testButton = new Button
|
||||
{
|
||||
Text = "测试功能",
|
||||
Size = new Size(100, 30),
|
||||
Location = new Point(10, 40),
|
||||
Font = new Font("微软雅黑", 9)
|
||||
};
|
||||
_testButton.Click += OnTestButtonClick;
|
||||
this.Controls.Add(_testButton);
|
||||
|
||||
// 创建信息列表
|
||||
_infoListView = new ListView
|
||||
{
|
||||
View = System.Windows.Forms.View.Details,
|
||||
FullRowSelect = true,
|
||||
GridLines = true,
|
||||
Location = new Point(10, 80),
|
||||
Size = new Size(380, 500),
|
||||
Font = new Font("微软雅黑", 8)
|
||||
};
|
||||
|
||||
// 添加列
|
||||
_infoListView.Columns.Add("时间", 120);
|
||||
_infoListView.Columns.Add("事件", 100);
|
||||
_infoListView.Columns.Add("描述", 160);
|
||||
|
||||
this.Controls.Add(_infoListView);
|
||||
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
|
||||
private void InitializeSession()
|
||||
{
|
||||
GlobalExceptionHandler.SafeExecute(() =>
|
||||
{
|
||||
LogManager.Info("=== SimpleDockPaneControl 初始化开始 ===");
|
||||
|
||||
// 初始化全局异常处理
|
||||
GlobalExceptionHandler.Initialize();
|
||||
|
||||
// 订阅选择变化事件
|
||||
if (NavisApplication.ActiveDocument != null)
|
||||
{
|
||||
NavisApplication.ActiveDocument.CurrentSelection.Changed += OnSelectionChanged;
|
||||
}
|
||||
|
||||
// 添加初始化信息
|
||||
AddInfoItem("初始化", "插件已加载");
|
||||
|
||||
LogManager.Info("SimpleDockPaneControl 初始化完成");
|
||||
|
||||
}, "初始化SimpleDockPaneControl");
|
||||
}
|
||||
|
||||
private void OnTestButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
GlobalExceptionHandler.SafeExecute(() =>
|
||||
{
|
||||
LogManager.Info("测试按钮被点击");
|
||||
|
||||
// 获取当前文档信息
|
||||
var doc = NavisApplication.ActiveDocument;
|
||||
if (doc != null)
|
||||
{
|
||||
var modelCount = doc.Models?.Count ?? 0;
|
||||
var selectedCount = doc.CurrentSelection?.SelectedItems?.Count ?? 0;
|
||||
|
||||
AddInfoItem("测试", $"模型数量: {modelCount}, 选中: {selectedCount}");
|
||||
|
||||
MessageBox.Show($"当前文档信息:\n模型数量: {modelCount}\n选中项目: {selectedCount}",
|
||||
"测试结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddInfoItem("测试", "没有打开的文档");
|
||||
MessageBox.Show("请先打开一个Navisworks文档",
|
||||
"提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
|
||||
}, "测试按钮点击");
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.BeginInvoke(new Action(() => OnSelectionChanged(sender, e)));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var selectedCount = NavisApplication.ActiveDocument?.CurrentSelection?.SelectedItems?.Count ?? 0;
|
||||
AddInfoItem("选择变更", $"选中 {selectedCount} 个项目");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"处理选择变更事件失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void AddInfoItem(string eventType, string description)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.BeginInvoke(new Action(() => AddInfoItem(eventType, description)));
|
||||
return;
|
||||
}
|
||||
|
||||
var item = new ListViewItem(DateTime.Now.ToString("HH:mm:ss"));
|
||||
item.SubItems.Add(eventType);
|
||||
item.SubItems.Add(description);
|
||||
|
||||
_infoListView.Items.Insert(0, item);
|
||||
|
||||
// 保持最多50条记录
|
||||
while (_infoListView.Items.Count > 50)
|
||||
{
|
||||
_infoListView.Items.RemoveAt(_infoListView.Items.Count - 1);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"添加信息项失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info("开始清理SimpleDockPaneControl资源");
|
||||
|
||||
// 取消事件订阅
|
||||
if (NavisApplication.ActiveDocument != null)
|
||||
{
|
||||
NavisApplication.ActiveDocument.CurrentSelection.Changed -= OnSelectionChanged;
|
||||
}
|
||||
|
||||
AddInfoItem("清理", "资源已清理");
|
||||
|
||||
LogManager.Info("SimpleDockPaneControl资源清理完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"清理SimpleDockPaneControl资源失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Cleanup();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using System.Windows.Controls;
|
||||
using NavisworksTransport.UI.WPF.ViewModels;
|
||||
|
||||
namespace NavisworksTransport.UI.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// 简化的物流控制面板,用于诊断ViewModel问题
|
||||
/// </summary>
|
||||
public partial class SimpleLogisticsControlPanel : UserControl
|
||||
{
|
||||
public SimpleLogisticsControlViewModel ViewModel { get; private set; }
|
||||
|
||||
public SimpleLogisticsControlPanel()
|
||||
{
|
||||
try
|
||||
{
|
||||
NavisworksTransport.LogManager.Info("SimpleLogisticsControlPanel构造函数开始");
|
||||
|
||||
NavisworksTransport.LogManager.Info("开始InitializeComponent...");
|
||||
InitializeComponent();
|
||||
NavisworksTransport.LogManager.Info("InitializeComponent完成");
|
||||
|
||||
NavisworksTransport.LogManager.Info("开始创建ViewModel...");
|
||||
// 使用简化的ViewModel
|
||||
ViewModel = new SimpleLogisticsControlViewModel();
|
||||
NavisworksTransport.LogManager.Info("ViewModel创建完成");
|
||||
|
||||
NavisworksTransport.LogManager.Info("设置DataContext...");
|
||||
DataContext = ViewModel;
|
||||
NavisworksTransport.LogManager.Info("DataContext设置完成");
|
||||
|
||||
NavisworksTransport.LogManager.Info("SimpleLogisticsControlPanel构造函数完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NavisworksTransport.LogManager.Error($"SimpleLogisticsControlPanel构造函数异常: {ex.Message}");
|
||||
NavisworksTransport.LogManager.Error($"堆栈跟踪: {ex.StackTrace}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
var stackPanel = new StackPanel();
|
||||
stackPanel.Margin = new System.Windows.Thickness(10);
|
||||
|
||||
var titleTextBlock = new TextBlock();
|
||||
titleTextBlock.Text = "简化的物流控制面板";
|
||||
titleTextBlock.FontSize = 16;
|
||||
titleTextBlock.FontWeight = System.Windows.FontWeights.Bold;
|
||||
titleTextBlock.Margin = new System.Windows.Thickness(0, 0, 0, 10);
|
||||
|
||||
var statusTextBlock = new TextBlock();
|
||||
statusTextBlock.SetBinding(TextBlock.TextProperty,
|
||||
new System.Windows.Data.Binding("StatusText"));
|
||||
statusTextBlock.Margin = new System.Windows.Thickness(0, 0, 0, 5);
|
||||
|
||||
var selectedModelsTextBlock = new TextBlock();
|
||||
selectedModelsTextBlock.SetBinding(TextBlock.TextProperty,
|
||||
new System.Windows.Data.Binding("SelectedModelsText"));
|
||||
|
||||
stackPanel.Children.Add(titleTextBlock);
|
||||
stackPanel.Children.Add(statusTextBlock);
|
||||
stackPanel.Children.Add(selectedModelsTextBlock);
|
||||
|
||||
this.Content = stackPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,6 @@ using System.Windows.Media;
|
||||
using NavisworksTransport.UI.WPF.Collections;
|
||||
using NavisworksTransport.UI.WPF.Models;
|
||||
using NavisworksTransport.UI.WPF.Commands;
|
||||
using NavisworksTransport.Commands;
|
||||
using Autodesk.Navisworks.Api;
|
||||
using NavisApplication = Autodesk.Navisworks.Api.Application;
|
||||
using NavisworksTransport.Utils;
|
||||
@ -40,6 +39,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
#region 私有字段和依赖注入
|
||||
|
||||
private readonly FloorDetector _floorDetector;
|
||||
private readonly FloorAttributeManager _floorAttributeManager = new FloorAttributeManager();
|
||||
private readonly ModelSplitterManager _modelSplitterManager;
|
||||
private readonly AttributeGrouper _attributeGrouper;
|
||||
private readonly UIStateManager _uiStateManager;
|
||||
@ -655,14 +655,12 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
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))
|
||||
// 使用新的快速检查方法
|
||||
if (_floorAttributeManager.HasFloorAttributes(item))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -685,30 +683,33 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!HasSelectedModels || IsProcessing)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var document = Autodesk.Navisworks.Api.Application.ActiveDocument;
|
||||
if (document?.CurrentSelection?.SelectedItems == null || document.CurrentSelection.SelectedItems.Count == 0)
|
||||
if (IsProcessing || !HasSelectedItems)
|
||||
return false;
|
||||
|
||||
var floorManager = new FloorAttributeManager();
|
||||
// 检查是否有任何选中模型拥有分层属性
|
||||
foreach (ModelItem item in document.CurrentSelection.SelectedItems)
|
||||
// 检查选中的模型是否有楼层属性
|
||||
var document = Autodesk.Navisworks.Api.Application.ActiveDocument;
|
||||
if (document?.CurrentSelection?.SelectedItems?.Count > 0)
|
||||
{
|
||||
string floorLevel = floorManager.GetFloorLevel(item);
|
||||
if (!string.IsNullOrEmpty(floorLevel))
|
||||
var selection = document.CurrentSelection.SelectedItems;
|
||||
|
||||
foreach (var item in selection)
|
||||
{
|
||||
return true; // 只要找到一个有属性的就可以清除
|
||||
// 使用新的 Native API 方法
|
||||
var floorLevel = _floorAttributeManager.GetFloorProperty(item, "楼层");
|
||||
if (!string.IsNullOrEmpty(floorLevel))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false; // 没有找到任何有属性的模型
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false; // 出错时默认禁用
|
||||
LogManager.Error($"[LayerManagementViewModel] 检查清除楼层属性条件异常: {ex.Message}", ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3147,7 +3148,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
var floorManager = new FloorAttributeManager();
|
||||
// 使用成员变量 _floorAttributeManager
|
||||
var selectedItems = document.CurrentSelection.SelectedItems.ToList();
|
||||
var successCount = 0;
|
||||
|
||||
@ -3155,7 +3156,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
bool result = floorManager.SetFloorAttribute(
|
||||
bool result = _floorAttributeManager.SetFloorAttribute(
|
||||
item,
|
||||
SelectedFloorLevel,
|
||||
string.IsNullOrWhiteSpace(SelectedZone) ? null : SelectedZone,
|
||||
@ -3207,7 +3208,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
return new { Success = false, Count = 0, Message = "请先选择模型元素" };
|
||||
}
|
||||
|
||||
var floorManager = new FloorAttributeManager();
|
||||
// 使用成员变量 _floorAttributeManager
|
||||
var selectedItems = document.CurrentSelection.SelectedItems.ToList();
|
||||
var successCount = 0;
|
||||
|
||||
@ -3215,7 +3216,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
bool itemResult = floorManager.ClearFloorAttribute(item);
|
||||
bool itemResult = _floorAttributeManager.ClearFloorAttribute(item);
|
||||
if (itemResult)
|
||||
{
|
||||
successCount++;
|
||||
@ -3313,7 +3314,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
var floorManager = new FloorAttributeManager();
|
||||
var selectedItems = document.CurrentSelection.SelectedItems.ToList();
|
||||
var floorAttributeInfo = new List<string>();
|
||||
|
||||
@ -3321,7 +3321,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
string floorLevel = floorManager.GetFloorLevel(item);
|
||||
string floorLevel = _floorAttributeManager.GetFloorProperty(item, "楼层");
|
||||
string itemName = item.DisplayName ?? "未命名";
|
||||
|
||||
if (!string.IsNullOrEmpty(floorLevel))
|
||||
@ -3402,13 +3402,13 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
|
||||
try
|
||||
{
|
||||
var floorManager = new FloorAttributeManager();
|
||||
// 使用成员变量 _floorAttributeManager
|
||||
var selectedItems = document.CurrentSelection.SelectedItems.ToList();
|
||||
|
||||
foreach (var item in selectedItems)
|
||||
{
|
||||
// 使用新的SetSingleLayerAttribute方法,只设置指定的属性类型
|
||||
bool result = floorManager.SetSingleLayerAttribute(item, SelectedLayerParameter, SelectedParameterValue);
|
||||
bool result = _floorAttributeManager.SetSingleLayerAttribute(item, SelectedLayerParameter, SelectedParameterValue);
|
||||
|
||||
if (result)
|
||||
{
|
||||
@ -3459,14 +3459,14 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
|
||||
try
|
||||
{
|
||||
var floorManager = new FloorAttributeManager();
|
||||
// 使用成员变量 _floorAttributeManager
|
||||
var selectedItems = document.CurrentSelection.SelectedItems.ToList();
|
||||
|
||||
foreach (var item in selectedItems)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool result = floorManager.ClearFloorAttribute(item);
|
||||
bool result = _floorAttributeManager.ClearFloorAttribute(item);
|
||||
if (result)
|
||||
{
|
||||
processedItems++;
|
||||
@ -3524,7 +3524,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
var floorManager = new FloorAttributeManager();
|
||||
var selectedItems = document.CurrentSelection.SelectedItems.ToList();
|
||||
var totalItems = selectedItems.Count;
|
||||
var attributeInfo = new System.Text.StringBuilder();
|
||||
@ -3542,21 +3541,21 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
var itemAttributes = new List<string>();
|
||||
|
||||
// 获取楼层属性
|
||||
var floorLevel = floorManager.GetFloorLevel(item);
|
||||
var floorLevel = _floorAttributeManager.GetFloorProperty(item, "楼层");
|
||||
if (!string.IsNullOrEmpty(floorLevel))
|
||||
{
|
||||
itemAttributes.Add($"楼层={floorLevel}");
|
||||
}
|
||||
|
||||
// 获取区域属性
|
||||
var zone = floorManager.GetZoneAttribute(item);
|
||||
var zone = _floorAttributeManager.GetFloorProperty(item, "区域");
|
||||
if (!string.IsNullOrEmpty(zone))
|
||||
{
|
||||
itemAttributes.Add($"区域={zone}");
|
||||
}
|
||||
|
||||
// 获取子系统属性
|
||||
var subsystem = floorManager.GetSubSystemAttribute(item);
|
||||
var subsystem = _floorAttributeManager.GetFloorProperty(item, "子系统");
|
||||
if (!string.IsNullOrEmpty(subsystem))
|
||||
{
|
||||
itemAttributes.Add($"子系统={subsystem}");
|
||||
|
||||
@ -1,48 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 简化的物流控制面板ViewModel,用于诊断问题
|
||||
/// </summary>
|
||||
public class SimpleLogisticsControlViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _statusText = "简化ViewModel已加载";
|
||||
private string _selectedModelsText = "选中模型: 0 个";
|
||||
|
||||
public string StatusText
|
||||
{
|
||||
get => _statusText;
|
||||
set => SetProperty(ref _statusText, value);
|
||||
}
|
||||
|
||||
public string SelectedModelsText
|
||||
{
|
||||
get => _selectedModelsText;
|
||||
set => SetProperty(ref _selectedModelsText, value);
|
||||
}
|
||||
|
||||
public SimpleLogisticsControlViewModel()
|
||||
{
|
||||
// 最简单的初始化,没有复杂依赖
|
||||
StatusText = "简化ViewModel初始化成功";
|
||||
SelectedModelsText = "等待模型加载...";
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (Equals(field, value)) return false;
|
||||
field = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user