KiCad PCB EDA Suite
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 {
32  setCheckboxStatesFromOptions( aOptions );
33 
34  // Update "All Items" checkbox based on how many items are currently checked
35  m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
36 
37  m_sdbSizer1OK->SetDefault();
38  SetFocus();
39  GetSizer()->SetSizeHints( this );
40  Centre();
41 }
42 
43 
44 void DIALOG_FILTER_SELECTION::checkBoxClicked( wxCommandEvent& aEvent )
45 {
46  if( m_Include_Modules->GetValue() )
47  m_IncludeLockedModules->Enable();
48  else
49  m_IncludeLockedModules->Disable();
50 
51  // Update "All Items" checkbox based on how many items are currently checked
52  m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
53 }
54 
55 
57 {
60 
61  if( m_Include_Modules->GetValue() )
62  m_IncludeLockedModules->Enable();
63  else
64  m_IncludeLockedModules->Disable();
65 
72 }
73 
74 
76 {
77  m_Include_Modules->SetValue( aNewState );
78  m_IncludeLockedModules->SetValue( aNewState );
79 
80  if( aNewState ) // Make enable state match checkbox state
81  m_IncludeLockedModules->Enable();
82  else
83  m_IncludeLockedModules->Disable();
84 
85  m_Include_Tracks->SetValue( aNewState );
86  m_Include_Vias->SetValue( aNewState );
87  m_Include_Zones->SetValue( aNewState );
88  m_Include_Draw_Items->SetValue( aNewState );
89  m_Include_Edges_Items->SetValue( aNewState );
90  m_Include_PcbTexts->SetValue( aNewState );
91 }
92 
94 {
95  int NumChecked = 0;
96  int NumCheckboxesOnDlg = 0;
97  wxCheckBoxState SuggestedState = wxCHK_UNDETERMINED; // Assume some but not all are checked
98 
99  // Find out how many checkboxes are on this dialog. We do this at runtime so future
100  // changes to the dialog are easier to handle or automatic, depending on the change.
101  const wxWindowList& list = this->GetChildren();
102  for( wxWindowList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
103  {
104  wxWindow* current = node->GetData();
105 
106  // If casting the child window to a checkbox isn't NULL, then the child is a checkbox
107  wxCheckBox* CurrCB = dynamic_cast<wxCheckBox*>( current );
108 
109  if( CurrCB )
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() || 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 
135  if( m_Include_Tracks->GetValue() )
136  NumChecked++;
137 
138  if( m_Include_Vias->GetValue() )
139  NumChecked++;
140 
141  if( m_Include_Zones->GetValue() )
142  NumChecked++;
143 
144  if( m_Include_Draw_Items->GetValue() )
145  NumChecked++;
146 
147  if( m_Include_Edges_Items->GetValue() )
148  NumChecked++;
149 
150  if( m_Include_PcbTexts->GetValue() )
151  NumChecked++;
152 
153  // Change suggestion if all or none are checked
154 
155  if( !NumChecked )
156  SuggestedState = wxCHK_UNCHECKED;
157  else if( NumChecked == NumCheckboxesOnDlg )
158  SuggestedState = wxCHK_CHECKED;
159 
160  return SuggestedState;
161 }
162 
163 
164 void DIALOG_FILTER_SELECTION::allItemsClicked( wxCommandEvent& aEvent )
165 {
166  if( wxCHK_CHECKED == m_All_Items->Get3StateValue() )
167  forceCheckboxStates( true ); // Select all items
168  else
169  forceCheckboxStates( false ); // Clear all items
170 }
171 
172 
174 {
175  if( !wxDialog::TransferDataFromWindow() )
176  return false;
177 
178  m_options.allItems = m_All_Items->Get3StateValue();
182  m_options.includeVias = m_Include_Vias->GetValue();
183  m_options.includeZones = m_Include_Zones->GetValue();
187 
188  return true;
189 }
void checkBoxClicked(wxCommandEvent &aEvent) override
Struct that will be set with the result of the user choices in the dialog.
Class DIALOG_FILTER_SELECTION_BASE.
wxCheckBoxState GetSuggestedAllItemsState(void)
Reference to the options struct to fill.
void setCheckboxStatesFromOptions(OPTIONS &aOptions)
DIALOG_FILTER_SELECTION(PCB_BASE_FRAME *aParent, OPTIONS &aOptions)
Create the filter selection dialog.
void allItemsClicked(wxCommandEvent &aEvent) override
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void forceCheckboxStates(bool aNewState)