KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sprint_layout_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 The 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 * Binary format knowledge derived from:
20 * https://github.com/sergey-raevskiy/xlay (lay6.h)
21 * https://github.com/OpenBoardView/OpenBoardView (LAYFile.cpp)
22 */
23
25
26#include <board.h>
30#include <footprint.h>
31#include <memory>
32#include <netinfo.h>
33#include <pad.h>
34#include <pcb_group.h>
35#include <pcb_shape.h>
36#include <pcb_text.h>
37#include <zone.h>
39#include <math/util.h>
40#include <math/box2.h>
41#include <geometry/seg.h>
42#include <font/fontconfig.h>
43
44#include <wx/filename.h>
45#include <wx/wfstream.h>
46#include <wx/log.h>
47#include <wx/strconv.h>
48#include <wx/fontenc.h>
49
50#include <algorithm>
51#include <set>
52#include <cmath>
53#include <cstring>
54#include <limits>
55
56// All multi-byte reads below decode little-endian explicitly,
57// so this parser works correctly on any host byte order.
58
59static constexpr uint32_t MAX_OBJECTS = 1000000;
60static constexpr uint32_t MAX_GROUPS = 100000;
61static constexpr uint32_t MAX_CHILDREN = 10000;
62static constexpr uint32_t MAX_POINTS = 1000000;
63
64
66
67
69
70
71// ============================================================================
72// Binary reading helpers
73// ============================================================================
74
76{
77 if( m_pos + 1 > m_end )
78 THROW_IO_ERROR( _( "Unexpected end of Sprint Layout file" ) );
79
80 return *m_pos++;
81}
82
83
85{
86 if( m_pos + 2 > m_end )
87 THROW_IO_ERROR( _( "Unexpected end of Sprint Layout file" ) );
88
89 uint16_t v = static_cast<uint16_t>( m_pos[0] )
90 | ( static_cast<uint16_t>( m_pos[1] ) << 8 );
91 m_pos += 2;
92 return v;
93}
94
95
97{
98 return static_cast<int16_t>( readUint16() );
99}
100
101
103{
104 if( m_fileData.version >= 3 )
105 return readUint32();
106 else
107 return readUint16();
108}
109
110
112{
113 if( m_fileData.version >= 3 )
114 return readInt32();
115 else
116 return readInt16();
117}
118
119
121{
122 if( m_pos + 4 > m_end )
123 THROW_IO_ERROR( _( "Unexpected end of Sprint Layout file" ) );
124
125 uint32_t v = static_cast<uint32_t>( m_pos[0] )
126 | ( static_cast<uint32_t>( m_pos[1] ) << 8 )
127 | ( static_cast<uint32_t>( m_pos[2] ) << 16 )
128 | ( static_cast<uint32_t>( m_pos[3] ) << 24 );
129 m_pos += 4;
130 return v;
131}
132
133
135{
136 return static_cast<int32_t>( readUint32() );
137}
138
139
141{
142 uint32_t bits = readUint32();
143 float v;
144 std::memcpy( &v, &bits, sizeof( v ) );
145 return v;
146}
147
148
150{
151 if( m_pos + 8 > m_end )
152 THROW_IO_ERROR( _( "Unexpected end of Sprint Layout file" ) );
153
154 uint64_t bits = static_cast<uint64_t>( m_pos[0] )
155 | ( static_cast<uint64_t>( m_pos[1] ) << 8 )
156 | ( static_cast<uint64_t>( m_pos[2] ) << 16 )
157 | ( static_cast<uint64_t>( m_pos[3] ) << 24 )
158 | ( static_cast<uint64_t>( m_pos[4] ) << 32 )
159 | ( static_cast<uint64_t>( m_pos[5] ) << 40 )
160 | ( static_cast<uint64_t>( m_pos[6] ) << 48 )
161 | ( static_cast<uint64_t>( m_pos[7] ) << 56 );
162 m_pos += 8;
163
164 double v;
165 std::memcpy( &v, &bits, sizeof( v ) );
166 return v;
167}
168
169
171{
172 if( m_fileData.version >= 5 )
173 return readFloat();
174 else if( m_fileData.version >= 3 )
175 return static_cast<float>( readInt32() );
176 else
177 return static_cast<float>( readInt16() );
178}
179
180
181std::string SPRINT_LAYOUT_PARSER::readFixedString( size_t aMaxLen )
182{
183 size_t rawLen = readUint8();
184 size_t len = std::min( rawLen, aMaxLen );
185
186 if( m_pos + aMaxLen > m_end )
187 THROW_IO_ERROR( _( "Unexpected end of Sprint Layout file" ) );
188
189 std::string s( reinterpret_cast<const char*>( m_pos ), len );
190 m_pos += aMaxLen;
191 return s;
192}
193
194
196{
197 uint32_t len = readUint32();
198
199 if( len > 100000 )
200 THROW_IO_ERROR( _( "Invalid string length in Sprint Layout file" ) );
201
202 if( m_pos + len > m_end )
203 THROW_IO_ERROR( _( "Unexpected end of Sprint Layout file" ) );
204
205 std::string s( reinterpret_cast<const char*>( m_pos ), len );
206 m_pos += len;
207 return s;
208}
209
210
211void SPRINT_LAYOUT_PARSER::skip( size_t aBytes )
212{
213 if( m_pos + aBytes > m_end )
214 THROW_IO_ERROR( _( "Unexpected end of Sprint Layout file" ) );
215
216 m_pos += aBytes;
217}
218
219
221{
222 const uint8_t* seekTo = m_pos + aBytes;
223
224 if( seekTo > m_end || seekTo < m_start )
225 THROW_IO_ERROR( _( "Unexpected seek in Sprint Layout file" ) );
226
227 m_pos = seekTo;
228}
229
230
231// ============================================================================
232// Parsing
233// ============================================================================
234
235
236bool SPRINT_LAYOUT_PARSER::ParseBoard( const wxString& aFileName )
237{
238 m_parsingMacro = false;
239 parseFileStart( aFileName );
240
241 if( m_fileData.version >= 3 )
242 {
243 uint32_t numBoards = readUnsigned();
244
245 if( numBoards == 0 || numBoards > 100 )
246 THROW_IO_ERROR( _( "Invalid board count in Sprint Layout file" ) );
247
248 m_fileData.boards.resize( numBoards );
249 }
250 else
251 {
252 m_fileData.boards.resize( 1 );
253 }
254
255 for( uint32_t b = 0; b < m_fileData.boards.size(); b++ )
256 {
257 SPRINT_LAYOUT::BOARD_DATA& boardData = m_fileData.boards[b];
258 parseBoardHeader( boardData );
259
260 uint32_t numObjects = readUnsigned();
261
262 if( numObjects > MAX_OBJECTS )
263 THROW_IO_ERROR( _( "Too many objects in Sprint Layout board" ) );
264
265 boardData.objects.resize( numObjects );
266
267 for( uint32_t i = 0; i < numObjects; i++ )
268 parseObject( boardData.objects[i] );
269
270 if( m_fileData.version >= 3 )
271 {
272 uint32_t numConnections = 0;
273
274 for( const SPRINT_LAYOUT::OBJECT& obj : boardData.objects )
275 {
277 numConnections++;
278 }
279
280 // Read connection records (one per pad object)
281 for( uint32_t c = 0; c < numConnections; c++ )
282 {
283 uint32_t connCount = readUnsigned();
284
285 // Skip the connection data for now
286 for( uint32_t i = 0; i < connCount; i++ )
287 (void) readUnsigned();
288 }
289 }
290 }
291
292 parseTrailer();
293
294 return true;
295}
296
297
298bool SPRINT_LAYOUT_PARSER::ParseMacroFile( const wxString& aFileName )
299{
300 // Parse the macro data into BOARD_DATA
302 data.name = wxFileNameFromPath( aFileName ).BeforeLast( '.' );
303
304 m_parsingMacro = true;
305 parseFileStart( aFileName );
306 parseObjectsList( data );
307
308 m_fileData.boards = { data };
309
310 return true;
311}
312
313
314void SPRINT_LAYOUT_PARSER::parseFileStart( const wxString& aFileName )
315{
316 wxFFileInputStream stream( aFileName );
317
318 if( !stream.IsOk() )
319 THROW_IO_ERRORF( _( "Cannot open file '%s'" ), aFileName );
320
321 size_t fileSize = stream.GetLength();
322
323 if( fileSize < 8 )
324 THROW_IO_ERRORF( _( "File '%s' is too small to be a Sprint Layout file" ), aFileName );
325
326 m_buffer.resize( fileSize );
327 stream.Read( m_buffer.data(), fileSize );
328
329 if( stream.LastRead() != fileSize )
330 THROW_IO_ERRORF( _( "Failed to read file '%s'" ), aFileName );
331
332 m_start = m_buffer.data();
333 m_pos = m_start;
334 m_end = m_start + fileSize;
335
336 // File header: version + magic bytes (0x33, 0xAA, 0xFF)
337 m_fileData.version = readUint8();
338 uint8_t magic1 = readUint8();
339 uint8_t magic2 = readUint8();
340 uint8_t magic3 = readUint8();
341
342 if( m_fileData.version > 6 || magic1 != 0x33 || magic2 != 0xAA || magic3 != 0xFF )
343 THROW_IO_ERROR( _( "Invalid Sprint Layout file header" ) );
344}
345
346
348{
349 if( m_fileData.version >= 3 )
350 {
351 // Board name (Pascal string, 30 bytes max)
352 aBoard.name = readFixedString( 30 );
353
354 // Unknown padding
355 skip( 4 );
356
357 aBoard.size_x = readUint32();
358 aBoard.size_y = readUint32();
359
360 // Ground plane enabled flag per layer (C1, S1, C2, S2, I1, I2, O)
361 for( int i = 0; i < 7; i++ )
362 aBoard.ground_plane[i] = readUint8();
363
364 if( m_fileData.version >= 5 )
365 {
366 // Grid and viewport (not needed for import)
367 readDouble(); // active_grid_val
368 readDouble(); // zoom
369 readUint32(); // viewport_offset_x
370 readUint32(); // viewport_offset_y
371
372 // Active layer + padding
373 skip( 4 );
374
375 // Layer visibility + scanned copy flags
376 skip( 7 ); // layer_visible[7]
377 skip( 1 ); // show_scanned_copy_top
378 skip( 1 ); // show_scanned_copy_bottom
379
380 // Scanned copy paths
381 readFixedString( 200 );
382 readFixedString( 200 );
383
384 // DPI and shift values for scanned copies
385 skip( 4 * 6 ); // dpi_top, dpi_bottom, shiftx/y_top, shiftx/y_bottom
386
387 // Unknown fields
388 skip( 4 * 2 );
389
390 aBoard.center_x = readInt32();
391 aBoard.center_y = readInt32();
392
393 aBoard.is_multilayer = readUint8();
394 }
395 else if( m_fileData.version >= 4 )
396 {
397 skip( 19 );
398 readUint32(); // active_layer
399 skip( 7 ); // layer_visible
400 skip( 400 ); // unknown_list: 100 * 4 bytes
401 skip( 33 );
402
403 aBoard.center_x = readInt32();
404 aBoard.center_y = readInt32();
405 }
406 else if( m_fileData.version >= 3 )
407 {
408 skip( 19 );
409 readUint32(); // active_layer
410 skip( 7 ); // layer_visible
411 skip( 400 ); // unknown_list: 100 * 4 bytes
412 skip( 33 );
413 }
414 }
415 else // Version 2 and older
416 {
417 aBoard.size_x = readUint32();
418 aBoard.size_y = readUint32();
419 }
420}
421
422
424{
425 uint32_t numObjects = readUnsigned();
426
427 if( numObjects > MAX_OBJECTS )
428 THROW_IO_ERROR( _( "Too many objects in Sprint Layout file" ) );
429
430 aBoard.objects.resize( numObjects );
431
432 for( uint32_t i = 0; i < numObjects; i++ )
433 parseObject( aBoard.objects[i], false );
434}
435
436
438{
439 uint32_t groupCount = readUnsigned();
440
441 if( groupCount > MAX_GROUPS )
442 THROW_IO_ERROR( _( "Too many groups in Sprint Layout object" ) );
443
444 aObj.groups.resize( groupCount );
445
446 for( uint32_t i = 0; i < groupCount; i++ )
447 aObj.groups[i] = readUnsigned();
448}
449
450
452{
453 uint32_t pointCount = readUnsigned();
454
455 if( pointCount > MAX_POINTS )
456 THROW_IO_ERROR( _( "Too many points in Sprint Layout object" ) );
457
458 for( uint32_t i = 0; i < pointCount; i++ )
459 {
461 pt.x = readCoord();
462 pt.y = readCoord();
463
464 if( pt.x == 0.0f || std::isnormal( pt.x ) )
465 {
466 aObj.points.emplace_back( pt );
467 }
468 else
469 {
470 seek( -8 );
471 }
472 }
473}
474
475
477{
478 aObj.type = readUint8();
479
484 {
485 THROW_IO_ERRORF( _( "Unknown object type %d in Sprint Layout file" ), aObj.type );
486 }
487
488 aObj.x = readCoord();
489 aObj.y = readCoord();
490 aObj.outer = readCoord();
491 aObj.inner = readCoord();
492 aObj.line_width = readSigned();
493 skip( 1 ); // padding
494 aObj.layer = readUint8();
495 aObj.tht_shape = readUint8();
496
497 if( m_fileData.version >= 5 )
498 {
499 skip( 4 ); // padding
500 aObj.component_id = readUint16();
501 skip( 1 ); // selected
502 aObj.start_angle = readInt32(); // also th_style[4]
503 skip( 5 ); // unknown
504 aObj.filled = readUint8();
505 aObj.clearance = readInt32();
506 skip( 5 ); // padding
507 aObj.mirror_h = readUint8();
508 aObj.mirror_v = readUint8();
509 aObj.keepout = readUint8();
510 aObj.rotation = readInt32();
511 aObj.plated = readUint8();
512 aObj.soldermask = readUint8();
513 skip( 18 );
514
515 if( !aIsTextChild )
516 {
517 aObj.text = readVarString();
518 aObj.identifier = readVarString();
519 }
520 }
521 else if( m_fileData.version >= 4 )
522 {
523 skip( 4 ); // padding
524 skip( 3 );
525 aObj.start_angle = readInt32();
526 skip( 5 );
527 aObj.filled = readUint8();
528 aObj.clearance = readInt32();
529 skip( 9 ); // padding
530 aObj.mirror_h = readUint8(); // text H mirror
531 aObj.mirror_v = readUint8(); // text V mirror
532 aObj.keepout = readUint8();
533 skip( 18 );
534
535 if( !aIsTextChild )
536 {
537 aObj.text = readVarString();
538 }
539 }
540 else if( m_fileData.version >= 3 )
541 {
542 // 50 bytes of data
544 {
545 aObj.text = readFixedString( 15 );
546 skip( 7 );
547 aObj.rotation = readInt16();
548 skip( 25 );
549 }
550 else
551 {
552 skip( 23 );
553 aObj.start_angle = readInt32();
554 skip( 3 );
555 aObj.mirror_h = readUint8();
556 aObj.mirror_v = readUint8();
557 skip( 1 );
558 aObj.clearance = readInt32();
559 skip( 13 );
560 }
561 }
562 else // Versions 1 and 2
563 {
564 // 35 bytes of data
566 {
567 aObj.text = readFixedString( 15 );
568 skip( 7 );
569 aObj.rotation = readInt16();
570 skip( 10 );
571 }
572 else
573 {
574 skip( 35 );
575 }
576 }
577
578 if( m_fileData.version >= 2 && !aIsTextChild )
579 parseGroups( aObj );
580
581 switch( aObj.type )
582 {
586 return;
587
590 parsePoints( aObj );
591 return;
592
594 if( m_fileData.version >= 5 )
595 parsePoints( aObj );
596 else if( m_fileData.version >= 3 )
597 skip( 4 ); // Usually 0xFFFFFFFF
598
599 return;
600
602 if( m_fileData.version >= 5 )
603 parsePoints( aObj );
604
605 return; // No points in older versions
606
608 {
609 // Only present since version 3
610 uint32_t childCount = readUint32();
611
612 if( childCount > MAX_CHILDREN )
613 THROW_IO_ERROR( _( "Too many text children in Sprint Layout object" ) );
614
615 aObj.text_children.resize( childCount );
616
617 for( uint32_t i = 0; i < childCount; i++ )
618 parseObject( aObj.text_children[i], true );
619
620 // In v6, component data follows for text objects that define a component
621 if( m_fileData.version >= 6 && aObj.tht_shape == 1 )
622 {
623 aObj.component.valid = true;
624 aObj.component.off_x = readCoord();
625 aObj.component.off_y = readCoord();
630 aObj.component.use = readUint8();
631 }
632
633 return;
634 }
635
636 default:
637 THROW_IO_ERRORF( _( "Unknown object type %d in Sprint Layout file" ), aObj.type );
638 }
639}
640
641
643{
644 if( m_fileData.version >= 4 )
645 {
646 readUint32(); // active_board_tab
647 m_fileData.project_name = readFixedString( 100 );
648 m_fileData.project_author = readFixedString( 100 );
649 m_fileData.project_company = readFixedString( 100 );
650 m_fileData.project_comment = readVarString();
651 }
652}
653
654
655// ============================================================================
656// Board construction
657// ============================================================================
658
659PCB_LAYER_ID SPRINT_LAYOUT_PARSER::mapLayer( uint8_t aSprintLayer ) const
660{
661 if( m_fileData.version >= 4 )
662 {
663 switch( aSprintLayer )
664 {
665 case SPRINT_LAYOUT::LAYER_C1: return F_Cu;
666 case SPRINT_LAYOUT::LAYER_S1: return F_SilkS;
667 case SPRINT_LAYOUT::LAYER_C2: return B_Cu;
668 case SPRINT_LAYOUT::LAYER_S2: return B_SilkS;
669 case SPRINT_LAYOUT::LAYER_I1: return In1_Cu;
670 case SPRINT_LAYOUT::LAYER_I2: return In2_Cu;
672 default: return F_Cu;
673 }
674 }
675 else
676 {
677 // In older Sprint Layout versions the meaning of C1/C2 is flipped
678 switch( aSprintLayer )
679 {
680 case SPRINT_LAYOUT::LAYER_C1: return m_fileData.version >= 3 ? F_Cu : B_Cu;
681 case SPRINT_LAYOUT::LAYER_S1: return F_SilkS;
682 case SPRINT_LAYOUT::LAYER_C2: return m_fileData.version >= 3 ? B_Cu : F_Cu;
683 case SPRINT_LAYOUT::LAYER_S2: return B_SilkS;
685 case SPRINT_LAYOUT::LAYER_I1: return B_Cu; // used for PTH pads and tracks inside macros
686 case SPRINT_LAYOUT::LAYER_I2: return F_SilkS; // used for graphics inside macros
687 default: return F_Cu;
688 }
689 }
690}
691
692
694{
695 // Sprint Layout 6 uses 1/10000 mm
696 // Older versions seem to use 1/100 mm
697 // KiCad uses nanometers (1 nm = 1e-6 mm)
698 double nm;
699
700 if( m_fileData.version >= 6 )
701 nm = static_cast<double>( aValue ) * 100.0; // 100 nm
702 else
703 nm = static_cast<double>( aValue ) * 10000.0; // 10 um
704
705 nm = std::clamp( nm, static_cast<double>( -pcbIUScale.mmToIU( 500 ) ),
706 static_cast<double>( pcbIUScale.mmToIU( 500 ) ) );
707
708 return KiROUND( nm );
709}
710
711
713{
714 // Sprint Layout uses Y-up (mathematical), KiCad uses Y-down (screen)
715 return VECTOR2I( sprintToKicadCoord( aX ), sprintToKicadCoord( -aY ) );
716}
717
718
719wxString SPRINT_LAYOUT_PARSER::convertString( const std::string& aStr ) const
720{
721 static wxCSConv convCP1251( wxFONTENCODING_CP1251 );
722 static wxCSConv convCP1252( wxFONTENCODING_CP1252 );
723
724 if( aStr.empty() )
725 return wxEmptyString;
726
727 wxString ret = wxString::FromUTF8( aStr );
728
729 if( ret.empty() && convCP1251.IsOk() && convCP1252.IsOk() )
730 {
731 // Statistically determine if the string is more likely to be CP1251 (Cyrillic) or CP1252 (Western European)
732 size_t extNonGermanCount = 0;
733
734 for( unsigned char c : aStr )
735 {
736 // Extended-range German characters in CP1252
737 switch( c )
738 {
739 case 0xC4: // Ä
740 case 0xD6: // Ö
741 case 0xDC: // Ü
742 case 0xE4: // ä
743 case 0xF6: // ö
744 case 0xFC: // ü
745 case 0xDF: // ß
746 break;
747
748 default:
749 if( c >= 0x80 )
750 extNonGermanCount++;
751
752 break;
753 }
754 }
755
756 if( extNonGermanCount > 0 )
757 ret = wxString( aStr.c_str(), convCP1251 );
758 else
759 ret = wxString( aStr.c_str(), convCP1252 );
760 }
761
762 return ret;
763}
764
765
766bool SPRINT_LAYOUT_PARSER::layerHasGroundPlane( PCB_LAYER_ID aLayer, const uint8_t aGroundPlane[7] ) const
767{
768 // Ground plane index map mirrors CreateBoard()'s groundPlaneMap
769 if( m_fileData.version >= 5 )
770 {
771 switch( aLayer )
772 {
773 case F_Cu: return aGroundPlane[0] != 0;
774 case B_Cu: return aGroundPlane[2] != 0;
775 case In1_Cu: return aGroundPlane[4] != 0;
776 case In2_Cu: return aGroundPlane[5] != 0;
777 default: return false;
778 }
779 }
780 else
781 {
782 switch( aLayer )
783 {
784 case F_Cu: return aGroundPlane[0] != 0;
785 case B_Cu: return aGroundPlane[1] != 0;
786 default: return false;
787 }
788 }
789}
790
791
793 PCB_LAYER_ID aLayer, const uint8_t aGroundPlane[7],
794 NETINFO_ITEM* aGndPlaneNet ) const
795{
796 if( !aBoard )
797 return nullptr;
798
799 bool isPad = aObj.type == SPRINT_LAYOUT::OBJ_THT_PAD || aObj.type == SPRINT_LAYOUT::OBJ_SMD_PAD;
800
801 // Override the net for ground plane connection. Note that the identifier string
802 // could specify anything (e.g. component value), not just the net name
803 if( aGndPlaneNet != nullptr && layerHasGroundPlane( aLayer, aGroundPlane ) )
804 {
805 if( aObj.clearance == 0 )
806 return aGndPlaneNet;
807
808 // If pad thermal reliefs are enabled, connect to the plane
809 if( m_fileData.version >= 5 && isPad && aObj.mirror_h != 0 )
810 return aGndPlaneNet;
811 }
812
813 // TODO: if a pad is connected through lines to the GND_PLANE, we don't want to set the pad's
814 // netname as this would update the nets of the lines, disconnecting them from the plane.
815 //
816 //if( !aObj.identifier.empty() )
817 //{
818 // wxString netName = convertString( aObj.identifier );
819 // NETINFO_ITEM* net = aBoard->FindNet( netName );
820
821 // if( !net )
822 // {
823 // net = new NETINFO_ITEM( aBoard, netName );
824 // aBoard->Add( net );
825 // }
826
827 // return net;
828 //}
829
830 return nullptr;
831}
832
833
834bool SPRINT_LAYOUT_PARSER::CreateBoard( BOARD& aBoard, std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
835 size_t aBoardIndex )
836{
837 if( aBoardIndex >= m_fileData.boards.size() )
838 return false;
839
840 BOARD* board = &aBoard;
841
842 // Set up copper layers based on whether inner layers are used
843 const SPRINT_LAYOUT::BOARD_DATA& boardData = m_fileData.boards[aBoardIndex];
844 bool hasInnerLayers = false;
845
846 for( const SPRINT_LAYOUT::OBJECT& obj : boardData.objects )
847 {
849 {
850 hasInnerLayers = true;
851 break;
852 }
853 }
854
855 if( hasInnerLayers || boardData.is_multilayer )
856 board->SetCopperLayerCount( 4 );
857 else
858 board->SetCopperLayerCount( 2 );
859
860 // Create ground plane zones for layers where ground plane is enabled.
861 // Sprint Layout stores a per-layer flag in the board header.
862 const wxString gndPlaneNetName( "GND_PLANE" );
863 std::map<int, PCB_LAYER_ID> groundPlaneMap;
864 LSET groundPlaneLayerSet;
865 NETINFO_ITEM* gndPlaneNet = nullptr;
866
867 if( m_fileData.version >= 5 )
868 {
869 groundPlaneMap = {
870 { 0, F_Cu },
871 { 2, B_Cu },
872 { 4, In1_Cu },
873 { 5, In2_Cu },
874 };
875 }
876 else
877 {
878 groundPlaneMap = {
879 { 0, F_Cu },
880 { 1, B_Cu },
881 };
882 }
883
884 for( const auto& [index, layer] : groundPlaneMap )
885 {
886 if( boardData.ground_plane[index] != 0 )
887 groundPlaneLayerSet.set( layer );
888 }
889
890 if( groundPlaneLayerSet.any() )
891 {
892 int w = sprintToKicadCoord( static_cast<float>( boardData.size_x ) );
893 int h = sprintToKicadCoord( static_cast<float>( boardData.size_y ) );
894
895 gndPlaneNet = board->FindOrAddNet( gndPlaneNetName );
896
897 ZONE* zone = new ZONE( board );
898 zone->SetLayerSet( groundPlaneLayerSet );
899 zone->SetIsRuleArea( false );
900 zone->SetZoneName( wxS( "GND_PLANE" ) );
901 zone->SetLocalClearance( std::optional<int>( pcbIUScale.mmToIU( 0.3 ) ) );
902 zone->SetThermalReliefGap( pcbIUScale.mmToIU( 0.5 ) );
903 zone->SetThermalReliefSpokeWidth( pcbIUScale.mmToIU( 0.5 ) );
904 zone->SetAssignedPriority( 0 );
906 zone->SetNet( gndPlaneNet );
907
908 SHAPE_POLY_SET outline( BOX2D( VECTOR2D( 0, 0 ), VECTOR2D( w, h ) ) );
909 zone->AddPolygon( outline.COutline( 0 ) );
911
912 board->Add( zone );
913 }
914
915 // Maps component_id to FOOTPRINT for grouping component-owned objects
916 std::map<uint16_t, FOOTPRINT*> componentMap;
917 std::vector<std::vector<VECTOR2I>> outlineSegments;
918
919 auto getOrCreateComponentFootprint =
920 [&]( const SPRINT_LAYOUT::OBJECT& aObj ) -> FOOTPRINT*
921 {
922 if( aObj.component_id == 0 )
923 return nullptr;
924
925 auto it = componentMap.find( aObj.component_id );
926
927 if( it != componentMap.end() )
928 return it->second;
929
930 FOOTPRINT* fp = new FOOTPRINT( board );
931
932 if( aObj.type == SPRINT_LAYOUT::OBJ_STROKE_TEXT && !aObj.text.empty() )
933 {
934 fp->SetReference( convertString( aObj.text ) );
935 }
936 else
937 {
938 fp->SetReference( wxString::Format( wxS( "U%d" ), aObj.component_id ) );
939
940 for( PCB_FIELD* fd : fp->GetFields() )
941 fd->SetVisible( false );
942 }
943
944 if( aObj.type == SPRINT_LAYOUT::OBJ_STROKE_TEXT && aObj.component.valid )
945 {
946 if( !aObj.component.comment.empty() )
947 {
948 wxString comment = convertString( aObj.component.comment );
949 fp->GetField( FIELD_T::DESCRIPTION )->SetText( comment );
950 fp->SetValue( comment );
951 }
952 else if( !aObj.identifier.empty() )
953 {
954 fp->SetValue( convertString( aObj.identifier ) );
955 }
956
957 if( !aObj.component.package.empty() )
958 fp->SetLibDescription( convertString( aObj.component.package ) );
959
960 fp->SetOrientationDegrees( aObj.component.rotation );
961 }
962
963 PCB_LAYER_ID layer = mapLayer( aObj.layer );
964 fp->SetLayer( ( layer == B_Cu || layer == B_SilkS ) ? B_Cu : F_Cu );
965
966 componentMap[aObj.component_id] = fp;
967 board->Add( fp );
968 return fp;
969 };
970
971 // First pass: create footprints from component text records where available
972 for( const SPRINT_LAYOUT::OBJECT& obj : boardData.objects )
973 {
974 if( obj.type == SPRINT_LAYOUT::OBJ_STROKE_TEXT && obj.component_id > 0 && obj.component.valid )
975 getOrCreateComponentFootprint( obj );
976 }
977
978 std::map<uint32_t, std::set<BOARD_ITEM*>> gidToItems;
979
980 // Second pass: process all objects in board/footprint context
981 for( const SPRINT_LAYOUT::OBJECT& obj : boardData.objects )
982 {
983 BOARD_ITEM_CONTAINER* container = board;
984
985 if( FOOTPRINT* fp = getOrCreateComponentFootprint( obj ) )
986 container = fp;
987
988 // clang-format off
989 switch( obj.type )
990 {
993 processPad( container, obj, boardData.ground_plane, gndPlaneNet, gidToItems );
994 break;
995
997 processSegment( container, obj, outlineSegments, boardData.ground_plane, gndPlaneNet, gidToItems );
998 break;
999
1001 processLine( container, obj, outlineSegments, boardData.ground_plane, gndPlaneNet, gidToItems );
1002 break;
1003
1005 processPoly( container, obj, outlineSegments, boardData.ground_plane, gndPlaneNet, gidToItems );
1006 break;
1007
1009 processCircle( container, obj, outlineSegments, boardData.ground_plane, gndPlaneNet, gidToItems );
1010 break;
1011
1014 processText( container, obj, gidToItems );
1015 break;
1016
1017 default:
1018 break;
1019 }
1020 // clang-format on
1021 }
1022
1023 resolveGroups( board, gidToItems );
1024
1025 // Re-anchor footprints after all elements are added.
1026 for( FOOTPRINT* fp : board->Footprints() )
1027 {
1028 BOX2I fpBbox = fp->GetBoundingHull().BBox();
1029
1030 VECTOR2I anchor = fpBbox.GetCenter();
1031 fp->SetPosition( anchor );
1032
1033 VECTOR2I anchorShift( -anchor.x, -anchor.y );
1034 RotatePoint( anchorShift, fp->GetOrientation() );
1035 fp->MoveAnchorPosition( anchorShift );
1036 }
1037
1038 // Fill the footprint map
1039 for( const auto& [componentId, fp] : componentMap )
1040 {
1041 wxString fpKey = wxString::Format( wxS( "SprintLayout_%s" ), fp->GetReference() );
1042 FOOTPRINT* fpCopy = static_cast<FOOTPRINT*>( fp->Clone() );
1043 fpCopy->SetParent( nullptr );
1044 aFootprintMap[fpKey] = std::unique_ptr<FOOTPRINT>( fpCopy );
1045 }
1046
1047 buildOutline( board, outlineSegments, boardData );
1048
1049 // Center the board content on the page
1050 BOX2I bbox = board->ComputeBoundingBox( true );
1051
1052 if( bbox.GetWidth() > 0 && bbox.GetHeight() > 0 )
1053 {
1054 VECTOR2I pageSize = board->GetPageSettings().GetSizeIU( pcbIUScale.IU_PER_MILS );
1055 VECTOR2I centerOffset = VECTOR2I( pageSize.x / 2, pageSize.y / 2 ) - bbox.GetCenter();
1056
1057 for( FOOTPRINT* fp : board->Footprints() )
1058 fp->Move( centerOffset );
1059
1060 for( ZONE* zone : board->Zones() )
1061 zone->Move( centerOffset );
1062
1063 for( BOARD_ITEM* item : board->Drawings() )
1064 item->Move( centerOffset );
1065 }
1066
1067 return true;
1068}
1069
1070
1071std::unique_ptr<FOOTPRINT> SPRINT_LAYOUT_PARSER::CreateFootprint()
1072{
1073 if( m_fileData.boards.empty() )
1074 return nullptr;
1075
1076 const SPRINT_LAYOUT::BOARD_DATA& boardData = m_fileData.boards[0];
1077
1078 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>( nullptr );
1079
1080 wxString fpName = convertString( boardData.name );
1081
1082 fp->SetFPID( LIB_ID( wxEmptyString, fpName ) );
1083 fp->SetReference( wxT( "REF**" ) );
1084 fp->SetValue( fpName );
1085 fp->Reference().SetVisible( true );
1086 fp->Value().SetVisible( true );
1087
1088 std::vector<std::vector<VECTOR2I>> outlineSegments;
1089 uint8_t groundPlane[7] = {};
1090 std::map<uint32_t, std::set<BOARD_ITEM*>> gidToItems;
1091
1092 for( const SPRINT_LAYOUT::OBJECT& obj : boardData.objects )
1093 {
1094 BOARD_ITEM_CONTAINER* container = fp.get();
1095
1096 // clang-format off
1097 switch( obj.type )
1098 {
1101 processPad( container, obj, groundPlane, nullptr, gidToItems );
1102 break;
1103
1105 processSegment( container, obj, outlineSegments, groundPlane, nullptr, gidToItems );
1106 break;
1107
1109 processLine( container, obj, outlineSegments, groundPlane, nullptr, gidToItems );
1110 break;
1111
1113 processPoly( container, obj, outlineSegments, groundPlane, nullptr, gidToItems );
1114 break;
1115
1117 processCircle( container, obj, outlineSegments, groundPlane, nullptr, gidToItems );
1118 break;
1119
1122 processText( container, obj, gidToItems );
1123 break;
1124
1125 default:
1126 break;
1127 }
1128 // clang-format on
1129 }
1130
1131 resolveGroups( fp.get(), gidToItems );
1132
1133 fp->AutoPositionFields();
1134
1135 // Generate basic courtyard rectangle
1136 BOX2I bbox = fp->GetBoundingHull().BBox();
1137 bbox.Inflate( pcbIUScale.mmToIU( 0.25 ) ); // Default courtyard clearance
1138
1139 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( fp.get(), SHAPE_T::RECTANGLE );
1140 shape->SetWidth( pcbIUScale.mmToIU( DEFAULT_COURTYARD_WIDTH ) );
1141 shape->SetLayer( F_CrtYd );
1142 shape->SetStart( bbox.GetOrigin() );
1143 shape->SetEnd( bbox.GetEnd() );
1144
1145 fp->Add( shape.release(), ADD_MODE::APPEND );
1146
1147 return fp;
1148}
1149
1150
1152 const uint8_t aGroundPlane[7], NETINFO_ITEM* aGndPlaneNet,
1153 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1154{
1155 BOARD* board = aContainer ? aContainer->GetBoard() : nullptr;
1156 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aContainer );
1157 bool standaloneFp = false;
1158
1159 if( !fp )
1160 {
1161 // Standalone pad without a component gets its own footprint
1162 standaloneFp = true;
1163 fp = new FOOTPRINT( board );
1164 fp->SetReference( wxString::Format( wxS( "PAD%d" ), static_cast<int>( board->Footprints().size() ) ) );
1165 fp->Reference().SetVisible( false );
1166 fp->SetLayer( F_Cu );
1167 aContainer->Add( fp );
1168 }
1169
1170 PAD* pad = new PAD( fp );
1171
1172 // SMD pad x,y may be a component-relative offset rather than an absolute
1173 // position (depends on the Sprint Layout version that created the file).
1174 // The points array always stores absolute coordinates, so derive the pad
1175 // center from the points when available.
1176 // The rotation field for pads (both TH and SMD) is unknown, so detect
1177 // the pad angle from the points when possible.
1178 VECTOR2I ptsCenter;
1179 EDA_ANGLE ptsAngle;
1180
1181 if( !aObj.points.empty() )
1182 {
1183 double cx = 0, cy = 0;
1184
1185 for( const SPRINT_LAYOUT::POINT& pt : aObj.points )
1186 {
1187 cx += pt.x;
1188 cy += pt.y;
1189 }
1190
1191 cx /= static_cast<double>( aObj.points.size() );
1192 cy /= static_cast<double>( aObj.points.size() );
1193 ptsCenter = sprintToKicadPos( static_cast<float>( cx ), static_cast<float>( cy ) );
1194
1195 std::vector<VECTOR2I> pts;
1196
1197 for( const SPRINT_LAYOUT::POINT& pt : aObj.points )
1198 pts.emplace_back( sprintToKicadPos( pt.x, pt.y ) );
1199
1200 if( pts.size() == 2 ) // Oval or circle
1201 {
1202 ptsAngle = EDA_ANGLE( pts[1] - pts[0] );
1203
1205 ptsAngle -= ANGLE_90;
1206 }
1207 else if( pts.size() == 4 ) // Rectangular
1208 {
1209 ptsAngle = EDA_ANGLE( pts[1] - pts[0] );
1210 }
1211 else if( pts.size() == 8 ) // Octagonal
1212 {
1213 ptsAngle = EDA_ANGLE( pts[2] - pts[1] );
1214 }
1215 else
1216 {
1217 wxFAIL_MSG( wxString::Format( "Unknown pad type %d shape %d with %zu points", int( aObj.type ),
1218 int( aObj.tht_shape ), aObj.points.size() ) );
1219 }
1220
1221 ptsAngle = ptsAngle.Round( 2 );
1222 }
1223
1224 PCB_LAYER_ID padLayer = mapLayer( aObj.layer );
1225 VECTOR2I padPos = sprintToKicadPos( aObj.x, aObj.y );
1226
1227 if( aObj.type == SPRINT_LAYOUT::OBJ_THT_PAD )
1228 {
1229 int outerDia = sprintToKicadCoord( aObj.outer * 2.0f );
1230 int drillDia = sprintToKicadCoord( aObj.inner * 2.0f );
1231
1232 bool isPTH = aObj.plated != 0 || ( m_fileData.version <= 3 && aObj.layer == 5 );
1233
1234 if( isPTH )
1235 {
1236 pad->SetAttribute( PAD_ATTRIB::PTH );
1237 pad->SetLayerSet( PAD::PTHMask() );
1238 }
1239 else
1240 {
1241 pad->SetAttribute( drillDia > 0 ? PAD_ATTRIB ::NPTH : PAD_ATTRIB::SMD );
1242
1243 if( padLayer == F_Cu )
1244 pad->SetLayerSet( LSET( { F_Cu, F_Mask } ) );
1245 else if( padLayer == B_Cu )
1246 pad->SetLayerSet( LSET( { B_Cu, B_Mask } ) );
1247 else
1248 pad->SetLayerSet( LSET( { padLayer } ) );
1249
1250 if( standaloneFp && IsBackLayer( padLayer ) )
1251 fp->SetLayer( B_Cu );
1252 }
1253
1254 VECTOR2I padSize( outerDia, outerDia );
1255 VECTOR2I drillSize( drillDia, drillDia );
1256
1257 switch( aObj.tht_shape )
1258 {
1262 padSize.x *= 2;
1263 break;
1264
1268 padSize.y *= 2;
1269 break;
1270
1271 default:
1272 break;
1273 }
1274
1275 pad->SetSize( PADSTACK::TEMP_ALL_LAYERS, padSize );
1276 pad->SetDrillSize( drillSize );
1277
1278 switch( aObj.tht_shape )
1279 {
1282 break;
1283
1287 break;
1288
1293 pad->SetChamferRectRatio( PADSTACK::TEMP_ALL_LAYERS, 0.25 );
1294 pad->SetChamferPositions( PADSTACK::TEMP_ALL_LAYERS, RECT_CHAMFER_ALL );
1295 break;
1296
1301 break;
1302
1303 default:
1305 break;
1306 }
1307
1308 pad->SetPosition( padPos );
1309 pad->Rotate( padPos, -ptsAngle );
1310 }
1311 else
1312 {
1313 pad->SetAttribute( PAD_ATTRIB::SMD );
1314
1315 if( padLayer == F_Cu )
1316 pad->SetLayerSet( LSET( { F_Cu, F_Paste, F_Mask } ) );
1317 else if( padLayer == B_Cu )
1318 pad->SetLayerSet( LSET( { B_Cu, B_Paste, B_Mask } ) );
1319 else
1320 pad->SetLayerSet( LSET( { padLayer } ) );
1321
1322 if( standaloneFp && IsBackLayer( padLayer ) )
1323 fp->SetLayer( B_Cu );
1324
1326
1327 int width = sprintToKicadCoord( aObj.outer );
1328 int height = sprintToKicadCoord( aObj.inner );
1329
1330 if( height <= 0 )
1331 height = width;
1332
1333 if( !aObj.points.empty() )
1334 padPos = ptsCenter;
1335
1336 pad->SetSize( PADSTACK::TEMP_ALL_LAYERS, VECTOR2I( width, height ) );
1337 pad->SetPosition( padPos );
1338 pad->Rotate( padPos, -ptsAngle );
1339 }
1340
1341 // Solder mask: soldermask==0 means no mask opening (pad is tented/covered)
1342 if( aObj.soldermask == 0 )
1343 {
1344 pad->Padstack().FrontOuterLayers().has_solder_mask = false;
1345 pad->Padstack().BackOuterLayers().has_solder_mask = false;
1346 }
1347
1348 // Per-element ground plane clearance
1349 if( aObj.clearance > 0 )
1350 {
1351 int clearance = sprintToKicadCoord( static_cast<float>( aObj.clearance ) );
1352 pad->SetLocalClearance( std::optional<int>( clearance ) );
1353 pad->SetLocalThermalGapOverride( std::optional<int>( clearance ) );
1354 }
1355
1356 // Thermal reliefs
1357 if( m_fileData.version >= 5 && aObj.mirror_h != 0 )
1358 {
1359 int spokeWidth = aObj.rotation * 10000 / 2;
1360 pad->SetLocalThermalSpokeWidthOverride( spokeWidth );
1361
1362 // Each byte is the spoke directions for one copper layer (C1, C2, I1, I2).
1363 // 0x55 matches H/V directions, 0xAA matches diagonal directions
1364 uint32_t spokeMask = static_cast<uint32_t>( aObj.start_angle );
1365
1366 if( spokeMask != 0 )
1367 {
1368 pad->SetLocalZoneConnection( ZONE_CONNECTION::THERMAL );
1369
1370 if( spokeMask & 0x55555555 )
1371 pad->SetThermalSpokeAngle( ANGLE_90 );
1372 else if( spokeMask & 0xAAAAAAAA )
1373 pad->SetThermalSpokeAngle( ANGLE_45 );
1374 }
1375 else
1376 {
1377 pad->SetLocalZoneConnection( ZONE_CONNECTION::NONE );
1378 }
1379 }
1380 else
1381 {
1382 pad->SetLocalZoneConnection( ZONE_CONNECTION::FULL );
1383 pad->SetThermalSpokeAngle( ANGLE_90 );
1384 }
1385
1386 // Set net name. Plated THT pads span all copper layers, so accept the GND
1387 // default when any configured ground-plane layer is enabled; SMD and NPTH
1388 // pads only qualify on their own layer.
1389 PCB_LAYER_ID netLayer = padLayer;
1390
1391 if( aObj.type == SPRINT_LAYOUT::OBJ_THT_PAD && aObj.plated != 0
1392 && !layerHasGroundPlane( padLayer, aGroundPlane ) )
1393 {
1394 if( aGroundPlane[0] )
1395 netLayer = F_Cu;
1396 else if( aGroundPlane[2] )
1397 netLayer = B_Cu;
1398 else if( aGroundPlane[4] )
1399 netLayer = In1_Cu;
1400 else if( aGroundPlane[5] )
1401 netLayer = In2_Cu;
1402 }
1403
1404 if( NETINFO_ITEM* net = resolveItemNet( board, aObj, netLayer, aGroundPlane, aGndPlaneNet ) )
1405 pad->SetNet( net );
1406
1407 pad->SetNumber( wxString::Format( wxS( "%d" ), static_cast<int>( fp->Pads().size() + 1 ) ) );
1408
1409 fp->Add( pad );
1410
1411 if( standaloneFp )
1412 {
1413 for( PCB_FIELD* fd : fp->GetFields() )
1414 fd->SetTextPos( pad->GetPosition() );
1415
1416 processItemGroups( fp, aObj, aGidToItems );
1417 }
1418 else
1419 {
1420 processItemGroups( pad, aObj, aGidToItems );
1421 }
1422}
1423
1424
1426 std::vector<std::vector<VECTOR2I>>& aOutlineSegments,
1427 const uint8_t aGroundPlane[7], NETINFO_ITEM* aGndPlaneNet,
1428 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1429{
1430 if( aObj.points.size() < 2 )
1431 return;
1432
1433 BOARD* board = aContainer ? aContainer->GetBoard() : nullptr;
1434 PCB_LAYER_ID layer = mapLayer( aObj.layer );
1435
1436 if( layer == Edge_Cuts )
1437 {
1438 std::vector<VECTOR2I> segment;
1439
1440 for( const SPRINT_LAYOUT::POINT& pt : aObj.points )
1441 segment.push_back( sprintToKicadPos( pt.x, pt.y ) );
1442
1443 aOutlineSegments.push_back( std::move( segment ) );
1444 return;
1445 }
1446
1447 int width = sprintToKicadCoord( static_cast<float>( aObj.line_width ) );
1448
1449 if( width <= 0 )
1450 width = pcbIUScale.mmToIU( 0.25 );
1451
1452 for( size_t i = 0; i + 1 < aObj.points.size(); i++ )
1453 {
1454 PCB_SHAPE* shape = new PCB_SHAPE( aContainer );
1455 shape->SetShape( SHAPE_T::SEGMENT );
1456 shape->SetLayer( layer );
1457 shape->SetWidth( width );
1458 shape->SetStart( sprintToKicadPos( aObj.points[i].x, aObj.points[i].y ) );
1459 shape->SetEnd( sprintToKicadPos( aObj.points[i + 1].x, aObj.points[i + 1].y ) );
1460
1461 if( IsCopperLayer( layer ) )
1462 {
1463 if( NETINFO_ITEM* net = resolveItemNet( board, aObj, layer, aGroundPlane, aGndPlaneNet ) )
1464 shape->SetNet( net );
1465 }
1466
1467 aContainer->Add( shape );
1468 processItemGroups( shape, aObj, aGidToItems );
1469 }
1470}
1471
1472
1474 std::vector<std::vector<VECTOR2I>>& aOutlineSegments,
1475 const uint8_t aGroundPlane[7], NETINFO_ITEM* aGndPlaneNet,
1476 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1477{
1478 PCB_LAYER_ID layer = mapLayer( aObj.layer );
1479
1480 if( layer == Edge_Cuts )
1481 {
1482 std::vector<VECTOR2I> seg;
1483 seg.push_back( sprintToKicadPos( aObj.x, aObj.y ) );
1484 seg.push_back( sprintToKicadPos( aObj.outer, aObj.inner ) );
1485 aOutlineSegments.push_back( std::move( seg ) );
1486 return;
1487 }
1488
1489 VECTOR2I start = sprintToKicadPos( aObj.x, aObj.y );
1490 VECTOR2I end = sprintToKicadPos( aObj.outer, aObj.inner );
1491 int width = sprintToKicadCoord( static_cast<float>( aObj.line_width ) );
1492
1493 // Skip the dummy segment at 0,0 in version 1 files
1494 if( aObj.line_width == 0 && start == end )
1495 return;
1496
1497 PCB_SHAPE* shape = new PCB_SHAPE( aContainer );
1498 shape->SetShape( SHAPE_T::SEGMENT );
1499 shape->SetLayer( layer );
1500 shape->SetWidth( width );
1501 shape->SetStart( start );
1502 shape->SetEnd( end );
1503
1504 aContainer->Add( shape );
1505 processItemGroups( shape, aObj, aGidToItems );
1506}
1507
1508
1510 std::vector<std::vector<VECTOR2I>>& aOutlineSegments,
1511 const uint8_t aGroundPlane[7], NETINFO_ITEM* aGndPlaneNet,
1512 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1513{
1514 if( aObj.points.size() < 2 )
1515 return;
1516
1517 BOARD* board = aContainer ? aContainer->GetBoard() : nullptr;
1518 PCB_LAYER_ID layer = mapLayer( aObj.layer );
1519
1520 if( layer == Edge_Cuts )
1521 {
1522 std::vector<VECTOR2I> points;
1523
1524 for( const SPRINT_LAYOUT::POINT& pt : aObj.points )
1525 points.push_back( sprintToKicadPos( pt.x, pt.y ) );
1526
1527 points.push_back( points[0] );
1528
1529 aOutlineSegments.push_back( std::move( points ) );
1530 return;
1531 }
1532
1533 //bool isFilled = ( aObj.filled != 0 );
1534 bool isCutout = ( aObj.keepout != 0 );
1535
1536 int width = sprintToKicadCoord( static_cast<float>( aObj.line_width ) );
1537
1538 if( width < 0 )
1539 width = pcbIUScale.mmToIU( 0.25 );
1540
1541 SHAPE_LINE_CHAIN outline;
1542
1543 for( const SPRINT_LAYOUT::POINT& pt : aObj.points )
1544 {
1545 VECTOR2I pos = sprintToKicadPos( pt.x, pt.y );
1546 outline.Append( pos.x, pos.y );
1547 }
1548
1549 outline.SetClosed( true ); // Deduplicate the last point properly
1550
1551 if( isCutout && IsCopperLayer( layer ) && aObj.points.size() >= 3 )
1552 {
1553 // Cutout area for ground plane exclusion -> rule area (keepout zone)
1554 ZONE* zone = new ZONE( aContainer );
1555 zone->SetLayer( layer );
1556 zone->SetIsRuleArea( true );
1557 zone->SetDoNotAllowZoneFills( true );
1558 zone->SetDoNotAllowTracks( false );
1559 zone->SetDoNotAllowVias( false );
1560 zone->SetDoNotAllowPads( false );
1561 zone->SetDoNotAllowFootprints( false );
1562
1563 zone->AddPolygon( outline );
1564 aContainer->Add( zone );
1565 processItemGroups( zone, aObj, aGidToItems );
1566 }
1567 else if( aObj.points.size() >= 3 )
1568 {
1569 // Filled polygon on non-copper layer -> filled PCB_SHAPE
1570 PCB_SHAPE* shape = new PCB_SHAPE( aContainer );
1571 shape->SetShape( SHAPE_T::POLY );
1572 shape->SetFilled( true );
1573 shape->SetLayer( layer );
1574 shape->SetWidth( width );
1575
1576 shape->SetPolyShape( SHAPE_POLY_SET( outline ) );
1577
1578 if( NETINFO_ITEM* net = resolveItemNet( board, aObj, layer, aGroundPlane, aGndPlaneNet ) )
1579 shape->SetNet( net );
1580
1581 aContainer->Add( shape );
1582 processItemGroups( shape, aObj, aGidToItems );
1583 }
1584}
1585
1586
1588 std::vector<std::vector<VECTOR2I>>& aOutlineSegments,
1589 const uint8_t aGroundPlane[7], NETINFO_ITEM* aGndPlaneNet,
1590 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1591{
1592 BOARD* board = aContainer ? aContainer->GetBoard() : nullptr;
1593 PCB_LAYER_ID layer = mapLayer( aObj.layer );
1594 VECTOR2I center = sprintToKicadPos( aObj.x, aObj.y );
1595 float radius = ( aObj.outer + aObj.inner ) / 2.0f;
1596 int kiRadius = sprintToKicadCoord( radius );
1597 int width = sprintToKicadCoord( aObj.outer - aObj.inner );
1598
1599 if( width <= 0 )
1600 width = pcbIUScale.mmToIU( 0.25 );
1601
1602 bool isFullCircle = true;
1603 double startAngleDeg = 0, endAngleDeg = 0;
1604
1605 if( m_fileData.version >= 3 )
1606 {
1607 startAngleDeg = aObj.start_angle;
1608 endAngleDeg = aObj.line_width;
1609
1610 if( m_fileData.version >= 6 )
1611 {
1612 // There's nothing else in the format to specify the angle scale
1613 // It's either in 1 degree or 0.001 degree units
1614 if( startAngleDeg > 1000 || startAngleDeg < -1000 || endAngleDeg > 1000 || endAngleDeg < -1000 )
1615 {
1616 startAngleDeg /= 1000;
1617 endAngleDeg /= 1000;
1618 }
1619 }
1620 // Older versions always use 1 degree units
1621
1622 isFullCircle = ( startAngleDeg == 0 && endAngleDeg == 0 )
1623 || ( endAngleDeg - startAngleDeg >= 360 )
1624 || ( startAngleDeg == endAngleDeg );
1625 }
1626 // Older versions do not have arcs
1627
1628 if( layer == Edge_Cuts )
1629 {
1630 // Approximate arcs as line segments for outline reconstruction
1631 std::vector<VECTOR2I> segment;
1632
1633 if( isFullCircle )
1634 {
1635 for( int i = 0; i <= 24; i++ )
1636 {
1637 double angle = ( static_cast<double>( i ) / 24.0 ) * 2.0 * M_PI;
1638 int px = center.x + static_cast<int>( std::cos( angle ) * kiRadius );
1639 int py = center.y - static_cast<int>( std::sin( angle ) * kiRadius );
1640 segment.emplace_back( px, py );
1641 }
1642 }
1643 else
1644 {
1645 int32_t sa = startAngleDeg * 1000;
1646 int32_t ea = endAngleDeg * 1000;
1647
1648 if( ea <= sa )
1649 ea += 360000;
1650
1651 for( int32_t a = sa; a <= ea; a += 15000 )
1652 {
1653 double rad = ( static_cast<double>( a ) / 1000.0 ) * M_PI / 180.0;
1654 int px = center.x + static_cast<int>( std::cos( rad ) * kiRadius );
1655 int py = center.y - static_cast<int>( std::sin( rad ) * kiRadius );
1656 segment.emplace_back( px, py );
1657 }
1658
1659 double endRad = ( static_cast<double>( ea ) / 1000.0 ) * M_PI / 180.0;
1660 int epx = center.x + static_cast<int>( std::cos( endRad ) * kiRadius );
1661 int epy = center.y - static_cast<int>( std::sin( endRad ) * kiRadius );
1662 segment.emplace_back( epx, epy );
1663 }
1664
1665 aOutlineSegments.push_back( std::move( segment ) );
1666 return;
1667 }
1668
1669 PCB_SHAPE* shape = new PCB_SHAPE( aContainer );
1670 shape->SetLayer( layer );
1671 shape->SetWidth( width );
1672
1673 if( isFullCircle )
1674 {
1675 shape->SetShape( SHAPE_T::CIRCLE );
1676 shape->SetCenter( center );
1677 shape->SetEnd( VECTOR2I( center.x + kiRadius, center.y ) );
1678 }
1679 else
1680 {
1681 shape->SetShape( SHAPE_T::ARC );
1682 shape->SetCenter( center );
1683
1684 // Y-flip reverses angular direction, so negate start angle
1685 double startRad = startAngleDeg * M_PI / 180.0;
1686 int sx = center.x + static_cast<int>( std::cos( startRad ) * kiRadius );
1687 int sy = center.y - static_cast<int>( std::sin( startRad ) * kiRadius );
1688 shape->SetStart( VECTOR2I( sx, sy ) );
1689
1690 double newEndAngle = endAngleDeg;
1691
1692 if( newEndAngle < startAngleDeg )
1693 newEndAngle += 360;
1694
1695 // Negate arc angle for Y-flip (reverses sweep direction)
1696 double arcAngle = startAngleDeg - newEndAngle;
1697 shape->SetArcAngleAndEnd( EDA_ANGLE( arcAngle, DEGREES_T ), true );
1698 }
1699
1700 if( IsCopperLayer( layer ) )
1701 {
1702 if( NETINFO_ITEM* net = resolveItemNet( board, aObj, layer, aGroundPlane, aGndPlaneNet ) )
1703 shape->SetNet( net );
1704 }
1705
1706 aContainer->Add( shape );
1707 processItemGroups( shape, aObj, aGidToItems );
1708}
1709
1710
1712 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1713{
1714 FOOTPRINT* fp = dynamic_cast<FOOTPRINT*>( aContainer );
1715
1716 // Skip component reference/value text only when it is not attached to a footprint.
1717 if( aObj.component_id > 0 && !fp )
1718 return;
1719
1720 PCB_LAYER_ID layer = mapLayer( aObj.layer );
1721
1722 if( layer == Edge_Cuts )
1723 return;
1724
1725 PCB_TEXT* text = nullptr;
1726 bool add = false;
1727
1728 if( aObj.component_id > 0 && fp && aObj.type == SPRINT_LAYOUT::OBJ_STROKE_TEXT && aObj.tht_shape > 0
1729 && aObj.tht_shape <= 2 )
1730 {
1731 if( aObj.tht_shape == 1 )
1732 text = &fp->Reference();
1733 else if( aObj.tht_shape == 2 )
1734 text = &fp->Value();
1735 }
1736 else
1737 {
1738 if( aObj.text.empty() )
1739 return;
1740
1741 text = new PCB_TEXT( aContainer );
1742 add = true;
1743 }
1744
1745 if( !text )
1746 return;
1747
1748 // When inside a group, the rotation center seems to be at the group center.
1749 // Just so we don't have to do a complex fixup later, use points to detect
1750 // text center instead, they are always in absolute coordinates.
1751 VECTOR2I ptsCenter;
1752
1753 if( !aObj.text_children.empty() )
1754 {
1755 double cx = 0, cy = 0;
1756 size_t ptsCount = 0;
1757
1758 for( const SPRINT_LAYOUT::OBJECT& child : aObj.text_children )
1759 {
1760 if( child.type == SPRINT_LAYOUT::OBJ_LINE )
1761 {
1762 for( const SPRINT_LAYOUT::POINT& pt : child.points )
1763 {
1764 cx += pt.x;
1765 cy += pt.y;
1766 ptsCount += 1;
1767 }
1768 }
1769 else if( child.type == SPRINT_LAYOUT::OBJ_SEGMENT )
1770 {
1771 cx += child.x;
1772 cy += child.y;
1773 cx += child.outer;
1774 cy += child.inner;
1775 ptsCount += 2;
1776 }
1777 }
1778
1779 // Skip centering when the group contributed no points
1780 if( ptsCount > 0 )
1781 {
1782 cx /= static_cast<double>( ptsCount );
1783 cy /= static_cast<double>( ptsCount );
1784 ptsCenter = sprintToKicadPos( static_cast<float>( cx ), static_cast<float>( cy ) );
1785 }
1786 }
1787
1788 text->SetLayer( layer );
1789 text->SetText( convertString( aObj.text ) );
1790 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
1791 text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
1792 text->SetKeepUpright( false );
1793 text->SetVisible( aObj.component_id == 0 || aObj.filled != 0 );
1794
1796 {
1797 int height = sprintToKicadCoord( aObj.outer ) * 0.75;
1798
1799 if( height <= 0 )
1800 height = pcbIUScale.mmToIU( 1.0 );
1801
1802 double widthScale = 0.8 + 0.2 * aObj.line_width;
1803 text->SetTextSize( VECTOR2I( height * widthScale, height ) );
1804
1805 double thicknessScale = 0.06 + 0.05 * aObj.inner;
1806 int thickness = height * thicknessScale;
1807
1808 if( thickness <= 0 )
1809 thickness = std::max( 1, height / 8 );
1810
1811 text->SetTextThickness( thickness );
1812 }
1813 else
1814 {
1815 // -133 maps to 1 mm height
1816 int normalized = std::abs( aObj.line_width ) * 100 / 133;
1817 int height = sprintToKicadCoord( normalized ) * 0.75;
1818
1819 if( aObj.line_width < 0 ) // Seems to be always
1820 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
1821
1822 text->SetTextSize( VECTOR2I( height, height ) );
1823 text->SetTextThickness( height / 8 );
1824 }
1825
1826 VECTOR2I untransformedPos = sprintToKicadPos( aObj.x, aObj.y );
1827 text->SetTextPos( untransformedPos );
1828 VECTOR2I untransformedCenter = text->GetCenter();
1829
1830 VECTOR2I newCenter = !aObj.text_children.empty() ? ptsCenter : untransformedCenter;
1831 text->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
1832 text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
1833 text->SetTextPos( newCenter );
1834
1835 int rotation = 0;
1836
1837 if( m_fileData.version == 4 )
1838 rotation = aObj.start_angle * 90;
1839 else
1840 rotation = aObj.rotation;
1841
1842 bool mirrorH = aObj.mirror_h != 0;
1843 bool mirrorV = aObj.mirror_v != 0;
1844
1845 if( mirrorH ^ mirrorV )
1846 {
1847 text->SetMirrored( true );
1848 text->SetHorizJustify( (GR_TEXT_H_ALIGN_T) -text->GetHorizJustify() );
1849 rotation = -rotation;
1850 }
1851
1852 if( mirrorV )
1853 text->Rotate( newCenter, ANGLE_180 );
1854
1855 text->Rotate( newCenter, EDA_ANGLE( -rotation, DEGREES_T ) );
1856
1857 if( add )
1858 aContainer->Add( text );
1859
1860 processItemGroups( text, aObj, aGidToItems );
1861}
1862
1863
1865 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1866{
1867 for( uint32_t gid : aObj.groups )
1868 aGidToItems[gid].insert( aItem );
1869}
1870
1871
1873 std::map<uint32_t, std::set<BOARD_ITEM*>>& aGidToItems )
1874{
1875 std::map<uint32_t, PCB_GROUP*> gidGroupMap;
1876 std::vector<uint32_t> gidAscBySize;
1877
1878 for( const auto& [gid, _] : aGidToItems )
1879 {
1880 PCB_GROUP* group = new PCB_GROUP( aContainer );
1881
1882 gidGroupMap[gid] = group;
1883 gidAscBySize.push_back( gid );
1884
1885 if( aContainer )
1886 aContainer->Add( group );
1887 }
1888
1889 // Process groups in ascending member-count order (tie-break by group id) so smaller
1890 // groups attach first and larger groups can adopt them, producing stable nesting.
1891 std::sort( gidAscBySize.begin(), gidAscBySize.end(),
1892 [&]( uint32_t gidA, uint32_t gidB )
1893 {
1894 size_t sa = aGidToItems.at( gidA ).size();
1895 size_t sb = aGidToItems.at( gidB ).size();
1896
1897 if( sa != sb )
1898 return sa < sb;
1899
1900 return gidA < gidB;
1901 } );
1902
1903 for( uint32_t gid : gidAscBySize )
1904 {
1905 PCB_GROUP* grp = gidGroupMap[gid];
1906
1907 for( BOARD_ITEM* item : aGidToItems[gid] )
1908 {
1909 if( PCB_GROUP* itemGroup = static_cast<PCB_GROUP*>( item->GetParentGroup() ) )
1910 {
1911 if( itemGroup != grp )
1912 grp->AddItem( itemGroup );
1913 }
1914 else
1915 {
1916 // Only add if we don't cross board-footprint boundaries
1917 if( item->GetParent() == grp->GetParent() )
1918 grp->AddItem( item );
1919 }
1920 }
1921 }
1922}
1923
1924
1925void SPRINT_LAYOUT_PARSER::buildOutline( BOARD* aBoard, std::vector<std::vector<VECTOR2I>>& aOutlineSegments,
1926 const SPRINT_LAYOUT::BOARD_DATA& aBoardData )
1927{
1928 // Try to join outline segments into closed polygons
1929 // Similar to OpenBoardView's outline_order_segments algorithm
1930 static const int PROXIMITY_DELTA = 100; // 100 nm tolerance
1931
1932 auto closeEnough =
1933 []( const VECTOR2I& a, const VECTOR2I& b, int delta ) -> bool
1934 {
1935 return std::abs( a.x - b.x ) < delta && std::abs( a.y - b.y ) < delta;
1936 };
1937
1938 // Try to join segments end-to-end. After each successful join, restart
1939 // the inner scan because seg.back() has changed.
1940 for( size_t iterations = 0; iterations < aOutlineSegments.size(); iterations++ )
1941 {
1942 bool joined = false;
1943
1944 for( std::vector<VECTOR2I>& lineChain : aOutlineSegments )
1945 {
1946 if( lineChain.size() < 2 )
1947 continue;
1948
1949 for( std::vector<VECTOR2I>& other : aOutlineSegments )
1950 {
1951 if( &lineChain == &other || other.empty() )
1952 continue;
1953
1954 bool frontMatch = closeEnough( lineChain.back(), other.front(), PROXIMITY_DELTA );
1955 bool backMatch = !frontMatch && closeEnough( lineChain.back(), other.back(), PROXIMITY_DELTA );
1956
1957 if( backMatch )
1958 {
1959 std::reverse( other.begin(), other.end() );
1960 frontMatch = true;
1961 }
1962
1963 if( !frontMatch )
1964 continue;
1965
1966 if( lineChain.back() == other.front() )
1967 lineChain.insert( lineChain.end(), other.begin() + 1, other.end() );
1968 else
1969 lineChain.insert( lineChain.end(), other.begin(), other.end() );
1970
1971 other.clear();
1972 joined = true;
1973 break;
1974 }
1975 }
1976
1977 if( !joined )
1978 break;
1979 }
1980
1981 bool hasOutline = false;
1982
1983 // an edge drawn twice would read as a self-intersecting outline
1984 std::set<SEG> edges;
1985
1986 for( const std::vector<VECTOR2I>& seg : aOutlineSegments )
1987 {
1988 if( seg.size() < 2 )
1989 continue;
1990
1991 hasOutline = true;
1992
1993 for( size_t i = 0; i + 1 < seg.size(); i++ )
1994 {
1995 SEG edge( seg[i], seg[i + 1] );
1996
1997 if( !edges.insert( std::min( edge, edge.Reversed() ) ).second )
1998 continue;
1999
2000 PCB_SHAPE* shape = new PCB_SHAPE( aBoard );
2001 shape->SetShape( SHAPE_T::SEGMENT );
2002 shape->SetLayer( Edge_Cuts );
2003 shape->SetWidth( pcbIUScale.mmToIU( 0.1 ) );
2004 shape->SetStart( seg[i] );
2005 shape->SetEnd( seg[i + 1] );
2006 aBoard->Add( shape );
2007 }
2008 }
2009
2010 // Fallback: create rectangular outline from board dimensions
2011 if( !hasOutline )
2012 {
2013 int w = sprintToKicadCoord( static_cast<float>( aBoardData.size_x ) );
2014 int h = sprintToKicadCoord( static_cast<float>( aBoardData.size_y ) );
2015
2016 if( w > 0 && h > 0 )
2017 {
2018 VECTOR2I corners[4] = {
2019 { 0, 0 },
2020 { w, 0 },
2021 { w, h },
2022 { 0, h }
2023 };
2024
2025 for( int i = 0; i < 4; i++ )
2026 {
2027 PCB_SHAPE* shape = new PCB_SHAPE( aBoard );
2028 shape->SetShape( SHAPE_T::SEGMENT );
2029 shape->SetLayer( Edge_Cuts );
2030 shape->SetWidth( pcbIUScale.mmToIU( 0.1 ) );
2031 shape->SetStart( corners[i] );
2032 shape->SetEnd( corners[( i + 1 ) % 4] );
2033 aBoard->Add( shape );
2034 }
2035 }
2036 }
2037}
int index
static std::optional< VECTOR2D > normalized(const VECTOR2D &aVec)
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
#define DEFAULT_COURTYARD_WIDTH
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
BOX2< VECTOR2D > BOX2D
Definition box2.h:918
BASE_SET & set(size_t pos)
Definition base_set.h:126
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)=0
Adds an item to the container.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:281
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition board.cpp:1548
NETINFO_ITEM * FindOrAddNet(const wxString &aNetName, int aNetCode=-1, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)
Return the net with the given name, adding it to the board if there is none.
Definition board.cpp:2852
const PAGE_INFO & GetPageSettings() const
Definition board.h:1029
const ZONES & Zones() const
Definition board.h:469
const FOOTPRINTS & Footprints() const
Definition board.h:465
void SetCopperLayerCount(int aCount)
Definition board.cpp:1161
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aPhysicalLayersOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition board.cpp:2572
const DRAWINGS & Drawings() const
Definition board.h:467
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:556
constexpr const Vec GetEnd() const
Definition box2.h:215
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr const Vec GetCenter() const
Definition box2.h:233
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr const Vec & GetOrigin() const
Definition box2.h:213
EDA_ANGLE Round(int digits) const
Definition eda_angle.h:336
void AddItem(EDA_ITEM *aItem)
Add item to group.
Definition eda_group.cpp:58
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
virtual void SetFilled(bool aFlag)
Definition eda_shape.h:145
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
PCB_FIELD & Value()
read/write accessors:
Definition footprint.h:831
void SetOrientationDegrees(double aOrientation)
Definition footprint.h:408
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
std::deque< PAD * > & Pads()
Definition footprint.h:355
void SetReference(const wxString &aReference)
Definition footprint.h:799
void SetValue(const wxString &aValue)
Definition footprint.h:822
PCB_FIELD & Reference()
Definition footprint.h:832
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
void SetLibDescription(const wxString &aDesc)
Definition footprint.h:450
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Handle the data for a net.
Definition netinfo.h:50
static constexpr PCB_LAYER_ID TEMP_ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:181
Definition pad.h:61
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:620
const VECTOR2D GetSizeIU(double aIUScale) const
Gets the page size in internal units.
Definition page_info.h:172
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
void SetCenter(const VECTOR2I &aCenter) override
void SetWidth(int aWidth) override
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Definition pcb_shape.h:109
void SetShape(SHAPE_T aShape) override
Definition pcb_shape.h:214
void SetEnd(const VECTOR2I &aEnd) override
void SetPolyShape(const SHAPE_POLY_SET &aShape) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
Definition seg.h:38
SEG Reversed() const
Definition seg.h:391
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a set of closed polygons.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void processPoly(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments, const uint8_t aGroundPlane[7], NETINFO_ITEM *aGndPlaneNet, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
std::unique_ptr< FOOTPRINT > CreateFootprint()
void parsePoints(SPRINT_LAYOUT::OBJECT &aObj)
wxString convertString(const std::string &aStr) const
void processCircle(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments, const uint8_t aGroundPlane[7], NETINFO_ITEM *aGndPlaneNet, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
SPRINT_LAYOUT::FILE_DATA m_fileData
bool CreateBoard(BOARD &aBoard, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, size_t aBoardIndex=0)
PCB_LAYER_ID mapLayer(uint8_t aSprintLayer) const
void parseFileStart(const wxString &aFileName)
std::string readFixedString(size_t aMaxLen)
void processItemGroups(BOARD_ITEM *aItem, const SPRINT_LAYOUT::OBJECT &aObj, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
NETINFO_ITEM * resolveItemNet(BOARD *aBoard, const SPRINT_LAYOUT::OBJECT &aObj, PCB_LAYER_ID aLayer, const uint8_t aGroundPlane[7], NETINFO_ITEM *aGndPlaneNet) const
void processSegment(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments, const uint8_t aGroundPlane[7], NETINFO_ITEM *aGndPlaneNet, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
void buildOutline(BOARD *aBoard, std::vector< std::vector< VECTOR2I > > &aOutlineSegments, const SPRINT_LAYOUT::BOARD_DATA &aBoardData)
void processText(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
void parseGroups(SPRINT_LAYOUT::OBJECT &aObj)
void resolveGroups(BOARD_ITEM_CONTAINER *aContainer, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
void parseObject(SPRINT_LAYOUT::OBJECT &aObject, bool aIsTextChild=false)
void parseBoardHeader(SPRINT_LAYOUT::BOARD_DATA &aBoard)
void processPad(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, const uint8_t aGroundPlane[7], NETINFO_ITEM *aGndPlaneNet, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
VECTOR2I sprintToKicadPos(float aX, float aY) const
int sprintToKicadCoord(float aValue) const
void parseObjectsList(SPRINT_LAYOUT::BOARD_DATA &aBoard)
bool ParseMacroFile(const wxString &aFileName)
std::vector< uint8_t > m_buffer
bool layerHasGroundPlane(PCB_LAYER_ID aLayer, const uint8_t aGroundPlane[7]) const
void processLine(BOARD_ITEM_CONTAINER *aContainer, const SPRINT_LAYOUT::OBJECT &aObj, std::vector< std::vector< VECTOR2I > > &aOutlineSegments, const uint8_t aGroundPlane[7], NETINFO_ITEM *aGndPlaneNet, std::map< uint32_t, std::set< BOARD_ITEM * > > &aGidToItems)
bool ParseBoard(const wxString &aFileName)
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetDoNotAllowPads(bool aEnable)
Definition zone.h:860
void SetLocalClearance(std::optional< int > aClearance)
Definition zone.h:183
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
Definition zone.cpp:1502
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch, bool aRebuildBorderHatch)
Set all hatch parameters for the zone.
Definition zone.cpp:1618
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition zone.h:251
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:677
void SetIsRuleArea(bool aEnable)
Definition zone.h:835
void SetDoNotAllowTracks(bool aEnable)
Definition zone.h:859
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:702
void SetDoNotAllowVias(bool aEnable)
Definition zone.h:858
void SetNet(NETINFO_ITEM *aNetInfo) override
Override that drops aNetInfo when this zone is in copper-thieving fill mode.
Definition zone.cpp:668
void SetThermalReliefGap(int aThermalReliefGap)
Definition zone.h:240
void SetDoNotAllowFootprints(bool aEnable)
Definition zone.h:861
void SetDoNotAllowZoneFills(bool aEnable)
Definition zone.h:857
void SetAssignedPriority(unsigned aPriority)
Definition zone.h:117
void SetZoneName(const wxString &aName)
Definition zone.h:161
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition zone.h:864
static int GetDefaultHatchPitch()
Definition zone.cpp:1695
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
@ DEGREES_T
Definition eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_45
Definition eda_angle.h:473
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:476
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_IO_ERRORF(msg,...)
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:870
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_CrtYd
Definition layer_ids.h:112
@ Edge_Cuts
Definition layer_ids.h:108
@ F_Paste
Definition layer_ids.h:100
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ In2_Cu
Definition layer_ids.h:63
@ F_SilkS
Definition layer_ids.h:96
@ In1_Cu
Definition layer_ids.h:62
@ B_SilkS
Definition layer_ids.h:97
@ F_Cu
Definition layer_ids.h:60
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ PTH
Plated through hole pad.
Definition padstack.h:99
@ CHAMFERED_RECT
Definition padstack.h:61
@ RECTANGLE
Definition padstack.h:55
Class to handle a set of BOARD_ITEMs.
static constexpr uint32_t MAX_CHILDREN
static constexpr uint32_t MAX_GROUPS
static constexpr uint32_t MAX_OBJECTS
static constexpr uint32_t MAX_POINTS
std::vector< OBJECT > objects
std::vector< POINT > points
std::vector< OBJECT > text_children
std::vector< uint32_t > groups
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
VECTOR2I center
int radius
VECTOR2I end
int clearance
int delta
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
#define M_PI
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46
@ NONE
Pads are not covered.
Definition zones.h:45
@ FULL
pads are covered by copper
Definition zones.h:47