KiCad PCB EDA Suite
TOOL_MANAGER Class Reference

Master controller class: More...

#include <tool_manager.h>

Classes

struct  TOOL_STATE
 Struct describing the current execution state of a TOOL. More...
 

Public Types

typedef std::map< TOOL_BASE *, TOOL_STATE * > TOOL_STATE_MAP
 
typedef std::map< std::string, TOOL_STATE * > NAME_STATE_MAP
 
typedef std::map< TOOL_ID, TOOL_STATE * > ID_STATE_MAP
 
typedef std::list< TOOL_IDID_LIST
 

Public Member Functions

 TOOL_MANAGER ()
 
 ~TOOL_MANAGER ()
 
void RegisterTool (TOOL_BASE *aTool)
 Add a tool to the manager set and sets it up. More...
 
bool InvokeTool (TOOL_ID aToolId)
 Call a tool by sending a tool activation event to tool of given ID. More...
 
bool InvokeTool (const std::string &aToolName)
 Call a tool by sending a tool activation event to tool of given name. More...
 
void ShutdownAllTools ()
 Shutdown all tools with a currently registered event loop in this tool manager by waking them up with a null event. More...
 
void ShutdownTool (TOOL_BASE *aTool)
 Shutdown the specified tool by waking it up with a null event to terminate the processing loop. More...
 
void ShutdownTool (TOOL_ID aToolId)
 Shutdown the specified tool by waking it up with a null event to terminate the processing loop. More...
 
void ShutdownTool (const std::string &aToolName)
 Shutdown the specified tool by waking it up with a null event to terminate the processing loop. More...
 
template<typename T >
bool RunAction (const std::string &aActionName, bool aNow=false, T aParam=NULL)
 Run the specified action. More...
 
bool RunAction (const std::string &aActionName, bool aNow, void *aParam)
 
bool RunAction (const std::string &aActionName, bool aNow=false)
 
template<typename T >
bool RunAction (const TOOL_ACTION &aAction, bool aNow=false, T aParam=NULL)
 Run the specified action. More...
 
bool RunAction (const TOOL_ACTION &aAction, bool aNow, void *aParam)
 
bool RunAction (const TOOL_ACTION &aAction, bool aNow=false)
 
void CancelTool ()
 Send a cancel event to the tool currently at the top of the tool stack. More...
 
void PrimeTool (const VECTOR2D &aPosition)
 "Prime" a tool by sending a cursor left-click event with the mouse position set to the passed in position. More...
 
int GetHotKey (const TOOL_ACTION &aAction) const
 
ACTION_MANAGERGetActionManager () const
 
TOOL_BASEFindTool (int aId) const
 Search for a tool with given ID. More...
 
TOOL_BASEFindTool (const std::string &aName) const
 Search for a tool with given name. More...
 
template<typename T >
T * GetTool ()
 
std::vector< TOOL_BASE * > Tools ()
 
void DeactivateTool ()
 Deactivate the currently active tool. More...
 
bool IsToolActive (TOOL_ID aId) const
 Return true if a tool with given id is active (executing) More...
 
