KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_easyeda_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) 2023 Alex Shvartzkop <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
22
23#include <memory>
24
25#include <json_common.h>
26#include <core/map_helpers.h>
28#include <string_utils.h>
29
30#include <wx/log.h>
31
32#include <font/font.h>
33#include <footprint.h>
34#include <progress_reporter.h>
35#include <board.h>
38#include <bezier_curves.h>
39#include <pcb_group.h>
40#include <pcb_track.h>
41#include <pcb_shape.h>
42#include <pcb_text.h>
43#include <zone.h>
44#include <pad.h>
45#include <project.h>
46#include <fix_board_shape.h>
47
48
49static const wxString DIRECT_MODEL_UUID_KEY = wxS( "JLC_3DModel" );
50static const wxString MODEL_SIZE_KEY = wxS( "JLC_3D_Size" );
51
52static const int SHAPE_JOIN_DISTANCE = pcbIUScale.mmToIU( 1.5 );
53static const VECTOR2I HIDDEN_TEXT_SIZE( pcbIUScale.mmToIU( 0.5 ), pcbIUScale.mmToIU( 0.5 ) );
54
55
59
63
65{
66 int elayer = wxAtoi( aLayer );
67
68 switch( elayer )
69 {
70 case 1: return F_Cu;
71 case 2: return B_Cu;
72 case 3: return F_SilkS;
73 case 4: return B_SilkS;
74 case 5: return F_Paste;
75 case 6: return B_Paste;
76 case 7: return F_Mask;
77 case 8: return B_Mask;
78 /*case 9: return UNDEFINED_LAYER;*/ // Ratsnest
79 case 10: return Edge_Cuts;
80 case 11: return Eco1_User;
81 case 12: return Dwgs_User;
82 case 13: return F_Fab;
83 case 14: return B_Fab;
84 case 15: return Eco2_User;
85
86 case 19: return F_Fab; // 3D model
87
88 case 21: return In1_Cu;
89 case 22: return In2_Cu;
90 case 23: return In3_Cu;
91 case 24: return In4_Cu;
92 case 25: return In5_Cu;
93 case 26: return In6_Cu;
94 case 27: return In7_Cu;
95 case 28: return In8_Cu;
96 case 29: return In9_Cu;
97 case 30: return In10_Cu;
98 case 31: return In11_Cu;
99 case 32: return In12_Cu;
100 case 33: return In13_Cu;
101 case 34: return In14_Cu;
102 case 35: return In15_Cu;
103 case 36: return In16_Cu;
104 case 37: return In17_Cu;
105 case 38: return In18_Cu;
106 case 39: return In19_Cu;
107 case 40: return In20_Cu;
108 case 41: return In21_Cu;
109 case 42: return In22_Cu;
110 case 43: return In23_Cu;
111 case 44: return In24_Cu;
112 case 45: return In25_Cu;
113 case 46: return In26_Cu;
114 case 47: return In27_Cu;
115 case 48: return In28_Cu;
116 case 49: return In29_Cu;
117 case 50: return In30_Cu;
118
119 case 99: return User_3;
120 case 100: return User_4;
121 case 101: return User_5;
122
123 default: break;
124 }
125
126 return User_1;
127}
128
129
130static LIB_ID EasyEdaToKiCadLibID( const wxString& aLibName, const wxString& aLibReference )
131{
132 wxString libReference = EscapeString( aLibReference, CTX_LIBID );
133
134 wxString key = !aLibName.empty() ? ( aLibName + ':' + libReference ) : libReference;
135
136 LIB_ID libId;
137 libId.Parse( key, true );
138
139 return libId;
140}
141
142
144 std::map<wxString, wxString> paramMap,
145 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
146 wxArrayString aShapes )
147{
148 // TODO: make this path configurable?
149 const wxString easyedaModelDir = wxS( "EASYEDA_MODELS" );
150 wxString kicadModelPrefix = wxS( "${KIPRJMOD}/" ) + easyedaModelDir + wxS( "/" );
151
152 BOARD* board = aParent ? aParent : dynamic_cast<BOARD*>( aContainer );
153 FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aContainer );
154
155 auto getOrAddNetItem =
156 [&]( const wxString& aNetName ) -> NETINFO_ITEM*
157 {
158 if( !board )
159 return nullptr;
160
161 if( aNetName.empty() )
162 return nullptr;
163
164 if( NETINFO_ITEM* item = board->FindNet( aNetName ) )
165 {
166 return item;
167 }
168 else
169 {
170 item = new NETINFO_ITEM( board, aNetName, board->GetNetCount() + 1 );
171 board->Add( item, ADD_MODE::APPEND );
172 return item;
173 }
174 };
175
176 if( footprint )
177 {
178 // TODO: library name
179 LIB_ID fpID = EasyEdaToKiCadLibID( wxEmptyString, paramMap[wxS( "package" )] );
180 footprint->SetFPID( fpID );
181 }
182
183 for( wxString shape : aShapes )
184 {
185 wxArrayString arr = wxSplit( shape, '~', '\0' );
186
187 // Exports differ in how many trailing fields a record carries
188 auto field =
189 [&]( size_t aIndex )
190 {
191 return aIndex < arr.size() ? arr[aIndex] : wxString();
192 };
193
194 wxString elType = arr[0];
195 if( elType == wxS( "LIB" ) )
196 {
197 shape.Replace( wxS( "#@$" ), "\n" );
198 wxArrayString parts = wxSplit( shape, '\n', '\0' );
199
200 if( parts.size() < 1 )
201 continue;
202
203 wxArrayString paramsRoot = wxSplit( parts[0], '~', '\0' );
204
205 if( paramsRoot.size() < 4 )
206 continue;
207
208 VECTOR2D fpOrigin( Convert( paramsRoot[1] ), Convert( paramsRoot[2] ) );
209
210 wxString packageName = wxString::Format( wxS( "Unknown_%s_%s" ), paramsRoot[1], paramsRoot[2] );
211
212 wxArrayString paramParts = wxSplit( paramsRoot[3], '`', '\0' );
213
215
216 if( !paramsRoot[4].IsEmpty() )
217 orientation = EDA_ANGLE( Convert( paramsRoot[4] ), DEGREES_T ); // Already applied
218
219 int layer = 1;
220
221 if( !paramsRoot[7].IsEmpty() )
222 layer = Convert( paramsRoot[7] );
223
224 std::map<wxString, wxString> innerParamMap;
225
226 for( int i = 1; i < (int) paramParts.size(); i += 2 )
227 {
228 wxString key = paramParts[i - 1];
229 wxString value = paramParts[i];
230
231 if( key == wxS( "package" ) )
232 packageName = value;
233
234 innerParamMap[key] = value;
235 }
236
237 parts.RemoveAt( 0 );
238
239 VECTOR2D pcbOrigin = m_relOrigin;
240 std::unique_ptr<FOOTPRINT> fp = ParseFootprint( fpOrigin, orientation, layer, board, innerParamMap,
241 aFootprintMap, parts );
242
243 if( !fp )
244 continue;
245
246 m_relOrigin = pcbOrigin;
247
248 fp->Move( RelPos( fpOrigin ) );
249
250 aContainer->Add( fp.release(), ADD_MODE::APPEND );
251 }
252 else if( elType == wxS( "TRACK" ) )
253 {
254 double width = ConvertSize( field( 1 ) );
255 PCB_LAYER_ID layer = LayerToKi( field( 2 ) );
256 wxString netname = field( 3 );
257 wxArrayString data = wxSplit( field( 4 ), ' ', '\0' );
258
259 for( int i = 3; i < (int) data.size(); i += 2 )
260 {
261 VECTOR2D start, end;
262 start.x = RelPosX( data[i - 3] );
263 start.y = RelPosY( data[i - 2] );
264 end.x = RelPosX( data[i - 1] );
265 end.y = RelPosY( data[i] );
266
267 if( !footprint && IsCopperLayer( layer ) )
268 {
269 auto track = std::make_unique<PCB_TRACK>( aContainer );
270
271 track->SetLayer( layer );
272 track->SetWidth( width );
273 track->SetStart( start );
274 track->SetEnd( end );
275 track->SetNet( getOrAddNetItem( netname ) );
276
277 aContainer->Add( track.release(), ADD_MODE::APPEND );
278 }
279 else
280 {
281 auto seg = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
282
283 seg->SetLayer( layer );
284 seg->SetWidth( width );
285 seg->SetStart( start );
286 seg->SetEnd( end );
287
288 aContainer->Add( seg.release(), ADD_MODE::APPEND );
289 }
290 }
291 }
292 else if( elType == wxS( "CIRCLE" ) )
293 {
294 auto circleShape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::CIRCLE );
295 double width = ConvertSize( field( 4 ) );
296 circleShape->SetWidth( width );
297
298 PCB_LAYER_ID layer = LayerToKi( field( 5 ) );
299 circleShape->SetLayer( layer );
300
302 center.x = RelPosX( field( 1 ) );
303 center.y = RelPosY( field( 2 ) );
304
305 double radius = ConvertSize( field( 3 ) );
306
307 circleShape->SetCenter( center );
308 circleShape->SetEnd( center + VECTOR2I( radius, 0 ) );
309
310 if( IsCopperLayer( layer ) )
311 circleShape->SetNet( getOrAddNetItem( field( 8 ) ) );
312
313 aContainer->Add( circleShape.release(), ADD_MODE::APPEND );
314 }
315 else if( elType == wxS( "RECT" ) )
316 {
317 auto rectShape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::RECTANGLE );
318 // older records leave the stroke width empty
319 const wxString widthField = field( 8 );
320 double width = widthField.IsEmpty() ? 0.0 : ConvertSize( widthField );
321 rectShape->SetWidth( width );
322
323 PCB_LAYER_ID layer = LayerToKi( field( 5 ) );
324 rectShape->SetLayer( layer );
325
326 bool filled = field( 9 ) != wxS( "none" );
327 rectShape->SetFilled( filled );
328
329 VECTOR2D rectStart;
330 rectStart.x = RelPosX( field( 1 ) );
331 rectStart.y = RelPosY( field( 2 ) );
332
333 VECTOR2D rectSize;
334 rectSize.x = ConvertSize( field( 3 ) );
335 rectSize.y = ConvertSize( field( 4 ) );
336
337 rectShape->SetStart( rectStart );
338 rectShape->SetEnd( rectStart + rectSize );
339
340 if( IsCopperLayer( layer ) )
341 rectShape->SetNet( getOrAddNetItem( field( 11 ) ) );
342
343 aContainer->Add( rectShape.release(), ADD_MODE::APPEND );
344 }
345 else if( elType == wxS( "ARC" ) )
346 {
347 auto arcShape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::ARC );
348
349 double arcWidth = ConvertSize( field( 1 ) );
350 arcShape->SetWidth( arcWidth );
351
352 PCB_LAYER_ID layer = LayerToKi( field( 2 ) );
353 arcShape->SetLayer( layer );
354
355 if( IsCopperLayer( layer ) )
356 arcShape->SetNet( getOrAddNetItem( field( 3 ) ) );
357
358 VECTOR2D arcStart, arcEnd;
359 VECTOR2D rad( 10, 10 );
360 bool isFar = false;
361 bool cw = false;
362
363 int pos = 0;
364 wxString data = field( 4 );
365 auto readNumber = [&]( wxString& aOut )
366 {
367 wxUniChar ch = data[pos];
368
369 while( ch == ' ' || ch == ',' )
370 ch = data[++pos];
371
372 while( isdigit( ch ) || ch == '.' || ch == '-' )
373 {
374 aOut += ch;
375 pos++;
376
377 if( pos == (int) data.size() )
378 break;
379
380 ch = data[pos];
381 }
382 };
383
384 do
385 {
386 wxUniChar sym = data[pos++];
387
388 if( sym == 'M' )
389 {
390 wxString xStr, yStr;
391 readNumber( xStr );
392 readNumber( yStr );
393
394 arcStart = VECTOR2D( Convert( xStr ), Convert( yStr ) );
395 }
396 else if( sym == 'A' )
397 {
398 wxString radX, radY, unknown, farFlag, cwFlag, endX, endY;
399 readNumber( radX );
400 readNumber( radY );
401 readNumber( unknown );
402 readNumber( farFlag );
403 readNumber( cwFlag );
404 readNumber( endX );
405 readNumber( endY );
406
407 isFar = farFlag == wxS( "1" );
408 cw = cwFlag == wxS( "1" );
409 rad = VECTOR2D( Convert( radX ), Convert( radY ) );
410 arcEnd = VECTOR2D( Convert( endX ), Convert( endY ) );
411 }
412 } while( pos < (int) data.size() );
413
414 VECTOR2D delta = arcEnd - arcStart;
415
416 double d = delta.EuclideanNorm();
417 double h = sqrt( std::max( 0.0, rad.x * rad.x - d * d / 4 ) );
418
419 //( !far && cw ) => h
420 //( far && cw ) => -h
421 //( !far && !cw ) => -h
422 //( far && !cw ) => h
423 VECTOR2D arcCenter = arcStart + delta / 2 + delta.Perpendicular().Resize( ( isFar ^ cw ) ? h : -h );
424
425 if( !cw )
426 std::swap( arcStart, arcEnd );
427
428 arcShape->SetStart( RelPos( arcStart ) );
429 arcShape->SetEnd( RelPos( arcEnd ) );
430 arcShape->SetCenter( RelPos( arcCenter ) );
431
432 aContainer->Add( arcShape.release(), ADD_MODE::APPEND );
433 }
434 else if( elType == wxS( "DIMENSION" ) )
435 {
436 PCB_LAYER_ID layer = LayerToKi( field( 1 ) );
437 // older dimensions end before the width field
438 double lineWidth = ConvertSize( arr.size() > 7 ? field( 7 ) : wxString( wxS( "0.4" ) ) );
439 wxString shapeData = field( 2 ).Trim();
440 //double textHeight = !arr[4].IsEmpty() ? ConvertSize( arr[4] ) : 0;
441
442 std::vector<SHAPE_LINE_CHAIN> lineChains = ParseLineChains( shapeData, SHAPE_ARC::DefaultAccuracyForPCB(),
443 false );
444
445 std::unique_ptr<PCB_GROUP> group = std::make_unique<PCB_GROUP>( aContainer );
446 group->SetName( wxS( "Dimension" ) );
447
448 for( const SHAPE_LINE_CHAIN& chain : lineChains )
449 {
450 for( int segId = 0; segId < chain.SegmentCount(); segId++ )
451 {
452 SEG seg = chain.CSegment( segId );
453 auto dimSeg = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
454
455 dimSeg->SetLayer( layer );
456 dimSeg->SetWidth( lineWidth );
457 dimSeg->SetStart( seg.A );
458 dimSeg->SetEnd( seg.B );
459
460 group->AddItem( dimSeg.get() );
461
462 aContainer->Add( dimSeg.release(), ADD_MODE::APPEND );
463 }
464 }
465
466 aContainer->Add( group.release(), ADD_MODE::APPEND );
467 }
468 else if( elType == wxS( "SOLIDREGION" ) )
469 {
470 wxString layer = field( 1 );
471
472 SHAPE_POLY_SET polySet = ParseLineChains( field( 3 ).Trim(), SHAPE_ARC::DefaultAccuracyForPCB(), true );
473
474 bool validPolySet = polySet.OutlineCount() > 0;
475
476 for( const SHAPE_POLY_SET::POLYGON& polygon : polySet.CPolygons() )
477 {
478 for( const SHAPE_LINE_CHAIN& contour : polygon )
479 validPolySet &= contour.PointCount() >= 3;
480 }
481
482 if( !validPolySet )
483 continue;
484
485 if( layer == wxS( "11" ) ) // Multi-layer (board cutout)
486 {
487 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
488 {
489 auto cutoutShape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
490
491 cutoutShape->SetLayer( Edge_Cuts );
492 cutoutShape->SetFilled( false );
493 cutoutShape->SetWidth( pcbIUScale.mmToIU( 0.1 ) );
494 cutoutShape->SetPolyShape( poly );
495
496 aContainer->Add( cutoutShape.release(), ADD_MODE::APPEND );
497 }
498 }
499 else
500 {
501 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aContainer );
502
503 PCB_LAYER_ID klayer = LayerToKi( layer );
504 zone->SetLayer( klayer );
505
506 if( IsCopperLayer( klayer ) )
507 zone->SetNet( getOrAddNetItem( field( 2 ) ) );
508
509 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
510 zone->Outline()->AddPolygon( poly );
511
512 if( zone->GetNumCorners() == 0 )
513 continue;
514
515 if( field( 4 ).Lower() == wxS( "cutout" ) )
516 {
517 zone->SetIsRuleArea( true );
518 zone->SetDoNotAllowZoneFills( true );
519 zone->SetDoNotAllowTracks( false );
520 zone->SetDoNotAllowVias( false );
521 zone->SetDoNotAllowPads( false );
522 zone->SetDoNotAllowFootprints( false );
523 }
524 else
525 { // solid
526 zone->SetFilledPolysList( klayer, polySet );
527 zone->SetPadConnection( ZONE_CONNECTION::FULL );
528 zone->SetIsFilled( true );
529 zone->SetNeedRefill( false );
530 }
531
532 zone->SetMinThickness( 0 );
533 zone->SetLocalClearance( 0 );
534 zone->SetAssignedPriority( 100 );
535
536 aContainer->Add( zone.release(), ADD_MODE::APPEND );
537 }
538 }
539 else if( elType == wxS( "COPPERAREA" ) )
540 {
541 if( arr.size() < 11 )
542 continue;
543
544 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aContainer );
545
546 PCB_LAYER_ID layer = LayerToKi( field( 2 ) );
547 zone->SetLayer( layer );
548
549 wxString netname = field( 3 );
550
551 if( IsCopperLayer( layer ) )
552 zone->SetNet( getOrAddNetItem( netname ) );
553
554 zone->SetLocalClearance( ConvertSize( field( 5 ) ) );
555 zone->SetThermalReliefGap( zone->GetLocalClearance().value() );
556
557 wxString fillStyle = field( 5 );
558
559 if( fillStyle == wxS( "none" ) )
560 {
561 // Do not fill?
562 }
563
564 SHAPE_POLY_SET polySet = ParseLineChains( field( 4 ).Trim(), SHAPE_ARC::DefaultAccuracyForPCB(), true );
565
566 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
567 zone->Outline()->AddPolygon( poly );
568
569 wxString thermal = field( 8 );
570
571 if( thermal == wxS( "direct" ) )
572 zone->SetPadConnection( ZONE_CONNECTION::FULL );
573
574 wxString keepIsland = field( 9 );
575
576 if( keepIsland == wxS( "yes" ) )
577 zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::NEVER );
578
579 wxString fillData = field( 10 );
580 SHAPE_POLY_SET fillPolySet;
581 try
582 {
583 for( const nlohmann::json& polyData : nlohmann::json::parse( fillData ) )
584 {
585 for( const nlohmann::json& contourData : polyData )
586 {
587 SHAPE_POLY_SET contourPolySet = ParseLineChains( contourData.get<wxString>(),
589
590 SHAPE_POLY_SET currentOutline( contourPolySet.COutline( 0 ) );
591
592 for( int i = 0; i < contourPolySet.HoleCount( 0 ); i++ )
593 currentOutline.AddHole( contourPolySet.CHole( 0, i ) );
594
595 fillPolySet.Append( currentOutline );
596 }
597 }
598
599 fillPolySet.Fracture();
600
601 zone->SetFilledPolysList( layer, fillPolySet );
602 zone->SetIsFilled( true );
603 zone->SetNeedRefill( false );
604 }
605 catch( nlohmann::json::exception& )
606 {
607 }
608
609 int fillOrder = wxAtoi( field( 13 ) );
610 zone->SetAssignedPriority( 100 - fillOrder );
611
612 // Older exports stop at the fill order
613 wxString improveFabrication = field( 17 );
614 if( improveFabrication == wxS( "none" ) )
615 {
616 zone->SetMinThickness( 0 );
617 }
618 else
619 {
620 // arr[1] is "stroke Width" per docs
621 int minThickness = std::max( pcbIUScale.mmToIU( 0.03 ),
622 int( ConvertSize( field( 1 ) ) ) );
623 zone->SetMinThickness( minThickness );
624 }
625
626 if( arr.size() > 18 )
627 {
628 zone->SetThermalReliefSpokeWidth( std::max( int( ConvertSize( field( 18 ) ) ),
629 zone->GetMinThickness() ) );
630 }
631 else
632 {
633 zone->SetThermalReliefSpokeWidth( zone->GetMinThickness() );
634 }
635
636 aContainer->Add( zone.release(), ADD_MODE::APPEND );
637 }
638 else if( elType == wxS( "SVGNODE" ) )
639 {
640 nlohmann::json nodeData = nlohmann::json::parse( field( 1 ) );
641
642 int nodeType = nodeData.at( "nodeType" );
643 wxString layer = nodeData.at( "layerid" );
644 PCB_LAYER_ID klayer = LayerToKi( layer );
645
646 if( nodeType == 1 )
647 {
648 std::map<wxString, wxString> attributes = nodeData.at( "attrs" );
649
650 if( layer == wxS( "19" ) ) // 3DModel
651 {
652 if( !footprint )
653 continue;
654
655 auto ec_eType = get_opt( attributes, "c_etype" );
656 auto ec_rotation = get_opt( attributes, "c_rotation" );
657 auto ec_origin = get_opt( attributes, "c_origin" );
658 auto ec_width = get_opt( attributes, "c_width" );
659 auto ec_height = get_opt( attributes, "c_height" );
660 auto ez = get_opt( attributes, "z" );
661 auto etitle = get_opt( attributes, "title" );
662 auto euuid = get_opt( attributes, "uuid" );
663 auto etransform = get_opt( attributes, "transform" );
664
665 if( !ec_eType || *ec_eType != wxS( "outline3D" ) || !etitle )
666 continue;
667
668 wxString modelTitle = *etitle;
669 VECTOR3D kmodelOffset;
670 VECTOR3D kmodelRotation;
671
672 if( euuid )
673 {
674 PCB_FIELD* idField = new PCB_FIELD( footprint, FIELD_T::USER, DIRECT_MODEL_UUID_KEY );
675 idField->SetLayer( Cmts_User );
676 idField->SetVisible( false );
677 idField->SetText( *euuid );
678 footprint->Add( idField );
679 }
680
681 /*if( etransform )
682 {
683 PCB_FIELD* transformField = new PCB_FIELD( footprint, FIELD_T::USER, "3D Transform" );
684 transformField->SetLayer( Cmts_User );
685 transformField->SetVisible( false );
686 transformField->SetText( *etransform );
687 footprint->Add( transformField );
688 }*/
689
690 if( ec_width && ec_height )
691 {
692 double fitXmm = pcbIUScale.IUTomm( ScaleSize( Convert( *ec_width ) ) );
693 double fitYmm = pcbIUScale.IUTomm( ScaleSize( Convert( *ec_height ) ) );
694
695 double rounding = 0.001;
696 fitXmm = KiROUND( fitXmm / rounding ) * rounding;
697 fitYmm = KiROUND( fitYmm / rounding ) * rounding;
698
699 PCB_FIELD* sizeField = new PCB_FIELD( footprint, FIELD_T::USER, MODEL_SIZE_KEY );
700 sizeField->SetLayer( Cmts_User );
701 sizeField->SetVisible( false );
702 sizeField->SetText( wxString::FromCDouble( fitXmm ) + wxS( " " )
703 + wxString::FromCDouble( fitYmm ) );
704 footprint->Add( sizeField );
705 }
706
707 if( ec_origin )
708 {
709 wxArrayString orParts = wxSplit( *ec_origin, ',', '\0' );
710
711 if( orParts.size() == 2 )
712 {
713 VECTOR2D pos;
714 pos.x = Convert( orParts[0].Trim() );
715 pos.y = Convert( orParts[1].Trim() );
716
717 VECTOR2D rel = RelPos( pos );
718 kmodelOffset.x = -pcbIUScale.IUTomm( rel.x );
719 kmodelOffset.y = -pcbIUScale.IUTomm( rel.y );
720
721 RotatePoint( &kmodelOffset.x, &kmodelOffset.y,
722 -footprint->GetOrientation() );
723 }
724 }
725
726 if( ez )
727 {
728 kmodelOffset.z = pcbIUScale.IUTomm( ScaleSize( Convert( ez->Trim() ) ) );
729 }
730
731 if( ec_rotation )
732 {
733 wxArrayString rotParts = wxSplit( *ec_rotation, ',', '\0' );
734
735 if( rotParts.size() == 3 )
736 {
737 kmodelRotation.x = -Convert( rotParts[0].Trim() );
738 kmodelRotation.y = -Convert( rotParts[1].Trim() );
739 kmodelRotation.z = -Convert( rotParts[2].Trim() )
740 + footprint->GetOrientationDegrees();
741 }
742 }
743
744 if( footprint->GetLayer() == B_Cu )
745 {
746 kmodelRotation.z = 180 - kmodelRotation.z;
747 RotatePoint( &kmodelOffset.x, &kmodelOffset.y, ANGLE_180 );
748 }
749
751 model.m_Filename = kicadModelPrefix
753 + wxS( ".step" );
754 model.m_Offset = kmodelOffset;
755 model.m_Rotation = kmodelRotation;
756 footprint->Models().push_back( model );
757 }
758 else
759 {
760 if( auto dataStr = get_opt( attributes, "d" ) )
761 {
762 int maxError = SHAPE_ARC::DefaultAccuracyForPCB();
763
764 if( dataStr->size() >= 8000 )
765 maxError *= 10;
766
767 SHAPE_POLY_SET polySet = ParseLineChains( dataStr->Trim(), maxError, true );
768
769 polySet.RebuildHolesFromContours();
770
771 std::unique_ptr<PCB_GROUP> group;
772
773 if( polySet.OutlineCount() > 1 )
774 group = std::make_unique<PCB_GROUP>( aContainer );
775
776 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
777 {
778 auto svgShape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
779
780 svgShape->SetFilled( true );
781 svgShape->SetPolyShape( poly );
782 svgShape->SetLayer( klayer );
783 svgShape->SetWidth( 0 );
784
785 if( group )
786 group->AddItem( svgShape.get() );
787
788 aContainer->Add( svgShape.release(), ADD_MODE::APPEND );
789 }
790
791 if( group )
792 aContainer->Add( group.release(), ADD_MODE::APPEND );
793 }
794 }
795 }
796 else
797 {
798 THROW_IO_ERRORF( _( "Unknown SVGNODE nodeType %d" ), nodeType );
799 }
800 }
801 else if( elType == wxS( "TEXT" ) )
802 {
803 PCB_TEXT* text;
804 wxString textType = field( 1 );
805
806 if( footprint && textType == wxS( "P" ) )
807 {
808 text = footprint->GetField( FIELD_T::REFERENCE );
809 }
810 else if( footprint && textType == wxS( "N" ) )
811 {
812 text = footprint->GetField( FIELD_T::VALUE );
813 }
814 else if( field( 12 ) == wxS( "none" ) )
815 {
816 text = new PCB_FIELD( aContainer, FIELD_T::USER );
817 static_cast<PCB_FIELD*>( text )->SetVisible( false );
818 }
819 else
820 {
821 text = new PCB_TEXT( aContainer );
822 aContainer->Add( text, ADD_MODE::APPEND );
823 }
824
825 VECTOR2D start;
826 start.x = RelPosX( field( 2 ) );
827 start.y = RelPosY( field( 3 ) );
828 text->SetPosition( start );
829
830 double thickness = ConvertSize( field( 4 ) );
831 text->SetTextThickness( thickness );
832
833 double rot = Convert( field( 5 ) );
834 text->SetTextAngleDegrees( rot );
835
836 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
837 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
838
839 PCB_LAYER_ID layer = LayerToKi( field( 7 ) );
840 text->SetLayer( layer );
841
842 if( IsBackLayer( layer ) )
843 text->SetMirrored( true );
844
845 double height = ConvertSize( field( 9 ) ) * 0.8;
846 text->SetTextSize( VECTOR2I( height, height ) );
847
848 wxString textStr = field( 10 );
849 textStr.Replace( wxS( "\\n" ), wxS( "\n" ) );
850 text->SetText( UnescapeHTML( textStr ) );
851
852 //arr[11] // Geometry data
853
854 wxString font = field( 14 );
855 if( !font.IsEmpty() )
856 text->SetFont( KIFONT::FONT::GetFont( font ) );
857
858 TransformTextToBaseline( text, wxEmptyString );
859 }
860 else if( elType == wxS( "VIA" ) )
861 {
862 VECTOR2D center( RelPosX( field( 1 ) ), RelPosY( field( 2 ) ) );
863 int kdia = ConvertSize( field( 3 ) );
864 int kdrill = ConvertSize( field( 5 ) ) * 2;
865
866 if( footprint )
867 {
868 std::unique_ptr<PAD> pad = std::make_unique<PAD>( footprint );
869
870 pad->SetPosition( center );
871 pad->SetLayerSet( PAD::PTHMask() );
872 pad->SetAttribute( PAD_ATTRIB::PTH );
873 pad->SetPadstackMode( PADSTACK::MODE::NORMAL ); // EasyEDA doesn't have complex padstacks
875 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( kdia, kdia ) );
876 pad->SetDrillShape( PAD_DRILL_SHAPE::CIRCLE );
877 pad->SetDrillSize( VECTOR2I( kdrill, kdrill ) );
878
879 footprint->Add( pad.release(), ADD_MODE::APPEND );
880 }
881 else
882 {
883 std::unique_ptr<PCB_VIA> via = std::make_unique<PCB_VIA>( aContainer );
884
885 via->SetPosition( center );
886 via->SetPadstackMode( PADSTACK::MODE::NORMAL ); // EasyEDA doesn't have complex padstacks
887 via->SetWidth( PADSTACK::ALL_LAYERS, kdia );
888 via->SetNet( getOrAddNetItem( field( 4 ) ) );
889 via->SetDrill( kdrill );
890
891 aContainer->Add( via.release(), ADD_MODE::APPEND );
892 }
893 }
894 else if( elType == wxS( "HOLE" ) )
895 {
896 FOOTPRINT* padContainer;
897
898 VECTOR2D center( RelPosX( field( 1 ) ), RelPosY( field( 2 ) ) );
899 int kdia = ConvertSize( field( 3 ) ) * 2;
900 wxString holeUuid = field( 4 );
901
902 if( footprint )
903 {
904 padContainer = footprint;
905 }
906 else
907 {
908 auto newFootprint = std::make_unique<FOOTPRINT>( dynamic_cast<BOARD*>( aContainer ) );
909
910 wxString name = wxS( "Hole_" ) + holeUuid;
911
912 newFootprint->SetFPID( LIB_ID( wxEmptyString, name ) );
913 newFootprint->SetPosition( center );
914 newFootprint->SetLocked( true );
915
916 newFootprint->Reference().SetText( name );
917 newFootprint->Reference().SetVisible( false );
918 newFootprint->Reference().SetTextSize( HIDDEN_TEXT_SIZE );
919 newFootprint->Value().SetText( name );
920 newFootprint->Value().SetVisible( false );
921 newFootprint->Value().SetTextSize( HIDDEN_TEXT_SIZE );
922
923 padContainer = newFootprint.get();
924 aContainer->Add( newFootprint.release(), ADD_MODE::APPEND );
925 }
926
927 std::unique_ptr<PAD> pad = std::make_unique<PAD>( padContainer );
928
929 pad->SetPosition( center );
930 pad->SetLayerSet( PAD::UnplatedHoleMask() );
931 pad->SetAttribute( PAD_ATTRIB::NPTH );
932 pad->SetPadstackMode( PADSTACK::MODE::NORMAL ); // EasyEDA doesn't have complex padstacks
934 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( kdia, kdia ) );
935 pad->SetDrillShape( PAD_DRILL_SHAPE::CIRCLE );
936 pad->SetDrillSize( VECTOR2I( kdia, kdia ) );
937
938 padContainer->Add( pad.release(), ADD_MODE::APPEND );
939 }
940 else if( elType == wxS( "PAD" ) )
941 {
942 FOOTPRINT* padContainer;
943
944 VECTOR2D center( RelPosX( field( 2 ) ), RelPosY( field( 3 ) ) );
945 VECTOR2D size( ConvertSize( field( 4 ) ), ConvertSize( field( 5 ) ) );
946 wxString padUuid = field( 12 );
947
948 if( footprint )
949 {
950 padContainer = footprint;
951 }
952 else
953 {
954 auto newFootprint = std::make_unique<FOOTPRINT>( dynamic_cast<BOARD*>( aContainer ) );
955
956 wxString name = wxS( "Pad_" ) + padUuid;
957
958 newFootprint->SetFPID( LIB_ID( wxEmptyString, name ) );
959 newFootprint->SetPosition( center );
960 newFootprint->SetLocked( true );
961
962 newFootprint->Reference().SetText( name );
963 newFootprint->Reference().SetVisible( false );
964 newFootprint->Reference().SetTextSize( HIDDEN_TEXT_SIZE );
965 newFootprint->Value().SetText( name );
966 newFootprint->Value().SetVisible( false );
967 newFootprint->Value().SetTextSize( HIDDEN_TEXT_SIZE );
968
969 padContainer = newFootprint.get();
970 aContainer->Add( newFootprint.release(), ADD_MODE::APPEND );
971 }
972
973 std::unique_ptr<PAD> pad = std::make_unique<PAD>( padContainer );
974
975 pad->SetNet( getOrAddNetItem( field( 7 ) ) );
976 pad->SetNumber( field( 8 ) );
977 pad->SetPosition( center );
978 pad->SetPadstackMode( PADSTACK::MODE::NORMAL ); // EasyEDA doesn't have complex padstacks
979 pad->SetSize( PADSTACK::ALL_LAYERS, size );
980 pad->SetOrientationDegrees( Convert( field( 11 ) ) );
981 pad->SetThermalSpokeAngle( ANGLE_0 );
982
983 wxString elayer = field( 6 );
984 PCB_LAYER_ID klayer = LayerToKi( elayer );
985
986 bool plated = field( 15 ) == wxS( "Y" );
987
988 if( klayer == F_Cu )
989 {
990 pad->SetLayer( F_Cu );
991 pad->SetLayerSet( PAD::SMDMask() );
992 pad->SetAttribute( PAD_ATTRIB::SMD );
993 }
994 else if( klayer == B_Cu )
995 {
996 pad->SetLayer( B_Cu );
997 pad->SetLayerSet( PAD::SMDMask().FlipStandardLayers() );
998 pad->SetAttribute( PAD_ATTRIB::SMD );
999 }
1000 else if( elayer == wxS( "11" ) )
1001 {
1002 pad->SetLayerSet( plated ? PAD::PTHMask() : PAD::UnplatedHoleMask() );
1003 pad->SetAttribute( plated ? PAD_ATTRIB::PTH : PAD_ATTRIB::NPTH );
1004 }
1005 else
1006 {
1007 pad->SetLayer( klayer );
1008 pad->SetLayerSet( LSET( { klayer } ) );
1009 pad->SetAttribute( PAD_ATTRIB::SMD );
1010 }
1011
1012 const wxString& padType = field( 1 );
1013
1014 if( padType == wxS( "ELLIPSE" ) )
1015 {
1017 }
1018 else if( padType == wxS( "RECT" ) )
1019 {
1021 }
1022 else if( padType == wxS( "OVAL" ) )
1023 {
1024 if( pad->GetSize( PADSTACK::ALL_LAYERS ).x == pad->GetSize( PADSTACK::ALL_LAYERS ).y )
1026 else
1028 }
1029 else if( padType == wxS( "POLYGON" ) )
1030 {
1032 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CIRCLE );
1033 pad->SetSize( PADSTACK::ALL_LAYERS, { 1, 1 } );
1034
1035 wxArrayString data = wxSplit( field( 10 ), ' ', '\0' );
1036
1038
1039 for( int i = 1; i < (int) data.size(); i += 2 )
1040 {
1041 VECTOR2D pt;
1042 pt.x = RelPosX( data[i - 1] );
1043 pt.y = RelPosY( data[i] );
1044 chain.Append( pt );
1045 }
1046
1047 chain.SetClosed( true );
1048
1049 chain.Move( -center );
1050 chain.Rotate( -pad->GetOrientation() );
1051 pad->AddPrimitivePoly( PADSTACK::ALL_LAYERS, chain, 0, true );
1052 }
1053
1054 wxString holeDia = field( 9 );
1055
1056 if( !holeDia.IsEmpty() )
1057 {
1058 double holeD = ConvertSize( holeDia ) * 2;
1059 double holeL = 0;
1060
1061 wxString holeLength = field( 13 );
1062 if( !holeLength.IsEmpty() )
1063 holeL = ConvertSize( holeLength );
1064
1065 if( holeL > 0 )
1066 {
1067 pad->SetDrillShape( PAD_DRILL_SHAPE::OBLONG );
1068
1069 if( size.x < size.y )
1070 pad->SetDrillSize( VECTOR2I( holeD, holeL ) );
1071 else
1072 pad->SetDrillSize( VECTOR2I( holeL, holeD ) );
1073 }
1074 else
1075 {
1076 pad->SetDrillShape( PAD_DRILL_SHAPE::CIRCLE );
1077 pad->SetDrillSize( VECTOR2I( holeD, holeD ) );
1078 }
1079 }
1080
1081 wxString pasteExp = field( 17 );
1082
1083 if( !pasteExp.IsEmpty() )
1084 {
1085 double pasteExpansion = ConvertSize( pasteExp );
1086 pad->SetLocalSolderPasteMargin( pasteExpansion );
1087 }
1088
1089 wxString maskExp = field( 18 );
1090
1091 if( !maskExp.IsEmpty() )
1092 {
1093 double maskExpansion = ConvertSize( maskExp );
1094 pad->SetLocalSolderMaskMargin( maskExpansion );
1095 }
1096
1097 bool badPad = false;
1098
1099 pad->Padstack().ForEachUniqueLayer(
1100 [&]( PCB_LAYER_ID layer )
1101 {
1102 VECTOR2I padSize = pad->GetSize( layer );
1103
1104 if( padSize.x <= 0 || padSize.y <= 0 )
1105 badPad = true;
1106 } );
1107
1108 if( badPad )
1109 {
1110 // Not worth throwing, and we don't (at present) have a reporter....
1111 /*
1112 Report( wxString::Format( _( "Invalid zero-sized pad ignored in\nfile: %s" ),
1113 aParent->GetFileName() ),
1114 RPT_SEVERITY_ERROR );
1115 */
1116 }
1117 else
1118 {
1119 padContainer->Add( pad.release(), ADD_MODE::APPEND );
1120 }
1121 }
1122 }
1123}
1124
1125
1126std::unique_ptr<FOOTPRINT>
1127PCB_IO_EASYEDA_PARSER::ParseFootprint( const VECTOR2D& aOrigin, const EDA_ANGLE& aOrientation, int aLayer,
1128 BOARD* aParent, std::map<wxString, wxString> aParams,
1129 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
1130 wxArrayString aShapes )
1131{
1132 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aParent );
1133
1134 if( aLayer == 2 ) // Bottom layer
1135 {
1136 footprint->SetLayer( B_Cu );
1137 footprint->SetOrientation( aOrientation - ANGLE_180 );
1138 }
1139 else
1140 {
1141 footprint->SetLayer( F_Cu );
1142 footprint->SetOrientation( aOrientation );
1143 }
1144
1145 footprint->Value().SetText( aParams[wxS( "package" )] );
1146
1147 m_relOrigin = aOrigin;
1148
1149 ParseToBoardItemContainer( footprint.get(), aParent, aParams, aFootprintMap, aShapes );
1150
1151 // Heal board outlines
1152 std::vector<PCB_SHAPE*> shapes;
1153
1154 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1155 {
1156 if( !item->IsOnLayer( Edge_Cuts ) )
1157 continue;
1158
1159 if( item->Type() == PCB_SHAPE_T )
1160 shapes.push_back( static_cast<PCB_SHAPE*>( item ) );
1161 }
1162
1164
1165 // EasyEDA footprints don't have courtyard, so build a box ourselves
1166 if( !footprint->IsOnLayer( F_CrtYd ) )
1167 {
1168 BOX2I bbox = footprint->GetLayerBoundingBox( { F_Cu, F_Fab, F_Paste, F_Mask, Edge_Cuts } );
1169 bbox.Inflate( pcbIUScale.mmToIU( 0.25 ) ); // Default courtyard clearance
1170
1171 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint.get(), SHAPE_T::RECTANGLE );
1172
1173 shape->SetWidth( pcbIUScale.mmToIU( DEFAULT_COURTYARD_WIDTH ) );
1174 shape->SetLayer( F_CrtYd );
1175 shape->SetStart( bbox.GetOrigin() );
1176 shape->SetEnd( bbox.GetEnd() );
1177
1178 footprint->Add( shape.release(), ADD_MODE::APPEND );
1179 }
1180
1181 bool hasFabRef = false;
1182
1183 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1184 {
1185 if( item->Type() == PCB_TEXT_T && item->IsOnLayer( F_Fab ) )
1186 {
1187 if( static_cast<PCB_TEXT*>( item )->GetText() == wxT( "${REFERENCE}" ) )
1188 {
1189 hasFabRef = true;
1190 break;
1191 }
1192 }
1193 }
1194
1195 if( !hasFabRef )
1196 {
1197 // Add reference text field on F_Fab
1198 int c_refTextSize = pcbIUScale.mmToIU( 0.5 ); // KLC min Fab text size
1199 int c_refTextThickness = pcbIUScale.mmToIU( 0.1 ); // Decent text thickness
1200 std::unique_ptr<PCB_TEXT> refText = std::make_unique<PCB_TEXT>( footprint.get() );
1201
1202 refText->SetLayer( F_Fab );
1203 refText->SetTextSize( VECTOR2I( c_refTextSize, c_refTextSize ) );
1204 refText->SetTextThickness( c_refTextThickness );
1205 refText->SetText( wxT( "${REFERENCE}" ) );
1206
1207 footprint->Add( refText.release(), ADD_MODE::APPEND );
1208 }
1209
1210 return footprint;
1211}
1212
1213
1215 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
1216 wxArrayString aShapes )
1217{
1218 m_relOrigin = aOrigin;
1219
1220 ParseToBoardItemContainer( aBoard, nullptr, {}, aFootprintMap, aShapes );
1221
1222 // Heal board outlines
1223 std::vector<PCB_SHAPE*> shapes;
1224
1225 for( BOARD_ITEM* item : aBoard->Drawings() )
1226 {
1227 if( !item->IsOnLayer( Edge_Cuts ) )
1228 continue;
1229
1230 if( item->Type() == PCB_SHAPE_T )
1231 shapes.push_back( static_cast<PCB_SHAPE*>( item ) );
1232 }
1233
1235}
const char * name
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
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 void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
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 * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2833
unsigned GetNetCount() const
Definition board.h:1276
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 const Vec & GetOrigin() const
Definition box2.h:213
double ConvertSize(const wxString &aValue)
static double Convert(const wxString &aValue)
double RelPosX(double aValue)
double RelPosY(double aValue)
VECTOR2< T > RelPos(const VECTOR2< T > &aVec)
void TransformTextToBaseline(EDA_TEXT *textItem, const wxString &baselineAlign)
std::vector< SHAPE_LINE_CHAIN > ParseLineChains(const wxString &aData, int aMaxError, bool aForceClosed)
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:418
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
double GetOrientationDegrees() const
Definition footprint.h:412
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition footprint.h:393
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
std::vector< FP_3DMODEL > & Models()
Definition footprint.h:375
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:144
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Handle the data for a net.
Definition netinfo.h:50
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:620
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition pad.cpp:641
static LSET SMDMask()
layer set for a SMD pad on Front layer
Definition pad.cpp:627
PCB_IO_EASYEDA_PARSER(PROGRESS_REPORTER *aProgressReporter)
void ParseToBoardItemContainer(BOARD_ITEM_CONTAINER *aContainer, BOARD *aParent, std::map< wxString, wxString > paramMap, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, wxArrayString shapes)
std::unique_ptr< FOOTPRINT > ParseFootprint(const VECTOR2D &aOrigin, const EDA_ANGLE &aOrientation, int aLayer, BOARD *aParent, std::map< wxString, wxString > aParams, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, wxArrayString aShapes)
double ScaleSize(double aValue) override
void ParseBoard(BOARD *aBoard, const VECTOR2D &aOrigin, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, wxArrayString aShapes)
PCB_LAYER_ID LayerToKi(const wxString &aLayer)
A progress reporter interface for use in multi-threaded environments.
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
static int DefaultAccuracyForPCB()
Definition shape_arc.h:283
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
void RebuildHolesFromContours()
Extract all contours from this polygon set, then recreate polygons with holes.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const std::vector< POLYGON > & CPolygons() const
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
@ DEGREES_T
Definition eda_angle.h:30
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
void ConnectBoardShapes(std::vector< PCB_SHAPE * > &aShapeList, int aChainingEpsilon)
Connects shapes to each other, making continious contours (adjacent shapes will have a common vertex)...
#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
@ In22_Cu
Definition layer_ids.h:83
@ In11_Cu
Definition layer_ids.h:72
@ In29_Cu
Definition layer_ids.h:90
@ In30_Cu
Definition layer_ids.h:91
@ F_CrtYd
Definition layer_ids.h:112
@ In17_Cu
Definition layer_ids.h:78
@ Edge_Cuts
Definition layer_ids.h:108
@ Dwgs_User
Definition layer_ids.h:103
@ F_Paste
Definition layer_ids.h:100
@ In9_Cu
Definition layer_ids.h:70
@ Cmts_User
Definition layer_ids.h:104
@ In19_Cu
Definition layer_ids.h:80
@ In7_Cu
Definition layer_ids.h:68
@ In28_Cu
Definition layer_ids.h:89
@ In26_Cu
Definition layer_ids.h:87
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ User_5
Definition layer_ids.h:124
@ Eco1_User
Definition layer_ids.h:105
@ F_Mask
Definition layer_ids.h:93
@ In21_Cu
Definition layer_ids.h:82
@ In23_Cu
Definition layer_ids.h:84
@ B_Paste
Definition layer_ids.h:101
@ In15_Cu
Definition layer_ids.h:76
@ In2_Cu
Definition layer_ids.h:63
@ F_Fab
Definition layer_ids.h:115
@ In10_Cu
Definition layer_ids.h:71
@ F_SilkS
Definition layer_ids.h:96
@ In4_Cu
Definition layer_ids.h:65
@ Eco2_User
Definition layer_ids.h:106
@ In16_Cu
Definition layer_ids.h:77
@ In24_Cu
Definition layer_ids.h:85
@ In1_Cu
Definition layer_ids.h:62
@ User_3
Definition layer_ids.h:122
@ User_1
Definition layer_ids.h:120
@ B_SilkS
Definition layer_ids.h:97
@ In13_Cu
Definition layer_ids.h:74
@ User_4
Definition layer_ids.h:123
@ In8_Cu
Definition layer_ids.h:69
@ In14_Cu
Definition layer_ids.h:75
@ In12_Cu
Definition layer_ids.h:73
@ In27_Cu
Definition layer_ids.h:88
@ In6_Cu
Definition layer_ids.h:67
@ In5_Cu
Definition layer_ids.h:66
@ In3_Cu
Definition layer_ids.h:64
@ In20_Cu
Definition layer_ids.h:81
@ F_Cu
Definition layer_ids.h:60
@ In18_Cu
Definition layer_ids.h:79
@ In25_Cu
Definition layer_ids.h:86
@ B_Fab
Definition layer_ids.h:114
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
Definition map_helpers.h:30
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ PTH
Plated through hole pad.
Definition padstack.h:99
@ RECTANGLE
Definition padstack.h:55
Class to handle a set of BOARD_ITEMs.
static const wxString MODEL_SIZE_KEY
static const wxString DIRECT_MODEL_UUID_KEY
static const int SHAPE_JOIN_DISTANCE
static const VECTOR2I HIDDEN_TEXT_SIZE(pcbIUScale.mmToIU(0.5), pcbIUScale.mmToIU(0.5))
static LIB_ID EasyEdaToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
static LIB_ID EasyEdaToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
wxString UnescapeHTML(const wxString &aString)
Return a new wxString unescaped from HTML format.
@ CTX_FILENAME
@ CTX_LIBID
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
static EDA_ORIENTATION orientation(double d)
KIBIS_MODEL * model
bool cw
VECTOR2I center
const SHAPE_LINE_CHAIN chain
int radius
VECTOR2I end
int delta
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_TOP
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
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
VECTOR3< double > VECTOR3D
Definition vector3.h:230
static PIECE polygon(std::vector< VIA_CROSS_SECTION_GEOMETRY::POINT > aPoints, bool aMixed=false)
@ FULL
pads are covered by copper
Definition zones.h:47