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 <class_drawpanel.h>
29 #include <confirm.h>
30 #include <pcbnew.h>
31 #include <wxPcbStruct.h>
32 #include <ratsnest_data.h>
33 #include <board_commit.h>
34 
35 #include <class_board.h>
36 #include <class_module.h>
37 #include <class_track.h>
38 #include <class_zone.h>
39 
40 #include <tool/tool_manager.h>
41 #include <tools/pcb_actions.h>
42 
43 #include <dialog_global_deletion.h>
44 
45 
48 {
49  m_Parent = parent;
51  m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
52  m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
53  m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
54  m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
55  m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
56  m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
57  m_sdbSizer1OK->SetDefault();
58  SetFocus();
59  GetSizer()->SetSizeHints( this );
60  Centre();
61 }
62 
63 
65 {
66  DIALOG_GLOBAL_DELETION dlg( this );
68 
69  dlg.ShowModal();
70 }
71 
72 
74 {
75  m_currentLayer = aLayer;
76  m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
77 }
78 
79 
80 void DIALOG_GLOBAL_DELETION::OnCheckDeleteTracks( wxCommandEvent& event )
81 {
82  m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
83  m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
84  m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
85  m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
86 }
87 
88 
89 void DIALOG_GLOBAL_DELETION::OnCheckDeleteModules( wxCommandEvent& event )
90 {
91  m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
92  m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
93 }
94 
95 
97 {
98  bool gen_rastnest = false;
99 
100  // Clear selection before removing any items
102 
103  m_Parent->SetCurItem( NULL );
104 
105  bool delAll = false;
106 
107  if( m_DelAlls->GetValue() )
108  {
109  if( !IsOK( this, _( "Are you sure you want to delete the entire board?" ) ) )
110  return;
111 
112  delAll = true;
113  }
114  else if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
115  return;
116 
117  BOARD* pcb = m_Parent->GetBoard();
118  BOARD_COMMIT commit( m_Parent );
119  BOARD_ITEM* item;
120 
121  LSET layers_filter = LSET().set();
122 
123  if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
124  layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
125 
126  if( delAll || m_DelZones->GetValue() )
127  {
128  int area_index = 0;
129  item = pcb->GetArea( area_index );
130 
131  while( item )
132  {
133  if( delAll || layers_filter[item->GetLayer()] )
134  {
135  commit.Remove( item );
136  gen_rastnest = true;
137  }
138 
139  area_index++;
140  item = pcb->GetArea( area_index );
141  }
142  }
143 
144  bool delDrawings = m_DelDrawings->GetValue() || m_DelBoardEdges->GetValue();
145  bool delTexts = m_DelTexts->GetValue();
146 
147  if( delAll || delDrawings || delTexts )
148  {
149  // Layer mask for texts
150  LSET del_text_layers = layers_filter;
151 
152  // Layer mask for drawings
153  LSET masque_layer;
154 
155  if( m_DelDrawings->GetValue() )
156  masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
157 
158  if( m_DelBoardEdges->GetValue() )
159  masque_layer.set( Edge_Cuts );
160 
161  masque_layer &= layers_filter;
162 
163  for( auto dwg : pcb->Drawings() )
164  {
165  KICAD_T type = dwg->Type();
166  LAYER_NUM layer = dwg->GetLayer();
167 
168  if( delAll
169  || ( type == PCB_LINE_T && delDrawings && masque_layer[layer] )
170  || ( type == PCB_TEXT_T && delTexts && del_text_layers[layer] ) )
171  {
172  commit.Remove( dwg );
173  }
174  }
175  }
176 
177  if( delAll || m_DelModules->GetValue() )
178  {
179  for( item = pcb->m_Modules; item; item = item->Next() )
180  {
181  bool del_fp = delAll;
182 
183  if( layers_filter[item->GetLayer()] &&
184  ( ( m_ModuleFilterNormal->GetValue() && !item->IsLocked() ) ||
185  ( m_ModuleFilterLocked->GetValue() && item->IsLocked() ) ) )
186  del_fp = true;
187 
188  if( del_fp )
189  {
190  commit.Remove( item );
191  gen_rastnest = true;
192  }
193  }
194  }
195 
196  if( delAll || m_DelTracks->GetValue() )
197  {
198  STATUS_FLAGS track_mask_filter = 0;
199 
200  if( !m_TrackFilterLocked->GetValue() )
201  track_mask_filter |= TRACK_LOCKED;
202 
203  if( !m_TrackFilterAR->GetValue() )
204  track_mask_filter |= TRACK_AR;
205 
206  TRACK* nexttrack;
207 
208  for( TRACK *track = pcb->m_Track; track; track = nexttrack )
209  {
210  nexttrack = track->Next();
211 
212  if( !delAll )
213  {
214  if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) & track_mask_filter ) != 0 )
215  continue;
216 
217  if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) == 0 ) &&
218  !m_TrackFilterNormal->GetValue() )
219  continue;
220 
221  if( ( track->Type() == PCB_VIA_T ) && !m_TrackFilterVias->GetValue() )
222  continue;
223 
224  if( ( track->GetLayerSet() & layers_filter ) == 0 )
225  continue;
226  }
227 
228  commit.Remove( track );
229  gen_rastnest = true;
230  }
231  }
232 
233  commit.Push( "Global delete" );
234 
235  if( m_DelMarkers->GetValue() )
236  pcb->DeleteMARKERs();
237 
238  if( gen_rastnest )
239  m_Parent->Compile_Ratsnest( NULL, true );
240 
241  // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch
242  m_Parent->GetCanvas()->Refresh();
243 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
void InstallPcbGlobalDeleteFrame(const wxPoint &pos)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:326
This file is part of the common library.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
DIALOG_GLOBAL_DELETION(PCB_EDIT_FRAME *parent)
Class BOARD to handle a board.
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:662
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
void OnCheckDeleteTracks(wxCommandEvent &event) override
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:104
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
Classes to handle copper zones.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true) override
Executes the changes.
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
Functions relatives to tracks, vias and segments used to fill zones.
BOARD_ITEM * Next() const
Class LSET is a set of PCB_LAYER_IDs.
void DeleteMARKERs()
Function DeleteMARKERs deletes ALL MARKERS from the board.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
unsigned STATUS_FLAGS
Definition: base_struct.h:144
#define TRACK_LOCKED
Pcbnew: track locked: protected from global deletion.
Definition: base_struct.h:128
void OnCheckDeleteModules(wxCommandEvent &event) override
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
#define TRACK_AR
Pcbnew: autorouted track.
Definition: base_struct.h:129
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void Compile_Ratsnest(wxDC *aDC, bool aDisplayStatus)
Function Compile_Ratsnest Create the entire board ratsnest.
Definition: ratsnest.cpp:56
TOOL_MANAGER * GetToolManager() const
Function GetToolManager returns the tool manager instance, if any.
Definition: draw_frame.h:838
PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
TRACK * Next() const
Definition: class_track.h:98
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
virtual bool IsLocked() const
Function IsLocked.
DLIST< MODULE > m_Modules
Definition: class_board.h:245
void SetCurrentLayer(LAYER_NUM aLayer)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:108
DLIST< TRACK > m_Track
Definition: class_board.h:246
Module description (excepted pads)
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:103
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Function IsOK displays a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:129
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:767
DLIST_ITERATOR_WRAPPER< BOARD_ITEM > Drawings()
Definition: class_board.h:251