KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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.
 
bool InvokeTool (TOOL_ID aToolId)
 Call a tool by sending a tool activation event to tool of given ID.
 
bool InvokeTool (const std::string &aToolName)
 Call a tool by sending a tool activation event to tool of given name.
 
void ShutdownAllTools ()
 Shutdown all tools with a currently registered event loop in this tool manager by waking them up with a null event.
 
void ShutdownTool (TOOL_BASE *aTool)
 Shutdown the specified tool by waking it up with a null event to terminate the processing loop.
 
void ShutdownTool (TOOL_ID aToolId)
 Shutdown the specified tool by waking it up with a null event to terminate the processing loop.
 
void ShutdownTool (const std::string &aToolName)
 Shutdown the specified tool by waking it up with a null event to terminate the processing loop.
 
template<typename T, std::enable_if_t<!std::is_convertible_v< T *, COMMIT * > > * = nullptr>
bool RunAction (const std::string &aActionName, T aParam)
 Run the specified action immediately, pausing the current action to run the new one.
 
bool RunAction (const std::string &aActionName)
 
template<typename T, std::enable_if_t<!std::is_convertible_v< T, COMMIT * > > * = nullptr>
bool RunAction (const TOOL_ACTION &aAction, T aParam)
 Run the specified action immediately, pausing the current action to run the new one.
 
template<typename T>
bool RunSynchronousAction (const TOOL_ACTION &aAction, COMMIT *aCommit, T aParam)
 Run the specified action immediately, pausing the current action to run the new one.
 
bool RunSynchronousAction (const TOOL_ACTION &aAction, COMMIT *aCommit)
 
bool RunAction (const TOOL_ACTION &aAction)
 
template<typename T>
bool PostAction (const std::string &aActionName, T aParam)
 Run the specified action after the current action (coroutine) ends.
 
bool PostAction (const std::string &aActionName)
 
template<typename T, std::enable_if_t<!std::is_convertible_v< T, COMMIT * > > * = nullptr>
bool PostAction (const TOOL_ACTION &aAction, T aParam)
 Run the specified action after the current action (coroutine) ends.
 
void PostAction (const TOOL_ACTION &aAction)
 
bool PostAPIAction (const TOOL_ACTION &aAction, COMMIT *aCommit)
 
void CancelTool ()
 Send a cancel event to the tool currently at the top of the tool stack.
 
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.
 
int GetHotKey (const TOOL_ACTION &aAction) const
 Return the hot key associated with a given action or 0 if there is none.
 
ACTION_MANAGERGetActionManager () const
 
TOOL_BASEFindTool (int aId) const
 Search for a tool with given ID.
 
TOOL_BASEFindTool (const std::string &aName) const
 Search for a tool with given name.
 
template<typename T>
TGetTool ()
 
std::vector< TOOL_BASE * > Tools ()
 
void DeactivateTool ()
 Deactivate the currently active tool.
 
bool IsToolActive (TOOL_ID aId) const
 Return true if a tool with given id is active (executing)
 
void ResetTools (TOOL_BASE::RESET_REASON aReason)
 Reset all tools (i.e.
 
void InitTools ()
 Initialize all registered tools.
 
bool ProcessEvent (const TOOL_EVENT &aEvent)
 Propagate an event to tools that requested events of matching type(s).
 
void PostEvent (const TOOL_EVENT &aEvent)
 Put an event to the event queue to be processed at the end of event processing cycle.
 
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).
 
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).
 
TOOL_BASEGetCurrentTool () const
 Return the tool that is on the top of the active tools stack (was invoked the most recently).
 
TOOL_STATEGetCurrentToolState () const
 Return the TOOL_STATE object representing the state of the active tool.
 
int GetPriority (int aToolId) const
 Return priority of a given tool.
 
void ScheduleNextState (TOOL_BASE *aTool, TOOL_STATE_FUNC &aHandler, const TOOL_EVENT_LIST &aConditions)
 Define a state transition.
 
void ClearTransitions (TOOL_BASE *aTool)
 Clear the state transition map for a tool.
 
void RunMainStack (TOOL_BASE *aTool, std::function< void()> aFunc)
 
void UpdateUI (const TOOL_EVENT &aEvent)
 Update the status bar and synchronizes toolbars.
 
TOOL_EVENTScheduleWait (TOOL_BASE *aTool, const TOOL_EVENT_LIST &aConditions)
 Pause execution of a given tool until one or more events matching aConditions arrives.
 
