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
 
typedef std::vector< TOOL_BASE * > TOOL_VEC
 

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)
 
const std::map< std::string, TOOL_ACTION * > & GetActions () const
 
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 ()
 
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

TOOL_VEC 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, OPT< 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
 

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.

◆ TOOL_VEC

typedef std::vector<TOOL_BASE*> TOOL_MANAGER::TOOL_VEC

Definition at line 69 of file tool_manager.h.

◆ TRANSITION

Definition at line 446 of file tool_manager.h.

Constructor & Destructor Documentation

◆ TOOL_MANAGER()

TOOL_MANAGER::TOOL_MANAGER ( )

Definition at line 201 of file tool_manager.cpp.

201  :
202  m_model( nullptr ),
203  m_view( nullptr ),
204  m_viewControls( nullptr ),
205  m_frame( nullptr ),
206  m_settings( nullptr ),
208  m_menuActive( false ),
209  m_menuOwner( -1 ),
210  m_activeState( nullptr )
211 {
212  m_actionMgr = new ACTION_MANAGER( this );
213 }
bool m_menuActive
Tool currently displaying a popup menu. It is negative when there is no menu displayed.
Definition: tool_manager.h:574
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:554
Manage TOOL_ACTION objects.
TOOLS_HOLDER * m_frame
Definition: tool_manager.h:562
EDA_ITEM * m_model
Definition: tool_manager.h:559
TOOL_ID m_menuOwner
Pointer to the state object corresponding to the currently executed tool.
Definition: tool_manager.h:577
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561
KIGFX::VIEW * m_view
Definition: tool_manager.h:560
bool m_warpMouseAfterContextMenu
Flag indicating whether a context menu is currently displayed.
Definition: tool_manager.h:571
TOOL_STATE * m_activeState
Definition: tool_manager.h:580
APP_SETTINGS_BASE * m_settings
Queue that stores events to be processed at the end of the event processing cycle.
Definition: tool_manager.h:563

References m_actionMgr.

◆ ~TOOL_MANAGER()

TOOL_MANAGER::~TOOL_MANAGER ( )

Definition at line 216 of file tool_manager.cpp.

217 {
218  std::map<TOOL_BASE*, TOOL_STATE*>::iterator it, it_end;
219 
220  for( it = m_toolState.begin(), it_end = m_toolState.end(); it != it_end; ++it )
221  {
222  delete it->second->cofunc; // delete cofunction
223  delete it->second; // delete TOOL_STATE
224  delete it->first; // delete the tool itself
225  }
226 
227  delete m_actionMgr;
228 }
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:554
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539

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

1111 {
1112  m_viewControls->ApplySettings( aState->vcSettings );
1113 }
void ApplySettings(const VC_SETTINGS &aSettings)
Load new settings from program common settings.
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561

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

344 {
346 
347  processEvent( evt );
348 }
bool processEvent(const TOOL_EVENT &aEvent)
Main function for event processing.
Generic, UI-independent tool event.
Definition: tool_event.h:152

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

627 {
628  m_toolState[aTool]->transitions.clear();
629 }
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539

References m_toolState.

Referenced by TOOL_INTERACTIVE::resetTransitions().

◆ DeactivateTool()

void TOOL_MANAGER::DeactivateTool ( )

Deactivate the currently active tool.

Definition at line 544 of file tool_manager.cpp.

545 {
546  // Deactivate the active tool, but do not run anything new
548  processEvent( evt );
549 }
bool processEvent(const TOOL_EVENT &aEvent)
Main function for event processing.
Generic, UI-independent tool event.
Definition: tool_event.h:152

References processEvent(), TA_CANCEL_TOOL, and TC_COMMAND.

Referenced by GERBVIEW_FRAME::doCloseWindow(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), 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 803 of file tool_manager.cpp.

804 {
805  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchActivation - Received event: %s",
806  aEvent.Format() );
807 
808  if( aEvent.IsActivate() )
809  {
810  wxString cmdStr( *aEvent.GetCommandStr() );
811 
812  auto tool = m_toolNameIndex.find( *aEvent.GetCommandStr() );
813 
814  if( tool != m_toolNameIndex.end() )
815  {
816  wxLogTrace( kicadTraceToolStack,
817  "TOOL_MANAGER::dispatchActivation - Running tool %s for event: %s",
818  tool->second->theTool->GetName(), aEvent.Format() );
819 
820  runTool( tool->second->theTool );
821  return true;
822  }
823  }
824 
825  return false;
826 }
const std::string Format() const
Return information about event in form of a human-readable string.
Definition: tool_event.cpp:94
NAME_STATE_MAP m_toolNameIndex
Index of the registered tools current states, associated by tools' ID numbers.
Definition: tool_manager.h:542
bool runTool(TOOL_BASE *aTool)
Make a tool active, so it can receive events and react to them.
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
bool IsActivate() const
Definition: tool_event.h:310
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 828 of file tool_manager.cpp.

829 {
830  for( TOOL_ID toolId : m_activeTools )
831  {
832  TOOL_STATE* st = m_toolIdIndex[toolId];
833 
834  // the tool requested a context menu. The menu is activated on RMB click (CMENU_BUTTON mode)
835  // or immediately (CMENU_NOW) mode. The latter is used for clarification lists.
836  if( st->contextMenuTrigger == CMENU_OFF )
837  continue;
838 
839  if( st->contextMenuTrigger == CMENU_BUTTON && !aEvent.IsClick( BUT_RIGHT ) )
840  break;
841 
842  if( st->cofunc )
843  {
844  st->pendingWait = true;
845  st->waitEvents = TOOL_EVENT( TC_ANY, TA_ANY );
846  }
847 
848  // Store the menu pointer in case it is changed by the TOOL when handling menu events
849  ACTION_MENU* m = st->contextMenu;
850 
851  if( st->contextMenuTrigger == CMENU_NOW )
852  st->contextMenuTrigger = CMENU_OFF;
853 
854  // Store the cursor position, so the tools could execute actions
855  // using the point where the user has invoked a context menu
856  if( m_viewControls )
858 
859  // Save all tools cursor settings, as they will be overridden
860  for( auto idState : m_toolIdIndex )
861  {
862  TOOL_STATE* s = idState.second;
863  const auto& vc = s->vcSettings;
864 
865  if( vc.m_forceCursorPosition )
866  m_cursorSettings[idState.first] = vc.m_forcedPosition;
867  else
868  m_cursorSettings[idState.first] = NULLOPT;
869  }
870 
871  if( m_viewControls )
873 
874  // Display a copy of menu
875  std::unique_ptr<ACTION_MENU> menu( m->Clone() );
876 
877  m_menuOwner = toolId;
878  m_menuActive = true;
879 
880  if( wxWindow* frame = dynamic_cast<wxWindow*>( m_frame ) )
881  frame->PopupMenu( menu.get() );
882 
883  // If a menu is cancelled then notify tool
884  if( menu->GetSelected() < 0 )
885  {
887  evt.SetHasPosition( false );
888  evt.SetParameter( m );
889  dispatchInternal( evt );
890  }
891 
892  // Restore setting in case it was vetoed
894 
895  // Notify the tools that menu has been closed
897  evt.SetHasPosition( false );
898  evt.SetParameter( m );
899  dispatchInternal( evt );
900 
901  m_menuActive = false;
902  m_menuOwner = -1;
903 
904  // Restore cursor settings
905  for( auto cursorSetting : m_cursorSettings )
906  {
907  auto it = m_toolIdIndex.find( cursorSetting.first );
908  wxASSERT( it != m_toolIdIndex.end() );
909 
910  if( it == m_toolIdIndex.end() )
911  continue;
912 
913  KIGFX::VC_SETTINGS& vc = it->second->vcSettings;
914  vc.m_forceCursorPosition = (bool) cursorSetting.second;
915  vc.m_forcedPosition = cursorSetting.second ? *cursorSetting.second : VECTOR2D( 0, 0 );
916  }
917 
918  m_cursorSettings.clear();
919  break;
920  }
921 }
bool m_menuActive
Tool currently displaying a popup menu. It is negative when there is no menu displayed.
Definition: tool_manager.h:574
VECTOR2D m_menuCursor
Definition: tool_manager.h:569
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
bool dispatchInternal(TOOL_EVENT &aEvent)
Pass an event at first to the active tools, then to all others.
bool IsClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:199
std::map< TOOL_ID, OPT< VECTOR2D > > m_cursorSettings
Definition: tool_manager.h:557
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:55
TOOLS_HOLDER * m_frame
Definition: tool_manager.h:562
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
const auto NULLOPT
Definition: optional.h:9
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
Definition: view_controls.h:58
TOOL_ID m_menuOwner
Pointer to the state object corresponding to the currently executed tool.
Definition: tool_manager.h:577
Generic, UI-independent tool event.
Definition: tool_event.h:152
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:41
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.
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561
bool m_warpMouseAfterContextMenu
Flag indicating whether a context menu is currently displayed.
Definition: tool_manager.h:571
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

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, NULLOPT, 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 LIB_TREE::onContextMenu(), and 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 794 of file tool_manager.cpp.

