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>
25#include <tracks_cleaner.h>
26#include <drc/drc_item.h>
28#include <reporter.h>
32#include <pcb_group.h>
34
37 m_parentFrame( aParentFrame ),
38 m_brd( aParentFrame->GetBoard() ),
39 m_firstRun( true )
40{
42
43 // Populate the net filter list with net names
44 m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
45
46 // Populate the netclass filter list with netclass names
47 wxArrayString netclassNames;
48 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
49
50 netclassNames.push_back( settings->GetDefaultNetclass()->GetName() );
51
52 for( const auto& [name, netclass] : settings->GetNetclasses() )
53 netclassNames.push_back( name );
54
55 m_netclassFilter->Set( netclassNames );
56
57 // Populate the layer filter list
58 m_layerFilter->SetBoardFrame( m_parentFrame );
59 m_layerFilter->SetLayersHotkeys( false );
60 m_layerFilter->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
61 m_layerFilter->Resync();
62
64 m_changesDataView->AssociateModel( m_changesTreeModel );
65 m_changesDataView->SetLayoutDirection( wxLayout_LeftToRight );
66
68
69 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
71 nullptr, this );
72
73 m_sdbSizer->SetSizeHints( this );
74
76}
77
78
83
84
86{
87 if( m_firstRun )
88 SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
89 else
90 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
91}
92
93
94void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
95{
96 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
97 m_firstRun = true;
99}
100
101
103{
104 OnCheckBox( aEvent );
105}
106
107
109{
110 OnCheckBox( aEvent );
111}
112
113
115{
116 OnCheckBox( aEvent );
117}
118
119
121{
122 if( !m_brd->GetHighLightNetCodes().empty() )
123 m_netFilter->SetSelectedNetcode( *m_brd->GetHighLightNetCodes().begin() );
124
125 m_netclassFilter->SetStringSelection( m_brd->GetDesignSettings().GetCurrentNetClassName() );
126 m_layerFilter->SetLayerSelection( m_parentFrame->GetActiveLayer() );
127 return true;
128}
129
130
132{
133 bool dryRun = m_firstRun;
134
135 doCleanup( dryRun );
136
137 return !dryRun;
138}
139
140
142{
143 m_tcReport->Clear();
144 wxSafeYield(); // Timeslice to update UI
145
146 wxBusyCursor busy;
147 BOARD_COMMIT commit( m_parentFrame );
148 TRACKS_CLEANER cleaner( m_brd, commit );
149
150 cleaner.SetFilter(
151 [&]( BOARD_CONNECTED_ITEM* aItem ) -> bool
152 {
153 if( m_selectedItemsFilter->GetValue() )
154 {
155 if( !aItem->IsSelected() )
156 {
157 EDA_GROUP* group = aItem->GetParentGroup();
158
159 while( group && !group->AsEdaItem()->IsSelected() )
160 group = group->AsEdaItem()->GetParentGroup();
161
162 if( !group )
163 return true;
164 }
165 }
166
167 if( m_netFilterOpt->GetValue() )
168 {
169 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
170 return true;
171 }
172
173 if( m_netclassFilterOpt->GetValue() )
174 {
175 NETCLASS* netclass = aItem->GetEffectiveNetClass();
176
177 if( !netclass->ContainsNetclassWithName( m_netclassFilter->GetStringSelection() ) )
178 return true;
179 }
180
181 if( m_layerFilterOpt->GetValue() )
182 {
183 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
184 return true;
185 }
186
187 return false;
188 } );
189
190 m_outputBook->SetSelection( 1 );
191
192 if( !aDryRun )
193 {
194 // Clear current selection list to avoid selection of deleted items
195 m_parentFrame->GetToolManager()->RunAction( ACTIONS::selectionClear );
196
197 // ... and to keep the treeModel from trying to refresh a deleted item
198 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
199 }
200
201 m_items.clear();
202
203 if( m_firstRun )
204 {
205 if( m_cbRefillZones->GetValue() )
206 {
207 m_reporter->Report( _( "Checking zones..." ) );
208 wxSafeYield(); // Timeslice to update UI
209 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
210 wxSafeYield(); // Timeslice to close zone progress reporter
211 }
212
213 m_firstRun = false;
214 }
215
216 // Old model has to be refreshed, GAL normally does not keep updating it
217 m_reporter->Report( _( "Rebuilding connectivity..." ) );
218 wxSafeYield(); // Timeslice to update UI
219 m_parentFrame->GetBoard()->CompileRatsnest();
220
221 cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
222 m_cleanViasOpt->GetValue(),
223 m_mergeSegmOpt->GetValue(),
224 m_deleteUnconnectedOpt->GetValue(),
225 m_deleteTracksInPadsOpt->GetValue(),
226 m_deleteDanglingViasOpt->GetValue(),
227 m_reporter );
228
229 if( m_cbRefillZones->GetValue() == wxCHK_CHECKED && !aDryRun )
230 {
231 m_reporter->Report( _( "Refilling all zones..." ) );
232 wxSafeYield(); // Timeslice to update UI
233 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->FillAllZones( this );
234 wxSafeYield(); // Timeslice to close zone progress reporter
235 }
236
237 if( aDryRun )
238 {
239 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
241 }
242 else if( !commit.Empty() )
243 {
244 // Clear undo and redo lists to avoid inconsistencies between lists
245 commit.Push( _( "Board Cleanup" ) );
246 m_parentFrame->GetCanvas()->Refresh( true );
247 }
248
249 m_outputBook->SetSelection( 0 );
251}
252
253
254void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
255{
256 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
257
258 if( BOARD_ITEM* item = m_brd->ResolveItem( itemID, true ) )
259 {
261
262 m_parentFrame->FocusOnItem( item );
263 m_parentFrame->GetCanvas()->Refresh();
264 }
265
266 aEvent.Skip();
267}
268
269
271{
272 event.Skip();
273
274 if( m_changesDataView->GetCurrentItem().IsOk() )
275 {
276 if( !IsModal() )
277 Show( false );
278 }
279}
280
281
const char * name
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
virtual 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:81
bool Empty() const
Definition commit.h:134
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:42
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:114
bool IsSelected() const
Definition eda_item.h:132
Definition kiid.h:44
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:38
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition netclass.cpp:310
The main frame for Pcbnew.
static KIID ToUUID(wxDataViewItem aItem)
Definition rc_item.cpp:223
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:165
Handle actions specific to filling copper zones.
#define _(s)
Class to handle a set of BOARD_ITEMs.
@ RPT_SEVERITY_ACTION