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