void ResetTools (TOOL_BASE::RESET_REASON aReason)
 Reset all tools (i.e. More...
 
void InitTools ()
 Initializes all registered tools. More...
 
bool ProcessEvent (const TOOL_EVENT &aEvent)
 Propagate an event to tools that requested events of matching type(s). More...
 
void PostEvent (const TOOL_EVENT &aEvent)
 Put an event to the event queue to be processed at the end of event processing cycle. More...
 
void SetEnvironment (EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
 Set the work environment (model, view, view controls and the parent window). More...
 
KIGFX::VIEWGetView () const
 
KIGFX::VIEW_CONTROLSGetViewControls () const
 
VECTOR2D GetMousePosition () const
 
VECTOR2D GetCursorPosition () const
 
EDA_ITEMGetModel () const
 
APP_SETTINGS_BASEGetSettings () const
 
TOOLS_HOLDERGetToolHolder () const
 
int GetCurrentToolId () const
 Return id of the tool that is on the top of the active tools stack (was invoked the most recently). More...
 
TOOL_BASEGetCurrentTool () const
 Return the tool that is on the top of the active tools stack (was invoked the most recently). More...
 
TOOL_STATEGetCurrentToolState () const
 Return the #TOOL_STATE object representing the state of the active tool. More...
 
int GetPriority (int aToolId) const
 Return priority of a given tool. More...
 
void ScheduleNextState (TOOL_BASE *aTool, TOOL_STATE_FUNC &aHandler, const TOOL_EVENT_LIST &aConditions)
 Define a state transition. More...
 
void ClearTransitions (TOOL_BASE *aTool)
 Clear the state transition map for a tool. More...
 
void RunMainStack (TOOL_BASE *aTool, std::function< void()> aFunc)
 
void UpdateUI (const TOOL_EVENT &aEvent)
 Update the status bar and synchronizes toolbars. More...
 
TOOL_EVENTScheduleWait (TOOL_BASE *aTool, const TOOL_EVENT_LIST &aConditions)
 Pause execution of a given tool until one or more events matching aConditions arrives. More...
 
void ScheduleContextMenu (TOOL_BASE *aTool, ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
 Set behavior of the tool's context popup menu. More...
 
bool SaveClipboard (const std::string &aTextUTF8)
 Store information to the system clipboard. More...
 
std::string GetClipboardUTF8 () const
 Return the information currently stored in the system clipboard. More...
 
const KIGFX::VC_SETTINGSGetCurrentToolVC () const
 Return the view controls settings for the current tool or the general settings if there is no active tool. More...
 
bool IsContextMenuActive () const
 True while processing a context menu. More...
 
void VetoContextMenuMouseWarp ()
 Disable mouse warping after the current context menu is closed. More...
 
void DispatchContextMenu (const TOOL_EVENT &aEvent)
 Handle context menu related events. More...
 
bool DispatchHotKey (const TOOL_EVENT &aEvent)
 Handle specific events, that are intended for TOOL_MANAGER rather than tools. More...
 
VECTOR2D GetMenuCursorPos () const
 

Static Public Member Functions

static TOOL_ID MakeToolId (const std::string &aToolName)
 Generates a unique ID from for a tool with given name. More...
 

Private Types

typedef std::pair< TOOL_EVENT_LIST, TOOL_STATE_FUNCTRANSITION
 

Private Member Functions

bool dispatchInternal (TOOL_EVENT &aEvent)
 Pass an event at first to the active tools, then to all others. More...
 
bool dispatchActivation (const TOOL_EVENT &aEvent)
 Check if it is a valid activation event and invokes a proper tool. More...
 
bool invokeTool (TOOL_BASE *aTool)
 Invoke a tool by sending a proper event (in contrary to runTool, which makes the tool run for real). More...
 
bool runTool (TOOL_BASE *aTool)
 Make a tool active, so it can receive events and react to them. More...
 
ID_LIST::iterator finishTool (TOOL_STATE *aState)
 Deactivate a tool and does the necessary clean up. More...
 
bool isRegistered (TOOL_BASE *aTool) const
 Return information about a tool registration status. More...
 
bool isActive (TOOL_BASE *aTool) const
 Return information about a tool activation status. More...
 
void saveViewControls (TOOL_STATE *aState)
 Save the #VIEW_CONTROLS settings to the tool state object. More...
 
void applyViewControls (const TOOL_STATE *aState)
 Apply #VIEW_CONTROLS settings stored in a #TOOL_STATE object. More...
 
bool processEvent (const TOOL_EVENT &aEvent)
 Main function for event processing. More...
 
void setActiveState (TOOL_STATE *aState)
 Save the previous active state and sets a new one. More...
 

Private Attributes

std::vector< TOOL_BASE * > m_toolOrder
 Index of registered tools current states, associated by tools' objects. More...
 
TOOL_STATE_MAP m_toolState
 Index of the registered tools current states, associated by tools' names. More...
 
NAME_STATE_MAP m_toolNameIndex
 Index of the registered tools current states, associated by tools' ID numbers. More...
 
ID_STATE_MAP m_toolIdIndex
 Index of the registered tools to easily lookup by their type. More...
 
std::map< const char *, TOOL_BASE * > m_toolTypes
 Stack of the active tools. More...
 
ID_LIST m_activeTools
 Instance of ACTION_MANAGER that handles TOOL_ACTIONs. More...
 
ACTION_MANAGERm_actionMgr
 Original cursor position, if overridden by the context menu handler. More...
 
std::map< TOOL_ID, std::optional< VECTOR2D > > m_cursorSettings
 
EDA_ITEMm_model
 
KIGFX::VIEWm_view
 
KIGFX::VIEW_CONTROLSm_viewControls
 
TOOLS_HOLDERm_frame
 
APP_SETTINGS_BASEm_settings
 Queue that stores events to be processed at the end of the event processing cycle. More...
 
std::list< TOOL_EVENTm_eventQueue
 Right click context menu position. More...
 
VECTOR2D m_menuCursor
 
bool m_warpMouseAfterContextMenu
 Flag indicating whether a context menu is currently displayed. More...
 
bool m_menuActive
 Tool currently displaying a popup menu. It is negative when there is no menu displayed. More...
 
TOOL_ID m_menuOwner
 Pointer to the state object corresponding to the currently executed tool. More...
 
TOOL_STATEm_activeState
 True if the tool manager is shutting down (don't process additional events) More...
 
bool m_shuttingDown
 

Detailed Description

Master controller class:

  • registers editing tools
  • pumps UI events to tools requesting them
  • manages tool state machines (transitions and wait requests)

Definition at line 54 of file tool_manager.h.

Member Typedef Documentation

◆ ID_LIST

typedef std::list<TOOL_ID> TOOL_MANAGER::ID_LIST

Definition at line 68 of file tool_manager.h.

◆ ID_STATE_MAP

Definition at line 67 of file tool_manager.h.

◆ NAME_STATE_MAP

typedef std::map<std::string, TOOL_STATE*> TOOL_MANAGER::NAME_STATE_MAP

Definition at line 66 of file tool_manager.h.

◆ TOOL_STATE_MAP

Definition at line 65 of file tool_manager.h.

◆ TRANSITION

Definition at line 448 of file tool_manager.h.

Constructor & Destructor Documentation

◆ TOOL_MANAGER()

TOOL_MANAGER::TOOL_MANAGER ( )

Definition at line 205 of file tool_manager.cpp.

205 :
206 m_model( nullptr ),
207 m_view( nullptr ),
208 m_viewControls( nullptr ),
209 m_frame( nullptr ),
210 m_settings( nullptr ),
212 m_menuActive( false ),
213 m_menuOwner( -1 ),
214 m_activeState( nullptr ),
215 m_shuttingDown( false )
216{
217 m_actionMgr = new ACTION_MANAGER( this );
218}
Manage TOOL_ACTION objects.
TOOL_STATE * m_activeState
True if the tool manager is shutting down (don't process additional events)
Definition: tool_manager.h:582
APP_SETTINGS_BASE * m_settings
Queue that stores events to be processed at the end of the event processing cycle.
Definition: tool_manager.h:565
TOOLS_HOLDER * m_frame
Definition: tool_manager.h:564
bool m_warpMouseAfterContextMenu
Flag indicating whether a context menu is currently displayed.
Definition: tool_manager.h:573
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:563
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:556
TOOL_ID m_menuOwner
Pointer to the state object corresponding to the currently executed tool.
Definition: tool_manager.h:579
KIGFX::VIEW * m_view
Definition: tool_manager.h:562
bool m_shuttingDown
Definition: tool_manager.h:585
bool m_menuActive
Tool currently displaying a popup menu. It is negative when there is no menu displayed.
Definition: tool_manager.h:576
EDA_ITEM * m_model
Definition: tool_manager.h:561

References m_actionMgr.

◆ ~TOOL_MANAGER()

TOOL_MANAGER::~TOOL_MANAGER ( )

Definition at line 221 of file tool_manager.cpp.

222{
223 std::map<TOOL_BASE*, TOOL_STATE*>::iterator it, it_end;
224
225 for( it = m_toolState.begin(), it_end = m_toolState.end(); it != it_end; ++it )
226 {
227 delete it->second->cofunc; // delete cofunction
228 delete it->second; // delete TOOL_STATE
229 delete it->first; // delete the tool itself
230 }
231
232 delete m_actionMgr;
233}
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:541

References m_actionMgr, and m_toolState.

Member Function Documentation

◆ applyViewControls()

void TOOL_MANAGER::applyViewControls ( const TOOL_STATE aState)
private

Apply #VIEW_CONTROLS settings stored in a #TOOL_STATE object.

Definition at line 1136 of file tool_manager.cpp.

1137{
1138 m_viewControls->ApplySettings( aState->vcSettings );
1139}
void ApplySettings(const VC_SETTINGS &aSettings)
Load new settings from program common settings.

References KIGFX::VIEW_CONTROLS::ApplySettings(), m_viewControls, and TOOL_MANAGER::TOOL_STATE::vcSettings.

Referenced by setActiveState().

◆ CancelTool()

void TOOL_MANAGER::CancelTool ( )

Send a cancel event to the tool currently at the top of the tool stack.

Definition at line 351 of file tool_manager.cpp.

352{
354
355 processEvent( evt );
356}
Generic, UI-independent tool event.
Definition: tool_event.h:156
bool processEvent(const TOOL_EVENT &aEvent)
Main function for event processing.
@ TA_CANCEL_TOOL
Definition: tool_event.h:85
@ TC_COMMAND
Definition: tool_event.h:52

References processEvent(), TA_CANCEL_TOOL, and TC_COMMAND.

Referenced by ACTION_TOOLBAR::onToolEvent().

◆ ClearTransitions()

void TOOL_MANAGER::ClearTransitions ( TOOL_BASE aTool)

Clear the state transition map for a tool.

Parameters
aToolis the tool that should have the transition map cleared.

Definition at line 648 of file tool_manager.cpp.

649{
650 m_toolState[aTool]->transitions.clear();
651}

References m_toolState.

Referenced by TOOL_INTERACTIVE::resetTransitions().

◆ DeactivateTool()

void TOOL_MANAGER::DeactivateTool ( )

Deactivate the currently active tool.

Definition at line 565 of file tool_manager.cpp.

566{
567 // Deactivate the active tool, but do not run anything new
569 processEvent( evt );
570}

References processEvent(), TA_CANCEL_TOOL, and TC_COMMAND.

Referenced by GERBVIEW_FRAME::doCloseWindow(), SCH_DRAWING_TOOLS::DrawShape(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), DIALOG_UPDATE_PCB::PerformUpdate(), ResetTools(), and FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME().

◆ dispatchActivation()

bool TOOL_MANAGER::dispatchActivation ( const TOOL_EVENT aEvent)
private

Check if it is a valid activation event and invokes a proper tool.

Parameters
aEventis an event to be tested.
Returns
True if a tool was invoked, false otherwise.

Definition at line 826 of file tool_manager.cpp.

827{
828 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::dispatchActivation - Received event: %s" ),
829 aEvent.Format() );
830
831 if( aEvent.IsActivate() )
832 {
833 auto tool = m_toolNameIndex.find( aEvent.getCommandStr() );
834
835 if( tool != m_toolNameIndex.end() )
836 {
837 wxLogTrace( kicadTraceToolStack,
838 wxS( "TOOL_MANAGER::dispatchActivation - Running tool %s for event: %s" ),
839 tool->second->theTool->GetName(), aEvent.Format() );
840
841 runTool( tool->second->theTool );
842 return true;
843 }
844 }
845
846 return false;
847}
bool IsActivate() const
Definition: tool_event.h:318
const std::string & getCommandStr() const
Definition: tool_event.h:482
const std::string Format() const
Return information about event in form of a human-readable string.
Definition: tool_event.cpp:94
bool runTool(TOOL_BASE *aTool)
Make a tool active, so it can receive events and react to them.
NAME_STATE_MAP m_toolNameIndex
Index of the registered tools current states, associated by tools' ID numbers.
Definition: tool_manager.h:544
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.

References TOOL_EVENT::Format(), TOOL_EVENT::getCommandStr(), TOOL_EVENT::IsActivate(), kicadTraceToolStack, m_toolNameIndex, and runTool().

Referenced by processEvent().

◆ DispatchContextMenu()

void TOOL_MANAGER::DispatchContextMenu ( const TOOL_EVENT aEvent)

Handle context menu related events.

Definition at line 849 of file tool_manager.cpp.

850{
851 for( TOOL_ID toolId : m_activeTools )
852 {
853 TOOL_STATE* st = m_toolIdIndex[toolId];
854
855 // the tool requested a context menu. The menu is activated on RMB click (CMENU_BUTTON mode)
856 // or immediately (CMENU_NOW) mode. The latter is used for clarification lists.
857 if( st->contextMenuTrigger == CMENU_OFF )
858 continue;
859
860 if( st->contextMenuTrigger == CMENU_BUTTON && !aEvent.IsClick( BUT_RIGHT ) )
861 break;
862
863 if( st->cofunc )
864 {
865 st->pendingWait = true;
866 st->waitEvents = TOOL_EVENT( TC_ANY, TA_ANY );
867 }
868
869 // Store the menu pointer in case it is changed by the TOOL when handling menu events
870 ACTION_MENU* m = st->contextMenu;
871
872 if( st->contextMenuTrigger == CMENU_NOW )
873 st->contextMenuTrigger = CMENU_OFF;
874
875 // Store the cursor position, so the tools could execute actions
876 // using the point where the user has invoked a context menu
877 if( m_viewControls )
879
880 // Save all tools cursor settings, as they will be overridden
881 for( const std::pair<const TOOL_ID, TOOL_STATE*>& idState : m_toolIdIndex )
882 {
883 TOOL_STATE* s = idState.second;
884 const auto& vc = s->vcSettings;
885
886 if( vc.m_forceCursorPosition )
887 m_cursorSettings[idState.first] = vc.m_forcedPosition;
888 else
889 m_cursorSettings[idState.first] = std::nullopt;
890 }
891
892 if( m_viewControls )
894
895 // Display a copy of menu
896 std::unique_ptr<ACTION_MENU> menu( m->Clone() );
897
898 m_menuOwner = toolId;
899 m_menuActive = true;
900
901 if( wxWindow* frame = dynamic_cast<wxWindow*>( m_frame ) )
902 frame->PopupMenu( menu.get() );
903
904 // If a menu is canceled then notify tool
905 if( menu->GetSelected() < 0 )
906 {
908 evt.SetHasPosition( false );
909 evt.SetParameter( m );
910 dispatchInternal( evt );
911 }
912
913 // Restore setting in case it was vetoed
915
916 // Notify the tools that menu has been closed
918 evt.SetHasPosition( false );
919 evt.SetParameter( m );
920 dispatchInternal( evt );
921
922 m_menuActive = false;
923 m_menuOwner = -1;
924
925 // Restore cursor settings
926 for( const std::pair<const TOOL_ID, std::optional<VECTOR2D>>& cursorSetting : m_cursorSettings )
927 {
928 auto it = m_toolIdIndex.find( cursorSetting.first );
929 wxASSERT( it != m_toolIdIndex.end() );
930
931 if( it == m_toolIdIndex.end() )
932 continue;
933
934 KIGFX::VC_SETTINGS& vc = it->second->vcSettings;
935 vc.m_forceCursorPosition = (bool) cursorSetting.second;
936 vc.m_forcedPosition = cursorSetting.second ? *cursorSetting.second : VECTOR2D( 0, 0 );
937 }
938
939 m_cursorSettings.clear();
940 break;
941 }
942}
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:49
ACTION_MENU * Clone() const
Create a deep, recursive copy of this ACTION_MENU.
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
bool IsClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:200
std::map< TOOL_ID, std::optional< VECTOR2D > > m_cursorSettings
Definition: tool_manager.h:559
bool dispatchInternal(TOOL_EVENT &aEvent)
Pass an event at first to the active tools, then to all others.
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:547
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:553
VECTOR2D m_menuCursor
Definition: tool_manager.h:571
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:42
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:55
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
Definition: view_controls.h:58
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
@ CMENU_NOW
Definition: tool_event.h:148
@ CMENU_OFF
Definition: tool_event.h:149
@ CMENU_BUTTON
Definition: tool_event.h:147
@ TA_ANY
Definition: tool_event.h:121
@ TA_CHOICE_MENU_CHOICE
Definition: tool_event.h:93
@ TA_CHOICE_MENU_CLOSED
Definition: tool_event.h:96
@ TC_ANY
Definition: tool_event.h:55
@ BUT_RIGHT
Definition: tool_event.h:128

References BUT_RIGHT, ACTION_MENU::Clone(), CMENU_BUTTON, CMENU_NOW, CMENU_OFF, TOOL_MANAGER::TOOL_STATE::cofunc, TOOL_MANAGER::TOOL_STATE::contextMenu, TOOL_MANAGER::TOOL_STATE::contextMenuTrigger, dispatchInternal(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVENT::IsClick(), m_activeTools, m_cursorSettings, KIGFX::VC_SETTINGS::m_forceCursorPosition, KIGFX::VC_SETTINGS::m_forcedPosition, m_frame, m_menuActive, m_menuCursor, m_menuOwner, m_toolIdIndex, m_viewControls, m_warpMouseAfterContextMenu, TOOL_MANAGER::TOOL_STATE::pendingWait, TOOL_EVENT::SetHasPosition(), TOOL_EVENT::SetParameter(), TA_ANY, TA_CHOICE_MENU_CHOICE, TA_CHOICE_MENU_CLOSED, TC_ANY, TC_COMMAND, TOOL_MANAGER::TOOL_STATE::vcSettings, and TOOL_MANAGER::TOOL_STATE::waitEvents.

Referenced by processEvent().

◆ DispatchHotKey()

bool TOOL_MANAGER::DispatchHotKey ( const TOOL_EVENT aEvent)

Handle specific events, that are intended for TOOL_MANAGER rather than tools.

Parameters
aEventis the event to be processed.
Returns
true if the event was processed and should not go any further.

Definition at line 817 of file tool_manager.cpp.

818{
819 if( aEvent.Action() == TA_KEY_PRESSED )
820 return m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() );
821
822 return false;
823}
bool RunHotKey(int aHotKey) const
Run an action associated with a hotkey (if there is one available).
TOOL_ACTIONS Action() const
These give a tool a method of informing the TOOL_MANAGER that a particular event should be passed on ...
Definition: tool_event.h:233
int KeyCode() const
Definition: tool_event.h:349
int Modifier(int aMask=MD_MODIFIER_MASK) const
Definition: tool_event.h:339
@ TA_KEY_PRESSED
Definition: tool_event.h:71

References TOOL_EVENT::Action(), TOOL_EVENT::KeyCode(), m_actionMgr, TOOL_EVENT::Modifier(), ACTION_MANAGER::RunHotKey(), and TA_KEY_PRESSED.

Referenced by processEvent().

◆ dispatchInternal()

bool TOOL_MANAGER::dispatchInternal ( TOOL_EVENT aEvent)
private

Pass an event at first to the active tools, then to all others.

Definition at line 684 of file tool_manager.cpp.

685{
686 bool handled = false;
687
688 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::dispatchInternal - received event: %s" ),
689 aEvent.Format() );
690
691 auto it = m_activeTools.begin();
692
693 // iterate over active tool stack
694 while( it != m_activeTools.end() )
695 {
696 TOOL_STATE* st = m_toolIdIndex[*it];
697 bool increment = true;
698
699 // forward context menu events to the tool that created the menu
700 if( aEvent.IsChoiceMenu() )
701 {
702 if( *it != m_menuOwner )
703 {
704 ++it;
705 continue;
706 }
707 }
708
709 // If we're pendingWait then we had better have a cofunc to process the wait.
710 wxASSERT( !st || !st->pendingWait || st->cofunc );
711
712 // the tool state handler is waiting for events (i.e. called Wait() method)
713 if( st && st->cofunc && st->pendingWait && st->waitEvents.Matches( aEvent ) )
714 {
715 if( !aEvent.FirstResponder() )
716 aEvent.SetFirstResponder( st->theTool );
717
718 // got matching event? clear wait list and wake up the coroutine
719 st->wakeupEvent = aEvent;
720 st->pendingWait = false;
721 st->waitEvents.clear();
722
723 wxLogTrace( kicadTraceToolStack,
724 wxS( "TOOL_MANAGER::dispatchInternal - Waking tool %s for event: %s" ),
725 st->theTool->GetName(), aEvent.Format() );
726
727 setActiveState( st );
728 bool end = !st->cofunc->Resume();
729
730 if( end )
731 {
732 it = finishTool( st );
733 increment = false;
734 }
735
736 // If the tool did not request the event be passed to other tools, we're done
737 if( !st->wakeupEvent.PassEvent() )
738 {
739 wxLogTrace( kicadTraceToolStack,
740 wxS( "TOOL_MANAGER::dispatchInternal - tool %s stopped passing event: %s" ),
741 st->theTool->GetName(), aEvent.Format() );
742
743 return true;
744 }
745 }
746
747 if( increment )
748 ++it;
749 }
750
751 for( const auto& state : m_toolState )
752 {
753 TOOL_STATE* st = state.second;
754 bool finished = false;
755
756 // no state handler in progress - check if there are any transitions (defined by
757 // Go() method that match the event.
758 if( !st->transitions.empty() )
759 {
760 for( const TRANSITION& tr : st->transitions )
761 {
762 if( tr.first.Matches( aEvent ) )
763 {
764 auto func_copy = tr.second;
765
766 if( !aEvent.FirstResponder() )
767 aEvent.SetFirstResponder( st->theTool );
768
769 // if there is already a context, then push it on the stack
770 // and transfer the previous view control settings to the new context
771 if( st->cofunc )
772 {
773 auto vc = st->vcSettings;
774 st->Push();
775 st->vcSettings = vc;
776 }
777
778 st->cofunc = new COROUTINE<int, const TOOL_EVENT&>( std::move( func_copy ) );
779
780 // as the state changes, the transition table has to be set up again
781 st->transitions.clear();
782
783 wxLogTrace( kicadTraceToolStack,
784 wxS( "TOOL_MANAGER::dispatchInternal - Running tool %s for event: %s" ),
785 st->theTool->GetName(), aEvent.Format() );
786
787 // got match? Run the handler.
788 setActiveState( st );
789 st->idle = false;
790 st->initialEvent = aEvent;
791 st->cofunc->Call( st->initialEvent );
792 handled = true;
793
794 if( !st->cofunc->Running() )
795 finishTool( st ); // The coroutine has finished immediately?
796
797 // if it is a message, continue processing
798 finished = !( aEvent.Category() == TC_MESSAGE );
799
800 // there is no point in further checking, as transitions got cleared
801 break;
802 }
803 }
804 }
805
806 if( finished )
807 break; // only the first tool gets the event
808 }
809
810 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::dispatchInternal - %s handle event: %s" ),
811 ( handled ? wxS( "Did" ) : wxS( "Did not" ) ), aEvent.Format() );
812
813 return handled;
814}
TOOL_BASE * FirstResponder() const
Definition: tool_event.h:251
void SetFirstResponder(TOOL_BASE *aTool)
Controls whether the tool is first being pushed to the stack or being reactivated after a pause.
Definition: tool_event.h:252
TOOL_EVENT_CATEGORY Category() const
Returns more specific information about the type of an event.
Definition: tool_event.h:230
bool IsChoiceMenu() const
Definition: tool_event.h:328
std::pair< TOOL_EVENT_LIST, TOOL_STATE_FUNC > TRANSITION
Definition: tool_manager.h:448
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
ID_LIST::iterator finishTool(TOOL_STATE *aState)
Deactivate a tool and does the necessary clean up.
@ TC_MESSAGE
Definition: tool_event.h:53

References COROUTINE< ReturnType, ArgType >::Call(), TOOL_EVENT::Category(), TOOL_EVENT_LIST::clear(), TOOL_MANAGER::TOOL_STATE::cofunc, finishTool(), TOOL_EVENT::FirstResponder(), TOOL_EVENT::Format(), TOOL_BASE::GetName(), TOOL_MANAGER::TOOL_STATE::idle, TOOL_MANAGER::TOOL_STATE::initialEvent, TOOL_EVENT::IsChoiceMenu(), kicadTraceToolStack, m_activeTools, m_menuOwner, m_toolIdIndex, m_toolState, TOOL_EVENT_LIST::Matches(), TOOL_EVENT::PassEvent(), TOOL_MANAGER::TOOL_STATE::pendingWait, TOOL_MANAGER::TOOL_STATE::Push(), COROUTINE< ReturnType, ArgType >::Resume(), COROUTINE< ReturnType, ArgType >::Running(), setActiveState(), TOOL_EVENT::SetFirstResponder(), TC_MESSAGE, TOOL_MANAGER::TOOL_STATE::theTool, TOOL_MANAGER::TOOL_STATE::transitions, TOOL_MANAGER::TOOL_STATE::vcSettings, TOOL_MANAGER::TOOL_STATE::waitEvents, and TOOL_MANAGER::TOOL_STATE::wakeupEvent.

Referenced by DispatchContextMenu(), and processEvent().

◆ FindTool() [1/2]

TOOL_BASE * TOOL_MANAGER::FindTool ( const std::string &  aName) const

Search for a tool with given name.

Parameters
aNameis the name of the requested tool.
Returns
Pointer to the requested tool or NULL in case of failure.

Definition at line 554 of file tool_manager.cpp.

555{
556 std::map<std::string, TOOL_STATE*>::const_iterator it = m_toolNameIndex.find( aName );
557
558 if( it != m_toolNameIndex.end() )
559 return it->second->theTool;
560
561 return nullptr;
562}

References m_toolNameIndex.

◆ FindTool() [2/2]

TOOL_BASE * TOOL_MANAGER::FindTool ( int  aId) const

Search for a tool with given ID.

Parameters
aIdis the ID number of the requested tool.
Returns
Pointer to the requested tool or NULL in case of failure.

Definition at line 543 of file tool_manager.cpp.

544{
545 std::map<TOOL_ID, TOOL_STATE*>::const_iterator it = m_toolIdIndex.find( aId );
546
547 if( it != m_toolIdIndex.end() )
548 return it->second->theTool;
549
550 return nullptr;
551}

References m_toolIdIndex.

Referenced by GetCurrentTool(), InvokeTool(), ACTION_MANAGER::RunHotKey(), and ShutdownTool().

◆ finishTool()

TOOL_MANAGER::ID_LIST::iterator TOOL_MANAGER::finishTool ( TOOL_STATE aState)
private

Deactivate a tool and does the necessary clean up.

Parameters
aStateis the state variable of the tool to be stopped.
Returns
m_activeTools iterator. If the tool has been completely deactivated, it points to the next active tool on the list. Otherwise it is an iterator pointing to aState.

Definition at line 945 of file tool_manager.cpp.

946{
947 auto it = std::find( m_activeTools.begin(), m_activeTools.end(), aState->theTool->GetId() );
948
949 if( !aState->Pop() )
950 {
951 // Deactivate the tool if there are no other contexts saved on the stack
952 if( it != m_activeTools.end() )
953 it = m_activeTools.erase( it );
954
955 aState->idle = true;
956 }
957
958 if( aState == m_activeState )
959 setActiveState( nullptr );
960
961 // Set transitions to be ready for future TOOL_EVENTs
962 TOOL_BASE* tool = aState->theTool;
963
964 if( tool->GetType() == INTERACTIVE )
965 static_cast<TOOL_INTERACTIVE*>( tool )->resetTransitions();
966
967 return it;
968}
Base abstract interface for all kinds of tools.
Definition: tool_base.h:66
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:109
@ INTERACTIVE
Tool that interacts with the user.
Definition: tool_base.h:49

References TOOL_BASE::GetId(), TOOL_BASE::GetType(), TOOL_MANAGER::TOOL_STATE::idle, INTERACTIVE, m_activeState, m_activeTools, TOOL_MANAGER::TOOL_STATE::Pop(), setActiveState(), and TOOL_MANAGER::TOOL_STATE::theTool.

Referenced by dispatchInternal(), and ShutdownTool().

◆ GetActionManager()

◆ GetClipboardUTF8()

std::string TOOL_MANAGER::GetClipboardUTF8 ( ) const

Return the information currently stored in the system clipboard.

If data stored in the clipboard is in non-text format, empty string is returned.

Note
The clipboard is expected containing Unicode chars, not only ASCII7 chars. The returned string is UTF8 encoded

Definition at line 1031 of file tool_manager.cpp.

1032{
1033 std::string result;
1034
1035 wxLogNull doNotLog; // disable logging of failed clipboard actions
1036
1037 if( wxTheClipboard->Open() )
1038 {
1039 if( wxTheClipboard->IsSupported( wxDF_TEXT )
1040 || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
1041 {
1042 wxTextDataObject data;
1043 wxTheClipboard->GetData( data );
1044
1045 // The clipboard is expected containing a Unicode string, so return it
1046 // as UTF8 string
1047 result = data.GetText().utf8_str();
1048 }
1049
1050 wxTheClipboard->Close();
1051 }
1052
1053 return result;
1054}

Referenced by SCH_EDITOR_CONTROL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), and PL_EDIT_TOOL::Paste().

◆ GetCurrentTool()

TOOL_BASE * TOOL_MANAGER::GetCurrentTool ( ) const
inline

Return the tool that is on the top of the active tools stack (was invoked the most recently).

Returns
Pointer to the currently used tool.

Definition at line 315 of file tool_manager.h.

316 {
317 return FindTool( GetCurrentToolId() );
318 }
int GetCurrentToolId() const
Return id of the tool that is on the top of the active tools stack (was invoked the most recently).
Definition: tool_manager.h:304
TOOL_BASE * FindTool(int aId) const
Search for a tool with given ID.

References FindTool(), and GetCurrentToolId().

Referenced by PCB_GRID_HELPER::queryVisible().

◆ GetCurrentToolId()

int TOOL_MANAGER::GetCurrentToolId ( ) const
inline

Return id of the tool that is on the top of the active tools stack (was invoked the most recently).

Returns
Id of the currently used tool.

Definition at line 304 of file tool_manager.h.

305 {
306 return m_activeTools.empty() ? -1 : m_activeTools.front();
307 }

References m_activeTools.

Referenced by GetCurrentTool(), and GetCurrentToolState().

◆ GetCurrentToolState()

TOOL_STATE * TOOL_MANAGER::GetCurrentToolState ( ) const
inline

Return the #TOOL_STATE object representing the state of the active tool.

If there are no tools active, it returns nullptr.

Definition at line 324 of file tool_manager.h.

325 {
326 auto it = m_toolIdIndex.find( GetCurrentToolId() );
327 return ( it != m_toolIdIndex.end() ) ? it->second : nullptr;
328 }

References GetCurrentToolId(), and m_toolIdIndex.

Referenced by GetCurrentToolVC(), invokeTool(), and ProcessEvent().

◆ GetCurrentToolVC()

const KIGFX::VC_SETTINGS & TOOL_MANAGER::GetCurrentToolVC ( ) const

Return the view controls settings for the current tool or the general settings if there is no active tool.

Definition at line 1057 of file tool_manager.cpp.

1058{
1059 if( TOOL_STATE* active = GetCurrentToolState() )
1060 return active->vcSettings;
1061
1062 return m_viewControls->GetSettings();
1063}
const VC_SETTINGS & GetSettings() const
Apply VIEW_CONTROLS settings from an object.
TOOL_STATE * GetCurrentToolState() const
Return the #TOOL_STATE object representing the state of the active tool.
Definition: tool_manager.h:324

References GetCurrentToolState(), KIGFX::VIEW_CONTROLS::GetSettings(), and m_viewControls.

Referenced by COMMON_TOOLS::ResetLocalCoords().

◆ GetCursorPosition()

VECTOR2D TOOL_MANAGER::GetCursorPosition ( ) const

Definition at line 311 of file tool_manager.cpp.

312{
313 if( m_viewControls )
315 else
316 return wxGetMousePosition();
317}

References KIGFX::VIEW_CONTROLS::GetCursorPosition(), and m_viewControls.

Referenced by invokeTool(), and RunAction().

◆ GetHotKey()

int TOOL_MANAGER::GetHotKey ( const TOOL_ACTION aAction) const

Definition at line 390 of file tool_manager.cpp.

391{
392 return m_actionMgr->GetHotKey( aAction );
393}
int GetHotKey(const TOOL_ACTION &aAction) const
Return the hot key associated with a given action or 0 if there is none.

References ACTION_MANAGER::GetHotKey(), and m_actionMgr.

Referenced by ACTION_MENU::updateHotKeys().

◆ GetMenuCursorPos()

VECTOR2D TOOL_MANAGER::GetMenuCursorPos ( ) const
inline

Definition at line 442 of file tool_manager.h.

443 {
444 return m_menuCursor;
445 }

References m_menuCursor.

Referenced by ROUTER_TOOL::InlineBreakTrack().

◆ GetModel()

◆ GetMousePosition()

VECTOR2D TOOL_MANAGER::GetMousePosition ( ) const

Definition at line 302 of file tool_manager.cpp.

303{
304 if( m_viewControls )
306 else
307 return wxGetMousePosition();
308}
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.

References KIGFX::VIEW_CONTROLS::GetMousePosition(), and m_viewControls.

Referenced by EE_SELECTION_TOOL::Main(), PL_SELECTION_TOOL::Main(), PCB_SELECTION_TOOL::Main(), and ACTION_MENU::OnMenuEvent().

◆ GetPriority()

int TOOL_MANAGER::GetPriority ( int  aToolId) const

Return priority of a given tool.

Higher number means that the tool is closer to the beginning of the active tools queue (i.e. receives events earlier, tools with lower priority receive events later).

Parameters
aToolIdis the id of queried tool.
Returns
The priority of a given tool. If returned number is negative, then it means that the tool id is invalid or the tool is not active.

Definition at line 623 of file tool_manager.cpp.

624{
625 int priority = 0;
626
627 for( TOOL_ID tool : m_activeTools )
628 {
629 if( tool == aToolId )
630 return priority;
631
632 ++priority;
633 }
634
635 return -1;
636}

References m_activeTools.

Referenced by ACTION_MANAGER::RunHotKey().

◆ GetSettings()

◆ GetTool()

template<typename T >
T * TOOL_MANAGER::GetTool ( )
inline

Definition at line 218 of file tool_manager.h.

219 {
220 std::map<const char*, TOOL_BASE*>::iterator tool = m_toolTypes.find( typeid( T ).name() );
221
222 if( tool != m_toolTypes.end() )
223 return static_cast<T*>( tool->second );
224
225 return nullptr;
226 }
const char * name
Definition: DXF_plotter.cpp:56
std::map< const char *, TOOL_BASE * > m_toolTypes
Stack of the active tools.
Definition: tool_manager.h:550

References m_toolTypes, and name.

Referenced by FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), EDA_BASE_FRAME::AddStandardHelpMenu(), EDA_DRAW_FRAME::AddStandardSubMenus(), PCB_PROPERTIES_PANEL::AfterCommit(), SCH_MOVE_TOOL::AlignElements(), SCH_EDIT_FRAME::AnnotateSymbols(), SCH_EDITOR_CONTROL::AssignNetclass(), BOARD_EDITOR_CONTROL::AssignNetclass(), EE_SELECTION_TOOL::autostartEvent(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), PCB_EDIT_FRAME::canCloseWindow(), ROUTER_TOOL::CanInlineDrag(), SCH_EDIT_FRAME::CheckAnnotate(), PCB_EDIT_FRAME::CommonSettingsChanged(), PAD_TOOL::copyPadSettings(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), ZONE_CREATE_HELPER::createNewZone(), EE_INSPECTION_TOOL::CrossProbe(), DRC_TOOL::CrossProbe(), SCH_EDIT_FRAME::DeleteAnnotation(), SCH_EDIT_TOOL::DeleteItemCursor(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), SCH_EDIT_FRAME::DeleteJunction(), DIALOG_BOARD_REANNOTATE::DIALOG_BOARD_REANNOTATE(), BOARD_COMMIT::dirtyIntersectingZones(), SCH_EDIT_FRAME::DisplayCurrentSheet(), PL_DRAW_PANEL_GAL::DisplayDrawingSheet(), DIALOG_CLEANUP_TRACKS_AND_VIAS::doCleanup(), SCH_EDITOR_CONTROL::doCopy(), BOARD_EDITOR_CONTROL::doCrossProbePcbToSch(), SCH_EDITOR_CONTROL::doCrossProbeSchToPcb(), BOARD_INSPECTION_TOOL::doHideRatsnestNet(), SCH_FIELD::DoHypertextAction(), SCH_TEXT::DoHypertextAction(), SCH_TEXTBOX::DoHypertextAction(), EDIT_TOOL::doMoveSelection(), CVPCB_MAINFRAME::doReCreateMenuBar(), SCH_EDIT_FRAME::doReCreateMenuBar(), SYMBOL_EDIT_FRAME::doReCreateMenuBar(), SYMBOL_VIEWER_FRAME::doReCreateMenuBar(), GERBVIEW_FRAME::doReCreateMenuBar(), KICAD_MANAGER_FRAME::doReCreateMenuBar(), PL_EDITOR_FRAME::doReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::doReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::doReCreateMenuBar(), PCB_EDIT_FRAME::doReCreateMenuBar(), EDIT_TOOL::Drag(), DRAWING_TOOL::DrawVia(), BOARD_EDITOR_CONTROL::DrillOrigin(), EDIT_TOOL::Duplicate(), BOARD_EDITOR_CONTROL::EditFpInFpEditor(), PAD_TOOL::EditPad(), SYMBOL_EDITOR_EDIT_TOOL::editShapeProperties(), SYMBOL_EDITOR_EDIT_TOOL::editSymbolProperties(), SCH_EDITOR_CONTROL::EditWithSymbolEditor(), GROUP_TOOL::EnterGroup(), SCH_NAVIGATE_TOOL::EnterSheet(), EE_INSPECTION_TOOL::ExcludeMarker(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), SCH_EDITOR_CONTROL::FindSymbolAndItem(), EDIT_TOOL::GetAndPlace(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool(), FP_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool(), DISPLAY_FOOTPRINTS_FRAME::GetCurrentSelection(), SCH_EDIT_FRAME::GetCurrentSelection(), SYMBOL_EDIT_FRAME::GetCurrentSelection(), SYMBOL_VIEWER_FRAME::GetCurrentSelection(), GERBVIEW_FRAME::GetCurrentSelection(), PL_EDITOR_FRAME::GetCurrentSelection(), FOOTPRINT_EDIT_FRAME::GetCurrentSelection(), FOOTPRINT_VIEWER_FRAME::GetCurrentSelection(), PCB_EDIT_FRAME::GetCurrentSelection(), PL_EDITOR_FRAME::GetLayoutFromRedoList(), PL_EDITOR_FRAME::GetLayoutFromUndoList(), DRAWING_TOOL::getSourceZoneForAction(), EDA_DRAW_FRAME::GetUnitPair(), PCB_CONTROL::GridSetOrigin(), GROUP_TOOL::Group(), SYMBOL_EDIT_FRAME::HardRedraw(), PL_EDITOR_FRAME::HardRedraw(), GERBVIEW_CONTROL::HighlightControl(), BOARD_INSPECTION_TOOL::highlightNet(), highlightNet(), SCH_EDITOR_CONTROL::HighlightNetCursor(), EE_TOOL_BASE< T >::Init(), SCH_EDIT_TOOL::Init(), SYMBOL_EDITOR_CONTROL::Init(), SYMBOL_EDITOR_EDIT_TOOL::Init(), PL_DRAWING_TOOLS::Init(), PL_EDIT_TOOL::Init(), PL_POINT_EDITOR::Init(), BOARD_EDITOR_CONTROL::Init(), BOARD_INSPECTION_TOOL::Init(), BOARD_REANNOTATE_TOOL::Init(), CONVERT_TOOL::Init(), EDIT_TOOL::Init(), GLOBAL_EDIT_TOOL::Init(), GROUP_TOOL::Init(), PAD_TOOL::Init(), PCB_POINT_EDITOR::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), POSITION_RELATIVE_TOOL::Init(), DIALOG_PAD_PROPERTIES::initValues(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), BOARD_INSPECTION_TOOL::InspectClearance(), BOARD_INSPECTION_TOOL::InspectConstraints(), ARRAY_CREATOR::Invoke(), EDIT_TOOL::invokeInlineRouter(), EDIT_TOOL::isRouterActive(), SCH_EDIT_FRAME::KiwayMailIn(), GROUP_TOOL::LeaveGroup(), PCB_EDIT_FRAME::LoadProjectSettings(), FOOTPRINT_EDIT_FRAME::LoadSettings(), SYMBOL_EDIT_FRAME::LoadSymbol(), SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), EE_SELECTION_TOOL::Main(), SCH_MOVE_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_SELECTION_TOOL::Main(), PCB_SELECTION_TOOL::Main(), GRAPHICS_CLEANER::mergePads(), SCH_EDIT_TOOL::Mirror(), BOARD_EDITOR_CONTROL::modifyLockSelected(), PROPERTIES_FRAME::OnAcceptPrms(), DIALOG_DRC::OnActivateDlg(), PCB_EDIT_FRAME::onBoardLoaded(), DIALOG_DRC::OnCancelClick(), DIALOG_FOOTPRINT_CHECKER::OnCancelClick(), DIALOG_INSPECTOR::onCellClicked(), DIALOG_POSITION_RELATIVE::OnClear(), DIALOG_ERC::OnCloseErcDialog(), DIALOG_DRC::OnDRCItemRClick(), FOOTPRINT_EDIT_FRAME::OnEditItemRequest(), PCB_EDIT_FRAME::OnEditItemRequest(), SCH_EDIT_FRAME::OnImportProject(), DIALOG_POSITION_RELATIVE::OnOkClick(), DIALOG_PLOT::onRunDRC(), DIALOG_DRC::OnRunDRCClick(), DIALOG_POSITION_RELATIVE::OnSelectItemClick(), DIALOG_SYMBOL_FIELDS_TABLE::OnTableRangeSelected(), SCH_EDIT_FRAME::OpenProjectFiles(), PANEL_SELECTION_FILTER::PANEL_SELECTION_FILTER(), SCH_EDITOR_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), PCB_BASE_EDIT_FRAME::PCB_BASE_EDIT_FRAME(), GROUP_TOOL::PickNewMember(), EDIT_TOOL::pickReferencePoint(), PCB_CONTROL::placeBoardItems(), DRAWING_TOOL::PlaceImage(), SCH_DRAWING_TOOLS::PlaceSymbol(), DIALOG_PLOT::Plot(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), PAD_TOOL::pushPadSettings(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), SCH_EDIT_FRAME::ReCreateOptToolbar(), SYMBOL_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateVToolbar(), PCB_EDIT_FRAME::ReCreateVToolbar(), SCH_EDITOR_CONTROL::Redo(), SYMBOL_EDITOR_EDIT_TOOL::Redo(), SCH_BASE_FRAME::RefreshZoomDependentItems(), GROUP_TOOL::RemoveFromGroup(), SCH_EDIT_TOOL::RepeatDrawItem(), SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem(), BOARD_COMMIT::Revert(), PL_EDITOR_FRAME::RollbackFromUndo(), SCH_EDIT_FRAME::RollbackSchematicFromUndo(), SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo(), SCH_EDIT_TOOL::Rotate(), ROUTER_TOOL::RouteSelected(), DRC_TOOL::RunTests(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), PCB_EDIT_FRAME::SaveProjectSettings(), EDA_DRAW_FRAME::SaveSettings(), FOOTPRINT_EDIT_FRAME::SaveSettings(), SCH_BASE_FRAME::SCH_BASE_FRAME(), SCH_EDIT_FRAME::SchematicCleanUp(), PCB_TOOL_BASE::selection(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), CVPCB_MAINFRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), SCH_EDIT_FRAME::setupUIConditions(), PCB_EDIT_FRAME::setupUIConditions(), EDA_DRAW_FRAME::setupUnits(), PCB_EDIT_FRAME::ShowFindDialog(), SCH_EDIT_FRAME::ShowFindReplaceDialog(), PCB_BASE_EDIT_FRAME::ShowGraphicItemPropertiesDialog(), EDA_DRAW_FRAME::ToggleUserUnits(), BOARD_EDITOR_CONTROL::TrackWidthDec(), BOARD_EDITOR_CONTROL::TrackWidthInc(), DIALOG_LIB_TEXT_PROPERTIES::TransferDataFromWindow(), DIALOG_LIB_TEXTBOX_PROPERTIES::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), DIALOG_PAD_PROPERTIES::TransferDataFromWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow(), DIALOG_LIB_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_SYMBOL_FIELDS_TABLE::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataToWindow(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_EDITOR_CONTROL::Undo(), SYMBOL_EDITOR_EDIT_TOOL::Undo(), GROUP_TOOL::Ungroup(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), HIGHLIGHT_MENU::update(), GROUP_CONTEXT_MENU::update(), PCB_PROPERTIES_PANEL::UpdateData(), DIALOG_DRC::updateDisplayedCounts(), SCH_EDIT_FRAME::UpdateHierarchyNavigator(), BOARD_INSPECTION_TOOL::UpdateLocalRatsnest(), EE_INSPECTION_TOOL::UpdateMessagePanel(), GERBVIEW_CONTROL::UpdateMessagePanel(), PL_EDITOR_CONTROL::UpdateMessagePanel(), PCB_CONTROL::UpdateMessagePanel(), PCB_EDIT_FRAME::UpdateViaSizeSelectBox(), PCB_PROPERTIES_PANEL::valueChanged(), BOARD_EDITOR_CONTROL::ViaSizeDec(), BOARD_EDITOR_CONTROL::ViaSizeInc(), BOARD_EDITOR_CONTROL::ZoneDuplicate(), and BOARD_EDITOR_CONTROL::ZoneMerge().

◆ GetToolHolder()

◆ GetView()

◆ GetViewControls()

KIGFX::VIEW_CONTROLS * TOOL_MANAGER::GetViewControls ( ) const
inline

◆ InitTools()

void TOOL_MANAGER::InitTools ( )

Initializes all registered tools.

If a tool fails during the initialization, it is deactivated and becomes unavailable for further use. Initialization should be done only once.

Definition at line 590 of file tool_manager.cpp.

591{
592 for( auto it = m_toolOrder.begin(); it != m_toolOrder.end(); /* iter inside */ )
593 {
594 TOOL_BASE* tool = *it;
595 wxASSERT( m_toolState.count( tool ) );
596 TOOL_STATE* state = m_toolState[tool];
597 setActiveState( state );
598 ++it; // keep the iterator valid if the element is going to be erased
599
600 if( !tool->Init() )
601 {
602 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER initialization of tool '%s' failed" ),
603 tool->GetName() );
604
605 // Unregister the tool
606 setActiveState( nullptr );
607 m_toolState.erase( tool );
608 m_toolNameIndex.erase( tool->GetName() );
609 m_toolIdIndex.erase( tool->GetId() );
610 m_toolTypes.erase( typeid( *tool ).name() );
611
612 delete state;
613 delete tool;
614 }
615 }
616
617 m_actionMgr->UpdateHotKeys( true );
618
620}
void UpdateHotKeys(bool aFullUpdate)
Optionally read the hotkey config files and then rebuilds the internal hotkey maps.
virtual bool Init()
Init() is called once upon a registration of the tool.
Definition: tool_base.h:90
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:134
@ RUN
Tool is invoked after being inactive.
Definition: tool_base.h:79
TOOL_ID GetId() const
Return the unique identifier of the tool.
Definition: tool_base.h:121
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
std::vector< TOOL_BASE * > m_toolOrder
Index of registered tools current states, associated by tools' objects.
Definition: tool_manager.h:538