void ScheduleContextMenu (TOOL_BASE *aTool, ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
 Set behavior of the tool's context popup menu.
 
const KIGFX::VC_SETTINGSGetCurrentToolVC () const
 Return the view controls settings for the current tool or the general settings if there is no active tool.
 
bool IsContextMenuActive () const
 True while processing a context menu.
 
void VetoContextMenuMouseWarp ()
 Disable mouse warping after the current context menu is closed.
 
void WarpAfterContextMenu ()
 Normally we warp the mouse after the context menu action runs.
 
void DispatchContextMenu (const TOOL_EVENT &aEvent)
 Handle context menu related events.
 
bool DispatchHotKey (const TOOL_EVENT &aEvent)
 Handle specific events, that are intended for TOOL_MANAGER rather than tools.
 
VECTOR2D GetMenuCursorPos () const
 

Static Public Member Functions

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

Private Types

typedef std::pair< TOOL_EVENT_LIST, TOOL_STATE_FUNCTRANSITION
 

Private Member Functions

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

Private Attributes

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

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 61 of file tool_manager.h.

Member Typedef Documentation

◆ ID_LIST

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

Definition at line 75 of file tool_manager.h.

◆ ID_STATE_MAP

Definition at line 74 of file tool_manager.h.

◆ NAME_STATE_MAP

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

Definition at line 73 of file tool_manager.h.

◆ TOOL_STATE_MAP

Definition at line 72 of file tool_manager.h.

◆ TRANSITION

Definition at line 548 of file tool_manager.h.

Constructor & Destructor Documentation

◆ TOOL_MANAGER()

◆ ~TOOL_MANAGER()

TOOL_MANAGER::~TOOL_MANAGER ( )

Definition at line 226 of file tool_manager.cpp.

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

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

References processEvent(), TA_CANCEL_TOOL, and TC_COMMAND.

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

References m_toolState.

◆ DeactivateTool()

void TOOL_MANAGER::DeactivateTool ( )

Deactivate the currently active tool.

Definition at line 618 of file tool_manager.cpp.

References processEvent(), TA_CANCEL_TOOL, and TC_COMMAND.

Referenced by ResetTools().

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

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

Referenced by processEvent().

◆ DispatchContextMenu()

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

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

Referenced by processEvent().

◆ dispatchInternal()

◆ doRunAction() [1/2]

bool TOOL_MANAGER::doRunAction ( const std::string & aActionName,
bool aNow,
const ki::any & aParam,
COMMIT * aCommit )
private

Definition at line 295 of file tool_manager.cpp.

References doRunAction(), and m_actionMgr.

◆ doRunAction() [2/2]

bool TOOL_MANAGER::doRunAction ( const TOOL_ACTION & aAction,
bool aNow,
const ki::any & aParam,
COMMIT * aCommit,
bool aFromAPI = false )
private

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

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

References m_toolIdIndex.

Referenced by GetCurrentTool(), InvokeTool(), InvokeTool(), PCBNEW_JOBS_HANDLER::JobExportDrc(), PCBNEW_JOBS_HANDLER::JobExportDxf(), PCBNEW_JOBS_HANDLER::JobExportGerber(), PCBNEW_JOBS_HANDLER::JobExportGerbers(), PCBNEW_JOBS_HANDLER::JobExportPdf(), PCBNEW_JOBS_HANDLER::JobExportPs(), PCBNEW_JOBS_HANDLER::JobExportSvg(), ShutdownTool(), 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 1023 of file tool_manager.cpp.

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

Referenced by dispatchInternal(), and ShutdownTool().

◆ GetActionManager()

◆ 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 425 of file tool_manager.h.

References FindTool(), and GetCurrentToolId().

◆ 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 414 of file tool_manager.h.

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 434 of file tool_manager.h.

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

References GetCurrentToolState(), and m_viewControls.

◆ GetCursorPosition()

VECTOR2D TOOL_MANAGER::GetCursorPosition ( ) const

Definition at line 321 of file tool_manager.cpp.

References KIPLATFORM::UI::GetMousePosition(), m_viewControls, and ToVECTOR2D().

Referenced by doRunAction(), and invokeTool().

◆ GetHotKey()

int TOOL_MANAGER::GetHotKey ( const TOOL_ACTION & aAction) const

Return the hot key associated with a given action or 0 if there is none.

Parameters
aActionis the queried action.

Definition at line 440 of file tool_manager.cpp.

References m_actionMgr.

Referenced by ACTION_MENU::updateHotKeys().

◆ GetMenuCursorPos()

VECTOR2D TOOL_MANAGER::GetMenuCursorPos ( ) const
inline

Definition at line 542 of file tool_manager.h.

References m_menuCursor.

Referenced by ROUTER_TOOL::InlineBreakTrack().

◆ GetModel()

EDA_ITEM * TOOL_MANAGER::GetModel ( ) const
inline

Definition at line 402 of file tool_manager.h.

References m_model.

◆ GetMousePosition()

VECTOR2D TOOL_MANAGER::GetMousePosition ( ) const

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

References m_activeTools.

◆ GetSettings()

APP_SETTINGS_BASE * TOOL_MANAGER::GetSettings ( ) const
inline

Definition at line 404 of file tool_manager.h.

References m_settings.

Referenced by PCB_TUNING_PATTERN::Update().

◆ GetTool()

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

Definition at line 328 of file tool_manager.h.

References m_toolTypes, name, and T.

Referenced by FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), SCH_FIELD::DoHypertextAction(), SCH_TEXT::DoHypertextAction(), SCH_TEXTBOX::DoHypertextAction(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), PL_EDITOR_FRAME::GetLayoutFromRedoList(), PL_EDITOR_FRAME::GetLayoutFromUndoList(), API_HANDLER_PCB::handleAddToSelection(), API_HANDLER_PCB::handleGetSelection(), API_HANDLER_PCB::handleInteractiveMoveItems(), API_HANDLER_PCB::handleRemoveFromSelection(), API_HANDLER_PCB::handleSaveSelectionToString(), highlightNet(), PCBNEW_JOBS_HANDLER::JobExportDrc(), PCBNEW_JOBS_HANDLER::JobExportDxf(), PCBNEW_JOBS_HANDLER::JobExportGerber(), PCBNEW_JOBS_HANDLER::JobExportGerbers(), PCBNEW_JOBS_HANDLER::JobExportPdf(), PCBNEW_JOBS_HANDLER::JobExportPs(), PCBNEW_JOBS_HANDLER::JobExportSvg(), SCH_EDIT_FRAME::KiwayMailIn(), PCB_EDIT_FRAME::LoadProjectSettings(), SCH_EDIT_FRAME::LoadProjectSettings(), FOOTPRINT_EDIT_FRAME::LoadSettings(), SYMBOL_EDIT_FRAME::LoadSymbol(), SYMBOL_EDIT_FRAME::LoadSymbolFromSchematic(), makeShapeModificationMenu(), PCB_EDIT_FRAME::OnCrossProbeFlashTimer(), SCH_EDIT_FRAME::OnCrossProbeFlashTimer(), DIALOG_DRC::OnDRCItemRClick(), DIALOG_ERC::OnERCItemRClick(), PANEL_COMPONENT_CLASS_ASSIGNMENT::OnHighlightItemsClick(), DIALOG_PLOT::onRunDRC(), DIALOG_DRC::OnRunDRCClick(), DIALOG_CREATE_ARRAY::OnSelectCenterButton(), PL_EDITOR_FRAME::RollbackFromUndo(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), SCH_EDIT_FRAME::SaveProjectLocalSettings(), PCB_EDIT_FRAME::saveProjectSettings(), FOOTPRINT_EDIT_FRAME::SaveSettings(), SYMBOL_EDIT_FRAME::SaveSettings(), PCB_TUNING_PATTERN::ShowPropertiesDialog(), DIALOG_SYMBOL_FIELDS_TABLE::TransferDataToWindow(), ALT_PIN_FUNCTION_MENU::update(), BODY_STYLE_MENU::update(), HIGHLIGHT_MENU::update(), PIN_TRICKS_MENU::update(), SYMBOL_UNIT_MENU::update(), and GLOBAL_EDIT_TOOL::ZonesManager().

