2013-06-14 14:59:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-05-27 18:43:39 +00:00
|
|
|
* Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2020-03-23 15:17:22 +00:00
|
|
|
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-06-14 14:59:52 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file eeschema/dialogs/dialog_bom.cpp
|
|
|
|
* @brief Dialog box for creating bom and other documents from generic netlist.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <bom_plugins.h>
|
2013-06-14 14:59:52 +00:00
|
|
|
#include <confirm.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <dialog_bom_base.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <eeschema_settings.h>
|
2013-06-14 14:59:52 +00:00
|
|
|
#include <gestfich.h>
|
2020-10-25 13:14:52 +00:00
|
|
|
#include <dialogs/html_messagebox.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <i18n_utility.h> // for _HKI definition used in dialog_bom_help_md.h
|
|
|
|
#include <invoke_sch_dialog.h>
|
|
|
|
#include <kiface_i.h>
|
2013-06-14 14:59:52 +00:00
|
|
|
#include <netlist.h>
|
2020-11-15 13:58:21 +00:00
|
|
|
#include <netlist_exporter_xml.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pgm_base.h>
|
2015-06-12 07:02:06 +00:00
|
|
|
#include <reporter.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2021-02-17 04:26:46 +00:00
|
|
|
#include <paths.h>
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2019-07-03 09:08:55 +00:00
|
|
|
#include <dialogs/dialog_bom_cfg_lexer.h>
|
2019-05-27 18:43:39 +00:00
|
|
|
|
2020-10-18 18:24:20 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/textdlg.h>
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
static constexpr wxChar BOM_TRACE[] = wxT( "BOM_GENERATORS" );
|
2018-11-19 13:44:26 +00:00
|
|
|
|
2019-12-29 08:53:39 +00:00
|
|
|
wxString s_bomHelpInfo =
|
|
|
|
#include <dialog_bom_help_md.h>
|
2013-06-14 14:59:52 +00:00
|
|
|
;
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
using namespace T_BOMCFG_T; // for the BOM_CFG_PARSER parser and its keywords
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
// BOM "plugins" are not actually plugins. They are external tools
|
|
|
|
// (scripts or executables) called by this dialog.
|
|
|
|
typedef std::vector<BOM_GENERATOR_HANDLER::PTR> BOM_GENERATOR_ARRAY;
|
2016-03-31 06:28:16 +00:00
|
|
|
|
2018-10-25 14:33:19 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
/**
|
2018-10-25 14:33:19 +00:00
|
|
|
* Holds data and functions pertinent to parsing a S-expression file
|
2013-06-14 14:59:52 +00:00
|
|
|
*/
|
2018-06-28 20:21:42 +00:00
|
|
|
class BOM_CFG_PARSER : public DIALOG_BOM_CFG_LEXER
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
BOM_GENERATOR_ARRAY* m_generatorsList;
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
public:
|
2019-05-27 18:43:39 +00:00
|
|
|
BOM_CFG_PARSER( BOM_GENERATOR_ARRAY* aGenerators, const char* aData, const wxString& aSource );
|
2017-06-08 21:47:21 +00:00
|
|
|
void Parse();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
private:
|
2019-05-27 18:43:39 +00:00
|
|
|
void parseGenerator();
|
2013-06-14 14:59:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
BOM_CFG_PARSER::BOM_CFG_PARSER( BOM_GENERATOR_ARRAY* aGenerators, const char* aLine,
|
2018-06-28 20:21:42 +00:00
|
|
|
const wxString& aSource ) :
|
2013-06-14 14:59:52 +00:00
|
|
|
DIALOG_BOM_CFG_LEXER( aLine, aSource )
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
m_generatorsList = aGenerators;
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
void BOM_CFG_PARSER::Parse()
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
|
|
|
T token;
|
|
|
|
|
|
|
|
while( ( token = NextTok() ) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_EOF)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( token == T_LEFT )
|
|
|
|
token = NextTok();
|
|
|
|
|
|
|
|
if( token == T_plugins )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_plugin: // Defines a new plugin
|
2019-05-27 18:43:39 +00:00
|
|
|
parseGenerator();
|
2013-06-14 14:59:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-25 14:33:19 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
void BOM_CFG_PARSER::parseGenerator()
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
|
|
|
NeedSYMBOLorNUMBER();
|
2018-11-12 13:45:07 +00:00
|
|
|
wxString name = FromUTF8();
|
2019-05-27 18:43:39 +00:00
|
|
|
auto plugin = std::make_unique<BOM_GENERATOR_HANDLER>( name );
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
T token;
|
2018-10-25 14:33:19 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
while( ( token = NextTok() ) != T_RIGHT )
|
|
|
|
{
|
|
|
|
if( token == T_EOF)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch( token )
|
|
|
|
{
|
|
|
|
case T_LEFT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_cmd:
|
|
|
|
NeedSYMBOLorNUMBER();
|
2018-11-12 13:45:07 +00:00
|
|
|
|
|
|
|
if( plugin )
|
|
|
|
plugin->SetCommand( FromUTF8() );
|
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
NeedRIGHT();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_opts:
|
2016-03-31 06:28:16 +00:00
|
|
|
NeedSYMBOLorNUMBER();
|
2018-11-12 13:45:07 +00:00
|
|
|
|
|
|
|
if( plugin )
|
2018-12-28 20:30:37 +00:00
|
|
|
{
|
|
|
|
wxString option = FromUTF8();
|
|
|
|
|
|
|
|
if( option.StartsWith( "nickname=", &name ) )
|
|
|
|
plugin->SetName( name );
|
|
|
|
else
|
|
|
|
plugin->Options().Add( option );
|
|
|
|
}
|
2018-11-12 13:45:07 +00:00
|
|
|
|
2016-03-31 06:28:16 +00:00
|
|
|
NeedRIGHT();
|
2013-06-14 14:59:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Unexpected( CurText() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
if( plugin )
|
2019-05-27 18:43:39 +00:00
|
|
|
m_generatorsList->push_back( std::move( plugin ) );
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2016-03-31 06:28:16 +00:00
|
|
|
// The main dialog frame to run scripts to build bom
|
2013-06-14 14:59:52 +00:00
|
|
|
class DIALOG_BOM : public DIALOG_BOM_BASE
|
|
|
|
{
|
|
|
|
private:
|
2020-12-07 12:15:52 +00:00
|
|
|
SCH_EDIT_FRAME* m_parent;
|
|
|
|
BOM_GENERATOR_ARRAY m_generators;
|
|
|
|
bool m_initialized;
|
|
|
|
|
|
|
|
HTML_MESSAGE_BOX* m_helpWindow;
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DIALOG_BOM( SCH_EDIT_FRAME* parent );
|
|
|
|
~DIALOG_BOM();
|
|
|
|
|
|
|
|
private:
|
2019-05-27 18:43:39 +00:00
|
|
|
void OnGeneratorSelected( wxCommandEvent& event ) override;
|
|
|
|
void OnRunGenerator( wxCommandEvent& event ) override;
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnHelp( wxCommandEvent& event ) override;
|
2019-05-27 18:43:39 +00:00
|
|
|
void OnAddGenerator( wxCommandEvent& event ) override;
|
|
|
|
void OnRemoveGenerator( wxCommandEvent& event ) override;
|
|
|
|
void OnEditGenerator( wxCommandEvent& event ) override;
|
2016-09-24 18:53:15 +00:00
|
|
|
void OnCommandLineEdited( wxCommandEvent& event ) override;
|
|
|
|
void OnNameEdited( wxCommandEvent& event ) override;
|
|
|
|
void OnShowConsoleChanged( wxCommandEvent& event ) override;
|
2018-06-28 20:21:42 +00:00
|
|
|
void OnIdle( wxIdleEvent& event ) override;
|
2013-06-14 14:59:52 +00:00
|
|
|
|
* KIWAY Milestone A): Make major modules into DLL/DSOs.
! The initial testing of this commit should be done using a Debug build so that
all the wxASSERT()s are enabled. Also, be sure and keep enabled the
USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it
off is senseless anyways. If you want stable code, go back to a prior version,
the one tagged with "stable".
* Relocate all functionality out of the wxApp derivative into more finely
targeted purposes:
a) DLL/DSO specific
b) PROJECT specific
c) EXE or process specific
d) configuration file specific data
e) configuration file manipulations functions.
All of this functionality was blended into an extremely large wxApp derivative
and that was incompatible with the desire to support multiple concurrently
loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects.
An amazing amount of organization come from simply sorting each bit of
functionality into the proper box.
* Switch to wxConfigBase from wxConfig everywhere except instantiation.
* Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD,
PGM_SINGLE_TOP,
* Remove "Return" prefix on many function names.
* Remove obvious comments from CMakeLists.txt files, and from else() and endif()s.
* Fix building boost for use in a DSO on linux.
* Remove some of the assumptions in the CMakeLists.txt files that windows had
to be the host platform when building windows binaries.
* Reduce the number of wxStrings being constructed at program load time via
static construction.
* Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that
these functions are useful even when the wxConfigBase comes from another
source, as is the case in the KICAD_MANAGER_FRAME.
* Move the setting of the KIPRJMOD environment variable into class PROJECT,
so that it can be moved into a project variable soon, and out of FP_LIB_TABLE.
* Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all
its child wxFrames and wxDialogs now have a Kiway() member function which
returns a KIWAY& that that window tree branch is in support of. This is like
wxWindows DNA in that child windows get this member with proper value at time
of construction.
* Anticipate some of the needs for milestones B) and C) and make code
adjustments now in an effort to reduce work in those milestones.
* No testing has been done for python scripting, since milestone C) has that
being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
|
|
|
void pluginInit();
|
2019-05-27 18:43:39 +00:00
|
|
|
void installGeneratorsList();
|
|
|
|
BOM_GENERATOR_HANDLER* addGenerator( const wxString& aPath, const wxString& aName = wxEmptyString );
|
2018-11-19 13:44:26 +00:00
|
|
|
bool pluginExists( const wxString& aName );
|
2014-12-03 19:09:56 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
BOM_GENERATOR_HANDLER* selectedGenerator()
|
2018-11-12 13:45:07 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
int idx = m_lbGenerators->GetSelection();
|
2018-11-12 13:45:07 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
if( idx < 0 || idx >= (int)m_generators.size() )
|
2018-11-12 13:45:07 +00:00
|
|
|
return nullptr;
|
2014-12-03 16:22:06 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
return m_generators[idx].get();
|
2018-11-12 13:45:07 +00:00
|
|
|
}
|
2014-12-03 16:22:06 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
wxString chooseGenerator();
|
2013-06-14 14:59:52 +00:00
|
|
|
};
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2013-06-14 14:59:52 +00: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 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2013-06-14 14:59:52 +00: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 14:59:52 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
m_buttonAddGenerator->SetBitmap( KiBitmap( small_plus_xpm ) );
|
2021-01-02 20:48:43 +00:00
|
|
|
m_buttonDelGenerator->SetBitmap( KiBitmap( small_trash_xpm ) );
|
2018-08-13 17:00:08 +00:00
|
|
|
m_buttonEdit->SetBitmap( KiBitmap( small_edit_xpm ) );
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
installGeneratorsList();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2017-10-09 18:57:41 +00:00
|
|
|
#ifndef __WINDOWS__
|
|
|
|
m_checkBoxShowConsole->Show( false );
|
2016-03-31 06:28:16 +00:00
|
|
|
#endif
|
|
|
|
|
2019-01-14 12:14:13 +00:00
|
|
|
m_sdbSizerOK->SetLabel( _( "Generate" ) );
|
|
|
|
m_sdbSizerCancel->SetLabel( _( "Close" ) );
|
|
|
|
m_sdbSizer->Layout();
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
SetInitialFocus( m_lbGenerators );
|
2019-01-14 12:14:13 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2016-07-18 07:04:13 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_BOM::~DIALOG_BOM()
|
|
|
|
{
|
2020-12-07 12:15:52 +00:00
|
|
|
if( m_helpWindow )
|
|
|
|
m_helpWindow->Destroy();
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
// TODO(JE) maybe unpack this into JSON instead of sexpr
|
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
// Save the plugin descriptions in config.
|
2018-06-28 20:21:42 +00:00
|
|
|
// The config stores only one string, so we save the plugins inside a S-expr:
|
2013-06-14 14:59:52 +00:00
|
|
|
// ( plugins
|
2016-03-31 06:28:16 +00:00
|
|
|
// ( plugin "plugin name 1" (cmd "command line 1") )
|
|
|
|
// ( plugin "plugin name 2" (cmd "command line 2") (opts "option1") (opts "option2") )
|
2013-06-14 14:59:52 +00:00
|
|
|
// ....
|
|
|
|
// )
|
|
|
|
|
|
|
|
STRING_FORMATTER writer;
|
2013-06-17 19:01:47 +00:00
|
|
|
writer.Print( 0, "(plugins" );
|
2014-12-03 16:22:06 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
for( auto& plugin : m_generators )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2016-03-31 06:28:16 +00:00
|
|
|
writer.Print( 1, "(plugin %s (cmd %s)",
|
2018-11-12 13:45:07 +00:00
|
|
|
writer.Quotew( plugin->GetFile().GetFullPath() ).c_str(),
|
|
|
|
writer.Quotew( plugin->GetCommand() ).c_str() );
|
2016-03-31 06:28:16 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
for( unsigned jj = 0; jj < plugin->Options().GetCount(); jj++ )
|
2016-03-31 06:28:16 +00:00
|
|
|
{
|
|
|
|
writer.Print( 1, "(opts %s)",
|
2018-11-12 13:45:07 +00:00
|
|
|
writer.Quotew( plugin->Options().Item( jj ) ).c_str() );
|
2016-03-31 06:28:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:30:37 +00:00
|
|
|
if( !plugin->GetName().IsEmpty() )
|
|
|
|
{
|
|
|
|
wxString option = wxString::Format( "nickname=%s", plugin->GetName() );
|
|
|
|
|
|
|
|
writer.Print( 1, "(opts %s)",
|
|
|
|
writer.Quotew( option ).c_str() );
|
|
|
|
}
|
|
|
|
|
2016-03-31 06:28:16 +00:00
|
|
|
writer.Print( 0, ")" );
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
2014-12-03 16:22:06 +00:00
|
|
|
|
2013-06-17 19:01:47 +00:00
|
|
|
writer.Print( 0, ")" );
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2013-06-17 19:01:47 +00:00
|
|
|
wxString list( FROM_UTF8( writer.GetString().c_str() ) );
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2020-03-23 15:17:22 +00:00
|
|
|
auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
cfg->m_BomPanel.plugins = list.ToStdString();
|
|
|
|
cfg->m_BomPanel.selected_plugin = m_lbGenerators->GetStringSelection().ToStdString();
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 14:33:19 +00:00
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
// Read the initialized plugins in config and fill the list of names
|
2019-05-27 18:43:39 +00:00
|
|
|
void DIALOG_BOM::installGeneratorsList()
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2020-03-23 15:17:22 +00:00
|
|
|
auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
wxString list = cfg->m_BomPanel.plugins;
|
|
|
|
wxString active_plugin_name = cfg->m_BomPanel.selected_plugin;
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
if( !list.IsEmpty() )
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
BOM_CFG_PARSER cfg_parser( &m_generators, TO_UTF8( list ), wxT( "plugins" ) );
|
2018-10-25 14:33:19 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cfg_parser.Parse();
|
|
|
|
}
|
2016-10-10 15:04:48 +00:00
|
|
|
catch( const IO_ERROR& )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2016-09-14 22:38:52 +00:00
|
|
|
// wxLogMessage( ioe.What() );
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
2018-11-12 13:45:07 +00:00
|
|
|
catch( std::runtime_error& e )
|
|
|
|
{
|
|
|
|
DisplayError( nullptr, e.what() );
|
|
|
|
}
|
2018-11-19 13:44:26 +00:00
|
|
|
|
|
|
|
// Populate list box
|
2019-05-27 18:43:39 +00:00
|
|
|
for( unsigned ii = 0; ii < m_generators.size(); ii++ )
|
2018-11-19 13:44:26 +00:00
|
|
|
{
|
2021-01-11 21:50:01 +00:00
|
|
|
if( !m_generators[ii]->GetFile().Exists( wxFILE_EXISTS_REGULAR ) )
|
|
|
|
continue;
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
m_lbGenerators->Append( m_generators[ii]->GetName() );
|
2018-11-19 13:44:26 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
if( active_plugin_name == m_generators[ii]->GetName() )
|
|
|
|
m_lbGenerators->SetSelection( ii );
|
2018-11-19 13:44:26 +00:00
|
|
|
}
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
if( m_generators.empty() ) // No plugins found?
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2018-11-19 13:44:26 +00:00
|
|
|
// Load plugins from the default locations
|
|
|
|
std::vector<wxString> pluginPaths = {
|
|
|
|
#if defined(__WXGTK__)
|
|
|
|
"/usr/share/kicad/plugins",
|
|
|
|
"/usr/local/share/kicad/plugins",
|
|
|
|
#elif defined(__WXMSW__)
|
|
|
|
wxString::Format( "%s\\scripting\\plugins", Pgm().GetExecutablePath() ),
|
|
|
|
#elif defined(__WXMAC__)
|
2021-02-17 04:26:46 +00:00
|
|
|
wxString::Format( "%s/plugins", PATHS::GetOSXKicadDataDir() ),
|
2018-11-19 13:44:26 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
wxFileName pluginPath;
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2018-11-19 13:44:26 +00:00
|
|
|
for( const auto& path : pluginPaths )
|
|
|
|
{
|
|
|
|
wxDir dir( path );
|
|
|
|
|
|
|
|
if( !dir.IsOpened() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pluginPath.AssignDir( dir.GetName() );
|
|
|
|
wxString fileName;
|
2019-01-06 04:23:13 +00:00
|
|
|
bool cont = dir.GetFirst( &fileName, wxFileSelectorDefaultWildcardStr, wxDIR_FILES );
|
2018-11-19 13:44:26 +00:00
|
|
|
|
|
|
|
while( cont )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-08-18 14:17:16 +00:00
|
|
|
wxLogTrace( BOM_TRACE,"Checking if %s is a BOM generator", fileName );
|
2018-11-19 13:44:26 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
if( BOM_GENERATOR_HANDLER::IsValidGenerator( fileName ) )
|
2018-11-19 13:44:26 +00:00
|
|
|
{
|
|
|
|
pluginPath.SetFullName( fileName );
|
2019-05-27 18:43:39 +00:00
|
|
|
addGenerator( pluginPath.GetFullPath() );
|
2018-11-19 13:44:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... ) { /* well, no big deal */ }
|
|
|
|
|
|
|
|
cont = dir.GetNext( &fileName );
|
|
|
|
}
|
|
|
|
}
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-11-19 13:44:26 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
pluginInit();
|
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
BOM_GENERATOR_HANDLER* DIALOG_BOM::addGenerator( const wxString& aPath, const wxString& aName )
|
2018-11-19 13:44:26 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
BOM_GENERATOR_HANDLER* ret = nullptr;
|
|
|
|
auto plugin = std::make_unique<BOM_GENERATOR_HANDLER>( aPath );
|
2018-11-19 13:44:26 +00:00
|
|
|
|
|
|
|
if( !plugin )
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
if( !aName.IsEmpty() )
|
|
|
|
{
|
|
|
|
plugin->SetName( aName );
|
2019-05-27 18:43:39 +00:00
|
|
|
m_lbGenerators->Append( aName );
|
2018-11-19 13:44:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
m_lbGenerators->Append( plugin->GetName() );
|
2018-11-19 13:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = plugin.get();
|
2019-05-27 18:43:39 +00:00
|
|
|
m_generators.push_back( std::move( plugin ) );
|
2018-11-19 13:44:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_BOM::pluginExists( const wxString& aName )
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
for( unsigned ii = 0; ii < m_generators.size(); ii++ )
|
2018-11-19 13:44:26 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
if( aName == m_generators[ii]->GetName() )
|
2018-11-19 13:44:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
void DIALOG_BOM::OnGeneratorSelected( wxCommandEvent& event )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
|
|
|
pluginInit();
|
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
void DIALOG_BOM::pluginInit()
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
auto plugin = selectedGenerator();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
if( !plugin )
|
2013-06-15 18:02:52 +00:00
|
|
|
{
|
|
|
|
m_textCtrlName->SetValue( wxEmptyString );
|
|
|
|
m_textCtrlCommand->SetValue( wxEmptyString );
|
2018-11-12 13:45:07 +00:00
|
|
|
m_Messages->SetValue( wxEmptyString );
|
2013-06-14 14:59:52 +00:00
|
|
|
return;
|
2013-06-15 18:02:52 +00:00
|
|
|
}
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
m_textCtrlName->SetValue( plugin->GetName() );
|
|
|
|
m_textCtrlCommand->SetValue( plugin->GetCommand() );
|
|
|
|
m_Messages->SetValue( plugin->GetInfo() );
|
|
|
|
m_Messages->SetSelection( 0, 0 );
|
2016-03-31 06:28:16 +00:00
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
2018-11-19 13:44:26 +00:00
|
|
|
if( plugin->Options().Index( wxT( "show_console" ) ) == wxNOT_FOUND )
|
2016-03-31 06:28:16 +00:00
|
|
|
m_checkBoxShowConsole->SetValue( false );
|
|
|
|
else
|
|
|
|
m_checkBoxShowConsole->SetValue( true );
|
|
|
|
#endif
|
2019-01-14 12:14:13 +00: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 16:22:06 +00:00
|
|
|
}
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
void DIALOG_BOM::OnRunGenerator( wxCommandEvent& event )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
|
|
|
// Calculate the xml netlist filename
|
2020-05-13 02:00:37 +00:00
|
|
|
wxFileName fn = m_parent->Schematic().GetFileName();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2015-05-26 15:13:33 +00:00
|
|
|
fn.SetPath( wxPathOnly( Prj().GetProjectFullName() ) );
|
2013-06-14 14:59:52 +00:00
|
|
|
fn.ClearExt();
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
wxString fullfilename = fn.GetFullPath();
|
|
|
|
m_parent->ClearMsgPanel();
|
|
|
|
|
2015-06-12 07:02:06 +00:00
|
|
|
wxString reportmsg;
|
|
|
|
WX_STRING_REPORTER reporter( &reportmsg );
|
2013-06-14 14:59:52 +00:00
|
|
|
m_parent->SetNetListerCommand( m_textCtrlCommand->GetValue() );
|
2016-03-31 06:28:16 +00:00
|
|
|
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
if( m_checkBoxShowConsole->IsChecked() )
|
|
|
|
m_parent->SetExecFlags( wxEXEC_SHOW_CONSOLE );
|
|
|
|
#endif
|
|
|
|
|
2021-01-30 16:30:35 +00:00
|
|
|
if( m_parent->ReadyToNetlist( _( "Generating BOM requires a fully annotated schematic." ) ) )
|
2020-06-09 16:50:05 +00:00
|
|
|
m_parent->WriteNetListFile( -1, fullfilename, GNL_OPT_BOM, &reporter );
|
2015-06-12 07:02:06 +00:00
|
|
|
|
|
|
|
m_Messages->SetValue( reportmsg );
|
2019-06-28 22:58:12 +00:00
|
|
|
|
|
|
|
// Force focus back on the dialog
|
|
|
|
SetFocus();
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
void DIALOG_BOM::OnRemoveGenerator( wxCommandEvent& event )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
int ii = m_lbGenerators->GetSelection();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
m_lbGenerators->Delete( ii );
|
|
|
|
m_generators.erase( m_generators.begin() + ii );
|
2013-06-15 18:02:52 +00:00
|
|
|
|
|
|
|
// Select the next item, if exists
|
2019-05-27 18:43:39 +00:00
|
|
|
if( m_lbGenerators->GetCount() )
|
|
|
|
m_lbGenerators->SetSelection( std::min( ii, (int) m_lbGenerators->GetCount() - 1 ) );
|
2013-06-15 18:02:52 +00:00
|
|
|
|
|
|
|
pluginInit();
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
void DIALOG_BOM::OnAddGenerator( wxCommandEvent& event )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
wxString filename = chooseGenerator();
|
2014-12-03 19:09:56 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
if( filename.IsEmpty() )
|
2014-12-03 19:09:56 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
// Creates a new plugin entry
|
2018-11-12 13:45:07 +00:00
|
|
|
wxFileName fn( filename );
|
2019-05-27 18:43:39 +00:00
|
|
|
wxString name = wxGetTextFromUser( _( "Generator nickname:" ), _( "Add Generator" ),
|
2018-10-25 14:33:19 +00:00
|
|
|
fn.GetName(), this );
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Verify if it does not exists
|
2018-11-19 13:44:26 +00:00
|
|
|
if( pluginExists( name ) )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2018-11-19 13:44:26 +00:00
|
|
|
wxMessageBox( wxString::Format( _( "Nickname \"%s\" already in use." ), name ) );
|
|
|
|
return;
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
try
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
auto plugin = addGenerator( fn.GetFullPath(), name );
|
2018-11-12 13:45:07 +00:00
|
|
|
|
2018-11-19 13:44:26 +00:00
|
|
|
if( plugin )
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
m_lbGenerators->SetSelection( m_lbGenerators->GetCount() - 1 );
|
2018-11-19 13:44:26 +00:00
|
|
|
m_textCtrlCommand->SetValue( plugin->GetCommand() );
|
|
|
|
pluginInit();
|
|
|
|
}
|
2018-11-12 13:45:07 +00:00
|
|
|
}
|
|
|
|
catch( const std::runtime_error& e )
|
|
|
|
{
|
|
|
|
DisplayError( this, e.what() );
|
|
|
|
}
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 14:33:19 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
wxString DIALOG_BOM::chooseGenerator()
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2018-10-25 14:33:19 +00:00
|
|
|
static wxString lastPath;
|
|
|
|
|
|
|
|
if( lastPath.IsEmpty() )
|
|
|
|
{
|
2014-10-17 17:45:33 +00:00
|
|
|
#ifndef __WXMAC__
|
2018-10-25 14:33:19 +00:00
|
|
|
lastPath = Pgm().GetExecutablePath();
|
2014-10-17 17:45:33 +00:00
|
|
|
#else
|
2021-02-17 04:26:46 +00:00
|
|
|
lastPath = PATHS::GetOSXKicadDataDir() + "/plugins";
|
2014-10-17 17:45:33 +00:00
|
|
|
#endif
|
2018-10-25 14:33:19 +00:00
|
|
|
}
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
wxString fullFileName = EDA_FILE_SELECTOR( _( "Generator files:" ), lastPath, wxEmptyString,
|
2019-01-06 04:23:13 +00:00
|
|
|
wxEmptyString, wxFileSelectorDefaultWildcardStr,
|
|
|
|
this, wxFD_OPEN, true );
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
return fullFileName;
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 16:22:06 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
void DIALOG_BOM::OnEditGenerator( wxCommandEvent& event )
|
2013-06-14 14:59:52 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
auto plugin = selectedGenerator();
|
2015-06-29 16:34:31 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
if( !plugin )
|
|
|
|
return;
|
2014-12-03 16:22:06 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
wxString pluginFile = plugin->GetFile().GetFullPath();
|
2014-12-03 16:22:06 +00:00
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
if( pluginFile.Length() <= 2 ) // if name != ""
|
2014-12-03 16:22:06 +00:00
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
wxMessageBox( _( "Generator file name not found." ) );
|
2014-12-03 16:22:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
AddDelimiterString( pluginFile );
|
2018-06-28 20:21:42 +00:00
|
|
|
wxString editorname = Pgm().GetEditorName();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
if( !editorname.IsEmpty() )
|
2018-11-12 13:45:07 +00:00
|
|
|
ExecuteFile( this, editorname, pluginFile );
|
2013-06-14 14:59:52 +00:00
|
|
|
else
|
2018-06-28 20:21:42 +00:00
|
|
|
wxMessageBox( _( "No text editor selected in KiCad. Please choose one." ) );
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2013-06-14 14:59:52 +00: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 22:17:14 +00:00
|
|
|
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow = new HTML_MESSAGE_BOX( nullptr, _( "Bill of Material Generation Help" ) );
|
|
|
|
m_helpWindow->SetDialogSizeInDU( 500, 350 );
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2019-12-29 08:53:39 +00:00
|
|
|
wxString html_txt;
|
|
|
|
ConvertMarkdown2Html( wxGetTranslation( s_bomHelpInfo ), html_txt );
|
2020-08-24 22:17:14 +00:00
|
|
|
|
2020-12-07 12:15:52 +00:00
|
|
|
m_helpWindow->m_htmlWindow->AppendToPage( html_txt );
|
|
|
|
m_helpWindow->ShowModeless();
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
void DIALOG_BOM::OnCommandLineEdited( wxCommandEvent& event )
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
auto generator = selectedGenerator();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
if( generator )
|
|
|
|
generator->SetCommand( m_textCtrlCommand->GetValue() );
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 20:21:42 +00:00
|
|
|
|
2013-06-14 14:59:52 +00:00
|
|
|
void DIALOG_BOM::OnNameEdited( wxCommandEvent& event )
|
|
|
|
{
|
2019-05-27 18:43:39 +00:00
|
|
|
int ii = m_lbGenerators->GetSelection();
|
2013-06-14 14:59:52 +00:00
|
|
|
|
|
|
|
if( ii < 0 )
|
|
|
|
return;
|
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
m_generators[ii]->SetName( m_textCtrlName->GetValue() );
|
|
|
|
m_lbGenerators->SetString( ii, m_generators[ii]->GetName() );
|
2016-03-31 06:28:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-12 13:45:07 +00:00
|
|
|
|
2016-03-31 06:28:16 +00:00
|
|
|
void DIALOG_BOM::OnShowConsoleChanged( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
#ifdef __WINDOWS__
|
2018-11-12 13:45:07 +00:00
|
|
|
static constexpr wxChar OPT_SHOW_CONSOLE[] = wxT( "show_console" );
|
2016-03-31 06:28:16 +00:00
|
|
|
|
2019-05-27 18:43:39 +00:00
|
|
|
auto plugin = selectedGenerator();
|
2018-11-12 13:45:07 +00:00
|
|
|
|
|
|
|
if( !plugin )
|
2016-03-31 06:28:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_checkBoxShowConsole->IsChecked() )
|
|
|
|
{
|
2018-11-12 13:45:07 +00:00
|
|
|
if( plugin->Options().Index( OPT_SHOW_CONSOLE ) == wxNOT_FOUND )
|
|
|
|
plugin->Options().Add( OPT_SHOW_CONSOLE );
|
2016-03-31 06:28:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-12 13:45:07 +00:00
|
|
|
plugin->Options().Remove( OPT_SHOW_CONSOLE );
|
2016-03-31 06:28:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-06-14 14:59:52 +00:00
|
|
|
}
|
2018-06-28 20:21:42 +00: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;
|
|
|
|
}
|
|
|
|
}
|