2016-01-29 10:24:39 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <pcb_netlist.h>
|
|
|
|
#include <dialog_update_pcb.h>
|
|
|
|
#include <wx_html_report_panel.h>
|
|
|
|
#include <board_netlist_updater.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/common_actions.h>
|
|
|
|
#include <class_draw_panel_gal.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <ratsnest_data.h>
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
DIALOG_UPDATE_PCB::DIALOG_UPDATE_PCB( PCB_EDIT_FRAME* aParent, NETLIST *aNetlist ) :
|
|
|
|
DIALOG_UPDATE_PCB_BASE ( aParent ),
|
|
|
|
m_frame (aParent),
|
|
|
|
m_netlist (aNetlist)
|
|
|
|
{
|
|
|
|
m_messagePanel->SetLabel( _("Changes to be applied:") );
|
|
|
|
m_messagePanel->SetLazyUpdate ( true );
|
|
|
|
m_netlist->SortByReference();
|
|
|
|
m_btnPerformUpdate->SetFocus();
|
|
|
|
|
|
|
|
m_messagePanel->SetVisibleSeverities( REPORTER::RPT_WARNING | REPORTER::RPT_ERROR | REPORTER::RPT_ACTION );
|
|
|
|
}
|
|
|
|
|
|
|
|
DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
|
|
|
|
{
|
|
|
|
m_messagePanel->Clear();
|
|
|
|
|
|
|
|
REPORTER &reporter = m_messagePanel->Reporter();
|
|
|
|
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
|
|
|
TOOL_MANAGER *toolManager = m_frame->GetToolManager();
|
|
|
|
BOARD *board = m_frame->GetBoard();
|
|
|
|
|
|
|
|
if( !aDryRun )
|
|
|
|
{
|
|
|
|
// Remove old modules
|
|
|
|
for( MODULE* module = board->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
2016-06-29 10:23:11 +00:00
|
|
|
module->RunOnChildren( std::bind( &KIGFX::VIEW::Remove, view, _1 ) );
|
2016-01-29 10:24:39 +00:00
|
|
|
view->Remove( module );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear selection, just in case a selected item has to be removed
|
|
|
|
toolManager->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
}
|
|
|
|
|
2016-01-29 10:31:26 +00:00
|
|
|
m_netlist->SetDeleteExtraFootprints( true );
|
|
|
|
m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetValue() );
|
|
|
|
m_netlist->SetReplaceFootprints( true );
|
|
|
|
|
2016-01-29 10:29:56 +00:00
|
|
|
try {
|
|
|
|
m_frame->LoadFootprints( *m_netlist, &reporter );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR &error )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
reporter.Report( _( "Failed to load one or more footprints. Please add the missing libraries in PCBNew configuration. "
|
|
|
|
"The PCB will not update completely." ), REPORTER::RPT_ERROR );
|
|
|
|
reporter.Report( error.errorText, REPORTER::RPT_INFO );
|
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
|
|
|
|
|
|
|
|
updater.SetReporter ( &reporter );
|
|
|
|
updater.SetIsDryRun( aDryRun);
|
2016-01-29 10:29:56 +00:00
|
|
|
updater.SetLookupByTimestamp( m_matchByTimestamp->GetValue() );
|
2016-01-29 10:24:39 +00:00
|
|
|
updater.SetDeleteUnusedComponents ( true );
|
|
|
|
updater.SetReplaceFootprints( true );
|
|
|
|
updater.SetDeleteSinglePadNets ( false );
|
|
|
|
|
|
|
|
updater.UpdateNetlist( *m_netlist );
|
|
|
|
|
|
|
|
m_messagePanel->Flush();
|
|
|
|
|
|
|
|
if( aDryRun )
|
|
|
|
return;
|
|
|
|
|
2016-01-29 14:43:40 +00:00
|
|
|
std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-01-29 14:43:40 +00:00
|
|
|
m_frame->OnModify();
|
2016-01-29 10:24:39 +00:00
|
|
|
m_frame->SetCurItem( NULL );
|
|
|
|
|
|
|
|
// Reload modules
|
|
|
|
for( MODULE* module = board->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
2016-06-29 10:23:11 +00:00
|
|
|
module->RunOnChildren( std::bind( &KIGFX::VIEW::Add, view, _1 ) );
|
2016-01-29 10:24:39 +00:00
|
|
|
view->Add( module );
|
|
|
|
module->ViewUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rebuild the board connectivity:
|
|
|
|
if( m_frame->IsGalCanvasActive() )
|
|
|
|
board->GetRatsnest()->ProcessBoard();
|
|
|
|
|
|
|
|
m_frame->Compile_Ratsnest( NULL, true );
|
|
|
|
|
|
|
|
m_frame->SetMsgPanel( board );
|
|
|
|
|
2016-03-17 03:05:08 +00:00
|
|
|
|
|
|
|
if( m_frame->IsGalCanvasActive() )
|
|
|
|
{
|
2016-07-11 07:48:51 +00:00
|
|
|
m_frame->SpreadFootprints( &newFootprints, false, false, m_frame->GetCrossHairPosition() );
|
2016-03-17 03:05:08 +00:00
|
|
|
|
2016-03-18 03:09:24 +00:00
|
|
|
if( !newFootprints.empty() )
|
2016-03-17 03:05:08 +00:00
|
|
|
{
|
2016-06-29 20:07:55 +00:00
|
|
|
for( MODULE* footprint : newFootprints )
|
2016-03-18 03:09:24 +00:00
|
|
|
{
|
|
|
|
toolManager->RunAction( COMMON_ACTIONS::selectItem, true, footprint );
|
|
|
|
}
|
|
|
|
toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
|
2016-03-17 03:05:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-29 10:36:51 +00:00
|
|
|
m_btnPerformUpdate->Enable( false );
|
|
|
|
m_btnPerformUpdate->SetLabel( _( "Update complete" ) );
|
2016-03-17 03:05:08 +00:00
|
|
|
m_btnCancel->SetLabel ( _("Close") );
|
2016-01-29 10:36:51 +00:00
|
|
|
m_btnCancel->SetFocus();
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_UPDATE_PCB::OnMatchChange( wxCommandEvent& event )
|
|
|
|
{
|
2016-01-29 10:29:56 +00:00
|
|
|
PerformUpdate( true );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_UPDATE_PCB::OnCancelClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
EndModal( wxID_CANCEL );
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_messagePanel->SetLabel( _("Changes applied to the PCB:") );
|
|
|
|
PerformUpdate( false );
|
|
|
|
m_btnCancel->SetFocus( );
|
|
|
|
}
|