KiCad PCB EDA Suite
dialog_global_deletion.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-2015 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 <functional>
25 using namespace std::placeholders;
26 
27 #include <confirm.h>
28 #include <pcb_edit_frame.h>
29 #include <ratsnest/ratsnest_data.h>
30 #include <board_commit.h>
31 #include <board.h>
32 #include <footprint.h>
33 #include <track.h>
34 #include <tool/tool_manager.h>
35 #include <tools/pcb_actions.h>
36 #include <tools/global_edit_tool.h>
37 #include <dialog_global_deletion.h>
38 
39 
42 {
43  m_Parent = parent;
45  m_trackFilterLocked->Enable( m_delTracks->GetValue() );
46  m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
47  m_trackFilterVias->Enable( m_delTracks->GetValue() );
48  m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
49  m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
50  m_drawingFilterLocked->Enable( m_delDrawings->GetValue() );
51  m_drawingFilterUnlocked->Enable( m_delDrawings->GetValue() );
52  m_sdbSizer1OK->SetDefault();
53  SetFocus();
54  GetSizer()->SetSizeHints( this );
55  Centre();
56 }
57 
58 
60 {
61  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
62  DIALOG_GLOBAL_DELETION dlg( editFrame );
63 
64  dlg.SetCurrentLayer( frame()->GetActiveLayer() );
65  dlg.ShowModal();
66  return 0;
67 }
68 
69 
71 {
72  m_currentLayer = aLayer;
73  m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
74 }
75 
76 
77 void DIALOG_GLOBAL_DELETION::onCheckDeleteTracks( wxCommandEvent& event )
78 {
79  m_trackFilterLocked->Enable( m_delTracks->GetValue() );
80  m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
81  m_trackFilterVias->Enable( m_delTracks->GetValue() );
82 }
83 
84 
86 {
87  m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
88  m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
89 }
90 
91 
92 void DIALOG_GLOBAL_DELETION::onCheckDeleteDrawings( wxCommandEvent& event )
93 {
94  m_drawingFilterLocked->Enable( m_delDrawings->GetValue() );
95  m_drawingFilterUnlocked->Enable( m_delDrawings->GetValue() );
96 }
97 
98 
100 {
101  bool gen_rastnest = false;
102 
103  // Clear selection before removing any items
105 
106  bool delete_all = false;
107 
108  if( m_delAll->GetValue() )
109  {
110  if( !IsOK( this, _( "Are you sure you want to delete the entire board?" ) ) )
111  return;
112 
113  delete_all = true;
114  }
115  else if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
116  {
117  return;
118  }
119 
120  BOARD* board = m_Parent->GetBoard();
121  BOARD_COMMIT commit( m_Parent );
122  LSET layers_filter = LSET().set();
123 
124  if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
125  layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
126 
127  if( delete_all || m_delZones->GetValue() )
128  {
129  int area_index = 0;
130  auto item = board->GetArea( area_index );
131 
132  while( item )
133  {
134  if( delete_all || layers_filter[item->GetLayer()] )
135  {
136  commit.Remove( item );
137  gen_rastnest = true;
138  }
139 
140  area_index++;
141  item = board->GetArea( area_index );
142  }
143  }
144 
145  bool delete_shapes = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
146  bool delete_texts = m_delTexts->GetValue();
147 
148  if( delete_all || delete_shapes || delete_texts )
149  {
150  // Layer mask for texts
151  LSET del_text_layers = layers_filter;
152 
153  // Layer mask for drawings
154  LSET masque_layer;
155 
156  if( m_delDrawings->GetValue() )
157  masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
158 
159  if( m_delBoardEdges->GetValue() )
160  masque_layer.set( Edge_Cuts );
161 
162  masque_layer &= layers_filter;
163 
164  for( BOARD_ITEM* item : board->Drawings() )
165  {
166  KICAD_T type = item->Type();
167  LAYER_NUM layer = item->GetLayer();
168 
169  if( !delete_all )
170  {
171  if( type == PCB_SHAPE_T )
172  {
173  if( !delete_shapes || !masque_layer[layer] )
174  continue;
175 
176  if( item->IsLocked() && !m_drawingFilterLocked->GetValue() )
177  continue;
178 
179  if( !item->IsLocked() && !m_drawingFilterUnlocked->GetValue() )
180  continue;
181  }
182  else if( type == PCB_TEXT_T )
183  {
184  if( !delete_texts || !del_text_layers[layer] )
185  continue;
186  }
187  }
188 
189  commit.Remove( item );
190  }
191  }
192 
193  if( delete_all || m_delFootprints->GetValue() )
194  {
195  for( FOOTPRINT* footprint : board->Footprints() )
196  {
197  if( !delete_all )
198  {
199  if( footprint->IsLocked() && !m_footprintFilterLocked->GetValue() )
200  continue;
201 
202  if( !footprint->IsLocked() && !m_footprintFilterUnlocked->GetValue() )
203  continue;
204 
205  if( !layers_filter[footprint->GetLayer()] )
206  continue;
207  }
208 
209  commit.Remove( footprint );
210  gen_rastnest = true;
211  }
212  }
213 
214  if( delete_all || m_delTracks->GetValue() )
215  {
216  for( TRACK* track : board->Tracks() )
217  {
218  if( !delete_all )
219  {
220  if( track->Type() == PCB_TRACE_T )
221  {
222  if( track->IsLocked() && !m_trackFilterLocked->GetValue() )
223  continue;
224 
225  if( !track->IsLocked() && !m_trackFilterUnlocked->GetValue() )
226  continue;
227  }
228 
229  if( ( track->Type() == PCB_VIA_T ) && !m_trackFilterVias->GetValue() )
230  continue;
231 
232  if( ( track->GetLayerSet() & layers_filter ) == 0 )
233  continue;
234  }
235 
236  commit.Remove( track );
237  gen_rastnest = true;
238  }
239  }
240 
241  commit.Push( "Global delete" );
242 
243  if( m_delMarkers->GetValue() )
244  board->DeleteMARKERs();
245 
246  if( gen_rastnest )
247  m_Parent->Compile_Ratsnest( true );
248 
249  // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch
250  m_Parent->GetCanvas()->Refresh();
251 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:342
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:41
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
DIALOG_GLOBAL_DELETION(PCB_EDIT_FRAME *parent)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Class that computes missing connections on a PCB.
Class DIALOG_GLOBAL_DELETION_BASE.
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:773
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
ZONE * GetArea(int index) const
Return the Zone at a given index.
Definition: board.h:913
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PCB_BASE_EDIT_FRAME * frame() const
LSET is a set of PCB_LAYER_IDs.
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:783
FOOTPRINTS & Footprints()
Definition: board.h:305
Generic, UI-independent tool event.
Definition: tool_event.h:173
void onCheckDeleteFootprints(wxCommandEvent &event) override
COMMIT & Remove(EDA_ITEM *aItem)
Notify observers that aItem has been removed.
Definition: commit.h:90
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...
int LAYER_NUM
This can be replaced with int and removed.
int GlobalDeletions(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
void SetCurrentLayer(LAYER_NUM aLayer)
The main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
void onCheckDeleteDrawings(wxCommandEvent &event) override
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
BOARD * GetBoard() const
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:296
DRAWINGS & Drawings()
Definition: board.h:308
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
TRACKS & Tracks()
Definition: board.h:302
Definition: track.h:83
void onCheckDeleteTracks(wxCommandEvent &event) override