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>
|
2020-05-04 23:34:02 +00:00
|
|
|
* Copyright (C) 1992-2020 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
2012-01-26 09:37:36 +00:00
|
|
|
* @file eeschema/netform.cpp
|
2011-10-07 14:41:30 +00:00
|
|
|
* @brief Net list generation code.
|
|
|
|
*/
|
2010-07-31 23:57:36 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
* 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
|
|
|
#include <pgm_base.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.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>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
|
|
|
#include <netlist.h>
|
2015-03-21 10:46:54 +00:00
|
|
|
#include <netlist_exporter.h>
|
|
|
|
#include <netlist_exporter_orcadpcb2.h>
|
|
|
|
#include <netlist_exporter_cadstar.h>
|
|
|
|
#include <netlist_exporter_pspice.h>
|
|
|
|
#include <netlist_exporter_kicad.h>
|
|
|
|
#include <netlist_exporter_generic.h>
|
2010-08-11 05:58:34 +00:00
|
|
|
|
2018-01-30 09:45:35 +00:00
|
|
|
#include <invoke_sch_dialog.h>
|
|
|
|
|
2015-06-07 18:18:45 +00:00
|
|
|
bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST* aConnectedItemsList,
|
2013-09-27 12:30:35 +00:00
|
|
|
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
|
|
|
{
|
2019-04-13 15:54:15 +00:00
|
|
|
if( aConnectedItemsList == nullptr ) // Schematic netlist not available.
|
|
|
|
return false;
|
|
|
|
|
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;
|
|
|
|
|
2015-03-21 10:46:54 +00:00
|
|
|
NETLIST_EXPORTER *helper;
|
2007-09-21 13:23:51 +00:00
|
|
|
|
2010-07-14 13:24:36 +00:00
|
|
|
switch( aFormat )
|
2007-09-21 13:23:51 +00:00
|
|
|
{
|
|
|
|
case NET_TYPE_PCBNEW:
|
2020-05-04 23:34:02 +00:00
|
|
|
helper = new NETLIST_EXPORTER_KICAD( this, aConnectedItemsList, g_ConnectionGraph );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_ORCADPCB2:
|
2017-10-06 18:07:43 +00:00
|
|
|
helper = new NETLIST_EXPORTER_ORCADPCB2( aConnectedItemsList );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_CADSTAR:
|
2017-10-06 18:07:43 +00:00
|
|
|
helper = new NETLIST_EXPORTER_CADSTAR( aConnectedItemsList );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_TYPE_SPICE:
|
2017-10-06 18:07:43 +00:00
|
|
|
helper = new NETLIST_EXPORTER_PSPICE( aConnectedItemsList );
|
2007-09-21 13:23:51 +00:00
|
|
|
break;
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
default:
|
2015-03-21 10:46:54 +00:00
|
|
|
{
|
2015-06-07 18:18:45 +00:00
|
|
|
wxFileName tmpFile = fileName;
|
|
|
|
tmpFile.SetExt( GENERIC_INTERMEDIATE_NETLIST_EXT );
|
|
|
|
fileName = tmpFile.GetFullPath();
|
2015-03-21 10:46:54 +00:00
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
helper = new NETLIST_EXPORTER_GENERIC( this, aConnectedItemsList,
|
|
|
|
g_ConnectionGraph );
|
2015-06-07 18:18:45 +00:00
|
|
|
executeCommandLine = true;
|
2015-03-21 10:46:54 +00:00
|
|
|
}
|
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
|
|
|
|
2015-06-07 18:18:45 +00:00
|
|
|
res = helper->WriteNetlist( fileName, aNetlistOptions );
|
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();
|
|
|
|
|
2015-02-21 00:41:10 +00:00
|
|
|
// build full command line from user's format string, e.g.:
|
|
|
|
// "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I"
|
|
|
|
// 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"
|
2015-03-21 10:46:54 +00:00
|
|
|
wxString commandLine = NETLIST_EXPORTER::MakeCommandLine( m_netListerCommand,
|
2015-05-26 15:13:33 +00:00
|
|
|
fileName, aFullFileName,
|
|
|
|
prj_dir.SubString( 0, prj_dir.Len() - 2 ) // strip trailing '/'
|
|
|
|
);
|
2010-08-11 14:47:16 +00:00
|
|
|
|
2015-06-12 07:02:06 +00:00
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
wxArrayString output, errors;
|
2016-03-31 06:28:16 +00:00
|
|
|
int diag = wxExecute( commandLine, output, errors, m_exec_flags );
|
2015-06-12 07:02:06 +00:00
|
|
|
|
2015-06-16 12:20:42 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2015-07-01 10:55:41 +00:00
|
|
|
msg << _( "Run command:" ) << wxT( "\n" ) << commandLine << wxT( "\n\n" );
|
2015-06-16 12:20:42 +00:00
|
|
|
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter->ReportHead( msg, RPT_SEVERITY_ACTION );
|
2015-06-12 07:02:06 +00:00
|
|
|
|
|
|
|
if( diag != 0 )
|
2018-05-21 22:28:26 +00:00
|
|
|
aReporter->ReportTail( wxString::Format(
|
2020-02-28 00:05:40 +00:00
|
|
|
_("Command error. Return code %d" ), diag ),
|
2020-03-04 09:48:18 +00:00
|
|
|
RPT_SEVERITY_ERROR );
|
2015-06-12 07:02:06 +00:00
|
|
|
else
|
2020-03-04 09:48:18 +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
|
|
|
{
|
2015-07-01 10:55:41 +00:00
|
|
|
msg.Empty();
|
|
|
|
msg << wxT( "\n" ) << _( "Info messages:" ) << wxT( "\n" );
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter->Report( msg, RPT_SEVERITY_INFO );
|
2015-06-12 07:02:06 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < output.GetCount(); ii++ )
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter->Report( output[ii] + wxT( "\n" ), 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
|
|
|
{
|
2015-07-01 10:55:41 +00:00
|
|
|
msg.Empty();
|
|
|
|
msg << wxT("\n") << _( "Error messages:" ) << wxT( "\n" );
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter->Report( msg, RPT_SEVERITY_INFO );
|
2015-06-12 07:02:06 +00:00
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < errors.GetCount(); ii++ )
|
2020-03-04 09:48:18 +00:00
|
|
|
aReporter->Report( errors[ii] + wxT( "\n" ), RPT_SEVERITY_ERROR );
|
2015-06-12 07:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-03-31 06:28:16 +00:00
|
|
|
ProcessExecute( commandLine, m_exec_flags );
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
//Imported function:
|
|
|
|
int TestDuplicateSheetNames( bool aCreateMarker );
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDIT_FRAME::prepareForNetlist()
|
|
|
|
{
|
|
|
|
// Ensure all power symbols have a valid reference
|
|
|
|
SCH_SHEET_LIST sheets( g_RootSheet );
|
|
|
|
sheets.AnnotatePowerSymbols();
|
|
|
|
|
|
|
|
// Performs some controls:
|
2018-02-17 11:43:56 +00:00
|
|
|
if( CheckAnnotate( NULL_REPORTER::GetInstance(), 0 ) )
|
2018-01-30 09:45:35 +00:00
|
|
|
{
|
2018-02-18 20:44:33 +00:00
|
|
|
// Schematic must be annotated: call Annotate dialog and tell the user why.
|
|
|
|
ModalAnnotate( _( "Exporting the netlist requires a completely annotated schematic." ) );
|
2018-01-30 09:45:35 +00:00
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
if( CheckAnnotate( NULL_REPORTER::GetInstance(), 0 ) )
|
2018-01-30 09:45:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test duplicate sheet names:
|
|
|
|
if( TestDuplicateSheetNames( false ) > 0 )
|
|
|
|
{
|
2018-04-18 00:27:15 +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
|
|
|
{
|
2019-03-27 22:37:26 +00:00
|
|
|
NETLIST_OBJECT_LIST* net_atoms = BuildNetListBase();
|
2019-03-17 19:15:08 +00:00
|
|
|
NETLIST_EXPORTER_KICAD exporter( this, net_atoms, g_ConnectionGraph );
|
2019-03-27 22:37:26 +00:00
|
|
|
STRING_FORMATTER formatter;
|
2018-01-30 09:45:35 +00:00
|
|
|
|
|
|
|
// @todo : trim GNL_ALL down to minimum for CVPCB
|
|
|
|
exporter.Format( &formatter, GNL_ALL );
|
|
|
|
|
2019-03-27 22:37:26 +00:00
|
|
|
std::string packet = formatter.GetString(); // an abbreviated "kicad" (s-expr) netlist
|
|
|
|
Kiway().ExpressMail( FRAME_CVPCB, MAIL_EESCHEMA_NETLIST, packet, this );
|
2018-01-30 09:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-17 19:15:08 +00:00
|
|
|
NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::CreateNetlist( bool aSilent,
|
|
|
|
bool aSilentAnnotate )
|
2018-01-30 09:45:35 +00:00
|
|
|
{
|
2020-05-04 23:34:02 +00:00
|
|
|
if( !aSilent ) // checks for errors and invokes annotation dialog as necessary
|
2018-01-30 09:45:35 +00:00
|
|
|
{
|
|
|
|
if( !prepareForNetlist() )
|
2019-03-17 19:15:08 +00:00
|
|
|
return nullptr;
|
2018-01-30 09:45:35 +00:00
|
|
|
}
|
|
|
|
else // performs similar function as prepareForNetlist but without a dialog.
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheets( g_RootSheet );
|
|
|
|
sheets.AnnotatePowerSymbols();
|
|
|
|
|
2019-03-17 19:15:08 +00:00
|
|
|
if( aSilentAnnotate )
|
|
|
|
AnnotateComponents( true, UNSORTED, INCREMENTAL_BY_REF, 0, false, false, true,
|
|
|
|
NULL_REPORTER::GetInstance() );
|
|
|
|
}
|
2018-01-30 09:45:35 +00:00
|
|
|
|
2019-03-17 19:15:08 +00:00
|
|
|
// TODO(JE) This is really going to turn into "PrepareForNetlist"
|
|
|
|
// when the old netlister (BuildNetListBase) is removed
|
2018-01-30 09:45:35 +00:00
|
|
|
|
2019-03-17 19:15:08 +00:00
|
|
|
return BuildNetListBase();
|
2018-01-30 09:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NETLIST_OBJECT_LIST* SCH_EDIT_FRAME::BuildNetListBase( bool updateStatusText )
|
|
|
|
{
|
2019-04-09 08:36:39 +00:00
|
|
|
// Ensure netlist is up to date
|
2019-11-10 23:24:27 +00:00
|
|
|
RecalculateConnections( NO_CLEANUP );
|
2019-04-09 08:36:39 +00:00
|
|
|
|
2018-01-30 09:45:35 +00:00
|
|
|
// I own this list until I return it to the new owner.
|
|
|
|
std::unique_ptr<NETLIST_OBJECT_LIST> ret( new NETLIST_OBJECT_LIST() );
|
|
|
|
|
|
|
|
// Creates the flattened sheet list:
|
|
|
|
SCH_SHEET_LIST aSheets( g_RootSheet );
|
|
|
|
|
|
|
|
// Build netlist info
|
|
|
|
bool success = ret->BuildNetListInfo( aSheets );
|
|
|
|
|
|
|
|
if( !success )
|
|
|
|
{
|
|
|
|
if( updateStatusText )
|
|
|
|
SetStatusText( _( "No Objects" ) );
|
|
|
|
return ret.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString msg = wxString::Format( _( "Net count = %d" ), int( ret->size() ) );
|
|
|
|
|
|
|
|
if( updateStatusText )
|
|
|
|
SetStatusText( msg );
|
|
|
|
|
|
|
|
return ret.release();
|
|
|
|
}
|
|
|
|
|