2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/netlist.cpp
|
|
|
|
*/
|
2012-01-26 09:37:36 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2011 Jean-Pierre Charras.
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-01-26 09:37:36 +00:00
|
|
|
* Functions to read a netlist:
|
2011-09-16 14:13:02 +00:00
|
|
|
* - Load new footprints and initialize net info
|
2009-04-24 07:36:36 +00:00
|
|
|
* - Test for missing or extra footprints
|
2011-05-03 12:57:44 +00:00
|
|
|
* - Recalculate full connectivity info
|
2008-02-19 00:28:42 +00:00
|
|
|
*
|
2009-04-24 07:36:36 +00:00
|
|
|
* Important remark:
|
2012-01-26 09:37:36 +00:00
|
|
|
* When reading a netlist, Pcbnew must identify existing footprints (link
|
2009-11-18 12:52:19 +00:00
|
|
|
* between existing footprints an components in netlist)
|
2012-01-26 09:37:36 +00:00
|
|
|
* This identification can be made from 2 fields:
|
2009-04-24 07:36:36 +00:00
|
|
|
* - The reference (U2, R5 ..): this is the normal mode
|
2012-01-26 09:37:36 +00:00
|
|
|
* - The Time Stamp : useful after a full schematic
|
|
|
|
* reannotation because references can be changed for the component linked to its footprint.
|
|
|
|
* So when reading a netlist, ReadPcbNetlist() can use references or time stamps
|
2011-05-03 12:57:44 +00:00
|
|
|
* to identify footprints on board and the corresponding component in schematic.
|
2009-04-24 07:36:36 +00:00
|
|
|
* If we want to fully reannotate a schematic this sequence must be used
|
2011-05-03 12:57:44 +00:00
|
|
|
* 1 - SAVE your board !!!
|
|
|
|
* 2 - Create and read the netlist (to ensure all info is correct, mainly
|
2009-11-18 12:52:19 +00:00
|
|
|
* references and time stamp)
|
2011-05-03 12:57:44 +00:00
|
|
|
* 3 - Reannotate the schematic (references will be changed, but not time stamps )
|
|
|
|
* 4 - Recreate and read the new netlist using the Time Stamp identification
|
2009-11-18 12:52:19 +00:00
|
|
|
* (that reinit the new references)
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-04-02 16:14:07 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
|
2011-04-02 16:14:07 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <kicad_string.h>
|
|
|
|
#include <gestfich.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <richio.h>
|
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <macros.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <dialog_netlist.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
#include <netlist_reader.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-27 18:56:06 +00:00
|
|
|
#include <algorithm>
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function OpenNetlistFile
|
2009-04-24 07:36:36 +00:00
|
|
|
* used to open a netlist file
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
static FILE* OpenNetlistFile( const wxString& aFullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aFullFileName.IsEmpty() )
|
2012-01-26 09:37:36 +00:00
|
|
|
return NULL; // No filename: exit
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE* file = wxFopen( aFullFileName, wxT( "rt" ) );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
if( file == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2008-03-22 18:08:44 +00:00
|
|
|
wxString msg;
|
2010-04-23 14:46:00 +00:00
|
|
|
msg.Printf( _( "Netlist file %s not found" ), GetChars( aFullFileName ) );
|
2011-05-03 12:57:44 +00:00
|
|
|
wxMessageBox( msg );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
return file;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function ReadPcbNetlist
|
2009-11-18 12:52:19 +00:00
|
|
|
* Update footprints (load missing footprints and delete on request extra
|
|
|
|
* footprints)
|
2009-04-24 07:36:36 +00:00
|
|
|
* Update connectivity info ( Net Name list )
|
|
|
|
* Update Reference, value and "TIME STAMP"
|
|
|
|
* @param aNetlistFullFilename = netlist file name (*.net)
|
2009-11-18 12:52:19 +00:00
|
|
|
* @param aCmpFullFileName = cmp/footprint list file name (*.cmp) if not found,
|
2011-05-03 12:57:44 +00:00
|
|
|
* @param aMessageWindow = a wxTextCtrl to print messages (can be NULL).
|
|
|
|
* @param aChangeFootprint = true to change existing footprints
|
|
|
|
* when the netlist gives a different footprint.
|
|
|
|
* false to keep existing footprints
|
|
|
|
* @param aDeleteBadTracks - true to erase erroneous tracks after updating connectivity info.
|
2011-09-16 14:13:02 +00:00
|
|
|
* @param aDeleteExtraFootprints - true to remove unlocked footprints found on board but not
|
|
|
|
* in netlist.
|
2011-05-03 12:57:44 +00:00
|
|
|
* @param aSelect_By_Timestamp - true to use schematic timestamps instead of schematic references
|
|
|
|
* to identify footprints on board
|
|
|
|
* (Must be used after a full reannotation in schematic).
|
2010-04-16 16:28:35 +00:00
|
|
|
* @return true if Ok
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-05-03 12:57:44 +00:00
|
|
|
bool PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFullFilename,
|
|
|
|
const wxString& aCmpFullFileName,
|
|
|
|
wxTextCtrl* aMessageWindow,
|
|
|
|
bool aChangeFootprint,
|
|
|
|
bool aDeleteBadTracks,
|
|
|
|
bool aDeleteExtraFootprints,
|
|
|
|
bool aSelect_By_Timestamp )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-05-03 12:57:44 +00:00
|
|
|
FILE* netfile = OpenNetlistFile( aNetlistFullFilename );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-04-16 16:28:35 +00:00
|
|
|
if( !netfile )
|
|
|
|
return false;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-04-23 14:46:00 +00:00
|
|
|
SetLastNetListRead( aNetlistFullFilename );
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool useCmpfile = ! aCmpFullFileName.IsEmpty() && wxFileExists( aCmpFullFileName );
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
if( aMessageWindow )
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2010-04-23 14:46:00 +00:00
|
|
|
msg.Printf( _( "Reading Netlist \"%s\"" ), GetChars( aNetlistFullFilename ) );
|
2009-04-24 07:36:36 +00:00
|
|
|
aMessageWindow->AppendText( msg + wxT( "\n" ) );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
if( useCmpfile )
|
2011-05-03 12:57:44 +00:00
|
|
|
{
|
2011-09-16 14:13:02 +00:00
|
|
|
msg.Printf( _( "Using component/footprint link file \"%s\"" ),
|
|
|
|
GetChars( aCmpFullFileName ) );
|
2011-05-03 12:57:44 +00:00
|
|
|
aMessageWindow->AppendText( msg + wxT( "\n" ) );
|
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
|
|
|
|
if( aSelect_By_Timestamp )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Using time stamp selection" ),
|
|
|
|
GetChars( aCmpFullFileName ) );
|
|
|
|
aMessageWindow->AppendText( msg + wxT( "\n" ) );
|
|
|
|
}
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
// Clear undo and redo lists to avoid inconsistencies between lists
|
2010-04-16 16:28:35 +00:00
|
|
|
GetScreen()->ClearUndoRedoList();
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2010-04-16 16:28:35 +00:00
|
|
|
OnModify();
|
2011-02-28 18:36:19 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
// Clear flags and pointers to avoid inconsistencies
|
2010-04-16 16:28:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-01-20 11:26:10 +00:00
|
|
|
SetCurItem( NULL );
|
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
wxBusyCursor dummy; // Shows an hourglass while calculating
|
|
|
|
|
|
|
|
NETLIST_READER netList_Reader( this, aMessageWindow );
|
|
|
|
netList_Reader.m_UseTimeStamp = aSelect_By_Timestamp;
|
|
|
|
netList_Reader.m_ChangeFootprints = aChangeFootprint;
|
2012-01-26 09:37:36 +00:00
|
|
|
netList_Reader.m_UseCmpFile = useCmpfile;
|
|
|
|
netList_Reader.SetFilesnames( aNetlistFullFilename, aCmpFullFileName );
|
|
|
|
|
2012-02-17 19:43:43 +00:00
|
|
|
// True to read footprint filters section: true for CvPcb, false for Pcbnew
|
2012-02-01 19:49:37 +00:00
|
|
|
netList_Reader.ReadLibpartSectionSetOpt( false );
|
|
|
|
|
2012-01-27 18:56:06 +00:00
|
|
|
bool success = netList_Reader.ReadNetList( netfile );
|
|
|
|
if( !success )
|
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
wxMessageBox( _("Netlist read error") );
|
2012-01-27 18:56:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-03 12:57:44 +00:00
|
|
|
|
|
|
|
// Delete footprints not found in netlist:
|
|
|
|
if( aDeleteExtraFootprints )
|
|
|
|
{
|
2012-01-26 09:37:36 +00:00
|
|
|
if( IsOK( NULL,
|
|
|
|
_( "Ok to delete not locked footprints not found in netlist?" ) ) )
|
|
|
|
netList_Reader.RemoveExtraFootprints();
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rebuild the board connectivity:
|
|
|
|
Compile_Ratsnest( NULL, true );
|
|
|
|
|
2011-05-03 16:57:15 +00:00
|
|
|
if( aDeleteBadTracks && GetBoard()->m_Track )
|
2011-05-03 12:57:44 +00:00
|
|
|
{
|
2011-05-03 16:57:15 +00:00
|
|
|
// Remove erroneous tracks
|
2012-01-26 09:37:36 +00:00
|
|
|
if( RemoveMisConnectedTracks() )
|
|
|
|
Compile_Ratsnest( NULL, true );
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GetBoard()->DisplayInfo( this );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2011-05-03 12:57:44 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
/**
|
|
|
|
* build and shows a list of existing modules on board
|
2009-11-18 12:52:19 +00:00
|
|
|
* The user can select a module from this list
|
2009-04-24 07:36:36 +00:00
|
|
|
* @return a pointer to the selected module or NULL
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-04-24 07:36:36 +00:00
|
|
|
MODULE* Module;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2009-01-05 05:21:35 +00:00
|
|
|
if( GetBoard()->m_Modules == NULL )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
DisplayError( this, _( "No Modules" ) );
|
|
|
|
return 0;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
wxArrayString listnames;
|
2009-04-24 07:36:36 +00:00
|
|
|
Module = (MODULE*) GetBoard()->m_Modules;
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; Module != NULL; Module = (MODULE*) Module->Next() )
|
2010-11-19 18:50:23 +00:00
|
|
|
listnames.Add( Module->m_Reference->m_Text );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-09-06 19:42:46 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Components" ), listnames, wxEmptyString );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
wxString ref = dlg.GetTextSelection();
|
|
|
|
Module = (MODULE*) GetBoard()->m_Modules;
|
2011-09-06 19:42:46 +00:00
|
|
|
|
2010-11-19 18:50:23 +00:00
|
|
|
for( ; Module != NULL; Module = Module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2010-11-19 18:50:23 +00:00
|
|
|
if( Module->m_Reference->m_Text == ref )
|
|
|
|
break;
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Module;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
/*
|
|
|
|
* Function Test_Duplicate_Missing_And_Extra_Footprints
|
|
|
|
* Build a list of duplicate, missing and extra footprints
|
|
|
|
* from the current board and a netlist netlist :
|
|
|
|
* Shows 3 lists:
|
|
|
|
* 1 - duplicate footprints on board
|
|
|
|
* 2 - missing footprints (found in netlist but not on board)
|
|
|
|
* 3 - footprints not in netlist but on board
|
2012-12-18 17:50:00 +00:00
|
|
|
* param aFilename = the full filename netlist
|
|
|
|
* param aDuplicate = the list of duplicate modules to populate
|
|
|
|
* param aMissing = the list of missing module references and values
|
|
|
|
* to populate. For each missing item, the first string is the ref,
|
|
|
|
* the second is the value.
|
|
|
|
* param aNotInNetlist = the list of not-in-netlist modules to populate
|
2007-08-20 19:33:15 +00:00
|
|
|
*/
|
2012-12-18 17:50:00 +00:00
|
|
|
bool PCB_EDIT_FRAME::Test_Duplicate_Missing_And_Extra_Footprints(
|
|
|
|
const wxString& aFilename,
|
|
|
|
std::vector <MODULE*>& aDuplicate,
|
|
|
|
wxArrayString& aMissing,
|
|
|
|
std::vector <MODULE*>& aNotInNetlist )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-12-18 17:50:00 +00:00
|
|
|
FILE* netfile = OpenNetlistFile( aFilename );
|
2012-01-26 09:37:36 +00:00
|
|
|
if( !netfile )
|
2012-12-18 17:50:00 +00:00
|
|
|
return false;
|
2012-01-30 13:25:46 +00:00
|
|
|
|
2011-12-16 17:03:25 +00:00
|
|
|
// Build the list of references of the net list modules.
|
2011-05-03 12:57:44 +00:00
|
|
|
NETLIST_READER netList_Reader( this );
|
2012-12-18 17:50:00 +00:00
|
|
|
netList_Reader.SetFilesnames( aFilename, wxEmptyString );
|
2012-01-27 18:56:06 +00:00
|
|
|
netList_Reader.BuildModuleListOnlySetOpt( true );
|
2012-01-26 09:37:36 +00:00
|
|
|
if( ! netList_Reader.ReadNetList( netfile ) )
|
2012-12-18 17:50:00 +00:00
|
|
|
return false; // error
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2012-02-01 19:49:37 +00:00
|
|
|
COMPONENT_INFO_LIST& moduleInfoList = netList_Reader.GetComponentInfoList();
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2011-12-16 17:03:25 +00:00
|
|
|
// Search for duplicate footprints.
|
2011-05-05 17:45:35 +00:00
|
|
|
MODULE* module = GetBoard()->m_Modules;
|
|
|
|
for( ; module != NULL; module = module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
MODULE* altmodule = module->Next();
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
for( ; altmodule != NULL; altmodule = altmodule->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2011-05-05 17:45:35 +00:00
|
|
|
if( module->m_Reference->m_Text.CmpNoCase( altmodule->m_Reference->m_Text ) == 0 )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2012-12-18 17:50:00 +00:00
|
|
|
aDuplicate.push_back( module );
|
2007-08-20 19:33:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
// Search for missing modules on board.
|
|
|
|
for( unsigned ii = 0; ii < moduleInfoList.size(); ii++ )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
COMPONENT_INFO* cmp_info = moduleInfoList[ii];
|
|
|
|
module = GetBoard()->FindModuleByReference( cmp_info->m_Reference );
|
2011-05-05 17:45:35 +00:00
|
|
|
if( module == NULL ) // Module missing, not found in board
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2012-12-18 17:50:00 +00:00
|
|
|
aMissing.Add( cmp_info->m_Reference );
|
|
|
|
aMissing.Add( cmp_info->m_Value );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
// Search for modules found on board but not in net list.
|
2011-05-05 17:45:35 +00:00
|
|
|
module = GetBoard()->m_Modules;
|
|
|
|
for( ; module != NULL; module = module->Next() )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2012-01-26 09:37:36 +00:00
|
|
|
unsigned ii;
|
|
|
|
for( ii = 0; ii < moduleInfoList.size(); ii++ )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2012-02-01 19:49:37 +00:00
|
|
|
COMPONENT_INFO* cmp_info = moduleInfoList[ii];
|
|
|
|
if( module->m_Reference->m_Text.CmpNoCase( cmp_info->m_Reference ) == 0 )
|
2011-12-16 17:03:25 +00:00
|
|
|
break; // Module is in net list.
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
if( ii == moduleInfoList.size() ) // Module not found in netlist
|
2012-12-18 17:50:00 +00:00
|
|
|
aNotInNetlist.push_back( module );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 17:50:00 +00:00
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|