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-2022 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 auto cfg = m_parentFrame->GetPcbNewSettings();
63
64 cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue();
65 cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue();
66 cfg->m_Cleanup.cleanup_unconnected = m_deleteUnconnectedOpt->GetValue();
67 cfg->m_Cleanup.cleanup_short_circuits = m_cleanShortCircuitOpt->GetValue();
68 cfg->m_Cleanup.cleanup_tracks_in_pad = m_deleteTracksInPadsOpt->GetValue();
69 cfg->m_Cleanup.delete_dangling_vias = m_deleteDanglingViasOpt->GetValue();
70
71 m_changesTreeModel->DecRef();
72}
73
74
76{
77 if( m_firstRun )
78 SetupStandardButtons( { { wxID_OK, _( "Build Changes" ) } } );
79 else
80 SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) } } );
81}
82
83
84void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
85{
86 m_firstRun = true;
88 m_tcReport->Clear();
89}
90
91
93{
94 return true;
95}
96
97
99{
100 bool dryRun = m_firstRun;
101
102 doCleanup( dryRun );
103
104 return !dryRun;
105}
106
107
109{
110 m_tcReport->Clear();
111 wxSafeYield(); // Timeslice to update UI
112
113 wxBusyCursor busy;
114 BOARD_COMMIT commit( m_parentFrame );
115 TRACKS_CLEANER cleaner( m_parentFrame->GetBoard(), commit );
116
117 if( !aDryRun )
118 {
119 // Clear current selection list to avoid selection of deleted items
121
122 // ... and to keep the treeModel from trying to refresh a deleted item
124 }
125
126 m_items.clear();
127
128 if( m_firstRun )
129 {
130 m_reporter->Report( _( "Checking zones..." ) );
131 wxSafeYield(); // Timeslice to update UI
132 m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
133 wxSafeYield(); // Timeslice to close zone progress reporter
134 m_firstRun = false;
135 }
136
137 // Old model has to be refreshed, GAL normally does not keep updating it
138 m_reporter->Report( _( "Rebuilding connectivity..." ) );
139 wxSafeYield(); // Timeslice to update UI
141
142 cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
143 m_cleanViasOpt->GetValue(),
144 m_mergeSegmOpt->GetValue(),
145 m_deleteUnconnectedOpt->GetValue(),
146 m_deleteTracksInPadsOpt->GetValue(),
147 m_deleteDanglingViasOpt->GetValue(),
148 m_reporter );
149
150 if( aDryRun )
151 {
152 m_changesTreeModel->Update( std::make_shared<VECTOR_CLEANUP_ITEMS_PROVIDER>( &m_items ),
154 }
155 else if( !commit.Empty() )
156 {
157 // Clear undo and redo lists to avoid inconsistencies between lists
158 commit.Push( _( "Board cleanup" ) );
159 m_parentFrame->GetCanvas()->Refresh( true );
160 }
161
162 m_reporter->Report( _( "Done." ) );
164}
165
166
167void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
168{
169 const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
170 BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
172
173 m_parentFrame->FocusOnItem( item );
175
176 aEvent.Skip();
177}
178
179
181{
182 event.Skip();
183
184 if( m_changesDataView->GetCurrentItem().IsOk() )
185 {
186 if( !IsModal() )
187 Show( false );
188 }
189}
190
191
virtual void Push(const wxString &aMessage=wxT("A commit"), 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:1095
bool Empty() const
Returns status of an item.
Definition: commit.h:142
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:351
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:211
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