795 {
796  if( aEvent.Action() == TA_KEY_PRESSED )
797  return m_actionMgr->RunHotKey( aEvent.Modifier() | aEvent.KeyCode() );
798 
799  return false;
800 }
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:554
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:230
bool RunHotKey(int aHotKey) const
Run an action associated with a hotkey (if there is one available).
int Modifier(int aMask=MD_MODIFIER_MASK) const
Definition: tool_event.h:331
int KeyCode() const
Definition: tool_event.h:341

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

663 {
664  bool handled = false;
665 
666  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchInternal - received event: %s",
667  aEvent.Format() );
668 
669  auto it = m_activeTools.begin();
670 
671  // iterate over active tool stack
672  while( it != m_activeTools.end() )
673  {
674  TOOL_STATE* st = m_toolIdIndex[*it];
675  bool increment = true;
676 
677  // forward context menu events to the tool that created the menu
678  if( aEvent.IsChoiceMenu() )
679  {
680  if( *it != m_menuOwner )
681  {
682  ++it;
683  continue;
684  }
685  }
686 
687  // If we're pendingWait then we had better have a cofunc to process the wait.
688  wxASSERT( !st || !st->pendingWait || st->cofunc );
689 
690  // the tool state handler is waiting for events (i.e. called Wait() method)
691  if( st && st->cofunc && st->pendingWait && st->waitEvents.Matches( aEvent ) )
692  {
693  if( !aEvent.FirstResponder() )
694  aEvent.SetFirstResponder( st->theTool );
695 
696  // got matching event? clear wait list and wake up the coroutine
697  st->wakeupEvent = aEvent;
698  st->pendingWait = false;
699  st->waitEvents.clear();
700 
701  wxLogTrace( kicadTraceToolStack,
702  "TOOL_MANAGER::dispatchInternal - Waking tool %s for event: %s",
703  st->theTool->GetName(), aEvent.Format() );
704 
705  setActiveState( st );
706  bool end = !st->cofunc->Resume();
707 
708  if( end )
709  {
710  it = finishTool( st );
711  increment = false;
712  }
713 
714  // If the tool did not request the event be passed to other tools, we're done
715  if( !st->wakeupEvent.PassEvent() )
716  {
717  wxLogTrace( kicadTraceToolStack,
718  "TOOL_MANAGER::dispatchInternal - tool %s stopped passing event: %s",
719  st->theTool->GetName(), aEvent.Format() );
720 
721  return true;
722  }
723  }
724 
725  if( increment )
726  ++it;
727  }
728 
729  for( const auto& state : m_toolState )
730  {
731  TOOL_STATE* st = state.second;
732  bool finished = false;
733 
734  // no state handler in progress - check if there are any transitions (defined by
735  // Go() method that match the event.
736  if( !st->transitions.empty() )
737  {
738  for( const TRANSITION& tr : st->transitions )
739  {
740  if( tr.first.Matches( aEvent ) )
741  {
742  auto func_copy = tr.second;
743 
744  if( !aEvent.FirstResponder() )
745  aEvent.SetFirstResponder( st->theTool );
746 
747  // if there is already a context, then push it on the stack
748  // and transfer the previous view control settings to the new context
749  if( st->cofunc )
750  {
751  auto vc = st->vcSettings;
752  st->Push();
753  st->vcSettings = vc;
754  }
755 
756  st->cofunc = new COROUTINE<int, const TOOL_EVENT&>( std::move( func_copy ) );
757 
758  // as the state changes, the transition table has to be set up again
759  st->transitions.clear();
760 
761  wxLogTrace( kicadTraceToolStack,
762  "TOOL_MANAGER::dispatchInternal - Running tool %s for event: %s",
763  st->theTool->GetName(), aEvent.Format() );
764 
765  // got match? Run the handler.
766  setActiveState( st );
767  st->idle = false;
768  st->cofunc->Call( aEvent );
769  handled = true;
770 
771  if( !st->cofunc->Running() )
772  finishTool( st ); // The coroutine has finished immediately?
773 
774  // if it is a message, continue processing
775  finished = !( aEvent.Category() == TC_MESSAGE );
776 
777  // there is no point in further checking, as transitions got cleared
778  break;
779  }
780  }
781  }
782 
783  if( finished )
784  break; // only the first tool gets the event
785  }
786 
787  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchInternal - %s handle event: %s",
788  ( handled ? "Did" : "Did not" ), aEvent.Format() );
789 
790  return handled;
791 }
const std::string Format() const
Return information about event in form of a human-readable string.
Definition: tool_event.cpp:94
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
ID_LIST::iterator finishTool(TOOL_STATE *aState)
Deactivate a tool and does the necessary clean up.
TOOL_EVENT_CATEGORY Category() const
Returns more specific information about the type of an event.
Definition: tool_event.h:227
TOOL_ID m_menuOwner
Pointer to the state object corresponding to the currently executed tool.
Definition: tool_manager.h:577
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
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:249
bool IsChoiceMenu() const
Definition: tool_event.h:320
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
TOOL_BASE * FirstResponder() const
Definition: tool_event.h:248
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539
std::pair< TOOL_EVENT_LIST, TOOL_STATE_FUNC > TRANSITION
Definition: tool_manager.h:446

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_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 ( 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 522 of file tool_manager.cpp.

523 {
524  std::map<TOOL_ID, TOOL_STATE*>::const_iterator it = m_toolIdIndex.find( aId );
525 
526  if( it != m_toolIdIndex.end() )
527  return it->second->theTool;
528 
529  return NULL;
530 }
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
#define NULL

References m_toolIdIndex, and NULL.

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

◆ FindTool() [2/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 533 of file tool_manager.cpp.

534 {
535  std::map<std::string, TOOL_STATE*>::const_iterator it = m_toolNameIndex.find( aName );
536 
537  if( it != m_toolNameIndex.end() )
538  return it->second->theTool;
539 
540  return NULL;
541 }
NAME_STATE_MAP m_toolNameIndex
Index of the registered tools current states, associated by tools' ID numbers.
Definition: tool_manager.h:542
#define NULL

References m_toolNameIndex, and NULL.

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

925 {
926  auto it = std::find( m_activeTools.begin(), m_activeTools.end(), aState->theTool->GetId() );
927 
928  if( !aState->Pop() )
929  {
930  // Deactivate the tool if there are no other contexts saved on the stack
931  if( it != m_activeTools.end() )
932  it = m_activeTools.erase( it );
933 
934  aState->idle = true;
935  }
936 
937  if( aState == m_activeState )
938  setActiveState( nullptr );
939 
940  // Set transitions to be ready for future TOOL_EVENTs
941  TOOL_BASE* tool = aState->theTool;
942 
943  if( tool->GetType() == INTERACTIVE )
944  static_cast<TOOL_INTERACTIVE*>( tool )->resetTransitions();
945 
946  return it;
947 }
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:108
Tool that interacts with the user.
Definition: tool_base.h:49
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
TOOL_STATE * m_activeState
Definition: tool_manager.h:580
Base abstract interface for all kinds of tools.
Definition: tool_base.h:65
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551

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()

◆ GetActions()

const std::map< std::string, TOOL_ACTION * > & TOOL_MANAGER::GetActions ( ) const

Definition at line 376 of file tool_manager.cpp.

377 {
378  return m_actionMgr->GetActions();
379 }
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:554
const std::map< std::string, TOOL_ACTION * > & GetActions() const
Get a list of currently-registered actions mapped by their name.

References ACTION_MANAGER::GetActions(), and m_actionMgr.

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

1006 {
1007  std::string result;
1008 
1009  wxLogNull doNotLog; // disable logging of failed clipboard actions
1010 
1011  if( wxTheClipboard->Open() )
1012  {
1013  if( wxTheClipboard->IsSupported( wxDF_TEXT )
1014  || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
1015  {
1016  wxTextDataObject data;
1017  wxTheClipboard->GetData( data );
1018 
1019  // The clipboard is expected containing a unicode string, so return it
1020  // as UTF8 string
1021  result = data.GetText().utf8_str();
1022  }
1023 
1024  wxTheClipboard->Close();
1025  }
1026 
1027  return result;
1028 }

Referenced by PL_EDIT_TOOL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), and SCH_EDITOR_CONTROL::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 313 of file tool_manager.h.

314  {
315  return FindTool( GetCurrentToolId() );
316  }
TOOL_BASE * FindTool(int aId) const
Search for a tool with given ID.
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:302

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

303  {
304  return m_activeTools.empty() ? -1 : m_activeTools.front();
305  }
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551

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

323  {
324  auto it = m_toolIdIndex.find( GetCurrentToolId() );
325  return ( it != m_toolIdIndex.end() ) ? it->second : nullptr;
326  }
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
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:302

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

1032 {
1033  if( TOOL_STATE* active = GetCurrentToolState() )
1034  return active->vcSettings;
1035 
1036  return m_viewControls->GetSettings();
1037 }
const VC_SETTINGS & GetSettings() const
Apply VIEW_CONTROLS settings from an object.
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561
TOOL_STATE * GetCurrentToolState() const
Return the #TOOL_STATE object representing the state of the active tool.
Definition: tool_manager.h:322

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

Referenced by COMMON_TOOLS::ResetLocalCoords().

◆ GetCursorPosition()

VECTOR2D TOOL_MANAGER::GetCursorPosition ( ) const

Definition at line 306 of file tool_manager.cpp.

307 {
308  if( m_viewControls )
310  else
311  return wxGetMousePosition();
312 }
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

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

383 {
384  return m_actionMgr->GetHotKey( aAction );
385 }
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:554
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 440 of file tool_manager.h.

441  {
442  return m_menuCursor;
443  }
VECTOR2D m_menuCursor
Definition: tool_manager.h:569

References m_menuCursor.

Referenced by ROUTER_TOOL::InlineBreakTrack().

◆ GetModel()

◆ GetMousePosition()

VECTOR2D TOOL_MANAGER::GetMousePosition ( ) const

Definition at line 297 of file tool_manager.cpp.

298 {
299  if( m_viewControls )
301  else
302  return wxGetMousePosition();
303 }
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561

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

Referenced by 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 601 of file tool_manager.cpp.

602 {
603  int priority = 0;
604 
605  for( TOOL_ID tool : m_activeTools )
606  {
607  if( tool == aToolId )
608  return priority;
609 
610  ++priority;
611  }
612 
613  return -1;
614 }
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551

References m_activeTools.

Referenced by ACTION_MANAGER::RunHotKey().

◆ GetSettings()

APP_SETTINGS_BASE* TOOL_MANAGER::GetSettings ( ) const
inline

Definition at line 292 of file tool_manager.h.

292 { return m_settings; }
APP_SETTINGS_BASE * m_settings
Queue that stores events to be processed at the end of the event processing cycle.
Definition: tool_manager.h:563

References m_settings.

Referenced by COMMON_TOOLS::doZoomInOut(), COMMON_TOOLS::doZoomToPreset(), COMMON_TOOLS::GridNext(), COMMON_TOOLS::GridPreset(), COMMON_TOOLS::GridPrev(), COMMON_TOOLS::OnGridChanged(), and COMMON_TOOLS::Reset().

◆ GetTool()

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

Definition at line 221 of file tool_manager.h.

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

References m_toolTypes, and name.

Referenced by EDA_BASE_FRAME::AddStandardHelpMenu(), EDA_DRAW_FRAME::AddStandardSubMenus(), SCH_EDIT_FRAME::AnnotateSymbols(), SCH_EDITOR_CONTROL::AssignNetclass(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), SCH_EDIT_FRAME::CheckAnnotate(), PAD_TOOL::copyPadSettings(), EDA_3D_VIEWER_FRAME::CreateMenuBar(), ZONE_CREATE_HELPER::createNewZone(), BOARD_INSPECTION_TOOL::CrossProbePcbToSch(), SCH_EDIT_FRAME::DeleteAnnotation(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), SCH_EDIT_FRAME::DeleteJunction(), DIALOG_BOARD_REANNOTATE::DIALOG_BOARD_REANNOTATE(), SCH_EDIT_FRAME::DisplayCurrentSheet(), PL_DRAW_PANEL_GAL::DisplayDrawingSheet(), DIALOG_CLEANUP_TRACKS_AND_VIAS::doCleanup(), SCH_EDITOR_CONTROL::doCopy(), SCH_EDITOR_CONTROL::doCrossProbeSchToPcb(), BOARD_INSPECTION_TOOL::doHideNet(), DRAWING_TOOL::DrawVia(), BOARD_EDITOR_CONTROL::DrillOrigin(), EDIT_TOOL::Duplicate(), BOARD_EDITOR_CONTROL::EditFpInFpEditor(), SYMBOL_EDITOR_EDIT_TOOL::editGraphicProperties(), PAD_TOOL::EditPad(), SYMBOL_EDITOR_EDIT_TOOL::editSymbolProperties(), SCH_EDITOR_CONTROL::EditWithSymbolEditor(), GROUP_TOOL::EnterGroup(), SCH_NAVIGATE_TOOL::EnterSheet(), SCH_EDITOR_CONTROL::EnterSheet(), EE_INSPECTION_TOOL::ExcludeMarker(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), EDIT_TOOL::GetAndPlace(), FP_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool(), SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool(), FOOTPRINT_EDIT_FRAME::GetCurrentSelection(), FOOTPRINT_VIEWER_FRAME::GetCurrentSelection(), PL_EDITOR_FRAME::GetCurrentSelection(), SYMBOL_EDIT_FRAME::GetCurrentSelection(), DISPLAY_FOOTPRINTS_FRAME::GetCurrentSelection(), SCH_EDIT_FRAME::GetCurrentSelection(), SYMBOL_VIEWER_FRAME::GetCurrentSelection(), GERBVIEW_FRAME::GetCurrentSelection(), PL_EDITOR_FRAME::GetLayoutFromRedoList(), PL_EDITOR_FRAME::GetLayoutFromUndoList(), DRAWING_TOOL::getSourceZoneForAction(), EDA_DRAW_FRAME::GetUnitPair(), PCB_CONTROL::GridSetOrigin(), GROUP_TOOL::Group(), PL_EDITOR_FRAME::HardRedraw(), SYMBOL_EDIT_FRAME::HardRedraw(), GERBVIEW_CONTROL::HighlightControl(), BOARD_INSPECTION_TOOL::highlightNet(), highlightNet(), SCH_EDITOR_CONTROL::HighlightNetCursor(), BOARD_REANNOTATE_TOOL::Init(), SYMBOL_EDITOR_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), PL_EDIT_TOOL::Init(), GROUP_TOOL::Init(), PAD_TOOL::Init(), CONVERT_TOOL::Init(), SYMBOL_EDITOR_CONTROL::Init(), GLOBAL_EDIT_TOOL::Init(), PL_DRAWING_TOOLS::Init(), PL_POINT_EDITOR::Init(), ALIGN_DISTRIBUTE_TOOL::Init(), PCB_POINT_EDITOR::Init(), BOARD_EDITOR_CONTROL::Init(), POSITION_RELATIVE_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), BOARD_INSPECTION_TOOL::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), BOARD_INSPECTION_TOOL::InspectClearance(), BOARD_INSPECTION_TOOL::InspectConstraints(), EDIT_TOOL::invokeInlineRouter(), EDIT_TOOL::isInteractiveDragEnabled(), 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(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PCB_SELECTION_TOOL::Main(), BOARD_EDITOR_CONTROL::modifyLockSelected(), PROPERTIES_FRAME::OnAcceptPrms(), DIALOG_DRC::OnActivateDlg(), DIALOG_FOOTPRINT_CHECKER::OnCancelClick(), DIALOG_DRC::OnCancelClick(), DIALOG_INSPECTOR::onCellClicked(), DIALOG_POSITION_RELATIVE::OnClear(), DIALOG_ERC::OnCloseErcDialog(), DIALOG_DRC::OnDRCItemRClick(), SCH_EDIT_FRAME::OnImportProject(), DIALOG_POSITION_RELATIVE::OnOkClick(), DIALOG_PLOT::onRunDRC(), DIALOG_DRC::OnRunDRCClick(), DIALOG_POSITION_RELATIVE::OnSelectItemClick(), DIALOG_FIELDS_EDITOR_GLOBAL::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(), DIALOG_PLOT::Plot(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), PAD_TOOL::pushPadSettings(), KICAD_MANAGER_FRAME::ReCreateMenuBar(), GERBVIEW_FRAME::ReCreateMenuBar(), SYMBOL_VIEWER_FRAME::ReCreateMenuBar(), SYMBOL_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_VIEWER_FRAME::ReCreateMenuBar(), PL_EDITOR_FRAME::ReCreateMenuBar(), CVPCB_MAINFRAME::ReCreateMenuBar(), SCH_EDIT_FRAME::ReCreateMenuBar(), PCB_EDIT_FRAME::ReCreateMenuBar(), FOOTPRINT_EDIT_FRAME::ReCreateOptToolbar(), SCH_EDIT_FRAME::ReCreateOptToolbar(), SYMBOL_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateOptToolbar(), PCB_EDIT_FRAME::ReCreateVToolbar(), SYMBOL_EDITOR_EDIT_TOOL::Redo(), SCH_EDITOR_CONTROL::Redo(), SCH_BASE_FRAME::RefreshSelection(), GROUP_TOOL::RemoveFromGroup(), SYMBOL_EDITOR_DRAWING_TOOLS::RepeatDrawItem(), BOARD_COMMIT::Revert(), PL_EDITOR_FRAME::RollbackFromUndo(), SCH_EDIT_FRAME::RollbackSchematicFromUndo(), SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo(), DRC_TOOL::RunTests(), PCB_EDIT_FRAME::SaveProjectSettings(), FOOTPRINT_EDIT_FRAME::SaveSettings(), EDA_DRAW_FRAME::SaveSettings(), SCH_EDIT_FRAME::SaveSymbolToSchematic(), SCH_BASE_FRAME::SCH_BASE_FRAME(), SCH_EDIT_FRAME::SchematicCleanUp(), PCB_TOOL_BASE::selection(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), FOOTPRINT_EDIT_FRAME::setupTools(), CVPCB_MAINFRAME::setupTools(), EDA_DRAW_FRAME::setupUnits(), PCB_BASE_FRAME::ShowPadPropertiesDialog(), BOARD_EDITOR_CONTROL::TrackWidthDec(), BOARD_EDITOR_CONTROL::TrackWidthInc(), PANEL_3D_DISPLAY_OPTIONS::TransferDataFromWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), DIALOG_FIELDS_EDITOR_GLOBAL::TransferDataToWindow(), PANEL_3D_DISPLAY_OPTIONS::TransferDataToWindow(), DIALOG_LIB_EDIT_TEXT::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SYMBOL_EDITOR_EDIT_TOOL::Undo(), SCH_EDITOR_CONTROL::Undo(), GROUP_TOOL::Ungroup(), GROUP_CONTEXT_MENU::update(), SYMBOL_UNIT_MENU::update(), BUS_UNFOLD_MENU::update(), EE_INSPECTION_TOOL::UpdateMessagePanel(), GERBVIEW_CONTROL::UpdateMessagePanel(), PL_EDITOR_CONTROL::UpdateMessagePanel(), PCB_CONTROL::UpdateMessagePanel(), BOARD_INSPECTION_TOOL::UpdateSelectionRatsnest(), PCB_EDIT_FRAME::UpdateViaSizeSelectBox(), 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

