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

Parametrized TOOL_ACTIONs.

parent 89699a19
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -303,6 +303,9 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a
    if( action )
    {
        TOOL_EVENT event = action->MakeEvent();

        // Allow to override the action parameter
        if( aParam )
            event.SetParameter( aParam );

        if( aNow )
@@ -320,6 +323,9 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a
void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam )
{
    TOOL_EVENT event = aAction.MakeEvent();

    // Allow to override the action parameter
    if( aParam )
        event.SetParameter( aParam );

    if( aNow )
+11 −14
Original line number Diff line number Diff line
/*
 * 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 Maciej Suminski <maciej.suminski@cern.ch>
 *
@@ -41,7 +41,7 @@ struct BITMAP_OPAQUE;
 * - running the DRC from the menu
 * and so on, and so forth....
 * Action class groups all necessary properties of an action, including explanation,
 * icons, hotkeys,.menu items, etc.
 * icons, hotkeys, menu items, etc.
 */
class TOOL_ACTION
{
@@ -49,10 +49,10 @@ public:
    TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
            int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString,
            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_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ),
        m_menuDescription( aMenuDesc ), m_icon( aIcon ), m_id( -1 ), m_flags( aFlags )
        m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
        m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
    {
        TOOL_MANAGER::GetActionList().push_back( this );
    }
@@ -150,11 +150,11 @@ public:
    TOOL_EVENT MakeEvent() const
    {
        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() )
            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
            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
@@ -219,7 +219,7 @@ private:
    /// Name of the action (convention is: app.[tool.]action.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;

    /// Default hot key that activates the action.
@@ -243,11 +243,8 @@ private:
    /// Action flags
    TOOL_ACTION_FLAGS m_flags;

    /// Origin of the action
    // const TOOL_BASE* m_origin;

    /// Originating UI object
    // wxWindow* m_uiOrigin;
    /// Generic parameter
    void* m_param;
};

#endif
+13 −10
Original line number Diff line number Diff line
@@ -159,24 +159,24 @@ public:
    const std::string Format() const;

    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_actions( aAction ),
        m_scope( aScope ),
        m_mouseButtons( 0 ),
        m_keyCode( 0 ),
        m_modifiers( 0 ),
        m_param( NULL ) {}
        m_param( aParameter ) {}

    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_actions( aAction ),
        m_scope( aScope ),
        m_mouseButtons( 0 ),
        m_keyCode( 0 ),
        m_modifiers( 0 ),
        m_param( NULL )
        m_param( aParameter )
    {
        if( aCategory == TC_MOUSE )
        {
@@ -198,14 +198,15 @@ public:
    }

    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_actions( aAction ),
        m_scope( aScope ),
        m_mouseButtons( 0 ),
        m_keyCode( 0 ),
        m_modifiers( 0 ),
        m_param( NULL )
        m_param( aParameter )
    {
        if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE )
            m_commandStr = aExtraParam;
@@ -360,9 +361,10 @@ public:
     * Returns a non-standard parameter assigned to the event. Its meaning depends on the
     * 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:
     * target tool.
     * @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
+10 −9
Original line number Diff line number Diff line
/*
 * 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>
 *
 * This program is free software; you can redistribute it and/or
@@ -25,6 +25,7 @@
#include "common_actions.h"
#include <tool/action_manager.h>
#include <pcbnew_id.h>
#include <layers_id_colors_and_visibility.h>
#include <wx/defs.h>

// These members are static in class COMMON_ACTIONS: Build them here:
@@ -246,35 +247,35 @@ TOOL_ACTION COMMON_ACTIONS::highContrastDec( "pcbnew.Control.highContrastDec",
// Layer control
TOOL_ACTION COMMON_ACTIONS::layerTop( "pcbnew.Control.layerTop",
        AS_GLOBAL, WXK_PAGEUP,
        "", "" );
        "", "", NULL, AF_NONE, (void*) F_Cu );

TOOL_ACTION COMMON_ACTIONS::layerInner1( "pcbnew.Control.layerInner1",
        AS_GLOBAL, WXK_F5,
        "", "" );
        "", "", NULL, AF_NONE, (void*) In1_Cu );

TOOL_ACTION COMMON_ACTIONS::layerInner2( "pcbnew.Control.layerInner2",
        AS_GLOBAL, WXK_F6,
        "", "" );
        "", "", NULL, AF_NONE, (void*) In2_Cu );

TOOL_ACTION COMMON_ACTIONS::layerInner3( "pcbnew.Control.layerInner3",
        AS_GLOBAL, WXK_F7,
        "", "" );
        "", "", NULL, AF_NONE, (void*) In3_Cu );

TOOL_ACTION COMMON_ACTIONS::layerInner4( "pcbnew.Control.layerInner4",
        AS_GLOBAL, WXK_F8,
        "", "" );
        "", "", NULL, AF_NONE, (void*) In4_Cu );

TOOL_ACTION COMMON_ACTIONS::layerInner5( "pcbnew.Control.layerInner5",
        AS_GLOBAL, WXK_F9,
        "", "" );
        "", "", NULL, AF_NONE, (void*) In5_Cu );

TOOL_ACTION COMMON_ACTIONS::layerInner6( "pcbnew.Control.layerInner6",
        AS_GLOBAL, WXK_F10,
        "", "" );
        "", "", NULL, AF_NONE, (void*) In6_Cu );

TOOL_ACTION COMMON_ACTIONS::layerBottom( "pcbnew.Control.layerBottom",
        AS_GLOBAL, WXK_PAGEDOWN,
        "", "" );
        "", "", NULL, AF_NONE, (void*) B_Cu );

TOOL_ACTION COMMON_ACTIONS::layerNext( "pcbnew.Control.layerNext",
        AS_GLOBAL, '+',
+2 −19
Original line number Diff line number Diff line
@@ -285,23 +285,7 @@ int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent )
// Layer control
int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent )
{
    if( aEvent.IsAction( &COMMON_ACTIONS::layerTop ) )
        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 );

    m_frame->SwitchLayer( NULL, (LAYER_ID) aEvent.Parameter<long>() );
    setTransitions();

    return 0;
@@ -450,8 +434,7 @@ int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
{
    Activate();
    m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL,
                                               _( "Adjust grid origin" ) );
    m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );

    KIGFX::VIEW_CONTROLS* controls = getViewControls();
    controls->ShowCursor( true );
Loading