2017-01-22 09:05:46 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-06-04 13:04:30 +00:00
|
|
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-22 09:05:46 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2018-01-30 14:34:09 +00:00
|
|
|
* @file action_plugin.h
|
2017-01-22 09:05:46 +00:00
|
|
|
* @brief Class PCBNEW_ACTION_PLUGINS
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CLASS_ACTION_PLUGIN_H
|
|
|
|
#define CLASS_ACTION_PLUGIN_H
|
|
|
|
#include <vector>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* This is the parent class from where any action plugin class must derive.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
class ACTION_PLUGIN
|
|
|
|
{
|
2017-01-22 19:23:00 +00:00
|
|
|
public:
|
2018-08-15 09:26:32 +00:00
|
|
|
ACTION_PLUGIN() : m_actionMenuId( 0 ), m_actionButtonId( 0 ),
|
|
|
|
show_on_toolbar( false ) {}
|
2017-01-22 09:05:46 +00:00
|
|
|
virtual ~ACTION_PLUGIN();
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @return the category name of the action (to be able to group action under the same submenu).
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
virtual wxString GetCategoryName() = 0;
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @return the name of the action.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
virtual wxString GetName() = 0;
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @return a description of the action plugin.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
virtual wxString GetDescription() = 0;
|
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @return true if button should be shown on top toolbar.
|
2018-08-15 09:26:32 +00:00
|
|
|
*/
|
|
|
|
virtual bool GetShowToolbarButton() = 0;
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @param aDark set to true if requesting dark theme icon.
|
|
|
|
* @return a path to icon for the action plugin button.
|
2018-08-15 09:26:32 +00:00
|
|
|
*/
|
2021-03-24 22:11:32 +00:00
|
|
|
virtual wxString GetIconFileName( bool aDark ) = 0;
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @return a path this plugin was loaded from.
|
2018-08-15 09:26:32 +00:00
|
|
|
*/
|
|
|
|
virtual wxString GetPluginPath() = 0;
|
|
|
|
|
2017-01-22 09:05:46 +00:00
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* This method gets the pointer to the object from where this action constructs.
|
|
|
|
*
|
|
|
|
* @return it's a void pointer, as it could be a PyObject or any other
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
virtual void* GetObject() = 0;
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* This method the the action.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
virtual void Run() = 0;
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* It's the standard method of a "ACTION_PLUGIN" to register itself into the ACTION_PLUGINS
|
|
|
|
* singleton manager.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
void register_action();
|
2021-06-04 13:04:30 +00:00
|
|
|
|
|
|
|
// association between the plugin and its menu id
|
|
|
|
// m_actionMenuId set to 0 means the corresponding menuitem to call this
|
|
|
|
// action is not yet created
|
|
|
|
int m_actionMenuId;
|
|
|
|
|
|
|
|
// Same for button id
|
|
|
|
int m_actionButtonId;
|
|
|
|
|
|
|
|
// Icon for the action button and menu entry
|
|
|
|
wxBitmap iconBitmap;
|
|
|
|
|
|
|
|
// If show_on_toolbar is true a button will be added to top toolbar
|
|
|
|
bool show_on_toolbar;
|
|
|
|
|
2017-01-22 09:05:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Mainly static. Storing all plugins information.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
class ACTION_PLUGINS
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* An action calls this static method when it wants to register itself
|
2021-06-04 13:04:30 +00:00
|
|
|
* into the system actions.
|
2017-01-22 09:05:46 +00:00
|
|
|
*
|
2021-06-04 13:04:30 +00:00
|
|
|
* @param aAction is the action plugin to be registered.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
static void register_action( ACTION_PLUGIN* aAction );
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Deregister an object which builds a action.
|
|
|
|
*
|
|
|
|
* Lookup on the vector calling GetObject until find, then removed and deleted.
|
2017-01-22 09:05:46 +00:00
|
|
|
*
|
2021-06-04 13:04:30 +00:00
|
|
|
* @param aObject is the action plugin object to be deregistered.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
static bool deregister_object( void* aObject );
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @param aName is the action plugin name.
|
2017-01-22 09:05:46 +00:00
|
|
|
* @return a action object by it's name or NULL if it isn't available.
|
|
|
|
*/
|
2017-09-23 09:20:10 +00:00
|
|
|
static ACTION_PLUGIN* GetAction( const wxString& aName );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Associate a menu id to an action plugin.
|
|
|
|
*
|
|
|
|
* @param aIndex is the action index.
|
|
|
|
* @param idMenu is the associated menuitem ID.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
static void SetActionMenu( int aIndex, int idMenu );
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Find action plugin associated to a menu ID.
|
|
|
|
*
|
|
|
|
* @param aMenu is the menu id (defined with SetActionMenu).
|
|
|
|
* @return the associated ACTION_PLUGIN (or null if not found).
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
2017-01-22 19:23:00 +00:00
|
|
|
static ACTION_PLUGIN* GetActionByMenu( int aMenu );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Associate a button id to an action plugin.
|
|
|
|
*
|
|
|
|
* @param aAction is the action.
|
|
|
|
* @param idButton is the associated menuitem ID.
|
2018-08-15 09:26:32 +00:00
|
|
|
*/
|
|
|
|
static void SetActionButton( ACTION_PLUGIN* aAction, int idButton );
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Find action plugin associated to a button ID.
|
|
|
|
*
|
|
|
|
* @param aButton is the button id (defined with SetActionButton).
|
|
|
|
* @return the associated ACTION_PLUGIN (or null if not found).
|
2018-08-15 09:26:32 +00:00
|
|
|
*/
|
|
|
|
static ACTION_PLUGIN* GetActionByButton( int aButton );
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Find action plugin by module path.
|
|
|
|
*
|
|
|
|
* @param aPath is the path of plugin.
|
|
|
|
* @return the corresponding ACTION_PLUGIN (or null if not found).
|
2018-08-15 09:26:32 +00:00
|
|
|
*/
|
|
|
|
static ACTION_PLUGIN* GetActionByPath( const wxString& aPath );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @param aIndex is the action index in list.
|
2017-01-22 09:05:46 +00:00
|
|
|
* @return a action object by it's number or NULL if it isn't available.
|
|
|
|
*/
|
|
|
|
static ACTION_PLUGIN* GetAction( int aIndex );
|
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @return the number of actions available into the system.
|
2017-01-22 09:05:46 +00:00
|
|
|
*/
|
|
|
|
static int GetActionsCount();
|
2018-03-06 08:28:57 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* @return true if an action running right now otherwise false.
|
2018-03-06 08:28:57 +00:00
|
|
|
*/
|
|
|
|
static bool IsActionRunning();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param aRunning sets whether an action is running now.
|
|
|
|
*/
|
|
|
|
static void SetActionRunning( bool aRunning );
|
2021-02-20 16:19:24 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-04 13:04:30 +00:00
|
|
|
* Unload (deregister) all action plugins.
|
2021-02-20 16:19:24 +00:00
|
|
|
*/
|
|
|
|
static void UnloadAll();
|
2021-06-04 13:04:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* ACTION_PLUGIN system wide static list.
|
|
|
|
*/
|
|
|
|
static std::vector<ACTION_PLUGIN*> m_actionsList;
|
|
|
|
static bool m_actionRunning;
|
2017-01-22 09:05:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PCBNEW_ACTION_PLUGINS_H */
|