References TOOL_BASE::GetId(), TOOL_BASE::GetName(), TOOL_BASE::Init(), kicadTraceToolStack, m_actionMgr, m_toolIdIndex, m_toolNameIndex, m_toolOrder, m_toolState, m_toolTypes, ResetTools(), TOOL_BASE::RUN, setActiveState(), and ACTION_MANAGER::UpdateHotKeys().

Referenced by PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), CVPCB_MAINFRAME::setupTools(), SCH_EDIT_FRAME::setupTools(), SYMBOL_EDIT_FRAME::setupTools(), SYMBOL_VIEWER_FRAME::setupTools(), GERBVIEW_FRAME::setupTools(), KICAD_MANAGER_FRAME::setupTools(), PL_EDITOR_FRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), and PCB_EDIT_FRAME::setupTools().

◆ InvokeTool() [1/2]

bool TOOL_MANAGER::InvokeTool ( const std::string &  aToolName)

Call a tool by sending a tool activation event to tool of given name.

Parameters
aToolNameis the name of the requested tool.
Returns
True if the requested tool was invoked successfully.

Definition at line 272 of file tool_manager.cpp.

273{
274 TOOL_BASE* tool = FindTool( aToolName );
275
276 if( tool && tool->GetType() == INTERACTIVE )
277 return invokeTool( tool );
278
279 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::InvokeTool - no tool with name %s" ),
280 aToolName );
281
282 return false; // there is no tool with the given name
283}
bool invokeTool(TOOL_BASE *aTool)
Invoke a tool by sending a proper event (in contrary to runTool, which makes the tool run for real).

