2018-08-15 09:26:32 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Andrew Lutsenko, anlutsenko at gmail dot com
|
2022-08-18 16:56:36 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-08-15 09:26:32 +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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-03-19 23:06:29 +00:00
|
|
|
#include <action_plugin.h>
|
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <dialog_footprint_wizard_list.h>
|
|
|
|
#include <grid_tricks.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2021-03-19 23:06:29 +00:00
|
|
|
#include <panel_pcbnew_action_plugins.h>
|
2018-08-15 09:26:32 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2021-03-19 23:38:11 +00:00
|
|
|
#include <python/scripting/pcbnew_scripting.h>
|
2021-08-29 23:33:08 +00:00
|
|
|
#include <pcb_scripting_tool.h>
|
2020-02-20 15:59:45 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2018-08-15 09:26:32 +00:00
|
|
|
#include <widgets/grid_icon_text_helpers.h>
|
2021-03-19 23:06:29 +00:00
|
|
|
#include <widgets/paged_dialog.h>
|
2018-08-15 09:26:32 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2021-06-03 15:41:26 +00:00
|
|
|
|
|
|
|
|
2020-08-05 18:37:04 +00:00
|
|
|
#define GRID_CELL_MARGIN 4
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
PANEL_PCBNEW_ACTION_PLUGINS::PANEL_PCBNEW_ACTION_PLUGINS( wxWindow* aParent ) :
|
|
|
|
PANEL_PCBNEW_ACTION_PLUGINS_BASE( aParent )
|
2018-08-15 09:26:32 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
m_genericIcon = KiBitmap( BITMAPS::puzzle_piece );
|
2018-08-15 09:26:32 +00:00
|
|
|
m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
|
2024-02-05 05:52:11 +00:00
|
|
|
m_grid->SetUseNativeColLabels();
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2023-10-21 18:56:19 +00:00
|
|
|
m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
|
|
|
|
m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
|
|
|
|
m_openDirectoryButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
|
|
|
m_reloadButton->SetBitmap( KiBitmapBundle( BITMAPS::small_refresh ) );
|
|
|
|
m_showErrorsButton->SetBitmap( KiBitmapBundle( BITMAPS::small_warning ) );
|
2018-08-15 09:26:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PANEL_PCBNEW_ACTION_PLUGINS::~PANEL_PCBNEW_ACTION_PLUGINS()
|
|
|
|
{
|
|
|
|
m_grid->PopEventHandler( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::OnGridCellClick( wxGridEvent& event )
|
|
|
|
{
|
|
|
|
SelectRow( event.GetRow() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::SelectRow( int aRow )
|
|
|
|
{
|
|
|
|
m_grid->ClearSelection();
|
|
|
|
m_grid->SelectRow( aRow );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveUpButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
auto selectedRows = m_grid->GetSelectedRows();
|
|
|
|
|
|
|
|
// If nothing is selected or multiple rows are selected don't do anything.
|
|
|
|
if( selectedRows.size() != 1 ) return;
|
|
|
|
|
|
|
|
int selectedRow = selectedRows[0];
|
|
|
|
|
|
|
|
// If first row is selected, then it can't go any further up.
|
|
|
|
if( selectedRow == 0 )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwapRows( selectedRow, selectedRow - 1 );
|
|
|
|
|
|
|
|
SelectRow( selectedRow - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::OnMoveDownButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
auto selectedRows = m_grid->GetSelectedRows();
|
|
|
|
|
|
|
|
// If nothing is selected or multiple rows are selected don't do anything.
|
|
|
|
if( selectedRows.size() != 1 ) return;
|
|
|
|
|
|
|
|
int selectedRow = selectedRows[0];
|
|
|
|
|
|
|
|
// If last row is selected, then it can't go any further down.
|
|
|
|
if( selectedRow + 1 == m_grid->GetNumberRows() )
|
|
|
|
{
|
|
|
|
wxBell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwapRows( selectedRow, selectedRow + 1 );
|
|
|
|
|
|
|
|
SelectRow( selectedRow + 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::SwapRows( int aRowA, int aRowB )
|
|
|
|
{
|
|
|
|
m_grid->Freeze();
|
|
|
|
|
|
|
|
// Swap all columns except icon
|
|
|
|
wxString tempStr;
|
|
|
|
|
|
|
|
for( int column = 1; column < m_grid->GetNumberCols(); column++ )
|
|
|
|
{
|
|
|
|
tempStr = m_grid->GetCellValue( aRowA, column );
|
|
|
|
m_grid->SetCellValue( aRowA, column, m_grid->GetCellValue( aRowB, column ) );
|
|
|
|
m_grid->SetCellValue( aRowB, column, tempStr );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Swap icon column renderers
|
|
|
|
auto cellRenderer = m_grid->GetCellRenderer( aRowA, COLUMN_ICON );
|
|
|
|
m_grid->SetCellRenderer( aRowA, COLUMN_ICON, m_grid->GetCellRenderer( aRowB, COLUMN_ICON ) );
|
|
|
|
m_grid->SetCellRenderer( aRowB, COLUMN_ICON, cellRenderer );
|
|
|
|
|
|
|
|
m_grid->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::OnReloadButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
SCRIPTING_TOOL::ReloadPlugins();
|
2018-08-15 09:26:32 +00:00
|
|
|
TransferDataToWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataFromWindow()
|
|
|
|
{
|
2020-03-25 13:13:03 +00:00
|
|
|
PCBNEW_SETTINGS* settings = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-02-20 15:59:45 +00:00
|
|
|
wxASSERT( settings );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2020-03-25 13:13:03 +00:00
|
|
|
if( settings )
|
|
|
|
{
|
|
|
|
settings->m_VisibleActionPlugins.clear();
|
|
|
|
|
|
|
|
for( int ii = 0; ii < m_grid->GetNumberRows(); ii++ )
|
|
|
|
{
|
|
|
|
settings->m_VisibleActionPlugins.emplace_back( std::make_pair(
|
|
|
|
m_grid->GetCellValue( ii, COLUMN_PATH ),
|
|
|
|
m_grid->GetCellValue( ii, COLUMN_VISIBLE ) == wxT( "1" ) ) );
|
|
|
|
}
|
|
|
|
}
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
m_grid->Freeze();
|
2020-03-25 13:13:03 +00:00
|
|
|
|
2021-08-10 11:59:53 +00:00
|
|
|
m_grid->ClearRows();
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
const auto& orderedPlugins = PCB_EDIT_FRAME::GetOrderedActionPlugins();
|
2018-08-15 09:26:32 +00:00
|
|
|
m_grid->AppendRows( orderedPlugins.size() );
|
|
|
|
|
|
|
|
for( size_t row = 0; row < orderedPlugins.size(); row++ )
|
|
|
|
{
|
|
|
|
ACTION_PLUGIN* ap = orderedPlugins[row];
|
|
|
|
|
|
|
|
// Icon
|
|
|
|
m_grid->SetCellRenderer( row, COLUMN_ICON, new GRID_CELL_ICON_RENDERER(
|
|
|
|
ap->iconBitmap.IsOk() ? ap->iconBitmap : m_genericIcon ) );
|
|
|
|
|
|
|
|
// Toolbar button checkbox
|
|
|
|
m_grid->SetCellRenderer( row, COLUMN_VISIBLE, new wxGridCellBoolRenderer() );
|
|
|
|
m_grid->SetCellAlignment( row, COLUMN_VISIBLE, wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
bool show = PCB_EDIT_FRAME::GetActionPluginButtonVisible( ap->GetPluginPath(),
|
|
|
|
ap->GetShowToolbarButton() );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
m_grid->SetCellValue( row, COLUMN_VISIBLE, show ? wxT( "1" ) : wxEmptyString );
|
2018-08-15 09:26:32 +00:00
|
|
|
|
|
|
|
m_grid->SetCellValue( row, COLUMN_NAME, ap->GetName() );
|
|
|
|
m_grid->SetCellValue( row, COLUMN_CATEGORY, ap->GetCategoryName() );
|
|
|
|
m_grid->SetCellValue( row, COLUMN_DESCRIPTION, ap->GetDescription() );
|
|
|
|
m_grid->SetCellValue( row, COLUMN_PATH, ap->GetPluginPath() );
|
|
|
|
}
|
|
|
|
|
2019-02-10 06:59:27 +00:00
|
|
|
for( int col = 0; col < m_grid->GetNumberCols(); col++ )
|
2019-02-10 10:39:07 +00:00
|
|
|
{
|
2020-08-05 18:37:04 +00:00
|
|
|
const wxString& heading = m_grid->GetColLabelValue( col );
|
|
|
|
int headingWidth = GetTextExtent( heading ).x + 2 * GRID_CELL_MARGIN;
|
|
|
|
|
2019-02-10 10:39:07 +00:00
|
|
|
// Set the minimal width to the column label size.
|
2020-08-05 18:37:04 +00:00
|
|
|
m_grid->SetColMinimalWidth( col, headingWidth );
|
2019-02-10 08:49:42 +00:00
|
|
|
// Set the width to see the full contents
|
2022-08-18 16:56:36 +00:00
|
|
|
m_grid->SetColSize( col, m_grid->GetVisibleWidth( col ) );
|
2019-02-10 10:39:07 +00:00
|
|
|
}
|
2019-02-09 23:31:31 +00:00
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
m_grid->AutoSizeRows();
|
|
|
|
|
|
|
|
m_grid->Thaw();
|
|
|
|
|
2020-12-15 22:46:52 +00:00
|
|
|
// Show errors button should be disabled if there are no errors.
|
|
|
|
wxString trace;
|
2021-08-29 23:33:08 +00:00
|
|
|
|
|
|
|
if( ACTION_PLUGINS::GetActionsCount() )
|
|
|
|
pcbnewGetWizardsBackTrace( trace );
|
|
|
|
|
2020-12-15 22:46:52 +00:00
|
|
|
if( trace.empty() )
|
|
|
|
{
|
|
|
|
m_showErrorsButton->Disable();
|
|
|
|
m_showErrorsButton->Hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_showErrorsButton->Enable();
|
|
|
|
m_showErrorsButton->Show();
|
|
|
|
}
|
|
|
|
|
2018-08-15 09:26:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-15 22:46:52 +00:00
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
|
2020-12-15 22:46:52 +00:00
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::OnOpenDirectoryButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
2021-08-29 23:33:08 +00:00
|
|
|
SCRIPTING_TOOL::ShowPluginFolder();
|
2020-12-15 22:46:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 23:33:08 +00:00
|
|
|
|
2020-12-15 22:46:52 +00:00
|
|
|
void PANEL_PCBNEW_ACTION_PLUGINS::OnShowErrorsButtonClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString trace;
|
|
|
|
pcbnewGetWizardsBackTrace( trace );
|
|
|
|
|
|
|
|
// Now display the filtered trace in our dialog
|
|
|
|
// (a simple wxMessageBox is really not suitable for long messages)
|
2024-02-02 17:47:34 +00:00
|
|
|
DIALOG_FOOTPRINT_WIZARD_LOG logWindow( wxGetTopLevelParent( this ) );
|
2020-12-15 22:46:52 +00:00
|
|
|
logWindow.m_Message->SetValue( trace );
|
|
|
|
logWindow.ShowModal();
|
|
|
|
}
|