2010-07-31 23:57:36 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
2010-07-31 23:57:36 +00:00
|
|
|
*
|
2018-01-30 09:45:35 +00:00
|
|
|
* Copyright (C) 1992-2018 jp.charras at wanadoo.fr
|
2013-09-27 12:30:35 +00:00
|
|
|
* Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2021-01-30 16:30:35 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see change_log.txt for contributors.
|
2010-07-31 23:57:36 +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
|
|
|
|
*/
|
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
#include <advanced_config.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <common.h> // for ProcessExecute
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gestfich.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2015-06-12 07:02:06 +00:00
|
|
|
#include <reporter.h>
|
2018-01-30 09:45:35 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <kiway.h>
|
2020-07-03 21:08:17 +00:00
|
|
|
#include <erc.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <netlist.h>
|
2020-11-15 13:58:21 +00:00
|
|
|
#include <netlist_exporter_base.h>
|
2015-03-21 10:46:54 +00:00
|
|
|
#include <netlist_exporter_orcadpcb2.h>
|
|
|
|
#include <netlist_exporter_cadstar.h>
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <netlist_exporter_spice.h>
|
2022-09-09 13:34:56 +00:00
|
|
|
#include <netlist_exporter_spice_model.h>
|
2015-03-21 10:46:54 +00:00
|
|
|
#include <netlist_exporter_kicad.h>
|
2023-06-28 22:47:30 +00:00
|
|
|
#include <netlist_exporter_allegro.h>
|
2024-03-09 14:57:24 +00:00
|
|
|
#include <netlist_exporter_pads.h>
|
2020-11-15 13:58:21 +00:00
|
|
|
#include <netlist_exporter_xml.h>
|
2010-08-11 05:58:34 +00:00
|
|
|
|
2018-01-30 09:45:35 +00:00
|
|
|
|
2020-05-23 17:14:05 +00:00
|
|
|
bool SCH_EDIT_FRAME::WriteNetListFile( int aFormat, const wxString& aFullFileName,
|
2015-06-12 07:02:06 +00:00
|
|
|
unsigned aNetlistOptions, REPORTER* aReporter )
|
2009-12-02 21:44:03 +00:00
|
|
|
{
|
2020-05-23 17:14:05 +00:00
|
|
|
// Ensure all power symbols have a valid reference
|
|
|
|
Schematic().GetSheets().AnnotatePowerSymbols();
|
|
|
|
|
2021-01-30 16:30:35 +00:00
|
|
|
if( !ReadyToNetlist( _( "Exporting netlist requires a fully annotated schematic." ) ) )
|
2019-04-13 15:54:15 +00:00
|
|
|
return false;
|
|
|
|
|
2023-04-21 20:25:01 +00:00
|
|
|
// If we are using the new connectivity, make sure that we do a full-rebuild
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
|
2023-06-09 16:24:49 +00:00
|
|
|
RecalculateConnections( nullptr, GLOBAL_CLEANUP );
|
2023-04-21 20:25:01 +00:00
|
|
|
|
2015-03-21 10:46:54 +00:00
|
|
|
bool res = true;
|
|
|
|
bool executeCommandLine = false;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2015-05-26 15:13:33 +00:00
|
|
|
wxString fileName = aFullFileName;
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
NETLIST_EXPORTER_BASE *helper = nullptr;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCHEMATIC* sch = &Schematic();
|
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
switch( aFormat )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
case NET_TYPE_PCBNEW:
|
2020-05-21 03:40:31 +00:00
|
|
|
helper = new NETLIST_EXPORTER_KICAD( sch );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_ORCADPCB2:
|
2020-05-21 03:40:31 +00:00
|
|
|
helper = new NETLIST_EXPORTER_ORCADPCB2( sch );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_CADSTAR:
|
2020-05-21 03:40:31 +00:00
|
|
|
helper = new NETLIST_EXPORTER_CADSTAR( sch );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_SPICE:
|
2022-04-12 14:37:06 +00:00
|
|
|
helper = new NETLIST_EXPORTER_SPICE( sch );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
2022-09-09 13:34:56 +00:00
|
|
|
case NET_TYPE_SPICE_MODEL:
|
|
|
|
helper = new NETLIST_EXPORTER_SPICE_MODEL( sch );
|
|
|
|
break;
|
|
|
|
|
2023-06-28 22:47:30 +00:00
|
|
|
case NET_TYPE_ALLEGRO:
|
|
|
|
helper = new NETLIST_EXPORTER_ALLEGRO( sch );
|
2024-03-09 14:57:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_PADS:
|
|
|
|
helper = new NETLIST_EXPORTER_PADS( sch );
|
|
|
|
break;
|
2023-06-28 22:47:30 +00:00
|
|
|
|
2022-01-05 19:05:18 +00:00
|
|
|
case NET_TYPE_BOM:
|
|
|
|
// When generating the BOM, we have a bare filename so don't strip
|
|
|
|
// the extension or you might string a '.' from the middle of the filename
|
|
|
|
fileName += wxT( "." GENERIC_INTERMEDIATE_NETLIST_EXT );
|
|
|
|
|
|
|
|
helper = new NETLIST_EXPORTER_XML( sch );
|
|
|
|
executeCommandLine = true;
|
|
|
|
break;
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
default:
|
2021-04-22 11:38:10 +00:00
|
|
|
{
|
|
|
|
wxFileName tmpFile = fileName;
|
|
|
|
tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT );
|
|
|
|
fileName = tmpFile.GetFullPath();
|
2015-03-21 10:46:54 +00:00
|
|
|
|
2021-04-22 11:38:10 +00:00
|
|
|
helper = new NETLIST_EXPORTER_XML( sch );
|
|
|
|
executeCommandLine = true;
|
|
|
|
}
|
2015-06-07 18:18:45 +00:00
|
|
|
break;
|
2015-03-21 10:46:54 +00:00
|
|
|
}
|
2010-08-11 14:47:16 +00:00
|
|
|
|
2022-11-18 15:27:53 +00:00
|
|
|
NULL_REPORTER devnull;
|
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
res = helper->WriteNetlist( fileName, aNetlistOptions, *aReporter );
|
|
|
|
else
|
|
|
|
res = helper->WriteNetlist( fileName, aNetlistOptions, devnull );
|
|
|
|
|
2015-06-12 07:02:06 +00:00
|
|
|
delete helper;
|
2010-07-30 21:41:55 +00:00
|
|
|
|
2015-06-12 07:02:06 +00:00
|
|
|
// If user provided a plugin command line, execute it.
|
|
|
|
if( executeCommandLine && res && !m_netListerCommand.IsEmpty() )
|
2015-03-21 10:46:54 +00:00
|
|
|
{
|
2015-05-26 15:13:33 +00:00
|
|
|
wxString prj_dir = Prj().GetProjectPath();
|
|
|
|
|
2020-11-15 13:58:21 +00:00
|
|
|
// strip trailing '/'
|
|
|
|
prj_dir = prj_dir.SubString( 0, prj_dir.Len() - 2 );
|
|
|
|
|
2021-04-22 11:38:10 +00:00
|
|
|
// build full command line from user's format string.
|
|
|
|
// For instance, "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I"
|
2015-02-21 00:41:10 +00:00
|
|
|
// becomes, after the user selects /tmp/s1.net as the output file from the file dialog:
|
|
|
|
// "xsltproc -o /tmp/s1.net /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl /tmp/s1.xml"
|
2020-11-15 13:58:21 +00:00
|
|
|
wxString commandLine = NETLIST_EXPORTER_BASE::MakeCommandLine( m_netListerCommand,
|
|
|
|
fileName, aFullFileName,
|
|
|
|
prj_dir );
|
2010-08-11 14:47:16 +00:00
|
|
|
|
2015-06-12 07:02:06 +00:00
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
wxArrayString output, errors;
|
2021-07-05 12:40:38 +00:00
|
|
|
int diag = wxExecute( commandLine, output, errors, m_exec_flags );
|
|
|
|
wxString msg;
|
2015-06-12 07:02:06 +00:00
|
|
|
|
2021-07-05 12:40:38 +00:00
|
|
|
aReporter->ReportHead( commandLine, RPT_SEVERITY_ACTION );
|
2015-06-12 07:02:06 +00:00
|
|
|
|
|
|
|
if( diag != 0 )
|
2021-04-22 11:38:10 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "Command error. Return code %d." ), diag );
|
2023-08-19 21:05:16 +00:00
|
|
|
res = false;
|
2021-04-22 11:38:10 +00:00
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2015-06-12 07:02:06 +00:00
|
|
|
else
|
2021-04-22 11:38:10 +00:00
|
|
|
{
|
|
|
|
aReporter->ReportTail( _( "Success." ), RPT_SEVERITY_INFO );
|
|
|
|
}
|
2015-06-12 07:02:06 +00:00
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
if( output.GetCount() )
|
2015-06-12 07:02:06 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < output.GetCount(); ii++ )
|
2021-07-05 12:40:38 +00:00
|
|
|
aReporter->Report( output[ii], RPT_SEVERITY_INFO );
|
2015-06-12 07:02:06 +00:00
|
|
|
}
|
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
if( errors.GetCount() )
|
2015-06-12 07:02:06 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < errors.GetCount(); ii++ )
|
2021-07-05 12:40:38 +00:00
|
|
|
aReporter->Report( errors[ii], RPT_SEVERITY_ERROR );
|
2015-06-12 07:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2021-04-22 11:38:10 +00:00
|
|
|
{
|
2023-08-19 21:05:16 +00:00
|
|
|
int diag = wxExecute( commandLine, m_exec_flags );
|
|
|
|
if( diag != 0 )
|
|
|
|
res = false;
|
2021-04-22 11:38:10 +00:00
|
|
|
}
|
2016-03-31 06:28:16 +00:00
|
|
|
|
|
|
|
DefaultExecFlags(); // Reset flags to default after executing
|
2007-09-21 13:23:51 +00:00
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
|
2015-03-21 10:46:54 +00:00
|
|
|
return res;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2018-01-30 09:45:35 +00:00
|
|
|
|
|
|
|
|
2021-01-30 16:30:35 +00:00
|
|
|
bool SCH_EDIT_FRAME::ReadyToNetlist( const wxString& aAnnotateMessage )
|
2018-01-30 09:45:35 +00:00
|
|
|
{
|
|
|
|
// Ensure all power symbols have a valid reference
|
2020-05-13 02:00:37 +00:00
|
|
|
Schematic().GetSheets().AnnotatePowerSymbols();
|
2018-01-30 09:45:35 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
// Symbols must be annotated
|
2021-01-24 22:25:32 +00:00
|
|
|
if( CheckAnnotate( []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* ) {} ) )
|
2018-01-30 09:45:35 +00:00
|
|
|
{
|
2021-01-30 16:30:35 +00:00
|
|
|
// Schematic must be annotated: call Annotate dialog and tell the user why.
|
|
|
|
ModalAnnotate( aAnnotateMessage );
|
2020-05-23 17:14:05 +00:00
|
|
|
|
2021-01-30 16:30:35 +00:00
|
|
|
if( CheckAnnotate( []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* ) {} ) )
|
|
|
|
return false;
|
2018-01-30 09:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test duplicate sheet names:
|
2020-07-03 21:08:17 +00:00
|
|
|
ERC_TESTER erc( &Schematic() );
|
|
|
|
|
|
|
|
if( erc.TestDuplicateSheetNames( false ) > 0 )
|
2018-01-30 09:45:35 +00:00
|
|
|
{
|
2021-01-30 16:30:35 +00:00
|
|
|
if( !IsOK( this, _( "Error: duplicate sheet names. Continue?" ) ) )
|
2018-01-30 09:45:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-17 19:15:08 +00:00
|
|
|
void SCH_EDIT_FRAME::sendNetlistToCvpcb()
|
2018-01-30 09:45:35 +00:00
|
|
|
{
|
2021-01-18 17:04:52 +00:00
|
|
|
std::string packet;
|
2018-01-30 09:45:35 +00:00
|
|
|
|
2021-01-18 17:04:52 +00:00
|
|
|
{
|
|
|
|
NETLIST_EXPORTER_KICAD exporter( &Schematic() );
|
|
|
|
STRING_FORMATTER formatter;
|
|
|
|
|
|
|
|
// @todo : trim GNL_ALL down to minimum for CVPCB
|
2021-12-10 23:00:21 +00:00
|
|
|
exporter.Format( &formatter, GNL_ALL | GNL_OPT_KICAD );
|
2021-01-18 17:04:52 +00:00
|
|
|
|
|
|
|
packet = formatter.GetString(); // an abbreviated "kicad" (s-expr) netlist
|
|
|
|
|
|
|
|
// NETLIST_EXPORTER_KICAD must go out of scope so it can clean up things like the
|
|
|
|
// current sheet setting before sending expressmail
|
|
|
|
}
|
2018-01-30 09:45:35 +00:00
|
|
|
|
2019-03-27 22:37:26 +00:00
|
|
|
Kiway().ExpressMail( FRAME_CVPCB, MAIL_EESCHEMA_NETLIST, packet, this );
|
2018-01-30 09:45:35 +00:00
|
|
|
}
|
|
|
|
|