KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_legacy_plugin.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 CERN
5 * Copyright (C) 2016-2023 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#include <boost/algorithm/string/join.hpp>
25#include <cctype>
26#include <mutex>
27#include <set>
28
29#include <wx/mstream.h>
30#include <wx/filename.h>
31#include <wx/log.h>
32#include <wx/textfile.h>
33#include <wx/tokenzr.h>
34#include <wx_filename.h> // For ::ResolvePossibleSymlinks()
35
36#include <kiway.h>
37#include <string_utils.h>
38#include <locale_io.h>
39#include <richio.h>
40#include <trace_helpers.h>
41#include <trigo.h>
42#include <progress_reporter.h>
43#include <general.h>
44#include <gr_text.h>
45#include <sch_bitmap.h>
46#include <sch_bus_entry.h>
47#include <sch_symbol.h>
48#include <sch_junction.h>
49#include <sch_line.h>
50#include <sch_marker.h>
51#include <sch_no_connect.h>
52#include <sch_text.h>
53#include <sch_sheet.h>
54#include <sch_sheet_pin.h>
55#include <bus_alias.h>
60#include <sch_screen.h>
61#include <schematic.h>
62#include <symbol_library.h>
63#include <eeschema_id.h> // for MAX_UNIT_COUNT_PER_PACKAGE definition
64#include <tool/selection.h>
66
67
68// Tokens to read/save graphic lines style
69#define T_STYLE "style"
70#define T_COLOR "rgb" // cannot be modified (used by wxWidgets)
71#define T_COLORA "rgba" // cannot be modified (used by wxWidgets)
72#define T_WIDTH "width"
73
74
76 m_appending( false ),
77 m_progressReporter( nullptr ),
78 m_lineReader( nullptr ),
79 m_lastProgressLine( 0 ),
80 m_lineCount( 0 )
81{
82 init( nullptr );
83}
84
85
87{
88 delete m_cache;
89}
90
91
92void SCH_LEGACY_PLUGIN::init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties )
93{
94 m_version = 0;
95 m_rootSheet = nullptr;
96 m_currentSheet = nullptr;
97 m_schematic = aSchematic;
98 m_cache = nullptr;
99 m_out = nullptr;
100}
101
102
104{
105 const unsigned PROGRESS_DELTA = 250;
106
108 {
109 unsigned curLine = m_lineReader->LineNumber();
110
111 if( curLine > m_lastProgressLine + PROGRESS_DELTA )
112 {
113 m_progressReporter->SetCurrentProgress( ( (double) curLine )
114 / std::max( 1U, m_lineCount ) );
115
117 THROW_IO_ERROR( _( "Open cancelled by user." ) );
118
119 m_lastProgressLine = curLine;
120 }
121 }
122}
123
124
125SCH_SHEET* SCH_LEGACY_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
126 SCH_SHEET* aAppendToMe,
127 const STRING_UTF8_MAP* aProperties )
128{
129 wxASSERT( !aFileName || aSchematic != nullptr );
130
131 LOCALE_IO toggle; // toggles on, then off, the C locale.
132 SCH_SHEET* sheet;
133
134 wxFileName fn = aFileName;
135
136 // Unfortunately child sheet file names the legacy schematic file format are not fully
137 // qualified and are always appended to the project path. The aFileName attribute must
138 // always be an absolute path so the project path can be used for load child sheet files.
139 wxASSERT( fn.IsAbsolute() );
140
141 if( aAppendToMe )
142 {
143 wxLogTrace( traceSchLegacyPlugin, "Append \"%s\" to sheet \"%s\".",
144 aFileName, aAppendToMe->GetFileName() );
145
146 wxFileName normedFn = aAppendToMe->GetFileName();
147
148 if( !normedFn.IsAbsolute() )
149 {
150 if( aFileName.Right( normedFn.GetFullPath().Length() ) == normedFn.GetFullPath() )
151 m_path = aFileName.Left( aFileName.Length() - normedFn.GetFullPath().Length() );
152 }
153
154 if( m_path.IsEmpty() )
155 m_path = aSchematic->Prj().GetProjectPath();
156
157 wxLogTrace( traceSchLegacyPlugin, "Normalized append path \"%s\".", m_path );
158 }
159 else
160 {
161 m_path = aSchematic->Prj().GetProjectPath();
162 }
163
164 m_currentPath.push( m_path );
165 init( aSchematic, aProperties );
166
167 if( aAppendToMe == nullptr )
168 {
169 // Clean up any allocated memory if an exception occurs loading the schematic.
170 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( aSchematic );
171 newSheet->SetFileName( aFileName );
172 m_rootSheet = newSheet.get();
173 loadHierarchy( newSheet.get() );
174
175 // If we got here, the schematic loaded successfully.
176 sheet = newSheet.release();
177 m_rootSheet = nullptr; // Quiet Coverity warning.
178 }
179 else
180 {
181 m_appending = true;
182 wxCHECK_MSG( aSchematic->IsValid(), nullptr, "Can't append to a schematic with no root!" );
183 m_rootSheet = &aSchematic->Root();
184 sheet = aAppendToMe;
185 loadHierarchy( sheet );
186 }
187
188 wxASSERT( m_currentPath.size() == 1 ); // only the project path should remain
189
190 return sheet;
191}
192
193
194// Everything below this comment is recursive. Modify with care.
195
197{
198 SCH_SCREEN* screen = nullptr;
199
200 m_currentSheet = aSheet;
201
202 if( !aSheet->GetScreen() )
203 {
204 // SCH_SCREEN objects store the full path and file name where the SCH_SHEET object only
205 // stores the file name and extension. Add the project path to the file name and
206 // extension to compare when calling SCH_SHEET::SearchHierarchy().
207 wxFileName fileName = aSheet->GetFileName();
208 fileName.SetExt( "sch" );
209
210 if( !fileName.IsAbsolute() )
211 fileName.MakeAbsolute( m_currentPath.top() );
212
213 // Save the current path so that it gets restored when descending and ascending the
214 // sheet hierarchy which allows for sheet schematic files to be nested in folders
215 // relative to the last path a schematic was loaded from.
216 wxLogTrace( traceSchLegacyPlugin, "Saving path '%s'", m_currentPath.top() );
217 m_currentPath.push( fileName.GetPath() );
218 wxLogTrace( traceSchLegacyPlugin, "Current path '%s'", m_currentPath.top() );
219 wxLogTrace( traceSchLegacyPlugin, "Loading '%s'", fileName.GetFullPath() );
220
221 m_rootSheet->SearchHierarchy( fileName.GetFullPath(), &screen );
222
223 if( screen )
224 {
225 aSheet->SetScreen( screen );
226 screen->SetParent( m_schematic );
227 // Do not need to load the sub-sheets - this has already been done.
228 }
229 else
230 {
231 aSheet->SetScreen( new SCH_SCREEN( m_schematic ) );
232 aSheet->GetScreen()->SetFileName( fileName.GetFullPath() );
233
234 if( aSheet == m_rootSheet )
235 const_cast<KIID&>( aSheet->m_Uuid ) = aSheet->GetScreen()->GetUuid();
236
237 try
238 {
239 loadFile( fileName.GetFullPath(), aSheet->GetScreen() );
240 }
241 catch( const IO_ERROR& ioe )
242 {
243 // If there is a problem loading the root sheet, there is no recovery.
244 if( aSheet == m_rootSheet )
245 throw( ioe );
246
247 // For all subsheets, queue up the error message for the caller.
248 if( !m_error.IsEmpty() )
249 m_error += "\n";
250
251 m_error += ioe.What();
252 }
253
254 aSheet->GetScreen()->SetFileReadOnly( !fileName.IsFileWritable() );
255 aSheet->GetScreen()->SetFileExists( true );
256
257 for( SCH_ITEM* aItem : aSheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
258 {
259 wxCHECK2( aItem->Type() == SCH_SHEET_T, continue );
260 auto sheet = static_cast<SCH_SHEET*>( aItem );
261
262 // Set the parent to aSheet. This effectively creates a method to find
263 // the root sheet from any sheet so a pointer to the root sheet does not
264 // need to be stored globally. Note: this is not the same as a hierarchy.
265 // Complex hierarchies can have multiple copies of a sheet. This only
266 // provides a simple tree to find the root sheet.
267 sheet->SetParent( aSheet );
268
269 // Recursion starts here.
270 loadHierarchy( sheet );
271 }
272 }
273
274 m_currentPath.pop();
275 wxLogTrace( traceSchLegacyPlugin, "Restoring path \"%s\"", m_currentPath.top() );
276 }
277}
278
279
280void SCH_LEGACY_PLUGIN::loadFile( const wxString& aFileName, SCH_SCREEN* aScreen )
281{
282 FILE_LINE_READER reader( aFileName );
283
285 {
286 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
287
289 THROW_IO_ERROR( _( "Open cancelled by user." ) );
290
291 m_lineReader = &reader;
292 m_lineCount = 0;
293
294 while( reader.ReadLine() )
295 m_lineCount++;
296
297 reader.Rewind();
298 }
299
300 loadHeader( reader, aScreen );
301
302 LoadContent( reader, aScreen, m_version );
303
304 // Unfortunately schematic files prior to version 2 are not terminated with $EndSCHEMATC
305 // so checking for its existance will fail so just exit here and take our chances. :(
306 if( m_version > 1 )
307 {
308 char* line = reader.Line();
309
310 while( *line == ' ' )
311 line++;
312
313 if( !strCompare( "$EndSCHEMATC", line ) )
314 THROW_IO_ERROR( "'$EndSCHEMATC' not found" );
315 }
316}
317
318
319void SCH_LEGACY_PLUGIN::LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen, int version )
320{
321 m_version = version;
322
323 // We cannot safely load content without a set root level.
324 wxCHECK_RET( m_rootSheet,
325 "Cannot call SCH_LEGACY_PLUGIN::LoadContent() without setting root sheet." );
326
327 while( aReader.ReadLine() )
328 {
329 checkpoint();
330
331 char* line = aReader.Line();
332
333 while( *line == ' ' )
334 line++;
335
336 // Either an object will be loaded properly or the file load will fail and raise
337 // an exception.
338 if( strCompare( "$Descr", line ) )
339 loadPageSettings( aReader, aScreen );
340 else if( strCompare( "$Comp", line ) )
341 aScreen->Append( loadSymbol( aReader ) );
342 else if( strCompare( "$Sheet", line ) )
343 aScreen->Append( loadSheet( aReader ) );
344 else if( strCompare( "$Bitmap", line ) )
345 aScreen->Append( loadBitmap( aReader ) );
346 else if( strCompare( "Connection", line ) )
347 aScreen->Append( loadJunction( aReader ) );
348 else if( strCompare( "NoConn", line ) )
349 aScreen->Append( loadNoConnect( aReader ) );
350 else if( strCompare( "Wire", line ) )
351 aScreen->Append( loadWire( aReader ) );
352 else if( strCompare( "Entry", line ) )
353 aScreen->Append( loadBusEntry( aReader ) );
354 else if( strCompare( "Text", line ) )
355 aScreen->Append( loadText( aReader ) );
356 else if( strCompare( "BusAlias", line ) )
357 aScreen->AddBusAlias( loadBusAlias( aReader, aScreen ) );
358 else if( strCompare( "Kmarq", line ) )
359 continue; // Ignore legacy (until 2009) ERC marker entry
360 else if( strCompare( "$EndSCHEMATC", line ) )
361 return;
362 else
363 SCH_PARSE_ERROR( "unrecognized token", aReader, line );
364 }
365}
366
367
369{
370 const char* line = aReader.ReadLine();
371
372 if( !line || !strCompare( "Eeschema Schematic File Version", line, &line ) )
373 {
374 m_error.Printf( _( "'%s' does not appear to be an Eeschema file." ),
375 aScreen->GetFileName() );
377 }
378
379 // get the file version here.
380 m_version = parseInt( aReader, line, &line );
381
382 // The next lines are the lib list section, and are mainly comments, like:
383 // LIBS:power
384 // the lib list is not used, but is in schematic file just in case.
385 // It is usually not empty, but we accept empty list.
386 // If empty, there is a legacy section, not used
387 // EELAYER i j
388 // and the last line is
389 // EELAYER END
390 // Skip all lines until the end of header "EELAYER END" is found
391 while( aReader.ReadLine() )
392 {
393 checkpoint();
394
395 line = aReader.Line();
396
397 while( *line == ' ' )
398 line++;
399
400 if( strCompare( "EELAYER END", line ) )
401 return;
402 }
403
404 THROW_IO_ERROR( _( "Missing 'EELAYER END'" ) );
405}
406
407
409{
410 wxASSERT( aScreen != nullptr );
411
412 wxString buf;
413 const char* line = aReader.Line();
414
415 PAGE_INFO pageInfo;
416 TITLE_BLOCK tb;
417
418 wxCHECK_RET( strCompare( "$Descr", line, &line ), "Invalid sheet description" );
419
420 parseUnquotedString( buf, aReader, line, &line );
421
422 if( !pageInfo.SetType( buf ) )
423 SCH_PARSE_ERROR( "invalid page size", aReader, line );
424
425 int pagew = parseInt( aReader, line, &line );
426 int pageh = parseInt( aReader, line, &line );
427
428 if( buf == PAGE_INFO::Custom )
429 {
430 pageInfo.SetWidthMils( pagew );
431 pageInfo.SetHeightMils( pageh );
432 }
433 else
434 {
435 wxString orientation;
436
437 // Non custom size, set portrait if its present. Can be empty string which defaults
438 // to landscape.
439 parseUnquotedString( orientation, aReader, line, &line, true );
440
441 if( orientation == "portrait" )
442 pageInfo.SetPortrait( true );
443 }
444
445 aScreen->SetPageSettings( pageInfo );
446
447 while( line != nullptr )
448 {
449 buf.clear();
450
451 if( !aReader.ReadLine() )
452 SCH_PARSE_ERROR( _( "unexpected end of file" ), aReader, line );
453
454 line = aReader.Line();
455
456 if( strCompare( "Sheet", line, &line ) )
457 {
458 aScreen->SetVirtualPageNumber( parseInt( aReader, line, &line ) );
459 aScreen->SetPageCount( parseInt( aReader, line, &line ) );
460 }
461 else if( strCompare( "Title", line, &line ) )
462 {
463 parseQuotedString( buf, aReader, line, &line, true );
464 tb.SetTitle( buf );
465 }
466 else if( strCompare( "Date", line, &line ) )
467 {
468 parseQuotedString( buf, aReader, line, &line, true );
469 tb.SetDate( buf );
470 }
471 else if( strCompare( "Rev", line, &line ) )
472 {
473 parseQuotedString( buf, aReader, line, &line, true );
474 tb.SetRevision( buf );
475 }
476 else if( strCompare( "Comp", line, &line ) )
477 {
478 parseQuotedString( buf, aReader, line, &line, true );
479 tb.SetCompany( buf );
480 }
481 else if( strCompare( "Comment1", line, &line ) )
482 {
483 parseQuotedString( buf, aReader, line, &line, true );
484 tb.SetComment( 0, buf );
485 }
486 else if( strCompare( "Comment2", line, &line ) )
487 {
488 parseQuotedString( buf, aReader, line, &line, true );
489 tb.SetComment( 1, buf );
490 }
491 else if( strCompare( "Comment3", line, &line ) )
492 {
493 parseQuotedString( buf, aReader, line, &line, true );
494 tb.SetComment( 2, buf );
495 }
496 else if( strCompare( "Comment4", line, &line ) )
497 {
498 parseQuotedString( buf, aReader, line, &line, true );
499 tb.SetComment( 3, buf );
500 }
501 else if( strCompare( "Comment5", line, &line ) )
502 {
503 parseQuotedString( buf, aReader, line, &line, true );
504 tb.SetComment( 4, buf );
505 }
506 else if( strCompare( "Comment6", line, &line ) )
507 {
508 parseQuotedString( buf, aReader, line, &line, true );
509 tb.SetComment( 5, buf );
510 }
511 else if( strCompare( "Comment7", line, &line ) )
512 {
513 parseQuotedString( buf, aReader, line, &line, true );
514 tb.SetComment( 6, buf );
515 }
516 else if( strCompare( "Comment8", line, &line ) )
517 {
518 parseQuotedString( buf, aReader, line, &line, true );
519 tb.SetComment( 7, buf );
520 }
521 else if( strCompare( "Comment9", line, &line ) )
522 {
523 parseQuotedString( buf, aReader, line, &line, true );
524 tb.SetComment( 8, buf );
525 }
526 else if( strCompare( "$EndDescr", line ) )
527 {
528 aScreen->SetTitleBlock( tb );
529 return;
530 }
531 }
532
533 SCH_PARSE_ERROR( "missing 'EndDescr'", aReader, line );
534}
535
536
538{
539 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>();
540
541 const char* line = aReader.ReadLine();
542
543 while( line != nullptr )
544 {
545 if( strCompare( "S", line, &line ) ) // Sheet dimensions.
546 {
547 VECTOR2I position;
548
549 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
550 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
551 sheet->SetPosition( position );
552
553 VECTOR2I size;
554
555 size.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
556 size.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
557 sheet->SetSize( size );
558 }
559 else if( strCompare( "U", line, &line ) ) // Sheet UUID.
560 {
561 wxString text;
562 parseUnquotedString( text, aReader, line );
563
564 if( text != "00000000" )
565 const_cast<KIID&>( sheet->m_Uuid ) = KIID( text );
566 }
567 else if( *line == 'F' ) // Sheet field.
568 {
569 line++;
570
571 wxString text;
572 int size;
573 int fieldId = parseInt( aReader, line, &line );
574
575 if( fieldId == 0 || fieldId == 1 ) // Sheet name and file name.
576 {
577 parseQuotedString( text, aReader, line, &line );
578 size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
579
580 SCH_FIELD& field = sheet->GetFields()[ fieldId ];
581 field.SetText( text );
582 field.SetTextSize( VECTOR2I( size, size ) );
583 }
584 else // Sheet pin.
585 {
586 // Use a unique_ptr so that we clean up in the case of a throw
587 std::unique_ptr<SCH_SHEET_PIN> sheetPin = std::make_unique<SCH_SHEET_PIN>( sheet.get() );
588
589 sheetPin->SetNumber( fieldId );
590
591 // Can be empty fields.
592 parseQuotedString( text, aReader, line, &line, true );
593
594 sheetPin->SetText( ConvertToNewOverbarNotation( text ) );
595
596 if( line == nullptr )
597 THROW_IO_ERROR( _( "unexpected end of line" ) );
598
599 switch( parseChar( aReader, line, &line ) )
600 {
601 case 'I': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_INPUT ); break;
602 case 'O': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_OUTPUT ); break;
603 case 'B': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_BIDI ); break;
604 case 'T': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_TRISTATE ); break;
605 case 'U': sheetPin->SetShape( LABEL_FLAG_SHAPE::L_UNSPECIFIED ); break;
606 default: SCH_PARSE_ERROR( "invalid sheet pin type", aReader, line );
607 }
608
609 switch( parseChar( aReader, line, &line ) )
610 {
611 case 'R': sheetPin->SetSide( SHEET_SIDE::RIGHT ); break;
612 case 'T': sheetPin->SetSide( SHEET_SIDE::TOP ); break;
613 case 'B': sheetPin->SetSide( SHEET_SIDE::BOTTOM ); break;
614 case 'L': sheetPin->SetSide( SHEET_SIDE::LEFT ); break;
615 default:
616 SCH_PARSE_ERROR( "invalid sheet pin side", aReader, line );
617 }
618
619 VECTOR2I position;
620
621 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
622 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
623 sheetPin->SetPosition( position );
624
625 size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
626
627 sheetPin->SetTextSize( VECTOR2I( size, size ) );
628
629 sheet->AddPin( sheetPin.release() );
630 }
631 }
632 else if( strCompare( "$EndSheet", line ) )
633 {
634 sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
635 return sheet.release();
636 }
637
638 line = aReader.ReadLine();
639 }
640
641 SCH_PARSE_ERROR( "missing '$EndSheet`", aReader, line );
642
643 return nullptr; // Prevents compiler warning. Should never get here.
644}
645
646
648{
649 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
650
651 const char* line = aReader.Line();
652
653 wxCHECK( strCompare( "$Bitmap", line, &line ), nullptr );
654
655 line = aReader.ReadLine();
656
657 while( line != nullptr )
658 {
659 if( strCompare( "Pos", line, &line ) )
660 {
661 VECTOR2I position;
662
663 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
664 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
665 bitmap->SetPosition( position );
666 }
667 else if( strCompare( "Scale", line, &line ) )
668 {
669 auto scalefactor = parseDouble( aReader, line, &line );
670
671 // Prevent scalefactor values that cannot be displayed.
672 // In the case of a bad value, we accept that the image might be mis-scaled
673 // rather than removing the full image. Users can then edit the scale factor in
674 // Eeschema to the appropriate value
675 if( !std::isnormal( scalefactor ) )
676 scalefactor = 1.0;
677
678 bitmap->GetImage()->SetScale( scalefactor );
679 }
680 else if( strCompare( "Data", line, &line ) )
681 {
682 wxMemoryBuffer buffer;
683
684 while( line )
685 {
686 if( !aReader.ReadLine() )
687 SCH_PARSE_ERROR( _( "Unexpected end of file" ), aReader, line );
688
689 line = aReader.Line();
690
691 if( strCompare( "EndData", line ) )
692 {
693 // all the PNG date is read.
694 bitmap->GetImage()->ReadImageFile( buffer );
695
696 // Legacy file formats assumed 300 image PPI at load.
697 BITMAP_BASE* bitmapImage = bitmap->GetImage();
698 bitmapImage->SetScale( bitmapImage->GetScale() * bitmapImage->GetPPI()
699 / 300.0 );
700 break;
701 }
702
703 // Read PNG data, stored in hexadecimal,
704 // each byte = 2 hexadecimal digits and a space between 2 bytes
705 // and put it in memory stream buffer
706 // Note:
707 // Some old files created bu the V4 schematic versions have a extra
708 // "$EndBitmap" at the end of the hexadecimal data. (Probably due to
709 // a bug). So discard it
710 int len = strlen( line );
711
712 for( ; len > 0 && !isspace( *line ) && '$' != *line; len -= 3, line += 3 )
713 {
714 int value = 0;
715
716 if( sscanf( line, "%X", &value ) == 1 )
717 buffer.AppendByte( (char) value );
718 else
719 THROW_IO_ERROR( "invalid PNG data" );
720 }
721 }
722
723 if( line == nullptr )
724 THROW_IO_ERROR( _( "unexpected end of file" ) );
725 }
726 else if( strCompare( "$EndBitmap", line ) )
727 {
728 return bitmap.release();
729 }
730
731 line = aReader.ReadLine();
732 }
733
734 THROW_IO_ERROR( _( "unexpected end of file" ) );
735}
736
737
739{
740 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
741
742 const char* line = aReader.Line();
743
744 wxCHECK( strCompare( "Connection", line, &line ), nullptr );
745
746 wxString name;
747
748 parseUnquotedString( name, aReader, line, &line );
749
750 VECTOR2I position;
751
752 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
753 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
754 junction->SetPosition( position );
755
756 return junction.release();
757}
758
759
761{
762 std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
763
764 const char* line = aReader.Line();
765
766 wxCHECK( strCompare( "NoConn", line, &line ), nullptr );
767
768 wxString name;
769
770 parseUnquotedString( name, aReader, line, &line );
771
772 VECTOR2I position;
773
774 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
775 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
776 no_connect->SetPosition( position );
777
778 return no_connect.release();
779}
780
781
783{
784 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
785
786 const char* line = aReader.Line();
787
788 wxCHECK( strCompare( "Wire", line, &line ), nullptr );
789
790 if( strCompare( "Wire", line, &line ) )
791 wire->SetLayer( LAYER_WIRE );
792 else if( strCompare( "Bus", line, &line ) )
793 wire->SetLayer( LAYER_BUS );
794 else if( strCompare( "Notes", line, &line ) )
795 wire->SetLayer( LAYER_NOTES );
796 else
797 SCH_PARSE_ERROR( "invalid line type", aReader, line );
798
799 if( !strCompare( "Line", line, &line ) )
800 SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
801
802 // Since Sept 15, 2017, a line style is alloved (width, style, color)
803 // Only non default values are stored
804 while( !is_eol( *line ) )
805 {
806 wxString buf;
807
808 parseUnquotedString( buf, aReader, line, &line );
809
810 if( buf == ")" )
811 continue;
812
813 else if( buf == T_WIDTH )
814 {
815 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
816 wire->SetLineWidth( size );
817 }
818 else if( buf == T_STYLE )
819 {
820 parseUnquotedString( buf, aReader, line, &line );
821
822 if( buf == wxT( "solid" ) )
823 wire->SetLineStyle( LINE_STYLE::SOLID );
824 else if( buf == wxT( "dashed" ) )
825 wire->SetLineStyle( LINE_STYLE::DASH );
826 else if( buf == wxT( "dash_dot" ) )
827 wire->SetLineStyle( LINE_STYLE::DASHDOT );
828 else if( buf == wxT( "dotted" ) )
829 wire->SetLineStyle( LINE_STYLE::DOT );
830 }
831 else // should be the color parameter.
832 {
833 // The color param is something like rgb(150, 40, 191)
834 // and because there is no space between ( and 150
835 // the first param is inside buf.
836 // So break keyword and the first param into 2 separate strings.
837 wxString prm, keyword;
838 keyword = buf.BeforeLast( '(', &prm );
839
840 if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
841 {
842 long color[4] = { 0 };
843
844 int ii = 0;
845
846 if( !prm.IsEmpty() )
847 {
848 prm.ToLong( &color[ii] );
849 ii++;
850 }
851
852 int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
853
854 // fix opacity to 1.0 or 255, when not exists in file
855 color[3] = 255;
856
857 for(; ii < prm_count && !is_eol( *line ); ii++ )
858 {
859 color[ii] = parseInt( aReader, line, &line );
860
861 // Skip the separator between values
862 if( *line == ',' || *line == ' ')
863 line++;
864 }
865
866 wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
867 }
868 }
869 }
870
871 // Read the segment en points coordinates:
872 line = aReader.ReadLine();
873
874 VECTOR2I begin, end;
875
876 begin.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
877 begin.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
878 end.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
879 end.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
880
881 wire->SetStartPoint( begin );
882 wire->SetEndPoint( end );
883
884 return wire.release();
885}
886
887
889{
890 const char* line = aReader.Line();
891
892 wxCHECK( strCompare( "Entry", line, &line ), nullptr );
893
894 std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
895
896 if( strCompare( "Wire", line, &line ) )
897 {
898 busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
899
900 if( !strCompare( "Line", line, &line ) )
901 SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
902 }
903 else if( strCompare( "Bus", line, &line ) )
904 {
905 busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
906
907 if( !strCompare( "Bus", line, &line ) )
908 SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
909 }
910 else
911 {
912 SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
913 }
914
915 line = aReader.ReadLine();
916
917 VECTOR2I pos;
918 VECTOR2I size;
919
920 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
921 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
922 size.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
923 size.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
924
925 size.x -= pos.x;
926 size.y -= pos.y;
927
928 busEntry->SetPosition( pos );
929 busEntry->SetSize( size );
930
931 return busEntry.release();
932}
933
934
935// clang-format off
936const std::map<LABEL_FLAG_SHAPE, const char*> sheetLabelNames
937{
938 { LABEL_FLAG_SHAPE::L_INPUT, "Input" },
939 { LABEL_FLAG_SHAPE::L_OUTPUT, "Output" },
940 { LABEL_FLAG_SHAPE::L_BIDI, "BiDi" },
941 { LABEL_FLAG_SHAPE::L_TRISTATE, "3State" },
943};
944// clang-format on
945
946
948{
949 const char* line = aReader.Line();
950 KICAD_T textType = TYPE_NOT_INIT;
951
952 wxCHECK( strCompare( "Text", line, &line ), nullptr );
953
954 if( strCompare( "Notes", line, &line ) )
955 {
956 textType = SCH_TEXT_T;
957 }
958 else if( strCompare( "Label", line, &line ) )
959 {
960 textType = SCH_LABEL_T;
961 }
962 else if( strCompare( "HLabel", line, &line ) )
963 {
964 textType = SCH_HIER_LABEL_T;
965 }
966 else if( strCompare( "GLabel", line, &line ) )
967 {
968 // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
969 if( m_version == 1 )
970 textType = SCH_HIER_LABEL_T;
971 else
972 textType = SCH_GLOBAL_LABEL_T;
973 }
974 else
975 {
976 SCH_PARSE_ERROR( "unknown Text type", aReader, line );
977 }
978
979 VECTOR2I position;
980
981 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
982 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
983
984 std::unique_ptr<SCH_TEXT> text;
985
986 switch( textType )
987 {
988 case SCH_TEXT_T: text.reset( new SCH_TEXT( position ) ); break;
989 case SCH_LABEL_T: text.reset( new SCH_LABEL( position ) ); break;
990 case SCH_HIER_LABEL_T: text.reset( new SCH_HIERLABEL( position ) ); break;
991 case SCH_GLOBAL_LABEL_T: text.reset( new SCH_GLOBALLABEL( position ) ); break;
992 default: break;
993 }
994
995 int spinStyle = parseInt( aReader, line, &line );
996 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
997
998 text->SetTextSize( VECTOR2I( size, size ) );
999
1000 if( textType == SCH_LABEL_T || textType == SCH_HIER_LABEL_T || textType == SCH_GLOBAL_LABEL_T )
1001 {
1002 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( text.get() );
1003
1004 // Sadly we store the orientation of hierarchical and global labels using a different
1005 // int encoding than that for local labels:
1006 // Global Local
1007 // Left justified 0 2
1008 // Up 1 3
1009 // Right justified 2 0
1010 // Down 3 1
1011 // So we must flip it as the enum is setup with the "global" numbering
1012 if( textType == SCH_LABEL_T )
1013 {
1014 if( spinStyle == 0 )
1015 spinStyle = 2;
1016 else if( spinStyle == 2 )
1017 spinStyle = 0;
1018 }
1019
1020 label->SetSpinStyle( static_cast<SPIN_STYLE::SPIN>( spinStyle ) );
1021
1022 // Parse the global and hierarchical label type.
1023 if( textType == SCH_HIER_LABEL_T || textType == SCH_GLOBAL_LABEL_T )
1024 {
1025 auto resultIt = std::find_if( sheetLabelNames.begin(), sheetLabelNames.end(),
1026 [ &line ]( const auto& it )
1027 {
1028 return strCompare( it.second, line, &line );
1029 } );
1030
1031 if( resultIt != sheetLabelNames.end() )
1032 label->SetShape( resultIt->first );
1033 else
1034 SCH_PARSE_ERROR( "invalid label type", aReader, line );
1035 }
1036 }
1037
1038 int penWidth = 0;
1039
1040 // The following tokens do not exist in version 1 schematic files,
1041 // and not always in version 2 for HLabels and GLabels
1042 if( m_version > 1 )
1043 {
1044 if( m_version > 2 || *line >= ' ' )
1045 {
1046 if( strCompare( "Italic", line, &line ) )
1047 text->SetItalic( true );
1048 else if( !strCompare( "~", line, &line ) )
1049 SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1050 }
1051
1052 // The penWidth token does not exist in older versions of the schematic file format
1053 // so calling parseInt will be made only if the EOL is not reached.
1054 if( *line >= ' ' )
1055 penWidth = parseInt( aReader, line, &line );
1056 }
1057
1058 text->SetBold( penWidth != 0 );
1059 text->SetTextThickness( penWidth != 0 ? GetPenSizeForBold( size ) : 0 );
1060
1061 // Read the text string for the text.
1062 char* tmp = aReader.ReadLine();
1063
1064 tmp = strtok( tmp, "\r\n" );
1065 wxString val = From_UTF8( tmp );
1066
1067 for( ; ; )
1068 {
1069 int i = val.find( wxT( "\\n" ) );
1070
1071 if( i == wxNOT_FOUND )
1072 break;
1073
1074 val.erase( i, 2 );
1075 val.insert( i, wxT( "\n" ) );
1076 }
1077
1078 text->SetText( ConvertToNewOverbarNotation( val ) );
1079
1080 return text.release();
1081}
1082
1083
1085{
1086 const char* line = aReader.Line();
1087
1088 wxCHECK( strCompare( "$Comp", line, &line ), nullptr );
1089
1090 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1091
1092 line = aReader.ReadLine();
1093
1094 while( line != nullptr )
1095 {
1096 if( strCompare( "L", line, &line ) )
1097 {
1098 wxString libName;
1099 size_t pos = 2; // "X" plus ' ' space character.
1100 wxString utf8Line = wxString::FromUTF8( line );
1101 wxStringTokenizer tokens( utf8Line, " \r\n\t" );
1102
1103 if( tokens.CountTokens() < 2 )
1104 THROW_PARSE_ERROR( "invalid symbol library definition", aReader.GetSource(),
1105 aReader.Line(), aReader.LineNumber(), pos );
1106
1107 libName = tokens.GetNextToken();
1108 libName.Replace( "~", " " );
1109
1110 LIB_ID libId;
1111
1112 // Prior to schematic version 4, library IDs did not have a library nickname so
1113 // parsing the symbol name with LIB_ID::Parse() would break symbol library links
1114 // that contained '/' and ':' characters.
1115 if( m_version > 3 )
1116 libId.Parse( libName, true );
1117 else
1118 libId.SetLibItemName( libName );
1119
1120 symbol->SetLibId( libId );
1121
1122 wxString refDesignator = tokens.GetNextToken();
1123
1124 refDesignator.Replace( "~", " " );
1125
1126 wxString prefix = refDesignator;
1127
1128 while( prefix.Length() )
1129 {
1130 if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1131 break;
1132
1133 prefix.RemoveLast();
1134 }
1135
1136 // Avoid a prefix containing trailing/leading spaces
1137 prefix.Trim( true );
1138 prefix.Trim( false );
1139
1140 if( prefix.IsEmpty() )
1141 symbol->SetPrefix( wxString( "U" ) );
1142 else
1143 symbol->SetPrefix( prefix );
1144 }
1145 else if( strCompare( "U", line, &line ) )
1146 {
1147 // This fixes a potentially buggy files caused by unit being set to zero which
1148 // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1149 int unit = parseInt( aReader, line, &line );
1150
1151 if( unit == 0 )
1152 {
1153 unit = 1;
1154
1155 // Set the file as modified so the user can be warned.
1156 if( m_rootSheet->GetScreen() )
1158 }
1159
1160 symbol->SetUnit( unit );
1161
1162 // Same can also happen with the convert parameter
1163 int convert = parseInt( aReader, line, &line );
1164
1165 if( convert == 0 )
1166 {
1167 convert = 1;
1168
1169 // Set the file as modified so the user can be warned.
1170 if( m_rootSheet->GetScreen() )
1172 }
1173
1174 symbol->SetConvert( convert );
1175
1176 wxString text;
1177 parseUnquotedString( text, aReader, line, &line );
1178
1179 if( text != "00000000" )
1180 const_cast<KIID&>( symbol->m_Uuid ) = KIID( text );
1181 }
1182 else if( strCompare( "P", line, &line ) )
1183 {
1184 VECTOR2I pos;
1185
1186 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1187 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1188 symbol->SetPosition( pos );
1189 }
1190 else if( strCompare( "AR", line, &line ) )
1191 {
1192 const char* strCompare = "Path=";
1193 int len = strlen( strCompare );
1194
1195 if( strncasecmp( strCompare, line, len ) != 0 )
1196 SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1197
1198 line += len;
1199 wxString pathStr, reference, unit;
1200
1201 parseQuotedString( pathStr, aReader, line, &line );
1202
1203 // Note: AR path excludes root sheet, but includes symbol. Drop the symbol ID
1204 // since it's already defined in the symbol itself.
1205 KIID_PATH path( pathStr );
1206
1207 if( path.size() > 0 )
1208 path.pop_back();
1209
1210 // In the new file format, the root schematic UUID is used as the virtual SCH_SHEET
1211 // UUID so we need to prefix it to the symbol path so the symbol instance paths
1212 // get saved with the root schematic UUID.
1213 if( !m_appending )
1214 path.insert( path.begin(), m_rootSheet->GetScreen()->GetUuid() );
1215
1216 strCompare = "Ref=";
1217 len = strlen( strCompare );
1218
1219 if( strncasecmp( strCompare, line, len ) != 0 )
1220 SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1221
1222 line+= len;
1223 parseQuotedString( reference, aReader, line, &line );
1224
1225 strCompare = "Part=";
1226 len = strlen( strCompare );
1227
1228 if( strncasecmp( strCompare, line, len ) != 0 )
1229 SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1230
1231 line+= len;
1232 parseQuotedString( unit, aReader, line, &line );
1233
1234 long tmp;
1235
1236 if( !unit.ToLong( &tmp, 10 ) )
1237 SCH_PARSE_ERROR( "expected integer value", aReader, line );
1238
1239 if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1240 SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1241
1242 symbol->AddHierarchicalReference( path, reference, (int)tmp );
1243 symbol->GetField( REFERENCE_FIELD )->SetText( reference );
1244 }
1245 else if( strCompare( "F", line, &line ) )
1246 {
1247 int index = parseInt( aReader, line, &line );
1248
1249 wxString text, name;
1250
1251 parseQuotedString( text, aReader, line, &line, true );
1252
1253 char orientation = parseChar( aReader, line, &line );
1254 VECTOR2I pos;
1255 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1256 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1257 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1258 int attributes = parseHex( aReader, line, &line );
1259
1260 if( index >= symbol->GetFieldCount() )
1261 {
1262 // The first MANDATOR_FIELDS _must_ be constructed within the SCH_SYMBOL
1263 // constructor. This assert is simply here to guard against a change in that
1264 // constructor.
1265 wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELDS );
1266
1267 // Ignore the _supplied_ fieldNdx. It is not important anymore if within the
1268 // user defined fields region (i.e. >= MANDATORY_FIELDS).
1269 // We freely renumber the index to fit the next available field slot.
1270 index = symbol->GetFieldCount(); // new has this index after insertion
1271
1272 SCH_FIELD field( VECTOR2I( 0, 0 ), index, symbol.get(), name );
1273 symbol->AddField( field );
1274 }
1275
1276 SCH_FIELD& field = symbol->GetFields()[index];
1277
1278 // Prior to version 2 of the schematic file format, none of the following existed.
1279 if( m_version > 1 )
1280 {
1281 wxString textAttrs;
1282 char hjustify = parseChar( aReader, line, &line );
1283
1284 parseUnquotedString( textAttrs, aReader, line, &line );
1285
1286 // The name of the field is optional.
1287 parseQuotedString( name, aReader, line, &line, true );
1288
1289 if( hjustify == 'L' )
1291 else if( hjustify == 'R' )
1293 else if( hjustify != 'C' )
1294 SCH_PARSE_ERROR( "symbol field text horizontal justification must be "
1295 "L, R, or C", aReader, line );
1296
1297 // We are guaranteed to have a least one character here for older file formats
1298 // otherwise an exception would have been raised..
1299 if( textAttrs[0] == 'T' )
1301 else if( textAttrs[0] == 'B' )
1303 else if( textAttrs[0] != 'C' )
1304 SCH_PARSE_ERROR( "symbol field text vertical justification must be "
1305 "B, T, or C", aReader, line );
1306
1307 // Newer file formats include the bold and italics text attribute.
1308 if( textAttrs.Length() > 1 )
1309 {
1310 if( textAttrs.Length() != 3 )
1311 {
1312 SCH_PARSE_ERROR( _( "symbol field text attributes must be 3 characters wide" ),
1313 aReader, line );
1314 }
1315
1316 if( textAttrs[1] == 'I' )
1317 {
1318 field.SetItalic( true );
1319 }
1320 else if( textAttrs[1] != 'N' )
1321 {
1322 SCH_PARSE_ERROR( "symbol field text italics indicator must be I or N",
1323 aReader, line );
1324 }
1325
1326 if( textAttrs[2] == 'B' )
1327 {
1328 field.SetBold( true );
1329 }
1330 else if( textAttrs[2] != 'N' )
1331 {
1332 SCH_PARSE_ERROR( "symbol field text bold indicator must be B or N",
1333 aReader, line );
1334 }
1335 }
1336 }
1337
1338 field.SetText( text );
1339 field.SetTextPos( pos );
1340 field.SetVisible( !attributes );
1341 field.SetTextSize( VECTOR2I( size, size ) );
1342
1343 if( orientation == 'H' )
1345 else if( orientation == 'V' )
1347 else
1348 SCH_PARSE_ERROR( "symbol field orientation must be H or V", aReader, line );
1349
1350 if( name.IsEmpty() )
1352
1353 field.SetName( name );
1354 }
1355 else if( strCompare( "$EndComp", line ) )
1356 {
1357 if( !m_appending )
1358 {
1360 {
1362 path.push_back( m_rootSheet->GetScreen()->GetUuid() );
1363
1364 SCH_SYMBOL_INSTANCE instance;
1365 instance.m_Path = path;
1366 instance.m_Reference = symbol->GetField( REFERENCE_FIELD )->GetText();
1367 instance.m_Unit = symbol->GetUnit();
1368 symbol->AddHierarchicalReference( instance );
1369 }
1370 else
1371 {
1372 for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstanceReferences() )
1373 {
1374 SCH_SYMBOL_INSTANCE tmpInstance = instance;
1375 symbol->AddHierarchicalReference( tmpInstance );
1376 }
1377 }
1378 }
1379
1380 // Ensure all flags (some are set by previous initializations) are reset:
1381 symbol->ClearFlags();
1382 return symbol.release();
1383 }
1384 else
1385 {
1386 // There are two lines that begin with a tab or spaces that includes a line with the
1387 // redundant position information and the transform matrix settings.
1388
1389 // Parse the redundant position information just the same to check for formatting
1390 // errors.
1391 parseInt( aReader, line, &line ); // Always 1.
1392 parseInt( aReader, line, &line ); // The X coordinate.
1393 parseInt( aReader, line, &line ); // The Y coordinate.
1394
1395 line = aReader.ReadLine();
1396
1397 TRANSFORM transform;
1398
1399 transform.x1 = parseInt( aReader, line, &line );
1400
1401 if( transform.x1 < -1 || transform.x1 > 1 )
1402 SCH_PARSE_ERROR( "invalid symbol X1 transform value", aReader, line );
1403
1404 transform.y1 = parseInt( aReader, line, &line );
1405
1406 if( transform.y1 < -1 || transform.y1 > 1 )
1407 SCH_PARSE_ERROR( "invalid symbol Y1 transform value", aReader, line );
1408
1409 transform.x2 = parseInt( aReader, line, &line );
1410
1411 if( transform.x2 < -1 || transform.x2 > 1 )
1412 SCH_PARSE_ERROR( "invalid symbol X2 transform value", aReader, line );
1413
1414 transform.y2 = parseInt( aReader, line, &line );
1415
1416 if( transform.y2 < -1 || transform.y2 > 1 )
1417 SCH_PARSE_ERROR( "invalid symbol Y2 transform value", aReader, line );
1418
1419 symbol->SetTransform( transform );
1420 }
1421
1422 line = aReader.ReadLine();
1423 }
1424
1425 SCH_PARSE_ERROR( "invalid symbol line", aReader, line );
1426
1427 return nullptr; // Prevents compiler warning. Should never get here.
1428}
1429
1430
1431std::shared_ptr<BUS_ALIAS> SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader,
1432 SCH_SCREEN* aScreen )
1433{
1434 auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
1435 const char* line = aReader.Line();
1436
1437 wxCHECK( strCompare( "BusAlias", line, &line ), nullptr );
1438
1439 wxString buf;
1440 parseUnquotedString( buf, aReader, line, &line );
1441 busAlias->SetName( buf );
1442
1443 while( *line != '\0' )
1444 {
1445 buf.clear();
1446 parseUnquotedString( buf, aReader, line, &line, true );
1447
1448 if( !buf.IsEmpty() )
1449 busAlias->Members().emplace_back( buf );
1450 }
1451
1452 return busAlias;
1453}
1454
1455
1456void SCH_LEGACY_PLUGIN::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet,
1457 SCHEMATIC* aSchematic,
1458 const STRING_UTF8_MAP* aProperties )
1459{
1460 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
1461 wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1462
1463 LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1464
1465 init( aSchematic, aProperties );
1466
1467 wxFileName fn = aFileName;
1468
1469 // File names should be absolute. Don't assume everything relative to the project path
1470 // works properly.
1471 wxASSERT( fn.IsAbsolute() );
1472
1473 FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1474
1475 m_out = &formatter; // no ownership
1476
1477 Format( aSheet );
1478
1479 aSheet->GetScreen()->SetFileExists( true );
1480}
1481
1482
1484{
1485 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
1486 wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
1487
1488 SCH_SCREEN* screen = aSheet->GetScreen();
1489
1490 wxCHECK( screen, /* void */ );
1491
1492 // Write the header
1493 m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1494
1495 // This section is not used, but written for file compatibility
1496 m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1497 m_out->Print( 0, "EELAYER END\n" );
1498
1499 /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1500 * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1501 * simple hierarchy and flat hierarchy. Used also to search the root
1502 * sheet ( ScreenNumber = 1 ) within the files
1503 */
1504 const TITLE_BLOCK& tb = screen->GetTitleBlock();
1505 const PAGE_INFO& page = screen->GetPageSettings();
1506
1507 m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1508 (int)page.GetWidthMils(),
1509 (int)page.GetHeightMils(),
1510 !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1511 m_out->Print( 0, "encoding utf-8\n" );
1512 m_out->Print( 0, "Sheet %d %d\n", screen->GetVirtualPageNumber(), screen->GetPageCount() );
1513 m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1514 m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1515 m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1516 m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1517 m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
1518 m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
1519 m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
1520 m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
1521 m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
1522 m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
1523 m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
1524 m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
1525 m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
1526 m_out->Print( 0, "$EndDescr\n" );
1527
1528 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
1529 saveBusAlias( alias );
1530
1531 // Enforce item ordering
1532 auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
1533 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
1534
1535 for( SCH_ITEM* item : screen->Items() )
1536 save_map.insert( item );
1537
1538
1539 for( auto& item : save_map )
1540 {
1541 switch( item->Type() )
1542 {
1543 case SCH_SYMBOL_T:
1544 saveSymbol( static_cast<SCH_SYMBOL*>( item ) );
1545 break;
1546 case SCH_BITMAP_T:
1547 saveBitmap( static_cast<SCH_BITMAP*>( item ) );
1548 break;
1549 case SCH_SHEET_T:
1550 saveSheet( static_cast<SCH_SHEET*>( item ) );
1551 break;
1552 case SCH_JUNCTION_T:
1553 saveJunction( static_cast<SCH_JUNCTION*>( item ) );
1554 break;
1555 case SCH_NO_CONNECT_T:
1556 saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
1557 break;
1560 saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
1561 break;
1562 case SCH_LINE_T:
1563 saveLine( static_cast<SCH_LINE*>( item ) );
1564 break;
1565 case SCH_TEXT_T:
1566 case SCH_LABEL_T:
1567 case SCH_GLOBAL_LABEL_T:
1568 case SCH_HIER_LABEL_T:
1569 saveText( static_cast<SCH_TEXT*>( item ) );
1570 break;
1571 default:
1572 wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1573 }
1574 }
1575
1576 m_out->Print( 0, "$EndSCHEMATC\n" );
1577}
1578
1579
1581{
1582 m_out = aFormatter;
1583
1584 for( unsigned i = 0; i < aSelection->GetSize(); ++i )
1585 {
1586 SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
1587
1588 switch( item->Type() )
1589 {
1590 case SCH_SYMBOL_T:
1591 saveSymbol( static_cast< SCH_SYMBOL* >( item ) );
1592 break;
1593 case SCH_BITMAP_T:
1594 saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1595 break;
1596 case SCH_SHEET_T:
1597 saveSheet( static_cast< SCH_SHEET* >( item ) );
1598 break;
1599 case SCH_JUNCTION_T:
1600 saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1601 break;
1602 case SCH_NO_CONNECT_T:
1603 saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1604 break;
1607 saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1608 break;
1609 case SCH_LINE_T:
1610 saveLine( static_cast< SCH_LINE* >( item ) );
1611 break;
1612 case SCH_TEXT_T:
1613 case SCH_LABEL_T:
1614 case SCH_GLOBAL_LABEL_T:
1615 case SCH_HIER_LABEL_T:
1616 saveText( static_cast< SCH_TEXT* >( item ) );
1617 break;
1618 default:
1619 wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1620 }
1621 }
1622}
1623
1624
1626{
1627 std::string name1;
1628 std::string name2;
1629
1630 static wxString delimiters( wxT( " " ) );
1631
1632 // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1633 if( aSymbol->GetInstanceReferences().size() > 0 )
1634 {
1635 const SCH_SYMBOL_INSTANCE& instance = aSymbol->GetInstanceReferences()[0];
1636 name1 = toUTFTildaText( instance.m_Reference );
1637 }
1638 else
1639 {
1640 if( aSymbol->GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
1641 name1 = toUTFTildaText( aSymbol->GetPrefix() );
1642 else
1643 name1 = toUTFTildaText( aSymbol->GetField( REFERENCE_FIELD )->GetText() );
1644 }
1645
1646 wxString symbol_name = aSymbol->GetLibId().Format();
1647
1648 if( symbol_name.size() )
1649 {
1650 name2 = toUTFTildaText( symbol_name );
1651 }
1652 else
1653 {
1654 name2 = "_NONAME_";
1655 }
1656
1657 m_out->Print( 0, "$Comp\n" );
1658 m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1659
1660 // Generate unit number, conversion and timestamp
1661 m_out->Print( 0, "U %d %d %8.8X\n",
1662 aSymbol->GetUnit(),
1663 aSymbol->GetConvert(),
1664 aSymbol->m_Uuid.AsLegacyTimestamp() );
1665
1666 // Save the position
1667 m_out->Print( 0, "P %d %d\n",
1668 schIUScale.IUToMils( aSymbol->GetPosition().x ),
1669 schIUScale.IUToMils( aSymbol->GetPosition().y ) );
1670
1671 /* If this is a complex hierarchy; save hierarchical references.
1672 * but for simple hierarchies it is not necessary.
1673 * the reference inf is already saved
1674 * this is useful for old Eeschema version compatibility
1675 */
1676 if( aSymbol->GetInstanceReferences().size() > 1 )
1677 {
1678 for( const SCH_SYMBOL_INSTANCE& instance : aSymbol->GetInstanceReferences() )
1679 {
1680 /*format:
1681 * AR Path="/140/2" Ref="C99" Part="1"
1682 * where 140 is the uid of the containing sheet and 2 is the timestamp of this symbol.
1683 * (timestamps are actually 8 hex chars)
1684 * Ref is the conventional symbol reference designator for this 'path'
1685 * Part is the conventional symbol unit selection for this 'path'
1686 */
1687 wxString path = "/";
1688
1689 // Skip root sheet
1690 for( int i = 1; i < (int) instance.m_Path.size(); ++i )
1691 path += instance.m_Path[i].AsLegacyTimestampString() + "/";
1692
1693 m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
1695 TO_UTF8( instance.m_Reference ),
1696 instance.m_Unit );
1697 }
1698 }
1699
1700 // update the ugly field id, which I would like to see go away someday soon.
1701 for( int i = 0; i < aSymbol->GetFieldCount(); ++i )
1702 aSymbol->GetFields()[i].SetId( i );
1703
1704 // Fixed fields:
1705 // Save mandatory fields even if they are blank,
1706 // because the visibility, size and orientation are set from library editor.
1707 for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
1708 saveField( &aSymbol->GetFields()[i] );
1709
1710 // User defined fields:
1711 // The *policy* about which user defined fields are symbol of a symbol is now
1712 // only in the dialog editors. No policy should be enforced here, simply
1713 // save all the user defined fields, they are present because a dialog editor
1714 // thought they should be. If you disagree, go fix the dialog editors.
1715 for( int i = MANDATORY_FIELDS; i < aSymbol->GetFieldCount(); ++i )
1716 saveField( &aSymbol->GetFields()[i] );
1717
1718 // Unit number, position, box ( old standard )
1719 m_out->Print( 0, "\t%-4d %-4d %-4d\n", aSymbol->GetUnit(),
1720 schIUScale.IUToMils( aSymbol->GetPosition().x ),
1721 schIUScale.IUToMils( aSymbol->GetPosition().y ) );
1722
1723 TRANSFORM transform = aSymbol->GetTransform();
1724
1725 m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
1726 transform.x1, transform.y1, transform.x2, transform.y2 );
1727 m_out->Print( 0, "$EndComp\n" );
1728}
1729
1730
1732{
1733 char hjustify = 'C';
1734
1735 if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
1736 hjustify = 'L';
1737 else if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
1738 hjustify = 'R';
1739
1740 char vjustify = 'C';
1741
1742 if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_BOTTOM )
1743 vjustify = 'B';
1744 else if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_TOP )
1745 vjustify = 'T';
1746
1747 m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1748 aField->GetId(),
1749 EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1750 aField->GetTextAngle().IsHorizontal() ? 'H' : 'V',
1751 schIUScale.IUToMils( aField->GetLibPosition().x ),
1752 schIUScale.IUToMils( aField->GetLibPosition().y ),
1753 schIUScale.IUToMils( aField->GetTextWidth() ),
1754 !aField->IsVisible(),
1755 hjustify, vjustify,
1756 aField->IsItalic() ? 'I' : 'N',
1757 aField->IsBold() ? 'B' : 'N' );
1758
1759 // Save field name, if the name is user definable
1760 if( aField->GetId() >= MANDATORY_FIELDS )
1761 m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1762
1763 m_out->Print( 0, "\n" );
1764}
1765
1766
1768{
1769 wxCHECK_RET( aBitmap != nullptr, "SCH_BITMAP* is NULL" );
1770
1771 const wxImage* image = aBitmap->GetImage()->GetImageData();
1772
1773 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
1774
1775 m_out->Print( 0, "$Bitmap\n" );
1776 m_out->Print( 0, "Pos %-4d %-4d\n",
1777 schIUScale.IUToMils( aBitmap->GetPosition().x ),
1778 schIUScale.IUToMils( aBitmap->GetPosition().y ) );
1779 m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
1780 m_out->Print( 0, "Data\n" );
1781
1782 wxMemoryOutputStream stream;
1783
1784 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1785
1786 // Write binary data in hexadecimal form (ASCII)
1787 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1788 char* begin = (char*) buffer->GetBufferStart();
1789
1790 for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1791 {
1792 if( ii >= 32 )
1793 {
1794 ii = 0;
1795
1796 m_out->Print( 0, "\n" );
1797 }
1798
1799 m_out->Print( 0, "%2.2X ", *begin & 0xFF );
1800 }
1801
1802 m_out->Print( 0, "\nEndData\n" );
1803 m_out->Print( 0, "$EndBitmap\n" );
1804}
1805
1806
1808{
1809 wxCHECK_RET( aSheet != nullptr, "SCH_SHEET* is NULL" );
1810
1811 m_out->Print( 0, "$Sheet\n" );
1812 m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
1813 schIUScale.IUToMils( aSheet->GetPosition().x ),
1814 schIUScale.IUToMils( aSheet->GetPosition().y ),
1815 schIUScale.IUToMils( aSheet->GetSize().x ),
1816 schIUScale.IUToMils( aSheet->GetSize().y ) );
1817
1818 m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
1819
1820 SCH_FIELD& sheetName = aSheet->GetFields()[SHEETNAME];
1821 SCH_FIELD& fileName = aSheet->GetFields()[SHEETFILENAME];
1822
1823 if( !sheetName.GetText().IsEmpty() )
1824 {
1825 m_out->Print( 0, "F0 %s %d\n",
1826 EscapedUTF8( sheetName.GetText() ).c_str(),
1827 schIUScale.IUToMils( sheetName.GetTextSize().x ) );
1828 }
1829
1830 if( !fileName.GetText().IsEmpty() )
1831 {
1832 m_out->Print( 0, "F1 %s %d\n",
1833 EscapedUTF8( fileName.GetText() ).c_str(),
1834 schIUScale.IUToMils( fileName.GetTextSize().x ) );
1835 }
1836
1837 for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1838 {
1839 int type, side;
1840
1841 if( pin->GetText().IsEmpty() )
1842 break;
1843
1844 switch( pin->GetSide() )
1845 {
1846 default:
1847 case SHEET_SIDE::LEFT: side = 'L'; break;
1848 case SHEET_SIDE::RIGHT: side = 'R'; break;
1849 case SHEET_SIDE::TOP: side = 'T'; break;
1850 case SHEET_SIDE::BOTTOM: side = 'B'; break;
1851 }
1852
1853 switch( pin->GetShape() )
1854 {
1855 default:
1856 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: type = 'U'; break;
1857 case LABEL_FLAG_SHAPE::L_INPUT: type = 'I'; break;
1858 case LABEL_FLAG_SHAPE::L_OUTPUT: type = 'O'; break;
1859 case LABEL_FLAG_SHAPE::L_BIDI: type = 'B'; break;
1860 case LABEL_FLAG_SHAPE::L_TRISTATE: type = 'T'; break;
1861 }
1862
1863 m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
1864 pin->GetNumber(),
1865 EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
1866 type, side, schIUScale.IUToMils( pin->GetPosition().x ),
1867 schIUScale.IUToMils( pin->GetPosition().y ),
1868 schIUScale.IUToMils( pin->GetTextWidth() ) );
1869 }
1870
1871 m_out->Print( 0, "$EndSheet\n" );
1872}
1873
1874
1876{
1877 wxCHECK_RET( aJunction != nullptr, "SCH_JUNCTION* is NULL" );
1878
1879 m_out->Print( 0, "Connection ~ %-4d %-4d\n",
1880 schIUScale.IUToMils( aJunction->GetPosition().x ),
1881 schIUScale.IUToMils( aJunction->GetPosition().y ) );
1882}
1883
1884
1886{
1887 wxCHECK_RET( aNoConnect != nullptr, "SCH_NOCONNECT* is NULL" );
1888
1889 m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
1890 schIUScale.IUToMils( aNoConnect->GetPosition().x ),
1891 schIUScale.IUToMils( aNoConnect->GetPosition().y ) );
1892}
1893
1894
1896{
1897 wxCHECK_RET( aBusEntry != nullptr, "SCH_BUS_ENTRY_BASE* is NULL" );
1898
1899 if( aBusEntry->GetLayer() == LAYER_WIRE )
1900 {
1901 m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
1902 schIUScale.IUToMils( aBusEntry->GetPosition().x ),
1903 schIUScale.IUToMils( aBusEntry->GetPosition().y ),
1904 schIUScale.IUToMils( aBusEntry->GetEnd().x ),
1905 schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
1906 }
1907 else
1908 {
1909 m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
1910 schIUScale.IUToMils( aBusEntry->GetPosition().x ),
1911 schIUScale.IUToMils( aBusEntry->GetPosition().y ),
1912 schIUScale.IUToMils( aBusEntry->GetEnd().x ),
1913 schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
1914 }
1915}
1916
1917
1919{
1920 wxCHECK_RET( aLine != nullptr, "SCH_LINE* is NULL" );
1921
1922 const char* layer = "Notes";
1923 const char* width = "Line";
1924
1925 if( aLine->GetLayer() == LAYER_WIRE )
1926 layer = "Wire";
1927 else if( aLine->GetLayer() == LAYER_BUS )
1928 layer = "Bus";
1929
1930 m_out->Print( 0, "Wire %s %s", layer, width );
1931
1932 // Write line style (width, type, color) only for non default values
1933 if( aLine->IsGraphicLine() )
1934 {
1935 if( aLine->GetLineWidth() != 0 )
1936 m_out->Print( 0, " %s %d", T_WIDTH, schIUScale.IUToMils( aLine->GetLineWidth() ) );
1937
1938 m_out->Print( 0, " %s %s", T_STYLE,
1940
1941 if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
1942 {
1943 m_out->Print( 0, " %s",
1944 TO_UTF8( aLine->GetLineColor().ToCSSString() ) );
1945 }
1946 }
1947
1948 m_out->Print( 0, "\n" );
1949
1950 m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
1951 schIUScale.IUToMils( aLine->GetStartPoint().x ),
1952 schIUScale.IUToMils( aLine->GetStartPoint().y ),
1953 schIUScale.IUToMils( aLine->GetEndPoint().x ),
1954 schIUScale.IUToMils( aLine->GetEndPoint().y ) );
1955
1956 m_out->Print( 0, "\n");
1957}
1958
1959
1961{
1962 wxCHECK_RET( aText != nullptr, "SCH_TEXT* is NULL" );
1963
1964 const char* italics = "~";
1965 const char* textType = "Notes";
1966
1967 if( aText->IsItalic() )
1968 italics = "Italic";
1969
1970 wxString text = aText->GetText();
1971
1972 SCH_LAYER_ID layer = aText->GetLayer();
1973
1974 if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
1975 {
1976 if( layer == LAYER_NOTES )
1977 {
1978 // For compatibility reasons, the text must be saved in only one text line
1979 // so replace all EOLs with \\n
1980 text.Replace( wxT( "\n" ), wxT( "\\n" ) );
1981
1982 // Here we should have no CR or LF character in line
1983 // This is not always the case if a multiline text was copied (using a copy/paste
1984 // function) from a text that uses E.O.L characters that differs from the current
1985 // EOL format. This is mainly the case under Linux using LF symbol when copying
1986 // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
1987 // (or LF left under MacOSX)
1988 for( unsigned ii = 0; ii < text.Len(); )
1989 {
1990 if( text[ii] == 0x0A || text[ii] == 0x0D )
1991 text.erase( ii, 1 );
1992 else
1993 ii++;
1994 }
1995 }
1996 else
1997 {
1998 textType = "Label";
1999 }
2000
2001 int spinStyle = 0;
2002
2003 // Local labels must have their spin style inverted for left and right
2004 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aText ) )
2005 {
2006 spinStyle = static_cast<int>( label->GetSpinStyle() );
2007
2008 if( spinStyle == 0 )
2009 spinStyle = 2;
2010 else if( spinStyle == 2 )
2011 spinStyle = 0;
2012 }
2013
2014 m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2015 schIUScale.IUToMils( aText->GetPosition().x ),
2016 schIUScale.IUToMils( aText->GetPosition().y ),
2017 spinStyle,
2018 schIUScale.IUToMils( aText->GetTextWidth() ),
2019 italics, schIUScale.IUToMils( aText->GetTextThickness() ), TO_UTF8( text ) );
2020 }
2021 else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2022 {
2023 textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2024
2025 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aText );
2026 auto shapeLabelIt = sheetLabelNames.find( label->GetShape() );
2027 wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
2028
2029 m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2030 schIUScale.IUToMils( aText->GetPosition().x ),
2031 schIUScale.IUToMils( aText->GetPosition().y ),
2032 static_cast<int>( label->GetSpinStyle() ),
2033 schIUScale.IUToMils( aText->GetTextWidth() ),
2034 shapeLabelIt->second,
2035 italics,
2037 }
2038}
2039
2040
2041void SCH_LEGACY_PLUGIN::saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias )
2042{
2043 wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
2044
2045 wxString members = boost::algorithm::join( aAlias->Members(), " " );
2046
2047 m_out->Print( 0, "BusAlias %s %s\n",
2048 TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2049}
2050
2051
2052void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties )
2053{
2054 if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
2055 {
2056 // a spectacular episode in memory management:
2057 delete m_cache;
2058 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
2059
2060 if( !isBuffering( aProperties ) )
2061 m_cache->Load();
2062 }
2063}
2064
2065
2067{
2068 std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
2069
2070 if( aProperties && aProperties->find( propName ) != aProperties->end() )
2071 return false;
2072
2073 return true;
2074}
2075
2076
2078{
2079 return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
2080}
2081
2082
2084{
2085 if( m_cache )
2086 return m_cache->GetModifyHash();
2087
2088 // If the cache hasn't been loaded, it hasn't been modified.
2089 return 0;
2090}
2091
2092
2093void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
2094 const wxString& aLibraryPath,
2095 const STRING_UTF8_MAP* aProperties )
2096{
2097 LOCALE_IO toggle; // toggles on, then off, the C locale.
2098
2099 bool powerSymbolsOnly = ( aProperties &&
2100 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2101
2102 cacheLib( aLibraryPath, aProperties );
2103
2104 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2105
2106 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2107 {
2108 if( !powerSymbolsOnly || it->second->IsPower() )
2109 aSymbolNameList.Add( it->first );
2110 }
2111}
2112
2113
2114void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
2115 const wxString& aLibraryPath,
2116 const STRING_UTF8_MAP* aProperties )
2117{
2118 LOCALE_IO toggle; // toggles on, then off, the C locale.
2119
2120 bool powerSymbolsOnly = ( aProperties &&
2121 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2122
2123 cacheLib( aLibraryPath, aProperties );
2124
2125 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2126
2127 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2128 {
2129 if( !powerSymbolsOnly || it->second->IsPower() )
2130 aSymbolList.push_back( it->second );
2131 }
2132}
2133
2134
2135LIB_SYMBOL* SCH_LEGACY_PLUGIN::LoadSymbol( const wxString& aLibraryPath,
2136 const wxString& aSymbolName,
2137 const STRING_UTF8_MAP* aProperties )
2138{
2139 LOCALE_IO toggle; // toggles on, then off, the C locale.
2140
2141 cacheLib( aLibraryPath, aProperties );
2142
2143 LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
2144
2145 if( it == m_cache->m_symbols.end() )
2146 return nullptr;
2147
2148 return it->second;
2149}
2150
2151
2152void SCH_LEGACY_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
2153 const STRING_UTF8_MAP* aProperties )
2154{
2155 LOCALE_IO toggle; // toggles on, then off, the C locale.
2156
2157 cacheLib( aLibraryPath, aProperties );
2158
2159 m_cache->AddSymbol( aSymbol );
2160
2161 if( !isBuffering( aProperties ) )
2162 m_cache->Save( writeDocFile( aProperties ) );
2163}
2164
2165
2166void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
2167 const STRING_UTF8_MAP* aProperties )
2168{
2169 LOCALE_IO toggle; // toggles on, then off, the C locale.
2170
2171 cacheLib( aLibraryPath, aProperties );
2172
2173 m_cache->DeleteSymbol( aSymbolName );
2174
2175 if( !isBuffering( aProperties ) )
2176 m_cache->Save( writeDocFile( aProperties ) );
2177}
2178
2179
2180void SCH_LEGACY_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
2181 const STRING_UTF8_MAP* aProperties )
2182{
2183 if( wxFileExists( aLibraryPath ) )
2184 {
2185 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
2186 aLibraryPath.GetData() ) );
2187 }
2188
2189 LOCALE_IO toggle;
2190
2191 delete m_cache;
2192 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
2194 m_cache->Save( writeDocFile( aProperties ) );
2195 m_cache->Load(); // update m_writable and m_mod_time
2196}
2197
2198
2199bool SCH_LEGACY_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath,
2200 const STRING_UTF8_MAP* aProperties )
2201{
2202 wxFileName fn = aLibraryPath;
2203
2204 if( !fn.FileExists() )
2205 return false;
2206
2207 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2208 // we don't want that. we want bare metal portability with no UI here.
2209 if( wxRemove( aLibraryPath ) )
2210 {
2211 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' cannot be deleted." ),
2212 aLibraryPath.GetData() ) );
2213 }
2214
2215 if( m_cache && m_cache->IsFile( aLibraryPath ) )
2216 {
2217 delete m_cache;
2218 m_cache = nullptr;
2219 }
2220
2221 return true;
2222}
2223
2224
2225void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
2226{
2227 if( !m_cache )
2228 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
2229
2230 wxString oldFileName = m_cache->GetFileName();
2231
2232 if( !m_cache->IsFile( aLibraryPath ) )
2233 {
2234 m_cache->SetFileName( aLibraryPath );
2235 }
2236
2237 // This is a forced save.
2239 m_cache->Save( writeDocFile( aProperties ) );
2240 m_cache->SetFileName( oldFileName );
2241}
2242
2243
2244bool SCH_LEGACY_PLUGIN::CanReadSchematicFile( const wxString& aFileName ) const
2245{
2246 if( !SCH_PLUGIN::CanReadSchematicFile( aFileName ) )
2247 return false;
2248
2249 return PLUGIN_UTILS::fileStartsWithPrefix( aFileName, wxT( "EESchema" ), true );
2250}
2251
2252
2253bool SCH_LEGACY_PLUGIN::CanReadLibrary( const wxString& aFileName ) const
2254{
2255 if( !SCH_PLUGIN::CanReadLibrary( aFileName ) )
2256 return false;
2257
2258 return PLUGIN_UTILS::fileStartsWithPrefix( aFileName, wxT( "EESchema" ), true );
2259}
2260
2261
2262bool SCH_LEGACY_PLUGIN::IsSymbolLibWritable( const wxString& aLibraryPath )
2263{
2264 // Writing legacy symbol libraries is deprecated.
2265 return false;
2266}
2267
2268
2270 int aMinorVersion )
2271{
2272 return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
2273}
2274
2275
2277{
2278 SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( symbol, formatter );
2279}
2280
2281
2282
2283const char* SCH_LEGACY_PLUGIN::PropBuffering = "buffering";
2284const char* SCH_LEGACY_PLUGIN::PropNoDocFile = "no_doc_file";
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
void SetPageCount(int aPageCount)
Definition: base_screen.cpp:63
int GetPageCount() const
Definition: base_screen.h:72
int GetVirtualPageNumber() const
Definition: base_screen.h:75
void SetVirtualPageNumber(int aPageNumber)
Definition: base_screen.h:76
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
This class handle bitmap images in KiCad.
Definition: bitmap_base.h:48
double GetScale() const
Definition: bitmap_base.h:72
int GetPPI() const
Definition: bitmap_base.h:117
wxImage * GetImageData()
Definition: bitmap_base.h:67
void SetScale(double aScale)
Definition: bitmap_base.h:73
bool IsHorizontal() const
Definition: eda_angle.h:174
const KIID m_Uuid
Definition: eda_item.h:482
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
void SetTextSize(VECTOR2I aNewSize)
Definition: eda_text.cpp:358
bool IsItalic() const
Definition: eda_text.h:141
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:131
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
virtual bool IsVisible() const
Definition: eda_text.h:147
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:401
int GetTextWidth() const
Definition: eda_text.h:221
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:260
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:160
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:229
void SetBold(bool aBold)
Definition: eda_text.cpp:221
bool IsBold() const
Definition: eda_text.h:144
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:163
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:205
int GetTextThickness() const
Definition: eda_text.h:123
void SetItalic(bool aItalic)
Definition: eda_text.cpp:213
VECTOR2I GetTextSize() const
Definition: eda_text.h:218
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:252
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
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
Used for text file output.
Definition: richio.h:475
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
wxString ToCSSString() const
Definition: color4d.cpp:147
Definition: kiid.h:49
wxString AsLegacyTimestampString() const
Definition: kiid.cpp:263
timestamp_t AsLegacyTimestamp() const
Definition: kiid.cpp:230
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:51
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition: lib_id.cpp:110
UTF8 Format() const
Definition: lib_id.cpp:118
Define a library symbol object.
Definition: lib_symbol.h:99
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:121
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:147
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:129
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
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:458
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:58
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:189
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:81
void SetHeightMils(double aHeightInMils)
Definition: page_info.cpp:261
double GetHeightMils() const
Definition: page_info.h:140
const wxString & GetType() const
Definition: page_info.h:98
double GetWidthMils() const
Definition: page_info.h:135
bool IsCustom() const
Definition: page_info.cpp:183
bool IsPortrait() const
Definition: page_info.h:121
void SetWidthMils(double aWidthInMils)
Definition: page_info.cpp:247
bool SetType(const wxString &aStandardPageDescriptionName, bool aIsPortrait=false)
Set the name of the page type and also the sizes and margins commonly associated with that type name.
Definition: page_info.cpp:122
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 void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:143
Holds all the data relating to one schematic.
Definition: schematic.h:75
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:121
SCH_SHEET & Root() const
Definition: schematic.h:105
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
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:147
BITMAP_BASE * GetImage() const
Definition: sch_bitmap.h:54
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
VECTOR2I GetPosition() const override
VECTOR2I GetEnd() const
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:52
int GetId() const
Definition: sch_field.h:128
VECTOR2I GetLibPosition() const
Definition: sch_field.h:262
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1000
void SetName(const wxString &aName)
Definition: sch_field.cpp:979
void SetText(const wxString &aText) override
Definition: sch_field.cpp:989
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:151
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
Definition: sch_item.h:258
VECTOR2I GetPosition() const override
Definition: sch_junction.h:106
SPIN_STYLE GetSpinStyle() const
Definition: sch_label.cpp:372
void SetShape(LABEL_FLAG_SHAPE aShape)
Definition: sch_label.h:168
LABEL_FLAG_SHAPE GetShape() const
Definition: sch_label.h:167
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Definition: sch_label.cpp:337
A cache assistant for KiCad legacy symbol libraries.
void Save(const std::optional< bool > &aOpt) override
Save the entire library to file m_libFileName;.
void DeleteSymbol(const wxString &aName) override
static void SaveSymbol(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter, LIB_SYMBOL_MAP *aMap=nullptr)
static LIB_SYMBOL * LoadPart(LINE_READER &aReader, int aMajorVersion, int aMinorVersion, LIB_SYMBOL_MAP *aMap=nullptr)
int m_version
Version of file being loaded.
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified symbol library file.
SCH_LINE * loadWire(LINE_READER &aReader)
void saveSymbol(SCH_SYMBOL *aSymbol)
int GetModifyHash() const override
Return the modification hash from the library cache.
wxString m_error
For throwing exceptions or errors on partial schematic loads.
void SaveLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
void saveSheet(SCH_SHEET *aSheet)
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
wxString m_path
Root project path for loading child sheets.
void saveText(SCH_TEXT *aText)
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
bool writeDocFile(const STRING_UTF8_MAP *aProperties)
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified schematic file.
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
void Format(SCH_SHEET *aSheet)
void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Create a new empty symbol library at aLibraryPath.
void saveField(SCH_FIELD *aField)
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.
void saveJunction(SCH_JUNCTION *aJunction)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
void saveLine(SCH_LINE *aLine)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
bool DeleteSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing symbol library and returns true if successful, or if library does not exist return...
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
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.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
static LIB_SYMBOL * ParsePart(LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
unsigned m_lineCount
for progress reporting
SCH_SHEET * loadSheet(LINE_READER &aReader)
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.
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
static void FormatPart(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
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 SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aScreen, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
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_PLUGIN implementation knows about,...
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_TEXT * loadText(LINE_READER &aReader)
void saveBitmap(SCH_BITMAP *aBitmap)
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
bool isBuffering(const STRING_UTF8_MAP *aProperties)
LINE_READER * m_lineReader
for progress reporting
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
void loadHierarchy(SCH_SHEET *aSheet)
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...
SCH_LEGACY_PLUGIN_CACHE * m_cache
SCH_SHEET * m_currentSheet
The sheet currently being loaded.
bool IsFile(const wxString &aFullPathAndFileName) const
wxString GetFileName() const
void SetFileName(const wxString &aFileName)
virtual void AddSymbol(const LIB_SYMBOL *aSymbol)
void SetModified(bool aModified=true)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
VECTOR2I GetEndPoint() const
Definition: sch_line.h:145
VECTOR2I GetStartPoint() const
Definition: sch_line.h:140
LINE_STYLE GetLineStyle() const
Definition: sch_line.cpp:293
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:967
int GetLineWidth() const
Definition: sch_line.h:177
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:267
VECTOR2I GetPosition() const override
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified schematic file.
Definition: sch_plugin.cpp:51
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified symbol library file.
Definition: sch_plugin.cpp:67
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
auto & GetBusAliases() const
Return a set of bus aliases defined in this screen.
Definition: sch_screen.h:510
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition: sch_screen.h:157
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:150
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Add a bus alias definition (and transfers ownership of the pointer).
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition: sch_screen.h:132
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
const wxString & GetFileName() const
Definition: sch_screen.h:144
const KIID & GetUuid() const
Definition: sch_screen.h:525
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:115
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:155
void SetFileReadOnly(bool aIsReadOnly)
Definition: sch_screen.h:146
void SetFileExists(bool aFileExists)
Definition: sch_screen.h:149
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
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:308
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:728
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:374
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
Schematic symbol object.
Definition: sch_symbol.h:81
int GetUnit() const
Definition: sch_symbol.h:228
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:476
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstanceReferences() const
Definition: sch_symbol.h:140
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:939
int GetConvert() const
Definition: sch_symbol.h:270
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:700
TRANSFORM & GetTransform()
Definition: sch_symbol.h:285
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:175
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:987
wxString GetPrefix() const
Definition: sch_symbol.h:274
VECTOR2I GetPosition() const override
Definition: sch_text.h:134
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:99
A name/value tuple with unique names and optional values.
bool Exists(const std::string &aProperty) const
static wxString GetLineStyleToken(LINE_STYLE aStyle)
static const char * PropPowerSymsOnly
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition: title_block.h:41
const wxString & GetCompany() const
Definition: title_block.h:96
void SetRevision(const wxString &aRevision)
Definition: title_block.h:81
void SetComment(int aIdx, const wxString &aComment)
Definition: title_block.h:101
const wxString & GetRevision() const
Definition: title_block.h:86
void SetTitle(const wxString &aTitle)
Definition: title_block.h:58
const wxString & GetDate() const
Definition: title_block.h:76
const wxString & GetComment(int aIdx) const
Definition: title_block.h:107
void SetCompany(const wxString &aCompany)
Definition: title_block.h:91
const wxString & GetTitle() const
Definition: title_block.h:63
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
Definition: title_block.h:71
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:46
int x2
Definition: transform.h:50
int y1
Definition: transform.h:49
int y2
Definition: transform.h:51
int x1
Definition: transform.h:48
#define _(s)
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:433
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:434
#define MAX_UNIT_COUNT_PER_PACKAGE
The maximum number of units per package.
Definition: eeschema_id.h:36
#define SCHEMATIC_HEAD_STRING
Definition: general.h:36
#define EESCHEMA_VERSION
Definition: general.h:35
int GetPenSizeForBold(int aTextSize)
Definition: gr_text.cpp:40
const wxChar *const traceSchLegacyPlugin
Flag to enable legacy schematic plugin debug output.
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:165
#define SCH_LAYER_ID_COUNT
Definition: layer_ids.h:399
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:346
@ LAYER_HIERLABEL
Definition: layer_ids.h:354
@ LAYER_GLOBLABEL
Definition: layer_ids.h:353
@ LAYER_WIRE
Definition: layer_ids.h:349
@ LAYER_NOTES
Definition: layer_ids.h:363
@ LAYER_BUS
Definition: layer_ids.h:350
@ LAYER_LOCLABEL
Definition: layer_ids.h:352
bool fileStartsWithPrefix(const wxString &aFilePath, const wxString &aPrefix, bool aIgnoreWhitespace)
Check if a file starts with a defined string.
@ L_BIDI
Definition: sch_label.h:94
@ L_TRISTATE
Definition: sch_label.h:95
@ L_UNSPECIFIED
Definition: sch_label.h:96
@ L_OUTPUT
Definition: sch_label.h:93
@ L_INPUT
Definition: sch_label.h:92
const std::map< LABEL_FLAG_SHAPE, const char * > sheetLabelNames
#define T_COLORA
#define T_WIDTH
#define T_COLOR
#define T_STYLE
int parseInt(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII integer string with possible leading whitespace into an integer and updates the pointe...
bool strCompare(const char *aString, const char *aLine, const char **aOutput)
Compare aString to the string starting at aLine and advances the character point to the end of String...
void parseQuotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
Parse an quoted ASCII utf8 and updates the pointer at aOutput if it is not NULL.
void parseUnquotedString(wxString &aString, LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken, bool aCanBeEmpty)
Parse an unquoted utf8 string and updates the pointer at aOutput if it is not NULL.
uint32_t parseHex(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parse an ASCII hex integer string with possible leading whitespace into a long integer and updates th...
bool is_eol(char c)
char parseChar(LINE_READER &aReader, const char *aCurrentToken, const char **aNextToken)
Parse a single ASCII character and updates the pointer at aOutput if it is not NULL.
double parseDouble(LINE_READER &aReader, const char *aLine, const char **aOutput)
Parses an ASCII point string with possible leading whitespace into a double precision floating point ...
#define SCH_PARSE_ERROR(text, reader, pos)
@ SHEETNAME
Definition: sch_sheet.h:45
@ SHEETFILENAME
Definition: sch_sheet.h:46
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:54
wxString ConvertToNewOverbarNotation(const wxString &aOldStr)
Convert the old ~...~ overbar notation to the new ~{...} one.
wxString From_UTF8(const char *cstring)
std::string EscapedUTF8(const wxString &aString)
Return an 8 bit UTF8 string given aString in Unicode form.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:391
constexpr int IUToMils(int iu) const
Definition: base_units.h:100
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
A simple container for schematic symbol instance information.
static const wxString GetDefaultFieldName(int aFieldNdx, bool aTranslateForHI=false)
Return a default symbol field name for field aFieldNdx for all components.
Definition for symbol library class.
std::map< wxString, LIB_SYMBOL *, LibSymbolMapSort > LIB_SYMBOL_MAP
@ 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".
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_TOP
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_LINE_T
Definition: typeinfo.h:146
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:143
@ TYPE_NOT_INIT
Definition: typeinfo.h:81
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_SHEET_T
Definition: typeinfo.h:158
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:145
@ SCH_TEXT_T
Definition: typeinfo.h:150
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:144
@ SCH_BITMAP_T
Definition: typeinfo.h:148
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
@ SCH_JUNCTION_T
Definition: typeinfo.h:142
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588
Definition of file extensions used in Kicad.