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-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2013-04-25 16:29:35 +00:00
|
|
|
#include <appl_wxstruct.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <dialog_helpers.h>
|
2013-04-25 16:29:35 +00:00
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <netlist_reader.h>
|
|
|
|
#include <reporter.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <pcbnew.h>
|
2013-04-25 16:29:35 +00:00
|
|
|
#include <io_mgr.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
void PCB_EDIT_FRAME::ReadPcbNetlist( const wxString& aNetlistFileName,
|
|
|
|
const wxString& aCmpFileName,
|
|
|
|
REPORTER* aReporter,
|
|
|
|
bool aChangeFootprints,
|
|
|
|
bool aDeleteUnconnectedTracks,
|
2011-05-03 12:57:44 +00:00
|
|
|
bool aDeleteExtraFootprints,
|
2013-04-25 16:29:35 +00:00
|
|
|
bool aSelectByTimeStamp,
|
|
|
|
bool aIsDryRun )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
wxString msg;
|
|
|
|
NETLIST netlist;
|
|
|
|
NETLIST_READER* netlistReader;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
try
|
2009-04-24 07:36:36 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
netlistReader = NETLIST_READER::GetNetlistReader( &netlist, aNetlistFileName,
|
|
|
|
aCmpFileName );
|
2011-09-16 14:13:02 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( netlistReader == NULL )
|
2011-05-03 12:57:44 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
msg.Printf( _( "Cannot open netlist file \"%s\"." ), GetChars( aNetlistFileName ) );
|
|
|
|
wxMessageBox( msg, _( "Netlist Load Error." ), wxOK | wxICON_ERROR, this );
|
|
|
|
return;
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
2012-01-26 09:37:36 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
std::auto_ptr< NETLIST_READER > nlr( netlistReader );
|
|
|
|
SetLastNetListRead( aNetlistFileName );
|
|
|
|
netlistReader->LoadNetlist();
|
|
|
|
loadFootprints( netlist, aReporter );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR& ioe )
|
|
|
|
{
|
2013-04-28 20:20:40 +00:00
|
|
|
msg.Printf( _( "Error loading netlist.\n%s" ), ioe.errorText.GetData() );
|
2013-04-25 16:29:35 +00:00
|
|
|
wxMessageBox( msg, _( "Netlist Load Error" ), wxOK | wxICON_ERROR );
|
|
|
|
return;
|
2013-03-19 01:25:19 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
netlist.SetIsDryRun( aIsDryRun );
|
|
|
|
netlist.SetFindByTimeStamp( aSelectByTimeStamp );
|
|
|
|
netlist.SetDeleteExtraFootprints( aDeleteExtraFootprints );
|
|
|
|
netlist.SetReplaceFootprints( aChangeFootprints );
|
2011-01-20 11:26:10 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// Clear undo and redo lists to avoid inconsistencies between lists
|
|
|
|
if( !netlist.IsDryRun() )
|
|
|
|
GetScreen()->ClearUndoRedoList();
|
2011-05-03 12:57:44 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
netlist.SortByReference();
|
|
|
|
GetBoard()->ReplaceNetlist( netlist, aReporter );
|
2012-01-26 09:37:36 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
// If it was a dry run, nothing has changed so we're done.
|
|
|
|
if( netlist.IsDryRun() )
|
|
|
|
return;
|
2012-02-01 19:49:37 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
OnModify();
|
2013-03-19 01:25:19 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
SetCurItem( NULL );
|
2011-05-03 12:57:44 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( aDeleteUnconnectedTracks && GetBoard()->m_Track )
|
2011-05-03 12:57:44 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
// Remove erroneous tracks. This should probably pushed down to the #BOARD object.
|
|
|
|
RemoveMisConnectedTracks();
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Rebuild the board connectivity:
|
|
|
|
Compile_Ratsnest( NULL, true );
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( GetBoard() );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2011-05-03 12:57:44 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
MODULE* PCB_EDIT_FRAME::ListAndSelectModuleName()
|
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() )
|
2013-03-13 18:53:58 +00:00
|
|
|
listnames.Add( Module->GetReference() );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
wxArrayString headers;
|
2013-04-25 16:29:35 +00:00
|
|
|
headers.Add( wxT( "Module" ) );
|
2013-03-19 01:25:19 +00:00
|
|
|
std::vector<wxArrayString> itemsToDisplay;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
// Conversion from wxArrayString to vector of ArrayString
|
|
|
|
for( unsigned i = 0; i < listnames.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( listnames[i] );
|
|
|
|
itemsToDisplay.push_back( item );
|
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-03-19 01:25:19 +00:00
|
|
|
EDA_LIST_DIALOG dlg( this, _( "Components" ), headers, itemsToDisplay, 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
|
|
|
{
|
2013-03-13 18:53:58 +00:00
|
|
|
if( Module->GetReference() == ref )
|
2010-11-19 18:50:23 +00:00
|
|
|
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
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
void PCB_EDIT_FRAME::loadFootprints( NETLIST& aNetlist, REPORTER* aReporter )
|
|
|
|
throw( IO_ERROR, PARSE_ERROR )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-04-28 20:20:40 +00:00
|
|
|
bool loadFootprint;
|
2013-04-25 16:29:35 +00:00
|
|
|
wxString msg;
|
|
|
|
wxString lastFootprintLibName;
|
|
|
|
COMPONENT* component;
|
2013-05-02 14:12:55 +00:00
|
|
|
MODULE* module = 0;
|
2013-04-28 20:20:40 +00:00
|
|
|
MODULE* fpOnBoard;
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
if( aNetlist.IsEmpty() )
|
|
|
|
return;
|
2012-01-30 13:25:46 +00:00
|
|
|
|
2013-04-28 20:20:40 +00:00
|
|
|
aNetlist.SortByFootprintName();
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
wxString libPath;
|
|
|
|
wxFileName fn;
|
2007-08-20 19:33:15 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) );
|
2013-03-13 18:53:58 +00:00
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
for( unsigned ii = 0; ii < aNetlist.GetCount(); ii++ )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
component = aNetlist.GetComponent( ii );
|
2011-04-19 14:28:34 +00:00
|
|
|
|
2013-04-28 20:20:40 +00:00
|
|
|
// Check if component footprint is already on BOARD and only load the footprint from
|
|
|
|
// the library if it's needed.
|
|
|
|
if( aNetlist.IsFindByTimeStamp() )
|
|
|
|
fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetTimeStamp(), true );
|
|
|
|
else
|
|
|
|
fpOnBoard = m_Pcb->FindModule( aNetlist.GetComponent( ii )->GetReference() );
|
|
|
|
|
2013-04-29 21:00:24 +00:00
|
|
|
loadFootprint = (fpOnBoard == NULL) ||
|
2013-04-28 20:20:40 +00:00
|
|
|
(fpOnBoard->GetPath() != component->GetFootprintName());
|
|
|
|
|
|
|
|
if( loadFootprint && (component->GetFootprintName() != lastFootprintLibName) )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
module = NULL;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < g_LibraryNames.GetCount(); ii++ )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
fn = wxFileName( wxEmptyString, g_LibraryNames[ii],
|
|
|
|
LegacyFootprintLibPathExtension );
|
|
|
|
|
|
|
|
libPath = wxGetApp().FindLibraryPath( fn );
|
|
|
|
|
|
|
|
if( !libPath )
|
2013-04-29 21:00:24 +00:00
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "*** Warning: Cannot find footprint library file \"%s\" "
|
|
|
|
"in any of the standard KiCad library search paths. ***\n" ),
|
|
|
|
GetChars( fn.GetFullPath() ) );
|
|
|
|
aReporter->Report( msg );
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
continue;
|
2013-04-29 21:00:24 +00:00
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
|
2013-04-28 20:20:40 +00:00
|
|
|
module = pi->FootprintLoad( libPath, component->GetFootprintName() );
|
2013-04-25 16:29:35 +00:00
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
2013-04-28 20:20:40 +00:00
|
|
|
lastFootprintLibName = component->GetFootprintName();
|
2013-04-25 16:29:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 16:29:35 +00:00
|
|
|
if( module == NULL )
|
|
|
|
{
|
2013-04-26 15:11:52 +00:00
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "*** Warning: component `%s` footprint <%s> was not found in "
|
|
|
|
"any libraries. ***\n" ),
|
|
|
|
GetChars( component->GetReference() ),
|
2013-04-28 20:20:40 +00:00
|
|
|
GetChars( component->GetFootprintName() ) );
|
2013-04-26 15:11:52 +00:00
|
|
|
aReporter->Report( msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
2013-04-25 16:29:35 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2013-04-25 16:29:35 +00:00
|
|
|
else
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2013-04-25 16:29:35 +00:00
|
|
|
// Footprint already loaded from a library, duplicate it (faster)
|
|
|
|
if( module == NULL )
|
|
|
|
continue; // Module does not exist in any library.
|
|
|
|
|
|
|
|
module = new MODULE( *module );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 21:00:24 +00:00
|
|
|
if( loadFootprint && module != NULL )
|
|
|
|
component->SetModule( module );
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|