KiCad PCB EDA Suite
Loading...
Searching...
No Matches
exporter_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) 2022 Mark Roszko <[email protected]>
5 * Copyright (C) 2016 Cirilo Bernardo <[email protected]>
6 * Copyright (C) 2016-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include "exporter_step.h"
27#include <advanced_config.h>
28#include <board.h>
30#include <footprint.h>
31#include <pcb_textbox.h>
32#include <pcb_track.h>
33#include <pcb_shape.h>
34#include <pad.h>
35#include <zone.h>
36#include <fp_lib_table.h>
37#include "step_pcb_model.h"
38
39#include <pgm_base.h>
40#include <base_units.h>
41#include <filename_resolver.h>
42#include <trace_helpers.h>
43#include <project_pcb.h>
45
46#include <Message.hxx> // OpenCascade messenger
47#include <Message_PrinterOStream.hxx> // OpenCascade output messenger
48#include <Standard_Failure.hxx> // In open cascade
49
50#include <Standard_Version.hxx>
51
52#include <wx/crt.h>
53#include <wx/log.h>
54#include <core/profile.h> // To use GetRunningMicroSecs or another profiling utility
55
56#define OCC_VERSION_MIN 0x070500
57
58#if OCC_VERSION_HEX < OCC_VERSION_MIN
59#include <Message_Messenger.hxx>
60#endif
61
62
63void ReportMessage( const wxString& aMessage )
64{
65 wxPrintf( aMessage );
66 fflush( stdout ); // Force immediate printing (needed on mingw)
67}
68
69class KiCadPrinter : public Message_Printer
70{
71public:
72 KiCadPrinter( EXPORTER_STEP* aConverter ) : m_converter( aConverter ) {}
73
74protected:
75#if OCC_VERSION_HEX < OCC_VERSION_MIN
76 virtual void Send( const TCollection_ExtendedString& theString,
77 const Message_Gravity theGravity,
78 const Standard_Boolean theToPutEol ) const override
79 {
80 Send( TCollection_AsciiString( theString ), theGravity, theToPutEol );
81 }
82
83 virtual void Send( const TCollection_AsciiString& theString,
84 const Message_Gravity theGravity,
85 const Standard_Boolean theToPutEol ) const override
86#else
87 virtual void send( const TCollection_AsciiString& theString,
88 const Message_Gravity theGravity ) const override
89#endif
90 {
91 if( theGravity >= Message_Warning
92 || ( wxLog::IsAllowedTraceMask( traceKiCad2Step ) && theGravity == Message_Info ) )
93 {
94 ReportMessage( theString.ToCString() );
95
96#if OCC_VERSION_HEX < OCC_VERSION_MIN
97 if( theToPutEol )
98 ReportMessage( wxT( "\n" ) );
99#else
100 ReportMessage( wxT( "\n" ) );
101#endif
102 }
103
104 if( theGravity == Message_Warning )
106
107 if( theGravity >= Message_Alarm )
109
110 if( theGravity == Message_Fail )
112 }
113
114private:
116};
117
118
120 m_params( aParams ),
121 m_error( false ),
122 m_fail( false ),
123 m_warn( false ),
124 m_board( aBoard ),
125 m_pcbModel( nullptr )
126{
127 m_copperColor = COLOR4D( 0.7, 0.61, 0.0, 1.0 );
128
130 m_padColor = COLOR4D( 0.50, 0.50, 0.50, 1.0 );
131 else
133
134 // TODO: make configurable
136
137 // Init m_pcbBaseName to the board short filename (no path, no ext)
138 // m_pcbName is used later to identify items in step file
139 wxFileName fn( aBoard->GetFileName() );
140 m_pcbBaseName = fn.GetName();
141
142 // Remove the autosave prefix
144
145 m_resolver = std::make_unique<FILENAME_RESOLVER>();
146 m_resolver->Set3DConfigDir( wxT( "" ) );
147 // needed to add the project to the search stack
148 m_resolver->SetProject( aBoard->GetProject() );
149 m_resolver->SetProgramBase( &Pgm() );
150}
151
152
154{
155}
156
157
159{
160 bool hasdata = false;
161 std::vector<PAD*> padsMatchingNetFilter;
162 int maxError = m_board->GetDesignSettings().m_MaxError;
163
164 // Dump the pad holes into the PCB
165 for( PAD* pad : aFootprint->Pads() )
166 {
167 std::shared_ptr<SHAPE_SEGMENT> holeShape = pad->GetEffectiveHoleShape();
168
169 SHAPE_POLY_SET holePoly;
170 holeShape->TransformToPolygon( holePoly, maxError, ERROR_INSIDE );
171
172 for( PCB_LAYER_ID pcblayer : pad->GetLayerSet().Seq() )
173 {
174 if( pad->IsOnLayer( pcblayer ) )
175 m_poly_holes[pcblayer].Append( holePoly );
176 }
177
178 if( pad->HasHole() )
179 {
180 int platingThickness = pad->GetAttribute() == PAD_ATTRIB::PTH ? m_platingThickness : 0;
181
182 if( m_pcbModel->AddHole( *holeShape, platingThickness, F_Cu, B_Cu, false, aOrigin, true,
183 true ) )
184 {
185 hasdata = true;
186 }
187
189 //if( m_layersToExport.Contains( F_SilkS ) || m_layersToExport.Contains( B_SilkS ) )
190 //{
191 // m_poly_holes[F_SilkS].Append( holePoly );
192 // m_poly_holes[B_SilkS].Append( holePoly );
193 //}
194 }
195
196 if( !m_params.m_NetFilter.IsEmpty() && !pad->GetNetname().Matches( m_params.m_NetFilter ) )
197 continue;
198
200 {
201 if( m_pcbModel->AddPadShape( pad, aOrigin, false ) )
202 hasdata = true;
203
205 {
206 for( PCB_LAYER_ID pcblayer : pad->GetLayerSet().Seq() )
207 {
208 if( pcblayer != F_Mask && pcblayer != B_Mask )
209 continue;
210
211 SHAPE_POLY_SET poly;
212 PCB_LAYER_ID cuLayer = ( pcblayer == F_Mask ) ? F_Cu : B_Cu;
213 pad->TransformShapeToPolygon( poly, cuLayer,
214 pad->GetSolderMaskExpansion( cuLayer ), maxError,
215 ERROR_INSIDE );
216
217 m_poly_shapes[pcblayer].Append( poly );
218 }
219 }
220 }
221
222 padsMatchingNetFilter.push_back( pad );
223 }
224
225 // Build 3D shapes of the footprint graphic items:
226 for( PCB_LAYER_ID pcblayer : m_layersToExport.Seq() )
227 {
228 if( IsCopperLayer( pcblayer ) && !m_params.m_ExportTracksVias )
229 continue;
230
231 SHAPE_POLY_SET buffer;
232
233 aFootprint->TransformFPShapesToPolySet( buffer, pcblayer, 0, maxError, ERROR_INSIDE,
234 true, /* include text */
235 true, /* include shapes */
236 false /* include private items */ );
237
238 if( m_params.m_NetFilter.IsEmpty() || !IsCopperLayer( pcblayer ) )
239 {
240 m_poly_shapes[pcblayer].Append( buffer );
241 }
242 else
243 {
244 // Only add shapes colliding with any matching pads
245 for( const SHAPE_POLY_SET::POLYGON& poly : buffer.CPolygons() )
246 {
247 for( PAD* pad : padsMatchingNetFilter )
248 {
249 if( !pad->IsOnLayer( pcblayer ) )
250 continue;
251
252 std::shared_ptr<SHAPE_POLY_SET> padPoly = pad->GetEffectivePolygon( pcblayer );
253 SHAPE_POLY_SET gfxPoly( poly );
254
255 if( padPoly->Collide( &gfxPoly ) )
256 {
257 m_poly_shapes[pcblayer].Append( gfxPoly );
258 break;
259 }
260 }
261 }
262 }
263 }
264
265 if( ( !(aFootprint->GetAttributes() & (FP_THROUGH_HOLE|FP_SMD)) ) && !m_params.m_IncludeUnspecified )
266 {
267 return hasdata;
268 }
269
270 if( ( aFootprint->GetAttributes() & FP_DNP ) && !m_params.m_IncludeDNP )
271 {
272 return hasdata;
273 }
274
275 // Prefetch the library for this footprint
276 // In case we need to resolve relative footprint paths
277 wxString libraryName = aFootprint->GetFPID().GetLibNickname();
278 wxString footprintBasePath = wxEmptyString;
279
280 double posX = aFootprint->GetPosition().x - aOrigin.x;
281 double posY = (aFootprint->GetPosition().y) - aOrigin.y;
282
283 if( m_board->GetProject() )
284 {
285 try
286 {
287 // FindRow() can throw an exception
288 const FP_LIB_TABLE_ROW* fpRow =
289 PROJECT_PCB::PcbFootprintLibs( m_board->GetProject() )->FindRow( libraryName, false );
290
291 if( fpRow )
292 footprintBasePath = fpRow->GetFullURI( true );
293 }
294 catch( ... )
295 {
296 // Do nothing if the libraryName is not found in lib table
297 }
298 }
299
300 // Exit early if we don't want to include footprint models
302 {
303 return hasdata;
304 }
305
306 bool componentFilter = !m_params.m_ComponentFilter.IsEmpty();
307 std::vector<wxString> componentFilterPatterns;
308
309 if( componentFilter )
310 {
311 wxStringTokenizer tokenizer( m_params.m_ComponentFilter, wxS( "," ), wxTOKEN_STRTOK );
312
313 while( tokenizer.HasMoreTokens() )
314 componentFilterPatterns.push_back( tokenizer.GetNextToken().Trim( false ) );
315
316 bool found = false;
317
318 for( const wxString& pattern : componentFilterPatterns )
319 {
320 if( aFootprint->GetReference().Matches( pattern ) )
321 {
322 found = true;
323 break;
324 }
325 }
326
327 if( !found )
328 return hasdata;
329 }
330
331 VECTOR2D newpos( pcbIUScale.IUTomm( posX ), pcbIUScale.IUTomm( posY ) );
332
333 for( const FP_3DMODEL& fp_model : aFootprint->Models() )
334 {
335 if( !fp_model.m_Show || fp_model.m_Filename.empty() )
336 continue;
337
338 std::vector<wxString> searchedPaths;
339 wxString mname = m_resolver->ResolvePath( fp_model.m_Filename, footprintBasePath, aFootprint );
340
341
342 if( mname.empty() || !wxFileName::FileExists( mname ) )
343 {
344 // the error path will return an empty name sometimes, at least report back the original filename
345 if( mname.empty() )
346 mname = fp_model.m_Filename;
347
348 ReportMessage( wxString::Format( wxT( "Could not add 3D model to %s.\n"
349 "File not found: %s\n" ),
350 aFootprint->GetReference(), mname ) );
351 continue;
352 }
353
354 std::string fname( mname.ToUTF8() );
355 std::string refName( aFootprint->GetReference().ToUTF8() );
356 try
357 {
358 bool bottomSide = aFootprint->GetLayer() == B_Cu;
359
360 // the rotation is stored in degrees but opencascade wants radians
361 VECTOR3D modelRot = fp_model.m_Rotation;
362 modelRot *= M_PI;
363 modelRot /= 180.0;
364
365 if( m_pcbModel->AddComponent( fname, refName, bottomSide,
366 newpos,
367 aFootprint->GetOrientation().AsRadians(),
368 fp_model.m_Offset, modelRot,
369 fp_model.m_Scale, m_params.m_SubstModels ) )
370 {
371 hasdata = true;
372 }
373 }
374 catch( const Standard_Failure& e )
375 {
376 ReportMessage( wxString::Format( wxT( "Could not add 3D model to %s.\n"
377 "OpenCASCADE error: %s\n" ),
378 aFootprint->GetReference(), e.GetMessageString() ) );
379 }
380
381 }
382
383 return hasdata;
384}
385
386
388{
389 bool skipCopper = !m_params.m_ExportTracksVias
390 || ( !m_params.m_NetFilter.IsEmpty()
391 && !aTrack->GetNetname().Matches( m_params.m_NetFilter ) );
392
393 int maxError = m_board->GetDesignSettings().m_MaxError;
394
395 if( aTrack->Type() == PCB_VIA_T )
396 {
397 PCB_VIA* via = static_cast<PCB_VIA*>( aTrack );
398
399 std::shared_ptr<SHAPE_SEGMENT> holeShape = via->GetEffectiveHoleShape();
400 SHAPE_POLY_SET holePoly;
401 holeShape->TransformToPolygon( holePoly, maxError, ERROR_INSIDE );
402
403 LSET layers( via->GetLayerSet() & m_layersToExport );
404
405 PCB_LAYER_ID top_layer, bot_layer;
406 via->LayerPair( &top_layer, &bot_layer );
407
408 if( !skipCopper )
409 {
410 for( PCB_LAYER_ID pcblayer : layers.Seq() )
411 {
412 const std::shared_ptr<SHAPE>& shape = via->GetEffectiveShape( pcblayer );
413
414 SHAPE_POLY_SET poly;
415 shape->TransformToPolygon( poly, maxError, ERROR_INSIDE );
416 m_poly_shapes[pcblayer].Append( poly );
417 m_poly_holes[pcblayer].Append( holePoly );
418 }
419
420 m_pcbModel->AddBarrel( *holeShape, top_layer, bot_layer, true, aOrigin );
421 }
422
424 //if( m_layersToExport.Contains( F_SilkS ) || m_layersToExport.Contains( B_SilkS ) )
425 //{
426 // m_poly_holes[F_SilkS].Append( holePoly );
427 // m_poly_holes[B_SilkS].Append( holePoly );
428 //}
429
430 m_pcbModel->AddHole( *holeShape, m_platingThickness, top_layer, bot_layer, true, aOrigin,
432
433 return true;
434 }
435
436 if( skipCopper )
437 return true;
438
439 PCB_LAYER_ID pcblayer = aTrack->GetLayer();
440
441 if( !m_layersToExport.Contains( pcblayer ) )
442 return false;
443
444 aTrack->TransformShapeToPolygon( m_poly_shapes[pcblayer], pcblayer, 0, maxError, ERROR_INSIDE );
445
446 return true;
447}
448
449
451{
452 for( ZONE* zone : m_board->Zones() )
453 {
454 LSET layers = zone->GetLayerSet();
455
456 if( ( layers & LSET::AllCuMask() ).count() && !m_params.m_NetFilter.IsEmpty()
457 && !zone->GetNetname().Matches( m_params.m_NetFilter ) )
458 {
459 continue;
460 }
461
462 for( PCB_LAYER_ID layer : layers.Seq() )
463 {
464 SHAPE_POLY_SET fill_shape;
465 zone->TransformSolidAreasShapesToPolygon( layer, fill_shape );
467
468 fill_shape.SimplifyOutlines( ADVANCED_CFG::GetCfg().m_TriangulateSimplificationLevel );
469
470 m_poly_shapes[layer].Append( fill_shape );
471 }
472 }
473}
474
475
477{
478 PCB_LAYER_ID pcblayer = aItem->GetLayer();
479
480 if( !m_layersToExport.Contains( pcblayer ) )
481 return false;
482
483 if( IsCopperLayer( pcblayer ) && !m_params.m_ExportTracksVias )
484 return false;
485
487 return false;
488
489 int maxError = m_board->GetDesignSettings().m_MaxError;
490
491 switch( aItem->Type() )
492 {
493 case PCB_SHAPE_T:
494 {
495 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( aItem );
496
497 if( IsCopperLayer( pcblayer ) && !m_params.m_NetFilter.IsEmpty()
498 && !graphic->GetNetname().Matches( m_params.m_NetFilter ) )
499 {
500 return true;
501 }
502
503 graphic->TransformShapeToPolygon( m_poly_shapes[pcblayer], pcblayer, 0, maxError,
504 ERROR_INSIDE );
505
506 break;
507 }
508
509 case PCB_TEXT_T:
510 {
511 PCB_TEXT* text = static_cast<PCB_TEXT*>( aItem );
512
513 text->TransformTextToPolySet( m_poly_shapes[pcblayer], 0, maxError, ERROR_INSIDE );
514 break;
515 }
516
517 case PCB_TEXTBOX_T:
518 {
519 PCB_TEXTBOX* textbox = static_cast<PCB_TEXTBOX*>( aItem );
520
521 textbox->TransformTextToPolySet( m_poly_shapes[pcblayer], 0, maxError, ERROR_INSIDE );
522 break;
523 }
524
525 case PCB_TABLE_T:
526 // JEY TODO: tables
527 break;
528
529 default: wxFAIL_MSG( "buildGraphic3DShape: unhandled item type" );
530 }
531
532 return true;
533}
534
535
537{
538 // Specialize the STEP_PCB_MODEL generator for specific output format
539 // it can have some minor actions for the generator
540 switch( m_params.m_Format )
541 {
543 m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_STEP );
544 break;
545
547 m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_BREP );
548 break;
549
551 m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_XAO );
552 break;
553
555 m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_GLTF );
556 break;
557
559 m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_PLY );
560 break;
561
563 m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_STL );
564 break;
565
566 default:
567 m_pcbModel->SpecializeVariant( OUTPUT_FORMAT::FMT_OUT_UNKNOWN );
568 break;
569 }
570}
571
572
574{
575 if( m_pcbModel )
576 return true;
577
578 SHAPE_POLY_SET pcbOutlines; // stores the board main outlines
579
580 if( !m_board->GetBoardPolygonOutlines( pcbOutlines,
581 /* error handler */ nullptr,
582 /* allows use arcs in outlines */ true ) )
583 {
584 wxLogWarning( _( "Board outline is malformed. Run DRC for a full analysis." ) );
585 }
586
587 VECTOR2D origin;
588
589 // Determine the coordinate system reference:
590 // Precedence of reference point is Drill Origin > Grid Origin > User Offset
593 else if( m_params.m_UseGridOrigin )
595 else
596 origin = m_params.m_Origin;
597
598 m_pcbModel = std::make_unique<STEP_PCB_MODEL>( m_pcbBaseName );
599
601
603 m_pcbModel->SetPadColor( m_padColor.r, m_padColor.g, m_padColor.b );
604
605 m_pcbModel->SetStackup( m_board->GetStackupOrDefault() );
606 m_pcbModel->SetEnabledLayers( m_layersToExport );
607 m_pcbModel->SetFuseShapes( m_params.m_FuseShapes );
608 m_pcbModel->SetNetFilter( m_params.m_NetFilter );
609
610 // Note: m_params.m_BoardOutlinesChainingEpsilon is used only to build the board outlines,
611 // not to set OCC chaining epsilon (much smaller)
612 //
613 // Set the min distance between 2 points for OCC to see these 2 points as merged
614 // OCC_MAX_DISTANCE_TO_MERGE_POINTS is acceptable for OCC, otherwise there are issues
615 // to handle the shapes chaining on copper layers, because the Z dist is 0.035 mm and the
616 // min dist must be much smaller (we use 0.001 mm giving good results)
617 m_pcbModel->OCCSetMergeMaxDistance( OCC_MAX_DISTANCE_TO_MERGE_POINTS );
618
620
621 // For copper layers, only pads and tracks are added, because adding everything on copper
622 // generate unreasonable file sizes and take a unreasonable calculation time.
623 for( FOOTPRINT* fp : m_board->Footprints() )
624 buildFootprint3DShapes( fp, origin );
625
626 for( PCB_TRACK* track : m_board->Tracks() )
627 buildTrack3DShape( track, origin );
628
629 for( BOARD_ITEM* item : m_board->Drawings() )
630 buildGraphic3DShape( item, origin );
631
633 {
634 buildZones3DShape( origin );
635 }
636
637 SHAPE_POLY_SET pcbOutlinesNoArcs = pcbOutlines;
638 pcbOutlinesNoArcs.ClearArcs();
639
640 for( PCB_LAYER_ID pcblayer : m_layersToExport.Seq() )
641 {
642 SHAPE_POLY_SET poly = m_poly_shapes[pcblayer];
644
645 poly.SimplifyOutlines( pcbIUScale.mmToIU( 0.003 ) );
647
648 SHAPE_POLY_SET holes = m_poly_holes[pcblayer];
650
651 // Mask layer is negative
652 if( pcblayer == F_Mask || pcblayer == B_Mask )
653 {
654 SHAPE_POLY_SET mask = pcbOutlinesNoArcs;
655
658
659 poly = mask;
660 }
661 else
662 {
663 // Subtract holes
665
666 // Clip to board outline
668 }
669
670 m_pcbModel->AddPolygonShapes( &poly, pcblayer, origin );
671 }
672
673 ReportMessage( wxT( "Create PCB solid model\n" ) );
674
675 wxString msg;
676 msg.Printf( wxT( "Board outline: find %d initial points\n" ), pcbOutlines.FullPointCount() );
677 ReportMessage( msg );
678
679 if( !m_pcbModel->CreatePCB( pcbOutlines, origin, m_params.m_ExportBoardBody ) )
680 {
681 ReportMessage( wxT( "could not create PCB solid model\n" ) );
682 return false;
683 }
684
685 return true;
686}
687
688
690{
691 // Display the export time, for statistics
692 int64_t stats_startExportTime = GetRunningMicroSecs();
693
694 // setup opencascade message log
695 Message::DefaultMessenger()->RemovePrinters( STANDARD_TYPE( Message_PrinterOStream ) );
696 Message::DefaultMessenger()->AddPrinter( new KiCadPrinter( this ) );
697
698 ReportMessage( _( "Determining PCB data\n" ) );
699
700 if( m_params.m_OutputFile.IsEmpty() )
701 {
702 wxFileName fn = m_board->GetFileName();
703 fn.SetName( fn.GetName() );
704 fn.SetExt( m_params.GetDefaultExportExtension() );
705
706 m_params.m_OutputFile = fn.GetFullName();
707 }
708
710
713
715 {
718 }
719
721 {
724 }
725
727
728 try
729 {
730 ReportMessage( wxString::Format( _( "Build %s data\n" ), m_params.GetFormatName() ) );
731
732 if( !buildBoard3DShapes() )
733 {
734 ReportMessage( _( "\n** Error building STEP board model. Export aborted. **\n" ) );
735 return false;
736 }
737
738 ReportMessage( wxString::Format( _( "Writing %s file\n" ), m_params.GetFormatName() ) );
739
740 bool success = true;
742 success = m_pcbModel->WriteSTEP( m_outputFile, m_params.m_OptimizeStep );
744 success = m_pcbModel->WriteBREP( m_outputFile );
746 success = m_pcbModel->WriteXAO( m_outputFile );
748 success = m_pcbModel->WriteGLTF( m_outputFile );
750 success = m_pcbModel->WritePLY( m_outputFile );
752 success = m_pcbModel->WriteSTL( m_outputFile );
753
754 if( !success )
755 {
756 ReportMessage( wxString::Format( _( "\n** Error writing %s file. **\n" ),
758 return false;
759 }
760 else
761 {
762 ReportMessage( wxString::Format( _( "%s file '%s' created.\n" ),
764 }
765 }
766 catch( const Standard_Failure& e )
767 {
768 ReportMessage( e.GetMessageString() );
769 ReportMessage( wxString::Format( _( "\n** Error exporting %s file. Export aborted. **\n" ),
771 return false;
772 }
773 catch( ... )
774 {
775 ReportMessage( wxString::Format( _( "\n** Error exporting %s file. Export aborted. **\n" ),
777 return false;
778 }
779
780 if( m_fail || m_error )
781 {
782 wxString msg;
783
784 if( m_fail )
785 {
786 msg = wxString::Format( _( "Unable to create %s file.\n"
787 "Check that the board has a valid outline and models." ),
789 }
790 else if( m_error || m_warn )
791 {
792 msg = wxString::Format( _( "%s file has been created, but there are warnings." ),
794 }
795
796 ReportMessage( msg );
797 }
798
799 // Display calculation time in seconds
800 double calculation_time = (double)( GetRunningMicroSecs() - stats_startExportTime) / 1e6;
801 ReportMessage( wxString::Format( _( "\nExport time %.3f s\n" ), calculation_time ) );
802
803 return true;
804}
@ ERROR_INSIDE
Definition: approximation.h:34
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
BASE_SET & set(size_t pos)
Definition: base_set.h:115
const VECTOR2I & GetGridOrigin()
const VECTOR2I & GetAuxOrigin()
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:237
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
BOARD_STACKUP GetStackupOrDefault() const
Definition: board.cpp:2291
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:2497
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:778
const ZONES & Zones() const
Definition: board.h:335
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
const wxString & GetFileName() const
Definition: board.h:327
PROJECT * GetProject() const
Definition: board.h:491
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
const DRAWINGS & Drawings() const
Definition: board.h:333
double AsRadians() const
Definition: eda_angle.h:117
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
wxString GetFormatName() const
wxString GetDefaultExportExtension() const
int m_platingThickness
Definition: exporter_step.h:90
void buildZones3DShape(VECTOR2D aOrigin)
LSET m_layersToExport
Definition: exporter_step.h:85
void initOutputVariant()
std::map< PCB_LAYER_ID, SHAPE_POLY_SET > m_poly_holes
Definition: exporter_step.h:83
BOARD * m_board
Definition: exporter_step.h:75
wxString m_outputFile
Definition: exporter_step.h:53
bool buildGraphic3DShape(BOARD_ITEM *aItem, VECTOR2D aOrigin)
EXPORTER_STEP_PARAMS m_params
Definition: exporter_step.h:67
EXPORTER_STEP(BOARD *aBoard, const EXPORTER_STEP_PARAMS &aParams)
wxString m_pcbBaseName
the name of the project (board short filename (no path, no ext) used to identify items in step file
Definition: exporter_step.h:80
bool buildFootprint3DShapes(FOOTPRINT *aFootprint, VECTOR2D aOrigin)
std::unique_ptr< FILENAME_RESOLVER > m_resolver
Definition: exporter_step.h:68
bool buildBoard3DShapes()
std::unique_ptr< STEP_PCB_MODEL > m_pcbModel
Definition: exporter_step.h:76
std::map< PCB_LAYER_ID, SHAPE_POLY_SET > m_poly_shapes
Definition: exporter_step.h:82
bool buildTrack3DShape(PCB_TRACK *aTrack, VECTOR2D aOrigin)
KIGFX::COLOR4D m_copperColor
Definition: exporter_step.h:87
KIGFX::COLOR4D m_padColor
Definition: exporter_step.h:88
EDA_ANGLE GetOrientation() const
Definition: footprint.h:227
std::deque< PAD * > & Pads()
Definition: footprint.h:206
int GetAttributes() const
Definition: footprint.h:290
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: footprint.h:236
void TransformFPShapesToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool aIncludeText=true, bool aIncludeShapes=true, bool aIncludePrivateItems=false) const
Generate shapes of graphic items (outlines) on layer aLayer as polygons and adds these polygons to aB...
Definition: footprint.cpp:3816
const LIB_ID & GetFPID() const
Definition: footprint.h:248
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:220
const wxString & GetReference() const
Definition: footprint.h:622
VECTOR2I GetPosition() const override
Definition: footprint.h:224
Hold a record identifying a library accessed by the appropriate footprint library #PLUGIN object in t...
Definition: fp_lib_table.h:42
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
double r
Red component.
Definition: color4d.h:392
double g
Green component.
Definition: color4d.h:393
double b
Blue component.
Definition: color4d.h:394
EXPORTER_STEP * m_converter
KiCadPrinter(EXPORTER_STEP *aConverter)
virtual void Send(const TCollection_ExtendedString &theString, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const override
virtual void Send(const TCollection_AsciiString &theString, const Message_Gravity theGravity, const Standard_Boolean theToPutEol) const override
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
const wxString GetFullURI(bool aSubstituted=false) const
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
static LSET ExternalCuMask()
Return a mask holding the Front and Bottom layers.
Definition: lset.cpp:704
static LSET InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition: lset.cpp:675
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:420
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:62
Definition: pad.h:54
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the shape to a closed polygon.
Definition: pcb_shape.cpp:774
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the track shape to a closed polygon.
Definition: pcb_track.cpp:1974
static FP_LIB_TABLE * PcbFootprintLibs(PROJECT *aProject)
Return the table of footprint libraries without Kiway.
Definition: project_pcb.cpp:37
Represent a set of closed polygons.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
int FullPointCount() const
Return the number of points in the shape poly set.
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
void Unfracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
void SimplifyOutlines(int aMaxError=0)
Simplifies the lines in the polyset.
void TransformToPolygon(SHAPE_POLY_SET &aBuffer, int aError, ERROR_LOC aErrorLoc) const override
Fills a SHAPE_POLY_SET with a polygon representation of this shape.
const std::vector< POLYGON > & CPolygons() const
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
#define _(s)
void ReportMessage(const wxString &aMessage)
@ FP_SMD
Definition: footprint.h:76
@ FP_DNP
Definition: footprint.h:83
@ FP_THROUGH_HOLE
Definition: footprint.h:75
static const std::string AutoSaveFilePrefix
const wxChar *const traceKiCad2Step
Flag to enable KiCad2Step debug tracing.
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:531
bool IsInnerCopperLayer(int aLayerId)
Tests whether a layer is an inner (In1_Cu to In30_Cu) copper layer.
Definition: layer_ids.h:553
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ F_Mask
Definition: layer_ids.h:97
@ F_SilkS
Definition: layer_ids.h:100
@ B_SilkS
Definition: layer_ids.h:101
@ F_Cu
Definition: layer_ids.h:64
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
int64_t GetRunningMicroSecs()
An alternate way to calculate an elapsed time (in microsecondes) to class PROF_COUNTER.
static constexpr double OCC_MAX_DISTANCE_TO_MERGE_POINTS
Default distance between points to treat them as separate ones (mm) 0.001 mm or less is a reasonable ...
constexpr double IUTomm(int iu) const
Definition: base_units.h:86
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
wxLogTrace helper definitions.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:93
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
Definition of file extensions used in Kicad.