37 double sx = aStart.
x - aCenter.
x;
38 double sy = aStart.
y - aCenter.
y;
39 double ex = aEnd.
x - aCenter.
x;
40 double ey = aEnd.
y - aCenter.
y;
41 double radius = std::sqrt( sx * sx + sy * sy );
45 double mlen = std::sqrt( mx * mx + my * my );
51 midPt.
x = aCenter.
x +
static_cast<int>(
radius * mx / mlen );
52 midPt.
y = aCenter.
y +
static_cast<int>(
radius * my / mlen );
56 midPt.
x = aCenter.
x +
static_cast<int>( -sy *
radius / std::max(
radius, 1.0 ) );
57 midPt.
y = aCenter.
y +
static_cast<int>( sx *
radius / std::max(
radius, 1.0 ) );
79 if( aLine.size() < 3 || aLine[0] !=
'*' )
82 size_t endPos = aLine.find(
'*', 1 );
83 return endPos != std::string::npos && endPos > 1;
89 if( aLine.size() < 3 || aLine[0] !=
'*' )
92 size_t endPos = aLine.find(
'*', 1 );
94 if( endPos == std::string::npos || endPos <= 1 )
97 return aLine.substr( 1, endPos - 1 );
119 std::ifstream file( aFileName );
121 if( !file.is_open() )
129 std::vector<std::string> lines;
132 while( std::getline( file, line ) )
134 if( !line.empty() && line.back() ==
'\r' )
137 lines.push_back( line );
160 for(
size_t i = 1; i < lines.size(); i++ )
163 const std::string& currentLine = lines[i];
165 if( currentLine.empty() )
168 if( currentLine.find(
"*REMARK*" ) == 0 )
176 if( sectionName ==
"SCH" )
180 else if( sectionName ==
"CAM" || sectionName ==
"MISC" )
184 else if( sectionName ==
"FIELDS" )
188 else if( sectionName ==
"SHT" )
192 else if( sectionName ==
"CAE" )
196 else if( sectionName ==
"TEXT" )
200 else if( sectionName ==
"LINES" )
204 else if( sectionName ==
"CAEDECAL" )
208 else if( sectionName ==
"PARTTYPE" )
212 else if( sectionName ==
"PART" )
216 else if( sectionName ==
"BUSSES" )
220 else if( sectionName ==
"OFFPAGE REFS" )
224 else if( sectionName ==
"TIEDOTS" )
228 else if( sectionName ==
"CONNECTION" )
232 else if( sectionName ==
"NETNAMES" )
236 else if( sectionName ==
"END" )
256 for(
auto& attr : part.attributes )
258 if( attr.name ==
"Ref.Des." && attr.value.empty() )
259 attr.value = part.reference;
261 auto ovr = part.attr_overrides.find( attr.name );
263 if( ovr != part.attr_overrides.end() && attr.value.empty() )
264 attr.value = ovr->second;
272 std::ifstream file( aFileName );
274 if( !file.is_open() )
277 std::string firstLine;
279 if( !std::getline( file, firstLine ) )
282 if( !firstLine.empty() && firstLine.back() ==
'\r' )
283 firstLine.pop_back();
285 if( firstLine.find(
"*PADS-LOGIC" ) == 0 )
288 if( firstLine.find(
"*PADS-POWERLOGIC" ) == 0 )
297 if( aLine.empty() || aLine[0] !=
'*' )
300 size_t endPos = aLine.find(
'*', 1 );
302 if( endPos == std::string::npos )
305 std::string headerTag = aLine.substr( 1, endPos - 1 );
308 std::regex headerRegex( R
"(PADS-(POWER)?LOGIC-V(\d+\.\d+)(?:-([A-Za-z0-9]+))?)" );
311 if( !std::regex_match( headerTag, match, headerRegex ) )
314 if( match[1].matched )
315 m_header.product =
"PADS-POWERLOGIC";
319 m_header.version =
"V" + match[2].str();
321 if( match[3].matched )
324 if( endPos + 1 < aLine.size() )
326 std::string desc = aLine.substr( endPos + 1 );
327 size_t start = desc.find_first_not_of(
' ' );
329 if( start != std::string::npos )
330 m_header.description = desc.substr( start );
339 size_t i = aStartLine + 1;
341 while( i < aLines.size() )
343 const std::string& line = aLines[i];
354 std::istringstream iss( line );
358 if( keyword ==
"UNITS" )
371 else if( keyword ==
"CUR" )
376 if( second ==
"SHEET" )
379 else if( keyword ==
"SHEET" )
385 if( second.starts_with(
"SIZE" ) )
387 std::string sizeCode;
389 if( second ==
"SIZE" )
392 sizeCode = second.substr( 4 );
396 if( sizeCode ==
"A" )
401 else if( sizeCode ==
"B" )
406 else if( sizeCode ==
"C" )
411 else if( sizeCode ==
"D" )
416 else if( sizeCode ==
"E" )
421 else if( sizeCode ==
"A0" )
426 else if( sizeCode ==
"A1" )
431 else if( sizeCode ==
"A2" )
436 else if( sizeCode ==
"A3" )
441 else if( sizeCode ==
"A4" )
448 else if( keyword ==
"USERGRID" )
452 else if( keyword ==
"LINEWIDTH" )
456 else if( keyword ==
"CONNWIDTH" )
460 else if( keyword ==
"BUSWIDTH" )
464 else if( keyword ==
"BUSANGLE" )
468 else if( keyword ==
"TEXTSIZE" )
473 else if( keyword ==
"PINNAMESIZE" )
477 else if( keyword ==
"REFNAMESIZE" )
481 else if( keyword ==
"PARTNAMESIZE" )
485 else if( keyword ==
"PINNOSIZE" )
489 else if( keyword ==
"NETNAMESIZE" )
493 else if( keyword ==
"DOTGRID" )
497 else if( keyword ==
"TIEDOTSIZE" )
501 else if( keyword ==
"REAL" )
506 if( second ==
"WIDTH" )
509 else if( keyword ==
"FONT" )
514 if( second ==
"MODE" )
517 else if( keyword ==
"DEFAULT" )
522 if( second ==
"FONT" )
525 std::getline( iss, rest );
526 size_t start = rest.find(
'"' );
528 if( start != std::string::npos )
530 size_t end = rest.find(
'"', start + 1 );
532 if(
end != std::string::npos )
537 else if( keyword ==
"BORDER" )
542 if( second ==
"NAME" )
553 else if( keyword ==
"JOBNAME" )
556 std::getline( iss, rest );
557 size_t start = rest.find_first_not_of(
" \t" );
559 if( start != std::string::npos )
561 rest = rest.substr( start );
563 if( rest.size() >= 2 && rest.front() ==
'"' && rest.back() ==
'"' )
564 rest = rest.substr( 1, rest.size() - 2 );
570 else if( keyword ==
"NTXCOL" || keyword ==
"HIRCOL" || keyword ==
"LINCOL" || keyword ==
"TXTCOL"
571 || keyword ==
"CONCOL" || keyword ==
"BUSCOL" || keyword ==
"PTXCOL" || keyword ==
"COMCOL"
572 || keyword ==
"NMCOL" || keyword ==
"PNMCOL" || keyword ==
"PINCOL" || keyword ==
"NETCOL"
573 || keyword ==
"FBGCOL" || keyword ==
"FIELDCOL" || keyword ==
"NNVISPWRGND" || keyword ==
"PCBFLAGS"
574 || keyword ==
"JOBTIME" || keyword ==
"BACKUPTIME" || keyword ==
"OFFREFVIEW" || keyword ==
"OFFREFNUM"
575 || keyword ==
"SHEETNUMSEP" )
582 return aLines.size() - 1;
588 size_t i = aStartLine + 1;
590 while( i < aLines.size() )
592 const std::string& line = aLines[i];
597 if( line.empty() || line[0] !=
'"' )
604 size_t closeQuote = line.find(
'"', 1 );
606 if( closeQuote != std::string::npos )
608 std::string fieldName = line.substr( 1, closeQuote - 1 );
609 std::string fieldValue;
611 if( closeQuote + 1 < line.size() )
613 fieldValue = line.substr( closeQuote + 1 );
614 size_t start = fieldValue.find_first_not_of(
" \t" );
616 if( start != std::string::npos )
617 fieldValue = fieldValue.substr( start );
628 return aLines.size() - 1;
635 const std::string& line = aLines[aStartLine];
636 std::string afterMarker = line.substr( line.find(
'*', 1 ) + 1 );
638 std::istringstream iss( afterMarker );
653 size_t i = aStartLine + 1;
655 while( i < aLines.size() )
657 const std::string& line = aLines[i];
665 return aLines.size() - 1;
671 size_t i = aStartLine + 1;
673 while( i < aLines.size() )
675 const std::string& line = aLines[i];
689 std::istringstream iss( line );
698 std::getline( iss, rest );
699 size_t qStart = rest.find(
'"' );
701 if( qStart != std::string::npos )
703 size_t qEnd = rest.find(
'"', qStart + 1 );
705 if( qEnd != std::string::npos )
706 item.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
711 if( i < aLines.size() )
718 return aLines.size() - 1;
724 size_t i = aStartLine + 1;
726 while( i < aLines.size() )
728 const std::string& line = aLines[i];
740 if( line.find(
"LINES" ) != std::string::npos )
743 std::istringstream iss( line );
744 std::string
name, keyword;
749 if( keyword ==
"LINES" )
759 while( i < aLines.size() )
761 const std::string& pline = aLines[i];
772 if( pline.find(
"LINES" ) != std::string::npos )
774 std::istringstream tiss( pline );
775 std::string tname, tkw;
776 tiss >> tname >> tkw;
782 std::istringstream piss( pline );
783 std::string firstToken;
786 if( firstToken ==
"OPEN" || firstToken ==
"CLOSED" || firstToken ==
"CIRCLE"
787 || firstToken ==
"COPCLS" )
799 && ( std::isdigit( firstToken[0] ) || firstToken[0] ==
'-' || firstToken[0] ==
'+' );
801 if( isNumber && pline.find(
'"' ) != std::string::npos )
805 std::istringstream tiss( pline );
808 tiss >> tx >> ty >>
text.rotation >>
text.justification >>
text.height >>
text.width_factor;
810 text.position.x = tx;
811 text.position.y = ty;
814 std::getline( tiss, trest );
815 size_t qStart = trest.find(
'"' );
817 if( qStart != std::string::npos )
819 size_t qEnd = trest.find(
'"', qStart + 1 );
821 if( qEnd != std::string::npos )
822 text.font_name = trest.substr( qStart + 1, qEnd - qStart - 1 );
827 if( i < aLines.size() )
828 text.content = aLines[i];
844 return aLines.size() - 1;
850 size_t i = aStartLine + 1;
852 while( i < aLines.size() )
854 const std::string& line = aLines[i];
868 if( !symbol.
name.empty() )
876 std::map<std::string, double> pinDecalLengths;
880 if( !sym.is_pin_decal )
883 for(
const auto& graphic : sym.graphics )
888 if( graphic.points.size() < 2 )
891 const auto& first = graphic.points.front().coord;
892 const auto& last = graphic.points.back().coord;
893 double dx = last.x - first.x;
894 double dy = last.y - first.y;
895 pinDecalLengths[sym.name] = std::sqrt( dx * dx + dy * dy );
902 if( sym.is_pin_decal )
905 for(
auto&
pin : sym.pins )
907 if(
pin.pin_decal_name.empty() )
910 auto it = pinDecalLengths.find(
pin.pin_decal_name );
912 if( it != pinDecalLengths.end() )
913 pin.length = it->second;
917 return i > 0 ? i - 1 : aLines.size() - 1;
923 if( aStartLine >= aLines.size() )
926 const std::string& headerLine = aLines[aStartLine];
930 std::istringstream iss( headerLine );
939 std::vector<std::string> tokens;
942 while( iss >> token )
943 tokens.push_back( token );
945 if( tokens.size() >= 12 )
963 if( tokens.size() >= 3 )
974 size_t idx = aStartLine + 1;
976 for(
int p = 0; p < aSymbol.
num_pieces && idx < aLines.size(); p++ )
978 const std::string& gline = aLines[idx];
984 std::istringstream giss( gline );
988 if( typeStr ==
"OPEN" || typeStr ==
"LINE" )
992 giss >> p1.
x >> p1.
y >> p2.
x >> p2.
y;
993 graphic.
points.push_back( { p1, std::nullopt } );
994 graphic.
points.push_back( { p2, std::nullopt } );
997 else if( typeStr ==
"CLOSED" || typeStr ==
"RECT" )
1001 giss >> p1.
x >> p1.
y >> p2.
x >> p2.
y;
1002 graphic.
points.push_back( { p1, std::nullopt } );
1003 graphic.
points.push_back( { p2, std::nullopt } );
1006 else if( typeStr ==
"CIRCLE" )
1013 aSymbol.
graphics.push_back( graphic );
1017 for(
int p = 0; p < aSymbol.
num_pins && idx < aLines.size(); p++ )
1019 const std::string& pline = aLines[idx];
1025 std::istringstream piss( pline );
1029 piss >>
pin.number >>
pin.name;
1033 std::string typeStr;
1035 if( piss >> typeStr )
1038 aSymbol.
pins.push_back(
pin );
1045 size_t idx = aStartLine + 1;
1047 if( idx < aLines.size() && aLines[idx].find(
"TIMESTAMP" ) == 0 )
1049 std::istringstream tiss( aLines[idx] );
1056 if( idx < aLines.size() && aLines[idx].size() >= 2 && aLines[idx][0] ==
'"' )
1058 size_t qEnd = aLines[idx].find(
'"', 1 );
1060 if( qEnd != std::string::npos )
1061 aSymbol.
font1 = aLines[idx].substr( 1, qEnd - 1 );
1066 if( idx < aLines.size() && aLines[idx].size() >= 2 && aLines[idx][0] ==
'"' )
1068 size_t qEnd = aLines[idx].find(
'"', 1 );
1070 if( qEnd != std::string::npos )
1071 aSymbol.
font2 = aLines[idx].substr( 1, qEnd - 1 );
1077 for(
int a = 0; a < aSymbol.
num_attrs && idx + 1 < aLines.size(); a++ )
1080 std::istringstream aiss( aLines[idx] );
1088 std::getline( aiss, rest );
1089 size_t qStart = rest.find(
'"' );
1091 if( qStart != std::string::npos )
1093 size_t qEnd = rest.find(
'"', qStart + 1 );
1095 if( qEnd != std::string::npos )
1096 attr.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
1101 if( idx < aLines.size() )
1104 aSymbol.
attrs.push_back( attr );
1108 for(
int p = 0; p < aSymbol.
num_pieces && idx < aLines.size(); p++ )
1110 if( aLines[idx].
empty() )
1119 aSymbol.
graphics.push_back( graphic );
1125 while( idx < aLines.size() )
1127 const std::string& tline = aLines[idx];
1136 if( tline.size() > 1 && tline[0] ==
'T'
1137 && ( std::isdigit(
static_cast<unsigned char>( tline[1] ) ) || tline[1] ==
'-' ) )
1143 std::istringstream tiss( tline );
1146 tiss >> tx >> ty >>
text.rotation >>
text.justification;
1148 int height = 0, width = 0;
1149 tiss >> height >> width;
1151 text.width_factor = width;
1153 text.position.x = tx;
1154 text.position.y = ty;
1158 if( idx < aLines.size() )
1160 text.content = aLines[idx];
1168 for(
int p = 0; p < aSymbol.
num_pins && idx < aLines.size(); p++ )
1170 const std::string& tLine = aLines[idx];
1186 if( tLine.size() > 1 && tLine[0] ==
'T' )
1188 std::string tContent = tLine.substr( 1 );
1189 std::istringstream tiss( tContent );
1190 int tx = 0, ty = 0, angle = 0, pnx = 0, pny = 0, plx = 0, ply = 0;
1192 tiss >> tx >> ty >> angle >>
pin.side >> pnx >> pny >>
pin.pn_angle >>
pin.pn_just >> plx >> ply
1193 >>
pin.pl_angle >>
pin.pl_just >>
pin.pin_decal_name;
1195 pin.position.x = tx;
1196 pin.position.y = ty;
1197 pin.rotation = angle;
1198 pin.pn_offset.x = pnx;
1199 pin.pn_offset.y = pny;
1200 pin.pl_offset.x = plx;
1201 pin.pl_offset.y = ply;
1204 if(
pin.pin_decal_name ==
"PINB" ||
pin.pin_decal_name ==
"PINORB" ||
pin.pin_decal_name ==
"PCLKB"
1205 ||
pin.pin_decal_name ==
"PINIEB" ||
pin.pin_decal_name ==
"PINCLKB" )
1207 pin.inverted =
true;
1210 if(
pin.pin_decal_name ==
"PCLK" ||
pin.pin_decal_name ==
"PCLKB" ||
pin.pin_decal_name ==
"PINCLK"
1211 ||
pin.pin_decal_name ==
"PINCLKB" )
1218 if(
pin.pin_decal_name.empty() )
1220 else if(
pin.pin_decal_name.find(
"SHORT" ) != std::string::npos )
1222 else if(
pin.pin_decal_name.find(
"LONG" ) != std::string::npos )
1229 if( idx < aLines.size() )
1231 const std::string& pLine = aLines[idx];
1233 if( pLine.size() > 1 && pLine[0] ==
'P' )
1235 std::string pContent = pLine.substr( 1 );
1236 std::istringstream piss( pContent );
1237 int px1 = 0, py1 = 0, px2 = 0, py2 = 0;
1239 piss >> px1 >> py1 >>
pin.p_angle1 >>
pin.p_just1 >> px2 >> py2 >>
pin.p_angle2 >>
pin.p_just2
1242 pin.p_position1.x = px1;
1243 pin.p_position1.y = py1;
1244 pin.p_position2.x = px2;
1245 pin.p_position2.y = py2;
1248 if(
pin.p_flags & 128 )
1256 pin.number = std::to_string( p + 1 );
1258 aSymbol.
pins.push_back(
pin );
1261 return idx > 0 ? idx - 1 : 0;
1268 if( aStartLine >= aLines.size() )
1271 const std::string& headerLine = aLines[aStartLine];
1272 std::istringstream iss( headerLine );
1273 std::string typeStr;
1274 int pointCount = 0, lineWidth = 0, lineStyle = 255;
1276 iss >> typeStr >> pointCount >> lineWidth >> lineStyle;
1281 if( typeStr ==
"OPEN" )
1286 else if( typeStr ==
"CLOSED" )
1291 else if( typeStr ==
"CIRCLE" )
1296 else if( typeStr ==
"COPCLS" )
1302 size_t idx = aStartLine + 1;
1304 for(
int p = 0; p < pointCount && idx < aLines.size(); p++ )
1306 const std::string& ptLine = aLines[idx];
1311 std::istringstream piss( ptLine );
1315 std::vector<std::string> extraTokens;
1318 while( piss >> tok )
1319 extraTokens.push_back( tok );
1321 if( extraTokens.size() >= 6 )
1333 aGraphic.
points.push_back( gpt );
1342 std::set<double> uniqueX, uniqueY;
1344 for(
const auto& pt : aGraphic.
points )
1346 uniqueX.insert( pt.coord.x );
1347 uniqueY.insert( pt.coord.y );
1350 bool isRect = ( uniqueX.size() == 2 && uniqueY.size() == 2 );
1354 double minX = *uniqueX.begin();
1355 double maxX = *uniqueX.rbegin();
1356 double minY = *uniqueY.begin();
1357 double maxY = *uniqueY.rbegin();
1360 aGraphic.
points.push_back( { { minX, minY }, std::nullopt } );
1361 aGraphic.
points.push_back( { { maxX, maxY }, std::nullopt } );
1374 double dx = aGraphic.
points[1].coord.x - aGraphic.
points[0].coord.x;
1375 double dy = aGraphic.
points[1].coord.y - aGraphic.
points[0].coord.y;
1376 aGraphic.
radius = std::sqrt( dx * dx + dy * dy ) / 2.0;
1379 return idx > 0 ? idx - 1 : aStartLine;
1385 size_t i = aStartLine + 1;
1387 while( i < aLines.size() )
1389 const std::string& line = aLines[i];
1402 std::istringstream iss( line );
1405 if( pt.
name.empty() )
1419 if( i < aLines.size() && aLines[i].find(
"TIMESTAMP" ) == 0 )
1421 std::istringstream tiss( aLines[i] );
1427 bool isSpecial = ( pt.
name ==
"$GND_SYMS" || pt.
name ==
"$PWR_SYMS" || pt.
name ==
"$OSR_SYMS" );
1432 bool isV52Gates = ( i < aLines.size() && aLines[i].size() >= 3 && aLines[i][0] ==
'G' && aLines[i][1] ==
':' );
1434 if( isSpecial && !isV52Gates )
1437 if( i < aLines.size() )
1439 std::istringstream siss( aLines[i] );
1440 int numVariants = 0;
1444 for(
int v = 0; v < numVariants && i < aLines.size(); v++ )
1447 std::istringstream viss( aLines[i] );
1460 else if( i < aLines.size() )
1464 if( pt.
name ==
"$GND_SYMS" )
1466 else if( pt.
name ==
"$PWR_SYMS" )
1473 while( i < aLines.size() )
1475 const std::string& gline = aLines[i];
1485 std::istringstream giss( gline );
1486 std::string keyword;
1489 if( keyword ==
"GATE" )
1504 for(
int p = 0; p < gate.
num_pins && i < aLines.size(); p++ )
1510 std::istringstream piss( aLines[i] );
1511 std::string pinType;
1513 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1515 if( !pinType.empty() )
1516 pin.pin_type = pinType[0];
1518 std::string pinName;
1520 if( piss >> pinName )
1521 pin.pin_name = pinName;
1527 pt.
gates.push_back( gate );
1530 else if( keyword.size() >= 3 && keyword[0] ==
'G' && keyword[1] ==
':' )
1539 std::string decalStr = keyword.substr( 2 );
1540 std::istringstream diss( decalStr );
1541 std::string decalName;
1543 while( std::getline( diss, decalName,
':' ) )
1545 if( !decalName.empty() )
1555 while( pinsRead < gate.
num_pins && i < aLines.size() )
1557 const std::string& pline = aLines[i];
1562 if( ( pline[0] ==
'G' && pline.size() >= 2 && pline[1] ==
':' ) || pline.find(
"SIGPIN" ) == 0 )
1567 std::istringstream piss( pline );
1568 std::string pinToken;
1570 while( piss >> pinToken && pinsRead < gate.
num_pins )
1573 std::vector<std::string> fields;
1574 std::istringstream fiss( pinToken );
1577 while( std::getline( fiss, field,
'.' ) )
1578 fields.push_back( field );
1580 if( fields.size() >= 1 )
1581 pin.pin_id = fields[0];
1583 if( fields.size() >= 2 )
1588 if( fields.size() >= 3 && !fields[2].empty() )
1589 pin.pin_type = fields[2][0];
1591 if( fields.size() >= 4 )
1592 pin.pin_name = fields[3];
1606 if( !gate.
pins.empty() )
1612 pt.
gates.push_back( gate );
1615 else if( keyword ==
"CONN" )
1629 std::istringstream diss( aLines[i] );
1630 std::string decalName, pinType;
1631 diss >> decalName >> pinType;
1636 for(
int p = 0; p < numPins && i < aLines.size(); p++ )
1642 std::istringstream piss( aLines[i] );
1643 std::string pinType;
1645 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1647 if( !pinType.empty() )
1648 pin.pin_type = pinType[0];
1654 pt.
gates.push_back( gate );
1657 else if( keyword ==
"SIGPIN" )
1665 if( token.find(
'.' ) != std::string::npos )
1667 std::vector<std::string> fields;
1668 std::istringstream fiss( token );
1671 while( std::getline( fiss, field,
'.' ) )
1672 fields.push_back( field );
1674 if( fields.size() >= 1 )
1677 if( fields.size() >= 3 )
1703 return aLines.size() - 1;
1709 size_t i = aStartLine + 1;
1711 while( i < aLines.size() && aLines[i].empty() )
1714 while( i < aLines.size() )
1716 const std::string& line = aLines[i];
1728 if( std::isalpha(
static_cast<unsigned char>( line[0] ) ) )
1746 return aLines.size() - 1;
1753 if( aStartLine >= aLines.size() )
1756 const std::string& headerLine = aLines[aStartLine];
1757 std::istringstream iss( headerLine );
1762 std::string refdes, partType;
1763 int x = 0, y = 0, angleCode = 0, mirrorFlag = 0;
1765 iss >> refdes >> partType;
1771 std::string actualPartType;
1772 iss >> actualPartType >> x >> y >> angleCode >> mirrorFlag;
1775 partType = actualPartType;
1779 iss >> y >> angleCode >> mirrorFlag;
1790 case 0: aPart.
rotation = 0.0;
break;
1791 case 1: aPart.
rotation = 90.0;
break;
1792 case 2: aPart.
rotation = 180.0;
break;
1793 case 3: aPart.
rotation = 270.0;
break;
1794 default: aPart.
rotation = angleCode;
break;
1804 if( iss >> variantIdx )
1809 int numAttrs = 0, numDisplayedValues = 0, numPins = 0, unused1 = 0, gateIdx = 0;
1812 if( iss >> aPart.
h1 >> aPart.
w1 >> aPart.
h2 >> aPart.
w2 >> numAttrs >> numDisplayedValues >> numPins >> unused1
1813 >> gateIdx >> unused2 )
1824 std::istringstream iss2( headerLine );
1832 std::string mirrorStr;
1834 if( iss2 >> mirrorStr )
1836 if( mirrorStr ==
"M" || mirrorStr ==
"Y" || mirrorStr ==
"1" )
1845 size_t sepPos = refdes.rfind(
'-' );
1847 if( sepPos == std::string::npos )
1848 sepPos = refdes.rfind(
'.' );
1850 if( sepPos != std::string::npos && sepPos + 1 < refdes.size() )
1852 char gateLetter = refdes[sepPos + 1];
1854 if( std::isalpha(
static_cast<unsigned char>( gateLetter ) ) )
1859 aPart.
gate_index = std::toupper(
static_cast<unsigned char>( gateLetter ) ) -
'A';
1869 const PARTTYPE_DEF& definition = partTypeDefinition->second;
1882 size_t i = aStartLine + 1;
1887 if( i < aLines.size() )
1889 const std::string& fl = aLines[i];
1891 if( fl.size() >= 2 && fl[0] ==
'"' )
1893 size_t qEnd = fl.find(
'"', 1 );
1895 if( qEnd != std::string::npos )
1896 aPart.
font1 = fl.substr( 1, qEnd - 1 );
1902 if( i < aLines.size() )
1904 const std::string& fl = aLines[i];
1906 if( fl.size() >= 2 && fl[0] ==
'"' )
1908 size_t qEnd = fl.find(
'"', 1 );
1910 if( qEnd != std::string::npos )
1911 aPart.
font2 = fl.substr( 1, qEnd - 1 );
1917 for(
int a = 0; a < aPart.
num_attrs && i + 1 < aLines.size(); a++ )
1920 std::istringstream aiss( aLines[i] );
1921 int ax = 0, ay = 0, angle = 0, disp = 0, h = 0, w = 0, vis = 0;
1923 aiss >> ax >> ay >> angle >> disp >> h >> w >> vis;
1937 attr.
visible = ( ( vis & 0x8 ) == 0 );
1940 std::getline( aiss, rest );
1941 size_t qStart = rest.find(
'"' );
1943 if( qStart != std::string::npos )
1945 size_t qEnd = rest.find(
'"', qStart + 1 );
1947 if( qEnd != std::string::npos )
1948 attr.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
1953 if( i < aLines.size() )
1954 attr.
name = aLines[i];
1963 if( !aLines[i].
empty() && std::isdigit(
static_cast<unsigned char>( aLines[i][0] ) ) )
1968 if( i >= aLines.size() )
1971 const std::string& valLine = aLines[i];
1973 if( valLine.size() > 2 && valLine[0] ==
'"' )
1975 size_t closeQ = valLine.find(
'"', 1 );
1977 if( closeQ != std::string::npos )
1979 std::string attrName = valLine.substr( 1, closeQ - 1 );
1980 std::string attrValue;
1982 if( closeQ + 1 < valLine.size() )
1984 attrValue = valLine.substr( closeQ + 1 );
1985 size_t start = attrValue.find_first_not_of(
" \t" );
1987 if( start != std::string::npos )
1988 attrValue = attrValue.substr( start );
2006 attr.value = it->second;
2010 while( i < aLines.size() )
2012 const std::string& pline = aLines[i];
2021 if( std::isalpha(
static_cast<unsigned char>( pline[0] ) ) )
2025 if( std::isdigit(
static_cast<unsigned char>( pline[0] ) ) )
2028 std::istringstream poiss( pline );
2040 while( i < aLines.size() )
2042 const std::string& attrLine = aLines[i];
2044 if( attrLine.empty() )
2050 if( attrLine[0] ==
'@' )
2053 std::istringstream aiss( attrLine.substr( 1 ) );
2057 std::getline( aiss, rest );
2058 size_t start = rest.find_first_not_of(
" \t" );
2060 if( start != std::string::npos )
2062 rest = rest.substr( start );
2064 if( !rest.empty() && rest[0] ==
'"' )
2066 size_t endQuote = rest.find(
'"', 1 );
2068 if( endQuote != std::string::npos )
2070 attr.
value = rest.substr( 1, endQuote - 1 );
2071 rest = rest.substr( endQuote + 1 );
2076 std::istringstream viss( rest );
2078 std::getline( viss, rest );
2081 std::istringstream piss( rest );
2086 if( piss >> visStr )
2087 attr.
visible = ( visStr !=
"N" && visStr !=
"0" && visStr !=
"H" );
2093 else if( std::isalpha(
static_cast<unsigned char>( attrLine[0] ) ) )
2110 constexpr long long MAX_BUS_POINTS = 1'000'000;
2111 size_t i = aStartLine + 1;
2116 [&](
size_t aLine,
const wxString& aDetail )
2120 m_reporter->Report( wxString::Format(
_(
"BUSSES line %llu: unsupported record, %s. "
2121 "The bus was skipped." ),
2122 static_cast<unsigned long long>( aLine + 1 ),
2128 while( i < aLines.size() )
2130 const std::string& line = aLines[i];
2142 long long parsedPointCount = -1;
2143 std::istringstream header( line );
2146 if( !( header >> bus.
handle >> bus.
name >> parsedPointCount ) || header >> extra
2147 || !bus.
handle.starts_with(
"@@@B" ) || bus.
handle.size() == 4
2148 || parsedPointCount < 0 || parsedPointCount > MAX_BUS_POINTS )
2150 unsupported( i, wxS(
"invalid bus header or point count" ) );
2155 const size_t pointCount =
static_cast<size_t>( parsedPointCount );
2156 bool busMalformed =
false;
2159 if( !bus.
name.empty() )
2164 while( i < aLines.size() && bus.
path.size() < pointCount )
2170 if( aLines[i].
empty() )
2177 std::istringstream coordinates( aLines[i] );
2180 if( !( coordinates >> point.
x >> point.
y ) || coordinates >> extra )
2182 busMalformed =
true;
2187 bus.
path.push_back( point );
2192 if( busMalformed || bus.
path.size() != pointCount )
2194 unsupported( i == aLines.size() ? i - 1 : i,
2195 busMalformed ? wxS(
"invalid bus point" )
2196 : wxS(
"bus ended before its declared point count" ) );
2200 m_buses.push_back( std::move( bus ) );
2203 return aLines.size() - 1;
2209 size_t i = aStartLine + 1;
2211 while( i < aLines.size() )
2213 const std::string& line = aLines[i];
2225 if( line.find(
"@@@O" ) == 0 )
2228 std::istringstream iss( line );
2229 std::string idToken;
2232 if( idToken.size() > 4 )
2247 return aBus.handle == opc.symbol_lib && aBus.sheet_number == m_currentSheet;
2254 if( std::find( bus->member_nets.begin(), bus->member_nets.end(), opc.
signal_name )
2255 == bus->member_nets.end() )
2265 return aLines.size() - 1;
2271 size_t i = aStartLine + 1;
2273 while( i < aLines.size() )
2275 const std::string& line = aLines[i];
2287 if( line.find(
"@@@D" ) == 0 )
2290 std::istringstream iss( line );
2291 std::string idToken;
2294 if( idToken.size() > 4 )
2309 return aLines.size() - 1;
2316 size_t i = aStartLine + 1;
2318 while( i < aLines.size() )
2320 const std::string& line = aLines[i];
2333 if( secName ==
"SIGNAL" )
2338 if( !signal.
name.empty() )
2340 for(
auto& wire : signal.
wires )
2344 for(
const auto& wire : signal.
wires )
2346 for(
const auto& ep : { wire.endpoint_a, wire.endpoint_b } )
2348 if( ep.find(
'.' ) != std::string::npos && ep.find(
"@@@" ) == std::string::npos )
2350 size_t dotPos = ep.find(
'.' );
2352 conn.
reference = ep.substr( 0, dotPos );
2373 m_signals.push_back( std::move( signal ) );
2388 return aLines.size() - 1;
2394 if( aStartLine >= aLines.size() )
2398 const std::string& headerLine = aLines[aStartLine];
2401 if( secName !=
"SIGNAL" )
2404 size_t afterMarker = headerLine.find(
'*', 1 );
2406 if( afterMarker == std::string::npos )
2409 std::string rest = headerLine.substr( afterMarker + 1 );
2410 std::istringstream iss( rest );
2414 size_t i = aStartLine + 1;
2416 if( aSignal.
flags2 == 1 && i < aLines.size() )
2418 const std::string& funcLine = aLines[i];
2420 if( funcLine.find(
"\"FUNCTION\"" ) != std::string::npos || funcLine.find(
"FUNCTION" ) == 0 )
2422 size_t qStart = funcLine.find(
'"' );
2424 if( qStart != std::string::npos )
2426 size_t qEnd = funcLine.find(
'"', qStart + 1 );
2428 if( qEnd != std::string::npos )
2430 size_t afterQ = funcLine.find_first_not_of(
" \t", qEnd + 1 );
2432 if( afterQ != std::string::npos )
2433 aSignal.
function = funcLine.substr( afterQ );
2443 while( i < aLines.size() )
2445 const std::string& line = aLines[i];
2457 std::istringstream wiss( line );
2468 for(
int v = 0; v < wire.
vertex_count && i < aLines.size(); v++ )
2470 const std::string& ptLine = aLines[i];
2476 std::istringstream piss( ptLine );
2477 piss >> pt.
x >> pt.
y;
2488 aSignal.
wires.push_back( wire );
2491 return i > 0 ? i - 1 : aStartLine;
2497 size_t i = aStartLine + 1;
2499 while( i < aLines.size() )
2501 const std::string& line = aLines[i];
2515 std::istringstream iss( line );
2522 std::getline( iss, rest );
2523 size_t qStart = rest.find(
'"' );
2525 if( qStart != std::string::npos )
2527 size_t qEnd = rest.find(
'"', qStart + 1 );
2529 if( qEnd != std::string::npos )
2530 label.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
2537 return aLines.size() - 1;
2543 size_t i = aStartLine + 1;
2545 bool foundFirstBrace =
false;
2547 while( i < aLines.size() )
2549 const std::string& line = aLines[i];
2551 for(
char c : line )
2556 foundFirstBrace =
true;
2564 if( foundFirstBrace && braceDepth <= 0 )
2574 return aLines.size() - 1;
2582 if( sym.name == aName )
2594 if( part.reference == aReference )
2606 if( signal.name == aName )
2618 if( sheets.empty() )
2621 return *sheets.rbegin();
2627 std::set<int> sheets;
2630 sheets.insert( header.sheet_num );
2633 sheets.insert( part.sheet_number );
2637 for(
const auto& wire : signal.wires )
2638 sheets.insert( wire.sheet_number );
2640 for(
const auto& conn : signal.connections )
2641 sheets.insert( conn.sheet_number );
2644 if( sheets.empty() )
2653 std::vector<SCH_SIGNAL>
result;
2658 filteredSignal.
name = signal.name;
2660 for(
const auto& wire : signal.wires )
2662 if( wire.sheet_number == aSheetNumber )
2663 filteredSignal.
wires.push_back( wire );
2666 for(
const auto& conn : signal.connections )
2668 if( conn.sheet_number == aSheetNumber )
2673 result.push_back( filteredSignal );
2682 std::vector<PART_PLACEMENT>
result;
2686 if( part.sheet_number == aSheetNumber )
2687 result.push_back( part );
2696 std::string upper = aTypeStr;
2697 std::transform( upper.begin(), upper.end(), upper.begin(), ::toupper );
2699 if( upper ==
"I" || upper ==
"IN" || upper ==
"INPUT" || upper ==
"L" )
2702 if( upper ==
"O" || upper ==
"OUT" || upper ==
"OUTPUT" || upper ==
"S" )
2705 if( upper ==
"B" || upper ==
"BI" || upper ==
"BIDIR" || upper ==
"BIDIRECTIONAL" )
2708 if( upper ==
"T" || upper ==
"TRI" || upper ==
"TRISTATE" )
2711 if( upper ==
"OC" || upper ==
"OPENCOLLECTOR" )
2714 if( upper ==
"OE" || upper ==
"OPENEMITTER" )
2717 if( upper ==
"P" || upper ==
"PWR" || upper ==
"POWER" || upper ==
"G" )
2720 if( upper ==
"PAS" || upper ==
"PASSIVE" )
2729 switch( std::toupper( aTypeChar ) )
size_t skipBraceDelimitedSection(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionBUSSES(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionPARTTYPE(const std::vector< std::string > &aLines, size_t aStartLine)
bool isSectionMarker(const std::string &aLine) const
bool Parse(const std::string &aFileName)
size_t parseSymbolDef(const std::vector< std::string > &aLines, size_t aStartLine, SYMBOL_DEF &aSymbol)
size_t parseSectionSCH(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionCAEDECAL(const std::vector< std::string > &aLines, size_t aStartLine)
std::vector< OFF_PAGE_CONNECTOR > m_offPageConnectors
size_t parseSectionTIEDOTS(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parsePartPlacement(const std::vector< std::string > &aLines, size_t aStartLine, PART_PLACEMENT &aPart)
size_t parseSectionSHT(const std::vector< std::string > &aLines, size_t aStartLine)
std::vector< SCH_SIGNAL > m_signals
size_t parseSectionOFFPAGEREFS(const std::vector< std::string > &aLines, size_t aStartLine)
std::string extractSectionName(const std::string &aLine) const
size_t parseSectionCONNECTION(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionLINES(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseGraphicPrimitive(const std::vector< std::string > &aLines, size_t aStartLine, SYMBOL_GRAPHIC &aGraphic)
static PIN_TYPE ParsePinTypeChar(char aTypeChar)
bool parseHeader(const std::string &aLine)
std::vector< SHEET_HEADER > m_sheetHeaders
size_t parseSectionNETNAMES(const std::vector< std::string > &aLines, size_t aStartLine)
std::vector< SYMBOL_DEF > m_symbolDefs
std::vector< PART_PLACEMENT > m_partPlacements
PIN_TYPE parsePinType(const std::string &aTypeStr)
std::vector< SCH_SIGNAL > GetSignalsOnSheet(int aSheetNumber) const
std::set< int > GetSheetNumbers() const
std::vector< TEXT_ITEM > m_textItems
static bool CheckFileHeader(const std::string &aFileName)
size_t parseSectionTEXT(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSignalDef(const std::vector< std::string > &aLines, size_t aStartLine, SCH_SIGNAL &aSignal)
std::vector< NETNAME_LABEL > m_netNameLabels
std::vector< PART_PLACEMENT > GetPartsOnSheet(int aSheetNumber) const
std::vector< LINES_ITEM > m_linesItems
const SCH_SIGNAL * GetSignal(const std::string &aName) const
std::vector< TIED_DOT > m_tiedDots
std::map< std::string, PARTTYPE_DEF > m_partTypes
std::vector< BUS_DEF > m_buses
const SYMBOL_DEF * GetSymbolDef(const std::string &aName) const
const PART_PLACEMENT * GetPartPlacement(const std::string &aReference) const
size_t parseSectionCAE(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionFIELDS(const std::vector< std::string > &aLines, size_t aStartLine)
size_t parseSectionPART(const std::vector< std::string > &aLines, size_t aStartLine)
int GetSheetCount() const
static bool empty(const wxTextEntryBase *aCtrl)
int ParseInt(const std::string &aStr, int aDefault, const std::string &aContext)
Parse integer from string with error context.
double ParseDouble(const std::string &aStr, double aDefault, const std::string &aContext)
Parse double from string with error context.
VECTOR2I padsSchArcMidpoint(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter)
Midpoint of the arc through aStart and aEnd about aCenter, on the minor-arc side (the perpendicular b...
std::vector< FAB_LAYER_COLOR > dummy
std::vector< POINT > path
std::vector< std::string > aliases
std::vector< std::string > decal_names
std::vector< PARTTYPE_PIN > pins
std::optional< ARC_DATA > arc
std::vector< TEXT_ITEM > texts
std::vector< SYMBOL_GRAPHIC > primitives
std::vector< GATE_DEF > gates
std::vector< SPECIAL_VARIANT > special_variants
std::vector< std::string > swap_lines
std::vector< SIGPIN > sigpins
std::string special_keyword
std::string power_net_name
std::map< std::string, std::string > attr_overrides
std::string symbol_name
The part type, which is also the power symbol's net name.
std::string decal_name
CAEDECAL the placed gate draws, empty when unresolved.
std::vector< PART_ATTRIBUTE > attributes
std::vector< PIN_OVERRIDE > pin_overrides
std::vector< PIN_CONNECTION > connections
std::vector< WIRE_SEGMENT > wires
std::vector< SYMBOL_GRAPHIC > graphics
std::vector< SYMBOL_PIN > pins
std::vector< CAEDECAL_ATTR > attrs
std::vector< SYMBOL_TEXT > texts
std::vector< GRAPHIC_POINT > points
Wire segment connecting two endpoints through coordinate vertices.
std::vector< POINT > vertices
static EDA_ORIENTATION orientation(double d)
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I