KiCad PCB EDA Suite
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-2020 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 
24 #include <wx/wx.h>
26 #include <pcb_edit_frame.h>
27 #include <pcbnew_settings.h>
28 #include <tool/tool_manager.h>
29 #include <tools/pcb_actions.h>
30 #include <tracks_cleaner.h>
31 #include <drc/drc_item.h>
32 #include <tools/zone_filler_tool.h>
33 
36  m_parentFrame( aParentFrame ),
37  m_firstRun( true )
38 {
39  auto cfg = m_parentFrame->GetPcbNewSettings();
40 
41  m_cleanViasOpt->SetValue( cfg->m_Cleanup.cleanup_vias );
42  m_mergeSegmOpt->SetValue( cfg->m_Cleanup.merge_segments );
43  m_deleteUnconnectedOpt->SetValue( cfg->m_Cleanup.cleanup_unconnected );
44  m_cleanShortCircuitOpt->SetValue( cfg->m_Cleanup.cleanup_short_circuits );
45  m_deleteTracksInPadsOpt->SetValue( cfg->m_Cleanup.cleanup_tracks_in_pad );
46  m_deleteDanglingViasOpt->SetValue( cfg->m_Cleanup.delete_dangling_vias );
47 
49  m_changesDataView->AssociateModel( m_changesTreeModel );
50 
52 
53  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
54  // that requires us to correct the button labels here.
55  m_sdbSizerOK->SetLabel( _( "Update PCB" ) );
56 
57  m_sdbSizerOK->SetDefault();
58  m_sdbSizer->SetSizeHints( this );
59 
61 }
62 
63 
65 {
66  auto cfg = m_parentFrame->GetPcbNewSettings();
67 
68  cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue();
69  cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue();
70  cfg->m_Cleanup.cleanup_unconnected = m_deleteUnconnectedOpt->GetValue();
71  cfg->m_Cleanup.cleanup_short_circuits = m_cleanShortCircuitOpt->GetValue();
72  cfg->m_Cleanup.cleanup_tracks_in_pad = m_deleteTracksInPadsOpt->GetValue();
73  cfg->m_Cleanup.delete_dangling_vias = m_deleteDanglingViasOpt->GetValue();
74 
75  m_changesTreeModel->DecRef();
76 }
77 
78 
79 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
80 {
81  doCleanup( true );
82 }
83 
84 
86 {
87  doCleanup( true );
88 
89  return true;
90 }
91 
92 
94 {
95  doCleanup( false );
96 
97  return true;
98 }
99 
100 
102 {
103  wxBusyCursor busy;
104  BOARD_COMMIT commit( m_parentFrame );
105  TRACKS_CLEANER cleaner( m_parentFrame->GetBoard(), commit );
106 
107  if( !aDryRun )
108  {
109  // Clear current selection list to avoid selection of deleted items
111 
112  // ... and to keep the treeModel from trying to refresh a deleted item
113  m_changesTreeModel->SetProvider( nullptr );
114  }
115 
116  m_items.clear();
117 
118  if( m_firstRun )
119  {
120  m_items.push_back( std::make_shared<CLEANUP_ITEM>( CLEANUP_CHECKING_ZONE_FILLS ) );
122  m_changesTreeModel->SetProvider( provider );
123 
124  m_parentFrame->GetToolManager()->GetTool<ZONE_FILLER_TOOL>()->CheckAllZones( this );
125  wxSafeYield(); // Timeslice to close zone progress reporter
126 
127  m_changesTreeModel->SetProvider( nullptr );
128  m_items.clear();
129  m_firstRun = false;
130  }
131 
132  // Old model has to be refreshed, GAL normally does not keep updating it
134 
135  cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
136  m_cleanViasOpt->GetValue(),
137  m_mergeSegmOpt->GetValue(),
138  m_deleteUnconnectedOpt->GetValue(),
139  m_deleteTracksInPadsOpt->GetValue(),
140  m_deleteDanglingViasOpt->GetValue() );
141 
142  if( aDryRun )
143  {
145  m_changesTreeModel->SetProvider( provider );
146  }
147  else if( !commit.Empty() )
148  {
149  // Clear undo and redo lists to avoid inconsistencies between lists
150  commit.Push( _( "Board cleanup" ) );
151  m_parentFrame->GetCanvas()->Refresh( true );
152  }
153 }
154 
155 
156 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
157 {
158  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
159  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
160  WINDOW_THAWER thawer( m_parentFrame );
161 
162  m_parentFrame->FocusOnItem( item );
164 
165  aEvent.Skip();
166 }
167 
168 
170 {
171  event.Skip();
172 
173  if( m_changesDataView->GetCurrentItem().IsOk() )
174  {
175  if( !IsModal() )
176  Show( false );
177  }
178 }
179 
180 
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
BOARD_ITEM * GetItem(const KIID &aID) const
Definition: board.cpp:792
DIALOG_CLEANUP m_Cleanup
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:264
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:41
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:119
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:270
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:43
Definition: kiid.h:44
Handle actions specific to filling copper zones.
std::vector< std::shared_ptr< CLEANUP_ITEM > > m_items
VECTOR_CLEANUP_ITEMS_PROVIDER is an implementation of the interface named RC_ITEMS_PROVIDER which use...
Definition: cleanup_item.h:71
void OnCheckBox(wxCommandEvent &anEvent) override
bool Show(bool show) override
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool Empty() const
Returns status of an item.
Definition: commit.h:140
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE.
void OnSelectItem(wxDataViewEvent &event) override
#define _(s)
Definition: 3d_actions.cpp:33
void OnLeftDClickItem(wxMouseEvent &event) override
The main frame for Pcbnew.
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
BOARD * GetBoard() const
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)
void FocusOnItem(BOARD_ITEM *aItem)