KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_cleanup_tracks_and_vias.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <board_commit.h>
22#include <pcb_edit_frame.h>
23#include <tool/tool_manager.h>
24#include <tools/pcb_actions.h>
26#include <tracks_cleaner.h>
27#include <drc/drc_item.h>
29#include <reporter.h>
33#include <pcb_group.h>
35
38 m_parentFrame( aParentFrame ),
39 m_brd( aParentFrame->GetBoard() ),
40 m_firstRun( true )
41{
43
44 // Populate the net filter list with net names
45 m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
46
47 // Populate the netclass filter list with netclass names
48 wxArrayString netclassNames;
49 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
50
51 netclassNames.push_back( settings->GetDefaultNetclass()->GetName() );
52
53 for( const auto& [name, netclass] : settings->GetNetclasses() )
54 netclassNames.push_back( name );
55
56 m_netclassFilter->Set( netclassNames );
57
58 // Populate the layer filter list
59 m_layerFilter->SetBoardFrame( m_parentFrame );
60 m_layerFilter->SetLayersHotkeys( false );
61 m_layerFilter->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
62 m_layerFilter->Resync();
63
65 m_changesDataView->AssociateModel( m_changesTreeModel );
66 m_changesDataView->SetLayoutDirection( wxLayout_LeftToRight );
67
69
70 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
72 nullptr, this );
73
74 m_sdbSizer->SetSizeHints( this );
75
77}
78
79
84
85
87{
88 if( m_firstRun )
89 SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
90 else
91 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
92}
93
94
95void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
96{
97 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
98 m_firstRun = true;
100}
101
102
104{
105 OnCheckBox( aEvent );
106}
107
108
110{
111 OnCheckBox( aEvent );
112}
113
114
116{
117 OnCheckBox( aEvent );
118}
119
120
122{
123 if( !m_brd->GetHighLightNetCodes().empty() )
124 m_netFilter->SetSelectedNetcode( *m_brd->GetHighLightNetCodes().begin() );
125
126 m_netclassFilter->SetStringSelection( m_brd->GetDesignSettings().GetCurrentNetClassName() );
127 m_layerFilter->SetLayerSelection( m_parentFrame->GetActiveLayer() );
128 return true;
129}
130
131
133{
134 bool dryRun = m_firstRun;
135
136 doCleanup( dryRun );
137
138 return !dryRun;
139}
140
141
143{
144 m_tcReport->Clear();
145 wxSafeYield(); // Timeslice to update UI
146
147 wxBusyCursor busy;
148 BOARD_COMMIT commit( m_parentFrame );
149 TRACKS_CLEANER cleaner( m_brd, commit );
150
151 // Keep the filter's selection after clearing the live selection before deleting items.
152 const PCB_SELECTION selectionCopy = m_parentFrame->GetToolManager()->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
153
154 cleaner.SetFilter(
155 [&]( BOARD_CONNECTED_ITEM* aItem ) -> bool
156 {
157 if( m_selectedItemsFilter->GetValue() )
158 {
159 if( !selectionCopy.Contains( aItem ) )
160 {
161 EDA_GROUP* group = aItem->GetParentGroup();
162
163 while( group && !selectionCopy.Contains( group->AsEdaItem() ) )
164 group = group->AsEdaItem()->GetParentGroup();
165
166 if( !group )
167 return true;
168 }
169 }
170
171 if( m_netFilterOpt->GetValue() )
172 {
173 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
174 return true;
175 }
176
177 if( m_netclassFilterOpt->GetValue() )
178 {
179 NETCLASS* netclass = aItem->GetEffectiveNetClass();
180
181 if( !netclass->ContainsNetclassWithName( m_netclassFilter->GetStringSelection() ) )
182 return true;
183 }
184
185 if( m_layerFilterOpt->GetValue() )
186 {
187 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
188 return true;
189 }
190
191 return false;
192 } );
193
194 m_outputBook->SetSelection( 1 );
195
196 if( !aDryRun )
197 {
198 // Clear current selection list to avoid selection of deleted items
199 m_parentFrame->GetToolManager()->RunAction( ACTIONS::selectionClear );
200
201 // ... and to keep the treeModel from trying to refresh a deleted item
202 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
203 }
204
205 m_items.clear();
206
207 if( m_firstRun )
208 {
209 if( m_cbRefillZones->GetValue() )
210 {
211 m_reporter->Report( _( "Checking zones..." ) );
212 wxSafeYield(); // Timeslice to update UI
213 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
214 wxSafeYield(); // Timeslice to close zone progress reporter
215 }
216
217 m_firstRun = false;
218 }
219
220 // Old model has to be refreshed, GAL normally does not keep updating it
221 m_reporter->Report( _( "Rebuilding connectivity..." ) );
222 wxSafeYield(); // Timeslice to update UI
223 m_parentFrame->GetBoard()->CompileRatsnest();
224
225 cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
226 m_cleanViasOpt->GetValue(),
227 m_mergeSegmOpt->GetValue(),
228 m_deleteUnconnectedOpt->GetValue(),
229 m_deleteTracksInPadsOpt->GetValue(),
230 m_deleteDanglingViasOpt->GetValue(),
231 m_reporter );
232
233 if( m_cbRefillZones->GetValue() == wxCHK_CHECKED && !aDryRun )
234 {
235 m_reporter->Report( _( "Refilling all zones..." ) );
236 wxSafeYield(); // Timeslice to update UI
237 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->FillAllZones( this );
238 wxSafeYield(); // Timeslice to close zone progress reporter
239 }
240
241 if( aDryRun )
242 {
243 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
245 }
246 else if( !commit.Empty() )
247 {
248 // Clear undo and redo lists to avoid inconsistencies between lists
249 commit.Push( _( "Board Cleanup" ) );
250 m_parentFrame->GetCanvas()->Refresh( true );
251 }
252
253 m_outputBook->SetSelection( 0 );
255}
256
257
258void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
259{
260 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
261
262 if( BOARD_ITEM* item = m_brd->ResolveItem( itemID, true ) )
263 {
265
266 m_parentFrame->FocusOnItem( item );
267 m_parentFrame->GetCanvas()->Refresh();
268 }
269
270 aEvent.Skip();
271}
272
273
275{
276 event.Skip();
277
278 if( m_changesDataView->GetCurrentItem().IsOk() )
279 {
280 if( !IsModal() )
281 Show( false );
282 }
283}
const char * name
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
bool Empty() const
Definition commit.h:145
DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Cleanup Tracks and Vias"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void OnNetclassFilterSelect(wxCommandEvent &aEvent) override
void OnSelectItem(wxDataViewEvent &event) override
std::vector< std::shared_ptr< CLEANUP_ITEM > > m_items
void OnCheckBox(wxCommandEvent &aEvent) override
void OnLeftDClickItem(wxMouseEvent &event) override
void OnLayerFilterSelect(wxCommandEvent &aEvent) override
bool Show(bool show) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
Definition kiid.h:46
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:623
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:43
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition netclass.cpp:324
The main frame for Pcbnew.
The selection tool: currently supports:
static KIID ToUUID(wxDataViewItem aItem)
Definition rc_item.cpp:223
bool Contains(EDA_ITEM *aItem) const
Definition selection.cpp:84
void CleanupBoard(bool aDryRun, std::vector< std::shared_ptr< CLEANUP_ITEM > > *aItemsList, bool aCleanVias, bool aRemoveMisConnected, bool aMergeSegments, bool aDeleteUnconnected, bool aDeleteTracksinPad, bool aDeleteDanglingVias, REPORTER *aReporter=nullptr)
the cleanup function.
void SetFilter(const std::function< bool(BOARD_CONNECTED_ITEM *aItem)> &aFilter)
A wrapper for reporting to a wxTextCtrl object.
Definition reporter.h:218
Handle actions specific to filling copper zones.
#define _(s)
Class to handle a set of BOARD_ITEMs.
@ RPT_SEVERITY_ACTION