References FindTool(), TOOL_BASE::GetType(), INTERACTIVE, invokeTool(), and kicadTraceToolStack.

◆ invokeTool()

bool TOOL_MANAGER::invokeTool ( TOOL_BASE aTool)
private

Invoke a tool by sending a proper event (in contrary to runTool, which makes the tool run for real).

Parameters
aToolis the tool to be invoked.

Definition at line 396 of file tool_manager.cpp.

397{
398 wxASSERT( aTool != nullptr );
399
400 TOOL_EVENT evt( TC_COMMAND, TA_ACTIVATE, aTool->GetName() );
401 evt.SetMousePosition( GetCursorPosition() );
402 processEvent( evt );
403
404 if( TOOL_STATE* active = GetCurrentToolState() )
405 setActiveState( active );
406
407 return true;
408}
VECTOR2D GetCursorPosition() const
@ TA_ACTIVATE
Definition: tool_event.h:110

References GetCurrentToolState(), GetCursorPosition(), TOOL_BASE::GetName(), processEvent(), setActiveState(), TOOL_EVENT::SetMousePosition(), TA_ACTIVATE, and TC_COMMAND.

Referenced by InvokeTool().

◆ InvokeTool() [2/2]

bool TOOL_MANAGER::InvokeTool ( TOOL_ID  aToolId)

