cleanup tool event and tool action includes

This commit is contained in:
Ian McInerney 2021-06-06 18:26:26 +01:00
parent 425331b655
commit dc27079b71
34 changed files with 99 additions and 100 deletions

View File

@ -28,7 +28,6 @@
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <core/optional.h>
class TOOL_EVENT; class TOOL_EVENT;
class TOOL_MANAGER; class TOOL_MANAGER;

View File

@ -34,6 +34,7 @@
#include <settings/common_settings.h> #include <settings/common_settings.h>
#include <tool/action_toolbar.h> #include <tool/action_toolbar.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <tool/tool_action.h>
#include <tool/tool_event.h> #include <tool/tool_event.h>
#include <tool/tool_interactive.h> #include <tool/tool_interactive.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
@ -65,6 +66,12 @@ ACTION_GROUP::ACTION_GROUP( std::string aName, const std::vector<const TOOL_ACTI
} }
int ACTION_GROUP::GetUIId() const
{
return m_id + TOOL_ACTION::GetBaseUIId();
}
void ACTION_GROUP::SetDefaultAction( const TOOL_ACTION& aDefault ) void ACTION_GROUP::SetDefaultAction( const TOOL_ACTION& aDefault )
{ {
bool valid = std::any_of( m_actions.begin(), m_actions.end(), bool valid = std::any_of( m_actions.begin(), m_actions.end(),

View File

@ -27,6 +27,8 @@
#include <eda_units.h> #include <eda_units.h>
#include <frame_type.h> #include <frame_type.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <tool/tool_action.h>
#include <tool/tool_event.h>
// Actions, being statically-defined, require specialized I18N handling. We continue to // Actions, being statically-defined, require specialized I18N handling. We continue to
// use the _() macro so that string harvesting by the I18N framework doesn't have to be // use the _() macro so that string harvesting by the I18N framework doesn't have to be

View File

@ -23,6 +23,7 @@
*/ */
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/tool_event.h>
#include <tool/action_manager.h> #include <tool/action_manager.h>
#include <algorithm> #include <algorithm>
@ -68,6 +69,17 @@ TOOL_ACTION::~TOOL_ACTION()
} }
TOOL_EVENT TOOL_ACTION::MakeEvent() const
{
if( IsActivation() )
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope, m_param );
else if( IsNotification() )
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope, m_param );
else
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope, m_param );
}
wxString TOOL_ACTION::GetLabel() const wxString TOOL_ACTION::GetLabel() const
{ {
return wxGetTranslation( m_label ); return wxGetTranslation( m_label );

View File

@ -362,6 +362,17 @@ void TOOL_MANAGER::PrimeTool( const VECTOR2D& aPosition )
} }
void TOOL_MANAGER::PostEvent( const TOOL_EVENT& aEvent )
{
// Horrific hack, but it's a crash bug. Don't let inter-frame commands stack up
// waiting to be processed.
if( aEvent.IsSimulator() && m_eventQueue.size() > 0 && m_eventQueue.back().IsSimulator() )
m_eventQueue.pop_back();
m_eventQueue.push_back( aEvent );
}
const std::map<std::string, TOOL_ACTION*>& TOOL_MANAGER::GetActions() const const std::map<std::string, TOOL_ACTION*>& TOOL_MANAGER::GetActions() const
{ {
return m_actionMgr->GetActions(); return m_actionMgr->GetActions();

View File

@ -23,6 +23,7 @@
#include <pgm_base.h> #include <pgm_base.h>
#include <settings/common_settings.h> #include <settings/common_settings.h>
#include <tool/action_manager.h>
#include <tool/action_menu.h> #include <tool/action_menu.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <tool/tools_holder.h> #include <tool/tools_holder.h>

View File

@ -28,7 +28,7 @@
#include <wx/treelist.h> #include <wx/treelist.h>
#include <wx/msgdlg.h> #include <wx/msgdlg.h>
#include <wx/menu.h> #include <wx/menu.h>
#include <tool/tool_action.h> #include <tool/tool_event.h>
#include <dialog_shim.h> #include <dialog_shim.h>
#include <wx/dcclient.h> #include <wx/dcclient.h>
#include <wx/stattext.h> #include <wx/stattext.h>

View File

@ -26,10 +26,7 @@
#ifndef CVPCB_ACTIONS_H #ifndef CVPCB_ACTIONS_H
#define CVPCB_ACTIONS_H #define CVPCB_ACTIONS_H
#include <core/optional.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <tool/tool_event.h>
class TOOL_ACTION;
/** /**
* Gather all the actions that are shared by tools. * Gather all the actions that are shared by tools.

View File

@ -30,6 +30,7 @@
#include <menus_helpers.h> #include <menus_helpers.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <schematic.h> #include <schematic.h>
#include <tool/action_manager.h>
#include <tool/action_menu.h> #include <tool/action_menu.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/ee_selection_tool.h> #include <tools/ee_selection_tool.h>

View File

@ -27,7 +27,6 @@
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <core/optional.h>
class TOOL_EVENT; class TOOL_EVENT;
class TOOL_MANAGER; class TOOL_MANAGER;
@ -218,26 +217,4 @@ public:
static TOOL_ACTION highlightNetTool; static TOOL_ACTION highlightNetTool;
}; };
//
// For LibEdit
//
inline VECTOR2I mapCoords( const wxPoint& aCoord )
{
return VECTOR2I( aCoord.x, -aCoord.y );
}
inline wxPoint mapCoords( const VECTOR2I& aCoord )
{
return wxPoint( aCoord.x, -aCoord.y );
}
inline wxPoint mapCoords( const int x, const int y )
{
return wxPoint( x, -y );
}
#endif #endif

View File

@ -25,6 +25,7 @@
#ifndef EE_TOOL_BASE_H #ifndef EE_TOOL_BASE_H
#define EE_TOOL_BASE_H #define EE_TOOL_BASE_H
#include <math/vector2d.h>
#include <tool/tool_event.h> #include <tool/tool_event.h>
#include <tool/tool_interactive.h> #include <tool/tool_interactive.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
@ -177,4 +178,21 @@ protected:
bool m_isSymbolEditor; bool m_isSymbolEditor;
}; };
// For LibEdit
inline VECTOR2I mapCoords( const wxPoint& aCoord )
{
return VECTOR2I( aCoord.x, -aCoord.y );
}
inline wxPoint mapCoords( const VECTOR2I& aCoord )
{
return wxPoint( aCoord.x, -aCoord.y );
}
inline wxPoint mapCoords( const int x, const int y )
{
return wxPoint( x, -y );
}
#endif #endif

View File

@ -31,12 +31,12 @@
#include <vector> #include <vector>
#include <math/vector2d.h> #include <math/vector2d.h>
#include <tool/tool_event.h>
#include <sch_edit_frame.h> #include <sch_edit_frame.h>
#include <sch_line.h> #include <sch_line.h>
#include <ee_tool_base.h> #include <ee_tool_base.h>
class TOOL_EVENT;
class SCH_BUS_WIRE_ENTRY; class SCH_BUS_WIRE_ENTRY;
class SCH_LABEL; class SCH_LABEL;

View File

@ -29,6 +29,7 @@
#include "gerbview_id.h" #include "gerbview_id.h"
#include <kiface_i.h> #include <kiface_i.h>
#include <menus_helpers.h> #include <menus_helpers.h>
#include <tool/action_manager.h>
#include <tool/action_menu.h> #include <tool/action_menu.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>

View File

@ -23,7 +23,6 @@
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <core/optional.h>
class TOOL_EVENT; class TOOL_EVENT;
class TOOL_MANAGER; class TOOL_MANAGER;

View File

@ -20,10 +20,11 @@
#ifndef GERBVIEW_INSPECTION_TOOL_H #ifndef GERBVIEW_INSPECTION_TOOL_H
#define GERBVIEW_INSPECTION_TOOL_H #define GERBVIEW_INSPECTION_TOOL_H
#include <tool/tool_event.h>
#include <tool/tool_interactive.h> #include <tool/tool_interactive.h>
#include <gerbview_frame.h> #include <gerbview_frame.h>
class TOOL_EVENT;
class GERBVIEW_INSPECTION_TOOL : public TOOL_INTERACTIVE class GERBVIEW_INSPECTION_TOOL : public TOOL_INTERACTIVE
{ {
public: public:

View File

@ -34,10 +34,11 @@
#include <wx/menu.h> #include <wx/menu.h>
#include <wx/textentry.h> #include <wx/textentry.h>
#include <tool/tool_action.h> #include <tool/tool_event.h>
class KIFACE_I; class KIFACE_I;
class TOOL_INTERACTIVE; class TOOL_INTERACTIVE;
class TOOL_MANAGER;
enum class BITMAPS : unsigned int; enum class BITMAPS : unsigned int;

View File

@ -33,12 +33,11 @@
#include <wx/popupwin.h> #include <wx/popupwin.h>
#include <wx/panel.h> #include <wx/panel.h>
#include <tool/action_manager.h> #include <tool/action_manager.h>
#include <tool/tool_action.h>
#include <tool/tool_event.h>
class ACTION_MENU; class ACTION_MENU;
class BITMAP_BUTTON; class BITMAP_BUTTON;
class EDA_BASE_FRAME; class EDA_BASE_FRAME;
class TOOL_ACTION;
class TOOL_MANAGER; class TOOL_MANAGER;
/** /**
@ -75,12 +74,12 @@ public:
/** /**
* Get the ID used in the UI to reference this group * Get the ID used in the UI to reference this group
*/ */
int GetUIId() const { return m_id + TOOL_ACTION::GetBaseUIId(); } int GetUIId() const;
/** /**
* Get a vector of all the actions contained inside this group. * Get a vector of all the actions contained inside this group.
*/ */
const std::vector< const TOOL_ACTION*>& GetActions() const { return m_actions; } const std::vector<const TOOL_ACTION*>& GetActions() const { return m_actions; }
protected: protected:
///< The action ID for this action group ///< The action ID for this action group

View File

@ -27,10 +27,7 @@
#define __ACTIONS_H #define __ACTIONS_H
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <core/optional.h> #include <tool/tool_event.h>
class TOOL_EVENT;
class TOOL_MANAGER;
#define LEGACY_HK_NAME( x ) x #define LEGACY_HK_NAME( x ) x

View File

@ -29,10 +29,10 @@
#include <functional> #include <functional>
#include <tool/selection.h> #include <tool/selection.h>
#include <tool/selection_conditions.h> #include <tool/selection_conditions.h>
#include <tool/tool_action.h>
class EDA_BASE_FRAME; class EDA_BASE_FRAME;
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
class TOOL_ACTION;
/** /**
* Class that groups generic conditions for editor states. * Class that groups generic conditions for editor states.

View File

@ -31,10 +31,28 @@
#include <string> #include <string>
#include <cassert> #include <cassert>
#include <tool/tool_event.h> #include <wx/string.h>
class TOOL_EVENT;
enum class BITMAPS : unsigned int; enum class BITMAPS : unsigned int;
/// Scope of tool actions
enum TOOL_ACTION_SCOPE
{
AS_CONTEXT = 1, ///< Action belongs to a particular tool (i.e. a part of a pop-up menu)
AS_ACTIVE, ///< All active tools
AS_GLOBAL ///< Global action (toolbar/main menu event, global shortcut)
};
/// Flags for tool actions
enum TOOL_ACTION_FLAGS
{
AF_NONE = 0,
AF_ACTIVATE = 1, ///< Action activates a tool
AF_NOTIFY = 2 ///< Action is a notification (it is by default passed to all tools)
};
/** /**
* Represent a single user action. * Represent a single user action.
* *
@ -120,15 +138,7 @@ public:
* Return the event associated with the action (i.e. the event that will be sent after * Return the event associated with the action (i.e. the event that will be sent after
* activating the action). * activating the action).
*/ */
TOOL_EVENT MakeEvent() const TOOL_EVENT MakeEvent() const;
{
if( IsActivation() )
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope, m_param );
else if( IsNotification() )
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope, m_param );
else
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope, m_param );
}
wxString GetLabel() const; wxString GetLabel() const;
wxString GetMenuItem() const; wxString GetMenuItem() const;

