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 1135 of file tool_manager.cpp.

1136{
1137 m_viewControls->ApplySettings( aState->vcSettings );
1138}
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 647 of file tool_manager.cpp.

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

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 825 of file tool_manager.cpp.

826{
827 wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchActivation - Received event: %s",
828 aEvent.Format() );
829
830 if( aEvent.IsActivate() )
831 {
832 auto tool = m_toolNameIndex.find( aEvent.getCommandStr() );
833
834 if( tool != m_toolNameIndex.end() )
835 {
836 wxLogTrace( kicadTraceToolStack,
837 "TOOL_MANAGER::dispatchActivation - Running tool %s for event: %s",
838 tool->second->theTool->GetName(), aEvent.Format() );
839
840 runTool( tool->second->theTool );
841 return true;
842 }
843 }
844
845 return false;
846}
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 848 of file tool_manager.cpp.

849{
850 for( TOOL_ID toolId : m_activeTools )
851 {
852 TOOL_STATE* st = m_toolIdIndex[toolId];
853
854 // the tool requested a context menu. The menu is activated on RMB click (CMENU_BUTTON mode)
855 // or immediately (CMENU_NOW) mode. The latter is used for clarification lists.
856 if( st->contextMenuTrigger == CMENU_OFF )
857 continue;
858
859 if( st->contextMenuTrigger == CMENU_BUTTON && !aEvent.IsClick( BUT_RIGHT ) )
860 break;
861
862 if( st->cofunc )
863 {
864 st->pendingWait = true;
865 st->waitEvents = TOOL_EVENT( TC_ANY, TA_ANY );
866 }
867
868 // Store the menu pointer in case it is changed by the TOOL when handling menu events
869 ACTION_MENU* m = st->contextMenu;
870
871 if( st->contextMenuTrigger == CMENU_NOW )
872 st->contextMenuTrigger = CMENU_OFF;
873
874 // Store the cursor position, so the tools could execute actions
875 // using the point where the user has invoked a context menu
876 if( m_viewControls )
878
879 // Save all tools cursor settings, as they will be overridden
880 for( const std::pair<const TOOL_ID, TOOL_STATE*>& idState : m_toolIdIndex )
881 {
882 TOOL_STATE* s = idState.second;
883 const auto& vc = s->vcSettings;
884
885 if( vc.m_forceCursorPosition )
886 m_cursorSettings[idState.first] = vc.m_forcedPosition;
887 else
888 m_cursorSettings[idState.first] = std::nullopt;
889 }
890
891 if( m_viewControls )
893
894 // Display a copy of menu
895 std::unique_ptr<ACTION_MENU> menu( m->Clone() );
896
897 m_menuOwner = toolId;
898 m_menuActive = true;
899
900 if( wxWindow* frame = dynamic_cast<wxWindow*>( m_frame ) )
901 frame->PopupMenu( menu.get() );
902
903 // If a menu is canceled then notify tool
904 if( menu->GetSelected() < 0 )
905 {
907 evt.SetHasPosition( false );
908 evt.SetParameter( m );
909 dispatchInternal( evt );
910 }
911
912 // Restore setting in case it was vetoed
914
915 // Notify the tools that menu has been closed
917 evt.SetHasPosition( false );
918 evt.SetParameter( m );
919 dispatchInternal( evt );
920
921 m_menuActive = false;
922 m_menuOwner = -1;
923
924 // Restore cursor settings
925 for( const std::pair<const TOOL_ID, std::optional<VECTOR2D>>& cursorSetting : m_cursorSettings )
926 {
927 auto it = m_toolIdIndex.find( cursorSetting.first );
928 wxASSERT( it != m_toolIdIndex.end() );
929
930 if( it == m_toolIdIndex.end() )
931 continue;
932
933 KIGFX::VC_SETTINGS& vc = it->second->vcSettings;
934 vc.m_forceCursorPosition = (bool) cursorSetting.second;
935 vc.m_forcedPosition = cursorSetting.second ? *cursorSetting.second : VECTOR2D( 0, 0 );
936 }
937
938 m_cursorSettings.clear();
939 break;
940 }
941}
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 816 of file tool_manager.cpp.

817{
818 if( aEvent.Action() == TA_KEY_PRESSED )
819 return m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() );
820
821 return false;
822}
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 683 of file tool_manager.cpp.

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

945{
946 auto it = std::find( m_activeTools.begin(), m_activeTools.end(), aState->theTool->GetId() );
947
948 if( !aState->Pop() )
949 {
950 // Deactivate the tool if there are no other contexts saved on the stack
951 if( it != m_activeTools.end() )
952 it = m_activeTools.erase( it );
953
954 aState->idle = true;
955 }
956
957 if( aState == m_activeState )
958 setActiveState( nullptr );
959
960 // Set transitions to be ready for future TOOL_EVENTs
961 TOOL_BASE* tool = aState->theTool;
962
963 if( tool->GetType() == INTERACTIVE )
964 static_cast<TOOL_INTERACTIVE*>( tool )->resetTransitions();
965
966 return it;
967}
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:108
@ 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 1030 of file tool_manager.cpp.

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

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 1056 of file tool_manager.cpp.

