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 (C) 2021-2024 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// For some reason wxWidgets is built with wxUSE_BASE64 unset so expose the wxWidgets
26// base64 code.
27#define wxUSE_BASE64 1
28#include <wx/base64.h>
29#include <wx/log.h>
30#include <wx/mstream.h>
31#include <boost/algorithm/string/join.hpp>
32
33#include <advanced_config.h>
34#include <base_units.h>
35#include <build_version.h>
36#include <ee_selection.h>
37#include <font/fontconfig.h>
39#include <locale_io.h>
40#include <progress_reporter.h>
41#include <schematic.h>
42#include <schematic_lexer.h>
43#include <sch_bitmap.h>
44#include <sch_bus_entry.h>
45#include <sch_edit_frame.h> // SYMBOL_ORIENTATION_T
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 <symbol_lib_table.h> // for PropPowerSymsOnly definition.
66#include <trace_helpers.h>
67#include <wx_filename.h> // for ::ResolvePossibleSymlinks()
68
69using namespace TSCHEMATIC_T;
70
71
72#define SCH_PARSE_ERROR( text, reader, pos ) \
73 THROW_PARSE_ERROR( text, reader.GetSource(), reader.Line(), \
74 reader.LineNumber(), pos - reader.Line() )
75
76
77SCH_IO_KICAD_SEXPR::SCH_IO_KICAD_SEXPR() : SCH_IO( wxS( "Eeschema s-expression" ) )
78{
79 init( nullptr );
80}
81
82
84{
85 delete m_cache;
86}
87
88
89void SCH_IO_KICAD_SEXPR::init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties )
90{
91 m_version = 0;
92 m_appending = false;
93 m_rootSheet = nullptr;
94 m_schematic = aSchematic;
95 m_cache = nullptr;
96 m_out = nullptr;
97 m_nextFreeFieldId = 100; // number arbitrarily > MANDATORY_FIELDS or SHEET_MANDATORY_FIELDS
98}
99
100
101SCH_SHEET* SCH_IO_KICAD_SEXPR::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
102 SCH_SHEET* aAppendToMe,
103 const STRING_UTF8_MAP* aProperties )
104{
105 wxASSERT( !aFileName || aSchematic != nullptr );
106
107 LOCALE_IO toggle; // toggles on, then off, the C locale.
108 SCH_SHEET* sheet;
109
110 wxFileName fn = aFileName;
111
112 // Show the font substitution warnings
114
115 // Unfortunately child sheet file names the legacy schematic file format are not fully
116 // qualified and are always appended to the project path. The aFileName attribute must
117 // always be an absolute path so the project path can be used for load child sheet files.
118 wxASSERT( fn.IsAbsolute() );
119
120 if( aAppendToMe )
121 {
122 m_appending = true;
123 wxLogTrace( traceSchPlugin, "Append \"%s\" to sheet \"%s\".",
124 aFileName, aAppendToMe->GetFileName() );
125
126 wxFileName normedFn = aAppendToMe->GetFileName();
127
128 if( !normedFn.IsAbsolute() )
129 {
130 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
131 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
132 }
133
134 if( m_path.IsEmpty() )
135 m_path = aSchematic->Prj().GetProjectPath();
136
137 wxLogTrace( traceSchPlugin, "Normalized append path \"%s\".", m_path );
138 }
139 else
140 {
141 m_path = aSchematic->Prj().GetProjectPath();
142 }
143
144 m_currentPath.push( m_path );
145 init( aSchematic, aProperties );
146
147 if( aAppendToMe == nullptr )
148 {
149 // Clean up any allocated memory if an exception occurs loading the schematic.
150 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
151
152 wxFileName relPath( aFileName );
153
154 // Do not use wxPATH_UNIX as option in MakeRelativeTo(). It can create incorrect
155 // relative paths on Windows, because paths have a disk identifier (C:, D: ...)
156 relPath.MakeRelativeTo( aSchematic->Prj().GetProjectPath() );
157
158 newSheet->SetFileName( relPath.GetFullPath() );
159 m_rootSheet = newSheet.get();
160 loadHierarchy( SCH_SHEET_PATH(), newSheet.get() );
161
162 // If we got here, the schematic loaded successfully.
163 sheet = newSheet.release();
164 m_rootSheet = nullptr; // Quiet Coverity warning.
165 }
166 else
167 {
168 wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
169 m_rootSheet = &aSchematic->Root();
170 sheet = aAppendToMe;
171 loadHierarchy( SCH_SHEET_PATH(), sheet );
172 }
173
174 wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
175
176 m_currentPath.pop(); // Clear the path stack for next call to Load
177
178 return sheet;
179}
180
181
182// Everything below this comment is recursive. Modify with care.
183
184void SCH_IO_KICAD_SEXPR::loadHierarchy( const SCH_SHEET_PATH& aParentSheetPath, SCH_SHEET* aSheet )
185{
187
188 SCH_SCREEN* screen = nullptr;
189
190 if( !aSheet->GetScreen() )
191 {
192 // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
193 // stores the file name and extension. Add the project path to the file name and
194 // extension to compare when calling SCH_SHEET::SearchHierarchy().
195 wxFileName fileName = aSheet->GetFileName();
196
197 if( !fileName.IsAbsolute() )
198 fileName.MakeAbsolute( m_currentPath.top() );
199
200 // Save the current path so that it gets restored when descending and ascending the
201 // sheet hierarchy which allows for sheet schematic files to be nested in folders
202 // relative to the last path a schematic was loaded from.
203 wxLogTrace( traceSchPlugin, "Saving path '%s'", m_currentPath.top() );
204 m_currentPath.push( fileName.GetPath() );
205 wxLogTrace( traceSchPlugin, "Current path '%s'", m_currentPath.top() );
206 wxLogTrace( traceSchPlugin, "Loading '%s'", fileName.GetFullPath() );
207
208 SCH_SHEET_PATH ancestorSheetPath = aParentSheetPath;
209
210 while( !ancestorSheetPath.empty() )
211 {
212 if( ancestorSheetPath.LastScreen()->GetFileName() == fileName.GetFullPath() )
213 {
214 if( !m_error.IsEmpty() )
215 m_error += "\n";
216
217 m_error += wxString::Format( _( "Could not load sheet '%s' because it already "
218 "appears as a direct ancestor in the schematic "
219 "hierarchy." ),
220 fileName.GetFullPath() );
221
222 fileName = wxEmptyString;
223
224 break;
225 }
226
227 ancestorSheetPath.pop_back();
228 }
229
230 if( ancestorSheetPath.empty() )
231 {
232 // Existing schematics could be either in the root sheet path or the current sheet
233 // load path so we have to check both.
234 if( !m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen ) )
235 m_currentSheetPath.at( 0 )->SearchHierarchy( fileName.GetFullPath(), &screen );
236 }
237
238 if( screen )
239 {
240 aSheet->SetScreen( screen );
241 aSheet->GetScreen()->SetParent( m_schematic );
242 // Do not need to load the sub-sheets - this has already been done.
243 }
244 else
245 {
246 aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
247 aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
248
249 try
250 {
251 loadFile( fileName.GetFullPath(), aSheet );
252 }
253 catch( const IO_ERROR& ioe )
254 {
255 // If there is a problem loading the root sheet, there is no recovery.
256 if( aSheet == m_rootSheet )
257 throw;
258
259 // For all subsheets, queue up the error message for the caller.
260 if( !m_error.IsEmpty() )
261 m_error += "\n";
262
263 m_error += ioe.What();
264 }
265
266 if( fileName.FileExists() )
267 {
268 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
269 aSheet->GetScreen()->SetFileExists( true );
270 }
271 else
272 {
273 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsDirWritable() );
274 aSheet->GetScreen()->SetFileExists( false );
275 }
276
277 SCH_SHEET_PATH currentSheetPath = aParentSheetPath;
278 currentSheetPath.push_back( aSheet );
279
280 // This was moved out of the try{} block so that any sheet definitions that
281 // the plugin fully parsed before the exception was raised will be loaded.
282 for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
283 {
284 wxCHECK2( aItem->Type() == SCH_SHEET_T, /* do nothing */ );
285 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( aItem );
286
287 // Recursion starts here.
288 loadHierarchy( currentSheetPath, sheet );
289 }
290 }
291
292 m_currentPath.pop();
293 wxLogTrace( traceSchPlugin, "Restoring path \"%s\"", m_currentPath.top() );
294 }
295
297}
298
299
300void SCH_IO_KICAD_SEXPR::loadFile( const wxString& aFileName, SCH_SHEET* aSheet )
301{
302 FILE_LINE_READER reader( aFileName );
303
304 size_t lineCount = 0;
305
307 {
308 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
309
311 THROW_IO_ERROR( _( "Open cancelled by user." ) );
312
313 while( reader.ReadLine() )
314 lineCount++;
315
316 reader.Rewind();
317 }
318
319 SCH_IO_KICAD_SEXPR_PARSER parser( &reader, m_progressReporter, lineCount, m_rootSheet,
320 m_appending );
321
322 parser.ParseSchematic( aSheet );
323}
324
325
326void SCH_IO_KICAD_SEXPR::LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet, int aFileVersion )
327{
328 wxCHECK( aSheet, /* void */ );
329
330 LOCALE_IO toggle;
331 SCH_IO_KICAD_SEXPR_PARSER parser( &aReader );
332
333 parser.ParseSchematic( aSheet, true, aFileVersion );
334}
335
336
337void SCH_IO_KICAD_SEXPR::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet,
338 SCHEMATIC* aSchematic,
339 const STRING_UTF8_MAP* aProperties )
340{
341 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
342 wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
343
344 LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
345
346 init( aSchematic, aProperties );
347
348 wxFileName fn = aFileName;
349
350 // File names should be absolute. Don't assume everything relative to the project path
351 // works properly.
352 wxASSERT( fn.IsAbsolute() );
353
354 PRETTIFIED_FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
355
356 m_out = &formatter; // no ownership
357
358 Format( aSheet );
359
360 if( aSheet->GetScreen() )
361 aSheet->GetScreen()->SetFileExists( true );
362}
363
364
366{
367 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
368 wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
369
371 SCH_SCREEN* screen = aSheet->GetScreen();
372
373 wxCHECK( screen, /* void */ );
374
375 // If we've requested to embed the fonts in the schematic, do so.
376 // Otherwise, clear the embedded fonts from the schematic. Embedded
377 // fonts will be used if available
380 else
382
383 m_out->Print( 0, "(kicad_sch (version %d) (generator \"eeschema\") (generator_version \"%s\")\n\n",
385
387
388 screen->GetPageSettings().Format( m_out, 1, 0 );
389 m_out->Print( 0, "\n" );
390 screen->GetTitleBlock().Format( m_out, 1, 0 );
391
392 // Save cache library.
393 m_out->Print( 1, "(lib_symbols\n" );
394
395 for( const auto& [ libItemName, libSymbol ] : screen->GetLibSymbols() )
396 SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( libSymbol, *m_out, 2, libItemName );
397
398 m_out->Print( 1, ")\n\n" );
399
400 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
401 saveBusAlias( alias, 1 );
402
403 // Enforce item ordering
404 auto cmp =
405 []( const SCH_ITEM* a, const SCH_ITEM* b )
406 {
407 if( a->Type() != b->Type() )
408 return a->Type() < b->Type();
409
410 return a->m_Uuid < b->m_Uuid;
411 };
412
413 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
414
415 for( SCH_ITEM* item : screen->Items() )
416 {
417 // Markers are not saved, so keep them from being considered below
418 if( item->Type() != SCH_MARKER_T )
419 save_map.insert( item );
420 }
421
422 KICAD_T itemType = TYPE_NOT_INIT;
424
425 for( SCH_ITEM* item : save_map )
426 {
427 if( itemType != item->Type() )
428 {
429 itemType = item->Type();
430
431 if( itemType != SCH_SYMBOL_T
432 && itemType != SCH_JUNCTION_T
433 && itemType != SCH_SHEET_T )
434 {
435 m_out->Print( 0, "\n" );
436 }
437 }
438
439 switch( item->Type() )
440 {
441 case SCH_SYMBOL_T:
442 m_out->Print( 0, "\n" );
443 saveSymbol( static_cast<SCH_SYMBOL*>( item ), *m_schematic, sheets, 1, false );
444 break;
445
446 case SCH_BITMAP_T:
447 saveBitmap( static_cast<SCH_BITMAP*>( item ), 1 );
448 break;
449
450 case SCH_SHEET_T:
451 m_out->Print( 0, "\n" );
452 saveSheet( static_cast<SCH_SHEET*>( item ), sheets, 1 );
453 break;
454
455 case SCH_JUNCTION_T:
456 saveJunction( static_cast<SCH_JUNCTION*>( item ), 1 );
457 break;
458
459 case SCH_NO_CONNECT_T:
460 saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ), 1 );
461 break;
462
465 saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ), 1 );
466 break;
467
468 case SCH_LINE_T:
469 if( layer != item->GetLayer() )
470 {
471 if( layer == SCH_LAYER_ID_START )
472 {
473 layer = item->GetLayer();
474 }
475 else
476 {
477 layer = item->GetLayer();
478 m_out->Print( 0, "\n" );
479 }
480 }
481
482 saveLine( static_cast<SCH_LINE*>( item ), 1 );
483 break;
484
485 case SCH_SHAPE_T:
486 saveShape( static_cast<SCH_SHAPE*>( item ), 1 );
487 break;
488
489 case SCH_RULE_AREA_T:
490 saveRuleArea( static_cast<SCH_RULE_AREA*>( item ), 1 );
491 break;
492
493 case SCH_TEXT_T:
494 case SCH_LABEL_T:
496 case SCH_HIER_LABEL_T:
498 saveText( static_cast<SCH_TEXT*>( item ), 1 );
499 break;
500
501 case SCH_TEXTBOX_T:
502 saveTextBox( static_cast<SCH_TEXTBOX*>( item ), 1 );
503 break;
504
505 case SCH_TABLE_T:
506 saveTable( static_cast<SCH_TABLE*>( item ), 1 );
507 break;
508
509 default:
510 wxASSERT( "Unexpected schematic object type in SCH_IO_KICAD_SEXPR::Format()" );
511 }
512 }
513
514 if( aSheet->HasRootInstance() )
515 {
516 std::vector< SCH_SHEET_INSTANCE> instances;
517
518 instances.emplace_back( aSheet->GetRootInstance() );
519 saveInstances( instances, 1 );
520
521 m_out->Print( 1, "(embedded_fonts %s)\n",
522 m_schematic->GetAreFontsEmbedded() ? "yes" : "no" );
523
524 // Save any embedded files
527 }
528
529 m_out->Print( 0, ")\n" );
530}
531
532
533void SCH_IO_KICAD_SEXPR::Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelectionPath,
534 SCHEMATIC& aSchematic, OUTPUTFORMATTER* aFormatter,
535 bool aForClipboard )
536{
537 wxCHECK( aSelection && aSelectionPath && aFormatter, /* void */ );
538
539 LOCALE_IO toggle;
541
542 m_schematic = &aSchematic;
543 m_out = aFormatter;
544
545 size_t i;
546 SCH_ITEM* item;
547 std::map<wxString, LIB_SYMBOL*> libSymbols;
548 SCH_SCREEN* screen = aSelection->GetScreen();
549 std::set<SCH_TABLE*> promotedTables;
550
551 for( i = 0; i < aSelection->GetSize(); ++i )
552 {
553 item = dynamic_cast<SCH_ITEM*>( aSelection->GetItem( i ) );
554
555 wxCHECK2( item, continue );
556
557 if( item->Type() != SCH_SYMBOL_T )
558 continue;
559
560 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
561
562 wxCHECK2( symbol, continue );
563
564 wxString libSymbolLookup = symbol->GetLibId().Format().wx_str();
565
566 if( !symbol->UseLibIdLookup() )
567 libSymbolLookup = symbol->GetSchSymbolLibraryName();
568
569 auto it = screen->GetLibSymbols().find( libSymbolLookup );
570
571 if( it != screen->GetLibSymbols().end() )
572 libSymbols[ libSymbolLookup ] = it->second;
573 }
574
575 if( !libSymbols.empty() )
576 {
577 m_out->Print( 0, "(lib_symbols\n" );
578
579 for( const std::pair<const wxString, LIB_SYMBOL*>& libSymbol : libSymbols )
580 {
581 SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( libSymbol.second, *m_out, 1,
582 libSymbol.first, false );
583 }
584
585 m_out->Print( 0, ")\n\n" );
586 }
587
588 for( i = 0; i < aSelection->GetSize(); ++i )
589 {
590 item = (SCH_ITEM*) aSelection->GetItem( i );
591
592 switch( item->Type() )
593 {
594 case SCH_SYMBOL_T:
595 saveSymbol( static_cast<SCH_SYMBOL*>( item ), aSchematic, 0, aForClipboard,
596 aSelectionPath );
597 break;
598
599 case SCH_BITMAP_T:
600 saveBitmap( static_cast< SCH_BITMAP* >( item ), 0 );
601 break;
602
603 case SCH_SHEET_T:
604 saveSheet( static_cast< SCH_SHEET* >( item ), sheets, 0 );
605 break;
606
607 case SCH_JUNCTION_T:
608 saveJunction( static_cast< SCH_JUNCTION* >( item ), 0 );
609 break;
610
611 case SCH_NO_CONNECT_T:
612 saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ), 0 );
613 break;
614
617 saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ), 0 );
618 break;
619
620 case SCH_LINE_T:
621 saveLine( static_cast< SCH_LINE* >( item ), 0 );
622 break;
623
624 case SCH_SHAPE_T:
625 saveShape( static_cast<SCH_SHAPE*>( item ), 0 );
626 break;
627
628 case SCH_RULE_AREA_T:
629 saveRuleArea( static_cast<SCH_RULE_AREA*>( item ), 0 );
630 break;
631
632 case SCH_TEXT_T:
633 case SCH_LABEL_T:
635 case SCH_HIER_LABEL_T:
637 saveText( static_cast<SCH_TEXT*>( item ), 0 );
638 break;
639
640 case SCH_TEXTBOX_T:
641 saveTextBox( static_cast<SCH_TEXTBOX*>( item ), 0 );
642 break;
643
644 case SCH_TABLECELL_T:
645 {
646 SCH_TABLE* table = static_cast<SCH_TABLE*>( item->GetParent() );
647
648 if( promotedTables.count( table ) )
649 break;
650
651 table->SetFlags( SKIP_STRUCT );
652 saveTable( table, 0 );
653 table->ClearFlags( SKIP_STRUCT );
654 promotedTables.insert( table );
655 break;
656 }
657
658 case SCH_TABLE_T:
659 item->ClearFlags( SKIP_STRUCT );
660 saveTable( static_cast<SCH_TABLE*>( item ), 0 );
661 break;
662
663 default:
664 wxASSERT( "Unexpected schematic object type in SCH_IO_KICAD_SEXPR::Format()" );
665 }
666 }
667}
668
669
670void SCH_IO_KICAD_SEXPR::saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchematic,
671 const SCH_SHEET_LIST& aSheetList,
672 int aNestLevel, bool aForClipboard,
673 const SCH_SHEET_PATH* aRelativePath )
674{
675 wxCHECK_RET( aSymbol != nullptr && m_out != nullptr, "" );
676
677 std::string libName;
678
679 wxString symbol_name = aSymbol->GetLibId().Format();
680
681 if( symbol_name.size() )
682 {
683 libName = toUTFTildaText( symbol_name );
684 }
685 else
686 {
687 libName = "_NONAME_";
688 }
689
690 EDA_ANGLE angle;
691 int orientation = aSymbol->GetOrientation() & ~( SYM_MIRROR_X | SYM_MIRROR_Y );
692
693 if( orientation == SYM_ORIENT_90 )
694 angle = ANGLE_90;
695 else if( orientation == SYM_ORIENT_180 )
696 angle = ANGLE_180;
697 else if( orientation == SYM_ORIENT_270 )
698 angle = ANGLE_270;
699 else
700 angle = ANGLE_0;
701
702 m_out->Print( aNestLevel, "(symbol" );
703
704 if( !aSymbol->UseLibIdLookup() )
705 {
706 m_out->Print( 0, " (lib_name %s)",
707 m_out->Quotew( aSymbol->GetSchSymbolLibraryName() ).c_str() );
708 }
709
710 m_out->Print( 0, " (lib_id %s) (at %s %s %s)",
711 m_out->Quotew( aSymbol->GetLibId().Format().wx_str() ).c_str(),
713 aSymbol->GetPosition().x ).c_str(),
715 aSymbol->GetPosition().y ).c_str(),
716 EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
717
718 bool mirrorX = aSymbol->GetOrientation() & SYM_MIRROR_X;
719 bool mirrorY = aSymbol->GetOrientation() & SYM_MIRROR_Y;
720
721 if( mirrorX || mirrorY )
722 {
723 m_out->Print( 0, " (mirror" );
724
725 if( mirrorX )
726 m_out->Print( 0, " x" );
727
728 if( mirrorY )
729 m_out->Print( 0, " y" );
730
731 m_out->Print( 0, ")" );
732 }
733
734 // The symbol unit is always set to the first instance regardless of the current sheet
735 // instance to prevent file churn.
736 int unit = ( aSymbol->GetInstances().size() == 0 ) ? aSymbol->GetUnit()
737 : aSymbol->GetInstances()[0].m_Unit;
738
739 if( aForClipboard && aRelativePath )
740 {
741 SCH_SYMBOL_INSTANCE unitInstance;
742
743 if( aSymbol->GetInstance( unitInstance, aRelativePath->Path() ) )
744 unit = unitInstance.m_Unit;
745 }
746
747 m_out->Print( 0, " (unit %d)", unit );
748
749 if( aSymbol->GetBodyStyle() == BODY_STYLE::DEMORGAN )
750 m_out->Print( 0, " (convert %d)", aSymbol->GetBodyStyle() );
751
752 m_out->Print( 0, "\n" );
753
754 m_out->Print( aNestLevel + 1, "(exclude_from_sim %s)",
755 ( aSymbol->GetExcludedFromSim() ) ? "yes" : "no" );
756 m_out->Print( 0, " (in_bom %s)", ( aSymbol->GetExcludedFromBOM() ) ? "no" : "yes" );
757 m_out->Print( 0, " (on_board %s)", ( aSymbol->GetExcludedFromBoard() ) ? "no" : "yes" );
758 m_out->Print( 0, " (dnp %s)", ( aSymbol->GetDNP() ) ? "yes" : "no" );
759
760 if( aSymbol->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
761 m_out->Print( 0, " (fields_autoplaced yes)" );
762
763 m_out->Print( 0, "\n" );
764
766
768
769 for( SCH_FIELD& field : aSymbol->GetFields() )
770 {
771 int id = field.GetId();
772 wxString value = field.GetText();
773
774 if( !aForClipboard && aSymbol->GetInstances().size() )
775 {
776 // The instance fields are always set to the default instance regardless of the
777 // sheet instance to prevent file churn.
778 if( id == REFERENCE_FIELD )
779 {
780 field.SetText( aSymbol->GetInstances()[0].m_Reference );
781 }
782 else if( id == VALUE_FIELD )
783 {
784 field.SetText( aSymbol->GetField( VALUE_FIELD )->GetText() );
785 }
786 else if( id == FOOTPRINT_FIELD )
787 {
788 field.SetText( aSymbol->GetField( FOOTPRINT_FIELD )->GetText() );
789 }
790 }
791 else if( aForClipboard && aSymbol->GetInstances().size() && aRelativePath
792 && ( id == REFERENCE_FIELD ) )
793 {
794 SCH_SYMBOL_INSTANCE instance;
795
796 if( aSymbol->GetInstance( instance, aRelativePath->Path() ) )
797 field.SetText( instance.m_Reference );
798 }
799
800 try
801 {
802 saveField( &field, aNestLevel + 1 );
803 }
804 catch( ... )
805 {
806 // Restore the changed field text on write error.
807 if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
808 field.SetText( value );
809
810 throw;
811 }
812
813 if( id == REFERENCE_FIELD || id == VALUE_FIELD || id == FOOTPRINT_FIELD )
814 field.SetText( value );
815 }
816
817 for( const std::unique_ptr<SCH_PIN>& pin : aSymbol->GetRawPins() )
818 {
819 if( pin->GetAlt().IsEmpty() )
820 {
821 m_out->Print( aNestLevel + 1, "(pin %s ", m_out->Quotew( pin->GetNumber() ).c_str() );
823 m_out->Print( aNestLevel + 1, ")\n" );
824 }
825 else
826 {
827 m_out->Print( aNestLevel + 1, "(pin %s ", m_out->Quotew( pin->GetNumber() ).c_str() );
829 m_out->Print( aNestLevel + 1, " (alternate %s))\n",
830 m_out->Quotew( pin->GetAlt() ).c_str() );
831 }
832 }
833
834 if( !aSymbol->GetInstances().empty() )
835 {
836 std::map<KIID, std::vector<SCH_SYMBOL_INSTANCE>> projectInstances;
837
838 m_out->Print( aNestLevel + 1, "(instances\n" );
839
840 wxString projectName;
841 KIID lastProjectUuid;
842 KIID rootSheetUuid = aSchematic.Root().m_Uuid;
843
844 for( const SCH_SYMBOL_INSTANCE& inst : aSymbol->GetInstances() )
845 {
846 // Zero length KIID_PATH objects are not valid and will cause a crash below.
847 wxCHECK2( inst.m_Path.size(), continue );
848
849 // If the instance data is part of this design but no longer has an associated sheet
850 // path, don't save it. This prevents large amounts of orphaned instance data for the
851 // current project from accumulating in the schematic files.
852 bool isOrphaned = ( inst.m_Path[0] == rootSheetUuid )
853 && !aSheetList.GetSheetPathByKIIDPath( inst.m_Path );
854
855 // Keep all instance data when copying to the clipboard. They may be needed on paste.
856 if( !aForClipboard && isOrphaned )
857 continue;
858
859 auto it = projectInstances.find( inst.m_Path[0] );
860
861 if( it == projectInstances.end() )
862 {
863 projectInstances[ inst.m_Path[0] ] = { inst };
864 }
865 else
866 {
867 it->second.emplace_back( inst );
868 }
869 }
870
871 for( auto& [uuid, instances] : projectInstances )
872 {
873 wxCHECK2( instances.size(), continue );
874
875 // Sort project instances by KIID_PATH.
876 std::sort( instances.begin(), instances.end(),
878 {
879 return aLhs.m_Path < aRhs.m_Path;
880 } );
881
882 projectName = instances[0].m_ProjectName;
883
884 m_out->Print( aNestLevel + 2, "(project %s\n",
885 m_out->Quotew( projectName ).c_str() );
886
887 for( const SCH_SYMBOL_INSTANCE& instance : instances )
888 {
889 wxString path;
890 KIID_PATH tmp = instance.m_Path;
891
892 if( aForClipboard && aRelativePath )
893 tmp.MakeRelativeTo( aRelativePath->Path() );
894
895 path = tmp.AsString();
896
897 m_out->Print( aNestLevel + 3, "(path %s\n",
898 m_out->Quotew( path ).c_str() );
899 m_out->Print( aNestLevel + 4, "(reference %s) (unit %d)\n",
900 m_out->Quotew( instance.m_Reference ).c_str(),
901 instance.m_Unit );
902 m_out->Print( aNestLevel + 3, ")\n" );
903 }
904
905 m_out->Print( aNestLevel + 2, ")\n" ); // Closes `project`.
906 }
907
908 m_out->Print( aNestLevel + 1, ")\n" ); // Closes `instances`.
909 }
910
911 m_out->Print( aNestLevel, ")\n" ); // Closes `symbol`.
912}
913
914
915void SCH_IO_KICAD_SEXPR::saveField( SCH_FIELD* aField, int aNestLevel )
916{
917 wxCHECK_RET( aField != nullptr && m_out != nullptr, "" );
918
919 wxString fieldName = aField->GetCanonicalName();
920 // For some reason (bug in legacy parser?) the field ID for non-mandatory fields is -1 so
921 // check for this in order to correctly use the field name.
922
923 if( aField->GetId() == -1 /* undefined ID */ )
924 {
925 // Replace the default name built by GetCanonicalName() by
926 // the field name if exists
927 if( !aField->GetName().IsEmpty() )
928 fieldName = aField->GetName();
929
930 aField->SetId( m_nextFreeFieldId );
932 }
933 else if( aField->GetId() >= m_nextFreeFieldId )
934 {
935 m_nextFreeFieldId = aField->GetId() + 1;
936 }
937
938 m_out->Print( aNestLevel, "(property %s %s (at %s %s %s)",
939 m_out->Quotew( fieldName ).c_str(),
940 m_out->Quotew( aField->GetText() ).c_str(),
942 aField->GetPosition().x ).c_str(),
944 aField->GetPosition().y ).c_str(),
945 EDA_UNIT_UTILS::FormatAngle( aField->GetTextAngle() ).c_str() );
946
947 if( aField->IsNameShown() )
948 m_out->Print( 0, " (show_name yes)" );
949
950 if( !aField->CanAutoplace() )
951 m_out->Print( 0, " (do_not_autoplace yes)" );
952
953 if( !aField->IsDefaultFormatting()
954 || ( aField->GetTextHeight() != schIUScale.MilsToIU( DEFAULT_SIZE_TEXT ) ) )
955 {
956 m_out->Print( 0, "\n" );
957 aField->Format( m_out, aNestLevel, 0 );
958 m_out->Print( aNestLevel, ")\n" ); // Closes property token with font effects.
959 }
960 else
961 {
962 m_out->Print( 0, ")\n" ); // Closes property token without font effects.
963 }
964}
965
966
967void SCH_IO_KICAD_SEXPR::saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel )
968{
969 wxCHECK_RET( aBitmap != nullptr && m_out != nullptr, "" );
970
971 const wxImage* image = aBitmap->GetImage()->GetImageData();
972
973 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
974
975 m_out->Print( aNestLevel, "(image (at %s %s)",
977 aBitmap->GetPosition().x ).c_str(),
979 aBitmap->GetPosition().y ).c_str() );
980
981 double scale = aBitmap->GetImage()->GetScale();
982
983 // 20230121 or older file format versions assumed 300 image PPI at load/save.
984 // Let's keep compatibility by changing image scale.
985 if( SEXPR_SCHEMATIC_FILE_VERSION <= 20230121 )
986 {
987 BITMAP_BASE* bm_image = aBitmap->GetImage();
988 scale = scale * 300.0 / bm_image->GetPPI();
989 }
990
991 if( scale != 1.0 )
992 m_out->Print( 0, " (scale %g)", scale );
993
994 m_out->Print( 0, "\n" );
995
997
998 m_out->Print( aNestLevel + 1, "(data" );
999
1000 wxString out = wxBase64Encode( aBitmap->GetImage()->GetImageDataBuffer() );
1001
1002 // Apparently the MIME standard character width for base64 encoding is 76 (unconfirmed)
1003 // so use it in a vein attempt to be standard like.
1004#define MIME_BASE64_LENGTH 76
1005
1006 size_t first = 0;
1007
1008 while( first < out.Length() )
1009 {
1010 m_out->Print( 0, "\n" );
1011 m_out->Print( aNestLevel + 2, "\"%s\"", TO_UTF8( out( first, MIME_BASE64_LENGTH ) ) );
1012 first += MIME_BASE64_LENGTH;
1013 }
1014
1015 m_out->Print( 0, "\n" );
1016 m_out->Print( aNestLevel + 1, ")\n" ); // Closes data token.
1017 m_out->Print( aNestLevel, ")\n" ); // Closes image token.
1018}
1019
1020
1022 int aNestLevel )
1023{
1024 wxCHECK_RET( aSheet != nullptr && m_out != nullptr, "" );
1025
1026 m_out->Print( aNestLevel, "(sheet (at %s %s) (size %s %s)",
1028 aSheet->GetPosition().x ).c_str(),
1030 aSheet->GetPosition().y ).c_str(),
1032 aSheet->GetSize().x ).c_str(),
1034 aSheet->GetSize().y ).c_str() );
1035
1036 m_out->Print( 0, " (exclude_from_sim %s)", ( aSheet->GetExcludedFromSim() ) ? "yes" : "no" );
1037 m_out->Print( 0, " (in_bom %s)", ( aSheet->GetExcludedFromBOM() ) ? "no" : "yes" );
1038 m_out->Print( 0, " (on_board %s)", ( aSheet->GetExcludedFromBoard() ) ? "no" : "yes" );
1039 m_out->Print( 0, " (dnp %s)", ( aSheet->GetDNP() ) ? "yes" : "no" );
1040
1041 if( aSheet->GetFieldsAutoplaced() != FIELDS_AUTOPLACED_NO )
1042 m_out->Print( 0, " (fields_autoplaced yes)" );
1043
1044 m_out->Print( 0, "\n" );
1045
1046 STROKE_PARAMS stroke( aSheet->GetBorderWidth(), LINE_STYLE::SOLID, aSheet->GetBorderColor() );
1047
1048 stroke.SetWidth( aSheet->GetBorderWidth() );
1049 stroke.Format( m_out, schIUScale, aNestLevel + 1 );
1050
1051 m_out->Print( 0, "\n" );
1052
1053 m_out->Print( aNestLevel + 1, "(fill (color %d %d %d %0.4f))\n",
1054 KiROUND( aSheet->GetBackgroundColor().r * 255.0 ),
1055 KiROUND( aSheet->GetBackgroundColor().g * 255.0 ),
1056 KiROUND( aSheet->GetBackgroundColor().b * 255.0 ),
1057 aSheet->GetBackgroundColor().a );
1058
1060
1062
1063 for( SCH_FIELD& field : aSheet->GetFields() )
1064 {
1065 saveField( &field, aNestLevel + 1 );
1066 }
1067
1068 for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1069 {
1070 m_out->Print( aNestLevel + 1, "(pin %s %s (at %s %s %s)\n",
1071 EscapedUTF8( pin->GetText() ).c_str(),
1072 getSheetPinShapeToken( pin->GetShape() ),
1074 pin->GetPosition().x ).c_str(),
1076 pin->GetPosition().y ).c_str(),
1077 EDA_UNIT_UTILS::FormatAngle( getSheetPinAngle( pin->GetSide() ) ).c_str() );
1078
1079 pin->Format( m_out, aNestLevel + 1, 0 );
1080
1082
1083 m_out->Print( aNestLevel + 1, ")\n" ); // Closes pin token.
1084 }
1085
1086 // Save all sheet instances here except the root sheet instance.
1087 std::vector< SCH_SHEET_INSTANCE > sheetInstances = aSheet->GetInstances();
1088
1089 auto it = sheetInstances.begin();
1090
1091 while( it != sheetInstances.end() )
1092 {
1093 if( it->m_Path.size() == 0 )
1094 it = sheetInstances.erase( it );
1095 else
1096 it++;
1097 }
1098
1099 if( !sheetInstances.empty() )
1100 {
1101 m_out->Print( aNestLevel + 1, "(instances\n" );
1102
1103 KIID lastProjectUuid;
1104 KIID rootSheetUuid = m_schematic->Root().m_Uuid;
1105 bool project_open = false;
1106
1107 for( size_t i = 0; i < sheetInstances.size(); i++ )
1108 {
1109 // If the instance data is part of this design but no longer has an associated sheet
1110 // path, don't save it. This prevents large amounts of orphaned instance data for the
1111 // current project from accumulating in the schematic files.
1112 //
1113 // Keep all instance data when copying to the clipboard. It may be needed on paste.
1114 if( ( sheetInstances[i].m_Path[0] == rootSheetUuid )
1115 && !aSheetList.GetSheetPathByKIIDPath( sheetInstances[i].m_Path, false ) )
1116 {
1117 if( project_open && ( ( i + 1 == sheetInstances.size() )
1118 || lastProjectUuid != sheetInstances[i+1].m_Path[0] ) )
1119 {
1120 m_out->Print( aNestLevel + 2, ")\n" ); // Closes `project` token.
1121 project_open = false;
1122 }
1123
1124 continue;
1125 }
1126
1127 if( lastProjectUuid != sheetInstances[i].m_Path[0] )
1128 {
1129 wxString projectName;
1130
1131 if( sheetInstances[i].m_Path[0] == rootSheetUuid )
1132 projectName = m_schematic->Prj().GetProjectName();
1133 else
1134 projectName = sheetInstances[i].m_ProjectName;
1135
1136 lastProjectUuid = sheetInstances[i].m_Path[0];
1137 m_out->Print( aNestLevel + 2, "(project %s\n",
1138 m_out->Quotew( projectName ).c_str() );
1139 project_open = true;
1140 }
1141
1142 wxString path = sheetInstances[i].m_Path.AsString();
1143
1144 m_out->Print( aNestLevel + 3, "(path %s (page %s))\n",
1145 m_out->Quotew( path ).c_str(),
1146 m_out->Quotew( sheetInstances[i].m_PageNumber ).c_str() );
1147
1148 if( project_open && ( ( i + 1 == sheetInstances.size() )
1149 || lastProjectUuid != sheetInstances[i+1].m_Path[0] ) )
1150 {
1151 m_out->Print( aNestLevel + 2, ")\n" ); // Closes `project` token.
1152 project_open = false;
1153 }
1154 }
1155
1156 m_out->Print( aNestLevel + 1, ")\n" ); // Closes `instances` token.
1157 }
1158
1159 m_out->Print( aNestLevel, ")\n" ); // Closes sheet token.
1160}
1161
1162
1163void SCH_IO_KICAD_SEXPR::saveJunction( SCH_JUNCTION* aJunction, int aNestLevel )
1164{
1165 wxCHECK_RET( aJunction != nullptr && m_out != nullptr, "" );
1166
1167 m_out->Print( aNestLevel, "(junction (at %s %s) (diameter %s) (color %d %d %d %s)\n",
1169 aJunction->GetPosition().x ).c_str(),
1171 aJunction->GetPosition().y ).c_str(),
1173 aJunction->GetDiameter() ).c_str(),
1174 KiROUND( aJunction->GetColor().r * 255.0 ),
1175 KiROUND( aJunction->GetColor().g * 255.0 ),
1176 KiROUND( aJunction->GetColor().b * 255.0 ),
1177 FormatDouble2Str( aJunction->GetColor().a ).c_str() );
1178
1179 KICAD_FORMAT::FormatUuid( m_out, aJunction->m_Uuid );
1180
1181 m_out->Print( aNestLevel, ")\n" );
1182}
1183
1184
1185void SCH_IO_KICAD_SEXPR::saveNoConnect( SCH_NO_CONNECT* aNoConnect, int aNestLevel )
1186{
1187 wxCHECK_RET( aNoConnect != nullptr && m_out != nullptr, "" );
1188
1189 m_out->Print( aNestLevel, "(no_connect (at %s %s)",
1191 aNoConnect->GetPosition().x ).c_str(),
1193 aNoConnect->GetPosition().y ).c_str() );
1194 KICAD_FORMAT::FormatUuid( m_out, aNoConnect->m_Uuid );
1195 m_out->Print( aNestLevel, ")\n" );
1196}
1197
1198
1200{
1201 wxCHECK_RET( aBusEntry != nullptr && m_out != nullptr, "" );
1202
1203 // Bus to bus entries are converted to bus line segments.
1204 if( aBusEntry->GetClass() == "SCH_BUS_BUS_ENTRY" )
1205 {
1206 SCH_LINE busEntryLine( aBusEntry->GetPosition(), LAYER_BUS );
1207
1208 busEntryLine.SetEndPoint( aBusEntry->GetEnd() );
1209 saveLine( &busEntryLine, aNestLevel );
1210 }
1211 else
1212 {
1213 m_out->Print( aNestLevel, "(bus_entry (at %s %s) (size %s %s)\n",
1215 aBusEntry->GetPosition().x ).c_str(),
1217 aBusEntry->GetPosition().y ).c_str(),
1219 aBusEntry->GetSize().x ).c_str(),
1221 aBusEntry->GetSize().y ).c_str() );
1222
1223 aBusEntry->GetStroke().Format( m_out, schIUScale, aNestLevel + 1 );
1224
1225 m_out->Print( 0, "\n" );
1226
1227 KICAD_FORMAT::FormatUuid( m_out, aBusEntry->m_Uuid );
1228
1229 m_out->Print( aNestLevel, ")\n" );
1230 }
1231}
1232
1233
1234void SCH_IO_KICAD_SEXPR::saveShape( SCH_SHAPE* aShape, int aNestLevel )
1235{
1236 wxCHECK_RET( aShape != nullptr && m_out != nullptr, "" );
1237
1238 switch( aShape->GetShape() )
1239 {
1240 case SHAPE_T::ARC:
1241 formatArc( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1242 aShape->GetFillColor(), false, aShape->m_Uuid );
1243 break;
1244
1245 case SHAPE_T::CIRCLE:
1246 formatCircle( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1247 aShape->GetFillColor(), false, aShape->m_Uuid );
1248 break;
1249
1250 case SHAPE_T::RECTANGLE:
1251 formatRect( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1252 aShape->GetFillColor(), false, aShape->m_Uuid );
1253 break;
1254
1255 case SHAPE_T::BEZIER:
1256 formatBezier( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1257 aShape->GetFillColor(), false, aShape->m_Uuid );
1258 break;
1259
1260 case SHAPE_T::POLY:
1261 formatPoly( m_out, aNestLevel, aShape, false, aShape->GetStroke(), aShape->GetFillMode(),
1262 aShape->GetFillColor(), false, aShape->m_Uuid );
1263 break;
1264
1265 default:
1267 }
1268}
1269
1270
1271void SCH_IO_KICAD_SEXPR::saveRuleArea( SCH_RULE_AREA* aRuleArea, int aNestLevel )
1272{
1273 wxCHECK_RET( aRuleArea != nullptr && m_out != nullptr, "" );
1274
1275 m_out->Print( aNestLevel, "(rule_area " );
1276 saveShape( aRuleArea, aNestLevel + 1 );
1277 m_out->Print( aNestLevel, ")\n" );
1278}
1279
1280
1281void SCH_IO_KICAD_SEXPR::saveLine( SCH_LINE* aLine, int aNestLevel )
1282{
1283 wxCHECK_RET( aLine != nullptr && m_out != nullptr, "" );
1284
1285 wxString lineType;
1286
1287 STROKE_PARAMS line_stroke = aLine->GetStroke();
1288
1289 switch( aLine->GetLayer() )
1290 {
1291 case LAYER_BUS: lineType = "bus"; break;
1292 case LAYER_WIRE: lineType = "wire"; break;
1293 case LAYER_NOTES: lineType = "polyline"; break;
1294 default:
1295 UNIMPLEMENTED_FOR( LayerName( aLine->GetLayer() ) );
1296 }
1297
1298 m_out->Print( aNestLevel, "(%s (pts (xy %s %s) (xy %s %s))\n",
1299 TO_UTF8( lineType ),
1301 aLine->GetStartPoint().x ).c_str(),
1303 aLine->GetStartPoint().y ).c_str(),
1305 aLine->GetEndPoint().x ).c_str(),
1307 aLine->GetEndPoint().y ).c_str() );
1308
1309 line_stroke.Format( m_out, schIUScale, aNestLevel + 1 );
1310 m_out->Print( 0, "\n" );
1311
1313
1314 m_out->Print( aNestLevel, ")\n" );
1315}
1316
1317
1318void SCH_IO_KICAD_SEXPR::saveText( SCH_TEXT* aText, int aNestLevel )
1319{
1320 wxCHECK_RET( aText != nullptr && m_out != nullptr, "" );
1321
1322 // Note: label is nullptr SCH_TEXT, but not for SCH_LABEL_XXX,
1323 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aText );
1324
1325 m_out->Print( aNestLevel, "(%s %s",
1326 getTextTypeToken( aText->Type() ),
1327 m_out->Quotew( aText->GetText() ).c_str() );
1328
1329 if( aText->Type() == SCH_TEXT_T )
1330 {
1331 m_out->Print( 0, " (exclude_from_sim %s)\n", aText->GetExcludedFromSim() ? "yes" : "no" );
1332 }
1333 else if( aText->Type() == SCH_DIRECTIVE_LABEL_T )
1334 {
1335 SCH_DIRECTIVE_LABEL* flag = static_cast<SCH_DIRECTIVE_LABEL*>( aText );
1336
1337 m_out->Print( 0, " (length %s)",
1339 flag->GetPinLength() ).c_str() );
1340 }
1341
1342 EDA_ANGLE angle = aText->GetTextAngle();
1343
1344 if( label )
1345 {
1346 if( label->Type() == SCH_GLOBAL_LABEL_T
1347 || label->Type() == SCH_HIER_LABEL_T
1348 || label->Type() == SCH_DIRECTIVE_LABEL_T )
1349 {
1350 m_out->Print( 0, " (shape %s)", getSheetPinShapeToken( label->GetShape() ) );
1351 }
1352
1353 // The angle of the text is always 0 or 90 degrees for readibility reasons,
1354 // but the item itself can have more rotation (-90 and 180 deg)
1355 switch( label->GetSpinStyle() )
1356 {
1357 default:
1358 case SPIN_STYLE::LEFT: angle += ANGLE_180; break;
1359 case SPIN_STYLE::UP: break;
1360 case SPIN_STYLE::RIGHT: break;
1361 case SPIN_STYLE::BOTTOM: angle += ANGLE_180; break;
1362 }
1363 }
1364
1365 if( aText->GetText().Length() < 50 )
1366 {
1367 m_out->Print( 0, " (at %s %s %s)",
1369 aText->GetPosition().x ).c_str(),
1371 aText->GetPosition().y ).c_str(),
1372 EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
1373 }
1374 else
1375 {
1376 m_out->Print( 0, "\n" );
1377 m_out->Print( aNestLevel + 1, "(at %s %s %s)",
1379 aText->GetPosition().x ).c_str(),
1381 aText->GetPosition().y ).c_str(),
1382 EDA_UNIT_UTILS::FormatAngle( angle ).c_str() );
1383 }
1384
1386 m_out->Print( 0, " (fields_autoplaced yes)" );
1387
1388 m_out->Print( 0, "\n" );
1389 aText->EDA_TEXT::Format( m_out, aNestLevel, 0 );
1390
1392
1393 if( label )
1394 {
1395 for( SCH_FIELD& field : label->GetFields() )
1396 saveField( &field, aNestLevel + 1 );
1397 }
1398
1399 m_out->Print( aNestLevel, ")\n" ); // Closes text token.
1400}
1401
1402
1403void SCH_IO_KICAD_SEXPR::saveTextBox( SCH_TEXTBOX* aTextBox, int aNestLevel )
1404{
1405 wxCHECK_RET( aTextBox != nullptr && m_out != nullptr, "" );
1406
1407 m_out->Print( aNestLevel, "(%s %s\n",
1408 aTextBox->Type() == SCH_TABLECELL_T ? "table_cell" : "text_box",
1409 m_out->Quotew( aTextBox->GetText() ).c_str() );
1410
1411 VECTOR2I pos = aTextBox->GetStart();
1412 VECTOR2I size = aTextBox->GetEnd() - pos;
1413
1414 m_out->Print( aNestLevel + 1, "(exclude_from_sim %s) (at %s %s %s) (size %s %s) (margins %s %s %s %s)",
1415 aTextBox->GetExcludedFromSim() ? "yes" : "no",
1418 EDA_UNIT_UTILS::FormatAngle( aTextBox->GetTextAngle() ).c_str(),
1425
1426 if( SCH_TABLECELL* cell = dynamic_cast<SCH_TABLECELL*>( aTextBox ) )
1427 m_out->Print( 0, " (span %d %d)", cell->GetColSpan(), cell->GetRowSpan() );
1428
1429 m_out->Print( 0, "\n" );
1430
1431 if( aTextBox->Type() != SCH_TABLECELL_T )
1432 {
1433 aTextBox->GetStroke().Format( m_out, schIUScale, aNestLevel + 1 );
1434 m_out->Print( 0, "\n" );
1435 }
1436
1437 formatFill( m_out, aNestLevel + 1, aTextBox->GetFillMode(), aTextBox->GetFillColor() );
1438 m_out->Print( 0, "\n" );
1439
1440 aTextBox->EDA_TEXT::Format( m_out, aNestLevel, 0 );
1441
1442 if( aTextBox->m_Uuid != niluuid )
1444
1445 m_out->Print( aNestLevel, ")\n" );
1446}
1447
1448
1449void SCH_IO_KICAD_SEXPR::saveTable( SCH_TABLE* aTable, int aNestLevel )
1450{
1451 if( aTable->GetFlags() & SKIP_STRUCT )
1452 {
1453 aTable = static_cast<SCH_TABLE*>( aTable->Clone() );
1454
1455 int minCol = aTable->GetColCount();
1456 int maxCol = -1;
1457 int minRow = aTable->GetRowCount();
1458 int maxRow = -1;
1459
1460 for( int row = 0; row < aTable->GetRowCount(); ++row )
1461 {
1462 for( int col = 0; col < aTable->GetColCount(); ++col )
1463 {
1464 SCH_TABLECELL* cell = aTable->GetCell( row, col );
1465
1466 if( cell->IsSelected() )
1467 {
1468 minRow = std::min( minRow, row );
1469 maxRow = std::max( maxRow, row );
1470 minCol = std::min( minCol, col );
1471 maxCol = std::max( maxCol, col );
1472 }
1473 else
1474 {
1475 cell->SetFlags( STRUCT_DELETED );
1476 }
1477 }
1478 }
1479
1480 wxCHECK_MSG( maxCol >= minCol && maxRow >= minRow, /*void*/, wxT( "No selected cells!" ) );
1481
1482 int destRow = 0;
1483
1484 for( int row = minRow; row <= maxRow; row++ )
1485 aTable->SetRowHeight( destRow++, aTable->GetRowHeight( row ) );
1486
1487 int destCol = 0;
1488
1489 for( int col = minCol; col <= maxCol; col++ )
1490 aTable->SetColWidth( destCol++, aTable->GetColWidth( col ) );
1491
1492 aTable->DeleteMarkedCells();
1493 aTable->SetColCount( ( maxCol - minCol ) + 1 );
1494 }
1495
1496 wxCHECK_RET( aTable != nullptr && m_out != nullptr, "" );
1497
1498 m_out->Print( aNestLevel, "(table (column_count %d)\n",
1499 aTable->GetColCount() );
1500
1501 m_out->Print( aNestLevel + 1, "(border (external %s) (header %s)",
1502 aTable->StrokeExternal() ? "yes" : "no",
1503 aTable->StrokeHeader() ? "yes" : "no" );
1504
1505 if( aTable->StrokeExternal() || aTable->StrokeHeader() )
1506 {
1507 m_out->Print( 0, " " );
1508 aTable->GetBorderStroke().Format( m_out, schIUScale, 0 );
1509 }
1510
1511 m_out->Print( 0, ")\n" );
1512
1513 m_out->Print( aNestLevel + 1, "(separators (rows %s) (cols %s)",
1514 aTable->StrokeRows() ? "yes" : "no",
1515 aTable->StrokeColumns() ? "yes" : "no" );
1516
1517 if( aTable->StrokeRows() || aTable->StrokeColumns() )
1518 {
1519 m_out->Print( 0, " " );
1520 aTable->GetSeparatorsStroke().Format( m_out, schIUScale, 0 );
1521 }
1522
1523 m_out->Print( 0, ")\n" ); // Close `separators` token.
1524
1525 m_out->Print( aNestLevel + 1, "(column_widths" );
1526
1527 for( int col = 0; col < aTable->GetColCount(); ++col )
1528 {
1529 m_out->Print( 0, " %s",
1531 aTable->GetColWidth( col ) ).c_str() );
1532 }
1533
1534 m_out->Print( 0, ")\n" );
1535
1536 m_out->Print( aNestLevel + 1, "(row_heights" );
1537
1538 for( int row = 0; row < aTable->GetRowCount(); ++row )
1539 {
1540 m_out->Print( 0, " %s",
1542 aTable->GetRowHeight( row ) ).c_str() );
1543 }
1544
1545 m_out->Print( 0, ")\n" );
1546
1547 m_out->Print( aNestLevel + 1, "(cells\n" );
1548
1549 for( SCH_TABLECELL* cell : aTable->GetCells() )
1550 saveTextBox( cell, aNestLevel + 2 );
1551
1552 m_out->Print( aNestLevel + 1, ")\n" ); // Close `cells` token.
1553 m_out->Print( aNestLevel, ")\n" ); // Close `table` token.
1554
1555 if( aTable->GetFlags() & SKIP_STRUCT )
1556 delete aTable;
1557}
1558
1559
1560void SCH_IO_KICAD_SEXPR::saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias, int aNestLevel )
1561{
1562 wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
1563
1564 wxString members;
1565
1566 for( const wxString& member : aAlias->Members() )
1567 {
1568 if( !members.IsEmpty() )
1569 members += wxS( " " );
1570
1571 members += m_out->Quotew( member );
1572 }
1573
1574 m_out->Print( aNestLevel, "(bus_alias %s (members %s))\n",
1575 m_out->Quotew( aAlias->GetName() ).c_str(),
1576 TO_UTF8( members ) );
1577}
1578
1579
1580void SCH_IO_KICAD_SEXPR::saveInstances( const std::vector<SCH_SHEET_INSTANCE>& aInstances,
1581 int aNestLevel )
1582{
1583 if( aInstances.size() )
1584 {
1585 m_out->Print( 0, "\n" );
1586 m_out->Print( aNestLevel, "(sheet_instances\n" );
1587
1588 for( const SCH_SHEET_INSTANCE& instance : aInstances )
1589 {
1590 wxString path = instance.m_Path.AsString();
1591
1592 if( path.IsEmpty() )
1593 path = wxT( "/" ); // Root path
1594
1595 m_out->Print( aNestLevel + 1, "(path %s (page %s))\n",
1596 m_out->Quotew( path ).c_str(),
1597 m_out->Quotew( instance.m_PageNumber ).c_str() );
1598 }
1599
1600 m_out->Print( aNestLevel, ")\n" ); // Close sheet instances token.
1601 }
1602}
1603
1604
1605void SCH_IO_KICAD_SEXPR::cacheLib( const wxString& aLibraryFileName,
1606 const STRING_UTF8_MAP* aProperties )
1607{
1608 // Suppress font substitution warnings
1610
1611 if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
1612 {
1613 // a spectacular episode in memory management:
1614 delete m_cache;
1615 m_cache = new SCH_IO_KICAD_SEXPR_LIB_CACHE( aLibraryFileName );
1616
1617 if( !isBuffering( aProperties ) )
1618 m_cache->Load();
1619 }
1620}
1621
1622
1624{
1625 return ( aProperties && aProperties->Exists( SCH_IO_KICAD_SEXPR::PropBuffering ) );
1626}
1627
1628
1630{
1631 if( m_cache )
1632 return m_cache->GetModifyHash();
1633
1634 // If the cache hasn't been loaded, it hasn't been modified.
1635 return 0;
1636}
1637
1638
1639void SCH_IO_KICAD_SEXPR::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
1640 const wxString& aLibraryPath,
1641 const STRING_UTF8_MAP* aProperties )
1642{
1643 LOCALE_IO toggle; // toggles on, then off, the C locale.
1644
1645 bool powerSymbolsOnly = ( aProperties &&
1646 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
1647
1648 cacheLib( aLibraryPath, aProperties );
1649
1650 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1651
1652 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1653 {
1654 if( !powerSymbolsOnly || it->second->IsPower() )
1655 aSymbolNameList.Add( it->first );
1656 }
1657}
1658
1659
1660void SCH_IO_KICAD_SEXPR::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
1661 const wxString& aLibraryPath,
1662 const STRING_UTF8_MAP* aProperties )
1663{
1664 LOCALE_IO toggle; // toggles on, then off, the C locale.
1665
1666 bool powerSymbolsOnly = ( aProperties &&
1667 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
1668
1669 cacheLib( aLibraryPath, aProperties );
1670
1671 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1672
1673 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1674 {
1675 if( !powerSymbolsOnly || it->second->IsPower() )
1676 aSymbolList.push_back( it->second );
1677 }
1678}
1679
1680
1681LIB_SYMBOL* SCH_IO_KICAD_SEXPR::LoadSymbol( const wxString& aLibraryPath,
1682 const wxString& aSymbolName,
1683 const STRING_UTF8_MAP* aProperties )
1684{
1685 LOCALE_IO toggle; // toggles on, then off, the C locale.
1686
1687 cacheLib( aLibraryPath, aProperties );
1688
1689 LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
1690
1691 // We no longer escape '/' in symbol names, but we used to.
1692 if( it == m_cache->m_symbols.end() && aSymbolName.Contains( '/' ) )
1693 it = m_cache->m_symbols.find( EscapeString( aSymbolName, CTX_LEGACY_LIBID ) );
1694
1695 if( it == m_cache->m_symbols.end() && aSymbolName.Contains( wxT( "{slash}" ) ) )
1696 {
1697 wxString unescaped = aSymbolName;
1698 unescaped.Replace( wxT( "{slash}" ), wxT( "/" ) );
1699 it = m_cache->m_symbols.find( unescaped );
1700 }
1701
1702 if( it == m_cache->m_symbols.end() )
1703 return nullptr;
1704
1705 return it->second;
1706}
1707
1708
1709void SCH_IO_KICAD_SEXPR::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
1710 const STRING_UTF8_MAP* aProperties )
1711{
1712 LOCALE_IO toggle; // toggles on, then off, the C locale.
1713
1714 cacheLib( aLibraryPath, aProperties );
1715
1716 m_cache->AddSymbol( aSymbol );
1717
1718 if( !isBuffering( aProperties ) )
1719 m_cache->Save();
1720}
1721
1722
1723void SCH_IO_KICAD_SEXPR::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
1724 const STRING_UTF8_MAP* aProperties )
1725{
1726 LOCALE_IO toggle; // toggles on, then off, the C locale.
1727
1728 cacheLib( aLibraryPath, aProperties );
1729
1730 m_cache->DeleteSymbol( aSymbolName );
1731
1732 if( !isBuffering( aProperties ) )
1733 m_cache->Save();
1734}
1735
1736
1737void SCH_IO_KICAD_SEXPR::CreateLibrary( const wxString& aLibraryPath,
1738 const STRING_UTF8_MAP* aProperties )
1739{
1740 if( wxFileExists( aLibraryPath ) )
1741 {
1742 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
1743 aLibraryPath.GetData() ) );
1744 }
1745
1746 LOCALE_IO toggle;
1747
1748 delete m_cache;
1749 m_cache = new SCH_IO_KICAD_SEXPR_LIB_CACHE( aLibraryPath );
1751 m_cache->Save();
1752 m_cache->Load(); // update m_writable and m_mod_time
1753}
1754
1755
1756bool SCH_IO_KICAD_SEXPR::DeleteLibrary( const wxString& aLibraryPath,
1757 const STRING_UTF8_MAP* aProperties )
1758{
1759 wxFileName fn = aLibraryPath;
1760
1761 if( !fn.FileExists() )
1762 return false;
1763
1764 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
1765 // we don't want that. we want bare metal portability with no UI here.
1766 if( wxRemove( aLibraryPath ) )
1767 {
1768 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' cannot be deleted." ),
1769 aLibraryPath.GetData() ) );
1770 }
1771
1772 if( m_cache && m_cache->IsFile( aLibraryPath ) )
1773 {
1774 delete m_cache;
1775 m_cache = nullptr;
1776 }
1777
1778 return true;
1779}
1780
1781
1782void SCH_IO_KICAD_SEXPR::SaveLibrary( const wxString& aLibraryPath,
1783 const STRING_UTF8_MAP* aProperties )
1784{
1785 if( !m_cache )
1786 m_cache = new SCH_IO_KICAD_SEXPR_LIB_CACHE( aLibraryPath );
1787
1788 wxString oldFileName = m_cache->GetFileName();
1789
1790 if( !m_cache->IsFile( aLibraryPath ) )
1791 {
1792 m_cache->SetFileName( aLibraryPath );
1793 }
1794
1795 // This is a forced save.
1797 m_cache->Save();
1798 m_cache->SetFileName( oldFileName );
1799}
1800
1801
1802bool SCH_IO_KICAD_SEXPR::IsLibraryWritable( const wxString& aLibraryPath )
1803{
1804 wxFileName fn( aLibraryPath );
1805
1806 return ( fn.FileExists() && fn.IsFileWritable() ) || fn.IsDirWritable();
1807}
1808
1809
1810void SCH_IO_KICAD_SEXPR::GetAvailableSymbolFields( std::vector<wxString>& aNames )
1811{
1812 if( !m_cache )
1813 return;
1814
1815 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
1816
1817 std::set<wxString> fieldNames;
1818
1819 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
1820 {
1821 std::vector<SCH_FIELD*> fields;
1822 it->second->GetFields( fields );
1823
1824 for( SCH_FIELD* field : fields )
1825 {
1826 if( field->IsMandatory() )
1827 continue;
1828
1829 // TODO(JE): enable configurability of this outside database libraries?
1830 // if( field->ShowInChooser() )
1831 fieldNames.insert( field->GetName() );
1832 }
1833 }
1834
1835 std::copy( fieldNames.begin(), fieldNames.end(), std::back_inserter( aNames ) );
1836}
1837
1838
1839void SCH_IO_KICAD_SEXPR::GetDefaultSymbolFields( std::vector<wxString>& aNames )
1840{
1841 GetAvailableSymbolFields( aNames );
1842}
1843
1844
1845std::vector<LIB_SYMBOL*> SCH_IO_KICAD_SEXPR::ParseLibSymbols( std::string& aSymbolText,
1846 std::string aSource,
1847 int aFileVersion )
1848{
1849 LOCALE_IO toggle; // toggles on, then off, the C locale.
1850 LIB_SYMBOL* newSymbol = nullptr;
1851 LIB_SYMBOL_MAP map;
1852
1853 std::vector<LIB_SYMBOL*> newSymbols;
1854 std::unique_ptr<STRING_LINE_READER> reader = std::make_unique<STRING_LINE_READER>( aSymbolText,
1855 aSource );
1856
1857 do
1858 {
1859 SCH_IO_KICAD_SEXPR_PARSER parser( reader.get() );
1860
1861 newSymbol = parser.ParseSymbol( map, aFileVersion );
1862
1863 if( newSymbol )
1864 newSymbols.emplace_back( newSymbol );
1865
1866 reader.reset( new STRING_LINE_READER( *reader ) );
1867 }
1868 while( newSymbol );
1869
1870 return newSymbols;
1871}
1872
1873
1875{
1876
1877 LOCALE_IO toggle; // toggles on, then off, the C locale.
1878 SCH_IO_KICAD_SEXPR_LIB_CACHE::SaveSymbol( symbol, formatter );
1879}
1880
1881
1882const char* SCH_IO_KICAD_SEXPR::PropBuffering = "buffering";
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
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:48
double GetScale() const
Definition: bitmap_base.h:72
const wxMemoryBuffer & GetImageDataBuffer() const
Definition: bitmap_base.h:240
int GetPPI() const
Definition: bitmap_base.h:117
wxImage * GetImageData()
Definition: bitmap_base.h:67
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:127
const KIID m_Uuid
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:129
bool IsSelected() const
Definition: eda_item.h:110
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
EDA_ITEM_FLAGS GetFlags() const
Definition: eda_item.h:130
FILL_T GetFillMode() const
Definition: eda_shape.h:107
SHAPE_T GetShape() const
Definition: eda_shape.h:125
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:167
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:130
COLOR4D GetFillColor() const
Definition: eda_shape.h:111
wxString SHAPE_T_asString() const
Definition: eda_shape.cpp:89
int GetTextHeight() const
Definition: eda_text.h:224
bool IsDefaultFormatting() const
Definition: eda_text.cpp:896
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:130
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:94
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: eda_text.cpp:911
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
SCH_SCREEN * GetScreen()
Definition: ee_selection.h:52
bool IsEmpty() const
void WriteEmbeddedFiles(OUTPUTFORMATTER &aOut, int aNestLevel, bool aWriteData) const
Output formatter for the embedded files.
void ClearEmbeddedFonts()
Removes all embedded fonts from the collection.
bool GetAreFontsEmbedded() const
A LINE_READER that reads from an open file.
Definition: richio.h:185
void Rewind()
Rewind the file and resets the line number back to zero.
Definition: richio.h:234
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:244
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition: io_base.h:218
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
double r
Red component.
Definition: color4d.h:392
double g
Green component.
Definition: color4d.h:393
double a
Alpha component.
Definition: color4d.h:395
double b
Blue component.
Definition: color4d.h:394
bool MakeRelativeTo(const KIID_PATH &aPath)
Definition: kiid.cpp:311
wxString AsString() const
Definition: kiid.cpp:356
Definition: kiid.h:49
UTF8 Format() const
Definition: lib_id.cpp:118
Define a library symbol object.
Definition: lib_symbol.h:78
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
std::string Quotew(const wxString &aWrapee) const
Definition: richio.cpp:526
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the page class to aFormatter in s-expression form.
Definition: page_info.cpp:275
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.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:147
Holds all the data relating to one schematic.
Definition: schematic.h:76
void EmbedFonts() override
Embed fonts in the schematic.
Definition: schematic.cpp:866
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition: schematic.cpp:854
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:129
SCH_SHEET & Root() const
Definition: schematic.h:113
SCH_SHEET_LIST BuildSheetListSortedByPageNumbers() const override
Definition: schematic.h:96
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:91
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:41
VECTOR2I GetPosition() const override
Definition: sch_bitmap.h:145
BITMAP_BASE * GetImage() const
Definition: sch_bitmap.h:54
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
VECTOR2I GetSize() const
Definition: sch_bus_entry.h:73
VECTOR2I GetPosition() const override
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_bus_entry.h:81
VECTOR2I GetEnd() const
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1462
bool IsNameShown() const
Definition: sch_field.h:208
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: sch_field.cpp:1229
int GetId() const
Definition: sch_field.h:133
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1204
bool CanAutoplace() const
Definition: sch_field.h:219
void SetId(int aId)
Definition: sch_field.cpp:159
A cache assistant for the KiCad s-expression symbol libraries.
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, int aNestLevel=0, const wxString &aLibName=wxEmptyString, bool aIncludeData=true)
void DeleteSymbol(const wxString &aName) override
void Save(const std::optional< bool > &aOpt=std::nullopt) override
Save the entire library to file m_libFileName;.
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 SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
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 saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
void SaveLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
SCH_SHEET_PATH m_currentSheetPath
void saveRuleArea(SCH_RULE_AREA *aRuleArea, int aNestLevel)
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
void saveText(SCH_TEXT *aText, int aNestLevel)
bool m_appending
Schematic load append status.
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 cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
void loadHierarchy(const SCH_SHEET_PATH &aParentSheetPath, SCH_SHEET *aSheet)
static std::vector< LIB_SYMBOL * > ParseLibSymbols(std::string &aSymbolText, std::string aSource, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
void saveField(SCH_FIELD *aField, int aNestLevel)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
bool isBuffering(const STRING_UTF8_MAP *aProperties)
wxString m_error
For throwing exceptions or errors on partial loads.
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 init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.
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 saveSymbol(SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic, const SCH_SHEET_LIST &aSheetList, int aNestLevel, bool aForClipboard, const SCH_SHEET_PATH *aRelativePath=nullptr)
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
void saveShape(SCH_SHAPE *aShape, int aNestLevel)
int GetModifyHash() const override
Return the modification hash from the library cache.
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
void saveTextBox(SCH_TEXTBOX *aText, int aNestLevel)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
void saveInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheets, int aNestLevel)
void saveSheet(SCH_SHEET *aSheet, const SCH_SHEET_LIST &aSheetList, int aNestLevel)
bool DeleteLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
void CreateLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
void saveLine(SCH_LINE *aLine, int aNestLevel)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void saveTable(SCH_TABLE *aTable, int aNestLevel)
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
bool IsFile(const wxString &aFullPathAndFileName) const
void SetFileName(const wxString &aFileName)
virtual void AddSymbol(const LIB_SYMBOL *aSymbol)
LIB_SYMBOL_MAP m_symbols
bool IsFileChanged() const
wxString GetFileName() const
void SetModified(bool aModified=true)
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
int GetBodyStyle() const
Definition: sch_item.h:232
int GetUnit() const
Definition: sch_item.h:229
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:281
FIELDS_AUTOPLACED GetFieldsAutoplaced() const
Return whether the fields have been automatically placed.
Definition: sch_item.h:548
wxString GetClass() const override
Return the class name.
Definition: sch_item.h:176
COLOR4D GetColor() const
Definition: sch_junction.h:119
int GetDiameter() const
Definition: sch_junction.h:114
VECTOR2I GetPosition() const override
Definition: sch_junction.h:107
SPIN_STYLE GetSpinStyle() const
Definition: sch_label.cpp:383
LABEL_FLAG_SHAPE GetShape() const
Definition: sch_label.h:177
std::vector< SCH_FIELD > & GetFields()
Definition: sch_label.h:201
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
virtual STROKE_PARAMS GetStroke() const override
Definition: sch_line.h:184
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:142
VECTOR2I GetPosition() const override
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:130
auto & GetBusAliases() const
Return a set of bus aliases defined in this screen.
Definition: sch_screen.h:516
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:480
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
const wxString & GetFileName() const
Definition: sch_screen.h:143
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:117
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:154
KIID m_uuid
A unique identifier for each schematic file.
Definition: sch_screen.h:696
void SetFileReadOnly(bool aIsReadOnly)
Definition: sch_screen.h:145
void SetFileExists(bool aFileExists)
Definition: sch_screen.h:148
STROKE_PARAMS GetStroke() const override
Definition: sch_shape.h:55
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()
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
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.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
bool GetExcludedFromBOM() const
Definition: sch_sheet.h:376
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:306
bool HasRootInstance() const
Check to see if this sheet has a root sheet instance.
Definition: sch_sheet.cpp:1477
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
bool GetExcludedFromBoard() const
Definition: sch_sheet.h:382
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:782
VECTOR2I GetSize() const
Definition: sch_sheet.h:112
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:400
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:172
const SCH_SHEET_INSTANCE & GetRootInstance() const
Return the root sheet instance data.
Definition: sch_sheet.cpp:1489
KIGFX::COLOR4D GetBorderColor() const
Definition: sch_sheet.h:118
bool GetExcludedFromSim() const override
Definition: sch_sheet.h:370
int GetBorderWidth() const
Definition: sch_sheet.h:115
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
const std::vector< SCH_SHEET_INSTANCE > & GetInstances() const
Definition: sch_sheet.h:417
bool GetDNP() const
Set or clear the 'Do Not Populate' flaga.
Definition: sch_sheet.h:387
KIGFX::COLOR4D GetBackgroundColor() const
Definition: sch_sheet.h:121
Schematic symbol object.
Definition: sch_symbol.h:105
std::vector< std::unique_ptr< SCH_PIN > > & GetRawPins()
Definition: sch_symbol.h:662
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition: sch_symbol.h:164
bool UseLibIdLookup() const
Definition: sch_symbol.h:211
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:266
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:919
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:802
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:194
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_symbol.cpp:568
int GetOrientation() const
Get the display symbol orientation.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:967
void SetRowHeight(int aRow, int aHeight)
Definition: sch_table.h:121
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition: sch_table.h:72
void SetColCount(int aCount)
Definition: sch_table.h:103
bool StrokeExternal() const
Definition: sch_table.h:54
int GetRowHeight(int aRow) const
Definition: sch_table.h:123
void SetColWidth(int aCol, int aWidth)
Definition: sch_table.h:111
std::vector< SCH_TABLECELL * > GetCells() const
Definition: sch_table.h:141
int GetColWidth(int aCol) const
Definition: sch_table.h:113
const STROKE_PARAMS & GetBorderStroke() const
Definition: sch_table.h:60
int GetColCount() const
Definition: sch_table.h:104
void DeleteMarkedCells()
Definition: sch_table.h:166
SCH_TABLECELL * GetCell(int aRow, int aCol) const
Definition: sch_table.h:131
bool StrokeColumns() const
Definition: sch_table.h:84
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: sch_table.h:210
bool StrokeRows() const
Definition: sch_table.h:87
int GetRowCount() const
Definition: sch_table.h:106
bool StrokeHeader() const
Definition: sch_table.h:57
int GetMarginBottom() const
Definition: sch_textbox.h:66
int GetMarginLeft() const
Definition: sch_textbox.h:63
bool GetExcludedFromSim() const override
Definition: sch_textbox.h:94
int GetMarginRight() const
Definition: sch_textbox.h:65
int GetMarginTop() const
Definition: sch_textbox.h:64
VECTOR2I GetPosition() const override
Definition: sch_text.h:141
bool GetExcludedFromSim() const override
Definition: sch_text.h:86
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:75
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:100
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:253
A name/value tuple with unique names and optional values.
bool Exists(const std::string &aProperty) const
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
void SetWidth(int aWidth)
Definition: stroke_params.h:92
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale, int nestLevel) const
static const char * PropPowerSymsOnly
bool GetExcludedFromBoard() const
Definition: symbol.h:148
bool GetExcludedFromBOM() const
Definition: symbol.h:142
bool GetDNP() const
Set or clear the 'Do Not Populate' flaga.
Definition: symbol.h:153
bool GetExcludedFromSim() const override
Definition: symbol.h:136
virtual void Format(OUTPUTFORMATTER *aFormatter, int aNestLevel, int aControlBits) const
Output the object to aFormatter in s-expression form.
Definition: title_block.cpp:30
wxString wx_str() const
Definition: utf8.cpp:45
static REPORTER & GetInstance()
Definition: reporter.cpp:212
static void SetReporter(REPORTER *aReporter)
Set the reporter to use for reporting font substitution warnings.
Definition: fontconfig.cpp:64
#define MIME_BASE64_LENGTH
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:406
static constexpr EDA_ANGLE ANGLE_180
Definition: eda_angle.h:405
#define STRUCT_DELETED
flag indication structures to be erased
#define SKIP_STRUCT
flag indicating that the structure should be ignored
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:69
const wxChar *const traceSchPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
KIID niluuid(0)
wxString LayerName(int aLayer)
Returns the default display name for a given layer.
Definition: layer_id.cpp:30
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:354
@ LAYER_WIRE
Definition: layer_ids.h:357
@ LAYER_NOTES
Definition: layer_ids.h:372
@ LAYER_BUS
Definition: layer_ids.h:358
@ SCH_LAYER_ID_START
Definition: layer_ids.h:355
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:96
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue)
Converts aValue from internal units to a string appropriate for writing to file.
Definition: eda_units.cpp:169
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Converts aAngle from board units to a string appropriate for writing to file.
Definition: eda_units.cpp:161
void FormatUuid(OUTPUTFORMATTER *aOut, const KIID &aUuid, char aSuffix)
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
const char * getSheetPinShapeToken(LABEL_FLAG_SHAPE aShape)
void formatArc(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aArc, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatFill(OUTPUTFORMATTER *aFormatter, int aNestLevel, FILL_T aFillMode, const COLOR4D &aFillColor)
Fill token formatting helper.
const char * getTextTypeToken(KICAD_T aType)
void formatCircle(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aCircle, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatBezier(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aBezier, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatRect(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aRect, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
void formatPoly(OUTPUTFORMATTER *aFormatter, int aNestLevel, EDA_SHAPE *aPolyLine, bool aIsPrivate, const STROKE_PARAMS &aStroke, FILL_T aFillMode, const COLOR4D &aFillColor, bool aInvertY, const KIID &aUuid)
EDA_ANGLE getSheetPinAngle(SHEET_SIDE aSide)
@ FIELDS_AUTOPLACED_NO
Definition: sch_item.h:69
@ SHEET_MANDATORY_FIELDS
The first 2 are mandatory, and must be instantiated in SCH_SHEET.
Definition: sch_sheet.h:49
std::string toUTFTildaText(const wxString &txt)
Convert a wxString to UTF8 and replace any control characters with a ~, where a control character is ...
Definition: sch_symbol.cpp:52
@ SYM_ORIENT_270
Definition: sch_symbol.h:84
@ SYM_MIRROR_Y
Definition: sch_symbol.h:86
@ SYM_ORIENT_180
Definition: sch_symbol.h:83
@ SYM_MIRROR_X
Definition: sch_symbol.h:85
@ SYM_ORIENT_90
Definition: sch_symbol.h:82
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.
Definition: string_utils.h:391
@ CTX_LEGACY_LIBID
Definition: string_utils.h:55
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 5 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_TABLE_T
Definition: typeinfo.h:165
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:160
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_TABLECELL_T
Definition: typeinfo.h:166
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:171
@ SCH_LABEL_T
Definition: typeinfo.h:167
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_MARKER_T
Definition: typeinfo.h:158
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_RULE_AREA_T
Definition: typeinfo.h:170
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:162
@ SCH_TEXT_T
Definition: typeinfo.h:151
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:161
@ SCH_BITMAP_T
Definition: typeinfo.h:164
@ SCH_TEXTBOX_T
Definition: typeinfo.h:152
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
@ SCH_JUNCTION_T
Definition: typeinfo.h:159
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:121