KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_eagle.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) 2017 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Alejandro GarcĂ­a Montoro <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 * @author Russell Oliver <[email protected]>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 3
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
26
27#include <algorithm>
28#include <memory>
29#include <fmt/format.h>
30#include <wx/filename.h>
31#include <wx/string.h>
32#include <wx/tokenzr.h>
33#include <wx/wfstream.h>
34#include <wx/txtstrm.h>
35#include <wx/mstream.h>
36#include <wx/xml/xml.h>
37
38#include <advanced_config.h>
39#include <font/fontconfig.h>
40#include <reporter.h>
43#include <lib_id.h>
44#include <progress_reporter.h>
45#include <project.h>
47#include <project_sch.h>
48#include <sch_bus_entry.h>
49#include <sch_edit_frame.h>
51#include <sch_junction.h>
52#include <sch_label.h>
53#include <sch_marker.h>
54#include <sch_pin.h>
55#include <sch_screen.h>
56#include <sch_shape.h>
57#include <sch_sheet.h>
58#include <sch_sheet_path.h>
59#include <sch_sheet_pin.h>
60#include <sch_symbol.h>
61#include <schematic.h>
62#include <string_utils.h>
65
66
67// Eagle schematic axes are aligned with x increasing left to right and Y increasing bottom to top
68// KiCad schematic axes are aligned with x increasing left to right and Y increasing top to bottom.
69
70using namespace std;
71
75static const std::map<wxString, ELECTRICAL_PINTYPE> pinDirectionsMap = {
76 { wxT( "sup" ), ELECTRICAL_PINTYPE::PT_POWER_IN },
77 { wxT( "pas" ), ELECTRICAL_PINTYPE::PT_PASSIVE },
78 { wxT( "out" ), ELECTRICAL_PINTYPE::PT_OUTPUT },
79 { wxT( "in" ), ELECTRICAL_PINTYPE::PT_INPUT },
80 { wxT( "nc" ), ELECTRICAL_PINTYPE::PT_NC },
81 { wxT( "io" ), ELECTRICAL_PINTYPE::PT_BIDI },
83 { wxT( "hiz" ), ELECTRICAL_PINTYPE::PT_TRISTATE },
84 { wxT( "pwr" ), ELECTRICAL_PINTYPE::PT_POWER_IN },
85};
86
87
89static BOX2I getSheetBbox( SCH_SHEET* aSheet )
90{
91 BOX2I bbox;
92
93 for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
94 bbox.Merge( item->GetBoundingBox() );
95
96 return bbox;
97}
98
99
101static inline wxString extractNetName( const wxString& aPinName )
102{
103 return aPinName.BeforeFirst( '@' );
104}
105
106
111
112
114{
115 SCH_SHEET* currentSheet = m_sheetPath.Last();
116 wxCHECK( currentSheet, nullptr );
117 return currentSheet->GetScreen();
118}
119
120
122{
123 if( m_libName.IsEmpty() )
124 {
125 // Try to come up with a meaningful name
126 m_libName = m_schematic->Project().GetProjectName();
127
128 if( m_libName.IsEmpty() )
129 {
130 wxFileName fn( m_rootSheet->GetFileName() );
131 m_libName = fn.GetName();
132 }
133
134 if( m_libName.IsEmpty() )
135 m_libName = wxT( "noname" );
136
137 m_libName += wxT( "-eagle-import" );
139 }
140
141 return m_libName;
142}
143
144
146{
147 wxFileName fn;
148
149 wxCHECK( m_schematic, fn );
150
151 fn.Assign( m_schematic->Project().GetProjectPath(), getLibName(),
153
154 return fn;
155}
156
157
158void SCH_IO_EAGLE::loadLayerDefs( const std::vector<std::unique_ptr<ELAYER>>& aLayers )
159{
160 // match layers based on their names
161 for( const std::unique_ptr<ELAYER>& elayer : aLayers )
162 {
179
180 switch ( elayer->number)
181 {
182 case 91:
183 m_layerMap[elayer->number] = LAYER_WIRE;
184 break;
185 case 92:
186 m_layerMap[elayer->number] = LAYER_BUS;
187 break;
188 case 97:
189 case 98:
190 m_layerMap[elayer->number] = LAYER_NOTES;
191 break;
192
193 default:
194 break;
195 }
196 }
197}
198
199
201{
202 auto it = m_layerMap.find( aEagleLayer );
203 return it == m_layerMap.end() ? LAYER_NOTES : it->second;
204}
205
206
207// Return the KiCad symbol orientation based on eagle rotation degrees.
209{
210 int roti = int( eagleDegrees );
211
212 switch( roti )
213 {
214 case 0: return SYM_ORIENT_0;
215 case 90: return SYM_ORIENT_90;
216 case 180: return SYM_ORIENT_180;
217 case 270: return SYM_ORIENT_270;
218
219 default:
220 wxASSERT_MSG( false, wxString::Format( wxT( "Unhandled orientation (%d degrees)" ),
221 roti ) );
222 return SYM_ORIENT_0;
223 }
224}
225
226
227// Calculate text alignment based on the given Eagle text alignment parameters.
228static void eagleToKicadAlignment( EDA_TEXT* aText, int aEagleAlignment, int aRelDegress,
229 bool aMirror, bool aSpin, int aAbsDegress )
230{
231 int align = aEagleAlignment;
232
233 if( aRelDegress == 90 )
234 {
236 }
237 else if( aRelDegress == 180 )
238 {
239 align = -align;
240 }
241 else if( aRelDegress == 270 )
242 {
244 align = -align;
245 }
246
247 if( aMirror == true )
248 {
249 if( aAbsDegress == 90 || aAbsDegress == 270 )
250 {
251 if( align == ETEXT::BOTTOM_RIGHT )
252 align = ETEXT::TOP_RIGHT;
253 else if( align == ETEXT::BOTTOM_LEFT )
254 align = ETEXT::TOP_LEFT;
255 else if( align == ETEXT::TOP_LEFT )
256 align = ETEXT::BOTTOM_LEFT;
257 else if( align == ETEXT::TOP_RIGHT )
258 align = ETEXT::BOTTOM_RIGHT;
259 }
260 else if( aAbsDegress == 0 || aAbsDegress == 180 )
261 {
262 if( align == ETEXT::BOTTOM_RIGHT )
263 align = ETEXT::BOTTOM_LEFT;
264 else if( align == ETEXT::BOTTOM_LEFT )
265 align = ETEXT::BOTTOM_RIGHT;
266 else if( align == ETEXT::TOP_LEFT )
267 align = ETEXT::TOP_RIGHT;
268 else if( align == ETEXT::TOP_RIGHT )
269 align = ETEXT::TOP_LEFT;
270 else if( align == ETEXT::CENTER_LEFT )
271 align = ETEXT::CENTER_RIGHT;
272 else if( align == ETEXT::CENTER_RIGHT )
273 align = ETEXT::CENTER_LEFT;
274 }
275 }
276
277 switch( align )
278 {
279 case ETEXT::CENTER:
282 break;
283
287 break;
288
292 break;
293
297 break;
298
299 case ETEXT::TOP_LEFT:
302 break;
303
304 case ETEXT::TOP_RIGHT:
307 break;
308
312 break;
313
317 break;
318
322 break;
323
324 default:
327 break;
328 }
329}
330
331
332SCH_IO_EAGLE::SCH_IO_EAGLE() : SCH_IO( wxS( "EAGLE" ) ),
333 m_rootSheet( nullptr ),
334 m_schematic( nullptr ),
335 m_sheetIndex( 1 )
336{
337}
338
339
343
344
346{
347 return 0;
348}
349
350
351SCH_SHEET* SCH_IO_EAGLE::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
352 SCH_SHEET* aAppendToMe,
353 const std::map<std::string, UTF8>* aProperties )
354{
355 wxASSERT( !aFileName || aSchematic != nullptr );
356
357 // Collect the font substitution warnings (RAII - automatically reset on scope exit)
359
360 m_filename = aFileName;
361 m_schematic = aSchematic;
362
364 {
365 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) );
366
367 if( !m_progressReporter->KeepRefreshing() )
369 }
370
371 // Load the document
372 wxXmlDocument xmlDocument = loadXmlDocument( m_filename.GetFullPath() );
373
374 // Retrieve the root as current node
375 wxXmlNode* currentNode = xmlDocument.GetRoot();
376
378 m_progressReporter->SetNumPhases( static_cast<int>( GetNodeCount( currentNode ) ) );
379
380 wxFileName newFilename( m_filename );
381 newFilename.SetExt( FILEEXT::KiCadSchematicFileExtension );
382
383 // Owns the temporary VR for the non-append path so it is freed when this scope exits.
384 // The actual schematic VR will be created by SetTopLevelSheets() inside loadSchematic().
385 unique_ptr<SCH_SHEET> tempVROwner;
386
387 if( aAppendToMe )
388 {
389 wxCHECK_MSG( aSchematic->IsValid(), nullptr,
390 wxT( "Can't append to a schematic with no root!" ) );
391
392 m_rootSheet = &aSchematic->Root();
393
394 // We really should be passing the SCH_SHEET_PATH object to the aAppendToMe attribute
395 // instead of the SCH_SHEET. The full path is needed to properly generate instance
396 // data.
397 SCH_SHEET_LIST hierarchy( m_rootSheet );
398
399 for( const SCH_SHEET_PATH& sheetPath : hierarchy )
400 {
401 if( sheetPath.Last() == aAppendToMe )
402 {
403 m_sheetPath = sheetPath;
404 break;
405 }
406 }
407 }
408 else
409 {
410 // Create a temporary local VR used only to anchor m_sheetPath during loading.
411 // loadSchematic() will call SetTopLevelSheets() with the real Eagle pages, which
412 // creates the actual schematic VR and re-parents the pages to it.
413 tempVROwner = std::make_unique<SCH_SHEET>( aSchematic );
414 m_rootSheet = tempVROwner.get();
415 const_cast<KIID&>( m_rootSheet->m_Uuid ) = niluuid;
416 }
417
418 if( !m_rootSheet->GetScreen() )
419 {
420 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
421 screen->SetFileName( newFilename.GetFullPath() );
422 m_rootSheet->SetScreen( screen );
423
424 // Virtual root sheet UUID must be nil since all Eagle pages are loaded as subsheets.
425 const_cast<KIID&>( m_rootSheet->m_Uuid ) = niluuid;
426
427 // There is always at least a root sheet.
428 m_sheetPath.push_back( m_rootSheet );
429 }
430
432 LIBRARY_TABLE* table = adapter->ProjectTable().value_or( nullptr );
433 wxCHECK_MSG( table, nullptr, "Could not load symbol lib table." );
434
435 m_pi.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
436
439 if( !table->HasRow( getLibName() ) )
440 {
441 // Create a new empty symbol library.
442 m_pi->CreateLibrary( getLibFileName().GetFullPath() );
443 wxString libTableUri = wxT( "${KIPRJMOD}/" ) + getLibFileName().GetFullName();
444
445 // Add the new library to the project symbol library table.
446 LIBRARY_TABLE_ROW& row = table->InsertRow();
447 row.SetNickname( getLibName() );
448 row.SetURI( libTableUri );
449 row.SetType( "KiCad" );
450
451 table->Save();
452
453 adapter->LoadOne( getLibName() );
454 }
455
456 m_eagleDoc = std::make_unique<EAGLE_DOC>( currentNode, this );
457
458 // If the attribute is found, store the Eagle version;
459 // otherwise, store the dummy "0.0" version.
460 m_version = ( m_eagleDoc->version.IsEmpty() ) ? wxString( wxS( "0.0" ) ) : m_eagleDoc->version;
461
462 // Load drawing
463 loadDrawing( m_eagleDoc->drawing );
464
465 if( !aAppendToMe )
466 m_rootSheet = &aSchematic->Root();
467
468 m_pi->SaveLibrary( getLibFileName().GetFullPath() );
469
470 // The project library was created empty and then cached by the adapter (LoadOne above)
471 // before any symbols were written to it. Reload it from disk now that SaveLibrary has
472 // populated the file, otherwise UpdateSymbolLinks resolves against the stale empty cache
473 // and every imported symbol is reported as missing.
475
476 SCH_SCREENS allSheets( m_rootSheet );
477 allSheets.UpdateSymbolLinks( &LOAD_INFO_REPORTER::GetInstance() ); // Update all symbol library links for all sheets.
478
479 return m_rootSheet;
480}
481
482
483void SCH_IO_EAGLE::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
484 const wxString& aLibraryPath,
485 const std::map<std::string, UTF8>* aProperties )
486{
487 m_filename = aLibraryPath;
488 m_libName = m_filename.GetName();
489
490 ensureLoadedLibrary( aLibraryPath );
491
492 auto it = m_eagleLibs.find( m_libName );
493
494 if( it != m_eagleLibs.end() )
495 {
496 for( const auto& [symName, libSymbol] : it->second.KiCadSymbols )
497 aSymbolNameList.push_back( symName );
498 }
499}
500
501
502void SCH_IO_EAGLE::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
503 const wxString& aLibraryPath,
504 const std::map<std::string, UTF8>* aProperties )
505{
506 m_filename = aLibraryPath;
507 m_libName = m_filename.GetName();
508
509 ensureLoadedLibrary( aLibraryPath );
510
511 auto it = m_eagleLibs.find( m_libName );
512
513 if( it != m_eagleLibs.end() )
514 {
515 for( const auto& [symName, libSymbol] : it->second.KiCadSymbols )
516 aSymbolList.push_back( libSymbol.get() );
517 }
518}
519
520
521LIB_SYMBOL* SCH_IO_EAGLE::LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
522 const std::map<std::string, UTF8>* aProperties )
523{
524 m_filename = aLibraryPath;
525 m_libName = m_filename.GetName();
526
527 ensureLoadedLibrary( aLibraryPath );
528
529 auto it = m_eagleLibs.find( m_libName );
530
531 if( it != m_eagleLibs.end() )
532 {
533 auto it2 = it->second.KiCadSymbols.find( aAliasName );
534
535 if( it2 != it->second.KiCadSymbols.end() )
536 return it2->second.get();
537 }
538
539 return nullptr;
540}
541
542
543long long SCH_IO_EAGLE::getLibraryTimestamp( const wxString& aLibraryPath ) const
544{
545 wxFileName fn( aLibraryPath );
546
547 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
548 return fn.GetModificationTime().GetValue().GetValue();
549 else
550 return 0;
551}
552
553
554void SCH_IO_EAGLE::ensureLoadedLibrary( const wxString& aLibraryPath )
555{
556 // Suppress font substitution warnings (RAII - automatically restored on scope exit)
557 FONTCONFIG_REPORTER_SCOPE fontconfigScope( nullptr );
558
559 if( m_eagleLibs.find( m_libName ) != m_eagleLibs.end() )
560 {
561 wxCHECK( m_timestamps.count( m_libName ), /*void*/ );
562
563 if( m_timestamps.at( m_libName ) == getLibraryTimestamp( aLibraryPath ) )
564 return;
565 }
566
568 {
569 m_progressReporter->Report( wxString::Format( _( "Loading %s..." ), aLibraryPath ) );
570
571 if( !m_progressReporter->KeepRefreshing() )
573 }
574
575 // Load the document
576 wxXmlDocument xmlDocument = loadXmlDocument( m_filename.GetFullPath() );
577
578 // Retrieve the root as current node
579 std::unique_ptr<EAGLE_DOC> doc = std::make_unique<EAGLE_DOC>( xmlDocument.GetRoot(), this );
580
581 // If the attribute is found, store the Eagle version;
582 // otherwise, store the dummy "0.0" version.
583 m_version = ( doc->version.IsEmpty() ) ? wxString( wxS( "0.0" ) ) : doc->version;
584
585 // Load drawing
586 loadDrawing( doc->drawing );
587
588 // Remember timestamp
589 m_timestamps[m_libName] = getLibraryTimestamp( aLibraryPath );
590}
591
592
593wxXmlDocument SCH_IO_EAGLE::loadXmlDocument( const wxString& aFileName )
594{
595 wxXmlDocument xmlDocument;
596 wxFFileInputStream stream( m_filename.GetFullPath() );
597
598 if( !stream.IsOk() )
599 THROW_IO_ERRORF( _( "Unable to read file '%s'." ), m_filename.GetFullPath() );
600
601 // Pre-v6 schematics are a binary stream identified by a two-byte magic. Decode
602 // them into an XML-compatible DOM and adopt that tree, mirroring PCB_IO_EAGLE.
603 bool isBinary = EAGLE_BIN_PARSER::IsBinaryEagle( stream );
604
605 if( isBinary )
606 {
607 std::vector<uint8_t> bytes;
608 bytes.resize( static_cast<size_t>( stream.GetLength() ) );
609 stream.Read( bytes.data(), bytes.size() );
610
611 if( stream.LastRead() != bytes.size() )
612 THROW_IO_ERRORF( _( "Unable to read file '%s'." ), m_filename.GetFullPath() );
613
614 EAGLE_BIN_PARSER binParser;
615 std::unique_ptr<wxXmlDocument> binDocument = binParser.Parse( bytes );
616
617 xmlDocument.SetRoot( binDocument->DetachRoot() );
618 return xmlDocument;
619 }
620
621 // read first line to check for Eagle XML format file
622 wxTextInputStream text( stream );
623 wxString line = text.ReadLine();
624
625 if( !line.StartsWith( wxT( "<?xml" ) ) && !line.StartsWith( wxT( "<!--" ) )
626 && !line.StartsWith( wxT( "<eagle " ) ) )
627 {
628 THROW_IO_ERRORF( _( "'%s' is an Eagle binary-format file; only Eagle XML-format files can be imported." ),
629 m_filename.GetFullPath() );
630 }
631
632#if wxCHECK_VERSION( 3, 3, 0 )
633 wxXmlParseError err;
634
635 if( !xmlDocument.Load( stream, wxXMLDOC_NONE, &err ) )
636 {
637 if( err.message == wxS( "no element found" ) )
638 {
639 // Some files don't have the correct header, throwing off the xml parser
640 // So prepend the correct header
641 wxMemoryOutputStream memOutput;
642
643 wxString header;
644 header << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
645 header << "<!DOCTYPE eagle SYSTEM \"eagle.dtd\">\n";
646
647 wxScopedCharBuffer headerBuf = header.utf8_str();
648 memOutput.Write( headerBuf.data(), headerBuf.length() );
649
650 wxFFileInputStream stream2( m_filename.GetFullPath() );
651 memOutput.Write( stream2 );
652
653 wxMemoryInputStream memInput( memOutput );
654
655 if( !xmlDocument.Load( memInput, wxXMLDOC_NONE, &err ) )
656 {
657 THROW_IO_ERRORF( _( "Unable to read file '%s'." ), m_filename.GetFullPath() );
658 }
659 }
660 else
661 {
662 THROW_IO_ERRORF( _( "Unable to read file '%s'.\n'%s' at line %d, column %d, offset %d" ),
663 m_filename.GetFullPath(), err.message, err.line, err.column, err.offset );
664 }
665 }
666#else
667 if( !xmlDocument.Load( stream ) )
668 {
669 // Some files don't have the correct header, throwing off the xml parser
670 // So prepend the correct header
671 wxMemoryOutputStream memOutput;
672
673 wxString header;
674 header << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
675 header << "<!DOCTYPE eagle SYSTEM \"eagle.dtd\">\n";
676
677 wxScopedCharBuffer headerBuf = header.utf8_str();
678 memOutput.Write( headerBuf.data(), headerBuf.length() );
679
680 wxFFileInputStream stream2( m_filename.GetFullPath() );
681 memOutput.Write( stream2 );
682
683 wxMemoryInputStream memInput( memOutput );
684
685 if( !xmlDocument.Load( memInput ) )
686 THROW_IO_ERRORF( _( "Unable to read file '%s'." ), m_filename.GetFullPath() );
687 }
688#endif
689
690 return xmlDocument;
691}
692
693
694void SCH_IO_EAGLE::loadDrawing( const std::unique_ptr<EDRAWING>& aDrawing )
695{
696 wxCHECK( aDrawing, /* void */ );
697
698 loadLayerDefs( aDrawing->layers );
699
700 if( aDrawing->library )
701 {
703 elib.name = m_libName;
704
705 loadLibrary( &aDrawing->library.value(), &elib );
706 }
707
708 if( aDrawing->schematic )
709 loadSchematic( *aDrawing->schematic );
710}
711
712
713void SCH_IO_EAGLE::countNets( const ESCHEMATIC& aSchematic )
714{
715 for( const std::unique_ptr<ESHEET>& esheet : aSchematic.sheets )
716 {
717 for( const std::unique_ptr<ENET>& enet : esheet->nets )
718 {
719 wxString netName = enet->netname;
720
721 if( m_netCounts.count( netName ) )
722 m_netCounts[netName] = m_netCounts[netName] + 1;
723 else
724 m_netCounts[netName] = 1;
725 }
726 }
727
728 for( const auto& [modname, emodule] : aSchematic.modules )
729 {
730 for( const std::unique_ptr<ESHEET>& esheet : emodule->sheets )
731 {
732 for( const std::unique_ptr<ENET>& enet : esheet->nets )
733 {
734 wxString netName = enet->netname;
735
736 if( m_netCounts.count( netName ) )
737 m_netCounts[netName] = m_netCounts[netName] + 1;
738 else
739 m_netCounts[netName] = 1;
740 }
741 }
742 }
743}
744
745
747{
748 // Map all children into a readable dictionary
749 if( aSchematic.sheets.empty() )
750 return;
751
752 for( const auto& [name, variantDef] : aSchematic.variantdefs )
753 {
754 m_schematic->AddVariant( name );
755
756 if( variantDef->current.value_or( false ) )
757 m_schematic->SetCurrentVariant( name );
758 }
759
760 // N.B. Eagle parts are case-insensitive in matching but we keep the display case
761 for( const auto& [name, epart] : aSchematic.parts )
762 m_partlist[name.Upper()] = epart.get();
763
764 for( const auto& [modName, emodule] : aSchematic.modules )
765 {
766 for( const auto& [partName, epart] : emodule->parts )
767 m_partlist[partName.Upper()] = epart.get();
768 }
769
770 if( !aSchematic.libraries.empty() )
771 {
772 for( const auto& [libName, elibrary] : aSchematic.libraries )
773 {
774 EAGLE_LIBRARY* elib = &m_eagleLibs[elibrary->GetName()];
775 elib->name = elibrary->GetName();
776
777 loadLibrary( elibrary.get(), &m_eagleLibs[elibrary->GetName()] );
778 }
779
780 m_pi->SaveLibrary( getLibFileName().GetFullPath() );
781 }
782
783 // Count how many sheets each named net appears on. Used by the fallback-label path
784 // in loadSegments to decide whether to add an extra label on otherwise-unlabelled
785 // segments of nets that span multiple sheets.
786 countNets( aSchematic );
787
788 // Create all Eagle pages as top-level sheets (direct children of the virtual root).
789 // Collect them first so we can atomically replace any spurious default sheet created
790 // during schematic construction with exactly the set of real Eagle pages.
791 std::vector<SCH_SHEET*> eaglePages;
792 eaglePages.reserve( aSchematic.sheets.size() );
793
794 for( const std::unique_ptr<ESHEET>& esheet : aSchematic.sheets )
795 {
796 // Eagle schematics are never more than one sheet deep so the parent sheet is
797 // always the root sheet.
798 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>( m_rootSheet );
799 SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
800 sheet->SetScreen( screen );
801
802 wxCHECK2( sheet && screen, continue );
803
804 wxString pageNo = wxString::Format( wxT( "%d" ), m_sheetIndex );
805
806 m_sheetPath.push_back( sheet.get() );
807 loadSheet( esheet );
808
809 m_sheetPath.SetPageNumber( pageNo );
810 m_sheetPath.pop_back();
811
812 eaglePages.push_back( sheet.release() );
813
814 m_sheetIndex++;
815 }
816
817 if( !eaglePages.empty() )
818 {
819 // In the append path m_rootSheet is already the schematic's VR. Use
820 // AddTopLevelSheet to avoid discarding sheets already in the target.
821 // In the fresh-import path m_rootSheet is a temporary local VR, so we use
822 // SetTopLevelSheets to atomically replace any spurious default sheet with
823 // exactly the Eagle pages.
824 if( m_rootSheet == &m_schematic->Root() )
825 {
826 for( SCH_SHEET* page : eaglePages )
827 m_schematic->AddTopLevelSheet( page );
828 }
829 else
830 {
831 m_schematic->SetTopLevelSheets( eaglePages );
832 }
833 }
834
835 // Handle the missing symbol units that need to be instantiated
836 // to create the missing implicit connections
837
838 // Calculate the already placed items bounding box and the page size to determine
839 // placement for the new symbols
840 SCH_SHEET* schematicRoot = &m_schematic->Root();
841
842 struct MISSING_UNIT_PLACEMENT
843 {
844 VECTOR2I pageSizeIU;
845 BOX2I sheetBbox;
846 VECTOR2I newCmpPosition;
847 int maxY;
848 SCH_SHEET_PATH sheetpath;
849 SCH_SCREEN* screen;
850 };
851
852 std::map<SCH_SCREEN*, MISSING_UNIT_PLACEMENT> placements;
853
854 for( auto& cmp : m_missingCmps )
855 {
856 const SCH_SYMBOL* origSymbol = cmp.second.cmp;
857
858 for( auto& unitEntry : cmp.second.units )
859 {
860 if( unitEntry.second == false )
861 continue; // unit has been already processed
862
863 // Instantiate the missing symbol unit
864 int unit = unitEntry.first;
865 const wxString reference = origSymbol->GetField( FIELD_T::REFERENCE )->GetText();
866 std::unique_ptr<SCH_SYMBOL> symbol( (SCH_SYMBOL*) origSymbol->Duplicate( IGNORE_PARENT_GROUP ) );
867
868 SCH_SCREEN* targetScreen = cmp.second.screen;
869
870 if( !targetScreen )
871 {
872 SCH_SHEET* fallbackSheet = m_schematic->GetTopLevelSheet( 0 );
873
874 if( fallbackSheet )
875 targetScreen = fallbackSheet->GetScreen();
876 else
877 targetScreen = schematicRoot->GetScreen();
878 }
879
880 auto placementIt = placements.find( targetScreen );
881
882 if( placementIt == placements.end() )
883 {
884 MISSING_UNIT_PLACEMENT placement;
885 placement.screen = targetScreen;
886 placement.pageSizeIU = targetScreen->GetPageSettings().GetSizeIU( schIUScale.IU_PER_MILS );
887 schematicRoot->LocatePathOfScreen( targetScreen, &placement.sheetpath );
888
889 SCH_SHEET* targetSheet = placement.sheetpath.Last();
890
891 if( targetSheet )
892 placement.sheetBbox = getSheetBbox( targetSheet );
893
894 placement.newCmpPosition = VECTOR2I( placement.sheetBbox.GetLeft(),
895 placement.sheetBbox.GetBottom() );
896 placement.maxY = placement.sheetBbox.GetY();
897 placementIt = placements.emplace( targetScreen, placement ).first;
898 }
899
900 MISSING_UNIT_PLACEMENT& placement = placementIt->second;
901
902 symbol->SetUnitSelection( &placement.sheetpath, unit );
903 symbol->SetUnit( unit );
904 symbol->SetOrientation( 0 );
905 symbol->AddHierarchicalReference( placement.sheetpath.Path(), reference, unit );
906
907 // Calculate the placement position
908 BOX2I cmpBbox = symbol->GetBoundingBox();
909 int posY = placement.newCmpPosition.y + cmpBbox.GetHeight();
910 symbol->SetPosition( VECTOR2I( placement.newCmpPosition.x, posY ) );
911 placement.newCmpPosition.x += cmpBbox.GetWidth();
912 placement.maxY = std::max( placement.maxY, posY );
913
914 if( placement.newCmpPosition.x >= placement.pageSizeIU.x ) // reached the page boundary?
915 placement.newCmpPosition = VECTOR2I( placement.sheetBbox.GetLeft(),
916 placement.maxY ); // then start a new row
917
918 // Add the global net labels to recreate the implicit connections
919 addImplicitConnections( symbol.get(), placement.screen, false );
920 placement.screen->Append( symbol.release() );
921 }
922 }
923
924 m_missingCmps.clear();
925}
926
927
928void SCH_IO_EAGLE::loadSheet( const std::unique_ptr<ESHEET>& aSheet )
929{
930 SCH_SHEET* sheet = getCurrentSheet();
931 SCH_SCREEN* screen = getCurrentScreen();
932
933 wxCHECK( sheet && screen, /* void */ );
934
935 if( m_modules.empty() )
936 {
937 std::string filename;
938
939 filename = wxString::Format( wxT( "%s_%d" ), m_filename.GetName(), m_sheetIndex );
940
941 if( aSheet->description )
942 sheet->SetName( aSheet->description.value().text );
943 else
944 sheet->SetName( filename );
945
946 ReplaceIllegalFileNameChars( filename );
947 replace( filename.begin(), filename.end(), ' ', '_' );
948
949 // Use the project directory so saved pages land alongside the project file,
950 // not in the Eagle source directory.
951 wxFileName fn;
952 fn.SetPath( m_schematic->Project().GetProjectPath() );
953 fn.SetName( filename );
955
956 sheet->SetFileName( fn.GetFullName() );
957 screen->SetFileName( fn.GetFullPath() );
958 }
959
960 for( const auto& [name, moduleinst] : aSheet->moduleinsts )
961 loadModuleInstance( moduleinst );
962
963 sheet->AutoplaceFields( screen, AUTOPLACE_AUTO );
964
965 if( aSheet->plain )
966 {
967 for( const std::unique_ptr<EPOLYGON>& epoly : aSheet->plain->polygons )
968 {
969 if( SCH_SHAPE* shape = loadPolyLine( epoly ) )
970 screen->Append( shape );
971 }
972
973 for( const std::unique_ptr<EWIRE>& ewire : aSheet->plain->wires )
974 {
975 SEG endpoints;
976 screen->Append( loadWire( ewire, endpoints ) );
977 }
978
979 for( const std::unique_ptr<ETEXT>& etext : aSheet->plain->texts )
980 screen->Append( loadPlainText( etext ) );
981
982 for( const std::unique_ptr<ECIRCLE>& ecircle : aSheet->plain->circles )
983 screen->Append( loadCircle( ecircle ) );
984
985 for( const std::unique_ptr<ERECT>& erectangle : aSheet->plain->rectangles )
986 screen->Append( loadRectangle( erectangle ) );
987
988 for( const std::unique_ptr<EFRAME>& eframe : aSheet->plain->frames )
989 {
990 std::vector<SCH_ITEM*> frameItems;
991
992 loadFrame( eframe, frameItems );
993
994 for( SCH_ITEM* item : frameItems )
995 screen->Append( item );
996 }
997
998 // Holes and splines currently not handled. Not sure hole has any meaning in scheamtics.
999 }
1000
1001 for( const std::unique_ptr<EINSTANCE>& einstance : aSheet->instances )
1002 {
1003 loadInstance( einstance, ( m_modules.size() ) ? m_modules.back()->parts
1004 : m_eagleDoc->drawing->schematic->parts );
1005 }
1006
1007 // Loop through all buses
1008 // From the DTD: "Buses receive names which determine which signals they include.
1009 // A bus is a drawing object. It does not create any electrical connections.
1010 // These are always created by means of the nets and their names."
1011 for( const std::unique_ptr<EBUS>& ebus : aSheet->busses )
1012 {
1013 // Get the bus name
1014 wxString busName = translateEagleBusName( ebus->name );
1015
1016 // Load segments of this bus
1017 loadSegments( ebus->segments, busName, wxString(), /* aIsBus */ true );
1018 }
1019
1020 for( const std::unique_ptr<ENET>& enet : aSheet->nets )
1021 {
1022 // Get the net name and class
1023 wxString netName = enet->netname;
1024 wxString netClass = wxString::Format( wxS( "%i" ), enet->netcode );
1025
1026 // Load segments of this net
1027 loadSegments( enet->segments, netName, netClass );
1028 }
1029
1030 adjustNetLabels(); // needs to be called before addBusEntries()
1031 addBusEntries();
1032
1033 // Calculate the new sheet size.
1034 BOX2I sheetBoundingBox = getSheetBbox( sheet );
1035 VECTOR2I targetSheetSize = sheetBoundingBox.GetSize();
1036 targetSheetSize += VECTOR2I( schIUScale.MilsToIU( 1500 ), schIUScale.MilsToIU( 1500 ) );
1037
1038 // Get current Eeschema sheet size.
1039 VECTOR2I pageSizeIU = screen->GetPageSettings().GetSizeIU( schIUScale.IU_PER_MILS );
1040 PAGE_INFO pageInfo = screen->GetPageSettings();
1041
1042 // Increase if necessary
1043 if( pageSizeIU.x < targetSheetSize.x )
1044 pageInfo.SetWidthMils( schIUScale.IUToMils( targetSheetSize.x ) );
1045
1046 if( pageSizeIU.y < targetSheetSize.y )
1047 pageInfo.SetHeightMils( schIUScale.IUToMils( targetSheetSize.y ) );
1048
1049 // Set the new sheet size.
1050 screen->SetPageSettings( pageInfo );
1051
1052 pageSizeIU = screen->GetPageSettings().GetSizeIU( schIUScale.IU_PER_MILS );
1053 VECTOR2I sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
1054 VECTOR2I itemsCentre = sheetBoundingBox.Centre();
1055
1056 // round the translation to nearest 100mil to place it on the grid.
1057 VECTOR2I translation = sheetcentre - itemsCentre;
1058 translation.x = translation.x - translation.x % schIUScale.MilsToIU( 100 );
1059 translation.y = translation.y - translation.y % schIUScale.MilsToIU( 100 );
1060
1061 // Add global net labels for the named power input pins in this sheet
1062 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1063 {
1064 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1065 addImplicitConnections( symbol, screen, true );
1066 }
1067
1068 m_connPoints.clear();
1069
1070 // Translate the items.
1071 std::vector<SCH_ITEM*> allItems;
1072
1073 std::copy( screen->Items().begin(), screen->Items().end(), std::back_inserter( allItems ) );
1074
1075 for( SCH_ITEM* item : allItems )
1076 {
1077 item->SetPosition( item->GetPosition() + translation );
1078
1079 // We don't read positions of Eagle label fields (primarily intersheet refs), so we
1080 // need to autoplace them after applying the translation.
1081 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item ) )
1082 label->AutoplaceFields( screen, AUTOPLACE_AUTO );
1083
1084 item->ClearFlags();
1085 screen->Update( item );
1086 }
1087}
1088
1089
1090void SCH_IO_EAGLE::loadModuleInstance( const std::unique_ptr<EMODULEINST>& aModuleInstance )
1091{
1092 SCH_SHEET* currentSheet = getCurrentSheet();
1093 SCH_SCREEN* currentScreen = getCurrentScreen();
1094
1095 wxCHECK( currentSheet &&currentScreen, /* void */ );
1096
1097 m_sheetIndex++;
1098
1099 // Eagle document has already be checked for drawing and schematic nodes so this
1100 // should not segfault.
1101 auto it = m_eagleDoc->drawing->schematic->modules.find( aModuleInstance->moduleinst );
1102
1103 // Find the module referenced by the module instance.
1104 if( it == m_eagleDoc->drawing->schematic->modules.end() )
1105 {
1106 THROW_IO_ERRORF( _( "No module instance '%s' found in schematic file:\n%s" ),
1107 aModuleInstance->name, m_filename.GetFullPath() );
1108 }
1109
1110 wxFileName fn = m_filename;
1111 fn.SetName( aModuleInstance->moduleinst );
1113
1114 VECTOR2I portExtWireEndpoint;
1115 VECTOR2I size( it->second->dx.ToSchUnits(), it->second->dy.ToSchUnits() );
1116
1117 int halfX = KiROUND( size.x / 2.0 );
1118 int halfY = KiROUND( size.y / 2.0 );
1119 int portExtWireLength = schIUScale.mmToIU( 5.08 );
1120 VECTOR2I pos( aModuleInstance->x.ToSchUnits() - halfX,
1121 -aModuleInstance->y.ToSchUnits() - halfY );
1122
1123 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( currentSheet, pos, size );
1124
1125 // The Eagle module for this instance (SCH_SCREEN in KiCad) may have already been loaded.
1126 SCH_SCREEN* newScreen = nullptr;
1127 SCH_SCREENS schFiles( m_rootSheet );
1128
1129 for( SCH_SCREEN* schFile = schFiles.GetFirst(); schFile; schFile = schFiles.GetNext() )
1130 {
1131 if( schFile->GetFileName() == fn.GetFullPath() )
1132 {
1133 newScreen = schFile;
1134 break;
1135 }
1136 }
1137
1138 bool isNewSchFile = ( newScreen == nullptr );
1139
1140 if( !newScreen )
1141 {
1142 newScreen = new SCH_SCREEN( m_schematic );
1143 newScreen->SetFileName( fn.GetFullPath() );
1144 }
1145
1146 wxCHECK( newSheet && newScreen, /* void */ );
1147
1148 newSheet->SetScreen( newScreen );
1149 newSheet->SetFileName( fn.GetFullName() );
1150 newSheet->SetName( aModuleInstance->name );
1151
1152 for( const auto& [portName, port] : it->second->ports )
1153 {
1154 VECTOR2I pinPos( 0, 0 );
1155 int pinOffset = port->coord.ToSchUnits();
1157
1158 if( port->side == "left" )
1159 {
1160 side = SHEET_SIDE::LEFT;
1161 pinPos.x = pos.x;
1162 pinPos.y = pos.y + halfY - pinOffset;
1163 portExtWireEndpoint = pinPos;
1164 portExtWireEndpoint.x -= portExtWireLength;
1165 }
1166 else if( port->side == "right" )
1167 {
1168 side = SHEET_SIDE::RIGHT;
1169 pinPos.x = pos.x + size.x;
1170 pinPos.y = pos.y + halfY - pinOffset;
1171 portExtWireEndpoint = pinPos;
1172 portExtWireEndpoint.x += portExtWireLength;
1173 }
1174 else if( port->side == "top" )
1175 {
1176 side = SHEET_SIDE::TOP;
1177 pinPos.x = pos.x + halfX + pinOffset;
1178 pinPos.y = pos.y;
1179 portExtWireEndpoint = pinPos;
1180 portExtWireEndpoint.y -= portExtWireLength;
1181 }
1182 else if( port->side == "bottom" )
1183 {
1184 side = SHEET_SIDE::BOTTOM;
1185 pinPos.x = pos.x + halfX + pinOffset;
1186 pinPos.y = pos.y + size.y;
1187 portExtWireEndpoint = pinPos;
1188 portExtWireEndpoint.y += portExtWireLength;
1189 }
1190
1191 SCH_LINE* portExtWire = new SCH_LINE( pinPos, LAYER_WIRE );
1192 portExtWire->SetEndPoint( portExtWireEndpoint );
1193 currentScreen->Append( portExtWire );
1194
1196
1197 if( port->direction.has_value() )
1198 {
1199 if( port->direction.value() == "in" )
1200 pinType = LABEL_FLAG_SHAPE::L_INPUT;
1201 else if( port->direction.value() == "out" )
1203 else if( port->direction.value() == "io" )
1204 pinType = LABEL_FLAG_SHAPE::L_BIDI;
1205 else if( port->direction.value() == "hiz" )
1207
1208 // KiCad does not support passive, power, open collector, or no-connect sheet pins that
1209 // Eagle ports support. They are left set to L_UNSPECIFIED to minimize ERC issues.
1210 }
1211
1212 SCH_SHEET_PIN* sheetPin = new SCH_SHEET_PIN( newSheet.get(), VECTOR2I( 0, 0 ), portName );
1213
1214 sheetPin->SetShape( pinType );
1215 sheetPin->SetPosition( pinPos );
1216 sheetPin->SetSide( side );
1217 newSheet->AddPin( sheetPin );
1218 }
1219
1220 wxString pageNo = wxString::Format( wxT( "%d" ), m_sheetIndex );
1221
1222 newSheet->SetParent( currentSheet );
1223 m_sheetPath.push_back( newSheet.get() );
1224 m_sheetPath.SetPageNumber( pageNo );
1225 currentScreen->Append( newSheet.release() );
1226
1227 m_modules.push_back( it->second.get() );
1228 m_moduleInstances.push_back( aModuleInstance.get() );
1229
1230 // Do not reload shared modules that are already loaded.
1231 if( isNewSchFile )
1232 {
1233 for( const std::unique_ptr<ESHEET>& esheet : it->second->sheets )
1234 loadSheet( esheet );
1235 }
1236 else
1237 {
1238 // Add instances for shared schematics.
1239 wxString refPrefix;
1240
1241 for( const EMODULEINST* emoduleInst : m_moduleInstances )
1242 {
1243 wxCHECK2( emoduleInst, continue );
1244
1245 refPrefix += emoduleInst->name + wxS( ":" );
1246 }
1247
1248 SCH_SCREEN* sharedScreen = m_sheetPath.LastScreen();
1249
1250 if( sharedScreen )
1251 {
1252 for( SCH_ITEM* schItem : sharedScreen->Items().OfType( SCH_SYMBOL_T ) )
1253 {
1254 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( schItem );
1255
1256 wxCHECK2( symbol && !symbol->GetInstances().empty(), continue );
1257
1258 SCH_SYMBOL_INSTANCE inst = symbol->GetInstances().at( 0 );
1259 wxString newReference = refPrefix + inst.m_Reference.AfterLast( ':' );
1260
1261 symbol->AddHierarchicalReference( m_sheetPath.Path(), newReference, inst.m_Unit );
1262 }
1263 }
1264 }
1265
1266 m_moduleInstances.pop_back();
1267 m_modules.pop_back();
1268 m_sheetPath.pop_back();
1269}
1270
1271
1272void SCH_IO_EAGLE::loadFrame( const std::unique_ptr<EFRAME>& aFrame, std::vector<SCH_ITEM*>& aItems,
1273 SCH_LAYER_ID aLayer )
1274{
1275 int xMin = aFrame->x1.ToSchUnits();
1276 int xMax = aFrame->x2.ToSchUnits();
1277 int yMin = -aFrame->y1.ToSchUnits();
1278 int yMax = -aFrame->y2.ToSchUnits();
1279
1280 if( xMin > xMax )
1281 std::swap( xMin, xMax );
1282
1283 if( yMin > yMax )
1284 std::swap( yMin, yMax );
1285
1286 SCH_SHAPE* lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1287 lines->AddPoint( VECTOR2I( xMin, yMin ) );
1288 lines->AddPoint( VECTOR2I( xMax, yMin ) );
1289 lines->AddPoint( VECTOR2I( xMax, yMax ) );
1290 lines->AddPoint( VECTOR2I( xMin, yMax ) );
1291 lines->AddPoint( VECTOR2I( xMin, yMin ) );
1292 aItems.push_back( lines );
1293
1294 if( !( aFrame->border_left == false ) )
1295 {
1296 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1297 lines->AddPoint( VECTOR2I( xMin + schIUScale.MilsToIU( 150 ), yMin + schIUScale.MilsToIU( 150 ) ) );
1298 lines->AddPoint( VECTOR2I( xMin + schIUScale.MilsToIU( 150 ), yMax - schIUScale.MilsToIU( 150 ) ) );
1299 aItems.push_back( lines );
1300
1301 int i;
1302 int height = yMax - yMin;
1303 int x1 = xMin;
1304 int x2 = x1 + schIUScale.MilsToIU( 150 );
1305 int legendPosX = xMin + schIUScale.MilsToIU( 75 );
1306 double rowSpacing = height / double( aFrame->rows );
1307 double legendPosY = yMin + ( rowSpacing / 2 );
1308
1309 for( i = 1; i < aFrame->rows; i++ )
1310 {
1311 int newY = KiROUND( yMin + ( rowSpacing * (double) i ) );
1312 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1313 lines->AddPoint( VECTOR2I( x1, newY ) );
1314 lines->AddPoint( VECTOR2I( x2, newY ) );
1315 aItems.push_back( lines );
1316 }
1317
1318 char legendChar = 'A';
1319
1320 for( i = 0; i < aFrame->rows; i++ )
1321 {
1322 SCH_TEXT* legendText = new SCH_TEXT();
1323 legendText->SetLayer( aLayer );
1324 legendText->SetPosition( VECTOR2I( legendPosX, KiROUND( legendPosY ) ) );
1327 legendText->SetText( wxString( legendChar ) );
1328 legendText->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 90 ), schIUScale.MilsToIU( 100 ) ) );
1329 aItems.push_back( legendText );
1330 legendChar++;
1331 legendPosY += rowSpacing;
1332 }
1333 }
1334
1335 if( !( aFrame->border_right == false ) )
1336 {
1337 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1338 lines->AddPoint( VECTOR2I( xMax - schIUScale.MilsToIU( 150 ), yMin + schIUScale.MilsToIU( 150 ) ) );
1339 lines->AddPoint( VECTOR2I( xMax - schIUScale.MilsToIU( 150 ), yMax - schIUScale.MilsToIU( 150 ) ) );
1340 aItems.push_back( lines );
1341
1342 int i;
1343 int height = yMax - yMin;
1344 int x1 = xMax - schIUScale.MilsToIU( 150 );
1345 int x2 = xMax;
1346 int legendPosX = xMax - schIUScale.MilsToIU( 75 );
1347 double rowSpacing = height / double( aFrame->rows );
1348 double legendPosY = yMin + ( rowSpacing / 2 );
1349
1350 for( i = 1; i < aFrame->rows; i++ )
1351 {
1352 int newY = KiROUND( yMin + ( rowSpacing * (double) i ) );
1353 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1354 lines->AddPoint( VECTOR2I( x1, newY ) );
1355 lines->AddPoint( VECTOR2I( x2, newY ) );
1356 aItems.push_back( lines );
1357 }
1358
1359 char legendChar = 'A';
1360
1361 for( i = 0; i < aFrame->rows; i++ )
1362 {
1363 SCH_TEXT* legendText = new SCH_TEXT();
1364 legendText->SetLayer( aLayer );
1365 legendText->SetPosition( VECTOR2I( legendPosX, KiROUND( legendPosY ) ) );
1368 legendText->SetText( wxString( legendChar ) );
1369 legendText->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 90 ), schIUScale.MilsToIU( 100 ) ) );
1370 aItems.push_back( legendText );
1371 legendChar++;
1372 legendPosY += rowSpacing;
1373 }
1374 }
1375
1376 if( !( aFrame->border_top == false ) )
1377 {
1378 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1379 lines->AddPoint( VECTOR2I( xMax - schIUScale.MilsToIU( 150 ), yMin + schIUScale.MilsToIU( 150 ) ) );
1380 lines->AddPoint( VECTOR2I( xMin + schIUScale.MilsToIU( 150 ), yMin + schIUScale.MilsToIU( 150 ) ) );
1381 aItems.push_back( lines );
1382
1383 int i;
1384 int width = xMax - xMin;
1385 int y1 = yMin;
1386 int y2 = yMin + schIUScale.MilsToIU( 150 );
1387 int legendPosY = yMin + schIUScale.MilsToIU( 75 );
1388 double columnSpacing = width / double( aFrame->columns );
1389 double legendPosX = xMin + ( columnSpacing / 2 );
1390
1391 for( i = 1; i < aFrame->columns; i++ )
1392 {
1393 int newX = KiROUND( xMin + ( columnSpacing * (double) i ) );
1394 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1395 lines->AddPoint( VECTOR2I( newX, y1 ) );
1396 lines->AddPoint( VECTOR2I( newX, y2 ) );
1397 aItems.push_back( lines );
1398 }
1399
1400 int legendNo = 1;
1401
1402 for( i = 0; i < aFrame->columns; i++ )
1403 {
1404 SCH_TEXT* legendText = new SCH_TEXT();
1405 legendText->SetLayer( aLayer );
1406 legendText->SetPosition( VECTOR2I( KiROUND( legendPosX ), legendPosY ) );
1409 legendText->SetText( fmt::format( "{}", legendNo++ ) );
1410 legendText->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 90 ), schIUScale.MilsToIU( 100 ) ) );
1411 aItems.push_back( legendText );
1412 legendPosX += columnSpacing;
1413 }
1414 }
1415
1416 if( !( aFrame->border_bottom == false ) )
1417 {
1418 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1419 lines->AddPoint( VECTOR2I( xMax - schIUScale.MilsToIU( 150 ), yMax - schIUScale.MilsToIU( 150 ) ) );
1420 lines->AddPoint( VECTOR2I( xMin + schIUScale.MilsToIU( 150 ), yMax - schIUScale.MilsToIU( 150 ) ) );
1421 aItems.push_back( lines );
1422
1423 int i;
1424 int width = xMax - xMin;
1425 int y1 = yMax - schIUScale.MilsToIU( 150 );
1426 int y2 = yMax;
1427 int legendPosY = yMax - schIUScale.MilsToIU( 75 );
1428 double columnSpacing = width / double( aFrame->columns );
1429 double legendPosX = xMin + ( columnSpacing / 2 );
1430
1431 for( i = 1; i < aFrame->columns; i++ )
1432 {
1433 int newX = KiROUND( xMin + ( columnSpacing * (double) i ) );
1434 lines = new SCH_SHAPE( SHAPE_T::POLY, aLayer );
1435 lines->AddPoint( VECTOR2I( newX, y1 ) );
1436 lines->AddPoint( VECTOR2I( newX, y2 ) );
1437 aItems.push_back( lines );
1438 }
1439
1440 int legendNo = 1;
1441
1442 for( i = 0; i < aFrame->columns; i++ )
1443 {
1444 SCH_TEXT* legendText = new SCH_TEXT();
1445 legendText->SetLayer( aLayer );
1446 legendText->SetPosition( VECTOR2I( KiROUND( legendPosX ), legendPosY ) );
1449 legendText->SetText( fmt::format( "{}", legendNo++ ) );
1450 legendText->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 90 ), schIUScale.MilsToIU( 100 ) ) );
1451 aItems.push_back( legendText );
1452 legendPosX += columnSpacing;
1453 }
1454 }
1455}
1456
1457
1458void SCH_IO_EAGLE::loadSegments( const std::vector<std::unique_ptr<ESEGMENT>>& aSegments,
1459 const wxString& netName, const wxString& aNetClass, bool aIsBus )
1460{
1461 // Loop through all segments
1462 SCH_SCREEN* screen = getCurrentScreen();
1463
1464 wxCHECK( screen, /* void */ );
1465
1466 size_t segmentCount = aSegments.size();
1467
1468 for( const std::unique_ptr<ESEGMENT>& esegment : aSegments )
1469 {
1470 bool labelled = false; // has a label been added to this continuously connected segment
1471 bool firstWireFound = false;
1472 SEG firstWire;
1473
1474 m_segments.emplace_back();
1475 SEG_DESC& segDesc = m_segments.back();
1476
1477 for( const std::unique_ptr<EWIRE>& ewire : esegment->wires )
1478 {
1479 // TODO: Check how intersections used in adjustNetLabels should be
1480 // calculated - for now we pretend that all wires are line segments.
1481 SEG thisWire;
1482 SCH_ITEM* wire = loadWire( ewire, thisWire );
1483 m_connPoints[thisWire.A].emplace( wire );
1484 m_connPoints[thisWire.B].emplace( wire );
1485
1486 if( !firstWireFound )
1487 {
1488 firstWire = thisWire;
1489 firstWireFound = true;
1490 }
1491
1492 // Test for intersections with other wires
1493 for( SEG_DESC& desc : m_segments )
1494 {
1495 if( !desc.labels.empty() && desc.labels.front()->GetText() == netName )
1496 continue; // no point in saving intersections of the same net
1497
1498 for( const SEG& seg : desc.segs )
1499 {
1500 OPT_VECTOR2I intersection = thisWire.Intersect( seg, true );
1501
1502 if( intersection )
1503 m_wireIntersections.push_back( *intersection );
1504 }
1505 }
1506
1507 segDesc.segs.push_back( thisWire );
1508 screen->Append( wire );
1509 }
1510
1511 for( const std::unique_ptr<EJUNCTION>& ejunction : esegment->junctions )
1512 screen->Append( loadJunction( ejunction ) );
1513
1514 for( const std::unique_ptr<ELABEL>& elabel : esegment->labels )
1515 {
1516 SCH_LABEL_BASE* label = loadLabel( elabel, netName, aIsBus );
1517 screen->Append( label );
1518
1519 wxASSERT( segDesc.labels.empty() || segDesc.labels.front()->GetText() == label->GetText() );
1520
1521 segDesc.labels.push_back( label );
1522 labelled = true;
1523 }
1524
1525 for( const std::unique_ptr<EPINREF>& epinref : esegment->pinRefs )
1526 {
1527 wxString part = epinref->part;
1528 wxString pin = epinref->pin;
1529
1530 auto powerPort = m_powerPorts.find( wxT( "#" ) + part );
1531
1532 if( powerPort != m_powerPorts.end() && powerPort->second == EscapeString( pin, CTX_NETNAME ) )
1533 labelled = true;
1534 }
1535
1536 // Add a small label to the net segment if it hasn't been labeled already or is not
1537 // connect to a power symbol with a pin on the same net. This preserves the named net
1538 // feature of Eagle schematics.
1539 if( !labelled && firstWireFound )
1540 {
1541 std::unique_ptr<SCH_LABEL_BASE> label;
1542
1543 // Eagle uses a flat net namespace, so a named net should retain its name across
1544 // every segment and every sheet. The PCB importer carries Eagle signal names
1545 // through verbatim, so we must use a global label here too: a local SCH_LABEL
1546 // would prepend the sheet path (e.g. "/+24V_SWD") and split the net from the
1547 // matching PCB signal on net update.
1548 //
1549 // Two exceptions: (1) buses are conceptual groupings in Eagle, not electrical
1550 // signals, so a global bus label would join same-named buses project-wide where
1551 // Eagle only had visual grouping; (2) nets inside module instances are scoped
1552 // by the module's ports, so a global label would punch through the hierarchy.
1553 if( segmentCount > 1 || m_netCounts[netName] > 1 )
1554 {
1555 if( aIsBus || !m_modules.empty() )
1556 label.reset( new SCH_LABEL );
1557 else
1558 label.reset( new SCH_GLOBALLABEL );
1559 }
1560
1561 if( label )
1562 {
1563 label->SetPosition( firstWire.A );
1564 label->SetText( escapeName( netName ) );
1565 label->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 40 ), schIUScale.MilsToIU( 40 ) ) );
1566
1567 if( firstWire.A.y == firstWire.B.y ) // Horizontal wire.
1568 {
1569 if( firstWire.B.x > firstWire.A.x )
1570 label->SetSpinStyle( SPIN_STYLE::LEFT );
1571 else
1572 label->SetSpinStyle( SPIN_STYLE::RIGHT );
1573 }
1574 else if( firstWire.A.x == firstWire.B.x ) // Vertical wire.
1575 {
1576 if( firstWire.B.y > firstWire.A.y )
1577 label->SetSpinStyle( SPIN_STYLE::BOTTOM );
1578 else
1579 label->SetSpinStyle( SPIN_STYLE::UP );
1580 }
1581
1582 screen->Append( label.release() );
1583 }
1584 }
1585 }
1586}
1587
1588
1589SCH_SHAPE* SCH_IO_EAGLE::loadPolyLine( const std::unique_ptr<EPOLYGON>& aPolygon )
1590{
1591 if( !aPolygon->IsValidOutline() )
1592 return nullptr;
1593
1594 std::unique_ptr<SCH_SHAPE> poly = std::make_unique<SCH_SHAPE>( SHAPE_T::POLY );
1595 VECTOR2I pt, prev_pt;
1596 std::optional<double> prev_curve;
1597
1598 for( const std::unique_ptr<EVERTEX>& evertex : aPolygon->vertices )
1599 {
1600 pt = VECTOR2I( evertex->x.ToSchUnits(), -evertex->y.ToSchUnits() );
1601
1602 if( prev_curve.has_value() )
1603 {
1604 SHAPE_ARC arc;
1605 arc.ConstructFromStartEndAngle( prev_pt, pt, -EDA_ANGLE( prev_curve.value(), DEGREES_T ) );
1606 poly->GetPolyShape().Append( arc, -1, -1, ARC_ACCURACY );
1607 }
1608 else
1609 {
1610 poly->AddPoint( pt );
1611 }
1612
1613 prev_pt = pt;
1614 prev_curve = evertex->curve;
1615 }
1616
1617 poly->SetLayer( kiCadLayer( aPolygon->layer ) );
1618 poly->SetStroke( STROKE_PARAMS( aPolygon->width.ToSchUnits(), LINE_STYLE::SOLID ) );
1619 poly->SetFillMode( FILL_T::FILLED_SHAPE );
1620
1621 return poly.release();
1622}
1623
1624
1625SCH_ITEM* SCH_IO_EAGLE::loadWire( const std::unique_ptr<EWIRE>& aWire, SEG& endpoints )
1626{
1627 VECTOR2I start, end;
1628
1629 start.x = aWire->x1.ToSchUnits();
1630 start.y = -aWire->y1.ToSchUnits();
1631 end.x = aWire->x2.ToSchUnits();
1632 end.y = -aWire->y2.ToSchUnits();
1633
1634 // For segment wires.
1635 endpoints = SEG( start, end );
1636
1637 int kicadLayer = kiCadLayer( aWire->layer );
1638
1639 // Don't process curved wires on an electrical layer into arcs, they aren't supported
1640 // in the rest of the code
1641 // TODO: When curved wires/buses are added, remove this restriction
1642 if( (kicadLayer == LAYER_NOTES) && aWire->curve )
1643 {
1644 std::unique_ptr<SCH_SHAPE> arc = std::make_unique<SCH_SHAPE>( SHAPE_T::ARC );
1645
1646 VECTOR2I center = ConvertArcCenter( start, end, *aWire->curve );
1647 arc->SetCenter( center );
1648 arc->SetStart( start );
1649
1650 // KiCad rotates the other way.
1651 arc->SetArcAngleAndEnd( -EDA_ANGLE( *aWire->curve, DEGREES_T ), true );
1652 arc->SetLayer( kiCadLayer( aWire->layer ) );
1653 arc->SetStroke( STROKE_PARAMS( aWire->width.ToSchUnits(), LINE_STYLE::SOLID ) );
1654
1655 return arc.release();
1656 }
1657 else
1658 {
1659 std::unique_ptr<SCH_LINE> line = std::make_unique<SCH_LINE>();
1660
1661 line->SetStartPoint( start );
1662 line->SetEndPoint( end );
1663 line->SetLayer( kiCadLayer( aWire->layer ) );
1664 line->SetStroke( STROKE_PARAMS( aWire->width.ToSchUnits(), LINE_STYLE::SOLID ) );
1665
1666 return line.release();
1667 }
1668}
1669
1670
1671SCH_SHAPE* SCH_IO_EAGLE::loadCircle( const std::unique_ptr<ECIRCLE>& aCircle )
1672{
1673 std::unique_ptr<SCH_SHAPE> circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE );
1674 VECTOR2I center( aCircle->x.ToSchUnits(), -aCircle->y.ToSchUnits() );
1675
1676 circle->SetLayer( kiCadLayer( aCircle->layer ) );
1677 circle->SetPosition( center );
1678 circle->SetEnd( VECTOR2I( center.x + aCircle->radius.ToSchUnits(), center.y ) );
1679 circle->SetStroke( STROKE_PARAMS( aCircle->width.ToSchUnits(), LINE_STYLE::SOLID ) );
1680
1681 return circle.release();
1682}
1683
1684
1685SCH_SHAPE* SCH_IO_EAGLE::loadRectangle( const std::unique_ptr<ERECT>& aRectangle )
1686{
1687 std::unique_ptr<SCH_SHAPE> rectangle = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE );
1688
1689 rectangle->SetLayer( kiCadLayer( aRectangle->layer ) );
1690 rectangle->SetPosition( VECTOR2I( aRectangle->x1.ToSchUnits(), -aRectangle->y1.ToSchUnits() ) );
1691 rectangle->SetEnd( VECTOR2I( aRectangle->x2.ToSchUnits(), -aRectangle->y2.ToSchUnits() ) );
1692
1693 if( aRectangle->rot.has_value() )
1694 {
1695 VECTOR2I pos( rectangle->GetPosition() );
1696 VECTOR2I end( rectangle->GetEnd() );
1697 VECTOR2I center( rectangle->GetCenter() );
1698
1699 RotatePoint( pos, center, EDA_ANGLE( aRectangle->rot.value().degrees, DEGREES_T ) );
1700 RotatePoint( end, center, EDA_ANGLE( aRectangle->rot.value().degrees, DEGREES_T ) );
1701
1702 rectangle->SetPosition( pos );
1703 rectangle->SetEnd( end );
1704 }
1705
1706 // Eagle rectangles are filled by definition.
1707 rectangle->SetFillMode( FILL_T::FILLED_SHAPE );
1708
1709 return rectangle.release();
1710}
1711
1712
1713SCH_JUNCTION* SCH_IO_EAGLE::loadJunction( const std::unique_ptr<EJUNCTION>& aJunction )
1714{
1715 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
1716
1717 VECTOR2I pos( aJunction->x.ToSchUnits(), -aJunction->y.ToSchUnits() );
1718
1719 junction->SetPosition( pos );
1720
1721 return junction.release();
1722}
1723
1724
1725SCH_LABEL_BASE* SCH_IO_EAGLE::loadLabel( const std::unique_ptr<ELABEL>& aLabel,
1726 const wxString& aNetName, bool aIsBus )
1727{
1728 VECTOR2I elabelpos( aLabel->x.ToSchUnits(), -aLabel->y.ToSchUnits() );
1729
1730 // Label-kind decision mirrors loadSegments(): SCH_HIERLABEL for module ports,
1731 // SCH_LABEL for buses and module-internal nets, SCH_GLOBALLABEL otherwise so the
1732 // Eagle flat net namespace round-trips through the matching PCB signal name.
1733 std::unique_ptr<SCH_LABEL_BASE> label;
1734
1735 VECTOR2I textSize = KiROUND( aLabel->size.ToSchUnits() * 0.7, aLabel->size.ToSchUnits() * 0.7 );
1736
1737 auto findModulePort =
1738 [&]() -> const EPORT*
1739 {
1740 if( m_modules.empty() )
1741 return nullptr;
1742
1743 const auto& ports = m_modules.back()->ports;
1744 const auto it = ports.find( aNetName );
1745 return it == ports.end() ? nullptr : it->second.get();
1746 };
1747
1748 const EPORT* port = findModulePort();
1749
1750 if( port )
1751 {
1752 std::unique_ptr<SCH_HIERLABEL> hierLabel = std::make_unique<SCH_HIERLABEL>();
1754
1755 if( port->direction.has_value() )
1756 {
1757 if( port->direction.value() == "in" )
1759 else if( port->direction.value() == "out" )
1761 else if( port->direction.value() == "io" )
1763 else if( port->direction.value() == "hiz" )
1765 }
1766
1767 hierLabel->SetLabelShape( type );
1768
1769 label = std::move( hierLabel );
1770 }
1771 else if( aIsBus || !m_modules.empty() )
1772 {
1773 label = std::make_unique<SCH_LABEL>();
1774 }
1775 else
1776 {
1777 label = std::make_unique<SCH_GLOBALLABEL>();
1778 }
1779
1780 label->SetText( escapeName( aNetName ) );
1781 label->SetPosition( elabelpos );
1782 label->SetTextSize( textSize );
1783 label->SetSpinStyle( SPIN_STYLE::RIGHT );
1784
1785 if( aLabel->rot.has_value() )
1786 {
1787 // According to the Eagle DTD, labels can only be rotated in 90 degree increments.
1788 int angle = KiROUND( aLabel->rot.value().degrees );
1789
1790 switch( angle )
1791 {
1792 case 90: label->SetSpinStyle( aLabel->rot.value().mirror ? SPIN_STYLE::BOTTOM : SPIN_STYLE::UP ); break;
1793 case 180: label->SetSpinStyle( aLabel->rot.value().mirror ? SPIN_STYLE::RIGHT : SPIN_STYLE::LEFT ); break;
1794 case 270: label->SetSpinStyle( aLabel->rot.value().mirror ? SPIN_STYLE::UP : SPIN_STYLE::BOTTOM ); break;
1795 default: label->SetSpinStyle( aLabel->rot.value().mirror ? SPIN_STYLE::LEFT : SPIN_STYLE::RIGHT ); break;
1796 }
1797 }
1798
1799 return label.release();
1800}
1801
1802
1803std::pair<VECTOR2I, const SEG*> SCH_IO_EAGLE::findNearestLinePoint( const VECTOR2I& aPoint,
1804 const std::vector<SEG>& aLines ) const
1805{
1806 VECTOR2I nearestPoint;
1807 const SEG* nearestLine = nullptr;
1808
1809 double d, mindistance = std::numeric_limits<double>::max();
1810
1811 // Project the label onto the closest wire. Snapping to the perpendicular foot keeps a
1812 // detached Eagle label at its position along the wire; snapping only to the wire's
1813 // endpoints or midpoint would slide it far along a long wire and pile parallel labels
1814 // onto the same point.
1815 for( const SEG& line : aLines )
1816 {
1817 VECTOR2I testpoint = line.NearestPoint( aPoint );
1818 d = aPoint.Distance( testpoint );
1819
1820 if( d < mindistance )
1821 {
1822 mindistance = d;
1823 nearestPoint = testpoint;
1824 nearestLine = &line;
1825 }
1826 }
1827
1828 return std::make_pair( nearestPoint, nearestLine );
1829}
1830
1831
1832void SCH_IO_EAGLE::loadInstance( const std::unique_ptr<EINSTANCE>& aInstance,
1833 const std::map<wxString, std::unique_ptr<EPART>>& aParts )
1834{
1835 wxCHECK( aInstance, /* void */ );
1836
1837 SCH_SCREEN* screen = getCurrentScreen();
1838
1839 wxCHECK( screen, /* void */ );
1840
1841 const auto partIt = aParts.find( aInstance->part );
1842
1843 if( partIt == aParts.end() )
1844 {
1845 Report( wxString::Format( _( "Error parsing Eagle file. Could not find '%s' "
1846 "instance but it is referenced in the schematic." ),
1847 aInstance->part ),
1849
1850 return;
1851 }
1852
1853 const std::unique_ptr<EPART>& epart = partIt->second;
1854
1855 wxString libName = epart->library;
1856
1857 // Correctly handle versioned libraries.
1858 if( epart->libraryUrn.has_value() )
1859 libName += wxS( "_" ) + epart->libraryUrn.value().assetId;
1860
1861 wxString gatename = epart->deviceset + wxS( "_" ) + epart->device + wxS( "_" ) + aInstance->gate;
1862 wxString symbolname = wxString( epart->deviceset + epart->device );
1863 wxString kiPackageName = epart->deviceset + epart->device;
1864
1865 if( epart->technology.has_value() )
1866 symbolname += epart->technology.value();
1867
1868 symbolname.Replace( wxT( "*" ), wxEmptyString );
1869 kiPackageName.Replace( wxT( "*" ), wxEmptyString );
1870
1871 wxString kisymbolname = EscapeString( symbolname, CTX_LIBID );
1872
1873 // Eagle schematics can have multiple libraries containing symbols with duplicate symbol
1874 // names. Because this parser stores all of the symbols in a single library, the
1875 // loadSymbol() function, prefixed the original Eagle library name to the symbol name
1876 // in case of a name clash. Check for the prefixed symbol first. This ensures that
1877 // the correct library symbol gets mapped on load.
1878 wxString altSymbolName = libName + wxT( "_" ) + symbolname;
1879 altSymbolName = EscapeString( altSymbolName, CTX_LIBID );
1880
1881 wxString libIdSymbolName = altSymbolName;
1882
1883 const auto libIt = m_eagleLibs.find( libName );
1884
1885 if( libIt == m_eagleLibs.end() )
1886 {
1887 Report( wxString::Format( wxS( "Eagle library '%s' not found while looking up symbol for "
1888 "deviceset '%s', device '%s', and gate '%s." ),
1889 libName, epart->deviceset, epart->device, aInstance->gate ) );
1890 return;
1891 }
1892
1893 const auto gateIt = libIt->second.GateToUnitMap.find( gatename );
1894
1895 if( gateIt == libIt->second.GateToUnitMap.end() )
1896 {
1897 Report( wxString::Format( wxS( "Symbol not found for deviceset '%s', device '%s', and "
1898 "gate '%s in library '%s'." ),
1899 epart->deviceset, epart->device, aInstance->gate, libName ) );
1900 return;
1901 }
1902
1903 int unit = gateIt->second;
1904
1905 wxString package;
1906 EAGLE_LIBRARY* elib = &m_eagleLibs[libName];
1907
1908 auto p = elib->package.find( kisymbolname );
1909
1910 if( p != elib->package.end() )
1911 {
1912 package = p->second;
1913 }
1914 else
1915 {
1916 p = elib->package.find( kiPackageName );
1917
1918 if( p != elib->package.end() )
1919 package = p->second;
1920 }
1921
1922 // set properties to prevent save file on every symbol save
1923 std::map<std::string, UTF8> properties;
1924 properties.emplace( SCH_IO_KICAD_SEXPR::PropBuffering, wxEmptyString );
1925
1926 LIB_SYMBOL* part = m_pi->LoadSymbol( getLibFileName().GetFullPath(), altSymbolName, &properties );
1927
1928 if( !part )
1929 {
1930 part = m_pi->LoadSymbol( getLibFileName().GetFullPath(), kisymbolname, &properties );
1931 libIdSymbolName = kisymbolname;
1932 }
1933
1934 if( !part )
1935 {
1936 Report( wxString::Format( _( "Could not find '%s' in the imported library." ),
1937 UnescapeString( kisymbolname ) ),
1939 return;
1940 }
1941
1942 LIB_ID libId( getLibName(), libIdSymbolName );
1943 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1944 symbol->SetLibId( libId );
1945 symbol->SetUnit( unit );
1946 symbol->SetPosition( VECTOR2I( aInstance->x.ToSchUnits(), -aInstance->y.ToSchUnits() ) );
1947
1948 // assume that footprint library is identical to project name
1949 if( !package.IsEmpty() )
1950 {
1951 wxString footprint = m_schematic->Project().GetProjectName() + wxT( ":" ) + package;
1952 symbol->GetField( FIELD_T::FOOTPRINT )->SetText( footprint );
1953 }
1954
1955 if( aInstance->rot.has_value() )
1956 {
1957 symbol->SetOrientation( kiCadComponentRotation( aInstance->rot.value().degrees ) );
1958
1959 if( aInstance->rot.value().mirror )
1960 symbol->MirrorHorizontally( aInstance->x.ToSchUnits() );
1961 }
1962
1963 std::vector<SCH_FIELD*> partFields;
1964 part->GetFields( partFields );
1965
1966 VECTOR2I nextFieldPosition = getLastSymbolFieldPosition( part ) + symbol->GetPosition();
1967
1968 for( const SCH_FIELD* partField : partFields )
1969 {
1970 SCH_FIELD* symbolField = nullptr;
1971
1972 if( partField->IsMandatory() )
1973 symbolField = symbol->GetField( partField->GetId() );
1974 else
1975 symbolField = symbol->GetField( partField->GetName() );
1976
1977 if( !symbolField )
1978 {
1979 SCH_FIELD newField( symbol.get(), FIELD_T::USER, partField->GetName() );
1980
1981 newField.SetVisible( false );
1982 newField.SetText( partField->GetText() );
1983
1984 nextFieldPosition.y += newField.GetTextHeight() + schIUScale.MilsToIU( 10 );
1985 newField.SetPosition( nextFieldPosition );
1986 symbol->AddField( newField );
1987 }
1988 else
1989 {
1990 symbolField->ImportValues( *partField );
1991 symbolField->SetTextPos( symbol->GetPosition() + partField->GetTextPos() );
1992 }
1993 }
1994
1995 wxString reference = aInstance->part;
1996 bool referenceVisible = !reference.IsEmpty();
1997
1998 // If there is no footprint assigned, then prepend the reference value
1999 // with a hash character to mute netlist updater complaints
2000 if( package.IsEmpty() )
2001 reference.Prepend( '#' );
2002
2003 // reference must end with a number but EAGLE does not enforce this
2004 if( reference.find_last_not_of( wxT( "0123456789" ) ) == ( reference.Length()-1 ) )
2005 reference.Append( wxT( "0" ) );
2006
2007 // EAGLE allows references to be single digits. This breaks KiCad netlisting, which requires
2008 // parts to have non-digit + digit annotation. If the reference begins with a number,
2009 // we prepend 'UNK' (unknown) for the symbol designator
2010 if( reference.find_first_not_of( wxT( "0123456789" ) ) != 0 )
2011 reference.Prepend( wxT( "UNK" ) );
2012
2013 // EAGLE allows designator to start with # but that is used in KiCad
2014 // for symbols which do not have a footprint
2015 if( aInstance->part.find_first_not_of( wxT( "#" ) ) != 0 )
2016 reference.Prepend( wxT( "UNK" ) );
2017
2018 SCH_FIELD* referenceField = symbol->GetField( FIELD_T::REFERENCE );
2019 referenceField->SetVisible( referenceVisible );
2020 referenceField->SetText( reference );
2021
2022 SCH_FIELD* valueField = symbol->GetField( FIELD_T::VALUE );
2023 bool userValue = m_userValue.at( libIdSymbolName );
2024
2025 if( part->GetUnitCount() > 1 )
2026 {
2027 getEagleSymbolFieldAttributes( aInstance, wxS( ">NAME" ), referenceField );
2028 getEagleSymbolFieldAttributes( aInstance, wxS( ">VALUE" ), valueField );
2029 }
2030
2031 if( epart->value.has_value() && !epart->value.value().IsEmpty() )
2032 {
2033 valueField->SetText( epart->value.value() );
2034 }
2035 else
2036 {
2037 valueField->SetText( kisymbolname );
2038
2039 if( userValue )
2040 valueField->SetVisible( false );
2041 }
2042
2043 for( const auto& [ attrName, attr ] : epart->attributes )
2044 {
2045 SCH_FIELD newField( symbol.get(), FIELD_T::USER );
2046
2047 newField.SetName( attrName );
2048
2049 if( !symbol->GetFields().empty() )
2050 newField.SetTextPos( symbol->GetFields().back().GetPosition() );
2051
2052 if( attr->value.has_value() )
2053 newField.SetText( attr->value.value() );
2054
2055 if( attr->display.has_value() && attr->display.value() == EATTR::Off )
2056 newField.SetVisible( false );
2057
2058 symbol->AddField( newField );
2059 }
2060
2061 bool valueAttributeFound = false;
2062 bool nameAttributeFound = false;
2063
2064 // Parse attributes for the instance
2065 for( auto& [name, eattr] : aInstance->attributes )
2066 {
2067 SCH_FIELD* field = nullptr;
2068
2069 if( eattr->name.Lower() == wxT( "name" ) )
2070 {
2071 field = symbol->GetField( FIELD_T::REFERENCE );
2072 nameAttributeFound = true;
2073 }
2074 else if( eattr->name.Lower() == wxT( "value" ) )
2075 {
2076 field = symbol->GetField( FIELD_T::VALUE );
2077 valueAttributeFound = true;
2078 }
2079 else
2080 {
2081 field = symbol->GetField( eattr->name );
2082 }
2083
2084 if( field )
2085 {
2086 field->SetVisible( true );
2087 field->SetPosition( VECTOR2I( eattr->x->ToSchUnits(), -eattr->y->ToSchUnits() ) );
2088
2089 if( eattr->size.has_value() )
2090 field->SetTextSize( ConvertEagleTextSize( eattr->font, eattr->size.value() ) );
2091
2092 int align = eattr->align.value_or( ETEXT::BOTTOM_LEFT );
2093 int absdegrees = eattr->rot.has_value() ? KiROUND( eattr->rot.value().degrees ) : 0;
2094 bool mirror = eattr->rot.has_value() ? eattr->rot.value().mirror : false;
2095 bool spin = eattr->rot.has_value() ? eattr->rot.value().spin : false;
2096
2097 if( aInstance->rot.has_value() && aInstance->rot.value().mirror )
2098 mirror = !mirror;
2099
2100 if( eattr->display.has_value() && ( eattr->display.value() == EATTR::Off
2101 || eattr->display.value() == EATTR::NAME ) )
2102 {
2103 field->SetVisible( false );
2104 }
2105
2106 int rotation = aInstance->rot.has_value() ? KiROUND( aInstance->rot.value().degrees ) : 0;
2107 int reldegrees = KiROUND( absdegrees - rotation + 360.0 );
2108 reldegrees %= 360;
2109
2110 eagleToKicadAlignment( field, align, reldegrees, mirror, spin, absdegrees );
2111 }
2112 }
2113
2114 // Use the instance attribute to determine the reference and value field visibility.
2115 if( aInstance->smashed.has_value() && aInstance->smashed.value() )
2116 {
2117 symbol->GetField( FIELD_T::VALUE )->SetVisible( valueAttributeFound );
2118 symbol->GetField( FIELD_T::REFERENCE )->SetVisible( nameAttributeFound );
2119 }
2120
2121 // Eagle has a brain dead module reference scheme where the module names separated by colons
2122 // are prefixed to the symbol references. This will get blown away in KiCad the first time
2123 // any annotation is performed. It is required for the initial synchronization between the
2124 // schematic and the board.
2125 wxString refPrefix;
2126
2127 for( const EMODULEINST* emoduleInst : m_moduleInstances )
2128 {
2129 wxCHECK2( emoduleInst, continue );
2130
2131 refPrefix += emoduleInst->name + wxS( ":" );
2132 }
2133
2134 symbol->AddHierarchicalReference( m_sheetPath.Path(), refPrefix + reference, unit );
2135
2136 // Cache the lib symbol so pin positions are available for connection-point tracking.
2137 // Use the already-loaded `part` directly rather than re-fetching through the adapter,
2138 // because the .kicad_sym library is still buffered in m_pi and has not yet been saved to
2139 // disk at the time loadInstance runs.
2140 symbol->SetLibSymbol( part->Flatten().release() );
2141
2142 for( const auto& [name, variant] : epart->variants )
2143 {
2144 SCH_SYMBOL_VARIANT symbolVariant( name );
2145
2146 if( variant->populate.has_value() && variant->populate.value() == false )
2147 symbolVariant.m_DNP = true;
2148
2149 if( variant->value )
2150 symbolVariant.m_Fields[GetDefaultFieldName( FIELD_T::VALUE, UNTRANSLATED )] = *variant->value;
2151
2152 if( variant->technology.has_value() )
2153 {
2154 auto eLibIt = m_eagleDoc->drawing->schematic->libraries.find( epart->library );
2155
2156 if( eLibIt == m_eagleDoc->drawing->schematic->libraries.end() )
2157 {
2158 Report( wxString::Format( wxS( "Library '%s' not found in schematic." ), epart->library ) );
2159 continue;
2160 }
2161
2162 auto eDeviceSetIt = eLibIt->second->devicesets.find( epart->deviceset );
2163
2164 if( eDeviceSetIt == eLibIt->second->devicesets.end() )
2165 {
2166 Report( wxString::Format( wxS( "Device set '%s' not found in library '%s'." ),
2167 epart->deviceset,
2168 epart->library ) );
2169 continue;
2170 }
2171
2172 auto eDeviceIt = eDeviceSetIt->second->devices.find( epart->device );
2173
2174 if( eDeviceIt == eDeviceSetIt->second->devices.end() )
2175 {
2176 Report( wxString::Format( wxS( "Device '%s' not found in device set '%s' in library '%s'." ),
2177 epart->device,
2178 epart->deviceset,
2179 epart->library ) );
2180 continue;
2181 }
2182
2183 auto eTechnologyIt = eDeviceIt->second->technologies.find( variant->technology.value() );
2184
2185 if( eTechnologyIt == eDeviceIt->second->technologies.end() )
2186 {
2187 Report( wxString::Format( wxS( "Technology '%s' not found in device '%s' in device set '%s' "
2188 "in library '%s'." ),
2189 variant->technology.value(),
2190 epart->device,
2191 epart->deviceset,
2192 epart->library ) );
2193 continue;
2194 }
2195
2196 for( const std::unique_ptr<EATTR>& attr : eTechnologyIt->second->attributes )
2197 {
2198 wxString attrValue;
2199
2200 if( attr->value.has_value() )
2201 attrValue = attr->value.value();
2202
2203 symbolVariant.m_Fields[attr->name] = attrValue;
2204 }
2205 }
2206
2207 symbol->AddVariant( m_sheetPath, symbolVariant );
2208 }
2209
2210 for( const SCH_PIN* pin : symbol->GetLibPins() )
2211 m_connPoints[symbol->GetPinPhysicalPosition( pin )].emplace( pin );
2212
2213 if( part->IsGlobalPower() )
2214 m_powerPorts[ reference ] = symbol->GetField( FIELD_T::VALUE )->GetText();
2215
2216 symbol->ClearFlags();
2217
2218 screen->Append( symbol.release() );
2219}
2220
2221
2223{
2224 wxCHECK( aLibrary && aEagleLibrary, nullptr );
2226
2227 // Loop through the device sets and load each of them
2228 for( const auto& [name, edeviceset] : aLibrary->devicesets )
2229 {
2230 // Get Device set information
2231 wxString prefix = edeviceset->prefix.value_or( wxEmptyString );
2232 wxString deviceSetDescr;
2233
2234 if( edeviceset->description )
2235 deviceSetDescr = convertDescription( UnescapeHTML( edeviceset->description->text ) );
2236
2237 // For each device in the device set:
2238 for( const auto& [devname, edevice] : edeviceset->devices )
2239 {
2240 std::vector<std::unique_ptr<LIB_SYMBOL>> derivedSymbols;
2241
2242 // Create symbol name from deviceset and device names.
2243 wxString symbolName = edeviceset->name + edevice->name;
2244 symbolName.Replace( wxT( "*" ), wxEmptyString );
2245 wxASSERT( !symbolName.IsEmpty() );
2246 symbolName = EscapeString( symbolName, CTX_LIBID );
2247
2248 if( edevice->package.has_value() )
2249 aEagleLibrary->package[symbolName] = edevice->package.value();
2250
2251 // Create KiCad symbol.
2252 std::unique_ptr<LIB_SYMBOL> libSymbol = std::make_unique<LIB_SYMBOL>( symbolName );
2253
2254 // Process each gate in the deviceset for this device.
2255 int gate_count = static_cast<int>( edeviceset->gates.size() );
2256
2257 if( gate_count > 1 )
2258 libSymbol->SetUnitCount( gate_count, true );
2259
2260 libSymbol->LockUnits( true );
2261
2262 SCH_FIELD* reference = libSymbol->GetField( FIELD_T::REFERENCE );
2263
2264 if( prefix.length() == 0 )
2265 {
2266 reference->SetVisible( false );
2267 }
2268 else
2269 {
2270 // If there is no footprint assigned, then prepend the reference value
2271 // with a hash character to mute netlist updater complaints
2272 reference->SetText( edevice->package.has_value() ? prefix : '#' + prefix );
2273 }
2274
2275 libSymbol->GetValueField().SetVisible( true );
2276
2277 int gateindex = 1;
2278 bool ispower = false;
2279
2280 for( const auto& [gateName, egate] : edeviceset->gates )
2281 {
2282 const auto it = aLibrary->symbols.find( egate->symbol );
2283
2284 if( it == aLibrary->symbols.end() )
2285 {
2286 Report( wxString::Format( wxS( "Eagle symbol '%s' not found in library '%s'." ),
2287 egate->symbol,
2288 aLibrary->GetName() ) );
2289 continue;
2290 }
2291
2292 wxString gateMapName = edeviceset->name + wxS( "_" ) + edevice->name + wxS( "_" ) + egate->name;
2293 aEagleLibrary->GateToUnitMap[gateMapName] = gateindex;
2294 ispower = loadSymbol( it->second, libSymbol, edevice, gateindex, egate->name );
2295
2296 gateindex++;
2297 }
2298
2299 std::vector<SCH_FIELD*> fields;
2300 libSymbol->GetFields( fields );
2301
2302 for( SCH_FIELD* field : fields )
2303 field->SetCanAutoplace( canAutoplace );
2304
2305 for( const auto& [techname, technology ] : edevice->technologies )
2306 {
2307 std::unique_ptr<LIB_SYMBOL> derivedSymbol;
2308 VECTOR2I nextFieldPosition = getLastSymbolFieldPosition( libSymbol.get() );
2309
2310 if( !technology->name.IsEmpty() )
2311 {
2312 derivedSymbol = std::make_unique<LIB_SYMBOL>( symbolName + technology->name, libSymbol.get() );
2313
2314 for( SCH_FIELD* parentField : fields )
2315 {
2316 SCH_FIELD* childField = derivedSymbol->GetField( parentField->GetName() );
2317
2318 if( childField )
2319 {
2320 childField->SetAttributes( *parentField );
2321 childField->SetCanAutoplace( canAutoplace );
2322 }
2323 }
2324 }
2325
2326 for( const std::unique_ptr<EATTR>& attr : technology->attributes )
2327 {
2328 if( !attr->value.has_value() )
2329 continue;
2330
2331 SCH_FIELD* field = nullptr;
2332
2333 if( !derivedSymbol )
2334 field = libSymbol->FindFieldCaseInsensitive( attr->name );
2335 else
2336 field = derivedSymbol->FindFieldCaseInsensitive( attr->name );
2337
2338 if( field )
2339 {
2340 field->SetText( attr->value.value() );
2341 }
2342 else
2343 {
2344 SCH_FIELD* newField = new SCH_FIELD( derivedSymbol ? derivedSymbol.get() : libSymbol.get(),
2345 FIELD_T::USER, attr->name );
2346
2347 if( derivedSymbol )
2348 {
2349 SCH_FIELD* parentField = libSymbol->FindFieldCaseInsensitive( attr->name );
2350
2351 if( parentField )
2352 newField->SetAttributes( *parentField );
2353 }
2354
2355 nextFieldPosition.y += newField->GetTextHeight() + schIUScale.MilsToIU( 10 );
2356 newField->SetText( attr->value.value() );
2357 newField->SetVisible( false );
2358 newField->SetPosition( nextFieldPosition );
2359 newField->SetCanAutoplace( canAutoplace );
2360
2361 if( !derivedSymbol )
2362 libSymbol->AddField( newField );
2363 else
2364 derivedSymbol->AddField( newField );
2365 }
2366 }
2367
2368 if( derivedSymbol )
2369 derivedSymbols.push_back( std::move( derivedSymbol ) );
2370 }
2371
2372 if( gate_count > 1 )
2373 libSymbol->SetUnitCount( gate_count, true );
2374
2375 if( gate_count == 1 && ispower )
2376 libSymbol->SetGlobalPower();
2377
2378 // Don't set the footprint field if no package is defined in the Eagle schematic.
2379 if( edevice->package.has_value() && !edevice->package.value().IsEmpty() )
2380 {
2381 wxString libName;
2382
2383 if( m_schematic )
2384 {
2385 // assume that footprint library is identical to project name
2386 libName = m_schematic->Project().GetProjectName();
2387 }
2388 else
2389 {
2390 libName = m_libName;
2391 }
2392
2393 wxString packageString = libName + wxT( ":" ) + aEagleLibrary->package[symbolName];
2394
2395 libSymbol->GetFootprintField().SetText( packageString );
2396 }
2397
2398 wxString libName = libSymbol->GetName();
2399 libSymbol->SetName( libName );
2400 libSymbol->SetDescription( deviceSetDescr );
2401
2402 if( m_pi )
2403 {
2404 // If duplicate symbol names exist in multiple Eagle symbol libraries, prefix the
2405 // Eagle symbol library name to the symbol which should ensure that it is unique.
2406 try
2407 {
2408 if( m_pi->LoadSymbol( getLibFileName().GetFullPath(), libName ) )
2409 {
2410 libName = aEagleLibrary->name + wxT( "_" ) + libName;
2411 libName = EscapeString( libName, CTX_LIBID );
2412 libSymbol->SetName( libName );
2413 }
2414
2415 // set properties to prevent save file on every symbol save
2416 std::map<std::string, UTF8> properties;
2417 properties.emplace( SCH_IO_KICAD_SEXPR::PropBuffering, wxEmptyString );
2418
2419
2420 std::unique_ptr<LIB_SYMBOL> parentSymbol = std::make_unique<LIB_SYMBOL>( *libSymbol );
2421
2422 m_pi->SaveSymbol( getLibFileName().GetFullPath(), std::move( parentSymbol ),
2423 &properties );
2424
2425 // The plugin cache owns the parent symbol after the save, we cannot use it
2426 // safely after handing it to the plugin.
2427 // Borrow the parent symbol from the plugin cache.
2428 LIB_SYMBOL* parent = m_pi->LoadSymbol( getLibFileName().GetFullPath(), libSymbol->GetName() );
2429
2430 if( !parent )
2431 {
2432 Report( wxString::Format( _( "Could not reload saved symbol '%s'" ),
2433 UnescapeString( libSymbol->GetName() ) ),
2435 }
2436 else
2437 {
2438 for( std::unique_ptr<LIB_SYMBOL>& symbol : derivedSymbols )
2439 {
2440 if( m_pi->LoadSymbol( getLibFileName().GetFullPath(), symbol->GetName() ) )
2441 {
2442 wxString tmp = aEagleLibrary->name + wxT( "_" ) + symbol->GetName();
2443 tmp = EscapeString( tmp, CTX_LIBID );
2444 symbol->SetName( tmp );
2445 }
2446
2447 std::unique_ptr<LIB_SYMBOL> derivedSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
2448
2449 derivedSymbol->SetParent( parent );
2450 m_pi->SaveSymbol( getLibFileName().GetFullPath(), std::move( derivedSymbol ), &properties );
2451 }
2452 }
2453 }
2454 catch(...)
2455 {
2456 // A library symbol cannot be loaded for some reason.
2457 // Just skip this symbol creating an issue.
2458 // The issue will be reported later by the Reporter
2459 }
2460 }
2461
2462 aEagleLibrary->KiCadSymbols[ libName ] = std::move( libSymbol );
2463
2464 // Store information on whether the value of FIELD_T::VALUE for a part should be
2465 // part/@value or part/@deviceset + part/@device.
2466 m_userValue.emplace( std::make_pair( libName, edeviceset->uservalue.value_or( false ) ) );
2467
2468 for( std::unique_ptr<LIB_SYMBOL>& symbol : derivedSymbols )
2469 {
2470 m_userValue.emplace( std::make_pair( symbol->GetName(), edeviceset->uservalue.value_or( false ) ) );
2471 aEagleLibrary->KiCadSymbols[symbol->GetName()] = std::move( symbol );
2472 }
2473 }
2474 }
2475
2476 return aEagleLibrary;
2477}
2478
2479
2480bool SCH_IO_EAGLE::loadSymbol( const std::unique_ptr<ESYMBOL>& aEsymbol, std::unique_ptr<LIB_SYMBOL>& aSymbol,
2481 const std::unique_ptr<EDEVICE>& aDevice, int aGateNumber, const wxString& aGateName )
2482{
2483 wxCHECK( aEsymbol && aSymbol && aDevice, false );
2484
2485 std::vector<SCH_ITEM*> items;
2486
2487 bool showRefDes = false;
2488 bool showValue = false;
2489 bool ispower = false;
2490 int pincount = 0;
2491
2492 for( const std::unique_ptr<ECIRCLE>& ecircle : aEsymbol->circles )
2493 aSymbol->AddDrawItem( loadSymbolCircle( aSymbol, ecircle, aGateNumber ) );
2494
2495 for( const std::unique_ptr<EPIN>& epin : aEsymbol->pins )
2496 {
2497 std::unique_ptr<SCH_PIN> pin( loadPin( aSymbol, epin, aGateNumber ) );
2498 pincount++;
2499
2500 pin->SetType( ELECTRICAL_PINTYPE::PT_BIDI );
2501
2502 if( epin->direction.has_value() )
2503 {
2504 for( const auto& pinDir : pinDirectionsMap )
2505 {
2506 if( epin->direction.value().Lower() == pinDir.first )
2507 {
2508 pin->SetType( pinDir.second );
2509
2510 if( pinDir.first == wxT( "sup" ) ) // power supply symbol
2511 ispower = true;
2512
2513 break;
2514 }
2515 }
2516 }
2517
2518 if( aDevice->connects.size() != 0 )
2519 {
2520 for( const std::unique_ptr<ECONNECT>& connect : aDevice->connects )
2521 {
2522 // Eagle <connect> references the full pin name including any "@<tag>"
2523 // linking hint, so match against the raw Eagle name rather than the
2524 // stripped display name set on the pin.
2525 if( connect->gate == aGateName && epin->name == connect->pin )
2526 {
2527 wxArrayString pads = wxSplit( wxString( connect->pad ), ' ' );
2528
2529 pin->SetUnit( aGateNumber );
2530 pin->SetName( escapeName( pin->GetName() ) );
2531
2532 if( pads.GetCount() > 1 )
2533 {
2534 pin->SetNumberTextSize( 0 );
2535 }
2536
2537 for( unsigned i = 0; i < pads.GetCount(); i++ )
2538 {
2539 SCH_PIN* apin = new SCH_PIN( *pin );
2540
2541 wxString padname( pads[i] );
2542 apin->SetNumber( padname );
2543 aSymbol->AddDrawItem( apin );
2544 }
2545
2546 break;
2547 }
2548 }
2549 }
2550 else
2551 {
2552 pin->SetUnit( aGateNumber );
2553 pin->SetNumber( wxString::Format( wxT( "%i" ), pincount ) );
2554 aSymbol->AddDrawItem( pin.release() );
2555 }
2556 }
2557
2558 for( const std::unique_ptr<EPOLYGON>& epolygon : aEsymbol->polygons )
2559 {
2560 if( SCH_SHAPE* shape = loadSymbolPolyLine( aSymbol, epolygon, aGateNumber ) )
2561 aSymbol->AddDrawItem( shape );
2562 }
2563
2564 for( const std::unique_ptr<ERECT>& erectangle : aEsymbol->rectangles )
2565 aSymbol->AddDrawItem( loadSymbolRectangle( aSymbol, erectangle, aGateNumber ) );
2566
2567 for( const std::unique_ptr<ETEXT>& etext : aEsymbol->texts )
2568 {
2569 std::unique_ptr<SCH_TEXT> libtext( loadSymbolText( aSymbol, etext, aGateNumber ) );
2570
2571 if( libtext->GetText() == wxT( "${REFERENCE}" ) )
2572 {
2573 // Keep the deviceset prefix because the Eagle text is only a placeholder
2574 aSymbol->GetReferenceField().SetAttributes( *libtext );
2575
2576 // Show Reference field if Eagle reference was uppercase
2577 showRefDes = etext->text == wxT( ">NAME" );
2578 }
2579 else if( libtext->GetText() == wxT( "${VALUE}" ) )
2580 {
2581 // Keep the field value because the Eagle text is only a placeholder
2582 aSymbol->GetValueField().SetAttributes( *libtext );
2583
2584 // Show Value field if Eagle reference was uppercase
2585 showValue = etext->text == wxT( ">VALUE" );
2586 }
2587 else if( etext->text.StartsWith( ">" ) )
2588 {
2589 // Text values that start with '>' are place holders for fields defined later
2590 // in library deviceset objects.
2591 wxString fieldName = etext->text.Mid( 1 );
2592
2593 if( !fieldName.IsEmpty() )
2594 {
2595 SCH_FIELD* field = new SCH_FIELD( aSymbol.get(), FIELD_T::USER, fieldName );
2596
2597 field->SetAttributes( *libtext );
2598
2599 // Field visibility is determined by the symbol instance attributes.
2600 field->SetVisible( false );
2601 aSymbol->AddField( field );
2602 }
2603 }
2604 else
2605 {
2606 aSymbol->AddDrawItem( libtext.release() );
2607 }
2608 }
2609
2610 for( const std::unique_ptr<EWIRE>& ewire : aEsymbol->wires )
2611 aSymbol->AddDrawItem( loadSymbolWire( aSymbol, ewire, aGateNumber ) );
2612
2613 for( const std::unique_ptr<EFRAME>& eframe : aEsymbol->frames )
2614 {
2615 std::vector<SCH_ITEM*> frameItems;
2616
2617 loadFrame( eframe, frameItems );
2618
2619 for( SCH_ITEM* item : frameItems )
2620 {
2621 item->SetParent( aSymbol.get() );
2622 item->SetUnit( aGateNumber );
2623 aSymbol->AddDrawItem( item );
2624 }
2625 }
2626
2627 aSymbol->GetReferenceField().SetVisible( showRefDes );
2628 aSymbol->GetValueField().SetVisible( showValue );
2629
2630 return pincount == 1 ? ispower : false;
2631}
2632
2633
2634SCH_SHAPE* SCH_IO_EAGLE::loadSymbolCircle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
2635 const std::unique_ptr<ECIRCLE>& aCircle, int aGateNumber )
2636{
2637 wxCHECK( aSymbol && aCircle, nullptr );
2638
2639 // Parse the circle properties
2641 VECTOR2I center( aCircle->x.ToSchUnits(), -aCircle->y.ToSchUnits() );
2642
2643 circle->SetParent( aSymbol.get() );
2644 circle->SetPosition( center );
2645 circle->SetEnd( VECTOR2I( center.x + aCircle->radius.ToSchUnits(), center.y ) );
2646
2647 if( aCircle->width.ToSchUnits() == 0 )
2648 {
2649 circle->SetStroke( STROKE_PARAMS( -1, LINE_STYLE::SOLID ) );
2650 circle->SetFillMode( FILL_T::FILLED_SHAPE );
2651 }
2652 else
2653 {
2654 circle->SetStroke( STROKE_PARAMS( aCircle->width.ToSchUnits(), LINE_STYLE::SOLID ) );
2655 }
2656
2657 if( aSymbol->IsMultiUnit() )
2658 circle->SetUnit( aGateNumber );
2659
2660 return circle;
2661}
2662
2663
2664SCH_SHAPE* SCH_IO_EAGLE::loadSymbolRectangle( std::unique_ptr<LIB_SYMBOL>& aSymbol,
2665 const std::unique_ptr<ERECT>& aRectangle, int aGateNumber )
2666{
2667 wxCHECK( aSymbol && aRectangle, nullptr );
2668
2670
2671 rectangle->SetParent( aSymbol.get() );
2672 rectangle->SetPosition( VECTOR2I( aRectangle->x1.ToSchUnits(), -aRectangle->y1.ToSchUnits() ) );
2673 rectangle->SetEnd( VECTOR2I( aRectangle->x2.ToSchUnits(), -aRectangle->y2.ToSchUnits() ) );
2674
2675 if( aRectangle->rot.has_value() )
2676 {
2677 VECTOR2I pos( rectangle->GetPosition() );
2678 VECTOR2I end( rectangle->GetEnd() );
2679 VECTOR2I center( rectangle->GetCenter() );
2680
2681 RotatePoint( pos, center, EDA_ANGLE( aRectangle->rot.value().degrees, DEGREES_T ) );
2682 RotatePoint( end, center, EDA_ANGLE( aRectangle->rot.value().degrees, DEGREES_T ) );
2683
2684 rectangle->SetPosition( pos );
2685 rectangle->SetEnd( end );
2686 }
2687
2688 if( aSymbol->IsMultiUnit() )
2689 rectangle->SetUnit( aGateNumber );
2690
2691 // Eagle rectangles are filled and have vanishing line width by definition.
2692 rectangle->SetFillMode( FILL_T::FILLED_SHAPE );
2693 rectangle->SetWidth( -1 );
2694
2695 return rectangle;
2696}
2697
2698
2699SCH_ITEM* SCH_IO_EAGLE::loadSymbolWire( std::unique_ptr<LIB_SYMBOL>& aSymbol,
2700 const std::unique_ptr<EWIRE>& aWire, int aGateNumber )
2701{
2702 wxCHECK( aSymbol && aWire, nullptr );
2703
2704 VECTOR2I begin, end;
2705
2706 begin.x = aWire->x1.ToSchUnits();
2707 begin.y = -aWire->y1.ToSchUnits();
2708 end.x = aWire->x2.ToSchUnits();
2709 end.y = -aWire->y2.ToSchUnits();
2710
2711 if( begin == end )
2712 return nullptr;
2713
2714 // if the wire is an arc
2715 if( aWire->curve )
2716 {
2718 VECTOR2I center = ConvertArcCenter( begin, end, *aWire->curve );
2719 double radius = sqrt( ( ( center.x - begin.x ) * ( center.x - begin.x ) ) +
2720 ( ( center.y - begin.y ) * ( center.y - begin.y ) ) );
2721
2722 arc->SetParent( aSymbol.get() );
2723
2724 // this emulates the filled semicircles created by a thick arc with flat ends caps.
2725 if( aWire->cap.has_value() && aWire->cap.value() == EWIRE::FLAT && aWire->width.ToSchUnits() >= 2 * radius )
2726 {
2727 VECTOR2I centerStartVector = ( begin - center ) * ( aWire->width.ToSchUnits() / radius );
2728 begin = center + centerStartVector;
2729
2732 }
2733 else
2734 {
2735 arc->SetStroke( STROKE_PARAMS( aWire->width.ToSchUnits(), LINE_STYLE::SOLID ) );
2736 }
2737
2738 arc->SetCenter( center );
2739 arc->SetStart( begin );
2740
2741 // KiCad rotates the other way.
2742 arc->SetArcAngleAndEnd( -EDA_ANGLE( *aWire->curve, DEGREES_T ), true );
2743
2744 if( aSymbol->IsMultiUnit() )
2745 arc->SetUnit( aGateNumber );
2746
2747 return arc;
2748 }
2749 else
2750 {
2752
2753 poly->AddPoint( begin );
2754 poly->AddPoint( end );
2755
2756 if( aSymbol->IsMultiUnit() )
2757 poly->SetUnit( aGateNumber );
2758
2759 poly->SetStroke( STROKE_PARAMS( aWire->width.ToSchUnits(), LINE_STYLE::SOLID ) );
2760
2761 return poly;
2762 }
2763}
2764
2765
2766SCH_SHAPE* SCH_IO_EAGLE::loadSymbolPolyLine( std::unique_ptr<LIB_SYMBOL>& aSymbol,
2767 const std::unique_ptr<EPOLYGON>& aPolygon, int aGateNumber )
2768{
2769 wxCHECK( aSymbol && aPolygon, nullptr );
2770
2771 if( !aPolygon->IsValidOutline() )
2772 return nullptr;
2773
2775 VECTOR2I pt;
2776 VECTOR2I prev_pt;
2777 std::optional<double> prev_curve;
2778 std::optional<VECTOR2I> first_pt;
2779
2780 poly->SetParent( aSymbol.get() );
2781
2782 for( const std::unique_ptr<EVERTEX>& evertex : aPolygon->vertices )
2783 {
2784 pt = VECTOR2I( evertex->x.ToSchUnits(), -evertex->y.ToSchUnits() );
2785
2786 if( !first_pt.has_value() )
2787 first_pt = pt;
2788
2789 if( prev_curve.has_value() )
2790 {
2791 SHAPE_ARC arc;
2792 arc.ConstructFromStartEndAngle( prev_pt, pt, -EDA_ANGLE( prev_curve.value(), DEGREES_T ) );
2793 poly->GetPolyShape().Append( arc, -1, -1, ARC_ACCURACY );
2794 }
2795 else
2796 {
2797 poly->AddPoint( pt );
2798 }
2799
2800 prev_pt = pt;
2801 prev_curve = evertex->curve;
2802 }
2803
2804 if( first_pt.has_value() )
2805 poly->AddPoint( first_pt.value() );
2806
2807 poly->SetStroke( STROKE_PARAMS( aPolygon->width.ToSchUnits(), LINE_STYLE::SOLID ) );
2809
2810 if( aSymbol->IsMultiUnit() )
2811 poly->SetUnit( aGateNumber );
2812
2813 return poly;
2814}
2815
2816
2817SCH_PIN* SCH_IO_EAGLE::loadPin( std::unique_ptr<LIB_SYMBOL>& aSymbol,
2818 const std::unique_ptr<EPIN>& aPin, int aGateNumber )
2819{
2820 wxCHECK( aSymbol && aPin, nullptr );
2821
2822 std::unique_ptr<SCH_PIN> pin = std::make_unique<SCH_PIN>( aSymbol.get() );
2823 pin->SetPosition( VECTOR2I( aPin->x.ToSchUnits(), -aPin->y.ToSchUnits() ) );
2824
2825 // Eagle pin names may carry a trailing "@<tag>" linking hint that disambiguates
2826 // duplicate names within a symbol. It is metadata, not visible text, so strip it
2827 // from the displayed name. The full Eagle name is still used to match <connect>.
2828 pin->SetName( extractNetName( aPin->name ) );
2829
2830 if( aSymbol->IsMultiUnit() )
2831 pin->SetUnit( aGateNumber );
2832
2833 int roti = aPin->rot.has_value() ? KiROUND( aPin->rot.value().degrees ) : 0;
2834
2835 switch( roti )
2836 {
2837 case 0: pin->SetOrientation( PIN_ORIENTATION::PIN_RIGHT ); break;
2838 case 90: pin->SetOrientation( PIN_ORIENTATION::PIN_UP ); break;
2839 case 180: pin->SetOrientation( PIN_ORIENTATION::PIN_LEFT ); break;
2840 case 270: pin->SetOrientation( PIN_ORIENTATION::PIN_DOWN ); break;
2841 default: wxFAIL_MSG( wxString::Format( wxT( "Unhandled orientation (%d degrees)." ), roti ) );
2842 }
2843
2844 pin->SetLength( schIUScale.MilsToIU( 300 ) ); // Default pin length when not defined.
2845
2846 if( aPin->length.has_value() )
2847 {
2848 if( aPin->length.value() == wxT( "short" ) )
2849 pin->SetLength( schIUScale.MilsToIU( 100 ) );
2850 else if( aPin->length.value() == wxT( "middle" ) )
2851 pin->SetLength( schIUScale.MilsToIU( 200 ) );
2852 else if( aPin->length.value() == wxT( "long" ) )
2853 pin->SetLength( schIUScale.MilsToIU( 300 ) );
2854 else if( aPin->length.value() == wxT( "point" ) )
2855 pin->SetLength( schIUScale.MilsToIU( 0 ) );
2856 }
2857
2858 // Pin names and numbers are fixed size in Eagle.
2859 pin->SetNumberTextSize( schIUScale.MilsToIU( 60 ) );
2860 pin->SetNameTextSize( schIUScale.MilsToIU( 60 ) );
2861
2862 // emulate the visibility of pin elements
2863 if( aPin->visible.has_value() )
2864 {
2865 if( aPin->visible.value() == wxT( "off" ) )
2866 {
2867 pin->SetNameTextSize( 0 );
2868 pin->SetNumberTextSize( 0 );
2869 }
2870 else if( aPin->visible.value() == wxT( "pad" ) )
2871 {
2872 pin->SetNameTextSize( 0 );
2873 }
2874 else if( aPin->visible.value() == wxT( "pin" ) )
2875 {
2876 pin->SetNumberTextSize( 0 );
2877 }
2878
2879 /*
2880 * else if( visible == wxT( "both" ) )
2881 * {
2882 * }
2883 */
2884 }
2885
2886 if( aPin->function.has_value() )
2887 {
2888 if( aPin->function.value() == wxT( "dot" ) )
2889 pin->SetShape( GRAPHIC_PINSHAPE::INVERTED );
2890 else if( aPin->function.value() == wxT( "clk" ) )
2891 pin->SetShape( GRAPHIC_PINSHAPE::CLOCK );
2892 else if( aPin->function.value() == wxT( "dotclk" ) )
2894 }
2895
2896 return pin.release();
2897}
2898
2899
2900SCH_TEXT* SCH_IO_EAGLE::loadSymbolText( std::unique_ptr<LIB_SYMBOL>& aSymbol,
2901 const std::unique_ptr<ETEXT>& aText, int aGateNumber )
2902{
2903 wxCHECK( aSymbol && aText, nullptr );
2904
2905 std::unique_ptr<SCH_TEXT> libtext = std::make_unique<SCH_TEXT>();
2906
2907 libtext->SetLayer( LAYER_DEVICE );
2908 libtext->SetParent( aSymbol.get() );
2909
2910 if( aSymbol->IsMultiUnit() )
2911 libtext->SetUnit( aGateNumber );
2912
2913 libtext->SetPosition( VECTOR2I( aText->x.ToSchUnits(), -aText->y.ToSchUnits() ) );
2914
2915 const wxString& eagleText = aText->text;
2916 wxString adjustedText;
2917 wxStringTokenizer tokenizer( eagleText, "\r\n" );
2918
2919 // Strip the whitespace from both ends of each line.
2920 while( tokenizer.HasMoreTokens() )
2921 {
2922 wxString tmp = interpretText( tokenizer.GetNextToken().Trim( true ).Trim( false ) );
2923
2924 if( tokenizer.HasMoreTokens() )
2925 tmp += wxT( "\n" );
2926
2927 adjustedText += tmp;
2928 }
2929
2930 libtext->SetText( adjustedText.IsEmpty() ? wxString( wxS( "~" ) ) : adjustedText );
2931
2932 loadTextAttributes( libtext.get(), aText );
2933
2934 return libtext.release();
2935}
2936
2937
2938SCH_TEXT* SCH_IO_EAGLE::loadPlainText( const std::unique_ptr<ETEXT>& aText )
2939{
2940 wxCHECK( aText, nullptr );
2941
2942 std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>();
2943
2944 const wxString& eagleText = aText->text;
2945 wxString adjustedText;
2946 wxStringTokenizer tokenizer( eagleText, "\r\n" );
2947
2948 // Strip the whitespace from both ends of each line.
2949 while( tokenizer.HasMoreTokens() )
2950 {
2951 wxString tmp = interpretText( tokenizer.GetNextToken().Trim( true ).Trim( false ) );
2952
2953 if( tokenizer.HasMoreTokens() )
2954 tmp += wxT( "\n" );
2955
2956 adjustedText += tmp;
2957 }
2958
2959 schtext->SetText( adjustedText.IsEmpty() ? wxString( wxS( "\" \"" ) )
2960 : escapeName( adjustedText ) );
2961
2962 schtext->SetPosition( VECTOR2I( aText->x.ToSchUnits(), -aText->y.ToSchUnits() ) );
2963 loadTextAttributes( schtext.get(), aText );
2964 schtext->SetItalic( false );
2965
2966 return schtext.release();
2967}
2968
2969
2970void SCH_IO_EAGLE::loadTextAttributes( EDA_TEXT* aText, const std::unique_ptr<ETEXT>& aAttributes ) const
2971{
2972 wxCHECK( aText && aAttributes, /* void */ );
2973
2974 aText->SetTextSize( aAttributes->ConvertSize() );
2975
2976 // Must come after SetTextSize()
2977 if( aAttributes->ratio.value_or( 8 ) > 12 )
2978 aText->SetBold( true );
2979
2980 int align = aAttributes->align.value_or( ETEXT::BOTTOM_LEFT );
2981 int degrees = aAttributes->rot.has_value() ? KiROUND( aAttributes->rot.value().degrees ) : 0;
2982 bool mirror = aAttributes->rot.has_value() ? aAttributes->rot.value().mirror : false;
2983 bool spin = aAttributes->rot.has_value() ? aAttributes->rot.value().spin : false;
2984
2985 eagleToKicadAlignment( aText, align, degrees, mirror, spin, 0 );
2986}
2987
2988
2990{
2991 // Eagle supports detached labels, so a label does not need to be placed on a wire
2992 // to be associated with it. KiCad needs to move them, so the labels actually touch the
2993 // corresponding wires.
2994
2995 // Sort the intersection points to speed up the search process
2996 std::sort( m_wireIntersections.begin(), m_wireIntersections.end() );
2997
2998 auto onIntersection =
2999 [&]( const VECTOR2I& aPos )
3000 {
3001 return std::binary_search( m_wireIntersections.begin(), m_wireIntersections.end(), aPos );
3002 };
3003
3004 for( SEG_DESC& segDesc : m_segments )
3005 {
3006 for( SCH_LABEL_BASE* label : segDesc.labels )
3007 {
3008 VECTOR2I labelPos( label->GetPosition() );
3009 const SEG* segAttached = segDesc.LabelAttached( label );
3010
3011 if( segAttached && !onIntersection( labelPos ) )
3012 continue; // label is placed correctly
3013
3014 // Move the label to the nearest wire
3015 if( !segAttached )
3016 {
3017 std::tie( labelPos, segAttached ) = findNearestLinePoint( label->GetPosition(), segDesc.segs );
3018
3019 if( !segAttached ) // we cannot do anything
3020 continue;
3021 }
3022
3023 // Create a vector pointing in the direction of the wire, 50 mils long
3024 VECTOR2I wireDirection( segAttached->B - segAttached->A );
3025
3026 if( ( wireDirection.x == 0 ) && (wireDirection.y == 0 ) )
3027 continue;
3028
3029 wireDirection = wireDirection.Resize( schIUScale.MilsToIU( 50 ) );
3030 const VECTOR2I origPos( labelPos );
3031
3032 // Flags determining the search direction
3033 bool checkPositive = true;
3034 bool checkNegative = true;
3035 bool move = false;
3036 int trial = 0;
3037
3038 // Be sure the label is not placed on a wire intersection
3039 while( ( !move || onIntersection( labelPos ) ) && ( checkPositive || checkNegative ) )
3040 {
3041 move = false;
3042
3043 // Move along the attached wire to find the new label position
3044 if( trial % 2 == 1 )
3045 {
3046 labelPos = VECTOR2I( origPos + wireDirection * trial / 2 );
3047 move = checkPositive = segAttached->Contains( labelPos );
3048 }
3049 else
3050 {
3051 labelPos = VECTOR2I( origPos - wireDirection * trial / 2 );
3052 move = checkNegative = segAttached->Contains( labelPos );
3053 }
3054
3055 ++trial;
3056 }
3057
3058 if( move )
3059 {
3060 label->SetPosition( VECTOR2I( labelPos ) );
3061
3062 if( wireDirection.x == 0 ) // Moved vertically
3063 {
3064 if( wireDirection.y < 0 )
3065 label->SetSpinStyle( SPIN_STYLE::UP );
3066 else
3068 }
3069 else if( wireDirection.y == 0 ) // Moved horizontally
3070 {
3071 if( wireDirection.x < 0 )
3073 else
3075 }
3076 }
3077 }
3078 }
3079
3080 m_segments.clear();
3081 m_wireIntersections.clear();
3082}
3083
3084
3085bool SCH_IO_EAGLE::CanReadSchematicFile( const wxString& aFileName ) const
3086{
3087 if( !SCH_IO::CanReadSchematicFile( aFileName ) )
3088 return false;
3089
3090 return checkHeader( aFileName );
3091}
3092
3093
3094bool SCH_IO_EAGLE::CanReadLibrary( const wxString& aFileName ) const
3095{
3096 if( !SCH_IO::CanReadLibrary( aFileName ) )
3097 return false;
3098
3099 return checkHeader( aFileName );
3100}
3101
3102
3103bool SCH_IO_EAGLE::checkHeader( const wxString& aFileName ) const
3104{
3105 wxFileInputStream input( aFileName );
3106
3107 if( !input.IsOk() )
3108 return false;
3109
3110 // Pre-v6 schematics are a binary stream identified by a two-byte magic.
3111 if( EAGLE_BIN_PARSER::IsBinaryEagle( input ) )
3112 return true;
3113
3114 wxTextInputStream text( input );
3115
3116 for( int i = 0; i < 8; i++ )
3117 {
3118 if( input.Eof() )
3119 return false;
3120
3121 if( text.ReadLine().Contains( wxS( "<eagle" ) ) )
3122 return true;
3123 }
3124
3125 return false;
3126}
3127
3128
3129void SCH_IO_EAGLE::moveLabels( SCH_LINE* aWire, const VECTOR2I& aNewEndPoint )
3130{
3131 wxCHECK( aWire, /* void */ );
3132
3133 SCH_SCREEN* screen = getCurrentScreen();
3134
3135 wxCHECK( screen, /* void */ );
3136
3137 for( SCH_ITEM* item : screen->Items().Overlapping( aWire->GetBoundingBox() ) )
3138 {
3139 if( !item->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
3140 continue;
3141
3142 if( TestSegmentHit( item->GetPosition(), aWire->GetStartPoint(), aWire->GetEndPoint(), 0 ) )
3143 item->SetPosition( aNewEndPoint );
3144 }
3145}
3146
3147
3149{
3150 // Add bus entry symbols
3151 // TODO: Cleanup this function and break into pieces
3152
3153 // for each wire segment, compare each end with all busses.
3154 // If the wire end is found to end on a bus segment, place a bus entry symbol.
3155
3156 std::vector<SCH_LINE*> buses;
3157 std::vector<SCH_LINE*> wires;
3158
3159 SCH_SCREEN* screen = getCurrentScreen();
3160
3161 wxCHECK( screen, /* void */ );
3162
3163 for( SCH_ITEM* ii : screen->Items().OfType( SCH_LINE_T ) )
3164 {
3165 SCH_LINE* line = static_cast<SCH_LINE*>( ii );
3166
3167 if( line->IsBus() )
3168 buses.push_back( line );
3169 else if( line->IsWire() )
3170 wires.push_back( line );
3171 }
3172
3173 for( SCH_LINE* wire : wires )
3174 {
3175 VECTOR2I wireStart = wire->GetStartPoint();
3176 VECTOR2I wireEnd = wire->GetEndPoint();
3177
3178 for( SCH_LINE* bus : buses )
3179 {
3180 VECTOR2I busStart = bus->GetStartPoint();
3181 VECTOR2I busEnd = bus->GetEndPoint();
3182
3183 auto entrySize =
3184 []( int signX, int signY ) -> VECTOR2I
3185 {
3186 return VECTOR2I( schIUScale.MilsToIU( DEFAULT_SCH_ENTRY_SIZE ) * signX,
3187 schIUScale.MilsToIU( DEFAULT_SCH_ENTRY_SIZE ) * signY );
3188 };
3189
3190 auto testBusHit =
3191 [&]( const VECTOR2I& aPt ) -> bool
3192 {
3193 return TestSegmentHit( aPt, busStart, busEnd, 0 );
3194 };
3195
3196 if( wireStart.y == wireEnd.y && busStart.x == busEnd.x )
3197 {
3198 // Horizontal wire and vertical bus
3199
3200 if( testBusHit( wireStart ) )
3201 {
3202 // Wire start is on the vertical bus
3203
3204 if( wireEnd.x < busStart.x )
3205 {
3206 /* the end of the wire is to the left of the bus
3207 * ⎥⎢
3208 * ——————⎥⎢
3209 * ⎥⎢
3210 */
3211 VECTOR2I p = wireStart + entrySize( -1, 0 );
3212
3213 if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
3214 {
3215 /* there is room above the wire for the bus entry
3216 * ⎥⎢
3217 * _____/⎥⎢
3218 * ⎥⎢
3219 */
3220 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
3221 busEntry->SetFlags( IS_NEW );
3222 screen->Append( busEntry );
3223 moveLabels( wire, p );
3224 wire->SetStartPoint( p );
3225 }
3226 else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
3227 {
3228 /* there is room below the wire for the bus entry
3229 * _____ ⎥⎢
3230 * \⎥⎢
3231 * ⎥⎢
3232 */
3233 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
3234 busEntry->SetFlags( IS_NEW );
3235 screen->Append( busEntry );
3236 moveLabels( wire, p );
3237 wire->SetStartPoint( p );
3238 }
3239 else
3240 {
3241 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3242 screen->Append( new SCH_MARKER( std::move( ercItem ), wireStart ) );
3243 }
3244 }
3245 else
3246 {
3247 /* the wire end is to the right of the bus
3248 * ⎥⎢
3249 * ⎥⎢——————
3250 * ⎥⎢
3251 */
3252 VECTOR2I p = wireStart + entrySize( 1, 0 );
3253
3254 if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
3255 {
3256 /* There is room above the wire for the bus entry
3257 * ⎥⎢
3258 * ⎥⎢\_____
3259 * ⎥⎢
3260 */
3261 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p , 4 );
3262 busEntry->SetFlags( IS_NEW );
3263 screen->Append( busEntry );
3264 moveLabels( wire, p );
3265 wire->SetStartPoint( p );
3266 }
3267 else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
3268 {
3269 /* There is room below the wire for the bus entry
3270 * ⎥⎢ _____
3271 * ⎥⎢/
3272 * ⎥⎢
3273 */
3274 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
3275 busEntry->SetFlags( IS_NEW );
3276 screen->Append( busEntry );
3277 moveLabels( wire, p );
3278 wire->SetStartPoint( p );
3279 }
3280 else
3281 {
3282 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3283 screen->Append( new SCH_MARKER( std::move( ercItem ), wireStart ) );
3284 }
3285 }
3286
3287 break;
3288 }
3289 else if( testBusHit( wireEnd ) )
3290 {
3291 // Wire end is on the vertical bus
3292
3293 if( wireStart.x < busStart.x )
3294 {
3295 /* start of the wire is to the left of the bus
3296 * ⎥⎢
3297 * ——————⎥⎢
3298 * ⎥⎢
3299 */
3300 VECTOR2I p = wireEnd + entrySize( -1, 0 );
3301
3302 if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3303 {
3304 /* there is room above the wire for the bus entry
3305 * ⎥⎢
3306 * _____/⎥⎢
3307 * ⎥⎢
3308 */
3309 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
3310 busEntry->SetFlags( IS_NEW );
3311 screen->Append( busEntry );
3312 moveLabels( wire, p );
3313 wire->SetEndPoint( p );
3314 }
3315 else if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3316 {
3317 /* there is room below the wire for the bus entry
3318 * _____ ⎥⎢
3319 * \⎥⎢
3320 * ⎥⎢
3321 */
3322 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
3323 busEntry->SetFlags( IS_NEW );
3324 screen->Append( busEntry );
3325 moveLabels( wire, wireEnd + entrySize( -1, 0 ) );
3326 wire->SetEndPoint( wireEnd + entrySize( -1, 0 ) );
3327 }
3328 else
3329 {
3330 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3331 screen->Append( new SCH_MARKER( std::move( ercItem ), wireEnd ) );
3332 }
3333 }
3334 else
3335 {
3336 /* the start of the wire is to the right of the bus
3337 * ⎥⎢
3338 * ⎥⎢——————
3339 * ⎥⎢
3340 */
3341 VECTOR2I p = wireEnd + entrySize( 1, 0 );
3342
3343 if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3344 {
3345 /* There is room above the wire for the bus entry
3346 * ⎥⎢
3347 * ⎥⎢\_____
3348 * ⎥⎢
3349 */
3350 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
3351 busEntry->SetFlags( IS_NEW );
3352 screen->Append( busEntry );
3353 moveLabels( wire, p );
3354 wire->SetEndPoint( p );
3355 }
3356 else if( testBusHit( wireEnd + entrySize( 0, 1 ) ) )
3357 {
3358 /* There is room below the wire for the bus entry
3359 * ⎥⎢ _____
3360 * ⎥⎢/
3361 * ⎥⎢
3362 */
3363 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
3364 busEntry->SetFlags( IS_NEW );
3365 screen->Append( busEntry );
3366 moveLabels( wire, p );
3367 wire->SetEndPoint( p );
3368 }
3369 else
3370 {
3371 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3372 screen->Append( new SCH_MARKER( std::move( ercItem ), wireEnd ) );
3373 }
3374 }
3375
3376 break;
3377 }
3378 }
3379 else if( wireStart.x == wireEnd.x && busStart.y == busEnd.y )
3380 {
3381 // Vertical wire and horizontal bus
3382
3383 if( testBusHit( wireStart ) )
3384 {
3385 // Wire start is on the bus
3386
3387 if( wireEnd.y < busStart.y )
3388 {
3389 /* the end of the wire is above the bus
3390 * |
3391 * |
3392 * |
3393 * =======
3394 */
3395 VECTOR2I p = wireStart + entrySize( 0, -1 );
3396
3397 if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
3398 {
3399 /* there is room to the left of the wire for the bus entry
3400 * |
3401 * |
3402 * /
3403 * =======
3404 */
3405 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
3406 busEntry->SetFlags( IS_NEW );
3407 screen->Append( busEntry );
3408 moveLabels( wire, p );
3409 wire->SetStartPoint( p );
3410 }
3411 else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
3412 {
3413 /* there is room to the right of the wire for the bus entry
3414 * |
3415 * |
3416 * \
3417 * =======
3418 */
3419 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
3420 busEntry->SetFlags( IS_NEW );
3421 screen->Append( busEntry );
3422 moveLabels( wire, p );
3423 wire->SetStartPoint( p );
3424 }
3425 else
3426 {
3427 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3428 screen->Append( new SCH_MARKER( std::move( ercItem ), wireStart ) );
3429 }
3430 }
3431 else
3432 {
3433 /* wire end is below the bus
3434 * =======
3435 * |
3436 * |
3437 * |
3438 */
3439 VECTOR2I p = wireStart + entrySize( 0, 1 );
3440
3441 if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
3442 {
3443 /* there is room to the left of the wire for the bus entry
3444 * =======
3445 * \
3446 * |
3447 * |
3448 */
3449 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
3450 busEntry->SetFlags( IS_NEW );
3451 screen->Append( busEntry );
3452 moveLabels( wire, p );
3453 wire->SetStartPoint( p );
3454 }
3455 else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
3456 {
3457 /* there is room to the right of the wire for the bus entry
3458 * =======
3459 * /
3460 * |
3461 * |
3462 */
3463 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
3464 busEntry->SetFlags( IS_NEW );
3465 screen->Append( busEntry );
3466 moveLabels( wire, p );
3467 wire->SetStartPoint( p );
3468 }
3469 else
3470 {
3471 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3472 screen->Append( new SCH_MARKER( std::move( ercItem ), wireStart ) );
3473 }
3474 }
3475
3476 break;
3477 }
3478 else if( testBusHit( wireEnd ) )
3479 {
3480 // Wire end is on the bus
3481
3482 if( wireStart.y < busStart.y )
3483 {
3484 /* the start of the wire is above the bus
3485 * |
3486 * |
3487 * |
3488 * =======
3489 */
3490 VECTOR2I p = wireEnd + entrySize( 0, -1 );
3491
3492 if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
3493 {
3494 /* there is room to the left of the wire for the bus entry
3495 * |
3496 * |
3497 * /
3498 * =======
3499 */
3500 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
3501 busEntry->SetFlags( IS_NEW );
3502 screen->Append( busEntry );
3503 moveLabels( wire, p );
3504 wire->SetEndPoint( p );
3505 }
3506 else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
3507 {
3508 /* there is room to the right of the wire for the bus entry
3509 * |
3510 * |
3511 * \
3512 * =======
3513 */
3514 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
3515 busEntry->SetFlags( IS_NEW );
3516 screen->Append( busEntry );
3517 moveLabels( wire, p );
3518 wire->SetEndPoint( p );
3519 }
3520 else
3521 {
3522 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3523 screen->Append( new SCH_MARKER( std::move( ercItem ), wireEnd ) );
3524 }
3525 }
3526 else
3527 {
3528 /* wire start is below the bus
3529 * =======
3530 * |
3531 * |
3532 * |
3533 */
3534 VECTOR2I p = wireEnd + entrySize( 0, 1 );
3535
3536 if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
3537 {
3538 /* there is room to the left of the wire for the bus entry
3539 * =======
3540 * \
3541 * |
3542 * |
3543 */
3544 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
3545 busEntry->SetFlags( IS_NEW );
3546 screen->Append( busEntry );
3547 moveLabels( wire, p );
3548 wire->SetEndPoint( p );
3549 }
3550 else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
3551 {
3552 /* there is room to the right of the wire for the bus entry
3553 * =======
3554 * /
3555 * |
3556 * |
3557 */
3558 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
3559 busEntry->SetFlags( IS_NEW );
3560 screen->Append( busEntry );
3561 moveLabels( wire, p );
3562 wire->SetEndPoint( p );
3563 }
3564 else
3565 {
3566 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_NEEDED );
3567 screen->Append( new SCH_MARKER( std::move( ercItem ), wireEnd ) );
3568 }
3569 }
3570
3571 break;
3572 }
3573 }
3574 else
3575 {
3576 // Wire isn't horizontal or vertical
3577
3578 if( testBusHit( wireStart ) )
3579 {
3580 VECTOR2I wirevector = wireStart - wireEnd;
3581
3582 if( wirevector.x > 0 )
3583 {
3584 if( wirevector.y > 0 )
3585 {
3586 VECTOR2I p = wireStart + entrySize( -1, -1 );
3587 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
3588 busEntry->SetFlags( IS_NEW );
3589 screen->Append( busEntry );
3590
3591 moveLabels( wire, p );
3592 wire->SetStartPoint( p );
3593 }
3594 else
3595 {
3596 VECTOR2I p = wireStart + entrySize( -1, 1 );
3597 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
3598 busEntry->SetFlags( IS_NEW );
3599 screen->Append( busEntry );
3600
3601 moveLabels( wire, p );
3602 wire->SetStartPoint( p );
3603 }
3604 }
3605 else
3606 {
3607 if( wirevector.y > 0 )
3608 {
3609 VECTOR2I p = wireStart + entrySize( 1, -1 );
3610 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
3611 busEntry->SetFlags( IS_NEW );
3612 screen->Append( busEntry );
3613
3614 moveLabels( wire, p );
3615 wire->SetStartPoint( p );
3616 }
3617 else
3618 {
3619 VECTOR2I p = wireStart + entrySize( 1, 1 );
3620 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
3621 busEntry->SetFlags( IS_NEW );
3622 screen->Append( busEntry );
3623
3624 moveLabels( wire, p );
3625 wire->SetStartPoint( p );
3626 }
3627 }
3628
3629 break;
3630 }
3631 else if( testBusHit( wireEnd ) )
3632 {
3633 VECTOR2I wirevector = wireStart - wireEnd;
3634
3635 if( wirevector.x > 0 )
3636 {
3637 if( wirevector.y > 0 )
3638 {
3639 VECTOR2I p = wireEnd + entrySize( 1, 1 );
3640 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 4 );
3641 busEntry->SetFlags( IS_NEW );
3642 screen->Append( busEntry );
3643
3644 moveLabels( wire, p );
3645 wire->SetEndPoint( p );
3646 }
3647 else
3648 {
3649 VECTOR2I p = wireEnd + entrySize( 1, -1 );
3650 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 3 );
3651 busEntry->SetFlags( IS_NEW );
3652 screen->Append( busEntry );
3653
3654 moveLabels( wire, p );
3655 wire->SetEndPoint( p );
3656 }
3657 }
3658 else
3659 {
3660 if( wirevector.y > 0 )
3661 {
3662 VECTOR2I p = wireEnd + entrySize( -1, 1 );
3663 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 1 );
3664 busEntry->SetFlags( IS_NEW );
3665 screen->Append( busEntry );
3666
3667 moveLabels( wire, p );
3668 wire->SetEndPoint( p );
3669 }
3670 else
3671 {
3672 VECTOR2I p = wireEnd + entrySize( -1, -1 );
3673 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( p, 2 );
3674 busEntry->SetFlags( IS_NEW );
3675 screen->Append( busEntry );
3676
3677 moveLabels( wire, p );
3678 wire->SetEndPoint( p );
3679 }
3680 }
3681
3682 break;
3683 }
3684 }
3685 }
3686 }
3687}
3688
3689
3691{
3692 wxCHECK( aLabel, nullptr );
3693
3694 VECTOR2I labelPos( aLabel->GetPosition() );
3695
3696 for( const SEG& seg : segs )
3697 {
3698 if( seg.Contains( labelPos ) )
3699 return &seg;
3700 }
3701
3702 return nullptr;
3703}
3704
3705
3706// TODO could be used to place junctions, instead of IsJunctionNeeded()
3707// (see SCH_EDIT_FRAME::importFile())
3708bool SCH_IO_EAGLE::checkConnections( const SCH_SYMBOL* aSymbol, const SCH_PIN* aPin ) const
3709{
3710 wxCHECK( aSymbol && aPin, false );
3711
3712 VECTOR2I pinPosition = aSymbol->GetPinPhysicalPosition( aPin );
3713 auto pointIt = m_connPoints.find( pinPosition );
3714
3715 if( pointIt == m_connPoints.end() )
3716 return false;
3717
3718 const std::set<const EDA_ITEM*>& items = pointIt->second;
3719
3720 wxCHECK( items.find( aPin ) != items.end(), false );
3721
3722 return items.size() > 1;
3723}
3724
3725
3726void SCH_IO_EAGLE::addImplicitConnections( SCH_SYMBOL* aSymbol, SCH_SCREEN* aScreen, bool aUpdateSet )
3727{
3728 wxCHECK( aSymbol && aScreen && aSymbol->GetLibSymbolRef(), /*void*/ );
3729
3730 // Normally power parts also have power input pins,
3731 // but they already force net names on the attached wires
3732 if( aSymbol->GetLibSymbolRef()->IsGlobalPower() )
3733 return;
3734
3735 int unit = aSymbol->GetUnit();
3736 const wxString reference = aSymbol->GetField( FIELD_T::REFERENCE )->GetText();
3737 std::vector<SCH_PIN*> pins = aSymbol->GetLibSymbolRef()->GetGraphicalPins( 0, 0 );
3738 std::set<int> missingUnits;
3739
3740 // Search all units for pins creating implicit connections
3741 for( const SCH_PIN* pin : pins )
3742 {
3743 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
3744 {
3745 bool pinInUnit = !unit || pin->GetUnit() == unit; // pin belongs to the tested unit
3746
3747 // Create a global net label only if there are no other wires/pins attached
3748 if( pinInUnit )
3749 {
3750 if( !checkConnections( aSymbol, pin ) )
3751 {
3752 // Create a net label to force the net name on the pin
3753 SCH_GLOBALLABEL* netLabel = new SCH_GLOBALLABEL;
3754 netLabel->SetPosition( aSymbol->GetPinPhysicalPosition( pin ) );
3755 netLabel->SetText( extractNetName( pin->GetName() ) );
3756 netLabel->SetTextSize( VECTOR2I( schIUScale.MilsToIU( 40 ), schIUScale.MilsToIU( 40 ) ) );
3757
3758 switch( pin->GetOrientation() )
3759 {
3760 default:
3764 case PIN_ORIENTATION::PIN_DOWN: netLabel->SetSpinStyle( SPIN_STYLE::UP ); break;
3765 }
3766
3767 aScreen->Append( netLabel );
3768 }
3769 }
3770 else if( aUpdateSet )
3771 {
3772 // Found a pin creating implicit connection information in another unit.
3773 // Such units will be instantiated if they do not appear in another sheet and
3774 // processed later.
3775 wxASSERT( pin->GetUnit() );
3776 missingUnits.insert( pin->GetUnit() );
3777 }
3778 }
3779 }
3780
3781 if( aUpdateSet && aSymbol->GetLibSymbolRef()->GetUnitCount() > 1 )
3782 {
3783 auto cmpIt = m_missingCmps.find( reference );
3784
3785 // The first unit found has always already been processed.
3786 if( cmpIt == m_missingCmps.end() )
3787 {
3788 EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
3789 entry.cmp = aSymbol;
3790 entry.screen = aScreen;
3791 entry.units.emplace( unit, false );
3792 }
3793 else
3794 {
3795 // Set the flag indicating this unit has been processed.
3796 cmpIt->second.units[unit] = false;
3797 }
3798
3799 if( !missingUnits.empty() ) // Save the units that need later processing
3800 {
3801 EAGLE_MISSING_CMP& entry = m_missingCmps[reference];
3802 entry.cmp = aSymbol;
3803 entry.screen = aScreen;
3804
3805 // Add units that haven't already been processed.
3806 for( int i : missingUnits )
3807 {
3808 if( entry.units.find( i ) != entry.units.end() )
3809 entry.units.emplace( i, true );
3810 }
3811 }
3812 }
3813}
3814
3815
3816wxString SCH_IO_EAGLE::translateEagleBusName( const wxString& aEagleName ) const
3817{
3818 if( NET_SETTINGS::ParseBusVector( aEagleName, nullptr, nullptr ) )
3819 return aEagleName;
3820
3821 wxString ret = wxT( "{" );
3822
3823 wxStringTokenizer tokenizer( aEagleName, "," );
3824
3825 while( tokenizer.HasMoreTokens() )
3826 {
3827 wxString member = tokenizer.GetNextToken();
3828
3829 // In Eagle, overbar text is automatically stopped at the end of the net name, even when
3830 // that net name is part of a bus definition. In KiCad, we don't (currently) do that, so
3831 // if there is an odd number of overbar markers in this net name, we need to append one
3832 // to close it out before appending the space.
3833
3834 if( member.Freq( '!' ) % 2 > 0 )
3835 member << wxT( "!" );
3836
3837 ret << member << wxS( " " );
3838 }
3839
3840 ret.Trim( true );
3841 ret << wxT( "}" );
3842
3843 return ret;
3844}
3845
3846
3847const ESYMBOL* SCH_IO_EAGLE::getEagleSymbol( const std::unique_ptr<EINSTANCE>& aInstance )
3848{
3849 wxCHECK( m_eagleDoc && m_eagleDoc->drawing && m_eagleDoc->drawing->schematic && aInstance, nullptr );
3850
3851 std::unique_ptr<EPART>& epart = m_eagleDoc->drawing->schematic->parts[aInstance->part];
3852
3853 if( !epart || epart->deviceset.IsEmpty() )
3854 return nullptr;
3855
3856 std::unique_ptr<ELIBRARY>& elibrary = m_eagleDoc->drawing->schematic->libraries[epart->library];
3857
3858 if( !elibrary )
3859 return nullptr;
3860
3861 std::unique_ptr<EDEVICE_SET>& edeviceset = elibrary->devicesets[epart->deviceset];
3862
3863 if( !edeviceset )
3864 return nullptr;
3865
3866 std::unique_ptr<EGATE>& egate = edeviceset->gates[aInstance->gate];
3867
3868 if( !egate )
3869 return nullptr;
3870
3871 std::unique_ptr<ESYMBOL>& esymbol = elibrary->symbols[egate->symbol];
3872
3873 if( esymbol )
3874 return esymbol.get();
3875
3876 return nullptr;
3877}
3878
3879
3880void SCH_IO_EAGLE::getEagleSymbolFieldAttributes( const std::unique_ptr<EINSTANCE>& aInstance,
3881 const wxString& aEagleFieldName,
3882 SCH_FIELD* aField )
3883{
3884 wxCHECK( aField && !aEagleFieldName.IsEmpty(), /* void */ );
3885
3886 const ESYMBOL* esymbol = getEagleSymbol( aInstance );
3887
3888 if( esymbol )
3889 {
3890 for( const std::unique_ptr<ETEXT>& text : esymbol->texts )
3891 {
3892 if( text->text == aEagleFieldName )
3893 {
3894 aField->SetVisible( true );
3895 VECTOR2I pos( text->x.ToSchUnits() + aInstance->x.ToSchUnits(),
3896 -text->y.ToSchUnits() - aInstance->y.ToSchUnits() );
3897
3898 bool mirror = text->rot ? text->rot->mirror : false;
3899
3900 if( aInstance->rot.has_value() && aInstance->rot.value().mirror )
3901 mirror = !mirror;
3902
3903 if( mirror )
3904 pos.y = -aInstance->y.ToSchUnits() + text->y.ToSchUnits();
3905
3906 aField->SetPosition( pos );
3907 }
3908 }
3909 }
3910}
3911
3912
3914{
3915 VECTOR2I retv;
3916
3917 std::vector<SCH_FIELD*> fields;
3918 aPart->GetFields( fields );
3919
3920 if( fields.size() )
3921 {
3922 retv = fields[0]->GetPosition();
3923
3924 for( size_t i = 1; i < fields.size(); i++ )
3925 {
3926 if( fields[i]->GetPosition().x > retv.x )
3927 retv.x = fields[i]->GetPosition().x;
3928
3929 if( fields[i]->GetPosition().y > retv.y )
3930 retv.y = fields[i]->GetPosition().y;
3931 }
3932 }
3933
3934 return retv;
3935}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
constexpr size_type GetWidth() const
Definition box2.h:211
constexpr Vec Centre() const
Definition box2.h:94
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:653
constexpr size_type GetHeight() const
Definition box2.h:212
constexpr const SizeVec & GetSize() const
Definition box2.h:203
Read-only parser for the pre-v6 binary Eagle .brd format.
std::unique_ptr< wxXmlDocument > Parse(const std::vector< uint8_t > &aBytes)
Parse a binary Eagle board into an XML DOM compatible with the XML walker.
static bool IsBinaryEagle(wxInputStream &aStream)
Probe the first two bytes for the binary magic without changing the stream position.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
virtual void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:329
void SetCenter(const VECTOR2I &aCenter)
SHAPE_POLY_SET & GetPolyShape()
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:325
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
virtual void SetWidth(int aWidth)
void SetFillMode(FILL_T aFill)
virtual void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:279
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:495
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:539
virtual int GetTextHeight() const
Definition eda_text.h:307
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:389
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:373
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:342
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
Definition eda_text.cpp:305
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:231
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition eda_text.cpp:263
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:365
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition sch_rtree.h:253
ee_rtree::Iterator begin() const
Return a read/write iterator that points to the first.
Definition sch_rtree.h:288
ee_rtree::Iterator end() const
Return a read/write iterator that points to one past the last element in the EE_RTREE.
Definition sch_rtree.h:296
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition erc_item.cpp:305
RAII class to set and restore the fontconfig reporter.
Definition reporter.h:385
virtual void Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) const
Definition io_base.cpp:124
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition io_base.h:241
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
Definition io_base.cpp:71
Definition kiid.h:46
void ReloadLibraryEntry(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
std::optional< LIBRARY_TABLE * > ProjectTable() const
Retrieves the project library table for this adapter type, or nullopt if one doesn't exist.
void SetNickname(const wxString &aNickname)
void SetType(const wxString &aType)
void SetURI(const wxString &aUri)
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition lib_id.cpp:205
Define a library symbol object.
Definition lib_symbol.h:119
std::vector< const SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
void GetFields(std::vector< SCH_FIELD * > &aList, bool aVisibleOnly=false) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
bool IsGlobalPower() const override
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
static LOAD_INFO_REPORTER & GetInstance()
Definition reporter.cpp:351
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
void SetHeightMils(double aHeightInMils)
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition page_info.h:173
void SetWidthMils(double aWidthInMils)
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Holds all the data relating to one schematic.
Definition schematic.h:148
PROJECT & Project() const
Return a reference to the project this schematic is part of.
Definition schematic.h:170
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Definition schematic.h:288
SCH_SHEET & Root() const
Definition schematic.h:199
Class for a wire to bus entry.
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:138
void SetCanAutoplace(bool aCanPlace)
Definition sch_field.h:240
void ImportValues(const SCH_FIELD &aSource)
Copy parameters from a SCH_FIELD source.
bool IsEmpty()
Return true if both the name and value of the field are empty.
Definition sch_field.h:181
void SetPosition(const VECTOR2I &aPosition) override
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
void SetSpinStyle(SPIN_STYLE aSpinStyle) override
std::unique_ptr< EAGLE_DOC > m_eagleDoc
SCH_ITEM * loadWire(const std::unique_ptr< EWIRE > &aWire, SEG &endpoints)
void loadTextAttributes(EDA_TEXT *aText, const std::unique_ptr< ETEXT > &aAttributes) const
Move net labels that are detached from any wire to the nearest wire.
void loadSegments(const std::vector< std::unique_ptr< ESEGMENT > > &aSegments, const wxString &aNetName, const wxString &aNetClass, bool aIsBus=false)
void loadModuleInstance(const std::unique_ptr< EMODULEINST > &aModuleInstance)
void ensureLoadedLibrary(const wxString &aLibraryPath)
void loadSchematic(const ESCHEMATIC &aSchematic)
SCH_TEXT * loadPlainText(const std::unique_ptr< ETEXT > &aSchText)
void loadSheet(const std::unique_ptr< ESHEET > &aSheet)
void loadLayerDefs(const std::vector< std::unique_ptr< ELAYER > > &aLayers)
VECTOR2I getLastSymbolFieldPosition(const LIB_SYMBOL *aPart)
const ESYMBOL * getEagleSymbol(const std::unique_ptr< EINSTANCE > &aInstance)
EAGLE_LIBRARY * loadLibrary(const ELIBRARY *aLibrary, EAGLE_LIBRARY *aEagleLib)
wxXmlDocument loadXmlDocument(const wxString &aFileName)
wxString translateEagleBusName(const wxString &aEagleName) const
Translate an Eagle-style bus name into one that is KiCad-compatible.
std::map< wxString, wxString > m_powerPorts
map from symbol reference to global label equivalent
SCH_SHEET_PATH m_sheetPath
The current sheet path of the schematic being loaded.
wxString m_libName
Library name to save symbols.
SCH_TEXT * loadSymbolText(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< ETEXT > &aText, int aGateNumber)
std::pair< VECTOR2I, const SEG * > findNearestLinePoint(const VECTOR2I &aPoint, const std::vector< SEG > &aLines) const
std::map< wxString, long long > m_timestamps
SCH_LABEL_BASE * loadLabel(const std::unique_ptr< ELABEL > &aLabel, const wxString &aNetName, bool aIsBus=false)
void loadInstance(const std::unique_ptr< EINSTANCE > &aInstance, const std::map< wxString, std::unique_ptr< EPART > > &aParts)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
std::unordered_map< wxString, bool > m_userValue
deviceset/@uservalue for device.
int GetModifyHash() const override
Return the modification hash from the library cache.
std::map< wxString, int > m_netCounts
wxFileName m_filename
std::map< wxString, EAGLE_LIBRARY > m_eagleLibs
bool loadSymbol(const std::unique_ptr< ESYMBOL > &aEsymbol, std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EDEVICE > &aDevice, int aGateNumber, const wxString &aGateName)
SCH_SHEET * getCurrentSheet()
void loadDrawing(const std::unique_ptr< EDRAWING > &aDrawing)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
SCH_SHAPE * loadSymbolPolyLine(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EPOLYGON > &aPolygon, int aGateNumber)
std::vector< VECTOR2I > m_wireIntersections
Wires and labels of a single connection (segment in Eagle nomenclature)
std::map< VECTOR2I, std::set< const EDA_ITEM * > > m_connPoints
The fully parsed Eagle schematic file.
bool checkConnections(const SCH_SYMBOL *aSymbol, const SCH_PIN *aPin) const
IO_RELEASER< SCH_IO > m_pi
PI to create KiCad symbol library.
SCH_SHAPE * loadRectangle(const std::unique_ptr< ERECT > &aRect)
void addBusEntries()
This function finds best way to place a bus entry symbol for when an Eagle wire segment ends on an Ea...
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
void addImplicitConnections(SCH_SYMBOL *aSymbol, SCH_SCREEN *aScreen, bool aUpdateSet)
Create net labels to emulate implicit connections in Eagle.
std::map< int, SCH_LAYER_ID > m_layerMap
SCH_LAYER_ID kiCadLayer(int aEagleLayer)
Return the matching layer or return LAYER_NOTES.
wxString getLibName()
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,...
SCH_PIN * loadPin(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EPIN > &aPin, int aGateNumber)
SCH_SHAPE * loadCircle(const std::unique_ptr< ECIRCLE > &aCircle)
wxFileName getLibFileName()
Checks if there are other wires or pins at the position of the tested pin.
SCH_SHAPE * loadSymbolRectangle(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< ERECT > &aRectangle, int aGateNumber)
SCH_JUNCTION * loadJunction(const std::unique_ptr< EJUNCTION > &aJunction)
wxString m_version
Eagle file version.
void getEagleSymbolFieldAttributes(const std::unique_ptr< EINSTANCE > &aInstance, const wxString &aEagleFieldName, SCH_FIELD *aField)
std::map< wxString, const EPART * > m_partlist
void moveLabels(SCH_LINE *aWire, const VECTOR2I &aNewEndPoint)
Move any labels on the wire to the new end point of the wire.
bool checkHeader(const wxString &aFileName) const
SCHEMATIC * m_schematic
Passed to Load(), the schematic object being loaded.
void countNets(const ESCHEMATIC &aSchematic)
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
SCH_SHAPE * loadPolyLine(const std::unique_ptr< EPOLYGON > &aPolygon)
SCH_SHAPE * loadSymbolCircle(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< ECIRCLE > &aCircle, int aGateNumber)
SCH_SCREEN * getCurrentScreen()
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
std::map< wxString, EAGLE_MISSING_CMP > m_missingCmps
void loadFrame(const std::unique_ptr< EFRAME > &aFrame, std::vector< SCH_ITEM * > &aItems, SCH_LAYER_ID aLayer=LAYER_NOTES)
const int ARC_ACCURACY
std::vector< SEG_DESC > m_segments
Nets as defined in the <nets> sections of an Eagle schematic file.
std::vector< EMODULE * > m_modules
The current module stack being loaded.
std::vector< EMODULEINST * > m_moduleInstances
SCH_ITEM * loadSymbolWire(std::unique_ptr< LIB_SYMBOL > &aSymbol, const std::unique_ptr< EWIRE > &aWire, int aGateNumber)
long long getLibraryTimestamp(const wxString &aLibraryPath) const
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
Definition sch_io.cpp:47
SCH_IO(const wxString &aName)
Definition sch_io.h:407
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
Definition sch_item.cpp:170
int GetUnit() const
Definition sch_item.h:237
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:346
virtual void SetUnit(int aUnit)
Definition sch_item.h:236
void SetShape(LABEL_FLAG_SHAPE aShape)
Definition sch_label.h:179
void SetPosition(const VECTOR2I &aPosition) override
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
bool IsWire() const
Return true if the line is a wire.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_line.cpp:315
VECTOR2I GetEndPoint() const
Definition sch_line.h:145
VECTOR2I GetStartPoint() const
Definition sch_line.h:136
bool IsBus() const
Return true if the line is a bus.
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:146
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:825
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition sch_screen.h:758
SCH_SCREEN * GetNext()
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
SCH_SCREEN * GetFirst()
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:140
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition sch_screen.h:141
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:118
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
void SetPosition(const VECTOR2I &aPos) override
Definition sch_shape.h:87
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition sch_shape.cpp:97
VECTOR2I GetCenter() const
Definition sch_shape.h:94
void AddPoint(const VECTOR2I &aPosition)
VECTOR2I GetPosition() const override
Definition sch_shape.h:86
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
void SetPosition(const VECTOR2I &aPosition) override
void SetSide(SHEET_SIDE aEdge)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
void SetFileName(const wxString &aFilename)
Definition sch_sheet.h:390
bool LocatePathOfScreen(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aList)
Search the existing hierarchy for an instance of screen loaded from aFileName.
void SetName(const wxString &aName)
Definition sch_sheet.h:143
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:145
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Variant information for a schematic symbol.
Schematic symbol object.
Definition sch_symbol.h:75
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition sch_symbol.h:134
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:183
VECTOR2I GetPinPhysicalPosition(const SCH_PIN *Pin) const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
VECTOR2I GetPosition() const override
Definition sch_text.h:143
void SetPosition(const VECTOR2I &aPosition) override
Definition sch_text.h:144
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
Definition seg.cpp:442
bool Contains(const SEG &aSeg) const
Definition seg.h:320
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, const EDA_ANGLE &aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
Simple container to manage line stroke parameters.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
wxString wx_str() const
Definition utf8.cpp:41
std::map< wxString, wxString > m_Fields
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition vector2d.h:549
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition vector2d.h:381
#define DEFAULT_SCH_ENTRY_SIZE
The default text size in mils. (can be changed in preference menu)
wxString escapeName(const wxString &aNetName)
Translates Eagle special characters to their counterparts in KiCad.
wxString interpretText(const wxString &aText)
Interprets special characters in Eagle text and converts them to KiCAD notation.
size_t GetNodeCount(const wxXmlNode *aNode)
Fetch the number of XML nodes within aNode.
VECTOR2I ConvertEagleTextSize(const std::optional< wxString > &font, const ECOORD &size)
Converts Eagle's text size to KiCad text size depending on the font used.
VECTOR2I ConvertArcCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle)
Convert an Eagle curve end to a KiCad center for S_ARC.
wxString convertDescription(wxString aDescr)
Converts Eagle's HTML description into KiCad description format.
#define _(s)
@ DEGREES_T
Definition eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:419
@ FILLED_SHAPE
Fill with object color.
Definition eda_fill.h:31
#define IGNORE_PARENT_GROUP
Definition eda_item.h:55
#define IS_NEW
New item, just created.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:57
@ ERCE_BUS_ENTRY_NEEDED
Importer failed to auto-place a bus entry.
bool m_EagleImportFieldsCanAutoplace
Default CanAutoplace value for fields imported from EAGLE files.
static const std::string KiCadSchematicFileExtension
static const std::string KiCadSymbolLibFileExtension
#define THROW_IO_ERRORF(msg,...)
#define THROW_IO_CANCELLED()
KIID niluuid(0)
SCH_LAYER_ID
Eeschema drawing layers.
Definition layer_ids.h:471
@ LAYER_DEVICE
Definition layer_ids.h:488
@ LAYER_WIRE
Definition layer_ids.h:474
@ LAYER_NOTES
Definition layer_ids.h:489
@ LAYER_BUS
Definition layer_ids.h:475
STL namespace.
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_NC
not connected (must be left open)
Definition pin_type.h:46
@ PT_OUTPUT
usual output
Definition pin_type.h:34
@ PT_TRISTATE
tri state bus pin
Definition pin_type.h:36
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:35
@ PT_OPENCOLLECTOR
pin type open collector
Definition pin_type.h:44
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
Definition pin_type.h:123
@ PIN_RIGHT
The pin extends rightwards from the connection point.
Definition pin_type.h:107
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
Definition pin_type.h:114
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
Definition pin_type.h:131
@ RPT_SEVERITY_ERROR
static wxString extractNetName(const wxString &aPinName)
static const std::map< wxString, ELECTRICAL_PINTYPE > pinDirectionsMap
Map of EAGLE pin type values to KiCad pin type values.
static SYMBOL_ORIENTATION_T kiCadComponentRotation(float eagleDegrees)
static void eagleToKicadAlignment(EDA_TEXT *aText, int aEagleAlignment, int aRelDegress, bool aMirror, bool aSpin, int aAbsDegress)
static BOX2I getSheetBbox(SCH_SHEET *aSheet)
Strip the Eagle "@<tag>" linking hint from a pin name (e.g. return 'GND' for 'GND@2')
@ AUTOPLACE_AUTO
Definition sch_item.h:70
LABEL_FLAG_SHAPE
Definition sch_label.h:97
@ L_BIDI
Definition sch_label.h:100
@ L_TRISTATE
Definition sch_label.h:101
@ L_UNSPECIFIED
Definition sch_label.h:102
@ L_OUTPUT
Definition sch_label.h:99
@ L_INPUT
Definition sch_label.h:98
LABEL_SHAPE
Definition sch_label.h:115
@ LABEL_BIDI
Definition sch_label.h:118
@ LABEL_INPUT
Definition sch_label.h:116
@ LABEL_OUTPUT
Definition sch_label.h:117
@ LABEL_PASSIVE
Definition sch_label.h:120
@ LABEL_TRISTATE
Definition sch_label.h:119
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
SHEET_SIDE
Define the edge of the sheet that the sheet pin is positioned.
std::optional< VECTOR2I > OPT_VECTOR2I
Definition seg.h:35
wxString UnescapeString(const wxString &aSource)
bool ReplaceIllegalFileNameChars(std::string &aName, int aReplaceChar)
Checks aName for illegal file name characters.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
wxString UnescapeHTML(const wxString &aString)
Return a new wxString unescaped from HTML format.
@ CTX_LIBID
@ CTX_NETNAME
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > KiCadSymbols
std::unordered_map< wxString, wxString > package
wxString name
std::unordered_map< wxString, int > GateToUnitMap
Map Eagle gate unit number (which are strings) to KiCad library symbol unit number.
std::map< wxString, std::unique_ptr< EDEVICE_SET > > devicesets
wxString GetName() const
Fetch the fully unique library name.
std::map< wxString, std::unique_ptr< ESYMBOL > > symbols
std::optional< wxString > direction
std::map< wxString, std::unique_ptr< EMODULE > > modules
std::vector< std::unique_ptr< ESHEET > > sheets
std::map< wxString, std::unique_ptr< EPART > > parts
std::map< wxString, std::unique_ptr< ELIBRARY > > libraries
std::map< wxString, std::unique_ptr< EVARIANTDEF > > variantdefs
std::vector< std::unique_ptr< ETEXT > > texts
@ BOTTOM_CENTER
@ BOTTOM_RIGHT
@ CENTER_RIGHT
@ CENTER_LEFT
@ BOTTOM_LEFT
Map references to missing symbol units data.
const SCH_SYMBOL * cmp
Screen where the parent symbol is located.
std::map< int, bool > units
Segments representing wires for intersection checking.
std::vector< SEG > segs
std::vector< SCH_LABEL_BASE * > labels
const SEG * LabelAttached(const SCH_LABEL_BASE *aLabel) const
< Test if a particular label is attached to any of the stored segments
A simple container for schematic symbol instance information.
SYMBOL_ORIENTATION_T
enum used in RotationMiroir()
Definition symbol.h:31
@ SYM_ORIENT_270
Definition symbol.h:38
@ SYM_ORIENT_180
Definition symbol.h:37
@ SYM_ORIENT_90
Definition symbol.h:36
@ SYM_ORIENT_0
Definition symbol.h:35
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
@ UNTRANSLATED
KIBIS_PIN * pin
VECTOR2I center
int radius
VECTOR2I end
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
bool TestSegmentHit(const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition trigo.cpp:171
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:225
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_SYMBOL_T
Definition typeinfo.h:168
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
Definition of file extensions used in Kicad.