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 (C) 2020-2024 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 <footprint.h>
30#include <pcb_track.h>
31#include <pad.h>
32#include <pcb_edit_frame.h>
34
35
37 const PCB_SELECTION& aItems,
38 COMMIT& aCommit )
40 m_frame( aParent ),
41 m_items( aItems ),
42 m_commit( aCommit )
43{
44 m_image->SetBitmap( KiBitmapBundle( BITMAPS::pads_remove_unused ) );
45
46 // Set keep Through Hole pads on external layers ON by default.
47 // Because such a pad does not allow soldering/unsoldering, disable this option
48 // is probably not frequent
49 m_cbPreserveExternalLayers->SetValue( true );
50
51 SetupStandardButtons( { { wxID_OK, _( "Remove Unused Layers" ) },
52 { wxID_APPLY, _( "Restore All Layers" ) },
53 { wxID_CANCEL, _( "Cancel" ) } } );
54
56
57 // Now all widgets have the size fixed, call FinishDialogSettings
59}
60
61
63{
64 if( m_cbPreserveExternalLayers->IsChecked() )
65 m_image->SetBitmap( KiBitmapBundle( BITMAPS::pads_remove_unused_keep_bottom ) );
66 else
67 m_image->SetBitmap( KiBitmapBundle( BITMAPS::pads_remove_unused ) );
68}
69
70
71void DIALOG_UNUSED_PAD_LAYERS::syncImages( wxCommandEvent& aEvent )
72{
74}
75
76
77void DIALOG_UNUSED_PAD_LAYERS::onApply( wxCommandEvent& event )
78{
79 updatePadsAndVias( false );
80 EndModal( wxID_APPLY );
81}
82
83
84void DIALOG_UNUSED_PAD_LAYERS::onOK( wxCommandEvent& event )
85{
86 updatePadsAndVias( true ); // called only with wxID_OK
87 event.Skip();
88}
89
90
92{
93 auto viaHasPotentiallyUnusedLayers =
94 [&]( PCB_VIA* via )
95 {
96 if( via->GetViaType() == VIATYPE::THROUGH )
97 return m_frame->GetBoard()->GetCopperLayerCount() > 2;
98
99 PCB_LAYER_ID startLayer = via->Padstack().StartLayer();
100 PCB_LAYER_ID endLayer = via->Padstack().EndLayer();
101
102 if( startLayer < 0 || endLayer < 0 )
103 return m_frame->GetBoard()->GetCopperLayerCount() > 2;
104 else
105 return m_frame->GetBoard()->LayerDepth( startLayer, endLayer ) > 1;
106 };
107
108 auto padHasPotentiallyUnusedLayers =
109 [&]( PAD* pad )
110 {
111 return pad->GetAttribute() == PAD_ATTRIB::PTH;
112 };
113
114 if( m_cbSelectedOnly->IsChecked() )
115 {
116 for( EDA_ITEM* item : m_items )
117 {
118 m_commit.Modify( item );
119
120 if( item->Type() == PCB_VIA_T && m_cbVias->IsChecked() )
121 {
122 PCB_VIA* via = static_cast<PCB_VIA*>( item );
123
124 if( viaHasPotentiallyUnusedLayers( via ) )
125 {
126 via->SetRemoveUnconnected( aRemoveLayers );
127
128 if( aRemoveLayers )
129 via->SetKeepStartEnd( m_cbPreserveExternalLayers->IsChecked() );
130 }
131 }
132
133 if( item->Type() == PCB_FOOTPRINT_T && m_cbPads->IsChecked() )
134 {
135 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
136
137 for( PAD* pad : footprint->Pads() )
138 {
139 if( padHasPotentiallyUnusedLayers( pad ) )
140 {
141 pad->SetRemoveUnconnected( aRemoveLayers );
142
143 if( aRemoveLayers )
144 pad->SetKeepTopBottom( m_cbPreserveExternalLayers->IsChecked() );
145 }
146 }
147 }
148
149 if( item->Type() == PCB_PAD_T && m_cbPads->IsChecked() )
150 {
151 PAD* pad = static_cast<PAD*>( item );
152
153 if( padHasPotentiallyUnusedLayers( pad ) )
154 {
155 pad->SetRemoveUnconnected( aRemoveLayers );
156
157 if( aRemoveLayers )
158 pad->SetKeepTopBottom( m_cbPreserveExternalLayers->IsChecked() );
159 }
160 }
161 }
162 }
163 else
164 {
165 if( m_cbPads->IsChecked() )
166 {
167 for( FOOTPRINT* footprint : m_frame->GetBoard()->Footprints() )
168 {
169 m_commit.Modify( footprint );
170
171 for( PAD* pad : footprint->Pads() )
172 {
173 if( padHasPotentiallyUnusedLayers( pad ) )
174 {
175 pad->SetRemoveUnconnected( aRemoveLayers );
176
177 if( aRemoveLayers )
178 pad->SetKeepTopBottom( m_cbPreserveExternalLayers->IsChecked() );
179 }
180 }
181 }
182 }
183
184 if( m_cbVias->IsChecked() )
185 {
186 for( PCB_TRACK* item : m_frame->GetBoard()->Tracks() )
187 {
188 if( item->Type() != PCB_VIA_T )
189 continue;
190
191 PCB_VIA* via = static_cast<PCB_VIA*>( item );
192
193 if( viaHasPotentiallyUnusedLayers( via ) )
194 {
196 via->SetRemoveUnconnected( aRemoveLayers );
197
198 if( aRemoveLayers )
199 via->SetKeepStartEnd( m_cbPreserveExternalLayers->IsChecked() );
200 }
201 }
202 }
203 }
204
205 m_commit.Push( _( "Remove Unused Pads" ) );
206}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
int GetCopperLayerCount() const
Definition: board.cpp:741
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
int LayerDepth(PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer) const
Definition: board.cpp:766
Represent a set of changes (additions, deletions or modifications) of a data model (e....
Definition: commit.h:74
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
virtual void Push(const wxString &aMessage=wxT("A commit"), int aFlags=0)=0
Revert the commit by restoring the modified items state.
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...
Class DIALOG_UNUSED_PAD_LAYERS_BASE.
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:89
std::deque< PAD * > & Pads()
Definition: footprint.h:206
Definition: pad.h:54
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
#define _(s)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87