Definition at line 285 of file tool_manager.h.

285 { return m_viewControls; }
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561

References m_viewControls.

Referenced by ZONE_CREATE_HELPER::createNewZone(), TOOL_DISPATCHER::DispatchWxEvent(), and TOOL_BASE::getViewControls().

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

569 {
570  for( TOOL_VEC::iterator it = m_toolOrder.begin(); it != m_toolOrder.end(); /* iter inside */ )
571  {
572  TOOL_BASE* tool = *it;
573  wxASSERT( m_toolState.count( tool ) );
574  TOOL_STATE* state = m_toolState[tool];
575  setActiveState( state );
576  ++it; // keep the iterator valid if the element is going to be erased
577 
578  if( !tool->Init() )
579  {
580  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER initialization of tool '%s' failed",
581  tool->GetName() );
582 
583  // Unregister the tool
584  setActiveState( nullptr );
585  m_toolState.erase( tool );
586  m_toolNameIndex.erase( tool->GetName() );
587  m_toolIdIndex.erase( tool->GetId() );
588  m_toolTypes.erase( typeid( *tool ).name() );
589 
590  delete state;
591  delete tool;
592  }
593  }
594 
595  m_actionMgr->UpdateHotKeys( true );
596 
598 }
virtual bool Init()
Init() is called once upon a registration of the tool.
Definition: tool_base.h:89
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:554
TOOL_VEC m_toolOrder
Index of registered tools current states, associated by tools' objects.
Definition: tool_manager.h:536
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
TOOL_ID GetId() const
Return the unique identifier of the tool.
Definition: tool_base.h:120
Tool is invoked after being inactive.
Definition: tool_base.h:79
void UpdateHotKeys(bool aFullUpdate)
Optionally read the hotkey config files and then rebuilds the internal hotkey maps.
NAME_STATE_MAP m_toolNameIndex
Index of the registered tools current states, associated by tools' ID numbers.
Definition: tool_manager.h:542
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
Base abstract interface for all kinds of tools.
Definition: tool_base.h:65
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:133
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539
std::map< const char *, TOOL_BASE * > m_toolTypes
Stack of the active tools.
Definition: tool_manager.h:548

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 FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), PL_EDITOR_FRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), SYMBOL_VIEWER_FRAME::setupTools(), KICAD_MANAGER_FRAME::setupTools(), CVPCB_MAINFRAME::setupTools(), SYMBOL_EDIT_FRAME::setupTools(), GERBVIEW_FRAME::setupTools(), and SCH_EDIT_FRAME::setupTools().

