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 <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  DIALOG_GLOBAL_DELETION dlg( this );
65 
66  dlg.ShowModal();
67 }
68 
69 
71 {
72  m_currentLayer = aLayer;
73  m_textCtrlCurrLayer->SetValue( m_Parent->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) ) );
74 }
75 
76 
77 void DIALOG_GLOBAL_DELETION::OnCheckDeleteTracks( wxCommandEvent& event )
78 {
79  m_TrackFilterAR->Enable( m_DelTracks->GetValue() );
80  m_TrackFilterLocked->Enable( m_DelTracks->GetValue() );
81  m_TrackFilterNormal->Enable( m_DelTracks->GetValue() );
82  m_TrackFilterVias->Enable( m_DelTracks->GetValue() );
83 }
84 
85 
86 void DIALOG_GLOBAL_DELETION::OnCheckDeleteModules( wxCommandEvent& event )
87 {
88  m_ModuleFilterLocked->Enable( m_DelModules->GetValue() );
89  m_ModuleFilterNormal->Enable( m_DelModules->GetValue() );
90 }
91 
92 
94 {
95  bool gen_rastnest = false;
96 
97  m_Parent->SetCurItem( NULL );
98 
99  bool delAll = false;
100 
101  if( m_DelAlls->GetValue() )
102  {
103  if( !IsOK( this, _( "Are you sure you want to delete the entire board?" ) ) )
104  return;
105 
106  delAll = true;
107  }
108  else if( !IsOK( this, _( "Are you sure you want to delete the selected items?" ) ) )
109  return;
110 
111  BOARD* pcb = m_Parent->GetBoard();
112  BOARD_COMMIT commit( m_Parent );
113  BOARD_ITEM* item;
114 
115  LSET layers_filter = LSET().set();
116 
117  if( m_rbLayersOption->GetSelection() != 0 ) // Use current layer only
118  layers_filter = LSET( ToLAYER_ID( m_currentLayer ) );
119 
120  if( delAll || m_DelZones->GetValue() )
121  {
122  int area_index = 0;
123  item = pcb->GetArea( area_index );
124 
125  while( item )
126  {
127  if( delAll || layers_filter[item->GetLayer()] )
128  {
129  commit.Remove( item );
130  gen_rastnest = true;
131  }
132 
133  area_index++;
134  item = pcb->GetArea( area_index );
135  }
136  }
137 
138  bool delDrawings = m_DelDrawings->GetValue() || m_DelBoardEdges->GetValue();
139  bool delTexts = m_DelTexts->GetValue();
140 
141  if( delAll || delDrawings || delTexts )
142  {
143  // Layer mask for texts
144  LSET del_text_layers = layers_filter;
145 
146  // Layer mask for drawings
147  LSET masque_layer;
148 
149  if( m_DelDrawings->GetValue() )
150  masque_layer = LSET::AllNonCuMask().set( Edge_Cuts, false );
151 
152  if( m_DelBoardEdges->GetValue() )
153  masque_layer.set( Edge_Cuts );
154 
155  masque_layer &= layers_filter;
156 
157  for( item = pcb->m_Drawings; item; item = item->Next() )
158  {
159  KICAD_T type = item->Type();
160  LAYER_NUM layer = item->GetLayer();
161 
162  if( delAll
163  || ( type == PCB_LINE_T && delDrawings && masque_layer[layer] )
164  || ( type == PCB_TEXT_T && delTexts && del_text_layers[layer] ) )
165  {
166  commit.Remove( item );
167  }
168  }
169  }
170 
171  if( delAll || m_DelModules->GetValue() )
172  {
173  for( item = pcb->m_Modules; item; item = item->Next() )
174  {
175  bool del_fp = delAll;
176 
177  if( layers_filter[item->GetLayer()] &&
178  ( ( m_ModuleFilterNormal->GetValue() && !item->IsLocked() ) ||
179  ( m_ModuleFilterLocked->GetValue() && item->IsLocked() ) ) )
180  del_fp = true;
181 
182  if( del_fp )
183  {
184  commit.Remove( item );
185  gen_rastnest = true;
186  }
187  }
188  }
189 
190  if( delAll || m_DelTracks->GetValue() )
191  {
192  STATUS_FLAGS track_mask_filter = 0;
193 
194  if( !m_TrackFilterLocked->GetValue() )
195  track_mask_filter |= TRACK_LOCKED;
196 
197  if( !m_TrackFilterAR->GetValue() )
198  track_mask_filter |= TRACK_AR;
199 
200  TRACK* nexttrack;
201 
202  for( TRACK *track = pcb->m_Track; track; track = nexttrack )
203  {
204  nexttrack = track->Next();
205 
206  if( !delAll )
207  {
208  if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) & track_mask_filter ) != 0 )
209  continue;
210 
211  if( ( track->GetState( TRACK_LOCKED | TRACK_AR ) == 0 ) &&
212  !m_TrackFilterNormal->GetValue() )
213  continue;
214 
215  if( ( track->Type() == PCB_VIA_T ) && !m_TrackFilterVias->GetValue() )
216  continue;
217 
218  if( ( track->GetLayerSet() & layers_filter ) == 0 )
219  continue;
220  }
221 
222  commit.Remove( track );
223  gen_rastnest = true;
224  }
225  }
226 
227  commit.Push( "Global delete" );
228 
229  if( m_DelMarkers->GetValue() )
230  pcb->DeleteMARKERs();
231 
232  if( gen_rastnest )
233  m_Parent->Compile_Ratsnest( NULL, true );
234 
235  // There is a chance that some of tracks have changed their nets, so rebuild ratsnest from scratch
236  if( m_Parent->IsGalCanvasActive() )
237  pcb->GetRatsnest()->ProcessBoard();
238  else
239  m_Parent->GetCanvas()->Refresh();
240 
241 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
void InstallPcbGlobalDeleteFrame(const wxPoint &pos)
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
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
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.
void ProcessBoard()
Function ProcessBoard() Prepares data for computing (computes a list of current nodes and connections...
unsigned STATUS_FLAGS
Definition: base_struct.h:144
DLIST< BOARD_ITEM > m_Drawings
Definition: class_board.h:242
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:795
#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
RN_DATA * GetRatsnest() const
Function GetRatsnest() returns list of missing connections between components/tracks.
Definition: class_board.h:287
#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:165
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:1022
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
virtual bool IsLocked() const
Function IsLocked.
DLIST< MODULE > m_Modules
Definition: class_board.h:243
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:244
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:111
virtual PCB_LAYER_ID GetActiveLayer() const
Function GetActiveLayer returns the active layer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:767