◆ GetToolHolder()

◆ GetView()

KIGFX::VIEW * TOOL_MANAGER::GetView ( ) const
inline

◆ GetViewControls()

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

Definition at line 397 of file tool_manager.h.

References m_viewControls.

◆ InitTools()

void TOOL_MANAGER::InitTools ( )

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

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, and setActiveState().

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

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

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

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

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

Referenced by InvokeTool(), and InvokeTool().

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

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 504 of file tool_manager.h.

References m_menuActive.

Referenced by 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 605 of file tool_manager.h.

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

References m_toolIdIndex.

◆ MakeToolId()

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

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

Definition at line 1089 of file tool_manager.cpp.

◆ PostAction() [1/4]

bool TOOL_MANAGER::PostAction ( const std::string & aActionName)
inline

Definition at line 243 of file tool_manager.h.

References doRunAction().

◆ PostAction() [2/4]

template<typename T>
bool TOOL_MANAGER::PostAction ( const std::string & aActionName,
T aParam )
inline

Run the specified action after the current action (coroutine) ends.

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

Note
The type of the optional parameter must match exactly with the type the consuming action is expecting, otherwise an assert will occur when reading the parameter.
Parameters
aActionNameis the name of action to be invoked.
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 235 of file tool_manager.h.

References doRunAction(), and T.

