KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <functional>
21using namespace std::placeholders;
22
23#include <property_holder.h>
24#include <confirm.h>
25#include <pcb_edit_frame.h>
27#include <board_commit.h>
28#include <board.h>
29#include <footprint.h>
30#include <pcb_generator.h>
31#include <pcb_track.h>
33#include <tool/tool_manager.h>
34#include <tools/pcb_actions.h>
37
38
41{
42 m_Parent = parent;
44 m_trackFilterLocked->Enable( m_delTracks->GetValue() );
45 m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
46 m_viaFilterLocked->Enable( m_delTracks->GetValue() );
47 m_viaFilterUnlocked->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
53 // This is a destructive dialog. Don't save control state; we always want to come up in a benign state.
54 OptOut( this );
55
57
58 SetFocus();
59 GetSizer()->SetSizeHints( this );
60 Centre();
61}
62
63
65{
67 DIALOG_GLOBAL_DELETION dlg( editFrame );
68
69 dlg.SetCurrentLayer( frame()->GetActiveLayer() );
70
71 if( dlg.ShowModal() == wxID_OK )
73
74 return 0;
75}
76
77
79{
80 m_currentLayer = aLayer;
81 m_rbLayersOption->SetString( 1, wxString::Format( m_rbLayersOption->GetString( 1 ),
82 m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) ) );
83 m_rbLayersOption->SetSelection( 0 );
84}
85
86
88{
89 m_trackFilterLocked->Enable( m_delTracks->GetValue() );
90 m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
91 m_viaFilterLocked->Enable( m_delTracks->GetValue() );
92 m_viaFilterUnlocked->Enable( m_delTracks->GetValue() );
93}
94
95
97{
98 m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
99 m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
100}
101
102
104{
105 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
106
107 m_drawingFilterLocked->Enable( enable );
108 m_drawingFilterUnlocked->Enable( enable );
109}
110
111
113{
114 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
115
116 m_drawingFilterLocked->Enable( enable );
117 m_drawingFilterUnlocked->Enable( enable );
118}
119
120
122{
123 bool gen_rastnest = false;
124 bool delete_all = m_delAll->GetValue();
125
126 // Clear selection before removing any items
127 m_Parent->GetToolManager()->RunAction( ACTIONS::selectionClear );
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 for( ZONE* zone : board->Zones() )
157 {
158 if( delete_all )
159 {
160 processConnectedItem( zone, all_layers );
161 }
162 else if( zone->IsTeardropArea() )
163 {
164 if( m_delTeardrops->GetValue() )
165 processConnectedItem( zone, layers_filter );
166 }
167 else
168 {
169 if( m_delZones->GetValue() )
170 processConnectedItem( zone, layers_filter );
171 }
172 }
173
174 bool delete_shapes = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
175 bool delete_texts = m_delTexts->GetValue();
176
177 if( delete_all || delete_shapes || delete_texts )
178 {
179 // Layer mask for drawings
180 LSET drawing_layers_filter;
181
182 if( m_delDrawings->GetValue() )
183 drawing_layers_filter = LSET::AllNonCuMask().set( Edge_Cuts, false );
184
185 if( m_delBoardEdges->GetValue() )
186 drawing_layers_filter.set( Edge_Cuts );
187
188 drawing_layers_filter &= layers_filter;
189
190 for( BOARD_ITEM* item : board->Drawings() )
191 {
192 if( delete_all )
193 {
194 processItem( item, all_layers );
195 }
196 else if( delete_shapes )
197 {
198 if( item->Type() == PCB_SHAPE_T && item->IsLocked() )
199 {
200 if( m_drawingFilterLocked->GetValue() )
201 processItem( item, drawing_layers_filter );
202 }
203 else if( item->Type() == PCB_SHAPE_T && !item->IsLocked() )
204 {
205 if( m_drawingFilterUnlocked->GetValue() )
206 processItem( item, drawing_layers_filter );
207 }
208 }
209 else if( delete_texts )
210 {
211 if( item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T )
212 processItem( item, layers_filter );
213 }
214 }
215 }
216
217 if( delete_all || m_delFootprints->GetValue() )
218 {
219 for( FOOTPRINT* footprint : board->Footprints() )
220 {
221 if( delete_all )
222 {
223 processConnectedItem( footprint, all_layers );
224 }
225 else if( footprint->IsLocked() )
226 {
227 if( m_footprintFilterLocked->GetValue() )
228 processConnectedItem( footprint, layers_filter );
229 }
230 else
231 {
232 if( m_footprintFilterUnlocked->GetValue() )
233 processConnectedItem( footprint, layers_filter );
234 }
235 }
236 }
237
238 if( delete_all || m_delTracks->GetValue() )
239 {
240 for( PCB_TRACK* track : board->Tracks() )
241 {
242 if( delete_all )
243 {
244 processConnectedItem( track, all_layers );
245 }
246 else if( track->Type() == PCB_VIA_T )
247 {
248 if( track->IsLocked() )
249 {
250 if( m_viaFilterLocked->GetValue() )
251 processConnectedItem( track, layers_filter );
252 }
253 else
254 {
255 if( m_viaFilterUnlocked->GetValue() )
256 processConnectedItem( track, layers_filter );
257 }
258 }
259 else
260 {
261 if( track->IsLocked() )
262 {
263 if( m_trackFilterLocked->GetValue() )
264 processConnectedItem( track, layers_filter );
265 }
266 else
267 {
268 if( m_trackFilterUnlocked->GetValue() )
269 processConnectedItem( track, layers_filter );
270 }
271 }
272 }
273
274 for( PCB_GENERATOR* generator : board->Generators() )
275 {
276 if( PCB_TUNING_PATTERN* pattern = dynamic_cast<PCB_TUNING_PATTERN*>( generator ) )
277 {
278 if( pattern->GetBoardItems().empty() )
279 commit.Remove( pattern );
280 }
281 }
282 }
283
284 commit.Push( _( "Global Delete" ) );
285
286 if( m_delMarkers->GetValue() )
287 board->DeleteMARKERs();
288
289 if( gen_rastnest )
290 {
291 board->CompileRatsnest();
292 m_Parent->SetMsgPanel( board );
293 }
294
295 // There is a chance that some of tracks have changed their nets, so rebuild ratsnest
296 // from scratch.
297 m_Parent->GetCanvas()->Refresh();
298}
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
BASE_SET & set(size_t pos)
Definition base_set.h:116
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
bool IsLocked() const override
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:285
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
const GENERATORS & Generators() const
Definition board.h:426
void CompileRatsnest()
Rebuild the entire board ratsnest.
Definition board.cpp:3595
const ZONES & Zones() const
Definition board.h:424
const FOOTPRINTS & Footprints() const
Definition board.h:420
const TRACKS & Tracks() const
Definition board.h:418
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition board.cpp:1785
const DRAWINGS & Drawings() const
Definition board.h:422
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
DIALOG_GLOBAL_DELETION_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Delete Items"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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 OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
int ShowModal() override
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
int GlobalDeletions(const TOOL_EVENT &aEvent)
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition lset.cpp:623
The main frame for Pcbnew.
T * frame() const
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
Generic, UI-independent tool event.
Definition tool_event.h:167
Handle a list of polygons defining a copper zone.
Definition zone.h:70
This file is part of the common library.
#define _(s)
@ Edge_Cuts
Definition layer_ids.h:108
@ F_Cu
Definition layer_ids.h:60
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
Class that computes missing connections on a PCB.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:81
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:86
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85