KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_filter_selection.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) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <pcb_edit_frame.h>
26
27
30 m_options( aOptions )
31{
33
34 // Update "All Items" checkbox based on how many items are currently checked
35 m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
36
38
39 SetFocus();
40 GetSizer()->SetSizeHints( this );
41 Centre();
42}
43
44
45void DIALOG_FILTER_SELECTION::checkBoxClicked( wxCommandEvent& aEvent )
46{
47 if( m_Include_Modules->GetValue() )
48 m_IncludeLockedModules->Enable();
49 else
50 m_IncludeLockedModules->Disable();
51
52 // Update "All Items" checkbox based on how many items are currently checked
53 m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
54}
55
56
58{
61
62 if( m_Include_Modules->GetValue() )
63 m_IncludeLockedModules->Enable();
64 else
65 m_IncludeLockedModules->Disable();
66
73}
74
75
77{
78 m_Include_Modules->SetValue( aNewState );
79 m_IncludeLockedModules->SetValue( aNewState );
80
81 if( aNewState ) // Make enable state match checkbox state
82 m_IncludeLockedModules->Enable();
83 else
84 m_IncludeLockedModules->Disable();
85
86 m_Include_Tracks->SetValue( aNewState );
87 m_Include_Vias->SetValue( aNewState );
88 m_Include_Zones->SetValue( aNewState );
89 m_Include_Draw_Items->SetValue( aNewState );
90 m_Include_Edges_Items->SetValue( aNewState );
91 m_Include_PcbTexts->SetValue( aNewState );
92}
93
95{
96 int NumChecked = 0;
97 int NumCheckboxesOnDlg = 0;
98 wxCheckBoxState SuggestedState = wxCHK_UNDETERMINED; // Assume some but not all are checked
99
100 // Find out how many checkboxes are on this dialog. We do this at runtime so future
101 // changes to the dialog are easier to handle or automatic, depending on the change.
102 const wxWindowList& list = this->GetChildren();
103 for( wxWindowList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
104 {
105 wxWindow* current = node->GetData();
106
107 // If casting the child window to a checkbox isn't NULL, then the child is a checkbox
108 wxCheckBox* CurrCB = dynamic_cast<wxCheckBox*>( current );
109
110 if( CurrCB )
111 {
112 // Need to get count of checkboxes, but not include the "All Items" checkbox (the only
113 // one that allows the 3rd state) or the hidden one (the only one with an empty label)
114 // that keeps the dialog formatted properly
115
116 if( !( "" == CurrCB->GetLabelText() || CurrCB->Is3State() ) )
117 NumCheckboxesOnDlg++;
118 }
119 }
120
121 // Tally how many checkboxes are checked. Only include "locked footprints" in the total
122 // if "footprints" is checked.
123 if( m_Include_Modules->GetValue() )
124 {
125 NumChecked++;
126
127 if( m_IncludeLockedModules->GetValue() )
128 NumChecked++;
129 }
130 else
131 {
132 // If include modules isn't checked then ignore the "Locked Footprints" checkbox in tally
133 NumCheckboxesOnDlg--;
134 }
135
136 if( m_Include_Tracks->GetValue() )
137 NumChecked++;
138
139 if( m_Include_Vias->GetValue() )
140 NumChecked++;
141
142 if( m_Include_Zones->GetValue() )
143 NumChecked++;
144
145 if( m_Include_Draw_Items->GetValue() )
146 NumChecked++;
147
148 if( m_Include_Edges_Items->GetValue() )
149 NumChecked++;
150
151 if( m_Include_PcbTexts->GetValue() )
152 NumChecked++;
153
154 // Change suggestion if all or none are checked
155
156 if( !NumChecked )
157 SuggestedState = wxCHK_UNCHECKED;
158 else if( NumChecked == NumCheckboxesOnDlg )
159 SuggestedState = wxCHK_CHECKED;
160
161 return SuggestedState;
162}
163
164
165void DIALOG_FILTER_SELECTION::allItemsClicked( wxCommandEvent& aEvent )
166{
167 if( wxCHK_CHECKED == m_All_Items->Get3StateValue() )
168 forceCheckboxStates( true ); // Select all items
169 else
170 forceCheckboxStates( false ); // Clear all items
171}
172
173
175{
176 if( !wxDialog::TransferDataFromWindow() )
177 return false;
178
179 m_options.allItems = m_All_Items->Get3StateValue();
188
189 return true;
190}
Class DIALOG_FILTER_SELECTION_BASE.
void checkBoxClicked(wxCommandEvent &aEvent) override
DIALOG_FILTER_SELECTION(PCB_BASE_FRAME *aParent, OPTIONS &aOptions)
Create the filter selection dialog.
void forceCheckboxStates(bool aNewState)
void setCheckboxStatesFromOptions(OPTIONS &aOptions)
void allItemsClicked(wxCommandEvent &aEvent) override
wxCheckBoxState GetSuggestedAllItemsState(void)
Reference to the options struct to fill.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Struct that will be set with the result of the user choices in the dialog.