清理类别设置和插件主窗口的无效代码
This commit is contained in:
parent
fc0b6d6aaa
commit
049673c6bb
@ -830,9 +830,6 @@ namespace NavisworksTransport.PathPlanning
|
||||
// 最少采样5个点,最多10000个点(提高性能限制)
|
||||
samples = Math.Max(5, Math.Min(samples, 10000));
|
||||
|
||||
LogManager.Debug($"[斜线检查] 开始检查路径:起点({start.X:F2},{start.Y:F2})→终点({end.X:F2},{end.Y:F2})," +
|
||||
$"距离={distance:F2}m,采样数={samples}");
|
||||
|
||||
for (int i = 0; i <= samples; i++)
|
||||
{
|
||||
// 线性插值计算采样点
|
||||
@ -860,12 +857,12 @@ namespace NavisworksTransport.PathPlanning
|
||||
var deltaX = samplePoint.X - gridCenterX;
|
||||
var deltaY = samplePoint.Y - gridCenterY;
|
||||
|
||||
LogManager.Debug($"[斜线检查] 采样点{i}/{samples}失败:" +
|
||||
$"采样点({samplePoint.X:F3},{samplePoint.Y:F3},{samplePoint.Z:F3})," +
|
||||
$"网格({gridPos.X},{gridPos.Y})左下角({gridMinX:F3},{gridMinY:F3})," +
|
||||
$"网格中心({gridCenterX:F3},{gridCenterY:F3},{gridCenterZ:F3})," +
|
||||
$"偏差(ΔX={deltaX:F3}, ΔY={deltaY:F3})," +
|
||||
$"原因:{(!gridMap.IsValidGridPosition(gridPos) ? "网格无效" : "不可通行")}");
|
||||
// LogManager.Debug($"[斜线检查] 采样点{i}/{samples}失败:" +
|
||||
// $"采样点({samplePoint.X:F3},{samplePoint.Y:F3},{samplePoint.Z:F3})," +
|
||||
// $"网格({gridPos.X},{gridPos.Y})左下角({gridMinX:F3},{gridMinY:F3})," +
|
||||
// $"网格中心({gridCenterX:F3},{gridCenterY:F3},{gridCenterZ:F3})," +
|
||||
// $"偏差(ΔX={deltaX:F3}, ΔY={deltaY:F3})," +
|
||||
// $"原因:{(!gridMap.IsValidGridPosition(gridPos) ? "网格无效" : "不可通行")}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -882,11 +879,11 @@ namespace NavisworksTransport.PathPlanning
|
||||
var deltaX = samplePoint.X - gridCenterX;
|
||||
var deltaY = samplePoint.Y - gridCenterY;
|
||||
|
||||
LogManager.Debug($"[斜线检查] 采样点{i}/{samples}邻居障碍检查失败:" +
|
||||
$"采样点({samplePoint.X:F3},{samplePoint.Y:F3})," +
|
||||
$"网格左下角({gridMinX:F3},{gridMinY:F3})," +
|
||||
$"网格中心({gridCenterX:F3},{gridCenterY:F3})," +
|
||||
$"偏差(ΔX={deltaX:F3}, ΔY={deltaY:F3})");
|
||||
// LogManager.Debug($"[斜线检查] 采样点{i}/{samples}邻居障碍检查失败:" +
|
||||
// $"采样点({samplePoint.X:F3},{samplePoint.Y:F3})," +
|
||||
// $"网格左下角({gridMinX:F3},{gridMinY:F3})," +
|
||||
// $"网格中心({gridCenterX:F3},{gridCenterY:F3})," +
|
||||
// $"偏差(ΔX={deltaX:F3}, ΔY={deltaY:F3})");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,19 +25,14 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
private string _selectedModelsText;
|
||||
private string _instructionText;
|
||||
private string _statusText;
|
||||
private ObservableCollection<LogisticsModel> _logisticsModels;
|
||||
private LogisticsModel _selectedLogisticsModel;
|
||||
|
||||
|
||||
|
||||
private string _animationStatus;
|
||||
private double _animationProgress;
|
||||
private ObservableCollection<string> _availableCategories;
|
||||
private string _selectedCategory;
|
||||
private double _widthLimit;
|
||||
|
||||
|
||||
private bool _isLogisticsOnlyMode = false;
|
||||
private bool _isProcessing = false;
|
||||
|
||||
// UI状态管理和命令框架
|
||||
@ -94,23 +89,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
set => SetProperty(ref _statusText, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 物流模型集合
|
||||
/// </summary>
|
||||
public ObservableCollection<LogisticsModel> LogisticsModels
|
||||
{
|
||||
get => _logisticsModels;
|
||||
set => SetProperty(ref _logisticsModels, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中的物流模型
|
||||
/// </summary>
|
||||
public LogisticsModel SelectedLogisticsModel
|
||||
{
|
||||
get => _selectedLogisticsModel;
|
||||
set => SetProperty(ref _selectedLogisticsModel, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 路径集合
|
||||
@ -154,45 +132,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
set => SetProperty(ref _availableCategories, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选中的类别
|
||||
/// </summary>
|
||||
public string SelectedCategory
|
||||
{
|
||||
get => _selectedCategory;
|
||||
set => SetProperty(ref _selectedCategory, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 宽度限制(米)
|
||||
/// </summary>
|
||||
public double WidthLimit
|
||||
{
|
||||
get => _widthLimit;
|
||||
set => SetProperty(ref _widthLimit, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 路径文件状态
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 是否处于仅显示物流模式
|
||||
/// </summary>
|
||||
public bool IsLogisticsOnlyMode
|
||||
{
|
||||
get => _isLogisticsOnlyMode;
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref _isLogisticsOnlyMode, value))
|
||||
{
|
||||
// 当开关状态改变时,自动应用可见性设置
|
||||
ApplyVisibilityMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否正在处理中(用于统一状态栏进度条显示)
|
||||
/// </summary>
|
||||
@ -366,7 +305,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
public ICommand StopAnimationCommand { get; private set; }
|
||||
public ICommand RunCollisionDetectionCommand { get; private set; }
|
||||
public ICommand ViewCollisionReportCommand { get; private set; }
|
||||
public ICommand SetLogisticsAttributeCommand { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -394,8 +332,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
}
|
||||
|
||||
// 初始化线程安全的集合
|
||||
LogisticsModels = new ThreadSafeObservableCollection<LogisticsModel>();
|
||||
AvailableCategories = new ThreadSafeObservableCollection<string>();
|
||||
AvailableFrameRates = new ThreadSafeObservableCollection<int>();
|
||||
|
||||
// 初始化命令(使用新的Command Pattern框架)
|
||||
@ -426,14 +362,12 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
await UpdateInstructionTextAsync();
|
||||
await UpdateSelectionDisplayAsync();
|
||||
await InitializeCategoriesAsync();
|
||||
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
StatusText = "插件已就绪";
|
||||
AnimationStatus = "动画状态: 就绪";
|
||||
AnimationProgress = 0;
|
||||
WidthLimit = 3.0; // 默认宽度限制3米
|
||||
});
|
||||
|
||||
// 初始化动画参数
|
||||
@ -459,9 +393,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
// 碰撞检测命令
|
||||
RunCollisionDetectionCommand = new RelayCommand(async () => await ExecuteRunCollisionDetectionAsync(), () => CanRunCollisionDetection);
|
||||
ViewCollisionReportCommand = new RelayCommand(async () => await ExecuteViewCollisionReportAsync(), () => HasCollisionResults);
|
||||
|
||||
// 物流属性命令
|
||||
SetLogisticsAttributeCommand = new RelayCommand(async () => await ExecuteSetLogisticsAttributeAsync());
|
||||
|
||||
LogManager.Info("命令初始化完成 - 使用新的异步Command Pattern框架");
|
||||
}, "初始化命令");
|
||||
@ -514,91 +445,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
|
||||
#region 命令实现
|
||||
|
||||
/// <summary>
|
||||
/// 应用可见性模式
|
||||
/// </summary>
|
||||
private void ApplyVisibilityMode()
|
||||
{
|
||||
SafeExecute(() =>
|
||||
{
|
||||
if (IsLogisticsOnlyMode)
|
||||
{
|
||||
// 仅显示物流模式
|
||||
ShowLogisticsOnlyInternal();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 显示全部模式
|
||||
ShowAllInternal();
|
||||
}
|
||||
}, "应用可见性模式");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部方法:显示所有元素
|
||||
/// </summary>
|
||||
private void ShowAllInternal()
|
||||
{
|
||||
bool success = VisibilityHelper.ShowAllItems();
|
||||
|
||||
if (success)
|
||||
{
|
||||
// 更新物流模型列表中的可见性状态
|
||||
foreach (var model in LogisticsModels)
|
||||
{
|
||||
model.IsVisible = true;
|
||||
}
|
||||
|
||||
StatusText = "显示所有元素";
|
||||
LogManager.Info("切换到显示全部模式");
|
||||
}
|
||||
else
|
||||
{
|
||||
StatusText = "显示全部失败";
|
||||
LogManager.Error("显示全部失败");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部方法:仅显示物流元素
|
||||
/// </summary>
|
||||
private void ShowLogisticsOnlyInternal()
|
||||
{
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models != null)
|
||||
{
|
||||
// 查找所有具有物流属性的元素
|
||||
var logisticsItems = FindAllLogisticsModels();
|
||||
|
||||
if (logisticsItems.Count > 0)
|
||||
{
|
||||
// 使用 VisibilityHelper 来隔离显示物流元素
|
||||
bool success = VisibilityHelper.IsolateSpecificItems(logisticsItems);
|
||||
|
||||
if (success)
|
||||
{
|
||||
// 更新物流模型列表中的可见性状态
|
||||
foreach (var model in LogisticsModels)
|
||||
{
|
||||
model.IsVisible = true;
|
||||
}
|
||||
|
||||
StatusText = $"仅显示物流元素 ({logisticsItems.Count} 个物流节点)";
|
||||
LogManager.Info($"切换到仅显示物流模式: 找到 {logisticsItems.Count} 个物流节点");
|
||||
}
|
||||
else
|
||||
{
|
||||
StatusText = "隔离显示物流元素失败";
|
||||
LogManager.Error("隔离显示物流元素失败");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StatusText = "未找到物流元素";
|
||||
LogManager.Info("未找到任何物流元素");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步开始动画命令(使用UIStateManager和Command Pattern)
|
||||
@ -821,113 +667,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步设置物流属性命令(使用UIStateManager和Command Pattern)
|
||||
/// </summary>
|
||||
private async Task ExecuteSetLogisticsAttributeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证输入
|
||||
if (string.IsNullOrEmpty(SelectedCategory))
|
||||
{
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
StatusText = "请先选择物流类别";
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedItems = NavisApplication.ActiveDocument?.CurrentSelection?.SelectedItems;
|
||||
if (selectedItems == null || selectedItems.Count == 0)
|
||||
{
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
StatusText = "请先选择模型元素";
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
StatusText = "正在设置物流属性...";
|
||||
});
|
||||
|
||||
// 在后台线程执行属性设置
|
||||
var result = await Task.Run(() =>
|
||||
{
|
||||
if (Enum.TryParse<CategoryAttributeManager.LogisticsElementType>(SelectedCategory, out var elementType))
|
||||
{
|
||||
int successCount = CategoryAttributeManager.AddLogisticsAttributes(
|
||||
selectedItems,
|
||||
elementType,
|
||||
isTraversable: true,
|
||||
priority: 5,
|
||||
heightLimit: 3.0,
|
||||
speedLimit: 10.0,
|
||||
widthLimit: WidthLimit);
|
||||
|
||||
return new { Success = true, Count = successCount, Category = SelectedCategory, Width = WidthLimit };
|
||||
}
|
||||
|
||||
return new { Success = false, Count = 0, Category = SelectedCategory, Width = WidthLimit };
|
||||
});
|
||||
|
||||
// 更新UI结果
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
if (result.Success)
|
||||
{
|
||||
StatusText = $"已为 {result.Count} 个元素设置物流属性: {result.Category} (宽度限制: {result.Width}m)";
|
||||
LogManager.Info($"设置物流属性: {result.Category}, 宽度限制: {result.Width}m, 影响元素: {result.Count}");
|
||||
}
|
||||
else
|
||||
{
|
||||
StatusText = $"无效的物流类别: {result.Category}";
|
||||
LogManager.Warning($"无效的物流类别: {result.Category}");
|
||||
}
|
||||
});
|
||||
|
||||
// 异步刷新物流模型列表
|
||||
await RefreshAllLogisticsModelsAsync();
|
||||
|
||||
// 如果当前处于仅显示物流模式,重新应用可见性设置
|
||||
if (IsLogisticsOnlyMode)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
ApplyVisibilityMode();
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
StatusText = $"设置物流属性出错: {ex.Message}";
|
||||
LogManager.Error($"设置物流属性异常: {ex.Message}", ex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#region 自动路径规划命令实现
|
||||
|
||||
/// <summary>
|
||||
/// 设置自动路径规划的起点(供外部调用)
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置自动路径规划的终点(供外部调用)
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 处理自动路径规划的鼠标点击事件(直接从PathClickToolPlugin获取)
|
||||
/// </summary>
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1038,165 +777,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
}, "更新选择显示");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化物流类别
|
||||
/// </summary>
|
||||
private async Task InitializeCategoriesAsync()
|
||||
{
|
||||
await SafeExecuteAsync(async () =>
|
||||
{
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
AvailableCategories.Clear();
|
||||
|
||||
// 添加所有物流元素类型
|
||||
foreach (var elementType in Enum.GetValues(typeof(CategoryAttributeManager.LogisticsElementType)))
|
||||
{
|
||||
AvailableCategories.Add(elementType.ToString());
|
||||
}
|
||||
|
||||
// 设置默认选择
|
||||
if (AvailableCategories.Count > 0)
|
||||
{
|
||||
SelectedCategory = AvailableCategories[0];
|
||||
}
|
||||
});
|
||||
|
||||
LogManager.Info($"已初始化 {AvailableCategories.Count} 个物流类别");
|
||||
}, "初始化物流类别");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从模型项获取物流类型
|
||||
/// </summary>
|
||||
private string GetLogisticsTypeFromItem(ModelItem item)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用 CategoryAttributeManager 的专用方法获取物流属性值
|
||||
return CategoryAttributeManager.GetLogisticsPropertyValue(item, CategoryAttributeManager.LogisticsProperties.TYPE);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"获取物流类型失败: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从模型项获取物流属性描述
|
||||
/// </summary>
|
||||
private string GetLogisticsAttributesFromItem(ModelItem item)
|
||||
{
|
||||
try
|
||||
{
|
||||
var attributes = new System.Text.StringBuilder();
|
||||
|
||||
// 查找物流属性类别
|
||||
foreach (var category in item.PropertyCategories)
|
||||
{
|
||||
if (category.DisplayName == CategoryAttributeManager.LogisticsCategories.LOGISTICS)
|
||||
{
|
||||
foreach (var property in category.Properties)
|
||||
{
|
||||
if (property.DisplayName != CategoryAttributeManager.LogisticsProperties.TYPE)
|
||||
{
|
||||
if (attributes.Length > 0) attributes.Append(", ");
|
||||
attributes.Append($"{property.DisplayName}: {property.Value.ToDisplayString()}");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return attributes.Length > 0 ? attributes.ToString() : null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"获取物流属性失败: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找所有具有物流属性的模型项
|
||||
/// </summary>
|
||||
private ModelItemCollection FindAllLogisticsModels()
|
||||
{
|
||||
var logisticsItems = new ModelItemCollection();
|
||||
|
||||
try
|
||||
{
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models != null)
|
||||
{
|
||||
// 使用Search API查找所有具有物流属性的模型项
|
||||
var search = new Search();
|
||||
search.Selection.SelectAll();
|
||||
|
||||
// 查找具有物流属性类别的项目
|
||||
search.SearchConditions.Add(
|
||||
SearchCondition.HasCategoryByDisplayName(CategoryAttributeManager.LogisticsCategories.LOGISTICS)
|
||||
);
|
||||
|
||||
logisticsItems = search.FindAll(document, false);
|
||||
LogManager.Info($"找到 {logisticsItems.Count} 个具有物流属性的模型项");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"查找物流模型失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return logisticsItems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型中的所有ModelItem
|
||||
/// </summary>
|
||||
private List<ModelItem> GetAllModelItems()
|
||||
{
|
||||
var allItems = new List<ModelItem>();
|
||||
try
|
||||
{
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models != null)
|
||||
{
|
||||
foreach (var model in document.Models)
|
||||
{
|
||||
// 从根模型的子项开始收集,以避免包含不可见的根节点
|
||||
foreach (var item in model.RootItem.Children)
|
||||
{
|
||||
CollectModelItems(item, allItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"获取所有模型项失败: {ex.Message}");
|
||||
}
|
||||
return allItems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归收集ModelItem及其所有子项
|
||||
/// </summary>
|
||||
private void CollectModelItems(ModelItem item, List<ModelItem> 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
|
||||
|
||||
@ -1220,49 +802,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
Task.Run(async () => await UpdateSelectionDisplayAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向后兼容:同步版本的刷新物流模型方法
|
||||
/// </summary>
|
||||
[Obsolete("请使用RefreshAllLogisticsModelsAsync方法以获得更好的性能", false)]
|
||||
public void RefreshAllLogisticsModels()
|
||||
{
|
||||
Task.Run(async () => await RefreshAllLogisticsModelsAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步版本的刷新所有物流模型方法
|
||||
/// </summary>
|
||||
public async Task RefreshAllLogisticsModelsAsync()
|
||||
{
|
||||
await SafeExecuteAsync(async () =>
|
||||
{
|
||||
await _uiStateManager.ExecuteUIUpdateAsync(() =>
|
||||
{
|
||||
LogisticsModels.Clear();
|
||||
|
||||
// 查找所有具有物流属性的模型项
|
||||
var allLogisticsItems = FindAllLogisticsModels();
|
||||
|
||||
foreach (var item in allLogisticsItems)
|
||||
{
|
||||
var logisticsType = GetLogisticsTypeFromItem(item);
|
||||
var attributes = GetLogisticsAttributesFromItem(item);
|
||||
|
||||
var model = new LogisticsModel
|
||||
{
|
||||
Name = item.DisplayName ?? "未命名模型",
|
||||
Category = logisticsType ?? "未分类",
|
||||
Attributes = attributes ?? "无属性",
|
||||
IsVisible = !item.IsHidden,
|
||||
NavisworksItem = item
|
||||
};
|
||||
LogisticsModels.Add(model);
|
||||
}
|
||||
});
|
||||
|
||||
LogManager.Info($"已刷新所有物流模型列表,共 {LogisticsModels.Count} 个模型");
|
||||
}, "刷新所有物流模型列表");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向后兼容:提供CommandManager访问接口
|
||||
@ -1281,7 +821,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
return _uiStateManager != null &&
|
||||
_commandManager != null &&
|
||||
LogisticsModels != null &&
|
||||
AvailableCategories != null;
|
||||
}
|
||||
|
||||
@ -1291,8 +830,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
public string GetStateInfo()
|
||||
{
|
||||
return $"UIStateManager: {(_uiStateManager != null ? "已初始化" : "未初始化")}, " +
|
||||
$"CommandManager: {(_commandManager != null ? "已初始化" : "未初始化")}, " +
|
||||
$"物流模型数量: {LogisticsModels?.Count ?? 0}";
|
||||
$"CommandManager: {(_commandManager != null ? "已初始化" : "未初始化")}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -624,19 +624,21 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
var logisticsItems = FindAllLogisticsModels();
|
||||
// 直接使用 CategoryAttributeManager 的 API
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
var logisticsItems = CategoryAttributeManager.GetAllLogisticsItems(document);
|
||||
var models = new List<LogisticsModel>();
|
||||
|
||||
foreach (var item in logisticsItems)
|
||||
{
|
||||
var logisticsType = GetLogisticsTypeFromItem(item);
|
||||
var attributes = GetLogisticsAttributesFromItem(item);
|
||||
// 直接使用 CategoryAttributeManager 的 API
|
||||
var info = CategoryAttributeManager.GetLogisticsAttributeInfo(item);
|
||||
|
||||
var model = new LogisticsModel
|
||||
{
|
||||
Name = item.DisplayName ?? "未命名模型",
|
||||
Category = logisticsType ?? "未分类",
|
||||
Attributes = attributes ?? "无属性",
|
||||
Category = info?.ElementType ?? "未分类",
|
||||
Attributes = FormatLogisticsAttributes(info),
|
||||
IsVisible = !item.IsHidden,
|
||||
NavisworksItem = item
|
||||
};
|
||||
@ -922,7 +924,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info("[UI-ModelSettings] 开始仅显示物流元素(优化版)");
|
||||
LogManager.Info("[UI-ModelSettings] 开始仅显示物流元素");
|
||||
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document == null || document.Models == null)
|
||||
@ -932,7 +934,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
// 使用 CategoryAttributeManager 的优化查询方法(Search API)
|
||||
var logisticsItems = CategoryAttributeManager.GetAllLogisticsItems(document);
|
||||
|
||||
if (logisticsItems == null || logisticsItems.Count == 0)
|
||||
@ -942,9 +943,8 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
return;
|
||||
}
|
||||
|
||||
LogManager.Info($"[UI-ModelSettings] 使用 Search API 找到 {logisticsItems.Count} 个物流元素");
|
||||
LogManager.Info($"[UI-ModelSettings] 找到 {logisticsItems.Count} 个物流元素");
|
||||
|
||||
// 使用 VisibilityManager 的优化隔离显示方法(带缓存,4-148ms)
|
||||
bool success = VisibilityHelper.IsolateSpecificItems(logisticsItems);
|
||||
|
||||
if (success)
|
||||
@ -955,7 +955,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
model.IsVisible = true;
|
||||
}
|
||||
|
||||
LogManager.Info($"[UI-ModelSettings] 成功隔离显示物流元素:显示 {logisticsItems.Count} 个核心项");
|
||||
LogManager.Info($"[UI-ModelSettings] 成功隔离显示物流元素");
|
||||
UpdateMainStatus($"仅显示物流元素 ({logisticsItems.Count} 个物流节点)");
|
||||
}
|
||||
else
|
||||
@ -971,225 +971,19 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找所有具有物流属性的模型项
|
||||
/// </summary>
|
||||
private ModelItemCollection FindAllLogisticsModels()
|
||||
{
|
||||
var logisticsItems = new ModelItemCollection();
|
||||
|
||||
try
|
||||
{
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models != null)
|
||||
{
|
||||
var search = new Search();
|
||||
search.Selection.SelectAll();
|
||||
|
||||
search.SearchConditions.Add(
|
||||
SearchCondition.HasCategoryByDisplayName(CategoryAttributeManager.LogisticsCategories.LOGISTICS)
|
||||
);
|
||||
|
||||
logisticsItems = search.FindAll(document, false);
|
||||
LogManager.Info($"找到 {logisticsItems.Count} 个具有物流属性的模型项");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"查找物流模型失败: {ex.Message}");
|
||||
}
|
||||
|
||||
return logisticsItems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从模型项获取物流类型
|
||||
/// 格式化物流属性为显示字符串
|
||||
/// </summary>
|
||||
private string GetLogisticsTypeFromItem(ModelItem item)
|
||||
private string FormatLogisticsAttributes(LogisticsAttributeInfo info)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 防御性检查:确保item和其属性集合不为null
|
||||
if (item?.PropertyCategories == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var category in item.PropertyCategories)
|
||||
{
|
||||
// 防御性检查:跳过无效或损坏的属性类别
|
||||
if (category == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 检查类别显示名称,捕获"幽灵"属性异常
|
||||
if (category.DisplayName == CategoryAttributeManager.LogisticsCategories.LOGISTICS)
|
||||
{
|
||||
// 防御性检查:确保Properties集合存在
|
||||
if (category.Properties == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var property in category.Properties)
|
||||
{
|
||||
// 防御性检查:跳过无效属性
|
||||
if (property == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (property.DisplayName == CategoryAttributeManager.LogisticsProperties.TYPE)
|
||||
{
|
||||
return property.Value.ToDisplayString();
|
||||
}
|
||||
}
|
||||
catch (Exception propEx)
|
||||
{
|
||||
// 捕获单个属性读取异常,继续处理其他属性
|
||||
LogManager.Warning($"读取物流属性失败,跳过: {propEx.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception catEx)
|
||||
{
|
||||
// 捕获单个类别处理异常(如"幽灵"属性错误),继续处理其他类别
|
||||
LogManager.Warning($"处理属性类别时发生异常,跳过: {catEx.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"获取物流类型失败: {ex.Message}");
|
||||
}
|
||||
if (info == null) return "无属性";
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从模型项获取物流属性描述
|
||||
/// </summary>
|
||||
private string GetLogisticsAttributesFromItem(ModelItem item)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 防御性检查:确保item和其属性集合不为null
|
||||
if (item?.PropertyCategories == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var attributes = new System.Text.StringBuilder();
|
||||
|
||||
foreach (var category in item.PropertyCategories)
|
||||
{
|
||||
// 防御性检查:跳过无效或损坏的属性类别
|
||||
if (category == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 检查类别显示名称,捕获"幽灵"属性异常
|
||||
if (category.DisplayName == CategoryAttributeManager.LogisticsCategories.LOGISTICS)
|
||||
{
|
||||
// 防御性检查:确保Properties集合存在
|
||||
if (category.Properties == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var property in category.Properties)
|
||||
{
|
||||
// 防御性检查:跳过无效属性
|
||||
if (property == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (property.DisplayName != CategoryAttributeManager.LogisticsProperties.TYPE)
|
||||
{
|
||||
if (attributes.Length > 0) attributes.Append(", ");
|
||||
attributes.Append($"{property.DisplayName}: {property.Value.ToDisplayString()}");
|
||||
}
|
||||
}
|
||||
catch (Exception propEx)
|
||||
{
|
||||
// 捕获单个属性读取异常,继续处理其他属性
|
||||
LogManager.Warning($"读取物流属性详情失败,跳过: {propEx.Message}");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception catEx)
|
||||
{
|
||||
// 捕获单个类别处理异常(如"幽灵"属性错误),继续处理其他类别
|
||||
LogManager.Warning($"处理属性类别详情时发生异常,跳过: {catEx.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
return attributes.Length > 0 ? attributes.ToString() : null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"获取物流属性失败: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型中的所有ModelItem
|
||||
/// </summary>
|
||||
private List<ModelItem> GetAllModelItems()
|
||||
{
|
||||
var allItems = new List<ModelItem>();
|
||||
try
|
||||
{
|
||||
var document = NavisApplication.ActiveDocument;
|
||||
if (document?.Models != null)
|
||||
{
|
||||
foreach (var model in document.Models)
|
||||
{
|
||||
foreach (var item in model.RootItem.Children)
|
||||
{
|
||||
CollectModelItems(item, allItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"获取所有模型项失败: {ex.Message}");
|
||||
}
|
||||
return allItems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归收集ModelItem及其所有子项
|
||||
/// </summary>
|
||||
private void CollectModelItems(ModelItem item, List<ModelItem> 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);
|
||||
}
|
||||
}
|
||||
// 简单格式化:可通行、优先级、限制等
|
||||
return $"可通行: {(info.IsTraversable ? "是" : "否")}, " +
|
||||
$"优先级: {info.Priority}, " +
|
||||
$"高度限制: {info.HeightLimit}m, " +
|
||||
$"速度限制: {info.SpeedLimit}km/h";
|
||||
}
|
||||
|
||||
private void RefreshAllCommands()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user