36#include <wx/clipbrd.h>
163 auto state = std::make_unique<TOOL_STATE>( *
this );
214 m_viewControls( nullptr ),
216 m_settings( nullptr ),
217 m_warpMouseAfterContextMenu( true ),
218 m_menuActive( false ),
220 m_activeState( nullptr ),
221 m_shuttingDown( false )
229 std::map<TOOL_BASE*, TOOL_STATE*>::iterator it, it_end;
233 delete it->second->cofunc;
245 wxT(
"Adding two tools with the same name may result in unexpected behavior.") );
247 wxT(
"Adding two tools with the same ID may result in unexpected behavior.") );
249 wxT(
"Adding two tools of the same type may result in unexpected behavior.") );
252 wxS(
"TOOL_MANAGER::RegisterTool: Registering tool %s with ID %d" ),
303 wxASSERT_MSG(
false, wxString::Format(
"Could not find action %s.", aActionName ) );
332 COMMIT* aCommit,
bool aFromAPI )
345 event.SetParameter( aParam );
356 std::atomic<SYNCRONOUS_TOOL_STATE> synchronousControl =
STS_FINISHED;
358 event.SetSynchronous( &synchronousControl );
359 event.SetCommit( aCommit );
390 wxASSERT_MSG( aFromAPI, wxT(
"Deferred actions have no way of guaranteeing the "
391 "lifetime of the COMMIT object" ) );
392 event.SetCommit( aCommit );
449 wxASSERT( aTool !=
nullptr );
464 wxASSERT( aTool !=
nullptr );
466 wxString msg = wxString::Format( wxS(
"TOOL_MANAGER::runTool - running tool %s" ), aTool->
GetName() );
471 wxASSERT_MSG(
false, wxT(
"You cannot run unregistered tools" ) );
520 for(
auto id : tmpList )
528 for(
auto id : tmpList )
554 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::ShutdownTool - no tool with name %s" ),
561 wxASSERT( aTool !=
nullptr );
567 TOOL_MANAGER::ID_LIST::iterator it = std::find(
m_activeTools.begin(),
583 wxS(
"TOOL_MANAGER::ShutdownTool - Shutting down tool %s" ),
599 std::map<TOOL_ID, TOOL_STATE*>::const_iterator it =
m_toolIdIndex.find( aId );
602 return it->second->theTool;
610 std::map<std::string, TOOL_STATE*>::const_iterator it =
m_toolNameIndex.find( aName );
613 return it->second->theTool;
640 tool->
Reset( aReason );
661 wxS(
"TOOL_MANAGER initialization of tool '%s' failed" ),
688 if( tool == aToolId )
733 wxCHECK( st->
cofunc,
nullptr );
748 bool handled =
false;
750 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::dispatchInternal - received event: %s" ),
759 bool increment =
true;
786 wxS(
"TOOL_MANAGER::dispatchInternal - Waking tool %s for event: %s" ),
802 wxS(
"TOOL_MANAGER::dispatchInternal - tool %s stopped passing "
817 bool finished =
false;
825 if( tr.first.Matches( aEvent ) )
827 auto func_copy = tr.second;
838 st->
vcSettings = std::move( viewControlSettings );
844 wxS(
"TOOL_MANAGER::dispatchInternal - Running tool %s for "
871 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::dispatchInternal - %s handle event: %s" ),
872 ( handled ? wxS(
"Did" ) : wxS(
"Did not" ) ), aEvent.
Format() );
889 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::dispatchActivation - Received event: %s" ),
899 wxS(
"TOOL_MANAGER::dispatchActivation - Running tool %s for event: %s" ),
900 tool->second->theTool->GetName(), aEvent.
Format() );
902 runTool( tool->second->theTool );
943 for(
const std::pair<const TOOL_ID, TOOL_STATE*>& idState :
m_toolIdIndex )
948 if( vc.m_forceCursorPosition )
958 std::unique_ptr<ACTION_MENU> menu( m->
Clone() );
963 if( wxWindow* frame =
dynamic_cast<wxWindow*
>(
m_frame ) )
964 frame->PopupMenu( menu.get() );
967 if( menu->GetSelected() >= 0 )
994 for(
const std::pair<
const TOOL_ID,
1028 if( !aState->
Pop() )
1034 aState->
idle =
true;
1060#if defined( __WXMAC__ )
1061 wxTheApp->ProcessPendingEvents();
1084 return active->vcSettings;
1092 static int currentId;
1137 it->second = std::nullopt;
1143 std::optional<VECTOR2D>
cursor = it->second;
1206 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::processEvent - %s handle event: %s" ),
1207 ( handled ?
"Did" :
"Did not" ), aEvent.
Format() );
1232 return !it->second->idle;
Manage TOOL_ACTION objects.
bool RunHotKey(int aHotKey) const
Run an action associated with a hotkey (if there is one available).
TOOL_ACTION * FindAction(const std::string &aActionName) const
Find an action with a given name (if there is one available).
int GetHotKey(const TOOL_ACTION &aAction) const
Return the hot key associated with a given action or 0 if there is none.
void UpdateHotKeys(bool aFullUpdate)
Optionally read the hotkey config files and then rebuilds the internal hotkey maps.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Represent a set of changes (additions, deletions or modifications) of a data model (e....
bool Call(ArgType aArg)
Start execution of a coroutine, passing args as its arguments.
void KiYield()
Stop execution of the coroutine and returns control to the caller.
bool Resume()
Resume execution of a previously yielded coroutine.
void RunMainStack(std::function< void()> func)
Run a functor inside the application main stack context.
The base frame for deriving all KiCad main window classes.
virtual void UpdateStatusBar()
Update the status bar information.
A base class for most all the KiCad significant classes used in schematics and boards.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void WarpMouseCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false)=0
If enabled (.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
void ApplySettings(const VC_SETTINGS &aSettings)
Apply VIEW_CONTROLS settings from an object.
const VC_SETTINGS & GetSettings() const
Return the current VIEW_CONTROLS settings.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
bool IsDirty() const
Return true if any of the VIEW layers needs to be refreshened.
A type-safe container of any type.
bool has_value() const noexcept
Report whether there is a contained object or not.
Base window classes and related definitions.
const wxChar *const kicadTraceToolStack
Flag to enable tracing of the tool handling stack.
void AddTransactionBreadcrumb(const wxString &aMsg, const wxString &aCategory)
Add a transaction breadcrumb.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Structure to keep VIEW_CONTROLS settings for easy store/restore operations.
VECTOR2D m_forcedPosition
Forced cursor position (world coordinates).
void Reset()
Restore the default settings.
bool m_forceCursorPosition
Is the forced cursor position enabled.
wxLogTrace helper definitions.
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)