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 
126  m_changesTreeModel->SetProvider( nullptr );
127  m_items.clear();
128  }
129 
130  // Old model has to be refreshed, GAL normally does not keep updating it
132 
133  cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
134  m_cleanViasOpt->GetValue(),
135  m_mergeSegmOpt->GetValue(),
136  m_deleteUnconnectedOpt->GetValue(),
137  m_deleteTracksInPadsOpt->GetValue(),
138  m_deleteDanglingViasOpt->GetValue() );
139 
140  if( aDryRun )
141  {
143  m_changesTreeModel->SetProvider( provider );
144  }
145  else if( !commit.Empty() )
146  {
147  // Clear undo and redo lists to avoid inconsistencies between lists
148  commit.Push( _( "Board cleanup" ) );
149  m_parentFrame->GetCanvas()->Refresh( true );
150  }
151 }
152 
153 
154 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
155 {
156  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
157  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
158  WINDOW_THAWER thawer( m_parentFrame );
159 
160  m_parentFrame->FocusOnItem( item );
162 
163  aEvent.Skip();
164 }
165 
166 
168 {
169  event.Skip();
170 
171  if( m_changesDataView->GetCurrentItem().IsOk() )
172  {
173  if( !IsModal() )
174  Show( false );
175  }
176 }
177 
178 
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
DIALOG_CLEANUP m_Cleanup
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:234
void Compile_Ratsnest(bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:95
PCBNEW_SETTINGS * GetPcbNewSettings()
BOARD_ITEM * GetItem(const KIID &aID)
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:240
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:42
Definition: common.h:68
ZONE_FILLER_TOOL.
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
Definition: commit.h:139
Class DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE.
void OnSelectItem(wxDataViewEvent &event) override
#define _(s)
Definition: 3d_actions.cpp:33
void OnLeftDClickItem(wxMouseEvent &event) override
PCB_EDIT_FRAME is the main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:78
BOARD * GetBoard() const
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)
void FocusOnItem(BOARD_ITEM *aItem)