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