KiCad PCB EDA Suite
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, "m_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 wxSize size;
550
551 size.SetWidth( schIUScale.MilsToIU( parseInt( aReader, line, &line ) ) );
552 size.SetHeight( 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( wxSize( 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( wxSize( 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 bitmap->GetImage()->SetImage( image );
695 break;
696 }
697
698 // Read PNG data, stored in hexadecimal,
699 // each byte = 2 hexadecimal digits and a space between 2 bytes
700 // and put it in memory stream buffer
701 // Note:
702 // Some old files created bu the V4 schematic versions have a extra
703 // "$EndBitmap" at the end of the hexadecimal data. (Probably due to
704 // a bug). So discard it
705 int len = strlen( line );
706
707 for( ; len > 0 && !isspace( *line ) && '$' != *line; len -= 3, line += 3 )
708 {
709 int value = 0;
710
711 if( sscanf( line, "%X", &value ) == 1 )
712 stream.PutC( (char) value );
713 else
714 THROW_IO_ERROR( "invalid PNG data" );
715 }
716 }
717
718 if( line == nullptr )
719 THROW_IO_ERROR( _( "unexpected end of file" ) );
720 }
721 else if( strCompare( "$EndBitmap", line ) )
722 {
723 return bitmap.release();
724 }
725
726 line = aReader.ReadLine();
727 }
728
729 THROW_IO_ERROR( _( "unexpected end of file" ) );
730}
731
732
734{
735 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
736
737 const char* line = aReader.Line();
738
739 wxCHECK( strCompare( "Connection", line, &line ), nullptr );
740
741 wxString name;
742
743 parseUnquotedString( name, aReader, line, &line );
744
745 VECTOR2I position;
746
747 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
748 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
749 junction->SetPosition( position );
750
751 return junction.release();
752}
753
754
756{
757 std::unique_ptr<SCH_NO_CONNECT> no_connect = std::make_unique<SCH_NO_CONNECT>();
758
759 const char* line = aReader.Line();
760
761 wxCHECK( strCompare( "NoConn", line, &line ), nullptr );
762
763 wxString name;
764
765 parseUnquotedString( name, aReader, line, &line );
766
767 VECTOR2I position;
768
769 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
770 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
771 no_connect->SetPosition( position );
772
773 return no_connect.release();
774}
775
776
778{
779 std::unique_ptr<SCH_LINE> wire = std::make_unique<SCH_LINE>();
780
781 const char* line = aReader.Line();
782
783 wxCHECK( strCompare( "Wire", line, &line ), nullptr );
784
785 if( strCompare( "Wire", line, &line ) )
786 wire->SetLayer( LAYER_WIRE );
787 else if( strCompare( "Bus", line, &line ) )
788 wire->SetLayer( LAYER_BUS );
789 else if( strCompare( "Notes", line, &line ) )
790 wire->SetLayer( LAYER_NOTES );
791 else
792 SCH_PARSE_ERROR( "invalid line type", aReader, line );
793
794 if( !strCompare( "Line", line, &line ) )
795 SCH_PARSE_ERROR( "invalid wire definition", aReader, line );
796
797 // Since Sept 15, 2017, a line style is alloved (width, style, color)
798 // Only non default values are stored
799 while( !is_eol( *line ) )
800 {
801 wxString buf;
802
803 parseUnquotedString( buf, aReader, line, &line );
804
805 if( buf == ")" )
806 continue;
807
808 else if( buf == T_WIDTH )
809 {
810 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
811 wire->SetLineWidth( size );
812 }
813 else if( buf == T_STYLE )
814 {
815 parseUnquotedString( buf, aReader, line, &line );
816
817 if( buf == wxT( "solid" ) )
818 wire->SetLineStyle( PLOT_DASH_TYPE::SOLID );
819 else if( buf == wxT( "dashed" ) )
820 wire->SetLineStyle( PLOT_DASH_TYPE::DASH );
821 else if( buf == wxT( "dash_dot" ) )
822 wire->SetLineStyle( PLOT_DASH_TYPE::DASHDOT );
823 else if( buf == wxT( "dotted" ) )
824 wire->SetLineStyle( PLOT_DASH_TYPE::DOT );
825 }
826 else // should be the color parameter.
827 {
828 // The color param is something like rgb(150, 40, 191)
829 // and because there is no space between ( and 150
830 // the first param is inside buf.
831 // So break keyword and the first param into 2 separate strings.
832 wxString prm, keyword;
833 keyword = buf.BeforeLast( '(', &prm );
834
835 if( ( keyword == T_COLOR ) || ( keyword == T_COLORA ) )
836 {
837 long color[4] = { 0 };
838
839 int ii = 0;
840
841 if( !prm.IsEmpty() )
842 {
843 prm.ToLong( &color[ii] );
844 ii++;
845 }
846
847 int prm_count = ( keyword == T_COLORA ) ? 4 : 3;
848
849 // fix opacity to 1.0 or 255, when not exists in file
850 color[3] = 255;
851
852 for(; ii < prm_count && !is_eol( *line ); ii++ )
853 {
854 color[ii] = parseInt( aReader, line, &line );
855
856 // Skip the separator between values
857 if( *line == ',' || *line == ' ')
858 line++;
859 }
860
861 wire->SetLineColor( color[0]/255.0, color[1]/255.0, color[2]/255.0,color[3]/255.0 );
862 }
863 }
864 }
865
866 // Read the segment en points coordinates:
867 line = aReader.ReadLine();
868
869 VECTOR2I begin, end;
870
871 begin.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
872 begin.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
873 end.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
874 end.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
875
876 wire->SetStartPoint( begin );
877 wire->SetEndPoint( end );
878
879 return wire.release();
880}
881
882
884{
885 const char* line = aReader.Line();
886
887 wxCHECK( strCompare( "Entry", line, &line ), nullptr );
888
889 std::unique_ptr<SCH_BUS_ENTRY_BASE> busEntry;
890
891 if( strCompare( "Wire", line, &line ) )
892 {
893 busEntry = std::make_unique<SCH_BUS_WIRE_ENTRY>();
894
895 if( !strCompare( "Line", line, &line ) )
896 SCH_PARSE_ERROR( "invalid bus entry definition expected 'Line'", aReader, line );
897 }
898 else if( strCompare( "Bus", line, &line ) )
899 {
900 busEntry = std::make_unique<SCH_BUS_BUS_ENTRY>();
901
902 if( !strCompare( "Bus", line, &line ) )
903 SCH_PARSE_ERROR( "invalid bus entry definition expected 'Bus'", aReader, line );
904 }
905 else
906 {
907 SCH_PARSE_ERROR( "invalid bus entry type", aReader, line );
908 }
909
910 line = aReader.ReadLine();
911
912 VECTOR2I pos;
913 wxSize size;
914
915 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
916 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
917 size.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
918 size.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
919
920 size.x -= pos.x;
921 size.y -= pos.y;
922
923 busEntry->SetPosition( pos );
924 busEntry->SetSize( size );
925
926 return busEntry.release();
927}
928
929
930// clang-format off
931const std::map<LABEL_FLAG_SHAPE, const char*> sheetLabelNames
932{
933 { LABEL_FLAG_SHAPE::L_INPUT, "Input" },
934 { LABEL_FLAG_SHAPE::L_OUTPUT, "Output" },
935 { LABEL_FLAG_SHAPE::L_BIDI, "BiDi" },
936 { LABEL_FLAG_SHAPE::L_TRISTATE, "3State" },
938};
939// clang-format on
940
941
943{
944 const char* line = aReader.Line();
945 KICAD_T textType = TYPE_NOT_INIT;
946
947 wxCHECK( strCompare( "Text", line, &line ), nullptr );
948
949 if( strCompare( "Notes", line, &line ) )
950 {
951 textType = SCH_TEXT_T;
952 }
953 else if( strCompare( "Label", line, &line ) )
954 {
955 textType = SCH_LABEL_T;
956 }
957 else if( strCompare( "HLabel", line, &line ) )
958 {
959 textType = SCH_HIER_LABEL_T;
960 }
961 else if( strCompare( "GLabel", line, &line ) )
962 {
963 // Prior to version 2, the SCH_GLOBALLABEL object did not exist.
964 if( m_version == 1 )
965 textType = SCH_HIER_LABEL_T;
966 else
967 textType = SCH_GLOBAL_LABEL_T;
968 }
969 else
970 {
971 SCH_PARSE_ERROR( "unknown Text type", aReader, line );
972 }
973
974 VECTOR2I position;
975
976 position.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
977 position.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
978
979 std::unique_ptr<SCH_TEXT> text;
980
981 switch( textType )
982 {
983 case SCH_TEXT_T: text.reset( new SCH_TEXT( position ) ); break;
984 case SCH_LABEL_T: text.reset( new SCH_LABEL( position ) ); break;
985 case SCH_HIER_LABEL_T: text.reset( new SCH_HIERLABEL( position ) ); break;
986 case SCH_GLOBAL_LABEL_T: text.reset( new SCH_GLOBALLABEL( position ) ); break;
987 default: break;
988 }
989
990 int spinStyle = parseInt( aReader, line, &line );
991
992 // Sadly we store the orientation of hierarchical and global labels using a different
993 // int encoding than that for local labels:
994 // Global Local
995 // Left justified 0 2
996 // Up 1 3
997 // Right justified 2 0
998 // Down 3 1
999 // So we must flip it as the enum is setup with the "global" numbering
1000 if( text->Type() != SCH_GLOBAL_LABEL_T && text->Type() != SCH_HIER_LABEL_T )
1001 {
1002 if( spinStyle == 0 )
1003 spinStyle = 2;
1004 else if( spinStyle == 2 )
1005 spinStyle = 0;
1006 }
1007
1008 text->SetTextSpinStyle( static_cast<TEXT_SPIN_STYLE::SPIN>( spinStyle ) );
1009
1010 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1011
1012 text->SetTextSize( wxSize( size, size ) );
1013
1014 // Parse the global and hierarchical label type.
1015 if( text->Type() == SCH_HIER_LABEL_T || text->Type() == SCH_GLOBAL_LABEL_T )
1016 {
1017 auto resultIt = std::find_if( sheetLabelNames.begin(), sheetLabelNames.end(),
1018 [ &line ]( const auto& it )
1019 {
1020 return strCompare( it.second, line, &line );
1021 } );
1022
1023 if( resultIt != sheetLabelNames.end() )
1024 text->SetShape( resultIt->first );
1025 else
1026 SCH_PARSE_ERROR( "invalid label type", aReader, line );
1027 }
1028
1029 int penWidth = 0;
1030
1031 // The following tokens do not exist in version 1 schematic files,
1032 // and not always in version 2 for HLabels and GLabels
1033 if( m_version > 1 )
1034 {
1035 if( m_version > 2 || *line >= ' ' )
1036 {
1037 if( strCompare( "Italic", line, &line ) )
1038 text->SetItalic( true );
1039 else if( !strCompare( "~", line, &line ) )
1040 SCH_PARSE_ERROR( _( "expected 'Italics' or '~'" ), aReader, line );
1041 }
1042
1043 // The penWidth token does not exist in older versions of the schematic file format
1044 // so calling parseInt will be made only if the EOL is not reached.
1045 if( *line >= ' ' )
1046 penWidth = parseInt( aReader, line, &line );
1047 }
1048
1049 text->SetBold( penWidth != 0 );
1050 text->SetTextThickness( penWidth != 0 ? GetPenSizeForBold( size ) : 0 );
1051
1052 // Read the text string for the text.
1053 char* tmp = aReader.ReadLine();
1054
1055 tmp = strtok( tmp, "\r\n" );
1056 wxString val = FROM_UTF8( tmp );
1057
1058 for( ; ; )
1059 {
1060 int i = val.find( wxT( "\\n" ) );
1061
1062 if( i == wxNOT_FOUND )
1063 break;
1064
1065 val.erase( i, 2 );
1066 val.insert( i, wxT( "\n" ) );
1067 }
1068
1069 text->SetText( ConvertToNewOverbarNotation( val ) );
1070
1071 return text.release();
1072}
1073
1074
1076{
1077 const char* line = aReader.Line();
1078
1079 wxCHECK( strCompare( "$Comp", line, &line ), nullptr );
1080
1081 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1082
1083 line = aReader.ReadLine();
1084
1085 while( line != nullptr )
1086 {
1087 if( strCompare( "L", line, &line ) )
1088 {
1089 wxString libName;
1090 size_t pos = 2; // "X" plus ' ' space character.
1091 wxString utf8Line = wxString::FromUTF8( line );
1092 wxStringTokenizer tokens( utf8Line, " \r\n\t" );
1093
1094 if( tokens.CountTokens() < 2 )
1095 THROW_PARSE_ERROR( "invalid symbol library definition", aReader.GetSource(),
1096 aReader.Line(), aReader.LineNumber(), pos );
1097
1098 libName = tokens.GetNextToken();
1099 libName.Replace( "~", " " );
1100
1101 LIB_ID libId;
1102
1103 // Prior to schematic version 4, library IDs did not have a library nickname so
1104 // parsing the symbol name with LIB_ID::Parse() would break symbol library links
1105 // that contained '/' and ':' characters.
1106 if( m_version > 3 )
1107 libId.Parse( libName, true );
1108 else
1109 libId.SetLibItemName( libName );
1110
1111 symbol->SetLibId( libId );
1112
1113 wxString refDesignator = tokens.GetNextToken();
1114
1115 refDesignator.Replace( "~", " " );
1116
1117 wxString prefix = refDesignator;
1118
1119 while( prefix.Length() )
1120 {
1121 if( ( prefix.Last() < '0' || prefix.Last() > '9') && prefix.Last() != '?' )
1122 break;
1123
1124 prefix.RemoveLast();
1125 }
1126
1127 // Avoid a prefix containing trailing/leading spaces
1128 prefix.Trim( true );
1129 prefix.Trim( false );
1130
1131 if( prefix.IsEmpty() )
1132 symbol->SetPrefix( wxString( "U" ) );
1133 else
1134 symbol->SetPrefix( prefix );
1135 }
1136 else if( strCompare( "U", line, &line ) )
1137 {
1138 // This fixes a potentially buggy files caused by unit being set to zero which
1139 // causes netlist issues. See https://bugs.launchpad.net/kicad/+bug/1677282.
1140 int unit = parseInt( aReader, line, &line );
1141
1142 if( unit == 0 )
1143 {
1144 unit = 1;
1145
1146 // Set the file as modified so the user can be warned.
1147 if( m_rootSheet->GetScreen() )
1149 }
1150
1151 symbol->SetUnit( unit );
1152
1153 // Same can also happen with the convert parameter
1154 int convert = parseInt( aReader, line, &line );
1155
1156 if( convert == 0 )
1157 {
1158 convert = 1;
1159
1160 // Set the file as modified so the user can be warned.
1161 if( m_rootSheet->GetScreen() )
1163 }
1164
1165 symbol->SetConvert( convert );
1166
1167 wxString text;
1168 parseUnquotedString( text, aReader, line, &line );
1169
1170 if( text != "00000000" )
1171 const_cast<KIID&>( symbol->m_Uuid ) = KIID( text );
1172 }
1173 else if( strCompare( "P", line, &line ) )
1174 {
1175 VECTOR2I pos;
1176
1177 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1178 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1179 symbol->SetPosition( pos );
1180 }
1181 else if( strCompare( "AR", line, &line ) )
1182 {
1183 const char* strCompare = "Path=";
1184 int len = strlen( strCompare );
1185
1186 if( strncasecmp( strCompare, line, len ) != 0 )
1187 SCH_PARSE_ERROR( "missing 'Path=' token", aReader, line );
1188
1189 line += len;
1190 wxString pathStr, reference, unit;
1191
1192 parseQuotedString( pathStr, aReader, line, &line );
1193
1194 // Note: AR path excludes root sheet, but includes symbol. Drop the symbol ID
1195 // since it's already defined in the symbol itself.
1196 KIID_PATH path( pathStr );
1197
1198 if( path.size() > 0 )
1199 path.pop_back();
1200
1201 // In the new file format, the root schematic UUID is used as the virtual SCH_SHEET
1202 // UUID so we need to prefix it to the symbol path so the symbol instance paths
1203 // get saved with the root schematic UUID.
1204 if( !m_appending )
1205 path.insert( path.begin(), m_rootSheet->GetScreen()->GetUuid() );
1206
1207 strCompare = "Ref=";
1208 len = strlen( strCompare );
1209
1210 if( strncasecmp( strCompare, line, len ) != 0 )
1211 SCH_PARSE_ERROR( "missing 'Ref=' token", aReader, line );
1212
1213 line+= len;
1214 parseQuotedString( reference, aReader, line, &line );
1215
1216 strCompare = "Part=";
1217 len = strlen( strCompare );
1218
1219 if( strncasecmp( strCompare, line, len ) != 0 )
1220 SCH_PARSE_ERROR( "missing 'Part=' token", aReader, line );
1221
1222 line+= len;
1223 parseQuotedString( unit, aReader, line, &line );
1224
1225 long tmp;
1226
1227 if( !unit.ToLong( &tmp, 10 ) )
1228 SCH_PARSE_ERROR( "expected integer value", aReader, line );
1229
1230 if( tmp < 0 || tmp > MAX_UNIT_COUNT_PER_PACKAGE )
1231 SCH_PARSE_ERROR( "unit value out of range", aReader, line );
1232
1233 symbol->AddHierarchicalReference( path, reference, (int)tmp );
1234 symbol->GetField( REFERENCE_FIELD )->SetText( reference );
1235 }
1236 else if( strCompare( "F", line, &line ) )
1237 {
1238 int index = parseInt( aReader, line, &line );
1239
1240 wxString text, name;
1241
1242 parseQuotedString( text, aReader, line, &line, true );
1243
1244 char orientation = parseChar( aReader, line, &line );
1245 VECTOR2I pos;
1246 pos.x = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1247 pos.y = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1248 int size = schIUScale.MilsToIU( parseInt( aReader, line, &line ) );
1249 int attributes = parseHex( aReader, line, &line );
1250
1251 if( index >= symbol->GetFieldCount() )
1252 {
1253 // The first MANDATOR_FIELDS _must_ be constructed within the SCH_SYMBOL
1254 // constructor. This assert is simply here to guard against a change in that
1255 // constructor.
1256 wxASSERT( symbol->GetFieldCount() >= MANDATORY_FIELDS );
1257
1258 // Ignore the _supplied_ fieldNdx. It is not important anymore if within the
1259 // user defined fields region (i.e. >= MANDATORY_FIELDS).
1260 // We freely renumber the index to fit the next available field slot.
1261 index = symbol->GetFieldCount(); // new has this index after insertion
1262
1263 SCH_FIELD field( VECTOR2I( 0, 0 ), index, symbol.get(), name );
1264 symbol->AddField( field );
1265 }
1266
1267 SCH_FIELD& field = symbol->GetFields()[index];
1268
1269 // Prior to version 2 of the schematic file format, none of the following existed.
1270 if( m_version > 1 )
1271 {
1272 wxString textAttrs;
1273 char hjustify = parseChar( aReader, line, &line );
1274
1275 parseUnquotedString( textAttrs, aReader, line, &line );
1276
1277 // The name of the field is optional.
1278 parseQuotedString( name, aReader, line, &line, true );
1279
1280 if( hjustify == 'L' )
1282 else if( hjustify == 'R' )
1284 else if( hjustify != 'C' )
1285 SCH_PARSE_ERROR( "symbol field text horizontal justification must be "
1286 "L, R, or C", aReader, line );
1287
1288 // We are guaranteed to have a least one character here for older file formats
1289 // otherwise an exception would have been raised..
1290 if( textAttrs[0] == 'T' )
1292 else if( textAttrs[0] == 'B' )
1294 else if( textAttrs[0] != 'C' )
1295 SCH_PARSE_ERROR( "symbol field text vertical justification must be "
1296 "B, T, or C", aReader, line );
1297
1298 // Newer file formats include the bold and italics text attribute.
1299 if( textAttrs.Length() > 1 )
1300 {
1301 if( textAttrs.Length() != 3 )
1302 {
1303 SCH_PARSE_ERROR( _( "symbol field text attributes must be 3 characters wide" ),
1304 aReader, line );
1305 }
1306
1307 if( textAttrs[1] == 'I' )
1308 {
1309 field.SetItalic( true );
1310 }
1311 else if( textAttrs[1] != 'N' )
1312 {
1313 SCH_PARSE_ERROR( "symbol field text italics indicator must be I or N",
1314 aReader, line );
1315 }
1316
1317 if( textAttrs[2] == 'B' )
1318 {
1319 field.SetBold( true );
1320 }
1321 else if( textAttrs[2] != 'N' )
1322 {
1323 SCH_PARSE_ERROR( "symbol field text bold indicator must be B or N",
1324 aReader, line );
1325 }
1326 }
1327 }
1328
1329 field.SetText( text );
1330 field.SetTextPos( pos );
1331 field.SetVisible( !attributes );
1332 field.SetTextSize( wxSize( size, size ) );
1333
1334 if( orientation == 'H' )
1336 else if( orientation == 'V' )
1338 else
1339 SCH_PARSE_ERROR( "symbol field orientation must be H or V", aReader, line );
1340
1341 if( name.IsEmpty() )
1343
1344 field.SetName( name );
1345 }
1346 else if( strCompare( "$EndComp", line ) )
1347 {
1348 if( !m_appending )
1349 {
1351 {
1353 path.push_back( m_rootSheet->GetScreen()->GetUuid() );
1354
1355 SCH_SYMBOL_INSTANCE instance;
1356 instance.m_Path = path;
1357 instance.m_Reference = symbol->GetField( REFERENCE_FIELD )->GetText();
1358 instance.m_Unit = symbol->GetUnit();
1359 symbol->AddHierarchicalReference( instance );
1360 }
1361 else
1362 {
1363 for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstanceReferences() )
1364 {
1365 SCH_SYMBOL_INSTANCE tmpInstance = instance;
1366 symbol->AddHierarchicalReference( tmpInstance );
1367 }
1368 }
1369 }
1370
1371 // Ensure all flags (some are set by previous initializations) are reset:
1372 symbol->ClearFlags();
1373 return symbol.release();
1374 }
1375 else
1376 {
1377 // There are two lines that begin with a tab or spaces that includes a line with the
1378 // redundant position information and the transform matrix settings.
1379
1380 // Parse the redundant position information just the same to check for formatting
1381 // errors.
1382 parseInt( aReader, line, &line ); // Always 1.
1383 parseInt( aReader, line, &line ); // The X coordinate.
1384 parseInt( aReader, line, &line ); // The Y coordinate.
1385
1386 line = aReader.ReadLine();
1387
1388 TRANSFORM transform;
1389
1390 transform.x1 = parseInt( aReader, line, &line );
1391
1392 if( transform.x1 < -1 || transform.x1 > 1 )
1393 SCH_PARSE_ERROR( "invalid symbol X1 transform value", aReader, line );
1394
1395 transform.y1 = parseInt( aReader, line, &line );
1396
1397 if( transform.y1 < -1 || transform.y1 > 1 )
1398 SCH_PARSE_ERROR( "invalid symbol Y1 transform value", aReader, line );
1399
1400 transform.x2 = parseInt( aReader, line, &line );
1401
1402 if( transform.x2 < -1 || transform.x2 > 1 )
1403 SCH_PARSE_ERROR( "invalid symbol X2 transform value", aReader, line );
1404
1405 transform.y2 = parseInt( aReader, line, &line );
1406
1407 if( transform.y2 < -1 || transform.y2 > 1 )
1408 SCH_PARSE_ERROR( "invalid symbol Y2 transform value", aReader, line );
1409
1410 symbol->SetTransform( transform );
1411 }
1412
1413 line = aReader.ReadLine();
1414 }
1415
1416 SCH_PARSE_ERROR( "invalid symbol line", aReader, line );
1417
1418 return nullptr; // Prevents compiler warning. Should never get here.
1419}
1420
1421
1422std::shared_ptr<BUS_ALIAS> SCH_LEGACY_PLUGIN::loadBusAlias( LINE_READER& aReader,
1423 SCH_SCREEN* aScreen )
1424{
1425 auto busAlias = std::make_shared<BUS_ALIAS>( aScreen );
1426 const char* line = aReader.Line();
1427
1428 wxCHECK( strCompare( "BusAlias", line, &line ), nullptr );
1429
1430 wxString buf;
1431 parseUnquotedString( buf, aReader, line, &line );
1432 busAlias->SetName( buf );
1433
1434 while( *line != '\0' )
1435 {
1436 buf.clear();
1437 parseUnquotedString( buf, aReader, line, &line, true );
1438
1439 if( !buf.IsEmpty() )
1440 busAlias->Members().emplace_back( buf );
1441 }
1442
1443 return busAlias;
1444}
1445
1446
1447void SCH_LEGACY_PLUGIN::Save( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
1448 const STRING_UTF8_MAP* aProperties )
1449{
1450 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET object." );
1451 wxCHECK_RET( !aFileName.IsEmpty(), "No schematic file name defined." );
1452
1453 LOCALE_IO toggle; // toggles on, then off, the C locale, to write floating point values.
1454
1455 init( aSchematic, aProperties );
1456
1457 wxFileName fn = aFileName;
1458
1459 // File names should be absolute. Don't assume everything relative to the project path
1460 // works properly.
1461 wxASSERT( fn.IsAbsolute() );
1462
1463 FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
1464
1465 m_out = &formatter; // no ownership
1466
1467 Format( aSheet );
1468
1469 aSheet->GetScreen()->SetFileExists( true );
1470}
1471
1472
1474{
1475 wxCHECK_RET( aSheet != nullptr, "NULL SCH_SHEET* object." );
1476 wxCHECK_RET( m_schematic != nullptr, "NULL SCHEMATIC* object." );
1477
1478 SCH_SCREEN* screen = aSheet->GetScreen();
1479
1480 wxCHECK( screen, /* void */ );
1481
1482 // Write the header
1483 m_out->Print( 0, "%s %s %d\n", "EESchema", SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION );
1484
1485 // This section is not used, but written for file compatibility
1486 m_out->Print( 0, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 );
1487 m_out->Print( 0, "EELAYER END\n" );
1488
1489 /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
1490 * SheetNumber and Sheet Count in a complex hierarchy, but useful in
1491 * simple hierarchy and flat hierarchy. Used also to search the root
1492 * sheet ( ScreenNumber = 1 ) within the files
1493 */
1494 const TITLE_BLOCK& tb = screen->GetTitleBlock();
1495 const PAGE_INFO& page = screen->GetPageSettings();
1496
1497 m_out->Print( 0, "$Descr %s %d %d%s\n", TO_UTF8( page.GetType() ),
1498 page.GetWidthMils(),
1499 page.GetHeightMils(),
1500 !page.IsCustom() && page.IsPortrait() ? " portrait" : "" );
1501 m_out->Print( 0, "encoding utf-8\n" );
1502 m_out->Print( 0, "Sheet %d %d\n", screen->GetVirtualPageNumber(), screen->GetPageCount() );
1503 m_out->Print( 0, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() );
1504 m_out->Print( 0, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() );
1505 m_out->Print( 0, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() );
1506 m_out->Print( 0, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() );
1507 m_out->Print( 0, "Comment1 %s\n", EscapedUTF8( tb.GetComment( 0 ) ).c_str() );
1508 m_out->Print( 0, "Comment2 %s\n", EscapedUTF8( tb.GetComment( 1 ) ).c_str() );
1509 m_out->Print( 0, "Comment3 %s\n", EscapedUTF8( tb.GetComment( 2 ) ).c_str() );
1510 m_out->Print( 0, "Comment4 %s\n", EscapedUTF8( tb.GetComment( 3 ) ).c_str() );
1511 m_out->Print( 0, "Comment5 %s\n", EscapedUTF8( tb.GetComment( 4 ) ).c_str() );
1512 m_out->Print( 0, "Comment6 %s\n", EscapedUTF8( tb.GetComment( 5 ) ).c_str() );
1513 m_out->Print( 0, "Comment7 %s\n", EscapedUTF8( tb.GetComment( 6 ) ).c_str() );
1514 m_out->Print( 0, "Comment8 %s\n", EscapedUTF8( tb.GetComment( 7 ) ).c_str() );
1515 m_out->Print( 0, "Comment9 %s\n", EscapedUTF8( tb.GetComment( 8 ) ).c_str() );
1516 m_out->Print( 0, "$EndDescr\n" );
1517
1518 for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
1519 saveBusAlias( alias );
1520
1521 // Enforce item ordering
1522 auto cmp = []( const SCH_ITEM* a, const SCH_ITEM* b ) { return *a < *b; };
1523 std::multiset<SCH_ITEM*, decltype( cmp )> save_map( cmp );
1524
1525 for( SCH_ITEM* item : screen->Items() )
1526 save_map.insert( item );
1527
1528
1529 for( auto& item : save_map )
1530 {
1531 switch( item->Type() )
1532 {
1533 case SCH_SYMBOL_T:
1534 saveSymbol( static_cast<SCH_SYMBOL*>( item ) );
1535 break;
1536 case SCH_BITMAP_T:
1537 saveBitmap( static_cast<SCH_BITMAP*>( item ) );
1538 break;
1539 case SCH_SHEET_T:
1540 saveSheet( static_cast<SCH_SHEET*>( item ) );
1541 break;
1542 case SCH_JUNCTION_T:
1543 saveJunction( static_cast<SCH_JUNCTION*>( item ) );
1544 break;
1545 case SCH_NO_CONNECT_T:
1546 saveNoConnect( static_cast<SCH_NO_CONNECT*>( item ) );
1547 break;
1550 saveBusEntry( static_cast<SCH_BUS_ENTRY_BASE*>( item ) );
1551 break;
1552 case SCH_LINE_T:
1553 saveLine( static_cast<SCH_LINE*>( item ) );
1554 break;
1555 case SCH_TEXT_T:
1556 case SCH_LABEL_T:
1557 case SCH_GLOBAL_LABEL_T:
1558 case SCH_HIER_LABEL_T:
1559 saveText( static_cast<SCH_TEXT*>( item ) );
1560 break;
1561 default:
1562 wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1563 }
1564 }
1565
1566 m_out->Print( 0, "$EndSCHEMATC\n" );
1567}
1568
1569
1571{
1572 m_out = aFormatter;
1573
1574 for( unsigned i = 0; i < aSelection->GetSize(); ++i )
1575 {
1576 SCH_ITEM* item = (SCH_ITEM*) aSelection->GetItem( i );
1577
1578 switch( item->Type() )
1579 {
1580 case SCH_SYMBOL_T:
1581 saveSymbol( static_cast< SCH_SYMBOL* >( item ) );
1582 break;
1583 case SCH_BITMAP_T:
1584 saveBitmap( static_cast< SCH_BITMAP* >( item ) );
1585 break;
1586 case SCH_SHEET_T:
1587 saveSheet( static_cast< SCH_SHEET* >( item ) );
1588 break;
1589 case SCH_JUNCTION_T:
1590 saveJunction( static_cast< SCH_JUNCTION* >( item ) );
1591 break;
1592 case SCH_NO_CONNECT_T:
1593 saveNoConnect( static_cast< SCH_NO_CONNECT* >( item ) );
1594 break;
1597 saveBusEntry( static_cast< SCH_BUS_ENTRY_BASE* >( item ) );
1598 break;
1599 case SCH_LINE_T:
1600 saveLine( static_cast< SCH_LINE* >( item ) );
1601 break;
1602 case SCH_TEXT_T:
1603 case SCH_LABEL_T:
1604 case SCH_GLOBAL_LABEL_T:
1605 case SCH_HIER_LABEL_T:
1606 saveText( static_cast< SCH_TEXT* >( item ) );
1607 break;
1608 default:
1609 wxASSERT( "Unexpected schematic object type in SCH_LEGACY_PLUGIN::Format()" );
1610 }
1611 }
1612}
1613
1614
1616{
1617 std::string name1;
1618 std::string name2;
1619
1620 static wxString delimiters( wxT( " " ) );
1621
1622 // This is redundant with the AR entries below, but it makes the files backwards-compatible.
1623 if( aSymbol->GetInstanceReferences().size() > 0 )
1624 {
1625 const SCH_SYMBOL_INSTANCE& instance = aSymbol->GetInstanceReferences()[0];
1626 name1 = toUTFTildaText( instance.m_Reference );
1627 }
1628 else
1629 {
1630 if( aSymbol->GetField( REFERENCE_FIELD )->GetText().IsEmpty() )
1631 name1 = toUTFTildaText( aSymbol->GetPrefix() );
1632 else
1633 name1 = toUTFTildaText( aSymbol->GetField( REFERENCE_FIELD )->GetText() );
1634 }
1635
1636 wxString symbol_name = aSymbol->GetLibId().Format();
1637
1638 if( symbol_name.size() )
1639 {
1640 name2 = toUTFTildaText( symbol_name );
1641 }
1642 else
1643 {
1644 name2 = "_NONAME_";
1645 }
1646
1647 m_out->Print( 0, "$Comp\n" );
1648 m_out->Print( 0, "L %s %s\n", name2.c_str(), name1.c_str() );
1649
1650 // Generate unit number, conversion and timestamp
1651 m_out->Print( 0, "U %d %d %8.8X\n",
1652 aSymbol->GetUnit(),
1653 aSymbol->GetConvert(),
1654 aSymbol->m_Uuid.AsLegacyTimestamp() );
1655
1656 // Save the position
1657 m_out->Print( 0, "P %d %d\n",
1658 schIUScale.IUToMils( aSymbol->GetPosition().x ),
1659 schIUScale.IUToMils( aSymbol->GetPosition().y ) );
1660
1661 /* If this is a complex hierarchy; save hierarchical references.
1662 * but for simple hierarchies it is not necessary.
1663 * the reference inf is already saved
1664 * this is useful for old Eeschema version compatibility
1665 */
1666 if( aSymbol->GetInstanceReferences().size() > 1 )
1667 {
1668 for( const SCH_SYMBOL_INSTANCE& instance : aSymbol->GetInstanceReferences() )
1669 {
1670 /*format:
1671 * AR Path="/140/2" Ref="C99" Part="1"
1672 * where 140 is the uid of the containing sheet and 2 is the timestamp of this symbol.
1673 * (timestamps are actually 8 hex chars)
1674 * Ref is the conventional symbol reference designator for this 'path'
1675 * Part is the conventional symbol unit selection for this 'path'
1676 */
1677 wxString path = "/";
1678
1679 // Skip root sheet
1680 for( int i = 1; i < (int) instance.m_Path.size(); ++i )
1681 path += instance.m_Path[i].AsLegacyTimestampString() + "/";
1682
1683 m_out->Print( 0, "AR Path=\"%s\" Ref=\"%s\" Part=\"%d\" \n",
1685 TO_UTF8( instance.m_Reference ),
1686 instance.m_Unit );
1687 }
1688 }
1689
1690 // update the ugly field id, which I would like to see go away someday soon.
1691 for( int i = 0; i < aSymbol->GetFieldCount(); ++i )
1692 aSymbol->GetFields()[i].SetId( i );
1693
1694 // Fixed fields:
1695 // Save mandatory fields even if they are blank,
1696 // because the visibility, size and orientation are set from library editor.
1697 for( unsigned i = 0; i < MANDATORY_FIELDS; ++i )
1698 saveField( &aSymbol->GetFields()[i] );
1699
1700 // User defined fields:
1701 // The *policy* about which user defined fields are symbol of a symbol is now
1702 // only in the dialog editors. No policy should be enforced here, simply
1703 // save all the user defined fields, they are present because a dialog editor
1704 // thought they should be. If you disagree, go fix the dialog editors.
1705 for( int i = MANDATORY_FIELDS; i < aSymbol->GetFieldCount(); ++i )
1706 saveField( &aSymbol->GetFields()[i] );
1707
1708 // Unit number, position, box ( old standard )
1709 m_out->Print( 0, "\t%-4d %-4d %-4d\n", aSymbol->GetUnit(),
1710 schIUScale.IUToMils( aSymbol->GetPosition().x ),
1711 schIUScale.IUToMils( aSymbol->GetPosition().y ) );
1712
1713 TRANSFORM transform = aSymbol->GetTransform();
1714
1715 m_out->Print( 0, "\t%-4d %-4d %-4d %-4d\n",
1716 transform.x1, transform.y1, transform.x2, transform.y2 );
1717 m_out->Print( 0, "$EndComp\n" );
1718}
1719
1720
1722{
1723 char hjustify = 'C';
1724
1725 if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
1726 hjustify = 'L';
1727 else if( aField->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
1728 hjustify = 'R';
1729
1730 char vjustify = 'C';
1731
1732 if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_BOTTOM )
1733 vjustify = 'B';
1734 else if( aField->GetVertJustify() == GR_TEXT_V_ALIGN_TOP )
1735 vjustify = 'T';
1736
1737 m_out->Print( 0, "F %d %s %c %-3d %-3d %-3d %4.4X %c %c%c%c",
1738 aField->GetId(),
1739 EscapedUTF8( aField->GetText() ).c_str(), // wraps in quotes too
1740 aField->GetTextAngle().IsHorizontal() ? 'H' : 'V',
1741 schIUScale.IUToMils( aField->GetLibPosition().x ),
1742 schIUScale.IUToMils( aField->GetLibPosition().y ),
1743 schIUScale.IUToMils( aField->GetTextWidth() ),
1744 !aField->IsVisible(),
1745 hjustify, vjustify,
1746 aField->IsItalic() ? 'I' : 'N',
1747 aField->IsBold() ? 'B' : 'N' );
1748
1749 // Save field name, if the name is user definable
1750 if( aField->GetId() >= MANDATORY_FIELDS )
1751 m_out->Print( 0, " %s", EscapedUTF8( aField->GetName() ).c_str() );
1752
1753 m_out->Print( 0, "\n" );
1754}
1755
1756
1758{
1759 wxCHECK_RET( aBitmap != nullptr, "SCH_BITMAP* is NULL" );
1760
1761 const wxImage* image = aBitmap->GetImage()->GetImageData();
1762
1763 wxCHECK_RET( image != nullptr, "wxImage* is NULL" );
1764
1765 m_out->Print( 0, "$Bitmap\n" );
1766 m_out->Print( 0, "Pos %-4d %-4d\n",
1767 schIUScale.IUToMils( aBitmap->GetPosition().x ),
1768 schIUScale.IUToMils( aBitmap->GetPosition().y ) );
1769 m_out->Print( 0, "Scale %f\n", aBitmap->GetImage()->GetScale() );
1770 m_out->Print( 0, "Data\n" );
1771
1772 wxMemoryOutputStream stream;
1773
1774 image->SaveFile( stream, wxBITMAP_TYPE_PNG );
1775
1776 // Write binary data in hexadecimal form (ASCII)
1777 wxStreamBuffer* buffer = stream.GetOutputStreamBuffer();
1778 char* begin = (char*) buffer->GetBufferStart();
1779
1780 for( int ii = 0; begin < buffer->GetBufferEnd(); begin++, ii++ )
1781 {
1782 if( ii >= 32 )
1783 {
1784 ii = 0;
1785
1786 m_out->Print( 0, "\n" );
1787 }
1788
1789 m_out->Print( 0, "%2.2X ", *begin & 0xFF );
1790 }
1791
1792 m_out->Print( 0, "\nEndData\n" );
1793 m_out->Print( 0, "$EndBitmap\n" );
1794}
1795
1796
1798{
1799 wxCHECK_RET( aSheet != nullptr, "SCH_SHEET* is NULL" );
1800
1801 m_out->Print( 0, "$Sheet\n" );
1802 m_out->Print( 0, "S %-4d %-4d %-4d %-4d\n",
1803 schIUScale.IUToMils( aSheet->GetPosition().x ),
1804 schIUScale.IUToMils( aSheet->GetPosition().y ),
1805 schIUScale.IUToMils( aSheet->GetSize().x ),
1806 schIUScale.IUToMils( aSheet->GetSize().y ) );
1807
1808 m_out->Print( 0, "U %8.8X\n", aSheet->m_Uuid.AsLegacyTimestamp() );
1809
1810 SCH_FIELD& sheetName = aSheet->GetFields()[SHEETNAME];
1811 SCH_FIELD& fileName = aSheet->GetFields()[SHEETFILENAME];
1812
1813 if( !sheetName.GetText().IsEmpty() )
1814 {
1815 m_out->Print( 0, "F0 %s %d\n",
1816 EscapedUTF8( sheetName.GetText() ).c_str(),
1817 schIUScale.IUToMils( sheetName.GetTextSize().x ) );
1818 }
1819
1820 if( !fileName.GetText().IsEmpty() )
1821 {
1822 m_out->Print( 0, "F1 %s %d\n",
1823 EscapedUTF8( fileName.GetText() ).c_str(),
1824 schIUScale.IUToMils( fileName.GetTextSize().x ) );
1825 }
1826
1827 for( const SCH_SHEET_PIN* pin : aSheet->GetPins() )
1828 {
1829 int type, side;
1830
1831 if( pin->GetText().IsEmpty() )
1832 break;
1833
1834 switch( pin->GetSide() )
1835 {
1836 default:
1837 case SHEET_SIDE::LEFT: side = 'L'; break;
1838 case SHEET_SIDE::RIGHT: side = 'R'; break;
1839 case SHEET_SIDE::TOP: side = 'T'; break;
1840 case SHEET_SIDE::BOTTOM: side = 'B'; break;
1841 }
1842
1843 switch( pin->GetShape() )
1844 {
1845 default:
1846 case LABEL_FLAG_SHAPE::L_UNSPECIFIED: type = 'U'; break;
1847 case LABEL_FLAG_SHAPE::L_INPUT: type = 'I'; break;
1848 case LABEL_FLAG_SHAPE::L_OUTPUT: type = 'O'; break;
1849 case LABEL_FLAG_SHAPE::L_BIDI: type = 'B'; break;
1850 case LABEL_FLAG_SHAPE::L_TRISTATE: type = 'T'; break;
1851 }
1852
1853 m_out->Print( 0, "F%d %s %c %c %-3d %-3d %-3d\n",
1854 pin->GetNumber(),
1855 EscapedUTF8( pin->GetText() ).c_str(), // supplies wrapping quotes
1856 type, side, schIUScale.IUToMils( pin->GetPosition().x ),
1857 schIUScale.IUToMils( pin->GetPosition().y ),
1858 schIUScale.IUToMils( pin->GetTextWidth() ) );
1859 }
1860
1861 m_out->Print( 0, "$EndSheet\n" );
1862}
1863
1864
1866{
1867 wxCHECK_RET( aJunction != nullptr, "SCH_JUNCTION* is NULL" );
1868
1869 m_out->Print( 0, "Connection ~ %-4d %-4d\n",
1870 schIUScale.IUToMils( aJunction->GetPosition().x ),
1871 schIUScale.IUToMils( aJunction->GetPosition().y ) );
1872}
1873
1874
1876{
1877 wxCHECK_RET( aNoConnect != nullptr, "SCH_NOCONNECT* is NULL" );
1878
1879 m_out->Print( 0, "NoConn ~ %-4d %-4d\n",
1880 schIUScale.IUToMils( aNoConnect->GetPosition().x ),
1881 schIUScale.IUToMils( aNoConnect->GetPosition().y ) );
1882}
1883
1884
1886{
1887 wxCHECK_RET( aBusEntry != nullptr, "SCH_BUS_ENTRY_BASE* is NULL" );
1888
1889 if( aBusEntry->GetLayer() == LAYER_WIRE )
1890 {
1891 m_out->Print( 0, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
1892 schIUScale.IUToMils( aBusEntry->GetPosition().x ),
1893 schIUScale.IUToMils( aBusEntry->GetPosition().y ),
1894 schIUScale.IUToMils( aBusEntry->GetEnd().x ),
1895 schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
1896 }
1897 else
1898 {
1899 m_out->Print( 0, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
1900 schIUScale.IUToMils( aBusEntry->GetPosition().x ),
1901 schIUScale.IUToMils( aBusEntry->GetPosition().y ),
1902 schIUScale.IUToMils( aBusEntry->GetEnd().x ),
1903 schIUScale.IUToMils( aBusEntry->GetEnd().y ) );
1904 }
1905}
1906
1907
1909{
1910 wxCHECK_RET( aLine != nullptr, "SCH_LINE* is NULL" );
1911
1912 const char* layer = "Notes";
1913 const char* width = "Line";
1914
1915 if( aLine->GetLayer() == LAYER_WIRE )
1916 layer = "Wire";
1917 else if( aLine->GetLayer() == LAYER_BUS )
1918 layer = "Bus";
1919
1920 m_out->Print( 0, "Wire %s %s", layer, width );
1921
1922 // Write line style (width, type, color) only for non default values
1923 if( aLine->IsGraphicLine() )
1924 {
1925 if( aLine->GetLineSize() != 0 )
1926 m_out->Print( 0, " %s %d", T_WIDTH, schIUScale.IUToMils( aLine->GetLineSize() ) );
1927
1928 m_out->Print( 0, " %s %s", T_STYLE,
1930
1931 if( aLine->GetLineColor() != COLOR4D::UNSPECIFIED )
1932 {
1933 m_out->Print( 0, " %s",
1934 TO_UTF8( aLine->GetLineColor().ToCSSString() ) );
1935 }
1936 }
1937
1938 m_out->Print( 0, "\n" );
1939
1940 m_out->Print( 0, "\t%-4d %-4d %-4d %-4d",
1941 schIUScale.IUToMils( aLine->GetStartPoint().x ),
1942 schIUScale.IUToMils( aLine->GetStartPoint().y ),
1943 schIUScale.IUToMils( aLine->GetEndPoint().x ),
1944 schIUScale.IUToMils( aLine->GetEndPoint().y ) );
1945
1946 m_out->Print( 0, "\n");
1947}
1948
1949
1951{
1952 wxCHECK_RET( aText != nullptr, "SCH_TEXT* is NULL" );
1953
1954 const char* italics = "~";
1955 const char* textType = "Notes";
1956
1957 if( aText->IsItalic() )
1958 italics = "Italic";
1959
1960 wxString text = aText->GetText();
1961
1962 SCH_LAYER_ID layer = aText->GetLayer();
1963
1964 if( layer == LAYER_NOTES || layer == LAYER_LOCLABEL )
1965 {
1966 if( layer == LAYER_NOTES )
1967 {
1968 // For compatibility reasons, the text must be saved in only one text line
1969 // so replace all EOLs with \\n
1970 text.Replace( wxT( "\n" ), wxT( "\\n" ) );
1971
1972 // Here we should have no CR or LF character in line
1973 // This is not always the case if a multiline text was copied (using a copy/paste
1974 // function) from a text that uses E.O.L characters that differs from the current
1975 // EOL format. This is mainly the case under Linux using LF symbol when copying
1976 // a text from Windows (using CRLF symbol) so we must just remove the extra CR left
1977 // (or LF left under MacOSX)
1978 for( unsigned ii = 0; ii < text.Len(); )
1979 {
1980 if( text[ii] == 0x0A || text[ii] == 0x0D )
1981 text.erase( ii, 1 );
1982 else
1983 ii++;
1984 }
1985 }
1986 else
1987 {
1988 textType = "Label";
1989 }
1990
1991 // Local labels must have their spin style inverted for left and right
1992 int spinStyle = static_cast<int>( aText->GetTextSpinStyle() );
1993
1994 if( spinStyle == 0 )
1995 spinStyle = 2;
1996 else if( spinStyle == 2 )
1997 spinStyle = 0;
1998
1999 m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %d\n%s\n", textType,
2000 schIUScale.IUToMils( aText->GetPosition().x ),
2001 schIUScale.IUToMils( aText->GetPosition().y ),
2002 spinStyle,
2003 schIUScale.IUToMils( aText->GetTextWidth() ),
2004 italics, schIUScale.IUToMils( aText->GetTextThickness() ), TO_UTF8( text ) );
2005 }
2006 else if( layer == LAYER_GLOBLABEL || layer == LAYER_HIERLABEL )
2007 {
2008 textType = ( layer == LAYER_GLOBLABEL ) ? "GLabel" : "HLabel";
2009
2010 auto shapeLabelIt = sheetLabelNames.find( aText->GetShape() );
2011 wxCHECK_RET( shapeLabelIt != sheetLabelNames.end(), "Shape not found in names list" );
2012
2013 m_out->Print( 0, "Text %s %-4d %-4d %-4d %-4d %s %s %d\n%s\n", textType,
2014 schIUScale.IUToMils( aText->GetPosition().x ),
2015 schIUScale.IUToMils( aText->GetPosition().y ),
2016 static_cast<int>( aText->GetTextSpinStyle() ),
2017 schIUScale.IUToMils( aText->GetTextWidth() ),
2018 shapeLabelIt->second,
2019 italics,
2021 }
2022}
2023
2024
2025void SCH_LEGACY_PLUGIN::saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias )
2026{
2027 wxCHECK_RET( aAlias != nullptr, "BUS_ALIAS* is NULL" );
2028
2029 wxString members = boost::algorithm::join( aAlias->Members(), " " );
2030
2031 m_out->Print( 0, "BusAlias %s %s\n",
2032 TO_UTF8( aAlias->GetName() ), TO_UTF8( members ) );
2033}
2034
2035
2036void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties )
2037{
2038 if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
2039 {
2040 // a spectacular episode in memory management:
2041 delete m_cache;
2042 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
2043
2044 if( !isBuffering( aProperties ) )
2045 m_cache->Load();
2046 }
2047}
2048
2049
2051{
2052 std::string propName( SCH_LEGACY_PLUGIN::PropNoDocFile );
2053
2054 if( aProperties && aProperties->find( propName ) != aProperties->end() )
2055 return false;
2056
2057 return true;
2058}
2059
2060
2062{
2063 return ( aProperties && aProperties->Exists( SCH_LEGACY_PLUGIN::PropBuffering ) );
2064}
2065
2066
2068{
2069 if( m_cache )
2070 return m_cache->GetModifyHash();
2071
2072 // If the cache hasn't been loaded, it hasn't been modified.
2073 return 0;
2074}
2075
2076
2077void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
2078 const wxString& aLibraryPath,
2079 const STRING_UTF8_MAP* aProperties )
2080{
2081 LOCALE_IO toggle; // toggles on, then off, the C locale.
2082
2083 bool powerSymbolsOnly = ( aProperties &&
2084 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2085
2086 cacheLib( aLibraryPath, aProperties );
2087
2088 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2089
2090 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2091 {
2092 if( !powerSymbolsOnly || it->second->IsPower() )
2093 aSymbolNameList.Add( it->first );
2094 }
2095}
2096
2097
2098void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
2099 const wxString& aLibraryPath,
2100 const STRING_UTF8_MAP* aProperties )
2101{
2102 LOCALE_IO toggle; // toggles on, then off, the C locale.
2103
2104 bool powerSymbolsOnly = ( aProperties &&
2105 aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
2106
2107 cacheLib( aLibraryPath, aProperties );
2108
2109 const LIB_SYMBOL_MAP& symbols = m_cache->m_symbols;
2110
2111 for( LIB_SYMBOL_MAP::const_iterator it = symbols.begin(); it != symbols.end(); ++it )
2112 {
2113 if( !powerSymbolsOnly || it->second->IsPower() )
2114 aSymbolList.push_back( it->second );
2115 }
2116}
2117
2118
2119LIB_SYMBOL* SCH_LEGACY_PLUGIN::LoadSymbol( const wxString& aLibraryPath,
2120 const wxString& aSymbolName,
2121 const STRING_UTF8_MAP* aProperties )
2122{
2123 LOCALE_IO toggle; // toggles on, then off, the C locale.
2124
2125 cacheLib( aLibraryPath, aProperties );
2126
2127 LIB_SYMBOL_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
2128
2129 if( it == m_cache->m_symbols.end() )
2130 return nullptr;
2131
2132 return it->second;
2133}
2134
2135
2136void SCH_LEGACY_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
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 m_cache->AddSymbol( aSymbol );
2144
2145 if( !isBuffering( aProperties ) )
2146 m_cache->Save( writeDocFile( aProperties ) );
2147}
2148
2149
2150void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
2151 const STRING_UTF8_MAP* aProperties )
2152{
2153 LOCALE_IO toggle; // toggles on, then off, the C locale.
2154
2155 cacheLib( aLibraryPath, aProperties );
2156
2157 m_cache->DeleteSymbol( aSymbolName );
2158
2159 if( !isBuffering( aProperties ) )
2160 m_cache->Save( writeDocFile( aProperties ) );
2161}
2162
2163
2164void SCH_LEGACY_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
2165 const STRING_UTF8_MAP* aProperties )
2166{
2167 if( wxFileExists( aLibraryPath ) )
2168 {
2169 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' already exists." ),
2170 aLibraryPath.GetData() ) );
2171 }
2172
2173 LOCALE_IO toggle;
2174
2175 delete m_cache;
2176 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
2178 m_cache->Save( writeDocFile( aProperties ) );
2179 m_cache->Load(); // update m_writable and m_mod_time
2180}
2181
2182
2183bool SCH_LEGACY_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath,
2184 const STRING_UTF8_MAP* aProperties )
2185{
2186 wxFileName fn = aLibraryPath;
2187
2188 if( !fn.FileExists() )
2189 return false;
2190
2191 // Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
2192 // we don't want that. we want bare metal portability with no UI here.
2193 if( wxRemove( aLibraryPath ) )
2194 {
2195 THROW_IO_ERROR( wxString::Format( _( "Symbol library '%s' cannot be deleted." ),
2196 aLibraryPath.GetData() ) );
2197 }
2198
2199 if( m_cache && m_cache->IsFile( aLibraryPath ) )
2200 {
2201 delete m_cache;
2202 m_cache = nullptr;
2203 }
2204
2205 return true;
2206}
2207
2208
2209void SCH_LEGACY_PLUGIN::SaveLibrary( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
2210{
2211 if( !m_cache )
2212 m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
2213
2214 wxString oldFileName = m_cache->GetFileName();
2215
2216 if( !m_cache->IsFile( aLibraryPath ) )
2217 {
2218 m_cache->SetFileName( aLibraryPath );
2219 }
2220
2221 // This is a forced save.
2223 m_cache->Save( writeDocFile( aProperties ) );
2224 m_cache->SetFileName( oldFileName );
2225}
2226
2227
2228bool SCH_LEGACY_PLUGIN::CheckHeader( const wxString& aFileName )
2229{
2230 // Open file and check first line
2231 wxTextFile tempFile;
2232
2233 tempFile.Open( aFileName );
2234 wxString firstline;
2235 // read the first line
2236 firstline = tempFile.GetFirstLine();
2237 tempFile.Close();
2238
2239 return firstline.StartsWith( wxS( "EESchema" ) );
2240}
2241
2242
2243bool SCH_LEGACY_PLUGIN::IsSymbolLibWritable( const wxString& aLibraryPath )
2244{
2245 // Writing legacy symbol libraries is deprecated.
2246 return false;
2247}
2248
2249
2251 int aMinorVersion )
2252{
2253 return SCH_LEGACY_PLUGIN_CACHE::LoadPart( reader, aMajorVersion, aMinorVersion );
2254}
2255
2256
2258{
2259 SCH_LEGACY_PLUGIN_CACHE::SaveSymbol( symbol, formatter );
2260}
2261
2262
2263
2264const char* SCH_LEGACY_PLUGIN::PropBuffering = "buffering";
2265const 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
double GetScale() const
Definition: bitmap_base.h:78
wxImage * GetImageData()
Definition: bitmap_base.h:71
bool IsHorizontal() const
Definition: eda_angle.h:174
const KIID m_Uuid
Definition: eda_item.h:492
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:130
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:120
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
virtual bool IsVisible() const
Definition: eda_text.h:136
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:371
int GetTextWidth() const
Definition: eda_text.h:199
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:248
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:149
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:217
void SetBold(bool aBold)
Definition: eda_text.cpp:209
bool IsBold() const
Definition: eda_text.h:133
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:152
void SetTextSize(const VECTOR2I &aNewSize)
Definition: eda_text.cpp:347
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:193
int GetTextThickness() const
Definition: eda_text.h:112
void SetItalic(bool aItalic)
Definition: eda_text.cpp:201
VECTOR2I GetTextSize() const
Definition: eda_text.h:196
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:240
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
A LINE_READER that reads from an open file.
Definition: richio.h:173
void Rewind()
Rewind the file and resets the line number back to zero.
Definition: richio.h:222
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition: richio.cpp:219
Used for text file output.
Definition: richio.h:457
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
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:81
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:109
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
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:310
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:433
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:244
void SetPortrait(bool aIsPortrait)
Rotate the paper page 90 degrees.
Definition: page_info.cpp:187
static const wxChar Custom[]
"User" defined page type
Definition: page_info.h:77
void SetHeightMils(int aHeightInMils)
Definition: page_info.cpp:258
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:181
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:120
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:61
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition: schematic.h:107
SCH_SHEET & Root() const
Definition: schematic.h:91
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:76
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:136
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:226
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:813
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:246
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:263
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:931
COLOR4D GetLineColor() const
Returns COLOR4D::UNSPECIFIED if a custom color hasn't been set for this line.
Definition: sch_line.cpp:237
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:145
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:110
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:302
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:723
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:106
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:368
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
wxSize GetSize() const
Definition: sch_sheet.h:108
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:175
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:486
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:843
int GetConvert() const
Definition: sch_symbol.h:270
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:712
TRANSFORM & GetTransform()
Definition: sch_symbol.h:283
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:879
wxString GetPrefix() const
Definition: sch_symbol.h:274
VECTOR2I GetPosition() const override
Definition: sch_text.h:203
TEXT_SPIN_STYLE GetTextSpinStyle() const
Definition: sch_text.h:148
virtual LABEL_FLAG_SHAPE GetShape() const
Definition: sch_text.h:150
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:47
int x2
Definition: transform.h:51
int y1
Definition: transform.h:50
int y2
Definition: transform.h:52
int x1
Definition: transform.h:49
#define _(s)
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:419
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:420
#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:391
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:341
@ LAYER_HIERLABEL
Definition: layer_ids.h:349
@ LAYER_GLOBLABEL
Definition: layer_ids.h:348
@ LAYER_WIRE
Definition: layer_ids.h:344
@ LAYER_NOTES
Definition: layer_ids.h:358
@ LAYER_BUS
Definition: layer_ids.h:345
@ LAYER_LOCLABEL
Definition: layer_ids.h:347
#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
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
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:51
@ 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: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:618
Definition of file extensions used in Kicad.