Separate Cleanup Via from Cleanup Track

There are cases where you will want to keep vias that only connect to
one layer but still want to cleanup tracks.  As distinct entities, they
are given their own checkboxes and actions

Fixes https://gitlab.com/kicad/code/kicad/issues/5019
This commit is contained in:
Seth Hillbrand 2020-07-30 21:21:25 -07:00
parent 71882a7b0e
commit 51d7fea934
9 changed files with 115 additions and 21 deletions

View File

@ -30,6 +30,7 @@
CLEANUP_ITEM::CLEANUP_ITEM( int aErrorCode )
{
m_errorCode = aErrorCode;
m_errorTitle = GetErrorText( aErrorCode );
}

View File

@ -42,6 +42,7 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS::DIALOG_CLEANUP_TRACKS_AND_VIAS( PCB_EDIT_FRAME*
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 );
m_deleteDanglingViasOpt->SetValue( cfg->m_Cleanup.delete_dangling_vias );
m_changesTreeModel = new RC_TREE_MODEL( m_parentFrame, m_changesDataView );
m_changesDataView->AssociateModel( m_changesTreeModel );
@ -53,8 +54,9 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS::DIALOG_CLEANUP_TRACKS_AND_VIAS( PCB_EDIT_FRAME*
m_sdbSizerOK->SetLabel( _( "Update PCB" ) );
m_sdbSizerOK->SetDefault();
GetSizer()->SetSizeHints(this);
Centre();
m_sdbSizer->SetSizeHints( this );
FinishDialogSettings();
}
@ -67,6 +69,7 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS::~DIALOG_CLEANUP_TRACKS_AND_VIAS()
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();
cfg->m_Cleanup.delete_dangling_vias = m_deleteDanglingViasOpt->GetValue();
for( CLEANUP_ITEM* item : m_items )
delete item;
@ -124,7 +127,8 @@ void DIALOG_CLEANUP_TRACKS_AND_VIAS::doCleanup( bool aDryRun )
m_cleanViasOpt->GetValue(),
m_mergeSegmOpt->GetValue(),
m_deleteUnconnectedOpt->GetValue(),
m_deleteTracksInPadsOpt->GetValue() );
m_deleteTracksInPadsOpt->GetValue(),
m_deleteDanglingViasOpt->GetValue() );
if( aDryRun )
{

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// C++ code generated with wxFormBuilder (version 3.9.0 Jul 27 2020)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -29,17 +29,20 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE( wxWind
bSizerUpper->Add( m_cleanViasOpt, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
m_deleteDanglingViasOpt = new wxCheckBox( this, wxID_ANY, _("Delete vias connected only on one layer"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerUpper->Add( m_deleteDanglingViasOpt, 0, wxALL, 5 );
m_mergeSegmOpt = new wxCheckBox( this, wxID_ANY, _("&Merge co-linear tracks"), wxDefaultPosition, wxDefaultSize, 0 );
m_mergeSegmOpt->SetToolTip( _("merge aligned track segments, and remove null segments") );
bSizerUpper->Add( m_mergeSegmOpt, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
m_deleteUnconnectedOpt = new wxCheckBox( this, wxID_ANY, _("Delete &dangling tracks"), wxDefaultPosition, wxDefaultSize, 0 );
m_deleteUnconnectedOpt = new wxCheckBox( this, wxID_ANY, _("Delete tracks unconnected at one end"), wxDefaultPosition, wxDefaultSize, 0 );
m_deleteUnconnectedOpt->SetToolTip( _("delete tracks having at least one dangling end") );
bSizerUpper->Add( m_deleteUnconnectedOpt, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
m_deleteTracksInPadsOpt = new wxCheckBox( this, wxID_ANY, _("Delete Tracks in Pads"), wxDefaultPosition, wxDefaultSize, 0 );
m_deleteTracksInPadsOpt = new wxCheckBox( this, wxID_ANY, _("Delete tracks fully inside pads"), wxDefaultPosition, wxDefaultSize, 0 );
m_deleteTracksInPadsOpt->SetToolTip( _("Delete tracks that have both start and end positions inside of a pad") );
bSizerUpper->Add( m_deleteTracksInPadsOpt, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 );
@ -80,6 +83,7 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE( wxWind
// Connect Events
m_cleanShortCircuitOpt->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_cleanViasOpt->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_deleteDanglingViasOpt->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_mergeSegmOpt->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_deleteUnconnectedOpt->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_deleteTracksInPadsOpt->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
@ -92,6 +96,7 @@ DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::~DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE()
// Disconnect Events
m_cleanShortCircuitOpt->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_cleanViasOpt->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_deleteDanglingViasOpt->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_mergeSegmOpt->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_deleteUnconnectedOpt->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );
m_deleteTracksInPadsOpt->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE::OnCheckBox ), NULL, this );

View File

@ -197,6 +197,71 @@
<event name="OnCheckBox">OnCheckBox</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxCheckBox" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="checked">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="default_pane">0</property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Delete vias connected only on one layer</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_deleteDanglingViasOpt</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnCheckBox">OnCheckBox</event>
</object>
</object>
<object class="sizeritem" expanded="0">
<property name="border">5</property>
<property name="flag">wxBOTTOM|wxLEFT|wxRIGHT</property>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Oct 26 2018)
// C++ code generated with wxFormBuilder (version 3.9.0 Jul 27 2020)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -36,6 +36,7 @@ class DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE : public DIALOG_SHIM
protected:
wxCheckBox* m_cleanShortCircuitOpt;
wxCheckBox* m_cleanViasOpt;
wxCheckBox* m_deleteDanglingViasOpt;
wxCheckBox* m_mergeSegmOpt;
wxCheckBox* m_deleteUnconnectedOpt;
wxCheckBox* m_deleteTracksInPadsOpt;

View File

@ -174,6 +174,9 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS()
m_params.emplace_back( new PARAM<bool>( "cleanup.cleanup_vias",
&m_Cleanup.cleanup_vias, true ) );
m_params.emplace_back( new PARAM<bool>( "cleanup.delete_dangling_vias",
&m_Cleanup.delete_dangling_vias, true ) );
m_params.emplace_back( new PARAM<bool>( "cleanup.merge_segments",
&m_Cleanup.merge_segments, true ) );

View File

@ -74,6 +74,7 @@ public:
struct DIALOG_CLEANUP
{
bool cleanup_vias;
bool delete_dangling_vias;
bool cleanup_tracks_in_pad;
bool cleanup_unconnected;
bool cleanup_short_circuits;

View File

@ -52,8 +52,10 @@ TRACKS_CLEANER::TRACKS_CLEANER( BOARD* aPcb, BOARD_COMMIT& aCommit ) :
*/
void TRACKS_CLEANER::CleanupBoard( bool aDryRun, std::vector<CLEANUP_ITEM*>* aItemsList,
bool aRemoveMisConnected, bool aCleanVias, bool aMergeSegments,
bool aDeleteUnconnected, bool aDeleteTracksinPad )
bool aDeleteUnconnected, bool aDeleteTracksinPad, bool aDeleteDanglingVias )
{
bool has_deleted = false;
m_dryRun = aDryRun;
m_itemsList = aItemsList;
@ -80,15 +82,14 @@ void TRACKS_CLEANER::CleanupBoard( bool aDryRun, std::vector<CLEANUP_ITEM*>* aIt
// Delete dangling tracks
if( aDeleteUnconnected )
{
if( deleteDanglingTracks() )
{
// Removed tracks can leave aligned segments
// (when a T was formed by tracks and the "vertical" segment is removed)
if( aMergeSegments )
cleanupSegments();
}
}
has_deleted = deleteDanglingTracks( false );
// Delete dangling vias
if( aDeleteDanglingVias )
has_deleted |= deleteDanglingTracks( true );
if( has_deleted && aMergeSegments )
cleanupSegments();
// Clear the flag used to mark some segments:
for( TRACK* segment : m_brd->Tracks() )
@ -234,7 +235,7 @@ bool TRACKS_CLEANER::testTrackEndpointIsNode( TRACK* aTrack, bool aTstStart )
}
bool TRACKS_CLEANER::deleteDanglingTracks()
bool TRACKS_CLEANER::deleteDanglingTracks( bool aVia )
{
bool item_erased = false;
bool modified = false;
@ -253,13 +254,20 @@ bool TRACKS_CLEANER::deleteDanglingTracks()
bool flag_erase = false; // Start without a good reason to erase it
wxPoint pos;
if( aVia && track->Type() != PCB_VIA_T )
continue;
else if( !aVia && track->Type() == PCB_VIA_T )
continue;
// Tst if a track (or a via) endpoint is not connected to another track or to a zone.
if( m_brd->GetConnectivity()->TestTrackEndpointDangling( track, &pos ) )
flag_erase = true;
if( flag_erase )
{
int errorCode = track->IsTrack() ? CLEANUP_DANGLING_TRACK : CLEANUP_DANGLING_VIA;
int errorCode =
( track->Type() != PCB_VIA_T ) ?
CLEANUP_DANGLING_TRACK : CLEANUP_DANGLING_VIA;
CLEANUP_ITEM* item = new CLEANUP_ITEM( errorCode );
item->SetItems( track );
m_itemsList->push_back( item );

View File

@ -45,10 +45,11 @@ public:
* @param aMergeSegments = true to merge collinear segmenst and remove 0 len segm
* @param aDeleteUnconnected = true to remove dangling tracks
* @param aDeleteTracksinPad = true to remove tracks fully inside pads
* @param aDeleteDanglingVias = true to remove a via that is only connected to a single layer
*/
void CleanupBoard( bool aDryRun, std::vector<CLEANUP_ITEM*>* aItemsList, bool aCleanVias,
bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected,
bool aDeleteTracksinPad );
bool aDeleteTracksinPad, bool aDeleteDanglingVias );
private:
/*
@ -61,7 +62,12 @@ private:
*/
void cleanupVias();
bool deleteDanglingTracks();
/**
* Removes tracks or vias only connected on one end
* @param aVia if true, clean vias, if false clean tracks
* @return true if any items were deleted
*/
bool deleteDanglingTracks( bool aVia );
void deleteTracksInPads();