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 (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 // Clear selection before removing any items
122
123 BOARD* board = m_Parent->GetBoard();
124 BOARD_COMMIT commit( m_Parent );
125 LSET all_layers = LSET().set();
126 LSET layers_filter;
127
128 if( m_rbLayersOption->GetSelection() != 0 )
129 layers_filter.set( m_currentLayer );
130 else
131 layers_filter = all_layers;
132
133 auto processItem =
134 [&]( BOARD_ITEM* item, const LSET& layers_mask )
135 {
136 if( ( item->GetLayerSet() & layers_mask ).any() )
137 commit.Remove( item );
138 };
139
140 auto processConnectedItem =
141 [&]( BOARD_ITEM* item, const LSET& layers_mask )
142 {
143 if( ( item->GetLayerSet() & layers_mask ).any() )
144 {
145 commit.Remove( item );
146 gen_rastnest = true;
147 }
148 };
149
150 for( ZONE* zone : board->Zones() )
151 {
152 if( delete_all )
153 {
154 processConnectedItem( zone, all_layers );
155 }
156 else if( zone->IsTeardropArea() )
157 {
158 if( m_delTeardrops->GetValue() )
159 processConnectedItem( zone, layers_filter );
160 }
161 else
162 {
163 if( m_delZones->GetValue() )
164 processConnectedItem( zone, layers_filter );
165 }
166 }
167
168 bool delete_shapes = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
169 bool delete_texts = m_delTexts->GetValue();
170
171 if( delete_all || delete_shapes || delete_texts )
172 {
173 // Layer mask for drawings
174 LSET drawing_layers_filter;
175
176 if( m_delDrawings->GetValue() )
177 drawing_layers_filter = LSET::AllNonCuMask().set( Edge_Cuts, false );
178
179 if( m_delBoardEdges->GetValue() )
180 drawing_layers_filter.set( Edge_Cuts );
181
182 drawing_layers_filter &= layers_filter;
183
184 for( BOARD_ITEM* item : board->Drawings() )
185 {
186 if( delete_all )
187 {
188 processItem( item, all_layers );
189 }
190 else if( delete_shapes )
191 {
192 if( item->Type() == PCB_SHAPE_T && item->IsLocked() )
193 {
194 if( m_drawingFilterLocked->GetValue() )
195 processItem( item, drawing_layers_filter );
196 }
197 else if( item->Type() == PCB_SHAPE_T && !item->IsLocked() )
198 {
199 if( m_drawingFilterUnlocked->GetValue() )
200 processItem( item, drawing_layers_filter );
201 }
202 }
203 else if( delete_texts )
204 {
205 if( item->Type() == PCB_TEXT_T || item->Type() == PCB_TEXTBOX_T )
206 processItem( item, layers_filter );
207 }
208 }
209 }
210
211 if( delete_all || m_delFootprints->GetValue() )
212 {
213 for( FOOTPRINT* footprint : board->Footprints() )
214 {
215 if( delete_all )
216 {
217 processConnectedItem( footprint, all_layers );
218 }
219 else if( footprint->IsLocked() )
220 {
221 if( m_footprintFilterLocked->GetValue() )
222 processConnectedItem( footprint, layers_filter );
223 }
224 else
225 {
226 if( m_footprintFilterUnlocked->GetValue() )
227 processConnectedItem( footprint, layers_filter );
228 }
229 }
230 }
231
232 if( delete_all || m_delTracks->GetValue() )
233 {
234 for( PCB_TRACK* track : board->Tracks() )
235 {
236 if( delete_all )
237 {
238 processConnectedItem( track, all_layers );
239 }
240 else if( track->Type() == PCB_VIA_T )
241 {
242 if( m_trackFilterVias->GetValue() )
243 processConnectedItem( track, layers_filter );
244 }
245 else if( track->IsLocked() )
246 {
247 if( m_trackFilterLocked->GetValue() )
248 processConnectedItem( track, layers_filter );
249 }
250 else
251 {
252 if( m_trackFilterUnlocked->GetValue() )
253 processConnectedItem( track, layers_filter );
254 }
255 }
256 }
257
258 commit.Push( wxT( "Global delete" ) );
259
260 if( m_delMarkers->GetValue() )
261 board->DeleteMARKERs();
262
263 if( gen_rastnest )
264 m_Parent->Compile_Ratsnest( true );
265
266 // There is a chance that some of tracks have changed their nets, so rebuild ratsnest
267 // from scratch.
269}
virtual void Push(const wxString &aMessage=wxEmptyString, 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:77
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:231
virtual bool IsLocked() const
Definition: board_item.cpp:74
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
const ZONES & Zones() const
Definition: board.h:326
const FOOTPRINTS & Footprints() const
Definition: board.h:322
const TRACKS & Tracks() const
Definition: board.h:320
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:567
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:1239
const DRAWINGS & Drawings() const
Definition: board.h:324
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been removed.
Definition: commit.h:92
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
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
int GlobalDeletions(const TOOL_EVENT &aEvent)
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:574
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:884
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
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:55
Generic, UI-independent tool event.
Definition: tool_event.h:167
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:145
Handle a list of polygons defining a copper zone.
Definition: zone.h:72
This file is part of the common library.
@ Edge_Cuts
Definition: layer_ids.h:113
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:1022
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