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 <drc/drc_provider.h>
33 
36  m_parentFrame( aParentFrame )
37 {
38  auto cfg = m_parentFrame->GetPcbNewSettings();
39 
40  m_cleanViasOpt->SetValue( cfg->m_Cleanup.cleanup_vias );
41  m_mergeSegmOpt->SetValue( cfg->m_Cleanup.merge_segments );
42  m_deleteUnconnectedOpt->SetValue( cfg->m_Cleanup.cleanup_unconnected );
43  m_cleanShortCircuitOpt->SetValue( cfg->m_Cleanup.cleanup_short_circuits );
44  m_deleteTracksInPadsOpt->SetValue( cfg->m_Cleanup.cleanup_tracks_in_pad );
45 
47  m_changesDataView->AssociateModel( m_changesTreeModel );
48 
50 
51  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
52  // that requires us to correct the button labels here.
53  m_sdbSizerOK->SetLabel( _( "Update PCB" ) );
54 
55  m_sdbSizerOK->SetDefault();
56  GetSizer()->SetSizeHints(this);
57  Centre();
58 }
59 
60 
62 {
63  auto cfg = m_parentFrame->GetPcbNewSettings();
64 
65  cfg->m_Cleanup.cleanup_vias = m_cleanViasOpt->GetValue();
66  cfg->m_Cleanup.merge_segments = m_mergeSegmOpt->GetValue();
67  cfg->m_Cleanup.cleanup_unconnected = m_deleteUnconnectedOpt->GetValue();
68  cfg->m_Cleanup.cleanup_short_circuits = m_cleanShortCircuitOpt->GetValue();
69  cfg->m_Cleanup.cleanup_tracks_in_pad = m_deleteTracksInPadsOpt->GetValue();
70 
71  for( CLEANUP_ITEM* item : m_items )
72  delete item;
73 
74  m_changesTreeModel->DecRef();
75 }
76 
77 
78 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
79 {
80  doCleanup( true );
81 }
82 
83 
85 {
86  doCleanup( true );
87 
88  return true;
89 }
90 
91 
93 {
94  doCleanup( false );
95 
96  return true;
97 }
98 
99 
101 {
102  wxBusyCursor busy;
103  BOARD_COMMIT commit( m_parentFrame );
104  TRACKS_CLEANER cleaner( m_parentFrame->GetBoard(), commit );
105 
106  if( !aDryRun )
107  {
108  // Clear current selection list to avoid selection of deleted items
110 
111  // ... and to keep the treeModel from trying to refresh a deleted item
112  m_changesTreeModel->SetProvider( nullptr );
113  }
114 
115  for( CLEANUP_ITEM* item : m_items )
116  delete item;
117 
118  m_items.clear();
119 
120  // Old model has to be refreshed, GAL normally does not keep updating it
122 
123  cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
124  m_cleanViasOpt->GetValue(),
125  m_mergeSegmOpt->GetValue(),
126  m_deleteUnconnectedOpt->GetValue(),
127  m_deleteTracksInPadsOpt->GetValue() );
128 
129  if( aDryRun )
130  {
132  m_changesTreeModel->SetProvider( provider );
133  }
134  else if( !commit.Empty() )
135  {
136  // Clear undo and redo lists to avoid inconsistencies between lists
137  commit.Push( _( "Board cleanup" ) );
138  m_parentFrame->GetCanvas()->Refresh( true );
139  }
140 }
141 
142 
143 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
144 {
145  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
146  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
147  WINDOW_THAWER thawer( m_parentFrame );
148 
149  m_parentFrame->FocusOnItem( item );
151 
152  aEvent.Skip();
153 }
154 
155 
157 {
158  event.Skip();
159 
160  if( m_changesDataView->GetCurrentItem().IsOk() )
161  {
162  if( !IsModal() )
163  Show( false );
164  }
165 }
166 
167 
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:206
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.
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:91
PCBNEW_SETTINGS * GetPcbNewSettings()
BOARD_ITEM * GetItem(const KIID &aID)
void SetSeverities(int aSeverities)
Definition: rc_item.cpp:212
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:42
Definition: common.h:68
VECTOR_CLEANUP_ITEMS_PROVIDER is an implementation of the interface named RC_ITEMS_PROVIDER which use...
Definition: cleanup_item.h:74
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:74
BOARD * GetBoard() const
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)
void FocusOnItem(BOARD_ITEM *aItem)