KiCad PCB EDA Suite
dialog_unused_pad_layers.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) 2020 CERN
5  * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
26 
27 #include <bitmaps.h>
28 #include <board_commit.h>
29 #include <class_track.h>
30 #include <class_pad.h>
31 #include <pcb_edit_frame.h>
32 #include <tools/selection_tool.h>
33 
34 enum SCOPE : int
35 {
38 };
39 
40 
41 enum PAD_ACTION : int
42 {
45 };
46 
47 
49  const PCBNEW_SELECTION& aItems,
50  COMMIT& aCommit )
51  : DIALOG_UNUSED_PAD_LAYERS_BASE( aParent ),
52  m_frame( aParent ),
53  m_items( aItems ),
54  m_commit( aCommit )
55 {
56  m_StdButtonsOK->SetDefault();
57  m_image->SetBitmap( KiBitmap( pads_remove_unused_xpm ) );
58 
59  // Now all widgets have the size fixed, call FinishDialogSettings
61 }
62 
63 
64 void DIALOG_UNUSED_PAD_LAYERS::syncImages( wxCommandEvent& aEvent )
65 {
66  if( m_rbAction->GetSelection() == PAD_ACTION_RESET )
67  m_image->SetBitmap( KiBitmap( pads_reset_unused_xpm ) );
68  else if( m_cbPreservePads->IsChecked() )
70  else
71  m_image->SetBitmap( KiBitmap( pads_remove_unused_xpm ) );
72 }
73 
74 
75 void DIALOG_UNUSED_PAD_LAYERS::onScopeChange( wxCommandEvent& aEvent )
76 {
77  if( m_rbScope->GetSelection() == SCOPE_PADS )
78  {
79  m_cbPreservePads->SetValue( true );
80  m_cbPreservePads->Disable();
81  }
82  else
83  m_cbPreservePads->Enable();
84 
85  syncImages( aEvent );
86 }
87 
88 
90 {
91  if( m_cbSelectedOnly->IsChecked() )
92  {
93  for( auto item : m_items )
94  {
95  m_commit.Modify( item );
96 
97  if( item->Type() == PCB_VIA_T && m_rbScope->GetSelection() == SCOPE_VIAS )
98  {
99  VIA* via = static_cast<VIA*>( item );
100  via->SetRemoveUnconnected( m_rbAction->GetSelection() == PAD_ACTION_REMOVE );
101  via->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
102  }
103 
104  if( item->Type() == PCB_MODULE_T && m_rbScope->GetSelection() == SCOPE_PADS )
105  {
106  MODULE* mod = static_cast<MODULE*>( item );
107 
108  for( auto pad : mod->Pads() )
109  {
110  pad->SetRemoveUnconnected( m_rbAction->GetSelection() == PAD_ACTION_REMOVE );
111  pad->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
112  }
113  }
114 
115  if( item->Type() == PCB_PAD_T && m_rbScope->GetSelection() == SCOPE_PADS )
116  {
117  D_PAD* pad = static_cast<D_PAD*>( item );
118 
119  pad->SetRemoveUnconnected( m_rbAction->GetSelection() == PAD_ACTION_REMOVE );
120  pad->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
121  }
122  }
123  }
124  else
125  {
126  if( m_rbScope->GetSelection() == SCOPE_PADS )
127  {
128  for( auto item : m_frame->GetBoard()->Modules() )
129  {
130  m_commit.Modify( item );
131  MODULE* mod = static_cast<MODULE*>( item );
132 
133  for( auto pad : mod->Pads() )
134  {
135  pad->SetRemoveUnconnected( m_rbAction->GetSelection() == PAD_ACTION_REMOVE );
136  pad->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
137  }
138  }
139  }
140  else
141  {
142  for( auto item : m_frame->GetBoard()->Tracks() )
143  {
144  if( item->Type() != PCB_VIA_T )
145  continue;
146 
147  m_commit.Modify( item );
148  VIA* via = static_cast<VIA*>( item );
149  via->SetRemoveUnconnected( m_rbAction->GetSelection() == PAD_ACTION_REMOVE );
150  via->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
151  }
152  }
153  }
154 
155  m_commit.Push( _( "Set Unused Pad Properties" ) );
156  return true;
157 }
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
void SetRemoveUnconnected(bool aSet)
Sets the unconnected removal property.
Definition: class_pad.h:517
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
PADS & Pads()
Definition: class_module.h:181
const BITMAP_OPAQUE pads_reset_unused_xpm[1]
COMMIT.
Definition: commit.h:71
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void SetKeepTopBottom(bool aSet)
Sets whether we keep the top and bottom connections even if they are not connected.
Definition: class_pad.h:523
Class DIALOG_UNUSED_PAD_LAYERS_BASE.
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
const PCBNEW_SELECTION & m_items
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
class MODULE, a footprint
Definition: typeinfo.h:89
MODULES & Modules()
Definition: class_board.h:249
DIALOG_UNUSED_PAD_LAYERS(PCB_BASE_FRAME *aParent, const PCBNEW_SELECTION &aItems, COMMIT &aCommit)
const BITMAP_OPAQUE pads_remove_unused_keep_bottom_xpm[1]
Pad object description.
void syncImages(wxCommandEvent &aEvent) override
const BITMAP_OPAQUE pads_remove_unused_xpm[1]
void SetRemoveUnconnected(bool aSet)
Sets the unconnected removal property.
Definition: class_track.h:455
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true)=0
Executes the changes.
#define _(s)
Definition: 3d_actions.cpp:33
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
BOARD * GetBoard() const
void SetKeepTopBottom(bool aSet)
Sets whether we keep the top and bottom connections even if they are not connected.
Definition: class_track.h:461
void onScopeChange(wxCommandEvent &aEvent) override
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
TRACKS & Tracks()
Definition: class_board.h:246