◆ InvokeTool() [1/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 253 of file tool_manager.cpp.

254 {
255  TOOL_BASE* tool = FindTool( aToolId );
256 
257  if( tool && tool->GetType() == INTERACTIVE )
258  return invokeTool( tool );
259 
260  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::InvokeTool - no tool with ID %d",
261  aToolId );
262 
263  return false; // there is no tool with the given id
264 }
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:108
TOOL_BASE * FindTool(int aId) const
Search for a tool with given ID.
Tool that interacts with the user.
Definition: tool_base.h:49
Base abstract interface for all kinds of tools.
Definition: tool_base.h:65
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
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.

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

◆ InvokeTool() [2/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 267 of file tool_manager.cpp.

268 {
269  TOOL_BASE* tool = FindTool( aToolName );
270 
271  if( tool && tool->GetType() == INTERACTIVE )
272  return invokeTool( tool );
273 
274  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::InvokeTool - no tool with name %s",
275  aToolName );
276 
277  return false; // there is no tool with the given name
278 }
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:108
TOOL_BASE * FindTool(int aId) const
Search for a tool with given ID.
Tool that interacts with the user.
Definition: tool_base.h:49
Base abstract interface for all kinds of tools.
Definition: tool_base.h:65
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
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 388 of file tool_manager.cpp.

389 {
390  wxASSERT( aTool != NULL );
391 
392  TOOL_EVENT evt( TC_COMMAND, TA_ACTIVATE, aTool->GetName() );
394  processEvent( evt );
395 
396  if( TOOL_STATE* active = GetCurrentToolState() )
397  setActiveState( active );
398 
399  return true;
400 }
bool processEvent(const TOOL_EVENT &aEvent)
Main function for event processing.
void SetMousePosition(const VECTOR2D &aP)
Definition: tool_event.h:460
VECTOR2D GetCursorPosition() const
#define NULL
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
Generic, UI-independent tool event.
Definition: tool_event.h:152
TOOL_STATE * GetCurrentToolState() const
Return the #TOOL_STATE object representing the state of the active tool.
Definition: tool_manager.h:322
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:133

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

Referenced by 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 1060 of file tool_manager.cpp.

1061 {
1062  if( !isRegistered( aTool ) )
1063  return false;
1064 
1065  // Just check if the tool is on the active tools stack
1066  return alg::contains( m_activeTools, aTool->GetId() );
1067 }
TOOL_ID GetId() const
Return the unique identifier of the tool.
Definition: tool_base.h:120
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:81
bool isRegistered(TOOL_BASE *aTool) const
Return information about a tool registration status.
Definition: tool_manager.h:495
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551

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

412  {
413  return m_menuActive;
414  }
bool m_menuActive
Tool currently displaying a popup menu. It is negative when there is no menu displayed.
Definition: tool_manager.h:574

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

496  {
497  return m_toolState.count( aTool ) > 0;
498  }
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539

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

1176 {
1177  auto it = m_toolIdIndex.find( aId );
1178  return !it->second->idle;
1179 }
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545

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

1041 {
1042  static int currentId;
1043 
1044  return currentId++;
1045 }

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

366 {
367  // Horrific hack, but it's a crash bug. Don't let inter-frame commands stack up
368  // waiting to be processed.
369  if( aEvent.IsSimulator() && m_eventQueue.size() > 0 && m_eventQueue.back().IsSimulator() )
370  m_eventQueue.pop_back();
371 
372  m_eventQueue.push_back( aEvent );
373 }
bool IsSimulator() const
Indicate if the event is from the simulator.
Definition: tool_event.cpp:245
std::list< TOOL_EVENT > m_eventQueue
Right click context menu position.
Definition: tool_manager.h:566

References TOOL_EVENT::IsSimulator(), and m_eventQueue.

Referenced by SCH_EDIT_FRAME::AddJunction(), SCH_MOVE_TOOL::AlignElements(), EDIT_TOOL::doMoveSelection(), SCH_EDIT_TOOL::editFieldText(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), GROUP_TOOL::Group(), PL_EDIT_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), SCH_MOVE_TOOL::Main(), SYMBOL_EDITOR_EDIT_TOOL::Mirror(), SCH_EDIT_TOOL::Mirror(), BOARD_EDITOR_CONTROL::modifyLockSelected(), TOOLS_HOLDER::PopTool(), PrimeTool(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), BOARD_COMMIT::Push(), GROUP_TOOL::RemoveFromGroup(), SYMBOL_EDITOR_EDIT_TOOL::Rotate(), SCH_EDIT_TOOL::Rotate(), RunAction(), SCH_DRAWING_TOOLS::SingleClickPlace(), DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataFromWindow(), GROUP_TOOL::Ungroup(), and EDA_DRAW_FRAME::UpdateMsgPanel().

