1.pickerSubTool事件
1.1 定义事件
actions.h文件中定义一个TOOL_ACTION
class ACTIONS
{
static TOOL_ACTION pickerSubTool;
}
actions.cpp文件中实现
TOOL_ACTION ACTIONS::pickerSubTool( "common.InteractivePicker.pickerSubTool",
AS_GLOBAL );
1.2 关联事件与事件处理函数
void PCB_PICKER_TOOL::setTransitions()
{
Go( &PCB_PICKER_TOOL::Main, ACTIONS::pickerSubTool.MakeEvent() );
}
事件处理函数与Go在同一个文件中,也就是说在事件处理函数中关联事件与事件处理函数
int PCB_PICKER_TOOL::Main( const TOOL_EVENT& aEvent )
{
VECTOR2D cursorPos;
while( TOOL_EVENT* evt = Wait() )
{
setCursor();
cursorPos = controls->GetMousePosition();
if( m_snap )
{
grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
cursorPos = grid.BestSnapAnchor( cursorPos, nullptr );
controls->ForceCursorPosition( true, cursorPos );
}
}
注意:PCB_PICKER_TOOL::Main和PCB_PICKER_TOOL::setTransitions()都在PCB_PICKER_TOOL类中定义。
MakeEvent()是TOOL_ACTION的一个函数,该函数创造一个TOOL_ACTION实例:
TOOL_EVENT TOOL_ACTION::MakeEvent() const
{
if( IsActivation() )
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope, m_param );
else if( IsNotification() )
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope, m_param );
else
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope, m_param );
}
TOOL_ACTION构造函数:
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction,
const std::string& aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL,
void* aParameter = nullptr ) :
m_category( aCategory ),
m_actions( aAction ),
m_scope( aScope ),
m_mouseButtons( 0 ),
m_keyCode( 0 ),
m_modifiers( 0 ),
m_param( aParameter ),
m_firstResponder( nullptr )
{
if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE )
m_commandStr = aExtraParam;
init();
}
1.3事件的调用
edit_tool.cpp文件中调用
EDIT_TOOL::pickReferencePoint(...)
{
...
m_toolMgr->RunAction( ACTIONS::pickerSubTool, true );
...
}