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, 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 <property_holder.h>
28#include <confirm.h>
29#include <pcb_edit_frame.h>
31#include <board_commit.h>
32#include <board.h>
33#include <footprint.h>
34#include <pcb_generator.h>
35#include <pcb_track.h>
37#include <tool/tool_manager.h>
38#include <tools/pcb_actions.h>
41
42
45{
46 m_Parent = parent;
48 m_trackFilterLocked->Enable( m_delTracks->GetValue() );
49 m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
50 m_viaFilterLocked->Enable( m_delTracks->GetValue() );
51 m_viaFilterUnlocked->Enable( m_delTracks->GetValue() );
52 m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
53 m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
54 m_drawingFilterLocked->Enable( m_delDrawings->GetValue() );
55 m_drawingFilterUnlocked->Enable( m_delDrawings->GetValue() );
56
57 // This is a destructive dialog. Don't save control state; we always want to come up in a benign state.
58 OptOut( this );
59
61
62 SetFocus();
63 GetSizer()->SetSizeHints( this );
64 Centre();
65}
66
67
69{
71 DIALOG_GLOBAL_DELETION dlg( editFrame );
72
73 dlg.SetCurrentLayer( frame()->GetActiveLayer() );
74
75 if( dlg.ShowModal() == wxID_OK )
77
78 return 0;
79}
80
81
83{
84 m_currentLayer = aLayer;
85 m_rbLayersOption->SetString( 1, wxString::Format( m_rbLayersOption->GetString( 1 ),
86 m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) ) );
87 m_rbLayersOption->SetSelection( 0 );
88}
89
90
92{
93 m_trackFilterLocked->Enable( m_delTracks->GetValue() );
94 m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
95 m_viaFilterLocked->Enable( m_delTracks->GetValue() );
96 m_viaFilterUnlocked->Enable( m_delTracks->GetValue() );
97}
98
99
101{
102 m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
103 m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
104}
105
106
108{
109 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
110
111 m_drawingFilterLocked->Enable( enable );
112 m_drawingFilterUnlocked->Enable( enable );
113}
114
115
117{
118 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
119
120 m_drawingFilterLocked->Enable( enable );
121 m_drawingFilterUnlocked->Enable( enable );
122}
123
124
126{
127 bool gen_rastnest = false;
128 bool delete_all = m_delAll->GetValue();
129
130 // Clear selection before removing any items
131 m_Parent->GetToolManager()->RunAction( ACTIONS::selectionClear );
132
133 BOARD* board = m_Parent->GetBoard();
134 BOARD_COMMIT commit( m_Parent );
135 LSET all_layers = LSET().set();
136 LSET layers_filter;
137
138 if( m_rbLayersOption->GetSelection() != 0 )
139 layers_filter.set( m_currentLayer );
140 else
141 layers_filter = all_layers;
142
143 auto processItem =
144 [&]( BOARD_ITEM* item, const LSET& layers_mask )
145 {
146 if( ( item->GetLayerSet() & layers_mask ).any() )
147 commit.Remove( item );
148 };
149
150 auto processConnectedItem =
151 [&]( BOARD_ITEM* item, const LSET& layers_mask )
152 {
153 if( ( item->GetLayerSet() & layers_mask ).any() )
154 {
155 commit.Remove( item );
156 gen_rastnest = true;
157 }
158 };
159
160 for( ZONE* zone : board->Zones() )
161 {
162 if( delete_all )
163 {
164 processConnectedItem( zone, all_layers );
165 }
166 else if( zone->IsTeardropArea() )
167 {
168 if( m_delTeardrops->GetValue() )
169 processConnectedItem( zone, layers_filter );
170 }
171 else
172 {
173 if( m_delZones->GetValue() )
174 processConnectedItem( zone, layers_filter );
175 }
176 }
177
178 bool delete_shapes = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
179 bool delete_texts = m_delTexts->GetValue();
180
181 if( delete_all || delete_shapes || delete_texts )
182 {
183 // Layer mask for drawings
184 LSET drawing_layers_filter;
185
186 if( m_delDrawings->GetValue() )
187 drawing_layers_filter = LSET::AllNonCuMask().set( Edge_Cuts, false );
188
189 if( m_delBoardEdges->GetValue() )
190 drawing_layers_filter.set( Edge_Cuts );
191
192 drawing_layers_filter &= layers_filter;
193
194 for( BOARD_ITEM* item : board->Drawings() )
195 {
196 if( delete_all )
197 {
198 processItem( item, all_layers );
199 }
200 else if( delete_shapes )
201 {
202 if( item->Type() == PCB_SHAPE_T && item->IsLocked() )
203 {
204 if( m_drawingFilterLocked->GetValue() )
205 processItem( item, drawing_layers_filter );
206 }
207 else if( item->Type() == PCB_SHAPE_T && !item->IsLocked() )
208 {
209 if( m_drawingFilterUnlocked->GetValue() )
210 processItem( item, drawing_layers_filter );
211 }
212 }
213 else if( delete_texts )
214 {
215 if( item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T )
216 processItem( item, layers_filter );
217 }
218 }
219 }
220
221 if( delete_all || m_delFootprints->GetValue() )
222 {
223 for( FOOTPRINT* footprint : board->Footprints() )
224 {
225 if( delete_all )
226 {
227 processConnectedItem( footprint, all_layers );
228 }
229 else if( footprint->IsLocked() )
230 {
231 if( m_footprintFilterLocked->GetValue() )
232 processConnectedItem( footprint, layers_filter );
233 }
234 else
235 {
236 if( m_footprintFilterUnlocked->GetValue() )
237 processConnectedItem( footprint, layers_filter );
238 }
239 }
240 }
241
242 if( delete_all || m_delTracks->GetValue() )
243 {
244 for( PCB_TRACK* track : board->Tracks() )
245 {
246 if( delete_all )
247 {
248 processConnectedItem( track, all_layers );
249 }
250 else if( track->Type() == PCB_VIA_T )
251 {
252 if( track->IsLocked() )
253 {
254 if( m_viaFilterLocked->GetValue() )
255 processConnectedItem( track, layers_filter );
256 }
257 else
258 {
259 if( m_viaFilterUnlocked->GetValue() )
260 processConnectedItem( track, layers_filter );
261 }
262 }
263 else
264 {
265 if( track->IsLocked() )
266 {
267 if( m_trackFilterLocked->GetValue() )
268 processConnectedItem( track, layers_filter );
269 }
270 else
271 {
272 if( m_trackFilterUnlocked->GetValue() )
273 processConnectedItem( track, layers_filter );
274 }
275 }
276 }
277
278 for( PCB_GENERATOR* generator : board->Generators() )
279 {
280 if( PCB_TUNING_PATTERN* pattern = dynamic_cast<PCB_TUNING_PATTERN*>( generator ) )
281 {
282 if( pattern->GetBoardItems().empty() )
283 commit.Remove( pattern );
284 }
285 }
286 }
287
288 commit.Push( _( "Global Delete" ) );
289
290 if( m_delMarkers->GetValue() )
291 board->DeleteMARKERs();
292
293 if( gen_rastnest )
294 m_Parent->Compile_Ratsnest( true );
295
296 // There is a chance that some of tracks have changed their nets, so rebuild ratsnest
297 // from scratch.
298 m_Parent->GetCanvas()->Refresh();
299}
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:223
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:79
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:252
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
const GENERATORS & Generators() const
Definition board.h:364
const ZONES & Zones() const
Definition board.h:362
const FOOTPRINTS & Footprints() const
Definition board.h:358
const TRACKS & Tracks() const
Definition board.h:356
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition board.cpp:1560
const DRAWINGS & Drawings() const
Definition board.h:360
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:90
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:110
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:610
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:186
Generic, UI-independent tool event.
Definition tool_event.h:171
Handle a list of polygons defining a copper zone.
Definition zone.h:74
This file is part of the common library.
#define _(s)
@ Edge_Cuts
Definition layer_ids.h:112
@ F_Cu
Definition layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:737
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:97
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:93
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:92