29#include <wx/filename.h>
31#include <wx/tokenzr.h>
32#include <wx/wfstream.h>
33#include <wx/txtstrm.h>
34#include <wx/mstream.h>
35#include <wx/xml/xml.h>
93 bbox.
Merge( item->GetBoundingBox() );
102 return aPinName.BeforeFirst(
'@' );
115 wxCHECK( currentSheet,
nullptr );
160 for(
const std::unique_ptr<ELAYER>& elayer : aLayers )
179 switch ( elayer->number)
209 int roti = int( eagleDegrees );
219 wxASSERT_MSG(
false, wxString::Format( wxT(
"Unhandled orientation (%d degrees)" ),
228 bool aMirror,
bool aSpin,
int aAbsDegress )
230 int align = aEagleAlignment;
232 if( aRelDegress == 90 )
236 else if( aRelDegress == 180 )
240 else if( aRelDegress == 270 )
246 if( aMirror ==
true )
248 if( aAbsDegress == 90 || aAbsDegress == 270 )
259 else if( aAbsDegress == 0 || aAbsDegress == 180 )
353 const std::map<std::string, UTF8>* aProperties )
355 wxASSERT( !aFileName || aSchematic !=
nullptr );
375 wxXmlNode* currentNode = xmlDocument.GetRoot();
385 unique_ptr<SCH_SHEET> tempVROwner;
389 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
390 wxT(
"Can't append to a schematic with no root!" ) );
401 if( sheetPath.Last() == aAppendToMe )
413 tempVROwner = std::make_unique<SCH_SHEET>( aSchematic );
433 wxCHECK_MSG(
table,
nullptr,
"Could not load symbol lib table." );
435 m_pi.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
443 wxString libTableUri = wxT(
"${KIPRJMOD}/" ) +
getLibFileName().GetFullName();
448 row.
SetURI( libTableUri );
456 m_eagleDoc = std::make_unique<EAGLE_DOC>( currentNode,
this );
484 const wxString& aLibraryPath,
485 const std::map<std::string, UTF8>* aProperties )
496 for(
const auto& [symName, libSymbol] : it->second.KiCadSymbols )
497 aSymbolNameList.push_back( symName );
503 const wxString& aLibraryPath,
504 const std::map<std::string, UTF8>* aProperties )
515 for(
const auto& [symName, libSymbol] : it->second.KiCadSymbols )
516 aSymbolList.push_back( libSymbol.get() );
522 const std::map<std::string, UTF8>* aProperties )
533 auto it2 = it->second.KiCadSymbols.find( aAliasName );
535 if( it2 != it->second.KiCadSymbols.end() )
536 return it2->second.get();
545 wxFileName fn( aLibraryPath );
547 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
548 return fn.GetModificationTime().GetValue().GetValue();
579 std::unique_ptr<EAGLE_DOC> doc = std::make_unique<EAGLE_DOC>( xmlDocument.GetRoot(),
this );
583 m_version = ( doc->version.IsEmpty() ) ? wxString( wxS(
"0.0" ) ) : doc->version;
595 wxXmlDocument xmlDocument;
596 wxFFileInputStream stream(
m_filename.GetFullPath() );
601 wxString::Format(
_(
"Unable to read file '%s'." ),
m_filename.GetFullPath() ) );
612 std::vector<uint8_t> bytes;
613 bytes.resize(
static_cast<size_t>( stream.GetLength() ) );
614 stream.Read( bytes.data(), bytes.size() );
616 if( stream.LastRead() != bytes.size() )
619 wxString::Format(
_(
"Unable to read file '%s'." ),
m_filename.GetFullPath() ) );
623 std::unique_ptr<wxXmlDocument> binDocument = binParser.
Parse( bytes );
625 xmlDocument.SetRoot( binDocument->DetachRoot() );
630 wxTextInputStream
text( stream );
631 wxString line =
text.ReadLine();
633 if( !line.StartsWith( wxT(
"<?xml" ) ) && !line.StartsWith( wxT(
"<!--" ) )
634 && !line.StartsWith( wxT(
"<eagle " ) ) )
636 THROW_IO_ERROR( wxString::Format(
_(
"'%s' is an Eagle binary-format file; "
637 "only Eagle XML-format files can be imported." ),
641#if wxCHECK_VERSION( 3, 3, 0 )
644 if( !xmlDocument.Load( stream, wxXMLDOC_NONE, &err ) )
646 if( err.message == wxS(
"no element found" ) )
650 wxMemoryOutputStream memOutput;
653 header <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
654 header <<
"<!DOCTYPE eagle SYSTEM \"eagle.dtd\">\n";
656 wxScopedCharBuffer headerBuf =
header.utf8_str();
657 memOutput.Write( headerBuf.data(), headerBuf.length() );
659 wxFFileInputStream stream2(
m_filename.GetFullPath() );
660 memOutput.Write( stream2 );
662 wxMemoryInputStream memInput( memOutput );
664 if( !xmlDocument.Load( memInput, wxXMLDOC_NONE, &err ) )
671 THROW_IO_ERROR( wxString::Format(
_(
"Unable to read file '%s'.\n'%s' at line %d, column %d, offset %d" ),
672 m_filename.GetFullPath(), err.message, err.line, err.column,
677 if( !xmlDocument.Load( stream ) )
681 wxMemoryOutputStream memOutput;
684 header <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
685 header <<
"<!DOCTYPE eagle SYSTEM \"eagle.dtd\">\n";
687 wxScopedCharBuffer headerBuf =
header.utf8_str();
688 memOutput.Write( headerBuf.data(), headerBuf.length() );
690 wxFFileInputStream stream2(
m_filename.GetFullPath() );
691 memOutput.Write( stream2 );
693 wxMemoryInputStream memInput( memOutput );
695 if( !xmlDocument.Load( memInput ) )
708 wxCHECK( aDrawing, );
712 if( aDrawing->library )
720 if( aDrawing->schematic )
727 for(
const std::unique_ptr<ESHEET>& esheet : aSchematic.
sheets )
729 for(
const std::unique_ptr<ENET>& enet : esheet->nets )
731 wxString netName = enet->netname;
740 for(
const auto& [modname, emodule] : aSchematic.
modules )
742 for(
const std::unique_ptr<ESHEET>& esheet : emodule->sheets )
744 for(
const std::unique_ptr<ENET>& enet : esheet->nets )
746 wxString netName = enet->netname;
761 if( aSchematic.
sheets.empty() )
768 if( variantDef->current && *variantDef->current )
773 for(
const auto& [
name, epart] : aSchematic.
parts )
776 for(
const auto& [modName, emodule] : aSchematic.
modules )
778 for(
const auto& [partName, epart] : emodule->parts )
784 for(
const auto& [libName, elibrary] : aSchematic.
libraries )
787 elib->
name = elibrary->GetName();
803 std::vector<SCH_SHEET*> eaglePages;
804 eaglePages.reserve( aSchematic.
sheets.size() );
806 for(
const std::unique_ptr<ESHEET>& esheet : aSchematic.
sheets )
810 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>(
m_rootSheet );
812 sheet->SetScreen( screen );
814 wxCHECK2( sheet && screen,
continue );
816 wxString pageNo = wxString::Format( wxT(
"%d" ),
m_sheetIndex );
824 eaglePages.push_back( sheet.release() );
829 if( !eaglePages.empty() )
854 struct MISSING_UNIT_PLACEMENT
864 std::map<SCH_SCREEN*, MISSING_UNIT_PLACEMENT> placements;
868 const SCH_SYMBOL* origSymbol = cmp.second.cmp;
870 for(
auto& unitEntry : cmp.second.units )
872 if( unitEntry.second ==
false )
876 int unit = unitEntry.first;
887 targetScreen = fallbackSheet->
GetScreen();
889 targetScreen = schematicRoot->
GetScreen();
892 auto placementIt = placements.find( targetScreen );
894 if( placementIt == placements.end() )
896 MISSING_UNIT_PLACEMENT placement;
897 placement.screen = targetScreen;
901 SCH_SHEET* targetSheet = placement.sheetpath.Last();
906 placement.newCmpPosition =
VECTOR2I( placement.sheetBbox.GetLeft(),
907 placement.sheetBbox.GetBottom() );
908 placement.maxY = placement.sheetBbox.GetY();
909 placementIt = placements.emplace( targetScreen, placement ).first;
912 MISSING_UNIT_PLACEMENT& placement = placementIt->second;
914 symbol->SetUnitSelection( &placement.sheetpath, unit );
915 symbol->SetUnit( unit );
916 symbol->SetOrientation( 0 );
917 symbol->AddHierarchicalReference( placement.sheetpath.Path(), reference, unit );
920 BOX2I cmpBbox = symbol->GetBoundingBox();
921 int posY = placement.newCmpPosition.y + cmpBbox.
GetHeight();
922 symbol->SetPosition(
VECTOR2I( placement.newCmpPosition.x, posY ) );
923 placement.newCmpPosition.x += cmpBbox.
GetWidth();
924 placement.maxY = std::max( placement.maxY, posY );
926 if( placement.newCmpPosition.x >= placement.pageSizeIU.x )
927 placement.newCmpPosition =
VECTOR2I( placement.sheetBbox.GetLeft(),
932 placement.screen->Append( symbol.release() );
945 wxCHECK( sheet && screen, );
949 std::string filename;
953 if( aSheet->description )
954 sheet->
SetName( aSheet->description.value().text );
959 replace( filename.begin(), filename.end(),
' ',
'_' );
964 fn.SetPath(
m_schematic->Project().GetProjectPath() );
965 fn.SetName( filename );
972 for(
const auto& [
name, moduleinst] : aSheet->moduleinsts )
979 for(
const std::unique_ptr<EPOLYGON>& epoly : aSheet->plain->polygons )
985 for(
const std::unique_ptr<EWIRE>& ewire : aSheet->plain->wires )
991 for(
const std::unique_ptr<ETEXT>& etext : aSheet->plain->texts )
994 for(
const std::unique_ptr<ECIRCLE>& ecircle : aSheet->plain->circles )
997 for(
const std::unique_ptr<ERECT>& erectangle : aSheet->plain->rectangles )
1000 for(
const std::unique_ptr<EFRAME>& eframe : aSheet->plain->frames )
1002 std::vector<SCH_ITEM*> frameItems;
1013 for(
const std::unique_ptr<EINSTANCE>& einstance : aSheet->instances )
1021 for(
const std::unique_ptr<EBUS>& ebus : aSheet->busses )
1027 loadSegments( ebus->segments, busName, wxString(),
true );
1030 for(
const std::unique_ptr<ENET>& enet : aSheet->nets )
1033 wxString netName = enet->netname;
1034 wxString netClass = wxString::Format( wxS(
"%i" ), enet->netcode );
1053 if( pageSizeIU.
x < targetSheetSize.
x )
1056 if( pageSizeIU.
y < targetSheetSize.
y )
1063 VECTOR2I sheetcentre( pageSizeIU.
x / 2, pageSizeIU.
y / 2 );
1067 VECTOR2I translation = sheetcentre - itemsCentre;
1068 translation.
x = translation.
x - translation.
x %
schIUScale.MilsToIU( 100 );
1069 translation.
y = translation.
y - translation.
y %
schIUScale.MilsToIU( 100 );
1081 std::vector<SCH_ITEM*> allItems;
1083 std::copy( screen->
Items().
begin(), screen->
Items().
end(), std::back_inserter( allItems ) );
1087 item->SetPosition( item->GetPosition() + translation );
1105 wxCHECK( currentSheet &¤tScreen, );
1111 auto it =
m_eagleDoc->drawing->schematic->modules.find( aModuleInstance->moduleinst );
1114 if( it ==
m_eagleDoc->drawing->schematic->modules.end() )
1116 THROW_IO_ERROR( wxString::Format(
_(
"No module instance '%s' found in schematic "
1118 aModuleInstance->name,
m_filename.GetFullPath() ) );
1122 fn.SetName( aModuleInstance->moduleinst );
1126 VECTOR2I size( it->second->dx.ToSchUnits(), it->second->dy.ToSchUnits() );
1128 int halfX =
KiROUND( size.
x / 2.0 );
1129 int halfY =
KiROUND( size.
y / 2.0 );
1130 int portExtWireLength =
schIUScale.mmToIU( 5.08 );
1131 VECTOR2I pos( aModuleInstance->x.ToSchUnits() - halfX,
1132 -aModuleInstance->y.ToSchUnits() - halfY );
1134 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( currentSheet, pos, size );
1142 if( schFile->GetFileName() == fn.GetFullPath() )
1144 newScreen = schFile;
1149 bool isNewSchFile = ( newScreen == nullptr );
1157 wxCHECK( newSheet && newScreen, );
1159 newSheet->SetScreen( newScreen );
1160 newSheet->SetFileName( fn.GetFullName() );
1161 newSheet->SetName( aModuleInstance->name );
1163 for(
const auto& [portName, port] : it->second->ports )
1166 int pinOffset = port->coord.ToSchUnits();
1169 if( port->side ==
"left" )
1173 pinPos.
y = pos.
y + halfY - pinOffset;
1174 portExtWireEndpoint = pinPos;
1175 portExtWireEndpoint.
x -= portExtWireLength;
1177 else if( port->side ==
"right" )
1180 pinPos.
x = pos.
x + size.
x;
1181 pinPos.
y = pos.
y + halfY - pinOffset;
1182 portExtWireEndpoint = pinPos;
1183 portExtWireEndpoint.
x += portExtWireLength;
1185 else if( port->side ==
"top" )
1188 pinPos.
x = pos.
x + halfX + pinOffset;
1190 portExtWireEndpoint = pinPos;
1191 portExtWireEndpoint.
y -= portExtWireLength;
1193 else if( port->side ==
"bottom" )
1196 pinPos.
x = pos.
x + halfX + pinOffset;
1197 pinPos.
y = pos.
y + size.
y;
1198 portExtWireEndpoint = pinPos;
1199 portExtWireEndpoint.
y += portExtWireLength;
1204 currentScreen->
Append( portExtWire );
1208 if( port->direction )
1210 if( *port->direction ==
"in" )
1212 else if( *port->direction ==
"out" )
1214 else if( *port->direction ==
"io" )
1216 else if( *port->direction ==
"hiz" )
1231 newSheet->AddPin( sheetPin );
1234 wxString pageNo = wxString::Format( wxT(
"%d" ),
m_sheetIndex );
1236 newSheet->SetParent( currentSheet );
1239 currentScreen->
Append( newSheet.release() );
1241 m_modules.push_back( it->second.get() );
1247 for(
const std::unique_ptr<ESHEET>& esheet : it->second->sheets )
1257 wxCHECK2( emoduleInst,
continue );
1259 refPrefix += emoduleInst->name + wxS(
":" );
1270 wxCHECK2( symbol && !symbol->
GetInstances().empty(),
continue );
1273 wxString newReference = refPrefix + inst.
m_Reference.AfterLast(
':' );
1289 int xMin = aFrame->x1.ToSchUnits();
1290 int xMax = aFrame->x2.ToSchUnits();
1291 int yMin = -aFrame->y1.ToSchUnits();
1292 int yMax = -aFrame->y2.ToSchUnits();
1295 std::swap( xMin, xMax );
1298 std::swap( yMin, yMax );
1306 aItems.push_back( lines );
1308 if( !( aFrame->border_left ==
false ) )
1315 aItems.push_back( lines );
1318 int height = yMax - yMin;
1321 int legendPosX = xMin +
schIUScale.MilsToIU( 75 );
1322 double rowSpacing = height / double( aFrame->rows );
1323 double legendPosY = yMin + ( rowSpacing / 2 );
1325 for( i = 1; i < aFrame->rows; i++ )
1327 int newY =
KiROUND( yMin + ( rowSpacing * (
double) i ) );
1331 aItems.push_back( lines );
1334 char legendChar =
'A';
1336 for( i = 0; i < aFrame->rows; i++ )
1343 legendText->
SetText( wxString( legendChar ) );
1346 aItems.push_back( legendText );
1348 legendPosY += rowSpacing;
1352 if( !( aFrame->border_right ==
false ) )
1359 aItems.push_back( lines );
1362 int height = yMax - yMin;
1365 int legendPosX = xMax -
schIUScale.MilsToIU( 75 );
1366 double rowSpacing = height / double( aFrame->rows );
1367 double legendPosY = yMin + ( rowSpacing / 2 );
1369 for( i = 1; i < aFrame->rows; i++ )
1371 int newY =
KiROUND( yMin + ( rowSpacing * (
double) i ) );
1375 aItems.push_back( lines );
1378 char legendChar =
'A';
1380 for( i = 0; i < aFrame->rows; i++ )
1387 legendText->
SetText( wxString( legendChar ) );
1390 aItems.push_back( legendText );
1392 legendPosY += rowSpacing;
1396 if( !( aFrame->border_top ==
false ) )
1403 aItems.push_back( lines );
1406 int width = xMax - xMin;
1409 int legendPosY = yMin +
schIUScale.MilsToIU( 75 );
1410 double columnSpacing = width / double( aFrame->columns );
1411 double legendPosX = xMin + ( columnSpacing / 2 );
1413 for( i = 1; i < aFrame->columns; i++ )
1415 int newX =
KiROUND( xMin + ( columnSpacing * (
double) i ) );
1419 aItems.push_back( lines );
1422 char legendChar =
'1';
1424 for( i = 0; i < aFrame->columns; i++ )
1431 legendText->
SetText( wxString( legendChar ) );
1434 aItems.push_back( legendText );
1436 legendPosX += columnSpacing;
1440 if( !( aFrame->border_bottom ==
false ) )
1447 aItems.push_back( lines );
1450 int width = xMax - xMin;
1453 int legendPosY = yMax -
schIUScale.MilsToIU( 75 );
1454 double columnSpacing = width / double( aFrame->columns );
1455 double legendPosX = xMin + ( columnSpacing / 2 );
1457 for( i = 1; i < aFrame->columns; i++ )
1459 int newX =
KiROUND( xMin + ( columnSpacing * (
double) i ) );
1463 aItems.push_back( lines );
1466 char legendChar =
'1';
1468 for( i = 0; i < aFrame->columns; i++ )
1475 legendText->
SetText( wxString( legendChar ) );
1478 aItems.push_back( legendText );
1480 legendPosX += columnSpacing;
1487 const wxString& netName,
1488 const wxString& aNetClass,
1496 size_t segmentCount = aSegments.size();
1498 for(
const std::unique_ptr<ESEGMENT>& esegment : aSegments )
1500 bool labelled =
false;
1501 bool firstWireFound =
false;
1507 for(
const std::unique_ptr<EWIRE>& ewire : esegment->wires )
1516 if( !firstWireFound )
1518 firstWire = thisWire;
1519 firstWireFound =
true;
1525 if( !desc.labels.empty() && desc.labels.front()->GetText() == netName )
1528 for(
const SEG& seg : desc.segs )
1537 segDesc.
segs.push_back( thisWire );
1541 for(
const std::unique_ptr<EJUNCTION>& ejunction : esegment->junctions )
1544 for(
const std::unique_ptr<ELABEL>& elabel : esegment->labels )
1549 wxASSERT( segDesc.
labels.empty()
1552 segDesc.
labels.push_back( label );
1556 for(
const std::unique_ptr<EPINREF>& epinref : esegment->pinRefs )
1558 wxString part = epinref->part;
1559 wxString
pin = epinref->pin;
1561 auto powerPort =
m_powerPorts.find( wxT(
"#" ) + part );
1573 if( !labelled && firstWireFound )
1575 std::unique_ptr<SCH_LABEL_BASE> label;
1587 if( segmentCount > 1 ||
m_netCounts[netName] > 1 )
1597 label->SetPosition( firstWire.
A );
1602 if( firstWire.
A.
y == firstWire.
B.
y )
1604 if( firstWire.
B.
x > firstWire.
A.
x )
1609 else if( firstWire.
A.
x == firstWire.
B.
x )
1611 if( firstWire.
B.
y > firstWire.
A.
y )
1617 screen->
Append( label.release() );
1626 if( !aPolygon->IsValidOutline() )
1629 std::unique_ptr<SCH_SHAPE> poly = std::make_unique<SCH_SHAPE>(
SHAPE_T::POLY );
1633 for(
const std::unique_ptr<EVERTEX>& evertex : aPolygon->vertices )
1635 pt =
VECTOR2I( evertex->x.ToSchUnits(), -evertex->y.ToSchUnits() );
1641 poly->GetPolyShape().Append( arc, -1, -1,
ARC_ACCURACY );
1645 poly->AddPoint( pt );
1649 prev_curve = evertex->curve;
1652 poly->SetLayer(
kiCadLayer( aPolygon->layer ) );
1656 return poly.release();
1664 start.
x = aWire->x1.ToSchUnits();
1665 start.
y = -aWire->y1.ToSchUnits();
1666 end.x = aWire->x2.ToSchUnits();
1667 end.y = -aWire->y2.ToSchUnits();
1670 endpoints =
SEG( start,
end );
1679 std::unique_ptr<SCH_SHAPE> arc = std::make_unique<SCH_SHAPE>(
SHAPE_T::ARC );
1682 arc->SetCenter(
center );
1683 arc->SetStart( start );
1690 return arc.release();
1694 std::unique_ptr<SCH_LINE> line = std::make_unique<SCH_LINE>();
1696 line->SetStartPoint( start );
1697 line->SetEndPoint(
end );
1698 line->SetLayer(
kiCadLayer( aWire->layer ) );
1701 return line.release();
1709 VECTOR2I center( aCircle->x.ToSchUnits(), -aCircle->y.ToSchUnits() );
1722 std::unique_ptr<SCH_SHAPE> rectangle = std::make_unique<SCH_SHAPE>(
SHAPE_T::RECTANGLE );
1724 rectangle->SetLayer(
kiCadLayer( aRectangle->layer ) );
1725 rectangle->SetPosition(
VECTOR2I( aRectangle->x1.ToSchUnits(), -aRectangle->y1.ToSchUnits() ) );
1726 rectangle->SetEnd(
VECTOR2I( aRectangle->x2.ToSchUnits(), -aRectangle->y2.ToSchUnits() ) );
1728 if( aRectangle->rot )
1730 VECTOR2I pos( rectangle->GetPosition() );
1737 rectangle->SetPosition( pos );
1738 rectangle->SetEnd(
end );
1744 return rectangle.release();
1750 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
1752 VECTOR2I pos( aJunction->x.ToSchUnits(), -aJunction->y.ToSchUnits() );
1754 junction->SetPosition( pos );
1756 return junction.release();
1761 const wxString& aNetName,
bool aIsBus )
1763 VECTOR2I elabelpos( aLabel->x.ToSchUnits(), -aLabel->y.ToSchUnits() );
1768 std::unique_ptr<SCH_LABEL_BASE> label;
1770 VECTOR2I textSize =
KiROUND( aLabel->size.ToSchUnits() * 0.7, aLabel->size.ToSchUnits() * 0.7 );
1772 auto findModulePort =
1773 [&]() ->
const EPORT*
1778 const auto& ports =
m_modules.back()->ports;
1779 const auto it = ports.find( aNetName );
1780 return it == ports.end() ? nullptr : it->second.get();
1783 const EPORT* port = findModulePort();
1787 auto hierLabel = std::make_unique<SCH_HIERLABEL>();
1794 if( direction ==
"in" )
1796 else if( direction ==
"out" )
1798 else if( direction ==
"io" )
1800 else if( direction ==
"hiz" )
1808 hierLabel->SetLabelShape( type );
1811 label = std::move( hierLabel );
1815 label = std::make_unique<SCH_LABEL>();
1819 label = std::make_unique<SCH_GLOBALLABEL>();
1823 label->SetPosition( elabelpos );
1824 label->SetTextSize( textSize );
1830 int angle =
KiROUND( aLabel->rot->degrees );
1849 return label.release();
1853std::pair<VECTOR2I, const SEG*>
1855 const std::vector<SEG>& aLines )
const
1858 const SEG* nearestLine =
nullptr;
1860 double d, mindistance = std::numeric_limits<double>::max();
1866 for(
const SEG& line : aLines )
1868 VECTOR2I testpoint = line.NearestPoint( aPoint );
1871 if( d < mindistance )
1874 nearestPoint = testpoint;
1875 nearestLine = &line;
1879 return std::make_pair( nearestPoint, nearestLine );
1884 const std::map<wxString, std::unique_ptr<EPART>>& aParts )
1886 wxCHECK( aInstance, );
1892 const auto partIt = aParts.find( aInstance->part );
1894 if( partIt == aParts.end() )
1896 Report( wxString::Format(
_(
"Error parsing Eagle file. Could not find '%s' "
1897 "instance but it is referenced in the schematic." ),
1904 const std::unique_ptr<EPART>& epart = partIt->second;
1906 wxString libName = epart->library;
1909 if( epart->libraryUrn )
1910 libName += wxS(
"_" ) + epart->libraryUrn->assetId;
1912 wxString gatename = epart->deviceset + wxS(
"_" ) + epart->device + wxS(
"_" ) +
1914 wxString symbolname = wxString( epart->deviceset + epart->device );
1915 wxString kiPackageName = epart->deviceset + epart->device;
1917 if( epart->technology )
1918 symbolname += *epart->technology;
1920 symbolname.Replace( wxT(
"*" ), wxEmptyString );
1921 kiPackageName.Replace( wxT(
"*" ), wxEmptyString );
1930 wxString altSymbolName = libName + wxT(
"_" ) + symbolname;
1933 wxString libIdSymbolName = altSymbolName;
1939 Report( wxString::Format( wxS(
"Eagle library '%s' not found while looking up symbol for "
1940 "deviceset '%s', device '%s', and gate '%s." ),
1941 libName, epart->deviceset, epart->device, aInstance->gate ) );
1945 const auto gateIt = libIt->second.GateToUnitMap.find( gatename );
1947 if( gateIt == libIt->second.GateToUnitMap.end() )
1949 Report( wxString::Format( wxS(
"Symbol not found for deviceset '%s', device '%s', and "
1950 "gate '%s in library '%s'." ),
1951 epart->deviceset, epart->device, aInstance->gate, libName ) );
1955 int unit = gateIt->second;
1960 auto p = elib->
package.find( kisymbolname );
1962 if( p != elib->
package.end() )
1964 package = p->second;
1968 p = elib->
package.find( kiPackageName );
1970 if( p != elib->
package.end() )
1971 package = p->second;
1975 std::map<std::string, UTF8> properties;
1982 part =
m_pi->LoadSymbol(
getLibFileName().GetFullPath(), kisymbolname, &properties );
1983 libIdSymbolName = kisymbolname;
1988 Report( wxString::Format(
_(
"Could not find '%s' in the imported library." ),
1995 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
1996 symbol->SetLibId( libId );
1997 symbol->SetUnit( unit );
1998 symbol->SetPosition(
VECTOR2I( aInstance->x.ToSchUnits(), -aInstance->y.ToSchUnits() ) );
2001 if( !package.IsEmpty() )
2003 wxString footprint =
m_schematic->Project().GetProjectName() + wxT(
":" ) + package;
2007 if( aInstance->rot )
2011 if( aInstance->rot->mirror )
2012 symbol->MirrorHorizontally( aInstance->x.ToSchUnits() );
2015 std::vector<SCH_FIELD*> partFields;
2020 for(
const SCH_FIELD* partField : partFields )
2024 if( partField->IsMandatory() )
2025 symbolField = symbol->GetField( partField->GetId() );
2027 symbolField = symbol->GetField( partField->GetName() );
2034 newField.
SetText( partField->GetText() );
2038 symbol->AddField( newField );
2043 symbolField->
SetTextPos( symbol->GetPosition() + partField->GetTextPos() );
2049 wxString reference = package.IsEmpty() ?
'#' + aInstance->part : aInstance->part;
2052 if( reference.find_last_not_of( wxT(
"0123456789" ) ) == ( reference.Length()-1 ) )
2053 reference.Append( wxT(
"0" ) );
2058 if( reference.find_first_not_of( wxT(
"0123456789" ) ) != 0 )
2059 reference.Prepend( wxT(
"UNK" ) );
2063 if( aInstance->part.find_first_not_of( wxT(
"#" ) ) != 0 )
2064 reference.Prepend( wxT(
"UNK" ) );
2067 referenceField->
SetText( reference );
2070 bool userValue =
m_userValue.at( libIdSymbolName );
2078 if( epart->value && !epart->value.CGet().IsEmpty() )
2080 valueField->
SetText( *epart->value );
2084 valueField->
SetText( kisymbolname );
2090 for(
const auto& [ attrName, attr ] : epart->attributes )
2096 if( !symbol->GetFields().empty() )
2097 newField.
SetTextPos( symbol->GetFields().back().GetPosition() );
2100 newField.
SetText( *attr->value );
2104 symbol->AddField( newField );
2107 bool valueAttributeFound =
false;
2108 bool nameAttributeFound =
false;
2111 for(
auto& [
name, eattr] : aInstance->attributes )
2115 if( eattr->name.Lower() == wxT(
"name" ) )
2118 nameAttributeFound =
true;
2120 else if( eattr->name.Lower() == wxT(
"value" ) )
2123 valueAttributeFound =
true;
2127 field = symbol->GetField( eattr->name );
2139 int absdegrees = eattr->rot ? eattr->rot->degrees : 0;
2140 bool mirror = eattr->rot ? eattr->rot->mirror :
false;
2142 if( aInstance->rot && aInstance->rot->mirror )
2145 bool spin = eattr->rot ? eattr->rot->spin :
false;
2150 int rotation = aInstance->rot ? aInstance->rot->degrees : 0;
2151 int reldegrees = ( absdegrees - rotation + 360.0 );
2159 if( aInstance->smashed && aInstance->smashed.Get() )
2161 symbol->GetField(
FIELD_T::VALUE )->SetVisible( valueAttributeFound );
2173 wxCHECK2( emoduleInst,
continue );
2175 refPrefix += emoduleInst->name + wxS(
":" );
2178 symbol->AddHierarchicalReference(
m_sheetPath.Path(), refPrefix + reference, unit );
2184 symbol->SetLibSymbol( part->
Flatten().release() );
2186 for(
const auto& [
name, variant] : epart->variants )
2190 if( variant->populate && !*variant->populate )
2191 symbolVariant.
m_DNP =
true;
2193 if( variant->value )
2196 if( variant->technology )
2198 auto eLibIt =
m_eagleDoc->drawing->schematic->libraries.find( epart->library );
2200 if( eLibIt ==
m_eagleDoc->drawing->schematic->libraries.end() )
2202 Report( wxString::Format( wxS(
"Library '%s' not found in schematic." ), epart->library ) );
2206 auto eDeviceSetIt = eLibIt->second->devicesets.find( epart->deviceset );
2208 if( eDeviceSetIt == eLibIt->second->devicesets.end() )
2210 Report( wxString::Format( wxS(
"Device set '%s' not found in library '%s'." ),
2211 epart->deviceset, epart->library ) );
2215 auto eDeviceIt = eDeviceSetIt->second->devices.find( epart->device );
2217 if( eDeviceIt == eDeviceSetIt->second->devices.end() )
2219 Report( wxString::Format( wxS(
"Device '%s' not found in device set '%s' in library '%s'." ),
2220 epart->device, epart->deviceset, epart->library ) );
2224 auto eTechnologyIt = eDeviceIt->second->technologies.find( *variant->technology );
2226 if( eTechnologyIt == eDeviceIt->second->technologies.end() )
2228 Report( wxString::Format( wxS(
"Technology '%s' not found in device '%s' in device set '%s' "
2229 "in library '%s'." ),
2230 *variant->technology, epart->device, epart->deviceset, epart->library ) );
2234 for(
const auto& attr : eTechnologyIt->second->attributes )
2239 attrValue = *attr->value;
2241 symbolVariant.
m_Fields[attr->name] = attrValue;
2248 for(
const SCH_PIN*
pin : symbol->GetLibPins() )
2254 symbol->ClearFlags();
2256 screen->
Append( symbol.release() );
2262 wxCHECK( aLibrary && aEagleLibrary,
nullptr );
2269 wxString prefix = edeviceset->prefix ? edeviceset->prefix.Get() : wxString( wxT(
"" ) );
2270 wxString deviceSetDescr;
2272 if( edeviceset->description )
2276 for(
const auto& [devname, edevice] : edeviceset->devices )
2278 std::vector<std::unique_ptr<LIB_SYMBOL>> derivedSymbols;
2281 wxString symbolName = edeviceset->name + edevice->name;
2282 symbolName.Replace( wxT(
"*" ), wxEmptyString );
2283 wxASSERT( !symbolName.IsEmpty() );
2286 if( edevice->package )
2287 aEagleLibrary->
package[symbolName] = edevice->package.Get();
2290 std::unique_ptr<LIB_SYMBOL> libSymbol = std::make_unique<LIB_SYMBOL>( symbolName );
2293 int gate_count =
static_cast<int>( edeviceset->gates.size() );
2295 if( gate_count > 1 )
2296 libSymbol->SetUnitCount( gate_count,
true );
2298 libSymbol->LockUnits(
true );
2302 if( prefix.length() == 0 )
2310 reference->
SetText( edevice->package ? prefix :
'#' + prefix );
2313 libSymbol->GetValueField().SetVisible(
true );
2316 bool ispower =
false;
2318 for(
const auto& [gateName, egate] : edeviceset->gates )
2320 const auto it = aLibrary->
symbols.find( egate->symbol );
2322 if( it == aLibrary->
symbols.end() )
2324 Report( wxString::Format( wxS(
"Eagle symbol '%s' not found in library '%s'." ),
2325 egate->symbol, aLibrary->
GetName() ) );
2329 wxString gateMapName = edeviceset->name + wxS(
"_" ) + edevice->name +
2330 wxS(
"_" ) + egate->name;
2332 ispower =
loadSymbol( it->second, libSymbol, edevice, gateindex, egate->name );
2337 std::vector<SCH_FIELD*> fields;
2338 libSymbol->GetFields( fields );
2341 field->SetCanAutoplace( canAutoplace );
2343 for(
const auto& [techname, technology ] : edevice->technologies )
2345 std::unique_ptr<LIB_SYMBOL> derivedSymbol;
2348 if( !technology->name.IsEmpty() )
2350 derivedSymbol = std::make_unique<LIB_SYMBOL>( symbolName + technology->name, libSymbol.get() );
2354 SCH_FIELD* childField = derivedSymbol->GetField( parentField->GetName() );
2364 for(
const std::unique_ptr<EATTR>& attr : technology->attributes )
2371 if( !derivedSymbol )
2372 field = libSymbol->FindFieldCaseInsensitive( attr->name );
2374 field = derivedSymbol->FindFieldCaseInsensitive( attr->name );
2378 field->
SetText( *attr->value );
2382 SCH_FIELD* newField =
new SCH_FIELD( derivedSymbol ? derivedSymbol.get() : libSymbol.get(),
2387 SCH_FIELD* parentField = libSymbol->FindFieldCaseInsensitive( attr->name );
2394 newField->
SetText( *attr->value );
2399 if( !derivedSymbol )
2400 libSymbol->AddField( newField );
2402 derivedSymbol->AddField( newField );
2407 derivedSymbols.push_back( std::move( derivedSymbol ) );
2410 if( gate_count > 1 )
2411 libSymbol->SetUnitCount( gate_count,
true );
2413 if( gate_count == 1 && ispower )
2414 libSymbol->SetGlobalPower();
2417 if( edevice->package )
2424 libName =
m_schematic->Project().GetProjectName();
2431 wxString packageString = libName + wxT(
":" ) + aEagleLibrary->
package[symbolName];
2433 libSymbol->GetFootprintField().SetText( packageString );
2436 wxString libName = libSymbol->GetName();
2437 libSymbol->SetName( libName );
2438 libSymbol->SetDescription( deviceSetDescr );
2448 libName = aEagleLibrary->
name + wxT(
"_" ) + libName;
2450 libSymbol->SetName( libName );
2454 std::map<std::string, UTF8> properties;
2460 for( std::unique_ptr<LIB_SYMBOL>& symbol : derivedSymbols )
2464 wxString tmp = aEagleLibrary->
name + wxT(
"_" ) + symbol->GetName();
2466 symbol->SetName( tmp );
2471 derivedSymbol->
SetParent( parentSymbol );
2483 aEagleLibrary->
KiCadSymbols[ libName ] = std::move( libSymbol );
2487 m_userValue.emplace( std::make_pair( libName, edeviceset->uservalue ==
true ) );
2489 for( std::unique_ptr<LIB_SYMBOL>& symbol : derivedSymbols )
2491 m_userValue.emplace( std::make_pair( symbol->GetName(), edeviceset->uservalue ==
true ) );
2492 aEagleLibrary->
KiCadSymbols[symbol->GetName()] = std::move( symbol );
2497 return aEagleLibrary;
2502 std::unique_ptr<LIB_SYMBOL>& aSymbol,
2503 const std::unique_ptr<EDEVICE>& aDevice,
int aGateNumber,
2504 const wxString& aGateName )
2506 wxCHECK( aEsymbol && aSymbol && aDevice,
false );
2508 std::vector<SCH_ITEM*> items;
2510 bool showRefDes =
false;
2511 bool showValue =
false;
2512 bool ispower =
false;
2515 for(
const std::unique_ptr<ECIRCLE>& ecircle : aEsymbol->circles )
2518 for(
const std::unique_ptr<EPIN>& epin : aEsymbol->pins )
2520 std::unique_ptr<SCH_PIN>
pin(
loadPin( aSymbol, epin, aGateNumber ) );
2525 if( epin->direction )
2529 if( epin->direction->Lower() == pinDir.first )
2531 pin->SetType( pinDir.second );
2533 if( pinDir.first == wxT(
"sup" ) )
2542 if( aDevice->connects.size() != 0 )
2544 for(
const std::unique_ptr<ECONNECT>& connect : aDevice->connects )
2549 if( connect->gate == aGateName && epin->name == connect->pin )
2551 wxArrayString pads = wxSplit( wxString( connect->pad ),
' ' );
2553 pin->SetUnit( aGateNumber );
2556 if( pads.GetCount() > 1 )
2558 pin->SetNumberTextSize( 0 );
2561 for(
unsigned i = 0; i < pads.GetCount(); i++ )
2565 wxString padname( pads[i] );
2567 aSymbol->AddDrawItem( apin );
2576 pin->SetUnit( aGateNumber );
2577 pin->SetNumber( wxString::Format( wxT(
"%i" ), pincount ) );
2578 aSymbol->AddDrawItem(
pin.release() );
2582 for(
const std::unique_ptr<EPOLYGON>& epolygon : aEsymbol->polygons )
2584 aSymbol->AddDrawItem( shape );
2586 for(
const std::unique_ptr<ERECT>& erectangle : aEsymbol->rectangles )
2589 for(
const std::unique_ptr<ETEXT>& etext : aEsymbol->texts )
2591 std::unique_ptr<SCH_TEXT> libtext(
loadSymbolText( aSymbol, etext, aGateNumber ) );
2593 if( libtext->GetText() == wxT(
"${REFERENCE}" ) )
2599 showRefDes = etext->text == wxT(
">NAME" );
2601 else if( libtext->GetText() == wxT(
"${VALUE}" ) )
2607 showValue = etext->text == wxT(
">VALUE" );
2609 else if( etext->text.StartsWith(
">" ) )
2613 wxString fieldName = etext->text.Mid( 1 );
2615 if( !fieldName.IsEmpty() )
2623 aSymbol->AddField( field );
2628 aSymbol->AddDrawItem( libtext.release() );
2632 for(
const std::unique_ptr<EWIRE>& ewire : aEsymbol->wires )
2633 aSymbol->AddDrawItem(
loadSymbolWire( aSymbol, ewire, aGateNumber ) );
2635 for(
const std::unique_ptr<EFRAME>& eframe : aEsymbol->frames )
2637 std::vector<SCH_ITEM*> frameItems;
2643 item->SetParent( aSymbol.get() );
2644 item->SetUnit( aGateNumber );
2645 aSymbol->AddDrawItem( item );
2649 aSymbol->GetReferenceField().SetVisible( showRefDes );
2650 aSymbol->GetValueField().SetVisible( showValue );
2652 return pincount == 1 ? ispower :
false;
2657 const std::unique_ptr<ECIRCLE>& aCircle,
2660 wxCHECK( aSymbol && aCircle,
nullptr );
2664 VECTOR2I center( aCircle->x.ToSchUnits(), -aCircle->y.ToSchUnits() );
2666 circle->SetParent( aSymbol.get() );
2670 if( aCircle->width.ToSchUnits() == 0 )
2680 circle->SetUnit( aGateNumber );
2687 const std::unique_ptr<ERECT>& aRectangle,
2690 wxCHECK( aSymbol && aRectangle,
nullptr );
2695 rectangle->
SetPosition(
VECTOR2I( aRectangle->x1.ToSchUnits(), -aRectangle->y1.ToSchUnits() ) );
2696 rectangle->
SetEnd(
VECTOR2I( aRectangle->x2.ToSchUnits(), -aRectangle->y2.ToSchUnits() ) );
2698 if( aRectangle->rot )
2711 rectangle->
SetUnit( aGateNumber );
2722 const std::unique_ptr<EWIRE>& aWire,
int aGateNumber )
2724 wxCHECK( aSymbol && aWire,
nullptr );
2728 begin.
x = aWire->x1.ToSchUnits();
2729 begin.
y = -aWire->y1.ToSchUnits();
2730 end.x = aWire->x2.ToSchUnits();
2731 end.y = -aWire->y2.ToSchUnits();
2750 ( aWire->width.ToSchUnits() /
radius );
2751 begin =
center + centerStartVector;
2785 const std::unique_ptr<EPOLYGON>& aPolygon,
2788 wxCHECK( aSymbol && aPolygon,
nullptr );
2790 if( !aPolygon->IsValidOutline() )
2796 std::optional<VECTOR2I> first_pt;
2800 for(
const std::unique_ptr<EVERTEX>& evertex : aPolygon->vertices )
2802 pt =
VECTOR2I( evertex->x.ToSchUnits(), -evertex->y.ToSchUnits() );
2804 if( !first_pt.has_value() )
2819 prev_curve = evertex->curve;
2822 if( first_pt.has_value() )
2823 poly->
AddPoint( first_pt.value() );
2834 const std::unique_ptr<EPIN>& aPin,
int aGateNumber )
2836 wxCHECK( aSymbol && aPin,
nullptr );
2838 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>( aSymbol.get() );
2839 pin->SetPosition(
VECTOR2I( aPin->x.ToSchUnits(), -aPin->y.ToSchUnits() ) );
2845 pin->SetUnit( aGateNumber );
2847 int roti = aPin->rot ? aPin->rot->degrees : 0;
2855 default: wxFAIL_MSG( wxString::Format( wxT(
"Unhandled orientation (%d degrees)." ), roti ) );
2862 wxString length = aPin->length.Get();
2864 if( length == wxT(
"short" ) )
2866 else if( length == wxT(
"middle" ) )
2868 else if( length == wxT(
"long" ) )
2870 else if( length == wxT(
"point" ) )
2881 wxString visible = aPin->visible.Get();
2883 if( visible == wxT(
"off" ) )
2885 pin->SetNameTextSize( 0 );
2886 pin->SetNumberTextSize( 0 );
2888 else if( visible == wxT(
"pad" ) )
2890 pin->SetNameTextSize( 0 );
2892 else if( visible == wxT(
"pin" ) )
2894 pin->SetNumberTextSize( 0 );
2904 if( aPin->function )
2906 wxString function = aPin->function.Get();
2908 if( function == wxT(
"dot" ) )
2910 else if( function == wxT(
"clk" ) )
2912 else if( function == wxT(
"dotclk" ) )
2916 return pin.release();
2921 const std::unique_ptr<ETEXT>& aText,
int aGateNumber )
2923 wxCHECK( aSymbol && aText,
nullptr );
2925 std::unique_ptr<SCH_TEXT> libtext = std::make_unique<SCH_TEXT>();
2928 libtext->SetParent( aSymbol.get() );
2929 libtext->SetUnit( aGateNumber );
2930 libtext->SetPosition(
VECTOR2I( aText->x.ToSchUnits(), -aText->y.ToSchUnits() ) );
2932 const wxString& eagleText = aText->text;
2933 wxString adjustedText;
2934 wxStringTokenizer tokenizer( eagleText,
"\r\n" );
2937 while( tokenizer.HasMoreTokens() )
2939 wxString tmp =
interpretText( tokenizer.GetNextToken().Trim(
true ).Trim(
false ) );
2941 if( tokenizer.HasMoreTokens() )
2944 adjustedText += tmp;
2947 libtext->SetText( adjustedText.IsEmpty() ? wxString( wxS(
"~" ) ) : adjustedText );
2951 return libtext.release();
2957 wxCHECK( aText,
nullptr );
2959 std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>();
2961 const wxString& eagleText = aText->text;
2962 wxString adjustedText;
2963 wxStringTokenizer tokenizer( eagleText,
"\r\n" );
2966 while( tokenizer.HasMoreTokens() )
2968 wxString tmp =
interpretText( tokenizer.GetNextToken().Trim(
true ).Trim(
false ) );
2970 if( tokenizer.HasMoreTokens() )
2973 adjustedText += tmp;
2976 schtext->SetText( adjustedText.IsEmpty() ? wxString( wxS(
"\" \"" ) )
2979 schtext->SetPosition(
VECTOR2I( aText->x.ToSchUnits(), -aText->y.ToSchUnits() ) );
2981 schtext->SetItalic(
false );
2983 return schtext.release();
2988 const std::unique_ptr<ETEXT>& aAttributes )
const
2990 wxCHECK( aText && aAttributes, );
2995 if( aAttributes->ratio && aAttributes->ratio.CGet() > 12 )
2999 int degrees = aAttributes->rot ? aAttributes->rot->degrees : 0;
3000 bool mirror = aAttributes->rot ? aAttributes->rot->mirror :
false;
3001 bool spin = aAttributes->rot ? aAttributes->rot->spin :
false;
3009 wxCHECK( aField && aText, );
3033 auto onIntersection =
3045 const SEG* segAttached = segDesc.LabelAttached( label );
3047 if( segAttached && !onIntersection( labelPos ) )
3061 VECTOR2I wireDirection( segAttached->
B - segAttached->
A );
3063 if( ( wireDirection.
x == 0 ) && (wireDirection.
y == 0 ) )
3067 const VECTOR2I origPos( labelPos );
3070 bool checkPositive =
true;
3071 bool checkNegative =
true;
3076 while( ( !
move || onIntersection( labelPos ) ) && ( checkPositive || checkNegative ) )
3081 if( trial % 2 == 1 )
3083 labelPos =
VECTOR2I( origPos + wireDirection * trial / 2 );
3084 move = checkPositive = segAttached->
Contains( labelPos );
3088 labelPos =
VECTOR2I( origPos - wireDirection * trial / 2 );
3089 move = checkNegative = segAttached->
Contains( labelPos );
3099 if( wireDirection.
x == 0 )
3101 if( wireDirection.
y < 0 )
3106 else if( wireDirection.
y == 0 )
3108 if( wireDirection.
x < 0 )
3142 wxFileInputStream input( aFileName );
3147 wxTextInputStream
text( input );
3149 for(
int i = 0; i < 8; i++ )
3154 if(
text.ReadLine().Contains( wxS(
"<eagle" ) ) )
3172 if( !item->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
3176 item->SetPosition( aNewEndPoint );
3189 std::vector<SCH_LINE*> buses;
3190 std::vector<SCH_LINE*> wires;
3201 buses.push_back( line );
3202 else if( line->
IsWire() )
3203 wires.push_back( line );
3208 VECTOR2I wireStart = wire->GetStartPoint();
3209 VECTOR2I wireEnd = wire->GetEndPoint();
3213 VECTOR2I busStart = bus->GetStartPoint();
3214 VECTOR2I busEnd = bus->GetEndPoint();
3217 [](
int signX,
int signY ) ->
VECTOR2I
3229 if( wireStart.
y == wireEnd.
y && busStart.
x == busEnd.
x )
3233 if( testBusHit( wireStart ) )
3237 if( wireEnd.
x < busStart.
x )
3244 VECTOR2I p = wireStart + entrySize( -1, 0 );
3246 if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
3255 screen->
Append( busEntry );
3257 wire->SetStartPoint( p );
3259 else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
3268 screen->
Append( busEntry );
3270 wire->SetStartPoint( p );
3285 VECTOR2I p = wireStart + entrySize( 1, 0 );
3287 if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
3296 screen->
Append( busEntry );
3298 wire->SetStartPoint( p );
3300 else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
3309 screen->
Append( busEntry );
3311 wire->SetStartPoint( p );
3322 else if( testBusHit( wireEnd ) )
3326 if( wireStart.
x < busStart.
x )
3333 VECTOR2I p = wireEnd + entrySize( -1, 0 );
3335 if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3344 screen->
Append( busEntry );
3346 wire->SetEndPoint( p );
3348 else if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3357 screen->
Append( busEntry );
3358 moveLabels( wire, wireEnd + entrySize( -1, 0 ) );
3359 wire->SetEndPoint( wireEnd + entrySize( -1, 0 ) );
3374 VECTOR2I p = wireEnd + entrySize( 1, 0 );
3376 if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3385 screen->
Append( busEntry );
3387 wire->SetEndPoint( p );
3389 else if( testBusHit( wireEnd + entrySize( 0, 1 ) ) )
3398 screen->
Append( busEntry );
3400 wire->SetEndPoint( p );
3412 else if( wireStart.
x == wireEnd.
x && busStart.
y == busEnd.
y )
3416 if( testBusHit( wireStart ) )
3420 if( wireEnd.
y < busStart.
y )
3428 VECTOR2I p = wireStart + entrySize( 0, -1 );
3430 if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
3440 screen->
Append( busEntry );
3442 wire->SetStartPoint( p );
3444 else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
3454 screen->
Append( busEntry );
3456 wire->SetStartPoint( p );
3472 VECTOR2I p = wireStart + entrySize( 0, 1 );
3474 if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
3484 screen->
Append( busEntry );
3486 wire->SetStartPoint( p );
3488 else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
3498 screen->
Append( busEntry );
3500 wire->SetStartPoint( p );
3511 else if( testBusHit( wireEnd ) )
3515 if( wireStart.
y < busStart.
y )
3523 VECTOR2I p = wireEnd + entrySize( 0, -1 );
3525 if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
3535 screen->
Append( busEntry );
3537 wire->SetEndPoint( p );
3539 else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
3549 screen->
Append( busEntry );
3551 wire->SetEndPoint( p );
3567 VECTOR2I p = wireEnd + entrySize( 0, 1 );
3569 if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
3579 screen->
Append( busEntry );
3581 wire->SetEndPoint( p );
3583 else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
3593 screen->
Append( busEntry );
3595 wire->SetEndPoint( p );
3611 if( testBusHit( wireStart ) )
3613 VECTOR2I wirevector = wireStart - wireEnd;
3615 if( wirevector.
x > 0 )
3617 if( wirevector.
y > 0 )
3619 VECTOR2I p = wireStart + entrySize( -1, -1 );
3622 screen->
Append( busEntry );
3625 wire->SetStartPoint( p );
3629 VECTOR2I p = wireStart + entrySize( -1, 1 );
3632 screen->
Append( busEntry );
3635 wire->SetStartPoint( p );
3640 if( wirevector.
y > 0 )
3642 VECTOR2I p = wireStart + entrySize( 1, -1 );
3645 screen->
Append( busEntry );
3648 wire->SetStartPoint( p );
3652 VECTOR2I p = wireStart + entrySize( 1, 1 );
3655 screen->
Append( busEntry );
3658 wire->SetStartPoint( p );
3664 else if( testBusHit( wireEnd ) )
3666 VECTOR2I wirevector = wireStart - wireEnd;
3668 if( wirevector.
x > 0 )
3670 if( wirevector.
y > 0 )
3672 VECTOR2I p = wireEnd + entrySize( 1, 1 );
3675 screen->
Append( busEntry );
3678 wire->SetEndPoint( p );
3682 VECTOR2I p = wireEnd + entrySize( 1, -1 );
3685 screen->
Append( busEntry );
3688 wire->SetEndPoint( p );
3693 if( wirevector.
y > 0 )
3695 VECTOR2I p = wireEnd + entrySize( -1, 1 );
3698 screen->
Append( busEntry );
3701 wire->SetEndPoint( p );
3705 VECTOR2I p = wireEnd + entrySize( -1, -1 );
3708 screen->
Append( busEntry );
3711 wire->SetEndPoint( p );
3725 wxCHECK( aLabel,
nullptr );
3731 if( seg.Contains( labelPos ) )
3743 wxCHECK( aSymbol && aPin,
false );
3751 const auto& items = pointIt->second;
3753 wxCHECK( items.find( aPin ) != items.end(),
false );
3755 return items.size() > 1;
3769 int unit = aSymbol->
GetUnit();
3772 std::set<int> missingUnits;
3779 bool pinInUnit = !unit ||
pin->GetUnit() == unit;
3793 switch(
pin->GetOrientation() )
3810 aScreen->
Append( netLabel );
3813 else if( aUpdateSet )
3818 wxASSERT(
pin->GetUnit() );
3819 missingUnits.insert(
pin->GetUnit() );
3832 entry.
cmp = aSymbol;
3834 entry.
units.emplace( unit,
false );
3839 cmpIt->second.units[unit] =
false;
3842 if( !missingUnits.empty() )
3845 entry.
cmp = aSymbol;
3849 for(
int i : missingUnits )
3851 if( entry.
units.find( i ) != entry.
units.end() )
3852 entry.
units.emplace( i,
true );
3864 wxString ret = wxT(
"{" );
3866 wxStringTokenizer tokenizer( aEagleName,
"," );
3868 while( tokenizer.HasMoreTokens() )
3870 wxString member = tokenizer.GetNextToken();
3877 if( member.Freq(
'!' ) % 2 > 0 )
3878 member << wxT(
"!" );
3880 ret << member << wxS(
" " );
3895 std::unique_ptr<EPART>& epart =
m_eagleDoc->drawing->schematic->parts[aInstance->part];
3897 if( !epart || epart->deviceset.IsEmpty() )
3900 std::unique_ptr<ELIBRARY>& elibrary =
m_eagleDoc->drawing->schematic->libraries[epart->library];
3905 std::unique_ptr<EDEVICE_SET>& edeviceset = elibrary->devicesets[epart->deviceset];
3910 std::unique_ptr<EGATE>& egate = edeviceset->gates[aInstance->gate];
3915 std::unique_ptr<ESYMBOL>& esymbol = elibrary->symbols[egate->symbol];
3918 return esymbol.get();
3925 const wxString& aEagleFieldName,
3928 wxCHECK( aField && !aEagleFieldName.
IsEmpty(), );
3934 for(
const std::unique_ptr<ETEXT>&
text : esymbol->
texts )
3936 if(
text->text == aEagleFieldName )
3939 VECTOR2I pos(
text->x.ToSchUnits() + aInstance->x.ToSchUnits(),
3940 -
text->y.ToSchUnits() - aInstance->y.ToSchUnits() );
3942 bool mirror =
text->rot ?
text->rot->mirror :
false;
3944 if( aInstance->rot && aInstance->rot->mirror )
3948 pos.
y = -aInstance->y.ToSchUnits() +
text->y.ToSchUnits();
3961 std::vector<SCH_FIELD*> fields;
3966 retv = fields[0]->GetPosition();
3968 for(
size_t i = 1; i < fields.size(); i++ )
3970 if( fields[i]->GetPosition().x > retv.
x )
3971 retv.
x = fields[i]->GetPosition().x;
3973 if( fields[i]->GetPosition().y > retv.
y )
3974 retv.
y = fields[i]->GetPosition().y;
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
constexpr size_type GetWidth() const
constexpr Vec Centre() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr size_type GetHeight() const
constexpr const SizeVec & GetSize() const
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.
void SetFlags(EDA_ITEM_FLAGS aMask)
virtual void SetParent(EDA_ITEM *aParent)
virtual void SetEnd(const VECTOR2I &aEnd)
void SetCenter(const VECTOR2I &aCenter)
SHAPE_POLY_SET & GetPolyShape()
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
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)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual VECTOR2I GetTextSize() const
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
virtual const wxString & GetText() const
Return the string associated with the text object.
virtual void SetTextPos(const VECTOR2I &aPoint)
virtual int GetTextHeight() const
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
GR_TEXT_H_ALIGN_T GetHorizJustify() const
virtual void SetVisible(bool aVisible)
virtual EDA_ANGLE GetTextAngle() const
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
GR_TEXT_V_ALIGN_T GetVertJustify() const
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetItalic(bool aItalic)
Set the text to be italic - this will also update the font if needed.
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
EE_TYPE Overlapping(const BOX2I &aRect) const
ee_rtree::Iterator begin() const
Return a read/write iterator that points to the first.
ee_rtree::Iterator end() const
Return a read/write iterator that points to one past the last element in the EE_RTREE.
EE_TYPE OfType(KICAD_T aType) const
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
RAII class to set and restore the fontconfig reporter.
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
virtual void Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
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.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib)
Replace illegal LIB_ID item name characters with underscores '_'.
Define a library symbol object.
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.
void SetParent(LIB_SYMBOL *aParent=nullptr)
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()
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.
void SetHeightMils(double aHeightInMils)
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
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.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
bool IsValid() const
A simple test if the schematic is loaded, not a complete one.
Class for a wire to bus entry.
virtual const wxString & GetText() const override
Return the string associated with the text object.
void SetCanAutoplace(bool aCanPlace)
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.
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
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.
void loadFieldAttributes(SCH_FIELD *aField, const SCH_TEXT *aText) const
Move net labels that are detached from any wire to the nearest wire.
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
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.
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)
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.
SCH_IO(const wxString &aName)
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
void SetLayer(SCH_LAYER_ID aLayer)
virtual void SetUnit(int aUnit)
void SetShape(LABEL_FLAG_SHAPE aShape)
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,...
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.
VECTOR2I GetEndPoint() const
VECTOR2I GetStartPoint() const
bool IsBus() const
Return true if the line is a bus.
void SetEndPoint(const VECTOR2I &aPosition)
void SetNumber(const wxString &aNumber)
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
const PAGE_INFO & GetPageSettings() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPageSettings(const PAGE_INFO &aPageSettings)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
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
void SetStroke(const STROKE_PARAMS &aStroke) override
VECTOR2I GetCenter() const
void AddPoint(const VECTOR2I &aPosition)
VECTOR2I GetPosition() const override
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.
void SetFileName(const wxString &aFilename)
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)
SCH_SCREEN * GetScreen() const
void AutoplaceFields(SCH_SCREEN *aScreen, AUTOPLACE_ALGO aAlgo) override
Variant information for a schematic symbol.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
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()
VECTOR2I GetPinPhysicalPosition(const SCH_PIN *Pin) const
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
VECTOR2I GetPosition() const override
void SetPosition(const VECTOR2I &aPosition) override
OPT_VECTOR2I Intersect(const SEG &aSeg, bool aIgnoreEndpoints=false, bool aLines=false) const
Compute intersection point of segment (this) with segment aSeg.
bool Contains(const SEG &aSeg) const
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.
std::map< wxString, wxString > m_Fields
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
static REPORTER & GetInstance()
#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 opt_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.
OPTIONAL_XML_ATTRIBUTE< double > opt_double
static constexpr EDA_ANGLE ANGLE_VERTICAL
#define IGNORE_PARENT_GROUP
#define IS_NEW
New item, just created.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ FILLED_SHAPE
Fill with object color.
@ 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_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
SCH_LAYER_ID
Eeschema drawing layers.
@ PT_INPUT
usual pin input: must be connected
@ PT_NC
not connected (must be left open)
@ PT_TRISTATE
tri state bus pin
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_OPENCOLLECTOR
pin type open collector
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
@ PIN_RIGHT
The pin extends rightwards from the connection point.
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
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')
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
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.
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > KiCadSymbols
std::unordered_map< wxString, wxString > package
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::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
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< 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()
@ 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".
wxString GetCanonicalFieldName(FIELD_T aFieldType)
std::vector< std::string > header
std::vector< std::vector< std::string > > table
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
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.
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.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.