修复路径列表UI触发事件引起事件循环的问题
This commit is contained in:
parent
d63896bf63
commit
d9c2ec8c12
@ -4,15 +4,15 @@
|
||||
|
||||
### [2025/12/09]
|
||||
|
||||
1. [ ] (BUG)路径列表和动画当前路径的变化存在循环引用的情况
|
||||
1. [x] (BUG)路径列表和动画当前路径的变化存在循环引用的情况
|
||||
2. [ ] (BUG)动画过程中,有一些被碰撞的墙、柱子和其他对象没有被检测到
|
||||
|
||||
### [2025/12/08]
|
||||
|
||||
1. [x] (功能)碰撞检测时,增加手工指定被检测构件,用特殊颜色标识
|
||||
2. [ ] (功能)动画时,物流模型朝向随路径变化
|
||||
2. [x] (功能)动画时,物流模型朝向随路径变化
|
||||
3. [x] (功能)动画生成,增加使用模拟物流车辆立方体选项
|
||||
4. [ ] (功能)动画检测时,过滤门和其他可通行构件
|
||||
4. [x] (功能)动画检测时,过滤门和其他可通行构件
|
||||
5. [x] (BUG)只有手动路径时,导出路径按钮没激活
|
||||
6. [ ] (BUG)重复打开模型,有时程序崩溃,需要先关闭物流插件窗口
|
||||
7. [x] (优化)提高碰撞检测在处理大型模型时的性能
|
||||
|
||||
@ -963,9 +963,9 @@ namespace NavisworksTransport
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建几何对象列表缓存,一次性获取所有几何对象
|
||||
/// 构建几何对象列表缓存,一次性获取非隐藏几何对象
|
||||
/// </summary>
|
||||
public static void BuildAllGeometryItemsCache()
|
||||
public static void BuildNonHidddenGeometryItemsCache()
|
||||
{
|
||||
lock (_cacheLock)
|
||||
{
|
||||
|
||||
@ -263,9 +263,9 @@ namespace NavisworksTransport
|
||||
{
|
||||
var previousRoute = _currentRoute;
|
||||
_currentRoute = value;
|
||||
|
||||
// 触发当前路径变更事件
|
||||
RaiseCurrentRouteChanged(previousRoute, value);
|
||||
|
||||
// 只有真正的业务操作才触发事件,UI同步不触发事件
|
||||
RaiseCurrentRouteChanged(previousRoute, value, triggerEvent: true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,25 +552,29 @@ namespace NavisworksTransport
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseCurrentRouteChanged(PathRoute previousRoute, PathRoute newRoute)
|
||||
private void RaiseCurrentRouteChanged(PathRoute previousRoute, PathRoute newRoute, bool triggerEvent)
|
||||
{
|
||||
try
|
||||
{
|
||||
var eventArgs = new CurrentRouteChangedEventArgs(previousRoute, newRoute, _managerId);
|
||||
|
||||
if (_uiStateManager != null)
|
||||
// 只有需要触发事件时才执行事件触发逻辑
|
||||
if (triggerEvent)
|
||||
{
|
||||
_uiStateManager.QueueUIUpdate(() =>
|
||||
if (_uiStateManager != null)
|
||||
{
|
||||
_uiStateManager.QueueUIUpdate(() =>
|
||||
{
|
||||
CurrentRouteChanged?.Invoke(this, eventArgs);
|
||||
// 向后兼容的事件
|
||||
CurrentRouteChanged_Legacy?.Invoke(this, newRoute);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentRouteChanged?.Invoke(this, eventArgs);
|
||||
// 向后兼容的事件
|
||||
CurrentRouteChanged_Legacy?.Invoke(this, newRoute);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentRouteChanged?.Invoke(this, eventArgs);
|
||||
CurrentRouteChanged_Legacy?.Invoke(this, newRoute);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -1044,7 +1048,7 @@ namespace NavisworksTransport
|
||||
// 保存自动生成的路径到数据库
|
||||
SavePathToDatabase(autoRoute);
|
||||
}
|
||||
CurrentRoute = autoRoute;
|
||||
SetCurrentRouteInternal(autoRoute, triggerEvent: true);
|
||||
|
||||
// 8. 确保路径可视化使用正确的网格大小(修复尺寸自适应问题)
|
||||
var renderPlugin = PathPointRenderPlugin.Instance;
|
||||
@ -1090,14 +1094,32 @@ namespace NavisworksTransport
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置当前路线
|
||||
/// 设置当前路线(UI调用版本,不触发事件以避免循环)
|
||||
/// </summary>
|
||||
/// <param name="route">要设置的路线</param>
|
||||
public void SetCurrentRoute(PathRoute route)
|
||||
{
|
||||
SetCurrentRouteInternal(route, triggerEvent: false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内部设置当前路线(可选择是否触发事件)
|
||||
/// </summary>
|
||||
/// <param name="route">要设置的路线</param>
|
||||
/// <param name="triggerEvent">是否触发事件</param>
|
||||
private void SetCurrentRouteInternal(PathRoute route, bool triggerEvent)
|
||||
{
|
||||
try
|
||||
{
|
||||
CurrentRoute = route;
|
||||
// 直接设置字段,绕过事件触发
|
||||
var previousRoute = _currentRoute;
|
||||
_currentRoute = route;
|
||||
|
||||
// 如果需要触发事件(真正的业务操作)
|
||||
if (triggerEvent)
|
||||
{
|
||||
RaiseCurrentRouteChanged(previousRoute, route, triggerEvent: true);
|
||||
}
|
||||
|
||||
// 如果路径有关联的GridMap,加载它用于网格可视化
|
||||
if (route?.AssociatedGridMap != null)
|
||||
@ -1139,7 +1161,7 @@ namespace NavisworksTransport
|
||||
{
|
||||
PathEditState = PathEditState.Editing;
|
||||
EditingRoute = route ?? throw new ArgumentNullException(nameof(route));
|
||||
CurrentRoute = route;
|
||||
SetCurrentRouteInternal(route, triggerEvent: true);
|
||||
|
||||
// 智能管理ToolPlugin状态
|
||||
ManageToolPluginForEditState();
|
||||
@ -1274,7 +1296,7 @@ namespace NavisworksTransport
|
||||
|
||||
var newRoute = new PathRoute(routeName);
|
||||
_routes.Add(newRoute);
|
||||
CurrentRoute = newRoute;
|
||||
SetCurrentRouteInternal(newRoute, triggerEvent: true);
|
||||
|
||||
// 保存到数据库
|
||||
SavePathToDatabase(newRoute);
|
||||
@ -1315,7 +1337,7 @@ namespace NavisworksTransport
|
||||
if (_currentRoute == route)
|
||||
{
|
||||
var newRoute = _routes.FirstOrDefault() ?? new PathRoute("默认路径");
|
||||
CurrentRoute = newRoute;
|
||||
SetCurrentRouteInternal(newRoute, triggerEvent: true);
|
||||
}
|
||||
RaiseStatusChanged($"已删除路径: {route.Name}", PathPlanningStatusType.Success);
|
||||
}
|
||||
@ -1383,7 +1405,7 @@ namespace NavisworksTransport
|
||||
// 创建新路径
|
||||
var newRoute = new PathRoute(routeName ?? $"路径{DateTime.Now:yyyyMMdd_HHmmss}");
|
||||
_editingRoute = newRoute;
|
||||
CurrentRoute = newRoute;
|
||||
SetCurrentRouteInternal(newRoute, triggerEvent: true);
|
||||
|
||||
// 自动选择所有可通行的物流模型
|
||||
AutoSelectLogisticsChannels();
|
||||
|
||||
@ -1928,7 +1928,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
ClashDetectiveIntegration.ClearAllCaches();
|
||||
|
||||
UpdateMainStatus("正在缓存几何对象列表...", -1, true);
|
||||
ClashDetectiveIntegration.BuildAllGeometryItemsCache();
|
||||
ClashDetectiveIntegration.BuildNonHidddenGeometryItemsCache();
|
||||
|
||||
UpdateMainStatus("正在缓存通道对象...", -1, true);
|
||||
var clashIntegration = ClashDetectiveIntegration.Instance;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user