KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 m_frame->Bind( EDA_LANG_CHANGED, &PANEL_SELECTION_FILTER::OnLanguageChanged, this );
67}
68
69
71{
72 m_frame->Unbind( EDA_LANG_CHANGED, &PANEL_SELECTION_FILTER::OnLanguageChanged, this );
73}
74
75
77{
78 Freeze();
79
80 m_cbLockedItems->SetValue( aOptions.lockedItems );
81 m_cbFootprints->SetValue( aOptions.footprints );
82 m_cbText->SetValue( aOptions.text );
83 m_cbTracks->SetValue( aOptions.tracks );
84 m_cbVias->SetValue( aOptions.vias );
85 m_cbPads->SetValue( aOptions.pads );
86 m_cbGraphics->SetValue( aOptions.graphics );
87 m_cbZones->SetValue( aOptions.zones );
88 m_cbKeepouts->SetValue( aOptions.keepouts );
89 m_cbDimensions->SetValue( aOptions.dimensions );
90 m_cbOtherItems->SetValue( aOptions.otherItems );
91
92 m_cbAllItems->SetValue( aOptions.All() );
93
94 Thaw();
95}
96
97
98void PANEL_SELECTION_FILTER::OnFilterChanged( wxCommandEvent& aEvent )
99{
100 if( aEvent.GetEventObject() == m_cbAllItems )
101 {
102 bool newState = m_cbAllItems->GetValue();
103
104 m_cbFootprints->SetValue( newState );
105 m_cbText->SetValue( newState );
106 m_cbTracks->SetValue( newState );
107 m_cbVias->SetValue( newState );
108 m_cbPads->SetValue( newState );
109 m_cbGraphics->SetValue( newState );
110 m_cbZones->SetValue( newState );
111 m_cbKeepouts->SetValue( newState );
112 m_cbDimensions->SetValue( newState );
113 m_cbOtherItems->SetValue( newState );
114 }
115
117
118 // If any of the other checkboxes turned off, turn off the All Items checkbox
119 bool allChecked = setFilterFromCheckboxes( opts );
120 m_cbAllItems->SetValue( allChecked );
121}
122
123
125{
126 aOptions.lockedItems = m_cbLockedItems->GetValue();
127 aOptions.footprints = m_cbFootprints->GetValue();
128 aOptions.text = m_cbText->GetValue();
129 aOptions.tracks = m_cbTracks->GetValue();
130 aOptions.vias = m_cbVias->GetValue();
131 aOptions.pads = m_cbPads->GetValue();
132 aOptions.graphics = m_cbGraphics->GetValue();
133 aOptions.zones = m_cbZones->GetValue();
134 aOptions.keepouts = m_cbKeepouts->GetValue();
135 aOptions.dimensions = m_cbDimensions->GetValue();
136 aOptions.otherItems = m_cbOtherItems->GetValue();
137
138 return aOptions.All();
139}
140
141
142void PANEL_SELECTION_FILTER::onRightClick( wxMouseEvent& aEvent )
143{
144 wxMenu menu;
145
146 wxCheckBox* cb = dynamic_cast<wxCheckBox*>( aEvent.GetEventObject() );
147
148 if( !cb )
149 return;
150
151 m_onlyCheckbox = cb;
152
153 wxString label;
154 label.Printf( _( "Only %s" ), cb->GetLabel().Lower() );
155
156 menu.Append( new wxMenuItem( &menu, wxID_ANY, label, wxEmptyString, wxITEM_NORMAL ) );
157
158 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_SELECTION_FILTER::onPopupSelection, this );
159
160 PopupMenu( &menu );
161}
162
163
164void PANEL_SELECTION_FILTER::onPopupSelection( wxCommandEvent& aEvent )
165{
166 if( !m_onlyCheckbox )
167 return;
168
169 m_cbAllItems->SetValue( false );
170 m_cbFootprints->SetValue( false );
171 m_cbText->SetValue( false );
172 m_cbTracks->SetValue( false );
173 m_cbVias->SetValue( false );
174 m_cbPads->SetValue( false );
175 m_cbGraphics->SetValue( false );
176 m_cbZones->SetValue( false );
177 m_cbKeepouts->SetValue( false );
178 m_cbDimensions->SetValue( false );
179 m_cbOtherItems->SetValue( false );
180
181 m_onlyCheckbox->SetValue( true );
182 m_onlyCheckbox = nullptr;
183
184 wxCommandEvent dummy;
186}
187
188
189void PANEL_SELECTION_FILTER::OnLanguageChanged( wxCommandEvent& aEvent )
190{
191 m_cbAllItems->SetLabel( _( "All items" ) );
192 m_cbLockedItems->SetLabel( _( "Locked items" ) );
193 m_cbLockedItems->SetToolTip( _( "Allow selection of locked items" ) );
194 m_cbFootprints->SetLabel( _( "Footprints" ) );
195 m_cbText->SetLabel( _( "Text" ) );
196 m_cbTracks->SetLabel( _( "Tracks" ) );
197 m_cbVias->SetLabel( _( "Vias" ) );
198 m_cbPads->SetLabel( _( "Pads" ) );
199 m_cbGraphics->SetLabel( _( "Graphics" ) );
200 m_cbZones->SetLabel( _( "Zones" ) );
201 m_cbKeepouts->SetLabel( _( "Rule Areas" ) );
202 m_cbDimensions->SetLabel( _( "Dimensions" ) );
203 m_cbOtherItems->SetLabel( _( "Other items" ) );
204
205 m_cbAllItems->GetParent()->Layout();
206
207 aEvent.Skip();
208}
Class PANEL_SELECTION_FILTER_BASE.
PCB_BASE_EDIT_FRAME * m_frame
void onPopupSelection(wxCommandEvent &aEvent)
PCB_SELECTION_TOOL * m_tool
bool setFilterFromCheckboxes(PCB_SELECTION_FILTER_OPTIONS &aOptions)
PANEL_SELECTION_FILTER(wxWindow *aParent)
void SetCheckboxesFromFilter(PCB_SELECTION_FILTER_OPTIONS &aOptions)
void OnLanguageChanged(wxCommandEvent &aEvent)
void OnFilterChanged(wxCommandEvent &aEvent) override
void onRightClick(wxMouseEvent &aEvent)
Common, abstract interface for edit frames.
The selection tool: currently supports:
PCB_SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition: wx_panel.h:39
#define _(s)
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
std::vector< FAB_LAYER_COLOR > dummy
This file contains data structures that are saved in the project file or project local settings file ...
bool otherItems
Anything not fitting one of the above categories.
bool graphics
Graphic lines, shapes, polygons.
bool footprints
Allow selecting entire footprints.
bool text
Text (free or attached to a footprint)
bool lockedItems
Allow selecting locked items.