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 (C) 1992-2023 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( NET_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 cleaner.SetFilter(
192 [&]( BOARD_CONNECTED_ITEM* aItem ) -> bool
193 {
194 if( m_selectedItemsFilter->GetValue() )
195 {
196 if( !aItem->IsSelected() )
197 {
198 PCB_GROUP* group = aItem->GetParentGroup();
199
200 while( group && !group->IsSelected() )
201 group = group->GetParentGroup();
202
203 if( !group )
204 return true;
205 }
206 }
207
208 if( m_netFilterOpt->GetValue() && m_netFilter->GetSelectedNetcode() >= 0 )
209 {
210 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
211 return true;
212 }
213
214 if( m_netclassFilterOpt->GetValue()
215 && !m_netclassFilter->GetStringSelection().IsEmpty() )
216 {
217 wxString filterNetclass = m_netclassFilter->GetStringSelection();
218 NETCLASS* netclass = aItem->GetEffectiveNetClass();
219
220 if( !netclass->ContainsNetclassWithName( filterNetclass ) )
221 return true;
222 }
223
224 if( m_layerFilterOpt->GetValue()
226 {
227 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
228 return true;
229 }
230
231 return false;
232 } );
233
234 m_outputBook->SetSelection( 1 );
235
236 if( !aDryRun )
237 {
238 // Clear current selection list to avoid selection of deleted items
239 m_parentFrame->GetToolManager()->RunAction( PCB_ACTIONS::selectionClear );
240
241 // ... and to keep the treeModel from trying to refresh a deleted item
242 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
243 }
244
245 m_items.clear();
246
247 if( m_firstRun )
248 {
249 if( m_cbRefillZones->GetValue() )
250 {
251 m_reporter->Report( _( "Checking zones..." ) );
252 wxSafeYield(); // Timeslice to update UI
253 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
254 wxSafeYield(); // Timeslice to close zone progress reporter
255 }
256
257 m_firstRun = false;
258 }
259
260 // Old model has to be refreshed, GAL normally does not keep updating it
261 m_reporter->Report( _( "Rebuilding connectivity..." ) );
262 wxSafeYield(); // Timeslice to update UI
263 m_parentFrame->Compile_Ratsnest( false );
264
265 cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
266 m_cleanViasOpt->GetValue(),
267 m_mergeSegmOpt->GetValue(),
268 m_deleteUnconnectedOpt->GetValue(),
269 m_deleteTracksInPadsOpt->GetValue(),
270 m_deleteDanglingViasOpt->GetValue(),
271 m_reporter );
272
273 if( m_cbRefillZones->GetValue() == wxCHK_CHECKED && !aDryRun )
274 {
275 m_reporter->Report( _( "Refilling all zones..." ) );
276 wxSafeYield(); // Timeslice to update UI
277 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->FillAllZones( this );
278 wxSafeYield(); // Timeslice to close zone progress reporter
279 }
280
281 if( aDryRun )
282 {
283 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
285 }
286 else if( !commit.Empty() )
287 {
288 // Clear undo and redo lists to avoid inconsistencies between lists
289 commit.Push( _( "Board Cleanup" ) );
290 m_parentFrame->GetCanvas()->Refresh( true );
291 }
292
293 m_outputBook->SetSelection( 0 );
294 setupOKButtonLabel();
295}
296
297
298void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
299{
300 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
301 BOARD_ITEM* item = m_brd->GetItem( itemID );
303
304 m_parentFrame->FocusOnItem( item );
306
307 aEvent.Skip();
308}
309
310
312{
313 event.Skip();
314
315 if( m_changesDataView->GetCurrentItem().IsOk() )
316 {
317 if( !IsModal() )
318 Show( false );
319 }
320}
321
322
const char * name
Definition: DXF_plotter.cpp:57
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:871
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:532
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:1406
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:890
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:687
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