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 
30 #include <wx_html_report_panel.h>
31 #include <board_commit.h>
32 #include <tools/pcb_actions.h>
33 #include <pcb_edit_frame.h>
34 #include <tracks_cleaner.h>
35 #include <reporter.h>
36 #include <class_drawpanel.h>
37 #include <tool/tool_manager.h>
38 #include <collectors.h>
39 #include "dialog_drclistbox.h"
40 
41 // Static members of DIALOG_CLEANUP_TRACKS_AND_VIAS
46 
47 
50  m_parentFrame( aParentFrame )
51 {
52  m_cleanViasOpt->SetValue( m_cleanVias );
53  m_mergeSegmOpt->SetValue( m_mergeSegments );
56 
57  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
58  // that requires us to correct the button labels here.
59  m_sdbSizerOK->SetLabel( _( "Update PCB" ) );
60 
61  m_sdbSizerOK->SetDefault();
62  GetSizer()->SetSizeHints(this);
63  Centre();
64 }
65 
66 
68 {
69  m_cleanVias = m_cleanViasOpt->GetValue();
70  m_mergeSegments = m_mergeSegmOpt->GetValue();
73 
74  for( DRC_ITEM* item : m_items )
75  delete item;
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  for( DRC_ITEM* item : m_items )
104  delete item;
105 
106  m_items.clear();
107 
108  wxBusyCursor busy;
109  BOARD_COMMIT commit( m_parentFrame );
111 
112  if( !aDryRun )
113  {
114  // Clear current selection list to avoid selection of deleted items
116  }
117 
118  // Old model has to be refreshed, GAL normally does not keep updating it
119  m_parentFrame->Compile_Ratsnest( NULL, false );
120 
121  bool modified = cleaner.CleanupBoard( aDryRun, &m_items,
122  m_cleanShortCircuitOpt->GetValue(),
123  m_cleanViasOpt->GetValue(),
124  m_mergeSegmOpt->GetValue(),
125  m_deleteUnconnectedOpt->GetValue() );
126 
127  if( aDryRun )
128  {
130  }
131  else if( modified )
132  {
133  // Clear undo and redo lists to avoid inconsistencies between lists
134  m_parentFrame->SetCurItem( NULL );
135  commit.Push( _( "Board cleanup" ) );
136 
137  m_parentFrame->GetCanvas()->Refresh( true );
138  }
139 }
140 
141 
142 void DIALOG_CLEANUP_TRACKS_AND_VIAS::OnSelectItem( wxCommandEvent& event )
143 {
144  int selection = event.GetSelection();
145 
146  if( selection != wxNOT_FOUND )
147  {
148  // Find the selected DRC_ITEM in the listbox, position cursor there.
149  const DRC_ITEM* item = m_ItemsListBox->GetItem( selection );
150 
151  if( item )
152  {
153  // When selecting a item, center it on GAL and just move the graphic
154  // cursor in legacy mode gives the best result
155  bool center = m_parentFrame->IsGalCanvasActive() ? true : false;
156  m_parentFrame->FocusOnLocation( item->GetPointA(), false, center );
157 
158  WINDOW_THAWER thawer( m_parentFrame );
160  }
161  }
162 
163  event.Skip();
164 }
165 
166 
168 {
169  event.Skip();
170 
171  int selection = m_ItemsListBox->GetSelection();
172 
173  if( selection != wxNOT_FOUND )
174  {
175  // Find the selected DRC_ITEM in the listbox, position cursor there.
176  // Then hide the dialog.
177  const DRC_ITEM* item = m_ItemsListBox->GetItem( selection );
178  if( item )
179  {
180  // When selecting a item, center it on GAL and just move the graphic
181  // cursor in legacy mode gives the best result
182  bool center = m_parentFrame->IsGalCanvasActive() ? true : false;
183  m_parentFrame->FocusOnLocation( item->GetPointA(), true, center );
184 
185  if( !IsModal() )
186  {
187  Show( false );
188 
189  // We do not want the clarify selection popup when releasing the
190  // left button in the main window
192  }
193  }
194  }
195 }
196 
197 
199 {
200  // popup menu to go to either of the items listed in the DRC_ITEM.
201 
202  int selection = m_ItemsListBox->GetSelection();
203 
204  if( selection != wxNOT_FOUND )
205  {
206  // popup menu to go to either of the items listed in the DRC_ITEM.
207  const DRC_ITEM* item = m_ItemsListBox->GetItem( selection );
208  GENERAL_COLLECTOR items;
209 
210  items.Append( item->GetMainItem( m_parentFrame->GetBoard() ) );
211 
212  if( item->HasSecondItem() )
213  items.Append( item->GetAuxiliaryItem( m_parentFrame->GetBoard() ) );
214 
215  WINDOW_THAWER thawer( m_parentFrame );
218  }
219 }
220 
221 
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
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
BOARD_ITEM * GetAuxiliaryItem(BOARD *aBoard) const
Definition: drc_item.cpp:256
void OnRightUpItem(wxMouseEvent &event) override
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
static TOOL_ACTION selectionMenu
Runs a selection menu to select from a list of items.
Definition: pcb_actions.h:64
void SkipNextLeftButtonReleaseEvent()
After calling this function, if the left mouse button is down, the next left mouse button release eve...
void FocusOnLocation(const wxPoint &aPos, bool aWarpCursor=true, bool aCenterView=false)
Useful to focus on a particular location, in find functions Move the graphic cursor (crosshair cursor...
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:133
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use.
Definition: draw_frame.h:924
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.
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:289
TOOL_MANAGER * GetToolManager() const override
Return the tool manager instance, if any.
Definition: draw_frame.h:937
Class DRC_LIST_GENERIC is an implementation of the interface named DRC_ITEM_LIST which uses a vector ...
void OnCheckBox(wxCommandEvent &anEvent) override
virtual EDA_DRAW_PANEL * GetCanvas() const
Definition: draw_frame.h:399
BOARD_ITEM * GetMainItem(BOARD *aBoard) const
Access to A and B items for BOARDs.
Definition: drc_item.cpp:250
const wxPoint & GetPointA() const
Definition: drc_item.h:221
bool Show(bool show) override
void Compile_Ratsnest(wxDC *aDC, bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:53
bool HasSecondItem() const
Definition: drc_item.h:162
Class DIALOG_CLEANUP_TRACKS_AND_VIAS_BASE.
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
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL)
DIALOG_CLEANUP_TRACKS_AND_VIAS(PCB_EDIT_FRAME *parent)
EDA_UNITS_T GetUserUnits() const override
Definition: dialog_shim.h:133