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>
33
36 m_parentFrame( aParentFrame ),
37 m_firstRun( true )
38{
39 auto cfg = m_parentFrame->GetPcbNewSettings();
41
42 m_cleanViasOpt->SetValue( cfg->m_Cleanup.cleanup_vias );
43 m_mergeSegmOpt->SetValue( cfg->m_Cleanup.merge_segments );
44 m_deleteUnconnectedOpt->SetValue( cfg->m_Cleanup.cleanup_unconnected );
45 m_cleanShortCircuitOpt->SetValue( cfg->m_Cleanup.cleanup_short_circuits );
46 m_deleteTracksInPadsOpt->SetValue( cfg->m_Cleanup.cleanup_tracks_in_pad );
47 m_deleteDanglingViasOpt->SetValue( cfg->m_Cleanup.delete_dangling_vias );
48
50 m_changesDataView->AssociateModel( m_changesTreeModel );
51
53
54 m_sdbSizer->SetSizeHints( this );
55
57}
58
59
61{
62 PCBNEW_SETTINGS* cfg = nullptr;
63
64 try
65 {
67 }
68 catch( const std::runtime_error& e )
69 {
70 wxFAIL_MSG( e.what() );
71 }
72
73 if( cfg )
74 {
75 cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue();
76 cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue();
81 }
82
83 m_changesTreeModel->DecRef();
84}
85
86
88{
89 if( m_firstRun )
90 SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
91 else
92 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
93}
94
95
96void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
97{
98 m_firstRun = true;
100 m_tcReport->Clear();
101}
102
103
105{
106 return true;
107}
108
109
111{
112 bool dryRun = m_firstRun;
113
114 doCleanup( dryRun );
115
116 return !dryRun;
117}
118
119
121{
122 m_tcReport->Clear();
123 wxSafeYield(); // Timeslice to update UI
124
125 wxBusyCursor busy;
126 BOARD_COMMIT commit( m_parentFrame );
127 TRACKS_CLEANER cleaner( m_parentFrame->GetBoard(), commit );
128
129 if( !aDryRun )
130 {
131 // Clear current selection list to avoid selection of deleted items
133
134 // ... and to keep the treeModel from trying to refresh a deleted item
136 }
137
138 m_items.clear();
139
140 if( m_firstRun )
141 {
142 m_reporter->Report( _( "Checking zones..." ) );
143 wxSafeYield(); // Timeslice to update UI
144 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
145 wxSafeYield(); // Timeslice to close zone progress reporter
146 m_firstRun = false;
147 }
148
149 // Old model has to be refreshed, GAL normally does not keep updating it
150 m_reporter->Report( _( "Rebuilding connectivity..." ) );
151 wxSafeYield(); // Timeslice to update UI
153
154 cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
155 m_cleanViasOpt->GetValue(),
156 m_mergeSegmOpt->GetValue(),
157 m_deleteUnconnectedOpt->GetValue(),
158 m_deleteTracksInPadsOpt->GetValue(),
159 m_deleteDanglingViasOpt->GetValue(),
160 m_reporter );
161
162 if( aDryRun )
163 {
164 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
166 }
167 else if( !commit.Empty() )
168 {
169 // Clear undo and redo lists to avoid inconsistencies between lists
170 commit.Push( _( "Board Cleanup" ) );
171 m_parentFrame->GetCanvas()->Refresh( true );
172 }
173
174 m_reporter->Report( _( "Done." ) );
176}
177
178
179void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
180{
181 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
182 BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
184
185 m_parentFrame->FocusOnItem( item );
187
188 aEvent.Skip();
189}
190
191
193{
194 event.Skip();
195
196 if( m_changesDataView->GetCurrentItem().IsOk() )
197 {
198 if( !IsModal() )
199 Show( false );
200 }
201}
202
203
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:1166
bool Empty() const
Returns status of an item.
Definition: commit.h:144
Class DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE.
void OnSelectItem(wxDataViewEvent &event) override
std::vector< std::shared_ptr< CLEANUP_ITEM > > m_items
void OnLeftDClickItem(wxMouseEvent &event) override
void OnCheckBox(wxCommandEvent &anEvent) override
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)
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
DIALOG_CLEANUP m_Cleanup
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:35
void FocusOnItem(BOARD_ITEM *aItem, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
The main frame for Pcbnew.
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
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:145
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.
A wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:138
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:45
Handle actions specific to filling copper zones.
#define _(s)
@ RPT_SEVERITY_ACTION