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-2023 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_cbPreservePads->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_cbPreservePads->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 if( m_cbSelectedOnly->IsChecked() )
94 {
95 for( EDA_ITEM* item : m_items )
96 {
97 m_commit.Modify( item );
98
99 if( item->Type() == PCB_VIA_T && m_cbVias->IsChecked() )
100 {
101 PCB_VIA* via = static_cast<PCB_VIA*>( item );
102 via->SetRemoveUnconnected( aRemoveLayers );
103 via->SetKeepStartEnd( m_cbPreservePads->IsChecked() );
104 }
105
106 if( item->Type() == PCB_FOOTPRINT_T && m_cbPads->IsChecked() )
107 {
108 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
109
110 for( PAD* pad : footprint->Pads() )
111 {
112 pad->SetRemoveUnconnected( aRemoveLayers );
113 pad->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
114 }
115 }
116
117 if( item->Type() == PCB_PAD_T && m_cbPads->IsChecked() )
118 {
119 PAD* pad = static_cast<PAD*>( item );
120
121 pad->SetRemoveUnconnected( aRemoveLayers );
122 pad->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
123 }
124 }
125 }
126 else
127 {
128 if( m_cbPads->IsChecked() )
129 {
130 for( FOOTPRINT* footprint : m_frame->GetBoard()->Footprints() )
131 {
132 m_commit.Modify( footprint );
133
134 for( PAD* pad : footprint->Pads() )
135 {
136 pad->SetRemoveUnconnected( aRemoveLayers );
137 pad->SetKeepTopBottom( m_cbPreservePads->IsChecked() );
138 }
139 }
140 }
141
142 if( m_cbVias->IsChecked() )
143 {
144 for( PCB_TRACK* item : m_frame->GetBoard()->Tracks() )
145 {
146 if( item->Type() != PCB_VIA_T )
147 continue;
148
149 m_commit.Modify( item );
150 PCB_VIA* via = static_cast<PCB_VIA*>( item );
151 via->SetRemoveUnconnected( aRemoveLayers );
152 via->SetKeepStartEnd( m_cbPreservePads->IsChecked() );
153 }
154 }
155 }
156
157 m_commit.Push( _( "Set Unused Pad Properties" ) );
158}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
FOOTPRINTS & Footprints()
Definition: board.h:318
TRACKS & Tracks()
Definition: board.h:315
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:85
PADS & Pads()
Definition: footprint.h:188
Definition: pad.h:59
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard() const
#define _(s)
@ 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