Referenced by FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), SYMBOL_EDITOR_CONTROL::AddSymbolToSchematic(), GERBVIEW_FRAME::GERBVIEW_FRAME(), PCB_BASE_EDIT_FRAME::PutDataInPreviousState(), and SCH_EDIT_FRAME::PutDataInPreviousState().

◆ PostAction() [3/4]

void TOOL_MANAGER::PostAction ( const TOOL_ACTION & aAction)
inline

Definition at line 271 of file tool_manager.h.

References doRunAction().

◆ PostAction() [4/4]

template<typename T, std::enable_if_t<!std::is_convertible_v< T, COMMIT * > > * = nullptr>
bool TOOL_MANAGER::PostAction ( const TOOL_ACTION & aAction,
T aParam )
inline

Run the specified action after the current action (coroutine) ends.

@nite The type of the optional parameter must match exactly with the type the consuming action is expecting, otherwise an assert will occur when reading the parameter.

Parameters
aActionis the action to be invoked.
aParamis an optional parameter that might be used by the invoked action. Its meaning depends on the action. The parameter is not allowed to be a COMMIT as we have no way of guaranteeing the lifetime of the COMMIT object.

Definition at line 263 of file tool_manager.h.

References doRunAction(), and T.

◆ PostAPIAction()

bool TOOL_MANAGER::PostAPIAction ( const TOOL_ACTION & aAction,
COMMIT * aCommit )
inline

Definition at line 282 of file tool_manager.h.

References doRunAction().

Referenced by API_HANDLER_PCB::handleInteractiveMoveItems().

◆ PostEvent()

◆ 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

Definition at line 409 of file tool_manager.cpp.

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

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

References GetCurrentToolState(), m_shuttingDown, m_view, processEvent(), setActiveState(), and UpdateUI().

Referenced by ACTION_MENU::OnMenuEvent().

◆ processEvent()

◆ RegisterTool()

◆ ResetTools()

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

Reset all tools (i.e.

calls their Reset() method).

Definition at line 626 of file tool_manager.cpp.

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

Referenced by InitTools().

◆ RunAction() [1/4]

bool TOOL_MANAGER::RunAction ( const std::string & aActionName)
inline

Definition at line 158 of file tool_manager.h.

References doRunAction().

◆ RunAction() [2/4]

template<typename T, std::enable_if_t<!std::is_convertible_v< T *, COMMIT * > > * = nullptr>
bool TOOL_MANAGER::RunAction ( const std::string & aActionName,
T aParam )
inline

Run the specified action immediately, pausing the current action to run the new one.

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

Note
The type of the optional parameter must match exactly with the type the consuming action is expecting, otherwise an assert will occur when reading the parameter.
Parameters
aActionNameis the name of action to be invoked.
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 150 of file tool_manager.h.

References doRunAction(), and T.

