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