View File

@ -30,11 +30,10 @@
#include <cassert> #include <cassert>
#include <eda_item.h> // for KICAD_T #include <eda_item.h> // for KICAD_T
#include <tool/tool_event.h>
#include <functional> #include <functional>
class EDA_ITEM; class EDA_ITEM;
class TOOL_EVENT;
class TOOL_MANAGER; class TOOL_MANAGER;
class TOOLS_HOLDER; class TOOLS_HOLDER;

View File

@ -29,7 +29,7 @@
#include <vector> #include <vector>
#include <wx/event.h> #include <wx/event.h>
#include <tool/tool_event.h> #include <tool/tool_event.h> // Needed for MD_ constants
class TOOL_MANAGER; class TOOL_MANAGER;
class PCB_BASE_FRAME; class PCB_BASE_FRAME;

View File

@ -34,6 +34,7 @@
#include <math/vector2d.h> #include <math/vector2d.h>
#include <core/optional.h> #include <core/optional.h>
#include <tool/tool_action.h>
class TOOL_ACTION; class TOOL_ACTION;
class TOOL_MANAGER; class TOOL_MANAGER;
@ -137,22 +138,6 @@ enum TOOL_MODIFIERS
MD_MODIFIER_MASK = MD_SHIFT | MD_CTRL | MD_ALT, MD_MODIFIER_MASK = MD_SHIFT | MD_CTRL | MD_ALT,
}; };
/// Scope of tool actions
enum TOOL_ACTION_SCOPE
{
AS_CONTEXT = 1, ///< Action belongs to a particular tool (i.e. a part of a pop-up menu)
AS_ACTIVE, ///< All active tools
AS_GLOBAL ///< Global action (toolbar/main menu event, global shortcut)
};
/// Flags for tool actions
enum TOOL_ACTION_FLAGS
{
AF_NONE = 0,
AF_ACTIVATE = 1, ///< Action activates a tool
AF_NOTIFY = 2 ///< Action is a notification (it is by default passed to all tools)
};
/// Defines when a context menu is opened. /// Defines when a context menu is opened.
enum CONTEXT_MENU_TRIGGER enum CONTEXT_MENU_TRIGGER
{ {

View File

@ -29,7 +29,7 @@
#include <string> #include <string>
#include <tool/tool_menu.h> #include <tool/tool_menu.h>
#include <tool/tool_event.h> #include <tool/tool_event.h> // Needed for CONTEXT_MENU_TRIGGER
#include <tool/tool_base.h> #include <tool/tool_base.h>
class ACTION_MENU; class ACTION_MENU;

View File

@ -34,9 +34,11 @@
#include <stack> #include <stack>
#include <tool/tool_base.h> #include <tool/tool_base.h>
#include <tool/tool_event.h>
#include <view/view_controls.h> #include <view/view_controls.h>
class TOOLS_HOLDER; class TOOLS_HOLDER;
class TOOL_ACTION;
class TOOL_BASE; class TOOL_BASE;
class ACTION_MANAGER; class ACTION_MANAGER;
class ACTION_MENU; class ACTION_MENU;
@ -264,15 +266,7 @@ public:
* *
* @param aEvent is the event to be put into the queue. * @param aEvent is the event to be put into the queue.
*/ */
inline void PostEvent( const TOOL_EVENT& aEvent ) void PostEvent( const TOOL_EVENT& aEvent );
{
// Horrific hack, but it's a crash bug. Don't let inter-frame commands stack up
// waiting to be processed.
if( aEvent.IsSimulator() && m_eventQueue.size() > 0 && m_eventQueue.back().IsSimulator() )
m_eventQueue.pop_back();
m_eventQueue.push_back( aEvent );
}
/** /**
* Set the work environment (model, view, view controls and the parent window). * Set the work environment (model, view, view controls and the parent window).

View File

@ -25,12 +25,12 @@
#define TOOLS_TOOL_MENU__H_ #define TOOLS_TOOL_MENU__H_
#include <tool/conditional_menu.h> #include <tool/conditional_menu.h>
#include <tool/tool_event.h>
#include <vector> #include <vector>
#include <memory> #include <memory>
class ACTION_MENU; class ACTION_MENU;
class TOOL_INTERACTIVE;
/** /**
* Manage a #CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus. * Manage a #CONDITIONAL_MENU and some number of CONTEXT_MENUs as sub-menus.

View File

@ -26,15 +26,14 @@
#include <vector> #include <vector>
#include <view/view_controls.h> #include <view/view_controls.h>
#include <tool/action_manager.h>
#include <tool/selection.h> #include <tool/selection.h>
#include <tool/tool_action.h> #include <tool/tool_action.h>
struct ACTION_CONDITIONS;
class TOOL_MANAGER;
class TOOL_DISPATCHER;
class ACTIONS; class ACTIONS;
class TOOL_DISPATCHER;
class TOOL_MANAGER;
/* /*
* A mix-in class which allows its owner to hold a set of tools from the tool framework. * A mix-in class which allows its owner to hold a set of tools from the tool framework.

View File

@ -27,11 +27,6 @@
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <core/optional.h>
class TOOL_EVENT;
class TOOL_MANAGER;
class KICAD_MANAGER_ACTIONS : public ACTIONS class KICAD_MANAGER_ACTIONS : public ACTIONS
{ {

View File

@ -28,6 +28,7 @@
#include <kiface_i.h> #include <kiface_i.h>
#include <menus_helpers.h> #include <menus_helpers.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <tool/action_manager.h>
#include <tool/action_menu.h> #include <tool/action_menu.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <widgets/wx_menubar.h> #include <widgets/wx_menubar.h>

View File

@ -27,10 +27,6 @@
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <core/optional.h>
class TOOL_EVENT;
class TOOL_MANAGER;
/** /**
* Gather all the actions that are shared by tools. The instance of PL_ACTIONS is created * Gather all the actions that are shared by tools. The instance of PL_ACTIONS is created

View File

@ -33,6 +33,7 @@
#include <pcbnew_id.h> #include <pcbnew_id.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <python_scripting.h> #include <python_scripting.h>
#include <tool/action_manager.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include <tools/pcb_actions.h> #include <tools/pcb_actions.h>

View File

@ -29,10 +29,6 @@
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <tool/actions.h> #include <tool/actions.h>
#include <core/optional.h>
class TOOL_EVENT;
class TOOL_MANAGER;
enum class ZONE_MODE enum class ZONE_MODE
{ {

View File

@ -30,9 +30,10 @@
#include <tool/selection.h> #include <tool/selection.h>
#include <tool/tool_action.h> #include <tool/tool_action.h>
#include <pcb_base_frame.h>
class EDA_BASE_FRAME; class EDA_BASE_FRAME;
class EDA_DRAW_FRAME; class EDA_DRAW_FRAME;
class PCB_BASE_FRAME;
/** /**
* Group generic conditions for PCB editor states. * Group generic conditions for PCB editor states.

View File

@ -28,7 +28,6 @@
#include <string> #include <string>
#include <tool/tool_event.h>
#include <tool/tool_interactive.h> #include <tool/tool_interactive.h>
#include <pcb_edit_frame.h> #include <pcb_edit_frame.h>
#include <board.h> #include <board.h>