◆ 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 eventReturn the hot key associated with a given action or 0 if there is none.
aActionis the queried action.

Definition at line 351 of file tool_manager.cpp.

352 {
353  int modifiers = 0;
354  modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
355  modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
356  modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
357 
358  TOOL_EVENT evt( TC_MOUSE, TA_PRIME, BUT_LEFT | modifiers );
359  evt.SetMousePosition( aPosition );
360 
361  PostEvent( evt );
362 }
Generic, UI-independent tool event.
Definition: tool_event.h:152
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.

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

Referenced by DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawZone(), and ROUTER_TOOL::MainLoop().

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

951 {
952  bool handled = processEvent( aEvent );
953 
954  TOOL_STATE* activeTool = GetCurrentToolState();
955 
956  if( activeTool )
957  setActiveState( activeTool );
958 
959  if( m_view && m_view->IsDirty() )
960  {
961  if( GetToolHolder() )
963 
964 #if defined( __WXMAC__ )
965  wxTheApp->ProcessPendingEvents(); // required for updating brightening behind a popup menu
966 #endif
967  }
968 
969  UpdateUI( aEvent );
970 
971  return handled;
972 }
void UpdateUI(const TOOL_EVENT &aEvent)
Update the status bar and synchronizes toolbars.
bool processEvent(const TOOL_EVENT &aEvent)
Main function for event processing.
virtual void RefreshCanvas()
Definition: tools_holder.h:151
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
TOOL_STATE * GetCurrentToolState() const
Return the #TOOL_STATE object representing the state of the active tool.
Definition: tool_manager.h:322
KIGFX::VIEW * m_view
Definition: tool_manager.h:560
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:294
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
Definition: view.h:547

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

Referenced by PL_SELECTION_TOOL::AddItemsToSel(), EE_SELECTION_TOOL::AddItemsToSel(), PL_SELECTION_TOOL::AddItemToSel(), PCB_SELECTION_TOOL::AddItemToSel(), EE_SELECTION_TOOL::AddItemToSel(), EDIT_TOOL::ChangeTrackWidth(), PL_SELECTION_TOOL::ClearSelection(), PCB_SELECTION_TOOL::ClearSelection(), GERBVIEW_SELECTION_TOOL::clearSelection(), EE_SELECTION_TOOL::ClearSelection(), PANEL_KICAD_LAUNCHER::CreateLaunchers(), COMMON_TOOLS::CursorControl(), TOOL_DISPATCHER::DispatchWxEvent(), PCB_TOOL_BASE::doInteractiveItemPlacement(), PCB_SELECTION_TOOL::expandConnection(), PCB_SELECTION_TOOL::filterSelection(), PCB_SELECTION_TOOL::findCallback(), EDIT_TOOL::Flip(), TOOL_DISPATCHER::handleMouseButton(), SYMBOL_EDITOR_MOVE_TOOL::Main(), EE_SELECTION_TOOL::Main(), PCB_SELECTION_TOOL::Main(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), 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(), PL_SELECTION_TOOL::RemoveItemFromSel(), EE_SELECTION_TOOL::RemoveItemFromSel(), PCB_SELECTION_TOOL::RemoveItemFromSel(), PL_SELECTION_TOOL::RemoveItemsFromSel(), EE_SELECTION_TOOL::RemoveItemsFromSel(), EE_SELECTION_TOOL::RequestSelection(), EDIT_TOOL::Rotate(), EE_SELECTION_TOOL::SelectConnection(), COMMON_TOOLS::SelectionTool(), GERBVIEW_SELECTION_TOOL::SelectItem(), GERBVIEW_SELECTION_TOOL::SelectItems(), PCB_SELECTION_TOOL::SelectItems(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectNet(), PL_SELECTION_TOOL::SelectPoint(), GERBVIEW_SELECTION_TOOL::selectPoint(), EE_SELECTION_TOOL::selectPoint(), PCB_SELECTION_TOOL::selectPoint(), PCB_SELECTION_TOOL::selectSameSheet(), PCB_SELECTION_TOOL::selectSheetContents(), SCH_EDITOR_CONTROL::Undo(), GERBVIEW_SELECTION_TOOL::UnselectItem(), GERBVIEW_SELECTION_TOOL::UnselectItems(), and PCB_SELECTION_TOOL::UnselectItems().

◆ processEvent()

bool TOOL_MANAGER::processEvent ( const TOOL_EVENT aEvent)
private

Main function for event processing.

Returns
true if a hotkey was handled.

Definition at line 1116 of file tool_manager.cpp.

1117 {
1118  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::processEvent - %s", aEvent.Format() );
1119 
1120  // First try to dispatch the action associated with the event if it is a key press event
1121  bool handled = DispatchHotKey( aEvent );
1122 
1123  if( !handled )
1124  {
1125  TOOL_EVENT mod_event( aEvent );
1126 
1127  // Only immediate actions get the position. Otherwise clear for tool activation
1128  if( GetToolHolder() && !GetToolHolder()->GetDoImmediateActions() )
1129  {
1130  // An tool-selection-event has no position
1131  if( mod_event.GetCommandStr().is_initialized()
1132  && mod_event.GetCommandStr().get() != GetToolHolder()->CurrentToolName()
1133  && !mod_event.ForceImmediate() )
1134  {
1135  mod_event.SetHasPosition( false );
1136  }
1137  }
1138 
1139  // If the event is not handled through a hotkey activation, pass it to the currently
1140  // running tool loops
1141  handled |= dispatchInternal( mod_event );
1142  handled |= dispatchActivation( mod_event );
1143 
1144  // Open the context menu if requested by a tool
1145  DispatchContextMenu( mod_event );
1146 
1147  // Dispatch any remaining events in the event queue
1148  while( !m_eventQueue.empty() )
1149  {
1150  TOOL_EVENT event = m_eventQueue.front();
1151  m_eventQueue.pop_front();
1152  processEvent( event );
1153  }
1154  }
1155 
1156  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::processEvent - %s handle event: %s",
1157  ( handled ? "Did" : "Did not" ), aEvent.Format() );
1158 
1159  return handled;
1160 }
void DispatchContextMenu(const TOOL_EVENT &aEvent)
Handle context menu related events.
const std::string Format() const
Return information about event in form of a human-readable string.
Definition: tool_event.cpp:94
bool processEvent(const TOOL_EVENT &aEvent)
Main function for event processing.
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 DispatchHotKey(const TOOL_EVENT &aEvent)
Handle specific events, that are intended for TOOL_MANAGER rather than tools.
Generic, UI-independent tool event.
Definition: tool_event.h:152
std::string CurrentToolName() const
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:294
std::list< TOOL_EVENT > m_eventQueue
Right click context menu position.
Definition: tool_manager.h:566
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.

References TOOLS_HOLDER::CurrentToolName(), dispatchActivation(), DispatchContextMenu(), DispatchHotKey(), dispatchInternal(), TOOL_EVENT::ForceImmediate(), TOOL_EVENT::Format(), TOOL_EVENT::GetCommandStr(), GetToolHolder(), kicadTraceToolStack, m_eventQueue, and TOOL_EVENT::SetHasPosition().

Referenced by CancelTool(), DeactivateTool(), invokeTool(), 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 231 of file tool_manager.cpp.

232 {
233  wxASSERT_MSG( m_toolNameIndex.find( aTool->GetName() ) == m_toolNameIndex.end(),
234  wxT( "Adding two tools with the same name may result in unexpected behaviour.") );
235  wxASSERT_MSG( m_toolIdIndex.find( aTool->GetId() ) == m_toolIdIndex.end(),
236  wxT( "Adding two tools with the same ID may result in unexpected behaviour.") );
237  wxASSERT_MSG( m_toolTypes.find( typeid( *aTool ).name() ) == m_toolTypes.end(),
238  wxT( "Adding two tools of the same type may result in unexpected behaviour.") );
239 
240  m_toolOrder.push_back( aTool );
241 
242  TOOL_STATE* st = new TOOL_STATE( aTool );
243 
244  m_toolState[aTool] = st;
245  m_toolNameIndex[aTool->GetName()] = st;
246  m_toolIdIndex[aTool->GetId()] = st;
247  m_toolTypes[typeid( *aTool ).name()] = st->theTool;
248 
249  aTool->attachManager( this );
250 }
TOOL_VEC m_toolOrder
Index of registered tools current states, associated by tools' objects.
Definition: tool_manager.h:536
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
TOOL_ID GetId() const
Return the unique identifier of the tool.
Definition: tool_base.h:120
void attachManager(TOOL_MANAGER *aManager)
Set the TOOL_MANAGER the tool will belong to.
Definition: tool_base.cpp:60
NAME_STATE_MAP m_toolNameIndex
Index of the registered tools current states, associated by tools' ID numbers.
Definition: tool_manager.h:542
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:133
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539
std::map< const char *, TOOL_BASE * > m_toolTypes
Stack of the active tools.
Definition: tool_manager.h:548

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 FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), PL_EDITOR_FRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), SYMBOL_VIEWER_FRAME::setupTools(), KICAD_MANAGER_FRAME::setupTools(), CVPCB_MAINFRAME::setupTools(), SYMBOL_EDIT_FRAME::setupTools(), GERBVIEW_FRAME::setupTools(), and SCH_EDIT_FRAME::setupTools().

