KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pads_parser.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2025 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "pads_parser.h"
21#include <io/pads/pads_common.h>
22#include <fstream>
23#include <sstream>
24#include <iostream>
25#include <algorithm>
26#include <climits>
27#include <cmath>
28#include <cstdlib>
29#include <limits>
30#include <wx/log.h>
31#include <trace_helpers.h>
32
33namespace PADS_IO
34{
35
37{
38 return aLayer.shape == "RT" || aLayer.shape == "ST";
39}
40
41
42bool IsAntiPadRow( const PAD_STACK_LAYER& aLayer )
43{
44 return aLayer.shape == "RA" || aLayer.shape == "SA";
45}
46
47
48bool IsCopperPadRow( const PAD_STACK_LAYER& aLayer )
49{
50 return !IsThermalReliefPadRow( aLayer ) && !IsAntiPadRow( aLayer );
51}
52
53
63static std::vector<std::string> expandShortcutPattern( const std::string& aPattern )
64{
65 std::vector<std::string> result;
66
67 size_t braceStart = aPattern.find( '{' );
68 size_t braceEnd = aPattern.find( '}' );
69
70 if( braceStart == std::string::npos || braceEnd == std::string::npos || braceEnd <= braceStart )
71 {
72 result.push_back( aPattern );
73 return result;
74 }
75
76 std::string prefix = aPattern.substr( 0, braceStart );
77 std::string suffix = ( braceEnd + 1 < aPattern.length() ) ? aPattern.substr( braceEnd + 1 ) : "";
78 std::string range = aPattern.substr( braceStart + 1, braceEnd - braceStart - 1 );
79
80 size_t dashPos = range.find( '-' );
81
82 if( dashPos == std::string::npos )
83 {
84 result.push_back( aPattern );
85 return result;
86 }
87
88 int start = PADS_COMMON::ParseInt( range.substr( 0, dashPos ), INT_MIN, "shortcut range" );
89 int end = PADS_COMMON::ParseInt( range.substr( dashPos + 1 ), INT_MIN, "shortcut range" );
90
91 if( start == INT_MIN || end == INT_MIN )
92 {
93 result.push_back( aPattern );
94 return result;
95 }
96
97 static constexpr int MAX_EXPANSION = 10000;
98
99 if( std::abs( end - start ) > MAX_EXPANSION )
100 {
101 wxLogTrace( tracePadsIo, wxT( "PADS Import: shortcut range {%d-%d} exceeds limit, skipped" ),
102 start, end );
103 result.push_back( aPattern );
104 return result;
105 }
106
107 for( int i = start; i <= end; ++i )
108 {
109 result.push_back( prefix + std::to_string( i ) + suffix );
110 }
111
112 return result;
113}
114
115
116static std::string normalizeNetName( const std::string& aNetName )
117{
118 // PADS uses numeric sentinels in optional owner/signame fields for unassigned nets.
119 if( aNetName == "-1" || aNetName == "0" )
120 return {};
121
122 return aNetName;
123}
124
125
127{
128}
129
131{
132}
133
134void PARSER::Parse( const wxString& aFileName )
135{
136 std::ifstream file( aFileName.ToStdString() );
137 if( !file.is_open() )
138 {
139 throw std::runtime_error( "Could not open file " + aFileName.ToStdString() );
140 }
141
142 std::string line;
143
144 // Read header
145 if( !readLine( file, line ) )
146 {
147 throw std::runtime_error( "Empty file" );
148 }
149
150 // Parse header line format:
151 // PCB files: !PADS-product-version-units[-mode][-encoding]!
152 // Example: !PADS-POWERPCB-V9.4-MILS!
153 // Library files: *PADS-LIBRARY-type-Vversion*
154 // Example: *PADS-LIBRARY-PCB-DECALS-V9*
155 m_is_basic_units = false;
157
158 // Check for library file format (uses * delimiters)
159 if( line.size() > 2 && line[0] == '*' && line.back() == '*' )
160 {
161 std::string header = line.substr( 1, line.size() - 2 );
162 m_file_header.product = header;
163
164 // Detect library type from header
165 if( header.find( "LIBRARY-LINE-ITEMS" ) != std::string::npos ||
166 header.find( "LIBRARY-LINE" ) != std::string::npos )
167 {
169 }
170 else if( header.find( "LIBRARY-SCH-DECALS" ) != std::string::npos )
171 {
173 }
174 else if( header.find( "LIBRARY-PCB-DECALS" ) != std::string::npos ||
175 header.find( "LIBRARY-DECALS" ) != std::string::npos )
176 {
178 }
179 else if( header.find( "LIBRARY-PART-TYPES" ) != std::string::npos )
180 {
182 }
183
184 // Extract version from library header (e.g., V9 from *PADS-LIBRARY-PCB-DECALS-V9*)
185 size_t v_pos = header.rfind( "-V" );
186
187 if( v_pos != std::string::npos )
188 {
189 m_file_header.version = header.substr( v_pos + 1 );
190 }
191
192 // Library files default to mils
194 }
195 else if( line.size() > 2 && line[0] == '!' )
196 {
197 // PCB file format: !PADS-product-version-units[-mode][-encoding]! [description...]
198 // Find the closing '!' to extract just the header marker, ignoring any trailing text
199 size_t close_pos = line.find( '!', 1 );
200
201 if( close_pos == std::string::npos )
202 close_pos = line.size();
203
204 std::string header = line.substr( 1, close_pos - 1 );
205
206 // Split by '-'
207 std::vector<std::string> parts;
208 size_t start = 0;
209 size_t pos = 0;
210
211 while( ( pos = header.find( '-', start ) ) != std::string::npos )
212 {
213 parts.push_back( header.substr( start, pos - start ) );
214 start = pos + 1;
215 }
216
217 parts.push_back( header.substr( start ) );
218
219 // Parse parts: PADS, product, version, units, [mode], [encoding]
220 if( parts.size() >= 4 )
221 {
222 // First part should be "PADS"
223 m_file_header.product = parts[1];
224 m_file_header.version = parts[2];
225 m_file_header.units = parts[3];
226
227 if( parts.size() >= 5 )
228 m_file_header.mode = parts[4];
229
230 if( parts.size() >= 6 )
231 m_file_header.encoding = parts[5];
232 }
233 else if( parts.size() >= 2 )
234 {
235 // Simpler format
236 m_file_header.product = parts[0];
237
238 if( parts.size() >= 2 )
239 m_file_header.version = parts[1];
240
241 if( parts.size() >= 3 )
242 m_file_header.units = parts[2];
243 }
244
245 // Set units based on parsed header
246 if( m_file_header.units == "BASIC" )
247 {
248 m_is_basic_units = true;
249 }
250 else if( m_file_header.units == "MILS" || m_file_header.units == "MIL" )
251 {
253 }
254 else if( m_file_header.units == "MM" || m_file_header.units == "METRIC" )
255 {
257 }
258 else if( m_file_header.units == "INCH" || m_file_header.units == "INCHES" )
259 {
261 }
262 }
263 else if( line.find( "BASIC" ) != std::string::npos )
264 {
265 m_is_basic_units = true;
266 }
267
268 // PADS V3-V5 use 2-line text/label entries (no font line). The version
269 // sequence then jumps to the year releases V2003/V2005/V2007 and to V9+,
270 // all of which insert a font style line between the attribute and name
271 // lines. An unrecognized header defaults to the modern 3-line format.
272 int majorVer = parseMajorVersion();
273 m_has_font_lines = ( majorVer == 0 || majorVer >= 9 );
274
275 while( readLine( file, line ) )
276 {
277 if( line.empty() ) continue;
278
279 if( line.rfind( "*PCB*", 0 ) == 0 )
280 {
281 parseSectionPCB( file );
282 }
283 else if( line.rfind( "*PART*", 0 ) == 0 )
284 {
285 parseSectionPARTS( file );
286 }
287 else if( line.rfind( "*NET*", 0 ) == 0 )
288 {
289 parseSectionNETS( file );
290 }
291 else if( line.rfind( "*ROUTE*", 0 ) == 0 )
292 {
293 parseSectionROUTES( file );
294 }
295 else if( line.rfind( "*TEXT*", 0 ) == 0 )
296 {
297 parseSectionTEXT( file );
298 }
299 else if( line.rfind( "*BOARD*", 0 ) == 0 )
300 {
301 parseSectionBOARD( file );
302 }
303 else if( line.rfind( "*LINES*", 0 ) == 0 )
304 {
305 parseSectionLINES( file );
306 }
307 else if( line.rfind( "*VIA*", 0 ) == 0 )
308 {
309 parseSectionVIA( file );
310 }
311 else if( line.rfind( "*POUR*", 0 ) == 0 )
312 {
313 parseSectionPOUR( file );
314 }
315 else if( line.rfind( "*PARTDECAL*", 0 ) == 0 )
316 {
317 parseSectionPARTDECAL( file );
318 }
319 else if( line.rfind( "*PARTTYPE*", 0 ) == 0 )
320 {
321 parseSectionPARTTYPE( file );
322 }
323 else if( line.rfind( "*REUSE*", 0 ) == 0 )
324 {
325 parseSectionREUSE( file );
326 }
327 else if( line.rfind( "*CLUSTER*", 0 ) == 0 )
328 {
329 parseSectionCLUSTER( file );
330 }
331 else if( line.rfind( "*JUMPER*", 0 ) == 0 )
332 {
333 parseSectionJUMPER( file );
334 }
335 else if( line.rfind( "*TESTPOINT*", 0 ) == 0 )
336 {
337 parseSectionTESTPOINT( file );
338 }
339 else if( line.rfind( "*NETCLASS*", 0 ) == 0 || line.rfind( "*NETDEF*", 0 ) == 0 )
340 {
341 parseSectionNETCLASS( file );
342 }
343 else if( line.rfind( "*DIFFPAIR*", 0 ) == 0 || line.rfind( "*DIFFPAIRS*", 0 ) == 0 )
344 {
345 parseSectionDIFFPAIR( file );
346 }
347 else if( line.rfind( "LAYER MILS", 0 ) == 0 || line.rfind( "LAYER METRIC", 0 ) == 0 )
348 {
349 parseSectionLAYERDEFS( file );
350 }
351 else if( line.rfind( "*MISC*", 0 ) == 0 )
352 {
353 parseSectionMISC( file );
354 }
355 }
356}
357
358bool PARSER::readLine( std::ifstream& aStream, std::string& aLine )
359{
360 if( m_pushed_line )
361 {
362 aLine = *m_pushed_line;
363 m_pushed_line.reset();
364 return true;
365 }
366
367 while( std::getline( aStream, aLine ) )
368 {
369 // Trim whitespace
370 aLine.erase( 0, aLine.find_first_not_of( " \t\r\n" ) );
371 aLine.erase( aLine.find_last_not_of( " \t\r\n" ) + 1 );
372
373 if( aLine.empty() ) continue;
374 if( aLine.rfind( "*REMARK*", 0 ) == 0 ) continue;
375 return true;
376 }
377 return false;
378}
379
380void PARSER::pushBackLine( const std::string& aLine )
381{
382 m_pushed_line = aLine;
383}
384
385
387{
388 const std::string& ver = m_file_header.version;
389
390 // Version strings look like "V5.0", "V9.4", "V2005.0", etc.
391 size_t start = 0;
392
393 if( !ver.empty() && ( ver[0] == 'V' || ver[0] == 'v' ) )
394 start = 1;
395
396 size_t dot = ver.find( '.', start );
397 std::string major_str = ( dot != std::string::npos ) ? ver.substr( start, dot - start )
398 : ver.substr( start );
399
400 try
401 {
402 return std::stoi( major_str );
403 }
404 catch( const std::exception& )
405 {
406 return 0;
407 }
408}
409
410void PARSER::parseSectionPCB( std::ifstream& aStream )
411{
412 std::string line;
413 while( readLine( aStream, line ) )
414 {
415 if( line[0] == '*' )
416 {
417 pushBackLine( line );
418 break;
419 }
420
421 std::istringstream iss( line );
422 std::string token;
423 iss >> token;
424
425 if( token == "UNITS" )
426 {
427 std::string val;
428 iss >> val;
429
430 if( val == "0" ) m_parameters.units = UNIT_TYPE::MILS;
431 else if( val == "1" ) m_parameters.units = UNIT_TYPE::METRIC;
432 else if( val == "2" ) m_parameters.units = UNIT_TYPE::INCHES;
433 }
434 else if( token == "USERGRID" )
435 {
436 iss >> m_parameters.user_grid;
437 }
438 else if( token == "MAXIMUMLAYER" )
439 {
440 iss >> m_parameters.layer_count;
441 }
442 else if( token == "ORIGIN" )
443 {
444 iss >> m_parameters.origin.x >> m_parameters.origin.y;
445 }
446 else if( token == "THERLINEWID" )
447 {
448 iss >> m_parameters.thermal_line_width;
449 }
450 else if( token == "THERSMDWID" )
451 {
452 iss >> m_parameters.thermal_smd_width;
453 }
454 else if( token == "THERFLAGS" )
455 {
456 std::string flags_str;
457 iss >> flags_str;
458
459 try
460 {
461 m_parameters.thermal_flags = std::stoi( flags_str, nullptr, 0 );
462 }
463 catch( const std::exception& )
464 {
465 m_parameters.thermal_flags = 0;
466 }
467 }
468 else if( token == "DRLOVERSIZE" )
469 {
470 iss >> m_parameters.drill_oversize;
471 }
472 else if( token == "VIAPSHVIA" )
473 {
474 iss >> m_parameters.default_signal_via;
475 }
476 else if( token == "STMINCLEAR" )
477 {
478 iss >> m_parameters.thermal_min_clearance;
479 }
480 else if( token == "STMINSPOKES" )
481 {
482 iss >> m_parameters.thermal_min_spokes;
483 }
484 else if( token == "MINCLEAR" )
485 {
486 iss >> m_design_rules.min_clearance;
488 }
489 else if( token == "DEFAULTCLEAR" )
490 {
491 iss >> m_design_rules.default_clearance;
493 }
494 else if( token == "MINTRACKWID" )
495 {
496 iss >> m_design_rules.min_track_width;
498 }
499 else if( token == "DEFAULTTRACKWID" )
500 {
501 iss >> m_design_rules.default_track_width;
503 }
504 else if( token == "MINVIASIZE" )
505 {
506 iss >> m_design_rules.min_via_size;
508 }
509 else if( token == "DEFAULTVIASIZE" )
510 {
511 iss >> m_design_rules.default_via_size;
513 }
514 else if( token == "MINVIADRILL" )
515 {
516 iss >> m_design_rules.min_via_drill;
518 }
519 else if( token == "DEFAULTVIADRILL" )
520 {
521 iss >> m_design_rules.default_via_drill;
523 }
524 else if( token == "HOLEHOLE" )
525 {
526 iss >> m_design_rules.hole_to_hole;
528 }
529 else if( token == "SILKCLEAR" )
530 {
531 iss >> m_design_rules.silk_clearance;
533 }
534 else if( token == "MASKCLEAR" )
535 {
536 iss >> m_design_rules.mask_clearance;
538 }
539 }
540}
541
542void PARSER::parseSectionPARTS( std::ifstream& aStream )
543{
544 std::string line;
545 while( readLine( aStream, line ) )
546 {
547 if( line.find( "*REMARK*" ) == 0 )
548 continue;
549
550 if( line[0] == '*' )
551 {
552 pushBackLine( line );
553 break;
554 }
555
556 // Skip attribute lines and other non-part lines
557 if( line.rfind( "}", 0 ) == 0 ||
558 line.rfind( "{", 0 ) == 0 )
559 {
560 continue;
561 }
562
563 std::istringstream iss( line );
564 PART part;
565 part.location.x = 0.0;
566 part.location.y = 0.0;
567
568 std::string name_token, parttype_string;
569 iss >> name_token >> parttype_string >> part.location.x >> part.location.y >> part.rotation;
570
571 if( iss.fail() )
572 {
573 continue;
574 }
575
576 // Check for shortcut format: PRE{n1-n2}
577 // Example: C{2-20} with same attributes creates C2 through C20
578 std::vector<std::string> expanded_names = expandShortcutPattern( name_token );
579 bool is_shortcut = ( expanded_names.size() > 1 );
580 part.name = expanded_names[0];
581
582 // Check for explicit decal override using @ syntax
583 // Format: PARTTYPE@DECAL_NAME means use DECAL_NAME instead of looking up from PARTTYPE
584 size_t at_pos = parttype_string.find( '@' );
585
586 if( at_pos != std::string::npos )
587 {
588 // Explicit decal specified after @
589 part.part_type = parttype_string.substr( 0, at_pos );
590 part.decal = parttype_string.substr( at_pos + 1 );
591 part.explicit_decal = true;
592 }
593 else
594 {
595 // No @ - could be a direct decal name or a part type name
596 // Store as decal for now, resolution happens in pcb_io_pads.cpp
597 // Split on ':' to get primary and alternates (for direct decal lists)
598 size_t pos = 0;
599 size_t colon_pos = 0;
600 bool first = true;
601
602 while( ( colon_pos = parttype_string.find( ':', pos ) ) != std::string::npos )
603 {
604 std::string decal_name = parttype_string.substr( pos, colon_pos - pos );
605
606 if( first )
607 {
608 part.decal = decal_name;
609 first = false;
610 }
611 else
612 {
613 part.alternate_decals.push_back( decal_name );
614 }
615
616 pos = colon_pos + 1;
617 }
618
619 // Handle the last (or only) decal name
620 std::string last_decal = parttype_string.substr( pos );
621
622 if( first )
623 {
624 part.decal = last_decal;
625 }
626 else
627 {
628 part.alternate_decals.push_back( last_decal );
629 }
630 }
631
632 // Read all remaining tokens
633 std::vector<std::string> tokens;
634 std::string token;
635 while( iss >> token )
636 {
637 tokens.push_back( token );
638 }
639
640 int labels = 0;
641
642 // Process tokens for flags and label count
643 // Format per REMARK: GLUE MIRROR ALT CLSTID CLSTATTR BROTHERID LABELS
644 // GLUE: U (unglued) or G (glued)
645 // MIRROR: N (normal/top) or M (mirrored/bottom)
646 // ALT: Alternate decal index (0-based, -1 or missing = use primary)
647 for( size_t i = 0; i < tokens.size(); ++i )
648 {
649 const std::string& t = tokens[i];
650
651 if( t == "G" )
652 part.glued = true;
653 else if( t == "M" )
654 part.bottom_layer = true;
655
656 // U = unglued (default), N = normal/not-mirrored (default)
657 // These are defaults so we don't need to explicitly handle them
658
659 // Parse ALT field (token index 2 after GLUE and MIRROR)
660 // ALT field is 0-indexed in PADS format
661 if( i == 2 )
662 {
663 int alt = PADS_COMMON::ParseInt( t, -1, "PART ALT" );
664
665 if( alt >= 0 )
666 part.alt_decal_index = alt;
667 }
668
669 // The last token is the label count
670 if( i == tokens.size() - 1 )
671 {
672 try
673 {
674 size_t pos = 0;
675 labels = std::stoi( t, &pos );
676
677 if( pos != t.length() )
678 labels = 0;
679 }
680 catch( const std::exception& )
681 {
682 labels = 0;
683 }
684 }
685 }
686
687 // Check for optional .REUSE. line following part header
688 // Format: .REUSE. instance part
689 if( readLine( aStream, line ) )
690 {
691 if( line.find( ".REUSE." ) == 0 )
692 {
693 std::istringstream riss( line );
694 std::string reuse_keyword;
695 riss >> reuse_keyword >> part.reuse_instance >> part.reuse_part;
696 }
697 else
698 {
699 pushBackLine( line );
700 }
701 }
702
703 for( int i = 0; i < labels; ++i )
704 {
705 ATTRIBUTE attr;
706 if( !readLine( aStream, line ) ) break;
707
708 std::stringstream iss_attr( line );
709 std::string visible_str;
710 std::string mirrored_str;
711 std::string right_reading_str;
712
713 // VISIBLE XLOC YLOC ORI LEVEL HEIGHT WIDTH MIRRORED HJUST VJUST [RIGHTREADING]
714 if( iss_attr >> visible_str >> attr.x >> attr.y >> attr.orientation >> attr.level
715 >> attr.height >> attr.width >> mirrored_str >> attr.hjust >> attr.vjust )
716 {
717 attr.visible = ( visible_str == "VALUE" || visible_str == "FULL_NAME"
718 || visible_str == "NAME" || visible_str == "FULL_BOTH"
719 || visible_str == "BOTH" );
720 attr.mirrored = ( mirrored_str == "M" );
721 iss_attr >> right_reading_str;
722 attr.right_reading = ( right_reading_str == "Y" || right_reading_str == "ORTHO" );
723 }
724
725 if( m_has_font_lines )
726 {
727 if( !readLine( aStream, line ) ) break;
728 attr.font_info = line;
729 }
730
731 if( !readLine( aStream, line ) ) break;
732 attr.name = line;
733
734 part.attributes.push_back( attr );
735 }
736
737 // Add the first part (or only part if not a shortcut)
738 m_parts.push_back( part );
739
740 // If this was a shortcut pattern, create additional parts with same attributes
741 // but different reference designators
742 if( is_shortcut )
743 {
744 for( size_t i = 1; i < expanded_names.size(); ++i )
745 {
746 PART additional_part = part;
747 additional_part.name = expanded_names[i];
748 m_parts.push_back( additional_part );
749 }
750 }
751 }
752}
753
754void PARSER::parseSectionNETS( std::ifstream& aStream )
755{
756 // Implementation for NETS
757 // Format: *NET* NETNAME
758 // REF.PIN REF.PIN ... [.REUSE. instance rsignal]
759 // Supports shortcut format: PRE{n1-n2}.{pin1-pin2} expands to multiple pins
760 std::string line;
761 NET* current_net = nullptr;
762
763 // Helper lambda to parse a pin token that may have .REUSE. suffix
764 auto parsePinToken = []( const std::string& token, NET_PIN& pin ) -> bool
765 {
766 size_t dot_pos = token.find( '.' );
767
768 if( dot_pos == std::string::npos )
769 return false;
770
771 pin.ref_des = token.substr( 0, dot_pos );
772 pin.pin_name = token.substr( dot_pos + 1 );
773 return true;
774 };
775
776 // Helper lambda to expand shortcut format tokens like U{4-8}.{7-8}
777 // Returns a vector of expanded pins
778 auto expandShortcutPin = []( const std::string& token ) -> std::vector<std::string>
779 {
780 std::vector<std::string> results;
781
782 // Check if this contains any {n-m} range patterns
783 if( token.find( '{' ) == std::string::npos )
784 {
785 results.push_back( token );
786 return results;
787 }
788
789 // Parse the token to find all range patterns
790 // Format: PREFIX{start-end}MIDDLE{start-end}SUFFIX...
791 struct RangePart
792 {
793 std::string prefix;
794 int start = 0;
795 int end = 0;
796 bool is_range = false;
797 };
798
799 std::vector<RangePart> parts;
800 size_t pos = 0;
801 std::string current_prefix;
802
803 while( pos < token.size() )
804 {
805 if( token[pos] == '{' )
806 {
807 size_t close_pos = token.find( '}', pos );
808
809 if( close_pos == std::string::npos )
810 {
811 // Malformed, return as-is
812 results.push_back( token );
813 return results;
814 }
815
816 std::string range_str = token.substr( pos + 1, close_pos - pos - 1 );
817 size_t dash_pos = range_str.find( '-' );
818
819 if( dash_pos != std::string::npos )
820 {
821 RangePart part;
822 part.prefix = current_prefix;
823 part.is_range = true;
824
825 part.start = PADS_COMMON::ParseInt( range_str.substr( 0, dash_pos ),
826 INT_MIN, "net range" );
827 part.end = PADS_COMMON::ParseInt( range_str.substr( dash_pos + 1 ),
828 INT_MIN, "net range" );
829
830 if( part.start == INT_MIN || part.end == INT_MIN )
831 {
832 results.push_back( token );
833 return results;
834 }
835
836 parts.push_back( part );
837 current_prefix.clear();
838 }
839 else
840 {
841 // Single value in braces, treat as literal
842 current_prefix += range_str;
843 }
844
845 pos = close_pos + 1;
846 }
847 else
848 {
849 current_prefix += token[pos];
850 pos++;
851 }
852 }
853
854 // Add any trailing text as a final non-range part
855 if( !current_prefix.empty() || parts.empty() )
856 {
857 RangePart final_part;
858 final_part.prefix = current_prefix;
859 final_part.is_range = false;
860 final_part.start = 0;
861 final_part.end = 0;
862 parts.push_back( final_part );
863 }
864
865 // Generate all combinations
866 // Start with empty string
867 results.push_back( "" );
868
869 for( const auto& part : parts )
870 {
871 std::vector<std::string> new_results;
872
873 if( part.is_range )
874 {
875 for( const auto& base : results )
876 {
877 int step = ( part.start <= part.end ) ? 1 : -1;
878
879 for( int i = part.start; step > 0 ? i <= part.end : i >= part.end; i += step )
880 {
881 new_results.push_back( base + part.prefix + std::to_string( i ) );
882 }
883 }
884 }
885 else
886 {
887 for( const auto& base : results )
888 {
889 new_results.push_back( base + part.prefix );
890 }
891 }
892
893 results = std::move( new_results );
894 }
895
896 return results;
897 };
898
899 while( readLine( aStream, line ) )
900 {
901 if( line[0] == '*' )
902 {
903 pushBackLine( line );
904 break;
905 }
906
907 std::istringstream iss( line );
908 std::string token;
909 iss >> token;
910
911 if( token == "SIGNAL" )
912 {
913 NET net;
914 iss >> net.name;
915 m_nets.push_back( net );
916 current_net = &m_nets.back();
917
918 // Parse remaining tokens on this line
919 std::string pin_token;
920
921 while( iss >> pin_token )
922 {
923 // Check for .REUSE. suffix
924 if( pin_token == ".REUSE." )
925 {
926 // Read instance and signal for the previous pin
927 std::string instance, rsignal;
928
929 if( ( iss >> instance >> rsignal ) && !current_net->pins.empty() )
930 {
931 current_net->pins.back().reuse_instance = instance;
932 current_net->pins.back().reuse_signal = rsignal;
933 }
934
935 continue;
936 }
937
938 // Expand shortcut format and add all resulting pins
939 for( const auto& expanded : expandShortcutPin( pin_token ) )
940 {
941 NET_PIN pin;
942
943 if( parsePinToken( expanded, pin ) )
944 current_net->pins.push_back( pin );
945 }
946 }
947 }
948 else
949 {
950 // Continuation of pins for current net
951 if( current_net )
952 {
953 do
954 {
955 // Check for .REUSE. suffix
956 if( token == ".REUSE." )
957 {
958 std::string instance, rsignal;
959
960 if( ( iss >> instance >> rsignal ) && !current_net->pins.empty() )
961 {
962 current_net->pins.back().reuse_instance = instance;
963 current_net->pins.back().reuse_signal = rsignal;
964 }
965
966 continue;
967 }
968
969 // Expand shortcut format and add all resulting pins
970 for( const auto& expanded : expandShortcutPin( token ) )
971 {
972 NET_PIN pin;
973
974 if( parsePinToken( expanded, pin ) )
975 current_net->pins.push_back( pin );
976 }
977
978 } while( iss >> token );
979 }
980 }
981 }
982}
983
984void PARSER::parseSectionVIA( std::ifstream& aStream )
985{
986 std::string line;
987
988 while( readLine( aStream, line ) )
989 {
990 if( line[0] == '*' )
991 {
992 pushBackLine( line );
993 return;
994 }
995
996 std::stringstream iss( line );
997 std::string name;
998 double drill = 0.0;
999 int stacklines = 0;
1000
1001 if( !( iss >> name >> drill >> stacklines ) )
1002 continue;
1003
1004 VIA_DEF def;
1005 def.name = name;
1006 def.drill = drill;
1007
1008 // Parse optional drill_start and drill_end for blind/buried vias
1009 int drill_start_val = 0;
1010 int drill_end_val = 0;
1011
1012 if( iss >> drill_start_val >> drill_end_val )
1013 {
1014 def.drill_start = drill_start_val;
1015 def.drill_end = drill_end_val;
1016 }
1017
1018 int min_layer = INT_MAX;
1019 int max_layer = INT_MIN;
1020
1021 for( int i = 0; i < stacklines; ++i )
1022 {
1023 if( !readLine( aStream, line ) )
1024 break;
1025
1026 std::stringstream iss2( line );
1027 int level = 0;
1028 double size = 0.0;
1029 std::string shape;
1030
1031 if( !( iss2 >> level >> size >> shape ) )
1032 continue;
1033
1034 PAD_STACK_LAYER layer_data;
1035 layer_data.layer = level;
1036 layer_data.shape = shape;
1037 layer_data.sizeA = size;
1038 layer_data.plated = true;
1039
1040 // Parse shape-specific parameters per PADS spec
1041 if( shape == "R" || shape == "S" )
1042 {
1043 // Round or Square pad: level size shape [corner]
1044 // Negative corner = chamfered, positive = rounded, zero = square
1045 double corner = 0;
1046
1047 if( shape == "S" && ( iss2 >> corner ) )
1048 {
1049 if( corner < 0 )
1050 {
1051 layer_data.corner_radius = -corner;
1052 layer_data.chamfered = true;
1053 }
1054 else
1055 {
1056 layer_data.corner_radius = corner;
1057 }
1058 }
1059 }
1060 else if( shape == "RA" || shape == "SA" )
1061 {
1062 // Anti-pad shapes: level size shape (no additional params)
1063 // These define clearance shapes in planes
1064 }
1065 else if( shape == "A" )
1066 {
1067 // Annular pad: level size shape inner_diameter
1068 double intd = 0;
1069
1070 if( iss2 >> intd )
1071 layer_data.inner_diameter = intd;
1072 }
1073 else if( shape == "OF" )
1074 {
1075 // Oval finger: level size shape orientation length offset
1076 double ori = 0, length = 0, offset = 0;
1077
1078 if( iss2 >> ori >> length >> offset )
1079 {
1080 layer_data.rotation = ori;
1081 layer_data.sizeB = length;
1082 layer_data.finger_offset = offset;
1083 }
1084 }
1085 else if( shape == "RF" )
1086 {
1087 // Rectangular finger: level size shape orientation length offset
1088 // Per reference parser: rotation is first, then length (becomes sizeB), then offset
1089 double ori = 0, length = 0, offset = 0;
1090
1091 if( iss2 >> ori >> length >> offset )
1092 {
1093 layer_data.rotation = ori;
1094 layer_data.sizeB = length;
1095 layer_data.finger_offset = offset;
1096 }
1097 }
1098 else if( shape == "RT" || shape == "ST" )
1099 {
1100 // Thermal pads: level size shape orientation inner_diam spoke_width spoke_count
1101 double ori = 0, intd = 0, spkwid = 0;
1102 int spknum = 4;
1103
1104 if( iss2 >> ori >> intd >> spkwid >> spknum )
1105 {
1106 layer_data.thermal_spoke_orientation = ori;
1107 layer_data.thermal_outer_diameter = intd;
1108 layer_data.thermal_spoke_width = spkwid;
1109 layer_data.thermal_spoke_count = spknum;
1110 }
1111 }
1112 else if( shape == "O" || shape == "OC" )
1113 {
1114 // Odd shape (O) or Odd Circle (OC): level size shape
1115 // These use custom pad shapes defined elsewhere
1116 // No additional parameters, just store the shape type
1117 }
1118 else if( shape == "RC" )
1119 {
1120 // Rectangular with Corner: level size RC orientation length offset [corner]
1121 // Similar to RF but with optional corner radius
1122 double ori = 0, length = 0, offset = 0, corner = 0;
1123
1124 if( iss2 >> ori >> length >> offset )
1125 {
1126 layer_data.rotation = ori;
1127 layer_data.sizeB = length;
1128 layer_data.finger_offset = offset;
1129
1130 if( iss2 >> corner )
1131 {
1132 if( corner < 0 )
1133 {
1134 layer_data.corner_radius = -corner;
1135 layer_data.chamfered = true;
1136 }
1137 else
1138 {
1139 layer_data.corner_radius = corner;
1140 }
1141 }
1142 }
1143 }
1144
1145 def.stack.push_back( layer_data );
1146
1147 // Map special layer numbers to copper layer indices.
1148 // Non-copper layers (soldermask, silkscreen, etc.) must not
1149 // affect via type classification or pad size.
1150 int effective_layer = level;
1151
1152 if( level == -2 )
1153 effective_layer = 1;
1154 else if( level == -1 )
1155 effective_layer = m_parameters.layer_count;
1156
1157 bool is_copper = ( effective_layer >= 1
1158 && effective_layer <= m_parameters.layer_count );
1159
1160 if( is_copper )
1161 {
1162 if( size > def.size )
1163 def.size = size;
1164
1165 if( effective_layer < min_layer )
1166 min_layer = effective_layer;
1167
1168 if( effective_layer > max_layer )
1169 max_layer = effective_layer;
1170 }
1171
1172 // PADS layer 25 = top soldermask, 28 = bottom soldermask
1173 if( level == 25 )
1174 def.has_mask_front = true;
1175 else if( level == 28 )
1176 def.has_mask_back = true;
1177 }
1178
1179 if( def.drill_start > 0 && def.drill_end > 0 )
1180 {
1181 min_layer = std::min( def.drill_start, def.drill_end );
1182 max_layer = std::max( def.drill_start, def.drill_end );
1183 }
1184
1185 // Determine layer span and via type
1186 if( min_layer <= max_layer )
1187 {
1188 def.start_layer = min_layer;
1189 def.end_layer = max_layer;
1190
1191 int layer_count = m_parameters.layer_count;
1192 bool starts_at_surface = ( min_layer == 1 || max_layer == layer_count );
1193 bool ends_at_surface = ( max_layer == layer_count || min_layer == 1 );
1194 bool is_full_span = ( min_layer == 1 && max_layer == layer_count );
1195 int span = max_layer - min_layer;
1196
1197 if( is_full_span )
1198 {
1200 }
1201 else if( span == 1 && ( min_layer == 1 || max_layer == layer_count ) )
1202 {
1204 }
1205 else if( starts_at_surface || ends_at_surface )
1206 {
1208 }
1209 else
1210 {
1212 }
1213 }
1214
1215 m_via_defs[name] = def;
1216 }
1217
1218 // If no signal via was specified in the header, fall back to the first definition
1219 if( m_parameters.default_signal_via.empty() && !m_via_defs.empty() )
1220 m_parameters.default_signal_via = m_via_defs.begin()->first;
1221}
1222
1223void PARSER::parseSectionPOUR( std::ifstream& aStream )
1224{
1225 std::string line;
1226
1227 while( readLine( aStream, line ) )
1228 {
1229 if( line[0] == '*' )
1230 {
1231 pushBackLine( line );
1232 return;
1233 }
1234
1235 // Parse Header
1236 // NAME TYPE XLOC YLOC PIECES FLAGS [OWNERNAME SIGNAME [HATCHGRID HATCHRAD [PRIORITY]]]
1237 std::stringstream iss( line );
1238 std::string name, type;
1239 double x = 0.0, y = 0.0;
1240 int pieces = 0, flags = 0;
1241
1242 if( !( iss >> name >> type >> x >> y >> pieces >> flags ) )
1243 continue;
1244
1245 std::string owner, signame;
1246 double hatchgrid = 0.0, hatchrad = 0.0;
1247 int priority = 0;
1248
1249 if( iss >> owner >> signame )
1250 {
1251 iss >> hatchgrid >> hatchrad >> priority;
1252 }
1253
1254 for( int i = 0; i < pieces; ++i )
1255 {
1256 if( !readLine( aStream, line ) )
1257 break;
1258
1259 // PIECETYPE CORNERS ARCS WIDTH LEVEL [THERMALS]
1260 // PIECETYPE: POLY, SEG, CIRCLE, CUTOUT, CIRCUT, POCUT
1261 std::stringstream iss2( line );
1262 std::string poly_type;
1263 int corners = 0, arcs = 0;
1264 double width = 0.0;
1265 int level = 0;
1266
1267 if( !( iss2 >> poly_type >> corners >> arcs >> width >> level ) )
1268 continue;
1269
1270 POUR pour;
1271 pour.name = name;
1272 pour.net_name = normalizeNetName( signame );
1273 pour.layer = level;
1274 pour.priority = priority;
1275 pour.width = width;
1276 pour.is_cutout = ( poly_type == "POCUT" || poly_type == "CUTOUT"
1277 || poly_type == "CIRCUT" );
1278 pour.owner_pour = owner;
1279 pour.hatch_grid = hatchgrid;
1280 pour.hatch_width = hatchrad;
1281
1282 // The header TYPE field (POUROUT, HATOUT, VOIDOUT, PADTHERM, VIATHERM)
1283 // determines the record's role. The piece-level poly_type (POLY, SEG, etc.)
1284 // only describes the geometry shape.
1285 if( type == "HATOUT" )
1286 {
1288 }
1289 else if( type == "VOIDOUT" )
1290 {
1292 pour.is_cutout = true;
1293 }
1294 else if( type == "PADTHERM" )
1295 {
1297 }
1298 else if( type == "VIATHERM" )
1299 {
1301 }
1302
1303 // Handle different piece types
1304 if( poly_type == "CIRCLE" || poly_type == "CIRCUT" )
1305 {
1306 // Circle piece: `corners` lines (always 2 in practice), each a diametrically
1307 // opposite endpoint -- not a single "xloc yloc radius" line.
1308 std::vector<std::pair<double, double>> endpoints;
1309
1310 for( int j = 0; j < corners; ++j )
1311 {
1312 if( !readLine( aStream, line ) )
1313 break;
1314
1315 std::stringstream iss3( line );
1316 double px = 0.0, py = 0.0;
1317
1318 if( iss3 >> px >> py )
1319 endpoints.emplace_back( px, py );
1320 }
1321
1322 if( endpoints.size() == 2 )
1323 {
1324 double cx = ( endpoints[0].first + endpoints[1].first ) / 2.0;
1325 double cy = ( endpoints[0].second + endpoints[1].second ) / 2.0;
1326 double radius = std::hypot( endpoints[1].first - endpoints[0].first,
1327 endpoints[1].second - endpoints[0].second ) / 2.0;
1328
1329 // Create arc representing full circle
1330 ARC arc{};
1331 arc.cx = x + cx;
1332 arc.cy = y + cy;
1333 arc.radius = radius;
1334 arc.start_angle = 0.0;
1335 arc.delta_angle = 360.0;
1336 pour.points.emplace_back( x + cx + radius, y + cy, arc );
1337 }
1338 }
1339 else if( poly_type == "SEG" )
1340 {
1341 // Segment piece: pairs of points defining line segments
1342 for( int j = 0; j < corners; ++j )
1343 {
1344 if( !readLine( aStream, line ) )
1345 break;
1346
1347 std::stringstream iss3( line );
1348 double px = 0.0, py = 0.0;
1349
1350 if( iss3 >> px >> py )
1351 {
1352 pour.points.emplace_back( x + px, y + py );
1353 }
1354 }
1355 }
1356 else
1357 {
1358 // Polygon piece types: POLY, POCUT, HATOUT, POUROUT, VOIDOUT,
1359 // PADTHERM, VIATHERM.
1360 //
1361 // Total data lines = corners + arcs. Lines with 4 values
1362 // (cx cy beginAngle sweepAngle) define an arc center and
1363 // angles. The following line gives the arc endpoint.
1364 int totalLines = corners + arcs;
1365 bool nextIsArcEndpoint = false;
1366 ARC pendingArc{};
1367
1368 for( int j = 0; j < totalLines; ++j )
1369 {
1370 if( !readLine( aStream, line ) )
1371 break;
1372
1373 std::stringstream iss3( line );
1374 double px = 0.0, py = 0.0;
1375
1376 if( !( iss3 >> px >> py ) )
1377 continue;
1378
1379 int angle1 = 0, angle2 = 0;
1380
1381 if( iss3 >> angle1 >> angle2 )
1382 {
1383 // Arc center line. The two angles are begin angle
1384 // (direction from center to the previous vertex) and
1385 // sweep angle, both in tenths of degrees.
1386 pendingArc = ARC{};
1387 pendingArc.cx = x + px;
1388 pendingArc.cy = y + py;
1389 pendingArc.start_angle = angle1 / 10.0;
1390 pendingArc.delta_angle = angle2 / 10.0;
1391
1392 if( !pour.points.empty() )
1393 {
1394 double dx = pour.points.back().x - pendingArc.cx;
1395 double dy = pour.points.back().y - pendingArc.cy;
1396 pendingArc.radius = std::sqrt( dx * dx + dy * dy );
1397 }
1398
1399 nextIsArcEndpoint = true;
1400 }
1401 else if( nextIsArcEndpoint )
1402 {
1403 if( pendingArc.radius == 0.0 )
1404 {
1405 double dx = ( x + px ) - pendingArc.cx;
1406 double dy = ( y + py ) - pendingArc.cy;
1407 pendingArc.radius = std::sqrt( dx * dx + dy * dy );
1408 }
1409
1410 pour.points.emplace_back( x + px, y + py, pendingArc );
1411 nextIsArcEndpoint = false;
1412 }
1413 else
1414 {
1415 pour.points.emplace_back( x + px, y + py );
1416 }
1417 }
1418 }
1419
1420 m_pours.push_back( pour );
1421 }
1422 }
1423}
1424
1425void PARSER::parseSectionPARTDECAL( std::ifstream& aStream )
1426{
1427 std::string line;
1428 while( readLine( aStream, line ) )
1429 {
1430 if( line[0] == '*' )
1431 {
1432 pushBackLine( line );
1433 return;
1434 }
1435
1436 // Header: NAME UNITS ORIX ORIY PIECES TERMINALS STACKS TEXT LABELS
1437 std::stringstream iss( line );
1438 std::string name, units;
1439 double orix = 0.0, oriy = 0.0;
1440 int pieces = 0, terminals = 0, stacks = 0, text_cnt = 0, labels = 0;
1441
1442 if( !( iss >> name >> units >> orix >> oriy >> pieces >> terminals >> stacks >> text_cnt >> labels ) )
1443 continue;
1444
1445 PART_DECAL decal;
1446 decal.name = name;
1447 decal.units = units;
1448
1449 // Parse Pieces (Graphics)
1450 for( int i = 0; i < pieces; ++i )
1451 {
1452 if( !readLine( aStream, line ) ) break;
1453
1454 // PIECETYPE CORNERS WIDTHHGHT LINESTYLE LEVEL [RESTRICTIONS]
1455 std::stringstream iss2( line );
1456 std::string type;
1457 int corners = 0;
1458 double width = 0;
1459 int level = 0;
1460
1461 if( !( iss2 >> type >> corners >> width ) )
1462 {
1463 // Should not happen if line is valid
1464 continue;
1465 }
1466
1467 // Try to read optional fields
1468 // Some formats have LINESTYLE LEVEL, others just LEVEL
1469 int val1 = 0;
1470 if( iss2 >> val1 )
1471 {
1472 int val2 = 0;
1473 if( iss2 >> val2 )
1474 {
1475 level = val2;
1476 }
1477 else
1478 {
1479 level = val1;
1480 }
1481 }
1482
1483 DECAL_ITEM item;
1484 item.type = type;
1485 item.width = width;
1486 item.layer = level;
1487
1488 // Handle TAG piece type (no coordinates, used for grouping copper/cutouts)
1489 if( type == "TAG" )
1490 {
1491 // Level is used as open/close flag: 1=open group, 0=close group
1492 item.is_tag_open = ( level == 1 );
1493 item.is_tag_close = ( level == 0 );
1494 decal.items.push_back( item );
1495 continue;
1496 }
1497
1498 // Parse pinnum for copper pieces (COPCLS, COPOPN, COPCIR, COPCUT, COPCCO)
1499 // Format includes [pinnum] at the end for copper associated with a pin
1500 if( type.find( "COP" ) == 0 )
1501 {
1502 std::string remaining;
1503 std::getline( iss2, remaining );
1504
1505 // Check for pinnum in remaining tokens
1506 std::istringstream rem_ss( remaining );
1507 int pinnum_val = -1;
1508
1509 if( rem_ss >> pinnum_val )
1510 item.pinnum = pinnum_val;
1511 }
1512
1513 // Parse restrictions for keepout pieces (KPTCLS, KPTCIR)
1514 if( type.find( "KPT" ) == 0 )
1515 {
1516 std::string restrictions;
1517
1518 if( iss2 >> restrictions )
1519 item.restrictions = restrictions;
1520 }
1521
1522 for( int j = 0; j < corners; ++j )
1523 {
1524 if( !readLine( aStream, line ) )
1525 break;
1526
1527 std::stringstream iss3( line );
1528 double px = 0.0, py = 0.0;
1529
1530 if( !( iss3 >> px >> py ) )
1531 continue;
1532
1533 // Per PADS spec, arc format is: x1 y1 ab aa ax1 ay1 ax2 ay2
1534 // where x1,y1 = arc start point, ab = begin angle (tenths of deg),
1535 // aa = sweep angle (tenths of deg), ax1,ay1/ax2,ay2 = bounding box
1536 int startAngleTenths = 0, deltaAngleTenths = 0;
1537 double bboxMinX = 0.0, bboxMinY = 0.0, bboxMaxX = 0.0, bboxMaxY = 0.0;
1538
1539 if( iss3 >> startAngleTenths >> deltaAngleTenths
1540 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY )
1541 {
1542 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
1543 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
1544 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
1545 double startAngle = startAngleTenths / 10.0;
1546 double deltaAngle = deltaAngleTenths / 10.0;
1547
1548 // Calculate arc start point (center + radius at start angle)
1549 double startAngleRad = startAngle * M_PI / 180.0;
1550 double startX = cx + radius * std::cos( startAngleRad );
1551 double startY = cy + radius * std::sin( startAngleRad );
1552
1553 // Calculate arc endpoint (center + radius at end angle)
1554 double endAngleRad = ( startAngle + deltaAngle ) * M_PI / 180.0;
1555 double endX = cx + radius * std::cos( endAngleRad );
1556 double endY = cy + radius * std::sin( endAngleRad );
1557
1558 // Add arc start as a regular point (connects from previous point)
1559 item.points.emplace_back( startX, startY );
1560
1561 ARC arc{};
1562 arc.cx = cx;
1563 arc.cy = cy;
1564 arc.radius = radius;
1565 arc.start_angle = startAngle;
1566 arc.delta_angle = deltaAngle;
1567
1568 // Add arc end with arc data (draws the arc from start to end)
1569 item.points.emplace_back( endX, endY, arc );
1570 }
1571 else
1572 {
1573 item.points.emplace_back( px, py );
1574 }
1575 }
1576
1577 decal.items.push_back( item );
1578 }
1579
1580 // Parse Text/Labels
1581 // V9+ format: 3 lines per entry (VALUE line, font line, name line)
1582 // V5.x format: 2 lines per entry (VALUE line, name line, no font)
1583
1584 for( int i = 0; i < text_cnt + labels; ++i )
1585 {
1586 std::string attrLine, fontLine, nameLine;
1587
1588 if( !readLine( aStream, attrLine ) )
1589 break;
1590
1591 if( m_has_font_lines )
1592 {
1593 if( !readLine( aStream, fontLine ) )
1594 break;
1595 }
1596
1597 if( !readLine( aStream, nameLine ) )
1598 break;
1599
1600 ATTRIBUTE attr;
1601 std::stringstream ss( attrLine );
1602 std::string type_token;
1603 ss >> type_token;
1604
1605 std::string mirrored_str, right_reading_str;
1606
1607 if( ss >> attr.x >> attr.y >> attr.orientation >> attr.level
1608 >> attr.height >> attr.width >> mirrored_str >> attr.hjust >> attr.vjust )
1609 {
1610 attr.visible = ( type_token == "VALUE" || type_token == "FULL_NAME"
1611 || type_token == "NAME" || type_token == "FULL_BOTH"
1612 || type_token == "BOTH" );
1613 attr.mirrored = ( mirrored_str == "M" );
1614 ss >> right_reading_str;
1615 attr.right_reading = ( right_reading_str == "Y" || right_reading_str == "ORTHO" );
1616 }
1617
1618 attr.font_info = fontLine;
1619 attr.name = nameLine;
1620
1621 decal.attributes.push_back( attr );
1622 }
1623
1624 // Parse Terminals (T lines)
1625 // T-150 -110 -150 -110 1
1626 // Format: T X Y NMX NMY [PINNUM]
1627 // The T prefix is concatenated with the X coordinate (e.g. "T-150").
1628 // V5.x omits the pin number; V9+ includes it.
1629
1630 for( int i = 0; i < terminals; ++i )
1631 {
1632 if( !readLine( aStream, line ) ) break;
1633
1634 size_t t_pos = line.find( 'T' );
1635
1636 if( t_pos != std::string::npos )
1637 line[t_pos] = ' ';
1638
1639 std::stringstream iss_t( line );
1640 TERMINAL term;
1641 double nmx = 0.0, nmy = 0.0;
1642
1643 if( iss_t >> term.x >> term.y >> nmx >> nmy )
1644 {
1645 iss_t >> term.name;
1646
1647 if( term.name.empty() )
1648 term.name = std::to_string( i + 1 );
1649
1650 decal.terminals.push_back( term );
1651 }
1652 }
1653
1654 // Parse Stacks (PAD definitions)
1655 // PAD <PIN_INDEX> <STACK_LINES>
1656 // Then <STACK_LINES> lines of data.
1657
1658 for( int i = 0; i < stacks; ++i )
1659 {
1660 if( !readLine( aStream, line ) )
1661 break;
1662
1663 std::stringstream iss_pad( line );
1664 std::string token;
1665 int pin_idx = 0;
1666 int stack_lines = 0;
1667 iss_pad >> token >> pin_idx >> stack_lines;
1668
1669 if( token != "PAD" )
1670 continue;
1671
1672 // Parse optional P (plated) or N (non-plated) after stack_lines
1673 std::string plated_token;
1674 bool default_plated = true;
1675 double header_drill = 0.0;
1676
1677 if( iss_pad >> plated_token )
1678 {
1679 if( plated_token == "P" )
1680 default_plated = true;
1681 else if( plated_token == "N" )
1682 default_plated = false;
1683 else
1684 {
1685 header_drill = PADS_COMMON::ParseDouble( plated_token, 0.0, "pad drill" );
1686 }
1687 }
1688
1689 // Parse optional slotted drill parameters from header
1690 double header_slot_ori = 0.0;
1691 double header_slot_len = 0.0;
1692 double header_slot_off = 0.0;
1693
1694 if( iss_pad >> header_slot_ori >> header_slot_len >> header_slot_off )
1695 {
1696 // Got slotted drill from header
1697 }
1698
1699 std::vector<PAD_STACK_LAYER> stack;
1700
1701 for( int j = 0; j < stack_lines; ++j )
1702 {
1703 if( !readLine( aStream, line ) )
1704 break;
1705
1706 std::stringstream line_ss( line );
1707
1708 int layer = 0;
1709 double size = 0.0;
1710 std::string shape;
1711
1712 if( !( line_ss >> layer >> size >> shape ) )
1713 continue;
1714
1715 PAD_STACK_LAYER layer_data;
1716 layer_data.layer = layer;
1717 layer_data.sizeA = size;
1718 layer_data.sizeB = size;
1719 layer_data.shape = shape;
1720 layer_data.plated = default_plated;
1721 layer_data.drill = header_drill;
1722 layer_data.slot_orientation = header_slot_ori;
1723 layer_data.slot_length = header_slot_len;
1724 layer_data.slot_offset = header_slot_off;
1725
1726 // Parse shape-specific parameters per PADS specification
1727 if( shape == "R" )
1728 {
1729 // Round pad: level size R
1730 // No additional shape params, may have drill after
1731 }
1732 else if( shape == "S" )
1733 {
1734 // Square pad: level size S [corner]
1735 // Negative corner = chamfered, positive = rounded, zero = square
1736 double corner = 0.0;
1737
1738 if( line_ss >> corner )
1739 {
1740 if( corner < 0 )
1741 {
1742 layer_data.corner_radius = -corner;
1743 layer_data.chamfered = true;
1744 }
1745 else
1746 {
1747 layer_data.corner_radius = corner;
1748 }
1749 }
1750 }
1751 else if( shape == "RA" || shape == "SA" )
1752 {
1753 // Anti-pad shapes: level size RA/SA (no additional params)
1754 // These define clearance shapes in plane layers
1755 }
1756 else if( shape == "A" )
1757 {
1758 // Annular pad: level size A inner_diameter
1759 double intd = 0.0;
1760
1761 if( line_ss >> intd )
1762 layer_data.inner_diameter = intd;
1763 }
1764 else if( shape == "OF" )
1765 {
1766 // Oval finger: level size OF orientation length offset
1767 double ori = 0.0, length = 0.0, offset = 0.0;
1768
1769 if( line_ss >> ori >> length >> offset )
1770 {
1771 layer_data.rotation = ori;
1772 layer_data.sizeB = length;
1773 layer_data.finger_offset = offset;
1774 }
1775 }
1776 else if( shape == "RF" )
1777 {
1778 // Rectangular finger: level size RF orientation length offset [corner]
1779 // Per PADS spec, corner radius exists for square and rectangular finger shapes.
1780 double ori = 0.0, length = 0.0, offset = 0.0;
1781
1782 if( line_ss >> ori >> length >> offset )
1783 {
1784 layer_data.rotation = ori;
1785 layer_data.sizeB = length;
1786 layer_data.finger_offset = offset;
1787
1788 double corner = 0.0;
1789
1790 if( line_ss >> corner )
1791 {
1792 if( corner < 0 )
1793 {
1794 layer_data.corner_radius = -corner;
1795 layer_data.chamfered = true;
1796 }
1797 else
1798 {
1799 layer_data.corner_radius = corner;
1800 }
1801 }
1802 }
1803 }
1804 else if( shape == "RT" || shape == "ST" )
1805 {
1806 // Thermal pads: level size RT/ST orientation inner_diam spoke_width spoke_count
1807 double ori = 0.0, outsize = 0.0, spkwid = 0.0;
1808 int spknum = 4;
1809
1810 if( line_ss >> ori >> outsize >> spkwid >> spknum )
1811 {
1812 layer_data.thermal_spoke_orientation = ori;
1813 layer_data.thermal_outer_diameter = outsize;
1814 layer_data.thermal_spoke_width = spkwid;
1815 layer_data.thermal_spoke_count = spknum;
1816 }
1817 }
1818 else if( shape == "O" || shape == "OC" )
1819 {
1820 // Odd shape (O) or Odd Circle (OC): level size shape
1821 // These use custom pad shapes defined elsewhere
1822 // No additional parameters, just store the shape type
1823 }
1824 else if( shape == "RC" )
1825 {
1826 // Rectangular with Corner: level size RC orientation length offset [corner]
1827 // Similar to RF but with optional corner radius
1828 double ori = 0.0, length = 0.0, offset = 0.0, corner = 0.0;
1829
1830 if( line_ss >> ori >> length >> offset )
1831 {
1832 layer_data.rotation = ori;
1833 layer_data.sizeB = length;
1834 layer_data.finger_offset = offset;
1835
1836 if( line_ss >> corner )
1837 {
1838 if( corner < 0 )
1839 {
1840 layer_data.corner_radius = -corner;
1841 layer_data.chamfered = true;
1842 }
1843 else
1844 {
1845 layer_data.corner_radius = corner;
1846 }
1847 }
1848 }
1849 }
1850
1851 // For some shapes, additional tokens may be drill and plated
1852 // Read remaining tokens
1853 std::vector<std::string> remaining;
1854 std::string token_rem;
1855
1856 while( line_ss >> token_rem )
1857 remaining.push_back( token_rem );
1858
1859 // Parse remaining tokens for drill, plated, and slotted drill
1860 if( !remaining.empty() )
1861 {
1862 size_t idx = 0;
1863
1864 // Check for drill value (numeric)
1865 double drill_val = PADS_COMMON::ParseDouble( remaining[idx],
1866 -1.0, "pad layer drill" );
1867
1868 if( drill_val >= 0.0 )
1869 {
1870 layer_data.drill = drill_val;
1871 idx++;
1872 }
1873
1874 // Check for plated flag
1875 if( idx < remaining.size() )
1876 {
1877 if( remaining[idx] == "P" || remaining[idx] == "Y" )
1878 {
1879 layer_data.plated = true;
1880 idx++;
1881 }
1882 else if( remaining[idx] == "N" )
1883 {
1884 layer_data.plated = false;
1885 idx++;
1886 }
1887 }
1888
1889 // Check for slotted drill parameters
1890 if( idx + 2 < remaining.size() )
1891 {
1892 layer_data.slot_orientation =
1893 PADS_COMMON::ParseDouble( remaining[idx], 0.0, "slot params" );
1894 layer_data.slot_length =
1895 PADS_COMMON::ParseDouble( remaining[idx + 1], 0.0, "slot params" );
1896 layer_data.slot_offset =
1897 PADS_COMMON::ParseDouble( remaining[idx + 2], 0.0, "slot params" );
1898 }
1899 }
1900
1901 stack.push_back( layer_data );
1902 }
1903
1904 decal.pad_stacks[pin_idx] = stack;
1905 }
1906
1907 m_decals[name] = decal;
1908 }
1909}
1910
1911void PARSER::parseSectionROUTES( std::ifstream& aStream )
1912{
1913 std::string line;
1914 ROUTE* current_route = nullptr;
1915 TRACK current_track;
1916 bool in_track = false;
1917 bool prev_is_plane_connection = false;
1918 ARC_POINT last_plane_connection_pt;
1919 int last_plane_connection_layer = 0;
1920 double last_plane_connection_width = 0;
1921 bool last_plane_on_copper = false;
1922 std::string default_via_name;
1923 bool has_pending_arc_center = false;
1924 ARC_POINT pending_arc_center;
1925 std::string pending_arc_dir;
1926
1927 while( readLine( aStream, line ) )
1928 {
1929 if( line[0] == '*' )
1930 {
1931 if( line.rfind( "*SIGNAL*", 0 ) == 0 )
1932 {
1933 if( in_track && current_route )
1934 {
1935 current_route->tracks.push_back( current_track );
1936 current_track.points.clear();
1937 in_track = false;
1938 }
1939
1940 prev_is_plane_connection = false;
1941 has_pending_arc_center = false;
1942
1943 std::istringstream iss( line );
1944 std::string token;
1945 iss >> token; // *SIGNAL*
1946
1947 std::string net_name;
1948 iss >> net_name;
1949
1950 // Parse optional flags and default via
1951 default_via_name.clear();
1952
1953 while( iss >> token )
1954 {
1955 if( !token.empty() && token.back() == ';' )
1956 token.pop_back();
1957
1958 if( m_via_defs.count( token ) )
1959 default_via_name = token;
1960 }
1961
1962 m_routes.push_back( ROUTE() );
1963 current_route = &m_routes.back();
1964 current_route->net_name = net_name;
1965 continue;
1966 }
1967
1968 pushBackLine( line );
1969 break;
1970 }
1971
1972 // Parse pin pair lines (start with non-digit/non-sign)
1973 // Format: "REF.PIN REF.PIN"
1974 // These indicate which pins are connected by the following route segments
1975 if( !isdigit( line[0] ) && line[0] != '-' && line[0] != '+' )
1976 {
1977 if( in_track && current_route )
1978 {
1979 current_route->tracks.push_back( current_track );
1980 current_track.points.clear();
1981 in_track = false;
1982 }
1983
1984 prev_is_plane_connection = false;
1985
1986 // Parse pin pairs from this line and add to current route
1987 if( current_route )
1988 {
1989 std::istringstream pin_iss( line );
1990 std::string pin_token;
1991
1992 while( pin_iss >> pin_token )
1993 {
1994 size_t dot_pos = pin_token.find( '.' );
1995
1996 if( dot_pos != std::string::npos )
1997 {
1998 NET_PIN pin;
1999 pin.ref_des = pin_token.substr( 0, dot_pos );
2000 pin.pin_name = pin_token.substr( dot_pos + 1 );
2001
2002 // Check if pin already exists (avoid duplicates)
2003 bool found = false;
2004
2005 for( const auto& existing : current_route->pins )
2006 {
2007 if( existing.ref_des == pin.ref_des &&
2008 existing.pin_name == pin.pin_name )
2009 {
2010 found = true;
2011 break;
2012 }
2013 }
2014
2015 if( !found )
2016 current_route->pins.push_back( pin );
2017 }
2018 }
2019 }
2020
2021 continue;
2022 }
2023
2024 std::istringstream iss( line );
2025 ARC_POINT pt;
2026 int layer = 0;
2027 double width = 0.0;
2028 int flags = 0;
2029 iss >> pt.x >> pt.y >> layer >> width >> flags;
2030
2031 if( iss.fail() )
2032 continue;
2033
2034 // SEGMENTWIDTH is already in mils (not 1/256 mil units as previously thought)
2035
2036 // Parse FLAGS and optional arc direction / via name
2037 // Format: FLAGS [ARCDIR/VIANAME] [POWER] [TEARDROP ...] [JUMPER ...]
2038 // ARCDIR can be CW (clockwise) or CCW (counter-clockwise)
2039 // POWER indicates a connection through a power/ground plane (not a discrete track)
2040 std::string token;
2041 std::string via_name;
2042 std::string arc_dir;
2043
2044 // Per PADS spec, layer 0 means "unrouted portion" (virtual connection through
2045 // a plane or ratline). Only layer 0 makes a segment non-physical. Flag 0x100
2046 // ("plane thermal") and the THERMAL keyword describe pad/via thermal relief
2047 // style and do not affect whether the track segment exists.
2048 bool is_unrouted = ( layer == 0 );
2049 bool is_plane_connection = is_unrouted;
2050 TEARDROP teardrop;
2051 JUMPER_MARKER jumper;
2052 bool has_teardrop = false;
2053 bool has_jumper = false;
2054 bool has_power = false;
2055
2056 while( iss >> token )
2057 {
2058 // Check for arc direction
2059 if( token == "CW" || token == "CCW" )
2060 {
2061 arc_dir = token;
2062 continue;
2063 }
2064
2065 // POWER indicates a connection through a power/ground plane.
2066 // In PADS files, "POWER" often doubles as a via definition name.
2067 // THERMAL describes pad/via thermal relief style.
2068 if( token == "POWER" )
2069 {
2070 has_power = true;
2071
2072 if( m_via_defs.count( token ) )
2073 via_name = token;
2074
2075 continue;
2076 }
2077
2078 if( token == "THERMAL" )
2079 continue;
2080
2081 // Check for via name
2082 if( m_via_defs.count( token ) )
2083 {
2084 via_name = token;
2085 continue;
2086 }
2087
2088 // Parse TEARDROP: TEARDROP [P width length [flags]] [N width length [flags]]
2089 if( token == "TEARDROP" )
2090 {
2091 has_teardrop = true;
2092 std::string td_token;
2093
2094 while( iss >> td_token )
2095 {
2096 if( td_token == "P" )
2097 {
2098 teardrop.has_pad_teardrop = true;
2099 iss >> teardrop.pad_width >> teardrop.pad_length;
2100
2101 // Check for optional flags (numeric)
2102 std::streampos pos = iss.tellg();
2103 int td_flags = 0;
2104
2105 if( iss >> td_flags )
2106 {
2107 teardrop.pad_flags = td_flags;
2108 }
2109 else
2110 {
2111 iss.clear();
2112 iss.seekg( pos );
2113 }
2114 }
2115 else if( td_token == "N" )
2116 {
2117 teardrop.has_net_teardrop = true;
2118 iss >> teardrop.net_width >> teardrop.net_length;
2119
2120 std::streampos pos = iss.tellg();
2121 int td_flags = 0;
2122
2123 if( iss >> td_flags )
2124 {
2125 teardrop.net_flags = td_flags;
2126 }
2127 else
2128 {
2129 iss.clear();
2130 iss.seekg( pos );
2131 }
2132 }
2133 else
2134 {
2135 // Not a teardrop param, push back for further parsing
2136 // Since we can't push back easily, break and handle below
2137 if( td_token == "CW" || td_token == "CCW" )
2138 arc_dir = td_token;
2139 else if( td_token == "POWER" )
2140 {
2141 has_power = true;
2142
2143 if( m_via_defs.count( td_token ) )
2144 via_name = td_token;
2145 }
2146 else if( td_token == "THERMAL" )
2147 ;
2148 else if( m_via_defs.count( td_token ) )
2149 via_name = td_token;
2150
2151 break;
2152 }
2153 }
2154
2155 continue;
2156 }
2157
2158 // Parse JUMPER: jumper_name S|E
2159 // Jumper names are typically followed by S (start) or E (end)
2160 std::streampos pos = iss.tellg();
2161 std::string jumper_flag;
2162
2163 if( iss >> jumper_flag )
2164 {
2165 if( jumper_flag == "S" || jumper_flag == "E" )
2166 {
2167 has_jumper = true;
2168 jumper.name = token;
2169 jumper.is_start = ( jumper_flag == "S" );
2170 jumper.x = pt.x;
2171 jumper.y = pt.y;
2172 continue;
2173 }
2174 else
2175 {
2176 // Not a jumper, restore stream position
2177 iss.clear();
2178 iss.seekg( pos );
2179 }
2180 }
2181 else
2182 {
2183 iss.clear();
2184 iss.seekg( pos );
2185 }
2186
2187 // Skip REUSE tokens
2188 if( token == "REUSE" || token == ".REUSE." )
2189 {
2190 // Skip the instance name that follows
2191 std::string instance;
2192 iss >> instance;
2193 continue;
2194 }
2195 }
2196
2197 // A corner carrying an arc direction is the arc's center, not a track vertex.
2198 // Per the PADS ASCII spec the arc begins on the preceding corner and ends on
2199 // the following one, curving around this corner. Defer it and attach explicit
2200 // geometry to the next corner.
2201 if( !arc_dir.empty() )
2202 {
2203 pending_arc_center = pt;
2204 pending_arc_dir = arc_dir;
2205 has_pending_arc_center = true;
2206 continue;
2207 }
2208
2209 if( has_pending_arc_center )
2210 {
2211 has_pending_arc_center = false;
2212
2213 if( in_track && !current_track.points.empty() )
2214 {
2215 const ARC_POINT& arc_start = current_track.points.back();
2216 double dx0 = arc_start.x - pending_arc_center.x;
2217 double dy0 = arc_start.y - pending_arc_center.y;
2218 double start_angle = std::atan2( dy0, dx0 );
2219 double end_angle =
2220 std::atan2( pt.y - pending_arc_center.y, pt.x - pending_arc_center.x );
2221 double sweep = end_angle - start_angle;
2222
2223 // atan2 differences land in (-2pi, 2pi); pull the sweep onto the arc's
2224 // side so the winding matches the recorded direction.
2225 if( pending_arc_dir == "CCW" )
2226 {
2227 while( sweep <= 0.0 )
2228 sweep += 2.0 * M_PI;
2229 }
2230 else
2231 {
2232 while( sweep >= 0.0 )
2233 sweep -= 2.0 * M_PI;
2234 }
2235
2236 pt.is_arc = true;
2237 pt.arc.cx = pending_arc_center.x;
2238 pt.arc.cy = pending_arc_center.y;
2239 pt.arc.radius = std::sqrt( dx0 * dx0 + dy0 * dy0 );
2240 pt.arc.start_angle = start_angle * 180.0 / M_PI;
2241 pt.arc.delta_angle = sweep * 180.0 / M_PI;
2242 }
2243 }
2244
2245 // Per PADS spec: Layer 0 means "unrouted portion" - these are NOT physical tracks.
2246 // Layer 65 indicates the end of route/connection at a component pin.
2247 // Vias are only created when an explicit via token (STANDARDVIA, etc.) is present.
2248
2249 int effective_layer = layer;
2250 bool is_pad_connection = ( layer == 65 );
2251
2252 // Layer 0 means "unrouted" - this segment goes through a plane or is a ratline.
2253 // We still need an effective layer for via purposes, so use current track layer if available.
2254 if( is_unrouted && in_track )
2255 effective_layer = current_track.layer;
2256
2257 // Create via at this point if a via token was present.
2258 // This must happen before plane connection handling since plane connection points
2259 // with vias (STANDARDVIA + THERMAL) would otherwise skip via creation.
2260 if( !via_name.empty() && current_route )
2261 {
2262 VIA via;
2263 via.name = via_name;
2264 via.location = { pt.x, pt.y };
2265 current_route->vias.push_back( via );
2266 }
2267
2268 // POWER on a real copper layer means a via to the inner power/ground plane.
2269 // Routes often stub out to a POWER point and backtrack, with the via providing
2270 // the connection to the plane. Normally the POWER token itself names a via
2271 // definition (handled above), but if not, create an implicit via with the
2272 // route's default via type.
2273 if( has_power && via_name.empty() && !is_unrouted && !is_pad_connection && current_route )
2274 {
2275 VIA implicit_via;
2276
2277 if( !default_via_name.empty() )
2278 implicit_via.name = default_via_name;
2279 else if( !m_parameters.default_signal_via.empty() )
2280 implicit_via.name = m_parameters.default_signal_via;
2281
2282 implicit_via.location = { pt.x, pt.y };
2283 current_route->vias.push_back( implicit_via );
2284 }
2285
2286 // Store teardrop if present
2287 if( has_teardrop && current_route )
2288 {
2289 current_route->teardrops.push_back( teardrop );
2290 }
2291
2292 // Store jumper marker if present
2293 if( has_jumper && current_route )
2294 {
2295 current_route->jumpers.push_back( jumper );
2296 }
2297
2298 // Handle plane connections (POWER or THERMAL markers)
2299 // Segments between consecutive plane connection points are virtual connections through
2300 // copper pours and should not be created as discrete tracks.
2301 if( is_plane_connection && prev_is_plane_connection )
2302 {
2303 // Both current and previous points are plane connections - skip this segment.
2304 // The connection is made through the copper pour, not a discrete track.
2305 // Save this point as a potential track start/end if it's on a real copper layer
2306 // (not layer 0 / unrouted). Copper-layer plane points are where signals transition
2307 // between physical tracks and the pour.
2308 if( !is_unrouted )
2309 {
2310 last_plane_connection_pt = pt;
2311 last_plane_connection_layer = effective_layer;
2312 last_plane_connection_width = width;
2313 last_plane_on_copper = true;
2314 }
2315
2316 prev_is_plane_connection = true;
2317 continue;
2318 }
2319
2320 if( is_plane_connection && !prev_is_plane_connection )
2321 {
2322 // Transitioning from track to plane - add this point to complete the track
2323 // then end the track (no further segments until we exit the plane)
2324 if( in_track )
2325 {
2326 current_track.points.push_back( pt );
2327
2328 if( current_route && current_track.points.size() > 1 )
2329 current_route->tracks.push_back( current_track );
2330
2331 current_track.points.clear();
2332 in_track = false;
2333 }
2334
2335 // Save this plane connection point as a potential track start for the next
2336 // non-plane segment, if it's on a real copper layer (not layer 0 / unrouted).
2337 // Copper-layer plane points mark where signals transition between tracks and pours.
2338 last_plane_on_copper = !is_unrouted;
2339
2340 if( last_plane_on_copper )
2341 {
2342 last_plane_connection_pt = pt;
2343 last_plane_connection_layer = effective_layer;
2344 last_plane_connection_width = width;
2345 }
2346
2347 prev_is_plane_connection = true;
2348 continue;
2349 }
2350
2351 if( !is_plane_connection && prev_is_plane_connection )
2352 {
2353 // Transitioning from plane to track. Start a new track from the last copper-layer
2354 // plane point if it was on the same layer as the current point.
2355 if( in_track && current_route && current_track.points.size() > 1 )
2356 current_route->tracks.push_back( current_track );
2357
2358 prev_is_plane_connection = false;
2359
2360 if( is_pad_connection )
2361 {
2362 in_track = false;
2363 continue;
2364 }
2365
2366 current_track.points.clear();
2367
2368 if( last_plane_on_copper && last_plane_connection_layer == effective_layer )
2369 {
2370 current_track.layer = effective_layer;
2371 current_track.width = std::max( width, last_plane_connection_width );
2372 current_track.points.push_back( last_plane_connection_pt );
2373 current_track.points.push_back( pt );
2374 }
2375 else
2376 {
2377 // Layers differ. Create an implicit via if same location.
2378 // POWER vias are already handled by the central POWER handler above.
2379 if( !has_power && via_name.empty() && current_route && last_plane_on_copper &&
2380 std::abs( pt.x - last_plane_connection_pt.x ) < 0.001 &&
2381 std::abs( pt.y - last_plane_connection_pt.y ) < 0.001 )
2382 {
2383 VIA implicit_via;
2384
2385 if( !default_via_name.empty() )
2386 implicit_via.name = default_via_name;
2387 else if( !m_parameters.default_signal_via.empty() )
2388 implicit_via.name = m_parameters.default_signal_via;
2389
2390 implicit_via.location = { pt.x, pt.y };
2391 current_route->vias.push_back( implicit_via );
2392 }
2393
2394 current_track.layer = effective_layer;
2395 current_track.width = width;
2396 current_track.points.push_back( pt );
2397 }
2398
2399 last_plane_on_copper = false;
2400 in_track = true;
2401 continue;
2402 }
2403
2404 // Layer 65 is a special pad connection marker. Add the final point to terminate the
2405 // track at the pad, then stop building this track segment.
2406 if( is_pad_connection )
2407 {
2408 if( in_track && !current_track.points.empty() )
2409 {
2410 current_track.points.push_back( pt );
2411
2412 if( current_route && current_track.points.size() > 1 )
2413 current_route->tracks.push_back( current_track );
2414
2415 current_track.points.clear();
2416 in_track = false;
2417 }
2418
2419 continue;
2420 }
2421
2422 // Normal track building (neither current nor previous is plane connection)
2423 prev_is_plane_connection = false;
2424
2425 if( !in_track )
2426 {
2427 current_track.layer = effective_layer;
2428 current_track.width = width;
2429 current_track.points.clear();
2430 current_track.points.push_back( pt );
2431 in_track = true;
2432 }
2433 else
2434 {
2435 bool layer_changed = ( effective_layer != current_track.layer );
2436 bool width_changed = ( std::abs( width - current_track.width ) > 0.001 );
2437
2438 if( layer_changed || width_changed )
2439 {
2440 // Check if we should connect to this point
2441 bool connect = true;
2442
2443 if( layer_changed && via_name.empty() )
2444 {
2445 bool same_location =
2446 ( pt.x == current_track.points.back().x &&
2447 pt.y == current_track.points.back().y );
2448
2449 if( same_location )
2450 {
2451 // Same location layer change implies an implicit via.
2452 // POWER vias are already created in the central POWER handler.
2453 if( !has_power && current_route )
2454 {
2455 VIA implicit_via;
2456 implicit_via.name =
2457 default_via_name.empty() ? "STANDARDVIA" : default_via_name;
2458 implicit_via.location = { pt.x, pt.y };
2459 current_route->vias.push_back( implicit_via );
2460 }
2461 }
2462 else if( !has_power )
2463 {
2464 // Different location without POWER, treat as jump/ratline
2465 connect = false;
2466 }
2467 // POWER at different location: via already created, keep connected
2468 }
2469
2470 if( connect )
2471 {
2472 current_track.points.push_back( pt );
2473 }
2474
2475 if( current_route )
2476 current_route->tracks.push_back( current_track );
2477
2478 // Start new track from current point
2479 ARC_POINT prev_pt = pt;
2480
2481 current_track.layer = effective_layer;
2482 current_track.width = width;
2483 current_track.points.clear();
2484 current_track.points.push_back( prev_pt );
2485 }
2486 else
2487 {
2488 current_track.points.push_back( pt );
2489 }
2490 }
2491 }
2492
2493 if( in_track && current_route )
2494 {
2495 current_route->tracks.push_back( current_track );
2496 }
2497}
2498
2499void PARSER::parseSectionTEXT( std::ifstream& aStream )
2500{
2501 std::string line;
2502
2503 while( readLine( aStream, line ) )
2504 {
2505 if( line[0] == '*' )
2506 {
2507 pushBackLine( line );
2508 break;
2509 }
2510
2511 // Format: X Y ORI LEVEL HEIGHT WIDTH M HJUST VJUST [NDIM] [.REUSE. instance]
2512 // HJUST: LEFT, CENTER, RIGHT
2513 // VJUST: UP, CENTER, DOWN
2514 std::istringstream iss( line );
2515 TEXT text;
2516
2517 iss >> text.location.x >> text.location.y >> text.rotation >> text.layer
2518 >> text.height >> text.width;
2519
2520 if( iss.fail() )
2521 continue;
2522
2523 std::string mirrored;
2524 iss >> mirrored;
2525 text.mirrored = ( mirrored == "M" );
2526
2527 // Parse optional hjust and vjust
2528 iss >> text.hjust >> text.vjust;
2529
2530 // Parse optional ndim and .REUSE. instance
2531 std::string token;
2532
2533 if( iss >> token )
2534 {
2535 if( token == ".REUSE." )
2536 {
2537 iss >> text.reuse_instance;
2538 }
2539 else
2540 {
2541 text.ndim = PADS_COMMON::ParseInt( token, 0, "text ndim" );
2542
2543 if( iss >> token && token == ".REUSE." )
2544 {
2545 iss >> text.reuse_instance;
2546 }
2547 }
2548 }
2549
2550 if( m_has_font_lines )
2551 {
2552 // Read Font line
2553 // Format: fontstyle[:fontheight:fontdescent] fontface
2554 if( readLine( aStream, line ) )
2555 {
2556 std::istringstream fiss( line );
2557 std::string font_style_part;
2558
2559 fiss >> font_style_part;
2560
2561 size_t colon_pos = font_style_part.find( ':' );
2562
2563 if( colon_pos != std::string::npos )
2564 {
2565 text.font_style = font_style_part.substr( 0, colon_pos );
2566 std::string remaining = font_style_part.substr( colon_pos + 1 );
2567
2568 size_t second_colon = remaining.find( ':' );
2569
2570 if( second_colon != std::string::npos )
2571 {
2572 text.font_height = PADS_COMMON::ParseDouble(
2573 remaining.substr( 0, second_colon ), 0.0, "font height" );
2574 text.font_descent = PADS_COMMON::ParseDouble(
2575 remaining.substr( second_colon + 1 ), 0.0, "font descent" );
2576 }
2577 else
2578 {
2579 text.font_height =
2580 PADS_COMMON::ParseDouble( remaining, 0.0, "font height" );
2581 }
2582 }
2583 else
2584 {
2585 text.font_style = font_style_part;
2586 }
2587
2588 size_t bracket_start = line.find( '<' );
2589 size_t bracket_end = line.find( '>' );
2590
2591 if( bracket_start != std::string::npos && bracket_end != std::string::npos )
2592 {
2593 text.font_face =
2594 line.substr( bracket_start + 1, bracket_end - bracket_start - 1 );
2595 }
2596 else
2597 {
2598 std::string rest;
2599 std::getline( fiss, rest );
2600
2601 if( !rest.empty() && rest[0] == ' ' )
2602 rest = rest.substr( 1 );
2603
2604 text.font_face = rest;
2605 }
2606 }
2607 }
2608
2609 // Read Content line
2610 if( readLine( aStream, line ) )
2611 {
2612 // Standard PADS format uses literal backslash-n for line breaks
2613 size_t pos = 0;
2614
2615 while( ( pos = line.find( "\\n", pos ) ) != std::string::npos )
2616 {
2617 line.replace( pos, 2, "\n" );
2618 pos += 1;
2619 }
2620
2621 // EasyEDA exports (mode "250L") encode newlines as underscores
2622 if( m_file_header.mode == "250L" )
2623 std::replace( line.begin(), line.end(), '_', '\n' );
2624
2625 text.content = line;
2626 m_texts.push_back( text );
2627 }
2628 }
2629}
2630
2631void PARSER::parseSectionBOARD( std::ifstream& aStream )
2632{
2633 // The *BOARD* section uses the same format as LINES section with linetype=BOARD
2634 // Format: name BOARD xloc yloc pieces flags [text]
2635 std::string line;
2636
2637 while( readLine( aStream, line ) )
2638 {
2639 if( line[0] == '*' )
2640 {
2641 pushBackLine( line );
2642 break;
2643 }
2644
2645 std::istringstream iss( line );
2646 std::string name, type;
2647 double xloc = 0.0, yloc = 0.0;
2648 int pieces = 0;
2649 iss >> name >> type >> xloc >> yloc >> pieces;
2650
2651 // Parse all pieces for this board outline entry
2652 for( int i = 0; i < pieces; ++i )
2653 {
2654 if( !readLine( aStream, line ) )
2655 break;
2656
2657 if( line[0] == '*' )
2658 {
2659 pushBackLine( line );
2660 return;
2661 }
2662
2663 std::istringstream piss( line );
2664 std::string shape_type;
2665 int corners = 0;
2666 double width = 0.0;
2667 int linestyle = 0, level = 0;
2668 piss >> shape_type >> corners >> width >> linestyle >> level;
2669
2670 // Handle CLOSED, OPEN, CIRCLE, BRDCLS (board cutout), BRDCIR (circular cutout)
2671 if( shape_type == "CLOSED" || shape_type == "OPEN" || shape_type == "BRDCLS" )
2672 {
2673 POLYLINE polyline;
2674 polyline.layer = 0;
2675 polyline.width = width;
2676 polyline.closed = ( shape_type == "CLOSED" || shape_type == "BRDCLS" );
2677
2678 for( int j = 0; j < corners; ++j )
2679 {
2680 if( !readLine( aStream, line ) )
2681 break;
2682
2683 if( line[0] == '*' )
2684 {
2685 pushBackLine( line );
2686 return;
2687 }
2688
2689 std::istringstream ciss( line );
2690 double dx = 0.0, dy = 0.0;
2691 ciss >> dx >> dy;
2692
2693 // Per PADS spec, arc format is: x1 y1 ab aa ax1 ay1 ax2 ay2
2694 // where x1,y1 = arc start point; center = bounding box midpoint
2695 int startAngleTenths = 0, deltaAngleTenths = 0;
2696 double bboxMinX = 0.0, bboxMinY = 0.0, bboxMaxX = 0.0, bboxMaxY = 0.0;
2697
2698 if( ciss >> startAngleTenths >> deltaAngleTenths
2699 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY )
2700 {
2701 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
2702 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
2703 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
2704 double startAngle = startAngleTenths / 10.0;
2705 double deltaAngle = deltaAngleTenths / 10.0;
2706
2707 double startAngleRad = startAngle * M_PI / 180.0;
2708 double startX = cx + radius * std::cos( startAngleRad );
2709 double startY = cy + radius * std::sin( startAngleRad );
2710
2711 double endAngleRad = ( startAngle + deltaAngle ) * M_PI / 180.0;
2712 double endX = cx + radius * std::cos( endAngleRad );
2713 double endY = cy + radius * std::sin( endAngleRad );
2714
2715 polyline.points.emplace_back( xloc + startX, yloc + startY );
2716
2717 ARC arc{};
2718 arc.cx = xloc + cx;
2719 arc.cy = yloc + cy;
2720 arc.radius = radius;
2721 arc.start_angle = startAngle;
2722 arc.delta_angle = deltaAngle;
2723
2724 polyline.points.emplace_back( xloc + endX, yloc + endY, arc );
2725 }
2726 else
2727 {
2728 polyline.points.emplace_back( xloc + dx, yloc + dy );
2729 }
2730 }
2731
2732 if( !polyline.points.empty() )
2733 m_board_outlines.push_back( polyline );
2734 }
2735 else if( shape_type == "CIRCLE" || shape_type == "BRDCIR" )
2736 {
2737 // Circle format: 2 coordinates define opposite ends of diameter
2738 POLYLINE polyline;
2739 polyline.layer = 0;
2740 polyline.width = width;
2741 polyline.closed = true;
2742
2743 double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
2744
2745 if( readLine( aStream, line ) )
2746 {
2747 std::istringstream c1( line );
2748 c1 >> x1 >> y1;
2749 }
2750
2751 if( corners >= 2 && readLine( aStream, line ) )
2752 {
2753 std::istringstream c2( line );
2754 c2 >> x2 >> y2;
2755 }
2756
2757 // Calculate center and radius from diameter endpoints
2758 double cx = xloc + ( x1 + x2 ) / 2.0;
2759 double cy = yloc + ( y1 + y2 ) / 2.0;
2760 double radius = std::sqrt( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) ) / 2.0;
2761
2762 // Create full circle arc
2763 ARC arc{};
2764 arc.cx = cx;
2765 arc.cy = cy;
2766 arc.radius = radius;
2767 arc.start_angle = 0.0;
2768 arc.delta_angle = 360.0;
2769
2770 polyline.points.emplace_back( cx + radius, cy, arc );
2771
2772 if( !polyline.points.empty() )
2773 m_board_outlines.push_back( polyline );
2774 }
2775 else
2776 {
2777 // Unknown shape type, skip corners
2778 for( int j = 0; j < corners; ++j )
2779 {
2780 if( !readLine( aStream, line ) )
2781 break;
2782
2783 if( line[0] == '*' )
2784 {
2785 pushBackLine( line );
2786 return;
2787 }
2788 }
2789 }
2790 }
2791 }
2792}
2793
2794void PARSER::parseSectionLINES( std::ifstream& aStream )
2795{
2796 std::string line;
2797
2798 while( readLine( aStream, line ) )
2799 {
2800 if( line[0] == '*' )
2801 {
2802 pushBackLine( line );
2803 break;
2804 }
2805
2806 // Header format: name type xloc yloc pieces flags [text] [signame]
2807 // While the docs claim `... pieces flags [text [signame]]`, and the `*REMARK*` lines our
2808 // sample files claim `... pieces text signame`, the files themselves clearly contain many
2809 // instances of `pieces flags signame`.
2810 std::istringstream iss( line );
2811 std::string name, type;
2812 double xloc = 0.0, yloc = 0.0;
2813 int pieces = 0, flags = 0, textCount = 0;
2814 std::string seventhToken, eighthToken;
2815 std::string signame;
2816
2817 iss >> name >> type >> xloc >> yloc >> pieces >> flags >> seventhToken >> eighthToken;
2818
2819 if( !eighthToken.empty() )
2820 {
2821 // If we have the full eight tokens, the last two must be text-count and signame.
2822
2823 signame = eighthToken;
2824
2825 std::istringstream tiss( seventhToken );
2826 tiss >> textCount;
2827 }
2828 else if( !seventhToken.empty() )
2829 {
2830 // Here's where it gets dicey: with seven tokens we don't know whether the last
2831 // is a text-count or a signame. We can't compare with known signal names, as
2832 // they're all later in the file. The best we can do is assume that anything that
2833 // is all digits is a text-count, and that any signame will contain at least one
2834 // symbol or letter.
2835
2836 if( std::all_of( seventhToken.begin(), seventhToken.end(),
2837 [](unsigned char c)
2838 {
2839 return std::isdigit( c );
2840 } ) )
2841 {
2842 std::istringstream tiss( seventhToken );
2843 tiss >> textCount;
2844 }
2845 else
2846 {
2847 signame = seventhToken;
2848 }
2849 }
2850
2851 // Check for optional .REUSE. line after header
2852 std::string reuse_instance, reuse_signal;
2853
2854 if( readLine( aStream, line ) )
2855 {
2856 if( line.find( ".REUSE." ) != std::string::npos )
2857 {
2858 std::istringstream riss( line );
2859 std::string reuse_keyword;
2860 riss >> reuse_keyword >> reuse_instance >> reuse_signal;
2861 }
2862 else
2863 {
2864 pushBackLine( line );
2865 }
2866 }
2867
2868 if( type == "BOARD" )
2869 {
2870 for( int i=0; i<pieces; ++i )
2871 {
2872 if( !readLine( aStream, line ) ) break;
2873 if( line[0] == '*' ) { pushBackLine( line ); return; }
2874
2875 std::istringstream piss( line );
2876 std::string shape_type;
2877 int corners = 0;
2878 double width = 0.0;
2879 int piece_flags = 0;
2880 int level = 0;
2881 piss >> shape_type >> corners >> width >> piece_flags >> level;
2882
2883 if( shape_type == "CLOSED" || shape_type == "OPEN" || shape_type == "BRDCLS" )
2884 {
2885 POLYLINE polyline;
2886 polyline.layer = 0; // Board outline is layer-agnostic
2887 polyline.width = width;
2888 polyline.closed = ( shape_type == "CLOSED" || shape_type == "BRDCLS" );
2889
2890 for( int j = 0; j < corners; ++j )
2891 {
2892 if( !readLine( aStream, line ) )
2893 break;
2894
2895 if( line[0] == '*' )
2896 {
2897 pushBackLine( line );
2898 return;
2899 }
2900
2901 std::istringstream ciss( line );
2902 double dx = 0.0, dy = 0.0;
2903 ciss >> dx >> dy;
2904
2905 // Per PADS spec, arc format is: x1 y1 ab aa ax1 ay1 ax2 ay2
2906 // where x1,y1 = arc start point; center = bounding box midpoint
2907 int startAngleTenths = 0, deltaAngleTenths = 0;
2908 double bboxMinX = 0.0, bboxMinY = 0.0, bboxMaxX = 0.0, bboxMaxY = 0.0;
2909
2910 if( ciss >> startAngleTenths >> deltaAngleTenths
2911 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY )
2912 {
2913 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
2914 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
2915 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
2916 double startAngle = startAngleTenths / 10.0;
2917 double deltaAngle = deltaAngleTenths / 10.0;
2918
2919 double startAngleRad = startAngle * M_PI / 180.0;
2920 double startX = cx + radius * std::cos( startAngleRad );
2921 double startY = cy + radius * std::sin( startAngleRad );
2922
2923 double endAngleRad = ( startAngle + deltaAngle ) * M_PI / 180.0;
2924 double endX = cx + radius * std::cos( endAngleRad );
2925 double endY = cy + radius * std::sin( endAngleRad );
2926
2927 polyline.points.emplace_back( xloc + startX, yloc + startY );
2928
2929 ARC arc{};
2930 arc.cx = xloc + cx;
2931 arc.cy = yloc + cy;
2932 arc.radius = radius;
2933 arc.start_angle = startAngle;
2934 arc.delta_angle = deltaAngle;
2935
2936 polyline.points.emplace_back( xloc + endX, yloc + endY, arc );
2937 }
2938 else
2939 {
2940 polyline.points.emplace_back( xloc + dx, yloc + dy );
2941 }
2942 }
2943
2944 if( !polyline.points.empty() )
2945 m_board_outlines.push_back( polyline );
2946 }
2947 else if( shape_type == "CIRCLE" || shape_type == "BRDCIR" )
2948 {
2949 // Circle: 2 coordinates define opposite ends of diameter
2950 double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
2951
2952 if( readLine( aStream, line ) )
2953 {
2954 std::istringstream c1( line );
2955 c1 >> x1 >> y1;
2956 }
2957
2958 if( corners >= 2 && readLine( aStream, line ) )
2959 {
2960 std::istringstream c2( line );
2961 c2 >> x2 >> y2;
2962 }
2963
2964 double cx = xloc + ( x1 + x2 ) / 2.0;
2965 double cy = yloc + ( y1 + y2 ) / 2.0;
2966 double radius = std::sqrt( ( x2 - x1 ) * ( x2 - x1 ) +
2967 ( y2 - y1 ) * ( y2 - y1 ) ) / 2.0;
2968
2969 POLYLINE polyline;
2970 polyline.layer = 0;
2971 polyline.width = width;
2972 polyline.closed = true;
2973
2974 ARC arc{};
2975 arc.cx = cx;
2976 arc.cy = cy;
2977 arc.radius = radius;
2978 arc.start_angle = 0.0;
2979 arc.delta_angle = 360.0;
2980
2981 polyline.points.emplace_back( cx + radius, cy, arc );
2982
2983 if( !polyline.points.empty() )
2984 m_board_outlines.push_back( polyline );
2985 }
2986 else
2987 {
2988 for( int j=0; j<corners; ++j )
2989 {
2990 if( !readLine( aStream, line ) ) break;
2991 if( line[0] == '*' ) { pushBackLine( line ); return; }
2992 }
2993 }
2994 }
2995 }
2996 else if( name.rfind( "DIM", 0 ) == 0 && type == "LINES" )
2997 {
2998 // Dimension annotation with BASPNT (base points), ARWLN/ARWHD (arrows),
2999 // and EXTLN (extension lines).
3000 //
3001 // BASPNT pairs define the measurement endpoints. There are typically two
3002 // BASPNT shapes: the first defines the start point (usually at origin),
3003 // and the second defines the end point as an offset from the dimension origin.
3004 //
3005 // ARWLN defines the crossbar position (Y for horizontal, X for vertical).
3006 //
3007 // For a proper linear dimension, we extract:
3008 // - Start point from first BASPNT (first coordinate of the pair)
3009 // - End point from second BASPNT (first coordinate of the pair)
3010 // - Crossbar position from ARWLN (used to compute height)
3011 DIMENSION dim;
3012 dim.name = name;
3013 dim.x = xloc;
3014 dim.y = yloc;
3015
3016 double baspnt1_x = 0, baspnt1_y = 0;
3017 double baspnt2_x = 0, baspnt2_y = 0;
3018 double arwln_x = 0, arwln_y = 0;
3019 int baspnt_count = 0;
3020 bool hasArwln = false;
3021
3022 for( int i = 0; i < pieces; ++i )
3023 {
3024 if( !readLine( aStream, line ) )
3025 break;
3026
3027 if( line[0] == '*' )
3028 {
3029 pushBackLine( line );
3030 break;
3031 }
3032
3033 std::istringstream piss( line );
3034 std::string shape_type;
3035 int corners = 0;
3036 double width = 0;
3037 int piece_flags = 0;
3038 int level = 0;
3039 piss >> shape_type >> corners >> width >> piece_flags >> level;
3040
3041 dim.layer = level;
3042
3043 for( int j = 0; j < corners; ++j )
3044 {
3045 if( !readLine( aStream, line ) )
3046 break;
3047
3048 if( line[0] == '*' )
3049 {
3050 pushBackLine( line );
3051 break;
3052 }
3053
3054 std::istringstream ciss( line );
3055 double dx = 0.0, dy = 0.0;
3056 ciss >> dx >> dy;
3057
3058 // BASPNT defines measurement endpoints. First BASPNT is start,
3059 // second BASPNT is end. Only capture the first point of each pair.
3060 if( shape_type == "BASPNT" && j == 0 )
3061 {
3062 if( baspnt_count == 0 )
3063 {
3064 baspnt1_x = xloc + dx;
3065 baspnt1_y = yloc + dy;
3066 }
3067 else if( baspnt_count == 1 )
3068 {
3069 baspnt2_x = xloc + dx;
3070 baspnt2_y = yloc + dy;
3071 }
3072
3073 baspnt_count++;
3074 }
3075
3076 // ARWLN1 first point: crossbar position
3077 if( shape_type == "ARWLN1" && j == 0 )
3078 {
3079 arwln_x = xloc + dx;
3080 arwln_y = yloc + dy;
3081 hasArwln = true;
3082 }
3083 }
3084 }
3085
3086 // Build measurement points from BASPNT positions.
3087 if( baspnt_count >= 2 )
3088 {
3089 // Determine if this is a horizontal or vertical dimension based on
3090 // which axis has the larger offset between the two BASPNT points.
3091 double dx = std::abs( baspnt2_x - baspnt1_x );
3092 double dy = std::abs( baspnt2_y - baspnt1_y );
3093 bool isHorizontal = dx > dy;
3094
3095 dim.is_horizontal = isHorizontal;
3096
3097 POINT pt1{}, pt2{};
3098 pt1.x = baspnt1_x;
3099 pt1.y = baspnt1_y;
3100 pt2.x = baspnt2_x;
3101 pt2.y = baspnt2_y;
3102
3103 // Store crossbar position for height calculation
3104 if( hasArwln )
3105 {
3106 if( isHorizontal )
3107 dim.crossbar_pos = arwln_y;
3108 else
3109 dim.crossbar_pos = arwln_x;
3110 }
3111
3112 dim.points.push_back( pt1 );
3113 dim.points.push_back( pt2 );
3114 }
3115
3116 // Parse text items for this dimension.
3117 // The first text is used as the dimension value label.
3118 for( int t = 0; t < textCount; ++t )
3119 {
3120 if( !readLine( aStream, line ) )
3121 break;
3122
3123 if( line[0] == '*' )
3124 {
3125 pushBackLine( line );
3126 break;
3127 }
3128
3129 std::istringstream tiss( line );
3130 double tx = 0.0, ty = 0.0;
3131 tiss >> tx >> ty;
3132
3133 if( tiss.fail() )
3134 {
3135 int skipLines = m_has_font_lines ? 2 : 1;
3136
3137 for( int s = 0; s < skipLines; ++s )
3138 readLine( aStream, line );
3139
3140 continue;
3141 }
3142
3143 double trot = 0.0;
3144 int tlayer = 0;
3145 double theight = 0.0, twidth = 0.0;
3146 tiss >> trot >> tlayer >> theight >> twidth;
3147
3148 if( m_has_font_lines )
3149 {
3150 if( !readLine( aStream, line ) )
3151 break;
3152 }
3153
3154 // Content line
3155 if( !readLine( aStream, line ) )
3156 break;
3157
3158 if( t == 0 )
3159 {
3160 dim.text = line;
3161 dim.text_height = theight;
3162 dim.text_width = twidth;
3163 dim.rotation = trot;
3164 }
3165 }
3166
3167 textCount = 0;
3168
3169 if( !dim.points.empty() )
3170 m_dimensions.push_back( dim );
3171 }
3172 else if( type == "KEEPOUT" || type == "RESTRICTVIA" || type == "RESTRICTROUTE"
3173 || type == "RESTRICTAREA" || type == "PLACEMENT_KEEPOUT" )
3174 {
3175 // Parse keepout area definition
3176 KEEPOUT keepout;
3177
3178 // Set defaults based on type name (fallback if no restriction codes in piece)
3179 if( type == "KEEPOUT" || type == "RESTRICTAREA" )
3180 {
3181 keepout.type = KEEPOUT_TYPE::ALL;
3182 keepout.no_traces = true;
3183 keepout.no_vias = true;
3184 keepout.no_copper = true;
3185 }
3186 else if( type == "RESTRICTVIA" )
3187 {
3188 keepout.type = KEEPOUT_TYPE::VIA;
3189 keepout.no_traces = false;
3190 keepout.no_vias = true;
3191 keepout.no_copper = false;
3192 }
3193 else if( type == "RESTRICTROUTE" )
3194 {
3195 keepout.type = KEEPOUT_TYPE::ROUTE;
3196 keepout.no_traces = true;
3197 keepout.no_vias = false;
3198 keepout.no_copper = false;
3199 }
3200 else if( type == "PLACEMENT_KEEPOUT" )
3201 {
3202 keepout.type = KEEPOUT_TYPE::PLACEMENT;
3203 keepout.no_traces = false;
3204 keepout.no_vias = false;
3205 keepout.no_copper = false;
3206 keepout.no_components = true;
3207 }
3208
3209 for( int i = 0; i < pieces; ++i )
3210 {
3211 if( !readLine( aStream, line ) )
3212 break;
3213
3214 if( line[0] == '*' )
3215 {
3216 pushBackLine( line );
3217 break;
3218 }
3219
3220 // Piece format: PIECETYPE CORNERS WIDTH FLAGS LEVEL [RESTRICTIONS]
3221 // RESTRICTIONS is a string containing: P H R C V T A
3222 std::istringstream piss( line );
3223 std::string shape_type;
3224 int corners = 0;
3225 double width = 0;
3226 int piece_flags = 0;
3227 int level = 0;
3228 std::string restrictions;
3229 piss >> shape_type >> corners >> width >> piece_flags >> level >> restrictions;
3230
3231 if( level > 0 )
3232 keepout.layers.push_back( level );
3233
3234 // Parse restriction codes if present
3235 // Per PADS spec: P=Placement, H=Height, R=Trace/copper, C=Copper pour,
3236 // V=Via/jumper, T=Test point, A=Accordion
3237 // Only override defaults from type name if explicit restrictions are specified
3238 if( !restrictions.empty() )
3239 {
3240 // Check if this looks like a restriction code string (contains letters)
3241 bool has_restriction_codes = false;
3242
3243 for( char c : restrictions )
3244 {
3245 if( std::isalpha( c ) )
3246 {
3247 has_restriction_codes = true;
3248 break;
3249 }
3250 }
3251
3252 if( has_restriction_codes )
3253 {
3254 // Clear all defaults and set based on explicit restriction codes
3255 keepout.no_traces = false;
3256 keepout.no_vias = false;
3257 keepout.no_copper = false;
3258 keepout.no_components = false;
3259 keepout.height_restriction = false;
3260 keepout.no_test_points = false;
3261 keepout.no_accordion = false;
3262
3263 for( char c : restrictions )
3264 {
3265 switch( c )
3266 {
3267 case 'P':
3268 keepout.no_components = true;
3269 break;
3270
3271 case 'H':
3272 keepout.height_restriction = true;
3273 keepout.max_height = width;
3274 break;
3275
3276 case 'R':
3277 keepout.no_traces = true;
3278 break;
3279
3280 case 'C':
3281 keepout.no_copper = true;
3282 break;
3283
3284 case 'V':
3285 keepout.no_vias = true;
3286 break;
3287
3288 case 'T':
3289 keepout.no_test_points = true;
3290 break;
3291
3292 case 'A':
3293 keepout.no_accordion = true;
3294 break;
3295
3296 default:
3297 break;
3298 }
3299 }
3300 }
3301 }
3302
3303 // Handle KPTCIR (circle keepout) differently from KPTCLS (polygon keepout)
3304 if( shape_type == "KPTCIR" )
3305 {
3306 // Circle format: 2 coordinates define opposite ends of diameter
3307 double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
3308
3309 if( readLine( aStream, line ) )
3310 {
3311 std::istringstream c1( line );
3312 c1 >> x1 >> y1;
3313 }
3314
3315 if( corners >= 2 && readLine( aStream, line ) )
3316 {
3317 std::istringstream c2( line );
3318 c2 >> x2 >> y2;
3319 }
3320
3321 // Calculate center and radius from diameter endpoints
3322 double cx = xloc + ( x1 + x2 ) / 2.0;
3323 double cy = yloc + ( y1 + y2 ) / 2.0;
3324 double radius = std::sqrt( ( x2 - x1 ) * ( x2 - x1 ) +
3325 ( y2 - y1 ) * ( y2 - y1 ) ) / 2.0;
3326
3327 // Create full circle arc for keepout outline
3328 ARC arc{};
3329 arc.cx = cx;
3330 arc.cy = cy;
3331 arc.radius = radius;
3332 arc.start_angle = 0.0;
3333 arc.delta_angle = 360.0;
3334
3335 keepout.outline.emplace_back( cx + radius, cy, arc );
3336 }
3337 else
3338 {
3339 // KPTCLS or other polygon piece types
3340 for( int j = 0; j < corners; ++j )
3341 {
3342 if( !readLine( aStream, line ) )
3343 break;
3344
3345 if( line[0] == '*' )
3346 {
3347 pushBackLine( line );
3348 break;
3349 }
3350
3351 std::istringstream ciss( line );
3352 double dx = 0.0, dy = 0.0;
3353 ciss >> dx >> dy;
3354
3355 // Per PADS spec, arc format is: x1 y1 ab aa ax1 ay1 ax2 ay2
3356 // where x1,y1 = arc start point; center = bounding box midpoint
3357 int startAngleTenths = 0, deltaAngleTenths = 0;
3358 double bboxMinX = 0.0, bboxMinY = 0.0, bboxMaxX = 0.0, bboxMaxY = 0.0;
3359
3360 if( ciss >> startAngleTenths >> deltaAngleTenths
3361 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY )
3362 {
3363 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
3364 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
3365 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
3366 double startAngle = startAngleTenths / 10.0;
3367 double deltaAngle = deltaAngleTenths / 10.0;
3368
3369 double startAngleRad = startAngle * M_PI / 180.0;
3370 double startX = cx + radius * std::cos( startAngleRad );
3371 double startY = cy + radius * std::sin( startAngleRad );
3372
3373 double endAngleRad = ( startAngle + deltaAngle ) * M_PI / 180.0;
3374 double endX = cx + radius * std::cos( endAngleRad );
3375 double endY = cy + radius * std::sin( endAngleRad );
3376
3377 keepout.outline.emplace_back( xloc + startX, yloc + startY );
3378
3379 ARC arc{};
3380 arc.cx = xloc + cx;
3381 arc.cy = yloc + cy;
3382 arc.radius = radius;
3383 arc.start_angle = startAngle;
3384 arc.delta_angle = deltaAngle;
3385
3386 keepout.outline.emplace_back( xloc + endX, yloc + endY, arc );
3387 }
3388 else
3389 {
3390 keepout.outline.emplace_back( xloc + dx, yloc + dy );
3391 }
3392 }
3393 }
3394 }
3395
3396 if( !keepout.outline.empty() )
3397 m_keepouts.push_back( keepout );
3398 }
3399 else if( type == "COPPER" || type == "COPCUT" )
3400 {
3401 // Parse copper shape definition
3402 // Header already parsed: name type xloc yloc pieces flags [text [signame]]
3403 // signame was parsed earlier if present
3404
3405 for( int i = 0; i < pieces; ++i )
3406 {
3407 if( !readLine( aStream, line ) )
3408 break;
3409
3410 if( line[0] == '*' )
3411 {
3412 pushBackLine( line );
3413 return;
3414 }
3415
3416 // Piece format: PIECETYPE CORNERS WIDTH FLAGS LEVEL
3417 // PIECETYPE: COPOPN (polyline), COPCLS (filled polygon), COPCIR (filled circle),
3418 // COPCUT (polygon void), COPCCO (circle void), CIRCUR (circle void for COPCUT)
3419 std::istringstream piss( line );
3420 std::string shape_type;
3421 int corners = 0;
3422 double width = 0;
3423 int piece_flags = 0;
3424 int level = 0;
3425 piss >> shape_type >> corners >> width >> piece_flags >> level;
3426
3427 COPPER_SHAPE copper;
3428 copper.name = name;
3429 copper.layer = level;
3430 copper.width = width;
3431 copper.net_name = normalizeNetName( signame );
3432
3433 copper.filled = ( shape_type == "COPCLS" || shape_type == "COPCIR" );
3434 copper.is_cutout = ( shape_type == "COPCUT" || shape_type == "COPCCO" ||
3435 shape_type == "CIRCUR" || type == "COPCUT" );
3436
3437 // Handle circle shapes specially
3438 if( shape_type == "COPCIR" || shape_type == "COPCCO" || shape_type == "CIRCUR" )
3439 {
3440 // Circle: 2 coordinates define opposite ends of diameter
3441 double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
3442
3443 if( readLine( aStream, line ) )
3444 {
3445 std::istringstream c1( line );
3446 c1 >> x1 >> y1;
3447 }
3448
3449 if( corners >= 2 && readLine( aStream, line ) )
3450 {
3451 std::istringstream c2( line );
3452 c2 >> x2 >> y2;
3453 }
3454
3455 double cx = xloc + ( x1 + x2 ) / 2.0;
3456 double cy = yloc + ( y1 + y2 ) / 2.0;
3457 double radius = std::sqrt( ( x2 - x1 ) * ( x2 - x1 ) +
3458 ( y2 - y1 ) * ( y2 - y1 ) ) / 2.0;
3459
3460 ARC arc{};
3461 arc.cx = cx;
3462 arc.cy = cy;
3463 arc.radius = radius;
3464 arc.start_angle = 0.0;
3465 arc.delta_angle = 360.0;
3466
3467 copper.outline.emplace_back( cx + radius, cy, arc );
3468 }
3469 else
3470 {
3471 // COPOPN, COPCLS, COPCUT - polygon shapes
3472 for( int j = 0; j < corners; ++j )
3473 {
3474 if( !readLine( aStream, line ) )
3475 break;
3476
3477 if( line[0] == '*' )
3478 {
3479 pushBackLine( line );
3480 break;
3481 }
3482
3483 std::istringstream ciss( line );
3484 double dx = 0.0, dy = 0.0;
3485 ciss >> dx >> dy;
3486
3487 // Per PADS spec, arc format is: x1 y1 ab aa ax1 ay1 ax2 ay2
3488 // where x1,y1 = arc start point; center = bounding box midpoint
3489 int startAngleTenths = 0, deltaAngleTenths = 0;
3490 double bboxMinX = 0.0, bboxMinY = 0.0, bboxMaxX = 0.0, bboxMaxY = 0.0;
3491
3492 if( ciss >> startAngleTenths >> deltaAngleTenths
3493 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY )
3494 {
3495 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
3496 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
3497 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
3498 double startAngle = startAngleTenths / 10.0;
3499 double deltaAngle = deltaAngleTenths / 10.0;
3500
3501 double startAngleRad = startAngle * M_PI / 180.0;
3502 double startX = cx + radius * std::cos( startAngleRad );
3503 double startY = cy + radius * std::sin( startAngleRad );
3504
3505 double endAngleRad = ( startAngle + deltaAngle ) * M_PI / 180.0;
3506 double endX = cx + radius * std::cos( endAngleRad );
3507 double endY = cy + radius * std::sin( endAngleRad );
3508
3509 copper.outline.emplace_back( xloc + startX, yloc + startY );
3510
3511 ARC arc{};
3512 arc.cx = xloc + cx;
3513 arc.cy = yloc + cy;
3514 arc.radius = radius;
3515 arc.start_angle = startAngle;
3516 arc.delta_angle = deltaAngle;
3517
3518 copper.outline.emplace_back( xloc + endX, yloc + endY, arc );
3519 }
3520 else
3521 {
3522 copper.outline.emplace_back( xloc + dx, yloc + dy );
3523 }
3524 }
3525 }
3526
3527 if( !copper.outline.empty() )
3528 m_copper_shapes.push_back( copper );
3529 }
3530 }
3531 else if( type == "LINES" )
3532 {
3533 // Generic 2D graphic lines (non-dimension LINES items)
3534 for( int i = 0; i < pieces; ++i )
3535 {
3536 if( !readLine( aStream, line ) )
3537 break;
3538
3539 if( line[0] == '*' )
3540 {
3541 pushBackLine( line );
3542 return;
3543 }
3544
3545 // Piece format: PIECETYPE CORNERS WIDTH FLAGS LEVEL
3546 std::istringstream piss( line );
3547 std::string shape_type;
3548 int corners = 0;
3549 double width = 0;
3550 int piece_flags = 0;
3551 int level = 0;
3552 piss >> shape_type >> corners >> width >> piece_flags >> level;
3553
3554 GRAPHIC_LINE graphic;
3555 graphic.name = name;
3556 graphic.layer = level;
3557 graphic.width = width;
3558 graphic.reuse_instance = reuse_instance;
3559
3560 // Determine if closed based on shape type
3561 graphic.closed = ( shape_type == "CLOSED" || shape_type == "CIRCLE" );
3562
3563 if( shape_type == "CIRCLE" )
3564 {
3565 // Circle: 2 coordinates define opposite ends of diameter
3566 double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
3567
3568 if( readLine( aStream, line ) )
3569 {
3570 std::istringstream c1( line );
3571 c1 >> x1 >> y1;
3572 }
3573
3574 if( corners >= 2 && readLine( aStream, line ) )
3575 {
3576 std::istringstream c2( line );
3577 c2 >> x2 >> y2;
3578 }
3579
3580 double cx = xloc + ( x1 + x2 ) / 2.0;
3581 double cy = yloc + ( y1 + y2 ) / 2.0;
3582 double radius = std::sqrt( ( x2 - x1 ) * ( x2 - x1 ) +
3583 ( y2 - y1 ) * ( y2 - y1 ) ) / 2.0;
3584
3585 ARC arc{};
3586 arc.cx = cx;
3587 arc.cy = cy;
3588 arc.radius = radius;
3589 arc.start_angle = 0.0;
3590 arc.delta_angle = 360.0;
3591
3592 graphic.points.emplace_back( cx + radius, cy, arc );
3593 }
3594 else
3595 {
3596 // OPEN or CLOSED polyline
3597 for( int j = 0; j < corners; ++j )
3598 {
3599 if( !readLine( aStream, line ) )
3600 break;
3601
3602 if( line[0] == '*' )
3603 {
3604 pushBackLine( line );
3605 break;
3606 }
3607
3608 std::istringstream ciss( line );
3609 double dx = 0.0, dy = 0.0;
3610 ciss >> dx >> dy;
3611
3612 // Check for arc parameters
3613 int startAngleTenths = 0, deltaAngleTenths = 0;
3614 double bboxMinX = 0.0, bboxMinY = 0.0, bboxMaxX = 0.0, bboxMaxY = 0.0;
3615
3616 if( ciss >> startAngleTenths >> deltaAngleTenths
3617 >> bboxMinX >> bboxMinY >> bboxMaxX >> bboxMaxY )
3618 {
3619 double cx = ( bboxMinX + bboxMaxX ) / 2.0;
3620 double cy = ( bboxMinY + bboxMaxY ) / 2.0;
3621 double radius = ( bboxMaxX - bboxMinX ) / 2.0;
3622 double startAngle = startAngleTenths / 10.0;
3623 double deltaAngle = deltaAngleTenths / 10.0;
3624
3625 double startAngleRad = startAngle * M_PI / 180.0;
3626 double startX = cx + radius * std::cos( startAngleRad );
3627 double startY = cy + radius * std::sin( startAngleRad );
3628
3629 double endAngleRad = ( startAngle + deltaAngle ) * M_PI / 180.0;
3630 double endX = cx + radius * std::cos( endAngleRad );
3631 double endY = cy + radius * std::sin( endAngleRad );
3632
3633 graphic.points.emplace_back( xloc + startX, yloc + startY );
3634
3635 ARC arc{};
3636 arc.cx = xloc + cx;
3637 arc.cy = yloc + cy;
3638 arc.radius = radius;
3639 arc.start_angle = startAngle;
3640 arc.delta_angle = deltaAngle;
3641
3642 graphic.points.emplace_back( xloc + endX, yloc + endY, arc );
3643 }
3644 else
3645 {
3646 graphic.points.emplace_back( xloc + dx, yloc + dy );
3647 }
3648 }
3649 }
3650
3651 if( !graphic.points.empty() )
3652 m_graphic_lines.push_back( graphic );
3653 }
3654 }
3655 else
3656 {
3657 // Skip unknown types
3658 for( int i = 0; i < pieces; ++i )
3659 {
3660 if( !readLine( aStream, line ) )
3661 break;
3662
3663 if( line[0] == '*' )
3664 {
3665 pushBackLine( line );
3666 return;
3667 }
3668
3669 std::istringstream piss( line );
3670 std::string shape_type;
3671 int corners = 0;
3672 piss >> shape_type >> corners;
3673
3674 for( int j = 0; j < corners; ++j )
3675 {
3676 if( !readLine( aStream, line ) )
3677 break;
3678
3679 if( line[0] == '*' )
3680 {
3681 pushBackLine( line );
3682 return;
3683 }
3684 }
3685 }
3686 }
3687
3688 // Parse text items that follow the pieces.
3689 // V9+ format: 3 lines each (properties, font, content)
3690 // V5.x format: 2 lines each (properties, content)
3691 for( int t = 0; t < textCount; ++t )
3692 {
3693 if( !readLine( aStream, line ) )
3694 break;
3695
3696 if( line[0] == '*' )
3697 {
3698 pushBackLine( line );
3699 return;
3700 }
3701
3702 std::istringstream tiss( line );
3703 TEXT text;
3704
3705 tiss >> text.location.x >> text.location.y >> text.rotation >> text.layer
3706 >> text.height >> text.width;
3707
3708 if( tiss.fail() )
3709 {
3710 int skipLines = m_has_font_lines ? 2 : 1;
3711
3712 for( int s = 0; s < skipLines; ++s )
3713 readLine( aStream, line );
3714
3715 continue;
3716 }
3717
3718 text.location.x += xloc;
3719 text.location.y += yloc;
3720
3721 std::string mirrored;
3722 tiss >> mirrored;
3723 text.mirrored = ( mirrored == "M" );
3724 tiss >> text.hjust >> text.vjust;
3725
3726 if( m_has_font_lines )
3727 {
3728 if( !readLine( aStream, line ) )
3729 break;
3730
3731 if( line[0] == '*' )
3732 {
3733 pushBackLine( line );
3734 return;
3735 }
3736
3737 size_t bracket_start = line.find( '<' );
3738 size_t bracket_end = line.find( '>' );
3739
3740 if( bracket_start != std::string::npos && bracket_end != std::string::npos )
3741 {
3742 text.font_face =
3743 line.substr( bracket_start + 1, bracket_end - bracket_start - 1 );
3744 }
3745
3746 std::istringstream fiss( line );
3747 std::string font_style_part;
3748 fiss >> font_style_part;
3749
3750 size_t colon_pos = font_style_part.find( ':' );
3751
3752 if( colon_pos != std::string::npos )
3753 text.font_style = font_style_part.substr( 0, colon_pos );
3754 else
3755 text.font_style = font_style_part;
3756 }
3757
3758 // Content line
3759 if( !readLine( aStream, line ) )
3760 break;
3761
3762 if( line[0] == '*' )
3763 {
3764 pushBackLine( line );
3765 return;
3766 }
3767
3768 text.content = line;
3769 m_texts.push_back( text );
3770 }
3771 }
3772}
3773
3774void PARSER::parseSectionPARTTYPE( std::ifstream& aStream )
3775{
3776 std::string line;
3777 PART_TYPE* currentPartType = nullptr;
3778 GATE_DEF* currentGate = nullptr;
3779
3780 // Records carry no terminator and a part type name can look exactly like pin data, so the
3781 // header counts are the only reliable way to find where a record ends
3782 int pendingGates = 0;
3783 int pendingGatePins = 0;
3784 int pendingSigPins = 0;
3785 int pendingUnusedPins = 0;
3786
3787 // Helper to parse pin electrical type character
3788 auto parsePinElecType = []( char c ) -> PIN_ELEC_TYPE {
3789 switch( c )
3790 {
3791 case 'S': return PIN_ELEC_TYPE::SOURCE;
3792 case 'B': return PIN_ELEC_TYPE::BIDIRECTIONAL;
3793 case 'C': return PIN_ELEC_TYPE::OPEN_COLLECTOR;
3794 case 'T': return PIN_ELEC_TYPE::TRISTATE;
3795 case 'L': return PIN_ELEC_TYPE::LOAD;
3796 case 'Z': return PIN_ELEC_TYPE::TERMINATOR;
3797 case 'P': return PIN_ELEC_TYPE::POWER;
3798 case 'G': return PIN_ELEC_TYPE::GROUND;
3799 default: return PIN_ELEC_TYPE::UNDEFINED;
3800 }
3801 };
3802
3803 auto isInteger = []( const std::string& aToken ) -> bool
3804 {
3805 return !aToken.empty() && aToken.find_first_not_of( "0123456789" ) == std::string::npos;
3806 };
3807
3808 auto tokenize = []( const std::string& aLine ) -> std::vector<std::string>
3809 {
3810 std::istringstream lss( aLine );
3811 std::vector<std::string> tokens;
3812 std::string token;
3813
3814 while( lss >> token )
3815 tokens.push_back( token );
3816
3817 return tokens;
3818 };
3819
3820 while( readLine( aStream, line ) )
3821 {
3822 if( line[0] == '*' )
3823 {
3824 pushBackLine( line );
3825 break;
3826 }
3827
3828 // Attribute block enclosed in braces
3829 if( line[0] == '{' && currentPartType )
3830 {
3831 while( readLine( aStream, line ) )
3832 {
3833 if( line[0] == '}' )
3834 break;
3835
3836 if( line[0] == '*' )
3837 {
3838 pushBackLine( line );
3839 return;
3840 }
3841
3842 std::string attrName, attrValue;
3843
3844 if( line[0] == '"' )
3845 {
3846 size_t endQuote = line.find( '"', 1 );
3847
3848 if( endQuote != std::string::npos )
3849 {
3850 attrName = line.substr( 1, endQuote - 1 );
3851 attrValue = line.substr( endQuote + 1 );
3852 }
3853 }
3854 else
3855 {
3856 std::istringstream attrSS( line );
3857 attrSS >> attrName;
3858 std::getline( attrSS >> std::ws, attrValue );
3859 }
3860
3861 if( !attrValue.empty() && attrValue[0] == ' ' )
3862 attrValue = attrValue.substr( 1 );
3863
3864 if( !attrName.empty() && !attrValue.empty() )
3865 currentPartType->attributes[attrName] = attrValue;
3866 }
3867
3868 continue;
3869 }
3870
3871 if( line[0] == '{' || line[0] == '}' )
3872 continue;
3873
3874 std::vector<std::string> tokens = tokenize( line );
3875
3876 if( tokens.empty() )
3877 continue;
3878
3879 // Pin tokens wrap freely across lines, so the gate's declared count marks the end
3880 if( pendingGatePins > 0 )
3881 {
3882 for( const std::string& token : tokens )
3883 {
3884 if( pendingGatePins == 0 )
3885 break;
3886
3887 pendingGatePins--;
3888
3889 // Parse pin format: PINNAME.SWAPTYPE.PINTYPE[.FUNCNAME] or PINNAME.PADINDEX.TYPE.NET
3890 std::vector<std::string> parts;
3891 size_t start = 0;
3892 size_t pos = 0;
3893
3894 while( ( pos = token.find( '.', start ) ) != std::string::npos )
3895 {
3896 parts.push_back( token.substr( start, pos - start ) );
3897 start = pos + 1;
3898 }
3899
3900 parts.push_back( token.substr( start ) );
3901
3902 if( parts.size() < 3 )
3903 continue;
3904
3905 // Check if this is a gate pin definition or pad stack mapping
3906 // Gate pin: pinnumber.swaptype.pintype[.funcname]
3907 // Pad map: pinname.padindex.type.netname
3908 bool isNumericSecond = isInteger( parts[1] );
3909
3910 if( currentGate && parts[2].size() == 1 && !isNumericSecond )
3911 {
3912 GATE_PIN gpin;
3913 gpin.pin_number = parts[0];
3914 gpin.swap_type = PADS_COMMON::ParseInt( parts[1], 0, "gate pin swap" );
3915
3916 if( !parts[2].empty() )
3917 gpin.elec_type = parsePinElecType( parts[2][0] );
3918
3919 if( parts.size() >= 4 )
3920 gpin.func_name = parts[3];
3921
3922 currentGate->pins.push_back( gpin );
3923 }
3924 else if( isNumericSecond )
3925 {
3926 int padIdx = PADS_COMMON::ParseInt( parts[1], -1, "pad index" );
3927
3928 if( padIdx >= 0 )
3929 currentPartType->pin_pad_map[parts[0]] = padIdx;
3930 }
3931 }
3932
3933 continue;
3934 }
3935
3936 // Unused pin names are discarded, but still have to be counted off so a run of bare
3937 // pin numbers is not read as the next header
3938 if( pendingGates == 0 && pendingSigPins == 0 && pendingUnusedPins > 0 )
3939 {
3940 pendingUnusedPins -= std::min<int>( pendingUnusedPins, tokens.size() );
3941 continue;
3942 }
3943
3944 // Gate line: G gateswap pins
3945 if( currentPartType && tokens.size() >= 3 && tokens[0] == "G" && isInteger( tokens[1] )
3946 && isInteger( tokens[2] ) )
3947 {
3948 GATE_DEF gate;
3949 gate.gate_swap_type = PADS_COMMON::ParseInt( tokens[1], 0, "gate swap" );
3950 currentPartType->gates.push_back( gate );
3951 currentGate = &currentPartType->gates.back();
3952
3953 pendingGatePins = PADS_COMMON::ParseInt( tokens[2], 0, "gate pin count" );
3954
3955 if( pendingGates > 0 )
3956 pendingGates--;
3957
3958 continue;
3959 }
3960
3961 // SIGPIN pinno width signm
3962 if( currentPartType && tokens[0] == "SIGPIN" )
3963 {
3964 std::istringstream sss( line );
3965 std::string keyword;
3966 SIGPIN sigpin;
3967
3968 sss >> keyword >> sigpin.pin_number >> sigpin.width >> sigpin.signal_name;
3969
3970 if( !sigpin.pin_number.empty() )
3971 currentPartType->signal_pins.push_back( sigpin );
3972
3973 if( pendingSigPins > 0 )
3974 pendingSigPins--;
3975
3976 continue;
3977 }
3978
3979 // Header is NAME DECALNM [UNITS] TYPE GATES SIGPINS UNUSEDPINNMS FLAGS ECO, and V5.0
3980 // and V2005.0 insert UNITS, so the counts start at the first numeric column past the decal
3981 PART_TYPE pt;
3982 pt.name = tokens[0];
3983
3984 if( tokens.size() > 1 )
3985 pt.decal_name = tokens[1];
3986
3987 m_part_types[pt.name] = pt;
3988 currentPartType = &m_part_types[pt.name];
3989 currentGate = nullptr;
3990
3991 pendingGates = 0;
3992 pendingGatePins = 0;
3993 pendingSigPins = 0;
3994 pendingUnusedPins = 0;
3995
3996 for( size_t ii = 2; ii < tokens.size(); ++ii )
3997 {
3998 if( !isInteger( tokens[ii] ) )
3999 continue;
4000
4001 pendingGates = PADS_COMMON::ParseInt( tokens[ii], 0, "part type gates" );
4002
4003 if( ii + 1 < tokens.size() && isInteger( tokens[ii + 1] ) )
4004 pendingSigPins = PADS_COMMON::ParseInt( tokens[ii + 1], 0, "part type sigpins" );
4005
4006 if( ii + 2 < tokens.size() && isInteger( tokens[ii + 2] ) )
4007 pendingUnusedPins = PADS_COMMON::ParseInt( tokens[ii + 2], 0, "part type unused pins" );
4008
4009 break;
4010 }
4011 }
4012}
4013
4014
4015void PARSER::parseSectionREUSE( std::ifstream& aStream )
4016{
4017 std::string line;
4018 REUSE_BLOCK* currentBlock = nullptr;
4019
4020 while( readLine( aStream, line ) )
4021 {
4022 if( line[0] == '*' )
4023 {
4024 pushBackLine( line );
4025 break;
4026 }
4027
4028 std::stringstream ss( line );
4029 std::string keyword;
4030 ss >> keyword;
4031
4032 if( keyword == "TYPE" )
4033 {
4034 std::string typename_val;
4035 std::getline( ss, typename_val );
4036
4037 if( !typename_val.empty() && typename_val[0] == ' ' )
4038 typename_val = typename_val.substr( 1 );
4039
4040 REUSE_BLOCK block;
4041 block.name = typename_val;
4042 m_reuse_blocks[typename_val] = block;
4043 currentBlock = &m_reuse_blocks[typename_val];
4044 }
4045 else if( keyword == "TIMESTAMP" && currentBlock )
4046 {
4047 long timestamp = 0;
4048 ss >> timestamp;
4049 currentBlock->timestamp = timestamp;
4050 }
4051 else if( keyword == "PART_NAMING" && currentBlock )
4052 {
4053 std::string naming;
4054 std::getline( ss, naming );
4055
4056 if( !naming.empty() && naming[0] == ' ' )
4057 naming = naming.substr( 1 );
4058
4059 currentBlock->part_naming = naming;
4060 }
4061 else if( keyword == "PART" && currentBlock )
4062 {
4063 std::string partname;
4064 std::getline( ss, partname );
4065
4066 if( !partname.empty() && partname[0] == ' ' )
4067 partname = partname.substr( 1 );
4068
4069 currentBlock->part_names.push_back( partname );
4070 }
4071 else if( keyword == "NET_NAMING" && currentBlock )
4072 {
4073 std::string naming;
4074 std::getline( ss, naming );
4075
4076 if( !naming.empty() && naming[0] == ' ' )
4077 naming = naming.substr( 1 );
4078
4079 currentBlock->net_naming = naming;
4080 }
4081 else if( keyword == "NET" && currentBlock )
4082 {
4083 int merge_flag = 0;
4084 std::string netname;
4085
4086 ss >> merge_flag;
4087 std::getline( ss, netname );
4088
4089 if( !netname.empty() && netname[0] == ' ' )
4090 netname = netname.substr( 1 );
4091
4092 REUSE_NET net;
4093 net.merge = ( merge_flag == 1 );
4094 net.name = netname;
4095 currentBlock->nets.push_back( net );
4096 }
4097 else if( keyword == "REUSE" && currentBlock )
4098 {
4099 REUSE_INSTANCE instance;
4100 ss >> instance.instance_name;
4101
4102 std::string next_token;
4103 ss >> next_token;
4104
4105 if( next_token == "PREFIX" || next_token == "SUFFIX" )
4106 {
4107 std::string param;
4108 ss >> param;
4109 instance.part_naming = next_token + " " + param;
4110 ss >> next_token;
4111 }
4112 else if( next_token == "START" || next_token == "INCREMENT" )
4113 {
4114 std::string num;
4115 ss >> num;
4116 instance.part_naming = next_token + " " + num;
4117 ss >> next_token;
4118 }
4119 else if( next_token == "NEXT" )
4120 {
4121 instance.part_naming = next_token;
4122 ss >> next_token;
4123 }
4124
4125 if( next_token == "PREFIX" || next_token == "SUFFIX" )
4126 {
4127 std::string param;
4128 ss >> param;
4129 instance.net_naming = next_token + " " + param;
4130 }
4131 else if( next_token == "START" || next_token == "INCREMENT" )
4132 {
4133 std::string num;
4134 ss >> num;
4135 instance.net_naming = next_token + " " + num;
4136 }
4137 else if( next_token == "NEXT" )
4138 {
4139 instance.net_naming = next_token;
4140 }
4141
4142 std::string glued_str;
4143 ss >> instance.location.x >> instance.location.y >> instance.rotation >> glued_str;
4144
4145 instance.glued = ( glued_str == "Y" || glued_str == "YES" || glued_str == "1" );
4146 currentBlock->instances.push_back( instance );
4147 }
4148 }
4149}
4150
4151
4152void PARSER::parseSectionCLUSTER( std::ifstream& aStream )
4153{
4154 std::string line;
4155 CLUSTER* currentCluster = nullptr;
4156
4157 while( readLine( aStream, line ) )
4158 {
4159 if( line[0] == '*' )
4160 {
4161 pushBackLine( line );
4162 break;
4163 }
4164
4165 std::stringstream ss( line );
4166 std::string firstToken;
4167 ss >> firstToken;
4168
4169 // Check if this is a new cluster definition or a member line
4170 // Cluster definition format varies but typically starts with name/id
4171 if( firstToken.empty() )
4172 continue;
4173
4174 // Try parsing as cluster ID
4175 bool isNumeric = !firstToken.empty() &&
4176 std::all_of( firstToken.begin(), firstToken.end(), ::isdigit );
4177
4178 if( isNumeric )
4179 {
4180 // This could be a cluster ID starting a new cluster
4181 CLUSTER cluster;
4182 cluster.id = PADS_COMMON::ParseInt( firstToken, 0, "CLUSTER" );
4183
4184 // Read optional cluster name
4185 std::string name;
4186
4187 if( ss >> name )
4188 cluster.name = name;
4189 else
4190 cluster.name = "Cluster_" + firstToken;
4191
4192 m_clusters.push_back( cluster );
4193 currentCluster = &m_clusters.back();
4194 }
4195 else if( currentCluster )
4196 {
4197 // Could be a net name or segment reference belonging to current cluster
4198 // PADS format varies - add to net_names or segment_refs based on content
4199 if( firstToken.find( '.' ) != std::string::npos )
4200 {
4201 // Looks like a segment reference (e.g., "NET.1")
4202 currentCluster->segment_refs.push_back( firstToken );
4203 }
4204 else
4205 {
4206 // Treat as net name
4207 currentCluster->net_names.push_back( firstToken );
4208 }
4209
4210 // Continue reading additional items on the same line
4211 std::string item;
4212
4213 while( ss >> item )
4214 {
4215 if( item.find( '.' ) != std::string::npos )
4216 currentCluster->segment_refs.push_back( item );
4217 else
4218 currentCluster->net_names.push_back( item );
4219 }
4220 }
4221 }
4222}
4223
4224
4225void PARSER::parseSectionJUMPER( std::ifstream& aStream )
4226{
4227 std::string line;
4228
4229 while( readLine( aStream, line ) )
4230 {
4231 if( line[0] == '*' )
4232 {
4233 pushBackLine( line );
4234 break;
4235 }
4236
4237 // Jumper header format: name flags minlen maxlen lenincr lcount padstack [end_padstack]
4238 // flags: V=via enabled, N=no via, W=wirebond, D=display silk, G=glued
4239 std::stringstream ss( line );
4240 std::string name, flags;
4241 double minlen = 0.0, maxlen = 0.0, lenincr = 0.0;
4242 int lcount = 0;
4243 std::string padstack, end_padstack;
4244
4245 if( !( ss >> name >> flags >> minlen >> maxlen >> lenincr >> lcount >> padstack ) )
4246 continue;
4247
4248 ss >> end_padstack;
4249
4250 JUMPER_DEF jumper;
4251 jumper.name = name;
4252 jumper.min_length = minlen;
4253 jumper.max_length = maxlen;
4254 jumper.length_increment = lenincr;
4255 jumper.padstack = padstack;
4256 jumper.end_padstack = end_padstack;
4257
4258 // Parse flags
4259 for( char c : flags )
4260 {
4261 switch( c )
4262 {
4263 case 'V': jumper.via_enabled = true; break;
4264 case 'N': jumper.via_enabled = false; break;
4265 case 'W': jumper.wirebond = true; break;
4266 case 'D': jumper.display_silk = true; break;
4267 case 'G': jumper.glued = true; break;
4268 default: break;
4269 }
4270 }
4271
4272 // Parse label entries (each label is 2 lines)
4273 for( int i = 0; i < lcount; ++i )
4274 {
4275 ATTRIBUTE attr;
4276
4277 // Line 1: VISIBLE X Y ORI LEVEL HEIGHT WIDTH MIRRORED HJUST VJUST [RIGHTREADING]
4278 if( !readLine( aStream, line ) )
4279 break;
4280
4281 std::stringstream ss_attr( line );
4282 std::string visible_str, mirrored_str, right_reading_str;
4283
4284 if( ss_attr >> visible_str >> attr.x >> attr.y >> attr.orientation >> attr.level
4285 >> attr.height >> attr.width >> mirrored_str >> attr.hjust >> attr.vjust )
4286 {
4287 attr.visible = ( visible_str == "VALUE" || visible_str == "FULL_NAME" ||
4288 visible_str == "NAME" || visible_str == "FULL_BOTH" ||
4289 visible_str == "BOTH" );
4290 attr.mirrored = ( mirrored_str == "M" || mirrored_str == "1" );
4291 ss_attr >> right_reading_str;
4292 attr.right_reading = ( right_reading_str == "Y" || right_reading_str == "ORTHO" );
4293 }
4294
4295 if( m_has_font_lines )
4296 {
4297 if( !readLine( aStream, line ) )
4298 break;
4299
4300 attr.font_info = line;
4301 }
4302
4303 jumper.labels.push_back( attr );
4304 }
4305
4306 m_jumper_defs.push_back( jumper );
4307 }
4308}
4309
4310
4311void PARSER::parseSectionTESTPOINT( std::ifstream& aStream )
4312{
4313 std::string line;
4314
4315 while( readLine( aStream, line ) )
4316 {
4317 if( line[0] == '*' )
4318 {
4319 pushBackLine( line );
4320 break;
4321 }
4322
4323 std::stringstream ss( line );
4324 std::string type;
4325 ss >> type;
4326
4327 if( type.empty() )
4328 continue;
4329
4330 // Format: TYPE X Y SIDE NETNAME SYMBOLNAME
4331 // TYPE is VIA or PIN
4332 TEST_POINT tp;
4333 tp.type = type;
4334
4335 ss >> tp.x >> tp.y >> tp.side >> tp.net_name >> tp.symbol_name;
4336
4337 if( !tp.net_name.empty() )
4338 {
4339 m_test_points.push_back( tp );
4340 }
4341 }
4342}
4343
4344
4345void PARSER::parseSectionNETCLASS( std::ifstream& aStream )
4346{
4347 std::string line;
4348 NET_CLASS_DEF currentClass;
4349 bool inClass = false;
4350
4351 while( readLine( aStream, line ) )
4352 {
4353 if( line[0] == '*' )
4354 {
4355 // Save the last class if we were building one
4356 if( inClass && !currentClass.name.empty() )
4357 m_net_classes.push_back( currentClass );
4358
4359 pushBackLine( line );
4360 break;
4361 }
4362
4363 std::stringstream ss( line );
4364 std::string token;
4365 ss >> token;
4366
4367 if( token.empty() )
4368 continue;
4369
4370 // Check for class name definition (typically first token without a keyword)
4371 if( token == "CLASS" || token == "NETCLASS" )
4372 {
4373 // Save previous class if any
4374 if( inClass && !currentClass.name.empty() )
4375 m_net_classes.push_back( currentClass );
4376
4377 // Start new class
4378 currentClass = NET_CLASS_DEF();
4379 ss >> currentClass.name;
4380 inClass = true;
4381 }
4382 else if( token == "CLEARANCE" && inClass )
4383 {
4384 ss >> currentClass.clearance;
4385 }
4386 else if( token == "TRACKWIDTH" && inClass )
4387 {
4388 ss >> currentClass.track_width;
4389 }
4390 else if( token == "VIASIZE" && inClass )
4391 {
4392 ss >> currentClass.via_size;
4393 }
4394 else if( token == "VIADRILL" && inClass )
4395 {
4396 ss >> currentClass.via_drill;
4397 }
4398 else if( token == "DIFFPAIRGAP" && inClass )
4399 {
4400 ss >> currentClass.diff_pair_gap;
4401 }
4402 else if( token == "DIFFPAIRWIDTH" && inClass )
4403 {
4404 ss >> currentClass.diff_pair_width;
4405 }
4406 else if( token == "NET" && inClass )
4407 {
4408 // Net assignment: NET netname
4409 std::string netName;
4410 ss >> netName;
4411
4412 if( !netName.empty() )
4413 currentClass.net_names.push_back( netName );
4414 }
4415 else if( !token.empty() && token[0] != '#' )
4416 {
4417 // Check if this looks like a class name (no keyword prefix) in some formats
4418 if( !inClass || ( inClass && currentClass.name.empty() ) )
4419 {
4420 // Save previous if any
4421 if( inClass && !currentClass.name.empty() )
4422 m_net_classes.push_back( currentClass );
4423
4424 currentClass = NET_CLASS_DEF();
4425 currentClass.name = token;
4426 inClass = true;
4427 }
4428 }
4429 }
4430
4431 // Save final class
4432 if( inClass && !currentClass.name.empty() )
4433 m_net_classes.push_back( currentClass );
4434}
4435
4436
4437void PARSER::parseSectionDIFFPAIR( std::ifstream& aStream )
4438{
4439 std::string line;
4440
4441 while( readLine( aStream, line ) )
4442 {
4443 if( line[0] == '*' )
4444 {
4445 pushBackLine( line );
4446 break;
4447 }
4448
4449 std::stringstream ss( line );
4450 std::string token;
4451 ss >> token;
4452
4453 if( token.empty() )
4454 continue;
4455
4456 // Differential pair format can vary. Common patterns:
4457 // DIFFPAIR name positive_net negative_net gap width
4458 // or keyword-based like:
4459 // PAIR name
4460 // POS positive_net
4461 // NEG negative_net
4462 // GAP value
4463 // WIDTH value
4464
4465 if( token == "DIFFPAIR" || token == "PAIR" )
4466 {
4467 DIFF_PAIR_DEF dp;
4468 ss >> dp.name;
4469
4470 // Try to read the nets inline
4471 std::string posNet, negNet;
4472 ss >> posNet >> negNet;
4473
4474 if( !posNet.empty() )
4475 dp.positive_net = posNet;
4476
4477 if( !negNet.empty() )
4478 dp.negative_net = negNet;
4479
4480 // Try to read gap and width inline
4481 double gap = 0.0, width = 0.0;
4482
4483 if( ss >> gap )
4484 dp.gap = gap;
4485
4486 if( ss >> width )
4487 dp.width = width;
4488
4489 if( !dp.name.empty() )
4490 m_diff_pairs.push_back( dp );
4491 }
4492 else if( token == "POS" && !m_diff_pairs.empty() )
4493 {
4494 ss >> m_diff_pairs.back().positive_net;
4495 }
4496 else if( token == "NEG" && !m_diff_pairs.empty() )
4497 {
4498 ss >> m_diff_pairs.back().negative_net;
4499 }
4500 else if( token == "GAP" && !m_diff_pairs.empty() )
4501 {
4502 ss >> m_diff_pairs.back().gap;
4503 }
4504 else if( ( token == "WIDTH" || token == "TRACKWIDTH" ) && !m_diff_pairs.empty() )
4505 {
4506 ss >> m_diff_pairs.back().width;
4507 }
4508 }
4509}
4510
4511
4512void PARSER::parseSectionLAYERDEFS( std::ifstream& aStream )
4513{
4514 std::string line;
4515 int braceDepth = 0;
4516 int currentLayerNum = -1;
4517 LAYER_INFO currentLayer;
4518 bool inLayerBlock = false;
4519
4520 // Helper to parse LAYER_TYPE string to enum
4521 auto parseLayerType = []( const std::string& typeStr ) -> PADS_LAYER_FUNCTION {
4522 if( typeStr == "ROUTING" )
4524 else if( typeStr == "PLANE" )
4526 else if( typeStr == "MIXED" )
4528 else if( typeStr == "UNASSIGNED" )
4530 else if( typeStr == "SOLDER_MASK" )
4532 else if( typeStr == "PASTE_MASK" )
4534 else if( typeStr == "SILK_SCREEN" )
4536 else if( typeStr == "ASSEMBLY" )
4538 else if( typeStr == "DOCUMENTATION" )
4540 else if( typeStr == "DRILL" )
4543 };
4544
4545 while( readLine( aStream, line ) )
4546 {
4547 if( line.empty() )
4548 continue;
4549
4550 // Stop if we hit a new section marker
4551 if( line[0] == '*' )
4552 {
4553 pushBackLine( line );
4554 break;
4555 }
4556
4557 std::istringstream iss( line );
4558 std::string token;
4559 iss >> token;
4560
4561 if( token == "{" )
4562 {
4563 braceDepth++;
4564 continue;
4565 }
4566
4567 if( token == "}" )
4568 {
4569 braceDepth--;
4570
4571 // Closing a layer block, save if we have valid data
4572 if( inLayerBlock && braceDepth == 1 )
4573 {
4574 if( currentLayerNum >= 0 )
4575 {
4576 currentLayer.number = currentLayerNum;
4577
4578 // Determine if copper based on layer number and type
4579 currentLayer.is_copper = ( currentLayer.layer_type == PADS_LAYER_FUNCTION::ROUTING ||
4580 currentLayer.layer_type == PADS_LAYER_FUNCTION::PLANE ||
4581 currentLayer.layer_type == PADS_LAYER_FUNCTION::MIXED );
4582 currentLayer.required = currentLayer.is_copper;
4583 m_layer_defs[currentLayerNum] = currentLayer;
4584 }
4585
4586 inLayerBlock = false;
4587 currentLayerNum = -1;
4588 }
4589
4590 // Exiting the outer LAYER block
4591 if( braceDepth <= 0 )
4592 break;
4593
4594 continue;
4595 }
4596
4597 if( token == "LAYER" )
4598 {
4599 int layerNum = -1;
4600 iss >> layerNum;
4601
4602 if( !iss.fail() && layerNum >= 0 )
4603 {
4604 // Starting a new layer definition
4605 currentLayerNum = layerNum;
4606 currentLayer = LAYER_INFO();
4607 currentLayer.number = layerNum;
4609 inLayerBlock = true;
4610 }
4611 }
4612 else if( token == "LAYER_NAME" && inLayerBlock )
4613 {
4614 // Read the rest of the line as the layer name
4615 std::string name;
4616 std::getline( iss >> std::ws, name );
4617 currentLayer.name = name;
4618 }
4619 else if( token == "LAYER_TYPE" && inLayerBlock )
4620 {
4621 std::string typeStr;
4622 iss >> typeStr;
4623 currentLayer.layer_type = parseLayerType( typeStr );
4624 }
4625 else if( token == "LAYER_THICKNESS" && inLayerBlock )
4626 {
4627 iss >> currentLayer.layer_thickness;
4628 }
4629 else if( token == "COPPER_THICKNESS" && inLayerBlock )
4630 {
4631 iss >> currentLayer.copper_thickness;
4632 }
4633 else if( token == "DIELECTRIC" && inLayerBlock )
4634 {
4635 iss >> currentLayer.dielectric_constant;
4636 }
4637 }
4638}
4639
4640
4641void PARSER::parseSectionMISC( std::ifstream& aStream )
4642{
4643 // The MISC section contains various optional data:
4644 // - NET_CLASS DATA (net class definitions with member nets)
4645 // - GROUP DATA (pin pair groups)
4646 // - ASSOCIATED NET DATA (associated net pairs)
4647 // - DIF_PAIR definitions with extended parameters
4648 // - DESIGN_RULES / RULE_SET (hierarchical design rules)
4649 // - ATTRIBUTES DICTIONARY (attribute type definitions)
4650 //
4651 // We parse DIF_PAIR and NET_CLASS definitions as they're most relevant for KiCad.
4652
4653 std::string line;
4654 int braceDepth = 0;
4655 bool inDifPair = false;
4656 bool inNetClassData = false;
4657 bool inNetClass = false;
4658 bool inRuleSet = false;
4659 bool inRuleSetFor = false;
4660 bool inClearanceRule = false;
4661 int netClassDataDepth = -1;
4662 int netClassDepth = -1;
4663 int ruleSetDepth = -1;
4664 int clearanceRuleDepth = -1;
4665 bool foundDefaultRules = false;
4666 bool isDefaultRuleSet = false;
4667 std::string ruleSetNetClass;
4668 DIFF_PAIR_DEF currentDiffPair;
4669 NET_CLASS_DEF currentNetClass;
4670
4671 while( readLine( aStream, line ) )
4672 {
4673 if( line.empty() )
4674 continue;
4675
4676 // Stop at next section marker
4677 if( line[0] == '*' && braceDepth == 0 )
4678 {
4679 pushBackLine( line );
4680 break;
4681 }
4682
4683 // Track brace depth for nested structures
4684 for( char c : line )
4685 {
4686 if( c == '{' )
4687 braceDepth++;
4688 else if( c == '}' )
4689 {
4690 braceDepth--;
4691
4692 if( braceDepth == 0 && inDifPair )
4693 {
4694 // End of DIF_PAIR block
4695 if( !currentDiffPair.name.empty() )
4696 m_diff_pairs.push_back( currentDiffPair );
4697
4698 inDifPair = false;
4699 currentDiffPair = DIFF_PAIR_DEF();
4700 }
4701
4702 if( inNetClass && braceDepth <= netClassDepth )
4703 {
4704 if( !currentNetClass.name.empty() )
4705 m_net_classes.push_back( currentNetClass );
4706
4707 inNetClass = false;
4708 currentNetClass = NET_CLASS_DEF();
4709 }
4710
4711 if( inNetClassData && braceDepth <= netClassDataDepth )
4712 {
4713 inNetClassData = false;
4714 }
4715
4716 if( inClearanceRule && braceDepth < clearanceRuleDepth )
4717 {
4718 inClearanceRule = false;
4719
4720 if( isDefaultRuleSet )
4721 {
4722 if( m_design_rules.default_clearance != std::numeric_limits<double>::max() )
4723 {
4726 }
4727
4728 if( m_design_rules.copper_edge_clearance != std::numeric_limits<double>::max() )
4730
4731 if( m_design_rules.default_clearance
4732 == std::numeric_limits<double>::max() )
4733 {
4734 m_design_rules.default_clearance =
4735 DESIGN_RULES().default_clearance;
4736 }
4737
4738 m_design_rules.min_clearance = m_design_rules.default_clearance;
4739
4740 if( m_design_rules.copper_edge_clearance
4741 == std::numeric_limits<double>::max() )
4742 {
4743 m_design_rules.copper_edge_clearance =
4744 m_design_rules.default_clearance;
4745 }
4746
4747 foundDefaultRules = true;
4748 }
4749 }
4750
4751 if( inRuleSetFor && braceDepth < ruleSetDepth + 1 )
4752 inRuleSetFor = false;
4753
4754 if( inRuleSet && braceDepth < ruleSetDepth )
4755 {
4756 inRuleSet = false;
4757 isDefaultRuleSet = false;
4758 ruleSetNetClass.clear();
4759 }
4760 }
4761 }
4762
4763 std::istringstream iss( line );
4764 std::string token;
4765 iss >> token;
4766
4767 // LAYER DATA block contains per-layer definitions (name, type, etc.)
4768 // which may appear inside *MISC* instead of as a standalone section.
4769 if( token == "LAYER" )
4770 {
4771 std::string secondToken;
4772 iss >> secondToken;
4773
4774 if( secondToken == "DATA" )
4775 {
4776 parseSectionLAYERDEFS( aStream );
4777 continue;
4778 }
4779 }
4780
4781 if( token == "NET_CLASS" )
4782 {
4783 std::string secondToken;
4784 iss >> secondToken;
4785
4786 if( secondToken == "DATA" )
4787 {
4788 inNetClassData = true;
4789 netClassDataDepth = braceDepth;
4790 }
4791 else if( inNetClassData && !secondToken.empty() )
4792 {
4793 if( inNetClass && !currentNetClass.name.empty() )
4794 m_net_classes.push_back( currentNetClass );
4795
4796 currentNetClass = NET_CLASS_DEF();
4797 currentNetClass.name = secondToken;
4798 inNetClass = true;
4799 netClassDepth = braceDepth;
4800 }
4801 else if( inRuleSetFor && !secondToken.empty() )
4802 {
4803 ruleSetNetClass = secondToken;
4804 }
4805 }
4806 else if( inNetClass && token == "NET" )
4807 {
4808 std::string netName;
4809 iss >> netName;
4810
4811 if( !netName.empty() )
4812 currentNetClass.net_names.push_back( netName );
4813 }
4814 else if( token == "RULE_SET" )
4815 {
4816 std::string ruleNum;
4817 iss >> ruleNum;
4818
4819 inRuleSet = true;
4820 ruleSetDepth = braceDepth;
4821 ruleSetNetClass.clear();
4822 isDefaultRuleSet = ( ruleNum == "(1)" && !foundDefaultRules );
4823 }
4824 else if( inRuleSet && !inClearanceRule && token == "FOR" )
4825 {
4826 inRuleSetFor = true;
4827 }
4828 else if( inRuleSet && token == "CLEARANCE_RULE" )
4829 {
4830 inClearanceRule = true;
4831 clearanceRuleDepth = braceDepth;
4832
4833 if( isDefaultRuleSet )
4834 {
4835 m_design_rules.default_clearance = std::numeric_limits<double>::max();
4836 m_design_rules.copper_edge_clearance = std::numeric_limits<double>::max();
4837 }
4838 }
4839 else if( inClearanceRule )
4840 {
4841 double val = 0.0;
4842 iss >> val;
4843
4844 if( !iss.fail() && val > 0.0 )
4845 {
4846 if( isDefaultRuleSet )
4847 {
4848 if( token == "MIN_TRACK_WIDTH" )
4849 {
4850 m_design_rules.min_track_width = val;
4852 }
4853 else if( token == "REC_TRACK_WIDTH" )
4854 {
4855 m_design_rules.default_track_width = val;
4857 }
4858 else if( token == "DRILL_TO_DRILL" )
4859 {
4860 m_design_rules.hole_to_hole = val;
4862 }
4863 else if( token == "OUTLINE_TO_TRACK" || token == "OUTLINE_TO_VIA"
4864 || token == "OUTLINE_TO_PAD" || token == "OUTLINE_TO_COPPER"
4865 || token == "OUTLINE_TO_SMD" )
4866 {
4867 m_design_rules.copper_edge_clearance =
4868 std::min( m_design_rules.copper_edge_clearance, val );
4869 }
4870 else if( token.rfind( "SAME_NET_", 0 ) == 0 || token == "BODY_TO_BODY"
4871 || token == "MAX_TRACK_WIDTH"
4872 || token.rfind( "TEXT_TO_", 0 ) == 0
4873 || token.rfind( "COPPER_TO_", 0 ) == 0 )
4874 {
4875 // Exclude same-net spacings, physical body clearances, text
4876 // clearances, and copper-pour clearances from the inter-net
4877 // copper clearance.
4878 }
4879 else if( token == "TRACK_TO_TRACK" || token.rfind( "VIA_TO_", 0 ) == 0
4880 || token.rfind( "PAD_TO_", 0 ) == 0
4881 || token.rfind( "SMD_TO_", 0 ) == 0
4882 || token.rfind( "DRILL_TO_", 0 ) == 0 )
4883 {
4884 m_design_rules.default_clearance =
4885 std::min( m_design_rules.default_clearance, val );
4886 }
4887 }
4888 else if( !ruleSetNetClass.empty() )
4889 {
4890 for( auto& nc : m_net_classes )
4891 {
4892 if( nc.name == ruleSetNetClass )
4893 {
4894 if( token == "REC_TRACK_WIDTH" )
4895 nc.track_width = val;
4896 else if( token == "TRACK_TO_TRACK" )
4897 nc.clearance = val;
4898
4899 break;
4900 }
4901 }
4902 }
4903 }
4904 }
4905 else if( token == "DIF_PAIR" )
4906 {
4907 // Save previous diff pair if any
4908 if( inDifPair && !currentDiffPair.name.empty() )
4909 m_diff_pairs.push_back( currentDiffPair );
4910
4911 currentDiffPair = DIFF_PAIR_DEF();
4912 iss >> currentDiffPair.name;
4913 inDifPair = true;
4914 }
4915 else if( inDifPair )
4916 {
4917 if( token == "NET" )
4918 {
4919 std::string netName;
4920 iss >> netName;
4921
4922 // Assign to positive net first, then negative
4923 if( currentDiffPair.positive_net.empty() )
4924 currentDiffPair.positive_net = netName;
4925 else if( currentDiffPair.negative_net.empty() )
4926 currentDiffPair.negative_net = netName;
4927 }
4928 else if( token == "GAP" )
4929 {
4930 iss >> currentDiffPair.gap;
4931 }
4932 else if( token == "WIDTH" )
4933 {
4934 iss >> currentDiffPair.width;
4935 }
4936 else if( token == "CONNECTION" )
4937 {
4938 // CONNECTION format: ref.pin,ref.pin
4939 // This defines a pin pair for the diff pair
4940 // For now just skip - main net assignment is more important
4941 }
4942 else if( token == "ASSOCIATED" )
4943 {
4944 // ASSOCIATED NET netname - for associated net pairs
4945 std::string keyword, netName;
4946 iss >> keyword >> netName;
4947
4948 if( keyword == "NET" )
4949 {
4950 if( currentDiffPair.positive_net.empty() )
4951 currentDiffPair.positive_net = netName;
4952 else if( currentDiffPair.negative_net.empty() )
4953 currentDiffPair.negative_net = netName;
4954 }
4955 }
4956 }
4957
4958 // Parse per-instance attribute blocks: PART <refdes> { key value ... }
4959 // These appear inside ATTRIBUTE VALUES {...} at variable brace depth.
4960 if( token == "PART" && !inDifPair && !inNetClass )
4961 {
4962 std::string partName;
4963 iss >> partName;
4964
4965 if( !partName.empty() )
4966 {
4967 // Save brace depth before consuming the block's own { ... }
4968 int savedDepth = braceDepth;
4969 auto& attrs = m_part_instance_attrs[partName];
4970
4971 while( readLine( aStream, line ) )
4972 {
4973 if( line.empty() )
4974 continue;
4975
4976 if( line[0] == '}' )
4977 break;
4978
4979 if( line[0] == '{' )
4980 continue;
4981
4982 if( line[0] == '*' )
4983 {
4984 pushBackLine( line );
4986 return;
4987 }
4988
4989 std::string attrName, attrValue;
4990
4991 if( line[0] == '"' )
4992 {
4993 size_t endQuote = line.find( '"', 1 );
4994
4995 if( endQuote != std::string::npos )
4996 {
4997 attrName = line.substr( 1, endQuote - 1 );
4998 attrValue = line.substr( endQuote + 1 );
4999 }
5000 }
5001 else
5002 {
5003 std::istringstream attrSS( line );
5004 attrSS >> attrName;
5005 std::getline( attrSS >> std::ws, attrValue );
5006 }
5007
5008 if( !attrValue.empty() && attrValue[0] == ' ' )
5009 attrValue = attrValue.substr( 1 );
5010
5011 if( !attrName.empty() && !attrValue.empty() )
5012 attrs[attrName] = attrValue;
5013 }
5014
5015 // Restore to the depth before the PART block's braces
5016 braceDepth = savedDepth;
5017 }
5018
5019 continue;
5020 }
5021
5022 // Skip other MISC subsections (ATTRIBUTES DICTIONARY, DESIGN_RULES, etc.)
5023 }
5024
5026}
5027
5028
5030{
5031 DESIGN_RULES defaults;
5032
5033 if( m_design_rules.default_clearance == std::numeric_limits<double>::max() )
5034 m_design_rules.default_clearance = defaults.default_clearance;
5035
5036 if( m_design_rules.copper_edge_clearance == std::numeric_limits<double>::max() )
5037 m_design_rules.copper_edge_clearance = defaults.copper_edge_clearance;
5038}
5039
5040
5041std::vector<LAYER_INFO> PARSER::GetLayerInfos() const
5042{
5043 std::vector<LAYER_INFO> layers;
5044
5045 int layerCount = m_parameters.layer_count;
5046
5047 if( layerCount < 1 )
5048 layerCount = 2;
5049
5050 // Helper to check if a layer number is a copper layer
5051 auto isCopperLayer = [&]( int num ) {
5052 return num >= 1 && num <= layerCount;
5053 };
5054
5055 // Helper to get layer type from parsed defs or default
5056 auto getLayerDef = [&]( int num ) -> const LAYER_INFO* {
5057 auto it = m_layer_defs.find( num );
5058 return it != m_layer_defs.end() ? &it->second : nullptr;
5059 };
5060
5061 // Add copper layers with parsed info if available
5062 for( int i = 1; i <= layerCount; ++i )
5063 {
5064 const LAYER_INFO* parsed = getLayerDef( i );
5065
5066 if( parsed )
5067 {
5068 layers.push_back( *parsed );
5069 }
5070 else
5071 {
5072 // Generate default copper layer info
5074 info.number = i;
5076 info.is_copper = true;
5077 info.required = true;
5078
5079 if( i == 1 )
5080 info.name = "Top";
5081 else if( i == layerCount )
5082 info.name = "Bottom";
5083 else
5084 info.name = "Inner " + std::to_string( i - 1 );
5085
5086 layers.push_back( info );
5087 }
5088 }
5089
5090 // Add non-copper layers from parsed definitions
5091 for( const auto& [num, layerDef] : m_layer_defs )
5092 {
5093 if( !isCopperLayer( num ) )
5094 {
5095 layers.push_back( layerDef );
5096 }
5097 }
5098
5099 // If no non-copper layers were parsed, add default fallbacks
5100 if( m_layer_defs.empty() )
5101 {
5102 // Standard non-copper layers (common PADS layer numbers)
5103 layers.push_back( { 21, "Assembly Top", PADS_LAYER_FUNCTION::ASSEMBLY, false, false } );
5104 layers.push_back( { 22, "Assembly Bottom", PADS_LAYER_FUNCTION::ASSEMBLY, false, false } );
5105 layers.push_back( { 25, "Solder Mask Top", PADS_LAYER_FUNCTION::SOLDER_MASK, false, false } );
5106 layers.push_back( { 26, "Silkscreen Top", PADS_LAYER_FUNCTION::SILK_SCREEN, false, false } );
5107 layers.push_back( { 27, "Silkscreen Bottom", PADS_LAYER_FUNCTION::SILK_SCREEN, false, false } );
5108 layers.push_back( { 28, "Solder Mask Bottom", PADS_LAYER_FUNCTION::SOLDER_MASK, false, false } );
5109 layers.push_back( { 29, "Paste Top", PADS_LAYER_FUNCTION::PASTE_MASK, false, false } );
5110 layers.push_back( { 30, "Paste Bottom", PADS_LAYER_FUNCTION::PASTE_MASK, false, false } );
5111 }
5112
5113 return layers;
5114}
5115
5116} // namespace PADS_IO
const char * name
bool readLine(std::ifstream &aStream, std::string &aLine)
std::map< std::string, PART_DECAL > m_decals
std::vector< CLUSTER > m_clusters
std::map< std::string, REUSE_BLOCK > m_reuse_blocks
bool m_has_font_lines
True if text/label entries include a font line.
std::vector< KEEPOUT > m_keepouts
std::vector< POUR > m_pours
std::vector< JUMPER_DEF > m_jumper_defs
Jumper definitions from JUMPER section.
std::vector< TEXT > m_texts
void parseSectionPARTTYPE(std::ifstream &aStream)
void parseSectionJUMPER(std::ifstream &aStream)
void parseSectionTESTPOINT(std::ifstream &aStream)
void parseSectionLINES(std::ifstream &aStream)
PARAMETERS m_parameters
std::map< std::string, VIA_DEF > m_via_defs
void parseSectionBOARD(std::ifstream &aStream)
void parseSectionVIA(std::ifstream &aStream)
std::vector< COPPER_SHAPE > m_copper_shapes
Copper shapes from LINES section.
std::map< std::string, PART_TYPE > m_part_types
std::vector< NET > m_nets
void parseSectionPARTS(std::ifstream &aStream)
std::vector< ROUTE > m_routes
std::map< std::string, std::map< std::string, std::string > > m_part_instance_attrs
Per-instance attribute overrides from PART <name> {...} blocks in PARTTYPE section.
std::vector< NET_CLASS_DEF > m_net_classes
void parseSectionNETCLASS(std::ifstream &aStream)
void parseSectionMISC(std::ifstream &aStream)
void parseSectionREUSE(std::ifstream &aStream)
void parseSectionCLUSTER(std::ifstream &aStream)
void parseSectionLAYERDEFS(std::ifstream &aStream)
std::vector< LAYER_INFO > GetLayerInfos() const
Get layer information for the layer mapping dialog.
DESIGN_RULES m_design_rules
void parseSectionNETS(std::ifstream &aStream)
void Parse(const wxString &aFileName)
FILE_HEADER m_file_header
Parsed file header info.
std::vector< GRAPHIC_LINE > m_graphic_lines
2D graphic lines from LINES section
std::vector< DIMENSION > m_dimensions
std::vector< DIFF_PAIR_DEF > m_diff_pairs
void parseSectionPCB(std::ifstream &aStream)
void clampDesignRuleSentinels()
void parseSectionTEXT(std::ifstream &aStream)
std::vector< POLYLINE > m_board_outlines
std::vector< PART > m_parts
int parseMajorVersion() const
Parse the major version number from the file header version string.
std::map< int, LAYER_INFO > m_layer_defs
Parsed layer definitions by layer number.
void parseSectionROUTES(std::ifstream &aStream)
std::vector< TEST_POINT > m_test_points
std::optional< std::string > m_pushed_line
void pushBackLine(const std::string &aLine)
void parseSectionDIFFPAIR(std::ifstream &aStream)
void parseSectionPOUR(std::ifstream &aStream)
void parseSectionPARTDECAL(std::ifstream &aStream)
static bool empty(const wxTextEntryBase *aCtrl)
const wxChar *const tracePadsIo
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.
static std::vector< std::string > expandShortcutPattern(const std::string &aPattern)
Expand a shortcut format string like "PRE{n1-n2}" into individual names.
@ BURIED
Inner layers only.
@ THROUGH
Spans all copper layers.
@ BLIND
Surface to inner layer.
@ MICROVIA
Single-layer blind, typically HDI.
@ OPEN_COLLECTOR
C, open collector or or-tieable source.
static std::string normalizeNetName(const std::string &aNetName)
bool IsAntiPadRow(const PAD_STACK_LAYER &aLayer)
RA and SA rows carry a plane's anti-pad clearance rather than the pad's own copper.
bool IsThermalReliefPadRow(const PAD_STACK_LAYER &aLayer)
RT and ST rows carry a plane's thermal-relief spoke pattern rather than the pad's own copper.
@ LIB_PCB_DECAL
Library footprints.
Definition pads_parser.h:98
@ LIB_LINE
Library line items (drafting)
Definition pads_parser.h:96
bool IsCopperPadRow(const PAD_STACK_LAYER &aLayer)
True when the row describes pad or via copper.
PADS_LAYER_FUNCTION
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
A polyline point that may instead be an arc segment.
Definition pads_parser.h:64
ARC arc
Only valid when is_arc is true.
Definition pads_parser.h:68
Arc as center, radius and angles.
Definition pads_parser.h:50
double radius
Definition pads_parser.h:53
double delta_angle
Definition pads_parser.h:55
double start_angle
Definition pads_parser.h:54
std::string font_info
std::string hjust
std::string vjust
std::vector< std::string > segment_refs
std::string name
std::vector< std::string > net_names
Standalone copper area from the LINES section (type=COPPER), not part of a pour.
std::vector< ARC_POINT > outline
bool is_cutout
COPCUT, COPCCO.
std::string net_name
Empty if unconnected.
bool filled
COPCLS, COPCIR.
double width
For open polylines.
std::string restrictions
KPTCLS/KPTCIR keepout codes R,C,V,T,A.
bool is_tag_close
Closing TAG, level 0.
std::vector< ARC_POINT > points
int pinnum
Copper-piece pin association, -1 = none.
std::string type
CLOSED, OPEN, CIRCLE, COPCLS, TAG, etc.
bool is_tag_open
Opening TAG, level 1.
Board design rules.
double copper_edge_clearance
OUTLINE_TO_*.
double default_clearance
DEFAULTCLEAR.
double x
Origin.
double crossbar_pos
Y for horizontal, X for vertical.
std::vector< POINT > points
Measurement endpoints.
int gate_swap_type
0 = not swappable
std::vector< GATE_PIN > pins
std::string func_name
int swap_type
0 = not swappable
std::string pin_number
PIN_ELEC_TYPE elec_type
Non-electrical drawing item from the LINES section (type=LINES).
std::vector< ARC_POINT > points
std::string reuse_instance
std::string padstack
Start pin, or both if end_padstack empty.
bool wirebond
W flag.
std::string end_padstack
End pin, optional.
bool display_silk
D flag.
std::vector< ATTRIBUTE > labels
bool via_enabled
V flag.
bool is_start
S = start, E = end.
std::vector< ARC_POINT > outline
bool no_vias
V restriction.
bool no_components
P restriction.
bool no_copper
C restriction.
bool no_accordion
A restriction.
bool height_restriction
H restriction.
KEEPOUT_TYPE type
bool no_traces
R restriction.
std::vector< int > layers
Empty = all.
bool no_test_points
T restriction.
PADS_LAYER_FUNCTION layer_type
bool required
Layer must be mapped.
int number
PADS layer number.
double layer_thickness
Dielectric, BASIC units.
double dielectric_constant
Er.
double copper_thickness
Copper foil, BASIC units.
double via_drill
VIADRILL.
double clearance
CLEARANCE.
std::vector< std::string > net_names
double track_width
TRACKWIDTH.
double diff_pair_width
DIFFPAIRWIDTH.
double diff_pair_gap
DIFFPAIRGAP.
double via_size
VIASIZE.
std::string name
std::vector< NET_PIN > pins
bool chamfered
Negative corner value in PADS.
double drill
0 for SMD
std::string shape
R, S, A, O, OF, RF, RT, ST, RA, SA, RC, OC.
bool plated
PTH vs NPTH.
double thermal_outer_diameter
Thermal or void in plane.
double slot_orientation
0-179.999 degrees
double thermal_spoke_orientation
First spoke.
double inner_diameter
Annular ring, 0 = solid.
double finger_offset
Along orientation axis.
double sizeB
Height for rectangles/ovals.
double slot_offset
From electrical center.
double corner_radius
Always positive.
double sizeA
Diameter or width.
std::vector< DECAL_ITEM > items
std::vector< TERMINAL > terminals
std::vector< ATTRIBUTE > attributes
std::map< int, std::vector< PAD_STACK_LAYER > > pad_stacks
std::map< std::string, std::string > attributes
From {...} block.
std::map< std::string, int > pin_pad_map
Pin name to pad stack index.
std::vector< GATE_DEF > gates
std::vector< SIGPIN > signal_pins
std::string decal_name
std::string part_type
Part type name when using PARTTYPE@DECAL syntax.
bool explicit_decal
Decal given explicitly with @ syntax.
std::string reuse_instance
std::string decal
Primary decal (first in colon-separated list)
std::string name
int alt_decal_index
ALT field from placement (-1 = use primary decal)
std::vector< ATTRIBUTE > attributes
std::string reuse_part
Original part ref des inside the reuse block.
std::vector< std::string > alternate_decals
Alternate decals (remaining after ':' splits)
A polyline that may contain arc segments, used for board outlines and graphics.
std::vector< ARC_POINT > points
std::string name
bool is_cutout
POCUT piece.
POUR_STYLE style
std::string net_name
std::string owner_pour
Parent pour, 7th header field.
double hatch_grid
std::vector< ARC_POINT > points
THERMAL_TYPE thermal_type
double hatch_width
A reuse block definition containing parts and routes that can be instantiated.
std::vector< REUSE_NET > nets
std::string net_naming
Default scheme.
std::string part_naming
Default scheme.
std::vector< std::string > part_names
std::vector< REUSE_INSTANCE > instances
Placements of this block.
std::string part_naming
May be multi-word like "PREFIX pref".
std::string net_naming
May be multi-word like "SUFFIX suf".
std::string name
Original net name from reuse definition.
bool merge
Merge nets vs rename.
std::vector< VIA > vias
std::vector< TEARDROP > teardrops
std::vector< TRACK > tracks
std::vector< NET_PIN > pins
From pin pair lines.
std::vector< JUMPER_MARKER > jumpers
std::string net_name
std::string pin_number
double width
Track width for connections.
std::string signal_name
e.g. VCC, GND
std::string name
std::vector< ARC_POINT > points
bool has_mask_front
Stack includes top soldermask, layer 25.
int drill_start
Drill span from file, for blind/buried.
int start_layer
First PADS layer in span.
int end_layer
Last PADS layer in span.
std::vector< PAD_STACK_LAYER > stack
std::string name
bool has_mask_back
Stack includes bottom soldermask, layer 28.
std::string name
KIBIS_PIN * pin
int radius
VECTOR2I end
static double sweep(float aStart, float aEnd)
wxString result
Test unit parsing edge cases and error handling.
#define M_PI
static thread_pool * tp
wxLogTrace helper definitions.