KiCad PCB EDA Suite
panel_selection_filter.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 Jon Evans <[email protected]>
5 * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <pcb_base_edit_frame.h>
22#include <tool/tool_manager.h>
25
26
29 m_frame( dynamic_cast<PCB_BASE_EDIT_FRAME*>( aParent ) ),
30 m_onlyCheckbox( nullptr )
31{
32 wxFont font = KIUI::GetInfoFont( this );
33 m_cbLockedItems->SetFont( font );
34 m_cbFootprints->SetFont( font );
35 m_cbText->SetFont( font );
36 m_cbTracks->SetFont( font );
37 m_cbVias->SetFont( font );
38 m_cbPads->SetFont( font );
39 m_cbGraphics->SetFont( font );
40 m_cbZones->SetFont( font );
41 m_cbKeepouts->SetFont( font );
42 m_cbDimensions->SetFont( font );
43 m_cbOtherItems->SetFont( font );
44 m_cbAllItems->SetFont( font );
45
46 SetBorders( true, false, false, false );
47
48 wxASSERT( m_frame );
50 wxASSERT( m_tool );
51
54
55 m_cbFootprints->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
56 m_cbText->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
57 m_cbTracks->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
58 m_cbVias->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
59 m_cbPads->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
60 m_cbGraphics->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
61 m_cbZones->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
62 m_cbKeepouts->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
63 m_cbDimensions->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
64 m_cbOtherItems->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
65}
66
67
69{
70 Freeze();
71
72 m_cbLockedItems->SetValue( aOptions.lockedItems );
73 m_cbFootprints->SetValue( aOptions.footprints );
74 m_cbText->SetValue( aOptions.text );
75 m_cbTracks->SetValue( aOptions.tracks );
76 m_cbVias->SetValue( aOptions.vias );
77 m_cbPads->SetValue( aOptions.pads );
78 m_cbGraphics->SetValue( aOptions.graphics );
79 m_cbZones->SetValue( aOptions.zones );
80 m_cbKeepouts->SetValue( aOptions.keepouts );
81 m_cbDimensions->SetValue( aOptions.dimensions );
82 m_cbOtherItems->SetValue( aOptions.otherItems );
83
84 m_cbAllItems->SetValue( aOptions.All() );
85
86 Thaw();
87}
88
89
90void PANEL_SELECTION_FILTER::OnFilterChanged( wxCommandEvent& aEvent )
91{
92 if( aEvent.GetEventObject() == m_cbAllItems )
93 {
94 bool newState = m_cbAllItems->GetValue();
95
96 m_cbFootprints->SetValue( newState );
97 m_cbText->SetValue( newState );
98 m_cbTracks->SetValue( newState );
99 m_cbVias->SetValue( newState );
100 m_cbPads->SetValue( newState );
101 m_cbGraphics->SetValue( newState );
102 m_cbZones->SetValue( newState );
103 m_cbKeepouts->SetValue( newState );
104 m_cbDimensions->SetValue( newState );
105 m_cbOtherItems->SetValue( newState );
106 }
107
109
110 // If any of the other checkboxes turned off, turn off the All Items checkbox
111 bool allChecked = setFilterFromCheckboxes( opts );
112 m_cbAllItems->SetValue( allChecked );
113}
114
115
117{
118 aOptions.lockedItems = m_cbLockedItems->GetValue();
119 aOptions.footprints = m_cbFootprints->GetValue();
120 aOptions.text = m_cbText->GetValue();
121 aOptions.tracks = m_cbTracks->GetValue();
122 aOptions.vias = m_cbVias->GetValue();
123 aOptions.pads = m_cbPads->GetValue();
124 aOptions.graphics = m_cbGraphics->GetValue();
125 aOptions.zones = m_cbZones->GetValue();
126 aOptions.keepouts = m_cbKeepouts->GetValue();
127 aOptions.dimensions = m_cbDimensions->GetValue();
128 aOptions.otherItems = m_cbOtherItems->GetValue();
129
130 return aOptions.All();
131}
132
133
134void PANEL_SELECTION_FILTER::onRightClick( wxMouseEvent& aEvent )
135{
136 wxMenu menu;
137
138 wxCheckBox* cb = dynamic_cast<wxCheckBox*>( aEvent.GetEventObject() );
139
140 if( !cb )
141 return;
142
143 m_onlyCheckbox = cb;
144
145 wxString label;
146 label.Printf( _( "Only %s" ), cb->GetLabel().Lower() );
147
148 menu.Append( new wxMenuItem( &menu, wxID_ANY, label, wxEmptyString, wxITEM_NORMAL ) );
149
150 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_SELECTION_FILTER::onPopupSelection, this );
151
152 PopupMenu( &menu );
153}
154
155
156void PANEL_SELECTION_FILTER::onPopupSelection( wxCommandEvent& aEvent )
157{
158 if( !m_onlyCheckbox )
159 return;
160
161 m_cbAllItems->SetValue( false );
162 m_cbFootprints->SetValue( false );
163 m_cbText->SetValue( false );
164 m_cbTracks->SetValue( false );
165 m_cbVias->SetValue( false );
166 m_cbPads->SetValue( false );
167 m_cbGraphics->SetValue( false );
168 m_cbZones->SetValue( false );
169 m_cbKeepouts->SetValue( false );
170 m_cbDimensions->SetValue( false );
171 m_cbOtherItems->SetValue( false );
172
173 m_onlyCheckbox->SetValue( true );
174 m_onlyCheckbox = nullptr;
175
176 wxCommandEvent dummy;
178}
179
180
182{
183 m_cbAllItems->SetLabel( _( "All items" ) );
184 m_cbLockedItems->SetLabel( _( "Locked items" ) );
185 m_cbLockedItems->SetToolTip( _( "Allow selection of locked items" ) );
186 m_cbFootprints->SetLabel( _( "Footprints" ) );
187 m_cbText->SetLabel( _( "Text" ) );
188 m_cbTracks->SetLabel( _( "Tracks" ) );
189 m_cbVias->SetLabel( _( "Vias" ) );
190 m_cbPads->SetLabel( _( "Pads" ) );
191 m_cbGraphics->SetLabel( _( "Graphics" ) );
192 m_cbZones->SetLabel( _( "Zones" ) );
193 m_cbKeepouts->SetLabel( _( "Rule Areas" ) );
194 m_cbDimensions->SetLabel( _( "Dimensions" ) );
195 m_cbOtherItems->SetLabel( _( "Other items" ) );
196
197 m_cbAllItems->GetParent()->Layout();
198}
Class PANEL_SELECTION_FILTER_BASE.
PCB_BASE_EDIT_FRAME * m_frame
void onPopupSelection(wxCommandEvent &aEvent)
PCB_SELECTION_TOOL * m_tool
void SetCheckboxesFromFilter(SELECTION_FILTER_OPTIONS &aOptions)
PANEL_SELECTION_FILTER(wxWindow *aParent)
void OnFilterChanged(wxCommandEvent &aEvent) override
void onRightClick(wxMouseEvent &aEvent)
bool setFilterFromCheckboxes(SELECTION_FILTER_OPTIONS &aOptions)
Common, abstract interface for edit frames.
The selection tool: currently supports:
SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition: wx_panel.h:38
#define _(s)
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
std::vector< FAB_LAYER_COLOR > dummy
This file contains data structures that are saved in the project file or project local settings file ...
bool graphics
Graphic lines, shapes, polygons.
bool text
Text (free or attached to a footprint)
bool lockedItems
Allow selecting locked items.
bool footprints
Allow selecting entire footprints.
bool dimensions
Dimension items.
bool otherItems
Anything not fitting one of the above categories.