2013-06-14 16:59:52 +02:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-05-27 20:43:39 +02:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2021-05-06 15:42:15 -04:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-06-14 16:59:52 +02: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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file eeschema/dialogs/dialog_bom.cpp
|
|
|
|
* @brief Dialog box for creating bom and other documents from generic netlist.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-03-07 15:31:19 -05:00
|
|
|
#include <bitmaps.h>
|
2022-12-13 20:47:28 +00:00
|
|
|
#include <widgets/std_bitmap_button.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <bom_plugins.h>
|
2013-06-14 16:59:52 +02:00
|
|
|
#include <confirm.h>
|
2024-09-07 22:24:31 -04:00
|
|
|
#include <dialog_bom.h>
|
2022-01-05 11:05:18 -08:00
|
|
|
#include <dialogs/html_message_box.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <eeschema_settings.h>
|
2013-06-14 16:59:52 +02:00
|
|
|
#include <gestfich.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <i18n_utility.h> // for _HKI definition used in dialog_bom_help_md.h
|
|
|
|
#include <invoke_sch_dialog.h>
|
2021-09-14 23:45:14 +01:00
|
|
|
#include <kiface_base.h>
|
2022-01-05 11:05:18 -08:00
|
|
|
#include <netlist.h>
|
2020-11-15 13:58:21 +00:00
|
|
|
#include <netlist_exporter_xml.h>
|
2022-01-05 11:05:18 -08:00
|
|
|
#include <paths.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <pgm_base.h>
|
2015-06-12 09:02:06 +02:00
|
|
|
#include <reporter.h>
|
2020-01-12 20:44:19 -05:00
|
|
|
#include <sch_edit_frame.h>
|
2022-01-05 11:05:18 -08:00
|
|
|
#include <string_utils.h>
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2020-10-18 20:24:20 +02:00
|
|
|
#include <wx/filedlg.h>
|
2021-06-03 08:11:15 -04:00
|
|
|
#include <wx/log.h>
|
2024-04-27 22:57:24 +03:00
|
|
|
#include <wx/msgdlg.h>
|
2020-10-18 20:24:20 +02:00
|
|
|
#include <wx/textdlg.h>
|
|
|
|
|
2019-12-29 09:53:39 +01:00
|
|
|
wxString s_bomHelpInfo =
|
|
|
|
#include <dialog_bom_help_md.h>
|
2013-06-14 16:59:52 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
// Create and show DIALOG_BOM.
|
|
|
|
int InvokeDialogCreateBOM( SCH_EDIT_FRAME* aCaller )
|
|
|
|
{
|
|
|
|
DIALOG_BOM dlg( aCaller );
|
2020-10-29 22:46:33 +00:00
|
|
|
|
|
|
|
// QuasiModal so syntax help works
|
|
|
|
return dlg.ShowQuasiModal();
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
DIALOG_BOM::DIALOG_BOM( SCH_EDIT_FRAME* parent ) :
|
2020-12-07 12:15:52 +00:00
|
|
|
DIALOG_BOM_BASE( parent ),
|
|
|
|
m_parent( parent ),
|
|
|
|
m_initialized( false ),
|
|
|
|
m_helpWindow( nullptr )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2023-10-21 14:56:19 -04:00
|
|
|
m_buttonAddGenerator->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
|
|
|
|
m_buttonDelGenerator->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
|
|
|
|
m_buttonEdit->SetBitmap( KiBitmapBundle( BITMAPS::small_edit ) );
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
installGeneratorsList();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2017-10-09 20:57:41 +02:00
|
|
|
#ifndef __WINDOWS__
|
|
|
|
m_checkBoxShowConsole->Show( false );
|
2016-03-31 08:28:16 +02:00
|
|
|
#endif
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Generate" ) },
|
|
|
|
{ wxID_CANCEL, _( "Close" ) } } );
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
SetInitialFocus( m_lbGenerators );
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2016-07-18 09:04:13 +02:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2021-02-24 22:37:30 -05:00
|
|
|
|
|
|
|
m_buttonReset->Bind( wxEVT_BUTTON,
|
|
|
|
[&]( wxCommandEvent& )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
|
|
|
|
|
|
|
cfg->m_BomPanel.selected_plugin = wxEmptyString;
|
|
|
|
cfg->m_BomPanel.plugins = cfg->DefaultBomPlugins();
|
|
|
|
|
|
|
|
installGeneratorsList();
|
|
|
|
} );
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
DIALOG_BOM::~DIALOG_BOM()
|
|
|
|
{
|
2020-12-07 12:15:52 +00:00
|
|
|
if( m_helpWindow )
|
|
|
|
m_helpWindow->Destroy();
|
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
2020-01-12 20:44:19 -05:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
cfg->m_BomPanel.plugins.clear();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
for( const std::unique_ptr<BOM_GENERATOR_HANDLER>& plugin : m_generators )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2021-02-24 22:37:30 -05:00
|
|
|
wxString name = plugin->GetName();
|
2021-02-25 22:31:44 -05:00
|
|
|
wxFileName path( plugin->GetStoredPath() );
|
2016-03-31 08:28:16 +02:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
// handle empty nickname by stripping path
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
name = path.GetName();
|
2018-12-28 20:30:37 +00:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS setting( name, path.GetFullPath() );
|
|
|
|
setting.command = plugin->GetCommand();
|
2018-12-28 20:30:37 +00:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
cfg->m_BomPanel.plugins.emplace_back( setting );
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
2014-12-03 17:22:06 +01:00
|
|
|
|
2020-01-12 20:44:19 -05:00
|
|
|
cfg->m_BomPanel.selected_plugin = m_lbGenerators->GetStringSelection().ToStdString();
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 10:33:19 -04:00
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
// Read the initialized plugins in config and fill the list of names
|
2019-05-27 20:43:39 +02:00
|
|
|
void DIALOG_BOM::installGeneratorsList()
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2021-02-24 22:37:30 -05:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_parent->eeconfig();
|
2020-01-12 20:44:19 -05:00
|
|
|
|
|
|
|
wxString active_plugin_name = cfg->m_BomPanel.selected_plugin;
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
m_generators.clear();
|
2018-10-25 10:33:19 -04:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
for( EESCHEMA_SETTINGS::BOM_PLUGIN_SETTINGS& setting : cfg->m_BomPanel.plugins )
|
|
|
|
{
|
|
|
|
auto plugin = std::make_unique<BOM_GENERATOR_HANDLER>( setting.path );
|
2018-11-19 14:44:26 +01:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
plugin->SetName( setting.name );
|
2021-01-11 13:50:01 -08:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
if( !setting.command.IsEmpty() )
|
|
|
|
plugin->SetCommand( setting.command );
|
2018-11-19 14:44:26 +01:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
m_generators.emplace_back( std::move( plugin ) );
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
m_lbGenerators->Clear();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
if( !m_generators.empty() )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < m_generators.size(); ii++ )
|
2018-11-19 14:44:26 +01:00
|
|
|
{
|
2021-02-25 22:31:44 -05:00
|
|
|
wxString name = m_generators[ii]->GetName();
|
|
|
|
|
2021-02-24 22:37:30 -05:00
|
|
|
if( !m_generators[ii]->FindFilePath().Exists( wxFILE_EXISTS_REGULAR ) )
|
|
|
|
{
|
2023-01-16 23:14:38 -05:00
|
|
|
wxLogTrace( BOM_TRACE, wxS( "BOM plugin %s not found" ),
|
2021-02-24 22:37:30 -05:00
|
|
|
m_generators[ii]->FindFilePath().GetFullName() );
|
2021-02-25 22:31:44 -05:00
|
|
|
name.Append( wxT( " " ) + _( "(file missing)" ) );
|
|
|
|
|
|
|
|
if( active_plugin_name == name )
|
|
|
|
active_plugin_name.Clear();
|
2021-02-24 22:37:30 -05:00
|
|
|
}
|
2018-11-19 14:44:26 +01:00
|
|
|
|
2021-02-25 22:31:44 -05:00
|
|
|
m_lbGenerators->Append( name );
|
2018-11-19 14:44:26 +01:00
|
|
|
|
2021-02-25 22:31:44 -05:00
|
|
|
if( active_plugin_name == name )
|
2021-02-24 22:37:30 -05:00
|
|
|
m_lbGenerators->SetSelection( ii );
|
2018-11-19 14:44:26 +01:00
|
|
|
}
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pluginInit();
|
|
|
|
}
|
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
BOM_GENERATOR_HANDLER* DIALOG_BOM::addGenerator( const wxString& aPath, const wxString& aName )
|
2018-11-19 14:44:26 +01:00
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
BOM_GENERATOR_HANDLER* ret = nullptr;
|
|
|
|
auto plugin = std::make_unique<BOM_GENERATOR_HANDLER>( aPath );
|
2018-11-19 14:44:26 +01:00
|
|
|
|
2022-07-07 12:38:34 +02:00
|
|
|
if( !plugin->IsOk() )
|
2018-11-19 14:44:26 +01:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if( !aName.IsEmpty() )
|
|
|
|
{
|
|
|
|
plugin->SetName( aName );
|
2019-05-27 20:43:39 +02:00
|
|
|
m_lbGenerators->Append( aName );
|
2018-11-19 14:44:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
m_lbGenerators->Append( plugin->GetName() );
|
2018-11-19 14:44:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = plugin.get();
|
2019-05-27 20:43:39 +02:00
|
|
|
m_generators.push_back( std::move( plugin ) );
|
2018-11-19 14:44:26 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_BOM::pluginExists( const wxString& aName )
|
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
for( unsigned ii = 0; ii < m_generators.size(); ii++ )
|
2018-11-19 14:44:26 +01:00
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
if( aName == m_generators[ii]->GetName() )
|
2018-11-19 14:44:26 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
void DIALOG_BOM::OnGeneratorSelected( wxCommandEvent& event )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
|
|
|
pluginInit();
|
|
|
|
}
|
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
void DIALOG_BOM::pluginInit()
|
|
|
|
{
|
2021-02-25 22:31:44 -05:00
|
|
|
BOM_GENERATOR_HANDLER* plugin = selectedGenerator();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
if( !plugin )
|
2013-06-15 20:02:52 +02:00
|
|
|
{
|
|
|
|
m_textCtrlName->SetValue( wxEmptyString );
|
|
|
|
m_textCtrlCommand->SetValue( wxEmptyString );
|
2018-11-12 14:45:07 +01:00
|
|
|
m_Messages->SetValue( wxEmptyString );
|
2013-06-14 16:59:52 +02:00
|
|
|
return;
|
2013-06-15 20:02:52 +02:00
|
|
|
}
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2021-02-25 22:31:44 -05:00
|
|
|
if( !plugin->FindFilePath().Exists( wxFILE_EXISTS_REGULAR ) )
|
|
|
|
{
|
|
|
|
m_textCtrlName->SetValue( wxEmptyString );
|
|
|
|
m_textCtrlCommand->SetValue( wxEmptyString );
|
|
|
|
|
|
|
|
wxString msg =
|
|
|
|
wxString::Format( _( "The selected BOM generator script %s could not be found." ),
|
|
|
|
plugin->GetFile().GetFullPath() );
|
|
|
|
|
|
|
|
if( !plugin->GetFile().IsAbsolute() )
|
|
|
|
{
|
|
|
|
msg.Append( wxString::Format( _( "\n\nSearched:\n\t%s\n\t%s" ),
|
|
|
|
PATHS::GetUserPluginsPath(),
|
|
|
|
PATHS::GetStockPluginsPath() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Messages->SetValue( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
m_textCtrlName->SetValue( plugin->GetName() );
|
|
|
|
m_textCtrlCommand->SetValue( plugin->GetCommand() );
|
|
|
|
m_Messages->SetValue( plugin->GetInfo() );
|
|
|
|
m_Messages->SetSelection( 0, 0 );
|
2016-03-31 08:28:16 +02:00
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2018-11-19 14:44:26 +01:00
|
|
|
if( plugin->Options().Index( wxT( "show_console" ) ) == wxNOT_FOUND )
|
2016-03-31 08:28:16 +02:00
|
|
|
m_checkBoxShowConsole->SetValue( false );
|
|
|
|
else
|
|
|
|
m_checkBoxShowConsole->SetValue( true );
|
|
|
|
#endif
|
2019-01-14 13:14:13 +01:00
|
|
|
|
|
|
|
// A plugin can be not working, so do not left the OK button enabled if
|
|
|
|
// the plugin is not ready to use
|
|
|
|
m_sdbSizerOK->Enable( plugin->IsOk() );
|
2014-12-03 17:22:06 +01:00
|
|
|
}
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
void DIALOG_BOM::OnRunGenerator( wxCommandEvent& event )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
|
|
|
// Calculate the xml netlist filename
|
2020-05-12 22:00:37 -04:00
|
|
|
wxFileName fn = m_parent->Schematic().GetFileName();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
|
|
|
fn.ClearExt();
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
wxString fullfilename = fn.GetFullPath();
|
|
|
|
m_parent->ClearMsgPanel();
|
|
|
|
|
2024-08-27 05:49:37 +03:00
|
|
|
WX_STRING_REPORTER reporter;
|
2013-06-14 16:59:52 +02:00
|
|
|
m_parent->SetNetListerCommand( m_textCtrlCommand->GetValue() );
|
2016-03-31 08:28:16 +02:00
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
if( m_checkBoxShowConsole->IsChecked() )
|
|
|
|
m_parent->SetExecFlags( wxEXEC_SHOW_CONSOLE );
|
|
|
|
#endif
|
|
|
|
|
2023-08-19 21:05:16 +00:00
|
|
|
bool status = false;
|
|
|
|
|
2021-01-30 16:30:35 +00:00
|
|
|
if( m_parent->ReadyToNetlist( _( "Generating BOM requires a fully annotated schematic." ) ) )
|
2023-08-19 21:05:16 +00:00
|
|
|
status = m_parent->WriteNetListFile( NET_TYPE_BOM, fullfilename, GNL_OPT_BOM|GNL_ALL, &reporter );
|
|
|
|
|
|
|
|
if( !status )
|
|
|
|
DisplayError( this, _( "Failed to create file." ) );
|
2015-06-12 09:02:06 +02:00
|
|
|
|
2024-08-27 05:49:37 +03:00
|
|
|
m_Messages->SetValue( reporter.GetMessages() );
|
2019-06-28 23:58:12 +01:00
|
|
|
|
|
|
|
// Force focus back on the dialog
|
|
|
|
SetFocus();
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
void DIALOG_BOM::OnRemoveGenerator( wxCommandEvent& event )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
int ii = m_lbGenerators->GetSelection();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
m_lbGenerators->Delete( ii );
|
|
|
|
m_generators.erase( m_generators.begin() + ii );
|
2013-06-15 20:02:52 +02:00
|
|
|
|
|
|
|
// Select the next item, if exists
|
2019-05-27 20:43:39 +02:00
|
|
|
if( m_lbGenerators->GetCount() )
|
|
|
|
m_lbGenerators->SetSelection( std::min( ii, (int) m_lbGenerators->GetCount() - 1 ) );
|
2013-06-15 20:02:52 +02:00
|
|
|
|
|
|
|
pluginInit();
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
void DIALOG_BOM::OnAddGenerator( wxCommandEvent& event )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
wxString filename = chooseGenerator();
|
2014-12-03 20:09:56 +01:00
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
if( filename.IsEmpty() )
|
2014-12-03 20:09:56 +01:00
|
|
|
return;
|
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
// Creates a new plugin entry
|
2018-11-12 14:45:07 +01:00
|
|
|
wxFileName fn( filename );
|
2019-05-27 20:43:39 +02:00
|
|
|
wxString name = wxGetTextFromUser( _( "Generator nickname:" ), _( "Add Generator" ),
|
2018-10-25 10:33:19 -04:00
|
|
|
fn.GetName(), this );
|
2013-06-14 16:59:52 +02:00
|
|
|
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Verify if it does not exists
|
2018-11-19 14:44:26 +01:00
|
|
|
if( pluginExists( name ) )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2021-06-29 00:44:07 +01:00
|
|
|
wxMessageBox( wxString::Format( _( "Nickname '%s' already in use." ), name ) );
|
2018-11-19 14:44:26 +01:00
|
|
|
return;
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
try
|
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
auto plugin = addGenerator( fn.GetFullPath(), name );
|
2018-11-12 14:45:07 +01:00
|
|
|
|
2018-11-19 14:44:26 +01:00
|
|
|
if( plugin )
|
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
m_lbGenerators->SetSelection( m_lbGenerators->GetCount() - 1 );
|
2018-11-19 14:44:26 +01:00
|
|
|
m_textCtrlCommand->SetValue( plugin->GetCommand() );
|
|
|
|
pluginInit();
|
|
|
|
}
|
2018-11-12 14:45:07 +01:00
|
|
|
}
|
|
|
|
catch( const std::runtime_error& e )
|
|
|
|
{
|
|
|
|
DisplayError( this, e.what() );
|
|
|
|
}
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-25 10:33:19 -04:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
wxString DIALOG_BOM::chooseGenerator()
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2018-10-25 10:33:19 -04:00
|
|
|
static wxString lastPath;
|
|
|
|
|
|
|
|
if( lastPath.IsEmpty() )
|
2021-02-25 22:31:44 -05:00
|
|
|
lastPath = PATHS::GetUserPluginsPath();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2021-07-28 13:25:40 -04:00
|
|
|
wxString fullFileName = wxFileSelector( _( "Generator File" ), lastPath, wxEmptyString,
|
|
|
|
wxEmptyString, wxFileSelectorDefaultWildcardStr,
|
|
|
|
wxFD_OPEN, this );
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
return fullFileName;
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2014-12-03 17:22:06 +01:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
void DIALOG_BOM::OnEditGenerator( wxCommandEvent& event )
|
2013-06-14 16:59:52 +02:00
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
auto plugin = selectedGenerator();
|
2015-06-29 18:34:31 +02:00
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
if( !plugin )
|
|
|
|
return;
|
2014-12-03 17:22:06 +01:00
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
wxString pluginFile = plugin->GetFile().GetFullPath();
|
2014-12-03 17:22:06 +01:00
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
if( pluginFile.Length() <= 2 ) // if name != ""
|
2014-12-03 17:22:06 +01:00
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
wxMessageBox( _( "Generator file name not found." ) );
|
2014-12-03 17:22:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-19 14:45:27 +01:00
|
|
|
wxString editorname = Pgm().GetTextEditor();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
|
|
|
if( !editorname.IsEmpty() )
|
2021-09-19 14:45:27 +01:00
|
|
|
ExecuteFile( editorname, pluginFile );
|
2013-06-14 16:59:52 +02:00
|
|
|
else
|
2018-06-28 21:21:42 +01:00
|
|
|
wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
void DIALOG_BOM::OnHelp( wxCommandEvent& event )
|
|
|
|
{
|
2020-12-07 12:15:52 +00:00
|
|
|
if( m_helpWindow )
|
|
|
|
{
|
|
|
|
m_helpWindow->ShowModeless();
|
|
|
|
return;
|
|
|
|
}
|
2020-08-24 23:17:14 +01:00
|
|
|
|
2022-11-03 22:49:20 +00:00
|
|
|
m_helpWindow = new HTML_MESSAGE_BOX( nullptr, _( "Bill of Materials Generation Help" ) );
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow->SetDialogSizeInDU( 500, 350 );
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2019-12-29 09:53:39 +01:00
|
|
|
wxString html_txt;
|
|
|
|
ConvertMarkdown2Html( wxGetTranslation( s_bomHelpInfo ), html_txt );
|
2020-08-24 23:17:14 +01:00
|
|
|
|
2021-09-14 19:26:03 +01:00
|
|
|
m_helpWindow->AddHTML_Text( html_txt );
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow->ShowModeless();
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
void DIALOG_BOM::OnCommandLineEdited( wxCommandEvent& event )
|
|
|
|
{
|
2019-05-27 20:43:39 +02:00
|
|
|
auto generator = selectedGenerator();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
if( generator )
|
|
|
|
generator->SetCommand( m_textCtrlCommand->GetValue() );
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 21:21:42 +01:00
|
|
|
|
2013-06-14 16:59:52 +02:00
|
|
|
void DIALOG_BOM::OnNameEdited( wxCommandEvent& event )
|
|
|
|
{
|
2021-02-25 22:31:44 -05:00
|
|
|
if( m_textCtrlName->GetValue().IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
int ii = m_lbGenerators->GetSelection();
|
2013-06-14 16:59:52 +02:00
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
m_generators[ii]->SetName( m_textCtrlName->GetValue() );
|
|
|
|
m_lbGenerators->SetString( ii, m_generators[ii]->GetName() );
|
2016-03-31 08:28:16 +02:00
|
|
|
}
|
|
|
|
|
2018-11-12 14:45:07 +01:00
|
|
|
|
2016-03-31 08:28:16 +02:00
|
|
|
void DIALOG_BOM::OnShowConsoleChanged( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
#ifdef __WINDOWS__
|
2018-11-12 14:45:07 +01:00
|
|
|
static constexpr wxChar OPT_SHOW_CONSOLE[] = wxT( "show_console" );
|
2016-03-31 08:28:16 +02:00
|
|
|
|
2019-05-27 20:43:39 +02:00
|
|
|
auto plugin = selectedGenerator();
|
2018-11-12 14:45:07 +01:00
|
|
|
|
|
|
|
if( !plugin )
|
2016-03-31 08:28:16 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_checkBoxShowConsole->IsChecked() )
|
|
|
|
{
|
2018-11-12 14:45:07 +01:00
|
|
|
if( plugin->Options().Index( OPT_SHOW_CONSOLE ) == wxNOT_FOUND )
|
|
|
|
plugin->Options().Add( OPT_SHOW_CONSOLE );
|
2016-03-31 08:28:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-12 14:45:07 +01:00
|
|
|
plugin->Options().Remove( OPT_SHOW_CONSOLE );
|
2016-03-31 08:28:16 +02:00
|
|
|
}
|
|
|
|
#endif
|
2013-06-14 16:59:52 +02:00
|
|
|
}
|
2018-06-28 21:21:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_BOM::OnIdle( wxIdleEvent& event )
|
|
|
|
{
|
|
|
|
// On some platforms we initialize wxTextCtrls to all-selected, but we don't want that
|
|
|
|
// for the messages text box.
|
|
|
|
if( !m_initialized )
|
|
|
|
{
|
|
|
|
m_Messages->SetSelection( 0, 0 );
|
|
|
|
m_initialized = true;
|
|
|
|
}
|
|
|
|
}
|
2024-09-07 22:24:31 -04:00
|
|
|
|
|
|
|
|
|
|
|
BOM_GENERATOR_HANDLER* DIALOG_BOM::selectedGenerator()
|
|
|
|
{
|
|
|
|
int idx = m_lbGenerators->GetSelection();
|
|
|
|
|
|
|
|
if( idx < 0 || idx >= (int) m_generators.size() )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return m_generators[idx].get();
|
|
|
|
}
|