◆ ResetTools()

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

Reset all tools (i.e.

calls their Reset() method).

Definition at line 552 of file tool_manager.cpp.

553 {
554  DeactivateTool();
555 
556  for( auto& state : m_toolState )
557  {
558  TOOL_BASE* tool = state.first;
559  setActiveState( state.second );
560  tool->Reset( aReason );
561 
562  if( tool->GetType() == INTERACTIVE )
563  static_cast<TOOL_INTERACTIVE*>( tool )->resetTransitions();
564  }
565 }
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:108
void DeactivateTool()
Deactivate the currently active tool.
virtual void Reset(RESET_REASON aReason)=0
Bring the tool to a known, initial state.
Tool that interacts with the user.
Definition: tool_base.h:49
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
Base abstract interface for all kinds of tools.
Definition: tool_base.h:65
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539

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

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

◆ RunAction() [1/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 143 of file tool_manager.h.

144  {
145  return RunAction( aActionName, aNow, reinterpret_cast<void*>( aParam ) );
146  }
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143

Referenced by PROJECT_TREE_ITEM::Activate(), FOOTPRINT_VIEWER_FRAME::AddFootprintToPCB(), SYMBOL_EDITOR_CONTROL::AddSymbolToSchematic(), SCH_MOVE_TOOL::AlignElements(), APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), CVPCB_ASSOCIATION_TOOL::Associate(), SCH_EDIT_TOOL::AutoplaceFields(), SCH_EDIT_TOOL::BreakWire(), SCH_EDIT_FRAME::canCloseWindow(), ROUTER_TOOL::CanInlineDrag(), SCH_EDIT_TOOL::ChangeTextType(), EDIT_TOOL::ChangeTrackWidth(), SCH_EDIT_TOOL::CleanupSheetPins(), GERBVIEW_CONTROL::ClearAllLayers(), PCB_SELECTION_TOOL::ClearSelection(), ZONE_CREATE_HELPER::commitZone(), 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::DClickOnCmpList(), DIALOG_FOOTPRINT_CHECKER::deleteAllMarkers(), DIALOG_ERC::deleteAllMarkers(), DIALOG_DRC::deleteAllMarkers(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_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(), SYMBOL_EDITOR_EDIT_TOOL::DoDelete(), SCH_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), DIALOG_GLOBAL_DELETION::doGlobalDeletions(), SCH_FIELD::DoHypertextMenu(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EDIT_TOOL::doMoveSelection(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawRectangle(), DRAWING_TOOL::drawSegment(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::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(), SCH_NAVIGATE_TOOL::EnterSheet(), SCH_EDITOR_CONTROL::EnterSheet(), PAD_TOOL::EnumeratePads(), TRACK_WIDTH_MENU::eventHandler(), DIFF_PAIR_MENU::eventHandler(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), SCH_EDIT_FRAME::ExecuteRemoteCommand(), PAD_TOOL::explodePad(), SCH_EDITOR_CONTROL::FindSymbolAndItem(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), SCH_EDIT_FRAME::FixupJunctions(), EDIT_TOOL::Flip(), GERBVIEW_FRAME::GERBVIEW_FRAME(), EDIT_TOOL::GetAndPlace(), DRAWING_TOOL::getSourceZoneForAction(), SYMBOL_EDIT_FRAME::GetSymbolFromRedoList(), SYMBOL_EDIT_FRAME::GetSymbolFromUndoList(), PCB_CONTROL::GridSetOrigin(), BOARD_INSPECTION_TOOL::HighlightItem(), SCH_EDITOR_CONTROL::HighlightNetCursor(), SCH_NAVIGATE_TOOL::HypertextCommand(), 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(), EDIT_TOOL::invokeInlineRouter(), PCB_EDIT_FRAME::KiwayMailIn(), SCH_EDIT_FRAME::KiwayMailIn(), SCH_NAVIGATE_TOOL::LeaveSheet(), SCH_EDITOR_CONTROL::LeaveSheet(), SYMBOL_EDIT_FRAME::LoadOneLibrarySymbolAux(), SYMBOL_EDIT_FRAME::LoadSymbolFromCurrentLib(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PL_EDIT_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), CVPCB_CONTROL::Main(), SCH_MOVE_TOOL::Main(), PL_SELECTION_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), PCB_SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), SYMBOL_EDITOR_EDIT_TOOL::Mirror(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::Mirror(), BOARD_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::MoveExact(), DIALOG_GROUP_PROPERTIES::OnAddMember(), DIALOG_FOOTPRINT_CHECKER::OnDeleteOneClick(), DIALOG_DRC::OnDeleteOneClick(), SYMBOL_EDITOR_CONTROL::OnDeMorgan(), PCB_EDIT_FRAME::OnEditItemRequest(), DIALOG_ERC::OnERCItemSelected(), DIALOG_CONSTRAINTS_REPORTER::OnErrorLinkClicked(), DIALOG_INSPECTION_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(), PL_EDITOR_FRAME::OnNewDrawingSheet(), PANEL_PCBNEW_ACTION_PLUGINS::OnOpenDirectoryButtonClick(), KICAD_MANAGER_FRAME::OnOpenFileInTextEditor(), SIM_PLOT_FRAME::onProbe(), PANEL_PCBNEW_ACTION_PLUGINS::OnReloadButtonClick(), EDA_DRAW_FRAME::OnSelectGrid(), DIALOG_POSITION_RELATIVE::OnSelectItemClick(), HIERARCHY_NAVIG_DLG::onSelectSheetPath(), SYMBOL_EDIT_FRAME::OnSelectUnit(), EDA_DRAW_FRAME::OnSelectZoom(), SCH_EDIT_FRAME::onSize(), SYMBOL_TREE_PANE::onSymbolSelected(), SIM_PLOT_FRAME::onTune(), PCB_EDIT_FRAME::OpenProjectFiles(), SCH_EDIT_FRAME::OpenProjectFiles(), PL_EDIT_TOOL::Paste(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), ROUTER_TOOL::performRouting(), 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::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), PCB_CONTROL::Print(), GERBVIEW_CONTROL::Print(), SYMBOL_EDITOR_EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), SCH_EDIT_FRAME::PutDataInPreviousState(), FOOTPRINT_WIZARD_FRAME::PythonPluginsReload(), CVPCB_MAINFRAME::refreshAfterSymbolSearch(), 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(), PL_EDITOR_FRAME::RollbackFromUndo(), SYMBOL_EDIT_FRAME::RollbackSymbolFromUndo(), SYMBOL_EDITOR_EDIT_TOOL::Rotate(), SCH_EDIT_TOOL::Rotate(), EDIT_TOOL::Rotate(), RunAction(), ACTION_MANAGER::RunHotKey(), FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard(), SYMBOL_EDIT_FRAME::saveLibrary(), SCH_EDIT_FRAME::SaveSymbolToSchematic(), DIALOG_FIND::search(), PL_SELECTION_TOOL::SelectPoint(), EE_SELECTION_TOOL::selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), GERBVIEW_FRAME::SetActiveLayer(), DRAWING_TOOL::SetAnchor(), SYMBOL_EDIT_FRAME::SetCurSymbol(), SCH_EDIT_FRAME::SetScreen(), SYMBOL_VIEWER_FRAME::SetSelectedSymbol(), CVPCB_MAINFRAME::setupEventHandlers(), SCH_EDIT_FRAME::setupTools(), EDA_DRAW_FRAME::setupUnits(), DRC_TOOL::ShowDRCDialog(), APPEARANCE_CONTROLS::showNetclass(), SCH_DRAWING_TOOLS::SingleClickPlace(), 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(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), GROUP_TOOL::Ungroup(), EDA_DRAW_FRAME::unitsChangeRefresh(), NET_GRID_TABLE::updateNetVisibility(), DISPLAY_FOOTPRINTS_FRAME::updateView(), FOOTPRINT_WIZARD_FRAME::updateView(), FOOTPRINT_VIEWER_FRAME::updateView(), BOARD_EDITOR_CONTROL::ViaSizeDec(), BOARD_EDITOR_CONTROL::ViaSizeInc(), BOARD_EDITOR_CONTROL::ZoneMerge(), EDA_DRAW_FRAME::Zoom_Automatique(), DIALOG_NETLIST::~DIALOG_NETLIST(), and DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB().

