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
127 // DIALOG_SHIM needs a unique hash_key because classname will be the same for both job and
128 // non-job versions.
129 m_hash_key = TO_UTF8( GetTitle() );
130
131 m_choiceVariant->Append( m_editFrame->GetBoard()->GetVariantNamesForUI() );
132 m_choiceVariant->SetSelection( 0 );
133
134 Layout();
135 bSizerSTEPFile->Fit( this );
136
137 SetFocus();
138
139 wxString bad_scales;
140 size_t bad_count = 0;
141
142 for( FOOTPRINT* fp : m_editFrame->GetBoard()->Footprints() )
143 {
144 for( const FP_3DMODEL& model : fp->Models() )
145 {
146 if( model.m_Scale.x != 1.0 || model.m_Scale.y != 1.0 || model.m_Scale.z != 1.0 )
147 {
148 bad_scales.Append( wxS("\n") );
149 bad_scales.Append( model.m_Filename );
150 bad_count++;
151 }
152 }
153
154 if( bad_count >= 5 )
155 break;
156 }
157
158 if( !bad_scales.empty() && !Pgm().GetCommonSettings()->m_DoNotShowAgain.scaled_3d_models_warning )
159 {
160 wxString extendedMsg = _( "Non-unity scaled models:" ) + wxT( "\n" ) + bad_scales;
161
162 KIDIALOG msgDlg( m_editFrame, _( "Scaled models detected. Model scaling is not reliable for "
163 "mechanical export." ),
164 _( "Model Scale Warning" ), wxOK | wxICON_WARNING );
165 msgDlg.SetExtendedMessage( extendedMsg );
166 msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
167
168 msgDlg.ShowModal();
169
170 if( msgDlg.DoNotShowAgain() )
172 }
173
175
176 // Now all widgets have the size fixed, call FinishDialogSettings
178}
179
180
182{
183 if( !m_job )
184 {
185 wxString lastPath = m_editFrame->GetLastPath( LAST_PATH_STEP );
186
187 if( lastPath.IsEmpty() )
188 {
189 wxFileName brdFile( m_editFrame->GetBoard()->GetFileName() );
190 brdFile.SetExt( wxT( "step" ) );
191 lastPath = brdFile.GetFullPath();
192 }
193
194 m_outputFileName->SetValue( lastPath );
195
196 wxString currentVariant = m_editFrame->GetBoard()->GetCurrentVariant();
197
198 if( !currentVariant.IsEmpty() )
199 {
200 int idx = m_choiceVariant->FindString( currentVariant );
201
202 if( idx != wxNOT_FOUND )
203 m_choiceVariant->SetSelection( idx );
204 }
205
206 wxFileName fn = m_outputFileName->GetValue();
207
208 if( auto formatChoice = get_opt( c_formatExtToChoice, fn.GetExt().Lower() ) )
209 m_choiceFormat->SetSelection( *formatChoice );
210 }
211 else
212 {
213 m_rbBoardCenterOrigin->SetValue( true ); // Default
214
215 if( m_job->m_3dparams.m_UseDrillOrigin )
216 m_rbDrillAndPlotOrigin->SetValue( true );
217 else if( m_job->m_3dparams.m_UseGridOrigin )
218 m_rbGridOrigin->SetValue( true );
219 else if( m_job->m_3dparams.m_UseDefinedOrigin )
220 m_rbUserDefinedOrigin->SetValue( true );
221 else if( m_job->m_3dparams.m_UsePcbCenterOrigin )
222 m_rbBoardCenterOrigin->SetValue( true );
223
224 m_originX.SetValue( pcbIUScale.mmToIU( m_job->m_3dparams.m_Origin.x ) );
225 m_originY.SetValue( pcbIUScale.mmToIU( m_job->m_3dparams.m_Origin.y ) );
226
227 m_txtNetFilter->SetValue( m_job->m_3dparams.m_NetFilter );
228 m_cbOptimizeStep->SetValue( m_job->m_3dparams.m_OptimizeStep );
229 m_cbExportBody->SetValue( m_job->m_3dparams.m_ExportBoardBody );
230 m_cbExportComponents->SetValue( m_job->m_3dparams.m_ExportComponents );
231 m_cbExportTracks->SetValue( m_job->m_3dparams.m_ExportTracksVias );
232 m_cbExportPads->SetValue( m_job->m_3dparams.m_ExportPads );
233 m_cbExportZones->SetValue( m_job->m_3dparams.m_ExportZones );
234 m_cbExportInnerCopper->SetValue( m_job->m_3dparams.m_ExportInnerCopper );
235 m_cbExportSilkscreen->SetValue( m_job->m_3dparams.m_ExportSilkscreen );
236 m_cbExportSoldermask->SetValue( m_job->m_3dparams.m_ExportSoldermask );
237 m_cbFuseShapes->SetValue( m_job->m_3dparams.m_FuseShapes );
238 m_cbCutViasInBody->SetValue( m_job->m_3dparams.m_CutViasInBody );
239 m_cbFillAllVias->SetValue( m_job->m_3dparams.m_FillAllVias );
240 m_cbRemoveUnspecified->SetValue( !m_job->m_3dparams.m_IncludeUnspecified );
241 m_cbRemoveDNP->SetValue( !m_job->m_3dparams.m_IncludeDNP );
242 m_cbSubstModels->SetValue( m_job->m_3dparams.m_SubstModels );
243 m_cbOverwriteFile->SetValue( m_job->m_3dparams.m_Overwrite );
244
245 if( m_job->m_3dparams.m_BoardOutlinesChainingEpsilon > 0.05 )
246 m_choiceTolerance->SetSelection( 2 );
247 else if( m_job->m_3dparams.m_BoardOutlinesChainingEpsilon < 0.005 )
248 m_choiceTolerance->SetSelection( 0 );
249 else
250 m_choiceTolerance->SetSelection( 1 );
251
252 m_txtComponentFilter->SetValue( m_job->m_3dparams.m_ComponentFilter );
253 m_outputFileName->SetValue( m_job->GetConfiguredOutputPath() );
254
255 if( !m_job->m_variant.IsEmpty() )
256 {
257 int idx = m_choiceVariant->FindString( m_job->m_variant );
258
259 if( idx != wxNOT_FOUND )
260 m_choiceVariant->SetSelection( idx );
261 }
262
263 // Use the recorded format instead of the file extension for jobs
264 for( auto& formats : c_formatJobCommand )
265 {
266 if( formats.second == m_job->m_3dparams.m_Format )
267 {
268 m_choiceFormat->SetSelection( formats.first );
269 break;
270 }
271 }
272 }
273
274 // Sync the enabled states
275 wxCommandEvent dummy;
277
278 return true;
279}
280
281
283{
284 wxString variant;
285 int selection = m_choiceVariant->GetSelection();
286
287 if( ( selection != 0 ) && ( selection != wxNOT_FOUND ) )
288 variant = m_choiceVariant->GetString( selection );
289
290 return variant;
291}
292
293
295{
296 BOARD* board = m_frame->GetBoard();
297 wxFileName brdFile = board->GetFileName();
298
299 DIALOG_EXPORT_STEP dlg( m_frame, brdFile.GetFullPath() );
300 dlg.ShowModal();
301
302 return 0;
303}
304
305
306void DIALOG_EXPORT_STEP::onUpdateXPos( wxUpdateUIEvent& aEvent )
307{
308 aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
309}
310
311
312void DIALOG_EXPORT_STEP::onUpdateYPos( wxUpdateUIEvent& aEvent )
313{
314 aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
315}
316
317
318void DIALOG_EXPORT_STEP::onBrowseClicked( wxCommandEvent& aEvent )
319{
320 // clang-format off
321 wxString filter = _( "STEP files" )
323 + _( "Binary glTF files" )
325 + _( "XAO files" )
327 + _( "BREP (OCCT) files" )
329 + _( "PLY files" )
331 + _( "STL files" )
333 + _( "Universal 3D files" )
335 + _( "PDF files" )
337 // clang-format on
338
339 // Build the absolute path of current output directory to preselect it in the file browser.
340 wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
341 wxFileName fn( Prj().AbsolutePath( path ) );
342
343 wxFileDialog dlg( this, _( "3D Model Output File" ), fn.GetPath(), fn.GetFullName(), filter, wxFD_SAVE );
344
346
347 if( dlg.ShowModal() == wxID_CANCEL )
348 return;
349
350 path = dlg.GetPath();
351 m_outputFileName->SetValue( path );
352
353 fn = wxFileName( path );
354
355 if( auto formatChoice = get_opt( c_formatExtToChoice, fn.GetExt().Lower() ) )
356 m_choiceFormat->SetSelection( *formatChoice );
357}
358
359
360void DIALOG_EXPORT_STEP::onFormatChoice( wxCommandEvent& event )
361{
363}
364
365
367{
368 wxString newExt;
369 int idx = m_choiceFormat->GetSelection();
370
371 for( auto& choices : c_formatExtToChoice )
372 {
373 if( choices.second == idx )
374 {
375 newExt = choices.first;
376 break;
377 }
378 }
379
380 wxString path = m_outputFileName->GetValue();
381
382 int sepIdx = std::max( path.Find( '/', true ), path.Find( '\\', true ) );
383 int dotIdx = path.Find( '.', true );
384
385 if( dotIdx == -1 || dotIdx < sepIdx )
386 path << '.' << newExt;
387 else
388 path = path.Mid( 0, dotIdx ) << '.' << newExt;
389
390 m_outputFileName->SetValue( path );
391}
392
393
394void DIALOG_EXPORT_STEP::onCbExportComponents( wxCommandEvent& event )
395{
396 bool enable = m_cbExportComponents->GetValue();
397
398 m_rbAllComponents->Enable( enable );
399 m_rbOnlySelected->Enable( enable );
400 m_rbFilteredComponents->Enable( enable );
401 m_txtComponentFilter->Enable( enable && m_rbFilteredComponents->GetValue() );
402}
403
404
405void DIALOG_EXPORT_STEP::OnComponentModeChange( wxCommandEvent& event )
406{
407 m_txtComponentFilter->Enable( m_rbFilteredComponents->GetValue() );
408}
409
410
411wxString DIALOG_EXPORT_STEP::StageBoardForExport( const wxString& aBoardPath, bool aContentModified, BOARD* aBoard,
412 wxString& aInputPath, std::vector<wxString>& aTempFiles,
413 wxString& aErrorDetail )
414{
415 aErrorDetail = wxEmptyString;
416
417 if( aBoardPath.IsEmpty() )
418 return _( "Please save the board before exporting STEP." );
419
420 // A clean board exports its on-disk file directly, as long as it still exists.
421 if( !aContentModified )
422 {
423 if( !wxFileExists( aBoardPath ) )
424 {
425 return _( "Board file not found on disk.\n"
426 "Save the board before exporting STEP." );
427 }
428
429 aInputPath = aBoardPath;
430 return wxEmptyString;
431 }
432
433 wxFileName boardFn( aBoardPath );
434
435 if( !boardFn.DirExists() )
436 {
437 return _( "The board directory no longer exists.\n"
438 "Save the board to a valid location before exporting STEP." );
439 }
440
441 // Reserve a unique stem in the board directory so concurrent exports and stale leftovers from a
442 // crashed run cannot clobber each other.
443 wxString stemPrefix = boardFn.GetName() + wxS( "-unsaved-export-" );
444 wxString reserved = wxFileName::CreateTempFileName( boardFn.GetPathWithSep() + stemPrefix );
445
446 if( reserved.IsEmpty() )
447 return _( "Failed to reserve a temporary filename for STEP export." );
448
449 wxFileName stemFn( reserved );
450 wxFileName tempBoardFn( boardFn.GetPath(), stemFn.GetName(), FILEEXT::KiCadPcbFileExtension );
451 wxFileName tempProjectFn( boardFn.GetPath(), stemFn.GetName(), FILEEXT::ProjectFileExtension );
452
453 // Schedule the placeholder for cleanup. If this initial delete fails the later sweep will
454 // retry; we keep it registered in aTempFiles regardless so it never leaks.
455 aTempFiles.push_back( reserved );
456 wxRemoveFile( reserved );
457
458 try
459 {
461 pi->SaveBoard( tempBoardFn.GetFullPath(), aBoard, nullptr );
462 }
463 catch( const IO_ERROR& ioe )
464 {
465 aErrorDetail = ioe.What();
466 return _( "Failed to save the current board state for export." );
467 }
468
469 aTempFiles.push_back( tempBoardFn.GetFullPath() );
470
471 wxFileName srcProjectFn = boardFn;
472 srcProjectFn.SetExt( FILEEXT::ProjectFileExtension );
473
474 if( srcProjectFn.FileExists() )
475 {
476 if( !wxCopyFile( srcProjectFn.GetFullPath(), tempProjectFn.GetFullPath(), true ) )
477 {
478 wxRemoveFile( tempBoardFn.GetFullPath() );
479 return _( "Failed to stage the project file for STEP export." );
480 }
481
482 aTempFiles.push_back( tempProjectFn.GetFullPath() );
483 }
484
485 aInputPath = tempBoardFn.GetFullPath();
486 return wxEmptyString;
487}
488
489
490void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
491{
492 wxString path = m_outputFileName->GetValue();
493 double tolerance; // default value in mm
494
495 switch( m_choiceTolerance->GetSelection() )
496 {
497 case 0: tolerance = 0.001; break;
498 default:
499 case 1: tolerance = 0.01; break;
500 case 2: tolerance = 0.1; break;
501 }
502
503 if( !m_job )
504 {
505 // Build the absolute path of current output directory to preselect it in the file browser.
506 std::function<bool( wxString* )> textResolver =
507 [&]( wxString* token ) -> bool
508 {
509 return m_editFrame->GetBoard()->ResolveTextVar( token, 0 );
510 };
511
512 path = ExpandTextVars( path, &textResolver );
514 path = Prj().AbsolutePath( path );
515
516 if( path.IsEmpty() )
517 {
518 DisplayErrorMessage( this, _( "No filename for output file" ) );
519 return;
520 }
521
522 SHAPE_POLY_SET outline;
523 wxString msg;
524
525 // Check if the board outline is continuous
526 // max dist from one endPt to next startPt to build a closed shape:
527 int chainingEpsilon = pcbIUScale.mmToIU( tolerance );
528
529 // Arc to segment approximation error (not critical here: we do not use the outline shape):
530 int maxError = pcbIUScale.mmToIU( 0.05 );
531
532 if( !BuildBoardPolygonOutlines( m_editFrame->GetBoard(), outline, maxError, chainingEpsilon, false ) )
533 {
534 DisplayErrorMessage( this, wxString::Format( _( "Board outline is missing or not closed using "
535 "%.3f mm tolerance.\n"
536 "Run DRC for a full analysis." ),
537 tolerance ) );
538 return;
539 }
540
541 wxFileName fn( Prj().AbsolutePath( path ) );
542
543 if( fn.FileExists() && !m_cbOverwriteFile->GetValue() )
544 {
545 msg.Printf( _( "File '%s' already exists. Do you want overwrite this file?" ), fn.GetFullPath() );
546
547 if( wxMessageBox( msg, _( "STEP/GLTF Export" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
548 return;
549 }
550
551 m_editFrame->SetLastPath( LAST_PATH_STEP, fn.GetFullPath() );
552
553 wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
554 #ifdef __WXMAC__
555 // On macOS, we have standalone applications inside the main bundle, so we handle that here:
556 if( appK2S.GetPath().Find( "/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
557 {
558 appK2S.AppendDir( wxT( ".." ) );
559 appK2S.AppendDir( wxT( ".." ) );
560 appK2S.AppendDir( wxT( ".." ) );
561 appK2S.AppendDir( wxT( ".." ) );
562 appK2S.AppendDir( wxT( "MacOS" ) );
563 }
564 #else
565 if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
566 {
567 appK2S.RemoveLastDir();
568 appK2S.AppendDir( "kicad" );
569 }
570 #endif
571
572 appK2S.SetName( wxT( "kicad-cli" ) );
573 appK2S.Normalize( FN_NORMALIZE_FLAGS );
574
575 wxString cmdK2S = wxT( "\"" );
576 cmdK2S.Append( appK2S.GetFullPath() );
577 cmdK2S.Append( wxT( "\"" ) );
578
579 cmdK2S.Append( wxT( " pcb" ) );
580 cmdK2S.Append( wxT( " export" ) );
581
582 cmdK2S.Append( wxT( " " ) );
583 cmdK2S.Append( c_formatCommand[m_choiceFormat->GetSelection()] );
584
585 if( m_cbRemoveUnspecified->GetValue() )
586 cmdK2S.Append( wxT( " --no-unspecified" ) );
587
588 if( m_cbRemoveDNP->GetValue() )
589 cmdK2S.Append( wxT( " --no-dnp" ) );
590
591 if( m_cbSubstModels->GetValue() )
592 cmdK2S.Append( wxT( " --subst-models" ) );
593
594 if( !m_cbOptimizeStep->GetValue() )
595 cmdK2S.Append( wxT( " --no-optimize-step" ) );
596
597 if( !m_cbExportBody->GetValue() )
598 cmdK2S.Append( wxT( " --no-board-body" ) );
599
600 if( !m_cbExportComponents->GetValue() )
601 cmdK2S.Append( wxT( " --no-components" ) );
602
603 if( m_cbExportTracks->GetValue() )
604 cmdK2S.Append( wxT( " --include-tracks" ) );
605
606 if( m_cbExportPads->GetValue() )
607 cmdK2S.Append( wxT( " --include-pads" ) );
608
609 if( m_cbExportZones->GetValue() )
610 cmdK2S.Append( wxT( " --include-zones" ) );
611
612 if( m_cbExportInnerCopper->GetValue() )
613 cmdK2S.Append( wxT( " --include-inner-copper" ) );
614
615 if( m_cbExportSilkscreen->GetValue() )
616 cmdK2S.Append( wxT( " --include-silkscreen" ) );
617
618 if( m_cbExportSoldermask->GetValue() )
619 cmdK2S.Append( wxT( " --include-soldermask" ) );
620
621 if( m_cbFuseShapes->GetValue() )
622 cmdK2S.Append( wxT( " --fuse-shapes" ) );
623
624 if( m_cbCutViasInBody->GetValue() )
625 cmdK2S.Append( wxT( " --cut-vias-in-body" ) );
626
627 if( m_cbFillAllVias->GetValue() )
628 cmdK2S.Append( wxT( " --fill-all-vias" ) );
629
630 // Note: for some reason, using \" to insert a quote in a format string, under MacOS
631 // wxString::Format does not work. So use a %c format in string
632 int quote = '\'';
633 int dblquote = '"';
634
635 wxString selectedVariant = getSelectedVariant();
636
637 if( !selectedVariant.IsEmpty() )
638 {
639 cmdK2S.Append( wxString::Format( wxT( " --variant %c%s%c" ),
640 dblquote, selectedVariant, dblquote ) );
641 }
642
643 if( !m_txtNetFilter->GetValue().empty() )
644 {
645 cmdK2S.Append( wxString::Format( wxT( " --net-filter %c%s%c" ),
646 dblquote, m_txtNetFilter->GetValue(), dblquote ) );
647 }
648
649 if( m_rbOnlySelected->GetValue() )
650 {
651 wxArrayString components;
652 SELECTION& selection = m_editFrame->GetCurrentSelection();
653
654 std::for_each( selection.begin(), selection.end(),
655 [&components]( EDA_ITEM* item )
656 {
657 if( item->Type() == PCB_FOOTPRINT_T )
658 components.push_back( static_cast<FOOTPRINT*>( item )->GetReference() );
659 } );
660
661 cmdK2S.Append( wxString::Format( wxT( " --component-filter %c%s%c" ),
662 dblquote, wxJoin( components, ',' ), dblquote ) );
663 }
664 else if( m_rbFilteredComponents->GetValue() )
665 {
666 cmdK2S.Append( wxString::Format( wxT( " --component-filter %c%s%c" ),
667 dblquote, m_txtComponentFilter->GetValue(), dblquote ) );
668 }
669
670 if( m_rbDrillAndPlotOrigin->GetValue() )
671 {
672 cmdK2S.Append( wxT( " --drill-origin" ) );
673 }
674 else if( m_rbGridOrigin->GetValue() )
675 {
676 cmdK2S.Append( wxT( " --grid-origin" ) );
677 }
678 else if( m_rbUserDefinedOrigin->GetValue() )
679 {
680 double xOrg = pcbIUScale.IUTomm( m_originX.GetIntValue() );
681 double yOrg = pcbIUScale.IUTomm( m_originY.GetIntValue() );
682
684 cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
685 quote, xOrg, yOrg, quote ) );
686 }
687 else if( m_rbBoardCenterOrigin->GetValue() )
688 {
689 BOX2I bbox = m_editFrame->GetBoard()->ComputeBoundingBox( true, true );
690 double xOrg = pcbIUScale.IUTomm( bbox.GetCenter().x );
691 double yOrg = pcbIUScale.IUTomm( bbox.GetCenter().y );
693
694 cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
695 quote, xOrg, yOrg, quote ) );
696 }
697 else
698 {
699 wxFAIL_MSG( wxT( "Unsupported origin option: how did we get here?" ) );
700 }
701
702 {
704 cmdK2S.Append( wxString::Format( wxT( " --min-distance=%c%.3fmm%c" ),
705 quote, tolerance, quote ) );
706 }
707
708 // Output file path.
709 cmdK2S.Append( wxString::Format( wxT( " -f -o %c%s%c" ),
710 dblquote, fn.GetFullPath(), dblquote ) );
711
712 // kicad-cli runs in a separate process and reads the board from disk, so an unsaved board
713 // must be staged to a temp file first. Cleanup is delegated to the process-log dialog so
714 // we can wait for the child to actually exit.
715 wxString inputPath;
716 std::vector<wxString> tempFiles;
717 wxString errorDetail;
718 wxString error = StageBoardForExport( m_boardPath, m_editFrame->IsContentModified(), m_editFrame->GetBoard(),
719 inputPath, tempFiles, errorDetail );
720
721 if( !error.IsEmpty() )
722 {
723 DisplayErrorMessage( this, error, errorDetail );
724 return;
725 }
726
727 // Input file path.
728 cmdK2S.Append( wxString::Format( wxT( " %c%s%c" ), dblquote, inputPath, dblquote ) );
729
730 wxLogTrace( traceKiCad2Step, wxT( "export step command: %s" ), cmdK2S );
731
732 DIALOG_EXPORT_STEP_LOG* log = new DIALOG_EXPORT_STEP_LOG( this, cmdK2S );
733 log->SetTempFilesToCleanup( std::move( tempFiles ) );
734 log->ShowModal();
735 }
736 else
737 {
738 m_job->SetConfiguredOutputPath( path );
739 m_job->m_variant = getSelectedVariant();
740 m_job->m_3dparams.m_NetFilter = m_txtNetFilter->GetValue();
741 m_job->m_3dparams.m_ComponentFilter = m_txtComponentFilter->GetValue();
742 m_job->m_3dparams.m_ExportBoardBody = m_cbExportBody->GetValue();
743 m_job->m_3dparams.m_ExportComponents = m_cbExportComponents->GetValue();
744 m_job->m_3dparams.m_ExportTracksVias = m_cbExportTracks->GetValue();
745 m_job->m_3dparams.m_ExportPads = m_cbExportPads->GetValue();
746 m_job->m_3dparams.m_ExportZones = m_cbExportZones->GetValue();
747 m_job->m_3dparams.m_ExportInnerCopper = m_cbExportInnerCopper->GetValue();
748 m_job->m_3dparams.m_ExportSilkscreen = m_cbExportSilkscreen->GetValue();
749 m_job->m_3dparams.m_ExportSoldermask = m_cbExportSoldermask->GetValue();
750 m_job->m_3dparams.m_FuseShapes = m_cbFuseShapes->GetValue();
751 m_job->m_3dparams.m_CutViasInBody = m_cbCutViasInBody->GetValue();
752 m_job->m_3dparams.m_FillAllVias = m_cbFillAllVias->GetValue();
753 m_job->m_3dparams.m_OptimizeStep = m_cbOptimizeStep->GetValue();
754 m_job->m_3dparams.m_Overwrite = m_cbOverwriteFile->GetValue();
755 m_job->m_3dparams.m_IncludeUnspecified = !m_cbRemoveUnspecified->GetValue();
756 m_job->m_3dparams.m_IncludeDNP = !m_cbRemoveDNP->GetValue();
757 m_job->m_3dparams.m_SubstModels = m_cbSubstModels->GetValue();
758 m_job->m_3dparams.m_BoardOutlinesChainingEpsilon = tolerance;
759
760 if( auto formatChoice = get_opt( c_formatJobCommand, m_choiceFormat->GetSelection() ) )
761 {
762 m_job->SetStepFormat( *formatChoice );
763 }
764 else
765 {
766 wxASSERT_MSG(false, wxString::Format( "Unknown format value %d", m_choiceFormat->GetSelection() ) );
767 }
768
769
770 // ensure the main format on the job is populated
771 switch( m_job->m_3dparams.m_Format )
772 {
782 }
783
784 m_job->m_3dparams.m_UseDrillOrigin = false;
785 m_job->m_3dparams.m_UseGridOrigin = false;
786 m_job->m_3dparams.m_UseDefinedOrigin = false;
787 m_job->m_3dparams.m_UsePcbCenterOrigin = false;
788
789 if( m_rbDrillAndPlotOrigin->GetValue() )
790 {
791 m_job->m_3dparams.m_UseDrillOrigin = true;
792 }
793 else if( m_rbGridOrigin->GetValue() )
794 {
795 m_job->m_3dparams.m_UseGridOrigin = true;
796 }
797 else if( m_rbUserDefinedOrigin->GetValue() )
798 {
799 double xOrg = pcbIUScale.IUTomm( m_originX.GetIntValue() );
800 double yOrg = pcbIUScale.IUTomm( m_originY.GetIntValue() );
801
802 m_job->m_3dparams.m_UseDefinedOrigin = true;
803 m_job->m_3dparams.m_Origin = VECTOR2D( xOrg, yOrg );
804 }
805 else if( m_rbBoardCenterOrigin->GetValue() )
806 {
807 BOX2I bbox = m_editFrame->GetBoard()->ComputeBoundingBox( true, true );
808 double xOrg = pcbIUScale.IUTomm( bbox.GetCenter().x );
809 double yOrg = pcbIUScale.IUTomm( bbox.GetCenter().y );
811
812 m_job->m_3dparams.m_UsePcbCenterOrigin = true;
813 m_job->m_3dparams.m_Origin = VECTOR2D( xOrg, yOrg );
814 }
815
816 EndModal( wxID_OK );
817 }
818}
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:918
int ExportSTEP(const TOOL_EVENT &aEvent)
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
constexpr const Vec GetCenter() const
Definition box2.h:226
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
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:96
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:528
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
ITER end()
Definition selection.h:76
ITER begin()
Definition selection.h:75
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:704
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: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:448
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.
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