Call a tool by sending a tool activation event to tool of given ID.

Parameters
aToolIdis the ID number of the requested tool.
Returns
True if the requested tool was invoked successfully.

Definition at line 258 of file tool_manager.cpp.

259{
260 TOOL_BASE* tool = FindTool( aToolId );
261
262 if( tool && tool->GetType() == INTERACTIVE )
263 return invokeTool( tool );
264
265 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::InvokeTool - no tool with ID %d" ),
266 aToolId );
267
268 return false; // there is no tool with the given id
269}

References FindTool(), TOOL_BASE::GetType(), INTERACTIVE, invokeTool(), and kicadTraceToolStack.

Referenced by TOOL_INTERACTIVE::Activate(), CVPCB_MAINFRAME::CVPCB_MAINFRAME(), EE_SELECTION_TOOL::Main(), PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), SYMBOL_EDIT_FRAME::setupTools(), SYMBOL_VIEWER_FRAME::setupTools(), GERBVIEW_FRAME::setupTools(), PL_EDITOR_FRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), and PCB_EDIT_FRAME::setupTools().

◆ isActive()

bool TOOL_MANAGER::isActive ( TOOL_BASE aTool) const
private

Return information about a tool activation status.

Parameters
aToolis the tool to be checked.
Returns
True if the tool is on the active tools stack, false otherwise.

Definition at line 1086 of file tool_manager.cpp.

1087{
1088 if( !isRegistered( aTool ) )
1089 return false;
1090
1091 // Just check if the tool is on the active tools stack
1092 return alg::contains( m_activeTools, aTool->GetId() );
1093}
bool isRegistered(TOOL_BASE *aTool) const
Return information about a tool registration status.
Definition: tool_manager.h:497
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99

References alg::contains(), TOOL_BASE::GetId(), isRegistered(), and m_activeTools.

Referenced by runTool(), and ShutdownTool().

◆ IsContextMenuActive()

bool TOOL_MANAGER::IsContextMenuActive ( ) const
inline

True while processing a context menu.

Definition at line 413 of file tool_manager.h.

414 {
415 return m_menuActive;
416 }

References m_menuActive.

Referenced by DIALOG_SHIM::DIALOG_SHIM(), and ROUTER_TOOL::InlineBreakTrack().

◆ isRegistered()

bool TOOL_MANAGER::isRegistered ( TOOL_BASE aTool) const
inlineprivate

Return information about a tool registration status.

Parameters
aToolis the tool to be checked.
Returns
true if the tool is in the registered tools list, false otherwise.

Definition at line 497 of file tool_manager.h.

498 {
499 return m_toolState.count( aTool ) > 0;
500 }

References m_toolState.

Referenced by isActive(), and runTool().

◆ IsToolActive()

bool TOOL_MANAGER::IsToolActive ( TOOL_ID  aId) const

Return true if a tool with given id is active (executing)

Definition at line 1201 of file tool_manager.cpp.

1202{
1203 auto it = m_toolIdIndex.find( aId );
1204 return !it->second->idle;
1205}

References m_toolIdIndex.

Referenced by TOOL_BASE::IsToolActive().

◆ MakeToolId()

TOOL_ID TOOL_MANAGER::MakeToolId ( const std::string &  aToolName)
static

Generates a unique ID from for a tool with given name.

Definition at line 1066 of file tool_manager.cpp.

1067{
1068 static int currentId;
1069
1070 return currentId++;
1071}

◆ PostEvent()

void TOOL_MANAGER::PostEvent ( const TOOL_EVENT aEvent)

Put an event to the event queue to be processed at the end of event processing cycle.

Parameters
aEventis the event to be put into the queue.

Definition at line 379 of file tool_manager.cpp.

380{
381 // Horrific hack, but it's a crash bug. Don't let inter-frame commands stack up
382 // waiting to be processed.
383 if( aEvent.IsSimulator() && m_eventQueue.size() > 0 && m_eventQueue.back().IsSimulator() )
384 m_eventQueue.pop_back();
385
386 m_eventQueue.push_back( aEvent );
387}
bool IsSimulator() const
Indicate if the event is from the simulator.
Definition: tool_event.cpp:248
std::list< TOOL_EVENT > m_eventQueue
Right click context menu position.
Definition: tool_manager.h:568

References TOOL_EVENT::IsSimulator(), and m_eventQueue.

Referenced by SCH_EDIT_FRAME::AddJunction(), SCH_MOVE_TOOL::AlignElements(), SCH_EDIT_TOOL::AutoplaceFields(), EDIT_TOOL::doMoveSelection(), SCH_EDIT_TOOL::editFieldText(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), GROUP_TOOL::Group(), SCH_MOVE_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_EDIT_TOOL::Main(), SCH_EDIT_TOOL::Mirror(), SYMBOL_EDITOR_EDIT_TOOL::Mirror(), BOARD_EDITOR_CONTROL::modifyLockSelected(), PCB_EDIT_FRAME::OnRemoveTeardropTool(), PCB_EDIT_FRAME::OnRunTeardropTool(), TOOLS_HOLDER::PopTool(), PrimeTool(), SCH_EDIT_TOOL::Properties(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), PCB_BASE_FRAME::rebuildConnectivity(), EDIT_TOOL::rebuildConnectivity(), ZONE_FILLER_TOOL::rebuildConnectivity(), GROUP_TOOL::RemoveFromGroup(), PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList(), PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList(), SCH_EDIT_TOOL::Rotate(), SYMBOL_EDITOR_EDIT_TOOL::Rotate(), RunAction(), PCB_BASE_EDIT_FRAME::ShowBitmapPropertiesDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_EDIT_TOOL::Swap(), DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), GROUP_TOOL::Ungroup(), and PCB_BASE_EDIT_FRAME::unitsChangeRefresh().

◆ PrimeTool()

void TOOL_MANAGER::PrimeTool ( const VECTOR2D aPosition)

"Prime" a tool by sending a cursor left-click event with the mouse position set to the passed in position.

Parameters
aPositionis the mouse position to use in the event Return the hot key associated with a given action or 0 if there is none.
aActionis the queried action.

Definition at line 359 of file tool_manager.cpp.

360{
361 int modifiers = 0;
362
363 /*
364 * Don't include any modifiers. They're part of the hotkey, not part of the resulting
365 * click.
366 *
367 * modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
368 * modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
369 * modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
370 */
371
372 TOOL_EVENT evt( TC_MOUSE, TA_PRIME, BUT_LEFT | modifiers );
373 evt.SetMousePosition( aPosition );
374
375 PostEvent( evt );
376}
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
@ TA_PRIME
Definition: tool_event.h:119
@ TC_MOUSE
Definition: tool_event.h:50
@ BUT_LEFT
Definition: tool_event.h:127

References BUT_LEFT, PostEvent(), TOOL_EVENT::SetMousePosition(), TA_PRIME, and TC_MOUSE.

Referenced by DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), SCH_DRAWING_TOOLS::DrawShape(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), DRAWING_TOOL::drawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), DRAWING_TOOL::InteractivePlaceWithPreview(), ROUTER_TOOL::MainLoop(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), DRAWING_TOOL::PlaceText(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace().

◆ ProcessEvent()

bool TOOL_MANAGER::ProcessEvent ( const TOOL_EVENT aEvent)

Propagate an event to tools that requested events of matching type(s).

Parameters
aEventis the event to be processed.
Returns
true if the event is a managed hotkey

Definition at line 971 of file tool_manager.cpp.

972{
973 // Once the tool manager is shutting down, don't start
974 // activating more tools
975 if( m_shuttingDown )
976 return true;
977
978 bool handled = processEvent( aEvent );
979
980 TOOL_STATE* activeTool = GetCurrentToolState();
981
982 if( activeTool )
983 setActiveState( activeTool );
984
985 if( m_view && m_view->IsDirty() )
986 {
987 if( GetToolHolder() )
989
990#if defined( __WXMAC__ )
991 wxTheApp->ProcessPendingEvents(); // required for updating brightening behind a popup menu
992#endif
993 }
994
995 UpdateUI( aEvent );
996
997 return handled;
998}
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
Definition: view.h:589
virtual void RefreshCanvas()
Definition: tools_holder.h:165
void UpdateUI(const TOOL_EVENT &aEvent)
Update the status bar and synchronizes toolbars.
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:296

References GetCurrentToolState(), GetToolHolder(), KIGFX::VIEW::IsDirty(), m_shuttingDown, m_view, processEvent(), TOOLS_HOLDER::RefreshCanvas(), setActiveState(), and UpdateUI().

Referenced by SELECTION_TOOL::AddItemsToSel(), SELECTION_TOOL::AddItemToSel(), BOARD_EDITOR_CONTROL::AssignNetclass(), EDIT_TOOL::ChangeTrackWidth(), GERBVIEW_SELECTION_TOOL::clearSelection(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), PCB_SELECTION_TOOL::ClearSelection(), PANEL_KICAD_LAUNCHER::CreateLaunchers(), COMMON_TOOLS::CursorControl(), TOOL_DISPATCHER::DispatchWxEvent(), PCB_TOOL_BASE::doInteractiveItemPlacement(), PCB_SELECTION_TOOL::doSyncSelection(), PCB_SELECTION_TOOL::EnterGroup(), PCB_SELECTION_TOOL::ExitGroup(), PCB_SELECTION_TOOL::expandConnection(), PCB_SELECTION_TOOL::filterSelection(), PCB_SELECTION_TOOL::FindItem(), EDIT_TOOL::Flip(), TOOL_DISPATCHER::handleMouseButton(), EE_SELECTION_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PCB_SELECTION_TOOL::Main(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), SELECTION_TOOL::onDisambiguationExpire(), ACTION_MENU::OnMenuEvent(), ACTION_TOOLBAR::onPaletteEvent(), ACTION_TOOLBAR::onToolEvent(), PAD_TOOL::pastePadProperties(), PCB_CONTROL::placeBoardItems(), EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), PAD_TOOL::pushPadSettings(), EE_SELECTION_TOOL::RebuildSelection(), SCH_EDITOR_CONTROL::Redo(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), SELECTION_TOOL::RemoveItemFromSel(), SELECTION_TOOL::RemoveItemsFromSel(), EE_SELECTION_TOOL::RequestSelection(), PCB_BASE_EDIT_FRAME::RestoreCopyFromRedoList(), PCB_BASE_EDIT_FRAME::RestoreCopyFromUndoList(), EDIT_TOOL::Rotate(), EE_SELECTION_TOOL::SelectAll(), PCB_SELECTION_TOOL::SelectAll(), EE_SELECTION_TOOL::SelectConnection(), COMMON_TOOLS::SelectionTool(), GERBVIEW_SELECTION_TOOL::SelectItem(), GERBVIEW_SELECTION_TOOL::SelectItems(), EE_SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectNet(), GERBVIEW_SELECTION_TOOL::selectPoint(), PL_SELECTION_TOOL::SelectPoint(), PCB_SELECTION_TOOL::selectPoint(), EE_SELECTION_TOOL::selectPoint(), PCB_SELECTION_TOOL::selectSameSheet(), PCB_SELECTION_TOOL::selectSheetContents(), PCB_EDIT_FRAME::ShowBoardSetupDialog(), EE_SELECTION_TOOL::SyncSelection(), SCH_EDITOR_CONTROL::Undo(), GERBVIEW_SELECTION_TOOL::UnselectItem(), and GERBVIEW_SELECTION_TOOL::UnselectItems().

◆ processEvent()

bool TOOL_MANAGER::processEvent ( const TOOL_EVENT aEvent)
private

Main function for event processing.

Returns
true if a hotkey was handled.

Definition at line 1142 of file tool_manager.cpp.

1143{
1144 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::processEvent - %s" ), aEvent.Format() );
1145
1146 // First try to dispatch the action associated with the event if it is a key press event
1147 bool handled = DispatchHotKey( aEvent );
1148
1149 if( !handled )
1150 {
1151 TOOL_EVENT mod_event( aEvent );
1152
1153 // Only immediate actions get the position. Otherwise clear for tool activation
1154 if( GetToolHolder() && !GetToolHolder()->GetDoImmediateActions() )
1155 {
1156 // An tool-selection-event has no position
1157 if( !mod_event.getCommandStr().empty()
1158 && mod_event.getCommandStr() != GetToolHolder()->CurrentToolName()
1159 && !mod_event.ForceImmediate() )
1160 {
1161 mod_event.SetHasPosition( false );
1162 }
1163 }
1164
1165 // If the event is not handled through a hotkey activation, pass it to the currently
1166 // running tool loops
1167 handled |= dispatchInternal( mod_event );
1168 handled |= dispatchActivation( mod_event );
1169
1170 // Open the context menu if requested by a tool
1171 DispatchContextMenu( mod_event );
1172
1173 // Dispatch any remaining events in the event queue
1174 while( !m_eventQueue.empty() )
1175 {
1176 TOOL_EVENT event = m_eventQueue.front();
1177 m_eventQueue.pop_front();
1178 processEvent( event );
1179 }
1180 }
1181
1182 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::processEvent - %s handle event: %s" ),
1183 ( handled ? "Did" : "Did not" ), aEvent.Format() );
1184
1185 return handled;
1186}
bool dispatchActivation(const TOOL_EVENT &aEvent)
Check if it is a valid activation event and invokes a proper tool.
bool DispatchHotKey(const TOOL_EVENT &aEvent)
Handle specific events, that are intended for TOOL_MANAGER rather than tools.
void DispatchContextMenu(const TOOL_EVENT &aEvent)
Handle context menu related events.

