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