Commit 5c984aa0 authored by Maciej Suminski's avatar Maciej Suminski

Parametrized TOOL_ACTIONs.

parent 89699a19
...@@ -303,7 +303,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a ...@@ -303,7 +303,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a
if( action ) if( action )
{ {
TOOL_EVENT event = action->MakeEvent(); TOOL_EVENT event = action->MakeEvent();
event.SetParameter( aParam );
// Allow to override the action parameter
if( aParam )
event.SetParameter( aParam );
if( aNow ) if( aNow )
ProcessEvent( event ); ProcessEvent( event );
...@@ -320,7 +323,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a ...@@ -320,7 +323,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a
void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam ) void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam )
{ {
TOOL_EVENT event = aAction.MakeEvent(); TOOL_EVENT event = aAction.MakeEvent();
event.SetParameter( aParam );
// Allow to override the action parameter
if( aParam )
event.SetParameter( aParam );
if( aNow ) if( aNow )
ProcessEvent( event ); ProcessEvent( event );
......
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013-2015 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
...@@ -41,7 +41,7 @@ struct BITMAP_OPAQUE; ...@@ -41,7 +41,7 @@ struct BITMAP_OPAQUE;
* - running the DRC from the menu * - running the DRC from the menu
* and so on, and so forth.... * and so on, and so forth....
* Action class groups all necessary properties of an action, including explanation, * Action class groups all necessary properties of an action, including explanation,
* icons, hotkeys,.menu items, etc. * icons, hotkeys, menu items, etc.
*/ */
class TOOL_ACTION class TOOL_ACTION
{ {
...@@ -49,10 +49,10 @@ public: ...@@ -49,10 +49,10 @@ public:
TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT, TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString, int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString,
const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL, const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL,
TOOL_ACTION_FLAGS aFlags = AF_NONE ) : TOOL_ACTION_FLAGS aFlags = AF_NONE, void* aParam = NULL ) :
m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ), m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
m_menuDescription( aMenuDesc ), m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ) m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
{ {
TOOL_MANAGER::GetActionList().push_back( this ); TOOL_MANAGER::GetActionList().push_back( this );
} }
...@@ -150,11 +150,11 @@ public: ...@@ -150,11 +150,11 @@ public:
TOOL_EVENT MakeEvent() const TOOL_EVENT MakeEvent() const
{ {
if( IsActivation() ) if( IsActivation() )
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope ); return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope, m_param );
else if( IsNotification() ) else if( IsNotification() )
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope ); return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope, m_param );
else else
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope ); return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope, m_param );
} }
const wxString& GetMenuItem() const const wxString& GetMenuItem() const
...@@ -219,7 +219,7 @@ private: ...@@ -219,7 +219,7 @@ private:
/// Name of the action (convention is: app.[tool.]action.name) /// Name of the action (convention is: app.[tool.]action.name)
std::string m_name; std::string m_name;
/// Scope of the action (i.e. the event that is issued after activation). /// Scope of the action
TOOL_ACTION_SCOPE m_scope; TOOL_ACTION_SCOPE m_scope;
/// Default hot key that activates the action. /// Default hot key that activates the action.
...@@ -243,11 +243,8 @@ private: ...@@ -243,11 +243,8 @@ private:
/// Action flags /// Action flags
TOOL_ACTION_FLAGS m_flags; TOOL_ACTION_FLAGS m_flags;
/// Origin of the action /// Generic parameter
// const TOOL_BASE* m_origin; void* m_param;
/// Originating UI object
// wxWindow* m_uiOrigin;
}; };
#endif #endif
...@@ -159,24 +159,24 @@ public: ...@@ -159,24 +159,24 @@ public:
const std::string Format() const; const std::string Format() const;
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory = TC_NONE, TOOL_ACTIONS aAction = TA_NONE, TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory = TC_NONE, TOOL_ACTIONS aAction = TA_NONE,
TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) : TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = NULL ) :
m_category( aCategory ), m_category( aCategory ),
m_actions( aAction ), m_actions( aAction ),
m_scope( aScope ), m_scope( aScope ),
m_mouseButtons( 0 ), m_mouseButtons( 0 ),
m_keyCode( 0 ), m_keyCode( 0 ),
m_modifiers( 0 ), m_modifiers( 0 ),
m_param( NULL ) {} m_param( aParameter ) {}
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, int aExtraParam, TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, int aExtraParam,
TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) : TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = NULL ) :
m_category( aCategory ), m_category( aCategory ),
m_actions( aAction ), m_actions( aAction ),
m_scope( aScope ), m_scope( aScope ),
m_mouseButtons( 0 ), m_mouseButtons( 0 ),
m_keyCode( 0 ), m_keyCode( 0 ),
m_modifiers( 0 ), m_modifiers( 0 ),
m_param( NULL ) m_param( aParameter )
{ {
if( aCategory == TC_MOUSE ) if( aCategory == TC_MOUSE )
{ {
...@@ -198,14 +198,15 @@ public: ...@@ -198,14 +198,15 @@ public:
} }
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction,
const std::string& aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) : const std::string& aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL,
void* aParameter = NULL ) :
m_category( aCategory ), m_category( aCategory ),
m_actions( aAction ), m_actions( aAction ),
m_scope( aScope ), m_scope( aScope ),
m_mouseButtons( 0 ), m_mouseButtons( 0 ),
m_keyCode( 0 ), m_keyCode( 0 ),
m_modifiers( 0 ), m_modifiers( 0 ),
m_param( NULL ) m_param( aParameter )
{ {
if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE ) if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE )
m_commandStr = aExtraParam; m_commandStr = aExtraParam;
...@@ -360,9 +361,10 @@ public: ...@@ -360,9 +361,10 @@ public:
* Returns a non-standard parameter assigned to the event. Its meaning depends on the * Returns a non-standard parameter assigned to the event. Its meaning depends on the
* target tool. * target tool.
*/ */
void* Parameter() const template<typename T>
inline T Parameter() const
{ {
return m_param; return reinterpret_cast<T>( m_param );
} }
/** /**
...@@ -371,9 +373,10 @@ public: ...@@ -371,9 +373,10 @@ public:
* target tool. * target tool.
* @param aParam is the new parameter. * @param aParam is the new parameter.
*/ */
void SetParameter(void* aParam) template<typename T>
void SetParameter(T aParam)
{ {
m_param = aParam; m_param = (void*) aParam;
} }
boost::optional<int> GetCommandId() const boost::optional<int> GetCommandId() const
......
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013-2015 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "common_actions.h" #include "common_actions.h"
#include <tool/action_manager.h> #include <tool/action_manager.h>
#include <pcbnew_id.h> #include <pcbnew_id.h>
#include <layers_id_colors_and_visibility.h>
#include <wx/defs.h> #include <wx/defs.h>
// These members are static in class COMMON_ACTIONS: Build them here: // These members are static in class COMMON_ACTIONS: Build them here:
...@@ -246,35 +247,35 @@ TOOL_ACTION COMMON_ACTIONS::highContrastDec( "pcbnew.Control.highContrastDec", ...@@ -246,35 +247,35 @@ TOOL_ACTION COMMON_ACTIONS::highContrastDec( "pcbnew.Control.highContrastDec",
// Layer control // Layer control
TOOL_ACTION COMMON_ACTIONS::layerTop( "pcbnew.Control.layerTop", TOOL_ACTION COMMON_ACTIONS::layerTop( "pcbnew.Control.layerTop",
AS_GLOBAL, WXK_PAGEUP, AS_GLOBAL, WXK_PAGEUP,
"", "" ); "", "", NULL, AF_NONE, (void*) F_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner1( "pcbnew.Control.layerInner1", TOOL_ACTION COMMON_ACTIONS::layerInner1( "pcbnew.Control.layerInner1",
AS_GLOBAL, WXK_F5, AS_GLOBAL, WXK_F5,
"", "" ); "", "", NULL, AF_NONE, (void*) In1_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner2( "pcbnew.Control.layerInner2", TOOL_ACTION COMMON_ACTIONS::layerInner2( "pcbnew.Control.layerInner2",
AS_GLOBAL, WXK_F6, AS_GLOBAL, WXK_F6,
"", "" ); "", "", NULL, AF_NONE, (void*) In2_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner3( "pcbnew.Control.layerInner3", TOOL_ACTION COMMON_ACTIONS::layerInner3( "pcbnew.Control.layerInner3",
AS_GLOBAL, WXK_F7, AS_GLOBAL, WXK_F7,
"", "" ); "", "", NULL, AF_NONE, (void*) In3_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner4( "pcbnew.Control.layerInner4", TOOL_ACTION COMMON_ACTIONS::layerInner4( "pcbnew.Control.layerInner4",
AS_GLOBAL, WXK_F8, AS_GLOBAL, WXK_F8,
"", "" ); "", "", NULL, AF_NONE, (void*) In4_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner5( "pcbnew.Control.layerInner5", TOOL_ACTION COMMON_ACTIONS::layerInner5( "pcbnew.Control.layerInner5",
AS_GLOBAL, WXK_F9, AS_GLOBAL, WXK_F9,
"", "" ); "", "", NULL, AF_NONE, (void*) In5_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner6( "pcbnew.Control.layerInner6", TOOL_ACTION COMMON_ACTIONS::layerInner6( "pcbnew.Control.layerInner6",
AS_GLOBAL, WXK_F10, AS_GLOBAL, WXK_F10,
"", "" ); "", "", NULL, AF_NONE, (void*) In6_Cu );
TOOL_ACTION COMMON_ACTIONS::layerBottom( "pcbnew.Control.layerBottom", TOOL_ACTION COMMON_ACTIONS::layerBottom( "pcbnew.Control.layerBottom",
AS_GLOBAL, WXK_PAGEDOWN, AS_GLOBAL, WXK_PAGEDOWN,
"", "" ); "", "", NULL, AF_NONE, (void*) B_Cu );
TOOL_ACTION COMMON_ACTIONS::layerNext( "pcbnew.Control.layerNext", TOOL_ACTION COMMON_ACTIONS::layerNext( "pcbnew.Control.layerNext",
AS_GLOBAL, '+', AS_GLOBAL, '+',
......
...@@ -285,23 +285,7 @@ int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent ) ...@@ -285,23 +285,7 @@ int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent )
// Layer control // Layer control
int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent )
{ {
if( aEvent.IsAction( &COMMON_ACTIONS::layerTop ) ) m_frame->SwitchLayer( NULL, (LAYER_ID) aEvent.Parameter<long>() );
m_frame->SwitchLayer( NULL, F_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner1 ) )
m_frame->SwitchLayer( NULL, In1_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner2 ) )
m_frame->SwitchLayer( NULL, In2_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner3 ) )
m_frame->SwitchLayer( NULL, In3_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner4 ) )
m_frame->SwitchLayer( NULL, In4_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner5 ) )
m_frame->SwitchLayer( NULL, In5_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner6 ) )
m_frame->SwitchLayer( NULL, In6_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerBottom ) )
m_frame->SwitchLayer( NULL, B_Cu );
setTransitions(); setTransitions();
return 0; return 0;
...@@ -450,8 +434,7 @@ int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent ) ...@@ -450,8 +434,7 @@ int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
{ {
Activate(); Activate();
m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
_( "Adjust grid origin" ) );
KIGFX::VIEW_CONTROLS* controls = getViewControls(); KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->ShowCursor( true ); controls->ShowCursor( true );
......
...@@ -509,7 +509,7 @@ int SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent ) ...@@ -509,7 +509,7 @@ int SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent )
int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent ) int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent )
{ {
// Check if there is an item to be selected // Check if there is an item to be selected
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aEvent.Parameter() ); BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
if( item ) if( item )
{ {
...@@ -527,7 +527,7 @@ int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent ) ...@@ -527,7 +527,7 @@ int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent )
int SELECTION_TOOL::UnselectItem( const TOOL_EVENT& aEvent ) int SELECTION_TOOL::UnselectItem( const TOOL_EVENT& aEvent )
{ {
// Check if there is an item to be selected // Check if there is an item to be selected
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aEvent.Parameter() ); BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
if( item ) if( item )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment