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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include "dialog_export_step.h"
23
24#include <wx/log.h>
25#include <wx/stdpaths.h>
26#include <wx/process.h>
27#include <wx/string.h>
28#include <wx/filedlg.h>
29#include <kiplatform/ui.h>
30
31#include <pgm_base.h>
33#include <board.h>
34#include <confirm.h>
35#include <kidialog.h>
37#include <footprint.h>
38#include <kiface_base.h>
39#include <locale_io.h>
40#include <math/vector3.h>
41#include <pcb_edit_frame.h>
42#include <pcb_io/pcb_io_mgr.h>
44#include <project/project_file.h> // LAST_PATH_TYPE
45#include <reporter.h>
46#include <string_utils.h>
47#include <trace_helpers.h>
50#include <filename_resolver.h>
51#include <core/map_helpers.h>
54
55#include <wx/filefn.h>
56
57
58// Maps m_choiceFormat selection to extension (and kicad-cli command)
69
70// Maps m_choiceFormat selection to the step exporter format
82
83// Maps file extensions to m_choiceFormat selection
94
95
96DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aEditFrame, const wxString& aBoardPath ) :
97 DIALOG_EXPORT_STEP( aEditFrame, aEditFrame, aBoardPath )
98{
99}
100
101
103 const wxString& aBoardPath, JOB_EXPORT_PCB_3D* aJob ) :
104 DIALOG_EXPORT_STEP_BASE( aEditFrame ),
105 m_editFrame( aEditFrame ),
106 m_job( aJob ),
109 m_boardPath( aBoardPath )
110{
111 if( !m_job )
112 {
114 SetupStandardButtons( { { wxID_OK, _( "Export" ) },
115 { wxID_CANCEL, _( "Close" ) } } );
116
118 }
119 else
120 {
121 SetTitle( m_job->GetSettingsDialogTitle() );
122
123 m_browseButton->Hide();
125
126 // Every control here belongs to the job, so the global control-state cache must not
127 // supply values for one job that were left behind by another
128 OptOut( this );
129 }
130
131 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
132 // non-job versions.
133 m_hash_key = TO_UTF8( GetTitle() );
134
135 m_choiceVariant->Append( m_editFrame->GetBoard()->GetVariantNamesForUI() );
136 m_choiceVariant->SetSelection( 0 );
137
138 Layout();
139 bSizerSTEPFile->Fit( this );
140
141 SetFocus();
142
143 wxString bad_scales;
144 size_t bad_count = 0;
145
146 for( FOOTPRINT* fp : m_editFrame->GetBoard()->Footprints() )
147 {
148 for( const FP_3DMODEL& model : fp->Models() )
149 {
150 if( model.m_Scale.x != 1.0 || model.m_Scale.y != 1.0 || model.m_Scale.z != 1.0 )
151 {
152 bad_scales.Append( wxS("\n") );
153 bad_scales.Append( model.m_Filename );
154 bad_count++;
155 }
156 }
157
158 if( bad_count >= 5 )
159 break;
160 }
161
162 if( !bad_scales.empty() && !Pgm().GetCommonSettings()->m_DoNotShowAgain.scaled_3d_models_warning )
163 {
164 wxString extendedMsg = _( "Non-unity scaled models:" ) + wxT( "\n" ) + bad_scales;
165
166 KIDIALOG msgDlg( m_editFrame, _( "Scaled models detected. Model scaling is not reliable for "
167 "mechanical export." ),
168 _( "Model Scale Warning" ), wxOK | wxICON_WARNING );
169 msgDlg.SetExtendedMessage( extendedMsg );
170 msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
171
172 msgDlg.ShowModal();
173
174 if( msgDlg.DoNotShowAgain() )
176 }
177
179
180 // Now all widgets have the size fixed, call FinishDialogSettings
182}
183
184
186{
187 if( !m_job )
188 {
189 wxString lastPath = m_editFrame->GetLastPath( LAST_PATH_STEP );
190
191 if( lastPath.IsEmpty() )
192 {
193 wxFileName brdFile( m_editFrame->GetBoard()->GetFileName() );
194 brdFile.SetExt( wxT( "step" ) );
195 lastPath = brdFile.GetFullPath();
196 }
197
198 m_outputFileName->SetValue( lastPath );
199
200 wxString currentVariant = m_editFrame->GetBoard()->GetCurrentVariant();
201
202 if( !currentVariant.IsEmpty() )
203 {
204 int idx = m_choiceVariant->FindString( currentVariant );
205
206 if( idx != wxNOT_FOUND )
207 m_choiceVariant->SetSelection( idx );
208 }
209
210 wxFileName fn = m_outputFileName->GetValue();
211
212 if( auto formatChoice = get_opt( c_formatExtToChoice, fn.GetExt().Lower() ) )
213 m_choiceFormat->SetSelection( *formatChoice );
214 }
215 else
216 {
217 m_rbBoardCenterOrigin->SetValue( true ); // Default
218
219 if( m_job->m_3dparams.m_UseDrillOrigin )
220 m_rbDrillAndPlotOrigin->SetValue( true );
221 else if( m_job->m_3dparams.m_UseGridOrigin )
222 m_rbGridOrigin->SetValue( true );
223 else if( m_job->m_3dparams.m_UseDefinedOrigin )
224 m_rbUserDefinedOrigin->SetValue( true );
225 else if( m_job->m_3dparams.m_UsePcbCenterOrigin )
226 m_rbBoardCenterOrigin->SetValue( true );
227
228 m_originX.SetValue( KiROUND( m_job->m_3dparams.m_Origin.x ) );
229 m_originY.SetValue( KiROUND( m_job->m_3dparams.m_Origin.y ) );
230
231 m_txtNetFilter->SetValue( m_job->m_3dparams.m_NetFilter );
232 m_cbOptimizeStep->SetValue( m_job->m_3dparams.m_OptimizeStep );
233 m_cbExportBody->SetValue( m_job->m_3dparams.m_ExportBoardBody );
234 m_cbExportComponents->SetValue( m_job->m_3dparams.m_ExportComponents );
235 m_cbExportTracks->SetValue( m_job->m_3dparams.m_ExportTracksVias );
236 m_cbExportPads->SetValue( m_job->m_3dparams.m_ExportPads );
237 m_cbExportZones->SetValue( m_job->m_3dparams.m_ExportZones );
238 m_cbExportInnerCopper->SetValue( m_job->m_3dparams.m_ExportInnerCopper );
239 m_cbExportSilkscreen->SetValue( m_job->m_3dparams.m_ExportSilkscreen );
240 m_cbExportSoldermask->SetValue( m_job->m_3dparams.m_ExportSoldermask );
241 m_cbFuseShapes->SetValue( m_job->m_3dparams.m_FuseShapes );
242 m_cbCutViasInBody->SetValue( m_job->m_3dparams.m_CutViasInBody );
243 m_cbFillAllVias->SetValue( m_job->m_3dparams.m_FillAllVias );
244 m_cbRemoveUnspecified->SetValue( !m_job->m_3dparams.m_IncludeUnspecified );
245 m_cbRemoveDNP->SetValue( !m_job->m_3dparams.m_IncludeDNP );
246 m_cbSubstModels->SetValue( m_job->m_3dparams.m_SubstModels );
247 m_cbOverwriteFile->SetValue( m_job->m_3dparams.m_Overwrite );
248
249 if( m_job->m_3dparams.m_BoardOutlinesChainingEpsilon > 0.05 )
250 m_choiceTolerance->SetSelection( 2 );
251 else if( m_job->m_3dparams.m_BoardOutlinesChainingEpsilon < 0.005 )
252 m_choiceTolerance->SetSelection( 0 );
253 else
254 m_choiceTolerance->SetSelection( 1 );
255
256 // The job stores the resolved filter only, so an empty one means every component
257 if( m_job->m_3dparams.m_ComponentFilter.IsEmpty() )
258 m_rbAllComponents->SetValue( true );
259 else
260 m_rbFilteredComponents->SetValue( true );
261
262 m_txtComponentFilter->SetValue( m_job->m_3dparams.m_ComponentFilter );
263 m_outputFileName->SetValue( m_job->GetConfiguredOutputPath() );
264
265 if( !m_job->m_variant.IsEmpty() )
266 {
267 int idx = m_choiceVariant->FindString( m_job->m_variant );
268
269 if( idx != wxNOT_FOUND )
270 m_choiceVariant->SetSelection( idx );
271 }
272
273 // Use the recorded format instead of the file extension for jobs
274 for( auto& formats : c_formatJobCommand )
275 {
276 if( formats.second == m_job->m_3dparams.m_Format )
277 {
278 m_choiceFormat->SetSelection( formats.first );
279 break;
280 }
281 }
282 }
283
284 // Sync the enabled states
285 wxCommandEvent dummy;
287
288 return true;
289}
290
291
293{
294 wxString variant;
295 int selection = m_choiceVariant->GetSelection();
296
297 if( ( selection != 0 ) && ( selection != wxNOT_FOUND ) )
298 variant = m_choiceVariant->GetString( selection );
299
300 return variant;
301}
302
303
305{
306 if( m_rbOnlySelected->GetValue() )
307 {
308 wxArrayString components;
309 SELECTION& selection = m_editFrame->GetCurrentSelection();
310
311 for( EDA_ITEM* item : selection )
312 {
313 if( item->Type() == PCB_FOOTPRINT_T )
314 components.push_back( static_cast<FOOTPRINT*>( item )->GetReference() );
315 }
316
317 return wxJoin( components, ',' );
318 }
319
320 if( m_rbFilteredComponents->GetValue() )
321 return m_txtComponentFilter->GetValue();
322
323 return wxEmptyString;
324}
325
326
328{
329 BOARD* board = m_frame->GetBoard();
330 wxFileName brdFile = board->GetFileName();
331
332 DIALOG_EXPORT_STEP dlg( m_frame, brdFile.GetFullPath() );
333 dlg.ShowModal();
334
335 return 0;
336}
337
338
339void DIALOG_EXPORT_STEP::onUpdateXPos( wxUpdateUIEvent& aEvent )
340{
341 aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
342}
343
344
345void DIALOG_EXPORT_STEP::onUpdateYPos( wxUpdateUIEvent& aEvent )
346{
347 aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
348}
349
350
351void DIALOG_EXPORT_STEP::onBrowseClicked( wxCommandEvent& aEvent )
352{
353 // clang-format off
354 wxString filter = _( "STEP files" )
356 + _( "Binary glTF files" )
358 + _( "XAO files" )
360 + _( "BREP (OCCT) files" )
362 + _( "PLY files" )
364 + _( "STL files" )
366 + _( "Universal 3D files" )
368 + _( "PDF files" )
370 // clang-format on
371
372 // Build the absolute path of current output directory to preselect it in the file browser.
373 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
374 wxFileName fn( Prj().AbsolutePath( path ) );
375
376 wxFileDialog dlg( this, _( "3D Model Output File" ), fn.GetPath(), fn.GetFullName(), filter, wxFD_SAVE );
377
379
380 if( dlg.ShowModal() == wxID_CANCEL )
381 return;
382
383 path = dlg.GetPath();
384 m_outputFileName->SetValue( path );
385
386 fn = wxFileName( path );
387
388 if( auto formatChoice = get_opt( c_formatExtToChoice, fn.GetExt().Lower() ) )
389 m_choiceFormat->SetSelection( *formatChoice );
390}
391
392
393void DIALOG_EXPORT_STEP::onFormatChoice( wxCommandEvent& event )
394{
396}
397
398
400{
401 wxString newExt;
402 int idx = m_choiceFormat->GetSelection();
403
404 for( auto& choices : c_formatExtToChoice )
405 {
406 if( choices.second == idx )
407 {
408 newExt = choices.first;
409 break;
410 }
411 }
412
413 wxString path = m_outputFileName->GetValue();
414
415 int sepIdx = std::max( path.Find( '/', true ), path.Find( '\\', true ) );
416 int dotIdx = path.Find( '.', true );
417
418 if( dotIdx == -1 || dotIdx < sepIdx )
419 path << '.' << newExt;
420 else
421 path = path.Mid( 0, dotIdx ) << '.' << newExt;
422
423 m_outputFileName->SetValue( path );
424}
425
426
427void DIALOG_EXPORT_STEP::onCbExportComponents( wxCommandEvent& event )
428{
429 bool enable = m_cbExportComponents->GetValue();
430
431 m_rbAllComponents->Enable( enable );
432 m_rbOnlySelected->Enable( enable );
433 m_rbFilteredComponents->Enable( enable );
434 m_txtComponentFilter->Enable( enable && m_rbFilteredComponents->GetValue() );
435}
436
437
438void DIALOG_EXPORT_STEP::OnComponentModeChange( wxCommandEvent& event )
439{
440 m_txtComponentFilter->Enable( m_rbFilteredComponents->GetValue() );
441}
442
443
444wxString DIALOG_EXPORT_STEP::StageBoardForExport( const wxString& aBoardPath, bool aContentModified, BOARD* aBoard,
445 wxString& aInputPath, std::vector<wxString>& aTempFiles,
446 wxString& aErrorDetail )
447{
448 aErrorDetail = wxEmptyString;
449
450 if( aBoardPath.IsEmpty() )
451 return _( "Please save the board before exporting STEP." );
452
453 // A clean board exports its on-disk file directly, as long as it still exists.
454 if( !aContentModified )
455 {
456 if( !wxFileExists( aBoardPath ) )
457 {
458 return _( "Board file not found on disk.\n"
459 "Save the board before exporting STEP." );
460 }
461
462 aInputPath = aBoardPath;
463 return wxEmptyString;
464 }
465
466 wxFileName boardFn( aBoardPath );
467
468 if( !boardFn.DirExists() )
469 {
470 return _( "The board directory no longer exists.\n"
471 "Save the board to a valid location before exporting STEP." );
472 }
473
474 // Reserve a unique stem in the board directory so concurrent exports and stale leftovers from a
475 // crashed run cannot clobber each other.
476 wxString stemPrefix = boardFn.GetName() + wxS( "-unsaved-export-" );
477 wxString reserved = wxFileName::CreateTempFileName( boardFn.GetPathWithSep() + stemPrefix );
478
479 if( reserved.IsEmpty() )
480 return _( "Failed to reserve a temporary filename for STEP export." );
481
482 wxFileName stemFn( reserved );
483 wxFileName tempBoardFn( boardFn.GetPath(), stemFn.GetName(), FILEEXT::KiCadPcbFileExtension );
484 wxFileName tempProjectFn( boardFn.GetPath(), stemFn.GetName(), FILEEXT::ProjectFileExtension );
485
486 // Schedule the placeholder for cleanup. If this initial delete fails the later sweep will
487 // retry; we keep it registered in aTempFiles regardless so it never leaks.
488 aTempFiles.push_back( reserved );
489 wxRemoveFile( reserved );
490
491 try
492 {
494 pi->SaveBoard( tempBoardFn.GetFullPath(), *aBoard, nullptr );
495 }
496 catch( const IO_ERROR& ioe )
497 {
498 aErrorDetail = ioe.What();
499 return _( "Failed to save the current board state for export." );
500 }
501
502 aTempFiles.push_back( tempBoardFn.GetFullPath() );
503
504 wxFileName srcProjectFn = boardFn;
505 srcProjectFn.SetExt( FILEEXT::ProjectFileExtension );
506
507 if( srcProjectFn.FileExists() )
508 {
509 if( !wxCopyFile( srcProjectFn.GetFullPath(), tempProjectFn.GetFullPath(), true ) )
510 {
511 wxRemoveFile( tempBoardFn.GetFullPath() );
512 return _( "Failed to stage the project file for STEP export." );
513 }
514
515 aTempFiles.push_back( tempProjectFn.GetFullPath() );
516 }
517
518 aInputPath = tempBoardFn.GetFullPath();
519 return wxEmptyString;
520}
521
522
523void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
524{
525 wxString path = m_outputFileName->GetValue();
526 double tolerance; // default value in mm
527
528 switch( m_choiceTolerance->GetSelection() )
529 {
530 case 0: tolerance = 0.001; break;
531 default:
532 case 1: tolerance = 0.01; break;
533 case 2: tolerance = 0.1; break;
534 }
535
536 if( !m_job )
537 {
538 // Build the absolute path of current output directory to preselect it in the file browser.
539 std::function<bool( wxString* )> textResolver =
540 [&]( wxString* token ) -> bool
541 {
542 return m_editFrame->GetBoard()->ResolveTextVar( token, 0 );
543 };
544
545 path = ExpandTextVars( path, &textResolver, INTERNAL );
547 path = Prj().AbsolutePath( path );
548
549 if( path.IsEmpty() )
550 {
551 DisplayErrorMessage( this, _( "No filename for output file" ) );
552 return;
553 }
554
555 SHAPE_POLY_SET outline;
556 wxString msg;
557
558 // Check if the board outline is continuous
559 // max dist from one endPt to next startPt to build a closed shape:
560 int chainingEpsilon = pcbIUScale.mmToIU( tolerance );
561
562 // Arc to segment approximation error (not critical here: we do not use the outline shape):
563 int maxError = pcbIUScale.mmToIU( 0.05 );
564
565 if( !BuildBoardPolygonOutlines( m_editFrame->GetBoard(), outline, maxError, chainingEpsilon, false ) )
566 {
567 DisplayErrorMessage( this, wxString::Format( _( "Board outline is missing or not closed using "
568 "%.3f mm tolerance.\n"
569 "Run DRC for a full analysis." ),
570 tolerance ) );
571 return;
572 }
573
574 wxFileName fn( Prj().AbsolutePath( path ) );
575
576 if( fn.FileExists() && !m_cbOverwriteFile->GetValue() )
577 {
578 msg.Printf( _( "File '%s' already exists. Do you want overwrite this file?" ), fn.GetFullPath() );
579
580 if( wxMessageBox( msg, _( "STEP/GLTF Export" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
581 return;
582 }
583
584 m_editFrame->SetLastPath( LAST_PATH_STEP, fn.GetFullPath() );
585
586 wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
587 #ifdef __WXMAC__
588 // On macOS, we have standalone applications inside the main bundle, so we handle that here:
589 if( appK2S.GetPath().Find( "/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
590 {
591 appK2S.AppendDir( wxT( ".." ) );
592 appK2S.AppendDir( wxT( ".." ) );
593 appK2S.AppendDir( wxT( ".." ) );
594 appK2S.AppendDir( wxT( ".." ) );
595 appK2S.AppendDir( wxT( "MacOS" ) );
596 }
597 #else
598 if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
599 {
600 appK2S.RemoveLastDir();
601 appK2S.AppendDir( "kicad" );
602 }
603 #endif
604
605 appK2S.SetName( wxT( "kicad-cli" ) );
606 appK2S.Normalize( FN_NORMALIZE_FLAGS );
607
608 wxString cmdK2S = wxT( "\"" );
609 cmdK2S.Append( appK2S.GetFullPath() );
610 cmdK2S.Append( wxT( "\"" ) );
611
612 cmdK2S.Append( wxT( " pcb" ) );
613 cmdK2S.Append( wxT( " export" ) );
614
615 cmdK2S.Append( wxT( " " ) );
616 cmdK2S.Append( c_formatCommand[m_choiceFormat->GetSelection()] );
617
618 if( m_cbRemoveUnspecified->GetValue() )
619 cmdK2S.Append( wxT( " --no-unspecified" ) );
620
621 if( m_cbRemoveDNP->GetValue() )
622 cmdK2S.Append( wxT( " --no-dnp" ) );
623
624 if( m_cbSubstModels->GetValue() )
625 cmdK2S.Append( wxT( " --subst-models" ) );
626
627 if( !m_cbOptimizeStep->GetValue() )
628 cmdK2S.Append( wxT( " --no-optimize-step" ) );
629
630 if( !m_cbExportBody->GetValue() )
631 cmdK2S.Append( wxT( " --no-board-body" ) );
632
633 if( !m_cbExportComponents->GetValue() )
634 cmdK2S.Append( wxT( " --no-components" ) );
635
636 if( m_cbExportTracks->GetValue() )
637 cmdK2S.Append( wxT( " --include-tracks" ) );
638
639 if( m_cbExportPads->GetValue() )
640 cmdK2S.Append( wxT( " --include-pads" ) );
641
642 if( m_cbExportZones->GetValue() )
643 cmdK2S.Append( wxT( " --include-zones" ) );
644
645 if( m_cbExportInnerCopper->GetValue() )
646 cmdK2S.Append( wxT( " --include-inner-copper" ) );
647
648 if( m_cbExportSilkscreen->GetValue() )
649 cmdK2S.Append( wxT( " --include-silkscreen" ) );
650
651 if( m_cbExportSoldermask->GetValue() )
652 cmdK2S.Append( wxT( " --include-soldermask" ) );
653
654 if( m_cbFuseShapes->GetValue() )
655 cmdK2S.Append( wxT( " --fuse-shapes" ) );
656
657 if( m_cbCutViasInBody->GetValue() )
658 cmdK2S.Append( wxT( " --cut-vias-in-body" ) );
659
660 if( m_cbFillAllVias->GetValue() )
661 cmdK2S.Append( wxT( " --fill-all-vias" ) );
662
663 // Note: for some reason, using \" to insert a quote in a format string, under MacOS
664 // wxString::Format does not work. So use a %c format in string
665 int quote = '\'';
666 int dblquote = '"';
667
668 wxString selectedVariant = getSelectedVariant();
669
670 if( !selectedVariant.IsEmpty() )
671 {
672 cmdK2S.Append( wxString::Format( wxT( " --variant %c%s%c" ),
673 dblquote, selectedVariant, dblquote ) );
674 }
675
676 if( !m_txtNetFilter->GetValue().empty() )
677 {
678 cmdK2S.Append( wxString::Format( wxT( " --net-filter %c%s%c" ),
679 dblquote, m_txtNetFilter->GetValue(), dblquote ) );
680 }
681
682 if( !m_rbAllComponents->GetValue() )
683 {
684 cmdK2S.Append( wxString::Format( wxT( " --component-filter %c%s%c" ),
685 dblquote, getComponentFilter(), dblquote ) );
686 }
687
688 if( m_rbDrillAndPlotOrigin->GetValue() )
689 {
690 cmdK2S.Append( wxT( " --drill-origin" ) );
691 }
692 else if( m_rbGridOrigin->GetValue() )
693 {
694 cmdK2S.Append( wxT( " --grid-origin" ) );
695 }
696 else if( m_rbUserDefinedOrigin->GetValue() )
697 {
698 double xOrg = pcbIUScale.IUTomm( m_originX.GetIntValue() );
699 double yOrg = pcbIUScale.IUTomm( m_originY.GetIntValue() );
700
702 cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
703 quote, xOrg, yOrg, quote ) );
704 }
705 else if( m_rbBoardCenterOrigin->GetValue() )
706 {
707 BOX2I bbox = m_editFrame->GetBoard()->ComputeBoundingBox( true, true );
708 double xOrg = pcbIUScale.IUTomm( bbox.GetCenter().x );
709 double yOrg = pcbIUScale.IUTomm( bbox.GetCenter().y );
711
712 cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
713 quote, xOrg, yOrg, quote ) );
714 }
715 else
716 {
717 wxFAIL_MSG( wxT( "Unsupported origin option: how did we get here?" ) );
718 }
719
720 {
722 cmdK2S.Append( wxString::Format( wxT( " --min-distance=%c%.3fmm%c" ),
723 quote, tolerance, quote ) );
724 }
725
726 // Output file path.
727 cmdK2S.Append( wxString::Format( wxT( " -f -o %c%s%c" ),
728 dblquote, fn.GetFullPath(), dblquote ) );
729
730 // kicad-cli runs in a separate process and reads the board from disk, so an unsaved board
731 // must be staged to a temp file first. Cleanup is delegated to the process-log dialog so
732 // we can wait for the child to actually exit.
733 wxString inputPath;
734 std::vector<wxString> tempFiles;
735 wxString errorDetail;
736 wxString error = StageBoardForExport( m_boardPath, m_editFrame->IsContentModified(), m_editFrame->GetBoard(),
737 inputPath, tempFiles, errorDetail );
738
739 if( !error.IsEmpty() )
740 {
741 DisplayErrorMessage( this, error, errorDetail );
742 return;
743 }
744
745 // Input file path.
746 cmdK2S.Append( wxString::Format( wxT( " %c%s%c" ), dblquote, inputPath, dblquote ) );
747
748 wxLogTrace( traceKiCad2Step, wxT( "export step command: %s" ), cmdK2S );
749
750 DIALOG_EXPORT_STEP_LOG* log = new DIALOG_EXPORT_STEP_LOG( this, cmdK2S );
751 log->SetTempFilesToCleanup( std::move( tempFiles ) );
752 log->ShowModal();
753 }
754 else
755 {
756 m_job->SetConfiguredOutputPath( path );
757 m_job->m_variant = getSelectedVariant();
758 m_job->m_3dparams.m_NetFilter = m_txtNetFilter->GetValue();
759 m_job->m_3dparams.m_ComponentFilter = getComponentFilter();
760 m_job->m_3dparams.m_ExportBoardBody = m_cbExportBody->GetValue();
761 m_job->m_3dparams.m_ExportComponents = m_cbExportComponents->GetValue();
762 m_job->m_3dparams.m_ExportTracksVias = m_cbExportTracks->GetValue();
763 m_job->m_3dparams.m_ExportPads = m_cbExportPads->GetValue();
764 m_job->m_3dparams.m_ExportZones = m_cbExportZones->GetValue();
765 m_job->m_3dparams.m_ExportInnerCopper = m_cbExportInnerCopper->GetValue();
766 m_job->m_3dparams.m_ExportSilkscreen = m_cbExportSilkscreen->GetValue();
767 m_job->m_3dparams.m_ExportSoldermask = m_cbExportSoldermask->GetValue();
768 m_job->m_3dparams.m_FuseShapes = m_cbFuseShapes->GetValue();
769 m_job->m_3dparams.m_CutViasInBody = m_cbCutViasInBody->GetValue();
770 m_job->m_3dparams.m_FillAllVias = m_cbFillAllVias->GetValue();
771 m_job->m_3dparams.m_OptimizeStep = m_cbOptimizeStep->GetValue();
772 m_job->m_3dparams.m_Overwrite = m_cbOverwriteFile->GetValue();
773 m_job->m_3dparams.m_IncludeUnspecified = !m_cbRemoveUnspecified->GetValue();
774 m_job->m_3dparams.m_IncludeDNP = !m_cbRemoveDNP->GetValue();
775 m_job->m_3dparams.m_SubstModels = m_cbSubstModels->GetValue();
776 m_job->m_3dparams.m_BoardOutlinesChainingEpsilon = tolerance;
777
778 if( auto formatChoice = get_opt( c_formatJobCommand, m_choiceFormat->GetSelection() ) )
779 {
780 m_job->SetStepFormat( *formatChoice );
781 }
782 else
783 {
784 wxASSERT_MSG(false, wxString::Format( "Unknown format value %d", m_choiceFormat->GetSelection() ) );
785 }
786
787
788 // ensure the main format on the job is populated
789 switch( m_job->m_3dparams.m_Format )
790 {
800 }
801
802 m_job->m_3dparams.m_UseDrillOrigin = false;
803 m_job->m_3dparams.m_UseGridOrigin = false;
804 m_job->m_3dparams.m_UseDefinedOrigin = false;
805 m_job->m_3dparams.m_UsePcbCenterOrigin = false;
806
807 // VRML export reads m_Origin only when this is set, and otherwise takes the live board
808 // center, which is what the board center mode wants
809 m_job->m_hasUserOrigin = m_rbUserDefinedOrigin->GetValue();
810
811 if( m_rbDrillAndPlotOrigin->GetValue() )
812 {
813 m_job->m_3dparams.m_UseDrillOrigin = true;
814 }
815 else if( m_rbGridOrigin->GetValue() )
816 {
817 m_job->m_3dparams.m_UseGridOrigin = true;
818 }
819 else if( m_rbUserDefinedOrigin->GetValue() )
820 {
821 m_job->m_3dparams.m_UseDefinedOrigin = true;
822 m_job->m_3dparams.m_Origin = VECTOR2D( m_originX.GetIntValue(), m_originY.GetIntValue() );
823 }
824 else if( m_rbBoardCenterOrigin->GetValue() )
825 {
826 BOX2I bbox = m_editFrame->GetBoard()->ComputeBoundingBox( true, true );
827
828 m_job->m_3dparams.m_UsePcbCenterOrigin = true;
829 m_job->m_3dparams.m_Origin = VECTOR2D( bbox.GetCenter() );
830 }
831
832 EndModal( wxID_OK );
833 }
834}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
int ExportSTEP(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
constexpr const Vec GetCenter() const
Definition box2.h:227
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
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)
STD_BITMAP_BUTTON * m_browseButton
void SetTempFilesToCleanup(std::vector< wxString > aPaths)
Register files that should be removed once the subprocess is known to have terminated (or been repare...
void onFormatChoice(wxCommandEvent &event) override
void onCbExportComponents(wxCommandEvent &event) override
wxString getComponentFilter() const
Return the component filter implied by the component mode radio buttons.
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
static wxString StageBoardForExport(const wxString &aBoardPath, bool aContentModified, BOARD *aBoard, wxString &aInputPath, std::vector< wxString > &aTempFiles, wxString &aErrorDetail)
Resolve the board file to hand to the external 3D/STEP exporter.
bool TransferDataToWindow() override
void onExportButton(wxCommandEvent &aEvent) override
void onUpdateYPos(wxUpdateUIEvent &aEvent) override
void onBrowseClicked(wxCommandEvent &aEvent) override
void OptOut(wxWindow *aWindow)
Opt out of control state saving.
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::string m_hash_key
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
int ShowModal() override
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
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()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:38
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:89
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:37
The main frame for Pcbnew.
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
BOARD * board() const
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:546
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:407
Represent a set of closed polygons.
Generic, UI-independent tool event.
Definition tool_event.h:167
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:776
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject, RESOLUTION_CONTEXT aContext)
Definition common.cpp:60
@ INTERNAL
Definition common.h:92
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
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
#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 ProjectFileExtension
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
static const std::string KiCadPcbFileExtension
const wxChar *const traceKiCad2Step
Flag to enable KiCad2Step debug tracing.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
Definition map_helpers.h:30
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:521
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
@ LAST_PATH_STEP
std::vector< FAB_LAYER_COLOR > dummy
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
std::string path
KIBIS_MODEL * model
wxLogTrace helper definitions.
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
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:35