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{
46
47 // Populate the net filter list with net names
48 m_netFilter->SetNetInfo( &m_brd->GetNetInfo() );
49
50 // Populate the netclass filter list with netclass names
51 wxArrayString netclassNames;
52 std::shared_ptr<NET_SETTINGS>& settings = m_brd->GetDesignSettings().m_NetSettings;
53
54 netclassNames.push_back( settings->GetDefaultNetclass()->GetName() );
55
56 for( const auto& [name, netclass] : settings->GetNetclasses() )
57 netclassNames.push_back( name );
58
59 m_netclassFilter->Set( netclassNames );
60
61 // Populate the layer filter list
62 m_layerFilter->SetBoardFrame( m_parentFrame );
63 m_layerFilter->SetLayersHotkeys( false );
64 m_layerFilter->SetNotAllowedLayerSet( LSET::AllNonCuMask() );
65 m_layerFilter->Resync();
66
68 m_changesDataView->AssociateModel( m_changesTreeModel );
69 m_changesDataView->SetLayoutDirection( wxLayout_LeftToRight );
70
72
73 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
75 nullptr, this );
76
77 m_sdbSizer->SetSizeHints( this );
78
80}
81
82
87
88
90{
91 if( m_firstRun )
92 SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
93 else
94 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
95}
96
97
98void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
99{
100 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
101 m_firstRun = true;
103}
104
105
107{
108 OnCheckBox( aEvent );
109}
110
111
113{
114 OnCheckBox( aEvent );
115}
116
117
119{
120 OnCheckBox( aEvent );
121}
122
123
125{
126 if( !m_brd->GetHighLightNetCodes().empty() )
127 m_netFilter->SetSelectedNetcode( *m_brd->GetHighLightNetCodes().begin() );
128
129 m_netclassFilter->SetStringSelection( m_brd->GetDesignSettings().GetCurrentNetClassName() );
130 m_layerFilter->SetLayerSelection( m_parentFrame->GetActiveLayer() );
131 return true;
132}
133
134
136{
137 bool dryRun = m_firstRun;
138
139 doCleanup( dryRun );
140
141 return !dryRun;
142}
143
144
146{
147 m_tcReport->Clear();
148 wxSafeYield(); // Timeslice to update UI
149
150 wxBusyCursor busy;
151 BOARD_COMMIT commit( m_parentFrame );
152 TRACKS_CLEANER cleaner( m_brd, commit );
153
154 cleaner.SetFilter(
155 [&]( BOARD_CONNECTED_ITEM* aItem ) -> bool
156 {
157 if( m_selectedItemsFilter->GetValue() )
158 {
159 if( !aItem->IsSelected() )
160 {
161 EDA_GROUP* group = aItem->GetParentGroup();
162
163 while( group && !group->AsEdaItem()->IsSelected() )
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->Compile_Ratsnest( false );
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}
284
285
const char * name
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:224
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:83
bool Empty() const
Definition commit.h:137
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:46
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
bool IsSelected() const
Definition eda_item.h:127
Definition kiid.h:49
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:627
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:45
bool ContainsNetclassWithName(const wxString &netclass) const
Determines if the given netclass name is a constituent of this (maybe aggregate) netclass.
Definition netclass.cpp:284
The main frame for Pcbnew.
static KIID ToUUID(wxDataViewItem aItem)
Definition rc_item.cpp:226
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:167
Handle actions specific to filling copper zones.
#define _(s)
Class to handle a set of BOARD_ITEMs.
BOARD * GetBoard()
@ RPT_SEVERITY_ACTION