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 ) :
32 m_fields( aFields )
33{
34 m_textDistributor->SetSize( m_choiceDistPN->GetSize() );
35
36 std::set<wxString> options;
37
38 for( FOOTPRINT* fp : aBoard->Footprints() )
39 {
40 for( PCB_FIELD* field : fp->GetFields() )
41 {
42 wxCHECK2( field, continue );
43
44 options.insert( field->GetName() );
45 }
46 }
47
48 std::vector<wxString> items( options.begin(), options.end() );
49 m_oemRef->Append( items );
50 m_choiceMPN->Append( items );
51 m_choiceMfg->Append( items );
52 m_choiceDistPN->Append( items );
53
54 SetupStandardButtons();
55 finishDialogSettings();
56}
57
58
59wxString DIALOG_EXPORT_2581_BOM::choiceValue( const wxChoice* aChoice ) const
60{
61 if( !aChoice->IsEnabled() || aChoice->GetSelection() <= 0 )
62 return wxEmptyString;
63
64 return aChoice->GetStringSelection();
65}
66
67
69{
70 m_textBomRev->SetValue( m_fields.m_revision );
71
72 if( !m_oemRef->SetStringSelection( m_fields.m_internalId ) )
73 m_oemRef->SetSelection( 0 );
74
75 if( m_choiceMPN->SetStringSelection( m_fields.m_mfgPn ) )
76 {
77 m_choiceMfg->Enable( true );
78
79 if( !m_choiceMfg->SetStringSelection( m_fields.m_mfg ) )
80 m_choiceMfg->SetSelection( 0 );
81 }
82 else
83 {
84 m_choiceMPN->SetSelection( 0 );
85 m_choiceMfg->SetSelection( 0 );
86 m_choiceMfg->Enable( false );
87 }
88
89 if( m_choiceDistPN->SetStringSelection( m_fields.m_distPn ) )
90 {
91 m_textDistributor->Enable( true );
92 m_textDistributor->SetValue( m_fields.m_dist );
93 }
94 else
95 {
96 m_choiceDistPN->SetSelection( 0 );
97 m_textDistributor->SetValue( _( "N/A" ) );
98 m_textDistributor->Enable( false );
99 }
100
101 return true;
102}
103
104
106{
107 m_fields.m_revision = m_textBomRev->GetValue();
108 m_fields.m_internalId = choiceValue( m_oemRef );
109 m_fields.m_mfgPn = choiceValue( m_choiceMPN );
111 m_fields.m_distPn = choiceValue( m_choiceDistPN );
112
113 if( !m_textDistributor->IsEnabled() || m_textDistributor->GetValue() == _( "N/A" ) )
114 m_fields.m_dist = wxEmptyString;
115 else
116 m_fields.m_dist = m_textDistributor->GetValue();
117
118 return true;
119}
120
121
122void DIALOG_EXPORT_2581_BOM::onMfgPNChange( wxCommandEvent& event )
123{
124 if( event.GetSelection() == 0 )
125 {
126 m_choiceMfg->Enable( false );
127 }
128 else
129 {
130 m_choiceMfg->Enable( true );
131
132 // Do not guess the manufacturer if the user selected one
133 if( m_choiceMfg->GetSelection() > 0 )
134 return;
135
136 int it = 0;
137
138 if( it = m_choiceMfg->FindString( wxT( "manufacturer" ) ); it != wxNOT_FOUND )
139 m_choiceMfg->Select( it );
140 else if( it = m_choiceMfg->FindString( _( "manufacturer" ) ); it != wxNOT_FOUND )
141 m_choiceMfg->Select( it );
142 else if( it = m_choiceMfg->FindString( wxT( "mfg" ) ); it != wxNOT_FOUND )
143 m_choiceMfg->Select( it );
144 else if( it = m_choiceMfg->FindString( _( "mfg" ) ); it != wxNOT_FOUND )
145 m_choiceMfg->Select( it );
146 }
147}
148
149
150void DIALOG_EXPORT_2581_BOM::onDistPNChange( wxCommandEvent& event )
151{
152 if( event.GetSelection() == 0 )
153 {
154 m_textDistributor->Enable( false );
155 m_textDistributor->SetValue( _( "N/A" ) );
156 }
157 else
158 {
159 m_textDistributor->Enable( true );
160
161 // Do not guess the distributor if the user selected one
162 if( m_textDistributor->GetValue() != _( "N/A" ) )
163 return;
164
165 wxString dist = m_choiceDistPN->GetStringSelection();
166 dist.MakeUpper();
167
168 // Guess the distributor from the part number column
169
170 if( dist.Contains( wxT( "DIGIKEY" ) ) )
171 {
172 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
173 }
174 else if( dist.Contains( wxT( "DIGI-KEY" ) ) )
175 {
176 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
177 }
178 else if( dist.Contains( wxT( "MOUSER" ) ) )
179 {
180 m_textDistributor->SetValue( wxT( "Mouser" ) );
181 }
182 else if( dist.Contains( wxT( "NEWARK" ) ) )
183 {
184 m_textDistributor->SetValue( wxT( "Newark" ) );
185 }
186 else if( dist.Contains( wxT( "RS COMPONENTS" ) ) )
187 {
188 m_textDistributor->SetValue( wxT( "RS Components" ) );
189 }
190 else if( dist.Contains( wxT( "FARNELL" ) ) )
191 {
192 m_textDistributor->SetValue( wxT( "Farnell" ) );
193 }
194 else if( dist.Contains( wxT( "ARROW" ) ) )
195 {
196 m_textDistributor->SetValue( wxT( "Arrow" ) );
197 }
198 else if( dist.Contains( wxT( "AVNET" ) ) )
199 {
200 m_textDistributor->SetValue( wxT( "Avnet" ) );
201 }
202 else if( dist.Contains( wxT( "TME" ) ) )
203 {
204 m_textDistributor->SetValue( wxT( "TME" ) );
205 }
206 else if( dist.Contains( wxT( "LCSC" ) ) )
207 {
208 m_textDistributor->SetValue( wxT( "LCSC" ) );
209 }
210 }
211}
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
const FOOTPRINTS & Footprints() const
Definition board.h:463
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)
wxString choiceValue(const wxChoice *aChoice) const
#define _(s)
Fields that supply the IPC-2581 BOM section.