KiCad PCB EDA Suite
Loading...
Searching...
No Matches
drc_re_layers_selection_choice_popup.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) 2024 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
24#include <wx/tokenzr.h>
25
27
28
33
34
36{
37 m_checkListBox = new wxCheckListBox( aParent, wxID_ANY );
38 return true;
39}
40
41
46
47
49{
50 m_selectedItemsString = aValue;
51}
52
53
58
59
60void DRC_RE_LAYER_SELECTION_CHOICE_POPUP::populate( const wxArrayString& aItems )
61{
62 m_checkListBox->Clear();
63 m_checkListBox->Append( aItems );
64}
65
66
68{
69 wxArrayInt checkedItems;
70 wxString selectedItems;
71
72 m_checkListBox->GetCheckedItems( checkedItems );
73
74 for( size_t i = 0; i < checkedItems.GetCount(); ++i )
75 {
76 if( !selectedItems.IsEmpty() )
77 selectedItems += ", ";
78
79 selectedItems += m_checkListBox->GetString( checkedItems[i] );
80 }
81
82 SetStringValue( selectedItems );
83
84 return selectedItems;
85}
86
87
89 const std::vector<PCB_LAYER_ID>& aAllLayerIds,
90 const std::function<wxString( PCB_LAYER_ID )>& aNameGetter )
91{
92 wxString input = GetSelectedItemsString();
93 input.Replace( ", ", "," );
94
95 std::vector<PCB_LAYER_ID> selectedLayerIds;
96
97 for( const auto& layerID : aAllLayerIds )
98 {
99 wxString searchString = aNameGetter( layerID );
100 bool found = ( "," + input + "," ).Contains( "," + searchString + "," );
101
102 if( found )
103 {
104 selectedLayerIds.push_back( layerID );
105 }
106 }
107
108 return selectedLayerIds;
109}
110
111
113 const std::vector<PCB_LAYER_ID>& aLayerIDs,
114 const std::function<wxString( PCB_LAYER_ID )>& aNameGetter )
115{
116 wxArrayString names;
117
118 for( const auto& layerID : aLayerIDs )
119 {
120 names.Add( aNameGetter( layerID ) );
121 }
122
123 if( m_checkListBox )
124 {
125 for( const auto& item : names )
126 {
127 int index = m_checkListBox->FindString( item );
128
129 if( index != wxNOT_FOUND )
130 {
131 m_checkListBox->Check( index );
132 }
133 }
134 }
135}
136
137
139 const std::vector<PCB_LAYER_ID>& aLayerIDs,
140 const std::function<wxString( PCB_LAYER_ID )>& aNameGetter )
141{
142 wxArrayString names;
143
144 for( const auto& layerID : aLayerIDs )
145 {
146 names.Add( aNameGetter( layerID ) );
147 }
148
149 populate( names );
150}
int index
std::vector< PCB_LAYER_ID > GetSelectedLayers(const std::vector< PCB_LAYER_ID > &aAllLayerIds, const std::function< wxString(PCB_LAYER_ID)> &nameGetter)
void PopulateWithLayerIDs(const std::vector< PCB_LAYER_ID > &aLayerIDs, const std::function< wxString(PCB_LAYER_ID)> &aNameGetter)
void SetSelections(const std::vector< PCB_LAYER_ID > &aLayerIDs, const std::function< wxString(PCB_LAYER_ID)> &aNameGetter)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60