Referenced by PROJECT_TREE_ITEM::Activate(), FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), EDA_DRAW_FRAME::CommonSettingsChanged(), DIALOG_MIGRATE_BUSES::DIALOG_MIGRATE_BUSES(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DIFF_PAIR_MENU::eventHandler(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), GERBVIEW_FRAME::GERBVIEW_FRAME(), API_HANDLER_PCB::handleClearSelection(), API_HANDLER_PCB::handleInteractiveMoveItems(), API_HANDLER_PCB::handleRefillZones(), API_HANDLER_PCB::handleSetBoardOrigin(), PCB_EDIT_FRAME::KiwayMailIn(), FOOTPRINT_CHOOSER_FRAME::onFpChanged(), KICAD_MANAGER_FRAME::OnIdle(), FOOTPRINTS_LISTBOX::OnLeftDClick(), ACTION_MENU::OnMenuEvent(), APPEARANCE_CONTROLS::onNetclassContextMenu(), PCB_EDIT_FRAME::OnNetlistChanged(), SCH_EDIT_FRAME::onNetNavigatorSelection(), DIALOG_CREATE_ARRAY::OnSelectCenterButton(), PCB_EDIT_FRAME::onSize(), SCH_EDIT_FRAME::onSize(), PCB_DESIGN_BLOCK_PANE::PCB_DESIGN_BLOCK_PANE(), ZONE_CREATE_HELPER::performZoneCutout(), FOOTPRINT_WIZARD_FRAME::PythonPluginsReload(), SCH_EDIT_FRAME::RecalculateConnections(), FOOTPRINT_EDIT_FRAME::ReloadFootprint(), PL_EDITOR_FRAME::RollbackFromUndo(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), SCH_DESIGN_BLOCK_PANE::SCH_DESIGN_BLOCK_PANE(), NL_3D_VIEWER_PLUGIN_IMPL::SetActiveCommand(), NL_GERBVIEW_PLUGIN_IMPL::SetActiveCommand(), NL_PCBNEW_PLUGIN_IMPL::SetActiveCommand(), NL_PL_EDITOR_PLUGIN_IMPL::SetActiveCommand(), NL_SCHEMATIC_PLUGIN_IMPL::SetActiveCommand(), SYMBOL_EDIT_FRAME::SetCurSymbol(), CVPCB_MAINFRAME::setupEventHandlers(), FOOTPRINT_EDIT_FRAME::setupTools(), and CVPCB_MAINFRAME::updateFootprintViewerOnIdle().

◆ RunAction() [3/4]

bool TOOL_MANAGER::RunAction ( const TOOL_ACTION & aAction)
inline

Definition at line 213 of file tool_manager.h.

References doRunAction().

◆ RunAction() [4/4]

template<typename T, std::enable_if_t<!std::is_convertible_v< T, COMMIT * > > * = nullptr>
bool TOOL_MANAGER::RunAction ( const TOOL_ACTION & aAction,
T aParam )
inline

Run the specified action immediately, pausing the current action to run the new one.

Note
The type of the optional parameter must match exactly with the type the consuming action is expecting, otherwise an assert will occur when reading the parameter.
Parameters
aActionis the action to be invoked.
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 178 of file tool_manager.h.

References doRunAction(), and T.

◆ RunMainStack()

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

◆ RunSynchronousAction() [1/2]

bool TOOL_MANAGER::RunSynchronousAction ( const TOOL_ACTION & aAction,
COMMIT * aCommit )
inline

Definition at line 205 of file tool_manager.h.

References doRunAction().

◆ RunSynchronousAction() [2/2]

template<typename T>
bool TOOL_MANAGER::RunSynchronousAction ( const TOOL_ACTION & aAction,
COMMIT * aCommit,
T aParam )
inline

Run the specified action immediately, pausing the current action to run the new one.

Note
The type of the optional parameter must match exactly with the type the consuming action is expecting, otherwise an assert will occur when reading the parameter.
Parameters
aActionis the action to be invoked.
aCommitis the commit object the tool handling the action should add the new edits to
Returns
True if the action was handled immediately

Definition at line 197 of file tool_manager.h.

References doRunAction(), and T.

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

References APP_MONITOR::AddTransactionBreadcrumb(), 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().

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

References cursor, TOOL_BASE::GetId(), 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 1070 of file tool_manager.cpp.

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

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

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

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

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.

◆ 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.

Definition at line 1212 of file tool_manager.cpp.

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

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

◆ SetEnvironment()

void TOOL_MANAGER::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).

These are made available to the tool. Called by the parent frame when it is set up.

Definition at line 1097 of file tool_manager.cpp.

References m_frame, m_model, m_settings, m_view, and m_viewControls.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_DATA_TEST_CASE_F(), BOOST_DATA_TEST_CASE_F(), BOOST_FIXTURE_TEST_CASE(), EVT_GRID_CMD_CELL_CHANGED(), EVT_TOOL_RANGE(), KI_TEST::FillZones(), PCBNEW_JOBS_HANDLER::getToolManager(), and EESCHEMA_HELPERS::LoadSchematic().

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

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

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

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

◆ ShutdownTool() [2/3]

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

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

◆ Tools()

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

