KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_kicad_sexpr.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) 2012 CERN
5 * Copyright (C) 1992-2024 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// base64 code. Needed for PCB_REFERENCE_IMAGE
26#define wxUSE_BASE64 1
27#include <wx/base64.h>
28#include <wx/dir.h>
29#include <wx/ffile.h>
30#include <wx/log.h>
31#include <wx/msgdlg.h>
32#include <wx/mstream.h>
33
34#include <board.h>
36#include <callback_gal.h>
37#include <confirm.h>
38#include <convert_basic_shapes_to_polygon.h> // for enum RECT_CHAMFER_POSITIONS definition
39#include <fmt/core.h>
40#include <font/fontconfig.h>
41#include <footprint.h>
43#include <kiface_base.h>
44#include <layer_range.h>
45#include <locale_io.h>
46#include <macros.h>
47#include <pad.h>
48#include <pcb_dimension.h>
49#include <pcb_generator.h>
50#include <pcb_group.h>
53#include <pcb_reference_image.h>
54#include <pcb_shape.h>
55#include <pcb_table.h>
56#include <pcb_tablecell.h>
57#include <pcb_target.h>
58#include <pcb_text.h>
59#include <pcb_textbox.h>
60#include <pcb_track.h>
61#include <pcbnew_settings.h>
62#include <pgm_base.h>
63#include <progress_reporter.h>
64#include <reporter.h>
65#include <string_utils.h>
66#include <trace_helpers.h>
68#include <zone.h>
69
70#include <build_version.h>
71#include <filter_reader.h>
72#include <ctl_flags.h>
73
74
75using namespace PCB_KEYS_T;
76
77
78FP_CACHE_ITEM::FP_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName ) :
79 m_filename( aFileName ),
80 m_footprint( aFootprint )
81{ }
82
83
84FP_CACHE::FP_CACHE( PCB_IO_KICAD_SEXPR* aOwner, const wxString& aLibraryPath )
85{
86 m_owner = aOwner;
87 m_lib_raw_path = aLibraryPath;
88 m_lib_path.SetPath( aLibraryPath );
90 m_cache_dirty = true;
91}
92
93
94void FP_CACHE::Save( FOOTPRINT* aFootprint )
95{
97
98 if( !m_lib_path.DirExists() && !m_lib_path.Mkdir() )
99 {
100 THROW_IO_ERROR( wxString::Format( _( "Cannot create footprint library '%s'." ),
101 m_lib_raw_path ) );
102 }
103
104 if( !m_lib_path.IsDirWritable() )
105 {
106 THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' is read only." ),
107 m_lib_raw_path ) );
108 }
109
110 for( FP_CACHE_FOOTPRINT_MAP::iterator it = m_footprints.begin(); it != m_footprints.end(); ++it )
111 {
112 if( aFootprint && aFootprint != it->second->GetFootprint() )
113 continue;
114
115 // If we've requested to embed the fonts in the footprint, do so.
116 // Otherwise, clear the embedded fonts from the footprint. Embedded
117 // fonts will be used if available
118 if( aFootprint->GetAreFontsEmbedded() )
119 aFootprint->EmbedFonts();
120 else
121 aFootprint->GetEmbeddedFiles()->ClearEmbeddedFonts();
122
123 WX_FILENAME fn = it->second->GetFileName();
124
125 wxString tempFileName =
126#ifdef USE_TMP_FILE
127 wxFileName::CreateTempFileName( fn.GetPath() );
128#else
129 fn.GetFullPath();
130#endif
131 // Allow file output stream to go out of scope to close the file stream before
132 // renaming the file.
133 {
134 wxLogTrace( traceKicadPcbPlugin, wxT( "Creating temporary library file '%s'." ),
135 tempFileName );
136
137 PRETTIFIED_FILE_OUTPUTFORMATTER formatter( tempFileName );
138
139 m_owner->SetOutputFormatter( &formatter );
140 m_owner->Format( (BOARD_ITEM*) it->second->GetFootprint() );
141 }
142
143#ifdef USE_TMP_FILE
144 wxRemove( fn.GetFullPath() ); // it is not an error if this does not exist
145
146 // Even on Linux you can see an _intermittent_ error when calling wxRename(),
147 // and it is fully inexplicable. See if this dodges the error.
148 wxMilliSleep( 250L );
149
150 // Preserve the permissions of the current file
152
153 if( !wxRenameFile( tempFileName, fn.GetFullPath() ) )
154 {
155 wxString msg = wxString::Format( _( "Cannot rename temporary file '%s' to '%s'" ),
156 tempFileName,
157 fn.GetFullPath() );
158 THROW_IO_ERROR( msg );
159 }
160#endif
162 }
163
164 m_cache_timestamp += m_lib_path.GetModificationTime().GetValue().GetValue();
165
166 // If we've saved the full cache, we clear the dirty flag.
167 if( !aFootprint )
168 m_cache_dirty = false;
169}
170
171
173{
174 m_cache_dirty = false;
176
177 wxDir dir( m_lib_raw_path );
178
179 if( !dir.IsOpened() )
180 {
181 wxString msg = wxString::Format( _( "Footprint library '%s' not found." ),
183 THROW_IO_ERROR( msg );
184 }
185
186 wxString fullName;
187 wxString fileSpec = wxT( "*." ) + wxString( FILEEXT::KiCadFootprintFileExtension );
188
189 // wxFileName construction is egregiously slow. Construct it once and just swap out
190 // the filename thereafter.
191 WX_FILENAME fn( m_lib_raw_path, wxT( "dummyName" ) );
192
193 if( dir.GetFirst( &fullName, fileSpec ) )
194 {
195 wxString cacheError;
196
197 do
198 {
199 fn.SetFullName( fullName );
200
201 // Queue I/O errors so only files that fail to parse don't get loaded.
202 try
203 {
204 FILE_LINE_READER reader( fn.GetFullPath() );
205 PCB_IO_KICAD_SEXPR_PARSER parser( &reader, nullptr, nullptr );
206
207 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( parser.Parse() );
208 wxString fpName = fn.GetName();
209
210 if( !footprint )
211 THROW_IO_ERROR( wxEmptyString ); // caught locally, just below...
212
213 footprint->SetFPID( LIB_ID( wxEmptyString, fpName ) );
214 m_footprints.insert( fpName, new FP_CACHE_ITEM( footprint, fn ) );
215 }
216 catch( const IO_ERROR& ioe )
217 {
218 if( !cacheError.IsEmpty() )
219 cacheError += wxT( "\n\n" );
220
221 cacheError += wxString::Format( _( "Unable to read file '%s'" ) + '\n',
222 fn.GetFullPath() );
223 cacheError += ioe.What();
224 }
225 } while( dir.GetNext( &fullName ) );
226
228
229 if( !cacheError.IsEmpty() )
230 THROW_IO_ERROR( cacheError );
231 }
232}
233
234
235void FP_CACHE::Remove( const wxString& aFootprintName )
236{
237 FP_CACHE_FOOTPRINT_MAP::const_iterator it = m_footprints.find( aFootprintName );
238
239 if( it == m_footprints.end() )
240 {
241 wxString msg = wxString::Format( _( "Library '%s' has no footprint '%s'." ),
243 aFootprintName );
244 THROW_IO_ERROR( msg );
245 }
246
247 // Remove the footprint from the cache and delete the footprint file from the library.
248 wxString fullPath = it->second->GetFileName().GetFullPath();
249 m_footprints.erase( aFootprintName );
250 wxRemoveFile( fullPath );
251}
252
253
254bool FP_CACHE::IsPath( const wxString& aPath ) const
255{
256 return aPath == m_lib_raw_path;
257}
258
259
260void FP_CACHE::SetPath( const wxString& aPath )
261{
262 m_lib_raw_path = aPath;
263 m_lib_path.SetPath( aPath );
264
265
266 for( const auto& footprint : GetFootprints() )
267 {
268 footprint.second->SetFilePath( aPath );
269 }
270}
271
272
274{
276
277 return m_cache_dirty;
278}
279
280
281long long FP_CACHE::GetTimestamp( const wxString& aLibPath )
282{
283 wxString fileSpec = wxT( "*." ) + wxString( FILEEXT::KiCadFootprintFileExtension );
284
285 return TimestampDir( aLibPath, fileSpec );
286}
287
288
289bool PCB_IO_KICAD_SEXPR::CanReadBoard( const wxString& aFileName ) const
290{
291 if( !PCB_IO::CanReadBoard( aFileName ) )
292 return false;
293
294 try
295 {
296 FILE_LINE_READER reader( aFileName );
297 PCB_IO_KICAD_SEXPR_PARSER parser( &reader, nullptr, m_queryUserCallback );
298
299 return parser.IsValidBoardHeader();
300 }
301 catch( const IO_ERROR& )
302 {
303 }
304
305 return false;
306}
307
308
309void PCB_IO_KICAD_SEXPR::SaveBoard( const wxString& aFileName, BOARD* aBoard,
310 const std::map<std::string, UTF8>* aProperties )
311{
312 LOCALE_IO toggle; // toggles on, then off, the C locale.
313
314 wxString sanityResult = aBoard->GroupsSanityCheck();
315
316 if( sanityResult != wxEmptyString && m_queryUserCallback )
317 {
319 _( "Internal Group Data Error" ), wxICON_ERROR,
320 wxString::Format( _( "Please report this bug. Error validating group "
321 "structure: %s\n\nSave anyway?" ), sanityResult ),
322 _( "Save Anyway" ) ) )
323 {
324 return;
325 }
326 }
327
328 init( aProperties );
329
330 m_board = aBoard; // after init()
331
332 // If the user wants fonts embedded, make sure that they are added to the board. Otherwise,
333 // remove any fonts that were previously embedded.
336 else
338
339 // Prepare net mapping that assures that net codes saved in a file are consecutive integers
340 m_mapping->SetBoard( aBoard );
341
342 PRETTIFIED_FILE_OUTPUTFORMATTER formatter( aFileName );
343
344 m_out = &formatter; // no ownership
345
346 m_out->Print( "(kicad_pcb (version %d) (generator \"pcbnew\") (generator_version %s)",
348 m_out->Quotew( GetMajorMinorVersion() ).c_str() );
349
350 Format( aBoard );
351
352 m_out->Print( ")" );
353 m_out->Finish();
354
355 m_out = nullptr;
356}
357
358
359BOARD_ITEM* PCB_IO_KICAD_SEXPR::Parse( const wxString& aClipboardSourceInput )
360{
361 std::string input = TO_UTF8( aClipboardSourceInput );
362
363 STRING_LINE_READER reader( input, wxT( "clipboard" ) );
364 PCB_IO_KICAD_SEXPR_PARSER parser( &reader, nullptr, m_queryUserCallback );
365
366 try
367 {
368 return parser.Parse();
369 }
370 catch( const PARSE_ERROR& parse_error )
371 {
372 if( parser.IsTooRecent() )
373 throw FUTURE_FORMAT_ERROR( parse_error, parser.GetRequiredVersion() );
374 else
375 throw;
376 }
377}
378
379
380void PCB_IO_KICAD_SEXPR::Format( const BOARD_ITEM* aItem ) const
381{
382 LOCALE_IO toggle; // public API function, perform anything convenient for caller
383
384 switch( aItem->Type() )
385 {
386 case PCB_T:
387 format( static_cast<const BOARD*>( aItem ) );
388 break;
389
391 case PCB_DIM_CENTER_T:
392 case PCB_DIM_RADIAL_T:
394 case PCB_DIM_LEADER_T:
395 format( static_cast<const PCB_DIMENSION_BASE*>( aItem ) );
396 break;
397
398 case PCB_SHAPE_T:
399 format( static_cast<const PCB_SHAPE*>( aItem ) );
400 break;
401
403 format( static_cast<const PCB_REFERENCE_IMAGE*>( aItem ) );
404 break;
405
406 case PCB_TARGET_T:
407 format( static_cast<const PCB_TARGET*>( aItem ) );
408 break;
409
410 case PCB_FOOTPRINT_T:
411 format( static_cast<const FOOTPRINT*>( aItem ) );
412 break;
413
414 case PCB_PAD_T:
415 format( static_cast<const PAD*>( aItem ) );
416 break;
417
418 case PCB_FIELD_T:
419 // Handled in the footprint formatter when properties are formatted
420 break;
421
422 case PCB_TEXT_T:
423 format( static_cast<const PCB_TEXT*>( aItem ) );
424 break;
425
426 case PCB_TEXTBOX_T:
427 format( static_cast<const PCB_TEXTBOX*>( aItem ) );
428 break;
429
430 case PCB_TABLE_T:
431 format( static_cast<const PCB_TABLE*>( aItem ) );
432 break;
433
434 case PCB_GROUP_T:
435 format( static_cast<const PCB_GROUP*>( aItem ) );
436 break;
437
438 case PCB_GENERATOR_T:
439 format( static_cast<const PCB_GENERATOR*>( aItem ) );
440 break;
441
442 case PCB_TRACE_T:
443 case PCB_ARC_T:
444 case PCB_VIA_T:
445 format( static_cast<const PCB_TRACK*>( aItem ) );
446 break;
447
448 case PCB_ZONE_T:
449 format( static_cast<const ZONE*>( aItem ) );
450 break;
451
452 default:
453 wxFAIL_MSG( wxT( "Cannot format item " ) + aItem->GetClass() );
454 }
455}
456
457
458std::string formatInternalUnits( int aValue )
459{
461}
462
463
464std::string formatInternalUnits( const VECTOR2I& aCoord )
465{
467}
468
469
470std::string formatInternalUnits( const VECTOR2I& aCoord, const FOOTPRINT* aParentFP )
471{
472 if( aParentFP )
473 {
474 VECTOR2I coord = aCoord - aParentFP->GetPosition();
475 RotatePoint( coord, -aParentFP->GetOrientation() );
476 return formatInternalUnits( coord );
477 }
478
479 return formatInternalUnits( aCoord );
480}
481
482
483void PCB_IO_KICAD_SEXPR::formatLayer( PCB_LAYER_ID aLayer, bool aIsKnockout ) const
484{
485 m_out->Print( "(layer %s %s)",
486 m_out->Quotew( LSET::Name( aLayer ) ).c_str(),
487 aIsKnockout ? "knockout" : "" );
488}
489
490
492 const FOOTPRINT* aParentFP ) const
493{
494 m_out->Print( "(pts" );
495
496 for( int ii = 0; ii < outline.PointCount(); ++ii )
497 {
498 int ind = outline.ArcIndex( ii );
499
500 if( ind < 0 )
501 {
502 m_out->Print( "(xy %s)",
503 formatInternalUnits( outline.CPoint( ii ), aParentFP ).c_str() );
504 }
505 else
506 {
507 const SHAPE_ARC& arc = outline.Arc( ind );
508 m_out->Print( "(arc (start %s) (mid %s) (end %s))",
509 formatInternalUnits( arc.GetP0(), aParentFP ).c_str(),
510 formatInternalUnits( arc.GetArcMid(), aParentFP ).c_str(),
511 formatInternalUnits( arc.GetP1(), aParentFP ).c_str() );
512
513 do
514 {
515 ++ii;
516 } while( ii < outline.PointCount() && outline.ArcIndex( ii ) == ind );
517
518 --ii;
519 }
520 }
521
522 m_out->Print( ")" );
523}
524
525
527{
528 wxString resolvedText( aText->GetShownText( true ) );
529 std::vector<std::unique_ptr<KIFONT::GLYPH>>* cache = aText->GetRenderCache( aText->GetFont(),
530 resolvedText );
531
532 m_out->Print( "(render_cache %s %s",
533 m_out->Quotew( resolvedText ).c_str(),
534 EDA_UNIT_UTILS::FormatAngle( aText->GetDrawRotation() ).c_str() );
535
537
538 CALLBACK_GAL callback_gal( empty_opts,
539 // Polygon callback
540 [&]( const SHAPE_LINE_CHAIN& aPoly )
541 {
542 m_out->Print( "(polygon" );
543 formatPolyPts( aPoly );
544 m_out->Print( ")" );
545 } );
546
547 callback_gal.SetLineWidth( aText->GetTextThickness() );
548 callback_gal.DrawGlyphs( *cache );
549
550 m_out->Print( ")" );
551}
552
553
554void PCB_IO_KICAD_SEXPR::formatSetup( const BOARD* aBoard ) const
555{
556 // Setup
557 m_out->Print( "(setup" );
558
559 // Save the board physical stackup structure
560 const BOARD_STACKUP& stackup = aBoard->GetDesignSettings().GetStackupDescriptor();
561
562 if( aBoard->GetDesignSettings().m_HasStackup )
563 stackup.FormatBoardStackup( m_out, aBoard );
564
565 BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
566
567 m_out->Print( "(pad_to_mask_clearance %s)",
568 formatInternalUnits( dsnSettings.m_SolderMaskExpansion ).c_str() );
569
570 if( dsnSettings.m_SolderMaskMinWidth )
571 {
572 m_out->Print( "(solder_mask_min_width %s)",
573 formatInternalUnits( dsnSettings.m_SolderMaskMinWidth ).c_str() );
574 }
575
576 if( dsnSettings.m_SolderPasteMargin != 0 )
577 {
578 m_out->Print( "(pad_to_paste_clearance %s)",
579 formatInternalUnits( dsnSettings.m_SolderPasteMargin ).c_str() );
580 }
581
582 if( dsnSettings.m_SolderPasteMarginRatio != 0 )
583 {
584 m_out->Print( "(pad_to_paste_clearance_ratio %s)",
585 FormatDouble2Str( dsnSettings.m_SolderPasteMarginRatio ).c_str() );
586 }
587
588 KICAD_FORMAT::FormatBool( m_out, "allow_soldermask_bridges_in_footprints",
589 dsnSettings.m_AllowSoldermaskBridgesInFPs );
590
591 if( dsnSettings.m_TentViasFront || dsnSettings.m_TentViasBack )
592 {
593 m_out->Print( "(tenting %s %s)",
594 dsnSettings.m_TentViasFront ? "front" : "",
595 dsnSettings.m_TentViasBack ? "back" : "" );
596 }
597 else
598 {
599 m_out->Print( "(tenting none)" );
600 }
601
602 VECTOR2I origin = dsnSettings.GetAuxOrigin();
603
604 if( origin != VECTOR2I( 0, 0 ) )
605 {
606 m_out->Print( "(aux_axis_origin %s %s)",
607 formatInternalUnits( origin.x ).c_str(),
608 formatInternalUnits( origin.y ).c_str() );
609 }
610
611 origin = dsnSettings.GetGridOrigin();
612
613 if( origin != VECTOR2I( 0, 0 ) )
614 {
615 m_out->Print( "(grid_origin %s %s)",
616 formatInternalUnits( origin.x ).c_str(),
617 formatInternalUnits( origin.y ).c_str() );
618 }
619
620 aBoard->GetPlotOptions().Format( m_out );
621
622 m_out->Print( ")" );
623}
624
625
626void PCB_IO_KICAD_SEXPR::formatGeneral( const BOARD* aBoard ) const
627{
628 const BOARD_DESIGN_SETTINGS& dsnSettings = aBoard->GetDesignSettings();
629
630 m_out->Print( "(general" );
631
632 m_out->Print( "(thickness %s)",
633 formatInternalUnits( dsnSettings.GetBoardThickness() ).c_str() );
634
635 KICAD_FORMAT::FormatBool( m_out, "legacy_teardrops", aBoard->LegacyTeardrops() );
636
637 m_out->Print( ")" );
638
639 aBoard->GetPageSettings().Format( m_out );
640 aBoard->GetTitleBlock().Format( m_out );
641}
642
643
645{
646 m_out->Print( "(layers" );
647
648 // Save only the used copper layers from front to back.
649
650 for( PCB_LAYER_ID layer : aBoard->GetEnabledLayers().CuStack() )
651 {
652 m_out->Print( "(%d %s %s %s)",
653 layer,
654 m_out->Quotew( LSET::Name( layer ) ).c_str(),
655 LAYER::ShowType( aBoard->GetLayerType( layer ) ),
656 LSET::Name( layer ) == m_board->GetLayerName( layer )
657 ? ""
658 : m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
659
660 }
661
662 // Save used non-copper layers in the order they are defined.
663 LSEQ seq = aBoard->GetEnabledLayers().TechAndUserUIOrder();
664
665 for( PCB_LAYER_ID layer : seq )
666 {
667 m_out->Print( "(%d %s %s %s)",
668 layer,
669 m_out->Quotew( LSET::Name( layer ) ).c_str(),
670 layer >= User_1 && layer <= User_9
671 ? LAYER::ShowType( aBoard->GetLayerType( layer ) )
672 : "user",
673 m_board->GetLayerName( layer ) == LSET::Name( layer )
674 ? ""
675 : m_out->Quotew( m_board->GetLayerName( layer ) ).c_str() );
676 }
677
678 m_out->Print( ")" );
679}
680
681
683{
684 for( NETINFO_ITEM* net : *m_mapping )
685 {
686 if( net == nullptr ) // Skip not actually existing nets (orphan nets)
687 continue;
688
689 m_out->Print( "(net %d %s)",
690 m_mapping->Translate( net->GetNetCode() ),
691 m_out->Quotew( net->GetNetname() ).c_str() );
692 }
693}
694
695
697{
698 for( const std::pair<const wxString, wxString>& prop : aBoard->GetProperties() )
699 {
700 m_out->Print( "(property %s %s)",
701 m_out->Quotew( prop.first ).c_str(),
702 m_out->Quotew( prop.second ).c_str() );
703 }
704}
705
706
707void PCB_IO_KICAD_SEXPR::formatHeader( const BOARD* aBoard ) const
708{
709 formatGeneral( aBoard );
710
711 // Layers list.
712 formatBoardLayers( aBoard );
713
714 // Setup
715 formatSetup( aBoard );
716
717 // Properties
718 formatProperties( aBoard );
719
720 // Save net codes and names
721 formatNetInformation( aBoard );
722}
723
724
726{
727 static const TEARDROP_PARAMETERS defaults;
728
729 return tdParams.m_Enabled == defaults.m_Enabled
730 && tdParams.m_BestLengthRatio == defaults.m_BestLengthRatio
731 && tdParams.m_TdMaxLen == defaults.m_TdMaxLen
732 && tdParams.m_BestWidthRatio == defaults.m_BestWidthRatio
733 && tdParams.m_TdMaxWidth == defaults.m_TdMaxWidth
734 && tdParams.m_CurveSegCount == defaults.m_CurveSegCount
736 && tdParams.m_AllowUseTwoTracks == defaults.m_AllowUseTwoTracks
737 && tdParams.m_TdOnPadsInZones == defaults.m_TdOnPadsInZones;
738}
739
740
742{
743 m_out->Print( "(teardrops (best_length_ratio %s) (max_length %s) (best_width_ratio %s) "
744 "(max_width %s) (curve_points %d) (filter_ratio %s)",
745 FormatDouble2Str( tdParams.m_BestLengthRatio ).c_str(),
746 formatInternalUnits( tdParams.m_TdMaxLen ).c_str(),
747 FormatDouble2Str( tdParams.m_BestWidthRatio ).c_str(),
748 formatInternalUnits( tdParams.m_TdMaxWidth ).c_str(),
749 tdParams.m_CurveSegCount,
750 FormatDouble2Str( tdParams.m_WidthtoSizeFilterRatio ).c_str() );
751
752 KICAD_FORMAT::FormatBool( m_out, "enabled", tdParams.m_Enabled );
753 KICAD_FORMAT::FormatBool( m_out, "allow_two_segments", tdParams.m_AllowUseTwoTracks );
754 KICAD_FORMAT::FormatBool( m_out, "prefer_zone_connections", !tdParams.m_TdOnPadsInZones );
755 m_out->Print( ")" );
756}
757
758
759void PCB_IO_KICAD_SEXPR::format( const BOARD* aBoard ) const
760{
761 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_footprints( aBoard->Footprints().begin(),
762 aBoard->Footprints().end() );
763 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_drawings( aBoard->Drawings().begin(),
764 aBoard->Drawings().end() );
765 std::set<PCB_TRACK*, PCB_TRACK::cmp_tracks> sorted_tracks( aBoard->Tracks().begin(),
766 aBoard->Tracks().end() );
767 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aBoard->Zones().begin(),
768 aBoard->Zones().end() );
769 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_groups( aBoard->Groups().begin(),
770 aBoard->Groups().end() );
771 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_generators( aBoard->Generators().begin(),
772 aBoard->Generators().end() );
773 formatHeader( aBoard );
774
775 // Save the footprints.
776 for( BOARD_ITEM* footprint : sorted_footprints )
777 Format( footprint );
778
779 // Save the graphical items on the board (not owned by a footprint)
780 for( BOARD_ITEM* item : sorted_drawings )
781 Format( item );
782
783 // Do not save PCB_MARKERs, they can be regenerated easily.
784
785 // Save the tracks and vias.
786 for( PCB_TRACK* track : sorted_tracks )
787 Format( track );
788
789 // Save the polygon (which are the newer technology) zones.
790 for( auto zone : sorted_zones )
791 Format( zone );
792
793 // Save the groups
794 for( BOARD_ITEM* group : sorted_groups )
795 Format( group );
796
797 // Save the generators
798 for( BOARD_ITEM* gen : sorted_generators )
799 Format( gen );
800
801 // Save any embedded files
802 // Consolidate the embedded models in footprints into a single map
803 // to avoid duplicating the same model in the board file.
804 EMBEDDED_FILES files_to_write;
805
806 for( auto& file : aBoard->GetEmbeddedFiles()->EmbeddedFileMap() )
807 files_to_write.AddFile( file.second );
808
809 for( BOARD_ITEM* item : sorted_footprints )
810 {
811 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
812
813 for( auto& file : fp->GetEmbeddedFiles()->EmbeddedFileMap() )
814 files_to_write.AddFile( file.second );
815 }
816
817 m_out->Print( "(embedded_fonts %s)",
818 aBoard->GetEmbeddedFiles()->GetAreFontsEmbedded() ? "yes" : "no" );
819
820 if( !files_to_write.IsEmpty() )
821 files_to_write.WriteEmbeddedFiles( *m_out, ( m_ctl & CTL_FOR_BOARD ) );
822
823 // Remove the files so that they are not freed in the DTOR
824 files_to_write.ClearEmbeddedFiles( false );
825}
826
827
828void PCB_IO_KICAD_SEXPR::format( const PCB_DIMENSION_BASE* aDimension ) const
829{
830 const PCB_DIM_ALIGNED* aligned = dynamic_cast<const PCB_DIM_ALIGNED*>( aDimension );
831 const PCB_DIM_ORTHOGONAL* ortho = dynamic_cast<const PCB_DIM_ORTHOGONAL*>( aDimension );
832 const PCB_DIM_CENTER* center = dynamic_cast<const PCB_DIM_CENTER*>( aDimension );
833 const PCB_DIM_RADIAL* radial = dynamic_cast<const PCB_DIM_RADIAL*>( aDimension );
834 const PCB_DIM_LEADER* leader = dynamic_cast<const PCB_DIM_LEADER*>( aDimension );
835
836 m_out->Print( "(dimension" );
837
838 if( ortho ) // must be tested before aligned, because ortho is derived from aligned
839 // and aligned is not null
840 m_out->Print( "(type orthogonal)" );
841 else if( aligned )
842 m_out->Print( "(type aligned)" );
843 else if( leader )
844 m_out->Print( "(type leader)" );
845 else if( center )
846 m_out->Print( "(type center)" );
847 else if( radial )
848 m_out->Print( "(type radial)" );
849 else
850 wxFAIL_MSG( wxT( "Cannot format unknown dimension type!" ) );
851
852 if( aDimension->IsLocked() )
853 KICAD_FORMAT::FormatBool( m_out, "locked", aDimension->IsLocked() );
854
855 formatLayer( aDimension->GetLayer() );
856
857 KICAD_FORMAT::FormatUuid( m_out, aDimension->m_Uuid );
858
859 m_out->Print( "(pts (xy %s %s) (xy %s %s))",
860 formatInternalUnits( aDimension->GetStart().x ).c_str(),
861 formatInternalUnits( aDimension->GetStart().y ).c_str(),
862 formatInternalUnits( aDimension->GetEnd().x ).c_str(),
863 formatInternalUnits( aDimension->GetEnd().y ).c_str() );
864
865 if( aligned )
866 m_out->Print( "(height %s)", formatInternalUnits( aligned->GetHeight() ).c_str() );
867
868 if( radial )
869 {
870 m_out->Print( "(leader_length %s)",
871 formatInternalUnits( radial->GetLeaderLength() ).c_str() );
872 }
873
874 if( ortho )
875 m_out->Print( "(orientation %d)", static_cast<int>( ortho->GetOrientation() ) );
876
877 if( !center )
878 {
879 m_out->Print( "(format (prefix %s) (suffix %s) (units %d) (units_format %d) (precision %d)",
880 m_out->Quotew( aDimension->GetPrefix() ).c_str(),
881 m_out->Quotew( aDimension->GetSuffix() ).c_str(),
882 static_cast<int>( aDimension->GetUnitsMode() ),
883 static_cast<int>( aDimension->GetUnitsFormat() ),
884 static_cast<int>( aDimension->GetPrecision() ) );
885
886 if( aDimension->GetOverrideTextEnabled() )
887 {
888 m_out->Print( "(override_value %s)",
889 m_out->Quotew( aDimension->GetOverrideText() ).c_str() );
890 }
891
892 if( aDimension->GetSuppressZeroes() )
893 KICAD_FORMAT::FormatBool( m_out, "suppress_zeroes", true );
894
895 m_out->Print( ")" );
896 }
897
898 m_out->Print( "(style (thickness %s) (arrow_length %s) (text_position_mode %d)",
899 formatInternalUnits( aDimension->GetLineThickness() ).c_str(),
900 formatInternalUnits( aDimension->GetArrowLength() ).c_str(),
901 static_cast<int>( aDimension->GetTextPositionMode() ) );
902
903 if( ortho || aligned )
904 {
905 switch( aDimension->GetArrowDirection() )
906 {
907 case DIM_ARROW_DIRECTION::OUTWARD:
908 m_out->Print( "(arrow_direction outward)" );
909 break;
910 case DIM_ARROW_DIRECTION::INWARD:
911 m_out->Print( "(arrow_direction inward)" );
912 break;
913 // No default, handle all cases
914 }
915 }
916
917 if( aligned )
918 {
919 m_out->Print( "(extension_height %s)",
920 formatInternalUnits( aligned->GetExtensionHeight() ).c_str() );
921 }
922
923 if( leader )
924 m_out->Print( "(text_frame %d)", static_cast<int>( leader->GetTextBorder() ) );
925
926 m_out->Print( "(extension_offset %s)",
927 formatInternalUnits( aDimension->GetExtensionOffset() ).c_str() );
928
929 if( aDimension->GetKeepTextAligned() )
930 KICAD_FORMAT::FormatBool( m_out, "keep_text_aligned", true );
931
932 m_out->Print( ")" );
933
934 // Write dimension text after all other options to be sure the
935 // text options are known when reading the file
936 if( !center )
937 format( static_cast<const PCB_TEXT*>( aDimension ) );
938
939 m_out->Print( ")" );
940}
941
942
943void PCB_IO_KICAD_SEXPR::format( const PCB_SHAPE* aShape ) const
944{
945 FOOTPRINT* parentFP = aShape->GetParentFootprint();
946 std::string prefix = parentFP ? "fp" : "gr";
947
948 switch( aShape->GetShape() )
949 {
950 case SHAPE_T::SEGMENT:
951 m_out->Print( "(%s_line (start %s) (end %s)",
952 prefix.c_str(),
953 formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
954 formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
955 break;
956
957 case SHAPE_T::RECTANGLE:
958 m_out->Print( "(%s_rect (start %s) (end %s)",
959 prefix.c_str(),
960 formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
961 formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
962 break;
963
964 case SHAPE_T::CIRCLE:
965 m_out->Print( "(%s_circle (center %s) (end %s)",
966 prefix.c_str(),
967 formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
968 formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
969 break;
970
971 case SHAPE_T::ARC:
972 m_out->Print( "(%s_arc (start %s) (mid %s) (end %s)",
973 prefix.c_str(),
974 formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
975 formatInternalUnits( aShape->GetArcMid(), parentFP ).c_str(),
976 formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
977 break;
978
979 case SHAPE_T::POLY:
980 if( aShape->IsPolyShapeValid() )
981 {
982 const SHAPE_POLY_SET& poly = aShape->GetPolyShape();
983 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
984
985 m_out->Print( "(%s_poly", prefix.c_str() );
986 formatPolyPts( outline, parentFP );
987 }
988 else
989 {
990 wxFAIL_MSG( wxT( "Cannot format invalid polygon." ) );
991 return;
992 }
993
994 break;
995
996 case SHAPE_T::BEZIER:
997 m_out->Print( "(%s_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
998 prefix.c_str(),
999 formatInternalUnits( aShape->GetStart(), parentFP ).c_str(),
1000 formatInternalUnits( aShape->GetBezierC1(), parentFP ).c_str(),
1001 formatInternalUnits( aShape->GetBezierC2(), parentFP ).c_str(),
1002 formatInternalUnits( aShape->GetEnd(), parentFP ).c_str() );
1003 break;
1004
1005 default:
1007 return;
1008 };
1009
1010 aShape->GetStroke().Format( m_out, pcbIUScale );
1011
1012 // The filled flag represents if a solid fill is present on circles, rectangles and polygons
1013 if( ( aShape->GetShape() == SHAPE_T::POLY )
1014 || ( aShape->GetShape() == SHAPE_T::RECTANGLE )
1015 || ( aShape->GetShape() == SHAPE_T::CIRCLE ) )
1016 {
1017 KICAD_FORMAT::FormatBool( m_out, "fill", aShape->IsFilled() );
1018 }
1019
1020 if( aShape->IsLocked() )
1021 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1022
1023 if( aShape->GetLayerSet().count() > 1 )
1024 formatLayers( aShape->GetLayerSet() );
1025 else
1026 formatLayer( aShape->GetLayer() );
1027
1028 if( aShape->HasSolderMask()
1029 && aShape->GetLocalSolderMaskMargin().has_value()
1030 && IsExternalCopperLayer( aShape->GetLayer() ) )
1031 {
1032 m_out->Print( "(solder_mask_margin %s)",
1033 formatInternalUnits( aShape->GetLocalSolderMaskMargin().value() ).c_str() );
1034 }
1035
1036 if( aShape->GetNetCode() > 0 )
1037 m_out->Print( "(net %d)", m_mapping->Translate( aShape->GetNetCode() ) );
1038
1040 m_out->Print( ")" );
1041}
1042
1043
1045{
1046 wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
1047
1048 const REFERENCE_IMAGE& refImage = aBitmap->GetReferenceImage();
1049
1050 const wxImage* image = refImage.GetImage().GetImageData();
1051
1052 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
1053
1054 m_out->Print( "(image (at %s %s)",
1055 formatInternalUnits( aBitmap->GetPosition().x ).c_str(),
1056 formatInternalUnits( aBitmap->GetPosition().y ).c_str() );
1057
1058 formatLayer( aBitmap->GetLayer() );
1059
1060 if( refImage.GetImageScale() != 1.0 )
1061 m_out->Print( "(scale %g)", refImage.GetImageScale() );
1062
1063 if( aBitmap->IsLocked() )
1064 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1065
1066 m_out->Print( "(data" );
1067
1068 wxString out = wxBase64Encode( refImage.GetImage().GetImageDataBuffer() );
1069
1070 // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
1071 // so use it in a vain attempt to be standard like.
1072#define MIME_BASE64_LENGTH 76
1073
1074 size_t first = 0;
1075
1076 while( first < out.Length() )
1077 {
1078 m_out->Print( "\n\"%s\"", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
1079 first += MIME_BASE64_LENGTH;
1080 }
1081
1082 m_out->Print( ")" ); // Closes data token.
1083
1085 m_out->Print( ")" ); // Closes image token.
1086}
1087
1088
1089void PCB_IO_KICAD_SEXPR::format( const PCB_TARGET* aTarget ) const
1090{
1091 m_out->Print( "(target %s (at %s) (size %s)",
1092 ( aTarget->GetShape() ) ? "x" : "plus",
1093 formatInternalUnits( aTarget->GetPosition() ).c_str(),
1094 formatInternalUnits( aTarget->GetSize() ).c_str() );
1095
1096 if( aTarget->GetWidth() != 0 )
1097 m_out->Print( "(width %s)", formatInternalUnits( aTarget->GetWidth() ).c_str() );
1098
1099 formatLayer( aTarget->GetLayer() );
1101 m_out->Print( ")" );
1102}
1103
1104
1105void PCB_IO_KICAD_SEXPR::format( const FOOTPRINT* aFootprint ) const
1106{
1107 if( !( m_ctl & CTL_OMIT_INITIAL_COMMENTS ) )
1108 {
1109 const wxArrayString* initial_comments = aFootprint->GetInitialComments();
1110
1111 if( initial_comments )
1112 {
1113 for( unsigned i = 0; i < initial_comments->GetCount(); ++i )
1114 m_out->Print( "%s\n", TO_UTF8( (*initial_comments)[i] ) );
1115 }
1116 }
1117
1118 if( m_ctl & CTL_OMIT_LIBNAME )
1119 {
1120 m_out->Print( "(footprint %s",
1121 m_out->Quotes( aFootprint->GetFPID().GetLibItemName() ).c_str() );
1122 }
1123 else
1124 {
1125 m_out->Print( "(footprint %s",
1126 m_out->Quotes( aFootprint->GetFPID().Format() ).c_str() );
1127 }
1128
1130 {
1131 m_out->Print( "(version %d) (generator \"pcbnew\") (generator_version %s)",
1133 m_out->Quotew( GetMajorMinorVersion() ).c_str() );
1134 }
1135
1136 if( aFootprint->IsLocked() )
1137 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1138
1139 if( aFootprint->IsPlaced() )
1140 KICAD_FORMAT::FormatBool( m_out, "placed", true );
1141
1142 formatLayer( aFootprint->GetLayer() );
1143
1144 if( !( m_ctl & CTL_OMIT_UUIDS ) )
1145 KICAD_FORMAT::FormatUuid( m_out, aFootprint->m_Uuid );
1146
1147 if( !( m_ctl & CTL_OMIT_AT ) )
1148 {
1149 m_out->Print( "(at %s %s)",
1150 formatInternalUnits( aFootprint->GetPosition() ).c_str(),
1151 aFootprint->GetOrientation().IsZero()
1152 ? ""
1153 : EDA_UNIT_UTILS::FormatAngle( aFootprint->GetOrientation() ).c_str() );
1154 }
1155
1156 if( !aFootprint->GetLibDescription().IsEmpty() )
1157 m_out->Print( "(descr %s)", m_out->Quotew( aFootprint->GetLibDescription() ).c_str() );
1158
1159 if( !aFootprint->GetKeywords().IsEmpty() )
1160 m_out->Print( "(tags %s)", m_out->Quotew( aFootprint->GetKeywords() ).c_str() );
1161
1162 for( const PCB_FIELD* field : aFootprint->GetFields() )
1163 {
1164 m_out->Print( "(property %s %s",
1165 m_out->Quotew( field->GetCanonicalName() ).c_str(),
1166 m_out->Quotew( field->GetText() ).c_str() );
1167
1168 format( field );
1169
1170 m_out->Print( ")" );
1171 }
1172
1173 if( const COMPONENT_CLASS* compClass = aFootprint->GetComponentClass() )
1174 {
1175 if( !compClass->IsEmpty() )
1176 {
1177 m_out->Print( "(component_classes" );
1178
1179 for( const COMPONENT_CLASS* constituent : compClass->GetConstituentClasses() )
1180 m_out->Print( "(class %s)", m_out->Quotew( constituent->GetFullName() ).c_str() );
1181
1182 m_out->Print( ")" );
1183 }
1184 }
1185
1186 if( !aFootprint->GetFilters().empty() )
1187 {
1188 m_out->Print( "(property ki_fp_filters %s)",
1189 m_out->Quotew( aFootprint->GetFilters() ).c_str() );
1190 }
1191
1192 if( !( m_ctl & CTL_OMIT_PATH ) && !aFootprint->GetPath().empty() )
1193 m_out->Print( "(path %s)", m_out->Quotew( aFootprint->GetPath().AsString() ).c_str() );
1194
1195 if( !aFootprint->GetSheetname().empty() )
1196 m_out->Print( "(sheetname %s)", m_out->Quotew( aFootprint->GetSheetname() ).c_str() );
1197
1198 if( !aFootprint->GetSheetfile().empty() )
1199 m_out->Print( "(sheetfile %s)", m_out->Quotew( aFootprint->GetSheetfile() ).c_str() );
1200
1201 if( aFootprint->GetLocalSolderMaskMargin().has_value() )
1202 {
1203 m_out->Print( "(solder_mask_margin %s)",
1204 formatInternalUnits( aFootprint->GetLocalSolderMaskMargin().value() ).c_str() );
1205 }
1206
1207 if( aFootprint->GetLocalSolderPasteMargin().has_value() )
1208 {
1209 m_out->Print( "(solder_paste_margin %s)",
1210 formatInternalUnits( aFootprint->GetLocalSolderPasteMargin().value() ).c_str() );
1211 }
1212
1213 if( aFootprint->GetLocalSolderPasteMarginRatio().has_value() )
1214 {
1215 m_out->Print( "(solder_paste_margin_ratio %s)",
1216 FormatDouble2Str( aFootprint->GetLocalSolderPasteMarginRatio().value() ).c_str() );
1217 }
1218
1219 if( aFootprint->GetLocalClearance().has_value() )
1220 {
1221 m_out->Print( "(clearance %s)",
1222 formatInternalUnits( aFootprint->GetLocalClearance().value() ).c_str() );
1223 }
1224
1225 if( aFootprint->GetLocalZoneConnection() != ZONE_CONNECTION::INHERITED )
1226 {
1227 m_out->Print( "(zone_connect %d)",
1228 static_cast<int>( aFootprint->GetLocalZoneConnection() ) );
1229 }
1230
1231 // Attributes
1232 if( aFootprint->GetAttributes() )
1233 {
1234 m_out->Print( "(attr" );
1235
1236 if( aFootprint->GetAttributes() & FP_SMD )
1237 m_out->Print( " smd" );
1238
1239 if( aFootprint->GetAttributes() & FP_THROUGH_HOLE )
1240 m_out->Print( " through_hole" );
1241
1242 if( aFootprint->GetAttributes() & FP_BOARD_ONLY )
1243 m_out->Print( " board_only" );
1244
1245 if( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_POS_FILES )
1246 m_out->Print( " exclude_from_pos_files" );
1247
1248 if( aFootprint->GetAttributes() & FP_EXCLUDE_FROM_BOM )
1249 m_out->Print( " exclude_from_bom" );
1250
1251 if( aFootprint->GetAttributes() & FP_ALLOW_MISSING_COURTYARD )
1252 m_out->Print( " allow_missing_courtyard" );
1253
1254 if( aFootprint->GetAttributes() & FP_DNP )
1255 m_out->Print( " dnp" );
1256
1257 if( aFootprint->GetAttributes() & FP_ALLOW_SOLDERMASK_BRIDGES )
1258 m_out->Print( " allow_soldermask_bridges" );
1259
1260 m_out->Print( ")" );
1261 }
1262
1263 if( aFootprint->GetPrivateLayers().any() )
1264 {
1265 m_out->Print( "(private_layers" );
1266
1267 for( PCB_LAYER_ID layer : aFootprint->GetPrivateLayers().Seq() )
1268 {
1269 wxString canonicalName( LSET::Name( layer ) );
1270 m_out->Print( " %s", m_out->Quotew( canonicalName ).c_str() );
1271 }
1272
1273 m_out->Print( ")" );
1274 }
1275
1276 if( aFootprint->IsNetTie() )
1277 {
1278 m_out->Print( "(net_tie_pad_groups" );
1279
1280 for( const wxString& group : aFootprint->GetNetTiePadGroups() )
1281 m_out->Print( " %s", m_out->Quotew( group ).c_str() );
1282
1283 m_out->Print( ")" );
1284 }
1285
1286 Format( (BOARD_ITEM*) &aFootprint->Reference() );
1287 Format( (BOARD_ITEM*) &aFootprint->Value() );
1288
1289 std::set<PAD*, FOOTPRINT::cmp_pads> sorted_pads( aFootprint->Pads().begin(),
1290 aFootprint->Pads().end() );
1291 std::set<BOARD_ITEM*, FOOTPRINT::cmp_drawings> sorted_drawings(
1292 aFootprint->GraphicalItems().begin(),
1293 aFootprint->GraphicalItems().end() );
1294 std::set<ZONE*, FOOTPRINT::cmp_zones> sorted_zones( aFootprint->Zones().begin(),
1295 aFootprint->Zones().end() );
1296 std::set<BOARD_ITEM*, PCB_GROUP::ptr_cmp> sorted_groups( aFootprint->Groups().begin(),
1297 aFootprint->Groups().end() );
1298
1299 // Save drawing elements.
1300
1301 for( BOARD_ITEM* gr : sorted_drawings )
1302 Format( gr );
1303
1304 // Save pads.
1305 for( PAD* pad : sorted_pads )
1306 Format( pad );
1307
1308 // Save zones.
1309 for( BOARD_ITEM* zone : sorted_zones )
1310 Format( zone );
1311
1312 // Save groups.
1313 for( BOARD_ITEM* group : sorted_groups )
1314 Format( group );
1315
1316 KICAD_FORMAT::FormatBool( m_out, "embedded_fonts",
1317 aFootprint->GetEmbeddedFiles()->GetAreFontsEmbedded() );
1318
1319 if( !aFootprint->GetEmbeddedFiles()->IsEmpty() )
1320 aFootprint->WriteEmbeddedFiles( *m_out, !( m_ctl & CTL_FOR_BOARD ) );
1321
1322 // Save 3D info.
1323 auto bs3D = aFootprint->Models().begin();
1324 auto es3D = aFootprint->Models().end();
1325
1326 while( bs3D != es3D )
1327 {
1328 if( !bs3D->m_Filename.IsEmpty() )
1329 {
1330 m_out->Print( "(model %s", m_out->Quotew( bs3D->m_Filename ).c_str() );
1331
1332 if( !bs3D->m_Show )
1333 KICAD_FORMAT::FormatBool( m_out, "hide", !bs3D->m_Show );
1334
1335 if( bs3D->m_Opacity != 1.0 )
1336 m_out->Print( "(opacity %0.4f)", bs3D->m_Opacity );
1337
1338 m_out->Print( "(offset (xyz %s %s %s))",
1339 FormatDouble2Str( bs3D->m_Offset.x ).c_str(),
1340 FormatDouble2Str( bs3D->m_Offset.y ).c_str(),
1341 FormatDouble2Str( bs3D->m_Offset.z ).c_str() );
1342
1343 m_out->Print( "(scale (xyz %s %s %s))",
1344 FormatDouble2Str( bs3D->m_Scale.x ).c_str(),
1345 FormatDouble2Str( bs3D->m_Scale.y ).c_str(),
1346 FormatDouble2Str( bs3D->m_Scale.z ).c_str() );
1347
1348 m_out->Print( "(rotate (xyz %s %s %s))",
1349 FormatDouble2Str( bs3D->m_Rotation.x ).c_str(),
1350 FormatDouble2Str( bs3D->m_Rotation.y ).c_str(),
1351 FormatDouble2Str( bs3D->m_Rotation.z ).c_str() );
1352
1353 m_out->Print( ")" );
1354 }
1355
1356 ++bs3D;
1357 }
1358
1359 m_out->Print( ")" );
1360}
1361
1362
1364{
1365 static const LSET cu_all( LSET::AllCuMask() );
1366 static const LSET fr_bk( { B_Cu, F_Cu } );
1367 static const LSET adhes( { B_Adhes, F_Adhes } );
1368 static const LSET paste( { B_Paste, F_Paste } );
1369 static const LSET silks( { B_SilkS, F_SilkS } );
1370 static const LSET mask( { B_Mask, F_Mask } );
1371 static const LSET crt_yd( { B_CrtYd, F_CrtYd } );
1372 static const LSET fab( { B_Fab, F_Fab } );
1373
1374 LSET cu_mask = cu_all;
1375
1376 std::string output;
1377
1378 // output copper layers first, then non copper
1379
1380 if( ( aLayerMask & cu_mask ) == cu_mask )
1381 {
1382 output += ' ' + m_out->Quotew( "*.Cu" );
1383 aLayerMask &= ~cu_all; // clear bits, so they are not output again below
1384 }
1385 else if( ( aLayerMask & cu_mask ) == fr_bk )
1386 {
1387 output += ' ' + m_out->Quotew( "F&B.Cu" );
1388 aLayerMask &= ~fr_bk;
1389 }
1390
1391 if( ( aLayerMask & adhes ) == adhes )
1392 {
1393 output += ' ' + m_out->Quotew( "*.Adhes" );
1394 aLayerMask &= ~adhes;
1395 }
1396
1397 if( ( aLayerMask & paste ) == paste )
1398 {
1399 output += ' ' + m_out->Quotew( "*.Paste" );
1400 aLayerMask &= ~paste;
1401 }
1402
1403 if( ( aLayerMask & silks ) == silks )
1404 {
1405 output += ' ' + m_out->Quotew( "*.SilkS" );
1406 aLayerMask &= ~silks;
1407 }
1408
1409 if( ( aLayerMask & mask ) == mask )
1410 {
1411 output += ' ' + m_out->Quotew( "*.Mask" );
1412 aLayerMask &= ~mask;
1413 }
1414
1415 if( ( aLayerMask & crt_yd ) == crt_yd )
1416 {
1417 output += ' ' + m_out->Quotew( "*.CrtYd" );
1418 aLayerMask &= ~crt_yd;
1419 }
1420
1421 if( ( aLayerMask & fab ) == fab )
1422 {
1423 output += ' ' + m_out->Quotew( "*.Fab" );
1424 aLayerMask &= ~fab;
1425 }
1426
1427 // output any individual layers not handled in wildcard combos above
1428 wxString layerName;
1429
1430 for( int layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
1431 {
1432 if( aLayerMask[layer] )
1433 output += ' ' + m_out->Quotew( LSET::Name( PCB_LAYER_ID( layer ) ) );
1434 }
1435
1436 m_out->Print( "(layers %s)", output.c_str() );
1437}
1438
1439
1440void PCB_IO_KICAD_SEXPR::format( const PAD* aPad ) const
1441{
1442 const BOARD* board = aPad->GetBoard();
1443
1444 auto shapeName =
1445 [&]( PCB_LAYER_ID aLayer )
1446 {
1447 switch( aPad->GetShape( aLayer ) )
1448 {
1449 case PAD_SHAPE::CIRCLE: return "circle";
1450 case PAD_SHAPE::RECTANGLE: return "rect";
1451 case PAD_SHAPE::OVAL: return "oval";
1452 case PAD_SHAPE::TRAPEZOID: return "trapezoid";
1453 case PAD_SHAPE::CHAMFERED_RECT:
1454 case PAD_SHAPE::ROUNDRECT: return "roundrect";
1455 case PAD_SHAPE::CUSTOM: return "custom";
1456
1457 default:
1458 THROW_IO_ERROR( wxString::Format( _( "unknown pad type: %d"),
1459 aPad->GetShape( aLayer ) ) );
1460 }
1461 };
1462
1463 const char* type;
1464
1465 switch( aPad->GetAttribute() )
1466 {
1467 case PAD_ATTRIB::PTH: type = "thru_hole"; break;
1468 case PAD_ATTRIB::SMD: type = "smd"; break;
1469 case PAD_ATTRIB::CONN: type = "connect"; break;
1470 case PAD_ATTRIB::NPTH: type = "np_thru_hole"; break;
1471
1472 default:
1473 THROW_IO_ERROR( wxString::Format( wxT( "unknown pad attribute: %d" ),
1474 aPad->GetAttribute() ) );
1475 }
1476
1477 const char* property = nullptr;
1478
1479 switch( aPad->GetProperty() )
1480 {
1481 case PAD_PROP::NONE: break; // could be "none"
1482 case PAD_PROP::BGA: property = "pad_prop_bga"; break;
1483 case PAD_PROP::FIDUCIAL_GLBL: property = "pad_prop_fiducial_glob"; break;
1484 case PAD_PROP::FIDUCIAL_LOCAL: property = "pad_prop_fiducial_loc"; break;
1485 case PAD_PROP::TESTPOINT: property = "pad_prop_testpoint"; break;
1486 case PAD_PROP::HEATSINK: property = "pad_prop_heatsink"; break;
1487 case PAD_PROP::CASTELLATED: property = "pad_prop_castellated"; break;
1488 case PAD_PROP::MECHANICAL: property = "pad_prop_mechanical"; break;
1489
1490 default:
1491 THROW_IO_ERROR( wxString::Format( wxT( "unknown pad property: %d" ),
1492 aPad->GetProperty() ) );
1493 }
1494
1495 m_out->Print( "(pad %s %s %s",
1496 m_out->Quotew( aPad->GetNumber() ).c_str(),
1497 type,
1498 shapeName( PADSTACK::ALL_LAYERS ) );
1499
1500 m_out->Print( "(at %s %s)",
1501 formatInternalUnits( aPad->GetFPRelativePosition() ).c_str(),
1502 aPad->GetOrientation().IsZero()
1503 ? ""
1504 : EDA_UNIT_UTILS::FormatAngle( aPad->GetOrientation() ).c_str() );
1505
1506 m_out->Print( "(size %s)", formatInternalUnits( aPad->GetSize( PADSTACK::ALL_LAYERS ) ).c_str() );
1507
1508 if( aPad->GetDelta( PADSTACK::ALL_LAYERS ).x != 0
1509 || aPad->GetDelta( PADSTACK::ALL_LAYERS ).y != 0 )
1510 {
1511 m_out->Print( "(rect_delta %s)",
1513 }
1514
1515 VECTOR2I sz = aPad->GetDrillSize();
1516 VECTOR2I shapeoffset = aPad->GetOffset( PADSTACK::ALL_LAYERS );
1517
1518 if( (sz.x > 0) || (sz.y > 0) ||
1519 (shapeoffset.x != 0) || (shapeoffset.y != 0) )
1520 {
1521 m_out->Print( "(drill" );
1522
1523 if( aPad->GetDrillShape() == PAD_DRILL_SHAPE::OBLONG )
1524 m_out->Print( " oval" );
1525
1526 if( sz.x > 0 )
1527 m_out->Print( " %s", formatInternalUnits( sz.x ).c_str() );
1528
1529 if( sz.y > 0 && sz.x != sz.y )
1530 m_out->Print( " %s", formatInternalUnits( sz.y ).c_str() );
1531
1532 // NOTE: Shape offest is a property of the copper shape, not of the drill, but this was put
1533 // in the file format under the drill section. So, it is left here to minimize file format
1534 // changes, but note that the other padstack layers (if present) will have an offset stored
1535 // separately.
1536 if( shapeoffset.x != 0 || shapeoffset.y != 0 )
1537 {
1538 m_out->Print( "(offset %s)",
1540 }
1541
1542 m_out->Print( ")" );
1543 }
1544
1545 // Add pad property, if exists.
1546 if( property )
1547 m_out->Print( "(property %s)", property );
1548
1549 formatLayers( aPad->GetLayerSet() );
1550
1551 if( aPad->GetAttribute() == PAD_ATTRIB::PTH )
1552 {
1553 KICAD_FORMAT::FormatBool( m_out, "remove_unused_layers", aPad->GetRemoveUnconnected() );
1554
1555 if( aPad->GetRemoveUnconnected() )
1556 {
1557 KICAD_FORMAT::FormatBool( m_out, "keep_end_layers", aPad->GetKeepTopBottom() );
1558
1559 if( board ) // Will be nullptr in footprint library
1560 {
1561 m_out->Print( "(zone_layer_connections" );
1562
1563 for( PCB_LAYER_ID layer : board->GetEnabledLayers().CuStack() )
1564 {
1565 if( aPad->GetZoneLayerOverride( layer ) == ZLO_FORCE_FLASHED )
1566 m_out->Print( " %s", m_out->Quotew( LSET::Name( layer ) ).c_str() );
1567 }
1568
1569 m_out->Print( ")" );
1570 }
1571 }
1572 }
1573
1574 auto formatCornerProperties =
1575 [&]( PCB_LAYER_ID aLayer )
1576 {
1577 // Output the radius ratio for rounded and chamfered rect pads
1578 if( aPad->GetShape( aLayer ) == PAD_SHAPE::ROUNDRECT
1579 || aPad->GetShape( aLayer ) == PAD_SHAPE::CHAMFERED_RECT)
1580 {
1581 m_out->Print( "(roundrect_rratio %s)",
1582 FormatDouble2Str( aPad->GetRoundRectRadiusRatio( aLayer ) ).c_str() );
1583 }
1584
1585 // Output the chamfer corners for chamfered rect pads
1586 if( aPad->GetShape( aLayer ) == PAD_SHAPE::CHAMFERED_RECT)
1587 {
1588 m_out->Print( "(chamfer_ratio %s)",
1589 FormatDouble2Str( aPad->GetChamferRectRatio( aLayer ) ).c_str() );
1590
1591 m_out->Print( "(chamfer" );
1592
1593 if( ( aPad->GetChamferPositions( aLayer ) & RECT_CHAMFER_TOP_LEFT ) )
1594 m_out->Print( " top_left" );
1595
1596 if( ( aPad->GetChamferPositions( aLayer ) & RECT_CHAMFER_TOP_RIGHT ) )
1597 m_out->Print( " top_right" );
1598
1599 if( ( aPad->GetChamferPositions( aLayer ) & RECT_CHAMFER_BOTTOM_LEFT ) )
1600 m_out->Print( " bottom_left" );
1601
1602 if( ( aPad->GetChamferPositions( aLayer ) & RECT_CHAMFER_BOTTOM_RIGHT ) )
1603 m_out->Print( " bottom_right" );
1604
1605 m_out->Print( ")" );
1606 }
1607
1608 };
1609
1610 // For normal padstacks, this is the one and only set of properties. For complex ones, this
1611 // will represent the front layer properties, and other layers will be formatted below
1612 formatCornerProperties( PADSTACK::ALL_LAYERS );
1613
1614 // Unconnected pad is default net so don't save it.
1616 {
1617 m_out->Print( "(net %d %s)", m_mapping->Translate( aPad->GetNetCode() ),
1618 m_out->Quotew( aPad->GetNetname() ).c_str() );
1619 }
1620
1621 // Pin functions and types are closely related to nets, so if CTL_OMIT_NETS is set, omit
1622 // them as well (for instance when saved from library editor).
1623 if( !( m_ctl & CTL_OMIT_PAD_NETS ) )
1624 {
1625 if( !aPad->GetPinFunction().IsEmpty() )
1626 m_out->Print( "(pinfunction %s)", m_out->Quotew( aPad->GetPinFunction() ).c_str() );
1627
1628 if( !aPad->GetPinType().IsEmpty() )
1629 m_out->Print( "(pintype %s)", m_out->Quotew( aPad->GetPinType() ).c_str() );
1630 }
1631
1632 if( aPad->GetPadToDieLength() != 0 )
1633 {
1634 m_out->Print( "(die_length %s)",
1635 formatInternalUnits( aPad->GetPadToDieLength() ).c_str() );
1636 }
1637
1638 if( aPad->GetLocalSolderMaskMargin().has_value() )
1639 {
1640 m_out->Print( "(solder_mask_margin %s)",
1641 formatInternalUnits( aPad->GetLocalSolderMaskMargin().value() ).c_str() );
1642 }
1643
1644 if( aPad->GetLocalSolderPasteMargin().has_value() )
1645 {
1646 m_out->Print( "(solder_paste_margin %s)",
1647 formatInternalUnits( aPad->GetLocalSolderPasteMargin().value() ).c_str() );
1648 }
1649
1650 if( aPad->GetLocalSolderPasteMarginRatio().has_value() )
1651 {
1652 m_out->Print( "(solder_paste_margin_ratio %s)",
1653 FormatDouble2Str( aPad->GetLocalSolderPasteMarginRatio().value() ).c_str() );
1654 }
1655
1656 if( aPad->GetLocalClearance().has_value() )
1657 {
1658 m_out->Print( "(clearance %s)",
1659 formatInternalUnits( aPad->GetLocalClearance().value() ).c_str() );
1660 }
1661
1662 if( aPad->GetLocalZoneConnection() != ZONE_CONNECTION::INHERITED )
1663 {
1664 m_out->Print( "(zone_connect %d)",
1665 static_cast<int>( aPad->GetLocalZoneConnection() ) );
1666 }
1667
1668 if( aPad->GetThermalSpokeWidth() != 0 )
1669 {
1670 m_out->Print( "(thermal_bridge_width %s)",
1671 formatInternalUnits( aPad->GetThermalSpokeWidth() ).c_str() );
1672 }
1673
1674 EDA_ANGLE defaultThermalSpokeAngle = ANGLE_90;
1675
1676 if( aPad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::CIRCLE ||
1677 ( aPad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::CUSTOM
1678 && aPad->GetAnchorPadShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::CIRCLE ) )
1679 {
1680 defaultThermalSpokeAngle = ANGLE_45;
1681 }
1682
1683 if( aPad->GetThermalSpokeAngle() != defaultThermalSpokeAngle )
1684 {
1685 m_out->Print( "(thermal_bridge_angle %s)",
1687 }
1688
1689 if( aPad->GetThermalGap() != 0 )
1690 {
1691 m_out->Print( "(thermal_gap %s)",
1692 formatInternalUnits( aPad->GetThermalGap() ).c_str() );
1693 }
1694
1695 auto anchorShape =
1696 [&]( PCB_LAYER_ID aLayer )
1697 {
1698 switch( aPad->GetAnchorPadShape( aLayer ) )
1699 {
1700 case PAD_SHAPE::RECTANGLE: return "rect";
1701 default:
1702 case PAD_SHAPE::CIRCLE: return "circle";
1703 }
1704 };
1705
1706 auto formatPrimitives =
1707 [&]( PCB_LAYER_ID aLayer )
1708 {
1709 m_out->Print( "(primitives" );
1710
1711 // Output all basic shapes
1712 for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives( aLayer ) )
1713 {
1714 switch( primitive->GetShape() )
1715 {
1716 case SHAPE_T::SEGMENT:
1717 if( primitive->IsProxyItem() )
1718 {
1719 m_out->Print( "(gr_vector (start %s) (end %s)",
1720 formatInternalUnits( primitive->GetStart() ).c_str(),
1721 formatInternalUnits( primitive->GetEnd() ).c_str() );
1722 }
1723 else
1724 {
1725 m_out->Print( "(gr_line (start %s) (end %s)",
1726 formatInternalUnits( primitive->GetStart() ).c_str(),
1727 formatInternalUnits( primitive->GetEnd() ).c_str() );
1728 }
1729 break;
1730
1731 case SHAPE_T::RECTANGLE:
1732 if( primitive->IsProxyItem() )
1733 {
1734 m_out->Print( "(gr_bbox (start %s) (end %s)",
1735 formatInternalUnits( primitive->GetStart() ).c_str(),
1736 formatInternalUnits( primitive->GetEnd() ).c_str() );
1737 }
1738 else
1739 {
1740 m_out->Print( "(gr_rect (start %s) (end %s)",
1741 formatInternalUnits( primitive->GetStart() ).c_str(),
1742 formatInternalUnits( primitive->GetEnd() ).c_str() );
1743 }
1744 break;
1745
1746 case SHAPE_T::ARC:
1747 m_out->Print( "(gr_arc (start %s) (mid %s) (end %s)",
1748 formatInternalUnits( primitive->GetStart() ).c_str(),
1749 formatInternalUnits( primitive->GetArcMid() ).c_str(),
1750 formatInternalUnits( primitive->GetEnd() ).c_str() );
1751 break;
1752
1753 case SHAPE_T::CIRCLE:
1754 m_out->Print( "(gr_circle (center %s) (end %s)",
1755 formatInternalUnits( primitive->GetStart() ).c_str(),
1756 formatInternalUnits( primitive->GetEnd() ).c_str() );
1757 break;
1758
1759 case SHAPE_T::BEZIER:
1760 m_out->Print( "(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
1761 formatInternalUnits( primitive->GetStart() ).c_str(),
1762 formatInternalUnits( primitive->GetBezierC1() ).c_str(),
1763 formatInternalUnits( primitive->GetBezierC2() ).c_str(),
1764 formatInternalUnits( primitive->GetEnd() ).c_str() );
1765 break;
1766
1767 case SHAPE_T::POLY:
1768 if( primitive->IsPolyShapeValid() )
1769 {
1770 const SHAPE_POLY_SET& poly = primitive->GetPolyShape();
1771 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
1772
1773 m_out->Print( "(gr_poly" );
1774 formatPolyPts( outline );
1775 }
1776 break;
1777
1778 default:
1779 break;
1780 }
1781
1782 if( !primitive->IsProxyItem() )
1783 m_out->Print( "(width %s)", formatInternalUnits( primitive->GetWidth() ).c_str() );
1784
1785 // The filled flag represents if a solid fill is present on circles,
1786 // rectangles and polygons
1787 if( ( primitive->GetShape() == SHAPE_T::POLY )
1788 || ( primitive->GetShape() == SHAPE_T::RECTANGLE )
1789 || ( primitive->GetShape() == SHAPE_T::CIRCLE ) )
1790 {
1791 KICAD_FORMAT::FormatBool( m_out, "fill", primitive->IsFilled() );
1792 }
1793
1794 m_out->Print( ")" );
1795 }
1796
1797 m_out->Print( ")" ); // end of (primitives
1798 };
1799
1800 if( aPad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::CUSTOM )
1801 {
1802 m_out->Print( "(options" );
1803
1805 m_out->Print( "(clearance convexhull)" );
1806 else
1807 m_out->Print( "(clearance outline)" );
1808
1809 // Output the anchor pad shape (circle/rect)
1810 m_out->Print( "(anchor %s)", anchorShape( PADSTACK::ALL_LAYERS ) );
1811
1812 m_out->Print( ")"); // end of (options ...
1813
1814 // Output graphic primitive of the pad shape
1815 formatPrimitives( PADSTACK::ALL_LAYERS );
1816 }
1817
1820
1821 formatTenting( aPad->Padstack() );
1822
1824
1825 // TODO: Refactor so that we call formatPadLayer( ALL_LAYERS ) above instead of redundant code
1826 auto formatPadLayer =
1827 [&]( PCB_LAYER_ID aLayer )
1828 {
1829 const PADSTACK& padstack = aPad->Padstack();
1830
1831 m_out->Print( "(shape %s)", shapeName( aLayer ) );
1832 m_out->Print( "(size %s)", formatInternalUnits( aPad->GetSize( aLayer ) ).c_str() );
1833
1834 const VECTOR2I& delta = aPad->GetDelta( aLayer );
1835
1836 if( delta.x != 0 || delta.y != 0 )
1837 m_out->Print( "(rect_delta %s)", formatInternalUnits( delta ).c_str() );
1838
1839 shapeoffset = aPad->GetOffset( aLayer );
1840
1841 if( shapeoffset.x != 0 || shapeoffset.y != 0 )
1842 m_out->Print( "(offset %s)", formatInternalUnits( shapeoffset ).c_str() );
1843
1844 formatCornerProperties( aLayer );
1845
1846 if( aPad->GetShape( aLayer ) == PAD_SHAPE::CUSTOM )
1847 {
1848 m_out->Print( "(options" );
1849
1850 // Output the anchor pad shape (circle/rect)
1851 m_out->Print( "(anchor %s)", anchorShape( aLayer ) );
1852
1853 m_out->Print( ")" ); // end of (options ...
1854
1855 // Output graphic primitive of the pad shape
1856 formatPrimitives( aLayer );
1857 }
1858
1859 EDA_ANGLE defaultLayerAngle = ANGLE_90;
1860
1861 if( aPad->GetShape( aLayer ) == PAD_SHAPE::CIRCLE ||
1862 ( aPad->GetShape( aLayer ) == PAD_SHAPE::CUSTOM
1863 && aPad->GetAnchorPadShape( aLayer ) == PAD_SHAPE::CIRCLE ) )
1864 {
1865 defaultLayerAngle = ANGLE_45;
1866 }
1867
1868 EDA_ANGLE layerSpokeAngle = padstack.ThermalSpokeAngle( aLayer );
1869
1870 if( layerSpokeAngle != defaultLayerAngle )
1871 {
1872 m_out->Print( "(thermal_bridge_angle %s)",
1873 EDA_UNIT_UTILS::FormatAngle( layerSpokeAngle ).c_str() );
1874 }
1875
1876 if( padstack.ThermalGap( aLayer ).has_value() )
1877 {
1878 m_out->Print( "(thermal_gap %s)",
1879 formatInternalUnits( *padstack.ThermalGap( aLayer ) ).c_str() );
1880 }
1881
1882 if( padstack.ThermalSpokeWidth( aLayer ).has_value() )
1883 {
1884 m_out->Print( "(thermal_bridge_width %s)",
1885 formatInternalUnits( *padstack.ThermalSpokeWidth( aLayer ) ).c_str() );
1886 }
1887
1888 if( padstack.Clearance( aLayer ).has_value() )
1889 {
1890 m_out->Print( "(clearance %s)",
1891 formatInternalUnits( *padstack.Clearance( aLayer ) ).c_str() );
1892 }
1893
1894 if( padstack.ZoneConnection( aLayer ).has_value() )
1895 {
1896 m_out->Print( "(zone_connect %d)",
1897 static_cast<int>( *padstack.ZoneConnection( aLayer ) ) );
1898 }
1899 };
1900
1901
1902 if( aPad->Padstack().Mode() != PADSTACK::MODE::NORMAL )
1903 {
1905 {
1906 m_out->Print( "(padstack (mode front_inner_back)" );
1907
1908 m_out->Print( "(layer \"Inner\"" );
1909 formatPadLayer( PADSTACK::INNER_LAYERS );
1910 m_out->Print( ")" );
1911 m_out->Print( "(layer \"B.Cu\"" );
1912 formatPadLayer( B_Cu );
1913 m_out->Print( ")" );
1914 }
1915 else
1916 {
1917 m_out->Print( "(padstack (mode custom)" );
1918
1919 int layerCount = board ? board->GetCopperLayerCount() : MAX_CU_LAYERS;
1920
1921 for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, layerCount ) )
1922 {
1923 if( layer == F_Cu )
1924 continue;
1925
1926 m_out->Print( "(layer %s", m_out->Quotew( LSET::Name( layer ) ).c_str() );
1927 formatPadLayer( layer );
1928 m_out->Print( ")" );
1929 }
1930 }
1931
1932 m_out->Print( ")" );
1933 }
1934
1935 m_out->Print( ")" );
1936}
1937
1938
1939void PCB_IO_KICAD_SEXPR::formatTenting( const PADSTACK& aPadstack ) const
1940{
1941 std::optional<bool> front = aPadstack.FrontOuterLayers().has_solder_mask;
1942 std::optional<bool> back = aPadstack.BackOuterLayers().has_solder_mask;
1943
1944 if( front.has_value() || back.has_value() )
1945 {
1946 if( front.value_or( false ) || back.value_or( false ) )
1947 {
1948 m_out->Print( "(tenting %s %s)",
1949 front.value_or( false ) ? "front" : "",
1950 back.value_or( false ) ? "back" : "" );
1951 }
1952 else
1953 {
1954 m_out->Print( "(tenting none)" );
1955 }
1956 }
1957}
1958
1959
1960void PCB_IO_KICAD_SEXPR::format( const PCB_TEXT* aText ) const
1961{
1962 FOOTPRINT* parentFP = aText->GetParentFootprint();
1963 std::string prefix;
1964 std::string type;
1965 VECTOR2I pos = aText->GetTextPos();
1966 bool isField = dynamic_cast<const PCB_FIELD*>( aText ) != nullptr;
1967
1968 // Always format dimension text as gr_text
1969 if( dynamic_cast<const PCB_DIMENSION_BASE*>( aText ) )
1970 parentFP = nullptr;
1971
1972 if( parentFP )
1973 {
1974 prefix = "fp";
1975 type = "user";
1976
1977 pos -= parentFP->GetPosition();
1978 RotatePoint( pos, -parentFP->GetOrientation() );
1979 }
1980 else
1981 {
1982 prefix = "gr";
1983 }
1984
1985 if( !isField )
1986 {
1987 m_out->Print( "(%s_text %s %s",
1988 prefix.c_str(),
1989 type.c_str(),
1990 m_out->Quotew( aText->GetText() ).c_str() );
1991
1992 if( aText->IsLocked() )
1993 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1994 }
1995
1996 m_out->Print( "(at %s %s)",
1997 formatInternalUnits( pos ).c_str(),
1998 EDA_UNIT_UTILS::FormatAngle( aText->GetTextAngle() ).c_str() );
1999
2000 if( parentFP && !aText->IsKeepUpright() )
2001 KICAD_FORMAT::FormatBool( m_out, "unlocked", true );
2002
2003 formatLayer( aText->GetLayer(), aText->IsKnockout() );
2004
2005 if( parentFP && !aText->IsVisible() )
2006 KICAD_FORMAT::FormatBool( m_out, "hide", true );
2007
2009
2010 int ctl_flags = m_ctl | CTL_OMIT_HIDE;
2011
2012 // Currently, texts have no specific color and no hyperlink.
2013 // so ensure they are never written in kicad_pcb file
2014 ctl_flags |= CTL_OMIT_COLOR | CTL_OMIT_HYPERLINK;
2015
2016 aText->EDA_TEXT::Format( m_out, ctl_flags );
2017
2018 if( aText->GetFont() && aText->GetFont()->IsOutline() )
2019 formatRenderCache( aText );
2020
2021 if( !isField )
2022 m_out->Print( ")" );
2023}
2024
2025
2026void PCB_IO_KICAD_SEXPR::format( const PCB_TEXTBOX* aTextBox ) const
2027{
2028 FOOTPRINT* parentFP = aTextBox->GetParentFootprint();
2029
2030 m_out->Print( "(%s %s",
2031 aTextBox->Type() == PCB_TABLECELL_T ? "table_cell"
2032 : parentFP ? "fp_text_box"
2033 : "gr_text_box",
2034 m_out->Quotew( aTextBox->GetText() ).c_str() );
2035
2036 if( aTextBox->IsLocked() )
2037 KICAD_FORMAT::FormatBool( m_out, "locked", true );
2038
2039 if( aTextBox->GetShape() == SHAPE_T::RECTANGLE )
2040 {
2041 m_out->Print( "(start %s) (end %s)",
2042 formatInternalUnits( aTextBox->GetStart(), parentFP ).c_str(),
2043 formatInternalUnits( aTextBox->GetEnd(), parentFP ).c_str() );
2044 }
2045 else if( aTextBox->GetShape() == SHAPE_T::POLY )
2046 {
2047 const SHAPE_POLY_SET& poly = aTextBox->GetPolyShape();
2048 const SHAPE_LINE_CHAIN& outline = poly.Outline( 0 );
2049
2050 formatPolyPts( outline, parentFP );
2051 }
2052 else
2053 {
2054 UNIMPLEMENTED_FOR( aTextBox->SHAPE_T_asString() );
2055 }
2056
2057 m_out->Print( "(margins %s %s %s %s)",
2058 formatInternalUnits( aTextBox->GetMarginLeft() ).c_str(),
2059 formatInternalUnits( aTextBox->GetMarginTop() ).c_str(),
2060 formatInternalUnits( aTextBox->GetMarginRight() ).c_str(),
2061 formatInternalUnits( aTextBox->GetMarginBottom() ).c_str() );
2062
2063 if( const PCB_TABLECELL* cell = dynamic_cast<const PCB_TABLECELL*>( aTextBox ) )
2064 m_out->Print( "(span %d %d)", cell->GetColSpan(), cell->GetRowSpan() );
2065
2066 EDA_ANGLE angle = aTextBox->GetTextAngle();
2067
2068 if( parentFP )
2069 {
2070 angle -= parentFP->GetOrientation();
2071 angle.Normalize720();
2072 }
2073
2074 if( !angle.IsZero() )
2075 m_out->Print( "(angle %s)", EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
2076
2077 formatLayer( aTextBox->GetLayer() );
2078
2080
2081 // PCB_TEXTBOXes are never hidden, so always omit "hide" attribute
2082 aTextBox->EDA_TEXT::Format( m_out, m_ctl | CTL_OMIT_HIDE );
2083
2084 if( aTextBox->Type() != PCB_TABLECELL_T )
2085 {
2086 KICAD_FORMAT::FormatBool( m_out, "border", aTextBox->IsBorderEnabled() );
2087 aTextBox->GetStroke().Format( m_out, pcbIUScale );
2088 }
2089
2090 if( aTextBox->GetFont() && aTextBox->GetFont()->IsOutline() )
2091 formatRenderCache( aTextBox );
2092
2093 m_out->Print( ")" );
2094}
2095
2096
2097void PCB_IO_KICAD_SEXPR::format( const PCB_TABLE* aTable ) const
2098{
2099 wxCHECK_RET( aTable != nullptr && m_out != nullptr, "" );
2100
2101 m_out->Print( "(table (column_count %d)", aTable->GetColCount() );
2102
2103 if( aTable->IsLocked() )
2104 KICAD_FORMAT::FormatBool( m_out, "locked", true );
2105
2106 formatLayer( aTable->GetLayer() );
2107
2108 m_out->Print( "(border" );
2109 KICAD_FORMAT::FormatBool( m_out, "external", aTable->StrokeExternal() );
2110 KICAD_FORMAT::FormatBool( m_out, "header", aTable->StrokeHeader() );
2111
2112 if( aTable->StrokeExternal() || aTable->StrokeHeader() )
2113 aTable->GetBorderStroke().Format( m_out, pcbIUScale );
2114
2115 m_out->Print( ")" ); // Close `border` token.
2116
2117 m_out->Print( "(separators" );
2118 KICAD_FORMAT::FormatBool( m_out, "rows", aTable->StrokeRows() );
2119 KICAD_FORMAT::FormatBool( m_out, "cols", aTable->StrokeColumns() );
2120
2121 if( aTable->StrokeRows() || aTable->StrokeColumns() )
2123
2124 m_out->Print( ")" ); // Close `separators` token.
2125
2126 m_out->Print( "(column_widths" );
2127
2128 for( int col = 0; col < aTable->GetColCount(); ++col )
2129 m_out->Print( " %s", formatInternalUnits( aTable->GetColWidth( col ) ).c_str() );
2130
2131 m_out->Print( ")" );
2132
2133 m_out->Print( "(row_heights" );
2134
2135 for( int row = 0; row < aTable->GetRowCount(); ++row )
2136 m_out->Print( " %s", formatInternalUnits( aTable->GetRowHeight( row ) ).c_str() );
2137
2138 m_out->Print( ")" );
2139
2140 m_out->Print( "(cells" );
2141
2142 for( PCB_TABLECELL* cell : aTable->GetCells() )
2143 format( static_cast<PCB_TEXTBOX*>( cell ) );
2144
2145 m_out->Print( ")" ); // Close `cells` token.
2146 m_out->Print( ")" ); // Close `table` token.
2147}
2148
2149
2150void PCB_IO_KICAD_SEXPR::format( const PCB_GROUP* aGroup ) const
2151{
2152 // Don't write empty groups
2153 if( aGroup->GetItems().empty() )
2154 return;
2155
2156 m_out->Print( "(group %s", m_out->Quotew( aGroup->GetName() ).c_str() );
2157
2159
2160 if( aGroup->IsLocked() )
2161 KICAD_FORMAT::FormatBool( m_out, "locked", true );
2162
2163 wxArrayString memberIds;
2164
2165 for( BOARD_ITEM* member : aGroup->GetItems() )
2166 memberIds.Add( member->m_Uuid.AsString() );
2167
2168 memberIds.Sort();
2169
2170 m_out->Print( "(members" );
2171
2172 for( const wxString& memberId : memberIds )
2173 m_out->Print( " %s", m_out->Quotew( memberId ).c_str() );
2174
2175 m_out->Print( ")" ); // Close `members` token.
2176 m_out->Print( ")" ); // Close `group` token.
2177}
2178
2179
2180void PCB_IO_KICAD_SEXPR::format( const PCB_GENERATOR* aGenerator ) const
2181{
2182 m_out->Print( "(generated" );
2183
2184 KICAD_FORMAT::FormatUuid( m_out, aGenerator->m_Uuid );
2185
2186 m_out->Print( "(type %s) (name %s) (layer %s)",
2187 TO_UTF8( aGenerator->GetGeneratorType() ),
2188 m_out->Quotew( aGenerator->GetName() ).c_str(),
2189 m_out->Quotew( LSET::Name( aGenerator->GetLayer() ) ).c_str() );
2190
2191 if( aGenerator->IsLocked() )
2192 KICAD_FORMAT::FormatBool( m_out, "locked", true );
2193
2194 for( const auto& [key, value] : aGenerator->GetProperties() )
2195 {
2196 if( value.CheckType<double>() || value.CheckType<int>() || value.CheckType<long>()
2197 || value.CheckType<long long>() )
2198 {
2199 double val;
2200
2201 if( !value.GetAs( &val ) )
2202 continue;
2203
2204 std::string buf = fmt::format( "{:.10g}", val );
2205
2206 // Don't quote numbers
2207 m_out->Print( "(%s %s)", key.c_str(), buf.c_str() );
2208 }
2209 else if( value.CheckType<bool>() )
2210 {
2211 bool val;
2212 value.GetAs( &val );
2213
2214 KICAD_FORMAT::FormatBool( m_out, key, val );
2215 }
2216 else if( value.CheckType<VECTOR2I>() )
2217 {
2218 VECTOR2I val;
2219 value.GetAs( &val );
2220
2221 m_out->Print( "(%s (xy %s))",
2222 key.c_str(),
2223 formatInternalUnits( val ).c_str() );
2224 }
2225 else if( value.CheckType<SHAPE_LINE_CHAIN>() )
2226 {
2227 SHAPE_LINE_CHAIN val;
2228 value.GetAs( &val );
2229
2230 m_out->Print( "(%s ", key.c_str() );
2231 formatPolyPts( val );
2232 m_out->Print( ")" );
2233 }
2234 else
2235 {
2236 wxString val;
2237
2238 if( value.CheckType<wxString>() )
2239 {
2240 value.GetAs( &val );
2241 }
2242 else if( value.CheckType<std::string>() )
2243 {
2244 std::string str;
2245 value.GetAs( &str );
2246
2247 val = wxString::FromUTF8( str );
2248 }
2249
2250 m_out->Print( "(%s %s)", key.c_str(), m_out->Quotew( val ).c_str() );
2251 }
2252 }
2253
2254 wxArrayString memberIds;
2255
2256 for( BOARD_ITEM* member : aGenerator->GetItems() )
2257 memberIds.Add( member->m_Uuid.AsString() );
2258
2259 memberIds.Sort();
2260
2261 m_out->Print( "(members" );
2262
2263 for( const wxString& memberId : memberIds )
2264 m_out->Print( " %s", m_out->Quotew( memberId ).c_str() );
2265
2266 m_out->Print( ")" ); // Close `members` token.
2267 m_out->Print( ")" ); // Close `generated` token.
2268}
2269
2270
2271void PCB_IO_KICAD_SEXPR::format( const PCB_TRACK* aTrack ) const
2272{
2273 if( aTrack->Type() == PCB_VIA_T )
2274 {
2275 PCB_LAYER_ID layer1, layer2;
2276
2277 const PCB_VIA* via = static_cast<const PCB_VIA*>( aTrack );
2278 const BOARD* board = via->GetBoard();
2279
2280 wxCHECK_RET( board != nullptr, wxT( "Via has no parent." ) );
2281
2282 m_out->Print( "(via" );
2283
2284 via->LayerPair( &layer1, &layer2 );
2285
2286 switch( via->GetViaType() )
2287 {
2288 case VIATYPE::THROUGH: // Default shape not saved.
2289 break;
2290
2291 case VIATYPE::BLIND_BURIED:
2292 m_out->Print( " blind " );
2293 break;
2294
2295 case VIATYPE::MICROVIA:
2296 m_out->Print( " micro " );
2297 break;
2298
2299 default:
2300 THROW_IO_ERROR( wxString::Format( _( "unknown via type %d" ), via->GetViaType() ) );
2301 }
2302
2303 m_out->Print( "(at %s) (size %s)",
2304 formatInternalUnits( aTrack->GetStart() ).c_str(),
2305 formatInternalUnits( via->GetWidth( F_Cu ) ).c_str() );
2306
2307 // Old boards were using UNDEFINED_DRILL_DIAMETER value in file for via drill when
2308 // via drill was the netclass value.
2309 // recent boards always set the via drill to the actual value, but now we need to
2310 // always store the drill value, because netclass value is not stored in the board file.
2311 // Otherwise the drill value of some (old) vias can be unknown
2312 if( via->GetDrill() != UNDEFINED_DRILL_DIAMETER )
2313 m_out->Print( "(drill %s)", formatInternalUnits( via->GetDrill() ).c_str() );
2314 else
2315 m_out->Print( "(drill %s)", formatInternalUnits( via->GetDrillValue() ).c_str() );
2316
2317 m_out->Print( "(layers %s %s)",
2318 m_out->Quotew( LSET::Name( layer1 ) ).c_str(),
2319 m_out->Quotew( LSET::Name( layer2 ) ).c_str() );
2320
2321 switch( via->Padstack().UnconnectedLayerMode() )
2322 {
2324 KICAD_FORMAT::FormatBool( m_out, "remove_unused_layers", true );
2325 KICAD_FORMAT::FormatBool( m_out, "keep_end_layers", false );
2326 break;
2327
2329 KICAD_FORMAT::FormatBool( m_out, "remove_unused_layers", true );
2330 KICAD_FORMAT::FormatBool( m_out, "keep_end_layers", true );
2331 break;
2332
2334 break;
2335 }
2336
2337 if( via->IsLocked() )
2338 KICAD_FORMAT::FormatBool( m_out, "locked", true );
2339
2340 if( via->GetIsFree() )
2341 KICAD_FORMAT::FormatBool( m_out, "free", true );
2342
2343 if( via->GetRemoveUnconnected() )
2344 {
2345 m_out->Print( "(zone_layer_connections" );
2346
2347 for( PCB_LAYER_ID layer : board->GetEnabledLayers().CuStack() )
2348 {
2349 if( via->GetZoneLayerOverride( layer ) == ZLO_FORCE_FLASHED )
2350 m_out->Print( " %s", m_out->Quotew( LSET::Name( layer ) ).c_str() );
2351 }
2352
2353 m_out->Print( ")" );
2354 }
2355
2356 const PADSTACK& padstack = via->Padstack();
2357
2358 formatTenting( padstack );
2359
2360 if( padstack.Mode() != PADSTACK::MODE::NORMAL )
2361 {
2362 m_out->Print( "(padstack" );
2363
2364 if( padstack.Mode() == PADSTACK::MODE::FRONT_INNER_BACK )
2365 {
2366 m_out->Print( "(mode front_inner_back)" );
2367
2368 m_out->Print( "(layer \"Inner\"" );
2369 m_out->Print( "(size %s)",
2370 formatInternalUnits( padstack.Size( PADSTACK::INNER_LAYERS ).x ).c_str() );
2371 m_out->Print( ")" );
2372 m_out->Print( "(layer \"B.Cu\"" );
2373 m_out->Print( "(size %s)",
2374 formatInternalUnits( padstack.Size( B_Cu ).x ).c_str() );
2375 m_out->Print( ")" );
2376 }
2377 else
2378 {
2379 m_out->Print( "(mode custom)" );
2380
2381 for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, board->GetCopperLayerCount() ) )
2382 {
2383 if( layer == F_Cu )
2384 continue;
2385
2386 m_out->Print( "(layer %s", m_out->Quotew( LSET::Name( layer ) ).c_str() );
2387 m_out->Print( "(size %s)",
2388 formatInternalUnits( padstack.Size( layer ).x ).c_str() );
2389 m_out->Print( ")" );
2390 }
2391 }
2392
2393 m_out->Print( ")" );
2394 }
2395
2396 if( !isDefaultTeardropParameters( via->GetTeardropParams() ) )
2397 formatTeardropParameters( via->GetTeardropParams() );
2398 }
2399 else
2400 {
2401 if( aTrack->Type() == PCB_ARC_T )
2402 {
2403 const PCB_ARC* arc = static_cast<const PCB_ARC*>( aTrack );
2404
2405 m_out->Print( "(arc (start %s) (mid %s) (end %s) (width %s)",
2406 formatInternalUnits( arc->GetStart() ).c_str(),
2407 formatInternalUnits( arc->GetMid() ).c_str(),
2408 formatInternalUnits( arc->GetEnd() ).c_str(),
2409 formatInternalUnits( arc->GetWidth() ).c_str() );
2410 }
2411 else
2412 {
2413 m_out->Print( "(segment (start %s) (end %s) (width %s)",
2414 formatInternalUnits( aTrack->GetStart() ).c_str(),
2415 formatInternalUnits( aTrack->GetEnd() ).c_str(),
2416 formatInternalUnits( aTrack->GetWidth() ).c_str() );
2417 }
2418
2419 if( aTrack->IsLocked() )
2420 KICAD_FORMAT::FormatBool( m_out, "locked", true );
2421
2422 if( aTrack->GetLayerSet().count() > 1 )
2423 formatLayers( aTrack->GetLayerSet() );
2424 else
2425 formatLayer( aTrack->GetLayer() );
2426
2427 if( aTrack->HasSolderMask()
2428 && aTrack->GetLocalSolderMaskMargin().has_value()
2429 && ( aTrack->IsOnLayer( F_Cu ) || aTrack->IsOnLayer( B_Cu ) ) )
2430 {
2431 m_out->Print( "(solder_mask_margin %s)",
2432 formatInternalUnits( aTrack->GetLocalSolderMaskMargin().value() ).c_str() );
2433 }
2434 }
2435
2436 m_out->Print( "(net %d)", m_mapping->Translate( aTrack->GetNetCode() ) );
2437
2439 m_out->Print( ")" );
2440}
2441
2442
2443void PCB_IO_KICAD_SEXPR::format( const ZONE* aZone ) const
2444{
2445 // Save the NET info.
2446 // For keepout and non copper zones, net code and net name are irrelevant
2447 // so be sure a dummy value is stored, just for ZONE compatibility
2448 // (perhaps netcode and netname should be not stored)
2449
2450 bool has_no_net = aZone->GetIsRuleArea() || !aZone->IsOnCopperLayer();
2451
2452 m_out->Print( "(zone (net %d) (net_name %s)",
2453 has_no_net ? 0 : m_mapping->Translate( aZone->GetNetCode() ),
2454 m_out->Quotew( has_no_net ? wxString( wxT("") ) : aZone->GetNetname() ).c_str() );
2455
2456 if( aZone->IsLocked() )
2457 KICAD_FORMAT::FormatBool( m_out, "locked", true );
2458
2459 // If a zone exists on multiple layers, format accordingly
2460 LSET layers = aZone->GetLayerSet();
2461
2462 if( aZone->GetBoard() )
2463 layers &= aZone->GetBoard()->GetEnabledLayers();
2464
2465 if( layers.count() > 1 )
2466 formatLayers( layers );
2467 else
2468 formatLayer( aZone->GetFirstLayer() );
2469
2471
2472 if( !aZone->GetZoneName().empty() )
2473 m_out->Print( "(name %s)", m_out->Quotew( aZone->GetZoneName() ).c_str() );
2474
2475 // Save the outline aux info
2476 std::string hatch;
2477
2478 switch( aZone->GetHatchStyle() )
2479 {
2480 default:
2481 case ZONE_BORDER_DISPLAY_STYLE::NO_HATCH: hatch = "none"; break;
2482 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_EDGE: hatch = "edge"; break;
2483 case ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL: hatch = "full"; break;
2484 }
2485
2486 m_out->Print( "(hatch %s %s)", hatch.c_str(),
2487 formatInternalUnits( aZone->GetBorderHatchPitch() ).c_str() );
2488
2489
2490
2491 if( aZone->GetAssignedPriority() > 0 )
2492 m_out->Print( "(priority %d)", aZone->GetAssignedPriority() );
2493
2494 // Add teardrop keywords in file: (attr (teardrop (type xxx)))where xxx is the teardrop type
2495 if( aZone->IsTeardropArea() )
2496 {
2497 m_out->Print( "(attr (teardrop (type %s)))",
2498 aZone->GetTeardropAreaType() == TEARDROP_TYPE::TD_VIAPAD
2499 ? "padvia"
2500 : "track_end" );
2501 }
2502
2503 m_out->Print( "(connect_pads" );
2504
2505 switch( aZone->GetPadConnection() )
2506 {
2507 default:
2508 case ZONE_CONNECTION::THERMAL: // Default option not saved or loaded.
2509 break;
2510
2511 case ZONE_CONNECTION::THT_THERMAL:
2512 m_out->Print( " thru_hole_only" );
2513 break;
2514
2515 case ZONE_CONNECTION::FULL:
2516 m_out->Print( " yes" );
2517 break;
2518
2519 case ZONE_CONNECTION::NONE:
2520 m_out->Print( " no" );
2521 break;
2522 }
2523
2524 m_out->Print( "(clearance %s)",
2525 formatInternalUnits( aZone->GetLocalClearance().value() ).c_str() );
2526
2527 m_out->Print( ")" );
2528
2529 m_out->Print( "(min_thickness %s)",
2530 formatInternalUnits( aZone->GetMinThickness() ).c_str() );
2531
2532 // We continue to write this for 3rd-party parsers, but we no longer read it (as of V7).
2533 m_out->Print( "(filled_areas_thickness no)" );
2534
2535 if( aZone->GetIsRuleArea() )
2536 {
2537 // Keepout settings
2538 m_out->Print( "(keepout (tracks %s) (vias %s) (pads %s) (copperpour %s) (footprints %s))",
2539 aZone->GetDoNotAllowTracks() ? "not_allowed" : "allowed",
2540 aZone->GetDoNotAllowVias() ? "not_allowed" : "allowed",
2541 aZone->GetDoNotAllowPads() ? "not_allowed" : "allowed",
2542 aZone->GetDoNotAllowCopperPour() ? "not_allowed" : "allowed",
2543 aZone->GetDoNotAllowFootprints() ? "not_allowed" : "allowed" );
2544
2545 // Multichannel settings
2546 m_out->Print( "(placement" );
2548
2549 switch( aZone->GetRuleAreaPlacementSourceType() )
2550 {
2551 case RULE_AREA_PLACEMENT_SOURCE_TYPE::SHEETNAME:
2552 m_out->Print( "(sheetname %s)",
2553 m_out->Quotew( aZone->GetRuleAreaPlacementSource() ).c_str() );
2554 break;
2555 case RULE_AREA_PLACEMENT_SOURCE_TYPE::COMPONENT_CLASS:
2556 m_out->Print( "(component_class %s)",
2557 m_out->Quotew( aZone->GetRuleAreaPlacementSource() ).c_str() );
2558 break;
2559 }
2560
2561 m_out->Print( ")" );
2562 }
2563
2564 m_out->Print( "(fill" );
2565
2566 // Default is not filled.
2567 if( aZone->IsFilled() )
2568 m_out->Print( " yes" );
2569
2570 // Default is polygon filled.
2571 if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
2572 m_out->Print( "(mode hatch)" );
2573
2574 m_out->Print( "(thermal_gap %s) (thermal_bridge_width %s)",
2575 formatInternalUnits( aZone->GetThermalReliefGap() ).c_str(),
2576 formatInternalUnits( aZone->GetThermalReliefSpokeWidth() ).c_str() );
2577
2579 {
2580 switch( aZone->GetCornerSmoothingType() )
2581 {
2583 m_out->Print( "(smoothing chamfer)" );
2584 break;
2585
2587 m_out->Print( "(smoothing fillet)" );
2588 break;
2589
2590 default:
2591 THROW_IO_ERROR( wxString::Format( _( "unknown zone corner smoothing type %d" ),
2592 aZone->GetCornerSmoothingType() ) );
2593 }
2594
2595 if( aZone->GetCornerRadius() != 0 )
2596 m_out->Print( "(radius %s)", formatInternalUnits( aZone->GetCornerRadius() ).c_str() );
2597 }
2598
2599 if( aZone->GetIslandRemovalMode() != ISLAND_REMOVAL_MODE::ALWAYS )
2600 {
2601 m_out->Print( "(island_removal_mode %d) (island_area_min %s)",
2602 static_cast<int>( aZone->GetIslandRemovalMode() ),
2604 }
2605
2606 if( aZone->GetFillMode() == ZONE_FILL_MODE::HATCH_PATTERN )
2607 {
2608 m_out->Print( "(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
2609 formatInternalUnits( aZone->GetHatchThickness() ).c_str(),
2610 formatInternalUnits( aZone->GetHatchGap() ).c_str(),
2611 FormatDouble2Str( aZone->GetHatchOrientation().AsDegrees() ).c_str() );
2612
2613 if( aZone->GetHatchSmoothingLevel() > 0 )
2614 {
2615 m_out->Print( "(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
2616 aZone->GetHatchSmoothingLevel(),
2617 FormatDouble2Str( aZone->GetHatchSmoothingValue() ).c_str() );
2618 }
2619
2620 m_out->Print( "(hatch_border_algorithm %s) (hatch_min_hole_area %s)",
2621 aZone->GetHatchBorderAlgorithm() ? "hatch_thickness" : "min_thickness",
2622 FormatDouble2Str( aZone->GetHatchHoleMinArea() ).c_str() );
2623 }
2624
2625 m_out->Print( ")" );
2626
2627 if( aZone->GetNumCorners() )
2628 {
2629 SHAPE_POLY_SET::POLYGON poly = aZone->Outline()->Polygon(0);
2630
2631 for( const SHAPE_LINE_CHAIN& chain : poly )
2632 {
2633 m_out->Print( "(polygon" );
2634 formatPolyPts( chain );
2635 m_out->Print( ")" );
2636 }
2637 }
2638
2639 // Save the PolysList (filled areas)
2640 for( PCB_LAYER_ID layer : aZone->GetLayerSet().Seq() )
2641 {
2642 const std::shared_ptr<SHAPE_POLY_SET>& fv = aZone->GetFilledPolysList( layer );
2643
2644 for( int ii = 0; ii < fv->OutlineCount(); ++ii )
2645 {
2646 m_out->Print( "(filled_polygon" );
2647 m_out->Print( "(layer %s)", m_out->Quotew( LSET::Name( layer ) ).c_str() );
2648
2649 if( aZone->IsIsland( layer, ii ) )
2650 m_out->Print( "(island)" );
2651
2652 const SHAPE_LINE_CHAIN& chain = fv->COutline( ii );
2653
2654 formatPolyPts( chain );
2655 m_out->Print( ")" );
2656 }
2657 }
2658
2659 m_out->Print( ")" );
2660}
2661
2662
2663PCB_IO_KICAD_SEXPR::PCB_IO_KICAD_SEXPR( int aControlFlags ) : PCB_IO( wxS( "KiCad" ) ),
2664 m_cache( nullptr ),
2665 m_ctl( aControlFlags ),
2666 m_mapping( new NETINFO_MAPPING() )
2667{
2668 init( nullptr );
2669 m_out = &m_sf;
2670}
2671
2672
2674{
2675 delete m_cache;
2676 delete m_mapping;
2677}
2678
2679
2680BOARD* PCB_IO_KICAD_SEXPR::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
2681 const std::map<std::string, UTF8>* aProperties, PROJECT* aProject )
2682{
2683 FILE_LINE_READER reader( aFileName );
2684
2685 unsigned lineCount = 0;
2686
2688
2689 if( m_progressReporter )
2690 {
2691 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
2692
2694 THROW_IO_ERROR( _( "Open cancelled by user." ) );
2695
2696 while( reader.ReadLine() )
2697 lineCount++;
2698
2699 reader.Rewind();
2700 }
2701
2702 BOARD* board = DoLoad( reader, aAppendToMe, aProperties, m_progressReporter, lineCount );
2703
2704 // Give the filename to the board if it's new
2705 if( !aAppendToMe )
2706 board->SetFileName( aFileName );
2707
2708 return board;
2709}
2710
2711
2712BOARD* PCB_IO_KICAD_SEXPR::DoLoad( LINE_READER& aReader, BOARD* aAppendToMe, const std::map<std::string, UTF8>* aProperties,
2713 PROGRESS_REPORTER* aProgressReporter, unsigned aLineCount)
2714{
2715 init( aProperties );
2716
2717 PCB_IO_KICAD_SEXPR_PARSER parser( &aReader, aAppendToMe, m_queryUserCallback, aProgressReporter, aLineCount );
2718 BOARD* board;
2719
2720 try
2721 {
2722 board = dynamic_cast<BOARD*>( parser.Parse() );
2723 }
2724 catch( const FUTURE_FORMAT_ERROR& )
2725 {
2726 // Don't wrap a FUTURE_FORMAT_ERROR in another
2727 throw;
2728 }
2729 catch( const PARSE_ERROR& parse_error )
2730 {
2731 if( parser.IsTooRecent() )
2732 throw FUTURE_FORMAT_ERROR( parse_error, parser.GetRequiredVersion() );
2733 else
2734 throw;
2735 }
2736
2737 if( !board )
2738 {
2739 // The parser loaded something that was valid, but wasn't a board.
2740 THROW_PARSE_ERROR( _( "This file does not contain a PCB." ), parser.CurSource(),
2741 parser.CurLine(), parser.CurLineNumber(), parser.CurOffset() );
2742 }
2743
2744 return board;
2745}
2746
2747
2748void PCB_IO_KICAD_SEXPR::init( const std::map<std::string, UTF8>* aProperties )
2749{
2750 m_board = nullptr;
2751 m_reader = nullptr;
2752 m_props = aProperties;
2753}
2754
2755
2756void PCB_IO_KICAD_SEXPR::validateCache( const wxString& aLibraryPath, bool checkModified )
2757{
2759
2760 if( !m_cache || !m_cache->IsPath( aLibraryPath ) || ( checkModified && m_cache->IsModified() ) )
2761 {
2762 // a spectacular episode in memory management:
2763 delete m_cache;
2764 m_cache = new FP_CACHE( this, aLibraryPath );
2765 m_cache->Load();
2766 }
2767}
2768
2769
2770void PCB_IO_KICAD_SEXPR::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibPath,
2771 bool aBestEfforts, const std::map<std::string, UTF8>* aProperties )
2772{
2773 LOCALE_IO toggle; // toggles on, then off, the C locale.
2774 wxDir dir( aLibPath );
2775 wxString errorMsg;
2776
2777 init( aProperties );
2778
2779 try
2780 {
2781 validateCache( aLibPath );
2782 }
2783 catch( const IO_ERROR& ioe )
2784 {
2785 errorMsg = ioe.What();
2786 }
2787
2788 // Some of the files may have been parsed correctly so we want to add the valid files to
2789 // the library.
2790
2791 for( const auto& footprint : m_cache->GetFootprints() )
2792 aFootprintNames.Add( footprint.first );
2793
2794 if( !errorMsg.IsEmpty() && !aBestEfforts )
2795 THROW_IO_ERROR( errorMsg );
2796}
2797
2798
2799const FOOTPRINT* PCB_IO_KICAD_SEXPR::getFootprint( const wxString& aLibraryPath,
2800 const wxString& aFootprintName,
2801 const std::map<std::string, UTF8>* aProperties,
2802 bool checkModified )
2803{
2804 LOCALE_IO toggle; // toggles on, then off, the C locale.
2805
2806 init( aProperties );
2807
2808 try
2809 {
2810 validateCache( aLibraryPath, checkModified );
2811 }
2812 catch( const IO_ERROR& )
2813 {
2814 // do nothing with the error
2815 }
2816
2818 FP_CACHE_FOOTPRINT_MAP::const_iterator it = footprints.find( aFootprintName );
2819
2820 if( it == footprints.end() )
2821 return nullptr;
2822
2823 return it->second->GetFootprint();
2824}
2825
2826
2827const FOOTPRINT* PCB_IO_KICAD_SEXPR::GetEnumeratedFootprint( const wxString& aLibraryPath,
2828 const wxString& aFootprintName,
2829 const std::map<std::string, UTF8>* aProperties )
2830{
2831 return getFootprint( aLibraryPath, aFootprintName, aProperties, false );
2832}
2833
2834
2835bool PCB_IO_KICAD_SEXPR::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
2836 const std::map<std::string, UTF8>* aProperties )
2837{
2838 // Note: checking the cache sounds like a good idea, but won't catch files which differ
2839 // only in case.
2840 //
2841 // Since this goes out to the native filesystem, we get platform differences (ie: MSW's
2842 // case-insensitive filesystem) handled "for free".
2843 // Warning: footprint names frequently contain a point. So be careful when initializing
2844 // wxFileName, and use a CTOR with extension specified
2845 wxFileName footprintFile( aLibraryPath, aFootprintName, FILEEXT::KiCadFootprintFileExtension );
2846
2847 return footprintFile.Exists();
2848}
2849
2850
2851FOOTPRINT* PCB_IO_KICAD_SEXPR::ImportFootprint( const wxString& aFootprintPath, wxString& aFootprintNameOut,
2852 const std::map<std::string, UTF8>* aProperties )
2853{
2854 wxString fcontents;
2855 wxFFile f( aFootprintPath );
2856
2858
2859 if( !f.IsOpened() )
2860 return nullptr;
2861
2862 f.ReadAll( &fcontents );
2863
2864 aFootprintNameOut = wxFileName( aFootprintPath ).GetName();
2865
2866 return dynamic_cast<FOOTPRINT*>( Parse( fcontents ) );
2867}
2868
2869
2870FOOTPRINT* PCB_IO_KICAD_SEXPR::FootprintLoad( const wxString& aLibraryPath,
2871 const wxString& aFootprintName,
2872 bool aKeepUUID,
2873 const std::map<std::string, UTF8>* aProperties )
2874{
2876
2877 const FOOTPRINT* footprint = getFootprint( aLibraryPath, aFootprintName, aProperties, true );
2878
2879 if( footprint )
2880 {
2881 FOOTPRINT* copy;
2882
2883 if( aKeepUUID )
2884 copy = static_cast<FOOTPRINT*>( footprint->Clone() );
2885 else
2886 copy = static_cast<FOOTPRINT*>( footprint->Duplicate() );
2887
2888 copy->SetParent( nullptr );
2889 return copy;
2890 }
2891
2892 return nullptr;
2893}
2894
2895
2896void PCB_IO_KICAD_SEXPR::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFootprint,
2897 const std::map<std::string, UTF8>* aProperties )
2898{
2899 LOCALE_IO toggle; // toggles on, then off, the C locale.
2900
2901 init( aProperties );
2902
2903 // In this public PLUGIN API function, we can safely assume it was
2904 // called for saving into a library path.
2906
2907 validateCache( aLibraryPath, !aProperties || !aProperties->contains( "skip_cache_validation" ) );
2908
2909 if( !m_cache->IsWritable() )
2910 {
2911 if( !m_cache->Exists() )
2912 {
2913 const wxString msg = wxString::Format( _( "Library '%s' does not exist.\n"
2914 "Would you like to create it?"),
2915 aLibraryPath );
2916
2917 if( !Pgm().IsGUI()
2918 || wxMessageBox( msg, _( "Library Not Found" ), wxYES_NO | wxICON_QUESTION )
2919 != wxYES )
2920 return;
2921
2922 // Save throws its own IO_ERROR on failure, so no need to recreate here
2923 m_cache->Save( nullptr );
2924 }
2925 else
2926 {
2927 wxString msg = wxString::Format( _( "Library '%s' is read only." ), aLibraryPath );
2928 THROW_IO_ERROR( msg );
2929 }
2930 }
2931
2932 wxString footprintName = aFootprint->GetFPID().GetLibItemName();
2933
2935 wxString fpName = aFootprint->GetFPID().GetLibItemName().wx_str();
2936 ReplaceIllegalFileNameChars( fpName, '_' );
2937
2938 // Quietly overwrite footprint and delete footprint file from path for any by same name.
2939 wxFileName fn( aLibraryPath, fpName, FILEEXT::KiCadFootprintFileExtension );
2940
2941 // Write through symlinks, don't replace them
2943
2944 if( !fn.IsOk() )
2945 {
2946 THROW_IO_ERROR( wxString::Format( _( "Footprint file name '%s' is not valid." ),
2947 fn.GetFullPath() ) );
2948 }
2949
2950 if( fn.FileExists() && !fn.IsFileWritable() )
2951 {
2952 THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete '%s'." ),
2953 fn.GetFullPath() ) );
2954 }
2955
2956 wxString fullPath = fn.GetFullPath();
2957 wxString fullName = fn.GetFullName();
2958 FP_CACHE_FOOTPRINT_MAP::const_iterator it = footprints.find( footprintName );
2959
2960 if( it != footprints.end() )
2961 {
2962 wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint file '%s'." ), fullPath );
2963 footprints.erase( footprintName );
2964 wxRemoveFile( fullPath );
2965 }
2966
2967 // I need my own copy for the cache
2968 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aFootprint->Clone() );
2969
2970 // It's orientation should be zero and it should be on the front layer.
2971 footprint->SetOrientation( ANGLE_0 );
2972
2973 if( footprint->GetLayer() != F_Cu )
2974 {
2975 PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() );
2976
2977 if( cfg )
2978 footprint->Flip( footprint->GetPosition(), cfg->m_FlipDirection );
2979 else
2980 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
2981 }
2982
2983 // Detach it from the board and its group
2984 footprint->SetParent( nullptr );
2985 footprint->SetParentGroup( nullptr );
2986
2987 wxLogTrace( traceKicadPcbPlugin, wxT( "Creating s-expr footprint file '%s'." ), fullPath );
2988 footprints.insert( footprintName,
2989 new FP_CACHE_ITEM( footprint, WX_FILENAME( fn.GetPath(), fullName ) ) );
2990 m_cache->Save( footprint );
2991}
2992
2993
2994void PCB_IO_KICAD_SEXPR::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
2995 const std::map<std::string, UTF8>* aProperties )
2996{
2997 LOCALE_IO toggle; // toggles on, then off, the C locale.
2998
2999 init( aProperties );
3000
3001 validateCache( aLibraryPath );
3002
3003 if( !m_cache->IsWritable() )
3004 {
3005 THROW_IO_ERROR( wxString::Format( _( "Library '%s' is read only." ),
3006 aLibraryPath.GetData() ) );
3007 }
3008
3009 m_cache->Remove( aFootprintName );
3010}
3011
3012
3013
3014long long PCB_IO_KICAD_SEXPR::GetLibraryTimestamp( const wxString& aLibraryPath ) const
3015{
3016 return FP_CACHE::GetTimestamp( aLibraryPath );
3017}
3018
3019
3020void PCB_IO_KICAD_SEXPR::CreateLibrary( const wxString& aLibraryPath, const std::map<std::string, UTF8>* aProperties )
3021{
3022 if( wxDir::Exists( aLibraryPath ) )
3023 {
3024 THROW_IO_ERROR( wxString::Format( _( "Cannot overwrite library path '%s'." ),
3025 aLibraryPath.GetData() ) );
3026 }
3027
3028 LOCALE_IO toggle;
3029
3030 init( aProperties );
3031
3032 delete m_cache;
3033 m_cache = new FP_CACHE( this, aLibraryPath );
3034 m_cache->Save();
3035}
3036
3037
3038bool PCB_IO_KICAD_SEXPR::DeleteLibrary( const wxString& aLibraryPath, const std::map<std::string, UTF8>* aProperties )
3039{
3040 wxFileName fn;
3041 fn.SetPath( aLibraryPath );
3042
3043 // Return if there is no library path to delete.
3044 if( !fn.DirExists() )
3045 return false;
3046
3047 if( !fn.IsDirWritable() )
3048 {
3049 THROW_IO_ERROR( wxString::Format( _( "Insufficient permissions to delete folder '%s'." ),
3050 aLibraryPath.GetData() ) );
3051 }
3052
3053 wxDir dir( aLibraryPath );
3054
3055 if( dir.HasSubDirs() )
3056 {
3057 THROW_IO_ERROR( wxString::Format( _( "Library folder '%s' has unexpected sub-folders." ),
3058 aLibraryPath.GetData() ) );
3059 }
3060
3061 // All the footprint files must be deleted before the directory can be deleted.
3062 if( dir.HasFiles() )
3063 {
3064 unsigned i;
3065 wxFileName tmp;
3066 wxArrayString files;
3067
3068 wxDir::GetAllFiles( aLibraryPath, &files );
3069
3070 for( i = 0; i < files.GetCount(); i++ )
3071 {
3072 tmp = files[i];
3073
3074 if( tmp.GetExt() != FILEEXT::KiCadFootprintFileExtension )
3075 {
3076 THROW_IO_ERROR( wxString::Format( _( "Unexpected file '%s' found in library "
3077 "path '%s'." ),
3078 files[i].GetData(),
3079 aLibraryPath.GetData() ) );
3080 }
3081 }
3082
3083 for( i = 0; i < files.GetCount(); i++ )
3084 wxRemoveFile( files[i] );
3085 }
3086
3087 wxLogTrace( traceKicadPcbPlugin, wxT( "Removing footprint library '%s'." ),
3088 aLibraryPath.GetData() );
3089
3090 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
3091 // we don't want that. we want bare metal portability with no UI here.
3092 if( !wxRmdir( aLibraryPath ) )
3093 {
3094 THROW_IO_ERROR( wxString::Format( _( "Footprint library '%s' cannot be deleted." ),
3095 aLibraryPath.GetData() ) );
3096 }
3097
3098 // For some reason removing a directory in Windows is not immediately updated. This delay
3099 // prevents an error when attempting to immediately recreate the same directory when over
3100 // writing an existing library.
3101#ifdef __WINDOWS__
3102 wxMilliSleep( 250L );
3103#endif
3104
3105 if( m_cache && !m_cache->IsPath( aLibraryPath ) )
3106 {
3107 delete m_cache;
3108 m_cache = nullptr;
3109 }
3110
3111 return true;
3112}
3113
3114
3115bool PCB_IO_KICAD_SEXPR::IsLibraryWritable( const wxString& aLibraryPath )
3116{
3117 LOCALE_IO toggle;
3118
3119 init( nullptr );
3120
3121 validateCache( aLibraryPath );
3122
3123 return m_cache->IsWritable();
3124}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
@ ZLO_FORCE_FLASHED
Definition: board_item.h:68
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
const wxMemoryBuffer & GetImageDataBuffer() const
Definition: bitmap_base.h:246
wxImage * GetImageData()
Definition: bitmap_base.h:68
TEARDROP_PARAMETERS & GetTeardropParams()
Container for design settings for a BOARD object.
int GetBoardThickness() const
The full thickness of the board including copper and masks.
const VECTOR2I & GetGridOrigin()
const VECTOR2I & GetAuxOrigin()
BOARD_STACKUP & GetStackupDescriptor()
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
void SetParentGroup(PCB_GROUP *aGroup)
Definition: board_item.h:89
virtual bool IsKnockout() const
Definition: board_item.h:324
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:47
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:298
VECTOR2I GetFPRelativePosition() const
Definition: board_item.cpp:327
virtual bool IsLocked() const
Definition: board_item.cpp:75
Manage layers needed to make a physical board.
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, const BOARD *aBoard) const
Write the stackup info on board file.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:778
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: board.cpp:2550
const GENERATORS & Generators() const
Definition: board.h:337
void SetFileName(const wxString &aFileName)
Definition: board.h:325
const PAGE_INFO & GetPageSettings() const
Definition: board.h:689
const ZONES & Zones() const
Definition: board.h:335
const GROUPS & Groups() const
The groups must maintain the following invariants.
Definition: board.h:358
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
Definition: board.cpp:612
TITLE_BLOCK & GetTitleBlock()
Definition: board.h:695
int GetCopperLayerCount() const
Definition: board.cpp:741
const std::map< wxString, wxString > & GetProperties() const
Definition: board.h:362
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: board.h:692
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:574
bool LegacyTeardrops() const
Definition: board.h:1261
wxString GroupsSanityCheck(bool repair=false)
Consistency check of internal m_groups structure.
Definition: board.cpp:2753
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
void EmbedFonts() override
Finds all fonts used in the board and embeds them in the file if permissions allow.
Definition: board.cpp:2568
const DRAWINGS & Drawings() const
Definition: board.h:333
const std::vector< COMPONENT_CLASS * > & GetConstituentClasses() const
Fetches a vector of the constituent classes for this (effective) class.
double AsDegrees() const
Definition: eda_angle.h:113
bool IsZero() const
Definition: eda_angle.h:133
EDA_ANGLE Normalize720()
Definition: eda_angle.h:271
const KIID m_Uuid
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
virtual wxString GetClass() const =0
Return the class name.
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:213
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:286
bool IsFilled() const
Definition: eda_shape.h:98
SHAPE_T GetShape() const
Definition: eda_shape.h:132
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:174
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:137
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:340
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:210
bool IsPolyShapeValid() const
Definition: eda_shape.cpp:1571
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:796
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:257
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:134
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
bool IsKeepUpright() const
Definition: eda_text.h:193
virtual bool IsVisible() const
Definition: eda_text.h:174
KIFONT::FONT * GetFont() const
Definition: eda_text.h:234
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
Definition: eda_text.cpp:644
virtual EDA_ANGLE GetDrawRotation() const
Definition: eda_text.h:362
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
Definition: eda_text.h:109
int GetTextThickness() const
Definition: eda_text.h:126
bool IsEmpty() const
void WriteEmbeddedFiles(OUTPUTFORMATTER &aOut, bool aWriteData) const
Output formatter for the embedded files.
void ClearEmbeddedFiles(bool aDeleteFiles=true)
void ClearEmbeddedFonts()
Removes all embedded fonts from the collection.
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Loads a file from disk and adds it to the collection.
const std::map< wxString, EMBEDDED_FILE * > & EmbeddedFileMap() const
bool GetAreFontsEmbedded() const
A LINE_READER that reads from an open file.
Definition: richio.h:185
void Rewind()
Rewind the file and resets the line number back to zero.
Definition: richio.h:234
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:244
void EmbedFonts() override
Definition: footprint.cpp:3873
void SetFPID(const LIB_ID &aFPID)
Definition: footprint.h:249
wxString GetLibDescription() const
Definition: footprint.h:257
ZONE_CONNECTION GetLocalZoneConnection() const
Definition: footprint.h:288
EDA_ANGLE GetOrientation() const
Definition: footprint.h:227
ZONES & Zones()
Definition: footprint.h:212
void SetOrientation(const EDA_ANGLE &aNewAngle)
Definition: footprint.cpp:2458
wxString GetSheetname() const
Definition: footprint.h:266
std::optional< int > GetLocalSolderPasteMargin() const
Definition: footprint.h:281
EDA_ITEM * Clone() const override
Invoke a function on all children.
Definition: footprint.cpp:2075
PCB_FIELD & Value()
read/write accessors:
Definition: footprint.h:658
std::optional< int > GetLocalClearance() const
Definition: footprint.h:275
BOARD_ITEM * Duplicate() const override
Create a copy of this BOARD_ITEM.
Definition: footprint.cpp:2484
std::deque< PAD * > & Pads()
Definition: footprint.h:206
int GetAttributes() const
Definition: footprint.h:290
const COMPONENT_CLASS * GetComponentClass() const
Definition: footprint.h:1017
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: footprint.h:236
LSET GetPrivateLayers() const
Definition: footprint.h:141
wxString GetSheetfile() const
Definition: footprint.h:269
const std::vector< wxString > & GetNetTiePadGroups() const
Definition: footprint.h:339
const LIB_ID & GetFPID() const
Definition: footprint.h:248
bool IsLocked() const override
Definition: footprint.h:411
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with PCB_TEXTs.
Definition: footprint.cpp:616
PCB_FIELD & Reference()
Definition: footprint.h:659
bool IsNetTie() const
Definition: footprint.h:297
std::optional< double > GetLocalSolderPasteMarginRatio() const
Definition: footprint.h:284
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: footprint.cpp:2330
GROUPS & Groups()
Definition: footprint.h:215
wxString GetFilters() const
Definition: footprint.h:272
const wxArrayString * GetInitialComments() const
Return the initial comments block or NULL if none, without transfer of ownership.
Definition: footprint.h:973
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:220
const KIID_PATH & GetPath() const
Definition: footprint.h:263
std::optional< int > GetLocalSolderMaskMargin() const
Definition: footprint.h:278
wxString GetKeywords() const
Definition: footprint.h:260
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: footprint.h:1001
bool IsPlaced() const
Definition: footprint.h:434
VECTOR2I GetPosition() const override
Definition: footprint.h:224
DRAWINGS & GraphicalItems()
Definition: footprint.h:209
Helper class for creating a footprint library cache.
FP_CACHE_ITEM(FOOTPRINT *aFootprint, const WX_FILENAME &aFileName)
static long long GetTimestamp(const wxString &aLibPath)
Generate a timestamp representing all source files in the cache (including the parent directory).
FP_CACHE_FOOTPRINT_MAP & GetFootprints()
bool Exists() const
void Save(FOOTPRINT *aFootprint=nullptr)
Save the footprint cache or a single footprint from it to disk.
PCB_IO_KICAD_SEXPR * m_owner
bool IsModified()
Return true if the cache is not up-to-date.
long long m_cache_timestamp
wxString m_lib_raw_path
void SetPath(const wxString &aPath)
wxFileName m_lib_path
bool IsPath(const wxString &aPath) const
Check if aPath is the same as the current cache path.
FP_CACHE_FOOTPRINT_MAP m_footprints
FP_CACHE(PCB_IO_KICAD_SEXPR *aOwner, const wxString &aLibraryPath)
bool IsWritable() const
void Remove(const wxString &aFootprintName)
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition: io_base.h:221
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
virtual bool IsOutline() const
Definition: font.h:139
virtual void SetLineWidth(float aLineWidth)
Set the line width.
wxString AsString() const
Definition: kiid.cpp:348
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
UTF8 Format() const
Definition: lib_id.cpp:118
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition: lset.cpp:250
LSEQ TechAndUserUIOrder() const
Returns the technical and user layers in the order shown in layer widget.
Definition: lset.cpp:263
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
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:193
Handle the data for a net.
Definition: netinfo.h:56
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:381
void SetBoard(const BOARD *aBoard)
Set a BOARD object that is used to prepare the net code map.
Definition: netinfo.h:223
int Translate(int aNetCode) const
Translate net number according to the map prepared by Update() function.
virtual bool Finish()
Performs any cleanup needed at the end of a write.
Definition: richio.h:431
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:543
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
virtual std::string Quotes(const std::string &aWrapee) const
Check aWrapee input string for a need to be quoted (e.g.
Definition: richio.cpp:504
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
Definition: padstack.h:124
std::optional< int > & Clearance(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:1162
MASK_LAYER_PROPS & FrontOuterLayers()
Definition: padstack.h:312
std::optional< int > & ThermalSpokeWidth(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:1227
EDA_ANGLE ThermalSpokeAngle(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:1262
std::optional< int > & ThermalGap(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:1239
const VECTOR2I & Size(PCB_LAYER_ID aLayer) const
Definition: padstack.cpp:1049
@ NORMAL
Shape is the same on all layers.
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
MODE Mode() const
Definition: padstack.h:287
MASK_LAYER_PROPS & BackOuterLayers()
Definition: padstack.h:315
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:144
static constexpr PCB_LAYER_ID INNER_LAYERS
! The layer identifier to use for "inner layers" on top/inner/bottom padstacks
Definition: padstack.h:147
std::optional< ZONE_CONNECTION > & ZoneConnection(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:1215
Definition: pad.h:54
PAD_PROP GetProperty() const
Definition: pad.h:445
bool GetRemoveUnconnected() const
Definition: pad.h:711
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pad.h:439
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
Definition: pad.h:367
const ZONE_LAYER_OVERRIDE & GetZoneLayerOverride(PCB_LAYER_ID aLayer) const
Definition: pad.cpp:201
std::optional< double > GetLocalSolderPasteMarginRatio() const
Definition: pad.h:472
const wxString & GetPinType() const
Definition: pad.h:151
const VECTOR2I & GetDrillSize() const
Definition: pad.h:307
PAD_ATTRIB GetAttribute() const
Definition: pad.h:442
const wxString & GetPinFunction() const
Definition: pad.h:145
const wxString & GetNumber() const
Definition: pad.h:134
const VECTOR2I & GetDelta(PCB_LAYER_ID aLayer) const
Definition: pad.h:301
EDA_ANGLE GetThermalSpokeAngle() const
Definition: pad.h:615
double GetRoundRectRadiusRatio(PCB_LAYER_ID aLayer) const
Definition: pad.h:652
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition: pad.h:193
bool GetKeepTopBottom() const
Definition: pad.h:727
std::optional< int > GetLocalClearance() const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
Definition: pad.h:457
const PADSTACK & Padstack() const
Definition: pad.h:323
const VECTOR2I & GetOffset(PCB_LAYER_ID aLayer) const
Definition: pad.h:319
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition: pad.h:410
PADSTACK::CUSTOM_SHAPE_ZONE_MODE GetCustomShapeInZoneOpt() const
Definition: pad.h:223
PAD_DRILL_SHAPE GetDrillShape() const
Definition: pad.h:424
int GetChamferPositions(PCB_LAYER_ID aLayer) const
Definition: pad.h:688
std::optional< int > GetLocalSolderPasteMargin() const
Definition: pad.h:466
std::optional< int > GetLocalSolderMaskMargin() const
Definition: pad.h:460
int GetThermalSpokeWidth() const
Definition: pad.h:602
double GetChamferRectRatio(PCB_LAYER_ID aLayer) const
Definition: pad.h:671
ZONE_CONNECTION GetLocalZoneConnection() const
Definition: pad.h:482
int GetThermalGap() const
Definition: pad.h:631
PAD_SHAPE GetAnchorPadShape(PCB_LAYER_ID aLayer) const
Definition: pad.h:215
int GetPadToDieLength() const
Definition: pad.h:455
const VECTOR2I & GetSize(PCB_LAYER_ID aLayer) const
Definition: pad.h:266
void Format(OUTPUTFORMATTER *aFormatter) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:273
FLIP_DIRECTION m_FlipDirection
const VECTOR2I & GetMid() const
Definition: pcb_track.h:305
Abstract dimension API.
wxString GetOverrideText() const
wxString GetSuffix() const
int GetLineThickness() const
DIM_TEXT_POSITION GetTextPositionMode() const
bool GetKeepTextAligned() const
DIM_PRECISION GetPrecision() const
wxString GetPrefix() const
DIM_UNITS_MODE GetUnitsMode() const
DIM_UNITS_FORMAT GetUnitsFormat() const
virtual const VECTOR2I & GetStart() const
The dimension's origin is the first feature point for the dimension.
DIM_ARROW_DIRECTION GetArrowDirection() const
bool GetSuppressZeroes() const
int GetExtensionOffset() const
int GetArrowLength() const
bool GetOverrideTextEnabled() const
virtual const VECTOR2I & GetEnd() const
For better understanding of the points that make a dimension:
int GetHeight() const
int GetExtensionHeight() const
Mark the center of a circle or arc with a cross shape.
A leader is a dimension-like object pointing to a specific point.
DIM_TEXT_BORDER GetTextBorder() const
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
A radial dimension indicates either the radius or diameter of an arc or circle.
int GetLeaderLength() const
virtual const STRING_ANY_MAP GetProperties() const
virtual wxString GetGeneratorType() const
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
std::unordered_set< BOARD_ITEM * > & GetItems()
Definition: pcb_group.h:69
wxString GetName() const
Definition: pcb_group.h:66
Read a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object...
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
bool IsValidBoardHeader()
Partially parse the input and check if it matches expected header.
wxString GetRequiredVersion()
Return a string representing the version of KiCad required to open this file.
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
BOARD * DoLoad(LINE_READER &aReader, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties, PROGRESS_REPORTER *aProgressReporter, unsigned aLineCount)
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
void formatProperties(const BOARD *aBoard) const
formats the Nets and Netclasses
FOOTPRINT * ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete aFootprintName from the library at aLibraryPath.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void formatTeardropParameters(const TEARDROP_PARAMETERS &tdParams) const
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
NETINFO_MAPPING * m_mapping
mapping for net codes, so only not empty net codes are stored with consecutive integers as net codes
void formatNetInformation(const BOARD *aBoard) const
formats the Nets and Netclasses
const FOOTPRINT * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
void CreateLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
void formatPolyPts(const SHAPE_LINE_CHAIN &outline, const FOOTPRINT *aParentFP=nullptr) const
void formatLayers(LSET aLayerMask) const
FP_CACHE * m_cache
Footprint library cache.
void formatBoardLayers(const BOARD *aBoard) const
formats the board layer information
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Check for the existence of a footprint.
void FootprintSave(const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aFootprint to an existing library located at aLibraryPath.
void format(const BOARD *aBoard) const
void SaveBoard(const wxString &aFileName, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
void formatTenting(const PADSTACK &aPadstack) const
void formatGeneral(const BOARD *aBoard) const
formats the General section of the file
void formatSetup(const BOARD *aBoard) const
formats the board setup information
std::function< bool(wxString aTitle, int aIcon, wxString aMsg, wxString aAction)> m_queryUserCallback
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
void init(const std::map< std::string, UTF8 > *aProperties)
STRING_FORMATTER m_sf
void Format(const BOARD_ITEM *aItem) const
Output aItem to aFormatter in s-expression format.
void formatLayer(PCB_LAYER_ID aLayer, bool aIsKnockout=false) const
void formatHeader(const BOARD *aBoard) const
writes everything that comes before the board_items, like settings and layers etc
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties, bool checkModified)
void SetOutputFormatter(OUTPUTFORMATTER *aFormatter)
PCB_IO_KICAD_SEXPR(int aControlFlags=CTL_FOR_BOARD)
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
void formatRenderCache(const EDA_TEXT *aText) const
LINE_READER * m_reader
no ownership
A base class that BOARD loading and saving plugins should derive from.
Definition: pcb_io.h:71
BOARD * m_board
The board BOARD being worked on, no ownership here.
Definition: pcb_io.h:342
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
Definition: pcb_io.cpp:42
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
Definition: pcb_io.h:345
void Format(OUTPUTFORMATTER *aFormatter) const
Object to handle a bitmap image that can be inserted in a PCB.
VECTOR2I GetPosition() const override
Get the position of the image (this is the center of the image).
REFERENCE_IMAGE & GetReferenceImage()
std::optional< int > GetLocalSolderMaskMargin() const
Definition: pcb_shape.h:186
bool HasSolderMask() const
Definition: pcb_shape.h:183
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_shape.cpp:218
STROKE_PARAMS GetStroke() const override
Definition: pcb_shape.h:89
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: pcb_shape.h:69
bool StrokeRows() const
Definition: pcb_table.h:86
int GetRowCount() const
Definition: pcb_table.h:103
bool StrokeColumns() const
Definition: pcb_table.h:83
bool StrokeExternal() const
Definition: pcb_table.h:53
bool StrokeHeader() const
Definition: pcb_table.h:56
std::vector< PCB_TABLECELL * > GetCells() const
Definition: pcb_table.h:138
int GetColCount() const
Definition: pcb_table.h:101
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: pcb_table.h:71
const STROKE_PARAMS & GetBorderStroke() const
Definition: pcb_table.h:59
int GetColWidth(int aCol) const
Definition: pcb_table.h:110
int GetRowHeight(int aRow) const
Definition: pcb_table.h:120
int GetShape() const
Definition: pcb_target.h:58
int GetWidth() const
Definition: pcb_target.h:64
int GetSize() const
Definition: pcb_target.h:61
VECTOR2I GetPosition() const override
Definition: pcb_target.h:55
bool IsBorderEnabled() const
Disables the border, this is done by changing the stroke internally.
int GetMarginBottom() const
Definition: pcb_textbox.h:90
int GetMarginLeft() const
Definition: pcb_textbox.h:87
int GetMarginRight() const
Definition: pcb_textbox.h:89
int GetMarginTop() const
Definition: pcb_textbox.h:88
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_track.cpp:1046
bool HasSolderMask() const
Definition: pcb_track.h:146
std::optional< int > GetLocalSolderMaskMargin() const
Definition: pcb_track.h:149
const VECTOR2I & GetStart() const
Definition: pcb_track.h:122
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:119
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition: pcb_track.cpp:958
virtual int GetWidth() const
Definition: pcb_track.h:116
A progress reporter interface for use in multi-threaded environments.
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
Container for project specific data.
Definition: project.h:64
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:116
const VECTOR2I & GetP1() const
Definition: shape_arc.h:115
const VECTOR2I & GetP0() const
Definition: shape_arc.h:114
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_ARC & Arc(size_t aArc) const
int PointCount() const
Return the number of points (vertices) in this line chain.
ssize_t ArcIndex(size_t aSegment) const
Return the arc index for the given segment index.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:253
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale) const
TEARDROP_PARAMETARS is a helper class to handle parameters needed to build teardrops for a board thes...
int m_CurveSegCount
True if the teardrop should be curved.
double m_BestWidthRatio
The height of a teardrop as ratio between height and size of pad/via.
int m_TdMaxLen
max allowed length for teardrops in IU. <= 0 to disable
bool m_AllowUseTwoTracks
True to create teardrops using 2 track segments if the first in too small.
int m_TdMaxWidth
max allowed height for teardrops in IU. <= 0 to disable
double m_BestLengthRatio
The length of a teardrop as ratio between length and size of pad/via.
double m_WidthtoSizeFilterRatio
The ratio (H/D) between the via/pad size and the track width max value to create a teardrop 1....
bool m_TdOnPadsInZones
A filter to exclude pads inside zone fills.
bool m_Enabled
Flag to enable teardrops.
virtual void Format(OUTPUTFORMATTER *aFormatter) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:30
wxString wx_str() const
Definition: utf8.cpp:45
static REPORTER & GetInstance()
Definition: reporter.cpp:199
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: wx_filename.h:50
void SetFullName(const wxString &aFileNameAndExtension)
Definition: wx_filename.cpp:34
static void ResolvePossibleSymlinks(wxFileName &aFilename)
Definition: wx_filename.cpp:92
wxString GetPath() const
Definition: wx_filename.cpp:60
wxString GetName() const
Definition: wx_filename.cpp:47
wxString GetFullPath() const
Definition: wx_filename.cpp:66
long long GetTimestamp()
Definition: wx_filename.cpp:81
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
int GetHatchBorderAlgorithm() const
Definition: zone.h:306
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:724
std::optional< int > GetLocalClearance() const override
Definition: zone.cpp:714
wxString GetRuleAreaPlacementSource() const
Definition: zone.h:730
bool GetDoNotAllowVias() const
Definition: zone.h:732
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:620
bool GetDoNotAllowPads() const
Definition: zone.h:734
bool GetDoNotAllowTracks() const
Definition: zone.h:733
bool GetRuleAreaPlacementEnabled() const
Definition: zone.h:725
bool IsFilled() const
Definition: zone.h:264
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:753
SHAPE_POLY_SET * Outline()
Definition: zone.h:340
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
Definition: zone.cpp:1318
long long int GetMinIslandArea() const
Definition: zone.h:756
const wxString & GetZoneName() const
Definition: zone.h:135
int GetMinThickness() const
Definition: zone.h:273
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:270
int GetHatchThickness() const
Definition: zone.h:288
double GetHatchHoleMinArea() const
Definition: zone.h:303
bool IsTeardropArea() const
Definition: zone.h:699
int GetThermalReliefSpokeWidth() const
Definition: zone.h:217
int GetBorderHatchPitch() const
HatchBorder related methods.
Definition: zone.cpp:1099
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
Definition: zone.h:609
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:294
bool GetDoNotAllowFootprints() const
Definition: zone.h:735
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:196
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:133
bool GetDoNotAllowCopperPour() const
Definition: zone.h:731
int GetHatchGap() const
Definition: zone.h:291
RULE_AREA_PLACEMENT_SOURCE_TYPE GetRuleAreaPlacementSourceType() const
Definition: zone.h:726
TEARDROP_TYPE GetTeardropAreaType() const
Definition: zone.h:710
double GetHatchSmoothingValue() const
Definition: zone.h:300
int GetHatchSmoothingLevel() const
Definition: zone.h:297
unsigned int GetCornerRadius() const
Definition: zone.h:670
int GetCornerSmoothingType() const
Definition: zone.h:666
bool IsOnCopperLayer() const override
Definition: zone.cpp:475
PCB_LAYER_ID GetFirstLayer() const
Definition: zone.cpp:453
int GetThermalReliefGap() const
Definition: zone.h:206
unsigned GetAssignedPriority() const
Definition: zone.h:123
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition: zone.h:519
static void SetReporter(REPORTER *aReporter)
Set the reporter to use for reporting font substitution warnings.
Definition: fontconfig.cpp:64
long long TimestampDir(const wxString &aDirPath, const wxString &aFilespec)
A copy of ConvertFileTimeToWx() because wxWidgets left it as a static function private to src/common/...
Definition: common.cpp:597
This file is part of the common library.
#define CTL_OMIT_HYPERLINK
Omit the hyperlink attribute in .kicad_xxx files.
Definition: ctl_flags.h:47
#define CTL_OMIT_UUIDS
Omit component unique ids (useless in library)
Definition: ctl_flags.h:30
#define CTL_OMIT_FOOTPRINT_VERSION
Omit the version string from the (footprint) sexpr group.
Definition: ctl_flags.h:41
#define CTL_OMIT_INITIAL_COMMENTS
omit FOOTPRINT initial comments
Definition: ctl_flags.h:44
#define CTL_OMIT_LIBNAME
Omit lib alias when saving (used for board/not library).
Definition: ctl_flags.h:39
#define CTL_OMIT_PATH
Omit component sheet time stamp (useless in library)
Definition: ctl_flags.h:32
#define CTL_OMIT_HIDE
Omit the hide attribute in .kicad_xxx files.
Definition: ctl_flags.h:37
#define CTL_OMIT_AT
Omit position and rotation.
Definition: ctl_flags.h:33
#define CTL_OMIT_PAD_NETS
Omit pads net names (useless in library)
Definition: ctl_flags.h:29
#define CTL_OMIT_COLOR
Omit the color attribute in .kicad_xxx files.
Definition: ctl_flags.h:46
#define MIME_BASE64_LENGTH
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_45
Definition: eda_angle.h:402
@ FP_SMD
Definition: footprint.h:76
@ FP_DNP
Definition: footprint.h:83
@ FP_ALLOW_MISSING_COURTYARD
Definition: footprint.h:82
@ FP_EXCLUDE_FROM_POS_FILES
Definition: footprint.h:77
@ FP_BOARD_ONLY
Definition: footprint.h:79
@ FP_EXCLUDE_FROM_BOM
Definition: footprint.h:78
@ FP_THROUGH_HOLE
Definition: footprint.h:75
@ FP_ALLOW_SOLDERMASK_BRIDGES
Definition: footprint.h:81
static const std::string KiCadFootprintFileExtension
const wxChar *const traceKicadPcbPlugin
Flag to enable GEDA PCB plugin debug output.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:165
#define MAX_CU_LAYERS
Definition: layer_ids.h:140
bool IsExternalCopperLayer(int aLayerId)
Tests whether a layer is an external (F_Cu or B_Cu) copper layer.
Definition: layer_ids.h:542
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_CrtYd
Definition: layer_ids.h:116
@ B_Adhes
Definition: layer_ids.h:103
@ F_Paste
Definition: layer_ids.h:104
@ F_Adhes
Definition: layer_ids.h:102
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ F_Mask
Definition: layer_ids.h:97
@ B_Paste
Definition: layer_ids.h:105
@ User_9
Definition: layer_ids.h:132
@ F_Fab
Definition: layer_ids.h:119
@ F_SilkS
Definition: layer_ids.h:100
@ B_CrtYd
Definition: layer_ids.h:115
@ User_1
Definition: layer_ids.h:124
@ B_SilkS
Definition: layer_ids.h:101
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:135
@ F_Cu
Definition: layer_ids.h:64
@ B_Fab
Definition: layer_ids.h:118
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:96
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:169
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
Definition: eda_units.cpp:161
void FormatUuid(OUTPUTFORMATTER *aOut, const KIID &aUuid)
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
bool DuplicatePermissions(const wxString &aSrc, const wxString &aDest)
Duplicates the file security data from one file to another ensuring that they are the same between bo...
Definition: unix/io.cpp:40
Class to handle a set of BOARD_ITEMs.
bool isDefaultTeardropParameters(const TEARDROP_PARAMETERS &tdParams)
std::string formatInternalUnits(int aValue)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
#define CTL_FOR_BOARD
The zero arg constructor when PCB_PLUGIN is used for PLUGIN::Load() and PLUGIN::Save()ing a BOARD fil...
boost::ptr_map< wxString, FP_CACHE_ITEM > FP_CACHE_FOOTPRINT_MAP
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
Pcbnew s-expression file format parser definition.
#define UNDEFINED_DRILL_DIAMETER
Definition: pcb_track.h:81
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
bool ReplaceIllegalFileNameChars(std::string *aName, int aReplaceChar)
Checks aName for illegal file name characters.
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
const double IU_PER_MM
Definition: base_units.h:76
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:176
static const char * ShowType(LAYER_T aType)
Convert a LAYER_T enum to a string representation of the layer type.
Definition: board.cpp:644
std::optional< bool > has_solder_mask
True if this outer layer has mask (is not tented)
Definition: padstack.h:231
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:120
constexpr int delta
wxLogTrace helper definitions.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition: trigo.cpp:229
@ PCB_T
Definition: typeinfo.h:82
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:105
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition: typeinfo.h:91
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:103
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition: typeinfo.h:93
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition: typeinfo.h:107
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition: typeinfo.h:89
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition: typeinfo.h:90
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:106
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition: typeinfo.h:95
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:101
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition: typeinfo.h:94
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition: typeinfo.h:104
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691
Definition of file extensions used in Kicad.