From bea74c27e56b59a65b0552f6d8cf48c796edefba Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Sat, 27 Jul 2019 16:11:41 +0200 Subject: [PATCH] Add log trace for tool handling --- common/eda_base_frame.cpp | 2 +- common/tool/action_manager.cpp | 22 ++++++++++++++++++++-- common/tool/action_menu.cpp | 14 +++++++++----- common/tool/tool_dispatcher.cpp | 6 ++++++ common/tool/tool_manager.cpp | 32 ++++++++++++++++++++++++++++++-- common/trace_helpers.cpp | 1 + include/trace_helpers.h | 7 +++++++ 7 files changed, 74 insertions(+), 10 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index c39bfcf689..19ec945efc 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -307,7 +307,7 @@ bool EDA_BASE_FRAME::doAutoSave() void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& event ) { - wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_FRAME::OnCharHook %s", dump( event ) ); + wxLogTrace( kicadTraceKeyEvent, "EDA_BASE_FRAME::OnCharHook %s", dump( event ) ); // Key events can be filtered here. // Currently no filtering is made. event.Skip(); diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp index 1b681032d8..9e26c49b43 100644 --- a/common/tool/action_manager.cpp +++ b/common/tool/action_manager.cpp @@ -23,10 +23,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include -#include #include -#include +#include +#include #include #include @@ -92,6 +93,9 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const if( key >= 'a' && key <= 'z' ) key = std::toupper( key ); + wxLogTrace( kicadTraceToolStack, "ACTION_MANAGER::RunHotKey Key: %s", + KeyNameFromKeyCode( aHotKey ) ); + HOTKEY_LIST::const_iterator it = m_actionHotKeys.find( key | mod ); // If no luck, try without Shift, to handle keys that require it @@ -100,6 +104,9 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const // different combination if( it == m_actionHotKeys.end() ) { + wxLogTrace( kicadTraceToolStack, + "ACTION_MANAGER::RunHotKey No actions found, searching with key: %s", + KeyNameFromKeyCode( key | ( mod & ~MD_SHIFT ) ) ); it = m_actionHotKeys.find( key | ( mod & ~MD_SHIFT ) ); if( it == m_actionHotKeys.end() ) @@ -141,15 +148,26 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const if( context ) { + wxLogTrace( kicadTraceToolStack, + "ACTION_MANAGER::RunHotKey Running action %s for hotkey %s", context->GetName(), + KeyNameFromKeyCode( aHotKey ) ); + m_toolMgr->RunAction( *context, true ); return true; } else if( global ) { + wxLogTrace( kicadTraceToolStack, + "ACTION_MANAGER::RunHotKey Running action: %s for hotkey %s", global->GetName(), + KeyNameFromKeyCode( aHotKey ) ); + m_toolMgr->RunAction( *global, true ); return true; } + wxLogTrace( kicadTraceToolStack, "ACTION_MANAGER::RunHotKey No action found for key %s", + KeyNameFromKeyCode( aHotKey ) ); + return false; } diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp index c707fb1766..6293898ea0 100644 --- a/common/tool/action_menu.cpp +++ b/common/tool/action_menu.cpp @@ -24,16 +24,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include +#include +#include +#include #include #include -#include #include -#include +#include +#include #include -#include -#include -#include using namespace std::placeholders; @@ -436,6 +437,9 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent ) // clients that don't supply a tool will have to check GetSelected() themselves if( evt && m_tool ) { + + wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() ); + TOOL_MANAGER* toolMgr = m_tool->GetManager(); if( g_last_menu_highlighted_id == aEvent.GetId() && !m_isContextMenu ) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 5e9711ff97..8b42599445 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -463,6 +463,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) if( evt ) { + wxLogTrace( kicadTraceToolStack, "TOOL_DISPATCHER::DispatchWxEvent %s", evt->Format() ); + handled = m_toolMgr->ProcessEvent( *evt ); // ESC is the special key for canceling tools, and is therefore seen as handled @@ -499,7 +501,11 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent ) OPT evt = m_actions->TranslateLegacyId( aEvent.GetId() ); if( evt ) + { + wxLogTrace( kicadTraceToolStack, "TOOL_DISPATCHER::DispatchWxCommand %s", evt->Format() ); + m_toolMgr->ProcessEvent( *evt ); + } else aEvent.Skip(); } diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 250985c75b..71870b267c 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -24,10 +24,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include #include #include +#include +#include +#include #include #include @@ -528,6 +529,8 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) { bool handled = false; + wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchInternal %s", aEvent.Format() ); + // iterate over active tool stack for( auto it = m_activeTools.begin(); it != m_activeTools.end(); ++it ) { @@ -555,6 +558,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) if( st->cofunc ) { + wxLogTrace( kicadTraceToolStack, + "TOOL_MANAGER::dispatchInternal Waking tool %s for event: %s", + st->theTool->GetName(), aEvent.Format() ); + setActiveState( st ); bool end = !st->cofunc->Resume(); @@ -565,6 +572,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) // If the tool did not request the event be passed to other tools, we're done if( !st->wakeupEvent.PassEvent() ) { + wxLogTrace( kicadTraceToolStack, + "TOOL_MANAGER::dispatchInternal %s stopped passing event: %s", + st->theTool->GetName(), aEvent.Format() ); + handled = true; break; } @@ -604,6 +615,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) // as the state changes, the transition table has to be set up again st->transitions.clear(); + wxLogTrace( kicadTraceToolStack, + "TOOL_MANAGER::dispatchInternal Running tool %s for event: %s", + st->theTool->GetName(), aEvent.Format() ); + // got match? Run the handler. setActiveState( st ); st->idle = false; @@ -626,6 +641,9 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent ) break; // only the first tool gets the event } + wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchInternal handled: %s %s", + ( handled ? "true" : "false" ), aEvent.Format() ); + return handled; } @@ -641,6 +659,7 @@ bool TOOL_MANAGER::dispatchHotKey( const TOOL_EVENT& aEvent ) bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent ) { + wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchActivation %s", aEvent.Format() ); if( aEvent.IsActivate() ) { wxString cmdStr( *aEvent.GetCommandStr() ); @@ -649,6 +668,10 @@ bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent ) if( tool != m_toolNameIndex.end() ) { + wxLogTrace( kicadTraceToolStack, + "TOOL_MANAGER::dispatchActivation Running tool %s for event: %s", + tool->second->theTool->GetName(), aEvent.Format() ); + runTool( tool->second->theTool ); return true; } @@ -931,6 +954,8 @@ void TOOL_MANAGER::applyViewControls( TOOL_STATE* aState ) bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent ) { + wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::processEvent %s", aEvent.Format() ); + if( dispatchHotKey( aEvent ) ) return true; @@ -949,6 +974,9 @@ bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent ) processEvent( event ); } + wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::processEvent handled: %s %s", + ( handled ? "true" : "false" ), aEvent.Format() ); + return handled; } diff --git a/common/trace_helpers.cpp b/common/trace_helpers.cpp index c7b4c662c3..b4cda831b9 100644 --- a/common/trace_helpers.cpp +++ b/common/trace_helpers.cpp @@ -33,6 +33,7 @@ const wxChar* const traceFindReplace = wxT( "KICAD_FIND_REPLACE" ); const wxChar* const kicadTraceCoords = wxT( "KICAD_COORDS" ); const wxChar* const kicadTraceKeyEvent = wxT( "KICAD_KEY_EVENTS" ); +const wxChar* const kicadTraceToolStack = wxT( "KICAD_TOOL_STACK" ); const wxChar* const traceSchLibMem = wxT( "KICAD_SCH_LIB_MEM" ); const wxChar* const traceFindItem = wxT( "KICAD_FIND_ITEM" ); const wxChar* const traceSchLegacyPlugin = wxT( "KICAD_SCH_LEGACY_PLUGIN" ); diff --git a/include/trace_helpers.h b/include/trace_helpers.h index d310bf5eed..55caa48a11 100644 --- a/include/trace_helpers.h +++ b/include/trace_helpers.h @@ -75,6 +75,13 @@ extern const wxChar* const kicadTraceCoords; */ extern const wxChar* const kicadTraceKeyEvent; +/** + * Flag to enable tracing of the tool handling stack. + * + * Use "KICAD_TOOL_STACK" to enable. + */ +extern const wxChar* const kicadTraceToolStack; + /** * Flag to enable auto save feature debug tracing. *