增加了焦点捕捉功能,即使切换导航工具依然可以获取鼠标焦点,用于路径点设置
This commit is contained in:
parent
722e2ce9cc
commit
3ba3d328b8
@ -98,6 +98,7 @@
|
||||
<!-- Core - Main Plugin Files -->
|
||||
<Compile Include="src\Core\MainPlugin.cs" />
|
||||
<Compile Include="src\Core\PathClickToolPlugin.cs" />
|
||||
<Compile Include="src\Core\PathInputMonitor.cs" />
|
||||
<Compile Include="src\Core\PathPointRenderPlugin.cs" />
|
||||
|
||||
<!-- Core - Business Logic -->
|
||||
|
||||
@ -33,6 +33,17 @@ namespace NavisworksTransport
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 公开方法,允许外部代码触发 MouseClicked 事件
|
||||
/// 用于 PathInputMonitor 等备用输入机制
|
||||
/// </summary>
|
||||
/// <param name="sender">事件发送者</param>
|
||||
/// <param name="result">点击结果</param>
|
||||
public static void TriggerMouseClicked(object sender, PickItemResult result)
|
||||
{
|
||||
MouseClicked?.Invoke(sender, result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重写鼠标按下事件,获取精确的点击坐标
|
||||
|
||||
120
src/Core/PathInputMonitor.cs
Normal file
120
src/Core/PathInputMonitor.cs
Normal file
@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using Autodesk.Navisworks.Api;
|
||||
using Autodesk.Navisworks.Api.Plugins;
|
||||
using NavisworksTransport.Core;
|
||||
|
||||
namespace NavisworksTransport
|
||||
{
|
||||
/// <summary>
|
||||
/// 路径编辑输入监听器
|
||||
/// 作为PathClickToolPlugin的备用事件捕获机制,解决工具焦点丢失问题
|
||||
/// </summary>
|
||||
[Plugin("NavisworksTransport.PathInputMonitor", "NVTX", DisplayName = "PathInputMonitor")]
|
||||
public class PathInputMonitor : InputPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// 鼠标按下事件处理
|
||||
/// 在路径编辑模式下捕获鼠标点击,即使ToolPlugin失活也能响应
|
||||
/// </summary>
|
||||
public override bool MouseDown(View view, KeyModifiers modifiers, ushort button, int x, int y, double timeOffset)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 只处理左键点击
|
||||
if (button != 1) return false;
|
||||
|
||||
// 获取PathPlanningManager实例
|
||||
var pathManager = PathPlanningManager.GetActivePathManager();
|
||||
if (pathManager == null) return false;
|
||||
|
||||
// 只在路径编辑模式下处理
|
||||
if (pathManager.PathEditState == PathEditState.AddingPoints ||
|
||||
pathManager.PathEditState == PathEditState.EditingPoint)
|
||||
{
|
||||
LogManager.WriteLog("[InputMonitor] 检测到路径编辑模式下的鼠标点击");
|
||||
|
||||
// 如果ToolPlugin未激活,自动重新激活
|
||||
if (!pathManager.IsToolPluginActive)
|
||||
{
|
||||
LogManager.WriteLog("[InputMonitor] ToolPlugin未激活,自动重新激活");
|
||||
pathManager.ReactivateToolPlugin();
|
||||
|
||||
// 给用户一个视觉反馈
|
||||
var uiStateManager = UIStateManager.Instance;
|
||||
uiStateManager?.QueueUIUpdate(() =>
|
||||
{
|
||||
// 这里可以添加状态栏提示或其他UI反馈
|
||||
});
|
||||
}
|
||||
|
||||
// 获取精确的3D坐标
|
||||
PickItemResult itemResult = view.PickItemFromPoint(x, y);
|
||||
if (itemResult != null)
|
||||
{
|
||||
LogManager.WriteLog($"[InputMonitor] 获取到3D坐标: ({itemResult.Point.X:F3}, {itemResult.Point.Y:F3}, {itemResult.Point.Z:F3})");
|
||||
|
||||
// 触发PathClickToolPlugin的事件,复用现有的完整处理逻辑
|
||||
// 这确保了自动路径、手动路径的所有模式都能正常工作
|
||||
PathClickToolPlugin.TriggerMouseClicked(this, itemResult);
|
||||
|
||||
LogManager.WriteLog("[InputMonitor] 已触发PathClickToolPlugin事件");
|
||||
return true; // 返回true表示已处理,阻止其他处理程序
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.WriteLog("[InputMonitor] 未点击到有效对象");
|
||||
}
|
||||
|
||||
return false; // 让其他处理程序继续处理
|
||||
}
|
||||
|
||||
return false; // 不在编辑模式,不处理
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.WriteLog($"[InputMonitor] 处理鼠标点击异常: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标移动事件(暂不处理,避免性能影响)
|
||||
/// </summary>
|
||||
public override bool MouseMove(View view, KeyModifiers modifiers, int x, int y, double timeOffset)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 键盘按下事件
|
||||
/// 可以在这里添加快捷键恢复工具的功能
|
||||
/// </summary>
|
||||
public override bool KeyDown(View view, KeyModifiers modifier, ushort key, double timeOffset)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 空格键快速恢复工具
|
||||
if (key == 32) // 空格键
|
||||
{
|
||||
var pathManager = PathPlanningManager.GetActivePathManager();
|
||||
if (pathManager != null &&
|
||||
(pathManager.PathEditState == PathEditState.AddingPoints ||
|
||||
pathManager.PathEditState == PathEditState.EditingPoint) &&
|
||||
!pathManager.IsToolPluginActive)
|
||||
{
|
||||
LogManager.WriteLog("[InputMonitor] 用户按空格键,重新激活工具");
|
||||
pathManager.ReactivateToolPlugin();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.WriteLog($"[InputMonitor] 处理键盘事件异常: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -55,6 +55,11 @@ namespace NavisworksTransport
|
||||
private int _editingPointIndex = -1; // 正在修改的路径点索引
|
||||
private PathPoint _originalPoint = null; // 修改前的原始路径点
|
||||
private PathPoint _editingPreviewPoint = null; // 修改时的预览路径点
|
||||
|
||||
/// <summary>
|
||||
/// ToolPlugin是否处于激活状态(供InputMonitor使用)
|
||||
/// </summary>
|
||||
public bool IsToolPluginActive => _isToolPluginActive;
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前是否在预览模式
|
||||
@ -2304,6 +2309,45 @@ namespace NavisworksTransport
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重新激活ToolPlugin(供InputMonitor调用)
|
||||
/// 用于在工具失活后快速恢复,不重复订阅事件
|
||||
/// </summary>
|
||||
public void ReactivateToolPlugin()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 只有在编辑模式且工具未激活时才重新激活
|
||||
if (!_isToolPluginActive &&
|
||||
(PathEditState == PathEditState.AddingPoints ||
|
||||
PathEditState == PathEditState.EditingPoint))
|
||||
{
|
||||
LogManager.WriteLog("[ReactivateToolPlugin] 开始重新激活ToolPlugin");
|
||||
|
||||
// 调用现有的激活方法,但不重复订阅事件
|
||||
if (ActivateToolPlugin(false))
|
||||
{
|
||||
LogManager.WriteLog("[ReactivateToolPlugin] ToolPlugin重新激活成功");
|
||||
RaiseStatusChanged("工具已重新激活", PathPlanningStatusType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.WriteLog("[ReactivateToolPlugin] ToolPlugin重新激活失败");
|
||||
RaiseErrorOccurred("无法重新激活编辑工具");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManager.WriteLog($"[ReactivateToolPlugin] 跳过重新激活 - IsToolPluginActive: {_isToolPluginActive}, PathEditState: {PathEditState}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.WriteLog($"[ReactivateToolPlugin] 重新激活失败: {ex.Message}");
|
||||
RaiseErrorOccurred($"重新激活工具失败: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理ToolPlugin的鼠标点击事件
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user