References dispatchActivation(), DispatchContextMenu(), DispatchHotKey(), dispatchInternal(), TOOL_EVENT::ForceImmediate(), TOOL_EVENT::Format(), TOOL_EVENT::getCommandStr(), GetToolHolder(), kicadTraceToolStack, m_eventQueue, processEvent(), and TOOL_EVENT::SetHasPosition().

Referenced by CancelTool(), DeactivateTool(), invokeTool(), ProcessEvent(), processEvent(), and RunAction().

◆ RegisterTool()

void TOOL_MANAGER::RegisterTool ( TOOL_BASE aTool)

Add a tool to the manager set and sets it up.

Called once for each tool during application initialization.

Parameters
aTooltool to be added. Ownership is transferred.

Definition at line 236 of file tool_manager.cpp.

237{
238 wxASSERT_MSG( m_toolNameIndex.find( aTool->GetName() ) == m_toolNameIndex.end(),
239 wxT( "Adding two tools with the same name may result in unexpected behavior.") );
240 wxASSERT_MSG( m_toolIdIndex.find( aTool->GetId() ) == m_toolIdIndex.end(),
241 wxT( "Adding two tools with the same ID may result in unexpected behavior.") );
242 wxASSERT_MSG( m_toolTypes.find( typeid( *aTool ).name() ) == m_toolTypes.end(),
243 wxT( "Adding two tools of the same type may result in unexpected behavior.") );
244
245 m_toolOrder.push_back( aTool );
246
247 TOOL_STATE* st = new TOOL_STATE( aTool );
248
249 m_toolState[aTool] = st;
250 m_toolNameIndex[aTool->GetName()] = st;
251 m_toolIdIndex[aTool->GetId()] = st;
252 m_toolTypes[typeid( *aTool ).name()] = st->theTool;
253
254 aTool->attachManager( this );
255}
void attachManager(TOOL_MANAGER *aManager)
Set the TOOL_MANAGER the tool will belong to.
Definition: tool_base.cpp:60

References TOOL_BASE::attachManager(), TOOL_BASE::GetId(), TOOL_BASE::GetName(), m_toolIdIndex, m_toolNameIndex, m_toolOrder, m_toolState, m_toolTypes, and TOOL_MANAGER::TOOL_STATE::theTool.

Referenced by PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), CVPCB_MAINFRAME::setupTools(), SCH_EDIT_FRAME::setupTools(), SYMBOL_EDIT_FRAME::setupTools(), SYMBOL_VIEWER_FRAME::setupTools(), GERBVIEW_FRAME::setupTools(), KICAD_MANAGER_FRAME::setupTools(), PL_EDITOR_FRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), and PCB_EDIT_FRAME::setupTools().

◆ ResetTools()

void TOOL_MANAGER::ResetTools ( TOOL_BASE::RESET_REASON  aReason)

Reset all tools (i.e.

calls their Reset() method).

Definition at line 573 of file tool_manager.cpp.

574{
575 if( aReason != TOOL_BASE::REDRAW )
577
578 for( auto& state : m_toolState )
579 {
580 TOOL_BASE* tool = state.first;
581 setActiveState( state.second );
582 tool->Reset( aReason );
583
584 if( tool->GetType() == INTERACTIVE )
585 static_cast<TOOL_INTERACTIVE*>( tool )->resetTransitions();
586 }
587}
virtual void Reset(RESET_REASON aReason)=0
Bring the tool to a known, initial state.
@ REDRAW
Full drawing refresh.
Definition: tool_base.h:82
void DeactivateTool()
Deactivate the currently active tool.

References DeactivateTool(), TOOL_BASE::GetType(), INTERACTIVE, m_toolState, TOOL_BASE::REDRAW, TOOL_BASE::Reset(), and setActiveState().

Referenced by GERBVIEW_FRAME::ActivateGalCanvas(), PCB_BASE_FRAME::ActivateGalCanvas(), GERBVIEW_FRAME::Clear_DrawLayers(), FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList(), GERBVIEW_FRAME::Erase_Current_DrawLayer(), InitTools(), SYMBOL_EDITOR_CONTROL::OnDeMorgan(), SYMBOL_EDIT_FRAME::OnSelectUnit(), PCB_EDIT_FRAME::RebuildAndRefresh(), FOOTPRINT_WIZARD_FRAME::ReloadFootprint(), PCB_BASE_EDIT_FRAME::SetBoard(), SYMBOL_EDIT_FRAME::SetCurSymbol(), PCB_EDIT_FRAME::ShowBoardSetupDialog(), DIALOG_GRID_SETTINGS::TransferDataFromWindow(), DISPLAY_FOOTPRINTS_FRAME::updateView(), FOOTPRINT_EDIT_FRAME::UpdateView(), FOOTPRINT_VIEWER_FRAME::updateView(), and FOOTPRINT_WIZARD_FRAME::updateView().

◆ RunAction() [1/6]

bool TOOL_MANAGER::RunAction ( const std::string &  aActionName,
bool  aNow,
void *  aParam 
)

Definition at line 286 of file tool_manager.cpp.

287{
288 TOOL_ACTION* action = m_actionMgr->FindAction( aActionName );
289
290 if( !action )
291 {
292 wxASSERT_MSG( false, wxString::Format( "Could not find action %s.", aActionName ) );
293 return false;
294 }
295
296 RunAction( *action, aNow, aParam );
297
298 return false;
299}
TOOL_ACTION * FindAction(const std::string &aActionName) const
Find an action with a given name (if there is one available).
Represent a single user action.
Definition: tool_action.h:68
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References ACTION_MANAGER::FindAction(), Format(), m_actionMgr, and RunAction().

◆ RunAction() [2/6]

bool TOOL_MANAGER::RunAction ( const std::string &  aActionName,
bool  aNow = false 
)
inline

Definition at line 149 of file tool_manager.h.

150 {
151 return RunAction( aActionName, aNow, (void*) NULL );
152 }

References RunAction().

◆ RunAction() [3/6]

template<typename T >
bool TOOL_MANAGER::RunAction ( const std::string &  aActionName,
bool  aNow = false,
aParam = NULL 
)
inline

Run the specified action.

The common format for action names is "application.ToolName.Action".

Parameters
aActionNameis the name of action to be invoked.
aNowdecides if the action has to be run immediately or after the current coroutine is preemptied.
aParamis an optional parameter that might be used by the invoked action. Its meaning depends on the action.
Returns
False if the action was not found.

Definition at line 142 of file tool_manager.h.

143 {
144 return RunAction( aActionName, aNow, reinterpret_cast<void*>( aParam ) );
145 }

References RunAction().

Referenced by PROJECT_TREE_ITEM::Activate(), FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), SYMBOL_EDITOR_CONTROL::AddSymbolToSchematic(), APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), BOARD_EDITOR_CONTROL::AssignNetclass(), CVPCB_ASSOCIATION_TOOL::Associate(), SCH_EDIT_TOOL::AutoplaceFields(), SCH_NAVIGATE_TOOL::Back(), SCH_EDIT_TOOL::BreakWire(), SCH_EDIT_FRAME::canCloseWindow(), ROUTER_TOOL::CanInlineDrag(), SCH_EDITOR_CONTROL::ChangeLineMode(), SCH_NAVIGATE_TOOL::changeSheet(), SCH_EDIT_TOOL::ChangeTextType(), EDIT_TOOL::ChangeTrackWidth(), SCH_EDIT_TOOL::CleanupSheetPins(), GERBVIEW_CONTROL::ClearAllLayers(), PCB_SELECTION_TOOL::ClearSelection(), ZONE_CREATE_HELPER::commitZone(), EDA_DRAW_FRAME::CommonSettingsChanged(), SCH_EDIT_TOOL::ConvertDeMorgan(), SCH_EDIT_FRAME::ConvertPart(), MICROWAVE_TOOL::createInductorBetween(), SYMBOL_EDIT_FRAME::CreateNewSymbol(), COMMON_TOOLS::CursorControl(), SCH_EDITOR_CONTROL::Cut(), SYMBOL_VIEWER_FRAME::DClickOnSymbolList(), DIALOG_FOOTPRINT_CHECKER::deleteAllMarkers(), DIALOG_ERC::deleteAllMarkers(), DIALOG_DRC::deleteAllMarkers(), SCH_EDIT_TOOL::DeleteItemCursor(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), EDIT_TOOL::DeleteItems(), DIALOG_MIGRATE_BUSES::DIALOG_MIGRATE_BUSES(), SCH_EDIT_FRAME::DisplayCurrentSheet(), DIALOG_CLEANUP_GRAPHICS::doCleanup(), DIALOG_CLEANUP_TRACKS_AND_VIAS::doCleanup(), SIM_PLOT_FRAME::doCloseWindow(), SCH_EDITOR_CONTROL::doCopy(), SCH_EDIT_TOOL::DoDelete(), SYMBOL_EDITOR_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), DIALOG_GLOBAL_DELETION::DoGlobalDeletions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), EDA_BASE_FRAME::DoWithAcceptedFiles(), GERBVIEW_FRAME::DoWithAcceptedFiles(), KICAD_MANAGER_FRAME::DoWithAcceptedFiles(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawRectangle(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), SCH_DRAWING_TOOLS::DrawShape(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), DRAWING_TOOL::drawShape(), SCH_DRAWING_TOOLS::DrawSheet(), BOARD_EDITOR_CONTROL::DrillOrigin(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::EditField(), BOARD_EDITOR_CONTROL::EditFpInFpEditor(), PAD_TOOL::EditPad(), SYMBOL_EDITOR_EDIT_TOOL::editSymbolProperties(), SCH_EDITOR_CONTROL::EditWithSymbolEditor(), SYMBOL_EDIT_FRAME::emptyScreen(), PAD_TOOL::EnumeratePads(), TRACK_WIDTH_MENU::eventHandler(), DIFF_PAIR_MENU::eventHandler(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), PAD_TOOL::explodePad(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), EDIT_TOOL::Flip(), SCH_NAVIGATE_TOOL::Forward(), GERBVIEW_FRAME::GERBVIEW_FRAME(), EDIT_TOOL::GetAndPlace(), DRAWING_TOOL::getSourceZoneForAction(), SYMBOL_EDIT_FRAME::GetSymbolFromRedoList(), SYMBOL_EDIT_FRAME::GetSymbolFromUndoList(), PCB_SELECTION_TOOL::grabUnconnected(), PCB_CONTROL::GridSetOrigin(), BOARD_INSPECTION_TOOL::HighlightItem(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PL_EDIT_TOOL::ImportDrawingSheetContent(), SCH_EDIT_FRAME::importFile(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), SCH_EDIT_FRAME::initScreenZoom(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), DRAWING_TOOL::InteractivePlaceWithPreview(), ARRAY_CREATOR::Invoke(), EDIT_TOOL::invokeInlineRouter(), SCH_EDIT_FRAME::KiwayMailIn(), PCB_EDIT_FRAME::KiwayMailIn(), SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux(), SYMBOL_EDIT_FRAME::LoadSymbolFromCurrentLib(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), CVPCB_CONTROL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), SCH_MOVE_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), PL_EDIT_TOOL::Main(), PL_SELECTION_TOOL::Main(), PCB_SELECTION_TOOL::Main(), LENGTH_TUNER_TOOL::MainLoop(), ROUTER_TOOL::MainLoop(), SCH_EDIT_TOOL::Mirror(), SYMBOL_EDITOR_EDIT_TOOL::Mirror(), EDIT_TOOL::Mirror(), BOARD_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), SCH_EDITOR_CONTROL::NextLineMode(), DIALOG_GROUP_PROPERTIES::OnAddMember(), DIALOG_DRC::OnDeleteOneClick(), DIALOG_ERC::OnDeleteOneClick(), DIALOG_FOOTPRINT_CHECKER::OnDeleteOneClick(), SYMBOL_EDITOR_CONTROL::OnDeMorgan(), DIALOG_DRC::OnDRCItemSelected(), FOOTPRINT_EDIT_FRAME::OnEditItemRequest(), PCB_EDIT_FRAME::OnEditItemRequest(), DIALOG_ERC::OnERCItemSelected(), DIALOG_CONSTRAINTS_REPORTER::OnErrorLinkClicked(), SCH_EDIT_FRAME::OnFindDialogClose(), ZONE_CREATE_HELPER::OnFirstPoint(), KICAD_MANAGER_FRAME::OnIdle(), FOOTPRINTS_LISTBOX::OnLeftDClick(), ACTION_MENU::OnMenuEvent(), APPEARANCE_CONTROLS::onNetclassContextMenu(), APPEARANCE_CONTROLS::onNetContextMenu(), PCB_EDIT_FRAME::OnNetlistChanged(), PL_EDITOR_FRAME::OnNewDrawingSheet(), KICAD_MANAGER_FRAME::OnOpenFileInTextEditor(), GERBER_LAYER_WIDGET::onPopupSelection(), SIM_PLOT_FRAME::onProbe(), EDA_DRAW_FRAME::OnSelectGrid(), DIALOG_POSITION_RELATIVE::OnSelectItemClick(), HIERARCHY_PANE::onSelectSheetPath(), SYMBOL_EDIT_FRAME::OnSelectUnit(), EDA_DRAW_FRAME::OnSelectZoom(), SCH_EDIT_FRAME::onSize(), PCB_EDIT_FRAME::onSize(), SYMBOL_TREE_PANE::onSymbolSelected(), SIM_PLOT_FRAME::onTune(), SCH_EDIT_FRAME::OpenProjectFiles(), PCB_EDIT_FRAME::OpenProjectFiles(), SCH_EDITOR_CONTROL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), DIALOG_UPDATE_PCB::PerformUpdate(), ZONE_CREATE_HELPER::performZoneCutout(), GROUP_TOOL::PickNewMember(), EDIT_TOOL::pickReferencePoint(), SYMBOL_EDITOR_EDIT_TOOL::PinTable(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), DRAWING_TOOL::PlaceText(), GERBVIEW_CONTROL::Print(), PCB_CONTROL::Print(), SCH_EDIT_TOOL::Properties(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), SCH_EDIT_FRAME::PutDataInPreviousState(), FOOTPRINT_WIZARD_FRAME::PythonPluginsReload(), PAD_TOOL::RecombinePad(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), PCB_POINT_EDITOR::removeCorner(), GROUP_TOOL::RemoveFromGroup(), SCH_EDIT_TOOL::RepeatDrawItem(), SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem(), PCB_SELECTION_TOOL::RequestSelection(), PAD_TOOL::Reset(), SCH_EDITOR_CONTROL::Revert(), PL_EDITOR_FRAME::RollbackFromUndo(), SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo(), SCH_EDIT_TOOL::Rotate(), SYMBOL_EDITOR_EDIT_TOOL::Rotate(), EDIT_TOOL::Rotate(), ROUTER_TOOL::RouteSelected(), RunAction(), ACTION_MANAGER::RunHotKey(), FOOTPRINT_EDIT_FRAME::SaveFootprint(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), SYMBOL_EDIT_FRAME::saveLibrary(), DIALOG_FIND::search(), FOOTPRINT_SEARCH_HANDLER::SelectItems(), ZONE_SEARCH_HANDLER::SelectItems(), TEXT_SEARCH_HANDLER::SelectItems(), EE_SELECTION_TOOL::selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand(), NL_SCHEMATIC_PLUGIN_IMPL::SetActiveCommand(), NL_PCBNEW_PLUGIN_IMPL::SetActiveCommand(), GERBVIEW_FRAME::SetActiveLayer(), FOOTPRINT_EDIT_FRAME::SetActiveLayer(), PCB_EDIT_FRAME::SetActiveLayer(), DRAWING_TOOL::SetAnchor(), SYMBOL_EDIT_FRAME::SetCurSymbol(), SCH_EDIT_FRAME::SetScreen(), CVPCB_MAINFRAME::setupEventHandlers(), SCH_EDIT_FRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), EDA_DRAW_FRAME::setupUnits(), DRC_TOOL::ShowDRCDialog(), APPEARANCE_CONTROLS::showNetclass(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_EDIT_TOOL::Swap(), SYMBOL_VIEWER_FRAME::SYMBOL_VIEWER_FRAME(), PCB_EDIT_FRAME::Tracks_and_Vias_Size_Event(), BOARD_EDITOR_CONTROL::TrackWidthDec(), BOARD_EDITOR_CONTROL::TrackWidthInc(), DIALOG_GRID_SETTINGS::TransferDataFromWindow(), DIALOG_GROUP_PROPERTIES::TransferDataFromWindow(), SCH_DRAWING_TOOLS::TwoClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), GROUP_TOOL::Ungroup(), EDA_DRAW_FRAME::unitsChangeRefresh(), PCB_SELECTION_TOOL::unrouteSelected(), CVPCB_MAINFRAME::updateFootprintViewerOnIdle(), NET_GRID_TABLE::updateNetVisibility(), SYMBOL_VIEWER_FRAME::updatePreviewSymbol(), DISPLAY_FOOTPRINTS_FRAME::updateView(), FOOTPRINT_VIEWER_FRAME::updateView(), FOOTPRINT_WIZARD_FRAME::updateView(), BOARD_EDITOR_CONTROL::ViaSizeDec(), BOARD_EDITOR_CONTROL::ViaSizeInc(), BOARD_EDITOR_CONTROL::ZoneMerge(), EDA_DRAW_FRAME::Zoom_Automatique(), DIALOG_IMPORT_NETLIST::~DIALOG_IMPORT_NETLIST(), and DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB().

