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-2015 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>
25 using namespace std::placeholders;
26 
27 #include <confirm.h>
28 #include <pcbnew.h>
29 #include <pcb_edit_frame.h>
30 #include <ratsnest/ratsnest_data.h>
31 #include <board_commit.h>
32 #include <board.h>
33 #include <footprint.h>
34 #include <track.h>
35 #include <tool/tool_manager.h>
36 #include <tools/pcb_actions.h>
37 #include <tools/global_edit_tool.h>
38 #include <dialog_global_deletion.h>
39 
40 
43 {
44  m_Parent = parent;
46  m_trackFilterLocked->Enable( m_delTracks->GetValue() );
47  m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
48  m_trackFilterVias->Enable( m_delTracks->GetValue() );
49  m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
50  m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
51  m_drawingFilterLocked->Enable( m_delDrawings->GetValue() );
52  m_drawingFilterUnlocked->Enable( m_delDrawings->GetValue() );
53  m_sdbSizer1OK->SetDefault();
54  SetFocus();
55  GetSizer()->SetSizeHints( this );
56  Centre();
57 }
58 
59 
61 {
62  PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
63  DIALOG_GLOBAL_DELETION dlg( editFrame );
64 
65  dlg.SetCurrentLayer( frame()->GetActiveLayer() );
66  dlg.ShowModal();
67  return 0;
68 }
69 
70 
72 {
73  m_currentLayer = aLayer;
74  m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
75 }
76 
77 
78 void DIALOG_GLOBAL_DELETION::onCheckDeleteTracks( wxCommandEvent& event )
79 {
80  m_trackFilterLocked->Enable( m_delTracks->GetValue() );
81  m_trackFilterUnlocked->Enable( m_delTracks->GetValue() );
82  m_trackFilterVias->Enable( m_delTracks->GetValue() );
83 }
84 
85 
87 {
88  m_footprintFilterLocked->Enable( m_delFootprints->GetValue() );
89  m_footprintFilterUnlocked->Enable( m_delFootprints->GetValue() );
90 }
91 
92 
93 void DIALOG_GLOBAL_DELETION::onCheckDeleteDrawings( wxCommandEvent& event )
94 {
95  m_drawingFilterLocked->Enable( m_delDrawings->GetValue() );
96  m_drawingFilterUnlocked->Enable( m_delDrawings->GetValue() );
97 }
98 
99 
101 {
102  bool gen_rastnest = false;
103 
104  // Clear selection before removing any items
106 
107  bool delAll = false;
108 
109  if( m_delAll->GetValue() )
110  {
111  if( !IsOK( this, _( "Are you sure you want to delete the entire board?" ) ) )
112  return;
113 
114  delAll = true;
115  }
116  else if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
117  return;
118 
119  BOARD* pcb = m_Parent->GetBoard();
120  BOARD_COMMIT commit( m_Parent );
121 
122  LSET layers_filter = LSET().set();
123 
124  if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
125  layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
126 
127  if( delAll || m_delZones->GetValue() )
128  {
129  int area_index = 0;
130  auto item = pcb->GetArea( area_index );
131 
132  while( item )
133  {
134  if( delAll || layers_filter[item->GetLayer()] )
135  {
136  commit.Remove( item );
137  gen_rastnest = true;
138  }
139 
140  area_index++;
141  item = pcb->GetArea( area_index );
142  }
143  }
144 
145  bool delDrawings = m_delDrawings->GetValue() || m_delBoardEdges->GetValue();
146  bool delTexts = m_delTexts->GetValue();
147 
148  if( delAll || delDrawings || delTexts )
149  {
150  // Layer mask for texts
151  LSET del_text_layers = layers_filter;
152 
153  // Layer mask for drawings
154  LSET masque_layer;
155 
156  if( m_delDrawings->GetValue() )
157  masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
158 
159  if( m_delBoardEdges->GetValue() )
160  masque_layer.set( Edge_Cuts );
161 
162  masque_layer &= layers_filter;
163 
164  for( BOARD_ITEM* dwg : pcb->Drawings() )
165  {
166  KICAD_T type = dwg->Type();
167  LAYER_NUM layer = dwg->GetLayer();
168 
169  if( !delAll )
170  {
171  if( type == PCB_SHAPE_T )
172  {
173  if( !delDrawings || !masque_layer[layer] )
174  continue;
175 
176  if( layer == Edge_Cuts )
177  {
178  // We currently don't differentiate between locked and unlocked board
179  // edges. (If we did, we'd also need to add checkboxes to filter them
180  // as overloading m_drawingFilter* would be confusing.)
181  }
182  else
183  {
184  if( dwg->IsLocked() && !m_drawingFilterLocked->GetValue() )
185  continue;
186 
187  if( !dwg->IsLocked() && !m_drawingFilterUnlocked->GetValue() )
188  continue;
189  }
190  }
191  else if( type == PCB_TEXT_T )
192  {
193  if( !delTexts || !del_text_layers[layer] )
194  continue;
195  }
196  }
197 
198  commit.Remove( dwg );
199  }
200  }
201 
202  if( delAll || m_delFootprints->GetValue() )
203  {
204  for( FOOTPRINT* footprint : pcb->Footprints() )
205  {
206  if( !delAll )
207  {
208  if( footprint->IsLocked() && !m_footprintFilterLocked->GetValue() )
209  continue;
210 
211  if( !footprint->IsLocked() && !m_footprintFilterUnlocked->GetValue() )
212  continue;
213 
214  if( !layers_filter[footprint->GetLayer()] )
215  continue;
216  }
217 
218  commit.Remove( footprint );
219  gen_rastnest = true;
220  }
221  }
222 
223  if( delAll || m_delTracks->GetValue() )
224  {
225  for( TRACK* track : pcb->Tracks() )
226  {
227  if( !delAll )
228  {
229  if( track->Type() == PCB_TRACE_T )
230  {
231  if( track->IsLocked() && !m_trackFilterLocked->GetValue() )
232  continue;
233 
234  if( !track->IsLocked() && !m_trackFilterUnlocked->GetValue() )
235  continue;
236  }
237 
238  if( ( track->Type() == PCB_VIA_T ) && !m_trackFilterVias->GetValue() )
239  continue;
240 
241  if( ( track->GetLayerSet() & layers_filter ) == 0 )
242  continue;
243  }
244 
245  commit.Remove( track );
246  gen_rastnest = true;
247  }
248  }
249 
250  commit.Push( "Global delete" );
251 
252  if( m_delMarkers->GetValue() )
253  pcb->DeleteMARKERs();
254 
255  if( gen_rastnest )
256  m_Parent->Compile_Ratsnest( true );
257 
258  // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch
259  m_Parent->GetCanvas()->Refresh();
260 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:63
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:342
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:41
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
DIALOG_GLOBAL_DELETION(PCB_EDIT_FRAME *parent)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Class that computes missing connections on a PCB.
Class DIALOG_GLOBAL_DELETION_BASE.
static LSET AllNonCuMask()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:773
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
ZONE * GetArea(int index) const
Return the Zone at a given index.
Definition: board.h:904
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PCB_BASE_EDIT_FRAME * frame() const
LSET is a set of PCB_LAYER_IDs.
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:760
FOOTPRINTS & Footprints()
Definition: board.h:296
Generic, UI-independent tool event.
Definition: tool_event.h:173
void onCheckDeleteFootprints(wxCommandEvent &event) override
COMMIT & Remove(EDA_ITEM *aItem)
Notify observers that aItem has been removed.
Definition: commit.h:90
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int LAYER_NUM
This can be replaced with int and removed.
int GlobalDeletions(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:189
#define _(s)
Definition: 3d_actions.cpp:33
void SetCurrentLayer(LAYER_NUM aLayer)
The main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
void onCheckDeleteDrawings(wxCommandEvent &event) override
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
BOARD * GetBoard() const
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:297
DRAWINGS & Drawings()
Definition: board.h:299
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
TRACKS & Tracks()
Definition: board.h:293
Definition: track.h:83
void onCheckDeleteTracks(wxCommandEvent &event) override