NavisworksTransport/src/Core/PathInputMonitor.cs

71 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;
namespace NavisworksTransport
{
/// <summary>
/// 路径编辑输入监听器
/// 作为PathClickToolPlugin的备用事件捕获机制解决工具焦点丢失问题
/// </summary>
[Plugin("NavisworksTransport.PathInputMonitor", "NVTX", DisplayName = "PathInputMonitor")]
public class PathInputMonitor : InputPlugin
{
/// <summary>
/// 鼠标按下事件处理
/// 不处理鼠标点击让PathClickToolPlugin和导航工具正常工作
/// </summary>
public override bool MouseDown(View view, KeyModifiers modifiers, ushort button, int x, int y, double timeOffset)
{
// 不处理鼠标点击让PathClickToolPlugin和导航工具正常工作
// PathClickToolPlugin会在CustomToolPlugin模式下处理点击
// 导航工具会在导航模式下处理点击
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)
{
var currentTool = Application.MainDocument.Tool.Value;
if (currentTool != Tool.CustomToolPlugin)
{
LogManager.Info($"[InputMonitor] 用户按空格键,当前工具为{currentTool}强制恢复ToolPlugin焦点");
bool restored = pathManager.ForceReinitializeToolPlugin(subscribeToEvents: false);
if (restored)
{
return true;
}
}
}
}
return false;
}
catch (Exception ex)
{
LogManager.Error($"[InputMonitor] 处理键盘事件异常: {ex.Message}");
return false;
}
}
}
}