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 <fctsys.h>
28 #include <confirm.h>
29 #include <pcbnew.h>
30 #include <pcb_edit_frame.h>
31 #include <ratsnest_data.h>
32 #include <board_commit.h>
33 #include <class_board.h>
34 #include <class_module.h>
35 #include <class_track.h>
36 #include <class_zone.h>
37 #include <tool/tool_manager.h>
38 #include <tools/pcb_actions.h>
39 #include <tools/global_edit_tool.h>
40 #include <dialog_global_deletion.h>
41 
42 
45 {
46  m_Parent = parent;
48  m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
49  m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
50  m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
51  m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
52  m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
53  m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
54  m_sdbSizer1OK->SetDefault();
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  dlg.ShowModal();
68  return 0;
69 }
70 
71 
73 {
74  m_currentLayer = aLayer;
75  m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
76 }
77 
78 
79 void DIALOG_GLOBAL_DELETION::OnCheckDeleteTracks( wxCommandEvent& event )
80 {
81  m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
82  m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
83  m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
84  m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
85 }
86 
87 
88 void DIALOG_GLOBAL_DELETION::OnCheckDeleteModules( wxCommandEvent& event )
89 {
90  m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
91  m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
92 }
93 
94 
96 {
97  bool gen_rastnest = false;
98 
99  // Clear selection before removing any items
101 
102  bool delAll = false;
103 
104  if( m_DelAlls->GetValue() )
105  {
106  if( !IsOK( this, _( "Are you sure you want to delete the entire board?" ) ) )
107  return;
108 
109  delAll = true;
110  }
111  else if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
112  return;
113 
114  BOARD* pcb = m_Parent->GetBoard();
115  BOARD_COMMIT commit( m_Parent );
116 
117  LSET layers_filter = LSET().set();
118 
119  if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
120  layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
121 
122  if( delAll || m_DelZones->GetValue() )
123  {
124  int area_index = 0;
125  auto item = pcb->GetArea( area_index );
126 
127  while( item )
128  {
129  if( delAll || layers_filter[item->GetLayer()] )
130  {
131  commit.Remove( item );
132  gen_rastnest = true;
133  }
134 
135  area_index++;
136  item = pcb->GetArea( area_index );
137  }
138  }
139 
140  bool delDrawings = m_DelDrawings->GetValue() || m_DelBoardEdges->GetValue();
141  bool delTexts = m_DelTexts->GetValue();
142 
143  if( delAll || delDrawings || delTexts )
144  {
145  // Layer mask for texts
146  LSET del_text_layers = layers_filter;
147 
148  // Layer mask for drawings
149  LSET masque_layer;
150 
151  if( m_DelDrawings->GetValue() )
152  masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
153 
154  if( m_DelBoardEdges->GetValue() )
155  masque_layer.set( Edge_Cuts );
156 
157  masque_layer &= layers_filter;
158 
159  for( auto dwg : pcb->Drawings() )
160  {
161  KICAD_T type = dwg->Type();
162  LAYER_NUM layer = dwg->GetLayer();
163 
164  if( delAll
165  || ( type == PCB_LINE_T && delDrawings && masque_layer[layer] )
166  || ( type == PCB_TEXT_T && delTexts && del_text_layers[layer] ) )
167  {
168  commit.Remove( dwg );
169  }
170  }
171  }
172 
173  if( delAll || m_DelModules->GetValue() )
174  {
175  for( auto item : pcb->Modules() )
176  {
177  bool del_fp = delAll;
178 
179  if( layers_filter[item->GetLayer()] &&
180  ( ( m_ModuleFilterNormal->GetValue() && !item->IsLocked() ) ||
181  ( m_ModuleFilterLocked->GetValue() && item->IsLocked() ) ) )
182  del_fp = true;
183 
184  if( del_fp )
185  {
186  commit.Remove( item );
187  gen_rastnest = true;
188  }
189  }
190  }
191 
192  if( delAll || m_DelTracks->GetValue() )
193  {
194  STATUS_FLAGS track_mask_filter = 0;
195 
196  if( !m_TrackFilterLocked->GetValue() )
197  track_mask_filter |= TRACK_LOCKED;
198 
199  if( !m_TrackFilterAR->GetValue() )
200  track_mask_filter |= TRACK_AR;
201 
202  for( auto track : pcb->Tracks() )
203  {
204  if( !delAll )
205  {
206  if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) & track_mask_filter ) != 0 )
207  continue;
208 
209  if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) == 0 ) &&
210  !m_TrackFilterNormal->GetValue() )
211  continue;
212 
213  if( ( track->Type() == PCB_VIA_T ) && !m_TrackFilterVias->GetValue() )
214  continue;
215 
216  if( ( track->GetLayerSet() & layers_filter ) == 0 )
217  continue;
218  }
219 
220  commit.Remove( track );
221  gen_rastnest = true;
222  }
223  }
224 
225  commit.Push( "Global delete" );
226 
227  if( m_DelMarkers->GetValue() )
228  pcb->DeleteMARKERs();
229 
230  if( gen_rastnest )
231  m_Parent->Compile_Ratsnest( true );
232 
233  // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch
234  m_Parent->GetCanvas()->Refresh();
235 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
void Compile_Ratsnest(bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:44
This file is part of the common library.
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()
Function AllNonCuMask returns a mask holding all layer minus CU layers.
Definition: lset.cpp:699
void OnCheckDeleteTracks(wxCommandEvent &event) override
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
Definitions for tracks, vias and zones.
PCB_BASE_EDIT_FRAME * frame() const
Class LSET is a set of PCB_LAYER_IDs.
MODULES & Modules()
Definition: class_board.h:236
void DeleteMARKERs()
Function DeleteMARKERs deletes ALL MARKERS from the board.
Class TOOL_EVENT.
Definition: tool_event.h:168
unsigned STATUS_FLAGS
Definition: base_struct.h:156
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
Definition: base_struct.h:134
void OnCheckDeleteModules(wxCommandEvent &event) override
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
#define _(s)
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...
#define TRACK_AR
Pcbnew: autorouted track.
Definition: base_struct.h:135
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
int GlobalDeletions(const TOOL_EVENT &aEvent)
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
void SetCurrentLayer(LAYER_NUM aLayer)
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
Module description (excepted pads)
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:926
BOARD * GetBoard() const
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:281
DRAWINGS & Drawings()
Definition: class_board.h:245
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
TRACKS & Tracks()
Definition: class_board.h:227