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 // Fill wxChoice (and others) items with data before calling finishDialogSettings()
62 // to calculate suitable widgets sizes
63 Init();
64
65 // Now all widgets have the size fixed, call FinishDialogSettings
67}
68
69
70void DIALOG_EXPORT_2581::onBrowseClicked( wxCommandEvent& event )
71{
72 // Build the absolute path of current output directory to preselect it in the file browser.
73 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
74 wxFileName fn( Prj().AbsolutePath( path ) );
75 wxString ipc_files = _( "IPC-2581 Files (*.xml)|*.xml" );
76 wxString compressed_files = _( "IPC-2581 Compressed Files (*.zip)|*.zip" );
77
78 wxFileDialog dlg( this, _( "Export IPC-2581 File" ), fn.GetPath(), fn.GetFullName(),
79 m_cbCompress->IsChecked() ? compressed_files : ipc_files,
80 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
81
82 if( dlg.ShowModal() == wxID_CANCEL )
83 return;
84
85 m_outputFileName->SetValue( dlg.GetPath() );
86
87}
88
89void DIALOG_EXPORT_2581::onOKClick( wxCommandEvent& event )
90{
92
93 event.Skip();
94}
95
96
97void DIALOG_EXPORT_2581::onCompressCheck( wxCommandEvent& event )
98{
99 if( m_cbCompress->GetValue() )
100 {
101 wxFileName fn = m_outputFileName->GetValue();
102
103 fn.SetExt( "zip" );
104 m_outputFileName->SetValue( fn.GetFullPath() );
105 }
106 else
107 {
108 wxFileName fn = m_outputFileName->GetValue();
109
110 fn.SetExt( "xml" );
111 m_outputFileName->SetValue( fn.GetFullPath() );
112 }
113}
114
115
116void DIALOG_EXPORT_2581::onMfgPNChange( wxCommandEvent& event )
117{
118 if( event.GetSelection() == 0 )
119 {
120 m_choiceMfg->Enable( false );
121 }
122 else
123 {
124 m_choiceMfg->Enable( true );
125
126 // Don't try to guess the manufacturer if the user has already selected one
127 if( m_choiceMfg->GetSelection() > 0 )
128 return;
129
130 int it = 0;
131
132 if( it = m_choiceMfg->FindString( wxT( "manufacturer" ) ); it != wxNOT_FOUND )
133 {
134 m_choiceMfg->Select( it );
135 }
136 else if( it = m_choiceMfg->FindString( _( "manufacturer" ) ); it != wxNOT_FOUND )
137 {
138 m_choiceMfg->Select( it );
139 }
140 else if( it = m_choiceMfg->FindString( wxT( "mfg" ) ); it != wxNOT_FOUND )
141 {
142 m_choiceMfg->Select( it );
143 }
144 else if( it = m_choiceMfg->FindString( _( "mfg" ) ); it != wxNOT_FOUND )
145 {
146 m_choiceMfg->Select( it );
147 }
148 }
149}
150
151
152void DIALOG_EXPORT_2581::onDistPNChange( wxCommandEvent& event )
153{
154 if( event.GetSelection() == 0 )
155 {
156 m_textDistributor->Enable( false );
157 m_textDistributor->SetValue( _( "N/A" ) );
158 }
159 else
160 {
161 m_textDistributor->Enable( true );
162
163 // Don't try to guess the distributor if the user has already selected one
164 if( m_textDistributor->GetValue() != _( "N/A" ) )
165 return;
166
167 wxString dist = m_choiceDistPN->GetStringSelection();
168 dist.MakeUpper();
169
170 // Try to guess the distributor from the part number column
171
172 if( dist.Contains( wxT( "DIGIKEY" ) ) )
173 {
174 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
175 }
176 else if( dist.Contains( wxT( "DIGI-KEY" ) ) )
177 {
178 m_textDistributor->SetValue( wxT( "Digi-Key" ) );
179 }
180 else if( dist.Contains( wxT( "MOUSER" ) ) )
181 {
182 m_textDistributor->SetValue( wxT( "Mouser" ) );
183 }
184 else if( dist.Contains( wxT( "NEWARK" ) ) )
185 {
186 m_textDistributor->SetValue( wxT( "Newark" ) );
187 }
188 else if( dist.Contains( wxT( "RS COMPONENTS" ) ) )
189 {
190 m_textDistributor->SetValue( wxT( "RS Components" ) );
191 }
192 else if( dist.Contains( wxT( "FARNELL" ) ) )
193 {
194 m_textDistributor->SetValue( wxT( "Farnell" ) );
195 }
196 else if( dist.Contains( wxT( "ARROW" ) ) )
197 {
198 m_textDistributor->SetValue( wxT( "Arrow" ) );
199 }
200 else if( dist.Contains( wxT( "AVNET" ) ) )
201 {
202 m_textDistributor->SetValue( wxT( "Avnet" ) );
203 }
204 else if( dist.Contains( wxT( "TME" ) ) )
205 {
206 m_textDistributor->SetValue( wxT( "TME" ) );
207 }
208 else if( dist.Contains( wxT( "LCSC" ) ) )
209 {
210 m_textDistributor->SetValue( wxT( "LCSC" ) );
211 }
212 }
213}
214
215
217{
219
220 std::set<wxString> options;
221 BOARD* board = m_parent->GetBoard();
222
223 for( FOOTPRINT* fp : board->Footprints() )
224 {
225 for( PCB_FIELD* field : fp->GetFields() )
226 options.insert( field->GetName() );
227 }
228
229 m_choiceUnits->SetSelection( cfg->m_Export2581.units );
230 m_precision->SetValue( cfg->m_Export2581.precision );
231 m_versionChoice->SetSelection( cfg->m_Export2581.version );
232 m_cbCompress->SetValue( cfg->m_Export2581.compress );
233
234 wxCommandEvent dummy;
236
237 std::vector<wxString> items( options.begin(), options.end() );
238 m_oemRef->Append( items );
239 m_choiceMPN->Append( items );
240 m_choiceMfg->Append( items );
241 m_choiceDistPN->Append( items );
242
243 m_oemRef->SetStringSelection( s_oemColumn );
244
246
247 if( !m_choiceMPN->SetStringSelection( prj.m_IP2581Bom.id ) )
248 m_choiceMPN->SetSelection( 0 );
249
250 if( m_choiceMPN->SetStringSelection( prj.m_IP2581Bom.MPN ) )
251 {
252 m_choiceMfg->Enable( true );
253
254 if( !m_choiceMfg->SetStringSelection( prj.m_IP2581Bom.mfg ) )
255 m_choiceMfg->SetSelection( 0 );
256 }
257 else
258 {
259 m_choiceMPN->SetSelection( 0 );
260 m_choiceMfg->SetSelection( 0 );
261 m_choiceMfg->Enable( false );
262 }
263
264 if( m_choiceDistPN->SetStringSelection( prj.m_IP2581Bom.distPN ) )
265 {
266 m_textDistributor->Enable( true );
267
268 // The combo box selection can be fixed, so any value can be entered
269 if( !prj.m_IP2581Bom.distPN.empty() )
270 {
271 m_textDistributor->SetValue( prj.m_IP2581Bom.dist );
272 }
273 else
274 {
275 wxCommandEvent evt;
276 onDistPNChange( evt );
277 }
278 }
279 else
280 {
281 m_choiceDistPN->SetSelection( 0 );
282 m_textDistributor->SetValue( _( "N/A" ) );
283 m_textDistributor->Enable( false );
284 }
285
286 return true;
287}
288
290{
292
293 cfg->m_Export2581.units = m_choiceUnits->GetSelection();
294 cfg->m_Export2581.precision = m_precision->GetValue();
295 cfg->m_Export2581.version = m_versionChoice->GetSelection();
296 cfg->m_Export2581.compress = m_cbCompress->GetValue();
297
299 wxString empty;
300
301 prj.m_IP2581Bom.id = GetOEM();
302 prj.m_IP2581Bom.mfg = GetMfg();
303 prj.m_IP2581Bom.MPN = GetMPN();
305 prj.m_IP2581Bom.dist = GetDist();
306
307 s_oemColumn = m_oemRef->GetStringSelection();
308 return true;
309}
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
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.