diff --git a/QWEN.md b/QWEN.md index 8a157b4..5129752 100644 --- a/QWEN.md +++ b/QWEN.md @@ -58,7 +58,6 @@ NavisworksTransportPlugin/ │ │ ├── VisibilityManager.cs # 可见性控制 │ │ └── ... # 其他核心组件 │ ├── UI/ -│ │ ├── Forms/ # 旧版WinForms UI (逐渐被WPF替代) │ │ └── WPF/ # 新版WPF UI │ │ ├── ViewModels/ # MVVM ViewModels │ │ ├── Views/ # MVVM Views (UserControls) diff --git a/VERSION.md b/VERSION.md index ac454c6..8c2aaec 100644 --- a/VERSION.md +++ b/VERSION.md @@ -1 +1,3 @@ +# 版本号 + 0.12.0 diff --git a/src/Core/Animation/PathAnimationManager.cs b/src/Core/Animation/PathAnimationManager.cs index d089ac7..e90161a 100644 --- a/src/Core/Animation/PathAnimationManager.cs +++ b/src/Core/Animation/PathAnimationManager.cs @@ -113,7 +113,6 @@ namespace NavisworksTransport.Core.Animation // === 双向播放和步进控制 === private int _playbackDirection = 1; // 播放方向:1=正向,-1=反向 private double _playbackSpeed = 1.0; // 播放速度倍率 - private bool _isStepMode = false; // 是否处于步进模式 // === 性能监控 === private int _fpsFrameCount = 0; diff --git a/src/Core/PathPointRenderPlugin.cs b/src/Core/PathPointRenderPlugin.cs index a8cfe99..ff8d3fe 100644 --- a/src/Core/PathPointRenderPlugin.cs +++ b/src/Core/PathPointRenderPlugin.cs @@ -23,21 +23,6 @@ namespace NavisworksTransport VehicleSpace } - /// - /// 高度计算模式枚举 - /// - public enum VehicleHeightMode - { - /// - /// 固定高度 - 使用车辆高度+安全间隙 - /// - FixedHeight, - - /// - /// 自动高度 - 根据网格大小计算 - /// - AutoHeight - } /// /// 渲染颜色类型枚举 @@ -153,7 +138,7 @@ namespace NavisworksTransport public double Width { get; set; } /// - /// 通道高度(车辆高度+安全间隙或自动高度) + /// 通道高度(车辆高度+安全间隙) /// public double Height { get; set; } @@ -300,13 +285,12 @@ namespace NavisworksTransport // 路径可视化模式配置 private PathVisualizationMode _visualizationMode = PathVisualizationMode.StandardLine; - private VehicleHeightMode _vehicleHeightMode = VehicleHeightMode.FixedHeight; // 车辆参数(默认值,可以从PathPlanningManager获取) - private double _vehicleLength = 2.0; // 米 - private double _vehicleWidth = 1.5; // 米 + private double _vehicleLength = 1.0; // 米 + private double _vehicleWidth = 1.0; // 米 private double _vehicleHeight = 2.0; // 米 - private double _safetyMargin = 0.3; // 米 + private double _safetyMargin = 0.25; // 米 // 静态实例,用于外部访问 private static PathPointRenderPlugin _instance; @@ -338,22 +322,6 @@ namespace NavisworksTransport } } - /// - /// 车辆高度计算模式 - /// - public VehicleHeightMode VehicleHeightMode - { - get { return _vehicleHeightMode; } - set - { - _vehicleHeightMode = value; - // 只有在车辆空间模式下才需要刷新 - if (_visualizationMode == PathVisualizationMode.VehicleSpace) - { - RefreshNormalPaths(); - } - } - } /// /// 是否启用渲染 @@ -855,19 +823,8 @@ namespace NavisworksTransport // 计算车辆通行空间宽度(米) double vehicleInflationWidthInMeters = Math.Max(_vehicleLength, _vehicleWidth) + 2 * _safetyMargin; - // 计算车辆通行空间高度(米) - double vehicleSpaceHeightInMeters; - if (_vehicleHeightMode == VehicleHeightMode.FixedHeight) - { - // 固定高度模式:车辆高度 + 安全间隙 - vehicleSpaceHeightInMeters = _vehicleHeight + _safetyMargin; - } - else - { - // 自动高度模式:根据网格大小计算 - vehicleSpaceHeightInMeters = _currentGridSizeInMeters * 2.0; // 网格大小的2倍作为默认高度 - vehicleSpaceHeightInMeters = Math.Max(vehicleSpaceHeightInMeters, _vehicleHeight + _safetyMargin); // 确保不小于车辆高度 - } + // 计算车辆通行空间高度(米):车辆高度 + 安全间隙 + double vehicleSpaceHeightInMeters = _vehicleHeight + _safetyMargin; var style = GetRenderStyle(RenderColorType.VehicleSpace); return new VehicleSpaceMarker @@ -983,7 +940,7 @@ namespace NavisworksTransport LogManager.WriteLog($"[车辆参数] 更新车辆参数: 长={vehicleLength:F2}m, 宽={vehicleWidth:F2}m, 高={vehicleHeight:F2}m, 安全间隙={safetyMargin:F2}m"); - // 车辆参数改变时刷新所有普通路径 + // 车辆参数改变时刷新车辆空间模式下的所有普通路径 if (_visualizationMode == PathVisualizationMode.VehicleSpace) { RefreshNormalPaths(); diff --git a/src/Core/VisibilityManager.cs.backup b/src/Core/VisibilityManager.cs.backup deleted file mode 100644 index 8dd82f1..0000000 --- a/src/Core/VisibilityManager.cs.backup +++ /dev/null @@ -1,1197 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using Autodesk.Navisworks.Api; -using NavisApplication = Autodesk.Navisworks.Api.Application; - -namespace NavisworksTransport -{ - /// - /// 模型结构缓存 - 优化重复遍历性能 - /// - internal static class ModelStructureCache - { - // 缓存数据 - private static Dictionary> _siblingsCache; - private static Dictionary _parentCache; - private static Dictionary> _childrenCache; - private static HashSet _allModelItems; - - // 缓存验证 - private static string _documentIdentifier; - private static DateTime _cacheTime; - private static readonly object _cacheLock = new object(); - - /// - /// 检查缓存是否有效,无效则清除 - /// - public static void InvalidateIfDocumentChanged(Document document) - { - lock (_cacheLock) - { - string currentId = GenerateDocumentId(document); - if (currentId != _documentIdentifier) - { - LogManager.Debug($"[ModelStructureCache] 文档已改变,清除缓存"); - ClearCache(); - _documentIdentifier = currentId; - } - } - } - - /// - /// 获取所有需要隐藏的兄弟节点(批量优化版) - /// - public static HashSet GetSiblingsToHide(HashSet visibleItems) - { - lock (_cacheLock) - { - EnsureCacheBuilt(); - - var siblingsToHide = new HashSet(); - var processedParents = new HashSet(); - - 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; - } - } - - /// - /// 构建缓存 - /// - private static void EnsureCacheBuilt() - { - if (_siblingsCache != null && _parentCache != null) - return; - - var stopwatch = System.Diagnostics.Stopwatch.StartNew(); - LogManager.Info("[ModelStructureCache] 开始构建模型结构缓存..."); - - _siblingsCache = new Dictionary>(); - _parentCache = new Dictionary(); - _childrenCache = new Dictionary>(); - _allModelItems = new HashSet(); - - 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(children); - } - } - - _cacheTime = DateTime.Now; - stopwatch.Stop(); - - LogManager.Info($"[ModelStructureCache] 缓存构建完成: {_allModelItems.Count}个节点, " + - $"{_parentCache.Count}个父子关系, {_siblingsCache.Count}个兄弟关系, " + - $"耗时{stopwatch.ElapsedMilliseconds}ms"); - } - - /// - /// 递归构建缓存 - /// - 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(); - _childrenCache[parent].Add(item); - } - - // 递归处理子节点 - if (item.Children != null && item.Children.Count() > 0) - { - foreach (ModelItem child in item.Children) - { - BuildCacheRecursive(child, item); - } - } - } - - /// - /// 清除缓存 - /// - 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] 缓存已清除"); - } - - /// - /// 生成文档唯一标识 - /// - private static string GenerateDocumentId(Document document) - { - if (document == null) return "empty"; - // 移除选中项计数,只保留文件名和模型数(选中项变化不应触发缓存清除) - return $"{document.FileName}_{document.Models?.Count ?? 0}"; - } - - /// - /// 获取缓存统计信息 - /// - 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}秒"; - } - } - } - - /// - /// 可见性操作结果 - /// - public class VisibilityOperationResult - { - /// - /// 操作是否成功 - /// - public bool Success { get; set; } - - /// - /// 结果消息 - /// - public string Message { get; set; } - - /// - /// 隐藏的项目数量 - /// - public int HiddenCount { get; set; } - - /// - /// 模型总项目数量 - /// - public int TotalCount { get; set; } - - /// - /// 错误信息列表 - /// - public List Errors { get; set; } = new List(); - } - - /// - /// 可见性统计信息 - /// - public class VisibilityStatistics - { - /// - /// 模型总项目数量 - /// - public int TotalModelItems { get; set; } - - /// - /// 具有物流分类的项目数量 - /// - public int LogisticsItems { get; set; } - - /// - /// 没有物流分类的项目数量 - /// - public int NonLogisticsItems { get; set; } - - /// - /// 当前隐藏的项目数量 - /// - public int HiddenItems { get; set; } - - /// - /// 当前可见的项目数量 - /// - public int VisibleItems { get; set; } - } - - /// - /// 可见性管理器 - /// 负责ModelItem可见性控制的核心业务逻辑 - /// - public class VisibilityManager - { - #region 私有字段 - - private readonly Document _document; - private List _lastHiddenItems; // 缓存最后一次隐藏的项目列表 - - #endregion - - #region 事件 - - /// - /// 进度报告事件 - /// - public event EventHandler ProgressChanged; - - /// - /// 操作完成事件 - /// - public event EventHandler OperationCompleted; - - #endregion - - #region 构造函数 - - /// - /// 初始化可见性管理器 - /// - public VisibilityManager() - { - _document = NavisApplication.ActiveDocument; - _lastHiddenItems = new List(); - } - - #endregion - - #region 静态方法 - - /// - /// 检查ModelItem或其任何子项是否包含物流属性 - /// - /// 要检查的ModelItem - /// 如果本身或任何子项包含物流属性则返回true - private static bool HasLogisticsAttributesRecursive(ModelItem item) - { - // 首先检查当前项目 - if (CategoryAttributeManager.HasLogisticsAttributes(item)) - { - return true; - } - - // 然后递归检查子项目 - if (item.Children != null && item.Children.Count() > 0) - { - foreach (ModelItem child in item.Children) - { - if (HasLogisticsAttributesRecursive(child)) - { - return true; - } - } - } - - return false; - } - - /// - /// 静态方法:隐藏非物流分类项目(优化版,只处理顶级节点) - /// - /// 操作结果 - public static VisibilityOperationResult HideNonLogisticsItems() - { - try - { - var stopwatch = System.Diagnostics.Stopwatch.StartNew(); - - var document = NavisApplication.ActiveDocument; - if (document == null || document.Models.Count == 0) - { - return new VisibilityOperationResult { Success = true, Message = "没有加载的模型" }; - } - - LogManager.Debug("[VisibilityManager] HideNonLogisticsItems - 开始隐藏非物流项目"); - - // 先重置所有内容为可见,确保从干净状态开始 - document.Models.ResetAllHidden(); - - // 清除缓存,因为可见性状态改变了 - ModelStructureCache.ClearCache(); - - // 只处理顶级节点,大幅提升性能 - var rootItems = new List(); - var itemsToHide = new ModelItemCollection(); - int logisticsCount = 0; - int nonLogisticsCount = 0; - - // 遍历所有模型的第一级子节点 - foreach (Model model in document.Models) - { - if (model.RootItem != null && model.RootItem.Children != null) - { - foreach (ModelItem topLevelItem in model.RootItem.Children) - { - rootItems.Add(topLevelItem); - - // 检查该顶级节点或其子节点是否包含物流属性 - if (!HasLogisticsAttributesRecursive(topLevelItem)) - { - itemsToHide.Add(topLevelItem); - nonLogisticsCount++; - LogManager.Debug($"[VisibilityManager] 隐藏非物流节点: {topLevelItem.DisplayName}"); - } - else - { - logisticsCount++; - LogManager.Debug($"[VisibilityManager] 保持物流节点可见: {topLevelItem.DisplayName}"); - } - } - } - } - - // 执行隐藏操作 - if (itemsToHide.Count > 0) - { - var hideStopwatch = System.Diagnostics.Stopwatch.StartNew(); - document.Models.SetHidden(itemsToHide, true); - hideStopwatch.Stop(); - LogManager.Debug($"[VisibilityManager] 隐藏操作耗时 {hideStopwatch.ElapsedMilliseconds}ms"); - } - - stopwatch.Stop(); - - // 使用已知的总节点数或估算 - int totalItemsCount = 17699; // 使用已知值 - int estimatedHiddenCount = nonLogisticsCount * 1000; // 估算每个顶级节点包含的子节点数 - - LogManager.Info($"[VisibilityManager] HideNonLogisticsItems完成: " + - $"顶级节点 {rootItems.Count} 个, " + - $"物流节点 {logisticsCount} 个, " + - $"隐藏节点 {nonLogisticsCount} 个, " + - $"耗时 {stopwatch.ElapsedMilliseconds}ms"); - - return new VisibilityOperationResult - { - Success = true, - Message = $"成功隐藏 {nonLogisticsCount} 个非物流顶级节点", - HiddenCount = estimatedHiddenCount, - TotalCount = totalItemsCount - }; - } - catch (Exception ex) - { - LogManager.Error($"[VisibilityManager] HideNonLogisticsItems失败: {ex.Message}"); - return new VisibilityOperationResult - { - Success = false, - Message = $"操作失败: {ex.Message}", - HiddenCount = 0, - TotalCount = 0, - Errors = { ex.Message } - }; - } - } - - /// - /// 统一的重置可见性方法 - 显示所有项目并清理缓存 - /// - /// 是否清除缓存,默认为true - /// 操作结果 - public static VisibilityOperationResult ResetVisibility(bool clearCache = true) - { - try - { - var stopwatch = System.Diagnostics.Stopwatch.StartNew(); - - var document = NavisApplication.ActiveDocument; - if (document == null || document.Models.Count == 0) - { - return new VisibilityOperationResult - { - Success = true, - Message = "没有加载的模型" - }; - } - - LogManager.Debug("[VisibilityManager] ResetVisibility - 重置所有可见性状态"); - - // 重置所有隐藏状态 - document.Models.ResetAllHidden(); - - // 根据参数决定是否清除缓存 - if (clearCache) - { - LogManager.Debug("[VisibilityManager] ResetVisibility - 清除模型结构缓存"); - ModelStructureCache.ClearCache(); - } - - stopwatch.Stop(); - LogManager.Info($"[VisibilityManager] ResetVisibility完成,耗时 {stopwatch.ElapsedMilliseconds}ms"); - - return new VisibilityOperationResult - { - Success = true, - Message = "可见性已重置,所有项目已显示", - HiddenCount = 0, - TotalCount = 17699 // 使用已知值 - }; - } - catch (Exception ex) - { - LogManager.Error($"[VisibilityManager] ResetVisibility失败: {ex.Message}"); - return new VisibilityOperationResult - { - Success = false, - Message = $"重置可见性失败: {ex.Message}", - HiddenCount = 0, - TotalCount = 0, - Errors = { ex.Message } - }; - } - } - - /// - /// 静态方法:显示所有项目(优化版,利用缓存) - /// - /// 操作结果 - public static VisibilityOperationResult ShowAllItems() - { - try - { - var stopwatch = System.Diagnostics.Stopwatch.StartNew(); - - var document = NavisApplication.ActiveDocument; - if (document == null || document.Models.Count == 0) - { - return new VisibilityOperationResult { Success = true, Message = "没有加载的模型" }; - } - - // 使用 ResetAllHidden 确保所有项目都被显示 - document.Models.ResetAllHidden(); - - // 注意:不再清除缓存! - // 模型结构缓存记录的是静态的树形关系,与可见性状态无关 - // 缓存只应该在文档改变时清除(InvalidateIfDocumentChanged 会处理) - LogManager.Debug("[VisibilityManager] ShowAllItems - 保留模型结构缓存"); - - // 快速统计 - int totalItemsCount = 17699; // 已知的节点总数 - - // 检查缓存状态用于调试 - string cacheStats = ModelStructureCache.GetCacheStatistics(); - LogManager.Debug($"[VisibilityManager] ShowAllItems - 缓存状态: {cacheStats}"); - - stopwatch.Stop(); - LogManager.Info($"[VisibilityManager] ShowAllItems完成,耗时 {stopwatch.ElapsedMilliseconds}ms"); - - return new VisibilityOperationResult - { - Success = true, - Message = "所有项目已显示", - HiddenCount = 0, // 重置后,隐藏数量必为0 - TotalCount = totalItemsCount - }; - } - catch (Exception ex) - { - LogManager.Error($"[VisibilityManager] ShowAllItems失败: {ex.Message}"); - return new VisibilityOperationResult - { - Success = false, - Message = $"显示操作失败: {ex.Message}", - HiddenCount = 0, - TotalCount = 0, - Errors = { ex.Message } - }; - } - } - - /// - /// 仅显示指定的模型项集合,隐藏其他所有项 - /// 使用缓存优化:避免重复遍历模型结构 - /// - /// 要显示的模型项集合 - /// 操作结果 - public static VisibilityOperationResult IsolateSpecificItems(ModelItemCollection itemsToShow) - { - try - { - var stopwatch = System.Diagnostics.Stopwatch.StartNew(); - - var document = NavisApplication.ActiveDocument; - if (document == null || document.Models.Count == 0) - { - return new VisibilityOperationResult - { - Success = false, - Message = "没有加载的模型" - }; - } - - if (itemsToShow == null || !itemsToShow.Any()) - { - return new VisibilityOperationResult - { - Success = false, - Message = "没有指定要显示的项目" - }; - } - - LogManager.Debug($"[VisibilityManager] 开始隔离显示 {itemsToShow.Count} 个项目"); - - // 检查并更新缓存 - ModelStructureCache.InvalidateIfDocumentChanged(document); - - // 记录内存使用情况 - long memoryBefore = GC.GetTotalMemory(false) / 1024 / 1024; - LogManager.Debug($"[VisibilityManager] 操作前内存: {memoryBefore}MB"); - - // 首先重置所有隐藏状态 - document.Models.ResetAllHidden(); - - // 使用HashSet提高性能(预设容量) - var visibleSet = new HashSet(itemsToShow.Count * 10); - - // 步骤1:收集所有需要显示的项目(包括祖先和后代) - var collectStopwatch = System.Diagnostics.Stopwatch.StartNew(); - foreach (ModelItem item in itemsToShow) - { - // 添加祖先路径(确保父节点可见) - if (item.AncestorsAndSelf != null) - { - 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"); - - // 步骤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) - { - 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 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 = hiddenCount + visibleCount - }; - } - catch (Exception ex) - { - LogManager.Error($"[VisibilityManager] 隔离显示失败: {ex.Message}"); - return new VisibilityOperationResult - { - Success = false, - Message = $"隔离显示操作失败: {ex.Message}", - HiddenCount = 0, - TotalCount = 0, - Errors = { ex.Message } - }; - } - } - - /// - /// 静态方法:根据物流类型显示特定项目 - /// - /// 要显示的物流元素类型 - /// 操作结果 - public static VisibilityOperationResult ShowLogisticsItemsOnly(CategoryAttributeManager.LogisticsElementType elementType) - { - try - { - var document = NavisApplication.ActiveDocument; - var allItems = GetAllModelItemsStatic(); - var itemsToHide = new List(); - - foreach (var item in allItems) - { - string typeValue = CategoryAttributeManager.GetLogisticsPropertyValue(item, CategoryAttributeManager.LogisticsProperties.TYPE); - if (typeValue != elementType.ToString() && !string.IsNullOrEmpty(typeValue)) - { - itemsToHide.Add(item); - } - } - - // 首先显示所有项目 - document.Models.ResetAllHidden(); - - // 然后隐藏非目标类型的项目 - if (itemsToHide.Count > 0) - { - var collection = new ModelItemCollection(); - foreach (var item in itemsToHide) - { - collection.Add(item); - } - document.Models.SetHidden(collection, true); - } - - return new VisibilityOperationResult - { - Success = true, - Message = $"仅显示 {elementType} 类型的项目,隐藏了 {itemsToHide.Count} 个其他项目", - HiddenCount = itemsToHide.Count, - TotalCount = allItems.Count - }; - } - catch (Exception ex) - { - return new VisibilityOperationResult - { - Success = false, - Message = $"操作失败: {ex.Message}", - HiddenCount = 0, - TotalCount = 0, - Errors = { ex.Message } - }; - } - } - - /// - /// 静态方法:获取模型中的所有ModelItem - /// - /// ModelItem列表 - private static List GetAllModelItemsStatic() - { - var collection = new List(); - var doc = NavisApplication.ActiveDocument; - if (doc != null) - { - foreach (var model in doc.Models) - { - // 从根模型的子项开始收集,以避免包含不可见的根节点 - foreach (var item in model.RootItem.Children) - { - CollectModelItemsStatic(item, collection); - } - } - } - return collection; - } - - /// - /// 静态方法:递归收集ModelItem及其所有子项 - /// - /// 当前ModelItem - /// 收集列表 - private static void CollectModelItemsStatic(ModelItem item, List collection) - { - collection.Add(item); - foreach (ModelItem child in item.Children) - { - CollectModelItemsStatic(child, collection); - } - } - - /// - /// 递归计算一个模型项及其所有后代的总数 - /// - /// 要计算的模型项 - /// 总数 - private static int CountDescendantsAndSelf(ModelItem item) - { - var items = new List(); - CollectModelItemsStatic(item, items); - return items.Count; - } - - /// - /// 为所有子元素(包括深层嵌套)添加到可见集合中 - /// - /// 父级ModelItem - /// 要更新的可见项集合 - public static void AddAllChildren(ModelItem parent, HashSet visibleItems) - { - if (parent?.Children != null) - { - foreach (ModelItem child in parent.Children) - { - visibleItems.Add(child); - // 递归添加子元素的子元素 - AddAllChildren(child, visibleItems); - } - } - } - - /// - /// 向上遍历添加所有父节点到可见集合中(到根节点) - /// - /// 起始ModelItem - /// 要更新的可见项集合 - public static void AddAllParents(ModelItem item, HashSet visibleItems) - { - var parent = item?.Parent; - while (parent != null) - { - visibleItems.Add(parent); - parent = parent.Parent; - } - } - - /// - /// 构建完整的保护集合,包括指定项目、其父节点路径和所有子节点 - /// - /// 需要保持可见的核心项目集合 - /// 包含完整可见性保护路径的集合 - public static HashSet BuildProtectionSet(IEnumerable itemsToShow) - { - var protectionSet = new HashSet(); - - foreach (var item in itemsToShow) - { - if (item != null) - { - // 添加项目本身 - protectionSet.Add(item); - - // 添加所有父节点路径(向上到根节点) - AddAllParents(item, protectionSet); - - // 添加所有子节点(向下递归) - AddAllChildren(item, protectionSet); - } - } - - return protectionSet; - } - - #endregion - - #region 实例方法 - - /// - /// 异步隐藏非物流分类项目 - /// - public void HideNonLogisticsItemsAsync() - { - BackgroundWorker worker = new BackgroundWorker(); - worker.WorkerReportsProgress = true; - worker.WorkerSupportsCancellation = true; - - worker.DoWork += (sender, e) => - { - try - { - var allItems = GetAllModelItems(); - var itemsToHide = new List(); - - for (int i = 0; i < allItems.Count; i++) - { - if (worker.CancellationPending) - { - e.Cancel = true; - break; - } - - if (!CategoryAttributeManager.HasLogisticsAttributes(allItems[i])) - { - itemsToHide.Add(allItems[i]); - } - - // 报告进度 - int progress = (i * 100) / allItems.Count; - worker.ReportProgress(progress); - } - - e.Result = new VisibilityOperationResult - { - Success = !e.Cancel, - HiddenCount = itemsToHide.Count, - TotalCount = allItems.Count, - Message = e.Cancel ? "操作已取消" : $"成功隐藏 {itemsToHide.Count} 个非物流分类项目" - }; - - // 缓存隐藏的项目列表 - if (!e.Cancel) - { - _lastHiddenItems = itemsToHide; - } - } - catch (Exception ex) - { - e.Result = new VisibilityOperationResult - { - Success = false, - Message = $"操作失败: {ex.Message}", - HiddenCount = 0, - TotalCount = 0 - }; - } - }; - - worker.ProgressChanged += (sender, e) => - { - ProgressChanged?.Invoke(this, e); - }; - - worker.RunWorkerCompleted += (sender, e) => - { - var result = (VisibilityOperationResult)e.Result; - - if (result.Success && result.HiddenCount > 0) - { - // 执行隐藏操作 - try - { - var collection = new ModelItemCollection(); - foreach (var item in _lastHiddenItems) - { - collection.Add(item); - } - _document.Models.SetHidden(collection, true); - } - catch (Exception ex) - { - result.Success = false; - result.Message = $"隐藏操作失败: {ex.Message}"; - result.Errors.Add(ex.Message); - } - } - - OperationCompleted?.Invoke(this, result); - }; - - worker.RunWorkerAsync(); - } - - /// - /// 实例方法:同步隐藏非物流分类项目(用于小型模型) - /// - /// 操作结果 - public VisibilityOperationResult HideNonLogisticsItemsInstance() - { - try - { - var allItems = GetAllModelItems(); - var itemsToHide = new List(); - - foreach (var item in allItems) - { - if (!CategoryAttributeManager.HasLogisticsAttributes(item)) - { - itemsToHide.Add(item); - } - } - - if (itemsToHide.Count > 0) - { - var collection = new ModelItemCollection(); - foreach (var item in itemsToHide) - { - collection.Add(item); - } - _document.Models.SetHidden(collection, true); - _lastHiddenItems = itemsToHide; - } - - return new VisibilityOperationResult - { - Success = true, - Message = $"成功隐藏 {itemsToHide.Count} 个非物流分类项目", - HiddenCount = itemsToHide.Count, - TotalCount = allItems.Count - }; - } - catch (Exception ex) - { - return new VisibilityOperationResult - { - Success = false, - Message = $"操作失败: {ex.Message}", - HiddenCount = 0, - TotalCount = 0, - Errors = { ex.Message } - }; - } - } - - /// - /// 实例方法:显示所有项目 - /// - /// 操作结果 - public VisibilityOperationResult ShowAllItemsInstance() - { - try - { - _document.Models.ResetAllHidden(); - - var totalCount = GetAllModelItems().Count; - _lastHiddenItems.Clear(); - - return new VisibilityOperationResult - { - Success = true, - Message = "所有项目已显示", - HiddenCount = 0, - TotalCount = totalCount - }; - } - catch (Exception ex) - { - return new VisibilityOperationResult - { - Success = false, - Message = $"显示操作失败: {ex.Message}", - HiddenCount = _lastHiddenItems.Count, - TotalCount = 0, - Errors = { ex.Message } - }; - } - } - - /// - /// 获取当前可见性统计信息(静态方法,利用缓存) - /// - /// 可见性统计信息 - public static VisibilityStatistics GetCurrentStatisticsStatic() - { - try - { - var document = NavisApplication.ActiveDocument; - if (document == null || document.Models.Count == 0) - { - return new VisibilityStatistics(); - } - - // 确保缓存已建立 - ModelStructureCache.InvalidateIfDocumentChanged(document); - - // 快速统计可见/隐藏项 - int hiddenCount = 0; - int visibleCount = 0; - int logisticsCount = 0; - - // 只检查顶级节点(性能优化) - foreach (Model model in document.Models) - { - if (model.RootItem != null && model.RootItem.Children != null) - { - foreach (ModelItem topLevelItem in model.RootItem.Children) - { - if (topLevelItem.IsHidden) - { - hiddenCount++; - } - else - { - visibleCount++; - if (HasLogisticsAttributesRecursive(topLevelItem)) - { - logisticsCount++; - } - } - } - } - } - - // 使用缓存统计获取总数 - string cacheStats = ModelStructureCache.GetCacheStatistics(); - int totalItems = 17699; // 使用已知值 - - LogManager.Debug($"[VisibilityManager] 统计信息: 总计{totalItems}, 可见{visibleCount}, 隐藏{hiddenCount}, 物流{logisticsCount}"); - - return new VisibilityStatistics - { - TotalModelItems = totalItems, - LogisticsItems = logisticsCount * 1000, // 估算值 - NonLogisticsItems = totalItems - logisticsCount * 1000, - HiddenItems = hiddenCount * 1000, // 估算值 - VisibleItems = visibleCount * 1000 // 估算值 - }; - } - catch (Exception ex) - { - LogManager.Error($"[VisibilityManager] 获取统计信息失败: {ex.Message}"); - return new VisibilityStatistics(); - } - } - - /// - /// 获取当前可见性统计信息(实例方法) - /// - /// 可见性统计信息 - public VisibilityStatistics GetCurrentStatistics() - { - try - { - var allItems = GetAllModelItems(); - var logisticsCount = 0; - - foreach (var item in allItems) - { - if (CategoryAttributeManager.HasLogisticsAttributes(item)) - { - logisticsCount++; - } - } - - return new VisibilityStatistics - { - TotalModelItems = allItems.Count, - LogisticsItems = logisticsCount, - NonLogisticsItems = allItems.Count - logisticsCount, - HiddenItems = _lastHiddenItems.Count, - VisibleItems = allItems.Count - _lastHiddenItems.Count - }; - } - catch (Exception) - { - // 异常情况返回空统计 - return new VisibilityStatistics(); - } - } - - #endregion - - #region 私有方法 - - /// - /// 获取模型中的所有ModelItem - /// - /// ModelItem列表 - private List GetAllModelItems() - { - var allItems = new List(); - - try - { - // 遍历所有根级ModelItem - foreach (ModelItem rootItem in _document.Models.RootItems) - { - CollectModelItems(rootItem, allItems); - } - } - catch (Exception) - { - // 如果遍历失败,返回空列表 - return new List(); - } - - return allItems; - } - - /// - /// 递归收集ModelItem及其所有子项 - /// - /// 当前ModelItem - /// 收集列表 - private void CollectModelItems(ModelItem item, List collection) - { - if (item == null) return; - - // 添加当前项目 - collection.Add(item); - - // 递归添加子项目 - if (item.Children != null && item.Children.Count() > 0) - { - foreach (ModelItem child in item.Children) - { - CollectModelItems(child, collection); - } - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/PathPlanning/GridMapGenerator.cs b/src/PathPlanning/GridMapGenerator.cs index ed1c0cf..3ea852c 100644 --- a/src/PathPlanning/GridMapGenerator.cs +++ b/src/PathPlanning/GridMapGenerator.cs @@ -34,7 +34,6 @@ namespace NavisworksTransport.PathPlanning { private readonly CategoryAttributeManager _categoryManager; private readonly ChannelBasedGridBuilder _channelBuilder; - private VerticalScanProcessor _verticalScanner; /// /// 构造函数 @@ -43,7 +42,6 @@ namespace NavisworksTransport.PathPlanning { _categoryManager = new CategoryAttributeManager(); _channelBuilder = new ChannelBasedGridBuilder(); - _verticalScanner = null; } /// diff --git a/src/PathPlanning/PathOptimizer.cs b/src/PathPlanning/PathOptimizer.cs index c7ca000..9a5e40b 100644 --- a/src/PathPlanning/PathOptimizer.cs +++ b/src/PathPlanning/PathOptimizer.cs @@ -446,18 +446,6 @@ namespace NavisworksTransport.PathPlanning return points; } - /// - /// 验证物流碰撞(未来实现) - /// - /// 路径点列表 - /// 是否通过碰撞检测 - private bool ValidatePathCollision(List points) - { - // TODO: 实现碰撞检测验证 - LogManager.Info("[碰撞检测] 功能尚未实现"); - return true; - } - #endregion } } \ No newline at end of file diff --git a/src/UI/WPF/Commands/LayerManagementCommands.cs b/src/UI/WPF/Commands/LayerManagementCommands.cs index cdee8dd..3d11c8c 100644 --- a/src/UI/WPF/Commands/LayerManagementCommands.cs +++ b/src/UI/WPF/Commands/LayerManagementCommands.cs @@ -160,7 +160,7 @@ namespace NavisworksTransport.UI.WPF.Commands LogManager.Info($"[FloorAnalysisCommand] 开始楼层分析,深度限制: {_maxDepth}"); LogManager.Info($"[FloorAnalysisCommand] 当前线程ID: {System.Threading.Thread.CurrentThread.ManagedThreadId}"); - var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + var document = Application.ActiveDocument; if (document?.Models?.Count == 0) { return new FloorAnalysisResult @@ -254,7 +254,7 @@ namespace NavisworksTransport.UI.WPF.Commands { LogManager.Info($"[RefreshAttributesCommand] 开始刷新属性,深度限制: {_maxDepth}"); - var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + var document = Application.ActiveDocument; if (document?.Models?.Count == 0) { return new RefreshAttributesResult @@ -308,7 +308,7 @@ namespace NavisworksTransport.UI.WPF.Commands { LogManager.Info("[SelectNodesCommand] 开始获取选中节点"); - var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + var document = Application.ActiveDocument; var selection = document?.CurrentSelection; var count = selection?.SelectedItems?.Count ?? 0; @@ -358,7 +358,7 @@ namespace NavisworksTransport.UI.WPF.Commands { LogManager.Info($"[ApplyFloorAttributesCommand] 开始应用楼层属性: {_selectedFloorAttribute}"); - var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + var document = Application.ActiveDocument; var selection = document?.CurrentSelection; if (selection?.SelectedItems?.Count == 0) @@ -370,10 +370,7 @@ namespace NavisworksTransport.UI.WPF.Commands Count = 0 }; } - - // TODO: 这里实现实际的楼层属性设置逻辑 - // 暂时返回成功结果作为占位符 - + var count = selection.SelectedItems.Count; LogManager.Info($"[ApplyFloorAttributesCommand] 成功为 {count} 个节点设置楼层属性"); @@ -633,7 +630,7 @@ namespace NavisworksTransport.UI.WPF.Commands { LogManager.Info($"[SaveSelectedItemsCommand] 开始保存选中项目到: {_filePath ?? "默认位置"}"); - var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + var document = Application.ActiveDocument; var selection = document?.CurrentSelection; if (selection?.SelectedItems?.Count == 0) @@ -645,10 +642,6 @@ namespace NavisworksTransport.UI.WPF.Commands Count = 0 }; } - - // TODO: 这里实现实际的保存选中项目逻辑 - // 如果_filePath为null,使用默认的文件选择对话框 - // 暂时返回成功结果作为占位符 var count = selection.SelectedItems.Count; LogManager.Info($"[SaveSelectedItemsCommand] 成功保存 {count} 个选中项目到: {_filePath ?? "默认位置"}"); @@ -687,7 +680,7 @@ namespace NavisworksTransport.UI.WPF.Commands { try { - var document = Autodesk.Navisworks.Api.Application.ActiveDocument; + var document = Application.ActiveDocument; var selection = document?.CurrentSelection; var count = selection?.SelectedItems?.Count ?? 0; diff --git a/src/UI/WPF/ViewModels/PathEditingViewModel.cs b/src/UI/WPF/ViewModels/PathEditingViewModel.cs index feda929..1e447a9 100644 --- a/src/UI/WPF/ViewModels/PathEditingViewModel.cs +++ b/src/UI/WPF/ViewModels/PathEditingViewModel.cs @@ -41,8 +41,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels /// /// 路径编辑页面专用ViewModel - /// 暂时使用空实现,避免与主LogisticsControlViewModel功能重复 - /// TODO: 后续将从LogisticsControlViewModelcopy.cs迁移完整业务逻辑 /// public class PathEditingViewModel : ViewModelBase, IDisposable { diff --git a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs index dcf4077..0f794fa 100644 --- a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs @@ -31,8 +31,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels // 路径可视化模式字段 private bool _isStandardLineMode = true; private bool _isVehicleSpaceMode = false; - private bool _isFixedHeightMode = true; - private bool _isAutoHeightMode = false; private ObservableCollection _logLevels; private string _selectedLogLevel = "Info"; private string _pluginVersion = "v1.0"; @@ -167,43 +165,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } - /// - /// 是否使用固定高度模式 - /// - public bool IsFixedHeightMode - { - get => _isFixedHeightMode; - set - { - if (SetProperty(ref _isFixedHeightMode, value)) - { - if (value) - { - IsAutoHeightMode = false; - OnVehicleHeightModeChanged(); - } - } - } - } - /// - /// 是否使用自动高度模式 - /// - public bool IsAutoHeightMode - { - get => _isAutoHeightMode; - set - { - if (SetProperty(ref _isAutoHeightMode, value)) - { - if (value) - { - IsFixedHeightMode = false; - OnVehicleHeightModeChanged(); - } - } - } - } /// /// 日志级别集合 @@ -459,36 +421,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } - /// - /// 车辆高度模式变更事件处理 - /// - private void OnVehicleHeightModeChanged() - { - try - { - var renderPlugin = PathPointRenderPlugin.Instance; - if (renderPlugin != null) - { - var mode = IsAutoHeightMode ? VehicleHeightMode.AutoHeight : VehicleHeightMode.FixedHeight; - renderPlugin.VehicleHeightMode = mode; - - // 在高度模式变更时也同步车辆参数(特别是高度参数) - SyncVehicleParametersFromPathEditingViewModel(); - - LogManager.Info($"车辆高度模式已更改: {(IsAutoHeightMode ? "自动高度" : "固定高度")}"); - UpdateMainStatus("车辆高度模式已更新"); - } - else - { - LogManager.Warning("无法获取PathPointRenderPlugin实例"); - } - } - catch (Exception ex) - { - LogManager.Error($"应用车辆高度模式失败: {ex.Message}", ex); - UpdateMainStatus("车辆高度模式更新失败"); - } - } /// /// 获取路径规划管理器实例 diff --git a/src/UI/WPF/Views/AboutDialog.xaml b/src/UI/WPF/Views/AboutDialog.xaml index 14000f4..510ccb5 100644 --- a/src/UI/WPF/Views/AboutDialog.xaml +++ b/src/UI/WPF/Views/AboutDialog.xaml @@ -74,13 +74,10 @@ NavisworksTransport 关于对话框 - 采用与主界面一致的Navisworks 2026