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 The 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 SetMinSize( GetBestSize() );
69}
70
71
73{
74 m_frame->Unbind( EDA_LANG_CHANGED, &PANEL_SELECTION_FILTER::OnLanguageChanged, this );
75}
76
77
79{
80 Freeze();
81
82 m_cbLockedItems->SetValue( aOptions.lockedItems );
83 m_cbFootprints->SetValue( aOptions.footprints );
84 m_cbText->SetValue( aOptions.text );
85 m_cbTracks->SetValue( aOptions.tracks );
86 m_cbVias->SetValue( aOptions.vias );
87 m_cbPads->SetValue( aOptions.pads );
88 m_cbGraphics->SetValue( aOptions.graphics );
89 m_cbZones->SetValue( aOptions.zones );
90 m_cbKeepouts->SetValue( aOptions.keepouts );
91 m_cbDimensions->SetValue( aOptions.dimensions );
92 m_cbOtherItems->SetValue( aOptions.otherItems );
93
94 m_cbAllItems->SetValue( aOptions.All() );
95
96 Thaw();
97}
98
99
100void PANEL_SELECTION_FILTER::OnFilterChanged( wxCommandEvent& aEvent )
101{
102 if( aEvent.GetEventObject() == m_cbAllItems )
103 {
104 bool newState = m_cbAllItems->GetValue();
105
106 m_cbFootprints->SetValue( newState );
107 m_cbText->SetValue( newState );
108 m_cbTracks->SetValue( newState );
109 m_cbVias->SetValue( newState );
110 m_cbPads->SetValue( newState );
111 m_cbGraphics->SetValue( newState );
112 m_cbZones->SetValue( newState );
113 m_cbKeepouts->SetValue( newState );
114 m_cbDimensions->SetValue( newState );
115 m_cbOtherItems->SetValue( newState );
116 }
117
119
120 // If any of the other checkboxes turned off, turn off the All Items checkbox
121 bool allChecked = setFilterFromCheckboxes( opts );
122 m_cbAllItems->SetValue( allChecked );
123}
124
125
127{
128 aOptions.lockedItems = m_cbLockedItems->GetValue();
129 aOptions.footprints = m_cbFootprints->GetValue();
130 aOptions.text = m_cbText->GetValue();
131 aOptions.tracks = m_cbTracks->GetValue();
132 aOptions.vias = m_cbVias->GetValue();
133 aOptions.pads = m_cbPads->GetValue();
134 aOptions.graphics = m_cbGraphics->GetValue();
135 aOptions.zones = m_cbZones->GetValue();
136 aOptions.keepouts = m_cbKeepouts->GetValue();
137 aOptions.dimensions = m_cbDimensions->GetValue();
138 aOptions.otherItems = m_cbOtherItems->GetValue();
139
140 return aOptions.All();
141}
142
143
144void PANEL_SELECTION_FILTER::onRightClick( wxMouseEvent& aEvent )
145{
146 wxMenu menu;
147
148 wxCheckBox* cb = dynamic_cast<wxCheckBox*>( aEvent.GetEventObject() );
149
150 if( !cb )
151 return;
152
153 m_onlyCheckbox = cb;
154
155 wxString label;
156 label.Printf( _( "Only %s" ), cb->GetLabel().Lower() );
157
158 menu.Append( new wxMenuItem( &menu, wxID_ANY, label, wxEmptyString, wxITEM_NORMAL ) );
159
160 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_SELECTION_FILTER::onPopupSelection, this );
161
162 PopupMenu( &menu );
163}
164
165
166void PANEL_SELECTION_FILTER::onPopupSelection( wxCommandEvent& aEvent )
167{
168 if( !m_onlyCheckbox )
169 return;
170
171 m_cbAllItems->SetValue( false );
172 m_cbFootprints->SetValue( false );
173 m_cbText->SetValue( false );
174 m_cbTracks->SetValue( false );
175 m_cbVias->SetValue( false );
176 m_cbPads->SetValue( false );
177 m_cbGraphics->SetValue( false );
178 m_cbZones->SetValue( false );
179 m_cbKeepouts->SetValue( false );
180 m_cbDimensions->SetValue( false );
181 m_cbOtherItems->SetValue( false );
182
183 m_onlyCheckbox->SetValue( true );
184 m_onlyCheckbox = nullptr;
185
186 wxCommandEvent dummy;
188}
189
190
191void PANEL_SELECTION_FILTER::OnLanguageChanged( wxCommandEvent& aEvent )
192{
193 m_cbAllItems->SetLabel( _( "All items" ) );
194 m_cbLockedItems->SetLabel( _( "Locked items" ) );
195 m_cbLockedItems->SetToolTip( _( "Allow selection of locked items" ) );
196 m_cbFootprints->SetLabel( _( "Footprints" ) );
197 m_cbText->SetLabel( _( "Text" ) );
198 m_cbTracks->SetLabel( _( "Tracks" ) );
199 m_cbVias->SetLabel( _( "Vias" ) );
200 m_cbPads->SetLabel( _( "Pads" ) );
201 m_cbGraphics->SetLabel( _( "Graphics" ) );
202 m_cbZones->SetLabel( _( "Zones" ) );
203 m_cbKeepouts->SetLabel( _( "Rule Areas" ) );
204 m_cbDimensions->SetLabel( _( "Dimensions" ) );
205 m_cbOtherItems->SetLabel( _( "Other items" ) );
206
207 m_cbAllItems->GetParent()->Layout();
208
209 aEvent.Skip();
210}
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:155
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.