26#include <wx/stdpaths.h>
27#include <wx/process.h>
29#include <wx/filedlg.h>
99 const wxString& aBoardPath,
102 m_editFrame( aEditFrame ),
104 m_boardPath( aBoardPath )
110 { wxID_CANCEL,
_(
"Close" ) } } );
120 brdFile.SetExt( wxT(
"step" ) );
121 path = brdFile.GetFullPath();
192 wxCommandEvent
dummy;
199 tmpStr = wxEmptyString;
241 wxCommandEvent
dummy;
249 tmpStr = wxEmptyString;
255 size_t bad_count = 0;
261 if( model.m_Scale.x != 1.0 || model.m_Scale.y != 1.0 || model.m_Scale.z != 1.0 )
263 bad_scales.Append( wxS(
"\n") );
264 bad_scales.Append( model.m_Filename );
273 if( !bad_scales.empty()
274 && !
Pgm().GetCommonSettings()->m_DoNotShowAgain.scaled_3d_models_warning )
276 wxString extendedMsg =
_(
"Non-unity scaled models:" ) + wxT(
"\n" ) + bad_scales;
279 "Model scaling is not reliable for mechanical export." ),
280 _(
"Model Scale Warning" ), wxOK | wxICON_WARNING );
281 msgDlg.SetExtendedMessage( extendedMsg );
315 catch(
const std::runtime_error& e )
317 wxFAIL_MSG( e.what() );
390 wxFileName autosaveProjFile;
397 "Please save the PCB and try again" ) );
406 autosaveProjFile = brdFile;
407 autosaveProjFile.SetName( autosaveFileName );
408 autosaveProjFile.SetExt(
"kicad_pro" );
412 brdFile.SetName( autosaveFileName );
419 if( !autosaveProjFile.GetFullPath().IsEmpty() )
420 wxRemoveFile( autosaveProjFile.GetFullPath() );
445 wxString
filter =
_(
"STEP files" )
447 +
_(
"Binary glTF files" )
451 +
_(
"BREP (OCCT) files" )
461 wxFileName fn(
Prj().AbsolutePath(
path ) );
463 wxFileDialog dlg(
this,
_(
"3D Model Output File" ), fn.GetPath(), fn.GetFullName(),
filter,
466 if( dlg.ShowModal() == wxID_CANCEL )
469 path = dlg.GetPath();
472 fn = wxFileName(
path );
490 int sepIdx = std::max(
path.Find(
'/',
true ),
path.Find(
'\\',
true ) );
491 int dotIdx =
path.Find(
'.',
true );
493 if( dotIdx == -1 || dotIdx < sepIdx )
494 path <<
'.' << newExt;
496 path =
path.Mid( 0, dotIdx ) <<
'.' << newExt;
528 std::function<bool( wxString* )> textResolver =
529 [&]( wxString* token ) ->
bool
572 case 0: tolerance = 0.001;
break;
574 case 1: tolerance = 0.01;
break;
575 case 2: tolerance = 0.1;
break;
588 chainingEpsilon,
nullptr );
592 _(
"Board outline is missing or not closed using %.3f mm tolerance.\n"
593 "Run DRC for a full analysis." ), tolerance ) );
597 wxFileName fn(
Prj().AbsolutePath(
path ) );
601 msg.Printf(
_(
"File '%s' already exists. Do you want overwrite this file?" ),
604 if( wxMessageBox( msg,
_(
"STEP/GLTF Export" ), wxYES_NO | wxICON_QUESTION,
this ) == wxNO )
608 wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
611 if( appK2S.GetPath().Find(
"/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
613 appK2S.AppendDir( wxT(
".." ) );
614 appK2S.AppendDir( wxT(
".." ) );
615 appK2S.AppendDir( wxT(
".." ) );
616 appK2S.AppendDir( wxT(
".." ) );
617 appK2S.AppendDir( wxT(
"MacOS" ) );
620 if( wxGetEnv( wxT(
"KICAD_RUN_FROM_BUILD_DIR" ),
nullptr ) )
622 appK2S.RemoveLastDir();
623 appK2S.AppendDir(
"kicad" );
627 appK2S.SetName( wxT(
"kicad-cli" ) );
630 wxString cmdK2S = wxT(
"\"" );
631 cmdK2S.Append( appK2S.GetFullPath() );
632 cmdK2S.Append( wxT(
"\"" ) );
634 cmdK2S.Append( wxT(
" pcb" ) );
635 cmdK2S.Append( wxT(
" export" ) );
637 cmdK2S.Append( wxT(
" " ) );
641 cmdK2S.Append( wxT(
" --no-unspecified" ) );
644 cmdK2S.Append( wxT(
" --no-dnp" ) );
647 cmdK2S.Append( wxT(
" --subst-models" ) );
650 cmdK2S.Append( wxT(
" --no-optimize-step" ) );
653 cmdK2S.Append( wxT(
" --no-board-body" ) );
656 cmdK2S.Append( wxT(
" --no-components" ) );
659 cmdK2S.Append( wxT(
" --include-tracks" ) );
662 cmdK2S.Append( wxT(
" --include-pads" ) );
665 cmdK2S.Append( wxT(
" --include-zones" ) );
668 cmdK2S.Append( wxT(
" --include-inner-copper" ) );
671 cmdK2S.Append( wxT(
" --include-silkscreen" ) );
674 cmdK2S.Append( wxT(
" --include-soldermask" ) );
677 cmdK2S.Append( wxT(
" --fuse-shapes" ) );
680 cmdK2S.Append( wxT(
" --cut-vias-in-body" ) );
683 cmdK2S.Append( wxT(
" --fill-all-vias" ) );
692 cmdK2S.Append( wxString::Format( wxT(
" --net-filter %c%s%c" ), dblquote,
m_netFilter,
700 wxArrayString components;
703 std::for_each( selection.
begin(), selection.
end(),
706 if( item->Type() == PCB_FOOTPRINT_T )
707 components.push_back( static_cast<FOOTPRINT*>( item )->GetReference() );
710 cmdK2S.Append( wxString::Format( wxT(
" --component-filter %c%s%c" ), dblquote,
711 wxJoin( components,
',' ), dblquote ) );
716 cmdK2S.Append( wxString::Format( wxT(
" --component-filter %c%s%c" ), dblquote,
727 wxFAIL_MSG( wxT(
"Unsupported origin option: how did we get here?" ) );
731 cmdK2S.Append( wxT(
" --drill-origin" ) );
735 cmdK2S.Append( wxT(
" --grid-origin" ) );
751 cmdK2S.Append( wxString::Format( wxT(
" --user-origin=%c%.6fx%.6fmm%c" ),
752 quote, xOrg, yOrg, quote ) );
763 cmdK2S.Append( wxString::Format( wxT(
" --user-origin=%c%.6fx%.6fmm%c" ),
764 quote, xOrg, yOrg, quote ) );
771 cmdK2S.Append( wxString::Format( wxT(
" --min-distance=%c%.3fmm%c" ),
772 quote, tolerance, quote ) );
776 cmdK2S.Append( wxString::Format( wxT(
" -f -o %c%s%c" ),
777 dblquote, fn.GetFullPath(), dblquote ) );
781 cmdK2S.Append( wxString::Format( wxT(
" %c%s%c" ), dblquote,
m_boardPath, dblquote ) );
783 wxLogTrace(
traceKiCad2Step, wxT(
"export step command: %s" ), cmdK2S );
constexpr EDA_IU_SCALE pcbIUScale
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
bool ResolveTextVar(wxString *token, int aDepth) const
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
const FOOTPRINTS & Footprints() const
const wxString & GetFileName() const
constexpr const Vec GetCenter() const
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
Class DIALOG_EXPORT_STEP_BASE.
wxCheckBox * m_cbExportTracks
wxCheckBox * m_cbSubstModels
TEXT_CTRL_EVAL * m_STEP_Xorg
TEXT_CTRL_EVAL * m_STEP_Yorg
wxRadioButton * m_rbOnlySelected
wxRadioButton * m_rbGridOrigin
wxCheckBox * m_cbExportBody
wxCheckBox * m_cbRemoveUnspecified
wxCheckBox * m_cbOverwriteFile
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
wxChoice * m_STEP_OrgUnitChoice
wxTextCtrl * m_txtNetFilter
wxCheckBox * m_cbExportSoldermask
wxCheckBox * m_cbExportPads
wxChoice * m_choiceFormat
wxCheckBox * m_cbExportZones
wxRadioButton * m_rbAllComponents
wxRadioButton * m_rbUserDefinedOrigin
wxCheckBox * m_cbExportSilkscreen
wxRadioButton * m_rbFilteredComponents
wxCheckBox * m_cbCutViasInBody
wxRadioButton * m_rbDrillAndPlotOrigin
wxTextCtrl * m_txtComponentFilter
STD_BITMAP_BUTTON * m_browseButton
wxCheckBox * m_cbFillAllVias
void onFormatChoice(wxCommandEvent &event) override
STEP_ORIGIN_OPTION GetOriginOption()
static int m_formatLastChoice
static bool m_exportSoldermask
static bool m_cutViasInBody
void OnFmtChoiceOptionChanged()
int GetOrgUnitsChoice() const
void onCbExportComponents(wxCommandEvent &event) override
static bool m_fillAllVias
PCB_EDIT_FRAME * m_editFrame
void OnComponentModeChange(wxCommandEvent &event) override
@ STEP_ORIGIN_BOARD_CENTER
DIALOG_EXPORT_STEP(PCB_EDIT_FRAME *aEditFrame, const wxString &aBoardPath)
static COMPONENT_MODE m_componentMode
void onUpdateXPos(wxUpdateUIEvent &aEvent) override
static bool m_exportComponents
static bool m_exportZones
STEP_ORIGIN_OPTION m_origin
JOB_EXPORT_PCB_3D * m_job
void onExportButton(wxCommandEvent &aEvent) override
static bool m_exportBoardBody
static bool m_exportSilkscreen
static wxString m_componentFilter
static int m_toleranceLastChoice
static bool m_optimizeStep
void onUpdateUnits(wxUpdateUIEvent &aEvent) override
bool GetNoUnspecifiedOption()
static bool m_exportInnerCopper
void onUpdateYPos(wxUpdateUIEvent &aEvent) override
static bool m_exportTracks
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.
bool m_IncludeUnspecified
wxString m_ComponentFilter
JOB_EXPORT_PCB_3D::FORMAT m_format
wxString GetSettingsDialogTitle() const override
void SetStepFormat(EXPORTER_STEP_PARAMS::FORMAT aFormat)
EXPORTER_STEP_PARAMS m_3dparams
Despite the name; also used for other formats.
void SetConfiguredOutputPath(const wxString &aPath)
Sets the configured output path for the job, this path is always saved to file.
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
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.
DIALOG_EXPORT_STEP m_ExportStep
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
The main frame for Pcbnew.
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
bool doAutoSave() override
Perform auto save when the board has been modified and not saved within the auto save interval.
void OnExportSTEP(wxCommandEvent &event)
Export the current BOARD to a STEP assembly.
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
bool IsContentModified() const override
Get if the current board has been modified but not saved.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
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.
void SaveProjectCopy(const wxString &aFullPath, PROJECT *aProject=nullptr)
Save a copy of the current project under the given path.
Represent a set of closed polygons.
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer and display it in the wxTextCtrl.
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, 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::string BrepFileExtension
static const std::string StepFileAbrvExtension
static const std::string XaoFileExtension
static const std::string GltfBinaryFileExtension
static const std::string StlFileExtension
static const std::string AutoSaveFilePrefix
static const std::string PlyFileExtension
static const std::string StepFileExtension
const wxChar *const traceKiCad2Step
Flag to enable KiCad2Step debug tracing.
This file is part of the common library.
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
KICOMMON_API double DoubleValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue to a double.
SETTINGS_MANAGER * GetSettingsManager()
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
constexpr double IUTomm(int iu) const
constexpr int mmToIU(double mm) const
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().