1057{
1058 if( TOOL_STATE* active = GetCurrentToolState() )
1059 return active->vcSettings;
1060
1061 return m_viewControls->GetSettings();
1062}
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 622 of file tool_manager.cpp.

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

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(), SCH_EDIT_FRAME::AnnotateSymbols(), SCH_EDITOR_CONTROL::AssignNetclass(), BOARD_EDITOR_CONTROL::AssignNetclass(), EE_SELECTION_TOOL::autostartEvent(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), 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(), 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(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), EE_SELECTION_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_SELECTION_TOOL::Main(), PCB_SELECTION_TOOL::Main(), GRAPHICS_CLEANER::mergePads(), BOARD_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveIndividually(), 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::OnTableCellClick(), 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(), DIALOG_PLOT::Plot(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), PAD_TOOL::pushPadSettings(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), CVPCB_MAINFRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), SYMBOL_EDIT_FRAME::ReCreateOptToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateVToolbar(), SCH_EDITOR_CONTROL::Redo(), SYMBOL_EDITOR_EDIT_TOOL::Redo(), SCH_BASE_FRAME::RefreshZoomDependentItems(), GROUP_TOOL::RemoveFromGroup(), SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem(), BOARD_COMMIT::Revert(), PL_EDITOR_FRAME::RollbackFromUndo(), SCH_EDIT_FRAME::RollbackSchematicFromUndo(), SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo(), 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 589 of file tool_manager.cpp.

590{
591 for( auto it = m_toolOrder.begin(); it != m_toolOrder.end(); /* iter inside */ )
592 {
593 TOOL_BASE* tool = *it;
594 wxASSERT( m_toolState.count( tool ) );
595 TOOL_STATE* state = m_toolState[tool];
596 setActiveState( state );
597 ++it; // keep the iterator valid if the element is going to be erased
598
599 if( !tool->Init() )
600 {
601 wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER initialization of tool '%s' failed",
602 tool->GetName() );
603
604 // Unregister the tool
605 setActiveState( nullptr );
606 m_toolState.erase( tool );
607 m_toolNameIndex.erase( tool->GetName() );
608 m_toolIdIndex.erase( tool->GetId() );
609 m_toolTypes.erase( typeid( *tool ).name() );
610
611 delete state;
612 delete tool;
613 }
614 }
615
616 m_actionMgr->UpdateHotKeys( true );
617
619}
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:89
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:133
@ 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:120
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, "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, "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 1085 of file tool_manager.cpp.

1086{
1087 if( !isRegistered( aTool ) )
1088 return false;
1089
1090 // Just check if the tool is on the active tools stack
1091 return alg::contains( m_activeTools, aTool->GetId() );
1092}
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 1200 of file tool_manager.cpp.

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

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 1065 of file tool_manager.cpp.

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

◆ 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(), TOOLS_HOLDER::PopTool(), PrimeTool(), SCH_EDIT_TOOL::Properties(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), 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 970 of file tool_manager.cpp.

971{
972 // Once the tool manager is shutting down, don't start
973 // activating more tools
974 if( m_shuttingDown )
975 return true;
976
977 bool handled = processEvent( aEvent );
978
979 TOOL_STATE* activeTool = GetCurrentToolState();
980
981 if( activeTool )
982 setActiveState( activeTool );
983
984 if( m_view && m_view->IsDirty() )
985 {
986 if( GetToolHolder() )
988
989#if defined( __WXMAC__ )
990 wxTheApp->ProcessPendingEvents(); // required for updating brightening behind a popup menu
991#endif
992 }
993
994 UpdateUI( aEvent );
995
996 return handled;
997}
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(), 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::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(), 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::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(), GERBVIEW_SELECTION_TOOL::UnselectItems(), and EDA_DRAW_FRAME::UpdateMsgPanel().

◆ 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 1141 of file tool_manager.cpp.

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

◆ 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(), SCH_MOVE_TOOL::AlignElements(), 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(), 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_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(), SCH_EDIT_FRAME::FixupJunctions(), 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_NAVIG_PANEL::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(), 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_NETLIST_IMPORT::~DIALOG_NETLIST_IMPORT(), 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 653 of file tool_manager.cpp.

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

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, "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 1010 of file tool_manager.cpp.

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

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 1095 of file tool_manager.cpp.

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

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 1000 of file tool_manager.cpp.

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

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 638 of file tool_manager.cpp.

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

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 661 of file tool_manager.cpp.

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

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 1188 of file tool_manager.cpp.

1189{
1192
1193 m_activeState = aState;
1194
1196 applyViewControls( aState );
1197}
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, "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 "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, "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 1207 of file tool_manager.cpp.

1208{
1209 EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( GetToolHolder() );
1210
1211 if( frame )
1212 frame->UpdateStatusBar();
1213}
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: