2016-10-25 13:34:59 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/dialogs/dialog_update_pcb.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2016 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
|
|
|
|
*/
|
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
#include <common.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
#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>
|
2017-02-21 12:42:08 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
#include <class_draw_panel_gal.h>
|
2016-10-25 13:34:59 +00:00
|
|
|
#include <class_drawpanel.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <ratsnest_data.h>
|
2018-02-15 08:49:53 +00:00
|
|
|
#include <view/view.h>
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
2018-02-28 09:44:22 +00:00
|
|
|
#include <kiface_i.h>
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
using namespace std::placeholders;
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
#define NETLIST_FILTER_MESSAGES_KEY wxT("NetlistReportFilterMsg")
|
|
|
|
#define NETLIST_UPDATEFOOTPRINTS_KEY wxT("NetlistUpdateFootprints")
|
|
|
|
#define NETLIST_DELETESHORTINGTRACKS_KEY wxT("NetlistDeleteShortingTracks")
|
|
|
|
#define NETLIST_DELETEEXTRAFOOTPRINTS_KEY wxT("NetlistDeleteExtraFootprints")
|
|
|
|
#define NETLIST_DELETESINGLEPADNETS_KEY wxT("NetlistDeleteSinglePadNets")
|
|
|
|
|
|
|
|
|
2018-02-15 08:49:53 +00:00
|
|
|
DIALOG_UPDATE_PCB::DIALOG_UPDATE_PCB( PCB_EDIT_FRAME* aParent, NETLIST* aNetlist ) :
|
|
|
|
DIALOG_UPDATE_PCB_BASE( aParent ),
|
|
|
|
m_frame( aParent ),
|
2018-02-28 09:44:22 +00:00
|
|
|
m_netlist( aNetlist ),
|
|
|
|
m_initialized( false )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
m_config = Kiface().KifaceSettings();
|
|
|
|
|
|
|
|
m_cbUpdateFootprints->SetValue( m_config->Read( NETLIST_UPDATEFOOTPRINTS_KEY, 0l ) );
|
|
|
|
m_cbDeleteExtraFootprints->SetValue( m_config->Read( NETLIST_DELETEEXTRAFOOTPRINTS_KEY, 0l ) );
|
|
|
|
m_cbDeleteSinglePadNets->SetValue( m_config->Read( NETLIST_DELETESINGLEPADNETS_KEY, 0l ) );
|
|
|
|
|
|
|
|
m_messagePanel->SetLabel( _("Changes To Be Applied") );
|
2016-09-02 13:53:51 +00:00
|
|
|
m_messagePanel->SetLazyUpdate( true );
|
2016-01-29 10:24:39 +00:00
|
|
|
m_netlist->SortByReference();
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_messagePanel->SetVisibleSeverities( m_config->Read( NETLIST_FILTER_MESSAGES_KEY, -1l ) );
|
2018-03-10 17:19:52 +00:00
|
|
|
|
2018-05-22 20:27:51 +00:00
|
|
|
m_messagePanel->GetSizer()->SetSizeHints( this );
|
2018-02-28 09:44:22 +00:00
|
|
|
|
|
|
|
// 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_sdbSizer1Cancel->SetLabel( _( "Close" ) );
|
|
|
|
m_sdbSizer1->Layout();
|
|
|
|
|
|
|
|
m_sdbSizer1OK->SetDefault();
|
|
|
|
FinishDialogSettings();
|
|
|
|
|
|
|
|
m_initialized = true;
|
|
|
|
PerformUpdate( true );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
DIALOG_UPDATE_PCB::~DIALOG_UPDATE_PCB()
|
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
m_config->Write( NETLIST_UPDATEFOOTPRINTS_KEY, m_cbUpdateFootprints->GetValue() );
|
|
|
|
m_config->Write( NETLIST_DELETEEXTRAFOOTPRINTS_KEY, m_cbDeleteExtraFootprints->GetValue() );
|
|
|
|
m_config->Write( NETLIST_DELETESINGLEPADNETS_KEY, m_cbDeleteSinglePadNets->GetValue() );
|
|
|
|
m_config->Write( NETLIST_FILTER_MESSAGES_KEY, (long) m_messagePanel->GetVisibleSeverities() );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
void DIALOG_UPDATE_PCB::PerformUpdate( bool aDryRun )
|
|
|
|
{
|
|
|
|
m_messagePanel->Clear();
|
|
|
|
|
2016-09-13 08:06:49 +00:00
|
|
|
REPORTER& reporter = m_messagePanel->Reporter();
|
2016-09-02 13:53:51 +00:00
|
|
|
TOOL_MANAGER* toolManager = m_frame->GetToolManager();
|
|
|
|
BOARD* board = m_frame->GetBoard();
|
2016-01-29 10:24:39 +00:00
|
|
|
|
2016-10-25 13:34:59 +00:00
|
|
|
// keep trace of the initial baord area, if we want to place new footprints
|
|
|
|
// outside the existinag board
|
2017-02-23 04:31:26 +00:00
|
|
|
EDA_RECT bbox = board->GetBoundingBox();
|
2016-10-25 13:34:59 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
if( !aDryRun )
|
|
|
|
{
|
|
|
|
// Clear selection, just in case a selected item has to be removed
|
2017-02-21 12:42:08 +00:00
|
|
|
toolManager->RunAction( PCB_ACTIONS::selectionClear, true );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_netlist->SetDeleteExtraFootprints( m_cbDeleteExtraFootprints->GetValue() );
|
|
|
|
m_netlist->SetFindByTimeStamp( m_matchByTimestamp->GetSelection() == 0 );
|
|
|
|
m_netlist->SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
|
2016-01-29 10:31:26 +00:00
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
try
|
|
|
|
{
|
2016-01-29 10:29:56 +00:00
|
|
|
m_frame->LoadFootprints( *m_netlist, &reporter );
|
|
|
|
}
|
|
|
|
catch( IO_ERROR &error )
|
|
|
|
{
|
2018-05-21 22:28:26 +00:00
|
|
|
reporter.ReportTail( _( "Failed to load one or more footprints. Please add the missing libraries in PCBNew configuration. "
|
2016-01-29 10:29:56 +00:00
|
|
|
"The PCB will not update completely." ), REPORTER::RPT_ERROR );
|
2018-05-21 22:28:26 +00:00
|
|
|
reporter.ReportTail( error.What(), REPORTER::RPT_INFO );
|
2016-01-29 10:29:56 +00:00
|
|
|
}
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
BOARD_NETLIST_UPDATER updater( m_frame, m_frame->GetBoard() );
|
|
|
|
updater.SetReporter ( &reporter );
|
2018-02-15 08:49:53 +00:00
|
|
|
updater.SetIsDryRun( aDryRun );
|
2018-02-28 09:44:22 +00:00
|
|
|
updater.SetLookupByTimestamp( m_matchByTimestamp->GetSelection() == 0 );
|
|
|
|
updater.SetDeleteUnusedComponents ( m_cbDeleteExtraFootprints->GetValue() );
|
|
|
|
updater.SetReplaceFootprints( m_cbUpdateFootprints->GetValue() );
|
|
|
|
updater.SetDeleteSinglePadNets( m_cbDeleteSinglePadNets->GetValue() );
|
2016-01-29 10:24:39 +00:00
|
|
|
updater.UpdateNetlist( *m_netlist );
|
|
|
|
|
2018-05-21 22:28:26 +00:00
|
|
|
m_messagePanel->Flush( true );
|
2016-01-29 10:24:39 +00:00
|
|
|
|
|
|
|
if( aDryRun )
|
|
|
|
return;
|
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
m_frame->SetCurItem( nullptr );
|
2016-01-29 10:24:39 +00:00
|
|
|
m_frame->SetMsgPanel( board );
|
|
|
|
|
2018-02-15 08:49:53 +00:00
|
|
|
// Update rendered tracks and vias net labels
|
|
|
|
auto view = m_frame->GetGalCanvas()->GetView();
|
|
|
|
|
|
|
|
// TODO is there a way to extract information about which nets were modified?
|
|
|
|
for( auto track : board->Tracks() )
|
|
|
|
view->Update( track );
|
|
|
|
|
2016-10-25 13:34:59 +00:00
|
|
|
std::vector<MODULE*> newFootprints = updater.GetAddedComponents();
|
|
|
|
|
|
|
|
// Spread new footprints.
|
|
|
|
wxPoint areaPosition = m_frame->GetCrossHairPosition();
|
|
|
|
|
|
|
|
if( !m_frame->IsGalCanvasActive() )
|
2016-03-17 03:05:08 +00:00
|
|
|
{
|
2016-10-25 13:34:59 +00:00
|
|
|
// In legacy mode place area to the left side of the board.
|
|
|
|
// if the board is empty, the bbox position is (0,0)
|
|
|
|
areaPosition.x = bbox.GetEnd().x + Millimeter2iu( 10 );
|
|
|
|
areaPosition.y = bbox.GetOrigin().y;
|
|
|
|
}
|
2016-09-05 13:38:01 +00:00
|
|
|
|
2016-10-25 13:34:59 +00:00
|
|
|
m_frame->SpreadFootprints( &newFootprints, false, false, areaPosition, false );
|
2016-03-17 03:05:08 +00:00
|
|
|
|
2016-10-25 13:34:59 +00:00
|
|
|
if( m_frame->IsGalCanvasActive() )
|
|
|
|
{
|
|
|
|
// Start move and place the new modules command
|
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 )
|
2017-02-21 12:42:08 +00:00
|
|
|
toolManager->RunAction( PCB_ACTIONS::selectItem, true, footprint );
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2016-03-18 03:09:24 +00:00
|
|
|
toolManager->InvokeTool( "pcbnew.InteractiveEdit" );
|
2016-03-17 03:05:08 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-25 13:34:59 +00:00
|
|
|
else // Legacy canvas
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2018-02-28 09:44:22 +00:00
|
|
|
}
|
2016-03-17 03:05:08 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
|
|
|
|
void DIALOG_UPDATE_PCB::OnMatchChanged( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_initialized )
|
|
|
|
PerformUpdate( true );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2018-02-28 09:44:22 +00:00
|
|
|
void DIALOG_UPDATE_PCB::OnOptionChanged( wxCommandEvent& event )
|
2016-01-29 10:24:39 +00:00
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
if( m_initialized )
|
|
|
|
PerformUpdate( true );
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 13:53:51 +00:00
|
|
|
|
2016-01-29 10:24:39 +00:00
|
|
|
void DIALOG_UPDATE_PCB::OnUpdateClick( wxCommandEvent& event )
|
|
|
|
{
|
2018-02-28 09:44:22 +00:00
|
|
|
m_messagePanel->SetLabel( _( "Changes Applied To PCB" ) );
|
2016-01-29 10:24:39 +00:00
|
|
|
PerformUpdate( false );
|
2018-02-28 09:44:22 +00:00
|
|
|
m_sdbSizer1Cancel->SetDefault();
|
2016-01-29 10:24:39 +00:00
|
|
|
}
|