KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_easyedapro_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
24
25
26#include <algorithm>
27#include <cmath>
28#include <limits>
29#include <memory>
30
31
32#include <json_common.h>
34#include <core/map_helpers.h>
35#include <string_utils.h>
36
37#include <wx/wfstream.h>
38#include <wx/stdstream.h>
39#include <wx/base64.h>
40#include <wx/log.h>
41#include <glm/glm.hpp>
42
43#include <progress_reporter.h>
44#include <footprint.h>
45#include <board.h>
48#include <netclass.h>
50
51#include <bezier_curves.h>
52#include <pcb_group.h>
53#include <pcb_track.h>
54#include <pcb_shape.h>
55#include <pcb_text.h>
56#include <font/font.h>
57#include <geometry/shape_arc.h>
60#include <geometry/shape_rect.h>
62#include <zone.h>
63#include <pad.h>
65#include <project.h>
66#include <fix_board_shape.h>
67#include <pcb_reference_image.h>
68#include <core/mirror.h>
69#include <trace_helpers.h>
70
71
72static const wxString QUERY_MODEL_UUID_KEY = wxS( "JLC_3DModel_Q" );
73static const wxString MODEL_SIZE_KEY = wxS( "JLC_3D_Size" );
74
75static const int SHAPE_JOIN_DISTANCE = pcbIUScale.mmToIU( 1.5 );
76
77
78double PCB_IO_EASYEDAPRO_PARSER::Convert( wxString aValue )
79{
80 double value = 0;
81
82 if( !aValue.ToCDouble( &value ) )
83 THROW_IO_ERRORF( _( "Failed to parse value: '%s'" ), aValue );
84
85 return value;
86}
87
88
89nlohmann::json PCB_IO_EASYEDAPRO_PARSER::NormalizeSafeSpacing( const nlohmann::json& aTable )
90{
91 if( !aTable.is_array() || ( aTable.size() != 8 && aTable.size() != 10 ) )
92 return aTable;
93
94 // Eight-row tables omit Copper / Plane Zone and finish with Board Outline. Ten-row
95 // tables add Copper / Plane Zone and Hole. Both predate v3's inserted Slot, Line,
96 // and Text / Image rows.
97 static constexpr size_t legacy8ToV3[] = { 0, 1, 2, 3, 4, 5, 6, 11 };
98 static constexpr size_t legacy10ToV3[] = { 0, 1, 2, 3, 4, 5, 6, 7, 11, 12 };
99 const size_t* legacyToV3 = aTable.size() == 8 ? legacy8ToV3 : legacy10ToV3;
100
101 nlohmann::json normalized = nlohmann::json::array();
102
103 for( size_t i = 0; i < 13; ++i )
104 normalized.push_back( nlohmann::json::array() );
105
106 for( size_t sourceRow = 0; sourceRow < aTable.size(); ++sourceRow )
107 {
108 if( !aTable.at( sourceRow ).is_array() )
109 continue;
110
111 for( size_t sourceCol = 0; sourceCol < aTable.at( sourceRow ).size() && sourceCol < aTable.size(); ++sourceCol )
112 {
113 normalized[legacyToV3[sourceRow]][legacyToV3[sourceCol]] = aTable.at( sourceRow ).at( sourceCol );
114 }
115 }
116
117 return normalized;
118}
119
120
122{
123 m_board = aBoard;
124}
125
126
130
131
133{
134 switch( aLayer )
135 {
136 case 1: return F_Cu;
137 case 2: return B_Cu;
138 case 3: return F_SilkS;
139 case 4: return B_SilkS;
140 case 5: return F_Mask;
141 case 6: return B_Mask;
142 case 7: return F_Paste;
143 case 8: return B_Paste;
144 case 9: return F_Fab;
145 case 10: return B_Fab;
146 case 11: return Edge_Cuts;
147 case 12: return Edge_Cuts; // Multi
148 case 13: return Dwgs_User;
149 case 14: return Eco2_User;
150
151 case 15: return In1_Cu;
152 case 16: return In2_Cu;
153 case 17: return In3_Cu;
154 case 18: return In4_Cu;
155 case 19: return In5_Cu;
156 case 20: return In6_Cu;
157 case 21: return In7_Cu;
158 case 22: return In8_Cu;
159 case 23: return In9_Cu;
160 case 24: return In10_Cu;
161 case 25: return In11_Cu;
162 case 26: return In12_Cu;
163 case 27: return In13_Cu;
164 case 28: return In14_Cu;
165 case 29: return In15_Cu;
166 case 30: return In16_Cu;
167 case 31: return In17_Cu;
168 case 32: return In18_Cu;
169 case 33: return In19_Cu;
170 case 34: return In20_Cu;
171 case 35: return In21_Cu;
172 case 36: return In22_Cu;
173 case 37: return In23_Cu;
174 case 38: return In24_Cu;
175 case 39: return In25_Cu;
176 case 40: return In26_Cu;
177 case 41: return In27_Cu;
178 case 42: return In28_Cu;
179 case 43: return In29_Cu;
180 case 44: return In30_Cu;
181
182 case 48: return F_Fab; // Component shape layer
183 case 49: return F_Fab; // Component marking
184
185 case 53: return User_4; // 3D shell outline
186 case 54: return User_5; // 3D shell top
187 case 55: return User_6; // 3D shell bot
188 case 56: return User_7; // Drill drawing
189
190 default: break;
191 }
192
193 return User_1;
194}
195
196
197static void AlignText( EDA_TEXT* text, int align )
198{
199 switch( align )
200 {
201 case 1:
202 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
203 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
204 break;
205 case 2:
206 text->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
207 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
208 break;
209 case 3:
210 text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
211 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
212 break;
213
214 case 4:
215 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
216 text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
217 break;
218 case 5:
219 text->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
220 text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
221 break;
222 case 6:
223 text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
224 text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
225 break;
226
227 case 7:
228 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
229 text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
230 break;
231 case 8:
232 text->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
233 text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
234 break;
235 case 9:
236 text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
237 text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
238 break;
239 }
240}
241
242
243void PCB_IO_EASYEDAPRO_PARSER::FillFootprintModelInfo( FOOTPRINT* footprint, const wxString& modelUuid,
244 const wxString& modelTitle,
245 const wxString& modelTransform ) const
246{
247 // TODO: make this path configurable?
248 const wxString easyedaModelDir = wxS( "EASYEDA_MODELS" );
249 const wxString kicadModelPrefix = wxS( "${KIPRJMOD}/" ) + easyedaModelDir + wxS( "/" );
250
251 VECTOR3D kmodelOffset;
252 VECTOR3D kmodelRotation;
253
254 if( !modelUuid.IsEmpty() && !footprint->GetField( QUERY_MODEL_UUID_KEY ) )
255 {
256 PCB_FIELD* field = new PCB_FIELD( footprint, FIELD_T::USER, QUERY_MODEL_UUID_KEY );
257 field->SetLayer( Cmts_User );
258 field->SetVisible( false );
259 field->SetText( modelUuid );
260 footprint->Add( field );
261 }
262
263 if( !modelTransform.IsEmpty() && !footprint->GetField( MODEL_SIZE_KEY ) )
264 {
265 wxArrayString arr = wxSplit( modelTransform, ',', '\0' );
266
267 double fitXmm = pcbIUScale.IUTomm( ScaleSize( Convert( arr[0] ) ) );
268 double fitYmm = pcbIUScale.IUTomm( ScaleSize( Convert( arr[1] ) ) );
269
270 if( fitXmm > 0.0 && fitYmm > 0.0 )
271 {
272 PCB_FIELD* field = new PCB_FIELD( footprint, FIELD_T::USER, MODEL_SIZE_KEY );
273 field->SetLayer( Cmts_User );
274 field->SetVisible( false );
275 field->SetText( wxString::FromCDouble( fitXmm ) + wxS( " " ) + wxString::FromCDouble( fitYmm ) );
276 footprint->Add( field );
277 }
278
279 kmodelRotation.z = -Convert( arr[3] );
280 kmodelRotation.x = -Convert( arr[4] );
281 kmodelRotation.y = -Convert( arr[5] );
282
283 kmodelOffset.x = pcbIUScale.IUTomm( ScaleSize( Convert( arr[6] ) ) );
284 kmodelOffset.y = pcbIUScale.IUTomm( ScaleSize( Convert( arr[7] ) ) );
285 kmodelOffset.z = pcbIUScale.IUTomm( ScaleSize( Convert( arr[8] ) ) );
286 }
287
288 if( !modelTitle.IsEmpty() && footprint->Models().empty() )
289 {
291 model.m_Filename = kicadModelPrefix + EscapeString( modelTitle, ESCAPE_CONTEXT::CTX_FILENAME ) + wxS( ".step" );
292 model.m_Offset = kmodelOffset;
293 model.m_Rotation = kmodelRotation;
294 footprint->Models().push_back( model );
295 }
296}
297
298
299namespace
300{
302constexpr double NM_PER_UNIT = 25400.0;
303
304
305// Chords within a micrometer of an arc whose circle leaves the integer range, or one chord when the curve itself
306// does, as the points after aStart; none when the arc can be stored
307std::vector<VECTOR2D> chordsForUnstorableArc( const VECTOR2D& aStart, const VECTOR2D& aEnd, double aAngle )
308{
309 VECTOR2D delta = aEnd - aStart;
310 VECTOR2D mid = ( aStart + delta / 2 );
311
312 double ha = aAngle / 2;
313 double hd = delta.EuclideanNorm() / 2;
314 double cdist = ha == 0 ? 0 : hd / tan( DEG2RAD( ha ) );
315 VECTOR2D center = mid + delta.Perpendicular().Resize( cdist );
316
317 const double radiusNm = std::hypot( cdist, hd ) * NM_PER_UNIT;
318 const double limit = std::numeric_limits<int>::max();
319
320 if( ha != 0 && std::abs( center.x ) * NM_PER_UNIT + radiusNm <= limit
321 && std::abs( center.y ) * NM_PER_UNIT + radiusNm <= limit )
322 {
323 return {};
324 }
325
326 double radius = ha == 0 ? 0 : std::hypot( cdist, hd );
327
328 // The center sits left of the chord for a positive angle, so the sweep turns counterclockwise
329 double sweep = DEG2RAD( aAngle );
330 VECTOR2D v = aStart - center;
331 double startAngle = std::atan2( v.y, v.x );
332 auto rotated = [&]( double aRotation )
333 {
334 return center + VECTOR2D( v.x * std::cos( aRotation ) - v.y * std::sin( aRotation ),
335 v.x * std::sin( aRotation ) + v.y * std::cos( aRotation ) );
336 };
337
338 bool curveFits = radius > 0
339 && std::max( { std::abs( aStart.x ), std::abs( aStart.y ), std::abs( aEnd.x ),
340 std::abs( aEnd.y ) } ) * NM_PER_UNIT <= limit;
341
342 for( int quadrant = 0; quadrant < 4 && curveFits; quadrant++ )
343 {
344 double cardinal = quadrant * M_PI / 2;
345 double turn = sweep > 0 ? cardinal - startAngle : startAngle - cardinal;
346 double reach = std::fmod( turn, 2 * M_PI );
347 VECTOR2D extreme = center + VECTOR2D( std::cos( cardinal ), std::sin( cardinal ) ) * radius;
348
349 if( reach < 0 )
350 reach += 2 * M_PI;
351
352 if( reach <= std::abs( sweep )
353 && std::max( std::abs( extreme.x ), std::abs( extreme.y ) ) * NM_PER_UNIT > limit )
354 {
355 curveFits = false;
356 }
357 }
358
359 // Half a micrometer of sagitta leaves the other half for the rounding of the points
360 double maxStep = curveFits ? 2 * std::acos( 1 - ( 500.0 / NM_PER_UNIT ) / radius ) : 0;
361 int count = maxStep > 0 ? std::max( 1, (int) std::ceil( std::abs( sweep ) / maxStep ) ) : 1;
362
363 std::vector<VECTOR2D> points;
364
365 for( int step = 1; step <= count; step++ )
366 points.push_back( step == count ? aEnd : rotated( sweep * step / count ) );
367
368 return points;
369}
370} // namespace
371
372
373std::vector<std::unique_ptr<PCB_SHAPE>> PCB_IO_EASYEDAPRO_PARSER::ParsePoly( BOARD_ITEM_CONTAINER* aContainer,
374 nlohmann::json polyData, bool aClosed,
375 bool aInFill ) const
376{
377 std::vector<std::unique_ptr<PCB_SHAPE>> results;
378
379 VECTOR2D prevPt;
380 for( int i = 0; i < (int) polyData.size(); i++ )
381 {
382 nlohmann::json val = polyData.at( i );
383
384 if( val.is_string() )
385 {
386 wxString str = val;
387 if( str == wxS( "CIRCLE" ) )
388 {
390 center.x = ( polyData.at( ++i ) );
391 center.y = ( polyData.at( ++i ) );
392 double r = ( polyData.at( ++i ) );
393
394 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::CIRCLE );
395
396 shape->SetCenter( ScalePos( center ) );
397 shape->SetEnd( ScalePos( center + VECTOR2D( r, 0 ) ) );
398 shape->SetFilled( aClosed );
399
400 results.emplace_back( std::move( shape ) );
401 }
402 else if( str == wxS( "R" ) )
403 {
404 VECTOR2D start, size;
405 start.x = ( polyData.at( ++i ) );
406 start.y = ( polyData.at( ++i ) );
407 size.x = ( polyData.at( ++i ) );
408 size.y = -( polyData.at( ++i ).get<double>() );
409 double angle = polyData.at( ++i );
410 double cr = ( i + 1 ) < (int) polyData.size() ? polyData.at( ++i ).get<double>() : 0;
411
412 if( cr == 0 )
413 {
414 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::RECTANGLE );
415
416 shape->SetStart( ScalePos( start ) );
417 shape->SetEnd( ScalePos( start + size ) );
418 shape->SetFilled( aClosed );
419 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
420
421 results.emplace_back( std::move( shape ) );
422 }
423 else
424 {
425 VECTOR2D end = start + size;
426
427 auto addSegment = [&]( VECTOR2D aStart, VECTOR2D aEnd )
428 {
429 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
430
431 shape->SetStart( ScalePos( aStart ) );
432 shape->SetEnd( ScalePos( aEnd ) );
433 shape->SetFilled( aClosed );
434 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
435
436 results.emplace_back( std::move( shape ) );
437 };
438
439 auto addArc = [&]( VECTOR2D aStart, VECTOR2D aEnd, VECTOR2D center )
440 {
441 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::ARC );
442
443 shape->SetStart( ScalePos( aStart ) );
444 shape->SetEnd( ScalePos( aEnd ) );
445 shape->SetCenter( ScalePos( center ) );
446 shape->SetFilled( aClosed );
447 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
448
449 results.emplace_back( std::move( shape ) );
450 };
451
452 addSegment( { start.x + cr, start.y }, { end.x - cr, start.y } );
453 addSegment( { end.x, start.y - cr }, { end.x, end.y + cr } );
454 addSegment( { start.x + cr, end.y }, { end.x - cr, end.y } );
455 addSegment( { start.x, start.y - cr }, { start.x, end.y + cr } );
456
457 addArc( { end.x - cr, start.y }, { end.x, start.y - cr }, { end.x - cr, start.y - cr } );
458
459 addArc( { end.x, end.y + cr }, { end.x - cr, end.y }, { end.x - cr, end.y + cr } );
460
461 addArc( { start.x + cr, end.y }, { start.x, end.y + cr }, { start.x + cr, end.y + cr } );
462
463 addArc( { start.x, start.y - cr }, { start.x + cr, start.y }, { start.x + cr, start.y - cr } );
464 }
465 }
466 else if( str == wxS( "ARC" ) || str == wxS( "CARC" ) )
467 {
469 double angle = polyData.at( ++i ).get<double>() / ( aInFill ? 10 : 1 );
470 end.x = ( polyData.at( ++i ) );
471 end.y = ( polyData.at( ++i ) );
472
473 VECTOR2D delta = end - prevPt;
474 VECTOR2D mid = ( prevPt + delta / 2 );
475
476 double ha = angle / 2;
477 double hd = delta.EuclideanNorm() / 2;
478 double cdist = ha == 0 ? 0 : hd / tan( DEG2RAD( ha ) );
479 VECTOR2D center = mid + delta.Perpendicular().Resize( cdist );
480
481 if( std::vector<VECTOR2D> chords = chordsForUnstorableArc( prevPt, end, angle ); !chords.empty() )
482 {
483 for( const VECTOR2D& to : chords )
484 {
485 std::unique_ptr<PCB_SHAPE> line = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
486
487 line->SetStart( ScalePos( prevPt ) );
488 line->SetEnd( ScalePos( to ) );
489 line->SetFilled( aClosed );
490 results.emplace_back( std::move( line ) );
491
492 prevPt = to;
493 }
494
495 continue;
496 }
497
498 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::ARC );
499
500 if( angle < 0 )
501 {
502 shape->SetStart( ScalePos( prevPt ) );
503 shape->SetEnd( ScalePos( end ) );
504 }
505 else
506 {
507 shape->SetStart( ScalePos( end ) );
508 shape->SetEnd( ScalePos( prevPt ) );
509 }
510
511 shape->SetCenter( ScalePos( center ) );
512
513 shape->SetFilled( aClosed );
514
515 results.emplace_back( std::move( shape ) );
516
517 prevPt = end;
518 }
519 else if( str == wxS( "L" ) )
520 {
522 chain.Append( ScalePos( prevPt ) );
523
524 while( i < (int) polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
525 {
526 VECTOR2D pt;
527 pt.x = ( polyData.at( ++i ) );
528 pt.y = ( polyData.at( ++i ) );
529
530 chain.Append( ScalePos( pt ) );
531
532 prevPt = pt;
533 }
534
535 if( aClosed )
536 {
537 if( chain.PointCount() > 2 )
538 {
539 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
540
541 chain.SetClosed( true );
542 shape->SetFilled( true );
543 shape->SetPolyShape( chain );
544
545 results.emplace_back( std::move( shape ) );
546 }
547 }
548 else
549 {
550 for( int s = 0; s < chain.SegmentCount(); s++ )
551 {
552 SEG seg = chain.Segment( s );
553
554 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
555
556 shape->SetStart( seg.A );
557 shape->SetEnd( seg.B );
558
559 results.emplace_back( std::move( shape ) );
560 }
561 }
562 }
563 }
564 else if( val.is_number() )
565 {
566 prevPt.x = ( polyData.at( i ) );
567 prevPt.y = ( polyData.at( ++i ) );
568 }
569 }
570
571 return results;
572}
573
574
576PCB_IO_EASYEDAPRO_PARSER::ParseContour( nlohmann::json polyData, bool aInFill, int aMaxError ) const
577{
579 VECTOR2D prevPt;
580
581 for( int i = 0; i < (int) polyData.size(); i++ )
582 {
583 nlohmann::json val = polyData.at( i );
584
585 if( val.is_string() )
586 {
587 wxString str = val;
588 if( str == wxS( "CIRCLE" ) )
589 {
591 center.x = ( polyData.at( ++i ) );
592 center.y = ( polyData.at( ++i ) );
593 double r = ( polyData.at( ++i ) );
594
596 }
597 else if( str == wxS( "R" ) )
598 {
599 VECTOR2D start, size;
600 start.x = ( polyData.at( ++i ) );
601 start.y = ( polyData.at( ++i ) );
602 size.x = ( polyData.at( ++i ) );
603 size.y = ( polyData.at( ++i ).get<double>() );
604 double angle = polyData.at( ++i );
605 double cr = ( i + 1 ) < (int) polyData.size() ? polyData.at( ++i ).get<double>() : 0;
606
607 SHAPE_POLY_SET poly;
608
609 VECTOR2D kstart = ScalePos( start );
610 VECTOR2D ksize = ScaleSize( size );
611 VECTOR2D kcenter = kstart + ksize / 2;
612 RotatePoint( kcenter, kstart, EDA_ANGLE( angle, DEGREES_T ) );
613
614 double maxRadius = std::min( std::abs( ksize.x ), std::abs( ksize.y ) ) / 2.0;
615 double radius = std::min( ScaleSize( cr ), maxRadius );
616
617 TransformRoundChamferedRectToPolygon( poly, kcenter, ksize, EDA_ANGLE( angle, DEGREES_T ), radius, 0, 0,
618 0, aMaxError, ERROR_INSIDE );
619
620 result.Append( poly.Outline( 0 ) );
621 }
622 else if( str == wxS( "ARC" ) || str == wxS( "CARC" ) )
623 {
625 double angle = polyData.at( ++i ).get<double>();
626
627 if( aInFill ) // In .epcb fills, the angle is 10x for some reason
628 angle /= 10;
629
630 end.x = ( polyData.at( ++i ) );
631 end.y = ( polyData.at( ++i ) );
632
633 if( std::vector<VECTOR2D> chords = chordsForUnstorableArc( prevPt, end, angle ); !chords.empty() )
634 {
635 result.Append( ScalePos( prevPt ) );
636
637 for( const VECTOR2D& to : chords )
638 result.Append( ScalePos( to ) );
639 }
640 else
641 {
642 SHAPE_ARC sarc;
644 -EDA_ANGLE( angle, DEGREES_T ) );
645
646 result.Append( sarc, aMaxError );
647 }
648
649 prevPt = end;
650 }
651 else if( str == wxS( "C" ) )
652 {
653 VECTOR2D pt1;
654 pt1.x = ( polyData.at( ++i ) );
655 pt1.y = ( polyData.at( ++i ) );
656
657 VECTOR2D pt2;
658 pt2.x = ( polyData.at( ++i ) );
659 pt2.y = ( polyData.at( ++i ) );
660
661 VECTOR2D pt3;
662 pt3.x = ( polyData.at( ++i ) );
663 pt3.y = ( polyData.at( ++i ) );
664
665 std::vector<VECTOR2I> ctrlPoints = { ScalePos( prevPt ), ScalePos( pt1 ), ScalePos( pt2 ),
666 ScalePos( pt3 ) };
667 BEZIER_POLY converter( ctrlPoints );
668
669 std::vector<VECTOR2I> bezierPoints;
670 converter.GetPoly( bezierPoints, aMaxError );
671
672 result.Append( bezierPoints );
673
674 prevPt = pt3;
675 }
676 else if( str == wxS( "L" ) )
677 {
678 result.Append( ScalePos( prevPt ) );
679
680 while( i < (int) polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
681 {
682 VECTOR2D pt;
683 pt.x = ( polyData.at( ++i ) );
684 pt.y = ( polyData.at( ++i ) );
685
686 result.Append( ScalePos( pt ) );
687
688 prevPt = pt;
689 }
690 }
691 }
692 else if( val.is_number() )
693 {
694 prevPt.x = ( polyData.at( i ) );
695 prevPt.y = ( polyData.at( ++i ) );
696 }
697 }
698
699 return result;
700}
701
702
703NETINFO_ITEM* PCB_IO_EASYEDAPRO_PARSER::getNet( BOARD* aBoard, const wxString& aNetName )
704{
705 if( !aBoard || aNetName.empty() )
706 return nullptr;
707
708 NETINFO_ITEM* net = aBoard->FindNet( aNetName );
709
710 if( !net )
711 {
712 net = new NETINFO_ITEM( aBoard, aNetName, static_cast<int>( aBoard->GetNetCount() ) + 1 );
713 aBoard->Add( net );
714 }
715
716 return net;
717}
718
719
721{
723
724 if( size.x > 0 && size.y > 0 )
725 return;
726
727 VECTOR2I drill = aPad.GetDrillSize();
728
729 aPad.SetSize( PADSTACK::ALL_LAYERS, drill );
732
733 if( !aPlated )
734 {
737 }
738}
739
740
741std::unique_ptr<PAD> PCB_IO_EASYEDAPRO_PARSER::createPAD( FOOTPRINT* aFootprint, const nlohmann::json& line )
742{
743 wxString uuid = line.at( 1 );
744
745 // if( line.at( 2 ).is_number() )
746 // int unk = line.at( 2 ).get<int>();
747 // else if( line.at( 2 ).is_string() )
748 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
749
750 wxString netname = line.at( 3 );
751 int layer = line.at( 4 ).get<int>();
752 PCB_LAYER_ID klayer = LayerToKi( layer );
753
754 wxString padNumber = line.at( 5 );
755
757 center.x = line.at( 6 );
758 center.y = line.at( 7 );
759
760 double orientation = line.at( 8 );
761
762 nlohmann::json padHole = line.at( 9 );
763 nlohmann::json padShape = line.at( 10 );
764
765 std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
766
767 pad->SetNumber( padNumber );
768 pad->SetPosition( ScalePos( center ) );
769 pad->SetOrientationDegrees( orientation );
770 pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
771
772 // Check if this pad has a real drill hole
773 // JLCEDA may use ["ROUND",0,0] to indicate SMD pads
774 bool hasHole = false;
775
776 if( !padHole.is_null() && !padHole.empty() )
777 {
778 wxString holeShape = padHole.at( 0 );
779
780 if( holeShape == wxS( "ROUND" ) || holeShape == wxS( "SLOT" ) )
781 {
782 VECTOR2D drill;
783 drill.x = padHole.at( 1 );
784 drill.y = padHole.at( 2 );
785
786 // Only treat as PTH if hole size is non-zero
787 if( drill.x > 0 || drill.y > 0 )
788 {
789 hasHole = true;
790
791 double drill_dir = 0;
792
793 if( line.at( 14 ).is_number() )
794 drill_dir = line.at( 14 );
795
796 double deg = EDA_ANGLE( drill_dir, DEGREES_T ).Normalize90().AsDegrees();
797
798 if( std::abs( deg ) >= 45 )
799 std::swap( drill.x, drill.y ); // KiCad doesn't support arbitrary hole direction
800
801 if( holeShape == wxS( "SLOT" ) )
802 {
803 pad->SetDrillShape( PAD_DRILL_SHAPE::OBLONG );
804 }
805
806 pad->SetDrillSize( ScaleSize( drill ) );
807 pad->SetLayerSet( PAD::PTHMask() );
808 pad->SetAttribute( PAD_ATTRIB::PTH );
809 }
810 }
811 }
812
813 // If no valid hole, this is an SMD pad
814 if( !hasHole )
815 {
816 if( klayer == F_Cu )
817 {
818 pad->SetLayerSet( PAD::SMDMask() );
819 }
820 else if( klayer == B_Cu )
821 {
822 pad->SetLayerSet( PAD::SMDMask().FlipStandardLayers() );
823 }
824
825 pad->SetAttribute( PAD_ATTRIB::SMD );
826 }
827
828 wxString padSh = padShape.at( 0 );
829
830 if( padSh == wxS( "RECT" ) )
831 {
832 VECTOR2D size;
833 size.x = padShape.at( 1 );
834 size.y = padShape.at( 2 );
835 double cr_p = padShape.size() > 3 ? padShape.at( 3 ).get<double>() : 0;
836
837 pad->SetSize( PADSTACK::ALL_LAYERS, ScaleSize( size ) );
838
839 if( cr_p == 0 )
840 {
842 }
843 else
844 {
846 pad->SetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS, cr_p / 100 );
847 }
848 }
849 else if( padSh == wxS( "ELLIPSE" ) )
850 {
851 VECTOR2D size;
852 size.x = padShape.at( 1 );
853 size.y = padShape.at( 2 );
854
855 pad->SetSize( PADSTACK::ALL_LAYERS, ScaleSize( size ) );
857 }
858 else if( padSh == wxS( "OVAL" ) )
859 {
860 VECTOR2D size;
861 size.x = padShape.at( 1 );
862 size.y = padShape.at( 2 );
863
864 pad->SetSize( PADSTACK::ALL_LAYERS, ScaleSize( size ) );
866 }
867 else if( padSh == wxS( "POLY" ) || padSh == wxS( "POLYGON" ) )
868 {
870 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CIRCLE );
871 pad->SetSize( PADSTACK::ALL_LAYERS, { 1, 1 } );
872
873 nlohmann::json polyData = padShape.at( 1 );
874
875 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
876 wxASSERT( contour.PointCount() > 2 );
877
878 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aFootprint, SHAPE_T::POLY );
879
880 if( contour.PointCount() > 2 )
881 {
882 contour.SetClosed( true );
883 shape->SetFilled( true );
884 shape->SetPolyShape( contour );
885 shape->SetLayer( klayer );
886 shape->SetWidth( 0 );
887 shape->Move( -pad->GetPosition() );
888
889 pad->AddPrimitive( PADSTACK::ALL_LAYERS, shape.release() );
890 }
891 }
892
893 if( hasHole )
894 SizeHoleOnlyPad( *pad, !( line.size() > 15 && line.at( 15 ).is_number() && line.at( 15 ).get<int>() == 0 ) );
895
896 pad->SetThermalSpokeAngle( ANGLE_90 );
897
898 return pad;
899}
900
901
902std::unique_ptr<FOOTPRINT> PCB_IO_EASYEDAPRO_PARSER::ParseFootprint( const nlohmann::json& aProject,
903 const wxString& aFpUuid,
904 const std::vector<nlohmann::json>& aLines )
905{
906 std::unique_ptr<FOOTPRINT> footprintPtr = std::make_unique<FOOTPRINT>( m_board );
907 FOOTPRINT* footprint = footprintPtr.get();
908
909 const VECTOR2I defaultTextSize( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) );
910 const int defaultTextThickness( pcbIUScale.mmToIU( 0.15 ) );
911 VECTOR2I canvasOrigin( 0, 0 );
912
913 for( PCB_FIELD* field : footprint->GetFields() )
914 {
915 field->SetTextSize( defaultTextSize );
916 field->SetTextThickness( defaultTextThickness );
917 }
918
919 for( const nlohmann::json& line : aLines )
920 {
921 if( line.size() == 0 )
922 continue;
923
924 wxString type = line.at( 0 );
925
926 if( type == wxS( "CANVAS" ) )
927 {
928 if( line.size() > 2 && line.at( 1 ).is_number() && line.at( 2 ).is_number() )
929 {
930 canvasOrigin = ScalePos( VECTOR2D( line.at( 1 ), line.at( 2 ) ) );
931 }
932 }
933 else if( type == wxS( "POLY" ) || type == wxS( "PAD" ) || type == wxS( "FILL" ) || type == wxS( "ATTR" ) )
934 {
935 wxString uuid = line.at( 1 );
936
937 // if( line.at( 2 ).is_number() )
938 // int unk = line.at( 2 ).get<int>();
939 // else if( line.at( 2 ).is_string() )
940 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
941
942 wxString netname = line.at( 3 );
943 int layer = line.at( 4 ).get<int>();
944 PCB_LAYER_ID klayer = LayerToKi( layer );
945
946 if( type == wxS( "POLY" ) )
947 {
948 double thickness = ( line.at( 5 ) );
949 nlohmann::json polyData = line.at( 6 );
950
951 std::vector<std::unique_ptr<PCB_SHAPE>> results = ParsePoly( footprint, polyData, false, false );
952
953 for( auto& shape : results )
954 {
955 shape->SetLayer( klayer );
956 shape->SetWidth( ScaleSize( thickness ) );
957
958 footprint->Add( shape.release(), ADD_MODE::APPEND );
959 }
960 }
961 else if( type == wxS( "PAD" ) )
962 {
963 std::unique_ptr<PAD> pad = createPAD( footprint, line );
964
965 footprint->Add( pad.release(), ADD_MODE::APPEND );
966 }
967 else if( type == wxS( "FILL" ) )
968 {
969 int fillLayer = line.at( 4 ).get<int>();
970 PCB_LAYER_ID fillKlayer = LayerToKi( fillLayer );
971
972 nlohmann::json polyDataList = line.at( 7 );
973
974 if( !polyDataList.is_null() && !polyDataList.empty() )
975 {
976 if( !polyDataList.at( 0 ).is_array() )
977 polyDataList = nlohmann::json::array( { polyDataList } );
978
979 std::vector<SHAPE_LINE_CHAIN> contours;
980 for( nlohmann::json& polyData : polyDataList )
981 {
982 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
983 contour.SetClosed( true );
984
985 contours.push_back( contour );
986 }
987
988 SHAPE_POLY_SET polySet;
989
990 for( SHAPE_LINE_CHAIN& contour : contours )
991 polySet.AddOutline( contour );
992
993 polySet.RebuildHolesFromContours();
994
995 std::unique_ptr<PCB_GROUP> group;
996
997 if( polySet.OutlineCount() > 1 )
998 group = std::make_unique<PCB_GROUP>( footprint );
999
1000 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
1001 {
1002 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint, SHAPE_T::POLY );
1003
1004 shape->SetFilled( true );
1005 shape->SetPolyShape( poly );
1006 shape->SetLayer( fillKlayer );
1007 shape->SetWidth( 0 );
1008
1009 if( group )
1010 group->AddItem( shape.get() );
1011
1012 footprint->Add( shape.release(), ADD_MODE::APPEND );
1013 }
1014
1015 if( group )
1016 footprint->Add( group.release(), ADD_MODE::APPEND );
1017 }
1018 }
1019 else if( type == wxS( "ATTR" ) )
1020 {
1021 EASYEDAPRO::PCB_ATTR attr = line;
1022
1023 if( attr.key == wxS( "Designator" ) )
1024 footprint->GetField( FIELD_T::REFERENCE )->SetText( attr.value );
1025 }
1026 }
1027 else if( type == wxS( "REGION" ) )
1028 {
1029 wxString uuid = line.at( 1 );
1030
1031 // if( line.at( 2 ).is_number() )
1032 // int unk = line.at( 2 ).get<int>();
1033 // else if( line.at( 2 ).is_string() )
1034 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1035
1036 int layer = line.at( 3 ).get<int>();
1037 PCB_LAYER_ID klayer = LayerToKi( layer );
1038
1039 std::set<int> flags = line.at( 5 );
1040 nlohmann::json polyDataList = line.at( 6 );
1041
1042 for( nlohmann::json& polyData : polyDataList )
1043 {
1044 SHAPE_POLY_SET polySet;
1045
1046 std::vector<std::unique_ptr<PCB_SHAPE>> results = ParsePoly( nullptr, polyData, true, false );
1047
1048 for( auto& shape : results )
1049 {
1050 shape->SetFilled( true );
1051 shape->TransformShapeToPolygon( polySet, klayer, 0, ARC_HIGH_DEF, ERROR_INSIDE, true );
1052 }
1053
1054 polySet.Simplify();
1055
1056 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( footprint );
1057
1058 zone->SetIsRuleArea( true );
1059 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1060 zone->SetDoNotAllowZoneFills( !!flags.count( 7 ) || !!flags.count( 6 ) || !!flags.count( 8 ) );
1061 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1062 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1063 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1064
1065 zone->SetLayer( klayer );
1066 zone->Outline()->Append( polySet );
1067
1068 footprint->Add( zone.release(), ADD_MODE::APPEND );
1069 }
1070 }
1071 }
1072
1073 if( aProject.is_object() && aProject.contains( "devices" ) )
1074 {
1075 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at( "devices" );
1076 std::map<wxString, wxString> compAttrs;
1077
1078 for( auto& [devUuid, devData] : devicesMap )
1079 {
1080 if( auto fp = get_opt( devData.attributes, "Footprint" ) )
1081 {
1082 if( *fp == aFpUuid )
1083 {
1084 compAttrs = devData.attributes;
1085 break;
1086 }
1087 }
1088 }
1089
1090 wxString modelUuid, modelTitle, modelTransform;
1091
1092 modelUuid = get_def( compAttrs, "3D Model", "" );
1093 modelTitle = get_def( compAttrs, "3D Model Title", modelUuid );
1094 modelTransform = get_def( compAttrs, "3D Model Transform", "" );
1095
1096 FillFootprintModelInfo( footprint, modelUuid, modelTitle, modelTransform );
1097 }
1098
1099 // Heal board outlines
1100 std::vector<PCB_SHAPE*> edgeShapes;
1101
1102 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1103 {
1104 if( item->IsOnLayer( Edge_Cuts ) && item->Type() == PCB_SHAPE_T )
1105 edgeShapes.push_back( static_cast<PCB_SHAPE*>( item ) );
1106 }
1107
1109
1110 // EasyEDA footprints don't have courtyard, so build a box ourselves
1111 if( !footprint->IsOnLayer( F_CrtYd ) )
1112 {
1113 BOX2I bbox = footprint->GetLayerBoundingBox( { F_Cu, F_Fab, F_Paste, F_Mask, Edge_Cuts } );
1114 bbox.Inflate( pcbIUScale.mmToIU( 0.25 ) ); // Default courtyard clearance
1115
1116 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint, SHAPE_T::RECTANGLE );
1117
1118 shape->SetWidth( pcbIUScale.mmToIU( DEFAULT_COURTYARD_WIDTH ) );
1119 shape->SetLayer( F_CrtYd );
1120 shape->SetStart( bbox.GetOrigin() );
1121 shape->SetEnd( bbox.GetEnd() );
1122
1123 footprint->Add( shape.release(), ADD_MODE::APPEND );
1124 }
1125
1126 bool hasFabRef = false;
1127
1128 for( BOARD_ITEM* item : footprint->GraphicalItems() )
1129 {
1130 if( item->Type() == PCB_TEXT_T && item->IsOnLayer( F_Fab ) )
1131 {
1132 if( static_cast<PCB_TEXT*>( item )->GetText() == wxT( "${REFERENCE}" ) )
1133 {
1134 hasFabRef = true;
1135 break;
1136 }
1137 }
1138 }
1139
1140 if( !hasFabRef )
1141 {
1142 // Add reference text field on F_Fab
1143 int c_refTextSize = pcbIUScale.mmToIU( 0.5 ); // KLC min Fab text size
1144 int c_refTextThickness = pcbIUScale.mmToIU( 0.1 ); // Decent text thickness
1145 std::unique_ptr<PCB_TEXT> refText = std::make_unique<PCB_TEXT>( footprint );
1146
1147 refText->SetLayer( F_Fab );
1148 refText->SetTextSize( VECTOR2I( c_refTextSize, c_refTextSize ) );
1149 refText->SetTextThickness( c_refTextThickness );
1150 refText->SetText( wxT( "${REFERENCE}" ) );
1151
1152 footprint->Add( refText.release(), ADD_MODE::APPEND );
1153 }
1154
1155 footprint->MoveAnchorPosition( -canvasOrigin );
1156
1157 return footprintPtr;
1158}
1159
1160
1161void PCB_IO_EASYEDAPRO_PARSER::ParseBoard( BOARD* aBoard, const nlohmann::json& aProject,
1162 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
1163 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
1164 const std::multimap<wxString, EASYEDAPRO::POURED>& aPouredMap,
1165 const std::vector<nlohmann::json>& aLines, const wxString& aFpLibName )
1166{
1167 std::map<wxString, std::vector<nlohmann::json>> componentLines;
1168 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
1169
1170 std::multimap<wxString, EASYEDAPRO::POURED> boardPouredMap = aPouredMap;
1171 std::map<wxString, ZONE*> poursToFill;
1172
1173 m_safeSpacing = nlohmann::json();
1174
1176
1177 auto zoneClearance =
1178 [&]() -> int
1179 {
1180 if( m_safeSpacing.is_array()
1181 && m_safeSpacing.size() > 7
1182 && m_safeSpacing.at( 7 ).is_array()
1183 && !m_safeSpacing.at( 7 ).empty()
1184 && m_safeSpacing.at( 7 ).at( 0 ).is_number() )
1185 {
1186 const int clearance = ScaleSize( m_safeSpacing.at( 7 ).at( 0 ).get<double>() );
1187
1188 if( clearance > 0 )
1189 return clearance;
1190 }
1191
1192 return bds.m_MinClearance;
1193 };
1194
1195 const int zoneMinThickness = bds.GetDefaultZoneSettings().m_ZoneMinThickness;
1196
1197 std::map<wxString, nlohmann::json> safeSpacingProfiles;
1198 std::map<wxString, wxString> pourSafeSpacingProfiles;
1199
1200 for( const nlohmann::json& line : aLines )
1201 {
1202 if( line.empty() || !line.at( 0 ).is_string() )
1203 continue;
1204
1205 wxString type = line.at( 0 );
1206
1207 if( type == wxS( "RULE" ) && line.size() > 4 && line.at( 1 ).get<wxString>() == wxS( "1" )
1208 && line.at( 3 ).get<int>() != 2 && line.at( 4 ).is_array() && line.at( 4 ).size() > 1
1209 && line.at( 4 ).at( 1 ).is_array() )
1210 {
1211 safeSpacingProfiles[line.at( 2 ).get<wxString>()] = NormalizeSafeSpacing( line.at( 4 ).at( 1 ) );
1212 }
1213 else if( type == wxS( "RULE_SELECTOR" ) && line.size() > 3 && line.at( 1 ).is_array() && line.at( 1 ).size() > 1
1214 && line.at( 1 ).at( 0 ).is_string() && line.at( 1 ).at( 0 ).get<wxString>() == wxS( "POUR" )
1215 && line.at( 1 ).at( 1 ).is_string() && line.at( 3 ).is_object() && line.at( 3 ).contains( "1" )
1216 && line.at( 3 ).at( "1" ).is_string() )
1217 {
1218 pourSafeSpacingProfiles[line.at( 1 ).at( 1 ).get<wxString>()] = line.at( 3 ).at( "1" ).get<wxString>();
1219 }
1220 }
1221
1222
1223 for( const nlohmann::json& line : aLines )
1224 {
1225 if( line.size() == 0 )
1226 continue;
1227
1228 wxString type = line.at( 0 );
1229
1230 if( type == wxS( "LAYER" ) )
1231 {
1232 int layer = line.at( 1 );
1233 PCB_LAYER_ID klayer = LayerToKi( layer );
1234
1235 wxString layerType = line.at( 2 );
1236 wxString layerName = line.at( 3 );
1237 int layerFlag = line.at( 4 );
1238
1239 if( layerFlag != 0 )
1240 {
1241 LSET blayers = aBoard->GetEnabledLayers();
1242 blayers.set( klayer );
1243 aBoard->SetEnabledLayers( blayers );
1244 aBoard->SetLayerName( klayer, layerName );
1245 }
1246 }
1247 else if( type == wxS( "NET" ) )
1248 {
1249 wxString netname = line.at( 1 );
1250
1251 aBoard->FindOrAddNet( netname, aBoard->GetNetCount() + 1, ADD_MODE::APPEND );
1252 }
1253 else if( type == wxS( "RULE" ) )
1254 {
1255 wxString ruleType = line.at( 1 );
1256 wxString ruleName = line.at( 2 );
1257 int isDefault = line.at( 3 );
1258 nlohmann::json ruleData = line.at( 4 );
1259
1260 if( ruleType == wxS( "3" ) && isDefault ) // Track width
1261 {
1262 wxString units = ruleData.at( 0 );
1263
1264 if( ruleData.at( 1 ).is_number() )
1265 {
1266 // ["RULE","3","trackWidth",1,["mil",5,10,100]]
1267 double minVal = ruleData.at( 1 );
1268 // double optVal = ruleData.at( 2 );
1269 // double maxVal = ruleData.at( 3 );
1270
1271 bds.m_TrackMinWidth = ScaleSize( minVal );
1272 aBoard->m_LegacyDesignSettingsLoaded = true;
1273 }
1274 else
1275 {
1276 // ["RULE","3","trackWidth",1,["mil",{"1":[10,10,150]}]]
1277 nlohmann::json table = ruleData.at( 1 );
1278
1279 for( auto& [key, arr] : table.items() )
1280 {
1281 double minVal = arr.at( 0 );
1282 // double optVal = arr.at( 1 );
1283 // double maxVal = arr.at( 2 );
1284
1285 bds.m_TrackMinWidth = ScaleSize( minVal );
1286 aBoard->m_LegacyDesignSettingsLoaded = true;
1287 }
1288 }
1289 }
1290 else if( ruleType == wxS( "1" ) && isDefault )
1291 {
1292 wxString units = ruleData.at( 0 );
1293 nlohmann::json table = ruleData.at( 1 );
1294
1295 if( table.is_array() )
1296 {
1298 }
1299
1300 // EasyEDA Pro labels this array "mm", but its values are always mils. The
1301 // lower-triangular matrix starts with the track-to-track clearance, which maps
1302 // to KiCad's global minimum clearance; the remaining object-specific values
1303 // cannot be represented by that single board setting.
1304 const nlohmann::json& safeSpacing = m_safeSpacing;
1305
1306 if( safeSpacing.is_array() && !safeSpacing.empty() && safeSpacing.at( 0 ).is_array()
1307 && !safeSpacing.at( 0 ).empty() && safeSpacing.at( 0 ).at( 0 ).is_number() )
1308 {
1309 double trackClearance = safeSpacing.at( 0 ).at( 0 );
1310
1311 if( trackClearance > 0 )
1312 {
1313 int clearance = ScaleSize( trackClearance );
1316 aBoard->m_LegacyDesignSettingsLoaded = true;
1317 aBoard->m_LegacyNetclassesLoaded = true;
1318 }
1319 }
1320 double minEdgeClearance = 0;
1321
1322 if( safeSpacing.is_array() && safeSpacing.size() > 11 && safeSpacing.at( 11 ).is_array() )
1323 {
1324 for( const nlohmann::json& value : safeSpacing.at( 11 ) )
1325 {
1326 if( value.is_number() && value.get<double>() > 0
1327 && ( minEdgeClearance == 0 || value.get<double>() < minEdgeClearance ) )
1328 {
1329 minEdgeClearance = value;
1330 }
1331 }
1332 }
1333
1334 if( minEdgeClearance > 0 )
1335 {
1336 bds.m_CopperEdgeClearance = ScaleSize( minEdgeClearance );
1337 aBoard->m_LegacyDesignSettingsLoaded = true;
1338 }
1339 }
1340
1341 ruleLines[ruleType].push_back( line );
1342 }
1343 else if( type == wxS( "POURED" ) )
1344 {
1345 if( !line.at( 2 ).is_string() )
1346 continue; // Unknown type of POURED
1347
1348 EASYEDAPRO::POURED poured = line;
1349 boardPouredMap.emplace( poured.parentId, poured );
1350 }
1351 else if( type == wxS( "VIA" ) || type == wxS( "LINE" ) || type == wxS( "ARC" ) || type == wxS( "POLY" )
1352 || type == wxS( "FILL" ) || type == wxS( "POUR" ) )
1353 {
1354 wxString uuid = line.at( 1 );
1355
1356 // if( line.at( 2 ).is_number() )
1357 // int unk = line.at( 2 ).get<int>();
1358 // else if( line.at( 2 ).is_string() )
1359 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1360
1361 wxString netname = line.at( 3 );
1362
1363 if( type == wxS( "VIA" ) )
1364 {
1366 center.x = line.at( 5 );
1367 center.y = line.at( 6 );
1368
1369 double drill = line.at( 7 );
1370 double dia = line.at( 8 );
1371
1372 std::unique_ptr<PCB_VIA> via = std::make_unique<PCB_VIA>( aBoard );
1373
1374 via->SetPosition( ScalePos( center ) );
1375 via->SetPadstackMode( PADSTACK::MODE::NORMAL );
1376 via->SetDrill( ScaleSize( drill ) );
1377 via->SetWidth( PADSTACK::ALL_LAYERS, ScaleSize( dia ) );
1378
1379 via->SetNet( getNet( aBoard, netname ) );
1380
1381 aBoard->Add( via.release(), ADD_MODE::APPEND );
1382 }
1383 else if( type == wxS( "LINE" ) )
1384 {
1385 int layer = line.at( 4 ).get<int>();
1386 PCB_LAYER_ID klayer = LayerToKi( layer );
1387
1388 VECTOR2D start;
1389 start.x = line.at( 5 );
1390 start.y = line.at( 6 );
1391
1392 VECTOR2D end;
1393 end.x = line.at( 7 );
1394 end.y = line.at( 8 );
1395
1396 double width = line.at( 9 );
1397
1398 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( aBoard );
1399
1400 track->SetLayer( klayer );
1401 track->SetStart( ScalePos( start ) );
1402 track->SetEnd( ScalePos( end ) );
1403 track->SetWidth( ScaleSize( width ) );
1404
1405 track->SetNet( getNet( aBoard, netname ) );
1406
1407 aBoard->Add( track.release(), ADD_MODE::APPEND );
1408 }
1409 else if( type == wxS( "ARC" ) )
1410 {
1411 int layer = line.at( 4 ).get<int>();
1412 PCB_LAYER_ID klayer = LayerToKi( layer );
1413
1414 VECTOR2D start;
1415 start.x = line.at( 5 );
1416 start.y = line.at( 6 );
1417
1418 VECTOR2D end;
1419 end.x = line.at( 7 );
1420 end.y = line.at( 8 );
1421
1422 double angle = line.at( 9 );
1423 double width = line.at( 10 );
1424
1425 VECTOR2D delta = end - start;
1426 VECTOR2D mid = ( start + delta / 2 );
1427
1428 double ha = angle / 2;
1429 double hd = delta.EuclideanNorm() / 2;
1430 double cdist = hd / tan( DEG2RAD( ha ) );
1431 VECTOR2D center = mid + delta.Perpendicular().Resize( cdist );
1432
1433 SHAPE_ARC sarc;
1434 sarc.ConstructFromStartEndCenter( ScalePos( start ), ScalePos( end ), ScalePos( center ), angle >= 0,
1435 width );
1436
1437 std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( aBoard, &sarc );
1438 arc->SetWidth( ScaleSize( width ) );
1439
1440 arc->SetLayer( klayer );
1441 arc->SetNet( getNet( aBoard, netname ) );
1442
1443 aBoard->Add( arc.release(), ADD_MODE::APPEND );
1444 }
1445 else if( type == wxS( "FILL" ) )
1446 {
1447 int layer = line.at( 4 ).get<int>();
1448 PCB_LAYER_ID klayer = LayerToKi( layer );
1449
1450 nlohmann::json polyDataList = line.at( 7 );
1451
1452 if( !polyDataList.at( 0 ).is_array() )
1453 polyDataList = nlohmann::json::array( { polyDataList } );
1454
1455 std::vector<SHAPE_LINE_CHAIN> contours;
1456 for( nlohmann::json& polyData : polyDataList )
1457 {
1458 SHAPE_LINE_CHAIN contour = ParseContour( polyData, true );
1459 contour.SetClosed( true );
1460
1461 contours.push_back( contour );
1462 }
1463
1464 SHAPE_POLY_SET zoneFillPoly;
1465
1466 for( SHAPE_LINE_CHAIN& contour : contours )
1467 zoneFillPoly.AddOutline( contour );
1468
1469 zoneFillPoly.RebuildHolesFromContours();
1470 zoneFillPoly.ClearArcs();
1471 zoneFillPoly.Fracture();
1472
1473 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1474
1475 zone->SetNet( getNet( aBoard, netname ) );
1476 zone->SetLayer( klayer );
1477 zone->Outline()->Append( SHAPE_RECT( zoneFillPoly.BBox() ).Outline() );
1478 zone->SetFilledPolysList( klayer, zoneFillPoly );
1479 zone->SetAssignedPriority( 500 );
1480 zone->SetIsFilled( true );
1481 zone->SetNeedRefill( false );
1482
1483 zone->SetLocalClearance( zoneClearance() );
1484 zone->SetMinThickness( zoneMinThickness );
1485
1486 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1487 }
1488 else if( type == wxS( "POLY" ) )
1489 {
1490 int layer = line.at( 4 );
1491 PCB_LAYER_ID klayer = LayerToKi( layer );
1492
1493 double thickness = line.at( 5 );
1494 nlohmann::json polyData = line.at( 6 );
1495
1496 std::vector<std::unique_ptr<PCB_SHAPE>> results = ParsePoly( aBoard, polyData, false, false );
1497
1498 for( std::unique_ptr<PCB_SHAPE>& shape : results )
1499 {
1500 shape->SetLayer( klayer );
1501 shape->SetWidth( ScaleSize( thickness ) );
1502
1503 aBoard->Add( shape.release(), ADD_MODE::APPEND );
1504 }
1505 }
1506 else if( type == wxS( "POUR" ) )
1507 {
1508 int layer = line.at( 4 ).get<int>();
1509 PCB_LAYER_ID klayer = LayerToKi( layer );
1510
1511 wxString pourname = line.at( 6 );
1512 int fillOrder = line.at( 7 ).get<int>();
1513 nlohmann::json polyDataList = line.at( 8 );
1514
1515 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1516
1517 zone->SetNet( getNet( aBoard, netname ) );
1518 zone->SetLayer( klayer );
1519 zone->SetAssignedPriority( 500 - fillOrder );
1520 int localClearance = zoneClearance();
1521
1522 if( auto selector = pourSafeSpacingProfiles.find( uuid ); selector != pourSafeSpacingProfiles.end() )
1523 {
1524 auto profile = safeSpacingProfiles.find( selector->second );
1525
1526 if( profile != safeSpacingProfiles.end() && profile->second.size() > 7
1527 && profile->second.at( 7 ).is_array() && !profile->second.at( 7 ).empty()
1528 && profile->second.at( 7 ).at( 0 ).is_number() )
1529 {
1530 const int profileClearance = ScaleSize( profile->second.at( 7 ).at( 0 ).get<double>() );
1531
1532 if( profileClearance > 0 )
1533 localClearance = profileClearance;
1534 }
1535 }
1536
1537 zone->SetLocalClearance( localClearance );
1538 zone->SetMinThickness( zoneMinThickness );
1539
1540 for( nlohmann::json& polyData : polyDataList )
1541 {
1542 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1543 contour.SetClosed( true );
1544
1545 zone->Outline()->Append( contour );
1546 }
1547
1548 wxASSERT( zone->Outline()->OutlineCount() == 1 );
1549
1550 poursToFill.emplace( uuid, zone.get() );
1551
1552 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1553 }
1554 }
1555 else if( type == wxS( "TEARDROP" ) )
1556 {
1557 wxString uuid = line.at( 1 );
1558 wxString netname = line.at( 2 );
1559 int layer = line.at( 3 ).get<int>();
1560 PCB_LAYER_ID klayer = LayerToKi( layer );
1561
1562 nlohmann::json polyData = line.at( 4 );
1563
1564 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1565 contour.SetClosed( true );
1566
1567 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1568
1569 zone->SetNet( getNet( aBoard, netname ) );
1570 zone->SetLayer( klayer );
1571 zone->Outline()->Append( contour );
1572 SHAPE_POLY_SET teardropFill( contour );
1573 teardropFill.ClearArcs();
1574 zone->SetFilledPolysList( klayer, teardropFill );
1575 zone->SetNeedRefill( false );
1576 zone->SetIsFilled( true );
1577
1578 zone->SetAssignedPriority( 600 );
1579 zone->SetLocalClearance( 0 );
1580 zone->SetMinThickness( 0 );
1581 zone->SetTeardropAreaType( TEARDROP_TYPE::TD_VIAPAD );
1582
1583 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1584 }
1585 else if( type == wxS( "REGION" ) )
1586 {
1587 wxString uuid = line.at( 1 );
1588
1589 // if( line.at( 2 ).is_number() )
1590 // int unk = line.at( 2 ).get<int>();
1591 // else if( line.at( 2 ).is_string() )
1592 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1593
1594 int layer = line.at( 3 ).get<int>();
1595 PCB_LAYER_ID klayer = LayerToKi( layer );
1596
1597 std::set<int> flags = line.at( 5 );
1598 nlohmann::json polyDataList = line.at( 6 );
1599
1600 for( nlohmann::json& polyData : polyDataList )
1601 {
1602 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1603 contour.SetClosed( true );
1604
1605 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1606
1607 zone->SetIsRuleArea( true );
1608 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1609 zone->SetDoNotAllowZoneFills( !!flags.count( 7 ) || !!flags.count( 6 ) || !!flags.count( 8 ) );
1610 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1611 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1612 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1613
1614 zone->SetLayer( klayer );
1615 zone->Outline()->Append( contour );
1616
1617 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1618 }
1619 }
1620 else if( type == wxS( "PAD" ) )
1621 {
1622 wxString netname = line.at( 3 );
1623
1624 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aBoard );
1625 std::unique_ptr<PAD> pad = createPAD( footprint.get(), line );
1626
1627 pad->SetNet( getNet( aBoard, netname ) );
1628
1629 VECTOR2I pos = pad->GetPosition();
1630 EDA_ANGLE orient = pad->GetOrientation();
1631
1632 pad->SetPosition( VECTOR2I() );
1633 pad->SetOrientation( ANGLE_0 );
1634
1635 footprint->Add( pad.release(), ADD_MODE::APPEND );
1636 footprint->SetPosition( pos );
1637 footprint->SetOrientation( orient );
1638
1639 wxString fpName = wxS( "Pad_" ) + line.at( 1 ).get<wxString>();
1640 LIB_ID fpID = EASYEDAPRO::ToKiCadLibID( wxEmptyString, fpName );
1641
1642 footprint->SetFPID( fpID );
1643 footprint->Reference().SetVisible( true );
1644 footprint->Value().SetVisible( true );
1645 footprint->AutoPositionFields();
1646
1647 aBoard->Add( footprint.release(), ADD_MODE::APPEND );
1648 }
1649 else if( type == wxS( "IMAGE" ) )
1650 {
1651 wxString uuid = line.at( 1 );
1652
1653 // if( line.at( 2 ).is_number() )
1654 // int unk = line.at( 2 ).get<int>();
1655 // else if( line.at( 2 ).is_string() )
1656 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1657
1658 int layer = line.at( 3 ).get<int>();
1659 PCB_LAYER_ID klayer = LayerToKi( layer );
1660
1661 VECTOR2D start( line.at( 4 ), line.at( 5 ) );
1662 VECTOR2D size( line.at( 6 ), line.at( 7 ) );
1663
1664 double angle = line.at( 8 ); // from top left corner
1665 int mirror = line.at( 9 );
1666 nlohmann::json polyDataList = line.at( 10 );
1667
1668 BOX2I bbox;
1669 std::vector<SHAPE_LINE_CHAIN> contours;
1670 for( nlohmann::json& polyData : polyDataList )
1671 {
1672 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1673 contour.SetClosed( true );
1674
1675 contours.push_back( contour );
1676
1677 bbox.Merge( contour.BBox() );
1678 }
1679
1680 VECTOR2D scale( ScaleSize( size.x ) / bbox.GetSize().x, ScaleSize( size.y ) / bbox.GetSize().y );
1681
1682 SHAPE_POLY_SET polySet;
1683
1684 for( SHAPE_LINE_CHAIN& contour : contours )
1685 {
1686 for( int i = 0; i < contour.PointCount(); i++ )
1687 {
1688 VECTOR2I pt = contour.CPoint( i );
1689 contour.SetPoint( i, VECTOR2I( pt.x * scale.x, pt.y * scale.y ) );
1690 }
1691
1692 polySet.AddOutline( contour );
1693 }
1694
1695 polySet.RebuildHolesFromContours();
1696
1697 std::unique_ptr<PCB_GROUP> group;
1698
1699 if( polySet.OutlineCount() > 1 )
1700 group = std::make_unique<PCB_GROUP>( aBoard );
1701
1702 BOX2I polyBBox = polySet.BBox();
1703
1704 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
1705 {
1706 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aBoard, SHAPE_T::POLY );
1707
1708 shape->SetFilled( true );
1709 shape->SetPolyShape( poly );
1710 shape->SetLayer( klayer );
1711 shape->SetWidth( 0 );
1712
1713 shape->Move( ScalePos( start ) - polyBBox.GetOrigin() );
1714 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
1715
1716 if( IsBackLayer( klayer ) ^ !!mirror )
1717 {
1718 FLIP_DIRECTION flipDirection =
1720 shape->Mirror( ScalePos( start ), flipDirection );
1721 }
1722
1723 if( group )
1724 group->AddItem( shape.get() );
1725
1726 aBoard->Add( shape.release(), ADD_MODE::APPEND );
1727 }
1728
1729 if( group )
1730 aBoard->Add( group.release(), ADD_MODE::APPEND );
1731 }
1732 else if( type == wxS( "OBJ" ) )
1733 {
1734 VECTOR2D start, size;
1735 wxString mimeType, base64Data;
1736 double angle = 0;
1737 int flipped = 0;
1738
1739 if( !line.at( 3 ).is_number() )
1740 continue;
1741
1742 int layer = line.at( 3 ).get<int>();
1743 PCB_LAYER_ID klayer = LayerToKi( layer );
1744
1745 start = VECTOR2D( line.at( 5 ), line.at( 6 ) );
1746 size = VECTOR2D( line.at( 7 ), line.at( 8 ) );
1747 angle = line.at( 9 );
1748 flipped = line.at( 10 );
1749
1750 wxString imageUrl = line.at( 11 );
1751
1752 if( imageUrl.BeforeFirst( ':' ) == wxS( "blob" ) )
1753 {
1754 wxString objectId = imageUrl.AfterLast( ':' );
1755
1756 if( auto blob = get_opt( aBlobMap, objectId ) )
1757 {
1758 wxString blobUrl = blob->url;
1759
1760 if( blobUrl.BeforeFirst( ':' ) == wxS( "data" ) )
1761 {
1762 wxArrayString paramsArr = wxSplit( blobUrl.AfterFirst( ':' ).BeforeFirst( ',' ), ';', '\0' );
1763
1764 base64Data = blobUrl.AfterFirst( ',' );
1765
1766 if( paramsArr.size() > 0 )
1767 mimeType = paramsArr[0];
1768 }
1769 }
1770 }
1771
1772 VECTOR2D kstart = ScalePos( start );
1773 VECTOR2D ksize = ScaleSize( size );
1774
1775 if( mimeType.empty() || base64Data.empty() )
1776 continue;
1777
1778 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1779
1780 if( mimeType == wxS( "image/svg+xml" ) )
1781 {
1782 // Not yet supported by EasyEDA
1783 }
1784 else
1785 {
1786 VECTOR2D kcenter = kstart + ksize / 2;
1787
1788 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
1789 std::make_unique<PCB_REFERENCE_IMAGE>( aBoard, kcenter, klayer );
1790 REFERENCE_IMAGE& refImage = bitmap->GetReferenceImage();
1791
1792 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags() & ~wxImage::Load_Verbose );
1793
1794 if( refImage.ReadImageFile( buf ) )
1795 {
1796 double scaleFactor = ScaleSize( size.x ) / refImage.GetSize().x;
1797 refImage.SetImageScale( scaleFactor );
1798
1799 // TODO: support non-90-deg angles
1800 bitmap->Rotate( kstart, EDA_ANGLE( angle, DEGREES_T ) );
1801
1802 if( flipped )
1803 {
1804 int x = bitmap->GetPosition().x;
1805 MIRROR( x, KiROUND( kstart.x ) );
1806 bitmap->SetX( x );
1807
1809 }
1810
1811 aBoard->Add( bitmap.release(), ADD_MODE::APPEND );
1812 }
1813 }
1814 }
1815 else if( type == wxS( "STRING" ) )
1816 {
1817 wxString uuid = line.at( 1 );
1818
1819 // if( line.at( 2 ).is_number() )
1820 // int unk = line.at( 2 ).get<int>();
1821 // else if( line.at( 2 ).is_string() )
1822 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1823
1824 int layer = line.at( 3 ).get<int>();
1825 PCB_LAYER_ID klayer = LayerToKi( layer );
1826
1827 VECTOR2D location( line.at( 4 ), line.at( 5 ) );
1828 wxString string = line.at( 6 );
1829 wxString font = line.at( 7 );
1830
1831 double height = line.at( 8 );
1832 double strokew = line.at( 9 );
1833
1834 int align = line.at( 12 );
1835 double angle = line.at( 13 );
1836 int inverted = line.at( 14 );
1837 int mirror = line.at( 16 );
1838
1839 PCB_TEXT* text = new PCB_TEXT( aBoard );
1840
1841 text->SetText( string );
1842 text->SetLayer( klayer );
1843 text->SetPosition( ScalePos( location ) );
1844 text->SetIsKnockout( inverted );
1845 text->SetTextThickness( ScaleSize( strokew ) );
1846 text->SetTextSize( VECTOR2D( ScaleSize( height * 0.6 ), ScaleSize( height * 0.7 ) ) );
1847
1848 if( font != wxS( "default" ) )
1849 {
1850 text->SetFont( KIFONT::FONT::GetFont( font ) );
1851 //text->SetupRenderCache( text->GetShownText(), text->GetFont(), EDA_ANGLE( angle, DEGREES_T ) );
1852
1853 //text->AddRenderCacheGlyph();
1854 // TODO: import geometry cache
1855 }
1856
1857 AlignText( text, align );
1858
1859 if( IsBackLayer( klayer ) ^ !!mirror )
1860 {
1861 text->SetMirrored( true );
1862 text->SetTextAngleDegrees( -angle );
1863 }
1864 else
1865 {
1866 text->SetTextAngleDegrees( angle );
1867 }
1868
1869 aBoard->Add( text, ADD_MODE::APPEND );
1870 }
1871 else if( type == wxS( "COMPONENT" ) )
1872 {
1873 wxString compId = line.at( 1 );
1874 componentLines[compId].push_back( line );
1875 }
1876 else if( type == wxS( "ATTR" ) )
1877 {
1878 wxString compId = line.at( 3 );
1879 componentLines[compId].push_back( line );
1880 }
1881 else if( type == wxS( "PAD_NET" ) )
1882 {
1883 wxString compId = line.at( 1 );
1884 componentLines[compId].push_back( line );
1885 }
1886 }
1887
1888 for( auto const& [compId, lines] : componentLines )
1889 {
1890 wxString deviceId;
1891 wxString fpIdOverride;
1892 wxString fpDesignator;
1893 std::map<wxString, wxString> localCompAttribs;
1894
1895 for( auto& line : lines )
1896 {
1897 if( line.size() == 0 )
1898 continue;
1899
1900 wxString type = line.at( 0 );
1901
1902 if( type == wxS( "COMPONENT" ) )
1903 {
1904 localCompAttribs = line.at( 7 );
1905 }
1906 else if( type == wxS( "ATTR" ) )
1907 {
1908 EASYEDAPRO::PCB_ATTR attr = line;
1909
1910 if( attr.key == wxS( "Device" ) )
1911 deviceId = attr.value;
1912
1913 else if( attr.key == wxS( "Footprint" ) )
1914 fpIdOverride = attr.value;
1915
1916 else if( attr.key == wxS( "Designator" ) )
1917 fpDesignator = attr.value;
1918 }
1919 }
1920
1921 if( deviceId.empty() )
1922 continue;
1923
1924 nlohmann::json compAttrs = aProject.at( "devices" ).at( deviceId ).at( "attributes" );
1925
1926 wxString fpId;
1927
1928 if( !fpIdOverride.IsEmpty() )
1929 fpId = fpIdOverride;
1930 else
1931 fpId = compAttrs.at( "Footprint" ).get<wxString>();
1932
1933 auto it = aFootprintMap.find( fpId );
1934 if( it == aFootprintMap.end() )
1935 {
1936 wxLogTrace( traceEasyEdaIo, "Footprint of '%s' with uuid '%s' not found.", fpDesignator, fpId );
1937 continue;
1938 }
1939
1940 std::unique_ptr<FOOTPRINT>& footprintOrig = it->second;
1941 std::unique_ptr<FOOTPRINT> footprint( static_cast<FOOTPRINT*>( footprintOrig->Duplicate( false ) ) );
1942
1943 wxString modelUuid, modelTitle, modelTransform;
1944
1945 if( auto val = get_opt( localCompAttribs, "3D Model" ) )
1946 modelUuid = *val;
1947 else
1948 modelUuid = compAttrs.value<wxString>( "3D Model", "" );
1949
1950 if( auto val = get_opt( localCompAttribs, "3D Model Title" ) )
1951 modelTitle = val->Trim();
1952 else
1953 modelTitle = compAttrs.value<wxString>( "3D Model Title", modelUuid ).Trim();
1954
1955 if( auto val = get_opt( localCompAttribs, "3D Model Transform" ) )
1956 modelTransform = *val;
1957 else
1958 modelTransform = compAttrs.value<wxString>( "3D Model Transform", "" );
1959
1960 FillFootprintModelInfo( footprint.get(), modelUuid, modelTitle, modelTransform );
1961
1962 footprint->SetParent( aBoard );
1963
1964 for( auto& line : lines )
1965 {
1966 if( line.size() == 0 )
1967 continue;
1968
1969 wxString type = line.at( 0 );
1970
1971 if( type == wxS( "COMPONENT" ) )
1972 {
1973 int layer = line.at( 3 );
1974 PCB_LAYER_ID klayer = LayerToKi( layer );
1975
1976 VECTOR2D center( line.at( 4 ), line.at( 5 ) );
1977
1978 double orient = line.at( 6 );
1979 //std::map<wxString, wxString> props = line.at( 7 );
1980
1981 if( klayer == B_Cu )
1982 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::TOP_BOTTOM );
1983
1984 footprint->SetOrientationDegrees( orient );
1985 footprint->SetPosition( ScalePos( center ) );
1986 }
1987 else if( type == wxS( "ATTR" ) )
1988 {
1989 EASYEDAPRO::PCB_ATTR attr = line;
1990
1991 PCB_LAYER_ID klayer = LayerToKi( attr.layer );
1992
1993 PCB_FIELD* field = nullptr;
1994
1995 if( attr.key == wxS( "Designator" ) )
1996 {
1997 if( attr.key == wxS( "Designator" ) )
1998 {
1999 field = footprint->GetField( FIELD_T::REFERENCE );
2000 }
2001 else
2002 {
2003 field = new PCB_FIELD( footprint.get(), FIELD_T::USER, attr.key );
2004 footprint->Add( field, ADD_MODE::APPEND );
2005 }
2006
2007 if( attr.fontName != wxS( "default" ) )
2008 field->SetFont( KIFONT::FONT::GetFont( attr.fontName ) );
2009
2010 if( attr.valVisible && attr.keyVisible )
2011 {
2012 field->SetText( attr.key + ':' + attr.value );
2013 }
2014 else if( attr.keyVisible )
2015 {
2016 field->SetText( attr.key );
2017 }
2018 else
2019 {
2020 field->SetText( attr.value );
2021 }
2022
2023 field->SetVisible( attr.keyVisible || attr.valVisible );
2024 field->SetLayer( klayer );
2025 field->SetPosition( ScalePos( attr.position ) );
2026 field->SetTextAngleDegrees( footprint->IsFlipped() ? -attr.rotation : attr.rotation );
2027 field->SetIsKnockout( attr.inverted );
2028 field->SetTextThickness( ScaleSize( attr.strokeWidth ) );
2029 field->SetTextSize( VECTOR2D( ScaleSize( attr.height * 0.55 ), ScaleSize( attr.height * 0.6 ) ) );
2030
2031 AlignText( field, attr.textOrigin );
2032 }
2033 }
2034 else if( type == wxS( "PAD_NET" ) )
2035 {
2036 wxString padNumber = line.at( 2 );
2037 wxString padNet = line.at( 3 );
2038
2039 for( PAD* pad : footprint->Pads() )
2040 {
2041 if( pad->GetNumber() == padNumber )
2042 pad->SetNet( getNet( aBoard, padNet ) );
2043 }
2044 }
2045 }
2046
2047 aBoard->Add( footprint.release(), ADD_MODE::APPEND );
2048 }
2049
2050 // Set zone fills
2052 {
2053 for( auto& [uuid, zone] : poursToFill )
2054 {
2055 SHAPE_POLY_SET fillPolySet;
2056 SHAPE_POLY_SET thermalSpokes;
2057
2058 auto range = boardPouredMap.equal_range( uuid );
2059 for( auto& it = range.first; it != range.second; ++it )
2060 {
2061 const EASYEDAPRO::POURED& poured = it->second;
2062
2063 SHAPE_POLY_SET thisPoly;
2064
2065 for( int dataId = 0; dataId < (int) poured.polyData.size(); dataId++ )
2066 {
2067 const nlohmann::json& fillData = poured.polyData[dataId];
2068 const double ptScale = 10;
2069
2070 SHAPE_LINE_CHAIN contour = ParseContour( fillData, false, ARC_HIGH_DEF / ptScale );
2071
2072 // Scale the fill
2073 for( int i = 0; i < contour.PointCount(); i++ )
2074 contour.SetPoint( i, contour.GetPoint( i ) * ptScale );
2075
2076 if( poured.isPoly )
2077 {
2078 contour.SetClosed( true );
2079
2080 // The contour can be self-intersecting
2081 SHAPE_POLY_SET simple( contour );
2082 simple.Simplify();
2083
2084 if( dataId == 0 )
2085 {
2086 thisPoly.Append( simple );
2087 }
2088 else
2089 {
2090 thisPoly.BooleanSubtract( simple );
2091 }
2092 }
2093 else
2094 {
2095 const int thermalWidth = pcbIUScale.mmToIU( 0.2 ); // Generic
2096
2097 for( int segId = 0; segId < contour.SegmentCount(); segId++ )
2098 {
2099 const SEG& seg = contour.CSegment( segId );
2100
2101 TransformOvalToPolygon( thermalSpokes, seg.A, seg.B, thermalWidth, ARC_HIGH_DEF,
2102 ERROR_INSIDE );
2103 }
2104 }
2105 }
2106
2107 fillPolySet.Append( thisPoly );
2108 }
2109
2110 if( !fillPolySet.IsEmpty() )
2111 {
2112 fillPolySet.Simplify();
2113
2114 const int strokeWidth = pcbIUScale.MilsToIU( 8 ); // Seems to be 8 mils
2115
2116 fillPolySet.Inflate( strokeWidth / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_HIGH_DEF, false );
2117
2118 fillPolySet.BooleanAdd( thermalSpokes );
2119
2120 fillPolySet.Fracture();
2121
2122 zone->SetFilledPolysList( zone->GetFirstLayer(), fillPolySet );
2123 zone->SetNeedRefill( false );
2124 zone->SetIsFilled( true );
2125 }
2126 }
2127 }
2128
2129 // Heal board outlines
2130 std::vector<PCB_SHAPE*> shapes;
2131
2132 for( BOARD_ITEM* item : aBoard->Drawings() )
2133 {
2134 if( !item->IsOnLayer( Edge_Cuts ) )
2135 continue;
2136
2137 if( item->Type() == PCB_SHAPE_T )
2138 shapes.push_back( static_cast<PCB_SHAPE*>( item ) );
2139 }
2140
2142
2143 // Center the board
2144 BOX2I outlineBbox = aBoard->ComputeBoundingBox( true, true );
2145 PAGE_INFO pageInfo = aBoard->GetPageSettings();
2146
2147 VECTOR2D pageCenter( pcbIUScale.MilsToIU( pageInfo.GetWidthMils() / 2 ),
2148 pcbIUScale.MilsToIU( pageInfo.GetHeightMils() / 2 ) );
2149
2150 VECTOR2D offset = pageCenter - outlineBbox.GetCenter();
2151
2152
2153 int alignGrid = pcbIUScale.mmToIU( 10 );
2154 offset.x = KiROUND( offset.x / alignGrid ) * alignGrid;
2155 offset.y = KiROUND( offset.y / alignGrid ) * alignGrid;
2156
2157 aBoard->Move( offset );
2158 bds.SetAuxOrigin( offset );
2159}
@ ERROR_INSIDE
static std::optional< VECTOR2D > normalized(const VECTOR2D &aVec)
constexpr int ARC_HIGH_DEF
Definition base_units.h:144
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
BASE_SET & set(size_t pos)
Definition base_set.h:126
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
void Mirror(FLIP_DIRECTION aFlipDirection)
Mirror image vertically (i.e.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
void SetAuxOrigin(const VECTOR2I &aOrigin)
ZONE_SETTINGS & GetDefaultZoneSettings()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
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 SetIsKnockout(bool aKnockout)
Definition board_item.h:438
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
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
Definition board.h:565
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
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition board.cpp:2833
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition board.cpp:978
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition board.cpp:844
bool m_LegacyNetclassesLoaded
True if netclasses were loaded from the file.
Definition board.h:569
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1202
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
unsigned GetNetCount() const
Definition board.h:1276
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1222
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
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 BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr const Vec GetCenter() const
Definition box2.h:233
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr const SizeVec & GetSize() const
Definition box2.h:209
EDA_ANGLE Normalize90()
Definition eda_angle.h:260
double AsDegrees() const
Definition eda_angle.h:115
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
void SetTextAngleDegrees(double aOrientation)
Definition eda_text.h:181
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
void SetFont(KIFONT::FONT *aFont)
Definition eda_text.cpp:472
const BOX2I GetLayerBoundingBox(const LSET &aLayers) const
Return the bounding box of the footprint on a given set of layers.
void MoveAnchorPosition(const VECTOR2I &aMoveVector)
Move the reference point of the footprint.
PCB_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this footprint.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
std::vector< FP_3DMODEL > & Models()
Definition footprint.h:375
DRAWINGS & GraphicalItems()
Definition footprint.h:358
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
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
void SetClearance(int aClearance)
Definition netclass.h:144
Handle the data for a net.
Definition netinfo.h:50
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
@ 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
Definition pad.h:61
void SetAttribute(PAD_ATTRIB aAttribute)
Definition pad.cpp:1563
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:620
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
Definition pad.h:196
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition pad.cpp:641
VECTOR2I GetDrillSize() const
Definition pad.h:320
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:297
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.cpp:264
PAD_DRILL_SHAPE GetDrillShape() const
Definition pad.h:438
static LSET SMDMask()
layer set for a SMD pad on Front layer
Definition pad.cpp:627
void SetLayerSet(const LSET &aLayers) override
Definition pad.cpp:1930
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
double GetHeightMils() const
Definition page_info.h:142
double GetWidthMils() const
Definition page_info.h:137
static nlohmann::json NormalizeSafeSpacing(const nlohmann::json &aTable)
Map legacy eight- and ten-row safe-spacing matrices to the v3 category layout.
static void SizeHoleOnlyPad(PAD &aPad, bool aPlated)
A hole with no copper around it takes the drill size, and stays unplated if the source says it is.
static VECTOR2< T > ScalePos(VECTOR2< T > aValue)
PCB_IO_EASYEDAPRO_PARSER(BOARD *aBoard, PROGRESS_REPORTER *aProgressReporter)
std::unique_ptr< FOOTPRINT > ParseFootprint(const nlohmann::json &aProject, const wxString &aFpUuid, const std::vector< nlohmann::json > &aLines)
std::vector< std::unique_ptr< PCB_SHAPE > > ParsePoly(BOARD_ITEM_CONTAINER *aContainer, nlohmann::json polyData, bool aClosed, bool aInFill) const
SHAPE_LINE_CHAIN ParseContour(nlohmann::json polyData, bool aInFill, int aMaxError=SHAPE_ARC::DefaultAccuracyForPCB()) const
NETINFO_ITEM * getNet(BOARD *aBoard, const wxString &aNetName)
void FillFootprintModelInfo(FOOTPRINT *footprint, const wxString &modelUuid, const wxString &modelTitle, const wxString &modelTransform) const
void ParseBoard(BOARD *aBoard, const nlohmann::json &aProject, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap, const std::multimap< wxString, EASYEDAPRO::POURED > &aPouredMap, const std::vector< nlohmann::json > &aLines, const wxString &aFpLibName)
std::unique_ptr< PAD > createPAD(FOOTPRINT *aFootprint, const nlohmann::json &line)
PCB_LAYER_ID LayerToKi(int aLayer)
static double Convert(wxString aValue)
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
Definition pcb_text.cpp:514
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
Definition pcb_text.cpp:486
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_text.h:103
A progress reporter interface for use in multi-threaded environments.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
BITMAP_BASE & MutableImage() const
Only use this if you really need to modify the underlying image.
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
VECTOR2I GetSize() const
void SetImageScale(double aScale)
Set the image "zoom" value.
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
SHAPE_ARC & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, const EDA_ANGLE &aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual const VECTOR2I GetPoint(int aIndex) const override
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
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)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
void RebuildHolesFromContours()
Extract all contours from this polygon set, then recreate polygons with holes.
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...
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const std::vector< POLYGON > & CPolygons() const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
const SHAPE_LINE_CHAIN Outline() const
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ ROUND_ALL_CORNERS
All angles are rounded.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
@ DEGREES_T
Definition eda_angle.h:30
@ 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,...)
const wxChar *const traceEasyEdaIo
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition layer_ids.h:870
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
@ User_6
Definition layer_ids.h:125
@ User_7
Definition layer_ids.h:126
@ 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
@ 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_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
wxString get_def(const std::map< wxString, wxString > &aMap, const char *aKey, const char *aDefval="")
Definition map_helpers.h:60
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
Definition map_helpers.h:30
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:44
FLIP_DIRECTION
Definition mirror.h:26
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:27
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:28
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
static const bool IMPORT_POURED
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ 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
@ ROUNDRECT
Definition padstack.h:58
@ RECTANGLE
Definition padstack.h:55
Class to handle a set of BOARD_ITEMs.
static const wxString MODEL_SIZE_KEY
static const int SHAPE_JOIN_DISTANCE
static void AlignText(EDA_TEXT *text, int align)
static const wxString QUERY_MODEL_UUID_KEY
static bool addSegment(VRML_LAYER &model, IDF_SEGMENT *seg, int icont, int iseg)
const int scale
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_FILENAME
nlohmann::json polyData
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
const std::string table
static EDA_ORIENTATION orientation(double d)
static EDA_ANGLE deg(double d)
KIBIS_MODEL * model
VECTOR2I center
const SHAPE_LINE_CHAIN chain
int radius
VECTOR2I end
int clearance
VECTOR2I location
static double sweep(float aStart, float aEnd)
wxString result
Test unit parsing edge cases and error handling.
int delta
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
#define M_PI
wxLogTrace helper definitions.
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
double DEG2RAD(double deg)
Definition trigo.h:178
@ 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