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