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 #include <wx/wx.h>
24 
25 #include <board_commit.h>
27 #include <kiface_i.h>
28 #include <pcb_edit_frame.h>
29 #include <pcbnew_settings.h>
30 #include <reporter.h>
31 #include <tool/tool_manager.h>
32 #include <tools/pcb_actions.h>
33 #include <tracks_cleaner.h>
34 #include <drc/drc_item.h>
35 
38  m_parentFrame( aParentFrame )
39 {
40  auto cfg = m_parentFrame->GetSettings();
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 
49  m_changesDataView->AssociateModel( m_changesTreeModel );
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->GetSettings();
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( DRC_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  for( DRC_ITEM* item : m_items )
103  delete item;
104 
105  m_items.clear();
106 
107  wxBusyCursor busy;
108  BOARD_COMMIT commit( m_parentFrame );
110 
111  if( !aDryRun )
112  {
113  // Clear current selection list to avoid selection of deleted items
115  }
116 
117  // Old model has to be refreshed, GAL normally does not keep updating it
119 
120  bool modified = cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
121  m_cleanViasOpt->GetValue(), m_mergeSegmOpt->GetValue(),
122  m_deleteUnconnectedOpt->GetValue(), m_deleteTracksInPadsOpt->GetValue() );
123 
124  if( aDryRun )
125  {
127  m_changesTreeModel->SetProvider( provider );
128  }
129  else if( modified )
130  {
131  // Clear undo and redo lists to avoid inconsistencies between lists
132  commit.Push( _( "Board cleanup" ) );
133  m_parentFrame->GetCanvas()->Refresh( true );
134  }
135 }
136 
137 
138 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxDataViewEvent& aEvent )
139 {
140  const KIID& itemID = RC_TREE_MODEL::ToUUID( aEvent.GetItem() );
141  BOARD_ITEM* item = m_parentFrame->GetBoard()->GetItem( itemID );
142  WINDOW_THAWER thawer( m_parentFrame );
143 
144  m_parentFrame->FocusOnItem( item );
146 
147  aEvent.Skip();
148 }
149 
150 
152 {
153  event.Skip();
154 
155  if( m_changesDataView->GetCurrentItem().IsOk() )
156  {
157  if( !IsModal() )
158  Show( false );
159  }
160 }
161 
162 
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
DIALOG_CLEANUP m_Cleanup
void SetProvider(RC_ITEMS_PROVIDER *aProvider)
Definition: rc_item.cpp:166
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:139
static KIID ToUUID(wxDataViewItem aItem)
Definition: rc_item.cpp:67
BOARD_ITEM * GetItem(const KIID &aID)
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:42
Definition: common.h:65
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...
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.
BOARD * GetBoard() const
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)
void FocusOnItem(BOARD_ITEM *aItem)
VECTOR_DRC_ITEMS_PROVIDER is an implementation of the interface named DRC_ITEMS_PROVIDER which uses a...
Definition: drc_item.h:152
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
PCBNEW_SETTINGS * GetSettings()