29#include <wx/stdpaths.h>
30#include <wx/process.h>
32#include <wx/filedlg.h>
116 { wxID_CANCEL,
_(
"Close" ) } } );
120 SetTitle(
m_job->GetSettingsDialogTitle() );
139 size_t bad_count = 0;
145 if(
model.m_Scale.x != 1.0 ||
model.m_Scale.y != 1.0 ||
model.m_Scale.z != 1.0 )
147 bad_scales.Append( wxS(
"\n") );
148 bad_scales.Append(
model.m_Filename );
157 if( !bad_scales.empty() && !
Pgm().GetCommonSettings()->m_DoNotShowAgain.scaled_3d_models_warning )
159 wxString extendedMsg =
_(
"Non-unity scaled models:" ) + wxT(
"\n" ) + bad_scales;
162 "mechanical export." ),
163 _(
"Model Scale Warning" ), wxOK | wxICON_WARNING );
164 msgDlg.SetExtendedMessage( extendedMsg );
186 wxFileName brdFile(
m_editFrame->GetBoard()->GetFileName() );
187 brdFile.SetExt( wxT(
"step" ) );
191 wxString currentVariant =
m_editFrame->GetBoard()->GetCurrentVariant();
193 if( !currentVariant.IsEmpty() )
197 if( idx != wxNOT_FOUND )
210 if(
m_job->m_3dparams.m_UseDrillOrigin )
212 else if(
m_job->m_3dparams.m_UseGridOrigin )
214 else if(
m_job->m_3dparams.m_UseDefinedOrigin )
216 else if(
m_job->m_3dparams.m_UsePcbCenterOrigin )
240 if(
m_job->m_3dparams.m_BoardOutlinesChainingEpsilon > 0.05 )
242 else if(
m_job->m_3dparams.m_BoardOutlinesChainingEpsilon < 0.005 )
250 if( !
m_job->m_variant.IsEmpty() )
254 if( idx != wxNOT_FOUND )
261 if( formats.second ==
m_job->m_3dparams.m_Format )
270 wxCommandEvent
dummy;
282 if( ( selection != 0 ) && ( selection != wxNOT_FOUND ) )
292 wxFileName brdFile =
board->GetFileName();
316 wxString
filter =
_(
"STEP files" )
318 +
_(
"Binary glTF files" )
322 +
_(
"BREP (OCCT) files" )
328 +
_(
"Universal 3D files" )
336 wxFileName fn(
Prj().AbsolutePath(
path ) );
338 wxFileDialog dlg(
this,
_(
"3D Model Output File" ), fn.GetPath(), fn.GetFullName(),
filter, wxFD_SAVE );
342 if( dlg.ShowModal() == wxID_CANCEL )
345 path = dlg.GetPath();
348 fn = wxFileName(
path );
368 if( choices.second == idx )
370 newExt = choices.first;
377 int sepIdx = std::max(
path.Find(
'/',
true ),
path.Find(
'\\',
true ) );
378 int dotIdx =
path.Find(
'.',
true );
380 if( dotIdx == -1 || dotIdx < sepIdx )
381 path <<
'.' << newExt;
383 path =
path.Mid( 0, dotIdx ) <<
'.' << newExt;
413 case 0: tolerance = 0.001;
break;
415 case 1: tolerance = 0.01;
break;
416 case 2: tolerance = 0.1;
break;
422 std::function<bool( wxString* )> textResolver =
423 [&]( wxString* token ) ->
bool
425 return m_editFrame->GetBoard()->ResolveTextVar( token, 0 );
443 int chainingEpsilon =
pcbIUScale.mmToIU( tolerance );
451 "%.3f mm tolerance.\n"
452 "Run DRC for a full analysis." ),
457 wxFileName fn(
Prj().AbsolutePath(
path ) );
461 msg.Printf(
_(
"File '%s' already exists. Do you want overwrite this file?" ), fn.GetFullPath() );
463 if( wxMessageBox( msg,
_(
"STEP/GLTF Export" ), wxYES_NO | wxICON_QUESTION,
this ) == wxNO )
467 wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
470 if( appK2S.GetPath().Find(
"/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
472 appK2S.AppendDir( wxT(
".." ) );
473 appK2S.AppendDir( wxT(
".." ) );
474 appK2S.AppendDir( wxT(
".." ) );
475 appK2S.AppendDir( wxT(
".." ) );
476 appK2S.AppendDir( wxT(
"MacOS" ) );
479 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
481 appK2S.RemoveLastDir();
482 appK2S.AppendDir(
"kicad" );
486 appK2S.SetName( wxT(
"kicad-cli" ) );
489 wxString cmdK2S = wxT(
"\"" );
490 cmdK2S.Append( appK2S.GetFullPath() );
491 cmdK2S.Append( wxT(
"\"" ) );
493 cmdK2S.Append( wxT(
" pcb" ) );
494 cmdK2S.Append( wxT(
" export" ) );
496 cmdK2S.Append( wxT(
" " ) );
500 cmdK2S.Append( wxT(
" --no-unspecified" ) );
503 cmdK2S.Append( wxT(
" --no-dnp" ) );
506 cmdK2S.Append( wxT(
" --subst-models" ) );
509 cmdK2S.Append( wxT(
" --no-optimize-step" ) );
512 cmdK2S.Append( wxT(
" --no-board-body" ) );
515 cmdK2S.Append( wxT(
" --no-components" ) );
518 cmdK2S.Append( wxT(
" --include-tracks" ) );
521 cmdK2S.Append( wxT(
" --include-pads" ) );
524 cmdK2S.Append( wxT(
" --include-zones" ) );
527 cmdK2S.Append( wxT(
" --include-inner-copper" ) );
530 cmdK2S.Append( wxT(
" --include-silkscreen" ) );
533 cmdK2S.Append( wxT(
" --include-soldermask" ) );
536 cmdK2S.Append( wxT(
" --fuse-shapes" ) );
539 cmdK2S.Append( wxT(
" --cut-vias-in-body" ) );
542 cmdK2S.Append( wxT(
" --fill-all-vias" ) );
551 if( !selectedVariant.IsEmpty() )
553 cmdK2S.Append( wxString::Format( wxT(
" --variant %c%s%c" ),
554 dblquote, selectedVariant, dblquote ) );
559 cmdK2S.Append( wxString::Format( wxT(
" --net-filter %c%s%c" ),
565 wxArrayString components;
568 std::for_each( selection.
begin(), selection.
end(),
571 if( item->Type() == PCB_FOOTPRINT_T )
572 components.push_back( static_cast<FOOTPRINT*>( item )->GetReference() );
575 cmdK2S.Append( wxString::Format( wxT(
" --component-filter %c%s%c" ),
576 dblquote, wxJoin( components,
',' ), dblquote ) );
580 cmdK2S.Append( wxString::Format( wxT(
" --component-filter %c%s%c" ),
586 cmdK2S.Append( wxT(
" --drill-origin" ) );
590 cmdK2S.Append( wxT(
" --grid-origin" ) );
598 cmdK2S.Append( wxString::Format( wxT(
" --user-origin=%c%.6fx%.6fmm%c" ),
599 quote, xOrg, yOrg, quote ) );
608 cmdK2S.Append( wxString::Format( wxT(
" --user-origin=%c%.6fx%.6fmm%c" ),
609 quote, xOrg, yOrg, quote ) );
613 wxFAIL_MSG( wxT(
"Unsupported origin option: how did we get here?" ) );
618 cmdK2S.Append( wxString::Format( wxT(
" --min-distance=%c%.3fmm%c" ),
619 quote, tolerance, quote ) );
623 cmdK2S.Append( wxString::Format( wxT(
" -f -o %c%s%c" ),
624 dblquote, fn.GetFullPath(), dblquote ) );
628 cmdK2S.Append( wxString::Format( wxT(
" %c%s%c" ), dblquote,
m_boardPath, dblquote ) );
630 wxLogTrace(
traceKiCad2Step, wxT(
"export step command: %s" ), cmdK2S );
657 m_job->m_3dparams.m_BoardOutlinesChainingEpsilon = tolerance;
661 m_job->SetStepFormat( *formatChoice );
665 wxASSERT_MSG(
false, wxString::Format(
"Unknown format value %d",
m_choiceFormat->GetSelection() ) );
670 switch(
m_job->m_3dparams.m_Format )
683 m_job->m_3dparams.m_UseDrillOrigin =
false;
684 m_job->m_3dparams.m_UseGridOrigin =
false;
685 m_job->m_3dparams.m_UseDefinedOrigin =
false;
686 m_job->m_3dparams.m_UsePcbCenterOrigin =
false;
690 m_job->m_3dparams.m_UseDrillOrigin =
true;
694 m_job->m_3dparams.m_UseGridOrigin =
true;
701 m_job->m_3dparams.m_UseDefinedOrigin =
true;
711 m_job->m_3dparams.m_UsePcbCenterOrigin =
true;
constexpr EDA_IU_SCALE pcbIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
int ExportSTEP(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
constexpr const Vec GetCenter() const
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
wxCheckBox * m_cbExportTracks
wxChoice * m_choiceVariant
wxCheckBox * m_cbSubstModels
wxRadioButton * m_rbOnlySelected
wxRadioButton * m_rbGridOrigin
TEXT_CTRL_EVAL * m_originXCtrl
wxStaticText * m_originXUnits
wxStaticText * m_originYUnits
wxCheckBox * m_cbExportBody
wxCheckBox * m_cbRemoveUnspecified
wxCheckBox * m_cbOverwriteFile
wxStaticText * m_originXLabel
wxCheckBox * m_cbRemoveDNP
wxBoxSizer * bSizerSTEPFile
wxCheckBox * m_cbExportComponents
wxCheckBox * m_cbOptimizeStep
wxCheckBox * m_cbFuseShapes
wxRadioButton * m_rbBoardCenterOrigin
wxTextCtrl * m_outputFileName
wxCheckBox * m_cbExportInnerCopper
wxChoice * m_choiceTolerance
wxStaticText * m_originYLabel
wxTextCtrl * m_txtNetFilter
wxCheckBox * m_cbExportSoldermask
wxCheckBox * m_cbExportPads
wxChoice * m_choiceFormat
wxCheckBox * m_cbExportZones
DIALOG_EXPORT_STEP_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Export 3D Model"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxRadioButton * m_rbAllComponents
wxRadioButton * m_rbUserDefinedOrigin
wxCheckBox * m_cbExportSilkscreen
wxRadioButton * m_rbFilteredComponents
TEXT_CTRL_EVAL * m_originYCtrl
wxCheckBox * m_cbCutViasInBody
wxRadioButton * m_rbDrillAndPlotOrigin
wxTextCtrl * m_txtComponentFilter
STD_BITMAP_BUTTON * m_browseButton
wxCheckBox * m_cbFillAllVias
void onFormatChoice(wxCommandEvent &event) override
void OnFmtChoiceOptionChanged()
void onCbExportComponents(wxCommandEvent &event) override
PCB_EDIT_FRAME * m_editFrame
void OnComponentModeChange(wxCommandEvent &event) override
DIALOG_EXPORT_STEP(PCB_EDIT_FRAME *aEditFrame, const wxString &aBoardPath)
wxString getSelectedVariant() const
void onUpdateXPos(wxUpdateUIEvent &aEvent) override
JOB_EXPORT_PCB_3D * m_job
bool TransferDataToWindow() override
void onExportButton(wxCommandEvent &aEvent) override
void onUpdateYPos(wxUpdateUIEvent &aEvent) override
void onBrowseClicked(wxCommandEvent &aEvent) 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...
A base class for most all the KiCad significant classes used in schematics and boards.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
bool DoNotShowAgain() const
Checks the 'do not show again' setting for the dialog.
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
The main frame for Pcbnew.
virtual COMMON_SETTINGS * GetCommonSettings() const
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Represent a set of closed polygons.
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
bool BuildBoardPolygonOutlines(BOARD *aBoard, SHAPE_POLY_SET &aOutlines, int aErrorMax, int aChainingEpsilon, bool aInferOutlineIfNecessary, OUTLINE_ERROR_HANDLER *aErrorHandler, bool aAllowUseArcsInPolygons)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
static const std::map< wxString, int > c_formatExtToChoice
static const std::vector< wxString > c_formatCommand
static const std::map< int, EXPORTER_STEP_PARAMS::FORMAT > c_formatJobCommand
static const std::string BrepFileExtension
static const std::string StepFileAbrvExtension
static const std::string XaoFileExtension
static const std::string GltfBinaryFileExtension
static const std::string U3DFileExtension
static const std::string PdfFileExtension
static const std::string StlFileExtension
static const std::string PlyFileExtension
static const std::string StepFileExtension
static const std::string StepZFileAbrvExtension
const wxChar *const traceKiCad2Step
Flag to enable KiCad2Step debug tracing.
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
PGM_BASE & Pgm()
The global program "get" accessor.
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
bool scaled_3d_models_warning
wxLogTrace helper definitions.
VECTOR2< double > VECTOR2D
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
Definition of file extensions used in Kicad.
#define FN_NORMALIZE_FLAGS
Default flags to pass to wxFileName::Normalize().