2013-09-19 15:02:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-27 16:51:21 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2013-09-19 15:02:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-09-18 17:56:37 +00:00
|
|
|
#ifndef __TOOL_ACTION_H
|
|
|
|
#define __TOOL_ACTION_H
|
|
|
|
|
|
|
|
#include <string>
|
2013-09-26 12:09:18 +00:00
|
|
|
#include <cassert>
|
2013-09-18 17:56:37 +00:00
|
|
|
|
2014-03-21 09:40:50 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2013-09-18 17:56:37 +00:00
|
|
|
|
2015-04-02 14:09:48 +00:00
|
|
|
struct BITMAP_OPAQUE;
|
|
|
|
|
2013-09-27 16:51:21 +00:00
|
|
|
/**
|
|
|
|
* Class TOOL_ACTION
|
|
|
|
*
|
|
|
|
* Represents a single user action. For instance:
|
|
|
|
* - changing layer to top by pressing PgUp
|
|
|
|
* - 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.
|
|
|
|
*/
|
2013-09-19 15:02:57 +00:00
|
|
|
class TOOL_ACTION
|
2013-09-18 17:56:37 +00:00
|
|
|
{
|
2013-09-19 15:02:57 +00:00
|
|
|
public:
|
2013-10-14 18:40:36 +00:00
|
|
|
TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
|
2015-04-02 14:09:26 +00:00
|
|
|
int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString,
|
2015-04-02 14:09:48 +00:00
|
|
|
const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL,
|
|
|
|
TOOL_ACTION_FLAGS aFlags = AF_NONE ) :
|
2013-10-14 14:13:35 +00:00
|
|
|
m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
|
|
|
|
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ),
|
2015-04-02 14:09:48 +00:00
|
|
|
m_menuDescription( aMenuDesc ), m_icon( aIcon ), m_id( -1 ), m_flags( aFlags )
|
2013-09-19 15:02:57 +00:00
|
|
|
{
|
2014-05-14 14:29:53 +00:00
|
|
|
TOOL_MANAGER::GetActionList().push_back( this );
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~TOOL_ACTION()
|
|
|
|
{
|
2014-05-14 14:29:53 +00:00
|
|
|
TOOL_MANAGER::GetActionList().remove( this );
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==( const TOOL_ACTION& aRhs ) const
|
|
|
|
{
|
|
|
|
return m_id == aRhs.m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=( const TOOL_ACTION& aRhs ) const
|
|
|
|
{
|
|
|
|
return m_id != aRhs.m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetName()
|
|
|
|
* Returns name of the action. It is the same one that is contained in TOOL_EVENT that is
|
|
|
|
* sent by activating the TOOL_ACTION.
|
|
|
|
*
|
|
|
|
* @return Name of the action.
|
|
|
|
*/
|
|
|
|
const std::string& GetName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetId()
|
|
|
|
* Returns the unique id of the TOOL_ACTION object. It is valid only after registering the
|
|
|
|
* TOOL_ACTION by ACTION_MANAGER.
|
|
|
|
*
|
|
|
|
* @return The unique identification number. If the number is negative, then it is not valid.
|
|
|
|
*/
|
|
|
|
int GetId() const
|
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:09:18 +00:00
|
|
|
/**
|
|
|
|
* Function GetHotKey()
|
|
|
|
* Returns the associated hot key.
|
|
|
|
*/
|
|
|
|
int GetHotKey() const
|
|
|
|
{
|
|
|
|
return m_currentHotKey;
|
|
|
|
}
|
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
/**
|
|
|
|
* Function ChangeHotKey()
|
|
|
|
* Assigns a new hot key.
|
|
|
|
*
|
|
|
|
* @param aNewHotKey is the new hot key.
|
|
|
|
*/
|
|
|
|
void ChangeHotKey( int aNewHotKey )
|
|
|
|
{
|
2013-09-26 12:09:18 +00:00
|
|
|
assert( false );
|
|
|
|
// hotkey has to be changed in the ACTION_MANAGER, or change the implementation
|
2013-09-19 15:02:57 +00:00
|
|
|
m_currentHotKey = aNewHotKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function RestoreHotKey()
|
|
|
|
* Changes the assigned hot key to the default one.
|
|
|
|
*/
|
|
|
|
void RestoreHotKey()
|
|
|
|
{
|
2013-09-26 12:09:18 +00:00
|
|
|
assert( false );
|
|
|
|
// hotkey has to be changed in the ACTION_MANAGER, or change the implementation
|
2013-09-19 15:02:57 +00:00
|
|
|
m_currentHotKey = m_defaultHotKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function HasHotKey()
|
|
|
|
* Checks if the action has a hot key assigned.
|
|
|
|
*
|
|
|
|
* @return True if there is a hot key assigned, false otherwise.
|
|
|
|
*/
|
|
|
|
bool HasHotKey() const
|
|
|
|
{
|
|
|
|
return m_currentHotKey > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-27 16:51:21 +00:00
|
|
|
* Function MakeEvent()
|
2014-07-09 11:50:27 +00:00
|
|
|
* Returns the event associated with the action (i.e. the event that will be sent after
|
2013-09-19 15:02:57 +00:00
|
|
|
* activating the action).
|
|
|
|
*
|
|
|
|
* @return The event associated with the action.
|
|
|
|
*/
|
2013-09-27 16:51:21 +00:00
|
|
|
TOOL_EVENT MakeEvent() const
|
2013-09-19 15:02:57 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
if( IsActivation() )
|
|
|
|
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope );
|
2014-07-09 13:10:32 +00:00
|
|
|
else if( IsNotification() )
|
2015-03-10 12:20:22 +00:00
|
|
|
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope );
|
2014-07-09 11:50:27 +00:00
|
|
|
else
|
|
|
|
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope );
|
2013-09-19 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
const wxString& GetMenuItem() const
|
2013-09-26 12:09:18 +00:00
|
|
|
{
|
|
|
|
return m_menuItem;
|
|
|
|
}
|
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
void SetMenuItem( const wxString& aItem )
|
2013-09-26 12:09:18 +00:00
|
|
|
{
|
|
|
|
m_menuItem = aItem;
|
|
|
|
}
|
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
const wxString& GetDescription() const
|
2013-09-26 12:09:18 +00:00
|
|
|
{
|
|
|
|
return m_menuDescription;
|
|
|
|
}
|
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
void SetDescription( const wxString& aDescription )
|
2013-09-26 12:09:18 +00:00
|
|
|
{
|
|
|
|
m_menuDescription = aDescription;
|
|
|
|
}
|
|
|
|
|
2014-04-09 15:05:05 +00:00
|
|
|
TOOL_ACTION_SCOPE GetScope() const
|
|
|
|
{
|
|
|
|
return m_scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns name of the tool associated with the action. It is basically the action name
|
|
|
|
* stripped of the last part (e.g. for "pcbnew.InteractiveDrawing.drawCircle" it is
|
|
|
|
* "pcbnew.InteractiveDrawing").
|
|
|
|
*/
|
2014-07-09 11:50:27 +00:00
|
|
|
std::string GetToolName() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the action is intended to activate a tool.
|
|
|
|
*/
|
|
|
|
bool IsActivation() const
|
2014-04-09 15:05:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
return m_flags & AF_ACTIVATE;
|
2014-04-09 15:05:05 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 13:10:32 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the action is a notification.
|
|
|
|
*/
|
|
|
|
bool IsNotification() const
|
|
|
|
{
|
|
|
|
return m_flags & AF_NOTIFY;
|
|
|
|
}
|
|
|
|
|
2015-04-02 14:09:48 +00:00
|
|
|
/**
|
|
|
|
* Returns an icon associated with the action. It is used in context menu.
|
|
|
|
*/
|
|
|
|
const BITMAP_OPAQUE* GetIcon() const
|
|
|
|
{
|
|
|
|
return m_icon;
|
|
|
|
}
|
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
private:
|
|
|
|
friend class ACTION_MANAGER;
|
|
|
|
|
|
|
|
/// Name of the action (convention is: app.[tool.]action.name)
|
|
|
|
std::string m_name;
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
/// Scope of the action (i.e. the event that is issued after activation).
|
2013-10-14 18:40:36 +00:00
|
|
|
TOOL_ACTION_SCOPE m_scope;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
/// Default hot key that activates the action.
|
|
|
|
const int m_defaultHotKey;
|
|
|
|
|
|
|
|
/// Custom assigned hot key that activates the action.
|
|
|
|
int m_currentHotKey;
|
|
|
|
|
|
|
|
/// Menu entry text
|
2015-04-02 14:09:26 +00:00
|
|
|
wxString m_menuItem;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
/// Pop-up help
|
2015-04-02 14:09:26 +00:00
|
|
|
wxString m_menuDescription;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
// Icon for menu entry
|
2015-04-02 14:09:48 +00:00
|
|
|
const BITMAP_OPAQUE* m_icon;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
/// Unique ID for fast matching. Assigned by ACTION_MANAGER.
|
|
|
|
int m_id;
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
/// Action flags
|
|
|
|
TOOL_ACTION_FLAGS m_flags;
|
|
|
|
|
2013-09-19 15:02:57 +00:00
|
|
|
/// Origin of the action
|
2014-05-14 14:29:53 +00:00
|
|
|
// const TOOL_BASE* m_origin;
|
2013-09-19 15:02:57 +00:00
|
|
|
|
|
|
|
/// Originating UI object
|
2014-05-14 14:29:53 +00:00
|
|
|
// wxWindow* m_uiOrigin;
|
2013-09-18 17:56:37 +00:00
|
|
|
};
|
2013-09-26 12:09:18 +00:00
|
|
|
|
2013-09-18 17:56:37 +00:00
|
|
|
#endif
|