26#include <wx/filedlg.h>
47#include <wx/wfstream.h>
48#include <wx/zipstrm.h>
60 { wxID_CANCEL,
_(
"Close" ) } } );
74 int btnWidth =
m_stdButtons->GetMinSize().GetWidth() + 10;
76 int minWidth = std::max( btnWidth, panelWidth );
77 wxSize dialogMin = GetMinSize();
79 if( dialogMin.GetWidth() < minWidth )
81 SetMinSize( wxSize( minWidth, dialogMin.GetHeight() ) );
82 SetSize( wxSize( std::max( GetSize().GetWidth(), minWidth ), GetSize().GetHeight() ) );
97 SetTitle(
m_job->GetSettingsDialogTitle() );
111 int btnWidth =
m_stdButtons->GetMinSize().GetWidth() + 10;
113 int minWidth = std::max( btnWidth, panelWidth );
114 wxSize dialogMin = GetMinSize();
116 if( dialogMin.GetWidth() < minWidth )
118 SetMinSize( wxSize( minWidth, dialogMin.GetHeight() ) );
119 SetSize( wxSize( std::max( GetSize().GetWidth(), minWidth ), GetSize().GetHeight() ) );
128 wxFileName fn(
Prj().AbsolutePath(
path ) );
129 wxString ipc_files =
_(
"IPC-2581 Files (*.xml)|*.xml" );
130 wxString compressed_files =
_(
"IPC-2581 Compressed Files (*.zip)|*.zip" );
132 wxFileDialog dlg(
this,
_(
"Export IPC-2581 File" ), fn.GetPath(), fn.GetFullName(),
133 m_cbCompress->IsChecked() ? compressed_files : ipc_files,
134 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
138 if( dlg.ShowModal() == wxID_CANCEL )
166 if( event.GetSelection() == 0 )
180 if( it =
m_choiceMfg->FindString( wxT(
"manufacturer" ) ); it != wxNOT_FOUND )
182 else if( it =
m_choiceMfg->FindString(
_(
"manufacturer" ) ); it != wxNOT_FOUND )
184 else if( it =
m_choiceMfg->FindString( wxT(
"mfg" ) ); it != wxNOT_FOUND )
186 else if( it =
m_choiceMfg->FindString(
_(
"mfg" ) ); it != wxNOT_FOUND )
194 if( event.GetSelection() == 0 )
212 if( dist.Contains( wxT(
"DIGIKEY" ) ) )
216 else if( dist.Contains( wxT(
"DIGI-KEY" ) ) )
220 else if( dist.Contains( wxT(
"MOUSER" ) ) )
224 else if( dist.Contains( wxT(
"NEWARK" ) ) )
228 else if( dist.Contains( wxT(
"RS COMPONENTS" ) ) )
232 else if( dist.Contains( wxT(
"FARNELL" ) ) )
236 else if( dist.Contains( wxT(
"ARROW" ) ) )
240 else if( dist.Contains( wxT(
"AVNET" ) ) )
244 else if( dist.Contains( wxT(
"TME" ) ) )
248 else if( dist.Contains( wxT(
"LCSC" ) ) )
280 if( pcbFileName.GetName().empty() )
282 reporter.
Report(
_(
"The board must be saved before generating IPC-2581 file." ),
287 if( !
m_parent->IsWritable( pcbFileName ) )
289 reporter.
Report( wxString::Format(
_(
"Insufficient permissions to write file '%s'." ),
290 pcbFileName.GetFullPath() ),
307 wxCHECK( aBoard,
false );
318 std::map<std::string, UTF8> props;
320 props[
"sigfig"] = wxString::Format(
"%d", aJob.
m_precision );
330 if( bomRev.IsEmpty() && aBoard->
GetProject() )
333 bomRev = bomSettings.
bomRev;
335 if( bomRev.IsEmpty() )
339 if( !bomRev.IsEmpty() )
340 props[
"bomrev"] = bomRev;
342 wxString tempFile = wxFileName::CreateTempFileName( wxS(
"pcbnew_ipc" ) );
347 pi->SetProgressReporter( aProgressReporter );
348 pi->SaveBoard( tempFile, aBoard, &props );
354 aReporter->
Report( wxString::Format(
_(
"Error generating IPC-2581 file '%s'.\n%s" ),
360 wxRemoveFile( tempFile );
367 wxFileName tempfn = outPath;
369 wxFileName zipfn = tempFile;
370 zipfn.SetExt(
"zip" );
373 wxFFileOutputStream fnout( zipfn.GetFullPath() );
377 if( FILE* fp = fnout.GetFile()->fp() )
380 wxZipOutputStream
zip( fnout );
381 wxFFileInputStream fnin( tempFile );
383 zip.PutNextEntry( tempfn.GetFullName() );
387 wxRemoveFile( tempFile );
388 tempFile = zipfn.GetFullPath();
392 if( !wxRenameFile( tempFile, outPath ) )
396 aReporter->
Report( wxString::Format(
_(
"Error generating IPC-2581 file '%s'.\n"
397 "Failed to rename temporary file '%s." ),
415 std::set<wxString> options;
419 for(
PCB_FIELD* field : fp->GetFields() )
421 wxCHECK2( field,
continue );
423 options.insert( field->GetName() );
427 std::vector<wxString> items( options.begin(), options.end() );
443 wxFileName brdFile(
m_parent->GetBoard()->GetFileName() );
444 brdFile.SetExt( wxT(
"xml" ) );
445 path = brdFile.GetFullPath();
458 wxCommandEvent
dummy;
463 wxString internalIdCol;
478 if( bomRev.IsEmpty() )
485 internalIdCol =
m_job->m_colInternalId;
486 mpnCol =
m_job->m_colMfgPn;
487 distPnCol =
m_job->m_colDistPn;
488 mfgCol =
m_job->m_colMfg;
489 distCol =
m_job->m_colDist;
493 if( !
m_choiceMPN->SetStringSelection( internalIdCol ) )
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Information pertinent to a Pcbnew printed circuit board.
PROJECT * GetProject() const
wxStdDialogButtonSizer * m_stdButtons
wxTextCtrl * m_outputFileName
wxTextCtrl * m_textBomRev
wxChoice * m_versionChoice
DIALOG_EXPORT_2581_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Export IPC-2581"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
WX_HTML_REPORT_PANEL * m_messagesPanel
wxTextCtrl * m_textDistributor
STD_BITMAP_BUTTON * m_browseButton
wxChoice * m_choiceDistPN
wxCheckBox * m_cbCompress
void onMfgPNChange(wxCommandEvent &event) override
static bool GenerateFile(JOB_EXPORT_PCB_IPC2581 &aJob, BOARD *aBoard, PROGRESS_REPORTER *aProgressReporter, REPORTER *aReporter)
bool TransferDataToWindow() override
void onCompressCheck(wxCommandEvent &event) override
void onOKClick(wxCommandEvent &event) override
void onDistPNChange(wxCommandEvent &event) override
bool TransferDataFromWindow() override
wxString GetDistPN() const
DIALOG_EXPORT_2581(PCB_EDIT_FRAME *aParent)
PCB_EDIT_FRAME * m_parent
void onBrowseClicked(wxCommandEvent &event) override
wxString GetUnitsString() const
JOB_EXPORT_PCB_IPC2581 * m_job
wxString GetOutputPath() const
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...
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
IPC2581_VERSION m_version
void AddOutput(wxString aOutputPath)
wxString GetFullOutputPath(PROJECT *aProject) const
Returns the full output path for the job, taking into account the configured output path,...
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static bool EnsurePathExists(const wxString &aPath, bool aPathToFile=false)
Attempts to create a given path if it does not exist.
The main frame for Pcbnew.
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
A progress reporter interface for use in multi-threaded environments.
The backing store for a PROJECT, in JSON format.
struct IP2581_BOM m_IP2581Bom
Layer pair list for the board.
virtual PROJECT_FILE & GetProjectFile() const
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
static void ResolvePossibleSymlinks(wxFileName &aFilename)
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
static const std::string Ipc2581FileExtension
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
wxString mfg
Manufacturer name column.
wxString bomRev
Explicit BOM revision override set by user.
wxString schRevision
Auto-propagated schematic title block revision.
wxString MPN
Manufacturer part number column.
wxString id
Internal ID column.
wxString dist
Distributor name column.
wxString distPN
Distributor part number column.