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 );
277 std::regex headerRegex( R
"(PADS-(POWER)?LOGIC-V(\d+\.\d+))" );
280 if( !std::regex_match( headerTag, match, headerRegex ) )
283 if( match[1].matched )
284 m_header.product =
"PADS-POWERLOGIC";
288 m_header.version =
"V" + match[2].str();
290 if( endPos + 1 < aLine.size() )
292 std::string desc = aLine.substr( endPos + 1 );
293 size_t start = desc.find_first_not_of(
' ' );
295 if( start != std::string::npos )
296 m_header.description = desc.substr( start );
305 size_t i = aStartLine + 1;
307 while( i < aLines.size() )
309 const std::string& line = aLines[i];
320 std::istringstream iss( line );
324 if( keyword ==
"UNITS" )
337 else if( keyword ==
"CUR" )
343 if( second ==
"SHEET" )
346 else if( keyword ==
"SHEET" )
352 if( second ==
"SIZE" )
354 std::string sizeCode;
359 if( sizeCode ==
"A" )
364 else if( sizeCode ==
"B" )
369 else if( sizeCode ==
"C" )
374 else if( sizeCode ==
"D" )
379 else if( sizeCode ==
"E" )
386 else if( keyword ==
"USERGRID" )
390 else if( keyword ==
"LINEWIDTH" )
394 else if( keyword ==
"CONNWIDTH" )
398 else if( keyword ==
"BUSWIDTH" )
402 else if( keyword ==
"BUSANGLE" )
406 else if( keyword ==
"TEXTSIZE" )
411 else if( keyword ==
"PINNAMESIZE" )
415 else if( keyword ==
"REFNAMESIZE" )
419 else if( keyword ==
"PARTNAMESIZE" )
423 else if( keyword ==
"PINNOSIZE" )
427 else if( keyword ==
"NETNAMESIZE" )
431 else if( keyword ==
"DOTGRID" )
435 else if( keyword ==
"TIEDOTSIZE" )
439 else if( keyword ==
"REAL" )
445 if( second ==
"WIDTH" )
448 else if( keyword ==
"FONT" )
454 if( second ==
"MODE" )
457 else if( keyword ==
"DEFAULT" )
463 if( second ==
"FONT" )
466 std::getline( iss, rest );
467 size_t start = rest.find(
'"' );
469 if( start != std::string::npos )
471 size_t end = rest.find(
'"', start + 1 );
473 if(
end != std::string::npos )
478 else if( keyword ==
"BORDER" )
484 if( second ==
"NAME" )
496 else if( keyword ==
"JOBNAME" )
499 std::getline( iss, rest );
500 size_t start = rest.find_first_not_of(
" \t" );
502 if( start != std::string::npos )
504 rest = rest.substr( start );
506 if( rest.size() >= 2 && rest.front() ==
'"' && rest.back() ==
'"' )
507 rest = rest.substr( 1, rest.size() - 2 );
513 else if( keyword ==
"NTXCOL" || keyword ==
"HIRCOL" || keyword ==
"LINCOL" ||
514 keyword ==
"TXTCOL" || keyword ==
"CONCOL" || keyword ==
"BUSCOL" ||
515 keyword ==
"PTXCOL" || keyword ==
"COMCOL" || keyword ==
"NMCOL" ||
516 keyword ==
"PNMCOL" || keyword ==
"PINCOL" || keyword ==
"NETCOL" ||
517 keyword ==
"FBGCOL" || keyword ==
"FIELDCOL" ||
518 keyword ==
"NNVISPWRGND" || keyword ==
"PCBFLAGS" ||
519 keyword ==
"JOBTIME" || keyword ==
"BACKUPTIME" ||
520 keyword ==
"OFFREFVIEW" || keyword ==
"OFFREFNUM" ||
521 keyword ==
"SHEETNUMSEP" )
529 return aLines.size() - 1;
535 size_t i = aStartLine + 1;
537 while( i < aLines.size() )
539 const std::string& line = aLines[i];
544 if( line.empty() || line[0] !=
'"' )
551 size_t closeQuote = line.find(
'"', 1 );
553 if( closeQuote != std::string::npos )
555 std::string fieldName = line.substr( 1, closeQuote - 1 );
556 std::string fieldValue;
558 if( closeQuote + 1 < line.size() )
560 fieldValue = line.substr( closeQuote + 1 );
561 size_t start = fieldValue.find_first_not_of(
" \t" );
563 if( start != std::string::npos )
564 fieldValue = fieldValue.substr( start );
575 return aLines.size() - 1;
582 const std::string& line = aLines[aStartLine];
583 std::string afterMarker = line.substr( line.find(
'*', 1 ) + 1 );
585 std::istringstream iss( afterMarker );
600 size_t i = aStartLine + 1;
602 while( i < aLines.size() )
604 const std::string& line = aLines[i];
612 return aLines.size() - 1;
618 size_t i = aStartLine + 1;
620 while( i < aLines.size() )
622 const std::string& line = aLines[i];
635 std::istringstream iss( line );
646 std::getline( iss, rest );
647 size_t qStart = rest.find(
'"' );
649 if( qStart != std::string::npos )
651 size_t qEnd = rest.find(
'"', qStart + 1 );
653 if( qEnd != std::string::npos )
654 item.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
660 if( i < aLines.size() )
667 return aLines.size() - 1;
673 size_t i = aStartLine + 1;
675 while( i < aLines.size() )
677 const std::string& line = aLines[i];
689 if( line.find(
"LINES" ) != std::string::npos )
692 std::istringstream iss( line );
693 std::string
name, keyword;
698 if( keyword ==
"LINES" )
707 while( i < aLines.size() )
709 const std::string& pline = aLines[i];
721 if( pline.find(
"LINES" ) != std::string::npos )
723 std::istringstream tiss( pline );
724 std::string tname, tkw;
725 tiss >> tname >> tkw;
731 std::istringstream piss( pline );
732 std::string firstToken;
735 if( firstToken ==
"OPEN" || firstToken ==
"CLOSED" ||
736 firstToken ==
"CIRCLE" || firstToken ==
"COPCLS" )
748 && ( std::isdigit( firstToken[0] )
749 || firstToken[0] ==
'-'
750 || firstToken[0] ==
'+' );
752 if(
isNumber && pline.find(
'"' ) != std::string::npos )
756 std::istringstream tiss( pline );
759 tiss >> tx >> ty >>
text.rotation >>
text.justification >>
text.height
760 >>
text.width_factor;
762 text.position.x = tx;
763 text.position.y = ty;
766 std::getline( tiss, trest );
767 size_t qStart = trest.find(
'"' );
769 if( qStart != std::string::npos )
771 size_t qEnd = trest.find(
'"', qStart + 1 );
773 if( qEnd != std::string::npos )
774 text.font_name = trest.substr( qStart + 1, qEnd - qStart - 1 );
779 if( i < aLines.size() )
780 text.content = aLines[i];
796 return aLines.size() - 1;
803 size_t i = aStartLine + 1;
805 while( i < aLines.size() )
807 const std::string& line = aLines[i];
822 if( !symbol.
name.empty() )
831 std::map<std::string, double> pinDecalLengths;
835 if( !sym.is_pin_decal )
838 for(
const auto& graphic : sym.graphics )
843 if( graphic.points.size() < 2 )
846 const auto& first = graphic.points.front().coord;
847 const auto& last = graphic.points.back().coord;
848 double dx = last.x - first.x;
849 double dy = last.y - first.y;
850 pinDecalLengths[sym.name] = std::sqrt( dx * dx + dy * dy );
857 if( sym.is_pin_decal )
860 for(
auto&
pin : sym.pins )
862 if(
pin.pin_decal_name.empty() )
865 auto it = pinDecalLengths.find(
pin.pin_decal_name );
867 if( it != pinDecalLengths.end() )
868 pin.length = it->second;
872 return i > 0 ? i - 1 : aLines.size() - 1;
879 if( aStartLine >= aLines.size() )
882 const std::string& headerLine = aLines[aStartLine];
886 std::istringstream iss( headerLine );
896 std::vector<std::string> tokens;
899 while( iss >> token )
900 tokens.push_back( token );
902 if( tokens.size() >= 12 )
921 if( tokens.size() >= 3 )
933 size_t idx = aStartLine + 1;
935 for(
int p = 0; p < aSymbol.
num_pieces && idx < aLines.size(); p++ )
937 const std::string& gline = aLines[idx];
943 std::istringstream giss( gline );
947 if( typeStr ==
"OPEN" || typeStr ==
"LINE" )
951 giss >> p1.
x >> p1.
y >> p2.
x >> p2.
y;
952 graphic.
points.push_back( { p1, std::nullopt } );
953 graphic.
points.push_back( { p2, std::nullopt } );
956 else if( typeStr ==
"CLOSED" || typeStr ==
"RECT" )
960 giss >> p1.
x >> p1.
y >> p2.
x >> p2.
y;
961 graphic.
points.push_back( { p1, std::nullopt } );
962 graphic.
points.push_back( { p2, std::nullopt } );
965 else if( typeStr ==
"CIRCLE" )
972 aSymbol.
graphics.push_back( graphic );
976 for(
int p = 0; p < aSymbol.
num_pins && idx < aLines.size(); p++ )
978 const std::string& pline = aLines[idx];
984 std::istringstream piss( pline );
985 double orientation = 0;
987 piss >>
pin.position.x >>
pin.position.y >> orientation >>
pin.length;
988 piss >>
pin.number >>
pin.name;
990 pin.rotation = orientation;
994 if( piss >> typeStr )
1005 size_t idx = aStartLine + 1;
1008 if( idx < aLines.size() && aLines[idx].find(
"TIMESTAMP" ) == 0 )
1010 std::istringstream tiss( aLines[idx] );
1017 if( idx < aLines.size() && aLines[idx].size() >= 2 && aLines[idx][0] ==
'"' )
1019 size_t qEnd = aLines[idx].find(
'"', 1 );
1021 if( qEnd != std::string::npos )
1022 aSymbol.
font1 = aLines[idx].substr( 1, qEnd - 1 );
1027 if( idx < aLines.size() && aLines[idx].size() >= 2 && aLines[idx][0] ==
'"' )
1029 size_t qEnd = aLines[idx].find(
'"', 1 );
1031 if( qEnd != std::string::npos )
1032 aSymbol.
font2 = aLines[idx].substr( 1, qEnd - 1 );
1038 for(
int a = 0; a < aSymbol.
num_attrs && idx + 1 < aLines.size(); a++ )
1041 std::istringstream aiss( aLines[idx] );
1050 std::getline( aiss, rest );
1051 size_t qStart = rest.find(
'"' );
1053 if( qStart != std::string::npos )
1055 size_t qEnd = rest.find(
'"', qStart + 1 );
1057 if( qEnd != std::string::npos )
1058 attr.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
1063 if( idx < aLines.size() )
1066 aSymbol.
attrs.push_back( attr );
1071 for(
int p = 0; p < aSymbol.
num_pieces && idx < aLines.size(); p++ )
1073 if( aLines[idx].
empty() )
1082 aSymbol.
graphics.push_back( graphic );
1089 while( idx < aLines.size() )
1091 const std::string& tline = aLines[idx];
1100 if( tline.size() > 1 && tline[0] ==
'T' &&
1101 ( std::isdigit(
static_cast<unsigned char>( tline[1] ) ) || tline[1] ==
'-' ) )
1108 std::istringstream tiss( tline );
1111 tiss >> tx >> ty >>
text.rotation >>
text.justification;
1113 int height = 0, width = 0;
1114 tiss >> height >> width;
1116 text.width_factor = width;
1118 text.position.x = tx;
1119 text.position.y = ty;
1123 if( idx < aLines.size() )
1125 text.content = aLines[idx];
1133 for(
int p = 0; p < aSymbol.
num_pins && idx < aLines.size(); p++ )
1135 const std::string& tLine = aLines[idx];
1151 if( tLine.size() > 1 && tLine[0] ==
'T' )
1154 std::string tContent = tLine.substr( 1 );
1155 std::istringstream tiss( tContent );
1156 int tx = 0, ty = 0, angle = 0;
1158 tiss >> tx >> ty >> angle >>
pin.side >>
pin.pn_h >>
pin.pn_w >>
pin.pn_angle
1160 >>
pin.pin_decal_name;
1162 pin.position.x = tx;
1163 pin.position.y = ty;
1164 pin.rotation = angle;
1167 if(
pin.pin_decal_name ==
"PINB" ||
pin.pin_decal_name ==
"PINORB" ||
1168 pin.pin_decal_name ==
"PCLKB" ||
pin.pin_decal_name ==
"PINIEB" ||
1169 pin.pin_decal_name ==
"PINCLKB" )
1171 pin.inverted =
true;
1174 if(
pin.pin_decal_name ==
"PCLK" ||
pin.pin_decal_name ==
"PCLKB" ||
1175 pin.pin_decal_name ==
"PINCLK" ||
pin.pin_decal_name ==
"PINCLKB" )
1183 if(
pin.pin_decal_name.empty() )
1185 else if(
pin.pin_decal_name.find(
"SHORT" ) != std::string::npos )
1187 else if(
pin.pin_decal_name.find(
"LONG" ) != std::string::npos )
1194 if( idx < aLines.size() )
1196 const std::string& pLine = aLines[idx];
1198 if( pLine.size() > 1 && pLine[0] ==
'P' )
1200 std::string pContent = pLine.substr( 1 );
1201 std::istringstream piss( pContent );
1202 int px1 = 0, py1 = 0, px2 = 0, py2 = 0;
1204 piss >> px1 >> py1 >>
pin.pn_off_angle >>
pin.pn_off_just
1205 >> px2 >> py2 >>
pin.pl_off_angle >>
pin.pl_off_just >>
pin.p_flags;
1207 pin.pn_offset.x = px1;
1208 pin.pn_offset.y = py1;
1209 pin.pl_offset.x = px2;
1210 pin.pl_offset.y = py2;
1213 if(
pin.p_flags & 128 )
1222 pin.number = std::to_string( p + 1 );
1224 aSymbol.
pins.push_back(
pin );
1227 return idx > 0 ? idx - 1 : 0;
1234 if( aStartLine >= aLines.size() )
1237 const std::string& headerLine = aLines[aStartLine];
1238 std::istringstream iss( headerLine );
1239 std::string typeStr;
1240 int pointCount = 0, lineWidth = 0, lineStyle = 255;
1242 iss >> typeStr >> pointCount >> lineWidth >> lineStyle;
1247 if( typeStr ==
"OPEN" )
1252 else if( typeStr ==
"CLOSED" )
1257 else if( typeStr ==
"CIRCLE" )
1262 else if( typeStr ==
"COPCLS" )
1269 size_t idx = aStartLine + 1;
1271 for(
int p = 0; p < pointCount && idx < aLines.size(); p++ )
1273 const std::string& ptLine = aLines[idx];
1278 std::istringstream piss( ptLine );
1282 std::vector<std::string> extraTokens;
1285 while( piss >> tok )
1286 extraTokens.push_back( tok );
1288 if( extraTokens.size() >= 6 )
1300 aGraphic.
points.push_back( gpt );
1310 std::set<double> uniqueX, uniqueY;
1312 for(
const auto& pt : aGraphic.
points )
1314 uniqueX.insert( pt.coord.x );
1315 uniqueY.insert( pt.coord.y );
1318 bool isRect = ( uniqueX.size() == 2 && uniqueY.size() == 2 );
1322 double minX = *uniqueX.begin();
1323 double maxX = *uniqueX.rbegin();
1324 double minY = *uniqueY.begin();
1325 double maxY = *uniqueY.rbegin();
1328 aGraphic.
points.push_back( { { minX, minY }, std::nullopt } );
1329 aGraphic.
points.push_back( { { maxX, maxY }, std::nullopt } );
1342 double dx = aGraphic.
points[1].coord.x - aGraphic.
points[0].coord.x;
1343 double dy = aGraphic.
points[1].coord.y - aGraphic.
points[0].coord.y;
1344 aGraphic.
radius = std::sqrt( dx * dx + dy * dy ) / 2.0;
1347 return idx > 0 ? idx - 1 : aStartLine;
1354 size_t i = aStartLine + 1;
1356 while( i < aLines.size() )
1358 const std::string& line = aLines[i];
1371 std::istringstream iss( line );
1375 if( pt.
name.empty() )
1384 if( i < aLines.size() && aLines[i].find(
"TIMESTAMP" ) == 0 )
1386 std::istringstream tiss( aLines[i] );
1393 bool isSpecial = ( pt.
name ==
"$GND_SYMS" || pt.
name ==
"$PWR_SYMS" ||
1394 pt.
name ==
"$OSR_SYMS" );
1399 bool isV52Gates = ( i < aLines.size() && aLines[i].size() >= 3
1400 && aLines[i][0] ==
'G' && aLines[i][1] ==
':' );
1402 if( isSpecial && !isV52Gates )
1405 if( i < aLines.size() )
1407 std::istringstream siss( aLines[i] );
1408 int numVariants = 0;
1412 for(
int v = 0; v < numVariants && i < aLines.size(); v++ )
1415 std::istringstream viss( aLines[i] );
1428 else if( i < aLines.size() )
1432 if( pt.
name ==
"$GND_SYMS" )
1434 else if( pt.
name ==
"$PWR_SYMS" )
1441 while( i < aLines.size() )
1443 const std::string& gline = aLines[i];
1454 std::istringstream giss( gline );
1455 std::string keyword;
1458 if( keyword ==
"GATE" )
1475 for(
int p = 0; p < gate.
num_pins && i < aLines.size(); p++ )
1481 std::istringstream piss( aLines[i] );
1482 std::string pinType;
1484 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1486 if( !pinType.empty() )
1487 pin.pin_type = pinType[0];
1489 std::string pinName;
1491 if( piss >> pinName )
1492 pin.pin_name = pinName;
1498 pt.
gates.push_back( gate );
1501 else if( keyword.size() >= 3 && keyword[0] ==
'G' && keyword[1] ==
':' )
1510 std::string decalStr = keyword.substr( 2 );
1511 std::istringstream diss( decalStr );
1512 std::string decalName;
1514 while( std::getline( diss, decalName,
':' ) )
1516 if( !decalName.empty() )
1526 while( pinsRead < gate.
num_pins && i < aLines.size() )
1528 const std::string& pline = aLines[i];
1533 if( ( pline[0] ==
'G' && pline.size() >= 2 && pline[1] ==
':' )
1534 || pline.find(
"SIGPIN" ) == 0 )
1539 std::istringstream piss( pline );
1540 std::string pinToken;
1542 while( piss >> pinToken && pinsRead < gate.
num_pins )
1545 std::vector<std::string> fields;
1546 std::istringstream fiss( pinToken );
1549 while( std::getline( fiss, field,
'.' ) )
1550 fields.push_back( field );
1552 if( fields.size() >= 1 )
1553 pin.pin_id = fields[0];
1555 if( fields.size() >= 2 )
1561 if( fields.size() >= 3 && !fields[2].empty() )
1562 pin.pin_type = fields[2][0];
1564 if( fields.size() >= 4 )
1565 pin.pin_name = fields[3];
1580 if( !gate.
pins.empty() )
1586 pt.
gates.push_back( gate );
1589 else if( keyword ==
"CONN" )
1604 std::istringstream diss( aLines[i] );
1605 std::string decalName, pinType;
1606 diss >> decalName >> pinType;
1612 for(
int p = 0; p < numPins && i < aLines.size(); p++ )
1618 std::istringstream piss( aLines[i] );
1619 std::string pinType;
1621 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1623 if( !pinType.empty() )
1624 pin.pin_type = pinType[0];
1630 pt.
gates.push_back( gate );
1633 else if( keyword ==
"SIGPIN" )
1641 if( token.find(
'.' ) != std::string::npos )
1643 std::vector<std::string> fields;
1644 std::istringstream fiss( token );
1647 while( std::getline( fiss, field,
'.' ) )
1648 fields.push_back( field );
1650 if( fields.size() >= 1 )
1653 if( fields.size() >= 3 )
1679 return aLines.size() - 1;
1686 size_t i = aStartLine + 1;
1689 while( i < aLines.size() && aLines[i].empty() )
1692 while( i < aLines.size() )
1694 const std::string& line = aLines[i];
1706 if( std::isalpha(
static_cast<unsigned char>( line[0] ) ) )
1724 return aLines.size() - 1;
1731 if( aStartLine >= aLines.size() )
1734 const std::string& headerLine = aLines[aStartLine];
1735 std::istringstream iss( headerLine );
1741 std::string refdes, partType;
1742 int x = 0, y = 0, angleCode = 0, mirrorFlag = 0;
1744 iss >> refdes >> partType;
1750 std::string actualPartType;
1751 iss >> actualPartType >> x >> y >> angleCode >> mirrorFlag;
1754 partType = actualPartType;
1758 iss >> y >> angleCode >> mirrorFlag;
1769 case 0: aPart.
rotation = 0.0;
break;
1770 case 1: aPart.
rotation = 90.0;
break;
1771 case 2: aPart.
rotation = 180.0;
break;
1772 case 3: aPart.
rotation = 270.0;
break;
1773 default: aPart.
rotation = angleCode;
break;
1783 if( iss >> variantIdx )
1789 int numAttrs = 0, numDisplayedValues = 0, numPins = 0, unused1 = 0, gateIdx = 0;
1792 if( iss >> aPart.
h1 >> aPart.
w1 >> aPart.
h2 >> aPart.
w2 >> numAttrs >> numDisplayedValues
1793 >> numPins >> unused1 >> gateIdx >> unused2 )
1804 std::istringstream iss2( headerLine );
1812 std::string mirrorStr;
1814 if( iss2 >> mirrorStr )
1816 if( mirrorStr ==
"M" || mirrorStr ==
"Y" || mirrorStr ==
"1" )
1826 size_t sepPos = refdes.rfind(
'-' );
1828 if( sepPos == std::string::npos )
1829 sepPos = refdes.rfind(
'.' );
1831 if( sepPos != std::string::npos && sepPos + 1 < refdes.size() )
1833 char gateLetter = refdes[sepPos + 1];
1835 if( std::isalpha(
static_cast<unsigned char>( gateLetter ) ) )
1840 aPart.
gate_index = std::toupper(
static_cast<unsigned char>( gateLetter ) ) -
'A';
1846 size_t i = aStartLine + 1;
1852 if( i < aLines.size() )
1854 const std::string& fl = aLines[i];
1856 if( fl.size() >= 2 && fl[0] ==
'"' )
1858 size_t qEnd = fl.find(
'"', 1 );
1860 if( qEnd != std::string::npos )
1861 aPart.
font1 = fl.substr( 1, qEnd - 1 );
1867 if( i < aLines.size() )
1869 const std::string& fl = aLines[i];
1871 if( fl.size() >= 2 && fl[0] ==
'"' )
1873 size_t qEnd = fl.find(
'"', 1 );
1875 if( qEnd != std::string::npos )
1876 aPart.
font2 = fl.substr( 1, qEnd - 1 );
1883 for(
int a = 0; a < aPart.
num_attrs && i + 1 < aLines.size(); a++ )
1886 std::istringstream aiss( aLines[i] );
1887 int ax = 0, ay = 0, angle = 0, disp = 0, h = 0, w = 0, vis = 0;
1889 aiss >> ax >> ay >> angle >> disp >> h >> w >> vis;
1903 std::getline( aiss, rest );
1904 size_t qStart = rest.find(
'"' );
1906 if( qStart != std::string::npos )
1908 size_t qEnd = rest.find(
'"', qStart + 1 );
1910 if( qEnd != std::string::npos )
1911 attr.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
1916 if( i < aLines.size() )
1917 attr.
name = aLines[i];
1927 if( !aLines[i].
empty()
1928 && std::isdigit(
static_cast<unsigned char>( aLines[i][0] ) ) )
1933 if( i >= aLines.size() )
1936 const std::string& valLine = aLines[i];
1938 if( valLine.size() > 2 && valLine[0] ==
'"' )
1940 size_t closeQ = valLine.find(
'"', 1 );
1942 if( closeQ != std::string::npos )
1944 std::string attrName = valLine.substr( 1, closeQ - 1 );
1945 std::string attrValue;
1947 if( closeQ + 1 < valLine.size() )
1949 attrValue = valLine.substr( closeQ + 1 );
1950 size_t start = attrValue.find_first_not_of(
" \t" );
1952 if( start != std::string::npos )
1953 attrValue = attrValue.substr( start );
1971 attr.value = it->second;
1975 while( i < aLines.size() )
1977 const std::string& pline = aLines[i];
1986 if( std::isalpha(
static_cast<unsigned char>( pline[0] ) ) )
1990 if( std::isdigit(
static_cast<unsigned char>( pline[0] ) ) )
1993 std::istringstream poiss( pline );
2005 while( i < aLines.size() )
2007 const std::string& attrLine = aLines[i];
2009 if( attrLine.empty() )
2015 if( attrLine[0] ==
'@' )
2018 std::istringstream aiss( attrLine.substr( 1 ) );
2022 std::getline( aiss, rest );
2023 size_t start = rest.find_first_not_of(
" \t" );
2025 if( start != std::string::npos )
2027 rest = rest.substr( start );
2029 if( !rest.empty() && rest[0] ==
'"' )
2031 size_t endQuote = rest.find(
'"', 1 );
2033 if( endQuote != std::string::npos )
2035 attr.
value = rest.substr( 1, endQuote - 1 );
2036 rest = rest.substr( endQuote + 1 );
2041 std::istringstream viss( rest );
2043 std::getline( viss, rest );
2046 std::istringstream piss( rest );
2051 if( piss >> visStr )
2052 attr.
visible = ( visStr !=
"N" && visStr !=
"0" && visStr !=
"H" );
2058 else if( std::isalpha(
static_cast<unsigned char>( attrLine[0] ) ) )
2076 size_t i = aStartLine + 1;
2078 while( i < aLines.size() )
2080 const std::string& line = aLines[i];
2092 if( line.find(
"@@@O" ) == 0 )
2095 std::istringstream iss( line );
2096 std::string idToken;
2100 if( idToken.size() > 4 )
2117 return aLines.size() - 1;
2124 size_t i = aStartLine + 1;
2126 while( i < aLines.size() )
2128 const std::string& line = aLines[i];
2140 if( line.find(
"@@@D" ) == 0 )
2143 std::istringstream iss( line );
2144 std::string idToken;
2147 if( idToken.size() > 4 )
2162 return aLines.size() - 1;
2170 size_t i = aStartLine + 1;
2172 while( i < aLines.size() )
2174 const std::string& line = aLines[i];
2187 if( secName ==
"SIGNAL" )
2192 if( !signal.
name.empty() )
2195 for(
auto& wire : signal.
wires )
2199 for(
const auto& wire : signal.
wires )
2201 for(
const auto& ep : { wire.endpoint_a, wire.endpoint_b } )
2203 if( ep.find(
'.' ) != std::string::npos &&
2204 ep.find(
"@@@" ) == std::string::npos )
2206 size_t dotPos = ep.find(
'.' );
2208 conn.
reference = ep.substr( 0, dotPos );
2217 if( existing.reference == conn.
reference &&
2231 m_signals.push_back( std::move( signal ) );
2246 return aLines.size() - 1;
2253 if( aStartLine >= aLines.size() )
2257 const std::string& headerLine = aLines[aStartLine];
2260 if( secName !=
"SIGNAL" )
2264 size_t afterMarker = headerLine.find(
'*', 1 );
2266 if( afterMarker == std::string::npos )
2269 std::string rest = headerLine.substr( afterMarker + 1 );
2270 std::istringstream iss( rest );
2274 size_t i = aStartLine + 1;
2277 if( aSignal.
flags2 == 1 && i < aLines.size() )
2279 const std::string& funcLine = aLines[i];
2281 if( funcLine.find(
"\"FUNCTION\"" ) != std::string::npos ||
2282 funcLine.find(
"FUNCTION" ) == 0 )
2284 size_t qStart = funcLine.find(
'"' );
2286 if( qStart != std::string::npos )
2288 size_t qEnd = funcLine.find(
'"', qStart + 1 );
2290 if( qEnd != std::string::npos )
2292 size_t afterQ = funcLine.find_first_not_of(
" \t", qEnd + 1 );
2294 if( afterQ != std::string::npos )
2295 aSignal.
function = funcLine.substr( afterQ );
2306 while( i < aLines.size() )
2308 const std::string& line = aLines[i];
2321 std::istringstream wiss( line );
2333 for(
int v = 0; v < wire.
vertex_count && i < aLines.size(); v++ )
2335 const std::string& ptLine = aLines[i];
2341 std::istringstream piss( ptLine );
2342 piss >> pt.
x >> pt.
y;
2354 aSignal.
wires.push_back( wire );
2357 return i > 0 ? i - 1 : aStartLine;
2364 size_t i = aStartLine + 1;
2366 while( i < aLines.size() )
2368 const std::string& line = aLines[i];
2382 std::istringstream iss( line );
2390 std::getline( iss, rest );
2391 size_t qStart = rest.find(
'"' );
2393 if( qStart != std::string::npos )
2395 size_t qEnd = rest.find(
'"', qStart + 1 );
2397 if( qEnd != std::string::npos )
2398 label.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
2405 return aLines.size() - 1;
2412 size_t i = aStartLine + 1;
2414 bool foundFirstBrace =
false;
2416 while( i < aLines.size() )
2418 const std::string& line = aLines[i];
2420 for(
char c : line )
2425 foundFirstBrace =
true;
2433 if( foundFirstBrace && braceDepth <= 0 )
2443 return aLines.size() - 1;
2451 if( sym.name == aName )
2463 if( part.reference == aReference )
2475 if( signal.name == aName )
2487 if( sheets.empty() )
2490 return *sheets.rbegin();
2496 std::set<int> sheets;
2499 sheets.insert( header.sheet_num );
2502 sheets.insert( part.sheet_number );
2506 for(
const auto& wire : signal.wires )
2507 sheets.insert( wire.sheet_number );
2509 for(
const auto& conn : signal.connections )
2510 sheets.insert( conn.sheet_number );
2513 if( sheets.empty() )
2522 std::vector<SCH_SIGNAL>
result;
2527 filteredSignal.
name = signal.name;
2529 for(
const auto& wire : signal.wires )
2531 if( wire.sheet_number == aSheetNumber )
2532 filteredSignal.
wires.push_back( wire );
2535 for(
const auto& conn : signal.connections )
2537 if( conn.sheet_number == aSheetNumber )
2542 result.push_back( filteredSignal );
2551 std::vector<PART_PLACEMENT>
result;
2555 if( part.sheet_number == aSheetNumber )
2556 result.push_back( part );
2565 std::string upper = aTypeStr;
2566 std::transform( upper.begin(), upper.end(), upper.begin(), ::toupper );
2568 if( upper ==
"I" || upper ==
"IN" || upper ==
"INPUT" || upper ==
"L" )
2571 if( upper ==
"O" || upper ==
"OUT" || upper ==
"OUTPUT" || upper ==
"S" )
2574 if( upper ==
"B" || upper ==
"BI" || upper ==
"BIDIR" || upper ==
"BIDIRECTIONAL" )
2577 if( upper ==
"T" || upper ==
"TRI" || upper ==
"TRISTATE" )
2580 if( upper ==
"OC" || upper ==
"OPENCOLLECTOR" )
2583 if( upper ==
"OE" || upper ==
"OPENEMITTER" )
2586 if( upper ==
"P" || upper ==
"PWR" || upper ==
"POWER" || upper ==
"G" )
2589 if( upper ==
"PAS" || upper ==
"PASSIVE" )
2598 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
wxString result
Test unit parsing edge cases and error handling.