KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_export_2581.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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <board.h>
23#include <footprint.h>
24#include <kiway_holder.h>
25#include <pcb_edit_frame.h>
26#include <pcbnew_settings.h>
27#include <pgm_base.h>
28#include <project.h>
33
34#include <set>
35#include <vector>
36#include <wx/filedlg.h>
37
38
40 DIALOG_EXPORT_2581_BASE( aParent ),
41 m_parent( aParent ),
42 m_job( nullptr )
43{
44 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
45
46 SetupStandardButtons( { { wxID_OK, _( "Export" ) },
47 { wxID_CANCEL, _( "Close" ) } } );
48
49 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
50 // non-job versions.
51 m_hash_key = TO_UTF8( GetTitle() );
52
53 init();
54
55 // Now all widgets have the size fixed, call FinishDialogSettings
57}
58
59
61 wxWindow* aParent ) :
62 DIALOG_EXPORT_2581_BASE( aParent ),
63 m_parent( aEditFrame ),
64 m_job( aJob )
65{
66 m_browseButton->Hide();
67
69
70 SetTitle( m_job->GetSettingsDialogTitle() );
71
72 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
73 // non-job versions.
74 m_hash_key = TO_UTF8( GetTitle() );
75
76 init();
77
78 // Now all widgets have the size fixed, call FinishDialogSettings
80}
81
82
83void DIALOG_EXPORT_2581::onBrowseClicked( wxCommandEvent& event )
84{
85 // Build the absolute path of current output directory to preselect it in the file browser.
86 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
87 wxFileName fn( Prj().AbsolutePath( path ) );
88 wxString ipc_files = _( "IPC-2581 Files (*.xml)|*.xml" );
89 wxString compressed_files = _( "IPC-2581 Compressed Files (*.zip)|*.zip" );
90
91 wxFileDialog dlg( this, _( "Export IPC-2581 File" ), fn.GetPath(), fn.GetFullName(),
92 m_cbCompress->IsChecked() ? compressed_files : ipc_files,
93 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
94
95 if( dlg.ShowModal() == wxID_CANCEL )
96 return;
97
98 m_outputFileName->SetValue( dlg.GetPath() );
99
100}
101
102void DIALOG_EXPORT_2581::onCompressCheck( wxCommandEvent& event )
103{
104 if( m_cbCompress->GetValue() )
105 {
106 wxFileName fn = m_outputFileName->GetValue();
107
108 fn.SetExt( "zip" );
109 m_outputFileName->SetValue( fn.GetFullPath() );
110 }
111 else
112 {
113 wxFileName fn = m_outputFileName->GetValue();
114
115 fn.SetExt( "xml" );
116 m_outputFileName->SetValue( fn.GetFullPath() );
117 }
118}
119
120
121void DIALOG_EXPORT_2581::onMfgPNChange( wxCommandEvent& event )
122{
123 if( event.GetSelection() == 0 )
124 {
125 m_choiceMfg->Enable( false );
126 }
127 else
128 {
129 m_choiceMfg->Enable( true );
130
131 // Don't try to guess the manufacturer if the user has already selected one
132 if( m_choiceMfg->GetSelection() > 0 )
133 return;
134
135 int it = 0;
136
137 if( it = m_choiceMfg->FindString( wxT( "manufacturer" ) ); it != wxNOT_FOUND )
138 m_choiceMfg->Select( it );
139 else if( it = m_choiceMfg->FindString( _( "manufacturer" ) ); it != wxNOT_FOUND )
140 m_choiceMfg->Select( it );
141 else if( it = m_choiceMfg->FindString( wxT( "mfg" ) ); it != wxNOT_FOUND )
142 m_choiceMfg->Select( it );
143 else if( it = m_choiceMfg->FindString( _( "mfg" ) ); it != wxNOT_FOUND )
144 m_choiceMfg->Select( it );
145 }
146}
147
148
149void DIALOG_EXPORT_2581::onDistPNChange( wxCommandEvent& event )
150{
151 if( event.GetSelection() == 0 )
152 {
153 m_textDistributor->Enable( false );
154 m_textDistributor->SetValue( _( "N/A" ) );
155 }
156 else
157 {
158 m_textDistributor->Enable( true );
159
160 // Don't try to guess the distributor if the user has already selected one
161 if( m_textDistributor->GetValue() != _( "N/A" ) )
162 return;
163
164 wxString dist = m_choiceDistPN->GetStringSelection();
165 dist.MakeUpper();
166
167 // Try to guess the distributor from the part number column
168
169 if( dist.Contains( wxT( "DIGIKEY" ) ) )
170 {
171 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
172 }
173 else if( dist.Contains( wxT( "DIGI-KEY" ) ) )
174 {
175 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
176 }
177 else if( dist.Contains( wxT( "MOUSER" ) ) )
178 {
179 m_textDistributor->SetValue( wxT( "Mouser" ) );
180 }
181 else if( dist.Contains( wxT( "NEWARK" ) ) )
182 {
183 m_textDistributor->SetValue( wxT( "Newark" ) );
184 }
185 else if( dist.Contains( wxT( "RS COMPONENTS" ) ) )
186 {
187 m_textDistributor->SetValue( wxT( "RS Components" ) );
188 }
189 else if( dist.Contains( wxT( "FARNELL" ) ) )
190 {
191 m_textDistributor->SetValue( wxT( "Farnell" ) );
192 }
193 else if( dist.Contains( wxT( "ARROW" ) ) )
194 {
195 m_textDistributor->SetValue( wxT( "Arrow" ) );
196 }
197 else if( dist.Contains( wxT( "AVNET" ) ) )
198 {
199 m_textDistributor->SetValue( wxT( "Avnet" ) );
200 }
201 else if( dist.Contains( wxT( "TME" ) ) )
202 {
203 m_textDistributor->SetValue( wxT( "TME" ) );
204 }
205 else if( dist.Contains( wxT( "LCSC" ) ) )
206 {
207 m_textDistributor->SetValue( wxT( "LCSC" ) );
208 }
209 }
210}
211
212
214{
215 m_textDistributor->SetSize( m_choiceDistPN->GetSize() );
216
217 std::set<wxString> options;
218
219 for( FOOTPRINT* fp : m_parent->GetBoard()->Footprints() )
220 {
221 for( PCB_FIELD* field : fp->GetFields() )
222 options.insert( field->GetName() );
223 }
224
225 std::vector<wxString> items( options.begin(), options.end() );
226 m_oemRef->Append( items );
227 m_choiceMPN->Append( items );
228 m_choiceMfg->Append( items );
229 m_choiceDistPN->Append( items );
230}
231
232
234{
235 if( !m_job )
236 {
237 wxString path = m_outputFileName->GetValue();
238
239 if( path.IsEmpty() )
240 {
241 wxFileName brdFile( m_parent->GetBoard()->GetFileName() );
242 brdFile.SetExt( wxT( "xml" ) );
243 path = brdFile.GetFullPath();
244 m_outputFileName->SetValue( path );
245 }
246 }
247 else
248 {
250 m_precision->SetValue( static_cast<int>( m_job->m_precision ) );
252 m_cbCompress->SetValue( m_job->m_compress );
254 }
255
256 wxCommandEvent dummy;
258
260
261 wxString internalIdCol;
262 wxString mpnCol;
263 wxString distPnCol;
264 wxString mfgCol;
265 wxString distCol;
266
267 if( !m_job )
268 {
269 internalIdCol = prj.m_IP2581Bom.id;
270 mpnCol = prj.m_IP2581Bom.MPN;
271 distPnCol = prj.m_IP2581Bom.distPN;
272 mfgCol = prj.m_IP2581Bom.mfg;
273 distCol = prj.m_IP2581Bom.dist;
274 }
275 else
276 {
277 internalIdCol = m_job->m_colInternalId;
278 mpnCol = m_job->m_colMfgPn;
279 distPnCol = m_job->m_colDistPn;
280 mfgCol = m_job->m_colMfg;
281 distCol = m_job->m_colDist;
282 }
283
284 if( !m_choiceMPN->SetStringSelection( internalIdCol ) )
285 m_choiceMPN->SetSelection( 0 );
286
287 if( m_choiceMPN->SetStringSelection( mpnCol ) )
288 {
289 m_choiceMfg->Enable( true );
290
291 if( !m_choiceMfg->SetStringSelection( mfgCol ) )
292 m_choiceMfg->SetSelection( 0 );
293 }
294 else
295 {
296 m_choiceMPN->SetSelection( 0 );
297 m_choiceMfg->SetSelection( 0 );
298 m_choiceMfg->Enable( false );
299 }
300
301 if( m_choiceDistPN->SetStringSelection( distPnCol ) )
302 {
303 m_textDistributor->Enable( true );
304
305 // The combo box selection can be fixed, so any value can be entered
306 if( !prj.m_IP2581Bom.distPN.empty() )
307 {
308 m_textDistributor->SetValue( distCol );
309 }
310 else
311 {
312 wxCommandEvent evt;
313 onDistPNChange( evt );
314 }
315 }
316 else
317 {
318 m_choiceDistPN->SetSelection( 0 );
319 m_textDistributor->SetValue( _( "N/A" ) );
320 m_textDistributor->Enable( false );
321 }
322
323 return true;
324}
325
326
328{
329 if( !m_job )
330 {
332
333 prj.m_IP2581Bom.id = GetOEM();
334 prj.m_IP2581Bom.mfg = GetMfg();
335 prj.m_IP2581Bom.MPN = GetMPN();
337 prj.m_IP2581Bom.dist = GetDist();
338 }
339 else
340 {
342
346 m_job->m_colMfg = GetMfg();
348
353 m_job->m_precision = m_precision->GetValue();
355 }
356
357 return true;
358}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
const FOOTPRINTS & Footprints() const
Definition: board.h:358
const wxString & GetFileName() const
Definition: board.h:354
Class DIALOG_EXPORT_2581_BASE.
STD_BITMAP_BUTTON * m_browseButton
void onMfgPNChange(wxCommandEvent &event) override
wxString GetOEM() const
bool GetCompress() const
bool TransferDataToWindow() override
void onCompressCheck(wxCommandEvent &event) override
wxString GetMPN() const
void onDistPNChange(wxCommandEvent &event) override
bool TransferDataFromWindow() override
wxString GetDistPN() const
DIALOG_EXPORT_2581(PCB_EDIT_FRAME *aParent)
PCB_EDIT_FRAME * m_parent
wxString GetDist() const
wxString GetMfg() const
void onBrowseClicked(wxCommandEvent &event) override
wxString GetUnitsString() const
JOB_EXPORT_PCB_IPC2581 * m_job
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
Definition: dialog_shim.h:236
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
wxString GetSettingsDialogTitle() const override
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
Definition: job.cpp:153
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition: job.h:232
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
BOARD * GetBoard() const
The main frame for Pcbnew.
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:68
struct IP2581_BOM m_IP2581Bom
Layer pair list for the board.
Definition: project_file.h:208
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:204
void SetBitmap(const wxBitmapBundle &aBmp)
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:355
#define _(s)
see class PGM_BASE
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:429
wxString mfg
Manufacturer name column.
wxString MPN
Manufacturer part number column.
wxString id
Internal ID column.
wxString dist
Distributor name column.
wxString distPN
Distributor part number column.