2019-03-31 09:37:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-03-14 17:12:20 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-03-31 09:37:57 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
#include <dialog_cleanup_tracks_and_vias.h>
|
2021-06-03 17:03:25 +00:00
|
|
|
#include <board_commit.h>
|
2019-03-31 09:37:57 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
|
|
|
#include <tool/tool_manager.h>
|
2019-06-01 16:49:33 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tracks_cleaner.h>
|
2020-03-16 11:05:01 +00:00
|
|
|
#include <drc/drc_item.h>
|
2020-08-21 19:31:43 +00:00
|
|
|
#include <tools/zone_filler_tool.h>
|
2022-03-14 17:12:20 +00:00
|
|
|
#include <reporter.h>
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
DIALOG_CLEANUP_TRACKS_AND_VIAS::DIALOG_CLEANUP_TRACKS_AND_VIAS( PCB_EDIT_FRAME* aParentFrame ) :
|
2019-03-31 09:37:57 +00:00
|
|
|
DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE( aParentFrame ),
|
2020-08-21 19:31:43 +00:00
|
|
|
m_parentFrame( aParentFrame ),
|
|
|
|
m_firstRun( true )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parentFrame->GetPcbNewSettings();
|
2022-03-14 17:12:20 +00:00
|
|
|
m_reporter = new WX_TEXT_CTRL_REPORTER( m_tcReport );
|
2019-06-01 16:49:33 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_cleanViasOpt->SetValue( cfg->m_Cleanup.cleanup_vias );
|
|
|
|
m_mergeSegmOpt->SetValue( cfg->m_Cleanup.merge_segments );
|
|
|
|
m_deleteUnconnectedOpt->SetValue( cfg->m_Cleanup.cleanup_unconnected );
|
|
|
|
m_cleanShortCircuitOpt->SetValue( cfg->m_Cleanup.cleanup_short_circuits );
|
|
|
|
m_deleteTracksInPadsOpt->SetValue( cfg->m_Cleanup.cleanup_tracks_in_pad );
|
2020-07-31 04:21:25 +00:00
|
|
|
m_deleteDanglingViasOpt->SetValue( cfg->m_Cleanup.delete_dangling_vias );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
m_changesTreeModel = new RC_TREE_MODEL( m_parentFrame, m_changesDataView );
|
2020-02-24 23:17:30 +00:00
|
|
|
m_changesDataView->AssociateModel( m_changesTreeModel );
|
|
|
|
|
2022-03-14 17:12:20 +00:00
|
|
|
setupOKButtonLabel();
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-07-31 04:21:25 +00:00
|
|
|
m_sdbSizer->SetSizeHints( this );
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_CLEANUP_TRACKS_AND_VIAS::~DIALOG_CLEANUP_TRACKS_AND_VIAS()
|
|
|
|
{
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parentFrame->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue();
|
|
|
|
cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue();
|
|
|
|
cfg->m_Cleanup.cleanup_unconnected = m_deleteUnconnectedOpt->GetValue();
|
|
|
|
cfg->m_Cleanup.cleanup_short_circuits = m_cleanShortCircuitOpt->GetValue();
|
|
|
|
cfg->m_Cleanup.cleanup_tracks_in_pad = m_deleteTracksInPadsOpt->GetValue();
|
2020-07-31 04:21:25 +00:00
|
|
|
cfg->m_Cleanup.delete_dangling_vias = m_deleteDanglingViasOpt->GetValue();
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-02-24 23:17:30 +00:00
|
|
|
m_changesTreeModel->DecRef();
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-14 17:12:20 +00:00
|
|
|
void DIALOG_CLEANUP_TRACKS_AND_VIAS::setupOKButtonLabel()
|
|
|
|
{
|
|
|
|
if( m_firstRun )
|
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
|
|
|
|
else
|
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
|
|
|
|
{
|
2022-03-14 17:12:20 +00:00
|
|
|
m_firstRun = true;
|
|
|
|
setupOKButtonLabel();
|
|
|
|
m_tcReport->Clear();
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_CLEANUP_TRACKS_AND_VIAS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_CLEANUP_TRACKS_AND_VIAS::TransferDataFromWindow()
|
|
|
|
{
|
2022-03-14 17:12:20 +00:00
|
|
|
bool dryRun = m_firstRun;
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2022-03-14 17:12:20 +00:00
|
|
|
doCleanup( dryRun );
|
|
|
|
|
|
|
|
return !dryRun;
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CLEANUP_TRACKS_AND_VIAS::doCleanup( bool aDryRun )
|
|
|
|
{
|
2022-03-14 17:12:20 +00:00
|
|
|
m_tcReport->Clear();
|
|
|
|
wxSafeYield(); // Timeslice to update UI
|
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
wxBusyCursor busy;
|
|
|
|
BOARD_COMMIT commit( m_parentFrame );
|
2020-06-17 12:46:50 +00:00
|
|
|
TRACKS_CLEANER cleaner( m_parentFrame->GetBoard(), commit );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
|
|
|
if( !aDryRun )
|
|
|
|
{
|
|
|
|
// Clear current selection list to avoid selection of deleted items
|
|
|
|
m_parentFrame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear, true );
|
2020-04-24 13:36:10 +00:00
|
|
|
|
|
|
|
// ... and to keep the treeModel from trying to refresh a deleted item
|
2022-08-30 11:03:40 +00:00
|
|
|
m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
m_items.clear();
|
|
|
|
|
2020-08-21 19:31:43 +00:00
|
|
|
if( m_firstRun )
|
|
|
|
{
|
2022-04-23 20:04:43 +00:00
|
|
|
m_reporter->Report( _( "Checking zones..." ) );
|
2022-03-18 11:04:17 +00:00
|
|
|
wxSafeYield(); // Timeslice to update UI
|
2020-08-21 19:31:43 +00:00
|
|
|
m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
|
2022-03-14 17:12:20 +00:00
|
|
|
wxSafeYield(); // Timeslice to close zone progress reporter
|
2020-10-26 12:58:22 +00:00
|
|
|
m_firstRun = false;
|
2020-08-21 19:31:43 +00:00
|
|
|
}
|
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
// Old model has to be refreshed, GAL normally does not keep updating it
|
2022-04-23 20:04:43 +00:00
|
|
|
m_reporter->Report( _( "Rebuilding connectivity..." ) );
|
2022-03-18 11:04:17 +00:00
|
|
|
wxSafeYield(); // Timeslice to update UI
|
2019-05-30 15:11:17 +00:00
|
|
|
m_parentFrame->Compile_Ratsnest( false );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2021-06-01 15:13:43 +00:00
|
|
|
cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
|
|
|
|
m_cleanViasOpt->GetValue(),
|
|
|
|
m_mergeSegmOpt->GetValue(),
|
|
|
|
m_deleteUnconnectedOpt->GetValue(),
|
|
|
|
m_deleteTracksInPadsOpt->GetValue(),
|
2022-03-14 17:12:20 +00:00
|
|
|
m_deleteDanglingViasOpt->GetValue(),
|
|
|
|
m_reporter );
|
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
if( aDryRun )
|
|
|
|
{
|
2022-08-30 11:03:40 +00:00
|
|
|
m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
|
|
|
|
RPT_SEVERITY_ACTION );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2020-06-17 12:46:50 +00:00
|
|
|
else if( !commit.Empty() )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
|
|
|
// Clear undo and redo lists to avoid inconsistencies between lists
|
|
|
|
commit.Push( _( "Board cleanup" ) );
|
2019-06-13 17:28:55 +00:00
|
|
|
m_parentFrame->GetCanvas()->Refresh( true );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2022-03-14 17:12:20 +00:00
|
|
|
|
2022-04-23 20:04:43 +00:00
|
|
|
m_reporter->Report( _( "Done." ) );
|
2022-03-14 17:12:20 +00:00
|
|
|
setupOKButtonLabel();
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
|
|
|
|
BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
|
2020-02-24 23:17:30 +00:00
|
|
|
WINDOW_THAWER thawer( m_parentFrame );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-02-24 23:17:30 +00:00
|
|
|
m_parentFrame->FocusOnItem( item );
|
|
|
|
m_parentFrame->GetCanvas()->Refresh();
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
aEvent.Skip();
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnLeftDClickItem( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
|
2020-02-24 23:17:30 +00:00
|
|
|
if( m_changesDataView->GetCurrentItem().IsOk() )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2020-02-24 23:17:30 +00:00
|
|
|
if( !IsModal() )
|
|
|
|
Show( false );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|