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 if( i < aLines.size() )
1401 std::istringstream siss( aLines[i] );
1402 int numVariants = 0;
1406 for(
int v = 0; v < numVariants && i < aLines.size(); v++ )
1409 std::istringstream viss( aLines[i] );
1422 else if( i < aLines.size() )
1425 while( i < aLines.size() )
1427 const std::string& gline = aLines[i];
1438 std::istringstream giss( gline );
1439 std::string keyword;
1442 if( keyword ==
"GATE" )
1459 for(
int p = 0; p < gate.
num_pins && i < aLines.size(); p++ )
1465 std::istringstream piss( aLines[i] );
1466 std::string pinType;
1468 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1470 if( !pinType.empty() )
1471 pin.pin_type = pinType[0];
1473 std::string pinName;
1475 if( piss >> pinName )
1476 pin.pin_name = pinName;
1482 pt.
gates.push_back( gate );
1485 else if( keyword ==
"CONN" )
1500 std::istringstream diss( aLines[i] );
1501 std::string decalName, pinType;
1502 diss >> decalName >> pinType;
1508 for(
int p = 0; p < numPins && i < aLines.size(); p++ )
1514 std::istringstream piss( aLines[i] );
1515 std::string pinType;
1517 piss >>
pin.pin_id >>
pin.swap_group >> pinType;
1519 if( !pinType.empty() )
1520 pin.pin_type = pinType[0];
1526 pt.
gates.push_back( gate );
1529 else if( keyword ==
"SIGPIN" )
1550 return aLines.size() - 1;
1557 size_t i = aStartLine + 1;
1560 while( i < aLines.size() && aLines[i].empty() )
1563 while( i < aLines.size() )
1565 const std::string& line = aLines[i];
1577 if( std::isalpha(
static_cast<unsigned char>( line[0] ) ) )
1595 return aLines.size() - 1;
1602 if( aStartLine >= aLines.size() )
1605 const std::string& headerLine = aLines[aStartLine];
1606 std::istringstream iss( headerLine );
1612 std::string refdes, partType;
1613 int x = 0, y = 0, angleCode = 0, mirrorFlag = 0;
1615 iss >> refdes >> partType;
1621 std::string actualPartType;
1622 iss >> actualPartType >> x >> y >> angleCode >> mirrorFlag;
1625 partType = actualPartType;
1629 iss >> y >> angleCode >> mirrorFlag;
1640 case 0: aPart.
rotation = 0.0;
break;
1641 case 1: aPart.
rotation = 90.0;
break;
1642 case 2: aPart.
rotation = 180.0;
break;
1643 case 3: aPart.
rotation = 270.0;
break;
1644 default: aPart.
rotation = angleCode;
break;
1654 if( iss >> variantIdx )
1660 int numAttrs = 0, numDisplayedValues = 0, numPins = 0, unused1 = 0, gateIdx = 0;
1663 if( iss >> aPart.
h1 >> aPart.
w1 >> aPart.
h2 >> aPart.
w2 >> numAttrs >> numDisplayedValues
1664 >> numPins >> unused1 >> gateIdx >> unused2 )
1675 std::istringstream iss2( headerLine );
1683 std::string mirrorStr;
1685 if( iss2 >> mirrorStr )
1687 if( mirrorStr ==
"M" || mirrorStr ==
"Y" || mirrorStr ==
"1" )
1697 size_t sepPos = refdes.rfind(
'-' );
1699 if( sepPos == std::string::npos )
1700 sepPos = refdes.rfind(
'.' );
1702 if( sepPos != std::string::npos && sepPos + 1 < refdes.size() )
1704 char gateLetter = refdes[sepPos + 1];
1706 if( std::isalpha(
static_cast<unsigned char>( gateLetter ) ) )
1711 aPart.
gate_index = std::toupper(
static_cast<unsigned char>( gateLetter ) ) -
'A';
1717 size_t i = aStartLine + 1;
1723 if( i < aLines.size() )
1725 const std::string& fl = aLines[i];
1727 if( fl.size() >= 2 && fl[0] ==
'"' )
1729 size_t qEnd = fl.find(
'"', 1 );
1731 if( qEnd != std::string::npos )
1732 aPart.
font1 = fl.substr( 1, qEnd - 1 );
1738 if( i < aLines.size() )
1740 const std::string& fl = aLines[i];
1742 if( fl.size() >= 2 && fl[0] ==
'"' )
1744 size_t qEnd = fl.find(
'"', 1 );
1746 if( qEnd != std::string::npos )
1747 aPart.
font2 = fl.substr( 1, qEnd - 1 );
1754 for(
int a = 0; a < aPart.
num_attrs && i + 1 < aLines.size(); a++ )
1757 std::istringstream aiss( aLines[i] );
1758 int ax = 0, ay = 0, angle = 0, disp = 0, h = 0, w = 0, vis = 0;
1760 aiss >> ax >> ay >> angle >> disp >> h >> w >> vis;
1774 std::getline( aiss, rest );
1775 size_t qStart = rest.find(
'"' );
1777 if( qStart != std::string::npos )
1779 size_t qEnd = rest.find(
'"', qStart + 1 );
1781 if( qEnd != std::string::npos )
1782 attr.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
1787 if( i < aLines.size() )
1788 attr.
name = aLines[i];
1798 if( !aLines[i].
empty()
1799 && std::isdigit(
static_cast<unsigned char>( aLines[i][0] ) ) )
1804 if( i >= aLines.size() )
1807 const std::string& valLine = aLines[i];
1809 if( valLine.size() > 2 && valLine[0] ==
'"' )
1811 size_t closeQ = valLine.find(
'"', 1 );
1813 if( closeQ != std::string::npos )
1815 std::string attrName = valLine.substr( 1, closeQ - 1 );
1816 std::string attrValue;
1818 if( closeQ + 1 < valLine.size() )
1820 attrValue = valLine.substr( closeQ + 1 );
1821 size_t start = attrValue.find_first_not_of(
" \t" );
1823 if( start != std::string::npos )
1824 attrValue = attrValue.substr( start );
1842 attr.value = it->second;
1846 while( i < aLines.size() )
1848 const std::string& pline = aLines[i];
1857 if( std::isalpha(
static_cast<unsigned char>( pline[0] ) ) )
1861 if( std::isdigit(
static_cast<unsigned char>( pline[0] ) ) )
1864 std::istringstream poiss( pline );
1876 while( i < aLines.size() )
1878 const std::string& attrLine = aLines[i];
1880 if( attrLine.empty() )
1886 if( attrLine[0] ==
'@' )
1889 std::istringstream aiss( attrLine.substr( 1 ) );
1893 std::getline( aiss, rest );
1894 size_t start = rest.find_first_not_of(
" \t" );
1896 if( start != std::string::npos )
1898 rest = rest.substr( start );
1900 if( !rest.empty() && rest[0] ==
'"' )
1902 size_t endQuote = rest.find(
'"', 1 );
1904 if( endQuote != std::string::npos )
1906 attr.
value = rest.substr( 1, endQuote - 1 );
1907 rest = rest.substr( endQuote + 1 );
1912 std::istringstream viss( rest );
1914 std::getline( viss, rest );
1917 std::istringstream piss( rest );
1922 if( piss >> visStr )
1923 attr.
visible = ( visStr !=
"N" && visStr !=
"0" && visStr !=
"H" );
1929 else if( std::isalpha(
static_cast<unsigned char>( attrLine[0] ) ) )
1947 size_t i = aStartLine + 1;
1949 while( i < aLines.size() )
1951 const std::string& line = aLines[i];
1963 if( line.find(
"@@@O" ) == 0 )
1966 std::istringstream iss( line );
1967 std::string idToken;
1971 if( idToken.size() > 4 )
1988 return aLines.size() - 1;
1995 size_t i = aStartLine + 1;
1997 while( i < aLines.size() )
1999 const std::string& line = aLines[i];
2011 if( line.find(
"@@@D" ) == 0 )
2014 std::istringstream iss( line );
2015 std::string idToken;
2018 if( idToken.size() > 4 )
2033 return aLines.size() - 1;
2041 size_t i = aStartLine + 1;
2043 while( i < aLines.size() )
2045 const std::string& line = aLines[i];
2058 if( secName ==
"SIGNAL" )
2063 if( !signal.
name.empty() )
2066 for(
auto& wire : signal.
wires )
2070 for(
const auto& wire : signal.
wires )
2072 for(
const auto& ep : { wire.endpoint_a, wire.endpoint_b } )
2074 if( ep.find(
'.' ) != std::string::npos &&
2075 ep.find(
"@@@" ) == std::string::npos )
2077 size_t dotPos = ep.find(
'.' );
2079 conn.
reference = ep.substr( 0, dotPos );
2088 if( existing.reference == conn.
reference &&
2102 m_signals.push_back( std::move( signal ) );
2117 return aLines.size() - 1;
2124 if( aStartLine >= aLines.size() )
2128 const std::string& headerLine = aLines[aStartLine];
2131 if( secName !=
"SIGNAL" )
2135 size_t afterMarker = headerLine.find(
'*', 1 );
2137 if( afterMarker == std::string::npos )
2140 std::string rest = headerLine.substr( afterMarker + 1 );
2141 std::istringstream iss( rest );
2145 size_t i = aStartLine + 1;
2148 if( aSignal.
flags2 == 1 && i < aLines.size() )
2150 const std::string& funcLine = aLines[i];
2152 if( funcLine.find(
"\"FUNCTION\"" ) != std::string::npos ||
2153 funcLine.find(
"FUNCTION" ) == 0 )
2155 size_t qStart = funcLine.find(
'"' );
2157 if( qStart != std::string::npos )
2159 size_t qEnd = funcLine.find(
'"', qStart + 1 );
2161 if( qEnd != std::string::npos )
2163 size_t afterQ = funcLine.find_first_not_of(
" \t", qEnd + 1 );
2165 if( afterQ != std::string::npos )
2166 aSignal.
function = funcLine.substr( afterQ );
2177 while( i < aLines.size() )
2179 const std::string& line = aLines[i];
2192 std::istringstream wiss( line );
2204 for(
int v = 0; v < wire.
vertex_count && i < aLines.size(); v++ )
2206 const std::string& ptLine = aLines[i];
2212 std::istringstream piss( ptLine );
2213 piss >> pt.
x >> pt.
y;
2225 aSignal.
wires.push_back( wire );
2228 return i > 0 ? i - 1 : aStartLine;
2235 size_t i = aStartLine + 1;
2237 while( i < aLines.size() )
2239 const std::string& line = aLines[i];
2253 std::istringstream iss( line );
2261 std::getline( iss, rest );
2262 size_t qStart = rest.find(
'"' );
2264 if( qStart != std::string::npos )
2266 size_t qEnd = rest.find(
'"', qStart + 1 );
2268 if( qEnd != std::string::npos )
2269 label.
font_name = rest.substr( qStart + 1, qEnd - qStart - 1 );
2276 return aLines.size() - 1;
2283 size_t i = aStartLine + 1;
2285 bool foundFirstBrace =
false;
2287 while( i < aLines.size() )
2289 const std::string& line = aLines[i];
2291 for(
char c : line )
2296 foundFirstBrace =
true;
2304 if( foundFirstBrace && braceDepth <= 0 )
2314 return aLines.size() - 1;
2322 if( sym.name == aName )
2334 if( part.reference == aReference )
2346 if( signal.name == aName )
2358 if( sheets.empty() )
2361 return *sheets.rbegin();
2367 std::set<int> sheets;
2370 sheets.insert( header.sheet_num );
2373 sheets.insert( part.sheet_number );
2377 for(
const auto& wire : signal.wires )
2378 sheets.insert( wire.sheet_number );
2380 for(
const auto& conn : signal.connections )
2381 sheets.insert( conn.sheet_number );
2384 if( sheets.empty() )
2393 std::vector<SCH_SIGNAL>
result;
2398 filteredSignal.
name = signal.name;
2400 for(
const auto& wire : signal.wires )
2402 if( wire.sheet_number == aSheetNumber )
2403 filteredSignal.
wires.push_back( wire );
2406 for(
const auto& conn : signal.connections )
2408 if( conn.sheet_number == aSheetNumber )
2413 result.push_back( filteredSignal );
2422 std::vector<PART_PLACEMENT>
result;
2426 if( part.sheet_number == aSheetNumber )
2427 result.push_back( part );
2436 std::string upper = aTypeStr;
2437 std::transform( upper.begin(), upper.end(), upper.begin(), ::toupper );
2439 if( upper ==
"I" || upper ==
"IN" || upper ==
"INPUT" || upper ==
"L" )
2442 if( upper ==
"O" || upper ==
"OUT" || upper ==
"OUTPUT" || upper ==
"S" )
2445 if( upper ==
"B" || upper ==
"BI" || upper ==
"BIDIR" || upper ==
"BIDIRECTIONAL" )
2448 if( upper ==
"T" || upper ==
"TRI" || upper ==
"TRISTATE" )
2451 if( upper ==
"OC" || upper ==
"OPENCOLLECTOR" )
2454 if( upper ==
"OE" || upper ==
"OPENEMITTER" )
2457 if( upper ==
"P" || upper ==
"PWR" || upper ==
"POWER" || upper ==
"G" )
2460 if( upper ==
"PAS" || upper ==
"PASSIVE" )
2469 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.