2012-12-18 17:50:00 +00:00
|
|
|
/**
|
2013-01-03 20:21:40 +00:00
|
|
|
* @file pcbnew/dialogs/dialog_netlist.cpp
|
2012-12-18 17:50:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2012 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-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <confirm.h>
|
2012-12-18 17:50:00 +00:00
|
|
|
#include <dialog_helpers.h>
|
|
|
|
#include <html_messagebox.h>
|
|
|
|
#include <base_units.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <pcbcommon.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew_config.h>
|
|
|
|
#include <class_board_design_settings.h>
|
2012-08-29 16:59:50 +00:00
|
|
|
#include <class_board.h>
|
2012-12-18 17:50:00 +00:00
|
|
|
#include <class_module.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_netlist.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
void PCB_EDIT_FRAME::InstallNetlistFrame( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-02-02 17:39:59 +00:00
|
|
|
/* Setup the netlist file name to the last netlist file read,
|
|
|
|
* or the board file name if the last filename is empty or last file not existing.
|
2010-04-23 14:46:00 +00:00
|
|
|
*/
|
|
|
|
wxFileName fn = GetLastNetListRead();
|
2011-03-22 17:58:58 +00:00
|
|
|
wxString lastNetlistName = GetLastNetListRead();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-04-23 14:46:00 +00:00
|
|
|
if( !fn.FileExists() )
|
|
|
|
{
|
2012-08-29 16:59:50 +00:00
|
|
|
fn = GetBoard()->GetFileName();
|
2012-03-08 17:47:23 +00:00
|
|
|
fn.SetExt( NetlistFileExtension );
|
2011-08-19 13:08:24 +00:00
|
|
|
lastNetlistName = fn.GetFullPath();
|
2010-04-23 14:46:00 +00:00
|
|
|
}
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
DIALOG_NETLIST dlg( this, DC, lastNetlistName );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
dlg.ShowModal();
|
2011-03-22 17:58:58 +00:00
|
|
|
|
|
|
|
// Save project settings if needed.
|
|
|
|
// Project settings are saved in the corresponding <board name>.pro file
|
2013-02-02 17:39:59 +00:00
|
|
|
bool configChanged = lastNetlistName != GetLastNetListRead();
|
|
|
|
if( dlg.UseCmpFileForFpNames() != GetUseCmpFileForFpNames() )
|
|
|
|
{
|
|
|
|
SetUseCmpFileForFpNames( dlg.UseCmpFileForFpNames() );
|
|
|
|
configChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( configChanged &&
|
2012-08-29 16:59:50 +00:00
|
|
|
!GetBoard()->GetFileName().IsEmpty() &&
|
2011-03-22 17:58:58 +00:00
|
|
|
IsOK(NULL, _("Project config has changed. Save it ?") ) )
|
|
|
|
{
|
2012-08-29 16:59:50 +00:00
|
|
|
wxFileName fn = GetBoard()->GetFileName();
|
2011-03-22 17:58:58 +00:00
|
|
|
fn.SetExt( ProjectFileExtension );
|
|
|
|
wxGetApp().WriteProjectConfig( fn.GetFullPath(), GROUP,
|
|
|
|
GetProjectFileParameters() );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
DIALOG_NETLIST::DIALOG_NETLIST( PCB_EDIT_FRAME* aParent, wxDC * aDC,
|
2012-12-18 17:50:00 +00:00
|
|
|
const wxString & aNetlistFullFilename )
|
2010-04-23 14:46:00 +00:00
|
|
|
: DIALOG_NETLIST_FBP( aParent )
|
2008-03-22 18:08:44 +00:00
|
|
|
{
|
2012-12-18 17:50:00 +00:00
|
|
|
m_parent = aParent;
|
|
|
|
m_dc = aDC;
|
|
|
|
m_NetlistFilenameCtrl->SetValue( aNetlistFullFilename );
|
2013-02-02 17:39:59 +00:00
|
|
|
m_cmpNameSourceOpt->SetSelection( m_parent->GetUseCmpFileForFpNames() ? 1 : 0 );
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2011-05-03 12:57:44 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2012-12-18 17:50:00 +00:00
|
|
|
void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-04-23 14:46:00 +00:00
|
|
|
wxString lastPath = wxFileName::GetCwd();
|
2012-12-18 17:50:00 +00:00
|
|
|
wxString lastNetlistRead = m_parent->GetLastNetListRead();
|
2010-04-23 14:46:00 +00:00
|
|
|
|
|
|
|
if( !lastNetlistRead.IsEmpty() && !wxFileName::FileExists( lastNetlistRead ) )
|
|
|
|
{
|
|
|
|
lastNetlistRead = wxEmptyString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFileName fn = lastNetlistRead;
|
|
|
|
lastPath = fn.GetPath();
|
2010-04-24 09:03:35 +00:00
|
|
|
lastNetlistRead = fn.GetFullName();
|
2010-04-23 14:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxLogDebug( wxT( "Last net list read path <%s>, file name <%s>." ),
|
|
|
|
GetChars( lastPath ), GetChars( lastNetlistRead ) );
|
|
|
|
|
|
|
|
wxFileDialog FilesDialog( this, _( "Select Netlist" ), lastPath, lastNetlistRead,
|
|
|
|
NetlistFileWildcard, wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
if( FilesDialog.ShowModal() != wxID_OK )
|
|
|
|
return;
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2010-04-23 14:46:00 +00:00
|
|
|
m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
void DIALOG_NETLIST::OnReadNetlistFileClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2013-02-02 17:39:59 +00:00
|
|
|
wxString fullNetfileName = m_NetlistFilenameCtrl->GetValue();
|
|
|
|
wxString cmpFilename;
|
|
|
|
if( UseCmpFileForFpNames() )
|
|
|
|
{
|
|
|
|
wxFileName fn = m_NetlistFilenameCtrl->GetValue();
|
|
|
|
fn.SetExt( ComponentFileExtension );
|
|
|
|
cmpFilename = fn.GetFullPath();
|
|
|
|
}
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2013-02-02 17:39:59 +00:00
|
|
|
m_parent->ReadPcbNetlist( fullNetfileName, cmpFilename, m_MessageWindow,
|
2012-01-22 17:20:22 +00:00
|
|
|
m_ChangeExistingFootprintCtrl->GetSelection() == 1 ? true : false,
|
|
|
|
m_DeleteBadTracks->GetSelection() == 1 ? true : false,
|
|
|
|
m_RemoveExtraFootprintsCtrl->GetSelection() == 1 ? true : false,
|
|
|
|
m_Select_By_Timestamp->GetSelection() == 1 ? true : false );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
void DIALOG_NETLIST::OnTestFootprintsClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-12-18 17:50:00 +00:00
|
|
|
if( m_parent->GetBoard()->m_Modules == NULL )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( this, _( "No modules" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lists of duplicates, missing references and not in netlist footprints:
|
|
|
|
std::vector <MODULE*> duplicate;
|
|
|
|
wxArrayString missing;
|
|
|
|
std::vector <MODULE*> notInNetlist;
|
|
|
|
wxString netlistFilename = m_NetlistFilenameCtrl->GetValue();
|
|
|
|
|
|
|
|
if( ! m_parent->Test_Duplicate_Missing_And_Extra_Footprints(
|
|
|
|
netlistFilename, duplicate, missing, notInNetlist ) )
|
|
|
|
{
|
|
|
|
wxMessageBox( _("Netlist file not found!") );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ERR_CNT_MAX 100 // Max number of errors to output in dialog
|
|
|
|
// to avoid a too long message list
|
|
|
|
|
|
|
|
wxString list; // The messages to display
|
|
|
|
|
|
|
|
m_parent->SetLastNetListRead( netlistFilename );
|
|
|
|
|
|
|
|
int err_cnt = 0;
|
|
|
|
|
|
|
|
// Search for duplicate footprints.
|
|
|
|
if( duplicate.size() == 0 )
|
|
|
|
list << wxT("<p><b>") << _( "No duplicate." ) << wxT("</b></p>");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list << wxT("<p><b>") << _( "Duplicates:" ) << wxT("</b></p>");
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < duplicate.size(); ii++ )
|
|
|
|
{
|
|
|
|
MODULE* module = duplicate[ii];
|
|
|
|
|
|
|
|
if( module->m_Reference->m_Text.IsEmpty() )
|
|
|
|
list << wxT("<br>") << wxT("[noref)");
|
|
|
|
else
|
|
|
|
list << wxT("<br>") << module->m_Reference->m_Text;
|
|
|
|
|
|
|
|
list << wxT(" (<i>") << module->m_Value->m_Text << wxT("</i>)");
|
|
|
|
list << wxT(" @ ");
|
|
|
|
list << CoordinateToString( module->GetPosition().x ),
|
|
|
|
list << wxT(", ") << CoordinateToString( module->GetPosition().y ),
|
|
|
|
err_cnt++;
|
|
|
|
|
|
|
|
if( ERR_CNT_MAX < err_cnt )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search for missing modules on board.
|
|
|
|
if( missing.size() == 0 )
|
|
|
|
list << wxT("<p><b>") << _( "No missing modules." ) << wxT("</b></p>");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list << wxT("<p><b>") << _( "Missing:" ) << wxT("</b></p>");
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < missing.size(); ii += 2 )
|
|
|
|
{
|
|
|
|
list << wxT("<br>") << missing[ii];
|
|
|
|
list << wxT(" (<i>") << missing[ii+1] << wxT("</i>)");
|
|
|
|
err_cnt++;
|
|
|
|
|
|
|
|
if( ERR_CNT_MAX < err_cnt )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Search for modules found on board but not in net list.
|
|
|
|
if( notInNetlist.size() == 0 )
|
|
|
|
list << wxT("<p><b>") << _( "No extra modules." ) << wxT("</b></p>");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list << wxT("<p><b>") << _( "Not in Netlist:" ) << wxT("</b></p>");
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < notInNetlist.size(); ii++ )
|
|
|
|
{
|
|
|
|
MODULE* module = notInNetlist[ii];
|
|
|
|
|
|
|
|
if( module->m_Reference->m_Text.IsEmpty() )
|
|
|
|
list << wxT("<br>") << wxT("[noref)");
|
|
|
|
else
|
|
|
|
list << wxT("<br>") << module->m_Reference->m_Text ;
|
|
|
|
list << wxT(" (<i>") << module->m_Value->m_Text << wxT("</i>)");
|
|
|
|
list << wxT(" @ ");
|
|
|
|
list << CoordinateToString( module->GetPosition().x ),
|
|
|
|
list << wxT(", ") << CoordinateToString( module->GetPosition().y ),
|
|
|
|
err_cnt++;
|
|
|
|
|
|
|
|
if( ERR_CNT_MAX < err_cnt )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ERR_CNT_MAX < err_cnt )
|
|
|
|
{
|
|
|
|
list << wxT("<p><b>")
|
|
|
|
<< _( "Too many errors: some are skipped" )
|
|
|
|
<< wxT("</b></p>");
|
|
|
|
}
|
|
|
|
|
|
|
|
HTML_MESSAGE_BOX dlg( this, _( "Check Modules" ) );
|
|
|
|
dlg.AddHTML_Text(list);
|
|
|
|
dlg.ShowModal();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*!
|
|
|
|
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_COMPILE_RATSNEST
|
|
|
|
*/
|
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
void DIALOG_NETLIST::OnCompileRatsnestClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2012-12-18 17:50:00 +00:00
|
|
|
m_parent->Compile_Ratsnest( m_dc, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*!
|
2007-11-13 09:35:39 +00:00
|
|
|
* wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_CANCEL
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
|
|
|
|
2009-04-24 07:36:36 +00:00
|
|
|
void DIALOG_NETLIST::OnCancelClick( wxCommandEvent& event )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-11-13 09:35:39 +00:00
|
|
|
EndModal( -1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|