Definition at line 341 of file tool_manager.h.

References m_toolOrder.

◆ UpdateUI()

void TOOL_MANAGER::UpdateUI ( const TOOL_EVENT & aEvent)

Update the status bar and synchronizes toolbars.

Definition at line 1235 of file tool_manager.cpp.

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

Referenced by doRunAction(), and ProcessEvent().

◆ VetoContextMenuMouseWarp()

void TOOL_MANAGER::VetoContextMenuMouseWarp ( )
inline

Disable mouse warping after the current context menu is closed.

This must be called before invoking each context menu. It's a good idea to call this from non-modal dialogs (e.g. DRC window).

Definition at line 515 of file tool_manager.h.

References m_warpMouseAfterContextMenu.

◆ WarpAfterContextMenu()

void TOOL_MANAGER::WarpAfterContextMenu ( )

Normally we warp the mouse after the context menu action runs.

This works fine for something like the properties dialog, where you can continue drawing after the warp. However, if the menu command itself is a drawing action (such as "Attempt Finish", it will run before the warp (ie: from the position the command was in on the context menu). This call allows an action to perform the warp before it is run.

Definition at line 1013 of file tool_manager.cpp.

References m_menuCursor, m_viewControls, and m_warpMouseAfterContextMenu.

Member Data Documentation

◆ m_actionMgr

ACTION_MANAGER* TOOL_MANAGER::m_actionMgr
private

Instance of ACTION_MANAGER that handles TOOL_ACTIONs.

Definition at line 665 of file tool_manager.h.

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

◆ m_activeState

TOOL_STATE* TOOL_MANAGER::m_activeState
private

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

Definition at line 691 of file tool_manager.h.

Referenced by doRunAction(), finishTool(), setActiveState(), and TOOL_MANAGER().

◆ m_activeTools

ID_LIST TOOL_MANAGER::m_activeTools
private

◆ m_cursorSettings

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

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

Definition at line 668 of file tool_manager.h.

Referenced by DispatchContextMenu(), and saveViewControls().

◆ m_eventQueue

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

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

Definition at line 677 of file tool_manager.h.

Referenced by PostEvent(), and processEvent().

◆ m_frame

TOOLS_HOLDER* TOOL_MANAGER::m_frame
private

Definition at line 673 of file tool_manager.h.

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

◆ m_menuActive

bool TOOL_MANAGER::m_menuActive
private

Flag indicating whether a context menu is currently displayed.

Definition at line 685 of file tool_manager.h.

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

◆ m_menuCursor

VECTOR2D TOOL_MANAGER::m_menuCursor
private

Right click context menu position.

Definition at line 680 of file tool_manager.h.

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

◆ m_menuOwner

TOOL_ID TOOL_MANAGER::m_menuOwner
private

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

Definition at line 688 of file tool_manager.h.

Referenced by DispatchContextMenu(), dispatchInternal(), and TOOL_MANAGER().

◆ m_model

EDA_ITEM* TOOL_MANAGER::m_model
private

Definition at line 670 of file tool_manager.h.

Referenced by GetModel(), SetEnvironment(), and TOOL_MANAGER().

◆ m_settings

APP_SETTINGS_BASE* TOOL_MANAGER::m_settings
private

Definition at line 674 of file tool_manager.h.

Referenced by GetSettings(), SetEnvironment(), and TOOL_MANAGER().

◆ m_shuttingDown

bool TOOL_MANAGER::m_shuttingDown
private

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

Definition at line 694 of file tool_manager.h.

Referenced by doRunAction(), ProcessEvent(), ShutdownAllTools(), and TOOL_MANAGER().

◆ m_toolIdIndex

ID_STATE_MAP TOOL_MANAGER::m_toolIdIndex
private

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

Definition at line 656 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' names.

Definition at line 653 of file tool_manager.h.

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

◆ m_toolOrder

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

List of tools in the order they were registered.

Definition at line 647 of file tool_manager.h.

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

◆ m_toolState

TOOL_STATE_MAP TOOL_MANAGER::m_toolState
private

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

Definition at line 650 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

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

Definition at line 659 of file tool_manager.h.

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

◆ m_view

KIGFX::VIEW* TOOL_MANAGER::m_view
private

Definition at line 671 of file tool_manager.h.

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

◆ m_viewControls

◆ m_warpMouseAfterContextMenu

bool TOOL_MANAGER::m_warpMouseAfterContextMenu
private

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