◆ RunAction() [2/6]

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

Definition at line 281 of file tool_manager.cpp.

282 {
283  TOOL_ACTION* action = m_actionMgr->FindAction( aActionName );
284 
285  if( !action )
286  {
287  wxASSERT_MSG( false, wxString::Format( "Could not find action %s.", aActionName ) );
288  return false;
289  }
290 
291  RunAction( *action, aNow, aParam );
292 
293  return false;
294 }
ACTION_MANAGER * m_actionMgr
Original cursor position, if overridden by the context menu handler.
Definition: tool_manager.h:554
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
TOOL_ACTION * FindAction(const std::string &aActionName) const
Find an action with a given name (if there is one available).
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
Represent a single user action.
Definition: tool_action.h:67

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

◆ RunAction() [3/6]

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

Definition at line 150 of file tool_manager.h.

151  {
152  return RunAction( aActionName, aNow, (void*) NULL );
153  }
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
#define NULL

References NULL, and RunAction().

◆ RunAction() [4/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 169 of file tool_manager.h.

170  {
171  return RunAction( aAction, aNow, reinterpret_cast<void*>( aParam ) );
172  }
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143

References RunAction().

◆ RunAction() [5/6]

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

Definition at line 315 of file tool_manager.cpp.

316 {
317  bool handled = false;
318  TOOL_EVENT event = aAction.MakeEvent();
319 
320  if( event.Category() == TC_COMMAND )
322 
323  // Allow to override the action parameter
324  if( aParam )
325  event.SetParameter( aParam );
326 
327  if( aNow )
328  {
329  TOOL_STATE* current = m_activeState;
330  handled = processEvent( event );
331  setActiveState( current );
332  UpdateUI( event );
333  }
334  else
335  {
336  PostEvent( event );
337  }
338 
339  return handled;
340 }
void UpdateUI(const TOOL_EVENT &aEvent)
Update the status bar and synchronizes toolbars.
bool processEvent(const TOOL_EVENT &aEvent)
Main function for event processing.
void SetMousePosition(const VECTOR2D &aP)
Definition: tool_event.h:460
VECTOR2D GetCursorPosition() const
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
Generic, UI-independent tool event.
Definition: tool_event.h:152
TOOL_STATE * m_activeState
Definition: tool_manager.h:580
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.cpp:72
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.

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

◆ RunAction() [6/6]

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

Definition at line 176 of file tool_manager.h.

177  {
178  return RunAction( aAction, aNow, (void*) NULL );
179  }
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
#define NULL

References NULL, and RunAction().

◆ RunMainStack()

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

Definition at line 632 of file tool_manager.cpp.

633 {
634  TOOL_STATE* st = m_toolState[aTool];
635  setActiveState( st );
636  st->cofunc->RunMainStack( std::move( aFunc ) );
637 }
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539

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

404 {
405  wxASSERT( aTool != NULL );
406 
407  if( !isRegistered( aTool ) )
408  {
409  wxASSERT_MSG( false, wxT( "You cannot run unregistered tools" ) );
410  return false;
411  }
412 
413  TOOL_ID id = aTool->GetId();
414 
415  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::runTool - running tool %s",
416  aTool->GetName() );
417 
418  if( aTool->GetType() == INTERACTIVE )
419  static_cast<TOOL_INTERACTIVE*>( aTool )->resetTransitions();
420 
421  // If the tool is already active, bring it to the top of the active tools stack
422  if( isActive( aTool ) && m_activeTools.size() > 1 )
423  {
424  auto it = std::find( m_activeTools.begin(), m_activeTools.end(), id );
425 
426  if( it != m_activeTools.end() )
427  {
428  if( it != m_activeTools.begin() )
429  {
430  m_activeTools.erase( it );
431  m_activeTools.push_front( id );
432  }
433 
434  return false;
435  }
436  }
437 
439  aTool->Reset( TOOL_INTERACTIVE::RUN );
440 
441  // Add the tool on the front of the processing queue (it gets events first)
442  m_activeTools.push_front( id );
443 
444  return true;
445 }
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:108
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
TOOL_ID GetId() const
Return the unique identifier of the tool.
Definition: tool_base.h:120
Tool is invoked after being inactive.
Definition: tool_base.h:79
virtual void Reset(RESET_REASON aReason)=0
Bring the tool to a known, initial state.
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
Tool that interacts with the user.
Definition: tool_base.h:49
#define NULL
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
bool isActive(TOOL_BASE *aTool) const
Return information about a tool activation status.
bool isRegistered(TOOL_BASE *aTool) const
Return information about a tool registration status.
Definition: tool_manager.h:495
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
const std::string & GetName() const
Return the name of the tool.
Definition: tool_base.h:133
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551

References TOOL_BASE::GetId(), TOOL_BASE::GetName(), TOOL_BASE::GetType(), INTERACTIVE, isActive(), isRegistered(), kicadTraceToolStack, m_activeTools, m_toolIdIndex, NULL, 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 985 of file tool_manager.cpp.

986 {
987  wxLogNull doNotLog; // disable logging of failed clipboard actions
988 
989  if( wxTheClipboard->Open() )
990  {
991  // Store the UTF8 string as unicode string in clipboard:
992  wxTheClipboard->SetData( new wxTextDataObject( wxString( aTextUTF8.c_str(),
993  wxConvUTF8 ) ) );
994 
995  wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
996  wxTheClipboard->Close();
997 
998  return true;
999  }
1000 
1001  return false;
1002 }

Referenced by PL_EDIT_TOOL::Copy(), SYMBOL_EDITOR_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 1070 of file tool_manager.cpp.

1071 {
1072  aState->vcSettings = m_viewControls->GetSettings();
1073 
1074  if( m_menuActive )
1075  {
1076  // Context menu is active, so the cursor settings are overridden (see DispatchContextMenu())
1077  auto it = m_cursorSettings.find( aState->theTool->GetId() );
1078 
1079  if( it != m_cursorSettings.end() )
1080  {
1082 
1083  // Tool has overridden the cursor position, so store the new settings
1084  if( !curr.m_forceCursorPosition || curr.m_forcedPosition != m_menuCursor )
1085  {
1086  if( !curr.m_forceCursorPosition )
1087  it->second = NULLOPT;
1088  else
1089  it->second = curr.m_forcedPosition;
1090  }
1091  else
1092  {
1093  OPT<VECTOR2D> cursor = it->second;
1094 
1095  if( cursor )
1096  {
1097  aState->vcSettings.m_forceCursorPosition = true;
1098  aState->vcSettings.m_forcedPosition = *cursor;
1099  }
1100  else
1101  {
1102  aState->vcSettings.m_forceCursorPosition = false;
1103  }
1104  }
1105  }
1106  }
1107 }
bool m_menuActive
Tool currently displaying a popup menu. It is negative when there is no menu displayed.
Definition: tool_manager.h:574
VECTOR2D m_menuCursor
Definition: tool_manager.h:569
std::map< TOOL_ID, OPT< VECTOR2D > > m_cursorSettings
Definition: tool_manager.h:557
VECTOR2D m_forcedPosition
Is the forced cursor position enabled.
Definition: view_controls.h:55
const VC_SETTINGS & GetSettings() const
Apply VIEW_CONTROLS settings from an object.
const auto NULLOPT
Definition: optional.h:9
bool m_forceCursorPosition
Should the cursor be locked within the parent window area.
Definition: view_controls.h:58
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
Definition: view_controls.h:41
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561
boost::optional< T > OPT
Definition: optional.h:7

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, NULLOPT, 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 975 of file tool_manager.cpp.

977 {
978  TOOL_STATE* st = m_toolState[aTool];
979 
980  st->contextMenu = aMenu;
981  st->contextMenuTrigger = aTrigger;
982 }
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539

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

619 {
620  TOOL_STATE* st = m_toolState[aTool];
621 
622  st->transitions.emplace_back( TRANSITION( aConditions, aHandler ) );
623 }
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539
std::pair< TOOL_EVENT_LIST, TOOL_STATE_FUNC > TRANSITION
Definition: tool_manager.h:446

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

641 {
642  TOOL_STATE* st = m_toolState[aTool];
643 
644  wxASSERT( !st->pendingWait ); // everything collapses on two KiYield() in a row
645 
646  // indicate to the manager that we are going to sleep and we shall be
647  // woken up when an event matching aConditions arrive
648  st->pendingWait = true;
649  st->waitEvents = aConditions;
650 
651  // switch context back to event dispatcher loop
652  st->cofunc->KiYield();
653 
654  // If the tool should shutdown, it gets a null event to break the loop
655  if( st->shutdown )
656  return nullptr;
657  else
658  return &st->wakeupEvent;
659 }
TOOL_STATE_MAP m_toolState
Index of the registered tools current states, associated by tools' names.
Definition: tool_manager.h:539

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

