33#include <wx/evtloop.h>
34#include <wx/clipbrd.h>
80 wxASSERT_MSG(
stateStack.empty(), wxT(
"StateStack not empty!" ) );
160 auto state = std::make_unique<TOOL_STATE>( *
this );
230 std::map<TOOL_BASE*, TOOL_STATE*>::iterator it, it_end;
234 delete it->second->cofunc;
246 wxT(
"Adding two tools with the same name may result in unexpected behavior.") );
248 wxT(
"Adding two tools with the same ID may result in unexpected behavior.") );
250 wxT(
"Adding two tools of the same type may result in unexpected behavior.") );
253 wxS(
"TOOL_MANAGER::RegisterTool: Registering tool %s with ID %d" ),
337 COMMIT* aCommit,
bool aFromAPI )
350 event.SetParameter( aParam );
361 std::atomic<SYNCRONOUS_TOOL_STATE> synchronousControl =
STS_FINISHED;
363 event.SetSynchronous( &synchronousControl );
364 event.SetCommit( aCommit );
395 wxASSERT_MSG( aFromAPI, wxT(
"Deferred actions have no way of guaranteeing the "
396 "lifetime of the COMMIT object" ) );
397 event.SetCommit( aCommit );
454 wxASSERT( aTool !=
nullptr );
473 wxASSERT( aTool !=
nullptr );
475 wxString msg = wxString::Format( wxS(
"TOOL_MANAGER::runTool - running tool %s" ), aTool->
GetName() );
480 wxASSERT_MSG(
false, wxT(
"You cannot run unregistered tools" ) );
529 for(
auto id : tmpList )
537 for(
auto id : tmpList )
563 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::ShutdownTool - no tool with name %s" ),
570 wxASSERT( aTool !=
nullptr );
576 TOOL_MANAGER::ID_LIST::iterator it = std::find(
m_activeTools.begin(),
590 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::ShutdownTool - Shutting down tool %s" ),
607 std::map<TOOL_ID, TOOL_STATE*>::const_iterator it =
m_toolIdIndex.find( aId );
610 return it->second->theTool;
618 std::map<std::string, TOOL_STATE*>::const_iterator it =
m_toolNameIndex.find( aName );
621 return it->second->theTool;
648 tool->
Reset( aReason );
688 return aTool ==
nullptr;
703 if( tool == aToolId )
748 wxCHECK( st->
cofunc,
nullptr );
763 bool handled =
false;
765 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::dispatchInternal - received event: %s" ),
774 bool increment =
true;
800 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::dispatchInternal - Waking tool %s for event: %s" ),
816 wxS(
"TOOL_MANAGER::dispatchInternal - tool %s stopped passing event: %s" ),
830 bool finished =
false;
838 if( tr.first.Matches( aEvent ) )
840 auto func_copy = tr.second;
851 st->
vcSettings = std::move( viewControlSettings );
857 wxS(
"TOOL_MANAGER::dispatchInternal - Running tool %s for event: %s" ),
883 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::dispatchInternal - %s handle event: %s" ),
884 ( handled ? wxS(
"Did" ) : wxS(
"Did not" ) ), aEvent.
Format() );
901 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::dispatchActivation - Received event: %s" ),
911 wxS(
"TOOL_MANAGER::dispatchActivation - Running tool %s for event: %s" ),
912 tool->second->theTool->GetName(), aEvent.
Format() );
914 runTool( tool->second->theTool );
930 if( wxEventLoopBase* loop = wxEventLoopBase::GetActive() )
932 if( loop->IsYielding() )
967 for(
const std::pair<const TOOL_ID, TOOL_STATE*>& idState :
m_toolIdIndex )
972 if( vc.m_forceCursorPosition )
982 std::unique_ptr<ACTION_MENU> menu( m->
Clone() );
987 if( wxWindow* frame =
dynamic_cast<wxWindow*
>(
m_frame ) )
994 if( menu->GetSelected() >= 0 )
1021 for(
const std::pair<
const TOOL_ID,
1055 if( !aState->
Pop() )
1061 aState->
idle =
true;
1087#if defined( __WXMAC__ )
1088 wxTheApp->ProcessPendingEvents();
1111 return active->vcSettings;
1119 static int currentId;
1164 it->second = std::nullopt;
1170 std::optional<VECTOR2D>
cursor = it->second;
1208#if defined( __GNUC__ ) && !defined( __clang__ )
1209#pragma GCC diagnostic push
1210#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
1213#if defined( __GNUC__ ) && !defined( __clang__ )
1214#pragma GCC diagnostic pop
1253 wxLogTrace(
kicadTraceToolStack, wxS(
"TOOL_MANAGER::processEvent - %s handle event: %s" ),
1254 ( handled ?
"Did" :
"Did not" ), aEvent.
Format() );
1279 return !it->second->idle;
Manage TOOL_ACTION objects.
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,...
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
RAII class that sets an value at construction and resets it to the original value at destruction.
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).
bool m_forceCursorPosition
Is the forced cursor position enabled.
wxLogTrace helper definitions.
VECTOR2< double > VECTOR2D
VECTOR2D ToVECTOR2D(const wxPoint &aPoint)