KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_export_2581_bom.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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
22#include <set>
23
24#include <board.h>
25#include <footprint.h>
26#include <pcb_field.h>
27
28
30 const IPC2581_BOM_FIELDS& aFields, bool aMfgPnOnly ) :
32 m_fields( aFields )
33{
34 m_textDistributor->SetSize( m_choiceDistPN->GetSize() );
35
36 if( aMfgPnOnly )
37 {
38 for( wxWindow* window : std::initializer_list<wxWindow*>{ m_lblBomRev, m_textBomRev, m_lblOEM, m_oemRef,
39 m_staticText7, m_choiceMfg, m_staticText8,
40 m_choiceDistPN, m_staticText9, m_textDistributor } )
41 {
42 window->Hide();
43 }
44 }
45
46 std::set<wxString> options;
47
48 for( FOOTPRINT* fp : aBoard->Footprints() )
49 {
50 for( PCB_FIELD* field : fp->GetFields() )
51 {
52 wxCHECK2( field, continue );
53
54 options.insert( field->GetName() );
55 }
56 }
57
58 std::vector<wxString> items( options.begin(), options.end() );
59 m_oemRef->Append( items );
60 m_choiceMPN->Append( items );
61 m_choiceMfg->Append( items );
62 m_choiceDistPN->Append( items );
63
64 SetupStandardButtons();
65 finishDialogSettings();
66}
67
68
69wxString DIALOG_EXPORT_2581_BOM::choiceValue( const wxChoice* aChoice ) const
70{
71 if( !aChoice->IsEnabled() || aChoice->GetSelection() <= 0 )
72 return wxEmptyString;
73
74 return aChoice->GetStringSelection();
75}
76
77
79{
80 m_textBomRev->SetValue( m_fields.m_revision );
81
82 if( !m_oemRef->SetStringSelection( m_fields.m_internalId ) )
83 m_oemRef->SetSelection( 0 );
84
85 if( m_choiceMPN->SetStringSelection( m_fields.m_mfgPn ) )
86 {
87 m_choiceMfg->Enable( true );
88
89 if( !m_choiceMfg->SetStringSelection( m_fields.m_mfg ) )
90 m_choiceMfg->SetSelection( 0 );
91 }
92 else
93 {
94 m_choiceMPN->SetSelection( 0 );
95 m_choiceMfg->SetSelection( 0 );
96 m_choiceMfg->Enable( false );
97 }
98
99 if( m_choiceDistPN->SetStringSelection( m_fields.m_distPn ) )
100 {
101 m_textDistributor->Enable( true );
102 m_textDistributor->SetValue( m_fields.m_dist );
103 }
104 else
105 {
106 m_choiceDistPN->SetSelection( 0 );
107 m_textDistributor->SetValue( _( "N/A" ) );
108 m_textDistributor->Enable( false );
109 }
110
111 return true;
112}
113
114
116{
117 m_fields.m_revision = m_textBomRev->GetValue();
118 m_fields.m_internalId = choiceValue( m_oemRef );
119 m_fields.m_mfgPn = choiceValue( m_choiceMPN );
121 m_fields.m_distPn = choiceValue( m_choiceDistPN );
122
123 if( !m_textDistributor->IsEnabled() || m_textDistributor->GetValue() == _( "N/A" ) )
124 m_fields.m_dist = wxEmptyString;
125 else
126 m_fields.m_dist = m_textDistributor->GetValue();
127
128 return true;
129}
130
131
132void DIALOG_EXPORT_2581_BOM::onMfgPNChange( wxCommandEvent& event )
133{
134 if( event.GetSelection() == 0 )
135 {
136 m_choiceMfg->Enable( false );
137 }
138 else
139 {
140 m_choiceMfg->Enable( true );
141
142 // Do not guess the manufacturer if the user selected one
143 if( m_choiceMfg->GetSelection() > 0 )
144 return;
145
146 int it = 0;
147
148 if( it = m_choiceMfg->FindString( wxT( "manufacturer" ) ); it != wxNOT_FOUND )
149 m_choiceMfg->Select( it );
150 else if( it = m_choiceMfg->FindString( _( "manufacturer" ) ); it != wxNOT_FOUND )
151 m_choiceMfg->Select( it );
152 else if( it = m_choiceMfg->FindString( wxT( "mfg" ) ); it != wxNOT_FOUND )
153 m_choiceMfg->Select( it );
154 else if( it = m_choiceMfg->FindString( _( "mfg" ) ); it != wxNOT_FOUND )
155 m_choiceMfg->Select( it );
156 }
157}
158
159
160void DIALOG_EXPORT_2581_BOM::onDistPNChange( wxCommandEvent& event )
161{
162 if( event.GetSelection() == 0 )
163 {
164 m_textDistributor->Enable( false );
165 m_textDistributor->SetValue( _( "N/A" ) );
166 }
167 else
168 {
169 m_textDistributor->Enable( true );
170
171 // Do not guess the distributor if the user selected one
172 if( m_textDistributor->GetValue() != _( "N/A" ) )
173 return;
174
175 wxString dist = m_choiceDistPN->GetStringSelection();
176 dist.MakeUpper();
177
178 // Guess the distributor from the part number column
179
180 if( dist.Contains( wxT( "DIGIKEY" ) ) )
181 {
182 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
183 }
184 else if( dist.Contains( wxT( "DIGI-KEY" ) ) )
185 {
186 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
187 }
188 else if( dist.Contains( wxT( "MOUSER" ) ) )
189 {
190 m_textDistributor->SetValue( wxT( "Mouser" ) );
191 }
192 else if( dist.Contains( wxT( "NEWARK" ) ) )
193 {
194 m_textDistributor->SetValue( wxT( "Newark" ) );
195 }
196 else if( dist.Contains( wxT( "RS COMPONENTS" ) ) )
197 {
198 m_textDistributor->SetValue( wxT( "RS Components" ) );
199 }
200 else if( dist.Contains( wxT( "FARNELL" ) ) )
201 {
202 m_textDistributor->SetValue( wxT( "Farnell" ) );
203 }
204 else if( dist.Contains( wxT( "ARROW" ) ) )
205 {
206 m_textDistributor->SetValue( wxT( "Arrow" ) );
207 }
208 else if( dist.Contains( wxT( "AVNET" ) ) )
209 {
210 m_textDistributor->SetValue( wxT( "Avnet" ) );
211 }
212 else if( dist.Contains( wxT( "TME" ) ) )
213 {
214 m_textDistributor->SetValue( wxT( "TME" ) );
215 }
216 else if( dist.Contains( wxT( "LCSC" ) ) )
217 {
218 m_textDistributor->SetValue( wxT( "LCSC" ) );
219 }
220 }
221}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
DIALOG_EXPORT_2581_BOM_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("BOM Fields"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
void onDistPNChange(wxCommandEvent &event) override
void onMfgPNChange(wxCommandEvent &event) override
DIALOG_EXPORT_2581_BOM(wxWindow *aParent, BOARD *aBoard, const IPC2581_BOM_FIELDS &aFields, bool aMfgPnOnly=false)
wxString choiceValue(const wxChoice *aChoice) const
#define _(s)
Fields that supply the IPC-2581 BOM section.