26#include <wx/choicdlg.h>
27#include <wx/filedlg.h>
49#include <wx/wfstream.h>
50#include <wx/zipstrm.h>
62 { wxID_CANCEL,
_(
"Close" ) } } );
76 int btnWidth =
m_stdButtons->GetMinSize().GetWidth() + 10;
78 int minWidth = std::max( btnWidth, panelWidth );
79 wxSize dialogMin = GetMinSize();
81 if( dialogMin.GetWidth() < minWidth )
83 SetMinSize( wxSize( minWidth, dialogMin.GetHeight() ) );
84 SetSize( wxSize( std::max( GetSize().GetWidth(), minWidth ), GetSize().GetHeight() ) );
99 SetTitle(
m_job->GetSettingsDialogTitle() );
113 int btnWidth =
m_stdButtons->GetMinSize().GetWidth() + 10;
115 int minWidth = std::max( btnWidth, panelWidth );
116 wxSize dialogMin = GetMinSize();
118 if( dialogMin.GetWidth() < minWidth )
120 SetMinSize( wxSize( minWidth, dialogMin.GetHeight() ) );
121 SetSize( wxSize( std::max( GetSize().GetWidth(), minWidth ), GetSize().GetHeight() ) );
130 wxFileName fn(
Prj().AbsolutePath(
path ) );
131 wxString ipc_files =
_(
"IPC-2581 Files (*.xml)|*.xml" );
132 wxString compressed_files =
_(
"IPC-2581 Compressed Files (*.zip)|*.zip" );
134 wxFileDialog dlg(
this,
_(
"Export IPC-2581 File" ), fn.GetPath(), fn.GetFullName(),
135 m_cbCompress->IsChecked() ? compressed_files : ipc_files,
136 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
140 if( dlg.ShowModal() == wxID_CANCEL )
192 if( pcbFileName.GetName().empty() )
194 reporter.Report(
_(
"The board must be saved before generating IPC-2581 file." ),
199 if( !
m_parent->IsWritable( pcbFileName ) )
201 reporter.Report( wxString::Format(
_(
"Insufficient permissions to write file '%s'." ),
202 pcbFileName.GetFullPath() ),
220 wxCHECK( aBoard,
false );
231 std::map<std::string, UTF8> props;
233 props[
"sigfig"] = wxString::Format(
"%d", aJob.
m_precision );
241 if( !aJob.
m_mode.IsEmpty() )
242 props[
"mode"] = aJob.
m_mode;
255 if( bomRev.IsEmpty() && aBoard->
GetProject() )
258 bomRev = bomSettings.
bomRev;
260 if( bomRev.IsEmpty() )
264 if( !bomRev.IsEmpty() )
265 props[
"bomrev"] = bomRev;
267 wxString tempFile = wxFileName::CreateTempFileName( wxS(
"pcbnew_ipc" ) );
272 pi->SetProgressReporter( aProgressReporter );
273 pi->SetReporter( aReporter );
274 pi->SaveBoard( tempFile, *aBoard, &props );
280 aReporter->
Report( wxString::Format(
_(
"Error generating IPC-2581 file '%s'.\n%s" ),
286 wxRemoveFile( tempFile );
293 wxFileName tempfn = outPath;
295 wxFileName zipfn = tempFile;
296 zipfn.SetExt(
"zip" );
299 wxFFileOutputStream fnout( zipfn.GetFullPath() );
303 if( FILE* fp = fnout.GetFile()->fp() )
306 wxZipOutputStream
zip( fnout );
307 wxFFileInputStream fnin( tempFile );
309 zip.PutNextEntry( tempfn.GetFullName() );
313 wxRemoveFile( tempFile );
314 tempFile = zipfn.GetFullPath();
318 if( !wxRenameFile( tempFile, outPath ) )
322 aReporter->
Report( wxString::Format(
_(
"Error generating IPC-2581 file '%s'.\n"
323 "Failed to rename temporary file '%s." ),
391 if( !summary.IsEmpty() )
392 summary << wxT(
", " );
397 m_lblIncludes->SetLabel( wxString::Format(
_(
"Includes: %s" ), summary ) );
422 std::vector<IPC2581::SECTION> offered;
423 wxArrayString labels;
432 selected.Add(
static_cast<int>( offered.size() ) );
434 offered.push_back( section );
438 if( offered.empty() )
440 wxMessageBox(
_(
"This data set has no optional sections to choose from." ),
441 _(
"Customize Content" ), wxOK | wxICON_INFORMATION,
this );
445 wxMultiChoiceDialog dlg(
this,
_(
"Choose the optional sections to include." ),
446 _(
"Customize Content" ), labels );
447 dlg.SetSelections( selected );
449 if( dlg.ShowModal() != wxID_OK )
454 for(
int index : dlg.GetSelections() )
479 wxFileName brdFile(
m_parent->GetBoard()->GetFileName() );
480 brdFile.SetExt( wxT(
"xml" ) );
481 path = brdFile.GetFullPath();
494 wxCommandEvent
dummy;
530 if( !
m_job->m_sections.IsEmpty() )
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Information pertinent to a Pcbnew printed circuit board.
PROJECT * GetProject() const
wxStdDialogButtonSizer * m_stdButtons
wxTextCtrl * m_outputFileName
wxButton * m_btnBomFields
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)
wxStaticText * m_lblIncludes
WX_HTML_REPORT_PANEL * m_messagesPanel
STD_BITMAP_BUTTON * m_browseButton
wxChoice * m_choiceDataSet
wxChoice * m_choiceRefDes
wxChoice * m_choiceNetNames
wxCheckBox * m_cbCompress
const IPC2581_BOM_FIELDS & GetFields() const
void onCustomizeClick(wxCommandEvent &event) override
wxString GetNetNamePolicy() const
static bool GenerateFile(JOB_EXPORT_PCB_IPC2581 &aJob, BOARD *aBoard, PROGRESS_REPORTER *aProgressReporter, REPORTER *aReporter)
IPC2581::SECTION_SET resolvedSections() const
IPC2581_BOM_FIELDS m_bomFields
bool TransferDataToWindow() override
void onCompressCheck(wxCommandEvent &event) override
std::optional< wxString > m_sectionKey
Set when the user selects the sections An empty value is then a true selection.
void onDataSetChange(wxCommandEvent &event) override
void onOKClick(wxCommandEvent &event) override
void updateContentSummary()
Set the includes line and the BOM Fields button from the function mode.
bool TransferDataFromWindow() override
static std::vector< std::pair< IPC2581::SECTION, wxString > > sectionLabels()
IPC2581::MODE GetDataSet() const
void onBomFieldsClick(wxCommandEvent &event) override
wxString GetRefDesPolicy() 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 saveToProject()
Keep the dialog selections A job keeps them on the 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...
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()
bool Contains(SECTION aSection) const
SECTION_SET & Set(SECTION aSection, bool aOn=true)
wxString m_sections
Table 4 section key that replaces the optional sections of the function mode An empty value lets the ...
wxString m_refDesPolicy
Set to include or to omit.
wxString m_mode
Table 4 function mode token such as FABRICATION An empty value keeps the content that KiCad wrote bef...
IPC2581_VERSION m_version
wxString m_netNamePolicy
Set to include or to anonymize An anonymous name keeps the connections.
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 constexpr int EXPORT_PHASES
Content logistic history CAD data components the two netlists BOM vendor list references the write an...
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.
SECTION_SET RecommendedOptionalSections(MODE aMode)
Optional schema sections that aMode selects by default.
wxString ModeToken(MODE aMode)
Table 4 function mode token such as FABRICATION.
bool SectionSetFromKeyString(const wxString &aKey, SECTION_SET &aResult)
Read a sectionKey attribute value Return false for an unknown character.
RESOLVE_RESULT ResolveSections(REVISION aRevision, MODE aMode, const SECTION_SET &aRequested)
Compare aRequested with Table 4 and give the attributes to remove and the conflicts.
wxString SectionKeyString(const SECTION_SET &aSet)
Give aSet as a sectionKey attribute value.
SECTION_SET OptionalSections(MODE aMode)
Schema sections that Table 4 marks O for aMode.
std::optional< MODE > ModeFromToken(const wxString &aToken)
Read a Table 4 function mode token in upper case or in lower case.
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 refDes
Set to include or to omit.
wxString bomRev
Explicit BOM revision override set by user.
wxString schRevision
Auto-propagated schematic title block revision.
wxString sections
Table 4 section key for the optional sections.
wxString MPN
Manufacturer part number column.
wxString netNames
Set to include or to anonymize.
wxString id
Internal ID column.
wxString dist
Distributor name column.
wxString mode
Table 4 function mode token.
wxString distPN
Distributor part number column.
IbisParser parser & reporter