KiCad PCB EDA Suite
dialog_cleanup_tracks_and_vias.cpp
Go to the documentation of this file.
1 
5 /*
6  * This program source code file is part of KiCad, a free EDA CAD application.
7  *
8  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 #include <wx/wx.h>
28 
29 #include "dialog_drclistbox.h"
30 #include <board_commit.h>
31 #include <collectors.h>
33 #include <kiface_i.h>
34 #include <pcb_edit_frame.h>
35 #include <reporter.h>
36 #include <tool/tool_manager.h>
37 #include <tools/pcb_actions.h>
38 #include <tracks_cleaner.h>
39 #include <wx_html_report_panel.h>
40 
41 // Keywords for read and write config
42 #define CleanupViaKey wxT( "DialogCleanupVias" )
43 #define MergeKey wxT( "DialogCleanupMergeSegments" )
44 #define UnconnectedKey wxT( "DialogCleanupUnconnected" )
45 #define ShortCircuitKey wxT( "DialogCleanupShortCircuit" )
46 #define TracksInPadKey wxT( "DialogCleanupTracksInPads" )
47 
48 
51  m_parentFrame( aParentFrame )
52 {
54  m_config->SetPath( "/dialogs/cleanup_tracks/" );
55 
56  bool value;
57  m_config->Read( CleanupViaKey, &value, true );
58  m_cleanViasOpt->SetValue( value );
59 
60  m_config->Read( MergeKey, &value, true );
61  m_mergeSegmOpt->SetValue( value );
62 
63  m_config->Read( UnconnectedKey, &value, true );
64  m_deleteUnconnectedOpt->SetValue( value );
65 
66  m_config->Read( ShortCircuitKey, &value, true );
67  m_cleanShortCircuitOpt->SetValue( value );
68 
69  m_config->Read( TracksInPadKey, &value, true );
70  m_deleteTracksInPadsOpt->SetValue( value );
71 
72  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
73  // that requires us to correct the button labels here.
74  m_sdbSizerOK->SetLabel( _( "Update PCB" ) );
75 
76  m_sdbSizerOK->SetDefault();
77  GetSizer()->SetSizeHints(this);
78  Centre();
79 }
80 
81 
83 {
84  m_config->Write( CleanupViaKey, m_cleanViasOpt->GetValue() );
85  m_config->Write( MergeKey, m_mergeSegmOpt->GetValue() );
86  m_config->Write( UnconnectedKey, m_deleteUnconnectedOpt->GetValue() );
87  m_config->Write( ShortCircuitKey, m_cleanShortCircuitOpt->GetValue() );
88  m_config->Write( TracksInPadKey, m_deleteTracksInPadsOpt->GetValue() );
89 
90  for( DRC_ITEM* item : m_items )
91  delete item;
92 }
93 
94 
95 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnCheckBox( wxCommandEvent& anEvent )
96 {
97  doCleanup( true );
98 }
99 
100 
102 {
103  doCleanup( true );
104 
105  return true;
106 }
107 
108 
110 {
111  doCleanup( false );
112 
113  return true;
114 }
115 
116 
118 {
119  for( DRC_ITEM* item : m_items )
120  delete item;
121 
122  m_items.clear();
123 
124  wxBusyCursor busy;
125  BOARD_COMMIT commit( m_parentFrame );
127 
128  if( !aDryRun )
129  {
130  // Clear current selection list to avoid selection of deleted items
132  }
133 
134  // Old model has to be refreshed, GAL normally does not keep updating it
136 
137  bool modified = cleaner.CleanupBoard( aDryRun, &m_items, m_cleanShortCircuitOpt->GetValue(),
138  m_cleanViasOpt->GetValue(), m_mergeSegmOpt->GetValue(),
139  m_deleteUnconnectedOpt->GetValue(), m_deleteTracksInPadsOpt->GetValue() );
140 
141  if( aDryRun )
142  {
144  }
145  else if( modified )
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( wxCommandEvent& event )
155 {
156  int selection = event.GetSelection();
157 
158  if( selection != wxNOT_FOUND )
159  {
160  // Find the selected DRC_ITEM in the listbox, position cursor there.
161  const DRC_ITEM* item = m_ItemsListBox->GetItem( selection );
162 
163  if( item )
164  {
165  m_parentFrame->FocusOnLocation( item->GetPointA(), true );
166  WINDOW_THAWER thawer( m_parentFrame );
168  }
169  }
170 
171  event.Skip();
172 }
173 
174 
176 {
177  event.Skip();
178 
179  int selection = m_ItemsListBox->GetSelection();
180 
181  if( selection != wxNOT_FOUND )
182  {
183  // Find the selected DRC_ITEM in the listbox, position cursor there.
184  // Then hide the dialog.
185  const DRC_ITEM* item = m_ItemsListBox->GetItem( selection );
186  if( item )
187  {
188  m_parentFrame->FocusOnLocation( item->GetPointA(), true );
189 
190  if( !IsModal() )
191  Show( false );
192  }
193  }
194 }
195 
196 
198 {
199  // popup menu to go to either of the items listed in the DRC_ITEM.
200 
201  int selection = m_ItemsListBox->GetSelection();
202 
203  if( selection != wxNOT_FOUND )
204  {
205  // popup menu to go to either of the items listed in the DRC_ITEM.
206  const DRC_ITEM* item = m_ItemsListBox->GetItem( selection );
207  GENERAL_COLLECTOR items;
208 
209  items.Append( item->GetMainItem( m_parentFrame->GetBoard() ) );
210 
211  if( item->HasSecondItem() )
212  items.Append( item->GetAuxiliaryItem( m_parentFrame->GetBoard() ) );
213 
214  WINDOW_THAWER thawer( m_parentFrame );
217  }
218 }
219 
220 
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Class DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: drc_item.h:48
void OnSelectItem(wxCommandEvent &event) override
void Compile_Ratsnest(bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:44
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD_ITEM * GetAuxiliaryItem(BOARD *aBoard) const
Definition: drc_item.cpp:258
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
void OnRightUpItem(wxMouseEvent &event) override
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
static TOOL_ACTION selectionMenu
Runs a selection menu to select from a list of items.
Definition: pcb_actions.h:84
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:51
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:132
void SetList(EDA_UNITS_T aUnits, DRC_ITEM_LIST *aList)
Function SetList sets the DRC_ITEM_LIST for this listbox.
const DRC_ITEM * GetItem(int aIndex)
Function GetItem returns a requested DRC_ITEM* or NULL.
Class DRC_LIST_GENERIC is an implementation of the interface named DRC_ITEM_LIST which uses a vector ...
void OnCheckBox(wxCommandEvent &anEvent) override
BOARD_ITEM * GetMainItem(BOARD *aBoard) const
Access to A and B items for BOARDs.
Definition: drc_item.cpp:252
#define _(s)
const wxPoint & GetPointA() const
Definition: drc_item.h:226
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...
#define ShortCircuitKey
bool HasSecondItem() const
Definition: drc_item.h:167
Class DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE.
void FocusOnLocation(const wxPoint &aPos, bool aCenterView=false)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
EDA_UNITS_T GetUserUnits() const
Definition: dialog_shim.h:135
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
#define UnconnectedKey
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
void OnLeftDClickItem(wxMouseEvent &event) override
Class 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
#define TracksInPadKey
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)