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 <class_board.h>
33 #include <class_module.h>
34 #include <class_track.h>
35 #include <class_zone.h>
36 #include <tool/tool_manager.h>
37 #include <tools/pcb_actions.h>
38 #include <tools/global_edit_tool.h>
39 #include <dialog_global_deletion.h>
40 
41 
44 {
45  m_Parent = parent;
47  m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
48  m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
49  m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
50  m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
51  m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
52  m_ModuleFilterNormal->Enable( m_DelModules->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_TrackFilterAR->Enable( m_DelTracks->GetValue() );
81  m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
82  m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
83  m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
84 }
85 
86 
87 void DIALOG_GLOBAL_DELETION::OnCheckDeleteModules( wxCommandEvent& event )
88 {
89  m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
90  m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
91 }
92 
93 
95 {
96  bool gen_rastnest = false;
97 
98  // Clear selection before removing any items
100 
101  bool delAll = false;
102 
103  if( m_DelAlls->GetValue() )
104  {
105  if( !IsOK( this, _( "Are you sure you want to delete the entire board?" ) ) )
106  return;
107 
108  delAll = true;
109  }
110  else if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
111  return;
112 
113  BOARD* pcb = m_Parent->GetBoard();
114  BOARD_COMMIT commit( m_Parent );
115 
116  LSET layers_filter = LSET().set();
117 
118  if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
119  layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
120 
121  if( delAll || m_DelZones->GetValue() )
122  {
123  int area_index = 0;
124  auto item = pcb->GetArea( area_index );
125 
126  while( item )
127  {
128  if( delAll || layers_filter[item->GetLayer()] )
129  {
130  commit.Remove( item );
131  gen_rastnest = true;
132  }
133 
134  area_index++;
135  item = pcb->GetArea( area_index );
136  }
137  }
138 
139  bool delDrawings = m_DelDrawings->GetValue() || m_DelBoardEdges->GetValue();
140  bool delTexts = m_DelTexts->GetValue();
141 
142  if( delAll || delDrawings || delTexts )
143  {
144  // Layer mask for texts
145  LSET del_text_layers = layers_filter;
146 
147  // Layer mask for drawings
148  LSET masque_layer;
149 
150  if( m_DelDrawings->GetValue() )
151  masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
152 
153  if( m_DelBoardEdges->GetValue() )
154  masque_layer.set( Edge_Cuts );
155 
156  masque_layer &= layers_filter;
157 
158  for( auto dwg : pcb->Drawings() )
159  {
160  KICAD_T type = dwg->Type();
161  LAYER_NUM layer = dwg->GetLayer();
162 
163  if( delAll
164  || ( type == PCB_SHAPE_T && delDrawings && masque_layer[layer] )
165  || ( type == PCB_TEXT_T && delTexts && del_text_layers[layer] ) )
166  {
167  commit.Remove( dwg );
168  }
169  }
170  }
171 
172  if( delAll || m_DelModules->GetValue() )
173  {
174  for( auto item : pcb->Modules() )
175  {
176  bool del_fp = delAll;
177 
178  if( layers_filter[item->GetLayer()] &&
179  ( ( m_ModuleFilterNormal->GetValue() && !item->IsLocked() ) ||
180  ( m_ModuleFilterLocked->GetValue() && item->IsLocked() ) ) )
181  del_fp = true;
182 
183  if( del_fp )
184  {
185  commit.Remove( item );
186  gen_rastnest = true;
187  }
188  }
189  }
190 
191  if( delAll || m_DelTracks->GetValue() )
192  {
193  STATUS_FLAGS track_mask_filter = 0;
194 
195  if( !m_TrackFilterLocked->GetValue() )
196  track_mask_filter |= TRACK_LOCKED;
197 
198  if( !m_TrackFilterAR->GetValue() )
199  track_mask_filter |= TRACK_AR;
200 
201  for( auto track : pcb->Tracks() )
202  {
203  if( !delAll )
204  {
205  if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) & track_mask_filter ) != 0 )
206  continue;
207 
208  if( ( track->Type() == PCB_TRACE_T ) &&
209  ( 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:62
#define TRACK_AR
Pcbnew: autorouted track.
Definition: eda_item.h:121
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
void Compile_Ratsnest(bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
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()
Return a mask holding all layer minus CU layers.
Definition: lset.cpp:772
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
Definition: eda_item.h:120
void OnCheckDeleteTracks(wxCommandEvent &event) override
class PCB_TEXT, 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:141
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
PCB_BASE_EDIT_FRAME * frame() const
LSET is a set of PCB_LAYER_IDs.
MODULES & Modules()
Definition: class_board.h:284
void DeleteMARKERs()
Delete all MARKERS from the board.
TOOL_EVENT.
Definition: tool_event.h:171
unsigned STATUS_FLAGS
Definition: eda_item.h:141
void OnCheckDeleteModules(wxCommandEvent &event) override
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
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: class_board.h:186
#define _(s)
Definition: 3d_actions.cpp:33
void SetCurrentLayer(LAYER_NUM aLayer)
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:97
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
ZONE_CONTAINER * GetArea(int index) const
Return the Area (Zone Container) at a given index.
Definition: class_board.h:882
BOARD * GetBoard() const
class PCB_SHAPE, 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:284
DRAWINGS & Drawings()
Definition: class_board.h:287
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:897
TRACKS & Tracks()
Definition: class_board.h:281