48 if( aLine.size() < 3 || aLine[0] !=
'*' )
51 size_t endPos = aLine.find(
'*', 1 );
52 return endPos != std::string::npos && endPos > 1;
58 if( aLine.size() < 3 || aLine[0] !=
'*' )
61 size_t endPos = aLine.find(
'*', 1 );
63 if( endPos == std::string::npos || endPos <= 1 )
66 return aLine.substr( 1, endPos - 1 );
87 std::ifstream file( aFileName );
97 std::vector<std::string> lines;
100 while( std::getline( file, line ) )
102 if( !line.empty() && line.back() ==
'\r' )
105 lines.push_back( line );
128 for(
size_t i = 1; i < lines.size(); i++ )
131 const std::string& currentLine = lines[i];
133 if( currentLine.empty() )
137 if( currentLine.find(
"*REMARK*" ) == 0 )
145 if( sectionName ==
"SCH" )
149 else if( sectionName ==
"CAM" || sectionName ==
"MISC" )
153 else if( sectionName ==
"FIELDS" )
157 else if( sectionName ==
"SHT" )
161 else if( sectionName ==
"CAE" )
165 else if( sectionName ==
"TEXT" )
169 else if( sectionName ==
"LINES" )
173 else if( sectionName ==
"CAEDECAL" )
177 else if( sectionName ==
"PARTTYPE" )
181 else if( sectionName ==
"PART" )
185 else if( sectionName ==
"BUSSES" )
190 else if( sectionName ==
"OFFPAGE REFS" )
194 else if( sectionName ==
"TIEDOTS" )
198 else if( sectionName ==
"CONNECTION" )
202 else if( sectionName ==
"NETNAMES" )
206 else if( sectionName ==
"END" )
226 for(
auto& attr : part.attributes )
228 if( attr.name ==
"Ref.Des." && attr.value.empty() )
229 attr.value = part.reference;
231 auto ovr = part.attr_overrides.find( attr.name );
233 if( ovr != part.attr_overrides.end() && attr.value.empty() )
234 attr.value = ovr->second;
242 std::ifstream file( aFileName );
244 if( !file.is_open() )
247 std::string firstLine;
249 if( !std::getline( file, firstLine ) )
252 if( !firstLine.empty() && firstLine.back() ==
'\r' )
253 firstLine.pop_back();
255 if( firstLine.find(
"*PADS-LOGIC" ) == 0 )
258 if( firstLine.find(
"*PADS-POWERLOGIC" ) == 0 )
267 if( aLine.empty() || aLine[0] !=
'*' )
270 size_t endPos = aLine.find(
'*', 1 );
272 if( endPos == std::string::npos )
275 std::string headerTag = aLine.substr( 1, endPos - 1 );
280 std::regex headerRegex( R
"(PADS-(POWER)?LOGIC-V(\d+\.\d+)(?:-([A-Za-z0-9]+))?)" );
283 if( !std::regex_match( headerTag, match, headerRegex ) )
286 if( match[1].matched )
287 m_header.product =
"PADS-POWERLOGIC";
291 m_header.version =
"V" + match[2].str();
293 if( match[3].matched )
296 if( endPos + 1 < aLine.size() )
298 std::string desc = aLine.substr( endPos + 1 );
299 size_t start = desc.find_first_not_of(
' ' );
301 if( start != std::string::npos )
302 m_header.description = desc.substr( start );
311 size_t i = aStartLine + 1;
313 while( i < aLines.size() )
315 const std::string& line = aLines[i];
326 std::istringstream iss( line );
330 if( keyword ==
"UNITS" )
343 else if( keyword ==
"CUR" )
349 if( second ==
"SHEET" )
352 else if( keyword ==
"SHEET" )
358 if( second ==
"SIZE" )
360 std::string sizeCode;
365 if( sizeCode ==
"A" )
370 else if( sizeCode ==
"B" )
375 else if( sizeCode ==
"C" )
380 else if( sizeCode ==
"D" )
385 else if( sizeCode ==
"E" )
392 else if( keyword ==
"USERGRID" )
396 else if( keyword ==
"LINEWIDTH" )
400 else if( keyword ==
"CONNWIDTH" )
404 else if( keyword ==
"BUSWIDTH" )
408 else if( keyword ==
"BUSANGLE" )
412 else if( keyword ==
"TEXTSIZE" )
417 else if( keyword ==
"PINNAMESIZE" )
421 else if( keyword ==
"REFNAMESIZE" )
425 else if( keyword ==
"PARTNAMESIZE" )
429 else if( keyword ==
"PINNOSIZE" )
433 else if( keyword ==
"NETNAMESIZE" )
437 else if( keyword ==
"DOTGRID" )
441 else if( keyword ==
"TIEDOTSIZE" )
445 else if( keyword ==
"REAL" )
451 if( second ==
"WIDTH" )
454 else if( keyword ==
"FONT" )
460 if( second ==
"MODE" )
463 else if( keyword ==
"DEFAULT" )
469 if( second ==
"FONT" )
472 std::getline( iss, rest );
473 size_t start = rest.find(
'"' );
475 if( start != std::string::npos )
477 size_t end = rest.find(
'"', start + 1 );
479 if(
end != std::string::npos )
484 else if( keyword ==
"BORDER" )
490 if( second ==
"NAME" )
502 else if( keyword ==
"JOBNAME" )
505 std::getline( iss, rest );
506 size_t start = rest.find_first_not_of(
" \t" );
508 if( start != std::string::npos )
510 rest = rest.substr( start );
512 if( rest.size() >= 2 && rest.front() ==
'"' && rest.back() ==
'"' )
513 rest = rest.substr( 1, rest.size() - 2 );
519 else if( keyword ==
"NTXCOL" || keyword ==
"HIRCOL" || keyword ==
"LINCOL" ||
520 keyword ==
"TXTCOL" || keyword ==
"CONCOL" || keyword ==
"BUSCOL" ||
521 keyword ==
"PTXCOL" || keyword ==
"COMCOL" || keyword ==
"NMCOL" ||
522 keyword ==
"PNMCOL" || keyword ==
"PINCOL" || keyword ==
"NETCOL" ||
523 keyword ==
"FBGCOL" || keyword ==
"FIELDCOL" ||
524 keyword ==
"NNVISPWRGND" || keyword ==
"PCBFLAGS" ||
525 keyword ==
"JOBTIME" || keyword ==
"BACKUPTIME" ||
526 keyword ==
"OFFREFVIEW" || keyword ==
"OFFREFNUM" ||
527 keyword ==
"SHEETNUMSEP" )
535 return aLines.size() - 1;
541 size_t i = aStartLine + 1;
543 while( i < aLines.size() )
545 const std::string& line = aLines[i];
550 if( line.empty() || line[0] !=
'"' )
557 size_t closeQuote = line.find(
'"', 1 );
559 if( closeQuote != std::string::npos )
561 std::string fieldName = line.substr( 1, closeQuote - 1 );
562 std::string fieldValue;
564 if( closeQuote + 1 < line.size() )
566 fieldValue = line.substr( closeQuote + 1 );
567 size_t start = fieldValue.find_first_not_of(
" \t" );
569 if( start != std::string::npos )
570 fieldValue = fieldValue.substr( start );
581 return aLines.size() - 1;
588 const std::string& line = aLines[aStartLine];
589 std::string afterMarker = line.substr( line.find(
'*', 1 ) + 1 );
591 std::istringstream iss( afterMarker );
606 size_t i = aStartLine + 1;
608 while( i < aLines.size() )
610 const std::string& line = aLines[i];
618 return aLines.size() - 1;
624 size_t i = aStartLine + 1;
626 while( i < aLines.size() )
628 const std::string& line = aLines[i];
641 std::istringstream iss( line );
652 std::getline( iss, rest );
653 size_t qStart = rest.find(
'"' );
655 if( qStart != std::string::npos )
657 size_t qEnd = rest.find(
'"', qStart + 1 );
659 if( qEnd != std::string::npos )
660 item.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
666 if( i < aLines.size() )
673 return aLines.size() - 1;
679 size_t i = aStartLine + 1;
681 while( i < aLines.size() )
683 const std::string& line = aLines[i];
695 if( line.find(
"LINES" ) != std::string::npos )
698 std::istringstream iss( line );
699 std::string
name, keyword;
704 if( keyword ==
"LINES" )
713 while( i < aLines.size() )
715 const std::string& pline = aLines[i];
727 if( pline.find(
"LINES" ) != std::string::npos )
729 std::istringstream tiss( pline );
730 std::string tname, tkw;
731 tiss >> tname >> tkw;
737 std::istringstream piss( pline );
738 std::string firstToken;
741 if( firstToken ==
"OPEN" || firstToken ==
"CLOSED" ||
742 firstToken ==
"CIRCLE" || firstToken ==
"COPCLS" )
754 && ( std::isdigit( firstToken[0] )
755 || firstToken[0] ==
'-'
756 || firstToken[0] ==
'+' );
758 if(
isNumber && pline.find(
'"' ) != std::string::npos )
762 std::istringstream tiss( pline );
765 tiss >> tx >> ty >>
text.rotation >>
text.justification >>
text.height
766 >>
text.width_factor;
768 text.position.x = tx;
769 text.position.y = ty;
772 std::getline( tiss, trest );
773 size_t qStart = trest.find(
'"' );
775 if( qStart != std::string::npos )
777 size_t qEnd = trest.find(
'"', qStart + 1 );
779 if( qEnd != std::string::npos )
780 text.font_name = trest.substr( qStart + 1, qEnd - qStart - 1 );
785 if( i < aLines.size() )
786 text.content = aLines[i];
802 return aLines.size() - 1;
809 size_t i = aStartLine + 1;
811 while( i < aLines.size() )
813 const std::string& line = aLines[i];
828 if( !symbol.
name.empty() )
837 std::map<std::string, double> pinDecalLengths;
841 if( !sym.is_pin_decal )
844 for(
const auto& graphic : sym.graphics )
849 if( graphic.points.size() < 2 )
852 const auto& first = graphic.points.front().coord;
853 const auto& last = graphic.points.back().coord;
854 double dx = last.x - first.x;
855 double dy = last.y - first.y;
856 pinDecalLengths[sym.name] = std::sqrt( dx * dx + dy * dy );
863 if( sym.is_pin_decal )
866 for(
auto&
pin : sym.pins )
868 if(
pin.pin_decal_name.empty() )
871 auto it = pinDecalLengths.find(
pin.pin_decal_name );
873 if( it != pinDecalLengths.end() )
874 pin.length = it->second;
878 return i > 0 ? i - 1 : aLines.size() - 1;
885 if( aStartLine >= aLines.size() )
888 const std::string& headerLine = aLines[aStartLine];
892 std::istringstream iss( headerLine );
902 std::vector<std::string> tokens;
905 while( iss >> token )
906 tokens.push_back( token );
908 if( tokens.size() >= 12 )
927 if( tokens.size() >= 3 )
939 size_t idx = aStartLine + 1;
941 for(
int p = 0; p < aSymbol.
num_pieces && idx < aLines.size(); p++ )
943 const std::string& gline = aLines[idx];
949 std::istringstream giss( gline );
953 if( typeStr ==
"OPEN" || typeStr ==
"LINE" )
957 giss >> p1.
x >> p1.
y >> p2.
x >> p2.
y;
958 graphic.
points.push_back( { p1, std::nullopt } );
959 graphic.
points.push_back( { p2, std::nullopt } );
962 else if( typeStr ==
"CLOSED" || typeStr ==
"RECT" )
966 giss >> p1.
x >> p1.
y >> p2.
x >> p2.
y;
967 graphic.
points.push_back( { p1, std::nullopt } );
968 graphic.
points.push_back( { p2, std::nullopt } );
971 else if( typeStr ==
"CIRCLE" )
978 aSymbol.
graphics.push_back( graphic );
982 for(
int p = 0; p < aSymbol.
num_pins && idx < aLines.size(); p++ )
984 const std::string& pline = aLines[idx];
990 std::istringstream piss( pline );
991 double orientation = 0;
993 piss >>
pin.position.x >>
pin.position.y >> orientation >>
pin.length;
994 piss >>
pin.number >>
pin.name;
996 pin.rotation = orientation;
1000 if( piss >> typeStr )
1003 aSymbol.
pins.push_back(
pin );
1011 size_t idx = aStartLine + 1;
1014 if( idx < aLines.size() && aLines[idx].find(
"TIMESTAMP" ) == 0 )
1016 std::istringstream tiss( aLines[idx] );
1023 if( idx < aLines.size() && aLines[idx].size() >= 2 && aLines[idx][0] ==
'"' )
1025 size_t qEnd = aLines[idx].find(
'"', 1 );
1027 if( qEnd != std::string::npos )
1028 aSymbol.
font1 = aLines[idx].substr( 1, qEnd - 1 );
1033 if( idx < aLines.size() && aLines[idx].size() >= 2 && aLines[idx][0] ==
'"' )
1035 size_t qEnd = aLines[idx].find(
'"', 1 );
1037 if( qEnd != std::string::npos )
1038 aSymbol.
font2 = aLines[idx].substr( 1, qEnd - 1 );
1044 for(
int a = 0; a < aSymbol.
num_attrs && idx + 1 < aLines.size(); a++ )
1047 std::istringstream aiss( aLines[idx] );
1056 std::getline( aiss, rest );
1057 size_t qStart = rest.find(
'"' );
1059 if( qStart != std::string::npos )
1061 size_t qEnd = rest.find(
'"', qStart + 1 );
1063 if( qEnd != std::string::npos )
1064 attr.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
1069 if( idx < aLines.size() )
1072 aSymbol.
attrs.push_back( attr );
1077 for(
int p = 0; p < aSymbol.
num_pieces && idx < aLines.size(); p++ )
1079 if( aLines[idx].
empty() )
1088 aSymbol.
graphics.push_back( graphic );
1095 while( idx < aLines.size() )
1097 const std::string& tline = aLines[idx];
1106 if( tline.size() > 1 && tline[0] ==
'T' &&
1107 ( std::isdigit(
static_cast<unsigned char>( tline[1] ) ) || tline[1] ==
'-' ) )
1114 std::istringstream tiss( tline );
1117 tiss >> tx >> ty >>
text.rotation >>
text.justification;
1119 int height = 0, width = 0;
1120 tiss >> height >> width;
1122 text.width_factor = width;
1124 text.position.x = tx;
1125 text.position.y = ty;
1129 if( idx < aLines.size() )
1131 text.content = aLines[idx];
1139 for(
int p = 0; p < aSymbol.
num_pins && idx < aLines.size(); p++ )
1141 const std::string& tLine = aLines[idx];
1157 if( tLine.size() > 1 && tLine[0] ==
'T' )
1160 std::string tContent = tLine.substr( 1 );
1161 std::istringstream tiss( tContent );
1162 int tx = 0, ty = 0, angle = 0;
1164 tiss >> tx >> ty >> angle >>
pin.side >>
pin.pn_h >>
pin.pn_w >>
pin.pn_angle
1166 >>
pin.pin_decal_name;
1168 pin.position.x = tx;
1169 pin.position.y = ty;
1170 pin.rotation = angle;
1173 if(
pin.pin_decal_name ==
"PINB" ||
pin.pin_decal_name ==
"PINORB" ||
1174 pin.pin_decal_name ==
"PCLKB" ||
pin.pin_decal_name ==
"PINIEB" ||
1175 pin.pin_decal_name ==
"PINCLKB" )
1177 pin.inverted =
true;
1180 if(
pin.pin_decal_name ==
"PCLK" ||
pin.pin_decal_name ==
"PCLKB" ||
1181 pin.pin_decal_name ==
"PINCLK" ||
pin.pin_decal_name ==
"PINCLKB" )
1189 if(
pin.pin_decal_name.empty() )
1191 else if(
pin.pin_decal_name.find(
"SHORT" ) != std::string::npos )
1193 else if(
pin.pin_decal_name.find(
"LONG" ) != std::string::npos )
1200 if( idx < aLines.size() )
1202 const std::string& pLine = aLines[idx];
1204 if( pLine.size() > 1 && pLine[0] ==
'P' )
1206 std::string pContent = pLine.substr( 1 );
1207 std::istringstream piss( pContent );
1208 int px1 = 0, py1 = 0, px2 = 0, py2 = 0;
1210 piss >> px1 >> py1 >>
pin.pn_off_angle >>
pin.pn_off_just
1211 >> px2 >> py2 >>
pin.pl_off_angle >>
pin.pl_off_just >>
pin.p_flags;
1213 pin.pn_offset.x = px1;
1214 pin.pn_offset.y = py1;
1215 pin.pl_offset.x = px2;
1216 pin.pl_offset.y = py2;
1219 if(
pin.p_flags & 128 )
1228 pin.number = std::to_string( p + 1 );
1230 aSymbol.
pins.push_back(
pin );
1233 return idx > 0 ? idx - 1 : 0;
1240 if( aStartLine >= aLines.size() )
1243 const std::string& headerLine = aLines[aStartLine];
1244 std::istringstream iss( headerLine );
1245 std::string typeStr;
1246 int pointCount = 0, lineWidth = 0, lineStyle = 255;
1248 iss >> typeStr >> pointCount >> lineWidth >> lineStyle;
1253 if( typeStr ==
"OPEN" )
1258 else if( typeStr ==
"CLOSED" )
1263 else if( typeStr ==
"CIRCLE" )
1268 else if( typeStr ==
"COPCLS" )
1275 size_t idx = aStartLine + 1;
1277 for(
int p = 0; p < pointCount && idx < aLines.size(); p++ )
1279 const std::string& ptLine = aLines[idx];
1284 std::istringstream piss( ptLine );
1288 std::vector<std::string> extraTokens;
1291 while( piss >> tok )
1292 extraTokens.push_back( tok );
1294 if( extraTokens.size() >= 6 )
1306 aGraphic.
points.push_back( gpt );
1316 std::set<double> uniqueX, uniqueY;
1318 for(
const auto& pt : aGraphic.
points )
1320 uniqueX.insert( pt.coord.x );
1321 uniqueY.insert( pt.coord.y );
1324 bool isRect = ( uniqueX.size() == 2 && uniqueY.size() == 2 );
1328 double minX = *uniqueX.begin();
1329 double maxX = *uniqueX.rbegin();
1330 double minY = *uniqueY.begin();
1331 double maxY = *uniqueY.rbegin();
1334 aGraphic.
points.push_back( { { minX, minY }, std::nullopt } );
1335 aGraphic.
points.push_back( { { maxX, maxY }, std::nullopt } );
1348 double dx = aGraphic.
points[1].coord.x - aGraphic.
points[0].coord.x;
1349 double dy = aGraphic.
points[1].coord.y - aGraphic.
points[0].coord.y;
1350 aGraphic.
radius = std::sqrt( dx * dx + dy * dy ) / 2.0;
1353 return idx > 0 ? idx - 1 : aStartLine;
1360 size_t i = aStartLine + 1;
1362 while( i < aLines.size() )
1364 const std::string& line = aLines[i];
1377 std::istringstream iss( line );
1381 if( pt.
name.empty() )
1390 if( i < aLines.size() && aLines[i].find(
"TIMESTAMP" ) == 0 )
1392 std::istringstream tiss( aLines[i] );
1399 bool isSpecial = ( pt.
name ==
"$GND_SYMS" || pt.
name ==
"$PWR_SYMS" ||
1400 pt.
name ==
"$OSR_SYMS" );
1405 bool isV52Gates = ( i < aLines.size() && aLines[i].size() >= 3
1406 && aLines[i][0] ==
'G' && aLines[i][1] ==
':' );
1408 if( isSpecial && !isV52Gates )
1411 if( i < aLines.size() )
1413 std::istringstream siss( aLines[i] );
1414 int numVariants = 0;
1418 for(
int v = 0; v < numVariants && i < aLines.size(); v++ )
1421 std::istringstream viss( aLines[i] );
1434 else if( i < aLines.size() )
1438 if( pt.
name ==
"$GND_SYMS" )
1440 else if( pt.
name ==
"$PWR_SYMS" )
1447 while( i < aLines.size() )
1449 const std::string& gline = aLines[i];
1460 std::istringstream giss( gline );
1461 std::string keyword;
1464 if( keyword ==
"GATE" )
1481 for(
int p = 0; p < gate.
num_pins && i < aLines.size(); p++ )
1487 std::istringstream piss( aLines[i] );
1488 std::string pinType;
1490 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1492 if( !pinType.empty() )
1493 pin.pin_type = pinType[0];
1495 std::string pinName;
1497 if( piss >> pinName )
1498 pin.pin_name = pinName;
1504 pt.
gates.push_back( gate );
1507 else if( keyword.size() >= 3 && keyword[0] ==
'G' && keyword[1] ==
':' )
1516 std::string decalStr = keyword.substr( 2 );
1517 std::istringstream diss( decalStr );
1518 std::string decalName;
1520 while( std::getline( diss, decalName,
':' ) )
1522 if( !decalName.empty() )
1532 while( pinsRead < gate.
num_pins && i < aLines.size() )
1534 const std::string& pline = aLines[i];
1539 if( ( pline[0] ==
'G' && pline.size() >= 2 && pline[1] ==
':' )
1540 || pline.find(
"SIGPIN" ) == 0 )
1545 std::istringstream piss( pline );
1546 std::string pinToken;
1548 while( piss >> pinToken && pinsRead < gate.
num_pins )
1551 std::vector<std::string> fields;
1552 std::istringstream fiss( pinToken );
1555 while( std::getline( fiss, field,
'.' ) )
1556 fields.push_back( field );
1558 if( fields.size() >= 1 )
1559 pin.pin_id = fields[0];
1561 if( fields.size() >= 2 )
1567 if( fields.size() >= 3 && !fields[2].empty() )
1568 pin.pin_type = fields[2][0];
1570 if( fields.size() >= 4 )
1571 pin.pin_name = fields[3];
1586 if( !gate.
pins.empty() )
1592 pt.
gates.push_back( gate );
1595 else if( keyword ==
"CONN" )
1610 std::istringstream diss( aLines[i] );
1611 std::string decalName, pinType;
1612 diss >> decalName >> pinType;
1618 for(
int p = 0; p < numPins && i < aLines.size(); p++ )
1624 std::istringstream piss( aLines[i] );
1625 std::string pinType;
1627 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1629 if( !pinType.empty() )
1630 pin.pin_type = pinType[0];
1636 pt.
gates.push_back( gate );
1639 else if( keyword ==
"SIGPIN" )
1647 if( token.find(
'.' ) != std::string::npos )
1649 std::vector<std::string> fields;
1650 std::istringstream fiss( token );
1653 while( std::getline( fiss, field,
'.' ) )
1654 fields.push_back( field );
1656 if( fields.size() >= 1 )
1659 if( fields.size() >= 3 )
1685 return aLines.size() - 1;
1692 size_t i = aStartLine + 1;
1695 while( i < aLines.size() && aLines[i].empty() )
1698 while( i < aLines.size() )
1700 const std::string& line = aLines[i];
1712 if( std::isalpha(
static_cast<unsigned char>( line[0] ) ) )
1730 return aLines.size() - 1;
1737 if( aStartLine >= aLines.size() )
1740 const std::string& headerLine = aLines[aStartLine];
1741 std::istringstream iss( headerLine );
1747 std::string refdes, partType;
1748 int x = 0, y = 0, angleCode = 0, mirrorFlag = 0;
1750 iss >> refdes >> partType;
1756 std::string actualPartType;
1757 iss >> actualPartType >> x >> y >> angleCode >> mirrorFlag;
1760 partType = actualPartType;
1764 iss >> y >> angleCode >> mirrorFlag;
1775 case 0: aPart.
rotation = 0.0;
break;
1776 case 1: aPart.
rotation = 90.0;
break;
1777 case 2: aPart.
rotation = 180.0;
break;
1778 case 3: aPart.
rotation = 270.0;
break;
1779 default: aPart.
rotation = angleCode;
break;
1789 if( iss >> variantIdx )
1795 int numAttrs = 0, numDisplayedValues = 0, numPins = 0, unused1 = 0, gateIdx = 0;
1798 if( iss >> aPart.
h1 >> aPart.
w1 >> aPart.
h2 >> aPart.
w2 >> numAttrs >> numDisplayedValues
1799 >> numPins >> unused1 >> gateIdx >> unused2 )
1810 std::istringstream iss2( headerLine );
1818 std::string mirrorStr;
1820 if( iss2 >> mirrorStr )
1822 if( mirrorStr ==
"M" || mirrorStr ==
"Y" || mirrorStr ==
"1" )
1832 size_t sepPos = refdes.rfind(
'-' );
1834 if( sepPos == std::string::npos )
1835 sepPos = refdes.rfind(
'.' );
1837 if( sepPos != std::string::npos && sepPos + 1 < refdes.size() )
1839 char gateLetter = refdes[sepPos + 1];
1841 if( std::isalpha(
static_cast<unsigned char>( gateLetter ) ) )
1846 aPart.
gate_index = std::toupper(
static_cast<unsigned char>( gateLetter ) ) -
'A';
1852 size_t i = aStartLine + 1;
1858 if( i < aLines.size() )
1860 const std::string& fl = aLines[i];
1862 if( fl.size() >= 2 && fl[0] ==
'"' )
1864 size_t qEnd = fl.find(
'"', 1 );
1866 if( qEnd != std::string::npos )
1867 aPart.
font1 = fl.substr( 1, qEnd - 1 );
1873 if( i < aLines.size() )
1875 const std::string& fl = aLines[i];
1877 if( fl.size() >= 2 && fl[0] ==
'"' )
1879 size_t qEnd = fl.find(
'"', 1 );
1881 if( qEnd != std::string::npos )
1882 aPart.
font2 = fl.substr( 1, qEnd - 1 );
1889 for(
int a = 0; a < aPart.
num_attrs && i + 1 < aLines.size(); a++ )
1892 std::istringstream aiss( aLines[i] );
1893 int ax = 0, ay = 0, angle = 0, disp = 0, h = 0, w = 0, vis = 0;
1895 aiss >> ax >> ay >> angle >> disp >> h >> w >> vis;
1909 std::getline( aiss, rest );
1910 size_t qStart = rest.find(
'"' );
1912 if( qStart != std::string::npos )
1914 size_t qEnd = rest.find(
'"', qStart + 1 );
1916 if( qEnd != std::string::npos )
1917 attr.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
1922 if( i < aLines.size() )
1923 attr.
name = aLines[i];
1933 if( !aLines[i].
empty()
1934 && std::isdigit(
static_cast<unsigned char>( aLines[i][0] ) ) )
1939 if( i >= aLines.size() )
1942 const std::string& valLine = aLines[i];
1944 if( valLine.size() > 2 && valLine[0] ==
'"' )
1946 size_t closeQ = valLine.find(
'"', 1 );
1948 if( closeQ != std::string::npos )
1950 std::string attrName = valLine.substr( 1, closeQ - 1 );
1951 std::string attrValue;
1953 if( closeQ + 1 < valLine.size() )
1955 attrValue = valLine.substr( closeQ + 1 );
1956 size_t start = attrValue.find_first_not_of(
" \t" );
1958 if( start != std::string::npos )
1959 attrValue = attrValue.substr( start );
1977 attr.value = it->second;
1981 while( i < aLines.size() )
1983 const std::string& pline = aLines[i];
1992 if( std::isalpha(
static_cast<unsigned char>( pline[0] ) ) )
1996 if( std::isdigit(
static_cast<unsigned char>( pline[0] ) ) )
1999 std::istringstream poiss( pline );
2011 while( i < aLines.size() )
2013 const std::string& attrLine = aLines[i];
2015 if( attrLine.empty() )
2021 if( attrLine[0] ==
'@' )
2024 std::istringstream aiss( attrLine.substr( 1 ) );
2028 std::getline( aiss, rest );
2029 size_t start = rest.find_first_not_of(
" \t" );
2031 if( start != std::string::npos )
2033 rest = rest.substr( start );
2035 if( !rest.empty() && rest[0] ==
'"' )
2037 size_t endQuote = rest.find(
'"', 1 );
2039 if( endQuote != std::string::npos )
2041 attr.
value = rest.substr( 1, endQuote - 1 );
2042 rest = rest.substr( endQuote + 1 );
2047 std::istringstream viss( rest );
2049 std::getline( viss, rest );
2052 std::istringstream piss( rest );
2057 if( piss >> visStr )
2058 attr.
visible = ( visStr !=
"N" && visStr !=
"0" && visStr !=
"H" );
2064 else if( std::isalpha(
static_cast<unsigned char>( attrLine[0] ) ) )
2082 size_t i = aStartLine + 1;
2084 while( i < aLines.size() )
2086 const std::string& line = aLines[i];
2098 if( line.find(
"@@@O" ) == 0 )
2101 std::istringstream iss( line );
2102 std::string idToken;
2106 if( idToken.size() > 4 )
2123 return aLines.size() - 1;
2130 size_t i = aStartLine + 1;
2132 while( i < aLines.size() )
2134 const std::string& line = aLines[i];
2146 if( line.find(
"@@@D" ) == 0 )
2149 std::istringstream iss( line );
2150 std::string idToken;
2153 if( idToken.size() > 4 )
2168 return aLines.size() - 1;
2176 size_t i = aStartLine + 1;
2178 while( i < aLines.size() )
2180 const std::string& line = aLines[i];
2193 if( secName ==
"SIGNAL" )
2198 if( !signal.
name.empty() )
2201 for(
auto& wire : signal.
wires )
2205 for(
const auto& wire : signal.
wires )
2207 for(
const auto& ep : { wire.endpoint_a, wire.endpoint_b } )
2209 if( ep.find(
'.' ) != std::string::npos &&
2210 ep.find(
"@@@" ) == std::string::npos )
2212 size_t dotPos = ep.find(
'.' );
2214 conn.
reference = ep.substr( 0, dotPos );
2223 if( existing.reference == conn.
reference &&
2237 m_signals.push_back( std::move( signal ) );
2252 return aLines.size() - 1;
2259 if( aStartLine >= aLines.size() )
2263 const std::string& headerLine = aLines[aStartLine];
2266 if( secName !=
"SIGNAL" )
2270 size_t afterMarker = headerLine.find(
'*', 1 );
2272 if( afterMarker == std::string::npos )
2275 std::string rest = headerLine.substr( afterMarker + 1 );
2276 std::istringstream iss( rest );
2280 size_t i = aStartLine + 1;
2283 if( aSignal.
flags2 == 1 && i < aLines.size() )
2285 const std::string& funcLine = aLines[i];
2287 if( funcLine.find(
"\"FUNCTION\"" ) != std::string::npos ||
2288 funcLine.find(
"FUNCTION" ) == 0 )
2290 size_t qStart = funcLine.find(
'"' );
2292 if( qStart != std::string::npos )
2294 size_t qEnd = funcLine.find(
'"', qStart + 1 );
2296 if( qEnd != std::string::npos )
2298 size_t afterQ = funcLine.find_first_not_of(
" \t", qEnd + 1 );
2300 if( afterQ != std::string::npos )
2301 aSignal.
function = funcLine.substr( afterQ );
2312 while( i < aLines.size() )
2314 const std::string& line = aLines[i];
2327 std::istringstream wiss( line );
2339 for(
int v = 0; v < wire.
vertex_count && i < aLines.size(); v++ )
2341 const std::string& ptLine = aLines[i];
2347 std::istringstream piss( ptLine );
2348 piss >> pt.
x >> pt.
y;
2360 aSignal.
wires.push_back( wire );
2363 return i > 0 ? i - 1 : aStartLine;
2370 size_t i = aStartLine + 1;
2372 while( i < aLines.size() )
2374 const std::string& line = aLines[i];
2388 std::istringstream iss( line );
2396 std::getline( iss, rest );
2397 size_t qStart = rest.find(
'"' );
2399 if( qStart != std::string::npos )
2401 size_t qEnd = rest.find(
'"', qStart + 1 );
2403 if( qEnd != std::string::npos )
2404 label.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
2411 return aLines.size() - 1;
2418 size_t i = aStartLine + 1;
2420 bool foundFirstBrace =
false;
2422 while( i < aLines.size() )
2424 const std::string& line = aLines[i];
2426 for(
char c : line )
2431 foundFirstBrace =
true;
2439 if( foundFirstBrace && braceDepth <= 0 )
2449 return aLines.size() - 1;
2457 if( sym.name == aName )
2469 if( part.reference == aReference )
2481 if( signal.name == aName )
2493 if( sheets.empty() )
2496 return *sheets.rbegin();
2502 std::set<int> sheets;
2505 sheets.insert(
header.sheet_num );
2508 sheets.insert( part.sheet_number );
2512 for(
const auto& wire : signal.wires )
2513 sheets.insert( wire.sheet_number );
2515 for(
const auto& conn : signal.connections )
2516 sheets.insert( conn.sheet_number );
2519 if( sheets.empty() )
2528 std::vector<SCH_SIGNAL>
result;
2533 filteredSignal.
name = signal.name;
2535 for(
const auto& wire : signal.wires )
2537 if( wire.sheet_number == aSheetNumber )
2538 filteredSignal.
wires.push_back( wire );
2541 for(
const auto& conn : signal.connections )
2543 if( conn.sheet_number == aSheetNumber )
2548 result.push_back( filteredSignal );
2557 std::vector<PART_PLACEMENT>
result;
2561 if( part.sheet_number == aSheetNumber )
2562 result.push_back( part );
2571 std::string upper = aTypeStr;
2572 std::transform( upper.begin(), upper.end(), upper.begin(), ::toupper );
2574 if( upper ==
"I" || upper ==
"IN" || upper ==
"INPUT" || upper ==
"L" )
2577 if( upper ==
"O" || upper ==
"OUT" || upper ==
"OUTPUT" || upper ==
"S" )
2580 if( upper ==
"B" || upper ==
"BI" || upper ==
"BIDIR" || upper ==
"BIDIRECTIONAL" )
2583 if( upper ==
"T" || upper ==
"TRI" || upper ==
"TRISTATE" )
2586 if( upper ==
"OC" || upper ==
"OPENCOLLECTOR" )
2589 if( upper ==
"OE" || upper ==
"OPENEMITTER" )
2592 if( upper ==
"P" || upper ==
"PWR" || upper ==
"POWER" || upper ==
"G" )
2595 if( upper ==
"PAS" || upper ==
"PASSIVE" )
2604 switch( std::toupper( aTypeChar ) )
size_t skipBraceDelimitedSection(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
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)
static bool isNumber(const char *cp, const char *limit)
Return true if the next sequence of text is a number: either an integer, fixed point,...
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.
Common utilities and types for parsing PADS file formats.
std::vector< FAB_LAYER_COLOR > dummy
Attribute label pair from CAEDECAL or PART entries.
Gate definition within a PARTTYPE.
std::vector< std::string > decal_names
std::vector< PARTTYPE_PIN > pins
std::optional< ARC_DATA > arc
Graphical line/shape item from LINES section.
std::vector< TEXT_ITEM > texts
std::vector< SYMBOL_GRAPHIC > primitives
Net name label from NETNAMES section.
Off-page reference from OFFPAGE REFS section.
General schematic parameters from SCH and FIELDS sections.
Part type definition from PARTTYPE section.
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
Pin definition within a PARTTYPE GATE.
Part instance from PART section.
std::string power_net_name
std::map< std::string, std::string > attr_overrides
std::vector< PART_ATTRIBUTE > attributes
std::vector< PIN_OVERRIDE > pin_overrides
Signal (net) definition from CONNECTION and SIGNAL sections.
std::vector< PIN_CONNECTION > connections
std::vector< WIRE_SEGMENT > wires
Symbol definition from CAEDECAL section.
std::vector< SYMBOL_GRAPHIC > graphics
std::vector< SYMBOL_PIN > pins
std::vector< CAEDECAL_ATTR > attrs
std::vector< SYMBOL_TEXT > texts
Graphic primitive from CAEDECAL or LINES sections (OPEN, CLOSED, CIRCLE, COPCLS).
std::vector< GRAPHIC_POINT > points
Pin T/P line pair from CAEDECAL.
Free text item from TEXT section.
Junction dot from TIEDOTS section.
Wire segment connecting two endpoints through coordinate vertices.
std::vector< POINT > vertices
std::vector< std::string > header
wxString result
Test unit parsing edge cases and error handling.