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 The 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 SetFocus();
35 GetSizer()->SetSizeHints( this );
36 Centre();
37}
38
39
40void DIALOG_FILTER_SELECTION::checkBoxClicked( wxCommandEvent& aEvent )
41{
42 if( m_Include_Modules->GetValue() )
43 m_IncludeLockedModules->Enable();
44 else
45 m_IncludeLockedModules->Disable();
46
47 // Update "All Items" checkbox based on how many items are currently checked
48 m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
49}
50
51
53{
56
57 if( m_Include_Modules->GetValue() )
58 m_IncludeLockedModules->Enable();
59 else
60 m_IncludeLockedModules->Disable();
61
68
69 // Update "All Items" checkbox based on how many items are currently checked
70 m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
71
72 return true;
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
104 for( wxWindowList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
105 {
106 wxWindow* current = node->GetData();
107
108 // If casting the child window to a checkbox isn't NULL, then the child is a checkbox
109 if( wxCheckBox* currCB = dynamic_cast<wxCheckBox*>( current ) )
110 {
111 // Need to get count of checkboxes, but not include the "All Items" checkbox (the only
112 // one that allows the 3rd state) or the hidden one (the only one with an empty label)
113 // that keeps the dialog formatted properly
114
115 if( !( currCB->GetLabelText().IsEmpty() || currCB->Is3State() ) )
116 numCheckboxesOnDlg++;
117 }
118 }
119
120 // Tally how many checkboxes are checked. Only include "locked footprints" in the total
121 // if "footprints" is checked.
122 if( m_Include_Modules->GetValue() )
123 {
124 numChecked++;
125
126 if( m_IncludeLockedModules->GetValue() )
127 numChecked++;
128 }
129 else
130 {
131 // If include modules isn't checked then ignore the "Locked Footprints" checkbox in tally
132 numCheckboxesOnDlg--;
133 }
134
137 {
138 if( cb->GetValue() )
139 numChecked++;
140 }
141
142 // Change suggestion if all or none are checked
143
144 if( !numChecked )
145 suggestedState = wxCHK_UNCHECKED;
146 else if( numChecked == numCheckboxesOnDlg )
147 suggestedState = wxCHK_CHECKED;
148
149 return suggestedState;
150}
151
152
153void DIALOG_FILTER_SELECTION::allItemsClicked( wxCommandEvent& aEvent )
154{
155 if( m_All_Items->Get3StateValue() == wxCHK_CHECKED )
156 forceCheckboxStates( true ); // Select all items
157 else
158 forceCheckboxStates( false ); // Clear all items
159}
160
161
163{
164 if( !wxDialog::TransferDataFromWindow() )
165 return false;
166
175
176 return true;
177}
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 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.