◆ RunAction() [4/6]

bool TOOL_MANAGER::RunAction ( const TOOL_ACTION aAction,
bool  aNow,
void *  aParam 
)

Definition at line 320 of file tool_manager.cpp.

321{
322 if( m_shuttingDown )
323 return true;
324
325 bool handled = false;
326 TOOL_EVENT event = aAction.MakeEvent();
327
328 if( event.Category() == TC_COMMAND )
330
331 // Allow to override the action parameter
332 if( aParam )
333 event.SetParameter( aParam );
334
335 if( aNow )
336 {
337 TOOL_STATE* current = m_activeState;
338 handled = processEvent( event );
339 setActiveState( current );
340 UpdateUI( event );
341 }
342 else
343 {
344 PostEvent( event );
345 }
346
347 return handled;
348}
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.cpp:72
void SetMousePosition(const VECTOR2D &aP)
Definition: tool_event.h:470

References GetCursorPosition(), m_activeState, m_shuttingDown, TOOL_ACTION::MakeEvent(), PostEvent(), processEvent(), setActiveState(), TOOL_EVENT::SetMousePosition(), TC_COMMAND, and UpdateUI().

◆ RunAction() [5/6]

bool TOOL_MANAGER::RunAction ( const TOOL_ACTION aAction,
bool  aNow = false 
)
inline

Definition at line 175 of file tool_manager.h.

176 {
177 return RunAction( aAction, aNow, (void*) NULL );
178 }

References RunAction().

◆ RunAction() [6/6]

template<typename T >
bool TOOL_MANAGER::RunAction ( const TOOL_ACTION aAction,
bool  aNow = false,
aParam = NULL 
)
inline

Run the specified action.

This function will only return if the action has been handled when the action is run immediately (aNow = true), otherwise it will always return false.

Parameters
aActionis the action to be invoked.
aNowdecides if the action has to be run immediately or after the current coroutine is preemptied.
aParamis an optional parameter that might be used by the invoked action. Its meaning depends on the action.
Returns
True if the action was handled immediately

Definition at line 168 of file tool_manager.h.

169 {
170 return RunAction( aAction, aNow, reinterpret_cast<void*>( aParam ) );
171 }

References RunAction().

◆ RunMainStack()

void TOOL_MANAGER::RunMainStack ( TOOL_BASE aTool,
std::function< void()>  aFunc 
)

Definition at line 654 of file tool_manager.cpp.

655{
656 TOOL_STATE* st = m_toolState[aTool];
657 setActiveState( st );
658 st->cofunc->RunMainStack( std::move( aFunc ) );
659}

References TOOL_MANAGER::TOOL_STATE::cofunc, m_toolState, COROUTINE< ReturnType, ArgType >::RunMainStack(), and setActiveState().

Referenced by TOOL_INTERACTIVE::RunMainStack().

◆ runTool()

bool TOOL_MANAGER::runTool ( TOOL_BASE aTool)
private

Make a tool active, so it can receive events and react to them.

The activated tool is pushed on the active tools stack, so the last activated tool receives events first.

Parameters
aToolis the tool to be run.

Definition at line 411 of file tool_manager.cpp.

412{
413 wxASSERT( aTool != nullptr );
414
415 if( !isRegistered( aTool ) )
416 {
417 wxASSERT_MSG( false, wxT( "You cannot run unregistered tools" ) );
418 return false;
419 }
420
421 TOOL_ID id = aTool->GetId();
422
423 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::runTool - running tool %s" ),
424 aTool->GetName() );
425
426 if( aTool->GetType() == INTERACTIVE )
427 static_cast<TOOL_INTERACTIVE*>( aTool )->resetTransitions();
428
429 // If the tool is already active, bring it to the top of the active tools stack
430 if( isActive( aTool ) && m_activeTools.size() > 1 )
431 {
432 auto it = std::find( m_activeTools.begin(), m_activeTools.end(), id );
433
434 if( it != m_activeTools.end() )
435 {
436 if( it != m_activeTools.begin() )
437 {
438 m_activeTools.erase( it );
439 m_activeTools.push_front( id );
440 }
441
442 return false;
443 }
444 }
445
448
449 // Add the tool on the front of the processing queue (it gets events first)
450 m_activeTools.push_front( id );
451
452 return true;
453}
bool isActive(TOOL_BASE *aTool) const
Return information about a tool activation status.

References TOOL_BASE::GetId(), TOOL_BASE::GetName(), TOOL_BASE::GetType(), INTERACTIVE, isActive(), isRegistered(), kicadTraceToolStack, m_activeTools, m_toolIdIndex, TOOL_BASE::Reset(), TOOL_BASE::RUN, and setActiveState().

Referenced by dispatchActivation().

◆ SaveClipboard()

bool TOOL_MANAGER::SaveClipboard ( const std::string &  aTextUTF8)

Store information to the system clipboard.

Parameters
aTextis the information to be stored, expected UTF8 encoding. The text will be stored as Unicode string (not stored as UTF8 string).
Returns
False if error occurred.

Definition at line 1011 of file tool_manager.cpp.

1012{
1013 wxLogNull doNotLog; // disable logging of failed clipboard actions
1014
1015 if( wxTheClipboard->Open() )
1016 {
1017 // Store the UTF8 string as Unicode string in clipboard:
1018 wxTheClipboard->SetData( new wxTextDataObject( wxString( aTextUTF8.c_str(),
1019 wxConvUTF8 ) ) );
1020
1021 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
1022 wxTheClipboard->Close();
1023
1024 return true;
1025 }
1026
1027 return false;
1028}

Referenced by SYMBOL_EDITOR_EDIT_TOOL::Copy(), PL_EDIT_TOOL::Copy(), and SCH_EDITOR_CONTROL::doCopy().

◆ saveViewControls()

void TOOL_MANAGER::saveViewControls ( TOOL_STATE aState)
private

Save the #VIEW_CONTROLS settings to the tool state object.

If #VIEW_CONTROLS settings are affected by TOOL_MANAGER, the original settings are saved.

Definition at line 1096 of file tool_manager.cpp.

1097{
1098 aState->vcSettings = m_viewControls->GetSettings();
1099
1100 if( m_menuActive )
1101 {
1102 // Context menu is active, so the cursor settings are overridden (see DispatchContextMenu())
1103 auto it = m_cursorSettings.find( aState->theTool->GetId() );
1104
1105 if( it != m_cursorSettings.end() )
1106 {
1108
1109 // Tool has overridden the cursor position, so store the new settings
1111 {
1112 if( !curr.m_forceCursorPosition )
1113 it->second = std::nullopt;
1114 else
1115 it->second = curr.m_forcedPosition;
1116 }
1117 else
1118 {
1119 std::optional<VECTOR2D> cursor = it->second;
1120
1121 if( cursor )
1122 {
1123 aState->vcSettings.m_forceCursorPosition = true;
1124 aState->vcSettings.m_forcedPosition = *cursor;
1125 }
1126 else
1127 {
1128 aState->vcSettings.m_forceCursorPosition = false;
1129 }
1130 }
1131 }
1132 }
1133}

References cursor, TOOL_BASE::GetId(), KIGFX::VIEW_CONTROLS::GetSettings(), m_cursorSettings, KIGFX::VC_SETTINGS::m_forceCursorPosition, KIGFX::VC_SETTINGS::m_forcedPosition, m_menuActive, m_menuCursor, m_viewControls, TOOL_MANAGER::TOOL_STATE::theTool, and TOOL_MANAGER::TOOL_STATE::vcSettings.

Referenced by setActiveState().

◆ ScheduleContextMenu()

void TOOL_MANAGER::ScheduleContextMenu ( TOOL_BASE aTool,
ACTION_MENU aMenu,
CONTEXT_MENU_TRIGGER  aTrigger 
)

Set behavior of the tool's context popup menu.

Parameters
aToolis the parent tool.
aMenuis the menu structure, defined by the tool.
aTriggerdetermines when the menu is activated: CMENU_NOW: opens the menu right now CMENU_BUTTON: opens the menu when RMB is pressed CMENU_OFF: menu is disabled. May be called from a coroutine context.

Definition at line 1001 of file tool_manager.cpp.

1003{
1004 TOOL_STATE* st = m_toolState[aTool];
1005
1006 st->contextMenu = aMenu;
1007 st->contextMenuTrigger = aTrigger;
1008}

References TOOL_MANAGER::TOOL_STATE::contextMenu, TOOL_MANAGER::TOOL_STATE::contextMenuTrigger, and m_toolState.

Referenced by TOOL_INTERACTIVE::SetContextMenu().

◆ ScheduleNextState()

void TOOL_MANAGER::ScheduleNextState ( TOOL_BASE aTool,
TOOL_STATE_FUNC aHandler,
const TOOL_EVENT_LIST aConditions 
)

Define a state transition.

The events that cause a given handler method in the tool to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context.

Definition at line 639 of file tool_manager.cpp.

641{
642 TOOL_STATE* st = m_toolState[aTool];
643
644 st->transitions.emplace_back( TRANSITION( aConditions, aHandler ) );
645}

References m_toolState, and TOOL_MANAGER::TOOL_STATE::transitions.

Referenced by TOOL_INTERACTIVE::goInternal().

◆ ScheduleWait()

TOOL_EVENT * TOOL_MANAGER::ScheduleWait ( TOOL_BASE aTool,
const TOOL_EVENT_LIST aConditions 
)

Pause execution of a given tool until one or more events matching aConditions arrives.

The pause/resume operation is done through COROUTINE object. Called only from coroutines.

Definition at line 662 of file tool_manager.cpp.