1164 {
1165  if( m_activeState && m_viewControls )
1167 
1168  m_activeState = aState;
1169 
1170  if( m_activeState && m_viewControls )
1171  applyViewControls( aState );
1172 }
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561
TOOL_STATE * m_activeState
Definition: tool_manager.h:580
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()

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

1051 {
1052  m_model = aModel;
1053  m_view = aView;
1054  m_viewControls = aViewControls;
1055  m_frame = aFrame;
1056  m_settings = aSettings;
1057 }
TOOLS_HOLDER * m_frame
Definition: tool_manager.h:562
EDA_ITEM * m_model
Definition: tool_manager.h:559
KIGFX::VIEW_CONTROLS * m_viewControls
Definition: tool_manager.h:561
KIGFX::VIEW * m_view
Definition: tool_manager.h:560
APP_SETTINGS_BASE * m_settings
Queue that stores events to be processed at the end of the event processing cycle.
Definition: tool_manager.h:563

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

Referenced by GERBVIEW_FRAME::ActivateGalCanvas(), PCB_BASE_FRAME::ActivateGalCanvas(), DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME(), EVT_GRID_CMD_CELL_CHANGED(), EVT_TOOL_RANGE(), FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME(), PANEL_PREVIEW_3D_MODEL::PANEL_PREVIEW_3D_MODEL(), PCB_BASE_EDIT_FRAME::SetBoard(), PL_EDITOR_FRAME::setupTools(), FOOTPRINT_EDIT_FRAME::setupTools(), SYMBOL_VIEWER_FRAME::setupTools(), KICAD_MANAGER_FRAME::setupTools(), CVPCB_MAINFRAME::setupTools(), SYMBOL_EDIT_FRAME::setupTools(), GERBVIEW_FRAME::setupTools(), PCB_EDIT_FRAME::setupTools(), and SCH_EDIT_FRAME::setupTools().

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

449 {
450  // Create a temporary list of tools to iterate over since when the tools shutdown
451  // they remove themselves from the list automatically (invalidating the iterator)
452  ID_LIST tmpList = m_activeTools;
453 
454  for( auto id : tmpList )
455  {
456  ShutdownTool( id );
457  }
458 }
void ShutdownTool(TOOL_BASE *aTool)
Shutdown the specified tool by waking it up with a null event to terminate the processing loop.
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551
std::list< TOOL_ID > ID_LIST
Definition: tool_manager.h:68

References m_activeTools, 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(), 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 ( 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 485 of file tool_manager.cpp.

486 {
487  wxASSERT( aTool != NULL );
488 
489  TOOL_ID id = aTool->GetId();
490 
491  if( isActive( aTool ) )
492  {
493  TOOL_MANAGER::ID_LIST::iterator it = std::find( m_activeTools.begin(), m_activeTools.end(), id );
494 
495  TOOL_STATE* st = m_toolIdIndex[*it];
496 
497  // the tool state handler is waiting for events (i.e. called Wait() method)
498  if( st && st->pendingWait )
499  {
500  // Wake up the tool and tell it to shutdown
501  st->shutdown = true;
502  st->pendingWait = false;
503  st->waitEvents.clear();
504 
505  if( st->cofunc )
506  {
507  wxLogTrace( kicadTraceToolStack,
508  "TOOL_MANAGER::ShutdownTool - Shutting down tool %s",
509  st->theTool->GetName() );
510 
511  setActiveState( st );
512  bool end = !st->cofunc->Resume();
513 
514  if( end )
515  finishTool( st );
516  }
517  }
518  }
519 }
ID_STATE_MAP m_toolIdIndex
Index of the registered tools to easily lookup by their type.
Definition: tool_manager.h:545
TOOL_ID GetId() const
Return the unique identifier of the tool.
Definition: tool_base.h:120
ID_LIST::iterator finishTool(TOOL_STATE *aState)
Deactivate a tool and does the necessary clean up.
int TOOL_ID
Unique identifier for tools.
Definition: tool_base.h:56
#define NULL
void setActiveState(TOOL_STATE *aState)
Save the previous active state and sets a new one.
bool isActive(TOOL_BASE *aTool) const
Return information about a tool activation status.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
ID_LIST m_activeTools
Instance of ACTION_MANAGER that handles TOOL_ACTIONs.
Definition: tool_manager.h:551

References finishTool(), TOOL_BASE::GetId(), isActive(), kicadTraceToolStack, m_activeTools, m_toolIdIndex, NULL, and setActiveState().

Referenced by ShutdownAllTools(), and ShutdownTool().

◆ ShutdownTool() [2/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 461 of file tool_manager.cpp.

462 {
463  TOOL_BASE* tool = FindTool( aToolId );
464 
465  if( tool && tool->GetType() == INTERACTIVE )
466  ShutdownTool( tool );
467 
468  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::ShutdownTool - no tool with ID %d",
469  aToolId );
470 }
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:108
TOOL_BASE * FindTool(int aId) const
Search for a tool with given ID.
void ShutdownTool(TOOL_BASE *aTool)
Shutdown the specified tool by waking it up with a null event to terminate the processing loop.
Tool that interacts with the user.
Definition: tool_base.h:49
Base abstract interface for all kinds of tools.
Definition: tool_base.h:65
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.

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

◆ ShutdownTool() [3/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 473 of file tool_manager.cpp.

474 {
475  TOOL_BASE* tool = FindTool( aToolName );
476 
477  if( tool && tool->GetType() == INTERACTIVE )
478  ShutdownTool( tool );
479 
480  wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::ShutdownTool - no tool with name %s",
481  aToolName );
482 }
TOOL_TYPE GetType() const
Return the type of the tool.
Definition: tool_base.h:108
TOOL_BASE * FindTool(int aId) const
Search for a tool with given ID.
void ShutdownTool(TOOL_BASE *aTool)
Shutdown the specified tool by waking it up with a null event to terminate the processing loop.
Tool that interacts with the user.
Definition: tool_base.h:49
Base abstract interface for all kinds of tools.
Definition: tool_base.h:65
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.

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

◆ UpdateUI()

void TOOL_MANAGER::UpdateUI ( const TOOL_EVENT aEvent)

Update the status bar and synchronizes toolbars.

Definition at line 1182 of file tool_manager.cpp.

1183 {
1184  EDA_BASE_FRAME* frame = dynamic_cast<EDA_BASE_FRAME*>( GetToolHolder() );
1185 
1186  if( frame )
1187  frame->UpdateStatusBar();
1188 }
virtual void UpdateStatusBar()
Update the status bar information.
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:294
The base frame for deriving all KiCad main window classes.

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

Referenced by ProcessEvent(), and RunAction().

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

423  {
425  }
bool m_warpMouseAfterContextMenu
Flag indicating whether a context menu is currently displayed.
Definition: tool_manager.h:571

References m_warpMouseAfterContextMenu.

Referenced by DIALOG_SHIM::DIALOG_SHIM(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), LIB_TREE::onContextMenu(), SCH_DRAWING_TOOLS::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), and SCH_DRAWING_TOOLS::TwoClickPlace().

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

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

◆ m_activeState

TOOL_STATE* TOOL_MANAGER::m_activeState
private

Definition at line 580 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, OPT<VECTOR2D> > TOOL_MANAGER::m_cursorSettings
private

Definition at line 557 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 566 of file tool_manager.h.

Referenced by PostEvent(), and processEvent().

◆ m_frame

TOOLS_HOLDER* TOOL_MANAGER::m_frame
private

Definition at line 562 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 574 of file tool_manager.h.

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

◆ m_menuCursor

VECTOR2D TOOL_MANAGER::m_menuCursor
private

Definition at line 569 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 577 of file tool_manager.h.

Referenced by DispatchContextMenu(), and dispatchInternal().

◆ m_model

EDA_ITEM* TOOL_MANAGER::m_model
private

Definition at line 559 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 563 of file tool_manager.h.

Referenced by GetSettings(), and SetEnvironment().

◆ m_toolIdIndex

ID_STATE_MAP TOOL_MANAGER::m_toolIdIndex
private

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

Definition at line 545 of file tool_manager.h.

Referenced by DispatchContextMenu(), dispatchInternal(), FindTool(), GetCurrentToolState(), InitTools(), IsToolActive(), RegisterTool(), runTool(), 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 542 of file tool_manager.h.

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

◆ m_toolOrder

TOOL_VEC TOOL_MANAGER::m_toolOrder
private

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

Definition at line 536 of file tool_manager.h.

Referenced by InitTools(), and RegisterTool().

◆ m_toolState

TOOL_STATE_MAP TOOL_MANAGER::m_toolState
private

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

Definition at line 539 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 548 of file tool_manager.h.

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

◆ m_view

KIGFX::VIEW* TOOL_MANAGER::m_view
private

Definition at line 560 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 571 of file tool_manager.h.

Referenced by DispatchContextMenu(), and VetoContextMenuMouseWarp().


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