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
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
66
68 m_changesDataView->AssociateModel( m_changesTreeModel );
69
71
72 m_netFilter->Connect( FILTERED_ITEM_SELECTED,
74 nullptr, this );
75
76 m_sdbSizer->SetSizeHints( this );
77
79}
80
81
83{
84 m_changesTreeModel->DecRef();
85}
86
87
89{
90 if( m_firstRun )
91 SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
92 else
93 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
94}
95
96
97void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
98{
100 m_firstRun = true;
102}
103
104
106{
107 OnCheckBox( aEvent );
108}
109
110
112{
113 OnCheckBox( aEvent );
114}
115
116
118{
119 OnCheckBox( aEvent );
120}
121
122
124{
125 if( !m_brd->GetHighLightNetCodes().empty() )
127
130 return true;
131}
132
133
135{
136 bool dryRun = m_firstRun;
137
138 doCleanup( dryRun );
139
140 return !dryRun;
141}
142
143
145{
146 m_tcReport->Clear();
147 wxSafeYield(); // Timeslice to update UI
148
149 wxBusyCursor busy;
150 BOARD_COMMIT commit( m_parentFrame );
151 TRACKS_CLEANER cleaner( m_brd, commit );
152
153 cleaner.SetFilter(
154 [&]( BOARD_CONNECTED_ITEM* aItem ) -> bool
155 {
156 if( m_selectedItemsFilter->GetValue() )
157 {
158 if( !aItem->IsSelected() )
159 {
160 EDA_GROUP* group = aItem->GetParentGroup();
161
162 while( group && !group->AsEdaItem()->IsSelected() )
163 group = group->AsEdaItem()->GetParentGroup();
164
165 if( !group )
166 return true;
167 }
168 }
169
170 if( m_netFilterOpt->GetValue() )
171 {
172 if( aItem->GetNetCode() != m_netFilter->GetSelectedNetcode() )
173 return true;
174 }
175
176 if( m_netclassFilterOpt->GetValue() )
177 {
178 NETCLASS* netclass = aItem->GetEffectiveNetClass();
179
180 if( !netclass->ContainsNetclassWithName( m_netclassFilter->GetStringSelection() ) )
181 return true;
182 }
183
184 if( m_layerFilterOpt->GetValue() )
185 {
186 if( aItem->GetLayer() != m_layerFilter->GetLayerSelection() )
187 return true;
188 }
189
190 return false;
191 } );
192
193 m_outputBook->SetSelection( 1 );
194
195 if( !aDryRun )
196 {
197 // Clear current selection list to avoid selection of deleted items
198 m_parentFrame->GetToolManager()->RunAction( ACTIONS::selectionClear );
199
200 // ... and to keep the treeModel from trying to refresh a deleted item
201 m_changesTreeModel->Update( nullptr, RPT_SEVERITY_ACTION );
202 }
203
204 m_items.clear();
205
206 if( m_firstRun )
207 {
208 if( m_cbRefillZones->GetValue() )
209 {
210 m_reporter->Report( _( "Checking zones..." ) );
211 wxSafeYield(); // Timeslice to update UI
212 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
213 wxSafeYield(); // Timeslice to close zone progress reporter
214 }
215
216 m_firstRun = false;
217 }
218
219 // Old model has to be refreshed, GAL normally does not keep updating it
220 m_reporter->Report( _( "Rebuilding connectivity..." ) );
221 wxSafeYield(); // Timeslice to update UI
222 m_parentFrame->Compile_Ratsnest( false );
223
224 cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
225 m_cleanViasOpt->GetValue(),
226 m_mergeSegmOpt->GetValue(),
227 m_deleteUnconnectedOpt->GetValue(),
228 m_deleteTracksInPadsOpt->GetValue(),
229 m_deleteDanglingViasOpt->GetValue(),
230 m_reporter );
231
232 if( m_cbRefillZones->GetValue() == wxCHK_CHECKED && !aDryRun )
233 {
234 m_reporter->Report( _( "Refilling all zones..." ) );
235 wxSafeYield(); // Timeslice to update UI
236 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->FillAllZones( this );
237 wxSafeYield(); // Timeslice to close zone progress reporter
238 }
239
240 if( aDryRun )
241 {
242 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
244 }
245 else if( !commit.Empty() )
246 {
247 // Clear undo and redo lists to avoid inconsistencies between lists
248 commit.Push( _( "Board Cleanup" ) );
249 m_parentFrame->GetCanvas()->Refresh( true );
250 }
251
252 m_outputBook->SetSelection( 0 );
253 setupOKButtonLabel();
254}
255
256
257void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
258{
259 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
260
261 if( BOARD_ITEM* item = m_brd->ResolveItem( itemID, true ) )
262 {
264
265 m_parentFrame->FocusOnItem( item );
267 }
268
269 aEvent.Skip();
270}
271
272
274{
275 event.Skip();
276
277 if( m_changesDataView->GetCurrentItem().IsOk() )
278 {
279 if( !IsModal() )
280 Show( false );
281 }
282}
283
284
const char * name
Definition: DXF_plotter.cpp:62
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:221
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:934
const std::set< int > & GetHighLightNetCodes() const
Definition: board.h:579
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:1024
BOARD_ITEM * ResolveItem(const KIID &aID, bool aAllowNullptrReturn=false) const
Definition: board.cpp:1583
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:610
void SetNetInfo(const NETINFO_LIST *aNetInfoList)
void SetSelectedNetcode(int aNetcode)
void FocusOnItem(EDA_ITEM *aItem) override
Focus on a particular canvas item.
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.
The main frame for Pcbnew.
void SetBoardFrame(PCB_BASE_FRAME *aFrame)
void SetNotAllowedLayerSet(const LSET &aMask)
void Update(std::shared_ptr< RC_ITEMS_PROVIDER > aProvider, int aSeverities)
Definition: rc_item.cpp:361
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:217
void SetFilter(const std::function< bool(BOARD_CONNECTED_ITEM *aItem)> &aFilter)
A wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:164
Handle actions specific to filling copper zones.
#define _(s)
Class to handle a set of BOARD_ITEMs.
BOARD * GetBoard()
@ RPT_SEVERITY_ACTION