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 (C) 2023 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>
34
35#include <set>
36#include <vector>
37#include <wx/filedlg.h>
38
39static wxString s_oemColumn = wxEmptyString;
40
42 DIALOG_EXPORT_2581_BASE( aParent ),
43 m_parent( aParent ),
44 m_job( nullptr )
45{
46 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
47
48 SetupStandardButtons( { { wxID_OK, _( "Export" ) },
49 { wxID_CANCEL, _( "Close" ) } } );
50
52
53 if( path.IsEmpty() )
54 {
55 wxFileName brdFile( m_parent->GetBoard()->GetFileName() );
56 brdFile.SetExt( wxT( "xml" ) );
57 path = brdFile.GetFullPath();
58 }
59
60 m_outputFileName->SetValue( path );
61
62 m_textDistributor->SetSize( m_choiceDistPN->GetSize() );
63
64 // Fill wxChoice (and others) items with data before calling finishDialogSettings()
65 // to calculate suitable widgets sizes
66 Init();
67
68 // Now all widgets have the size fixed, call FinishDialogSettings
70}
71
72
74 wxWindow* aParent ) :
75 DIALOG_EXPORT_2581_BASE( aParent ),
76 m_parent( aEditFrame ),
77 m_job( aJob )
78{
79 m_browseButton->Hide();
80
81 SetupStandardButtons( { { wxID_OK, _( "Save" ) }, { wxID_CANCEL, _( "Close" ) } } );
82
83 m_outputFileName->SetValue( m_job->GetOutputPath() );
84
85 m_textDistributor->SetSize( m_choiceDistPN->GetSize() );
86
87 // Fill wxChoice (and others) items with data before calling finishDialogSettings()
88 // to calculate suitable widgets sizes
89 Init();
90
91 // Now all widgets have the size fixed, call FinishDialogSettings
93}
94
95
96void DIALOG_EXPORT_2581::onBrowseClicked( wxCommandEvent& event )
97{
98 // Build the absolute path of current output directory to preselect it in the file browser.
99 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
100 wxFileName fn( Prj().AbsolutePath( path ) );
101 wxString ipc_files = _( "IPC-2581 Files (*.xml)|*.xml" );
102 wxString compressed_files = _( "IPC-2581 Compressed Files (*.zip)|*.zip" );
103
104 wxFileDialog dlg( this, _( "Export IPC-2581 File" ), fn.GetPath(), fn.GetFullName(),
105 m_cbCompress->IsChecked() ? compressed_files : ipc_files,
106 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
107
108 if( dlg.ShowModal() == wxID_CANCEL )
109 return;
110
111 m_outputFileName->SetValue( dlg.GetPath() );
112
113}
114
115void DIALOG_EXPORT_2581::onOKClick( wxCommandEvent& event )
116{
117 if( !m_job )
118 {
120 }
121
122 event.Skip();
123}
124
125
126void DIALOG_EXPORT_2581::onCompressCheck( wxCommandEvent& event )
127{
128 if( m_cbCompress->GetValue() )
129 {
130 wxFileName fn = m_outputFileName->GetValue();
131
132 fn.SetExt( "zip" );
133 m_outputFileName->SetValue( fn.GetFullPath() );
134 }
135 else
136 {
137 wxFileName fn = m_outputFileName->GetValue();
138
139 fn.SetExt( "xml" );
140 m_outputFileName->SetValue( fn.GetFullPath() );
141 }
142}
143
144
145void DIALOG_EXPORT_2581::onMfgPNChange( wxCommandEvent& event )
146{
147 if( event.GetSelection() == 0 )
148 {
149 m_choiceMfg->Enable( false );
150 }
151 else
152 {
153 m_choiceMfg->Enable( true );
154
155 // Don't try to guess the manufacturer if the user has already selected one
156 if( m_choiceMfg->GetSelection() > 0 )
157 return;
158
159 int it = 0;
160
161 if( it = m_choiceMfg->FindString( wxT( "manufacturer" ) ); it != wxNOT_FOUND )
162 {
163 m_choiceMfg->Select( it );
164 }
165 else if( it = m_choiceMfg->FindString( _( "manufacturer" ) ); it != wxNOT_FOUND )
166 {
167 m_choiceMfg->Select( it );
168 }
169 else if( it = m_choiceMfg->FindString( wxT( "mfg" ) ); it != wxNOT_FOUND )
170 {
171 m_choiceMfg->Select( it );
172 }
173 else if( it = m_choiceMfg->FindString( _( "mfg" ) ); it != wxNOT_FOUND )
174 {
175 m_choiceMfg->Select( it );
176 }
177 }
178}
179
180
181void DIALOG_EXPORT_2581::onDistPNChange( wxCommandEvent& event )
182{
183 if( event.GetSelection() == 0 )
184 {
185 m_textDistributor->Enable( false );
186 m_textDistributor->SetValue( _( "N/A" ) );
187 }
188 else
189 {
190 m_textDistributor->Enable( true );
191
192 // Don't try to guess the distributor if the user has already selected one
193 if( m_textDistributor->GetValue() != _( "N/A" ) )
194 return;
195
196 wxString dist = m_choiceDistPN->GetStringSelection();
197 dist.MakeUpper();
198
199 // Try to guess the distributor from the part number column
200
201 if( dist.Contains( wxT( "DIGIKEY" ) ) )
202 {
203 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
204 }
205 else if( dist.Contains( wxT( "DIGI-KEY" ) ) )
206 {
207 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
208 }
209 else if( dist.Contains( wxT( "MOUSER" ) ) )
210 {
211 m_textDistributor->SetValue( wxT( "Mouser" ) );
212 }
213 else if( dist.Contains( wxT( "NEWARK" ) ) )
214 {
215 m_textDistributor->SetValue( wxT( "Newark" ) );
216 }
217 else if( dist.Contains( wxT( "RS COMPONENTS" ) ) )
218 {
219 m_textDistributor->SetValue( wxT( "RS Components" ) );
220 }
221 else if( dist.Contains( wxT( "FARNELL" ) ) )
222 {
223 m_textDistributor->SetValue( wxT( "Farnell" ) );
224 }
225 else if( dist.Contains( wxT( "ARROW" ) ) )
226 {
227 m_textDistributor->SetValue( wxT( "Arrow" ) );
228 }
229 else if( dist.Contains( wxT( "AVNET" ) ) )
230 {
231 m_textDistributor->SetValue( wxT( "Avnet" ) );
232 }
233 else if( dist.Contains( wxT( "TME" ) ) )
234 {
235 m_textDistributor->SetValue( wxT( "TME" ) );
236 }
237 else if( dist.Contains( wxT( "LCSC" ) ) )
238 {
239 m_textDistributor->SetValue( wxT( "LCSC" ) );
240 }
241 }
242}
243
244
246{
248
249 std::set<wxString> options;
250 BOARD* board = m_parent->GetBoard();
251
252 for( FOOTPRINT* fp : board->Footprints() )
253 {
254 for( PCB_FIELD* field : fp->GetFields() )
255 options.insert( field->GetName() );
256 }
257
258 if( !m_job )
259 {
260 m_choiceUnits->SetSelection( cfg->m_Export2581.units );
261 m_precision->SetValue( cfg->m_Export2581.precision );
262 m_versionChoice->SetSelection( cfg->m_Export2581.version );
263 m_cbCompress->SetValue( cfg->m_Export2581.compress );
264 }
265 else
266 {
267 m_choiceUnits->SetSelection( static_cast<int>( m_job->m_units ) );
268 m_precision->SetValue( static_cast<int>( m_job->m_precision ) );
270 m_cbCompress->SetValue( m_job->m_compress );
271 }
272
273 wxCommandEvent dummy;
275
276 std::vector<wxString> items( options.begin(), options.end() );
277 m_oemRef->Append( items );
278 m_choiceMPN->Append( items );
279 m_choiceMfg->Append( items );
280 m_choiceDistPN->Append( items );
281
282 m_oemRef->SetStringSelection( s_oemColumn );
283
285
286 wxString internalIdCol;
287 wxString mpnCol;
288 wxString distPnCol;
289 wxString mfgCol;
290 wxString distCol;
291
292 if( !m_job )
293 {
294 internalIdCol = prj.m_IP2581Bom.id;
295 mpnCol = prj.m_IP2581Bom.MPN;
296 distPnCol = prj.m_IP2581Bom.distPN;
297 mfgCol = prj.m_IP2581Bom.mfg;
298 distCol = prj.m_IP2581Bom.dist;
299 }
300 else
301 {
302 internalIdCol = m_job->m_colInternalId;
303 mpnCol = m_job->m_colMfgPn;
304 distPnCol = m_job->m_colDistPn;
305 mfgCol = m_job->m_colMfg;
306 distCol = m_job->m_colDist;
307 }
308
309 if( !m_choiceMPN->SetStringSelection( internalIdCol ) )
310 m_choiceMPN->SetSelection( 0 );
311
312 if( m_choiceMPN->SetStringSelection( mpnCol ) )
313 {
314 m_choiceMfg->Enable( true );
315
316 if( !m_choiceMfg->SetStringSelection( mfgCol ) )
317 m_choiceMfg->SetSelection( 0 );
318 }
319 else
320 {
321 m_choiceMPN->SetSelection( 0 );
322 m_choiceMfg->SetSelection( 0 );
323 m_choiceMfg->Enable( false );
324 }
325
326 if( m_choiceDistPN->SetStringSelection( distPnCol ) )
327 {
328 m_textDistributor->Enable( true );
329
330 // The combo box selection can be fixed, so any value can be entered
331 if( !prj.m_IP2581Bom.distPN.empty() )
332 {
333 m_textDistributor->SetValue( distCol );
334 }
335 else
336 {
337 wxCommandEvent evt;
338 onDistPNChange( evt );
339 }
340 }
341 else
342 {
343 m_choiceDistPN->SetSelection( 0 );
344 m_textDistributor->SetValue( _( "N/A" ) );
345 m_textDistributor->Enable( false );
346 }
347
348 return true;
349}
350
352{
353 if( !m_job )
354 {
356
357 cfg->m_Export2581.units = m_choiceUnits->GetSelection();
358 cfg->m_Export2581.precision = m_precision->GetValue();
359 cfg->m_Export2581.version = m_versionChoice->GetSelection();
360 cfg->m_Export2581.compress = m_cbCompress->GetValue();
361
363 wxString empty;
364
365 prj.m_IP2581Bom.id = GetOEM();
366 prj.m_IP2581Bom.mfg = GetMfg();
367 prj.m_IP2581Bom.MPN = GetMPN();
369 prj.m_IP2581Bom.dist = GetDist();
370
371 s_oemColumn = m_oemRef->GetStringSelection();
372 }
373 else
374 {
375 m_job->SetOutputPath( m_outputFileName->GetValue() );
376
380 m_job->m_colMfg = GetMfg();
382
387 m_job->m_precision = m_precision->GetValue();
389 }
390
391 return true;
392}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const wxString & GetFileName() const
Definition: board.h:327
Class DIALOG_EXPORT_2581_BASE.
STD_BITMAP_BUTTON * m_browseButton
void onMfgPNChange(wxCommandEvent &event) override
wxString GetOEM() const
bool GetCompress() const
void onCompressCheck(wxCommandEvent &event) override
void onOKClick(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={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void SetOutputPath(const wxString &aPath)
Definition: job.cpp:129
wxString GetOutputPath() const
Definition: job.h:119
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
DIALOG_EXPORT_2581 m_Export2581
BOARD * GetBoard() const
The main frame for Pcbnew.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:72
struct IP2581_BOM m_IP2581Bom
Layer pair list for the board.
Definition: project_file.h:186
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
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:348
static wxString s_oemColumn
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
@ LAST_PATH_2581
Definition: project_file.h:59
std::vector< FAB_LAYER_COLOR > dummy
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.