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_track.h>
35#include <tool/tool_manager.h>
36#include <tools/pcb_actions.h>
39
40
43{
44 m_Parent = parent;
46 m_trackFilterLocked->Enable( m_delTracks->GetValue() );
47 m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
48 m_viaFilterLocked->Enable( m_delTracks->GetValue() );
49 m_viaFilterUnlocked->Enable( m_delTracks->GetValue() );
50 m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
51 m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
52 m_drawingFilterLocked->Enable( m_delDrawings->GetValue() );
53 m_drawingFilterUnlocked->Enable( m_delDrawings->GetValue() );
54
55 // This is a destructive dialog. Don't save control state; we always want to come up in a benign state.
56 OptOut( this );
57
59
60 SetFocus();
61 GetSizer()->SetSizeHints( this );
62 Centre();
63}
64
65
67{
68 PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
69 DIALOG_GLOBAL_DELETION dlg( editFrame );
70
71 dlg.SetCurrentLayer( frame()->GetActiveLayer() );
72
73 if( dlg.ShowModal() == wxID_OK )
75
76 return 0;
77}
78
79
81{
82 m_currentLayer = aLayer;
83 m_rbLayersOption->SetString( 1, wxString::Format( m_rbLayersOption->GetString( 1 ),
84 m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) ) );
85 m_rbLayersOption->SetSelection( 0 );
86}
87
88
90{
91 m_trackFilterLocked->Enable( m_delTracks->GetValue() );
92 m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
93 m_viaFilterLocked->Enable( m_delTracks->GetValue() );
94 m_viaFilterUnlocked->Enable( m_delTracks->GetValue() );
95}
96
97
99{
100 m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
101 m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
102}
103
104
106{
107 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
108
109 m_drawingFilterLocked->Enable( enable );
110 m_drawingFilterUnlocked->Enable( enable );
111}
112
113
115{
116 bool enable = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
117
118 m_drawingFilterLocked->Enable( enable );
119 m_drawingFilterUnlocked->Enable( enable );
120}
121
122
124{
125 bool gen_rastnest = false;
126 bool delete_all = m_delAll->GetValue();
127
128 // Clear selection before removing any items
130
131 BOARD* board = m_Parent->GetBoard();
132 BOARD_COMMIT commit( m_Parent );
133 LSET all_layers = LSET().set();
134 LSET layers_filter;
135
136 if( m_rbLayersOption->GetSelection() != 0 )
137 layers_filter.set( m_currentLayer );
138 else
139 layers_filter = all_layers;
140
141 auto processItem =
142 [&]( BOARD_ITEM* item, const LSET& layers_mask )
143 {
144 if( ( item->GetLayerSet() & layers_mask ).any() )
145 commit.Remove( item );
146 };
147
148 auto processConnectedItem =
149 [&]( BOARD_ITEM* item, const LSET& layers_mask )
150 {
151 if( ( item->GetLayerSet() & layers_mask ).any() )
152 {
153 commit.Remove( item );
154 gen_rastnest = true;
155 }
156 };
157
158 for( ZONE* zone : board->Zones() )
159 {
160 if( delete_all )
161 {
162 processConnectedItem( zone, all_layers );
163 }
164 else if( zone->IsTeardropArea() )
165 {
166 if( m_delTeardrops->GetValue() )
167 processConnectedItem( zone, layers_filter );
168 }
169 else
170 {
171 if( m_delZones->GetValue() )
172 processConnectedItem( zone, layers_filter );
173 }
174 }
175
176 bool delete_shapes = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
177 bool delete_texts = m_delTexts->GetValue();
178
179 if( delete_all || delete_shapes || delete_texts )
180 {
181 // Layer mask for drawings
182 LSET drawing_layers_filter;
183
184 if( m_delDrawings->GetValue() )
185 drawing_layers_filter = LSET::AllNonCuMask().set( Edge_Cuts, false );
186
187 if( m_delBoardEdges->GetValue() )
188 drawing_layers_filter.set( Edge_Cuts );
189
190 drawing_layers_filter &= layers_filter;
191
192 for( BOARD_ITEM* item : board->Drawings() )
193 {
194 if( delete_all )
195 {
196 processItem( item, all_layers );
197 }
198 else if( delete_shapes )
199 {
200 if( item->Type() == PCB_SHAPE_T && item->IsLocked() )
201 {
202 if( m_drawingFilterLocked->GetValue() )
203 processItem( item, drawing_layers_filter );
204 }
205 else if( item->Type() == PCB_SHAPE_T && !item->IsLocked() )
206 {
207 if( m_drawingFilterUnlocked->GetValue() )
208 processItem( item, drawing_layers_filter );
209 }
210 }
211 else if( delete_texts )
212 {
213 if( item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T )
214 processItem( item, layers_filter );
215 }
216 }
217 }
218
219 if( delete_all || m_delFootprints->GetValue() )
220 {
221 for( FOOTPRINT* footprint : board->Footprints() )
222 {
223 if( delete_all )
224 {
225 processConnectedItem( footprint, all_layers );
226 }
227 else if( footprint->IsLocked() )
228 {
229 if( m_footprintFilterLocked->GetValue() )
230 processConnectedItem( footprint, layers_filter );
231 }
232 else
233 {
234 if( m_footprintFilterUnlocked->GetValue() )
235 processConnectedItem( footprint, layers_filter );
236 }
237 }
238 }
239
240 if( delete_all || m_delTracks->GetValue() )
241 {
242 for( PCB_TRACK* track : board->Tracks() )
243 {
244 if( delete_all )
245 {
246 processConnectedItem( track, all_layers );
247 }
248 else if( track->Type() == PCB_VIA_T )
249 {
250 if( track->IsLocked() )
251 {
252 if( m_viaFilterLocked->GetValue() )
253 processConnectedItem( track, layers_filter );
254 }
255 else
256 {
257 if( m_viaFilterUnlocked->GetValue() )
258 processConnectedItem( track, layers_filter );
259 }
260 }
261 else
262 {
263 if( track->IsLocked() )
264 {
265 if( m_trackFilterLocked->GetValue() )
266 processConnectedItem( track, layers_filter );
267 }
268 else
269 {
270 if( m_trackFilterUnlocked->GetValue() )
271 processConnectedItem( track, layers_filter );
272 }
273 }
274 }
275 }
276
277 commit.Push( _( "Global Delete" ) );
278
279 if( m_delMarkers->GetValue() )
280 board->DeleteMARKERs();
281
282 if( gen_rastnest )
283 m_Parent->Compile_Ratsnest( true );
284
285 // There is a chance that some of tracks have changed their nets, so rebuild ratsnest
286 // from scratch.
288}
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:221
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
Definition: board_item.cpp:103
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 ZONES & Zones() const
Definition: board.h:362
const FOOTPRINTS & Footprints() const
Definition: board.h:358
const TRACKS & Tracks() const
Definition: board.h:356
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:680
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:1530
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:91
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 OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
int ShowModal() override
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) 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
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.
T * frame() const
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
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:744
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