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 <jon@craftyjon.com>
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>
23 #include <tools/selection_tool.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  wxASSERT( m_frame );
34  wxASSERT( m_tool );
35 
38 
39  m_cbFootprints->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
40  m_cbText->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
41  m_cbTracks->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
42  m_cbVias->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
43  m_cbPads->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
44  m_cbGraphics->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
45  m_cbZones->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
46  m_cbKeepouts->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
47  m_cbDimensions->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
48  m_cbOtherItems->Bind( wxEVT_RIGHT_DOWN, &PANEL_SELECTION_FILTER::onRightClick, this );
49 }
50 
51 
53 {
54  Freeze();
55 
56  m_cbLockedItems->SetValue( aOptions.lockedItems );
57  m_cbFootprints->SetValue( aOptions.footprints );
58  m_cbText->SetValue( aOptions.text );
59  m_cbTracks->SetValue( aOptions.tracks );
60  m_cbVias->SetValue( aOptions.vias );
61  m_cbPads->SetValue( aOptions.pads );
62  m_cbGraphics->SetValue( aOptions.graphics );
63  m_cbZones->SetValue( aOptions.zones );
64  m_cbKeepouts->SetValue( aOptions.keepouts );
65  m_cbDimensions->SetValue( aOptions.dimensions );
66  m_cbOtherItems->SetValue( aOptions.otherItems );
67 
68  m_cbAllItems->SetValue( aOptions.All() );
69 
70  Thaw();
71 }
72 
73 
74 void PANEL_SELECTION_FILTER::OnFilterChanged( wxCommandEvent& aEvent )
75 {
76  if( aEvent.GetEventObject() == m_cbAllItems )
77  {
78  bool newState = m_cbAllItems->GetValue();
79 
80  m_cbFootprints->SetValue( newState );
81  m_cbText->SetValue( newState );
82  m_cbTracks->SetValue( newState );
83  m_cbVias->SetValue( newState );
84  m_cbPads->SetValue( newState );
85  m_cbGraphics->SetValue( newState );
86  m_cbZones->SetValue( newState );
87  m_cbKeepouts->SetValue( newState );
88  m_cbDimensions->SetValue( newState );
89  m_cbOtherItems->SetValue( newState );
90  }
91 
93 
94  // If any of the other checkboxes turned off, turn off the All Items checkbox
95  bool allChecked = setFilterFromCheckboxes( opts );
96  m_cbAllItems->SetValue( allChecked );
97 }
98 
99 
101 {
102  aOptions.lockedItems = m_cbLockedItems->GetValue();
103  aOptions.footprints = m_cbFootprints->GetValue();
104  aOptions.text = m_cbText->GetValue();
105  aOptions.tracks = m_cbTracks->GetValue();
106  aOptions.vias = m_cbVias->GetValue();
107  aOptions.pads = m_cbPads->GetValue();
108  aOptions.graphics = m_cbGraphics->GetValue();
109  aOptions.zones = m_cbZones->GetValue();
110  aOptions.keepouts = m_cbKeepouts->GetValue();
111  aOptions.dimensions = m_cbDimensions->GetValue();
112  aOptions.otherItems = m_cbOtherItems->GetValue();
113 
114  return aOptions.All();
115 }
116 
117 
118 void PANEL_SELECTION_FILTER::onRightClick( wxMouseEvent& aEvent )
119 {
120  wxMenu menu;
121 
122  wxCheckBox* cb = dynamic_cast<wxCheckBox*>( aEvent.GetEventObject() );
123 
124  if( !cb )
125  return;
126 
127  m_onlyCheckbox = cb;
128 
129  wxString label;
130  label.Printf( _( "Only %s" ), cb->GetLabel().Lower() );
131 
132  menu.Append( new wxMenuItem( &menu, wxID_ANY, label, wxEmptyString, wxITEM_NORMAL ) );
133 
134  menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_SELECTION_FILTER::onPopupSelection, this );
135 
136  PopupMenu( &menu );
137 }
138 
139 
140 void PANEL_SELECTION_FILTER::onPopupSelection( wxCommandEvent& aEvent )
141 {
142  if( !m_onlyCheckbox )
143  return;
144 
145  m_cbAllItems->SetValue( false );
146  m_cbFootprints->SetValue( false );
147  m_cbText->SetValue( false );
148  m_cbTracks->SetValue( false );
149  m_cbVias->SetValue( false );
150  m_cbPads->SetValue( false );
151  m_cbGraphics->SetValue( false );
152  m_cbZones->SetValue( false );
153  m_cbKeepouts->SetValue( false );
154  m_cbDimensions->SetValue( false );
155  m_cbOtherItems->SetValue( false );
156 
157  m_onlyCheckbox->SetValue( true );
158  m_onlyCheckbox = nullptr;
159 
160  wxCommandEvent dummy;
162 }
void onPopupSelection(wxCommandEvent &aEvent)
bool otherItems
Anything not fitting one of the above categories.
SELECTION_TOOL.
SELECTION_FILTER_OPTIONS & GetFilter()
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
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.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
#define _(s)
Definition: 3d_actions.cpp:33
PCB_BASE_EDIT_FRAME * m_frame
Class PANEL_SELECTION_FILTER_BASE.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
bool setFilterFromCheckboxes(SELECTION_FILTER_OPTIONS &aOptions)
PANEL_SELECTION_FILTER(wxWindow *aParent)