663{
664 TOOL_STATE* st = m_toolState[aTool];
665
666 wxASSERT( !st->pendingWait ); // everything collapses on two KiYield() in a row
667
668 // indicate to the manager that we are going to sleep and we shall be
669 // woken up when an event matching aConditions arrive
670 st->pendingWait = true;
671 st->waitEvents = aConditions;
672
673 // switch context back to event dispatcher loop
674 st->cofunc->KiYield();
675
676 // If the tool should shutdown, it gets a null event to break the loop
677 if( st->shutdown )
678 return nullptr;
679 else
680 return &st->wakeupEvent;
681}

References TOOL_MANAGER::TOOL_STATE::cofunc, COROUTINE< ReturnType, ArgType >::KiYield(), m_toolState, TOOL_MANAGER::TOOL_STATE::pendingWait, TOOL_MANAGER::TOOL_STATE::shutdown, TOOL_MANAGER::TOOL_STATE::waitEvents, and TOOL_MANAGER::TOOL_STATE::wakeupEvent.

Referenced by TOOL_INTERACTIVE::Wait().

◆ setActiveState()

void TOOL_MANAGER::setActiveState ( TOOL_STATE aState)
private

Save the previous active state and sets a new one.

Parameters
aStateis the new active state. Might be null to indicate there is no new active state. List of tools in the order they were registered

Definition at line 1189 of file tool_manager.cpp.

1190{
1193
1194 m_activeState = aState;
1195
1197 applyViewControls( aState );
1198}
void applyViewControls(const TOOL_STATE *aState)
Apply #VIEW_CONTROLS settings stored in a #TOOL_STATE object.
void saveViewControls(TOOL_STATE *aState)
Save the #VIEW_CONTROLS settings to the tool state object.

References applyViewControls(), m_activeState, m_viewControls, and saveViewControls().

Referenced by dispatchInternal(), finishTool(), InitTools(), invokeTool(), ProcessEvent(), ResetTools(), RunAction(), RunMainStack(), runTool(), and ShutdownTool().

◆ SetEnvironment()

◆ ShutdownAllTools()

void TOOL_MANAGER::ShutdownAllTools ( )

Shutdown all tools with a currently registered event loop in this tool manager by waking them up with a null event.

Definition at line 456 of file tool_manager.cpp.

457{
458 m_shuttingDown = true;
459
460 // Create a temporary list of tools to iterate over since when the tools shutdown
461 // they remove themselves from the list automatically (invalidating the iterator)
462 ID_LIST tmpList = m_activeTools;
463
464 // Make sure each tool knows that it is shutting down, so that loops get shut down
465 // at the dispatcher
466 for( auto id : tmpList )
467 {
468 if( m_toolIdIndex.count( id ) == 0 )
469 continue;
470
471 m_toolIdIndex[id]->shutdown = true;
472 }
473
474 for( auto id : tmpList )
475 {
476 ShutdownTool( id );
477 }
478}
std::list< TOOL_ID > ID_LIST
Definition: tool_manager.h:68
void ShutdownTool(TOOL_BASE *aTool)
Shutdown the specified tool by waking it up with a null event to terminate the processing loop.

References m_activeTools, m_shuttingDown, m_toolIdIndex, and ShutdownTool().

Referenced by SCH_EDIT_FRAME::doCloseWindow(), CVPCB_MAINFRAME::~CVPCB_MAINFRAME(), DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME(), FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME(), FOOTPRINT_VIEWER_FRAME::~FOOTPRINT_VIEWER_FRAME(), GERBVIEW_FRAME::~GERBVIEW_FRAME(), KICAD_MANAGER_FRAME::~KICAD_MANAGER_FRAME(), PCB_EDIT_FRAME::~PCB_EDIT_FRAME(), PL_EDITOR_FRAME::~PL_EDITOR_FRAME(), SCH_EDIT_FRAME::~SCH_EDIT_FRAME(), SYMBOL_EDIT_FRAME::~SYMBOL_EDIT_FRAME(), and SYMBOL_VIEWER_FRAME::~SYMBOL_VIEWER_FRAME().

◆ ShutdownTool() [1/3]

void TOOL_MANAGER::ShutdownTool ( const std::string &  aToolName)

Shutdown the specified tool by waking it up with a null event to terminate the processing loop.

Parameters
aToolNameis name of the tool to shutdown

Definition at line 493 of file tool_manager.cpp.

494{
495 TOOL_BASE* tool = FindTool( aToolName );
496
497 if( tool && tool->GetType() == INTERACTIVE )
498 ShutdownTool( tool );
499
500 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::ShutdownTool - no tool with name %s" ),
501 aToolName );
502}

References FindTool(), TOOL_BASE::GetType(), INTERACTIVE, kicadTraceToolStack, and ShutdownTool().

◆ ShutdownTool() [2/3]

void TOOL_MANAGER::ShutdownTool ( TOOL_BASE aTool)

Shutdown the specified tool by waking it up with a null event to terminate the processing loop.

Parameters
aToolis the tool to shutdown

Definition at line 505 of file tool_manager.cpp.

506{
507 wxASSERT( aTool != nullptr );
508
509 TOOL_ID id = aTool->GetId();
510
511 if( isActive( aTool ) )
512 {
513 TOOL_MANAGER::ID_LIST::iterator it = std::find( m_activeTools.begin(),
514 m_activeTools.end(), id );
515
516 TOOL_STATE* st = m_toolIdIndex[*it];
517
518 // the tool state handler is waiting for events (i.e. called Wait() method)
519 if( st && st->pendingWait )
520 {
521 // Wake up the tool and tell it to shutdown
522 st->shutdown = true;
523 st->pendingWait = false;
524 st->waitEvents.clear();
525
526 if( st->cofunc )
527 {
528 wxLogTrace( kicadTraceToolStack,
529 wxS( "TOOL_MANAGER::ShutdownTool - Shutting down tool %s" ),
530 st->theTool->GetName() );
531
532 setActiveState( st );
533 bool end = !st->cofunc->Resume();
534
535 if( end )
536 finishTool( st );
537 }
538 }
539 }
540}

References TOOL_EVENT_LIST::clear(), TOOL_MANAGER::TOOL_STATE::cofunc, finishTool(), TOOL_BASE::GetId(), TOOL_BASE::GetName(), isActive(), kicadTraceToolStack, m_activeTools, m_toolIdIndex, TOOL_MANAGER::TOOL_STATE::pendingWait, COROUTINE< ReturnType, ArgType >::Resume(), setActiveState(), TOOL_MANAGER::TOOL_STATE::shutdown, TOOL_MANAGER::TOOL_STATE::theTool, and TOOL_MANAGER::TOOL_STATE::waitEvents.

Referenced by ShutdownAllTools(), and ShutdownTool().

◆ ShutdownTool() [3/3]

void TOOL_MANAGER::ShutdownTool ( TOOL_ID  aToolId)

Shutdown the specified tool by waking it up with a null event to terminate the processing loop.

Parameters
aToolIdis the ID of the tool to shutdown

Definition at line 481 of file tool_manager.cpp.

482{
483 TOOL_BASE* tool = FindTool( aToolId );
484
485 if( tool && tool->GetType() == INTERACTIVE )
486 ShutdownTool( tool );
487
488 wxLogTrace( kicadTraceToolStack, wxS( "TOOL_MANAGER::ShutdownTool - no tool with ID %d" ),
489 aToolId );
490}

References FindTool(), TOOL_BASE::GetType(), INTERACTIVE, kicadTraceToolStack, and ShutdownTool().

◆ Tools()

std::vector< TOOL_BASE * > TOOL_MANAGER::Tools ( )
inline

Definition at line 231 of file tool_manager.h.

231{ return m_toolOrder; }

References m_toolOrder.

Referenced by FOOTPRINT_EDIT_FRAME::setupTools(), and PCB_EDIT_FRAME::setupTools().

◆ UpdateUI()

void TOOL_MANAGER::UpdateUI ( const TOOL_EVENT aEvent)

Update the status bar and synchronizes toolbars.

Definition at line 1208 of file tool_manager.cpp.

1209{
1210 EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( GetToolHolder() );
1211
1212 if( frame )
1213 frame->UpdateStatusBar();
1214}
The base frame for deriving all KiCad main window classes.
virtual void UpdateStatusBar()
Update the status bar information.

References GetToolHolder(), and EDA_BASE_FRAME::UpdateStatusBar().

Referenced by ProcessEvent(), and RunAction().

◆ VetoContextMenuMouseWarp()

void TOOL_MANAGER::VetoContextMenuMouseWarp ( )
inline

Member Data Documentation

◆ m_actionMgr

ACTION_MANAGER* TOOL_MANAGER::m_actionMgr
private

Original cursor position, if overridden by the context menu handler.

Definition at line 556 of file tool_manager.h.

Referenced by DispatchHotKey(), GetActionManager(), GetHotKey(), InitTools(), RunAction(), TOOL_MANAGER(), and ~TOOL_MANAGER().

◆ m_activeState

TOOL_STATE* TOOL_MANAGER::m_activeState
private

True if the tool manager is shutting down (don't process additional events)

Definition at line 582 of file tool_manager.h.

Referenced by finishTool(), RunAction(), and setActiveState().

◆ m_activeTools

ID_LIST TOOL_MANAGER::m_activeTools
private

◆ m_cursorSettings

std::map<TOOL_ID, std::optional<VECTOR2D> > TOOL_MANAGER::m_cursorSettings
private

Definition at line 559 of file tool_manager.h.

Referenced by DispatchContextMenu(), and saveViewControls().

◆ m_eventQueue

std::list<TOOL_EVENT> TOOL_MANAGER::m_eventQueue
private

Right click context menu position.

Definition at line 568 of file tool_manager.h.

Referenced by PostEvent(), and processEvent().

◆ m_frame

TOOLS_HOLDER* TOOL_MANAGER::m_frame
private

Definition at line 564 of file tool_manager.h.

Referenced by DispatchContextMenu(), GetToolHolder(), and SetEnvironment().

◆ m_menuActive

bool TOOL_MANAGER::m_menuActive
private

Tool currently displaying a popup menu. It is negative when there is no menu displayed.

Definition at line 576 of file tool_manager.h.

Referenced by DispatchContextMenu(), IsContextMenuActive(), and saveViewControls().

◆ m_menuCursor

VECTOR2D TOOL_MANAGER::m_menuCursor
private

Definition at line 571 of file tool_manager.h.

Referenced by DispatchContextMenu(), GetMenuCursorPos(), and saveViewControls().

◆ m_menuOwner

TOOL_ID TOOL_MANAGER::m_menuOwner
private

Pointer to the state object corresponding to the currently executed tool.

Definition at line 579 of file tool_manager.h.

Referenced by DispatchContextMenu(), and dispatchInternal().

◆ m_model

EDA_ITEM* TOOL_MANAGER::m_model
private

Definition at line 561 of file tool_manager.h.

Referenced by GetModel(), and SetEnvironment().

◆ m_settings

APP_SETTINGS_BASE* TOOL_MANAGER::m_settings
private

Queue that stores events to be processed at the end of the event processing cycle.

Definition at line 565 of file tool_manager.h.

Referenced by GetSettings(), and SetEnvironment().

◆ m_shuttingDown

bool TOOL_MANAGER::m_shuttingDown
private

Definition at line 585 of file tool_manager.h.

Referenced by ProcessEvent(), RunAction(), and ShutdownAllTools().

◆ m_toolIdIndex

ID_STATE_MAP TOOL_MANAGER::m_toolIdIndex
private

Index of the registered tools to easily lookup by their type.

Definition at line 547 of file tool_manager.h.

Referenced by DispatchContextMenu(), dispatchInternal(), FindTool(), GetCurrentToolState(), InitTools(), IsToolActive(), RegisterTool(), runTool(), ShutdownAllTools(), and ShutdownTool().

◆ m_toolNameIndex

NAME_STATE_MAP TOOL_MANAGER::m_toolNameIndex
private

Index of the registered tools current states, associated by tools' ID numbers.

Definition at line 544 of file tool_manager.h.

Referenced by dispatchActivation(), FindTool(), InitTools(), and RegisterTool().

◆ m_toolOrder

std::vector<TOOL_BASE*> TOOL_MANAGER::m_toolOrder
private

Index of registered tools current states, associated by tools' objects.

Definition at line 538 of file tool_manager.h.

Referenced by InitTools(), RegisterTool(), and Tools().

◆ m_toolState

TOOL_STATE_MAP TOOL_MANAGER::m_toolState
private

Index of the registered tools current states, associated by tools' names.

Definition at line 541 of file tool_manager.h.

Referenced by ClearTransitions(), dispatchInternal(), InitTools(), isRegistered(), RegisterTool(), ResetTools(), RunMainStack(), ScheduleContextMenu(), ScheduleNextState(), ScheduleWait(), and ~TOOL_MANAGER().

◆ m_toolTypes

std::map<const char*, TOOL_BASE*> TOOL_MANAGER::m_toolTypes
private

Stack of the active tools.

Definition at line 550 of file tool_manager.h.

Referenced by GetTool(), InitTools(), and RegisterTool().

◆ m_view

KIGFX::VIEW* TOOL_MANAGER::m_view
private

Definition at line 562 of file tool_manager.h.

Referenced by GetView(), ProcessEvent(), and SetEnvironment().

◆ m_viewControls

◆ m_warpMouseAfterContextMenu

bool TOOL_MANAGER::m_warpMouseAfterContextMenu
private

Flag indicating whether a context menu is currently displayed.

Definition at line 573 of file tool_manager.h.

Referenced by DispatchContextMenu(), and VetoContextMenuMouseWarp().


The documentation for this class was generated from the following files: