2017-01-22 09:05:46 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-08-26 23:52:12 +00:00
|
|
|
* Copyright (C) 2017-2020 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pcbnew_action_plugins.h"
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
2017-02-06 07:39:32 +00:00
|
|
|
#include <class_zone.h>
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <menus_helpers.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2019-12-05 14:03:15 +00:00
|
|
|
#include <python_scripting.h>
|
2019-06-03 13:49:17 +00:00
|
|
|
#include <tool/action_menu.h>
|
2019-06-09 21:57:23 +00:00
|
|
|
#include <tool/action_toolbar.h>
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
PYTHON_ACTION_PLUGIN::PYTHON_ACTION_PLUGIN( PyObject* aAction )
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
this->m_PyAction = aAction;
|
|
|
|
Py_XINCREF( aAction );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PYTHON_ACTION_PLUGIN::~PYTHON_ACTION_PLUGIN()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
Py_XDECREF( this->m_PyAction );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PyObject* PYTHON_ACTION_PLUGIN::CallMethod( const char* aMethod, PyObject* aArglist )
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
PyErr_Clear();
|
|
|
|
// pFunc is a new reference to the desired method
|
|
|
|
PyObject* pFunc = PyObject_GetAttrString( this->m_PyAction, aMethod );
|
|
|
|
|
|
|
|
if( pFunc && PyCallable_Check( pFunc ) )
|
|
|
|
{
|
|
|
|
PyObject* result = PyObject_CallObject( pFunc, aArglist );
|
|
|
|
|
|
|
|
if( PyErr_Occurred() )
|
|
|
|
{
|
|
|
|
wxMessageBox( PyErrStringWithTraceback(),
|
2018-03-30 16:43:17 +00:00
|
|
|
_( "Exception on python action plugin code" ),
|
2017-01-22 09:05:46 +00:00
|
|
|
wxICON_ERROR | wxOK );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( result )
|
|
|
|
{
|
|
|
|
Py_XDECREF( pFunc );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-11 07:46:37 +00:00
|
|
|
wxString msg = wxString::Format( _( "Method \"%s\" not found, or not callable" ), aMethod );
|
2018-03-30 16:43:17 +00:00
|
|
|
wxMessageBox( msg, _( "Unknown Method" ), wxICON_ERROR | wxOK );
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( pFunc )
|
|
|
|
{
|
|
|
|
Py_XDECREF( pFunc );
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PYTHON_ACTION_PLUGIN::CallRetStrMethod( const char* aMethod, PyObject* aArglist )
|
|
|
|
{
|
|
|
|
wxString ret;
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
PyObject* result = CallMethod( aMethod, aArglist );
|
|
|
|
|
2018-10-12 19:36:50 +00:00
|
|
|
ret = PyStringToWx( result );
|
|
|
|
Py_XDECREF( result );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PYTHON_ACTION_PLUGIN::GetCategoryName()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
return CallRetStrMethod( "GetCategoryName" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PYTHON_ACTION_PLUGIN::GetName()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
return CallRetStrMethod( "GetName" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PYTHON_ACTION_PLUGIN::GetDescription()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
return CallRetStrMethod( "GetDescription" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
bool PYTHON_ACTION_PLUGIN::GetShowToolbarButton()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
PyObject* result = CallMethod( "GetShowToolbarButton");
|
|
|
|
|
|
|
|
return PyObject_IsTrue(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PYTHON_ACTION_PLUGIN::GetIconFileName()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
return CallRetStrMethod( "GetIconFileName" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString PYTHON_ACTION_PLUGIN::GetPluginPath()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
return CallRetStrMethod( "GetPluginPath" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-22 09:05:46 +00:00
|
|
|
void PYTHON_ACTION_PLUGIN::Run()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
CallMethod( "Run" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void* PYTHON_ACTION_PLUGIN::GetObject()
|
|
|
|
{
|
|
|
|
return (void*) m_PyAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PYTHON_ACTION_PLUGINS::register_action( PyObject* aPyAction )
|
|
|
|
{
|
|
|
|
PYTHON_ACTION_PLUGIN* fw = new PYTHON_ACTION_PLUGIN( aPyAction );
|
|
|
|
|
|
|
|
fw->register_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PYTHON_ACTION_PLUGINS::deregister_action( PyObject* aPyAction )
|
|
|
|
{
|
2018-08-15 09:26:32 +00:00
|
|
|
// deregister also destroys the previously created "PYTHON_ACTION_PLUGIN object"
|
2017-01-22 09:05:46 +00:00
|
|
|
ACTION_PLUGINS::deregister_object( (void*) aPyAction );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
|
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
void PCB_EDIT_FRAME::OnActionPluginMenu( wxCommandEvent& aEvent )
|
2017-01-22 09:05:46 +00:00
|
|
|
{
|
2018-08-15 09:26:32 +00:00
|
|
|
ACTION_PLUGIN* actionPlugin = ACTION_PLUGINS::GetActionByMenu( aEvent.GetId() );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
if( actionPlugin )
|
|
|
|
RunActionPlugin( actionPlugin );
|
|
|
|
}
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
void PCB_EDIT_FRAME::OnActionPluginButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
ACTION_PLUGIN* actionPlugin = ACTION_PLUGINS::GetActionByButton( aEvent.GetId() );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
if( actionPlugin )
|
|
|
|
RunActionPlugin( actionPlugin );
|
|
|
|
}
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
void PCB_EDIT_FRAME::RunActionPlugin( ACTION_PLUGIN* aActionPlugin )
|
|
|
|
{
|
2019-09-23 12:07:45 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
PICKED_ITEMS_LIST itemsList;
|
|
|
|
BOARD* currentPcb = GetBoard();
|
|
|
|
bool fromEmpty = false;
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2020-08-26 18:04:32 +00:00
|
|
|
itemsList.m_Status = UNDO_REDO::CHANGED;
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Append tracks:
|
2020-08-26 23:52:12 +00:00
|
|
|
for( TRACK* item : currentPcb->Tracks() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED );
|
2018-08-15 09:26:32 +00:00
|
|
|
itemsList.PushItem( picker );
|
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Append modules:
|
2020-08-26 23:52:12 +00:00
|
|
|
for( MODULE* item : currentPcb->Modules() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED );
|
2018-08-15 09:26:32 +00:00
|
|
|
itemsList.PushItem( picker );
|
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Append drawings
|
2020-08-26 23:52:12 +00:00
|
|
|
for( BOARD_ITEM* item : currentPcb->Drawings() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, item, UNDO_REDO::CHANGED );
|
2018-08-15 09:26:32 +00:00
|
|
|
itemsList.PushItem( picker );
|
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Append zones outlines
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : currentPcb->Zones() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::CHANGED );
|
2018-08-15 09:26:32 +00:00
|
|
|
itemsList.PushItem( picker );
|
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
if( itemsList.GetCount() > 0 )
|
2020-08-26 18:04:32 +00:00
|
|
|
SaveCopyInUndoList( itemsList, UNDO_REDO::CHANGED, wxPoint( 0.0, 0.0 ) );
|
2018-08-15 09:26:32 +00:00
|
|
|
else
|
|
|
|
fromEmpty = true;
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
itemsList.ClearItemsList();
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Execute plugin itself...
|
|
|
|
ACTION_PLUGINS::SetActionRunning( true );
|
|
|
|
aActionPlugin->Run();
|
|
|
|
ACTION_PLUGINS::SetActionRunning( false );
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Get back the undo buffer to fix some modifications
|
|
|
|
PICKED_ITEMS_LIST* oldBuffer = NULL;
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
if( fromEmpty )
|
|
|
|
{
|
|
|
|
oldBuffer = new PICKED_ITEMS_LIST();
|
2020-08-26 18:04:32 +00:00
|
|
|
oldBuffer->m_Status = UNDO_REDO::NEWITEM;
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
oldBuffer = PopCommandFromUndoList();
|
2018-08-15 09:26:32 +00:00
|
|
|
wxASSERT( oldBuffer );
|
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Try do discover what was modified
|
|
|
|
PICKED_ITEMS_LIST deletedItemsList;
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2019-09-23 12:07:45 +00:00
|
|
|
// The list of existing items after running the action script
|
|
|
|
std::set<BOARD_ITEM*> currItemList;
|
2020-08-26 23:52:12 +00:00
|
|
|
|
2019-09-23 12:07:45 +00:00
|
|
|
// Append tracks:
|
2020-07-13 11:21:40 +00:00
|
|
|
for( TRACK* item : currentPcb->Tracks() )
|
2019-09-23 12:07:45 +00:00
|
|
|
currItemList.insert( item );
|
|
|
|
|
|
|
|
// Append modules:
|
2020-07-13 11:21:40 +00:00
|
|
|
for( MODULE* item : currentPcb->Modules() )
|
2019-09-23 12:07:45 +00:00
|
|
|
currItemList.insert( item );
|
|
|
|
|
|
|
|
// Append drawings
|
2020-07-13 11:21:40 +00:00
|
|
|
for( BOARD_ITEM* item : currentPcb->Drawings() )
|
2019-09-23 12:07:45 +00:00
|
|
|
currItemList.insert( item );
|
|
|
|
|
|
|
|
// Append zones outlines
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : currentPcb->Zones() )
|
|
|
|
currItemList.insert( zone );
|
2019-09-23 12:07:45 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Found deleted modules
|
|
|
|
for( unsigned int i = 0; i < oldBuffer->GetCount(); i++ )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = (BOARD_ITEM*) oldBuffer->GetPickedItem( i );
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, item, UNDO_REDO::DELETED );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
wxASSERT( item );
|
|
|
|
|
2019-09-23 12:07:45 +00:00
|
|
|
if( currItemList.find( item ) == currItemList.end() )
|
|
|
|
deletedItemsList.PushItem( picker );
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Mark deleted elements in undolist
|
|
|
|
for( unsigned int i = 0; i < deletedItemsList.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
oldBuffer->PushItem( deletedItemsList.GetItemWrapper( i ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find new modules
|
2020-07-13 11:21:40 +00:00
|
|
|
for( MODULE* item : currentPcb->Modules() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
|
|
|
if( !oldBuffer->ContainsItem( item ) )
|
2017-02-06 07:39:32 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM );
|
2018-08-15 09:26:32 +00:00
|
|
|
oldBuffer->PushItem( picker );
|
2017-02-06 07:39:32 +00:00
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
for( TRACK* item : currentPcb->Tracks() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
|
|
|
if( !oldBuffer->ContainsItem( item ) )
|
2017-02-06 07:39:32 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM );
|
2018-08-15 09:26:32 +00:00
|
|
|
oldBuffer->PushItem( picker );
|
2017-02-06 07:39:32 +00:00
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
for( BOARD_ITEM* item : currentPcb->Drawings() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
|
|
|
if( !oldBuffer->ContainsItem( item ) )
|
2017-02-06 07:39:32 +00:00
|
|
|
{
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER picker( nullptr, item, UNDO_REDO::NEWITEM );
|
2018-08-15 09:26:32 +00:00
|
|
|
oldBuffer->PushItem( picker );
|
2017-02-06 07:39:32 +00:00
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ZONE_CONTAINER* zone : currentPcb->Zones() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
if( !oldBuffer->ContainsItem( zone ) )
|
2017-02-06 07:39:32 +00:00
|
|
|
{
|
2020-08-26 23:52:12 +00:00
|
|
|
ITEM_PICKER picker( nullptr, zone, UNDO_REDO::NEWITEM );
|
2018-08-15 09:26:32 +00:00
|
|
|
oldBuffer->PushItem( picker );
|
2017-02-06 07:39:32 +00:00
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2019-09-23 12:07:45 +00:00
|
|
|
if( oldBuffer->GetCount() )
|
|
|
|
{
|
|
|
|
OnModify();
|
2020-07-13 11:21:40 +00:00
|
|
|
PushCommandToUndoList( oldBuffer );
|
2019-09-23 12:07:45 +00:00
|
|
|
}
|
2020-01-11 16:31:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
delete oldBuffer;
|
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2019-05-30 12:25:08 +00:00
|
|
|
ActivateGalCanvas();
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-03 13:49:17 +00:00
|
|
|
void PCB_EDIT_FRAME::buildActionPluginMenus( ACTION_MENU* actionMenu )
|
2017-01-22 09:05:46 +00:00
|
|
|
{
|
2017-02-06 07:39:32 +00:00
|
|
|
if( !actionMenu ) // Should not occur.
|
2017-01-22 19:23:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < ACTION_PLUGINS::GetActionsCount(); ii++ )
|
|
|
|
{
|
|
|
|
wxMenuItem* item;
|
2018-08-15 09:26:32 +00:00
|
|
|
ACTION_PLUGIN* ap = ACTION_PLUGINS::GetAction( ii );
|
|
|
|
const wxBitmap& bitmap = ap->iconBitmap.IsOk() ? ap->iconBitmap : KiBitmap( hammer_xpm );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2019-06-03 13:49:17 +00:00
|
|
|
item = AddMenuItem( actionMenu, wxID_ANY, ap->GetName(), ap->GetDescription(), bitmap );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2019-06-03 13:49:17 +00:00
|
|
|
Connect( item->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
2020-01-09 18:01:54 +00:00
|
|
|
wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginMenu ) );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
2017-01-22 19:23:00 +00:00
|
|
|
ACTION_PLUGINS::SetActionMenu( ii, item->GetId() );
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
void PCB_EDIT_FRAME::AddActionPluginTools()
|
|
|
|
{
|
|
|
|
bool need_separator = true;
|
2020-08-26 23:52:12 +00:00
|
|
|
const std::vector<ACTION_PLUGIN*>& orderedPlugins = GetOrderedActionPlugins();
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2020-08-26 23:52:12 +00:00
|
|
|
for( ACTION_PLUGIN* ap : orderedPlugins )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
|
|
|
if( GetActionPluginButtonVisible( ap->GetPluginPath(), ap->GetShowToolbarButton() ) )
|
|
|
|
{
|
2020-06-17 11:03:25 +00:00
|
|
|
if( need_separator )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-06-17 11:03:25 +00:00
|
|
|
m_mainToolBar->AddScaledSeparator( this );
|
2018-08-15 09:26:32 +00:00
|
|
|
need_separator = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add button
|
|
|
|
wxBitmap bitmap;
|
|
|
|
|
|
|
|
if ( ap->iconBitmap.IsOk() )
|
|
|
|
bitmap = KiScaledBitmap( ap->iconBitmap, this );
|
|
|
|
else
|
|
|
|
bitmap = KiScaledBitmap( hammer_xpm, this );
|
|
|
|
|
|
|
|
wxAuiToolBarItem* button = m_mainToolBar->AddTool(
|
|
|
|
wxID_ANY, wxEmptyString, bitmap, ap->GetName() );
|
|
|
|
|
|
|
|
Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
2020-01-09 18:01:54 +00:00
|
|
|
wxCommandEventHandler( PCB_EDIT_FRAME::OnActionPluginButton ) );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
// Link action plugin to button
|
|
|
|
ACTION_PLUGINS::SetActionButton( ap, button->GetId() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<ACTION_PLUGIN*> PCB_EDIT_FRAME::GetOrderedActionPlugins()
|
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
std::vector<ACTION_PLUGIN*> plugins;
|
2018-08-15 09:26:32 +00:00
|
|
|
std::vector<ACTION_PLUGIN*> orderedPlugins;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
for( int i = 0; i < ACTION_PLUGINS::GetActionsCount(); i++ )
|
|
|
|
plugins.push_back( ACTION_PLUGINS::GetAction( i ) );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
// First add plugins that have entries in settings
|
2020-02-20 15:59:45 +00:00
|
|
|
for( const auto& pair : m_Settings->m_VisibleActionPlugins )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto loc = std::find_if( plugins.begin(), plugins.end(),
|
2020-02-20 15:59:45 +00:00
|
|
|
[pair] ( ACTION_PLUGIN* plugin )
|
2020-01-13 01:44:19 +00:00
|
|
|
{
|
2020-02-20 15:59:45 +00:00
|
|
|
return plugin->GetPluginPath() == pair.first;
|
2020-01-13 01:44:19 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
if( loc != plugins.end() )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
orderedPlugins.push_back( *loc );
|
|
|
|
plugins.erase( loc );
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now append new plugins that have not been configured yet
|
2020-01-13 01:44:19 +00:00
|
|
|
for( auto remaining_plugin : plugins )
|
|
|
|
orderedPlugins.push_back( remaining_plugin );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
return orderedPlugins;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_EDIT_FRAME::GetActionPluginButtonVisible( const wxString& aPluginPath, bool aPluginDefault )
|
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto& settings = m_Settings->m_VisibleActionPlugins;
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
for( const auto& entry : settings )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2020-02-20 15:59:45 +00:00
|
|
|
if( entry.first == aPluginPath )
|
|
|
|
return entry.second;
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Plugin is not in settings, return default.
|
|
|
|
return aPluginDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-22 09:05:46 +00:00
|
|
|
#endif
|