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>
33
34#include <set>
35#include <vector>
36#include <wx/filedlg.h>
37
38static wxString s_oemColumn = wxEmptyString;
39
41 DIALOG_EXPORT_2581_BASE( aParent ), m_parent( aParent )
42{
43 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
44
45 SetupStandardButtons( { { wxID_OK, _( "Export" ) },
46 { wxID_CANCEL, _( "Close" ) } } );
47
49
50 if( path.IsEmpty() )
51 {
52 wxFileName brdFile( m_parent->GetBoard()->GetFileName() );
53 brdFile.SetExt( wxT( "xml" ) );
54 path = brdFile.GetFullPath();
55 }
56
57 m_outputFileName->SetValue( path );
58
59 m_textDistributor->SetSize( m_choiceDistPN->GetSize() );
60
61 // Now all widgets have the size fixed, call FinishDialogSettings
63}
64
65
66void DIALOG_EXPORT_2581::onBrowseClicked( wxCommandEvent& event )
67{
68 // Build the absolute path of current output directory to preselect it in the file browser.
69 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
70 wxFileName fn( Prj().AbsolutePath( path ) );
71 wxString ipc_files = _( "IPC-2581 Files (*.xml)|*.xml" );
72 wxString compressed_files = _( "IPC-2581 Compressed Files (*.zip)|*.zip" );
73
74 wxFileDialog dlg( this, _( "Export IPC-2581 File" ), fn.GetPath(), fn.GetFullName(),
75 m_cbCompress->IsChecked() ? compressed_files : ipc_files,
76 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
77
78 if( dlg.ShowModal() == wxID_CANCEL )
79 return;
80
81 m_outputFileName->SetValue( dlg.GetPath() );
82
83}
84
85void DIALOG_EXPORT_2581::onOKClick( wxCommandEvent& event )
86{
88
89 event.Skip();
90}
91
92
93void DIALOG_EXPORT_2581::onCompressCheck( wxCommandEvent& event )
94{
95 if( m_cbCompress->GetValue() )
96 {
97 wxFileName fn = m_outputFileName->GetValue();
98
99 fn.SetExt( "zip" );
100 m_outputFileName->SetValue( fn.GetFullPath() );
101 }
102 else
103 {
104 wxFileName fn = m_outputFileName->GetValue();
105
106 fn.SetExt( "xml" );
107 m_outputFileName->SetValue( fn.GetFullPath() );
108 }
109}
110
111
112void DIALOG_EXPORT_2581::onMfgPNChange( wxCommandEvent& event )
113{
114 if( event.GetSelection() == 0 )
115 {
116 m_choiceMfg->Enable( false );
117 }
118 else
119 {
120 m_choiceMfg->Enable( true );
121
122 // Don't try to guess the manufacturer if the user has already selected one
123 if( m_choiceMfg->GetSelection() > 0 )
124 return;
125
126 int it = 0;
127
128 if( it = m_choiceMfg->FindString( wxT( "manufacturer" ) ); it != wxNOT_FOUND )
129 {
130 m_choiceMfg->Select( it );
131 }
132 else if( it = m_choiceMfg->FindString( _( "manufacturer" ) ); it != wxNOT_FOUND )
133 {
134 m_choiceMfg->Select( it );
135 }
136 else if( it = m_choiceMfg->FindString( wxT( "mfg" ) ); it != wxNOT_FOUND )
137 {
138 m_choiceMfg->Select( it );
139 }
140 else if( it = m_choiceMfg->FindString( _( "mfg" ) ); it != wxNOT_FOUND )
141 {
142 m_choiceMfg->Select( it );
143 }
144 }
145}
146
147
148void DIALOG_EXPORT_2581::onDistPNChange( wxCommandEvent& event )
149{
150 if( event.GetSelection() == 0 )
151 {
152 m_textDistributor->Enable( false );
153 m_textDistributor->SetValue( _( "N/A" ) );
154 }
155 else
156 {
157 m_textDistributor->Enable( true );
158
159 // Don't try to guess the distributor if the user has already selected one
160 if( m_textDistributor->GetValue() != _( "N/A" ) )
161 return;
162
163 wxString dist = m_choiceDistPN->GetStringSelection();
164 dist.MakeUpper();
165
166 // Try to guess the distributor from the part number column
167
168 if( dist.Contains( wxT( "DIGIKEY" ) ) )
169 {
170 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
171 }
172 else if( dist.Contains( wxT( "DIGI-KEY" ) ) )
173 {
174 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
175 }
176 else if( dist.Contains( wxT( "MOUSER" ) ) )
177 {
178 m_textDistributor->SetValue( wxT( "Mouser" ) );
179 }
180 else if( dist.Contains( wxT( "NEWARK" ) ) )
181 {
182 m_textDistributor->SetValue( wxT( "Newark" ) );
183 }
184 else if( dist.Contains( wxT( "RS COMPONENTS" ) ) )
185 {
186 m_textDistributor->SetValue( wxT( "RS Components" ) );
187 }
188 else if( dist.Contains( wxT( "FARNELL" ) ) )
189 {
190 m_textDistributor->SetValue( wxT( "Farnell" ) );
191 }
192 else if( dist.Contains( wxT( "ARROW" ) ) )
193 {
194 m_textDistributor->SetValue( wxT( "Arrow" ) );
195 }
196 else if( dist.Contains( wxT( "AVNET" ) ) )
197 {
198 m_textDistributor->SetValue( wxT( "Avnet" ) );
199 }
200 else if( dist.Contains( wxT( "TME" ) ) )
201 {
202 m_textDistributor->SetValue( wxT( "TME" ) );
203 }
204 else if( dist.Contains( wxT( "LCSC" ) ) )
205 {
206 m_textDistributor->SetValue( wxT( "LCSC" ) );
207 }
208 }
209}
210
211
213{
215
216 std::set<wxString> options;
217 BOARD* board = m_parent->GetBoard();
218
219 for( FOOTPRINT* fp : board->Footprints() )
220 {
221 for( PCB_FIELD* field : fp->GetFields() )
222 options.insert( field->GetName() );
223 }
224
225 m_choiceUnits->SetSelection( cfg->m_Export2581.units );
226 m_precision->SetValue( cfg->m_Export2581.precision );
227 m_versionChoice->SetSelection( cfg->m_Export2581.version );
228 m_cbCompress->SetValue( cfg->m_Export2581.compress );
229
230 wxCommandEvent dummy;
232
233 std::vector<wxString> items( options.begin(), options.end() );
234 m_oemRef->Append( items );
235 m_choiceMPN->Append( items );
236 m_choiceMfg->Append( items );
237 m_choiceDistPN->Append( items );
238
239 m_oemRef->SetStringSelection( s_oemColumn );
240
242
243 if( !m_choiceMPN->SetStringSelection( prj.m_IP2581Bom.id ) )
244 m_choiceMPN->SetSelection( 0 );
245
246 if( m_choiceMPN->SetStringSelection( prj.m_IP2581Bom.MPN ) )
247 {
248 m_choiceMfg->Enable( true );
249
250 if( !m_choiceMfg->SetStringSelection( prj.m_IP2581Bom.mfg ) )
251 m_choiceMfg->SetSelection( 0 );
252 }
253 else
254 {
255 m_choiceMPN->SetSelection( 0 );
256 m_choiceMfg->SetSelection( 0 );
257 m_choiceMfg->Enable( false );
258 }
259
260 if( m_choiceDistPN->SetStringSelection( prj.m_IP2581Bom.distPN ) )
261 {
262 m_textDistributor->Enable( true );
263
264 // The combo box selection can be fixed, so any value can be entered
265 if( !prj.m_IP2581Bom.distPN.empty() )
266 {
267 m_textDistributor->SetValue( prj.m_IP2581Bom.dist );
268 }
269 else
270 {
271 wxCommandEvent evt;
272 onDistPNChange( evt );
273 }
274 }
275 else
276 {
277 m_choiceDistPN->SetSelection( 0 );
278 m_textDistributor->SetValue( _( "N/A" ) );
279 m_textDistributor->Enable( false );
280 }
281
282 return true;
283}
284
286{
288
289 cfg->m_Export2581.units = m_choiceUnits->GetSelection();
290 cfg->m_Export2581.precision = m_precision->GetValue();
291 cfg->m_Export2581.version = m_versionChoice->GetSelection();
292 cfg->m_Export2581.compress = m_cbCompress->GetValue();
293
295 wxString empty;
296
297 prj.m_IP2581Bom.id = GetOEM();
298 prj.m_IP2581Bom.mfg = GetMfg();
299 prj.m_IP2581Bom.MPN = GetMPN();
301 prj.m_IP2581Bom.dist = GetDist();
302
303 s_oemColumn = m_oemRef->GetStringSelection();
304 return true;
305}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
const FOOTPRINTS & Footprints() const
Definition: board.h:323
const wxString & GetFileName() const
Definition: board.h:319
Class DIALOG_EXPORT_2581_BASE.
STD_BITMAP_BUTTON * m_browseButton
void onMfgPNChange(wxCommandEvent &event) override
wxString GetOEM() const
bool TransferDataToWindow() override
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
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...
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:70
struct IP2581_BOM m_IP2581Bom
List of stored 3D viewports (view matrixes)
Definition: project_file.h:180
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
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:334
static wxString s_oemColumn
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
@ LAST_PATH_2581
Definition: project_file.h:58
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.