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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <board_commit.h>
26#include <pcb_edit_frame.h>
27#include <tool/tool_manager.h>
28#include <tools/pcb_actions.h>
29#include <tracks_cleaner.h>
30#include <drc/drc_item.h>
32#include <reporter.h>
36#include <pcb_group.h>
38
41 m_parentFrame( aParentFrame ),
42 m_brd( aParentFrame->GetBoard() ),
43 m_firstRun( true )
44{
47
49 m_cleanViasOpt->SetValue( cfg->m_Cleanup.cleanup_vias );
50 m_mergeSegmOpt->SetValue( cfg->m_Cleanup.merge_segments );
55
57
59 m_changesDataView->AssociateModel( m_changesTreeModel );
60
62
63 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
65 nullptr, this );
66
67 m_sdbSizer->SetSizeHints( this );
68
70}
71
72
74{
75 PCBNEW_SETTINGS* cfg = nullptr;
76
77 try
78 {
80 }
81 catch( const std::runtime_error& e )
82 {
83 wxFAIL_MSG( e.what() );
84 }
85
86 if( cfg )
87 {
89 cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue();
90 cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue();
95 }
96
97 m_changesTreeModel->DecRef();
98}
99
100
102{
103 // Populate the net filter list with net names
106
107 if( !m_brd->GetHighLightNetCodes().empty() )
109
110 // Populate the netclass filter list with netclass names
111 wxArrayString netclassNames;
112 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
113
114 netclassNames.push_back( settings->GetDefaultNetclass()->GetName() );
115
116 for( const auto& [name, netclass] : settings->GetNetclasses() )
117 netclassNames.push_back( name );
118
119 m_netclassFilter->Set( netclassNames );
121
122 // Populate the layer filter list
128}
129
130
132{
133 if( m_firstRun )
134 SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
135 else
136 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
137}
138
139
140void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
141{
143 m_firstRun = true;
145}
146
147
149{
150 OnCheckBox( aEvent );
151}
152
153
155{
156 OnCheckBox( aEvent );
157}
158
159
161{
162 OnCheckBox( aEvent );
163}
164
165
167{
168 return true;
169}
170
171
173{
174 bool dryRun = m_firstRun;
175
176 doCleanup( dryRun );
177
178 return !dryRun;
179}
180
181
183{
184 m_tcReport->Clear();
185 wxSafeYield(); // Timeslice to update UI
186
187 wxBusyCursor busy;
188 BOARD_COMMIT commit( m_parentFrame );
189 TRACKS_CLEANER cleaner( m_brd, commit );
190
191 struct FILTER_STATE
192 {
193 bool selectedOnly;
194 int netCodeOnly;
195 wxString netClassOnly;
196 int layerOnly;
197 };
198
199 FILTER_STATE filter_state = {
200 .selectedOnly = m_selectedItemsFilter->GetValue(),
201 .netCodeOnly = m_netFilterOpt->GetValue() ? m_netFilter->GetSelectedNetcode() : -1,
202 .netClassOnly = m_netclassFilterOpt->GetValue()
203 ? m_netclassFilter->GetStringSelection()
204 : wxString(),
205 .layerOnly = m_layerFilterOpt->GetValue()
208 };
209
210 cleaner.SetFilter(
211 [&, filter_state]( BOARD_CONNECTED_ITEM* aItem ) -> bool
212 {
213 if( filter_state.selectedOnly )
214 {
215 if( !aItem->IsSelected() )
216 {
217 PCB_GROUP* group = aItem->GetParentGroup();
218
219 while( group && !group->IsSelected() )
220 group = group->GetParentGroup();
221
222 if( !group )
223 return true;
224 }
225 }
226
227 if( filter_state.netCodeOnly >= 0 )
228 {
229 if( aItem->GetNetCode() != filter_state.netCodeOnly )
230 return true;
231 }
232
233 if( !filter_state.netClassOnly.IsEmpty() )
234 {
235 NETCLASS* netclass = aItem->GetEffectiveNetClass();
236
237 if( !netclass->ContainsNetclassWithName( filter_state.netClassOnly ) )
238 return true;
239 }
240
241 if( filter_state.layerOnly != UNDEFINED_LAYER )
242 {
243 if( aItem->GetLayer() != filter_state.layerOnly )
244 return true;
245 }
246
247 return false;
248 } );
249
250 m_outputBook->SetSelection( 1 );
251
252 if( !aDryRun )
253 {
254 // Clear current selection list to avoid selection of deleted items
255 m_parentFrame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
256
257 // ... and to keep the treeModel from trying to refresh a deleted item
258 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
259 }
260
261 m_items.clear();
262
263 if( m_firstRun )
264 {
265 if( m_cbRefillZones->GetValue() )
266 {
267 m_reporter->Report( _( "Checking zones..." ) );
268 wxSafeYield(); // Timeslice to update UI
269 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
270 wxSafeYield(); // Timeslice to close zone progress reporter
271 }
272
273 m_firstRun = false;
274 }
275
276 // Old model has to be refreshed, GAL normally does not keep updating it
277 m_reporter->Report( _( "Rebuilding connectivity..." ) );
278 wxSafeYield(); // Timeslice to update UI
279 m_parentFrame->Compile_Ratsnest( false );
280
281 cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
282 m_cleanViasOpt->GetValue(),
283 m_mergeSegmOpt->GetValue(),
284 m_deleteUnconnectedOpt->GetValue(),
285 m_deleteTracksInPadsOpt->GetValue(),
286 m_deleteDanglingViasOpt->GetValue(),
287 m_reporter );
288
289 if( m_cbRefillZones->GetValue() == wxCHK_CHECKED && !aDryRun )
290 {
291 m_reporter->Report( _( "Refilling all zones..." ) );
292 wxSafeYield(); // Timeslice to update UI
293 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->FillAllZones( this );
294 wxSafeYield(); // Timeslice to close zone progress reporter
295 }
296
297 if( aDryRun )
298 {
299 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
301 }
302 else if( !commit.Empty() )
303 {
304 // Clear undo and redo lists to avoid inconsistencies between lists
305 commit.Push( _( "Board Cleanup" ) );
306 m_parentFrame->GetCanvas()->Refresh( true );
307 }
308
309 m_outputBook->SetSelection( 0 );
310 setupOKButtonLabel();
311}
312
313
314void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
315{
316 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
317 BOARD_ITEM* item = m_brd->GetItem( itemID );
319
320 m_parentFrame->FocusOnItem( item );
322
323 aEvent.Skip();
324}
325
326
328{
329 event.Skip();
330
331 if( m_changesDataView->GetCurrentItem().IsOk() )
332 {
333 if( !IsModal() )
334 Show( false );
335 }
336}
337
338
const char * name
Definition: DXF_plotter.cpp:59
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
std::shared_ptr< NET_SETTINGS > m_NetSettings
const wxString & GetCurrentNetClassName() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
const NETINFO_LIST & GetNetInfo() const
Definition: board.h:888
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:546
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:1482
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:948
Class DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE.
void OnNetclassFilterSelect(wxCommandEvent &aEvent) override
void OnSelectItem(wxDataViewEvent &event) override
void OnCheckBox(wxCommandEvent &aEvent) override
void OnLeftDClickItem(wxMouseEvent &event) override
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)
void OnNetFilterSelect(wxCommandEvent &aEvent)
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...
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Definition: kiid.h:49
int SetLayerSelection(int layer)
bool SetLayersHotkeys(bool value)
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:575
void SetNetInfo(const NETINFO_LIST *aNetInfoList)
void SetBoard(BOARD *aBoard)
int GetSelectedNetcode()
void SetSelectedNetcode(int aNetcode)
DIALOG_CLEANUP m_Cleanup
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual PCB_LAYER_ID GetActiveLayer() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
The main frame for Pcbnew.
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void SetNotAllowedLayerSet(LSET aMask)
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:364
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:220
void SetFilter(const std::function< bool(BOARD_CONNECTED_ITEM *aItem)> &aFilter)
A wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:145
Handle actions specific to filling copper zones.
#define _(s)
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
Class to handle a set of BOARD_ITEMs.
BOARD * GetBoard()
@ RPT_SEVERITY_ACTION