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-2022 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>
25using namespace std::placeholders;
26
27#include <confirm.h>
28#include <pcb_edit_frame.h>
30#include <board_commit.h>
31#include <board.h>
32#include <footprint.h>
33#include <pcb_track.h>
34#include <tool/tool_manager.h>
35#include <tools/pcb_actions.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
54
55 SetFocus();
56 GetSizer()->SetSizeHints( this );
57 Centre();
58}
59
60
62{
63 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
64 DIALOG_GLOBAL_DELETION dlg( editFrame );
65
66 dlg.SetCurrentLayer( frame()->GetActiveLayer() );
67
68 if( dlg.ShowModal() == wxID_OK )
70
71 return 0;
72}
73
74
76{
77 m_currentLayer = aLayer;
78 m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
79}
80
81
83{
84 m_trackFilterLocked->Enable( m_delTracks->GetValue() );
85 m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
86 m_trackFilterVias->Enable( m_delTracks->GetValue() );
87}
88
89
91{
92 m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
93 m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
94}
95
96
98{
99 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
100
101 m_drawingFilterLocked->Enable( enable );
102 m_drawingFilterUnlocked->Enable( enable );
103}
104
105
107{
108 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
109
110 m_drawingFilterLocked->Enable( enable );
111 m_drawingFilterUnlocked->Enable( enable );
112}
113
114
116{
117 bool gen_rastnest = false;
118 bool delete_all = m_delAll->GetValue();
119
120 if( !IsOK( GetParent(), delete_all ? _( "Are you sure you want to delete the entire board?" )
121 : _( "Are you sure you want to delete the selected items?" ) ) )
122 {
123 return;
124 }
125
126 // Clear selection before removing any items
128
129 BOARD* board = m_Parent->GetBoard();
130 BOARD_COMMIT commit( m_Parent );
131 LSET all_layers = LSET().set();
132 LSET layers_filter;
133
134 if( m_rbLayersOption->GetSelection() != 0 )
135 layers_filter.set( m_currentLayer );
136 else
137 layers_filter = all_layers;
138
139 auto processItem =
140 [&]( BOARD_ITEM* item, const LSET& layers_mask )
141 {
142 if( ( item->GetLayerSet() & layers_mask ).any() )
143 commit.Remove( item );
144 };
145
146 auto processConnectedItem =
147 [&]( BOARD_ITEM* item, const LSET& layers_mask )
148 {
149 if( ( item->GetLayerSet() & layers_mask ).any() )
150 {
151 commit.Remove( item );
152 gen_rastnest = true;
153 }
154 };
155
156 if( delete_all || m_delZones->GetValue() )
157 {
158 for( ZONE* zone : board->Zones() )
159 {
160 if( delete_all )
161 processConnectedItem( zone, all_layers );
162 else
163 processConnectedItem( zone, layers_filter );
164 }
165 }
166
167 bool delete_shapes = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
168 bool delete_texts = m_delTexts->GetValue();
169
170 if( delete_all || delete_shapes || delete_texts )
171 {
172 // Layer mask for drawings
173 LSET drawing_layers_filter;
174
175 if( m_delDrawings->GetValue() )
176 drawing_layers_filter = LSET::AllNonCuMask().set( Edge_Cuts, false );
177
178 if( m_delBoardEdges->GetValue() )
179 drawing_layers_filter.set( Edge_Cuts );
180
181 drawing_layers_filter &= layers_filter;
182
183 for( BOARD_ITEM* item : board->Drawings() )
184 {
185 if( delete_all )
186 {
187 processItem( item, all_layers );
188 }
189 else if( delete_shapes )
190 {
191 if( item->Type() == PCB_SHAPE_T && item->IsLocked() )
192 {
193 if( m_drawingFilterLocked->GetValue() )
194 processItem( item, drawing_layers_filter );
195 }
196 else if( item->Type() == PCB_SHAPE_T && !item->IsLocked() )
197 {
198 if( m_drawingFilterUnlocked->GetValue() )
199 processItem( item, drawing_layers_filter );
200 }
201 }
202 else if( delete_texts )
203 {
204 if( item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T )
205 processItem( item, layers_filter );
206 }
207 }
208 }
209
210 if( delete_all || m_delFootprints->GetValue() )
211 {
212 for( FOOTPRINT* footprint : board->Footprints() )
213 {
214 if( delete_all )
215 {
216 processConnectedItem( footprint, all_layers );
217 }
218 else if( footprint->IsLocked() )
219 {
220 if( m_footprintFilterLocked->GetValue() )
221 processConnectedItem( footprint, layers_filter );
222 }
223 else
224 {
225 if( m_footprintFilterUnlocked->GetValue() )
226 processConnectedItem( footprint, layers_filter );
227 }
228 }
229 }
230
231 if( delete_all || m_delTracks->GetValue() )
232 {
233 for( PCB_TRACK* track : board->Tracks() )
234 {
235 if( delete_all )
236 {
237 processConnectedItem( track, all_layers );
238 }
239 else if( track->Type() == PCB_VIA_T )
240 {
241 if( m_trackFilterVias->GetValue() )
242 processConnectedItem( track, layers_filter );
243 }
244 else if( track->IsLocked() )
245 {
246 if( m_trackFilterLocked->GetValue() )
247 processConnectedItem( track, layers_filter );
248 }
249 else
250 {
251 if( m_trackFilterUnlocked->GetValue() )
252 processConnectedItem( track, layers_filter );
253 }
254 }
255 }
256
257 commit.Push( wxT( "Global delete" ) );
258
259 if( m_delMarkers->GetValue() )
260 board->DeleteMARKERs();
261
262 if( gen_rastnest )
263 m_Parent->Compile_Ratsnest( true );
264
265 // There is a chance that some of tracks have changed their nets, so rebuild ratsnest
266 // from scratch.
268}
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:50
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:172
virtual bool IsLocked() const
Definition: board_item.cpp:65
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
ZONES & Zones()
Definition: board.h:313
FOOTPRINTS & Footprints()
Definition: board.h:307
TRACKS & Tracks()
Definition: board.h:304
DRAWINGS & Drawings()
Definition: board.h:310
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:400
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:892
COMMIT & Remove(EDA_ITEM *aItem)
Notify observers that aItem has been removed.
Definition: commit.h:90
Class DIALOG_GLOBAL_DELETION_BASE.
DIALOG_GLOBAL_DELETION(PCB_EDIT_FRAME *parent)
void onCheckDeleteDrawings(wxCommandEvent &event) override
void onCheckDeleteFootprints(wxCommandEvent &event) override
void onCheckDeleteBoardOutlines(wxCommandEvent &event) override
void onCheckDeleteTracks(wxCommandEvent &event) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
int GlobalDeletions(const TOOL_EVENT &aEvent)
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:794
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:35
The main frame for Pcbnew.
PCB_BASE_EDIT_FRAME * frame() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
Generic, UI-independent tool event.
Definition: tool_event.h:156
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:342
This file is part of the common library.
#define _(s)
@ Edge_Cuts
Definition: layer_ids.h:113
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:926
Class that computes missing connections on a PCB.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:102
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:91
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:90