2017-01-22 09:05:46 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-02-09 16:35:43 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pcbnew_action_plugins.h"
|
2021-08-29 23:33:08 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <settings/settings_manager.h>
|
|
|
|
#include <pcbnew_settings.h>
|
2021-03-07 20:31:19 +00:00
|
|
|
#include <bitmaps.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <board_commit.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2020-11-11 23:05:59 +00:00
|
|
|
#include <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-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>
|
2021-06-06 12:41:16 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2021-03-08 14:54:22 +00:00
|
|
|
#include "../../scripting/python_scripting.h"
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
PYTHON_ACTION_PLUGIN::PYTHON_ACTION_PLUGIN( PyObject* aAction )
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
2021-02-09 16:35:43 +00:00
|
|
|
m_PyAction = aAction;
|
2017-01-22 09:05:46 +00:00
|
|
|
Py_XINCREF( aAction );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PYTHON_ACTION_PLUGIN::~PYTHON_ACTION_PLUGIN()
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
2021-02-09 16:35:43 +00:00
|
|
|
Py_XDECREF( m_PyAction );
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PyObject* PYTHON_ACTION_PLUGIN::CallMethod( const char* aMethod, PyObject* aArglist )
|
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
|
|
|
PyErr_Clear();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2017-01-22 09:05:46 +00:00
|
|
|
// pFunc is a new reference to the desired method
|
2021-02-09 16:35:43 +00:00
|
|
|
PyObject* pFunc = PyObject_GetAttrString( m_PyAction, aMethod );
|
2017-01-22 09:05:46 +00:00
|
|
|
|
|
|
|
if( pFunc && PyCallable_Check( pFunc ) )
|
|
|
|
{
|
|
|
|
PyObject* result = PyObject_CallObject( pFunc, aArglist );
|
|
|
|
|
|
|
|
if( PyErr_Occurred() )
|
|
|
|
{
|
|
|
|
wxMessageBox( PyErrStringWithTraceback(),
|
2021-07-19 23:56:05 +00:00
|
|
|
_( "Exception on python action plugin code" ),
|
|
|
|
wxICON_ERROR | wxOK );
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( result )
|
|
|
|
{
|
|
|
|
Py_XDECREF( pFunc );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-04 00:02:14 +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 );
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
return nullptr;
|
2017-01-22 09:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-24 22:11:32 +00:00
|
|
|
wxString PYTHON_ACTION_PLUGIN::GetIconFileName( bool aDark )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
|
|
|
PyLOCK lock;
|
|
|
|
|
2021-03-24 22:11:32 +00:00
|
|
|
PyObject* arglist = Py_BuildValue( "(i)", static_cast<int>( aDark ) );
|
2021-03-22 04:50:42 +00:00
|
|
|
|
|
|
|
wxString result = CallRetStrMethod( "GetIconFileName", arglist );
|
|
|
|
|
|
|
|
Py_DECREF( arglist );
|
|
|
|
|
|
|
|
return result;
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-03-19 23:06:29 +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
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
// Append tracks:
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_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
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Append footprints:
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* item : currentPcb->Footprints() )
|
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-11-11 23:05:59 +00:00
|
|
|
for( ZONE* 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 )
|
2021-02-12 19:26:48 +00:00
|
|
|
SaveCopyInUndoList( itemsList, UNDO_REDO::CHANGED );
|
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
|
|
|
|
2021-03-18 12:52:17 +00:00
|
|
|
BOARD_COMMIT commit( this );
|
|
|
|
|
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
|
2021-07-19 23:56:05 +00:00
|
|
|
PICKED_ITEMS_LIST* oldBuffer = nullptr;
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
if( fromEmpty )
|
|
|
|
{
|
|
|
|
oldBuffer = new PICKED_ITEMS_LIST();
|
|
|
|
}
|
|
|
|
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:
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* item : currentPcb->Tracks() )
|
2019-09-23 12:07:45 +00:00
|
|
|
currItemList.insert( item );
|
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Append footprints:
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* item : currentPcb->Footprints() )
|
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-11-11 23:05:59 +00:00
|
|
|
for( ZONE* zone : currentPcb->Zones() )
|
2020-08-26 23:52:12 +00:00
|
|
|
currItemList.insert( zone );
|
2019-09-23 12:07:45 +00:00
|
|
|
|
2021-03-18 12:52:17 +00:00
|
|
|
// Found deleted items
|
2018-08-15 09:26:32 +00:00
|
|
|
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() )
|
2021-03-18 12:52:17 +00:00
|
|
|
{
|
2019-09-23 12:07:45 +00:00
|
|
|
deletedItemsList.PushItem( picker );
|
2021-03-18 12:52:17 +00:00
|
|
|
commit.Removed( item );
|
|
|
|
}
|
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
|
2021-03-18 12:52:17 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
for( unsigned int i = 0; i < deletedItemsList.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
oldBuffer->PushItem( deletedItemsList.GetItemWrapper( i ) );
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Find new footprints
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* item : currentPcb->Footprints() )
|
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 );
|
2021-03-18 12:52:17 +00:00
|
|
|
commit.Added( item );
|
2017-02-06 07:39:32 +00:00
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_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 );
|
2021-03-18 12:52:17 +00:00
|
|
|
commit.Added( item );
|
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 );
|
2021-03-18 12:52:17 +00:00
|
|
|
commit.Added( item );
|
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-11-11 23:05:59 +00:00
|
|
|
for( ZONE* 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 );
|
2021-03-18 12:52:17 +00:00
|
|
|
commit.Added( zone );
|
2017-02-06 07:39:32 +00:00
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
2017-02-06 07:39:32 +00:00
|
|
|
|
2021-03-18 12:52:17 +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
|
|
|
|
2021-03-18 12:52:17 +00:00
|
|
|
commit.Push( _( "Apply action script" ) );
|
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 );
|
2021-07-19 23:56:05 +00:00
|
|
|
const wxBitmap& bitmap = ap->iconBitmap.IsOk() ? ap->iconBitmap :
|
|
|
|
KiBitmap( BITMAPS::puzzle_piece );
|
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,
|
2021-07-19 23:56:05 +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
|
2021-03-08 02:59:07 +00:00
|
|
|
bitmap = KiScaledBitmap( BITMAPS::puzzle_piece, this );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
wxAuiToolBarItem* button = m_mainToolBar->AddTool( wxID_ANY, wxEmptyString,
|
|
|
|
bitmap, ap->GetName() );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
Connect( button->GetId(), wxEVT_COMMAND_MENU_SELECTED,
|
2021-07-19 23:56:05 +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()
|
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
|
|
|
|
|
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
|
2021-08-29 23:33:08 +00:00
|
|
|
for( const auto& pair : cfg->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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
bool PCB_EDIT_FRAME::GetActionPluginButtonVisible( const wxString& aPluginPath,
|
|
|
|
bool aPluginDefault )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<PCBNEW_SETTINGS>();
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
for( const auto& entry : cfg->m_VisibleActionPlugins )
|
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;
|
|
|
|
}
|