KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_export_step.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) 2016 Cirilo Bernardo
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <wx/log.h>
26#include <wx/stdpaths.h>
27#include <wx/process.h>
28#include <wx/string.h>
29#include <wx/filedlg.h>
30
31#include <pgm_base.h>
32#include <board.h>
33#include <confirm.h>
34#include <kidialog.h>
36#include "dialog_export_step.h"
38#include <footprint.h>
39#include <kiface_base.h>
40#include <locale_io.h>
41#include <math/vector3.h>
42#include <pcb_edit_frame.h>
43#include <pcbnew_settings.h>
45#include <project/project_file.h> // LAST_PATH_TYPE
46#include <reporter.h>
47#include <trace_helpers.h>
50#include <filename_resolver.h>
51#include <core/map_helpers.h>
54
55
56// Maps m_choiceFormat selection to extension (and kicad-cli command)
57static const std::vector<wxString> c_formatCommand = { FILEEXT::StepFileExtension,
63
64// Maps file extensions to m_choiceFormat selection
65static const std::map<wxString, int> c_formatExtToChoice = { { FILEEXT::StepFileExtension, 0 },
72
73
74
75int DIALOG_EXPORT_STEP::m_toleranceLastChoice = -1; // Use default
76int DIALOG_EXPORT_STEP::m_formatLastChoice = -1; // Use default
91
92
93DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aEditFrame, const wxString& aBoardPath ) :
94 DIALOG_EXPORT_STEP( aEditFrame, aEditFrame, aBoardPath )
95{
96}
97
98
100 const wxString& aBoardPath,
101 JOB_EXPORT_PCB_3D* aJob ) :
102 DIALOG_EXPORT_STEP_BASE( aEditFrame ),
103 m_editFrame( aEditFrame ),
104 m_job( aJob ),
105 m_userOriginX( 0.0 ),
106 m_userOriginY( 0.0 ),
107 m_originUnits( 0 /* mm */ ),
108 m_boardPath( aBoardPath )
109{
110 if( !m_job )
111 {
112 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
113 SetupStandardButtons( { { wxID_OK, _( "Export" ) },
114 { wxID_CANCEL, _( "Close" ) } } );
115
116
117 // Build default output file name
118 // (last saved filename in project or built from board filename)
120
121 if( path.IsEmpty() )
122 {
123 wxFileName brdFile( m_editFrame->GetBoard()->GetFileName() );
124 brdFile.SetExt( wxT( "step" ) );
125 path = brdFile.GetFullPath();
126 }
127
128 m_outputFileName->SetValue( path );
129 }
130 else
131 {
132 SetTitle( m_job->GetSettingsDialogTitle() );
133
134 m_browseButton->Hide();
136 }
137
138 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
139 // non-job versions (which have different sizes).
140 m_hash_key = TO_UTF8( GetTitle() );
141
142 Layout();
143 bSizerSTEPFile->Fit( this );
144
145 SetFocus();
146
147 if( !m_job )
148 {
150 {
151 m_origin = static_cast<STEP_ORIGIN_OPTION>( cfg->m_ExportStep.origin_mode );
152
153 switch( m_origin )
154 {
155 default:
156 case STEP_ORIGIN_PLOT_AXIS: m_rbDrillAndPlotOrigin->SetValue( true ); break;
157 case STEP_ORIGIN_GRID_AXIS: m_rbGridOrigin->SetValue( true ); break;
158 case STEP_ORIGIN_USER: m_rbUserDefinedOrigin->SetValue( true ); break;
159 case STEP_ORIGIN_BOARD_CENTER: m_rbBoardCenterOrigin->SetValue( true ); break;
160 }
161
162 m_originUnits = cfg->m_ExportStep.origin_units;
163 m_userOriginX = cfg->m_ExportStep.origin_x;
164 m_userOriginY = cfg->m_ExportStep.origin_y;
165 m_noUnspecified = cfg->m_ExportStep.no_unspecified;
166 m_noDNP = cfg->m_ExportStep.no_dnp;
167
168 m_txtNetFilter->SetValue( m_netFilter );
169 m_cbOptimizeStep->SetValue( m_optimizeStep );
172 m_cbExportTracks->SetValue( m_exportTracks );
173 m_cbExportPads->SetValue( m_exportPads );
174 m_cbExportZones->SetValue( m_exportZones );
178 m_cbFuseShapes->SetValue( m_fuseShapes );
180 m_cbFillAllVias->SetValue( m_fillAllVias );
182 m_cbRemoveDNP->SetValue( m_noDNP );
183 m_cbSubstModels->SetValue( cfg->m_ExportStep.replace_models );
184 m_cbOverwriteFile->SetValue( cfg->m_ExportStep.overwrite_file );
185 }
186
188
189 switch( m_componentMode )
190 {
191 case COMPONENT_MODE::EXPORT_ALL: m_rbAllComponents->SetValue( true ); break;
192 case COMPONENT_MODE::EXPORT_SELECTED: m_rbOnlySelected->SetValue( true ); break;
193 case COMPONENT_MODE::CUSTOM_FILTER: m_rbFilteredComponents->SetValue( true ); break;
194 }
195
196 // Sync the enabled states
197 wxCommandEvent dummy;
199
200 m_STEP_OrgUnitChoice->SetSelection( m_originUnits );
201 wxString tmpStr;
202 tmpStr << m_userOriginX;
203 m_STEP_Xorg->SetValue( tmpStr );
204 tmpStr = wxEmptyString;
205 tmpStr << m_userOriginY;
206 m_STEP_Yorg->SetValue( tmpStr );
207 }
208 else
209 {
210 m_rbBoardCenterOrigin->SetValue( true ); // Default
211
213 m_rbDrillAndPlotOrigin->SetValue( true );
215 m_rbGridOrigin->SetValue( true );
217 m_rbUserDefinedOrigin->SetValue( true );
219 m_rbBoardCenterOrigin->SetValue( true );
220
223
226
244
246 m_choiceTolerance->SetSelection( 2 );
248 m_choiceTolerance->SetSelection( 0 );
249 else
250 m_choiceTolerance->SetSelection( 1 );
251
254
255 wxCommandEvent dummy;
257
258 m_STEP_OrgUnitChoice->SetSelection( m_originUnits );
259
260 wxString tmpStr;
261 tmpStr << m_userOriginX;
262 m_STEP_Xorg->SetValue( tmpStr );
263 tmpStr = wxEmptyString;
264 tmpStr << m_userOriginY;
265 m_STEP_Yorg->SetValue( tmpStr );
266 }
267
268 wxString bad_scales;
269 size_t bad_count = 0;
270
271 for( FOOTPRINT* fp : m_editFrame->GetBoard()->Footprints() )
272 {
273 for( const FP_3DMODEL& model : fp->Models() )
274 {
275 if( model.m_Scale.x != 1.0 || model.m_Scale.y != 1.0 || model.m_Scale.z != 1.0 )
276 {
277 bad_scales.Append( wxS("\n") );
278 bad_scales.Append( model.m_Filename );
279 bad_count++;
280 }
281 }
282
283 if( bad_count >= 5 )
284 break;
285 }
286
287 if( !bad_scales.empty()
288 && !Pgm().GetCommonSettings()->m_DoNotShowAgain.scaled_3d_models_warning )
289 {
290 wxString extendedMsg = _( "Non-unity scaled models:" ) + wxT( "\n" ) + bad_scales;
291
292 KIDIALOG msgDlg( m_editFrame, _( "Scaled models detected. "
293 "Model scaling is not reliable for mechanical export." ),
294 _( "Model Scale Warning" ), wxOK | wxICON_WARNING );
295 msgDlg.SetExtendedMessage( extendedMsg );
296 msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
297
298 msgDlg.ShowModal();
299
300 if( msgDlg.DoNotShowAgain() )
302 }
303
304 if( m_toleranceLastChoice >= 0 )
306
307 if( m_formatLastChoice >= 0 )
308 m_choiceFormat->SetSelection( m_formatLastChoice );
309 else
310 // ensure the selected fmt and the output file ext are synchronized the first time
311 // the dialog is opened
313
314 // Now all widgets have the size fixed, call FinishDialogSettings
316}
317
318
320{
321 GetOriginOption(); // Update m_origin member.
322
323 if( !m_job ) // dont save mru if its a job dialog
324 {
326 {
327 cfg->m_ExportStep.origin_mode = static_cast<int>( m_origin );
328 cfg->m_ExportStep.origin_units = m_STEP_OrgUnitChoice->GetSelection();
329 cfg->m_ExportStep.replace_models = m_cbSubstModels->GetValue();
330 cfg->m_ExportStep.overwrite_file = m_cbOverwriteFile->GetValue();
331
332 double val = 0.0;
333
334 m_STEP_Xorg->GetValue().ToDouble( &val );
335 cfg->m_ExportStep.origin_x = val;
336
337 m_STEP_Yorg->GetValue().ToDouble( &val );
338 cfg->m_ExportStep.origin_y = val;
339
340 cfg->m_ExportStep.no_unspecified = m_cbRemoveUnspecified->GetValue();
341 cfg->m_ExportStep.no_dnp = m_cbRemoveDNP->GetValue();
342 }
343
344 m_netFilter = m_txtNetFilter->GetValue();
346 m_formatLastChoice = m_choiceFormat->GetSelection();
347 m_optimizeStep = m_cbOptimizeStep->GetValue();
348 m_exportBoardBody = m_cbExportBody->GetValue();
350 m_exportTracks = m_cbExportTracks->GetValue();
351 m_exportPads = m_cbExportPads->GetValue();
352 m_exportZones = m_cbExportZones->GetValue();
356 m_fuseShapes = m_cbFuseShapes->GetValue();
358 m_fillAllVias = m_cbFillAllVias->GetValue();
360
361 if( m_rbAllComponents->GetValue() )
363 else if( m_rbOnlySelected->GetValue() )
365 else
367 }
368}
369
370
372{
374
375 if( m_rbDrillAndPlotOrigin->GetValue() )
377 else if( m_rbGridOrigin->GetValue() )
379 else if( m_rbUserDefinedOrigin->GetValue() )
381 else if( m_rbBoardCenterOrigin->GetValue() )
383
384 return m_origin;
385}
386
387
389{
391 wxFileName brdFile = board->GetFileName();
392
393 // The project filename (.kicad_pro) of the auto saved board filename, if it is created
394 wxFileName autosaveProjFile;
395
396 if( m_frame->GetScreen()->IsContentModified() || brdFile.GetFullPath().empty() )
397 {
398 if( !m_frame->DoAutoSave() )
399 {
400 DisplayErrorMessage( m_frame, _( "STEP export failed! Please save the PCB and try again" ) );
401 return 0;
402 }
403
404 wxString autosaveFileName = FILEEXT::AutoSaveFilePrefix + brdFile.GetName();
405
406 // Create a dummy .kicad_pro file for this auto saved board file.
407 // this is useful to use some settings (like project path and name)
408 // Because DoAutoSave() works, the target directory exists and is writable
409 autosaveProjFile = brdFile;
410 autosaveProjFile.SetName( autosaveFileName );
411 autosaveProjFile.SetExt( "kicad_pro" );
412
413 // Use auto-saved board for export
414 m_frame->GetSettingsManager()->SaveProjectCopy( autosaveProjFile.GetFullPath(), board->GetProject() );
415 brdFile.SetName( autosaveFileName );
416 }
417
418 DIALOG_EXPORT_STEP dlg( m_frame, brdFile.GetFullPath() );
419 dlg.ShowModal();
420
421 // If a dummy .kicad_pro file is created, delete it now it is useless.
422 if( !autosaveProjFile.GetFullPath().IsEmpty() )
423 wxRemoveFile( autosaveProjFile.GetFullPath() );
424
425 return 0;
426}
427
428
429void DIALOG_EXPORT_STEP::onUpdateUnits( wxUpdateUIEvent& aEvent )
430{
431 aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
432}
433
434
435void DIALOG_EXPORT_STEP::onUpdateXPos( wxUpdateUIEvent& aEvent )
436{
437 aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
438}
439
440
441void DIALOG_EXPORT_STEP::onUpdateYPos( wxUpdateUIEvent& aEvent )
442{
443 aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
444}
445
446
447void DIALOG_EXPORT_STEP::onBrowseClicked( wxCommandEvent& aEvent )
448{
449 // clang-format off
450 wxString filter = _( "STEP files" )
452 + _( "Binary glTF files" )
454 + _( "XAO files" )
456 + _( "BREP (OCCT) files" )
458 + _( "PLY files" )
460 + _( "STL files" )
462 // clang-format on
463
464 // Build the absolute path of current output directory to preselect it in the file browser.
465 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
466 wxFileName fn( Prj().AbsolutePath( path ) );
467
468 wxFileDialog dlg( this, _( "3D Model Output File" ), fn.GetPath(), fn.GetFullName(), filter,
469 wxFD_SAVE );
470
471 if( dlg.ShowModal() == wxID_CANCEL )
472 return;
473
474 path = dlg.GetPath();
475 m_outputFileName->SetValue( path );
476
477 fn = wxFileName( path );
478
479 if( auto formatChoice = get_opt( c_formatExtToChoice, fn.GetExt().Lower() ) )
480 m_choiceFormat->SetSelection( *formatChoice );
481}
482
483
484void DIALOG_EXPORT_STEP::onFormatChoice( wxCommandEvent& event )
485{
487}
488
489
491{
492 wxString newExt = c_formatCommand[m_choiceFormat->GetSelection()];
493 wxString path = m_outputFileName->GetValue();
494
495 int sepIdx = std::max( path.Find( '/', true ), path.Find( '\\', true ) );
496 int dotIdx = path.Find( '.', true );
497
498 if( dotIdx == -1 || dotIdx < sepIdx )
499 path << '.' << newExt;
500 else
501 path = path.Mid( 0, dotIdx ) << '.' << newExt;
502
503 m_outputFileName->SetValue( path );
505}
506
507
508void DIALOG_EXPORT_STEP::onCbExportComponents( wxCommandEvent& event )
509{
510 bool enable = m_cbExportComponents->GetValue();
511
512 m_rbAllComponents->Enable( enable );
513 m_rbOnlySelected->Enable( enable );
514 m_rbFilteredComponents->Enable( enable );
515 m_txtComponentFilter->Enable( enable && m_rbFilteredComponents->GetValue() );
516}
517
518
519void DIALOG_EXPORT_STEP::OnComponentModeChange( wxCommandEvent& event )
520{
521 m_txtComponentFilter->Enable( m_rbFilteredComponents->GetValue() );
522}
523
524
525void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
526{
527 wxString path = m_outputFileName->GetValue();
528 double tolerance; // default value in mm
529
530 switch( m_choiceTolerance->GetSelection() )
531 {
532 case 0: tolerance = 0.001; break;
533 default:
534 case 1: tolerance = 0.01; break;
535 case 2: tolerance = 0.1; break;
536 }
537
538 if( !m_job )
539 {
541
542 // Build the absolute path of current output directory to preselect it in the file browser.
543 std::function<bool( wxString* )> textResolver =
544 [&]( wxString* token ) -> bool
545 {
546 return m_editFrame->GetBoard()->ResolveTextVar( token, 0 );
547 };
548
549 path = ExpandTextVars( path, &textResolver );
551 path = Prj().AbsolutePath( path );
552
553 if( path.IsEmpty() )
554 {
555 DisplayErrorMessage( this, _( "No filename for output file" ) );
556 return;
557 }
558
559 m_netFilter = m_txtNetFilter->GetValue();
561
562 if( m_rbAllComponents->GetValue() )
564 else if( m_rbOnlySelected->GetValue() )
566 else
568
570 m_formatLastChoice = m_choiceFormat->GetSelection();
571 m_optimizeStep = m_cbOptimizeStep->GetValue();
572 m_exportBoardBody = m_cbExportBody->GetValue();
574 m_exportTracks = m_cbExportTracks->GetValue();
575 m_exportPads = m_cbExportPads->GetValue();
576 m_exportZones = m_cbExportZones->GetValue();
580 m_fuseShapes = m_cbFuseShapes->GetValue();
582 m_fillAllVias = m_cbFillAllVias->GetValue();
583
584 SHAPE_POLY_SET outline;
585 wxString msg;
586
587 // Check if the board outline is continuous
588 // max dist from one endPt to next startPt to build a closed shape:
589 int chainingEpsilon = pcbIUScale.mmToIU( tolerance );
590
591 // Arc to segment approximation error (not critical here: we do not use the outline shape):
592 int maxError = pcbIUScale.mmToIU( 0.05 );
593
594 if( !BuildBoardPolygonOutlines( m_editFrame->GetBoard(), outline, maxError, chainingEpsilon ) )
595 {
596 DisplayErrorMessage( this, wxString::Format( _( "Board outline is missing or not closed using "
597 "%.3f mm tolerance.\n"
598 "Run DRC for a full analysis." ),
599 tolerance ) );
600 return;
601 }
602
603 wxFileName fn( Prj().AbsolutePath( path ) );
604
605 if( fn.FileExists() && !GetOverwriteFile() )
606 {
607 msg.Printf( _( "File '%s' already exists. Do you want overwrite this file?" ),
608 fn.GetFullPath() );
609
610 if( wxMessageBox( msg, _( "STEP/GLTF Export" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
611 return;
612 }
613
614 wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
615 #ifdef __WXMAC__
616 // On macOS, we have standalone applications inside the main bundle, so we handle that here:
617 if( appK2S.GetPath().Find( "/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
618 {
619 appK2S.AppendDir( wxT( ".." ) );
620 appK2S.AppendDir( wxT( ".." ) );
621 appK2S.AppendDir( wxT( ".." ) );
622 appK2S.AppendDir( wxT( ".." ) );
623 appK2S.AppendDir( wxT( "MacOS" ) );
624 }
625 #else
626 if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
627 {
628 appK2S.RemoveLastDir();
629 appK2S.AppendDir( "kicad" );
630 }
631 #endif
632
633 appK2S.SetName( wxT( "kicad-cli" ) );
634 appK2S.Normalize( FN_NORMALIZE_FLAGS );
635
636 wxString cmdK2S = wxT( "\"" );
637 cmdK2S.Append( appK2S.GetFullPath() );
638 cmdK2S.Append( wxT( "\"" ) );
639
640 cmdK2S.Append( wxT( " pcb" ) );
641 cmdK2S.Append( wxT( " export" ) );
642
643 cmdK2S.Append( wxT( " " ) );
644 cmdK2S.Append( c_formatCommand[m_choiceFormat->GetSelection()] );
645
647 cmdK2S.Append( wxT( " --no-unspecified" ) );
648
649 if( GetNoDNPOption() )
650 cmdK2S.Append( wxT( " --no-dnp" ) );
651
652 if( GetSubstOption() )
653 cmdK2S.Append( wxT( " --subst-models" ) );
654
655 if( !m_optimizeStep )
656 cmdK2S.Append( wxT( " --no-optimize-step" ) );
657
658 if( !m_exportBoardBody )
659 cmdK2S.Append( wxT( " --no-board-body" ) );
660
661 if( !m_exportComponents )
662 cmdK2S.Append( wxT( " --no-components" ) );
663
664 if( m_exportTracks )
665 cmdK2S.Append( wxT( " --include-tracks" ) );
666
667 if( m_exportPads )
668 cmdK2S.Append( wxT( " --include-pads" ) );
669
670 if( m_exportZones )
671 cmdK2S.Append( wxT( " --include-zones" ) );
672
674 cmdK2S.Append( wxT( " --include-inner-copper" ) );
675
677 cmdK2S.Append( wxT( " --include-silkscreen" ) );
678
680 cmdK2S.Append( wxT( " --include-soldermask" ) );
681
682 if( m_fuseShapes )
683 cmdK2S.Append( wxT( " --fuse-shapes" ) );
684
685 if( m_cutViasInBody )
686 cmdK2S.Append( wxT( " --cut-vias-in-body" ) );
687
688 if( m_fillAllVias )
689 cmdK2S.Append( wxT( " --fill-all-vias" ) );
690
691 // Note: for some reason, using \" to insert a quote in a format string, under MacOS
692 // wxString::Format does not work. So use a %c format in string
693 int quote = '\'';
694 int dblquote = '"';
695
696 if( !m_netFilter.empty() )
697 {
698 cmdK2S.Append( wxString::Format( wxT( " --net-filter %c%s%c" ),
699 dblquote, m_netFilter, dblquote ) );
700 }
701
702 switch( m_componentMode )
703 {
705 {
706 wxArrayString components;
708
709 std::for_each( selection.begin(), selection.end(),
710 [&components]( EDA_ITEM* item )
711 {
712 if( item->Type() == PCB_FOOTPRINT_T )
713 components.push_back( static_cast<FOOTPRINT*>( item )->GetReference() );
714 } );
715
716 cmdK2S.Append( wxString::Format( wxT( " --component-filter %c%s%c" ),
717 dblquote, wxJoin( components, ',' ), dblquote ) );
718 break;
719 }
720
722 cmdK2S.Append( wxString::Format( wxT( " --component-filter %c%s%c" ),
723 dblquote, m_componentFilter, dblquote ) );
724 break;
725
726 default:
727 break;
728 }
729
730 switch( GetOriginOption() )
731 {
732 case STEP_ORIGIN_0:
733 wxFAIL_MSG( wxT( "Unsupported origin option: how did we get here?" ) );
734 break;
735
737 cmdK2S.Append( wxT( " --drill-origin" ) );
738 break;
739
741 cmdK2S.Append( wxT( " --grid-origin" ) );
742 break;
743
744 case STEP_ORIGIN_USER:
745 {
746 double xOrg = GetXOrg();
747 double yOrg = GetYOrg();
748
749 if( GetOrgUnitsChoice() == 1 )
750 {
751 // selected reference unit is in inches, and STEP units are mm
752 xOrg *= 25.4;
753 yOrg *= 25.4;
754 }
755
757 cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
758 quote, xOrg, yOrg, quote ) );
759 break;
760 }
761
763 {
764 BOX2I bbox = m_editFrame->GetBoard()->ComputeBoundingBox( true );
765 double xOrg = pcbIUScale.IUTomm( bbox.GetCenter().x );
766 double yOrg = pcbIUScale.IUTomm( bbox.GetCenter().y );
768
769 cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
770 quote, xOrg, yOrg, quote ) );
771 break;
772 }
773 }
774
775 {
777 cmdK2S.Append( wxString::Format( wxT( " --min-distance=%c%.3fmm%c" ),
778 quote, tolerance, quote ) );
779 }
780
781 // Output file path.
782 cmdK2S.Append( wxString::Format( wxT( " -f -o %c%s%c" ),
783 dblquote, fn.GetFullPath(), dblquote ) );
784
785
786 // Input file path.
787 cmdK2S.Append( wxString::Format( wxT( " %c%s%c" ), dblquote, m_boardPath, dblquote ) );
788
789 wxLogTrace( traceKiCad2Step, wxT( "export step command: %s" ), cmdK2S );
790
791 DIALOG_EXPORT_STEP_LOG* log = new DIALOG_EXPORT_STEP_LOG( this, cmdK2S );
792 log->ShowModal();
793 }
794 else
795 {
816
817 m_job->SetStepFormat( static_cast<EXPORTER_STEP_PARAMS::FORMAT>( m_choiceFormat->GetSelection() ) );
818
819 // ensure the main format on the job is populated
820 switch( m_job->m_3dparams.m_Format )
821 {
828 }
829
834
835 switch( GetOriginOption() )
836 {
837 case STEP_ORIGIN_0:
838 break;
841 break;
844 break;
845 case STEP_ORIGIN_USER:
846 {
847 double xOrg = GetXOrg();
848 double yOrg = GetYOrg();
849
850 if( GetOrgUnitsChoice() == 1 )
851 {
852 // selected reference unit is in inches, and STEP units are mm
853 xOrg *= 25.4;
854 yOrg *= 25.4;
855 }
856
858 m_job->m_3dparams.m_Origin = VECTOR2D( xOrg, yOrg );
859 break;
860 }
861
863 {
864 BOX2I bbox = m_editFrame->GetBoard()->ComputeBoundingBox( true );
865 double xOrg = pcbIUScale.IUTomm( bbox.GetCenter().x );
866 double yOrg = pcbIUScale.IUTomm( bbox.GetCenter().y );
868
870 m_job->m_3dparams.m_Origin = VECTOR2D( xOrg, yOrg );
871 break;
872 }
873 }
874
875 EndModal( wxID_OK );
876 }
877}
878
879
881{
883}
884
885
887{
889}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition: bitmap.cpp:110
bool IsContentModified() const
Definition: base_screen.h:60
int ExportSTEP(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
bool ResolveTextVar(wxString *token, int aDepth) const
Definition: board.cpp:434
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1766
const FOOTPRINTS & Footprints() const
Definition: board.h:358
const wxString & GetFileName() const
Definition: board.h:354
PROJECT * GetProject() const
Definition: board.h:536
constexpr const Vec GetCenter() const
Definition: box2.h:230
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
Class DIALOG_EXPORT_STEP_BASE.
wxRadioButton * m_rbFilteredComponents
wxRadioButton * m_rbDrillAndPlotOrigin
STD_BITMAP_BUTTON * m_browseButton
void onFormatChoice(wxCommandEvent &event) override
STEP_ORIGIN_OPTION GetOriginOption()
static bool m_exportSoldermask
int GetOrgUnitsChoice() const
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)
static COMPONENT_MODE m_componentMode
void onUpdateXPos(wxUpdateUIEvent &aEvent) override
static bool m_exportComponents
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
void onUpdateUnits(wxUpdateUIEvent &aEvent) override
static bool m_exportInnerCopper
void onUpdateYPos(wxUpdateUIEvent &aEvent) override
void onBrowseClicked(wxCommandEvent &aEvent) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
Definition: dialog_shim.h:194
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
SETTINGS_MANAGER * GetSettingsManager() const
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:97
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.
Definition: job.cpp:153
wxString GetConfiguredOutputPath() const
Returns the configured output path for the job.
Definition: job.h:227
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: kidialog.h:50
bool DoNotShowAgain() const
Checks the 'do not show again' setting for the dialog.
Definition: kidialog.cpp:59
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition: kidialog.cpp:51
int ShowModal() override
Definition: kidialog.cpp:95
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.
Definition: locale_io.h:41
PCBNEW_SETTINGS * GetPcbNewSettings() const
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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.
bool DoAutoSave()
Perform auto save when the board has been modified and not saved within the auto save interval.
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
SELECTION & GetCurrentSelection() override
Get the current selection from the canvas area.
BOARD * board() const
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:556
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.
Definition: project.cpp:372
ITER end()
Definition: selection.h:75
ITER begin()
Definition: selection.h:74
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 SetBitmap(const wxBitmapBundle &aBmp)
void SetValue(const wxString &aValue) override
Set a new value in evaluator buffer and display it in the wxTextCtrl.
Generic, UI-independent tool event.
Definition: tool_event.h:168
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:353
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, int aFlags)
Definition: common.cpp:59
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:203
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
#define _(s)
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)
Definition: map_helpers.h:34
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.
Definition: eda_units.cpp:559
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:893
see class PGM_BASE
@ LAST_PATH_STEP
Definition: project_file.h:53
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:429
constexpr double IUTomm(int iu) const
Definition: base_units.h:90
constexpr int mmToIU(double mm) const
Definition: base_units.h:92
wxLogTrace helper definitions.
VECTOR2< double > VECTOR2D
Definition: vector2d.h:694
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().
Definition: wx_filename.h:39