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_cbLockedItems->SetValue( newState );
81  m_cbFootprints->SetValue( newState );
82  m_cbText->SetValue( newState );
83  m_cbTracks->SetValue( newState );
84  m_cbVias->SetValue( newState );
85  m_cbPads->SetValue( newState );
86  m_cbGraphics->SetValue( newState );
87  m_cbZones->SetValue( newState );
88  m_cbKeepouts->SetValue( newState );
89  m_cbDimensions->SetValue( newState );
90  m_cbOtherItems->SetValue( newState );
91  }
92 
94 
95  // If any of the other checkboxes turned off, turn off the All Items checkbox
96  bool allChecked = setFilterFromCheckboxes( opts );
97  m_cbAllItems->SetValue( allChecked );
98 }
99 
100 
102 {
103  aOptions.lockedItems = m_cbLockedItems->GetValue();
104  aOptions.footprints = m_cbFootprints->GetValue();
105  aOptions.text = m_cbText->GetValue();
106  aOptions.tracks = m_cbTracks->GetValue();
107  aOptions.vias = m_cbVias->GetValue();
108  aOptions.pads = m_cbPads->GetValue();
109  aOptions.graphics = m_cbGraphics->GetValue();
110  aOptions.zones = m_cbZones->GetValue();
111  aOptions.keepouts = m_cbKeepouts->GetValue();
112  aOptions.dimensions = m_cbDimensions->GetValue();
113  aOptions.otherItems = m_cbOtherItems->GetValue();
114 
115  return aOptions.All();
116 }
117 
118 
119 void PANEL_SELECTION_FILTER::onRightClick( wxMouseEvent& aEvent )
120 {
121  wxMenu menu;
122 
123  wxCheckBox* cb = dynamic_cast<wxCheckBox*>( aEvent.GetEventObject() );
124 
125  if( !cb )
126  return;
127 
128  m_onlyCheckbox = cb;
129 
130  wxString label;
131  label.Printf( _( "Only %s" ), cb->GetLabel().Lower() );
132 
133  menu.Append( new wxMenuItem( &menu, wxID_ANY, label, wxEmptyString, wxITEM_NORMAL ) );
134 
135  menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &PANEL_SELECTION_FILTER::onPopupSelection, this );
136 
137  PopupMenu( &menu );
138 }
139 
140 
141 void PANEL_SELECTION_FILTER::onPopupSelection( wxCommandEvent& aEvent )
142 {
143  if( !m_onlyCheckbox )
144  return;
145 
146  m_cbAllItems->SetValue( false );
147  m_cbFootprints->SetValue( false );
148  m_cbText->SetValue( false );
149  m_cbTracks->SetValue( false );
150  m_cbVias->SetValue( false );
151  m_cbPads->SetValue( false );
152  m_cbGraphics->SetValue( false );
153  m_cbZones->SetValue( false );
154  m_cbKeepouts->SetValue( false );
155  m_cbDimensions->SetValue( false );
156  m_cbOtherItems->SetValue( false );
157 
158  m_onlyCheckbox->SetValue( true );
159  m_onlyCheckbox = nullptr;
160 
161  wxCommandEvent dummy;
163 }
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:74
bool setFilterFromCheckboxes(SELECTION_FILTER_OPTIONS &aOptions)
PANEL_SELECTION_FILTER(wxWindow *aParent)