KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <bitmaps.h>
24#include <board_commit.h>
25#include <footprint.h>
26#include <pcb_track.h>
27#include <pad.h>
28#include <pcb_edit_frame.h>
30
31
33 const PCB_SELECTION& aItems,
34 COMMIT& aCommit )
36 m_frame( aParent ),
37 m_items( aItems ),
38 m_commit( aCommit )
39{
41
42 // Set keep Through Hole pads on external layers ON by default.
43 // Because such a pad does not allow soldering/unsoldering, disable this option
44 // is probably not frequent
45 m_cbPreserveExternalLayers->SetValue( true );
46
47 SetupStandardButtons( { { wxID_OK, _( "Remove Unused Layers" ) },
48 { wxID_APPLY, _( "Restore All Layers" ) },
49 { wxID_CANCEL, _( "Cancel" ) } } );
50
52
53 // Now all widgets have the size fixed, call FinishDialogSettings
55}
56
57
65
66
67void DIALOG_UNUSED_PAD_LAYERS::syncImages( wxCommandEvent& aEvent )
68{
70}
71
72
73void DIALOG_UNUSED_PAD_LAYERS::onApply( wxCommandEvent& event )
74{
75 updatePadsAndVias( false );
76 EndModal( wxID_APPLY );
77}
78
79
80void DIALOG_UNUSED_PAD_LAYERS::onOK( wxCommandEvent& event )
81{
82 updatePadsAndVias( true ); // called only with wxID_OK
83 event.Skip();
84}
85
86
88{
89 auto viaHasPotentiallyUnusedLayers =
90 [&]( PCB_VIA* via )
91 {
92 if( via->GetViaType() == VIATYPE::THROUGH )
93 return m_frame->GetBoard()->GetCopperLayerCount() > 2;
94
95 PCB_LAYER_ID startLayer = via->Padstack().StartLayer();
96 PCB_LAYER_ID endLayer = via->Padstack().EndLayer();
97
98 if( startLayer < 0 || endLayer < 0 )
99 return m_frame->GetBoard()->GetCopperLayerCount() > 2;
100 else
101 return m_frame->GetBoard()->LayerDepth( startLayer, endLayer ) > 1;
102 };
103
104 auto padHasPotentiallyUnusedLayers =
105 [&]( PAD* pad )
106 {
107 return pad->GetAttribute() == PAD_ATTRIB::PTH;
108 };
109
110 if( m_cbSelectedOnly->IsChecked() )
111 {
112 for( EDA_ITEM* item : m_items )
113 {
114 m_commit.Modify( item );
115
116 if( item->Type() == PCB_VIA_T && m_cbVias->IsChecked() )
117 {
118 PCB_VIA* via = static_cast<PCB_VIA*>( item );
119
120 if( viaHasPotentiallyUnusedLayers( via ) )
121 {
122 via->SetRemoveUnconnected( aRemoveLayers );
123
124 if( aRemoveLayers )
125 via->SetKeepStartEnd( m_cbPreserveExternalLayers->IsChecked() );
126 }
127 }
128
129 if( item->Type() == PCB_FOOTPRINT_T && m_cbPads->IsChecked() )
130 {
131 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
132
133 for( PAD* pad : footprint->Pads() )
134 {
135 if( padHasPotentiallyUnusedLayers( pad ) )
136 {
137 pad->SetRemoveUnconnected( aRemoveLayers );
138
139 if( aRemoveLayers )
140 pad->SetKeepTopBottom( m_cbPreserveExternalLayers->IsChecked() );
141 }
142 }
143 }
144
145 if( item->Type() == PCB_PAD_T && m_cbPads->IsChecked() )
146 {
147 PAD* pad = static_cast<PAD*>( item );
148
149 if( padHasPotentiallyUnusedLayers( pad ) )
150 {
151 pad->SetRemoveUnconnected( aRemoveLayers );
152
153 if( aRemoveLayers )
154 pad->SetKeepTopBottom( m_cbPreserveExternalLayers->IsChecked() );
155 }
156 }
157 }
158 }
159 else
160 {
161 if( m_cbPads->IsChecked() )
162 {
163 for( FOOTPRINT* footprint : m_frame->GetBoard()->Footprints() )
164 {
165 m_commit.Modify( footprint );
166
167 for( PAD* pad : footprint->Pads() )
168 {
169 if( padHasPotentiallyUnusedLayers( pad ) )
170 {
171 pad->SetRemoveUnconnected( aRemoveLayers );
172
173 if( aRemoveLayers )
174 pad->SetKeepTopBottom( m_cbPreserveExternalLayers->IsChecked() );
175 }
176 }
177 }
178 }
179
180 if( m_cbVias->IsChecked() )
181 {
182 for( PCB_TRACK* item : m_frame->GetBoard()->Tracks() )
183 {
184 if( item->Type() != PCB_VIA_T )
185 continue;
186
187 PCB_VIA* via = static_cast<PCB_VIA*>( item );
188
189 if( viaHasPotentiallyUnusedLayers( via ) )
190 {
191 m_commit.Modify( via );
192 via->SetRemoveUnconnected( aRemoveLayers );
193
194 if( aRemoveLayers )
195 via->SetKeepStartEnd( m_cbPreserveExternalLayers->IsChecked() );
196 }
197 }
198 }
199 }
200
201 m_commit.Push( _( "Remove Unused Pads" ) );
202}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
@ pads_remove_unused
@ pads_remove_unused_keep_bottom
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition commit.h:68
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_UNUSED_PAD_LAYERS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Unused Pads"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void onApply(wxCommandEvent &event) override
void onOK(wxCommandEvent &event) override
void updatePadsAndVias(bool aRemoveLayers)
Update layers of pads and vias aRemoveLayers = true to remove not connected layers false to set all l...
void syncImages(wxCommandEvent &aEvent) override
DIALOG_UNUSED_PAD_LAYERS(PCB_BASE_FRAME *aParent, const PCB_SELECTION &aItems, COMMIT &aCommit)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
std::deque< PAD * > & Pads()
Definition footprint.h:375
Definition pad.h:61
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ PTH
Plated through hole pad.
Definition padstack.h:98
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:90
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:79
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:80