kicad/pcbnew/dialogs/dialog_netlist.cpp

275 lines
8.5 KiB
C++
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
2019-06-04 20:59:59 +00:00
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.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
* 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 <project.h>
#include <kiface_i.h>
#include <confirm.h>
2020-10-25 13:14:52 +00:00
#include <dialogs/html_messagebox.h>
2018-01-29 20:58:58 +00:00
#include <pcb_edit_frame.h>
#include <pcbnew_settings.h>
#include <reporter.h>
#include <bitmaps.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <board.h>
#include <connectivity/connectivity_data.h>
#include <wildcards_and_files_ext.h>
#include <netlist_reader/pcb_netlist.h>
#include <netlist_reader/board_netlist_updater.h>
#include <project/project_file.h> // LAST_PATH_TYPE
#include <dialog_netlist.h>
#include <wx_html_report_panel.h>
2007-05-06 16:03:28 +00:00
void PCB_EDIT_FRAME::InstallNetlistFrame()
2007-05-06 16:03:28 +00:00
{
wxString netlistName = GetLastPath( LAST_PATH_NETLIST );
2007-05-06 16:03:28 +00:00
DIALOG_NETLIST dlg( this, netlistName );
2007-05-06 16:03:28 +00:00
dlg.ShowModal();
SetLastPath( LAST_PATH_NETLIST, netlistName );
2007-05-06 16:03:28 +00:00
}
bool DIALOG_NETLIST::m_warnForNoNetPads = false;
bool DIALOG_NETLIST::m_matchByUUID = false;
DIALOG_NETLIST::DIALOG_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename )
: DIALOG_NETLIST_BASE( aParent ),
m_parent( aParent ),
m_netlistPath( aNetlistFullFilename ),
m_initialized( false ),
m_runDragCommand( false )
{
m_NetlistFilenameCtrl->SetValue( m_netlistPath );
m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
auto cfg = m_parent->GetPcbNewSettings();
m_cbUpdateFootprints->SetValue( cfg->m_NetlistDialog.update_footprints );
m_cbDeleteShortingTracks->SetValue( cfg->m_NetlistDialog.delete_shorting_tracks );
m_cbDeleteExtraFootprints->SetValue( cfg->m_NetlistDialog.delete_extra_footprints );
m_cbDeleteSinglePadNets->SetValue( cfg->m_NetlistDialog.delete_single_pad_nets );
m_cbWarnNoNetPad->SetValue( m_warnForNoNetPads );
m_matchByTimestamp->SetSelection( m_matchByUUID ? 0 : 1 );
m_MessageWindow->SetLabel( _("Changes To Be Applied") );
m_MessageWindow->SetVisibleSeverities( cfg->m_NetlistDialog.report_filter );
// We use a sdbSizer to get platform-dependent ordering of the action buttons, but
// that requires us to correct the button labels here.
m_sdbSizer1OK->SetLabel( _( "Update PCB" ) );
m_sdbSizer1Apply->SetLabel( _( "Rebuild Ratsnest" ) );
m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
m_buttonsSizer->Layout();
m_sdbSizer1OK->SetDefault();
2020-11-16 11:16:44 +00:00
finishDialogSettings();
m_initialized = true;
loadNetlist( true );
2007-05-06 16:03:28 +00:00
}
DIALOG_NETLIST::~DIALOG_NETLIST()
{
m_warnForNoNetPads = m_cbWarnNoNetPad->GetValue();
m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
auto cfg = m_parent->GetPcbNewSettings();
cfg->m_NetlistDialog.report_filter = m_MessageWindow->GetVisibleSeverities();
cfg->m_NetlistDialog.update_footprints = m_cbUpdateFootprints->GetValue();
cfg->m_NetlistDialog.delete_shorting_tracks = m_cbDeleteShortingTracks->GetValue();
cfg->m_NetlistDialog.delete_extra_footprints = m_cbDeleteExtraFootprints->GetValue();
cfg->m_NetlistDialog.delete_single_pad_nets = m_cbDeleteSinglePadNets->GetValue();
if( m_runDragCommand )
{
KIGFX::VIEW_CONTROLS* controls = m_parent->GetCanvas()->GetViewControls();
controls->SetCursorPosition( controls->GetMousePosition() );
m_parent->GetToolManager()->RunAction( PCB_ACTIONS::move, true );
}
}
void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event )
2007-05-06 16:03:28 +00:00
{
wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
wxString filename = m_parent->GetLastPath( LAST_PATH_NETLIST );
if( !filename.IsEmpty() )
{
wxFileName fn = filename;
dirPath = fn.GetPath();
filename = fn.GetFullName();
}
wxFileDialog FilesDialog( this, _( "Select Netlist" ), dirPath, filename,
NetlistFileWildcard(), wxFD_DEFAULT_STYLE | wxFD_FILE_MUST_EXIST );
if( FilesDialog.ShowModal() != wxID_OK )
return;
m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() );
onFilenameChanged();
}
void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event )
{
wxFileName fn = m_NetlistFilenameCtrl->GetValue();
if( !fn.IsOk() )
{
wxMessageBox( _( "Please, choose a valid netlist file." ) );
return;
}
if( !fn.FileExists() )
{
wxMessageBox( _( "The netlist file does not exist." ) );
return;
}
m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
loadNetlist( false );
m_sdbSizer1Cancel->SetDefault();
}
void DIALOG_NETLIST::OnFilenameKillFocus( wxFocusEvent& event )
{
onFilenameChanged();
event.Skip();
}
void DIALOG_NETLIST::onFilenameChanged()
{
if( m_initialized )
{
wxFileName fn = m_NetlistFilenameCtrl->GetValue();
if( fn.IsOk() )
{
if( fn.FileExists() )
{
m_netlistPath = m_NetlistFilenameCtrl->GetValue();
loadNetlist( true );
}
else
{
m_MessageWindow->Clear();
REPORTER& reporter = m_MessageWindow->Reporter();
reporter.Report( _( "The netlist file does not exist." ), RPT_SEVERITY_ERROR );
}
}
}
}
void DIALOG_NETLIST::OnMatchChanged( wxCommandEvent& event )
{
if( m_initialized )
loadNetlist( true );
}
void DIALOG_NETLIST::OnOptionChanged( wxCommandEvent& event )
{
if( m_initialized )
loadNetlist( true );
}
void DIALOG_NETLIST::OnCompileRatsnestClick( wxCommandEvent& event )
{
// Rebuild the board connectivity:
auto board = m_parent->GetBoard();
board->GetConnectivity()->RecalculateRatsnest();
}
void DIALOG_NETLIST::loadNetlist( bool aDryRun )
{
wxString netlistFileName = m_NetlistFilenameCtrl->GetValue();
wxFileName fn = netlistFileName;
if( !fn.IsOk() || !fn.FileExists() )
return;
m_MessageWindow->Clear();
REPORTER& reporter = m_MessageWindow->Reporter();
wxBusyCursor busy;
wxString msg;
msg.Printf( _( "Reading netlist file \"%s\".\n" ), netlistFileName );
reporter.ReportHead( msg, RPT_SEVERITY_INFO );
if( m_matchByTimestamp->GetSelection() == 1 )
msg = _( "Using reference designators to match components and footprints.\n" );
else
msg = _( "Using tstamps (unique IDs) to match components and footprints.\n" );
reporter.ReportHead( msg, RPT_SEVERITY_INFO );
m_MessageWindow->SetLazyUpdate( true ); // Use lazy update to speed the creation of the report
// (the window is not updated for each message)
m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
NETLIST netlist;
netlist.SetFindByTimeStamp( m_matchByUUID );
netlist.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
if( !m_parent->ReadNetlistFromFile( netlistFileName, netlist, reporter ) )
return;
BOARD_NETLIST_UPDATER updater( m_parent, m_parent->GetBoard() );
updater.SetReporter ( &reporter );
updater.SetIsDryRun( aDryRun );
updater.SetLookupByTimestamp( m_matchByUUID );
updater.SetDeleteUnusedComponents ( m_cbDeleteExtraFootprints->GetValue() );
updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
updater.SetDeleteSinglePadNets( m_cbDeleteSinglePadNets->GetValue() );
m_warnForNoNetPads = m_cbWarnNoNetPad->GetValue();
updater.SetWarnPadNoNetInNetlist( m_warnForNoNetPads );
updater.UpdateNetlist( netlist );
// The creation of the report was made without window update: the full page must be displayed
m_MessageWindow->Flush( true );
if( aDryRun )
return;
m_parent->OnNetlistChanged( updater, &m_runDragCommand );
}