29#include <fmt/format.h>
30#include <wx/filename.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>
94 bbox.
Merge( item->GetBoundingBox() );
103 return aPinName.BeforeFirst(
'@' );
112 return aNetName.StartsWith( wxS(
"N$" ), &number ) && !number.empty() && number.IsNumber();
125 wxCHECK( currentSheet,
nullptr );
170 for(
const std::unique_ptr<ELAYER>& elayer : aLayers )
189 switch ( elayer->number)
219 int roti = int( eagleDegrees );
229 wxASSERT_MSG(
false, wxString::Format( wxT(
"Unhandled orientation (%d degrees)" ),
238 bool aMirror,
bool aSpin,
int aAbsDegress )
240 int align = aEagleAlignment;
242 if( aRelDegress == 90 )
246 else if( aRelDegress == 180 )
250 else if( aRelDegress == 270 )
256 if( aMirror ==
true )
258 if( aAbsDegress == 90 || aAbsDegress == 270 )
269 else if( aAbsDegress == 0 || aAbsDegress == 180 )
362 const std::map<std::string, UTF8>* aProperties )
364 wxASSERT( !aFileName || aSchematic !=
nullptr );
384 wxXmlNode* currentNode = xmlDocument.GetRoot();
394 unique_ptr<SCH_SHEET> tempVROwner;
398 wxCHECK_MSG( aSchematic->
IsValid(),
nullptr,
399 wxT(
"Can't append to a schematic with no root!" ) );
410 if( sheetPath.Last() == aAppendToMe )
422 tempVROwner = std::make_unique<SCH_SHEET>( aSchematic );
442 wxCHECK_MSG(
table,
nullptr,
"Could not load symbol lib table." );
444 m_pi.reset( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) );
452 wxString libTableUri = wxT(
"${KIPRJMOD}/" ) +
getLibFileName().GetFullName();
457 row.
SetURI( libTableUri );
467 m_eagleDoc = std::make_unique<EAGLE_DOC>( currentNode,
this );
500 const wxString& aLibraryPath,
501 const std::map<std::string, UTF8>* aProperties )
512 for(
const auto& [symName, libSymbol] : it->second.KiCadSymbols )
513 aSymbolNameList.push_back( symName );
519 const wxString& aLibraryPath,
520 const std::map<std::string, UTF8>* aProperties )
531 for(
const auto& [symName, libSymbol] : it->second.KiCadSymbols )
532 aSymbolList.push_back( libSymbol.get() );
538 const std::map<std::string, UTF8>* aProperties )
549 auto it2 = it->second.KiCadSymbols.find( aAliasName );
551 if( it2 != it->second.KiCadSymbols.end() )
552 return it2->second.get();
561 wxFileName fn( aLibraryPath );
563 if( fn.IsFileReadable() && fn.GetModificationTime().IsValid() )
564 return fn.GetModificationTime().GetValue().GetValue();
595 std::unique_ptr<EAGLE_DOC> doc = std::make_unique<EAGLE_DOC>( xmlDocument.GetRoot(),
this );
599 m_version = ( doc->version.IsEmpty() ) ? wxString( wxS(
"0.0" ) ) : doc->version;
611 wxXmlDocument xmlDocument;
612 wxFFileInputStream stream(
m_filename.GetFullPath() );
623 std::vector<uint8_t>
bytes;
624 bytes.resize(
static_cast<size_t>( stream.GetLength() ) );
627 if( stream.LastRead() !=
bytes.size() )
631 std::unique_ptr<wxXmlDocument> binDocument = binParser.
Parse(
bytes );
633 xmlDocument.SetRoot( binDocument->DetachRoot() );
638 wxTextInputStream
text( stream );
639 wxString line =
text.ReadLine();
641 if( !line.StartsWith( wxT(
"<?xml" ) ) && !line.StartsWith( wxT(
"<!--" ) )
642 && !line.StartsWith( wxT(
"<eagle " ) ) )
644 THROW_IO_ERRORF(
_(
"'%s' is an Eagle binary-format file; only Eagle XML-format files can be imported." ),
648#if wxCHECK_VERSION( 3, 3, 0 )
651 if( !xmlDocument.Load( stream, wxXMLDOC_NONE, &err ) )
653 if( err.message == wxS(
"no element found" ) )
657 wxMemoryOutputStream memOutput;
660 header <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
661 header <<
"<!DOCTYPE eagle SYSTEM \"eagle.dtd\">\n";
663 wxScopedCharBuffer headerBuf = header.utf8_str();
664 memOutput.Write( headerBuf.data(), headerBuf.length() );
666 wxFFileInputStream stream2(
m_filename.GetFullPath() );
667 memOutput.Write( stream2 );
669 wxMemoryInputStream memInput( memOutput );
671 if( !xmlDocument.Load( memInput, wxXMLDOC_NONE, &err ) )
678 THROW_IO_ERRORF(
_(
"Unable to read file '%s'.\n'%s' at line %d, column %d, offset %d" ),
679 m_filename.GetFullPath(), err.message, err.line, err.column, err.offset );
683 if( !xmlDocument.Load( stream ) )
687 wxMemoryOutputStream memOutput;
690 header <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
691 header <<
"<!DOCTYPE eagle SYSTEM \"eagle.dtd\">\n";
693 wxScopedCharBuffer headerBuf = header.utf8_str();
694 memOutput.Write( headerBuf.data(), headerBuf.length() );
696 wxFFileInputStream stream2(
m_filename.GetFullPath() );
697 memOutput.Write( stream2 );
699 wxMemoryInputStream memInput( memOutput );
701 if( !xmlDocument.Load( memInput ) )
712 wxCHECK( aDrawing, );
716 if( aDrawing->library )
724 if( aDrawing->schematic )
731 for(
const std::unique_ptr<ESHEET>& esheet : aSchematic.
sheets )
733 for(
const std::unique_ptr<ENET>& enet : esheet->nets )
735 wxString netName = enet->netname;
744 for(
const auto& [modname, emodule] : aSchematic.
modules )
746 for(
const std::unique_ptr<ESHEET>& esheet : emodule->sheets )
748 for(
const std::unique_ptr<ENET>& enet : esheet->nets )
750 wxString netName = enet->netname;
765 if( aSchematic.
sheets.empty() )
772 if( variantDef->current.value_or(
false ) )
777 for(
const auto& [
name, epart] : aSchematic.
parts )
780 for(
const auto& [modName, emodule] : aSchematic.
modules )
782 for(
const auto& [partName, epart] : emodule->parts )
788 for(
const auto& [libName, elibrary] : aSchematic.
libraries )
791 elib->
name = elibrary->GetName();
807 std::vector<SCH_SHEET*> eaglePages;
808 eaglePages.reserve( aSchematic.
sheets.size() );
810 for(
const std::unique_ptr<ESHEET>& esheet : aSchematic.
sheets )
814 std::unique_ptr<SCH_SHEET> sheet = std::make_unique<SCH_SHEET>(
m_rootSheet );
816 sheet->SetScreen( screen );
818 wxCHECK2( sheet && screen,
continue );
820 wxString pageNo = wxString::Format( wxT(
"%d" ),
m_sheetIndex );
828 eaglePages.push_back( sheet.release() );
833 if( !eaglePages.empty() )
858 struct MISSING_UNIT_PLACEMENT
868 std::map<SCH_SCREEN*, MISSING_UNIT_PLACEMENT> placements;
872 const SCH_SYMBOL* origSymbol = cmp.second.cmp;
874 for(
auto& unitEntry : cmp.second.units )
876 if( unitEntry.second ==
false )
880 int unit = unitEntry.first;
891 targetScreen = fallbackSheet->
GetScreen();
893 targetScreen = schematicRoot->
GetScreen();
896 auto placementIt = placements.find( targetScreen );
898 if( placementIt == placements.end() )
900 MISSING_UNIT_PLACEMENT placement;
901 placement.screen = targetScreen;
905 SCH_SHEET* targetSheet = placement.sheetpath.Last();
910 placement.newCmpPosition =
VECTOR2I( placement.sheetBbox.GetLeft(),
911 placement.sheetBbox.GetBottom() );
912 placement.maxY = placement.sheetBbox.GetY();
913 placementIt = placements.emplace( targetScreen, placement ).first;
916 MISSING_UNIT_PLACEMENT& placement = placementIt->second;
918 symbol->SetUnitSelection( &placement.sheetpath, unit );
919 symbol->SetUnit( unit );
920 symbol->SetOrientation( 0 );
921 symbol->AddHierarchicalReference( placement.sheetpath.Path(), reference, unit );
924 BOX2I cmpBbox = symbol->GetBoundingBox();
925 int posY = placement.newCmpPosition.y + cmpBbox.
GetHeight();
926 symbol->SetPosition(
VECTOR2I( placement.newCmpPosition.x, posY ) );
927 placement.newCmpPosition.x += cmpBbox.
GetWidth();
928 placement.maxY = std::max( placement.maxY, posY );
930 if( placement.newCmpPosition.x >= placement.pageSizeIU.x )
931 placement.newCmpPosition =
VECTOR2I( placement.sheetBbox.GetLeft(),
936 placement.screen->Append( symbol.release() );
949 wxCHECK( sheet && screen, );
953 std::string filename;
957 if( aSheet->description )
958 sheet->
SetName( aSheet->description.value().text );
963 replace( filename.begin(), filename.end(),
' ',
'_' );
968 fn.SetPath(
m_schematic->Project().GetProjectPath() );
969 fn.SetName( filename );
976 for(
const auto& [
name, moduleinst] : aSheet->moduleinsts )
983 for(
const std::unique_ptr<EPOLYGON>& epoly : aSheet->plain->polygons )
989 for(
const std::unique_ptr<EWIRE>& ewire : aSheet->plain->wires )
995 for(
const std::unique_ptr<ETEXT>& etext : aSheet->plain->texts )
998 for(
const std::unique_ptr<ECIRCLE>& ecircle : aSheet->plain->circles )
1001 for(
const std::unique_ptr<ERECT>& erectangle : aSheet->plain->rectangles )
1004 for(
const std::unique_ptr<EFRAME>& eframe : aSheet->plain->frames )
1006 std::vector<SCH_ITEM*> frameItems;
1017 for(
const std::unique_ptr<EINSTANCE>& einstance : aSheet->instances )
1029 for(
const std::unique_ptr<EBUS>& ebus : aSheet->busses )
1035 loadSegments( ebus->segments, busName, wxString(), wiring,
true );
1038 for(
const std::unique_ptr<ENET>& enet : aSheet->nets )
1041 wxString netName = enet->netname;
1042 wxString netClass = wxString::Format( wxS(
"%i" ), enet->netcode );
1045 loadSegments( enet->segments, netName, netClass, wiring );
1061 if( pageSizeIU.
x < targetSheetSize.
x )
1064 if( pageSizeIU.
y < targetSheetSize.
y )
1071 VECTOR2I sheetcentre( pageSizeIU.
x / 2, pageSizeIU.
y / 2 );
1075 VECTOR2I translation = sheetcentre - itemsCentre;
1076 translation.
x = translation.
x - translation.
x %
schIUScale.MilsToIU( 100 );
1077 translation.
y = translation.
y - translation.
y %
schIUScale.MilsToIU( 100 );
1089 std::vector<SCH_ITEM*> allItems;
1091 std::copy( screen->
Items().
begin(), screen->
Items().
end(), std::back_inserter( allItems ) );
1095 item->SetPosition( item->GetPosition() + translation );
1113 wxCHECK( currentSheet &¤tScreen, );
1119 auto it =
m_eagleDoc->drawing->schematic->modules.find( aModuleInstance->moduleinst );
1122 if( it ==
m_eagleDoc->drawing->schematic->modules.end() )
1124 THROW_IO_ERRORF(
_(
"No module instance '%s' found in schematic file:\n%s" ),
1125 aModuleInstance->name,
m_filename.GetFullPath() );
1129 fn.SetName( aModuleInstance->moduleinst );
1133 VECTOR2I size( it->second->dx.ToSchUnits(), it->second->dy.ToSchUnits() );
1135 int halfX =
KiROUND( size.
x / 2.0 );
1136 int halfY =
KiROUND( size.
y / 2.0 );
1137 int portExtWireLength =
schIUScale.mmToIU( 5.08 );
1138 VECTOR2I pos( aModuleInstance->x.ToSchUnits() - halfX,
1139 -aModuleInstance->y.ToSchUnits() - halfY );
1141 std::unique_ptr<SCH_SHEET> newSheet = std::make_unique<SCH_SHEET>( currentSheet, pos, size );
1149 if( schFile->GetFileName() == fn.GetFullPath() )
1151 newScreen = schFile;
1156 bool isNewSchFile = ( newScreen == nullptr );
1164 wxCHECK( newSheet && newScreen, );
1166 newSheet->SetScreen( newScreen );
1167 newSheet->SetFileName( fn.GetFullName() );
1168 newSheet->SetName( aModuleInstance->name );
1170 for(
const auto& [portName, port] : it->second->ports )
1173 int pinOffset = port->coord.ToSchUnits();
1176 if( port->side ==
"left" )
1180 pinPos.
y = pos.
y + halfY - pinOffset;
1181 portExtWireEndpoint = pinPos;
1182 portExtWireEndpoint.
x -= portExtWireLength;
1184 else if( port->side ==
"right" )
1187 pinPos.
x = pos.
x + size.
x;
1188 pinPos.
y = pos.
y + halfY - pinOffset;
1189 portExtWireEndpoint = pinPos;
1190 portExtWireEndpoint.
x += portExtWireLength;
1192 else if( port->side ==
"top" )
1195 pinPos.
x = pos.
x + halfX + pinOffset;
1197 portExtWireEndpoint = pinPos;
1198 portExtWireEndpoint.
y -= portExtWireLength;
1200 else if( port->side ==
"bottom" )
1203 pinPos.
x = pos.
x + halfX + pinOffset;
1204 pinPos.
y = pos.
y + size.
y;
1205 portExtWireEndpoint = pinPos;
1206 portExtWireEndpoint.
y += portExtWireLength;
1211 currentScreen->
Append( portExtWire );
1215 if( port->direction.has_value() )
1217 if( port->direction.value() ==
"in" )
1219 else if( port->direction.value() ==
"out" )
1221 else if( port->direction.value() ==
"io" )
1223 else if( port->direction.value() ==
"hiz" )
1235 newSheet->AddPin( sheetPin );
1238 wxString pageNo = wxString::Format( wxT(
"%d" ),
m_sheetIndex );
1240 newSheet->SetParent( currentSheet );
1243 currentScreen->
Append( newSheet.release() );
1245 m_modules.push_back( it->second.get() );
1251 for(
const std::unique_ptr<ESHEET>& esheet : it->second->sheets )
1261 wxCHECK2( emoduleInst,
continue );
1263 refPrefix += emoduleInst->name + wxS(
":" );
1274 wxCHECK2( symbol && !symbol->
GetInstances().empty(),
continue );
1277 wxString newReference = refPrefix + inst.
m_Reference.AfterLast(
':' );
1293 int xMin = aFrame->x1.ToSchUnits();
1294 int xMax = aFrame->x2.ToSchUnits();
1295 int yMin = -aFrame->y1.ToSchUnits();
1296 int yMax = -aFrame->y2.ToSchUnits();
1299 std::swap( xMin, xMax );
1302 std::swap( yMin, yMax );
1310 aItems.push_back( lines );
1312 if( !( aFrame->border_left ==
false ) )
1317 aItems.push_back( lines );
1320 int height = yMax - yMin;
1323 int legendPosX = xMin +
schIUScale.MilsToIU( 75 );
1324 double rowSpacing = height / double( aFrame->rows );
1325 double legendPosY = yMin + ( rowSpacing / 2 );
1327 for( i = 1; i < aFrame->rows; i++ )
1329 int newY =
KiROUND( yMin + ( rowSpacing * (
double) i ) );
1333 aItems.push_back( lines );
1336 char legendChar =
'A';
1338 for( i = 0; i < aFrame->rows; i++ )
1345 legendText->
SetText( wxString( legendChar ) );
1347 aItems.push_back( legendText );
1349 legendPosY += rowSpacing;
1353 if( !( aFrame->border_right ==
false ) )
1358 aItems.push_back( lines );
1361 int height = yMax - yMin;
1364 int legendPosX = xMax -
schIUScale.MilsToIU( 75 );
1365 double rowSpacing = height / double( aFrame->rows );
1366 double legendPosY = yMin + ( rowSpacing / 2 );
1368 for( i = 1; i < aFrame->rows; i++ )
1370 int newY =
KiROUND( yMin + ( rowSpacing * (
double) i ) );
1374 aItems.push_back( lines );
1377 char legendChar =
'A';
1379 for( i = 0; i < aFrame->rows; i++ )
1386 legendText->
SetText( wxString( legendChar ) );
1388 aItems.push_back( legendText );
1390 legendPosY += rowSpacing;
1394 if( !( aFrame->border_top ==
false ) )
1399 aItems.push_back( lines );
1402 int width = xMax - xMin;
1405 int legendPosY = yMin +
schIUScale.MilsToIU( 75 );
1406 double columnSpacing = width / double( aFrame->columns );
1407 double legendPosX = xMin + ( columnSpacing / 2 );
1409 for( i = 1; i < aFrame->columns; i++ )
1411 int newX =
KiROUND( xMin + ( columnSpacing * (
double) i ) );
1415 aItems.push_back( lines );
1420 for( i = 0; i < aFrame->columns; i++ )
1427 legendText->
SetText( fmt::format(
"{}", legendNo++ ) );
1429 aItems.push_back( legendText );
1430 legendPosX += columnSpacing;
1434 if( !( aFrame->border_bottom ==
false ) )
1439 aItems.push_back( lines );
1442 int width = xMax - xMin;
1445 int legendPosY = yMax -
schIUScale.MilsToIU( 75 );
1446 double columnSpacing = width / double( aFrame->columns );
1447 double legendPosX = xMin + ( columnSpacing / 2 );
1449 for( i = 1; i < aFrame->columns; i++ )
1451 int newX =
KiROUND( xMin + ( columnSpacing * (
double) i ) );
1455 aItems.push_back( lines );
1460 for( i = 0; i < aFrame->columns; i++ )
1467 legendText->
SetText( fmt::format(
"{}", legendNo++ ) );
1469 aItems.push_back( legendText );
1470 legendPosX += columnSpacing;
1480 std::map<VECTOR2I, int> netAt;
1482 for(
const std::unique_ptr<ENET>& enet : aSheet->nets )
1484 auto netId = wiring.
NetIds.try_emplace( enet->netname,
static_cast<int>( wiring.
NetIds.size() ) + 1 ).first;
1485 const int net = netId->second;
1487 for(
const std::unique_ptr<ESEGMENT>& esegment : enet->segments )
1489 std::vector<SEG> segmentWires;
1491 for(
const std::unique_ptr<EWIRE>& ewire : esegment->wires )
1496 SEG seg(
VECTOR2I( ewire->x1.ToSchUnits(), -ewire->y1.ToSchUnits() ),
1497 VECTOR2I( ewire->x2.ToSchUnits(), -ewire->y2.ToSchUnits() ) );
1500 segmentWires.push_back( seg );
1501 netAt.try_emplace( seg.
A, net );
1502 netAt.try_emplace( seg.
B, net );
1505 for(
const std::unique_ptr<EJUNCTION>& ejunction : esegment->junctions )
1507 VECTOR2I pos( ejunction->x.ToSchUnits(), -ejunction->y.ToSchUnits() );
1510 netAt.try_emplace( pos, net );
1514 for(
const std::unique_ptr<ELABEL>& elabel : esegment->labels )
1516 const VECTOR2I pos( elabel->x.ToSchUnits(), -elabel->y.ToSchUnits() );
1518 if( std::any_of( segmentWires.begin(), segmentWires.end(),
1519 [&](
const SEG& aSeg )
1521 return aSeg.Contains( pos );
1538 if( unit &&
pin->GetUnit() &&
pin->GetUnit() != unit )
1542 auto it = netAt.find( pos );
1553 const wxString& netName,
const wxString& aNetClass,
1561 size_t segmentCount = aSegments.size();
1563 for(
const std::unique_ptr<ESEGMENT>& esegment : aSegments )
1565 bool labelled =
false;
1566 bool firstWireFound =
false;
1572 for(
const std::unique_ptr<EWIRE>& ewire : esegment->wires )
1577 std::vector<SEG> pieces = { eagleWire };
1578 std::vector<SCH_ITEM*> items = { wire };
1589 Report( wxString::Format(
_(
"A wire of net %s passes over a pin or wire of another net and could "
1590 "not be rerouted. The nets may be joined and require manual fixing." ),
1596 for(
size_t i = 1; i < pieces.size(); i++ )
1602 items.push_back( piece );
1605 for(
size_t i = 0; i < pieces.size(); i++ )
1607 if( pieces.size() > 1 )
1617 const SEG& thisWire = pieces[i];
1621 if( !firstWireFound )
1623 firstWire = thisWire;
1624 firstWireFound =
true;
1630 if( !desc.labels.empty() && desc.labels.front()->GetText() == netName )
1633 for(
const SEG& seg : desc.segs )
1642 segDesc.
segs.push_back( thisWire );
1643 screen->
Append( items[i] );
1647 for(
const std::unique_ptr<EJUNCTION>& ejunction : esegment->junctions )
1650 for(
const std::unique_ptr<ELABEL>& elabel : esegment->labels )
1655 wxASSERT( segDesc.
labels.empty() || segDesc.
labels.front()->GetText() == label->
GetText() );
1657 segDesc.
labels.push_back( label );
1661 for(
const std::unique_ptr<EPINREF>& epinref : esegment->pinRefs )
1663 wxString part = epinref->part;
1664 wxString
pin = epinref->pin;
1666 auto powerPort =
m_powerPorts.find( wxT(
"#" ) + part );
1675 if( !labelled && firstWireFound )
1677 std::unique_ptr<SCH_LABEL_BASE> label;
1689 bool joinedByName = segmentCount > 1 ||
m_netCounts[netName] > 1;
1704 label->SetPosition( firstWire.
A );
1708 if( firstWire.
A.
y == firstWire.
B.
y )
1710 if( firstWire.
B.
x > firstWire.
A.
x )
1715 else if( firstWire.
A.
x == firstWire.
B.
x )
1717 if( firstWire.
B.
y > firstWire.
A.
y )
1724 segDesc.
labels.push_back( label.get() );
1725 screen->
Append( label.release() );
1734 if( !aPolygon->IsValidOutline() )
1737 std::unique_ptr<SCH_SHAPE> poly = std::make_unique<SCH_SHAPE>(
SHAPE_T::POLY );
1739 std::optional<double> prev_curve;
1741 for(
const std::unique_ptr<EVERTEX>& evertex : aPolygon->vertices )
1743 pt =
VECTOR2I( evertex->x.ToSchUnits(), -evertex->y.ToSchUnits() );
1745 if( prev_curve.has_value() )
1749 poly->GetPolyShape().Append( arc, -1, -1,
ARC_ACCURACY );
1753 poly->AddPoint( pt );
1757 prev_curve = evertex->curve;
1760 poly->SetLayer(
kiCadLayer( aPolygon->layer ) );
1764 return poly.release();
1772 start.
x = aWire->x1.ToSchUnits();
1773 start.
y = -aWire->y1.ToSchUnits();
1774 end.x = aWire->x2.ToSchUnits();
1775 end.y = -aWire->y2.ToSchUnits();
1778 endpoints =
SEG( start,
end );
1787 std::unique_ptr<SCH_SHAPE> arc = std::make_unique<SCH_SHAPE>(
SHAPE_T::ARC );
1790 arc->SetCenter(
center );
1791 arc->SetStart( start );
1798 return arc.release();
1802 std::unique_ptr<SCH_LINE> line = std::make_unique<SCH_LINE>();
1804 line->SetStartPoint( start );
1805 line->SetEndPoint(
end );
1806 line->SetLayer(
kiCadLayer( aWire->layer ) );
1809 return line.release();
1817 VECTOR2I center( aCircle->x.ToSchUnits(), -aCircle->y.ToSchUnits() );
1830 std::unique_ptr<SCH_SHAPE> rectangle = std::make_unique<SCH_SHAPE>(
SHAPE_T::RECTANGLE );
1832 rectangle->SetLayer(
kiCadLayer( aRectangle->layer ) );
1833 rectangle->SetPosition(
VECTOR2I( aRectangle->x1.ToSchUnits(), -aRectangle->y1.ToSchUnits() ) );
1834 rectangle->SetEnd(
VECTOR2I( aRectangle->x2.ToSchUnits(), -aRectangle->y2.ToSchUnits() ) );
1836 if( aRectangle->rot.has_value() )
1838 VECTOR2I pos( rectangle->GetPosition() );
1845 rectangle->SetPosition( pos );
1846 rectangle->SetEnd(
end );
1852 return rectangle.release();
1858 std::unique_ptr<SCH_JUNCTION> junction = std::make_unique<SCH_JUNCTION>();
1860 VECTOR2I pos( aJunction->x.ToSchUnits(), -aJunction->y.ToSchUnits() );
1862 junction->SetPosition( pos );
1864 return junction.release();
1869 const wxString& aNetName,
bool aIsBus )
1871 VECTOR2I elabelpos( aLabel->x.ToSchUnits(), -aLabel->y.ToSchUnits() );
1876 std::unique_ptr<SCH_LABEL_BASE> label;
1878 VECTOR2I textSize =
KiROUND( aLabel->size.ToSchUnits() * 0.7, aLabel->size.ToSchUnits() * 0.7 );
1880 auto findModulePort =
1881 [&]() ->
const EPORT*
1886 const auto& ports =
m_modules.back()->ports;
1887 const auto it = ports.find( aNetName );
1888 return it == ports.end() ? nullptr : it->second.get();
1891 const EPORT* port = findModulePort();
1895 std::unique_ptr<SCH_HIERLABEL> hierLabel = std::make_unique<SCH_HIERLABEL>();
1902 else if( port->
direction.value() ==
"out" )
1904 else if( port->
direction.value() ==
"io" )
1906 else if( port->
direction.value() ==
"hiz" )
1910 hierLabel->SetLabelShape( type );
1912 label = std::move( hierLabel );
1916 label = std::make_unique<SCH_LABEL>();
1920 label = std::make_unique<SCH_GLOBALLABEL>();
1924 label->SetPosition( elabelpos );
1925 label->SetTextSize( textSize );
1928 if( aLabel->rot.has_value() )
1931 int angle =
KiROUND( aLabel->rot.value().degrees );
1942 return label.release();
1947 const std::vector<SEG>& aLines )
const
1950 const SEG* nearestLine =
nullptr;
1952 double d, mindistance = std::numeric_limits<double>::max();
1958 for(
const SEG& line : aLines )
1960 VECTOR2I testpoint = line.NearestPoint( aPoint );
1963 if( d < mindistance )
1966 nearestPoint = testpoint;
1967 nearestLine = &line;
1971 return std::make_pair( nearestPoint, nearestLine );
1976 const std::map<wxString, std::unique_ptr<EPART>>& aParts )
1978 wxCHECK( aInstance, );
1984 const auto partIt = aParts.find( aInstance->part );
1986 if( partIt == aParts.end() )
1988 Report( wxString::Format(
_(
"Error parsing Eagle file. Could not find '%s' "
1989 "instance but it is referenced in the schematic." ),
1996 const std::unique_ptr<EPART>& epart = partIt->second;
1998 wxString libName = epart->library;
2001 if( epart->libraryUrn.has_value() )
2002 libName += wxS(
"_" ) + epart->libraryUrn.value().assetId;
2004 wxString gatename = epart->deviceset + wxS(
"_" ) + epart->device + wxS(
"_" ) + aInstance->gate;
2005 wxString symbolname = wxString( epart->deviceset + epart->device );
2006 wxString kiPackageName = epart->deviceset + epart->device;
2008 if( epart->technology.has_value() )
2009 symbolname += epart->technology.value();
2011 symbolname.Replace( wxT(
"*" ), wxEmptyString );
2012 kiPackageName.Replace( wxT(
"*" ), wxEmptyString );
2021 wxString altSymbolName = libName + wxT(
"_" ) + symbolname;
2024 wxString libIdSymbolName = altSymbolName;
2030 Report( wxString::Format( wxS(
"Eagle library '%s' not found while looking up symbol for "
2031 "deviceset '%s', device '%s', and gate '%s." ),
2036 const auto gateIt = libIt->second.GateToUnitMap.find( gatename );
2038 if( gateIt == libIt->second.GateToUnitMap.end() )
2040 Report( wxString::Format( wxS(
"Symbol not found for deviceset '%s', device '%s', and "
2041 "gate '%s in library '%s'." ),
2046 int unit = gateIt->second;
2051 auto p = elib->
package.find( kisymbolname );
2053 if( p != elib->
package.end() )
2055 package = p->second;
2059 p = elib->
package.find( kiPackageName );
2061 if( p != elib->
package.end() )
2062 package = p->second;
2066 std::map<std::string, UTF8> properties;
2073 part =
m_pi->LoadSymbol(
getLibFileName().GetFullPath(), kisymbolname, &properties );
2074 libIdSymbolName = kisymbolname;
2079 Report( wxString::Format(
_(
"Could not find '%s' in the imported library." ),
2086 std::unique_ptr<SCH_SYMBOL> symbol = std::make_unique<SCH_SYMBOL>();
2087 symbol->SetLibId( libId );
2088 symbol->SetUnit( unit );
2089 symbol->SetPosition(
VECTOR2I( aInstance->x.ToSchUnits(), -aInstance->y.ToSchUnits() ) );
2092 if( !package.IsEmpty() )
2094 wxString footprint =
m_schematic->Project().GetProjectName() + wxT(
":" ) + package;
2098 if( aInstance->rot.has_value() )
2102 if( aInstance->rot.value().mirror )
2103 symbol->MirrorHorizontally( aInstance->x.ToSchUnits() );
2106 std::vector<SCH_FIELD*> partFields;
2111 for(
const SCH_FIELD* partField : partFields )
2115 if( partField->IsMandatory() )
2116 symbolField = symbol->GetField( partField->GetId() );
2118 symbolField = symbol->GetField( partField->GetName() );
2125 newField.
SetText( partField->GetText() );
2129 symbol->AddField( newField );
2134 symbolField->
SetTextPos( symbol->GetPosition() + partField->GetTextPos() );
2138 wxString reference = aInstance->part;
2139 bool referenceVisible = !reference.IsEmpty();
2143 if( package.IsEmpty() )
2144 reference.Prepend(
'#' );
2147 if( reference.find_last_not_of( wxT(
"0123456789" ) ) == ( reference.Length()-1 ) )
2148 reference.Append( wxT(
"0" ) );
2153 if( reference.find_first_not_of( wxT(
"0123456789" ) ) != 0 )
2154 reference.Prepend( wxT(
"UNK" ) );
2158 if( aInstance->part.find_first_not_of( wxT(
"#" ) ) != 0 )
2159 reference.Prepend( wxT(
"UNK" ) );
2162 referenceField->
SetVisible( referenceVisible );
2163 referenceField->
SetText( reference );
2166 bool userValue =
m_userValue.at( libIdSymbolName );
2174 if( epart->value.has_value() && !epart->value.value().IsEmpty() )
2176 valueField->
SetText( epart->value.value() );
2180 valueField->
SetText( kisymbolname );
2186 for(
const auto& [ attrName, attr ] : epart->attributes )
2192 if( !symbol->GetFields().empty() )
2193 newField.
SetTextPos( symbol->GetFields().back().GetPosition() );
2195 if( attr->value.has_value() )
2196 newField.
SetText( attr->value.value() );
2198 if( attr->display.has_value() && attr->display.value() ==
EATTR::Off )
2201 symbol->AddField( newField );
2204 bool valueAttributeFound =
false;
2205 bool nameAttributeFound =
false;
2208 for(
auto& [
name, eattr] : aInstance->attributes )
2212 if( eattr->name.Lower() == wxT(
"name" ) )
2215 nameAttributeFound =
true;
2217 else if( eattr->name.Lower() == wxT(
"value" ) )
2220 valueAttributeFound =
true;
2224 field = symbol->GetField( eattr->name );
2232 if( eattr->size.has_value() )
2236 int absdegrees = eattr->rot.has_value() ?
KiROUND( eattr->rot.value().degrees ) : 0;
2237 bool mirror = eattr->rot.has_value() ? eattr->rot.value().mirror :
false;
2238 bool spin = eattr->rot.has_value() ? eattr->rot.value().spin :
false;
2240 if( aInstance->rot.has_value() && aInstance->rot.value().mirror )
2243 if( eattr->display.has_value() && ( eattr->display.value() ==
EATTR::Off
2249 int rotation = aInstance->rot.has_value() ?
KiROUND( aInstance->rot.value().degrees ) : 0;
2250 int reldegrees =
KiROUND( absdegrees - rotation + 360.0 );
2258 if( aInstance->smashed.has_value() && aInstance->smashed.value() )
2260 symbol->GetField(
FIELD_T::VALUE )->SetVisible( valueAttributeFound );
2272 wxCHECK2( emoduleInst,
continue );
2274 refPrefix += emoduleInst->name + wxS(
":" );
2277 symbol->AddHierarchicalReference(
m_sheetPath.Path(), refPrefix + reference, unit );
2283 symbol->SetLibSymbol( part->
Flatten().release() );
2285 for(
const auto& [
name, variant] : epart->variants )
2289 if( variant->populate.has_value() && variant->populate.value() ==
false )
2290 symbolVariant.
m_DNP =
true;
2292 if( variant->value )
2295 if( variant->technology.has_value() )
2297 auto eLibIt =
m_eagleDoc->drawing->schematic->libraries.find( epart->library );
2299 if( eLibIt ==
m_eagleDoc->drawing->schematic->libraries.end() )
2301 Report( wxString::Format( wxS(
"Library '%s' not found in schematic." ), epart->library ),
2306 auto eDeviceSetIt = eLibIt->second->devicesets.find( epart->deviceset );
2308 if( eDeviceSetIt == eLibIt->second->devicesets.end() )
2310 Report( wxString::Format( wxS(
"Device set '%s' not found in library '%s'." ),
2316 auto eDeviceIt = eDeviceSetIt->second->devices.find( epart->device );
2318 if( eDeviceIt == eDeviceSetIt->second->devices.end() )
2320 Report( wxString::Format( wxS(
"Device '%s' not found in device set '%s' in library '%s'." ),
2327 auto eTechnologyIt = eDeviceIt->second->technologies.find( variant->technology.value() );
2329 if( eTechnologyIt == eDeviceIt->second->technologies.end() )
2331 Report( wxString::Format( wxS(
"Technology '%s' not found in device '%s' in device set '%s' "
2332 "in library '%s'." ),
2333 variant->technology.value(),
2340 for(
const std::unique_ptr<EATTR>& attr : eTechnologyIt->second->attributes )
2344 if( attr->value.has_value() )
2345 attrValue = attr->value.value();
2347 symbolVariant.
m_Fields[attr->name] = attrValue;
2354 for(
const SCH_PIN*
pin : symbol->GetLibPins() )
2360 symbol->ClearFlags();
2362 screen->
Append( symbol.release() );
2368 wxCHECK( aLibrary && aEagleLibrary,
nullptr );
2375 wxString prefix = edeviceset->prefix.value_or( wxEmptyString );
2376 wxString deviceSetDescr;
2378 if( edeviceset->description )
2382 for(
const auto& [devname, edevice] : edeviceset->devices )
2384 std::vector<std::unique_ptr<LIB_SYMBOL>> derivedSymbols;
2387 wxString symbolName = edeviceset->name + edevice->name;
2388 symbolName.Replace( wxT(
"*" ), wxEmptyString );
2389 wxASSERT( !symbolName.IsEmpty() );
2392 if( edevice->package.has_value() )
2393 aEagleLibrary->
package[symbolName] = edevice->package.value();
2396 std::unique_ptr<LIB_SYMBOL> libSymbol = std::make_unique<LIB_SYMBOL>( symbolName );
2399 int gate_count =
static_cast<int>( edeviceset->gates.size() );
2401 if( gate_count > 1 )
2402 libSymbol->SetUnitCount( gate_count,
true );
2404 libSymbol->LockUnits(
true );
2408 if( prefix.length() == 0 )
2416 reference->
SetText( edevice->package.has_value() ? prefix :
'#' + prefix );
2419 libSymbol->GetValueField().SetVisible(
true );
2422 bool ispower =
false;
2424 for(
const auto& [gateName, egate] : edeviceset->gates )
2426 const auto it = aLibrary->
symbols.find( egate->symbol );
2428 if( it == aLibrary->
symbols.end() )
2430 Report( wxString::Format( wxS(
"Eagle symbol '%s' not found in library '%s'." ),
2436 wxString gateMapName = edeviceset->name + wxS(
"_" ) + edevice->name + wxS(
"_" ) + egate->name;
2438 ispower =
loadSymbol( it->second, libSymbol, edevice, gateindex, egate->name );
2443 std::vector<SCH_FIELD*> fields;
2444 libSymbol->GetFields( fields );
2447 field->SetCanAutoplace( canAutoplace );
2449 for(
const auto& [techname, technology ] : edevice->technologies )
2451 std::unique_ptr<LIB_SYMBOL> derivedSymbol;
2454 if( !technology->name.IsEmpty() )
2456 derivedSymbol = std::make_unique<LIB_SYMBOL>( symbolName + technology->name, libSymbol.get() );
2460 SCH_FIELD* childField = derivedSymbol->GetField( parentField->GetName() );
2470 for(
const std::unique_ptr<EATTR>& attr : technology->attributes )
2472 if( !attr->value.has_value() )
2477 if( !derivedSymbol )
2478 field = libSymbol->FindFieldCaseInsensitive( attr->name );
2480 field = derivedSymbol->FindFieldCaseInsensitive( attr->name );
2484 field->
SetText( attr->value.value() );
2488 SCH_FIELD* newField =
new SCH_FIELD( derivedSymbol ? derivedSymbol.get() : libSymbol.get(),
2493 SCH_FIELD* parentField = libSymbol->FindFieldCaseInsensitive( attr->name );
2500 newField->
SetText( attr->value.value() );
2505 if( !derivedSymbol )
2506 libSymbol->AddField( newField );
2508 derivedSymbol->AddField( newField );
2513 derivedSymbols.push_back( std::move( derivedSymbol ) );
2516 if( gate_count > 1 )
2517 libSymbol->SetUnitCount( gate_count,
true );
2519 if( gate_count == 1 && ispower )
2520 libSymbol->SetGlobalPower();
2523 if( edevice->package.has_value() && !edevice->package.value().IsEmpty() )
2530 libName =
m_schematic->Project().GetProjectName();
2537 wxString packageString = libName + wxT(
":" ) + aEagleLibrary->
package[symbolName];
2539 libSymbol->GetFootprintField().SetText( packageString );
2542 wxString libName = libSymbol->GetName();
2543 libSymbol->SetName( libName );
2544 libSymbol->SetDescription( deviceSetDescr );
2554 libName = aEagleLibrary->
name + wxT(
"_" ) + libName;
2556 libSymbol->SetName( libName );
2560 std::map<std::string, UTF8> properties;
2564 std::unique_ptr<LIB_SYMBOL> parentSymbol = std::make_unique<LIB_SYMBOL>( *libSymbol );
2576 Report( wxString::Format(
_(
"Could not reload saved symbol '%s'" ),
2582 for( std::unique_ptr<LIB_SYMBOL>& symbol : derivedSymbols )
2586 wxString tmp = aEagleLibrary->
name + wxT(
"_" ) + symbol->GetName();
2588 symbol->SetName( tmp );
2591 std::unique_ptr<LIB_SYMBOL> derivedSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
2593 derivedSymbol->SetParent( parent );
2594 m_pi->SaveSymbol(
getLibFileName().GetFullPath(), std::move( derivedSymbol ), &properties );
2606 aEagleLibrary->
KiCadSymbols[ libName ] = std::move( libSymbol );
2610 m_userValue.emplace( std::make_pair( libName, edeviceset->uservalue.value_or(
false ) ) );
2612 for( std::unique_ptr<LIB_SYMBOL>& symbol : derivedSymbols )
2614 m_userValue.emplace( std::make_pair( symbol->GetName(), edeviceset->uservalue.value_or(
false ) ) );
2615 aEagleLibrary->
KiCadSymbols[symbol->GetName()] = std::move( symbol );
2620 return aEagleLibrary;
2625 const std::unique_ptr<EDEVICE>& aDevice,
int aGateNumber,
const wxString& aGateName )
2627 wxCHECK( aEsymbol && aSymbol && aDevice,
false );
2629 std::vector<SCH_ITEM*> items;
2631 bool showRefDes =
false;
2632 bool showValue =
false;
2633 bool ispower =
false;
2636 for(
const std::unique_ptr<ECIRCLE>& ecircle : aEsymbol->circles )
2639 for(
const std::unique_ptr<EPIN>& epin : aEsymbol->pins )
2641 std::unique_ptr<SCH_PIN>
pin(
loadPin( aSymbol, epin, aGateNumber ) );
2646 if( epin->direction.has_value() )
2650 if( epin->direction.value().Lower() == pinDir.first )
2652 pin->SetType( pinDir.second );
2654 if( pinDir.first == wxT(
"sup" ) )
2662 if( aDevice->connects.size() != 0 )
2664 for(
const std::unique_ptr<ECONNECT>& connect : aDevice->connects )
2669 if( connect->gate == aGateName && epin->name == connect->pin )
2671 wxArrayString pads = wxSplit( wxString( connect->pad ),
' ' );
2673 pin->SetUnit( aGateNumber );
2676 if( pads.GetCount() > 1 )
2678 pin->SetNumberTextSize( 0 );
2681 for(
unsigned i = 0; i < pads.GetCount(); i++ )
2685 wxString padname( pads[i] );
2687 aSymbol->AddDrawItem( apin );
2696 pin->SetUnit( aGateNumber );
2697 pin->SetNumber( wxString::Format( wxT(
"%i" ), pincount ) );
2698 aSymbol->AddDrawItem(
pin.release() );
2702 for(
const std::unique_ptr<EPOLYGON>& epolygon : aEsymbol->polygons )
2705 aSymbol->AddDrawItem( shape );
2708 for(
const std::unique_ptr<ERECT>& erectangle : aEsymbol->rectangles )
2711 for(
const std::unique_ptr<ETEXT>& etext : aEsymbol->texts )
2713 std::unique_ptr<SCH_TEXT> libtext(
loadSymbolText( aSymbol, etext, aGateNumber ) );
2715 if( libtext->GetText() == wxT(
"${REFERENCE}" ) )
2718 aSymbol->GetReferenceField().SetAttributes( *libtext );
2721 showRefDes = etext->text == wxT(
">NAME" );
2723 else if( libtext->GetText() == wxT(
"${VALUE}" ) )
2726 aSymbol->GetValueField().SetAttributes( *libtext );
2729 showValue = etext->text == wxT(
">VALUE" );
2731 else if( etext->text.StartsWith(
">" ) )
2735 wxString fieldName = etext->text.Mid( 1 );
2737 if( !fieldName.IsEmpty() )
2745 aSymbol->AddField( field );
2750 aSymbol->AddDrawItem( libtext.release() );
2754 for(
const std::unique_ptr<EWIRE>& ewire : aEsymbol->wires )
2755 aSymbol->AddDrawItem(
loadSymbolWire( aSymbol, ewire, aGateNumber ) );
2757 for(
const std::unique_ptr<EFRAME>& eframe : aEsymbol->frames )
2759 std::vector<SCH_ITEM*> frameItems;
2765 item->SetParent( aSymbol.get() );
2766 item->SetUnit( aGateNumber );
2767 aSymbol->AddDrawItem( item );
2771 aSymbol->GetReferenceField().SetVisible( showRefDes );
2772 aSymbol->GetValueField().SetVisible( showValue );
2774 return pincount == 1 ? ispower :
false;
2779 const std::unique_ptr<ECIRCLE>& aCircle,
int aGateNumber )
2781 wxCHECK( aSymbol && aCircle,
nullptr );
2785 VECTOR2I center( aCircle->x.ToSchUnits(), -aCircle->y.ToSchUnits() );
2787 circle->SetParent( aSymbol.get() );
2791 if( aCircle->width.ToSchUnits() == 0 )
2801 if( aSymbol->IsMultiUnit() )
2802 circle->SetUnit( aGateNumber );
2809 const std::unique_ptr<ERECT>& aRectangle,
int aGateNumber )
2811 wxCHECK( aSymbol && aRectangle,
nullptr );
2816 rectangle->
SetPosition(
VECTOR2I( aRectangle->x1.ToSchUnits(), -aRectangle->y1.ToSchUnits() ) );
2817 rectangle->
SetEnd(
VECTOR2I( aRectangle->x2.ToSchUnits(), -aRectangle->y2.ToSchUnits() ) );
2819 if( aRectangle->rot.has_value() )
2832 if( aSymbol->IsMultiUnit() )
2833 rectangle->
SetUnit( aGateNumber );
2844 const std::unique_ptr<EWIRE>& aWire,
int aGateNumber )
2846 wxCHECK( aSymbol && aWire,
nullptr );
2850 begin.
x = aWire->x1.ToSchUnits();
2851 begin.
y = -aWire->y1.ToSchUnits();
2852 end.x = aWire->x2.ToSchUnits();
2853 end.y = -aWire->y2.ToSchUnits();
2869 if( aWire->cap.has_value() && aWire->cap.value() ==
EWIRE::FLAT && aWire->width.ToSchUnits() >= 2 *
radius )
2872 begin =
center + centerStartVector;
2888 if( aSymbol->IsMultiUnit() )
2900 if( aSymbol->IsMultiUnit() )
2911 const std::unique_ptr<EPOLYGON>& aPolygon,
int aGateNumber )
2913 wxCHECK( aSymbol && aPolygon,
nullptr );
2915 if( !aPolygon->IsValidOutline() )
2921 std::optional<double> prev_curve;
2922 std::optional<VECTOR2I> first_pt;
2926 for(
const std::unique_ptr<EVERTEX>& evertex : aPolygon->vertices )
2928 pt =
VECTOR2I( evertex->x.ToSchUnits(), -evertex->y.ToSchUnits() );
2930 if( !first_pt.has_value() )
2933 if( prev_curve.has_value() )
2945 prev_curve = evertex->curve;
2948 if( first_pt.has_value() )
2949 poly->
AddPoint( first_pt.value() );
2954 if( aSymbol->IsMultiUnit() )
2962 const std::unique_ptr<EPIN>& aPin,
int aGateNumber )
2964 wxCHECK( aSymbol && aPin,
nullptr );
2966 std::unique_ptr<SCH_PIN>
pin = std::make_unique<SCH_PIN>( aSymbol.get() );
2967 pin->SetPosition(
VECTOR2I( aPin->x.ToSchUnits(), -aPin->y.ToSchUnits() ) );
2974 if( aSymbol->IsMultiUnit() )
2975 pin->SetUnit( aGateNumber );
2977 int roti = aPin->rot.has_value() ?
KiROUND( aPin->rot.value().degrees ) : 0;
2985 default: wxFAIL_MSG( wxString::Format( wxT(
"Unhandled orientation (%d degrees)." ), roti ) );
2990 if( aPin->length.has_value() )
2992 if( aPin->length.value() == wxT(
"short" ) )
2994 else if( aPin->length.value() == wxT(
"middle" ) )
2996 else if( aPin->length.value() == wxT(
"long" ) )
2998 else if( aPin->length.value() == wxT(
"point" ) )
3007 if( aPin->visible.has_value() )
3009 if( aPin->visible.value() == wxT(
"off" ) )
3011 pin->SetNameTextSize( 0 );
3012 pin->SetNumberTextSize( 0 );
3014 else if( aPin->visible.value() == wxT(
"pad" ) )
3016 pin->SetNameTextSize( 0 );
3018 else if( aPin->visible.value() == wxT(
"pin" ) )
3020 pin->SetNumberTextSize( 0 );
3030 if( aPin->function.has_value() )
3032 if( aPin->function.value() == wxT(
"dot" ) )
3034 else if( aPin->function.value() == wxT(
"clk" ) )
3036 else if( aPin->function.value() == wxT(
"dotclk" ) )
3040 return pin.release();
3045 const std::unique_ptr<ETEXT>& aText,
int aGateNumber )
3047 wxCHECK( aSymbol && aText,
nullptr );
3049 std::unique_ptr<SCH_TEXT> libtext = std::make_unique<SCH_TEXT>();
3052 libtext->SetParent( aSymbol.get() );
3054 if( aSymbol->IsMultiUnit() )
3055 libtext->SetUnit( aGateNumber );
3057 libtext->SetPosition(
VECTOR2I( aText->x.ToSchUnits(), -aText->y.ToSchUnits() ) );
3059 const wxString& eagleText = aText->text;
3060 wxString adjustedText;
3061 wxStringTokenizer tokenizer( eagleText,
"\r\n" );
3064 while( tokenizer.HasMoreTokens() )
3066 wxString tmp =
interpretText( tokenizer.GetNextToken().Trim(
true ).Trim(
false ) );
3068 if( tokenizer.HasMoreTokens() )
3071 adjustedText += tmp;
3074 libtext->SetText( adjustedText.IsEmpty() ? wxString( wxS(
"~" ) ) : adjustedText );
3078 return libtext.release();
3084 wxCHECK( aText,
nullptr );
3086 std::unique_ptr<SCH_TEXT> schtext = std::make_unique<SCH_TEXT>();
3088 const wxString& eagleText = aText->text;
3089 wxString adjustedText;
3090 wxStringTokenizer tokenizer( eagleText,
"\r\n" );
3093 while( tokenizer.HasMoreTokens() )
3095 wxString tmp =
interpretText( tokenizer.GetNextToken().Trim(
true ).Trim(
false ) );
3097 if( tokenizer.HasMoreTokens() )
3100 adjustedText += tmp;
3103 schtext->SetText( adjustedText.IsEmpty() ? wxString( wxS(
"\" \"" ) )
3106 schtext->SetPosition(
VECTOR2I( aText->x.ToSchUnits(), -aText->y.ToSchUnits() ) );
3108 schtext->SetItalic(
false );
3110 return schtext.release();
3116 wxCHECK( aText && aAttributes, );
3121 if( aAttributes->ratio.value_or( 8 ) > 12 )
3125 int degrees = aAttributes->rot.has_value() ?
KiROUND( aAttributes->rot.value().degrees ) : 0;
3126 bool mirror = aAttributes->rot.has_value() ? aAttributes->rot.value().mirror :
false;
3127 bool spin = aAttributes->rot.has_value() ? aAttributes->rot.value().spin :
false;
3142 auto onIntersection =
3153 const SEG* segAttached = segDesc.LabelAttached( label );
3155 if( segAttached && !onIntersection( labelPos ) )
3168 VECTOR2I wireDirection( segAttached->
B - segAttached->
A );
3170 if( ( wireDirection.
x == 0 ) && (wireDirection.
y == 0 ) )
3174 const VECTOR2I origPos( labelPos );
3177 bool checkPositive =
true;
3178 bool checkNegative =
true;
3183 while( ( !
move || onIntersection( labelPos ) ) && ( checkPositive || checkNegative ) )
3188 if( trial % 2 == 1 )
3190 labelPos =
VECTOR2I( origPos + wireDirection * trial / 2 );
3191 move = checkPositive = segAttached->
Contains( labelPos );
3195 labelPos =
VECTOR2I( origPos - wireDirection * trial / 2 );
3196 move = checkNegative = segAttached->
Contains( labelPos );
3206 if( wireDirection.
x == 0 )
3208 if( wireDirection.
y < 0 )
3213 else if( wireDirection.
y == 0 )
3215 if( wireDirection.
x < 0 )
3249 wxFileInputStream input( aFileName );
3258 wxTextInputStream
text( input );
3260 for(
int i = 0; i < 8; i++ )
3265 if(
text.ReadLine().Contains( wxS(
"<eagle" ) ) )
3283 if( !item->IsType( { SCH_LABEL_LOCATE_ANY_T } ) )
3287 item->SetPosition( aNewEndPoint );
3300 std::vector<SCH_LINE*> buses;
3301 std::vector<SCH_LINE*> wires;
3312 buses.push_back( line );
3313 else if( line->
IsWire() )
3314 wires.push_back( line );
3319 VECTOR2I wireStart = wire->GetStartPoint();
3320 VECTOR2I wireEnd = wire->GetEndPoint();
3324 VECTOR2I busStart = bus->GetStartPoint();
3325 VECTOR2I busEnd = bus->GetEndPoint();
3328 [](
int signX,
int signY ) ->
VECTOR2I
3340 if( wireStart.
y == wireEnd.
y && busStart.
x == busEnd.
x )
3344 if( testBusHit( wireStart ) )
3348 if( wireEnd.
x < busStart.
x )
3355 VECTOR2I p = wireStart + entrySize( -1, 0 );
3357 if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
3366 screen->
Append( busEntry );
3368 wire->SetStartPoint( p );
3370 else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
3379 screen->
Append( busEntry );
3381 wire->SetStartPoint( p );
3396 VECTOR2I p = wireStart + entrySize( 1, 0 );
3398 if( testBusHit( wireStart + entrySize( 0, -1 ) ) )
3407 screen->
Append( busEntry );
3409 wire->SetStartPoint( p );
3411 else if( testBusHit( wireStart + entrySize( 0, 1 ) ) )
3420 screen->
Append( busEntry );
3422 wire->SetStartPoint( p );
3433 else if( testBusHit( wireEnd ) )
3437 if( wireStart.
x < busStart.
x )
3444 VECTOR2I p = wireEnd + entrySize( -1, 0 );
3446 if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3455 screen->
Append( busEntry );
3457 wire->SetEndPoint( p );
3459 else if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3468 screen->
Append( busEntry );
3469 moveLabels( wire, wireEnd + entrySize( -1, 0 ) );
3470 wire->SetEndPoint( wireEnd + entrySize( -1, 0 ) );
3485 VECTOR2I p = wireEnd + entrySize( 1, 0 );
3487 if( testBusHit( wireEnd + entrySize( 0, -1 ) ) )
3496 screen->
Append( busEntry );
3498 wire->SetEndPoint( p );
3500 else if( testBusHit( wireEnd + entrySize( 0, 1 ) ) )
3509 screen->
Append( busEntry );
3511 wire->SetEndPoint( p );
3523 else if( wireStart.
x == wireEnd.
x && busStart.
y == busEnd.
y )
3527 if( testBusHit( wireStart ) )
3531 if( wireEnd.
y < busStart.
y )
3539 VECTOR2I p = wireStart + entrySize( 0, -1 );
3541 if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
3551 screen->
Append( busEntry );
3553 wire->SetStartPoint( p );
3555 else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
3565 screen->
Append( busEntry );
3567 wire->SetStartPoint( p );
3583 VECTOR2I p = wireStart + entrySize( 0, 1 );
3585 if( testBusHit( wireStart + entrySize( -1, 0 ) ) )
3595 screen->
Append( busEntry );
3597 wire->SetStartPoint( p );
3599 else if( testBusHit( wireStart + entrySize( 1, 0 ) ) )
3609 screen->
Append( busEntry );
3611 wire->SetStartPoint( p );
3622 else if( testBusHit( wireEnd ) )
3626 if( wireStart.
y < busStart.
y )
3634 VECTOR2I p = wireEnd + entrySize( 0, -1 );
3636 if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
3646 screen->
Append( busEntry );
3648 wire->SetEndPoint( p );
3650 else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
3660 screen->
Append( busEntry );
3662 wire->SetEndPoint( p );
3678 VECTOR2I p = wireEnd + entrySize( 0, 1 );
3680 if( testBusHit( wireEnd + entrySize( -1, 0 ) ) )
3690 screen->
Append( busEntry );
3692 wire->SetEndPoint( p );
3694 else if( testBusHit( wireEnd + entrySize( 1, 0 ) ) )
3704 screen->
Append( busEntry );
3706 wire->SetEndPoint( p );
3722 if( testBusHit( wireStart ) )
3724 VECTOR2I wirevector = wireStart - wireEnd;
3726 if( wirevector.
x > 0 )
3728 if( wirevector.
y > 0 )
3730 VECTOR2I p = wireStart + entrySize( -1, -1 );
3733 screen->
Append( busEntry );
3736 wire->SetStartPoint( p );
3740 VECTOR2I p = wireStart + entrySize( -1, 1 );
3743 screen->
Append( busEntry );
3746 wire->SetStartPoint( p );
3751 if( wirevector.
y > 0 )
3753 VECTOR2I p = wireStart + entrySize( 1, -1 );
3756 screen->
Append( busEntry );
3759 wire->SetStartPoint( p );
3763 VECTOR2I p = wireStart + entrySize( 1, 1 );
3766 screen->
Append( busEntry );
3769 wire->SetStartPoint( p );
3775 else if( testBusHit( wireEnd ) )
3777 VECTOR2I wirevector = wireStart - wireEnd;
3779 if( wirevector.
x > 0 )
3781 if( wirevector.
y > 0 )
3783 VECTOR2I p = wireEnd + entrySize( 1, 1 );
3786 screen->
Append( busEntry );
3789 wire->SetEndPoint( p );
3793 VECTOR2I p = wireEnd + entrySize( 1, -1 );
3796 screen->
Append( busEntry );
3799 wire->SetEndPoint( p );
3804 if( wirevector.
y > 0 )
3806 VECTOR2I p = wireEnd + entrySize( -1, 1 );
3809 screen->
Append( busEntry );
3812 wire->SetEndPoint( p );
3816 VECTOR2I p = wireEnd + entrySize( -1, -1 );
3819 screen->
Append( busEntry );
3822 wire->SetEndPoint( p );
3836 wxCHECK( aLabel,
nullptr );
3842 if( seg.Contains( labelPos ) )
3854 wxCHECK( aSymbol && aPin,
false );
3862 const std::set<const EDA_ITEM*>& items = pointIt->second;
3864 wxCHECK( items.find( aPin ) != items.end(),
false );
3866 return items.size() > 1;
3879 int unit = aSymbol->
GetUnit();
3882 std::set<int> missingUnits;
3889 bool pinInUnit = !unit ||
pin->GetUnit() == unit;
3902 switch(
pin->GetOrientation() )
3911 aScreen->
Append( netLabel );
3914 else if( aUpdateSet )
3919 wxASSERT(
pin->GetUnit() );
3920 missingUnits.insert(
pin->GetUnit() );
3933 entry.
cmp = aSymbol;
3935 entry.
units.emplace( unit,
false );
3940 cmpIt->second.units[unit] =
false;
3943 if( !missingUnits.empty() )
3946 entry.
cmp = aSymbol;
3950 for(
int i : missingUnits )
3952 if( entry.
units.find( i ) != entry.
units.end() )
3953 entry.
units.emplace( i,
true );
3965 wxString ret = wxT(
"{" );
3967 wxStringTokenizer tokenizer( aEagleName,
"," );
3969 while( tokenizer.HasMoreTokens() )
3971 wxString member = tokenizer.GetNextToken();
3978 if( member.Freq(
'!' ) % 2 > 0 )
3979 member << wxT(
"!" );
3981 ret << member << wxS(
" " );
3995 std::unique_ptr<EPART>& epart =
m_eagleDoc->drawing->schematic->parts[aInstance->part];
3997 if( !epart || epart->deviceset.IsEmpty() )
4000 std::unique_ptr<ELIBRARY>& elibrary =
m_eagleDoc->drawing->schematic->libraries[epart->library];
4005 std::unique_ptr<EDEVICE_SET>& edeviceset = elibrary->devicesets[epart->deviceset];
4010 std::unique_ptr<EGATE>& egate = edeviceset->gates[aInstance->gate];
4015 std::unique_ptr<ESYMBOL>& esymbol = elibrary->symbols[egate->symbol];
4018 return esymbol.get();
4025 const wxString& aEagleFieldName,
4028 wxCHECK( aField && !aEagleFieldName.
IsEmpty(), );
4034 for(
const std::unique_ptr<ETEXT>&
text : esymbol->
texts )
4036 if(
text->text == aEagleFieldName )
4039 VECTOR2I pos(
text->x.ToSchUnits() + aInstance->x.ToSchUnits(),
4040 -
text->y.ToSchUnits() - aInstance->y.ToSchUnits() );
4042 bool mirror =
text->rot ?
text->rot->mirror :
false;
4044 if( aInstance->rot.has_value() && aInstance->rot.value().mirror )
4048 pos.
y = -aInstance->y.ToSchUnits() +
text->y.ToSchUnits();
4061 std::vector<SCH_FIELD*> fields;
4066 retv = fields[0]->GetPosition();
4068 for(
size_t i = 1; i < fields.size(); i++ )
4070 if( fields[i]->GetPosition().x > retv.
x )
4071 retv.
x = fields[i]->GetPosition().x;
4073 if( fields[i]->GetPosition().y > retv.
y )
4074 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 without changing the stream position.
void SetFlags(EDA_ITEM_FLAGS aMask)
virtual void SetParent(EDA_ITEM *aParent)
virtual void SetEnd(const VECTOR2I &aEnd)
virtual 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 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)
virtual void SetVisible(bool aVisible)
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
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.
virtual void Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) const
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.
void ReloadLibraryEntry(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
Synchronously recreates the plugin for and reloads the given library.
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.
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.
std::vector< SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const override
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
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
The fully parsed Eagle schematic file.
SCH_ITEM * loadWire(const std::unique_ptr< EWIRE > &aWire, SEG &endpoints)
void loadTextAttributes(EDA_TEXT *aText, const std::unique_ptr< ETEXT > &aAttributes) const
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
void adjustNetLabels()
Move net labels that are detached from any wire to the nearest wire.
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
Wire intersection points, used for quick checks whether placing a net label in a particular place wou...
std::map< VECTOR2I, std::set< const EDA_ITEM * > > m_connPoints
Positions of pins and wire endings mapped to its parent.
bool checkConnections(const SCH_SYMBOL *aSymbol, const SCH_PIN *aPin) const
Checks if there are other wires or pins at the position of the tested pin.
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.
SHEET_WIRING collectSheetWiring(const std::unique_ptr< ESHEET > &aSheet, SCH_SCREEN *aScreen)
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()
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)
void loadSegments(const std::vector< std::unique_ptr< ESEGMENT > > &aSegments, const wxString &aNetName, const wxString &aNetClass, SHEET_WIRING &aWiring, bool aIsBus=false)
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
Map references to missing symbol units data.
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
Segments representing wires for intersection checking.
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 ...
void AddContact(const VECTOR2I &aPos, int aNet)
Register a pin or junction.
RESULT Route(const SEG &aWire, int aNet)
Detour a wire around foreign items lying on it and register the result as the wire's geometry.
void AddWire(const SEG &aWire, int aNet)
Register a wire as an obstacle for the wires of other nets.
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 aDoClone=false) const
Routine to create a new copy of given item.
void SetLayer(SCH_LAYER_ID aLayer)
SCH_LAYER_ID GetLayer() const
Return the layer this item is on.
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,...
void SetStartPoint(const VECTOR2I &aPosition)
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.
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
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)
Refresh a changed item in the tree and invalidate connectivity.
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::vector< SCH_PIN * > GetLibPins() const
Populate a vector with all the pins from the library object that match the current unit and bodyStyle...
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.
#define DEFAULT_SCH_ENTRY_SIZE
The default bus and wire entry size in mils.
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.
static constexpr EDA_ANGLE ANGLE_VERTICAL
@ FILLED_SHAPE
Fill with object color.
#define IGNORE_PARENT_GROUP
#define IS_NEW
New item, just created.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ ERCE_BUS_ENTRY_NEEDED
Importer failed to auto-place a bus entry.
bool m_EagleImportFieldsCanAutoplace
Default CanAutoplace value for fields imported from EAGLE files.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
#define THROW_IO_CANCELLED()
static const std::string KiCadSchematicFileExtension
static const std::string KiCadSymbolLibFileExtension
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)
Strip the Eagle "@<tag>" linking hint from a pin name (e.g. return 'GND' for 'GND@2')
static const std::map< wxString, ELECTRICAL_PINTYPE > pinDirectionsMap
Map of EAGLE pin type values to KiCad pin type values.
static bool isEagleAutoNetName(const wxString &aNetName)
True for the "N$<n>" names Eagle assigns to nets the user never named.
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)
Compute a bounding box for all items in a schematic sheet.
LABEL_FLAG_SHAPE
Label and flag shapes used with text objects.
LABEL_SHAPE
Specific enums for property manager (not used elsewhere)
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::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
const SCH_SYMBOL * cmp
Link to the parent symbol.
SCH_SCREEN * screen
Screen where the parent symbol is located.
std::map< int, bool > units
Wires and labels of a single connection (segment in Eagle nomenclature)
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.
Wires and the pins and junctions around them on one sheet, for keeping wires off other nets' pins.
std::map< wxString, int > NetIds
SCH_IO_WIRE_DETOUR Detour
bool Failed
A foreign item lies on the wire and no safe detour was found, the wire is left as it was.
std::vector< SEG > Pieces
The wire itself when nothing lies on it, otherwise the pieces of the detoured wire in order.
A simple container for schematic symbol instance information.
Implement a simple wrapper around runtime_error to isolate the errors thrown by the Eagle XML parser.
SYMBOL_ORIENTATION_T
enum used in RotationMiroir()
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".
static std::vector< uint8_t > bytes(const std::string &aText)
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.