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 
28  PANEL_SELECTION_FILTER_BASE( aParent ),
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  wxASSERT( m_frame );
48  wxASSERT( m_tool );
49 
52 
53  m_cbFootprints->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
54  m_cbText->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
55  m_cbTracks->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
56  m_cbVias->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
57  m_cbPads->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
58  m_cbGraphics->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
59  m_cbZones->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
60  m_cbKeepouts->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
61  m_cbDimensions->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
62  m_cbOtherItems->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
63 }
64 
65 
67 {
68  Freeze();
69 
70  m_cbLockedItems->SetValue( aOptions.lockedItems );
71  m_cbFootprints->SetValue( aOptions.footprints );
72  m_cbText->SetValue( aOptions.text );
73  m_cbTracks->SetValue( aOptions.tracks );
74  m_cbVias->SetValue( aOptions.vias );
75  m_cbPads->SetValue( aOptions.pads );
76  m_cbGraphics->SetValue( aOptions.graphics );
77  m_cbZones->SetValue( aOptions.zones );
78  m_cbKeepouts->SetValue( aOptions.keepouts );
79  m_cbDimensions->SetValue( aOptions.dimensions );
80  m_cbOtherItems->SetValue( aOptions.otherItems );
81 
82  m_cbAllItems->SetValue( aOptions.All() );
83 
84  Thaw();
85 }
86 
87 
88 void PANEL_SELECTION_FILTER::OnFilterChanged( wxCommandEvent& aEvent )
89 {
90  if( aEvent.GetEventObject() == m_cbAllItems )
91  {
92  bool newState = m_cbAllItems->GetValue();
93 
94  m_cbFootprints->SetValue( newState );
95  m_cbText->SetValue( newState );
96  m_cbTracks->SetValue( newState );
97  m_cbVias->SetValue( newState );
98  m_cbPads->SetValue( newState );
99  m_cbGraphics->SetValue( newState );
100  m_cbZones->SetValue( newState );
101  m_cbKeepouts->SetValue( newState );
102  m_cbDimensions->SetValue( newState );
103  m_cbOtherItems->SetValue( newState );
104  }
105 
107 
108  // If any of the other checkboxes turned off, turn off the All Items checkbox
109  bool allChecked = setFilterFromCheckboxes( opts );
110  m_cbAllItems->SetValue( allChecked );
111 }
112 
113 
115 {
116  aOptions.lockedItems = m_cbLockedItems->GetValue();
117  aOptions.footprints = m_cbFootprints->GetValue();
118  aOptions.text = m_cbText->GetValue();
119  aOptions.tracks = m_cbTracks->GetValue();
120  aOptions.vias = m_cbVias->GetValue();
121  aOptions.pads = m_cbPads->GetValue();
122  aOptions.graphics = m_cbGraphics->GetValue();
123  aOptions.zones = m_cbZones->GetValue();
124  aOptions.keepouts = m_cbKeepouts->GetValue();
125  aOptions.dimensions = m_cbDimensions->GetValue();
126  aOptions.otherItems = m_cbOtherItems->GetValue();
127 
128  return aOptions.All();
129 }
130 
131 
132 void PANEL_SELECTION_FILTER::onRightClick( wxMouseEvent& aEvent )
133 {
134  wxMenu menu;
135 
136  wxCheckBox* cb = dynamic_cast<wxCheckBox*>( aEvent.GetEventObject() );
137 
138  if( !cb )
139  return;
140 
141  m_onlyCheckbox = cb;
142 
143  wxString label;
144  label.Printf( _( "Only %s" ), cb->GetLabel().Lower() );
145 
146  menu.Append( new wxMenuItem( &menu, wxID_ANY, label, wxEmptyString, wxITEM_NORMAL ) );
147 
148  menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_SELECTION_FILTER::onPopupSelection, this );
149 
150  PopupMenu( &menu );
151 }
152 
153 
154 void PANEL_SELECTION_FILTER::onPopupSelection( wxCommandEvent& aEvent )
155 {
156  if( !m_onlyCheckbox )
157  return;
158 
159  m_cbAllItems->SetValue( false );
160  m_cbFootprints->SetValue( false );
161  m_cbText->SetValue( false );
162  m_cbTracks->SetValue( false );
163  m_cbVias->SetValue( false );
164  m_cbPads->SetValue( false );
165  m_cbGraphics->SetValue( false );
166  m_cbZones->SetValue( false );
167  m_cbKeepouts->SetValue( false );
168  m_cbDimensions->SetValue( false );
169  m_cbOtherItems->SetValue( false );
170 
171  m_onlyCheckbox->SetValue( true );
172  m_onlyCheckbox = nullptr;
173 
174  wxCommandEvent dummy;
176 }
void onPopupSelection(wxCommandEvent &aEvent)
bool otherItems
Anything not fitting one of the above categories.
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:144
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
void SetCheckboxesFromFilter(SELECTION_FILTER_OPTIONS &aOptions)
bool text
Text (free or attached to a footprint)
bool dimensions
Dimension items.
bool graphics
Graphic lines, shapes, polygons.
void OnFilterChanged(wxCommandEvent &aEvent) override
#define _(s)
This file contains data structures that are saved in the project file or project local settings file ...
bool footprints
Allow selecting entire footprints.
bool lockedItems
Allow selecting locked items.
void onRightClick(wxMouseEvent &aEvent)
Common, abstract interface for edit frames.
The selection tool: currently supports:
PCB_BASE_EDIT_FRAME * m_frame
SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
Class PANEL_SELECTION_FILTER_BASE.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
bool setFilterFromCheckboxes(SELECTION_FILTER_OPTIONS &aOptions)
PCB_SELECTION_TOOL * m_tool
PANEL_SELECTION_FILTER(wxWindow *aParent)