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