KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_kicad_sexpr.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Wayne Stambaugh <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include <algorithm>
24
25#include <fmt/format.h>
26
27#include <wx/dir.h>
28#include <wx/log.h>
29#include <wx/mstream.h>
30
31#include <base_units.h>
32#include <bitmap_base.h>
34#include <build_version.h>
35#include <sch_selection.h>
36#include <font/fontconfig.h>
39#include <progress_reporter.h>
40#include <schematic.h>
41#include <schematic_lexer.h>
42#include <sch_bitmap.h>
43#include <sch_bus_entry.h>
44#include <sch_edit_frame.h> // SYMBOL_ORIENTATION_T
45#include <sch_group.h>
50#include <sch_junction.h>
51#include <sch_line.h>
52#include <sch_no_connect.h>
53#include <sch_pin.h>
54#include <sch_rule_area.h>
55#include <sch_screen.h>
56#include <sch_shape.h>
57#include <sch_sheet.h>
58#include <sch_sheet_pin.h>
59#include <sch_symbol.h>
60#include <sch_table.h>
61#include <sch_tablecell.h>
62#include <sch_text.h>
63#include <sch_textbox.h>
64#include <string_utils.h>
65#include <trace_helpers.h>
66#include <reporter.h>
67
68using namespace TSCHEMATIC_T;
69
70
71#define SCH_PARSE_ERROR( text, reader, pos ) \
72 THROW_PARSE_ERROR( text, reader.GetSource(), reader.Line(), \
73 reader.LineNumber(), pos - reader.Line() )
74
75
76SCH_IO_KICAD_SEXPR::SCH_IO_KICAD_SEXPR() : SCH_IO( wxS( "Eeschema s-expression" ) )
77{
78 init( nullptr );
79}
80
81
86
87
89 const std::map<std::string, UTF8>* aProperties )
90{
91 if( m_schematic != aSchematic )
92 m_loadedRootSheets.clear();
93
94 m_version = 0;
95 m_appending = false;
96 m_rootSheet = nullptr;
97 m_schematic = aSchematic;
98 m_cache = nullptr;
99 m_out = nullptr;
100}
101
102
103SCH_SHEET* SCH_IO_KICAD_SEXPR::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
104 SCH_SHEET* aAppendToMe,
105 const std::map<std::string, UTF8>* aProperties )
106{
107 wxASSERT( !aFileName || aSchematic != nullptr );
108
109 SCH_SHEET* sheet;
110
111 wxFileName fn = aFileName;
112
113 // Collect the font substitution warnings (RAII - automatically reset on scope exit)
115
116 // Unfortunately child sheet file names the legacy schematic file format are not fully
117 // qualified and are always appended to the project path. The aFileName attribute must
118 // always be an absolute path so the project path can be used for load child sheet files.
119 wxASSERT( fn.IsAbsolute() );
120
121 if( aAppendToMe )
122 {
123 m_appending = true;
124 wxLogTrace( traceSchPlugin, "Append \"%s\" to sheet \"%s\".",
125 aFileName, aAppendToMe->GetFileName() );
126
127 wxFileName normedFn = aAppendToMe->GetFileName();
128
129 if( !normedFn.IsAbsolute() )
130 {
131 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
132 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
133 }
134
135 if( m_path.IsEmpty() )
136 m_path = aSchematic->Project().GetProjectPath();
137
138 wxLogTrace( traceSchPlugin, "Normalized append path \"%s\".", m_path );
139 }
140 else
141 {
142 m_path = aSchematic->Project().GetProjectPath();
143 }
144
145 m_currentPath.push( m_path );
146 init( aSchematic, aProperties );
147
148 if( aAppendToMe == nullptr )
149 {
150 // Clean up any allocated memory if an exception occurs loading the schematic.
151 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
152
153 wxFileName relPath( aFileName );
154
155 // Do not use wxPATH_UNIX as option in MakeRelativeTo(). It can create incorrect
156 // relative paths on Windows, because paths have a disk identifier (C:, D: ...)
157 relPath.MakeRelativeTo( aSchematic->Project().GetProjectPath() );
158
159 newSheet->SetFileName( relPath.GetFullPath() );
160 m_rootSheet = newSheet.get();
161 loadHierarchy( SCH_SHEET_PATH(), newSheet.get() );
162
163 // If we got here, the schematic loaded successfully.
164 sheet = newSheet.release();
165 m_rootSheet = nullptr; // Quiet Coverity warning.
166 m_loadedRootSheets.push_back( sheet );
167 }
168 else
169 {
170 wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
171 m_rootSheet = &aSchematic->Root();
172 sheet = aAppendToMe;
173 loadHierarchy( SCH_SHEET_PATH(), sheet );
174 }
175
176 wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
177
178 m_currentPath.pop(); // Clear the path stack for next call to Load
179
180 return sheet;
181}
182
183
184// Everything below this comment is recursive. Modify with care.
185
186void SCH_IO_KICAD_SEXPR::loadHierarchy( const SCH_SHEET_PATH& aParentSheetPath, SCH_SHEET* aSheet )
187{
188 m_currentSheetPath.push_back( aSheet );
189
190 SCH_SCREEN* screen = nullptr;
191
192 if( !aSheet->GetScreen() )
193 {
194 // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
195 // stores the file name and extension. Add the project path to the file name and
196 // extension to compare when calling SCH_SHEET::SearchHierarchy().
197 wxFileName fileName = aSheet->GetFileName();
198
199 if( !fileName.IsAbsolute() )
200 fileName.MakeAbsolute( m_currentPath.top() );
201
202 // Save the current path so that it gets restored when descending and ascending the
203 // sheet hierarchy which allows for sheet schematic files to be nested in folders
204 // relative to the last path a schematic was loaded from.
205 wxLogTrace( traceSchPlugin, "Saving path '%s'", m_currentPath.top() );
206 m_currentPath.push( fileName.GetPath() );
207 wxLogTrace( traceSchPlugin, "Current path '%s'", m_currentPath.top() );
208 wxLogTrace( traceSchPlugin, "Loading '%s'", fileName.GetFullPath() );
209
210 SCH_SHEET_PATH ancestorSheetPath = aParentSheetPath;
211
212 while( !ancestorSheetPath.empty() )
213 {
214 if( ancestorSheetPath.LastScreen()->GetFileName() == fileName.GetFullPath() )
215 {
216 if( !m_error.IsEmpty() )
217 m_error += "\n";
218
219 m_error += wxString::Format( _( "Could not load sheet '%s' because it already "
220 "appears as a direct ancestor in the schematic "
221 "hierarchy." ),
222 fileName.GetFullPath() );
223
224 fileName = wxEmptyString;
225
226 break;
227 }
228
229 ancestorSheetPath.pop_back();
230 }
231
232 if( ancestorSheetPath.empty() )
233 {
234 // Existing schematics could be either in the root sheet path or the current sheet
235 // load path so we have to check both.
236 if( !m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen ) )
237 m_currentSheetPath.at( 0 )->SearchHierarchy( fileName.GetFullPath(), &screen );
238
239 // When loading multiple top-level sheets that reference the same sub-sheet file,
240 // the screen may have already been loaded by a previous top-level sheet.
241 if( !screen )
242 {
243 for( SCH_SHEET* prevRoot : m_loadedRootSheets )
244 {
245 if( prevRoot->SearchHierarchy( fileName.GetFullPath(), &screen ) )
246 break;
247 }
248 }
249 }
250
251 if( screen )
252 {
253 aSheet->SetScreen( screen );
254 aSheet->GetScreen()->SetParent( m_schematic );
255 // Do not need to load the sub-sheets - this has already been done.
256 }
257 else
258 {
259 aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
260 aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
261
262 try
263 {
264 loadFile( fileName.GetFullPath(), aSheet );
265 }
266 catch( const IO_ERROR& ioe )
267 {
268 // If there is a problem loading the root sheet, there is no recovery.
269 if( aSheet == m_rootSheet )
270 throw;
271
272 // For all subsheets, queue up the error message for the caller.
273 if( !m_error.IsEmpty() )
274 m_error += "\n";
275
276 m_error += ioe.What();
277 }
278
279 if( fileName.FileExists() )
280 {
281 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
282 aSheet->GetScreen()->SetFileExists( true );
283 }
284 else
285 {
286 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsDirWritable() );
287 aSheet->GetScreen()->SetFileExists( false );
288 }
289
290 SCH_SHEET_PATH currentSheetPath = aParentSheetPath;
291 currentSheetPath.push_back( aSheet );
292
293 // This was moved out of the try{} block so that any sheet definitions that
294 // the plugin fully parsed before the exception was raised will be loaded.
295 for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
296 {
297 wxCHECK2( aItem->Type() == SCH_SHEET_T, /* do nothing */ );
298 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
299
300 // Recursion starts here.
301 loadHierarchy( currentSheetPath, sheet );
302 }
303 }
304
305 m_currentPath.pop();
306 wxLogTrace( traceSchPlugin, "Restoring path \"%s\"", m_currentPath.top() );
307 }
308
309 m_currentSheetPath.pop_back();
310}
311
312
313void SCH_IO_KICAD_SEXPR::loadFile( const wxString& aFileName, SCH_SHEET* aSheet )
314{
315 FILE_LINE_READER reader( aFileName );
316
317 size_t lineCount = 0;
318
320 {
321 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
322
323 if( !m_progressReporter->KeepRefreshing() )
324 THROW_IO_ERROR( _( "Open canceled by user." ) );
325
326 while( reader.ReadLine() )
327 lineCount++;
328
329 reader.Rewind();
330 }
331
332 SCH_IO_KICAD_SEXPR_PARSER parser( &reader, m_progressReporter, lineCount, m_rootSheet,
333 m_appending );
334
335 parser.ParseSchematic( aSheet );
336}
337
338
339void SCH_IO_KICAD_SEXPR::LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet, int aFileVersion )
340{
341 wxCHECK( aSheet, /* void */ );
342
343 SCH_IO_KICAD_SEXPR_PARSER parser( &aReader );
344
345 parser.ParseSchematic( aSheet, true, aFileVersion );
346}
347
348
349void SCH_IO_KICAD_SEXPR::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet,
350 SCHEMATIC* aSchematic,
351 const std::map<std::string, UTF8>* aProperties )
352{
353 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
354 wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
355
356 wxString sanityResult = aSheet->GetScreen()->GroupsSanityCheck();
357
358 if( sanityResult != wxEmptyString && m_queryUserCallback )
359 {
360 if( !m_queryUserCallback( _( "Internal Group Data Error" ), wxICON_ERROR,
361 wxString::Format( _( "Please report this bug. Error validating group "
362 "structure: %s\n\nSave anyway?" ),
363 sanityResult ),
364 _( "Save Anyway" ) ) )
365 {
366 return;
367 }
368 }
369
370 wxFileName fn = aFileName;
371
372 // File names should be absolute. Don't assume everything relative to the project path
373 // works properly.
374 wxASSERT( fn.IsAbsolute() );
375
376 PRETTIFIED_FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
377 FormatSchematicToFormatter( &formatter, aSheet, aSchematic, aProperties );
378
379 if( aSheet->GetScreen() )
380 aSheet->GetScreen()->SetFileExists( true );
381}
382
383
385 SCHEMATIC* aSchematic,
386 const std::map<std::string, UTF8>* aProperties )
387{
388 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
389
390 init( aSchematic, aProperties );
391
392 m_out = aOut;
393
394 Format( aSheet );
395
396 m_out = nullptr;
397}
398
399
401{
402 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
403 wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
404
405 SCH_SHEET_LIST sheets = m_schematic->Hierarchy();
406 SCH_SCREEN* screen = aSheet->GetScreen();
407
408 wxCHECK( screen, /* void */ );
409
410 // If we've requested to embed the fonts in the schematic, do so.
411 // Otherwise, clear the embedded fonts from the schematic. Embedded
412 // fonts will be used if available
413 if( m_schematic->GetAreFontsEmbedded() )
414 m_schematic->EmbedFonts();
415 else
416 m_schematic->GetEmbeddedFiles()->ClearEmbeddedFonts();
417
418 m_out->Print( "(kicad_sch (version %d) (generator \"eeschema\") (generator_version %s)",
420 m_out->Quotew( GetMajorMinorVersion() ).c_str() );
421
423
424 screen->GetPageSettings().Format( m_out );
425 screen->GetTitleBlock().Format( m_out );
426
427 // Save cache library.
428 m_out->Print( "(lib_symbols" );
429
430 for( const auto& [ libItemName, libSymbol ] : screen->GetLibSymbols() )
431 SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( libSymbol, *m_out, libItemName );
432
433 m_out->Print( ")" );
434
435 // Enforce item ordering
436 auto cmp =
437 []( const SCH_ITEM* a, const SCH_ITEM* b )
438 {
439 if( a->Type() != b->Type() )
440 return a->Type() < b->Type();
441
442 return a->m_Uuid < b->m_Uuid;
443 };
444
445 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
446
447 for( SCH_ITEM* item : screen->Items() )
448 {
449 // Markers are not saved, so keep them from being considered below
450 if( item->Type() != SCH_MARKER_T )
451 save_map.insert( item );
452 }
453
454 for( SCH_ITEM* item : save_map )
455 {
456 switch( item->Type() )
457 {
458 case SCH_SYMBOL_T:
459 saveSymbol( static_cast<SCH_SYMBOL*>( item ), *m_schematic, sheets, false );
460 break;
461
462 case SCH_BITMAP_T:
463 saveBitmap( static_cast<SCH_BITMAP&>( *item ) );
464 break;
465
466 case SCH_SHEET_T:
467 saveSheet( static_cast<SCH_SHEET*>( item ), sheets );
468 break;
469
470 case SCH_JUNCTION_T:
471 saveJunction( static_cast<SCH_JUNCTION*>( item ) );
472 break;
473
474 case SCH_NO_CONNECT_T:
475 saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
476 break;
477
480 saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
481 break;
482
483 case SCH_LINE_T:
484 saveLine( static_cast<SCH_LINE*>( item ) );
485 break;
486
487 case SCH_SHAPE_T:
488 saveShape( static_cast<SCH_SHAPE*>( item ) );
489 break;
490
491 case SCH_RULE_AREA_T:
492 saveRuleArea( static_cast<SCH_RULE_AREA*>( item ) );
493 break;
494
495 case SCH_TEXT_T:
496 case SCH_LABEL_T:
498 case SCH_HIER_LABEL_T:
500 saveText( static_cast<SCH_TEXT*>( item ) );
501 break;
502
503 case SCH_TEXTBOX_T:
504 saveTextBox( static_cast<SCH_TEXTBOX*>( item ) );
505 break;
506
507 case SCH_TABLE_T:
508 saveTable( static_cast<SCH_TABLE*>( item ) );
509 break;
510
511 case SCH_GROUP_T:
512 saveGroup( static_cast<SCH_GROUP*>( item ) );
513 break;
514
515 default:
516 wxASSERT( "Unexpected schematic object type in SCH_IO_KICAD_SEXPR::Format()" );
517 }
518 }
519
520 if( aSheet->HasRootInstance() )
521 {
522 std::vector< SCH_SHEET_INSTANCE> instances;
523
524 instances.emplace_back( aSheet->GetRootInstance() );
525 saveInstances( instances );
526
527 KICAD_FORMAT::FormatBool( m_out, "embedded_fonts", m_schematic->GetAreFontsEmbedded() );
528
529 // Save any embedded files
530 if( !m_schematic->GetEmbeddedFiles()->IsEmpty() )
531 m_schematic->WriteEmbeddedFiles( *m_out, true );
532 }
533
534 m_out->Print( ")" );
535}
536
537
538void SCH_IO_KICAD_SEXPR::Format( SCH_SELECTION* aSelection, SCH_SHEET_PATH* aSelectionPath,
539 SCHEMATIC& aSchematic, OUTPUTFORMATTER* aFormatter,
540 bool aForClipboard )
541{
542 wxCHECK( aSelection && aSelectionPath && aFormatter, /* void */ );
543
544 SCH_SHEET_LIST sheets = aSchematic.Hierarchy();
545
546 m_schematic = &aSchematic;
547 m_out = aFormatter;
548
549 std::map<wxString, LIB_SYMBOL*> libSymbols;
550 SCH_SCREEN* screen = aSelection->GetScreen();
551 std::set<SCH_TABLE*> promotedTables;
552
553 for( EDA_ITEM* item : *aSelection )
554 {
555 if( item->Type() != SCH_SYMBOL_T )
556 continue;
557
558 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
559
560 wxString libSymbolLookup = symbol->GetLibId().Format().wx_str();
561
562 if( !symbol->UseLibIdLookup() )
563 libSymbolLookup = symbol->GetSchSymbolLibraryName();
564
565 auto it = screen->GetLibSymbols().find( libSymbolLookup );
566
567 if( it != screen->GetLibSymbols().end() )
568 libSymbols[ libSymbolLookup ] = it->second;
569 }
570
571 if( !libSymbols.empty() )
572 {
573 m_out->Print( "(lib_symbols" );
574
575 for( const auto& [name, libSymbol] : libSymbols )
577
578 m_out->Print( ")" );
579 }
580
581 for( EDA_ITEM* edaItem : *aSelection )
582 {
583 if( !edaItem->IsSCH_ITEM() )
584 continue;
585
586 SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
587
588 switch( item->Type() )
589 {
590 case SCH_SYMBOL_T:
591 saveSymbol( static_cast<SCH_SYMBOL*>( item ), aSchematic, sheets, aForClipboard, aSelectionPath );
592 break;
593
594 case SCH_BITMAP_T:
595 saveBitmap( static_cast<SCH_BITMAP&>( *item ) );
596 break;
597
598 case SCH_SHEET_T:
599 saveSheet( static_cast<SCH_SHEET*>( item ), sheets );
600 break;
601
602 case SCH_JUNCTION_T:
603 saveJunction( static_cast<SCH_JUNCTION*>( item ) );
604 break;
605
606 case SCH_NO_CONNECT_T:
607 saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
608 break;
609
612 saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
613 break;
614
615 case SCH_LINE_T:
616 saveLine( static_cast<SCH_LINE*>( item ) );
617 break;
618
619 case SCH_SHAPE_T:
620 saveShape( static_cast<SCH_SHAPE*>( item ) );
621 break;
622
623 case SCH_RULE_AREA_T:
624 saveRuleArea( static_cast<SCH_RULE_AREA*>( item ) );
625 break;
626
627 case SCH_TEXT_T:
628 case SCH_LABEL_T:
630 case SCH_HIER_LABEL_T:
632 saveText( static_cast<SCH_TEXT*>( item ) );
633 break;
634
635 case SCH_TEXTBOX_T:
636 saveTextBox( static_cast<SCH_TEXTBOX*>( item ) );
637 break;
638
639 case SCH_TABLECELL_T:
640 {
641 SCH_TABLE* table = static_cast<SCH_TABLE*>( item->GetParent() );
642
643 if( promotedTables.count( table ) )
644 break;
645
646 table->SetFlags( SKIP_STRUCT );
647 saveTable( table );
648 table->ClearFlags( SKIP_STRUCT );
649 promotedTables.insert( table );
650 break;
651 }
652
653 case SCH_TABLE_T:
654 item->ClearFlags( SKIP_STRUCT );
655 saveTable( static_cast<SCH_TABLE*>( item ) );
656 break;
657
658 case SCH_GROUP_T:
659 saveGroup( static_cast<SCH_GROUP*>( item ) );
660 break;
661
662 default:
663 wxASSERT( "Unexpected schematic object type in SCH_IO_KICAD_SEXPR::Format()" );
664 }
665 }
666}
667
668
669void SCH_IO_KICAD_SEXPR::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchematic,
670 const SCH_SHEET_LIST& aSheetList, bool aForClipboard,
671 const SCH_SHEET_PATH* aRelativePath )
672{
673 wxCHECK_RET( aSymbol != nullptr && m_out != nullptr, "" );
674
675 std::string libName;
676
677 wxString symbol_name = aSymbol->GetLibId().Format();
678
679 if( symbol_name.size() )
680 {
681 libName = toUTFTildaText( symbol_name );
682 }
683 else
684 {
685 libName = "_NONAME_";
686 }
687
688 EDA_ANGLE angle;
689 int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
690
691 if( orientation == SYM_ORIENT_90 )
692 angle = ANGLE_90;
693 else if( orientation == SYM_ORIENT_180 )
694 angle = ANGLE_180;
695 else if( orientation == SYM_ORIENT_270 )
696 angle = ANGLE_270;
697 else
698 angle = ANGLE_0;
699
700 m_out->Print( "(symbol" );
701
702 if( !aSymbol->UseLibIdLookup() )
703 {
704 m_out->Print( "(lib_name %s)",
705 m_out->Quotew( aSymbol->GetSchSymbolLibraryName() ).c_str() );
706 }
707
708 m_out->Print( "(lib_id %s) (at %s %s %s)",
709 m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
711 aSymbol->GetPosition().x ).c_str(),
713 aSymbol->GetPosition().y ).c_str(),
714 EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
715
716 bool mirrorX = aSymbol->GetOrientation() & SYM_MIRROR_X;
717 bool mirrorY = aSymbol->GetOrientation() & SYM_MIRROR_Y;
718
719 if( mirrorX || mirrorY )
720 {
721 m_out->Print( "(mirror %s %s)",
722 mirrorX ? "x" : "",
723 mirrorY ? "y" : "" );
724 }
725
726 // The symbol unit is always set to the ordianal instance regardless of the current sheet
727 // instance to prevent file churn.
728 SCH_SYMBOL_INSTANCE ordinalInstance;
729
730 ordinalInstance.m_Reference = aSymbol->GetPrefix();
731
732 const SCH_SCREEN* parentScreen = static_cast<const SCH_SCREEN*>( aSymbol->GetParent() );
733
734 wxASSERT( parentScreen );
735
736 if( parentScreen && m_schematic )
737 {
738 std::optional<SCH_SHEET_PATH> ordinalPath =
739 m_schematic->Hierarchy().GetOrdinalPath( parentScreen );
740
741 // Design blocks are saved from a temporary sheet & screen which will not be found in
742 // the schematic, and will therefore have no ordinal path.
743 // wxASSERT( ordinalPath );
744
745 if( ordinalPath )
746 aSymbol->GetInstance( ordinalInstance, ordinalPath->Path() );
747 else if( aSymbol->GetInstances().size() )
748 ordinalInstance = aSymbol->GetInstances()[0];
749 }
750
751 int unit = ordinalInstance.m_Unit;
752
753 if( aForClipboard && aRelativePath )
754 {
755 SCH_SYMBOL_INSTANCE unitInstance;
756
757 if( aSymbol->GetInstance( unitInstance, aRelativePath->Path() ) )
758 unit = unitInstance.m_Unit;
759 }
760
761 m_out->Print( "(unit %d)", unit );
762 m_out->Print( "(body_style %d)", aSymbol->GetBodyStyle() );
763
764 KICAD_FORMAT::FormatBool( m_out, "exclude_from_sim", aSymbol->GetExcludedFromSim() );
765 KICAD_FORMAT::FormatBool( m_out, "in_bom", !aSymbol->GetExcludedFromBOM() );
766 KICAD_FORMAT::FormatBool( m_out, "on_board", !aSymbol->GetExcludedFromBoard() );
767 KICAD_FORMAT::FormatBool( m_out, "in_pos_files", !aSymbol->GetExcludedFromPosFiles() );
768 KICAD_FORMAT::FormatBool( m_out, "dnp", aSymbol->GetDNP() );
769
770 if( aSymbol->IsLocked() )
771 KICAD_FORMAT::FormatBool( m_out, "locked", true );
772
773 AUTOPLACE_ALGO fieldsAutoplaced = aSymbol->GetFieldsAutoplaced();
774
775 if( fieldsAutoplaced == AUTOPLACE_AUTO || fieldsAutoplaced == AUTOPLACE_MANUAL )
776 KICAD_FORMAT::FormatBool( m_out, "fields_autoplaced", true );
777
779
780 std::vector<SCH_FIELD*> orderedFields;
781 aSymbol->GetFields( orderedFields, false );
782
783 for( SCH_FIELD* field : orderedFields )
784 {
785 FIELD_T id = field->GetId();
786 wxString value = field->GetText();
787
788 if( !aForClipboard && aSymbol->GetInstances().size() )
789 {
790 // The instance fields are always set to the default instance regardless of the
791 // sheet instance to prevent file churn.
792 if( id == FIELD_T::REFERENCE )
793 field->SetText( ordinalInstance.m_Reference );
794 }
795 else if( aForClipboard && aSymbol->GetInstances().size() && aRelativePath
796 && ( id == FIELD_T::REFERENCE ) )
797 {
798 SCH_SYMBOL_INSTANCE instance;
799
800 if( aSymbol->GetInstance( instance, aRelativePath->Path() ) )
801 field->SetText( instance.m_Reference );
802 }
803
804 try
805 {
806 saveField( field );
807 }
808 catch( ... )
809 {
810 // Restore the changed field text on write error.
811 if( id == FIELD_T::REFERENCE )
812 field->SetText( value );
813
814 throw;
815 }
816
817 if( id == FIELD_T::REFERENCE )
818 field->SetText( value );
819 }
820
821 for( const std::unique_ptr<SCH_PIN>& pin : aSymbol->GetRawPins() )
822 {
823 // There was a bug introduced somewhere in the original alternated pin code that would
824 // set the alternate pin to the default pin name which caused a number of library symbol
825 // comparison issues. Clearing the alternate pin resolves this issue.
826 if( pin->GetAlt().IsEmpty() || ( pin->GetAlt() == pin->GetBaseName() ) )
827 {
828 m_out->Print( "(pin %s", m_out->Quotew( pin->GetNumber() ).c_str() );
830 m_out->Print( ")" );
831 }
832 else
833 {
834 m_out->Print( "(pin %s", m_out->Quotew( pin->GetNumber() ).c_str() );
836 m_out->Print( "(alternate %s))", m_out->Quotew( pin->GetAlt() ).c_str() );
837 }
838 }
839
840 if( !aSymbol->GetInstances().empty() )
841 {
842 std::map<KIID, std::vector<SCH_SYMBOL_INSTANCE>> projectInstances;
843 std::set<KIID> currentProjectKeys;
844
845 m_out->Print( "(instances" );
846
847 wxString projectName;
848 KIID rootSheetUuid = aSchematic.Root().m_Uuid;
849
850 // Collect top-level sheet UUIDs to identify current project instances.
851 // When root is virtual (niluuid), Path() skips it, so instance paths
852 // start with the real top-level sheet UUID, not niluuid.
853
854 if( rootSheetUuid == niluuid )
855 {
856 for( const SCH_SHEET* sheet : aSchematic.GetTopLevelSheets() )
857 currentProjectKeys.insert( sheet->m_Uuid );
858 }
859 else
860 {
861 currentProjectKeys.insert( rootSheetUuid );
862 }
863
864 for( const SCH_SYMBOL_INSTANCE& inst : aSymbol->GetInstances() )
865 {
866 // Zero length KIID_PATH objects are not valid and will cause a crash below.
867 wxCHECK2( inst.m_Path.size(), continue );
868
869 // If the instance data is part of this design but no longer has an associated sheet
870 // path, don't save it. This prevents large amounts of orphaned instance data for the
871 // current project from accumulating in the schematic files.
872 //
873 // The root sheet UUID can be niluuid for the virtual root. In that case, instance
874 // paths may include the virtual root, but SCH_SHEET_PATH::Path() skips it. We need
875 // to normalize the path by removing the virtual root before comparison.
876 KIID_PATH pathToCheck = inst.m_Path;
877
878 // If root is virtual (niluuid) and path starts with virtual root, strip it
879 if( rootSheetUuid == niluuid && !pathToCheck.empty() && pathToCheck[0] == niluuid )
880 {
881 if( pathToCheck.size() > 1 )
882 {
883 pathToCheck.erase( pathToCheck.begin() );
884 }
885 else
886 {
887 // Path only contains virtual root, skip it
888 continue;
889 }
890 }
891
892 // Check if this instance is orphaned (no matching sheet path)
893 // For virtual root, we check if the first real sheet matches one of the top-level sheets
894 // For non-virtual root, we check if it matches the root sheet UUID
895 bool belongsToThisProject = currentProjectKeys.count( pathToCheck[0] );
896
897 bool isOrphaned = belongsToThisProject && !aSheetList.GetSheetPathByKIIDPath( pathToCheck );
898
899 // Keep all instance data when copying to the clipboard. They may be needed on paste.
900 if( !aForClipboard && isOrphaned )
901 continue;
902
903 // Group by project - use the first real sheet KIID (after stripping virtual root)
904 KIID projectKey = pathToCheck[0];
905 auto it = projectInstances.find( projectKey );
906
907 if( it == projectInstances.end() )
908 projectInstances[ projectKey ] = { inst };
909 else
910 it->second.emplace_back( inst );
911 }
912
913 for( auto& [uuid, instances] : projectInstances )
914 {
915 wxCHECK2( instances.size(), continue );
916
917 // Sort project instances by KIID_PATH.
918 std::sort( instances.begin(), instances.end(),
920 {
921 return aLhs.m_Path < aRhs.m_Path;
922 } );
923
924 if( currentProjectKeys.count( uuid ) )
925 projectName = m_schematic->Project().GetProjectName();
926 else
927 projectName = instances[0].m_ProjectName;
928
929 m_out->Print( "(project %s", m_out->Quotew( projectName ).c_str() );
930
931 for( const SCH_SYMBOL_INSTANCE& instance : instances )
932 {
933 wxString path;
934 KIID_PATH tmp = instance.m_Path;
935
936 if( aForClipboard && aRelativePath )
937 tmp.MakeRelativeTo( aRelativePath->Path() );
938
939 path = tmp.AsString();
940
941 m_out->Print( "(path %s (reference %s) (unit %d)",
942 m_out->Quotew( path ).c_str(),
943 m_out->Quotew( instance.m_Reference ).c_str(),
944 instance.m_Unit );
945
946 if( !instance.m_Variants.empty() )
947 {
948 for( const auto&[name, variant] : instance.m_Variants )
949 {
950 m_out->Print( "(variant (name %s)", m_out->Quotew( name ).c_str() );
951
952 if( variant.m_DNP != aSymbol->GetDNP() )
953 KICAD_FORMAT::FormatBool( m_out, "dnp", variant.m_DNP );
954
955 if( variant.m_ExcludedFromSim != aSymbol->GetExcludedFromSim() )
956 KICAD_FORMAT::FormatBool( m_out, "exclude_from_sim", variant.m_ExcludedFromSim );
957
958 if( variant.m_ExcludedFromBOM != aSymbol->GetExcludedFromBOM() )
959 KICAD_FORMAT::FormatBool( m_out, "in_bom", !variant.m_ExcludedFromBOM );
960
961 if( variant.m_ExcludedFromBoard != aSymbol->GetExcludedFromBoard() )
962 KICAD_FORMAT::FormatBool( m_out, "on_board", !variant.m_ExcludedFromBoard );
963
964 if( variant.m_ExcludedFromPosFiles != aSymbol->GetExcludedFromPosFiles() )
965 KICAD_FORMAT::FormatBool( m_out, "in_pos_files", !variant.m_ExcludedFromPosFiles );
966
967 for( const auto&[fname, fvalue] : variant.m_Fields )
968 {
969 m_out->Print( "(field (name %s) (value %s))",
970 m_out->Quotew( fname ).c_str(), m_out->Quotew( fvalue ).c_str() );
971 }
972
973 m_out->Print( ")" ); // Closes `variant` token.
974 }
975 }
976
977 m_out->Print( ")" ); // Closes `path` token.
978 }
979
980 m_out->Print( ")" ); // Closes `project`.
981 }
982
983 m_out->Print( ")" ); // Closes `instances`.
984 }
985
986 m_out->Print( ")" ); // Closes `symbol`.
987}
988
989
991{
992 wxCHECK_RET( aField != nullptr && m_out != nullptr, "" );
993
994 wxString fieldName;
995
996 if( aField->IsMandatory() )
997 fieldName = aField->GetCanonicalName();
998 else
999 fieldName = aField->GetName();
1000
1001 m_out->Print( "(property %s %s %s (at %s %s %s)",
1002 aField->IsPrivate() ? "private" : "",
1003 m_out->Quotew( fieldName ).c_str(),
1004 m_out->Quotew( aField->GetText() ).c_str(),
1006 aField->GetPosition().x ).c_str(),
1008 aField->GetPosition().y ).c_str(),
1009 EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() );
1010
1011 if( !aField->IsVisible() )
1012 KICAD_FORMAT::FormatBool( m_out, "hide", true );
1013
1014 KICAD_FORMAT::FormatBool( m_out, "show_name", aField->IsNameShown() );
1015
1016 KICAD_FORMAT::FormatBool( m_out, "do_not_autoplace", !aField->CanAutoplace() );
1017
1018 if( !aField->IsDefaultFormatting()
1019 || ( aField->GetTextHeight() != schIUScale.MilsToIU( DEFAULT_SIZE_TEXT ) ) )
1020 {
1021 aField->Format( m_out, 0 );
1022 }
1023
1024 m_out->Print( ")" ); // Closes `property` token
1025}
1026
1027
1029{
1030 wxCHECK_RET( m_out != nullptr, "" );
1031
1032 const REFERENCE_IMAGE& refImage = aBitmap.GetReferenceImage();
1033 const BITMAP_BASE& bitmapBase = refImage.GetImage();
1034
1035 const wxImage* image = bitmapBase.GetImageData();
1036
1037 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
1038
1039 m_out->Print( "(image (at %s %s)",
1041 refImage.GetPosition().x ).c_str(),
1043 refImage.GetPosition().y ).c_str() );
1044
1045 double scale = refImage.GetImageScale();
1046
1047 // 20230121 or older file format versions assumed 300 image PPI at load/save.
1048 // Let's keep compatibility by changing image scale.
1049 if( SEXPR_SCHEMATIC_FILE_VERSION <= 20230121 )
1050 scale = scale * 300.0 / bitmapBase.GetPPI();
1051
1052 if( scale != 1.0 )
1053 m_out->Print( "%s", fmt::format("(scale {:g})", refImage.GetImageScale()).c_str() );
1054
1056
1057 if( aBitmap.IsLocked() )
1058 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1059
1060 wxMemoryOutputStream stream;
1061 bitmapBase.SaveImageData( stream );
1062
1063 KICAD_FORMAT::FormatStreamData( *m_out, *stream.GetOutputStreamBuffer() );
1064
1065 m_out->Print( ")" ); // Closes image token.
1066}
1067
1068
1070{
1071 wxCHECK_RET( aSheet != nullptr && m_out != nullptr, "" );
1072
1073 m_out->Print( "(sheet (at %s %s) (size %s %s)",
1075 aSheet->GetPosition().x ).c_str(),
1077 aSheet->GetPosition().y ).c_str(),
1079 aSheet->GetSize().x ).c_str(),
1081 aSheet->GetSize().y ).c_str() );
1082
1083 KICAD_FORMAT::FormatBool( m_out, "exclude_from_sim", aSheet->GetExcludedFromSim() );
1084 KICAD_FORMAT::FormatBool( m_out, "in_bom", !aSheet->GetExcludedFromBOM() );
1085 KICAD_FORMAT::FormatBool( m_out, "on_board", !aSheet->GetExcludedFromBoard() );
1086 KICAD_FORMAT::FormatBool( m_out, "dnp", aSheet->GetDNP() );
1087
1088 if( aSheet->IsLocked() )
1089 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1090
1091 AUTOPLACE_ALGO fieldsAutoplaced = aSheet->GetFieldsAutoplaced();
1092
1093 if( fieldsAutoplaced == AUTOPLACE_AUTO || fieldsAutoplaced == AUTOPLACE_MANUAL )
1094 KICAD_FORMAT::FormatBool( m_out, "fields_autoplaced", true );
1095
1096 STROKE_PARAMS stroke( aSheet->GetBorderWidth(), LINE_STYLE::SOLID, aSheet->GetBorderColor() );
1097
1098 stroke.SetWidth( aSheet->GetBorderWidth() );
1099 stroke.Format( m_out, schIUScale );
1100
1101 m_out->Print( "(fill (color %d %d %d %s))",
1102 KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
1103 KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
1104 KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
1105 FormatDouble2Str( aSheet->GetBackgroundColor().a ).c_str() );
1106
1108
1109 for( SCH_FIELD& field : aSheet->GetFields() )
1110 saveField( &field );
1111
1112 for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1113 {
1114 m_out->Print( "(pin %s %s (at %s %s %s)",
1115 EscapedUTF8( pin->GetText() ).c_str(),
1116 getSheetPinShapeToken( pin->GetShape() ),
1118 pin->GetPosition().x ).c_str(),
1120 pin->GetPosition().y ).c_str(),
1121 EDA_UNIT_UTILS::FormatAngle( getSheetPinAngle( pin->GetSide() ) ).c_str() );
1122
1124
1125 pin->Format( m_out, 0 );
1126
1127 m_out->Print( ")" ); // Closes pin token.
1128 }
1129
1130 // Save all sheet instances here except the root sheet instance.
1131 std::vector< SCH_SHEET_INSTANCE > sheetInstances = aSheet->GetInstances();
1132
1133 auto it = sheetInstances.begin();
1134
1135 while( it != sheetInstances.end() )
1136 {
1137 if( it->m_Path.size() == 0 )
1138 it = sheetInstances.erase( it );
1139 else
1140 it++;
1141 }
1142
1143 if( !sheetInstances.empty() )
1144 {
1145 m_out->Print( "(instances" );
1146
1147 KIID lastProjectUuid;
1148 KIID rootSheetUuid = m_schematic->Root().m_Uuid;
1149 bool inProjectClause = false;
1150
1151 std::set<KIID> currentProjectKeys;
1152
1153 if( rootSheetUuid == niluuid )
1154 {
1155 for( const SCH_SHEET* sheet : m_schematic->GetTopLevelSheets() )
1156 currentProjectKeys.insert( sheet->m_Uuid );
1157 }
1158 else
1159 {
1160 currentProjectKeys.insert( rootSheetUuid );
1161 }
1162
1163 for( size_t i = 0; i < sheetInstances.size(); i++ )
1164 {
1165 // If the instance data is part of this design but no longer has an associated sheet
1166 // path, don't save it. This prevents large amounts of orphaned instance data for the
1167 // current project from accumulating in the schematic files.
1168 //
1169 // Keep all instance data when copying to the clipboard. It may be needed on paste.
1170 bool belongsToThisProject =
1171 !sheetInstances[i].m_Path.empty() && currentProjectKeys.count( sheetInstances[i].m_Path[0] );
1172
1173 if( belongsToThisProject && !aSheetList.GetSheetPathByKIIDPath( sheetInstances[i].m_Path, false ) )
1174 {
1175 if( inProjectClause && ( ( i + 1 == sheetInstances.size() )
1176 || lastProjectUuid != sheetInstances[i+1].m_Path[0] ) )
1177 {
1178 m_out->Print( ")" ); // Closes `project` token.
1179 inProjectClause = false;
1180 }
1181
1182 continue;
1183 }
1184
1185 if( lastProjectUuid != sheetInstances[i].m_Path[0] )
1186 {
1187 wxString projectName;
1188
1189 if( belongsToThisProject )
1190 projectName = m_schematic->Project().GetProjectName();
1191 else
1192 projectName = sheetInstances[i].m_ProjectName;
1193
1194 lastProjectUuid = sheetInstances[i].m_Path[0];
1195 m_out->Print( "(project %s", m_out->Quotew( projectName ).c_str() );
1196 inProjectClause = true;
1197 }
1198
1199 wxString path = sheetInstances[i].m_Path.AsString();
1200
1201 m_out->Print( "(path %s (page %s)",
1202 m_out->Quotew( path ).c_str(),
1203 m_out->Quotew( sheetInstances[i].m_PageNumber ).c_str() );
1204
1205 if( !sheetInstances[i].m_Variants.empty() )
1206 {
1207 for( const auto&[name, variant] : sheetInstances[i].m_Variants )
1208 {
1209 m_out->Print( "(variant (name %s)", m_out->Quotew( name ).c_str() );
1210
1211 if( variant.m_DNP != aSheet->GetDNP() )
1212 KICAD_FORMAT::FormatBool( m_out, "dnp", variant.m_DNP );
1213
1214 if( variant.m_ExcludedFromSim != aSheet->GetExcludedFromSim() )
1215 KICAD_FORMAT::FormatBool( m_out, "exclude_from_sim", variant.m_ExcludedFromSim );
1216
1217 if( variant.m_ExcludedFromBOM != aSheet->GetExcludedFromBOM() )
1218 KICAD_FORMAT::FormatBool( m_out, "in_bom", !variant.m_ExcludedFromBOM );
1219
1220 for( const auto&[fname, fvalue] : variant.m_Fields )
1221 {
1222 m_out->Print( "(field (name %s) (value %s))",
1223 m_out->Quotew( fname ).c_str(), m_out->Quotew( fvalue ).c_str() );
1224 }
1225
1226 m_out->Print( ")" ); // Closes `variant` token.
1227 }
1228 }
1229
1230 m_out->Print( ")" ); // Closes `path` token.
1231
1232 if( inProjectClause && ( ( i + 1 == sheetInstances.size() )
1233 || lastProjectUuid != sheetInstances[i+1].m_Path[0] ) )
1234 {
1235 m_out->Print( ")" ); // Closes `project` token.
1236 inProjectClause = false;
1237 }
1238 }
1239
1240 m_out->Print( ")" ); // Closes `instances` token.
1241 }
1242
1243 m_out->Print( ")" ); // Closes sheet token.
1244}
1245
1246
1248{
1249 wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" );
1250
1251 m_out->Print( "(junction (at %s %s) (diameter %s) (color %d %d %d %s)",
1253 aJunction->GetPosition().x ).c_str(),
1255 aJunction->GetPosition().y ).c_str(),
1257 aJunction->GetDiameter() ).c_str(),
1258 KiROUND( aJunction->GetColor().r * 255.0 ),
1259 KiROUND( aJunction->GetColor().g * 255.0 ),
1260 KiROUND( aJunction->GetColor().b * 255.0 ),
1261 FormatDouble2Str( aJunction->GetColor().a ).c_str() );
1262
1263 KICAD_FORMAT::FormatUuid( m_out, aJunction->m_Uuid );
1264
1265 if( aJunction->IsLocked() )
1266 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1267
1268 m_out->Print( ")" );
1269}
1270
1271
1273{
1274 wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
1275
1276 m_out->Print( "(no_connect (at %s %s)",
1278 aNoConnect->GetPosition().x ).c_str(),
1280 aNoConnect->GetPosition().y ).c_str() );
1281
1282 KICAD_FORMAT::FormatUuid( m_out, aNoConnect->m_Uuid );
1283
1284 if( aNoConnect->IsLocked() )
1285 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1286
1287 m_out->Print( ")" );
1288}
1289
1290
1292{
1293 wxCHECK_RET( aBusEntry != nullptr && m_out != nullptr, "" );
1294
1295 // Bus to bus entries are converted to bus line segments.
1296 if( aBusEntry->GetClass() == "SCH_BUS_BUS_ENTRY" )
1297 {
1298 SCH_LINE busEntryLine( aBusEntry->GetPosition(), LAYER_BUS );
1299
1300 busEntryLine.SetEndPoint( aBusEntry->GetEnd() );
1301 saveLine( &busEntryLine );
1302 return;
1303 }
1304
1305 m_out->Print( "(bus_entry (at %s %s) (size %s %s)",
1307 aBusEntry->GetPosition().x ).c_str(),
1309 aBusEntry->GetPosition().y ).c_str(),
1311 aBusEntry->GetSize().x ).c_str(),
1313 aBusEntry->GetSize().y ).c_str() );
1314
1315 aBusEntry->GetStroke().Format( m_out, schIUScale );
1316 KICAD_FORMAT::FormatUuid( m_out, aBusEntry->m_Uuid );
1317
1318 if( aBusEntry->IsLocked() )
1319 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1320
1321 m_out->Print( ")" );
1322}
1323
1324
1326{
1327 wxCHECK_RET( aShape != nullptr && m_out != nullptr, "" );
1328
1329 // Rule areas handle locked at their own level via saveRuleArea(), so don't duplicate it
1330 // inside the shape sub-expression.
1331 bool writeLocked = aShape->Type() != SCH_RULE_AREA_T && aShape->IsLocked();
1332
1333 switch( aShape->GetShape() )
1334 {
1335 case SHAPE_T::ARC:
1336 formatArc( m_out, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1337 aShape->GetFillColor(), false, aShape->m_Uuid, writeLocked );
1338 break;
1339
1340 case SHAPE_T::CIRCLE:
1341 formatCircle( m_out, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1342 aShape->GetFillColor(), false, aShape->m_Uuid, writeLocked );
1343 break;
1344
1345 case SHAPE_T::RECTANGLE:
1346 formatRect( m_out, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1347 aShape->GetFillColor(), false, aShape->m_Uuid, writeLocked );
1348 break;
1349
1350 case SHAPE_T::BEZIER:
1351 formatBezier( m_out, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1352 aShape->GetFillColor(), false, aShape->m_Uuid, writeLocked );
1353 break;
1354
1355 case SHAPE_T::POLY:
1356 formatPoly( m_out, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1357 aShape->GetFillColor(), false, aShape->m_Uuid, writeLocked );
1358 break;
1359
1360 default:
1362 }
1363}
1364
1365
1367{
1368 wxCHECK_RET( aRuleArea != nullptr && m_out != nullptr, "" );
1369
1370 m_out->Print( "(rule_area " );
1371
1372 if( aRuleArea->IsLocked() )
1373 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1374
1375 KICAD_FORMAT::FormatBool( m_out, "exclude_from_sim", aRuleArea->GetExcludedFromSim() );
1376 KICAD_FORMAT::FormatBool( m_out, "in_bom", !aRuleArea->GetExcludedFromBOM() );
1377 KICAD_FORMAT::FormatBool( m_out, "on_board", !aRuleArea->GetExcludedFromBoard() );
1378 KICAD_FORMAT::FormatBool( m_out, "dnp", aRuleArea->GetDNP() );
1379
1380 saveShape( aRuleArea );
1381
1382 m_out->Print( ")" );
1383}
1384
1385
1387{
1388 wxCHECK_RET( aLine != nullptr && m_out != nullptr, "" );
1389
1390 wxString lineType;
1391
1392 STROKE_PARAMS line_stroke = aLine->GetStroke();
1393
1394 switch( aLine->GetLayer() )
1395 {
1396 case LAYER_BUS: lineType = "bus"; break;
1397 case LAYER_WIRE: lineType = "wire"; break;
1398 case LAYER_NOTES: lineType = "polyline"; break;
1399 default:
1400 UNIMPLEMENTED_FOR( LayerName( aLine->GetLayer() ) );
1401 }
1402
1403 m_out->Print( "(%s (pts (xy %s %s) (xy %s %s))",
1404 TO_UTF8( lineType ),
1406 aLine->GetStartPoint().x ).c_str(),
1408 aLine->GetStartPoint().y ).c_str(),
1410 aLine->GetEndPoint().x ).c_str(),
1412 aLine->GetEndPoint().y ).c_str() );
1413
1414 line_stroke.Format( m_out, schIUScale );
1416
1417 if( aLine->IsLocked() )
1418 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1419
1420 m_out->Print( ")" );
1421}
1422
1423
1425{
1426 wxCHECK_RET( aText != nullptr && m_out != nullptr, "" );
1427
1428 // Note: label is nullptr SCH_TEXT, but not for SCH_LABEL_XXX,
1429 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aText );
1430
1431 m_out->Print( "(%s %s",
1432 getTextTypeToken( aText->Type() ),
1433 m_out->Quotew( aText->GetText() ).c_str() );
1434
1435 if( aText->Type() == SCH_TEXT_T )
1436 KICAD_FORMAT::FormatBool( m_out, "exclude_from_sim", aText->GetExcludedFromSim() );
1437
1438 if( aText->Type() == SCH_DIRECTIVE_LABEL_T )
1439 {
1440 SCH_DIRECTIVE_LABEL* flag = static_cast<SCH_DIRECTIVE_LABEL*>( aText );
1441
1442 m_out->Print( "(length %s)",
1444 flag->GetPinLength() ).c_str() );
1445 }
1446
1447 EDA_ANGLE angle = aText->GetTextAngle();
1448
1449 if( label )
1450 {
1451 if( label->Type() == SCH_GLOBAL_LABEL_T
1452 || label->Type() == SCH_HIER_LABEL_T
1453 || label->Type() == SCH_DIRECTIVE_LABEL_T )
1454 {
1455 m_out->Print( "(shape %s)", getSheetPinShapeToken( label->GetShape() ) );
1456 }
1457
1458 // The angle of the text is always 0 or 90 degrees for readibility reasons,
1459 // but the item itself can have more rotation (-90 and 180 deg)
1460 switch( label->GetSpinStyle() )
1461 {
1462 default:
1463 case SPIN_STYLE::LEFT: angle += ANGLE_180; break;
1464 case SPIN_STYLE::UP: break;
1465 case SPIN_STYLE::RIGHT: break;
1466 case SPIN_STYLE::BOTTOM: angle += ANGLE_180; break;
1467 }
1468 }
1469
1470 m_out->Print( "(at %s %s %s)",
1472 aText->GetPosition().x ).c_str(),
1474 aText->GetPosition().y ).c_str(),
1475 EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
1476
1477 if( label && !label->GetFields().empty() )
1478 {
1479 AUTOPLACE_ALGO fieldsAutoplaced = label->GetFieldsAutoplaced();
1480
1481 if( fieldsAutoplaced == AUTOPLACE_AUTO || fieldsAutoplaced == AUTOPLACE_MANUAL )
1482 KICAD_FORMAT::FormatBool( m_out, "fields_autoplaced", true );
1483 }
1484
1485 aText->EDA_TEXT::Format( m_out, 0 );
1487
1488 if( aText->IsLocked() )
1489 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1490
1491 if( label )
1492 {
1493 for( SCH_FIELD& field : label->GetFields() )
1494 saveField( &field );
1495 }
1496
1497 m_out->Print( ")" ); // Closes text token.
1498}
1499
1500
1502{
1503 wxCHECK_RET( aTextBox != nullptr && m_out != nullptr, "" );
1504
1505 m_out->Print( "(%s %s",
1506 aTextBox->Type() == SCH_TABLECELL_T ? "table_cell" : "text_box",
1507 m_out->Quotew( aTextBox->GetText() ).c_str() );
1508
1509 KICAD_FORMAT::FormatBool( m_out, "exclude_from_sim", aTextBox->GetExcludedFromSim() );
1510
1511 VECTOR2I pos = aTextBox->GetStart();
1512 VECTOR2I size = aTextBox->GetEnd() - pos;
1513
1514 m_out->Print( "(at %s %s %s) (size %s %s) (margins %s %s %s %s)",
1517 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
1524
1525 if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( aTextBox ) )
1526 m_out->Print( "(span %d %d)", cell->GetColSpan(), cell->GetRowSpan() );
1527
1528 if( aTextBox->Type() != SCH_TABLECELL_T )
1529 aTextBox->GetStroke().Format( m_out, schIUScale );
1530
1531 formatFill( m_out, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
1532 aTextBox->EDA_TEXT::Format( m_out, 0 );
1534
1535 if( aTextBox->IsLocked() )
1536 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1537
1538 m_out->Print( ")" );
1539}
1540
1541
1543{
1544 if( aTable->GetFlags() & SKIP_STRUCT )
1545 {
1546 aTable = static_cast<SCH_TABLE*>( aTable->Clone() );
1547
1548 int minCol = aTable->GetColCount();
1549 int maxCol = -1;
1550 int minRow = aTable->GetRowCount();
1551 int maxRow = -1;
1552
1553 for( int row = 0; row < aTable->GetRowCount(); ++row )
1554 {
1555 for( int col = 0; col < aTable->GetColCount(); ++col )
1556 {
1557 SCH_TABLECELL* cell = aTable->GetCell( row, col );
1558
1559 if( cell->IsSelected() )
1560 {
1561 minRow = std::min( minRow, row );
1562 maxRow = std::max( maxRow, row );
1563 minCol = std::min( minCol, col );
1564 maxCol = std::max( maxCol, col );
1565 }
1566 else
1567 {
1568 cell->SetFlags( STRUCT_DELETED );
1569 }
1570 }
1571 }
1572
1573 wxCHECK_MSG( maxCol >= minCol && maxRow >= minRow, /*void*/, wxT( "No selected cells!" ) );
1574
1575 int destRow = 0;
1576
1577 for( int row = minRow; row <= maxRow; row++ )
1578 aTable->SetRowHeight( destRow++, aTable->GetRowHeight( row ) );
1579
1580 int destCol = 0;
1581
1582 for( int col = minCol; col <= maxCol; col++ )
1583 aTable->SetColWidth( destCol++, aTable->GetColWidth( col ) );
1584
1585 aTable->DeleteMarkedCells();
1586 aTable->SetColCount( ( maxCol - minCol ) + 1 );
1587 }
1588
1589 wxCHECK_RET( aTable != nullptr && m_out != nullptr, "" );
1590
1591 m_out->Print( "(table (column_count %d)", aTable->GetColCount() );
1592
1593 m_out->Print( "(border" );
1594 KICAD_FORMAT::FormatBool( m_out, "external", aTable->StrokeExternal() );
1596
1597 if( aTable->StrokeExternal() || aTable->StrokeHeaderSeparator() )
1598 aTable->GetBorderStroke().Format( m_out, schIUScale );
1599
1600 m_out->Print( ")" ); // Close `border` token.
1601
1602 m_out->Print( "(separators" );
1603 KICAD_FORMAT::FormatBool( m_out, "rows", aTable->StrokeRows() );
1604 KICAD_FORMAT::FormatBool( m_out, "cols", aTable->StrokeColumns() );
1605
1606 if( aTable->StrokeRows() || aTable->StrokeColumns() )
1608
1609 m_out->Print( ")" ); // Close `separators` token.
1610
1611 m_out->Print( "(column_widths" );
1612
1613 for( int col = 0; col < aTable->GetColCount(); ++col )
1614 {
1615 m_out->Print( " %s",
1616 EDA_UNIT_UTILS::FormatInternalUnits( schIUScale, aTable->GetColWidth( col ) ).c_str() );
1617 }
1618
1619 m_out->Print( ")" );
1620
1621 m_out->Print( "(row_heights" );
1622
1623 for( int row = 0; row < aTable->GetRowCount(); ++row )
1624 {
1625 m_out->Print( " %s",
1626 EDA_UNIT_UTILS::FormatInternalUnits( schIUScale, aTable->GetRowHeight( row ) ).c_str() );
1627 }
1628
1629 m_out->Print( ")" );
1630
1632
1633 if( aTable->IsLocked() )
1634 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1635
1636 m_out->Print( "(cells" );
1637
1638 for( SCH_TABLECELL* cell : aTable->GetCells() )
1639 saveTextBox( cell );
1640
1641 m_out->Print( ")" ); // Close `cells` token.
1642 m_out->Print( ")" ); // Close `table` token.
1643
1644 if( aTable->GetFlags() & SKIP_STRUCT )
1645 delete aTable;
1646}
1647
1648
1650{
1651 // Don't write empty groups
1652 if( aGroup->GetItems().empty() )
1653 return;
1654
1655 m_out->Print( "(group %s", m_out->Quotew( aGroup->GetName() ).c_str() );
1656
1658
1659 if( aGroup->IsLocked() )
1660 KICAD_FORMAT::FormatBool( m_out, "locked", true );
1661
1662 if( aGroup->HasDesignBlockLink() )
1663 m_out->Print( "(lib_id \"%s\")", aGroup->GetDesignBlockLibId().Format().c_str() );
1664
1665 wxArrayString memberIds;
1666
1667 for( EDA_ITEM* member : aGroup->GetItems() )
1668 memberIds.Add( member->m_Uuid.AsString() );
1669
1670 memberIds.Sort();
1671
1672 m_out->Print( "(members" );
1673
1674 for( const wxString& memberId : memberIds )
1675 m_out->Print( " %s", m_out->Quotew( memberId ).c_str() );
1676
1677 m_out->Print( ")" ); // Close `members` token.
1678 m_out->Print( ")" ); // Close `group` token.
1679}
1680
1681
1682void SCH_IO_KICAD_SEXPR::saveInstances( const std::vector<SCH_SHEET_INSTANCE>& aInstances )
1683{
1684 if( aInstances.size() )
1685 {
1686 m_out->Print( "(sheet_instances" );
1687
1688 for( const SCH_SHEET_INSTANCE& instance : aInstances )
1689 {
1690 wxString path = instance.m_Path.AsString();
1691
1692 if( path.IsEmpty() )
1693 path = wxT( "/" ); // Root path
1694
1695 m_out->Print( "(path %s (page %s))",
1696 m_out->Quotew( path ).c_str(),
1697 m_out->Quotew( instance.m_PageNumber ).c_str() );
1698 }
1699
1700 m_out->Print( ")" ); // Close sheet instances token.
1701 }
1702}
1703
1704
1705void SCH_IO_KICAD_SEXPR::cacheLib( const wxString& aLibraryFileName,
1706 const std::map<std::string, UTF8>* aProperties )
1707{
1708 // Suppress font substitution warnings (RAII - automatically restored on scope exit)
1709 FONTCONFIG_REPORTER_SCOPE fontconfigScope( nullptr );
1710
1711 if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
1712 {
1713 int oldModifyHash = 1;
1714 bool isNewCache = false;
1715
1716 if( m_cache )
1717 oldModifyHash = m_cache->m_modHash;
1718 else
1719 isNewCache = true;
1720
1721 // a spectacular episode in memory management:
1722 delete m_cache;
1723 m_cache = new SCH_IO_KICAD_SEXPR_LIB_CACHE( aLibraryFileName );
1724
1725 if( !isBuffering( aProperties ) || ( isNewCache && m_cache->isLibraryPathValid() ) )
1726 {
1727 m_cache->Load();
1728 m_cache->m_modHash = oldModifyHash + 1;
1729 }
1730 }
1731}
1732
1733
1734bool SCH_IO_KICAD_SEXPR::isBuffering( const std::map<std::string, UTF8>* aProperties )
1735{
1736 return ( aProperties && aProperties->contains( SCH_IO_KICAD_SEXPR::PropBuffering ) );
1737}
1738
1739
1741{
1742 if( m_cache )
1743 return m_cache->GetModifyHash();
1744
1745 // If the cache hasn't been loaded, it hasn't been modified.
1746 return 0;
1747}
1748
1749
1750void SCH_IO_KICAD_SEXPR::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
1751 const wxString& aLibraryPath,
1752 const std::map<std::string, UTF8>* aProperties )
1753{
1754 bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIBRARY_ADAPTER::PropPowerSymsOnly ) );
1755
1756 cacheLib( aLibraryPath, aProperties );
1757
1758 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1759
1760 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1761 {
1762 if( !powerSymbolsOnly || it->second->IsPower() )
1763 aSymbolNameList.Add( it->first );
1764 }
1765}
1766
1767
1768void SCH_IO_KICAD_SEXPR::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
1769 const wxString& aLibraryPath,
1770 const std::map<std::string, UTF8>* aProperties )
1771{
1772 bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIBRARY_ADAPTER::PropPowerSymsOnly ) );
1773
1774 cacheLib( aLibraryPath, aProperties );
1775
1776 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1777
1778 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1779 {
1780 if( !powerSymbolsOnly || it->second->IsPower() )
1781 aSymbolList.push_back( it->second );
1782 }
1783}
1784
1785
1786LIB_SYMBOL* SCH_IO_KICAD_SEXPR::LoadSymbol( const wxString& aLibraryPath,
1787 const wxString& aSymbolName,
1788 const std::map<std::string, UTF8>* aProperties )
1789{
1790 cacheLib( aLibraryPath, aProperties );
1791
1792 LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
1793
1794 // We no longer escape '/' in symbol names, but we used to.
1795 if( it == m_cache->m_symbols.end() && aSymbolName.Contains( '/' ) )
1796 it = m_cache->m_symbols.find( EscapeString( aSymbolName, CTX_LEGACY_LIBID ) );
1797
1798 if( it == m_cache->m_symbols.end() && aSymbolName.Contains( wxT( "{slash}" ) ) )
1799 {
1800 wxString unescaped = aSymbolName;
1801 unescaped.Replace( wxT( "{slash}" ), wxT( "/" ) );
1802 it = m_cache->m_symbols.find( unescaped );
1803 }
1804
1805 if( it == m_cache->m_symbols.end() )
1806 return nullptr;
1807
1808 return it->second;
1809}
1810
1811
1812void SCH_IO_KICAD_SEXPR::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
1813 const std::map<std::string, UTF8>* aProperties )
1814{
1815 cacheLib( aLibraryPath, aProperties );
1816
1817 m_cache->AddSymbol( aSymbol );
1818
1819 if( !isBuffering( aProperties ) )
1820 m_cache->Save();
1821}
1822
1823
1824void SCH_IO_KICAD_SEXPR::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
1825 const std::map<std::string, UTF8>* aProperties )
1826{
1827 cacheLib( aLibraryPath, aProperties );
1828
1829 m_cache->DeleteSymbol( aSymbolName );
1830
1831 if( !isBuffering( aProperties ) )
1832 m_cache->Save();
1833}
1834
1835
1836void SCH_IO_KICAD_SEXPR::CreateLibrary( const wxString& aLibraryPath,
1837 const std::map<std::string, UTF8>* aProperties )
1838{
1839 wxFileName fn( aLibraryPath );
1840
1841 // Normalize the path: if it's a directory on the filesystem, ensure fn is marked as a
1842 // directory so that IsDir() checks work correctly. wxFileName::IsDir() only checks if
1843 // the path string ends with a separator, not if the path is actually a directory.
1844 if( !fn.IsDir() && wxFileName::DirExists( fn.GetFullPath() ) )
1845 fn.AssignDir( fn.GetFullPath() );
1846
1847 if( !fn.IsDir() )
1848 {
1849 if( fn.FileExists() )
1850 THROW_IO_ERROR( wxString::Format( _( "Symbol library file '%s' already exists." ), fn.GetFullPath() ) );
1851 }
1852 else
1853 {
1854 if( fn.DirExists() )
1855 THROW_IO_ERROR( wxString::Format( _( "Symbol library path '%s' already exists." ), fn.GetPath() ) );
1856 }
1857
1858 delete m_cache;
1859 m_cache = new SCH_IO_KICAD_SEXPR_LIB_CACHE( aLibraryPath );
1860 m_cache->SetModified();
1861 m_cache->Save();
1862 m_cache->Load(); // update m_writable and m_timestamp
1863}
1864
1865
1866bool SCH_IO_KICAD_SEXPR::DeleteLibrary( const wxString& aLibraryPath,
1867 const std::map<std::string, UTF8>* aProperties )
1868{
1869 wxFileName fn = aLibraryPath;
1870
1871 // Normalize the path: if it's a directory on the filesystem, ensure fn is marked as a
1872 // directory so that IsDir() checks work correctly.
1873 if( !fn.IsDir() && wxFileName::DirExists( fn.GetFullPath() ) )
1874 fn.AssignDir( fn.GetFullPath() );
1875
1876 if( !fn.FileExists() && !fn.DirExists() )
1877 return false;
1878
1879 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
1880 // we don't want that. we want bare metal portability with no UI here.
1881 if( !fn.IsDir() )
1882 {
1883 if( wxRemove( aLibraryPath ) )
1884 {
1885 THROW_IO_ERROR( wxString::Format( _( "Symbol library file '%s' cannot be deleted." ),
1886 aLibraryPath.GetData() ) );
1887 }
1888 }
1889 else
1890 {
1891 // This may be overly agressive. Perhaps in the future we should remove all of the *.kicad_sym
1892 // files and only delete the folder if it's empty.
1893 if( !fn.Rmdir( wxPATH_RMDIR_RECURSIVE ) )
1894 {
1895 THROW_IO_ERROR( wxString::Format( _( "Symbol library folder '%s' cannot be deleted." ),
1896 fn.GetPath() ) );
1897 }
1898 }
1899
1900 if( m_cache && m_cache->IsFile( aLibraryPath ) )
1901 {
1902 delete m_cache;
1903 m_cache = nullptr;
1904 }
1905
1906 return true;
1907}
1908
1909
1910void SCH_IO_KICAD_SEXPR::SaveLibrary( const wxString& aLibraryPath, const std::map<std::string, UTF8>* aProperties )
1911{
1912 if( !m_cache )
1913 m_cache = new SCH_IO_KICAD_SEXPR_LIB_CACHE( aLibraryPath );
1914
1915 wxString oldFileName = m_cache->GetFileName();
1916
1917 if( !m_cache->IsFile( aLibraryPath ) )
1918 m_cache->SetFileName( aLibraryPath );
1919
1920 // This is a forced save.
1921 m_cache->SetModified();
1922 m_cache->Save();
1923
1924 m_cache->SetFileName( oldFileName );
1925}
1926
1927
1928bool SCH_IO_KICAD_SEXPR::CanReadLibrary( const wxString& aLibraryPath ) const
1929{
1930 // Check if the path is a directory containing at least one .kicad_sym file
1931 if( wxFileName::DirExists( aLibraryPath ) )
1932 {
1933 wxDir dir( aLibraryPath );
1934
1935 if( dir.IsOpened() )
1936 {
1937 wxString filename;
1938 wxString filespec = wxT( "*." ) + wxString( FILEEXT::KiCadSymbolLibFileExtension );
1939
1940 if( dir.GetFirst( &filename, filespec, wxDIR_FILES ) )
1941 return true;
1942 }
1943
1944 return false;
1945 }
1946
1947 // Check for proper extension
1948 if( !SCH_IO::CanReadLibrary( aLibraryPath ) )
1949 return false;
1950
1951 // Above just checks for proper extension; now check that it actually exists
1952 wxFileName fn( aLibraryPath );
1953 return fn.IsOk() && fn.FileExists();
1954}
1955
1956
1957bool SCH_IO_KICAD_SEXPR::IsLibraryWritable( const wxString& aLibraryPath )
1958{
1959 wxFileName fn( aLibraryPath );
1960
1961 if( fn.FileExists() )
1962 return fn.IsFileWritable();
1963
1964 return fn.IsDirWritable();
1965}
1966
1967
1968void SCH_IO_KICAD_SEXPR::GetAvailableSymbolFields( std::vector<wxString>& aNames )
1969{
1970 if( !m_cache )
1971 return;
1972
1973 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1974
1975 std::set<wxString> fieldNames;
1976
1977 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1978 {
1979 std::map<wxString, wxString> chooserFields;
1980 it->second->GetChooserFields( chooserFields );
1981
1982 for( const auto& [name, value] : chooserFields )
1983 fieldNames.insert( name );
1984 }
1985
1986 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
1987}
1988
1989
1990void SCH_IO_KICAD_SEXPR::GetDefaultSymbolFields( std::vector<wxString>& aNames )
1991{
1992 GetAvailableSymbolFields( aNames );
1993}
1994
1995
1996std::vector<LIB_SYMBOL*> SCH_IO_KICAD_SEXPR::ParseLibSymbols( std::string& aSymbolText, std::string aSource,
1997 int aFileVersion )
1998{
1999 LIB_SYMBOL* newSymbol = nullptr;
2000 LIB_SYMBOL_MAP map;
2001
2002 std::vector<LIB_SYMBOL*> newSymbols;
2003 std::unique_ptr<STRING_LINE_READER> reader = std::make_unique<STRING_LINE_READER>( aSymbolText,
2004 aSource );
2005
2006 do
2007 {
2008 SCH_IO_KICAD_SEXPR_PARSER parser( reader.get() );
2009
2010 newSymbol = parser.ParseSymbol( map, aFileVersion );
2011
2012 if( newSymbol )
2013 newSymbols.emplace_back( newSymbol );
2014
2015 reader.reset( new STRING_LINE_READER( *reader ) );
2016 }
2017 while( newSymbol );
2018
2019 return newSymbols;
2020}
2021
2022
2024{
2025 SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( symbol, formatter );
2026}
2027
2028
2029const char* SCH_IO_KICAD_SEXPR::PropBuffering = "buffering";
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
This class handle bitmap images in KiCad.
Definition bitmap_base.h:49
bool SaveImageData(wxOutputStream &aOutStream) const
Write the bitmap data to aOutStream.
int GetPPI() const
wxImage * GetImageData()
Definition bitmap_base.h:68
const LIB_ID & GetDesignBlockLibId() const
Definition eda_group.h:73
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:54
wxString GetName() const
Definition eda_group.h:51
bool HasDesignBlockLink() const
Definition eda_group.h:70
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:100
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:149
const KIID m_Uuid
Definition eda_item.h:528
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:112
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:151
bool IsSelected() const
Definition eda_item.h:129
EDA_ITEM * GetParent() const
Definition eda_item.h:114
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:93
EDA_ITEM_FLAGS GetFlags() const
Definition eda_item.h:152
FILL_T GetFillMode() const
Definition eda_shape.h:154
SHAPE_T GetShape() const
Definition eda_shape.h:181
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:228
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:186
COLOR4D GetFillColor() const
Definition eda_shape.h:165
wxString SHAPE_T_asString() const
int GetTextHeight() const
Definition eda_text.h:278
bool IsDefaultFormatting() const
const EDA_ANGLE & GetTextAngle() const
Definition eda_text.h:158
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:109
virtual bool IsVisible() const
Definition eda_text.h:198
virtual void Format(OUTPUTFORMATTER *aFormatter, int aControlBits) const
Output the object to aFormatter in s-expression form.
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:225
A LINE_READER that reads from an open file.
Definition richio.h:158
void Rewind()
Rewind the file and resets the line number back to zero.
Definition richio.h:207
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition richio.cpp:208
RAII class to set and restore the fontconfig reporter.
Definition reporter.h:334
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition io_base.h:240
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
Definition io_base.cpp:71
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
double r
Red component.
Definition color4d.h:393
double g
Green component.
Definition color4d.h:394
double a
Alpha component.
Definition color4d.h:396
double b
Blue component.
Definition color4d.h:395
bool MakeRelativeTo(const KIID_PATH &aPath)
Definition kiid.cpp:320
wxString AsString() const
Definition kiid.cpp:365
Definition kiid.h:48
UTF8 Format() const
Definition lib_id.cpp:119
Define a library symbol object.
Definition lib_symbol.h:83
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:66
static LOAD_INFO_REPORTER & GetInstance()
Definition reporter.cpp:222
An interface used to output 8 bit text in a convenient way.
Definition richio.h:295
void Format(OUTPUTFORMATTER *aFormatter) const
Output the page class to aFormatter in s-expression form.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:177
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
VECTOR2I GetPosition() const
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
Holds all the data relating to one schematic.
Definition schematic.h:89
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:104
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:173
SCH_SHEET & Root() const
Definition schematic.h:133
std::vector< SCH_SHEET * > GetTopLevelSheets() const
Get the list of top-level sheets.
Object to handle a bitmap image that can be inserted in a schematic.
Definition sch_bitmap.h:40
REFERENCE_IMAGE & GetReferenceImage()
Definition sch_bitmap.h:51
Base class for a bus or wire entry.
VECTOR2I GetSize() const
VECTOR2I GetPosition() const override
virtual STROKE_PARAMS GetStroke() const override
VECTOR2I GetEnd() const
bool IsMandatory() const
VECTOR2I GetPosition() const override
bool IsNameShown() const
Definition sch_field.h:213
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:123
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
bool CanAutoplace() const
Definition sch_field.h:224
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
A cache assistant for the KiCad s-expression symbol libraries.
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, const wxString &aLibName=wxEmptyString, bool aIncludeData=true)
Object to parser s-expression symbol library and schematic file formats.
void ParseSchematic(SCH_SHEET *aSheet, bool aIsCopyablyOnly=false, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
Parse the internal LINE_READER object into aSheet.
LIB_SYMBOL * ParseSymbol(LIB_SYMBOL_MAP &aSymbolLibMap, int aFileVersion=SEXPR_SYMBOL_LIB_FILE_VERSION)
Parse internal LINE_READER object into symbols and return all found.
wxString m_path
Root project path for loading child sheets.
void GetDefaultSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that should be shown by default for this library in the symb...
void saveShape(SCH_SHAPE *aShape)
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
void SaveLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
SCH_SHEET_PATH m_currentSheetPath
void saveGroup(SCH_GROUP *aGroup)
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
void FormatSchematicToFormatter(OUTPUTFORMATTER *aOut, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr)
Serialize a schematic sheet to an OUTPUTFORMATTER without file I/O or Prettify.
bool m_appending
Schematic load append status.
std::vector< SCH_SHEET * > m_loadedRootSheets
Root sheets from previous LoadSchematicFile() calls, enabling screen reuse across top-level sheets th...
int m_version
Version of file being loaded.
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
void loadHierarchy(const SCH_SHEET_PATH &aParentSheetPath, SCH_SHEET *aSheet)
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
static std::vector< LIB_SYMBOL * > ParseLibSymbols(std::string &aSymbolText, std::string aSource, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
wxString m_error
For throwing exceptions or errors on partial loads.
void saveInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheets)
bool isBuffering(const std::map< std::string, UTF8 > *aProperties)
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
void cacheLib(const wxString &aLibraryFileName, const std::map< std::string, UTF8 > *aProperties)
void saveRuleArea(SCH_RULE_AREA *aRuleArea)
void saveField(SCH_FIELD *aField)
SCH_IO_KICAD_SEXPR_LIB_CACHE * m_cache
void Format(SCH_SHEET *aSheet)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void init(SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr)
initialize PLUGIN like a constructor would.
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
void saveBitmap(const SCH_BITMAP &aBitmap)
void saveText(SCH_TEXT *aText)
void saveSheet(SCH_SHEET *aSheet, const SCH_SHEET_LIST &aSheetList)
int GetModifyHash() const override
Return the modification hash from the library cache.
bool CanReadLibrary(const wxString &aLibraryPath) const override
Checks if this IO object can read the specified library file/directory.
void saveLine(SCH_LINE *aLine)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
void saveTable(SCH_TABLE *aTable)
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void CreateLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
void saveJunction(SCH_JUNCTION *aJunction)
std::function< bool(wxString aTitle, int aIcon, wxString aMsg, wxString aAction)> m_queryUserCallback
void saveTextBox(SCH_TEXTBOX *aText)
void saveSymbol(SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic, const SCH_SHEET_LIST &aSheetList, bool aForClipboard, const SCH_SHEET_PATH *aRelativePath=nullptr)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
SCH_IO(const wxString &aName)
Definition sch_io.h:375
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:168
int GetBodyStyle() const
Definition sch_item.h:248
bool IsLocked() const override
Definition sch_item.cpp:149
bool IsPrivate() const
Definition sch_item.h:254
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition sch_item.h:344
AUTOPLACE_ALGO GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition sch_item.h:629
wxString GetClass() const override
Return the class name.
Definition sch_item.h:178
COLOR4D GetColor() const
int GetDiameter() const
VECTOR2I GetPosition() const override
SPIN_STYLE GetSpinStyle() const
LABEL_FLAG_SHAPE GetShape() const
Definition sch_label.h:180
std::vector< SCH_FIELD > & GetFields()
Definition sch_label.h:212
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:42
virtual STROKE_PARAMS GetStroke() const override
Definition sch_line.h:201
VECTOR2I GetEndPoint() const
Definition sch_line.h:148
VECTOR2I GetStartPoint() const
Definition sch_line.h:139
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:149
VECTOR2I GetPosition() const override
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:141
const std::map< wxString, LIB_SYMBOL * > & GetLibSymbols() const
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition sch_screen.h:497
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:119
const wxString & GetFileName() const
Definition sch_screen.h:154
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
wxString GroupsSanityCheck(bool repair=false)
Consistency check of internal m_groups structure.
const TITLE_BLOCK & GetTitleBlock() const
Definition sch_screen.h:165
KIID m_uuid
A unique identifier for each schematic file.
Definition sch_screen.h:735
void SetFileReadOnly(bool aIsReadOnly)
Definition sch_screen.h:156
void SetFileExists(bool aFileExists)
Definition sch_screen.h:159
SCH_SCREEN * GetScreen()
STROKE_PARAMS GetStroke() const override
Definition sch_shape.h:58
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath, bool aIncludeLastSheet=true) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool empty() const
Forwarded method from std::vector.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition sch_sheet.h:371
bool HasRootInstance() const
Check to see if this sheet has a root sheet instance.
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:88
bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
VECTOR2I GetSize() const
Definition sch_sheet.h:142
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:140
VECTOR2I GetPosition() const override
Definition sch_sheet.h:491
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
const SCH_SHEET_INSTANCE & GetRootInstance() const
Return the root sheet instance data.
KIGFX::COLOR4D GetBorderColor() const
Definition sch_sheet.h:148
bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flags.
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition sch_sheet.h:462
int GetBorderWidth() const
Definition sch_sheet.h:145
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:228
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition sch_sheet.h:506
KIGFX::COLOR4D GetBackgroundColor() const
Definition sch_sheet.h:151
Schematic symbol object.
Definition sch_symbol.h:76
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
Definition sch_symbol.h:667
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition sch_symbol.h:135
bool UseLibIdLookup() const
Definition sch_symbol.h:182
wxString GetSchSymbolLibraryName() const
bool GetExcludedFromBOM(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:871
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:165
bool GetExcludedFromPosFiles(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
int GetOrientation() const override
Get the display symbol orientation.
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
wxString GetPrefix() const
Definition sch_symbol.h:238
void SetRowHeight(int aRow, int aHeight)
Definition sch_table.h:137
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition sch_table.h:77
void SetColCount(int aCount)
Definition sch_table.h:119
bool StrokeExternal() const
Definition sch_table.h:53
int GetRowHeight(int aRow) const
Definition sch_table.h:139
void SetColWidth(int aCol, int aWidth)
Definition sch_table.h:127
std::vector< SCH_TABLECELL * > GetCells() const
Definition sch_table.h:157
int GetColWidth(int aCol) const
Definition sch_table.h:129
const STROKE_PARAMS & GetBorderStroke() const
Definition sch_table.h:59
int GetColCount() const
Definition sch_table.h:120
bool StrokeHeaderSeparator() const
Definition sch_table.h:56
void DeleteMarkedCells()
Definition sch_table.h:182
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition sch_table.h:147
bool StrokeColumns() const
Definition sch_table.h:99
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition sch_table.h:231
bool StrokeRows() const
Definition sch_table.h:102
int GetRowCount() const
Definition sch_table.h:122
int GetMarginBottom() const
Definition sch_textbox.h:73
int GetMarginLeft() const
Definition sch_textbox.h:70
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
int GetMarginRight() const
Definition sch_textbox.h:72
int GetMarginTop() const
Definition sch_textbox.h:71
bool GetExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition sch_text.h:90
VECTOR2I GetPosition() const override
Definition sch_text.h:147
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition richio.h:226
Simple container to manage line stroke parameters.
void SetWidth(int aWidth)
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale) const
static const char * PropPowerSymsOnly
virtual void Format(OUTPUTFORMATTER *aFormatter) const
Output the object to aFormatter in s-expression form.
const char * c_str() const
Definition utf8.h:108
wxString wx_str() const
Definition utf8.cpp:45
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:416
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:415
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:48
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition eda_text.h:81
static const std::string KiCadSymbolLibFileExtension
const wxChar *const traceSchPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
KIID niluuid(0)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition layer_id.cpp:31
@ LAYER_WIRE
Definition layer_ids.h:454
@ LAYER_NOTES
Definition layer_ids.h:469
@ LAYER_BUS
Definition layer_ids.h:455
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:96
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Convert aAngle from board units to a string appropriate for writing to file.
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
void FormatUuid(OUTPUTFORMATTER *aOut, const KIID &aUuid)
void FormatStreamData(OUTPUTFORMATTER &aOut, const wxStreamBuffer &aStream)
Write binary data to the formatter as base 64 encoded string.
void FormatBool(OUTPUTFORMATTER *aOut, const wxString &aKey, bool aValue)
Writes a boolean to the formatter, in the style (aKey [yes|no])
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
Class to handle a set of SCH_ITEMs.
void formatArc(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid, bool aLocked)
void formatCircle(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid, bool aLocked)
const char * getSheetPinShapeToken(LABEL_FLAG_SHAPE aShape)
void formatRect(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid, bool aLocked)
const char * getTextTypeToken(KICAD_T aType)
void formatBezier(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid, bool aLocked)
void formatPoly(OUTPUTFORMATTER *aFormatter, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid, bool aLocked)
EDA_ANGLE getSheetPinAngle(SHEET_SIDE aSide)
void formatFill(OUTPUTFORMATTER *aFormatter, FILL_T aFillMode, const COLOR4D &aFillColor)
Fill token formatting helper.
AUTOPLACE_ALGO
Definition sch_item.h:69
@ AUTOPLACE_MANUAL
Definition sch_item.h:72
@ AUTOPLACE_AUTO
Definition sch_item.h:71
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
const int scale
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
@ CTX_LEGACY_LIBID
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
@ SYM_ORIENT_270
Definition symbol.h:42
@ SYM_MIRROR_Y
Definition symbol.h:44
@ SYM_ORIENT_180
Definition symbol.h:41
@ SYM_MIRROR_X
Definition symbol.h:43
@ SYM_ORIENT_90
Definition symbol.h:40
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ REFERENCE
Field Reference of part, i.e. "IC21".
std::string path
KIBIS_PIN * pin
std::vector< std::vector< std::string > > table
wxLogTrace helper definitions.
@ SCH_GROUP_T
Definition typeinfo.h:174
@ SCH_TABLE_T
Definition typeinfo.h:166
@ SCH_LINE_T
Definition typeinfo.h:164
@ SCH_NO_CONNECT_T
Definition typeinfo.h:161
@ SCH_SYMBOL_T
Definition typeinfo.h:173
@ SCH_TABLECELL_T
Definition typeinfo.h:167
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:172
@ SCH_LABEL_T
Definition typeinfo.h:168
@ SCH_SHEET_T
Definition typeinfo.h:176
@ SCH_MARKER_T
Definition typeinfo.h:159
@ SCH_SHAPE_T
Definition typeinfo.h:150
@ SCH_RULE_AREA_T
Definition typeinfo.h:171
@ SCH_HIER_LABEL_T
Definition typeinfo.h:170
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:163
@ SCH_TEXT_T
Definition typeinfo.h:152
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:162
@ SCH_BITMAP_T
Definition typeinfo.h:165
@ SCH_TEXTBOX_T
Definition typeinfo.h:153
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:169
@ SCH_JUNCTION_T
Definition typeinfo.h:160
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687
Definition of file extensions used in Kicad.