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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <pcb_edit_frame.h>
22
23
26 m_options( aOptions )
27{
29
30 SetFocus();
31 GetSizer()->SetSizeHints( this );
32 Centre();
33}
34
35
36void DIALOG_FILTER_SELECTION::checkBoxClicked( wxCommandEvent& aEvent )
37{
38 if( m_Include_Modules->GetValue() )
39 m_IncludeLockedModules->Enable();
40 else
41 m_IncludeLockedModules->Disable();
42
43 // Update "All Items" checkbox based on how many items are currently checked
44 m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
45}
46
47
49{
50 m_Include_Modules->SetValue( m_options.includeFootprints );
51 m_IncludeLockedModules->SetValue( m_options.includeLockedFootprints );
52
53 if( m_Include_Modules->GetValue() )
54 m_IncludeLockedModules->Enable();
55 else
56 m_IncludeLockedModules->Disable();
57
58 m_Include_Tracks->SetValue( m_options.includeTracks );
59 m_Include_Vias->SetValue( m_options.includeVias );
60 m_Include_Zones->SetValue( m_options.includeZones );
61 m_Include_Draw_Items->SetValue( m_options.includeItemsOnTechLayers );
62 m_Include_Edges_Items->SetValue( m_options.includeBoardOutlineLayer );
63 m_Include_PcbTexts->SetValue( m_options.includePcbTexts );
64
65 // Update "All Items" checkbox based on how many items are currently checked
66 m_All_Items->Set3StateValue( GetSuggestedAllItemsState() );
67
68 return true;
69}
70
71
73{
74 m_Include_Modules->SetValue( aNewState );
75 m_IncludeLockedModules->SetValue( aNewState );
76
77 if( aNewState ) // Make enable state match checkbox state
78 m_IncludeLockedModules->Enable();
79 else
80 m_IncludeLockedModules->Disable();
81
82 m_Include_Tracks->SetValue( aNewState );
83 m_Include_Vias->SetValue( aNewState );
84 m_Include_Zones->SetValue( aNewState );
85 m_Include_Draw_Items->SetValue( aNewState );
86 m_Include_Edges_Items->SetValue( aNewState );
87 m_Include_PcbTexts->SetValue( aNewState );
88}
89
91{
92 int numChecked = 0;
93 int numCheckboxesOnDlg = 0;
94 wxCheckBoxState suggestedState = wxCHK_UNDETERMINED; // Assume some but not all are checked
95
96 // Find out how many checkboxes are on this dialog. We do this at runtime so future
97 // changes to the dialog are easier to handle or automatic, depending on the change.
98 const wxWindowList& list = this->GetChildren();
99
100 for( wxWindowList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
101 {
102 wxWindow* current = node->GetData();
103
104 // If casting the child window to a checkbox isn't NULL, then the child is a checkbox
105 if( wxCheckBox* currCB = dynamic_cast<wxCheckBox*>( current ) )
106 {
107 // Need to get count of checkboxes, but not include the "All Items" checkbox (the only
108 // one that allows the 3rd state) or the hidden one (the only one with an empty label)
109 // that keeps the dialog formatted properly
110
111 if( !( currCB->GetLabelText().IsEmpty() || currCB->Is3State() ) )
112 numCheckboxesOnDlg++;
113 }
114 }
115
116 // Tally how many checkboxes are checked. Only include "locked footprints" in the total
117 // if "footprints" is checked.
118 if( m_Include_Modules->GetValue() )
119 {
120 numChecked++;
121
122 if( m_IncludeLockedModules->GetValue() )
123 numChecked++;
124 }
125 else
126 {
127 // If include modules isn't checked then ignore the "Locked Footprints" checkbox in tally
128 numCheckboxesOnDlg--;
129 }
130
133 {
134 if( cb->GetValue() )
135 numChecked++;
136 }
137
138 // Change suggestion if all or none are checked
139
140 if( !numChecked )
141 suggestedState = wxCHK_UNCHECKED;
142 else if( numChecked == numCheckboxesOnDlg )
143 suggestedState = wxCHK_CHECKED;
144
145 return suggestedState;
146}
147
148
149void DIALOG_FILTER_SELECTION::allItemsClicked( wxCommandEvent& aEvent )
150{
151 if( m_All_Items->Get3StateValue() == wxCHK_CHECKED )
152 forceCheckboxStates( true ); // Select all items
153 else
154 forceCheckboxStates( false ); // Clear all items
155}
156
157
159{
160 if( !wxDialog::TransferDataFromWindow() )
161 return false;
162
163 m_options.includeFootprints = m_Include_Modules->GetValue();
164 m_options.includeLockedFootprints = m_IncludeLockedModules->GetValue();
165 m_options.includeTracks = m_Include_Tracks->GetValue();
166 m_options.includeVias = m_Include_Vias->GetValue();
167 m_options.includeZones = m_Include_Zones->GetValue();
168 m_options.includeItemsOnTechLayers = m_Include_Draw_Items->GetValue();
169 m_options.includeBoardOutlineLayer = m_Include_Edges_Items->GetValue();
170 m_options.includePcbTexts = m_Include_PcbTexts->GetValue();
171
172 return true;
173}
DIALOG_FILTER_SELECTION_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Filter Selected Items"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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.