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 (C) 2023 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
27
28#include <memory>
29
30#include <nlohmann/json.hpp>
32#include <core/map_helpers.h>
33#include <string_utils.h>
34
35#include <wx/wfstream.h>
36#include <wx/stdstream.h>
37#include <wx/log.h>
38#include <glm/glm.hpp>
39
40#include <progress_reporter.h>
41#include <footprint.h>
42#include <board.h>
44#include <bezier_curves.h>
45#include <pcb_group.h>
46#include <pcb_track.h>
47#include <pcb_shape.h>
48#include <pcb_text.h>
49#include <font/font.h>
50#include <geometry/shape_arc.h>
53#include <geometry/shape_rect.h>
55#include <zone.h>
56#include <pad.h>
58#include <project.h>
59#include <fix_board_shape.h>
60#include <pcb_reference_image.h>
61#include <core/mirror.h>
62
63
64static const wxString QUERY_MODEL_UUID_KEY = wxS( "JLC_3DModel_Q" );
65static const wxString MODEL_SIZE_KEY = wxS( "JLC_3D_Size" );
66
67static const int SHAPE_JOIN_DISTANCE = pcbIUScale.mmToIU( 1.5 );
68
69
70double PCB_IO_EASYEDAPRO_PARSER::Convert( wxString aValue )
71{
72 double value = 0;
73
74 if( !aValue.ToCDouble( &value ) )
75 THROW_IO_ERROR( wxString::Format( _( "Failed to parse value: '%s'" ), aValue ) );
76
77 return value;
78}
79
80
82{
83 m_board = aBoard;
84}
85
86
88{
89}
90
91
93{
94 switch( aLayer )
95 {
96 case 1: return F_Cu;
97 case 2: return B_Cu;
98 case 3: return F_SilkS;
99 case 4: return B_SilkS;
100 case 5: return F_Mask;
101 case 6: return B_Mask;
102 case 7: return F_Paste;
103 case 8: return B_Paste;
104 case 9: return F_Fab;
105 case 10: return B_Fab;
106 case 11: return Edge_Cuts;
107 case 12: return Edge_Cuts; // Multi
108 case 13: return Dwgs_User;
109 case 14: return Eco2_User;
110
111 case 15: return In1_Cu;
112 case 16: return In2_Cu;
113 case 17: return In3_Cu;
114 case 18: return In4_Cu;
115 case 19: return In5_Cu;
116 case 20: return In6_Cu;
117 case 21: return In7_Cu;
118 case 22: return In8_Cu;
119 case 23: return In9_Cu;
120 case 24: return In10_Cu;
121 case 25: return In11_Cu;
122 case 26: return In12_Cu;
123 case 27: return In13_Cu;
124 case 28: return In14_Cu;
125 case 29: return In15_Cu;
126 case 30: return In16_Cu;
127 case 31: return In17_Cu;
128 case 32: return In18_Cu;
129 case 33: return In19_Cu;
130 case 34: return In20_Cu;
131 case 35: return In21_Cu;
132 case 36: return In22_Cu;
133 case 37: return In23_Cu;
134 case 38: return In24_Cu;
135 case 39: return In25_Cu;
136 case 40: return In26_Cu;
137 case 41: return In27_Cu;
138 case 42: return In28_Cu;
139 case 43: return In29_Cu;
140 case 44: return In30_Cu;
141
142 case 48: return User_2; // Component shape layer
143 case 49: return User_3; // Component marking
144
145 case 53: return User_4; // 3D shell outline
146 case 54: return User_5; // 3D shell top
147 case 55: return User_6; // 3D shell bot
148 case 56: return User_7; // Drill drawing
149
150 default: break;
151 }
152
153 return User_1;
154}
155
156
157static void AlignText( EDA_TEXT* text, int align )
158{
159 switch( align )
160 {
161 case 1:
162 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
163 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
164 break;
165 case 2:
166 text->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
167 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
168 break;
169 case 3:
170 text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
171 text->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
172 break;
173
174 case 4:
175 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
176 text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
177 break;
178 case 5:
179 text->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
180 text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
181 break;
182 case 6:
183 text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
184 text->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
185 break;
186
187 case 7:
188 text->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
189 text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
190 break;
191 case 8:
192 text->SetVertJustify( GR_TEXT_V_ALIGN_CENTER );
193 text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
194 break;
195 case 9:
196 text->SetVertJustify( GR_TEXT_V_ALIGN_BOTTOM );
197 text->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
198 break;
199 }
200}
201
202
203void PCB_IO_EASYEDAPRO_PARSER::fillFootprintModelInfo( FOOTPRINT* footprint, const wxString& modelUuid,
204 const wxString& modelTitle,
205 const wxString& modelTransform ) const
206{
207 // TODO: make this path configurable?
208 const wxString easyedaModelDir = wxS( "EASYEDA_MODELS" );
209 const wxString kicadModelPrefix = wxS( "${KIPRJMOD}/" ) + easyedaModelDir + wxS( "/" );
210
211 VECTOR3D kmodelOffset;
212 VECTOR3D kmodelRotation;
213
214 if( !modelUuid.IsEmpty() && !footprint->GetFieldByName( QUERY_MODEL_UUID_KEY ) )
215 {
216 PCB_FIELD field( footprint, footprint->GetFieldCount(), QUERY_MODEL_UUID_KEY );
217 field.SetLayer( Cmts_User );
218 field.SetVisible( false );
219 field.SetText( modelUuid );
220 footprint->AddField( field );
221 }
222
223 if( !modelTransform.IsEmpty() && !footprint->GetFieldByName( MODEL_SIZE_KEY ) )
224 {
225 wxArrayString arr = wxSplit( modelTransform, ',', '\0' );
226
227 double fitXmm = pcbIUScale.IUTomm( ScaleSize( Convert( arr[0] ) ) );
228 double fitYmm = pcbIUScale.IUTomm( ScaleSize( Convert( arr[1] ) ) );
229
230 if( fitXmm > 0.0 && fitYmm > 0.0 )
231 {
232 PCB_FIELD field( footprint, footprint->GetFieldCount(), MODEL_SIZE_KEY );
233 field.SetLayer( Cmts_User );
234 field.SetVisible( false );
235 field.SetText( wxString::FromCDouble( fitXmm ) + wxS( " " )
236 + wxString::FromCDouble( fitYmm ) );
237 footprint->AddField( field );
238 }
239
240 // TODO: other axes
241 kmodelRotation.z = -Convert( arr[3] );
242
243 kmodelOffset.x = pcbIUScale.IUTomm( ScaleSize( Convert( arr[6] ) ) );
244 kmodelOffset.y = pcbIUScale.IUTomm( ScaleSize( Convert( arr[7] ) ) );
245 kmodelOffset.z = pcbIUScale.IUTomm( ScaleSize( Convert( arr[8] ) ) );
246 }
247
248 if( !modelTitle.IsEmpty() && footprint->Models().empty() )
249 {
250 FP_3DMODEL model;
251 model.m_Filename = kicadModelPrefix
252 + EscapeString( modelTitle, ESCAPE_CONTEXT::CTX_FILENAME )
253 + wxS( ".step" );
254 model.m_Offset = kmodelOffset;
255 model.m_Rotation = kmodelRotation;
256 footprint->Models().push_back( model );
257 }
258}
259
260
261std::vector<std::unique_ptr<PCB_SHAPE>>
262PCB_IO_EASYEDAPRO_PARSER::ParsePoly( BOARD_ITEM_CONTAINER* aContainer, nlohmann::json polyData,
263 bool aClosed, bool aInFill ) const
264{
265 std::vector<std::unique_ptr<PCB_SHAPE>> results;
266
267 VECTOR2D prevPt;
268 for( int i = 0; i < polyData.size(); i++ )
269 {
270 nlohmann::json val = polyData.at( i );
271
272 if( val.is_string() )
273 {
274 wxString str = val;
275 if( str == wxS( "CIRCLE" ) )
276 {
277 VECTOR2D center;
278 center.x = ( polyData.at( ++i ) );
279 center.y = ( polyData.at( ++i ) );
280 double r = ( polyData.at( ++i ) );
281
282 std::unique_ptr<PCB_SHAPE> shape =
283 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::CIRCLE );
284
285 shape->SetCenter( ScalePos( center ) );
286 shape->SetEnd( ScalePos( center + VECTOR2D( r, 0 ) ) );
287 shape->SetFilled( aClosed );
288
289 results.emplace_back( std::move( shape ) );
290 }
291 else if( str == wxS( "R" ) )
292 {
293 VECTOR2D start, size;
294 start.x = ( polyData.at( ++i ) );
295 start.y = ( polyData.at( ++i ) );
296 size.x = ( polyData.at( ++i ) );
297 size.y = -( polyData.at( ++i ).get<double>() );
298 double angle = polyData.at( ++i );
299 double cr = ( i + 1 ) < polyData.size() ? polyData.at( ++i ).get<double>() : 0;
300
301 if( cr == 0 )
302 {
303 std::unique_ptr<PCB_SHAPE> shape =
304 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::RECTANGLE );
305
306 shape->SetStart( ScalePos( start ) );
307 shape->SetEnd( ScalePos( start + size ) );
308 shape->SetFilled( aClosed );
309 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
310
311 results.emplace_back( std::move( shape ) );
312 }
313 else
314 {
315 VECTOR2D end = start + size;
316
317 auto addSegment = [&]( VECTOR2D aStart, VECTOR2D aEnd )
318 {
319 std::unique_ptr<PCB_SHAPE> shape =
320 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
321
322 shape->SetStart( ScalePos( aStart ) );
323 shape->SetEnd( ScalePos( aEnd ) );
324 shape->SetFilled( aClosed );
325 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
326
327 results.emplace_back( std::move( shape ) );
328 };
329
330 auto addArc = [&]( VECTOR2D aStart, VECTOR2D aEnd, VECTOR2D center )
331 {
332 std::unique_ptr<PCB_SHAPE> shape =
333 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::ARC );
334
335 shape->SetStart( ScalePos( aStart ) );
336 shape->SetEnd( ScalePos( aEnd ) );
337 shape->SetCenter( ScalePos( center ) );
338 shape->SetFilled( aClosed );
339 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
340
341 results.emplace_back( std::move( shape ) );
342 };
343
344 addSegment( { start.x + cr, start.y }, { end.x - cr, start.y } );
345 addSegment( { end.x, start.y - cr }, { end.x, end.y + cr } );
346 addSegment( { start.x + cr, end.y }, { end.x - cr, end.y } );
347 addSegment( { start.x, start.y - cr }, { start.x, end.y + cr } );
348
349 addArc( { end.x - cr, start.y }, { end.x, start.y - cr },
350 { end.x - cr, start.y - cr } );
351
352 addArc( { end.x, end.y + cr }, { end.x - cr, end.y },
353 { end.x - cr, end.y + cr } );
354
355 addArc( { start.x + cr, end.y }, { start.x, end.y + cr },
356 { start.x + cr, end.y + cr } );
357
358 addArc( { start.x, start.y - cr }, { start.x + cr, start.y },
359 { start.x + cr, start.y - cr } );
360 }
361 }
362 else if( str == wxS( "ARC" ) || str == wxS( "CARC" ) )
363 {
364 VECTOR2D end;
365 double angle = polyData.at( ++i ).get<double>() / ( aInFill ? 10 : 1 );
366 end.x = ( polyData.at( ++i ) );
367 end.y = ( polyData.at( ++i ) );
368
369 std::unique_ptr<PCB_SHAPE> shape =
370 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::ARC );
371
372 if( angle < 0 )
373 {
374 shape->SetStart( ScalePos( prevPt ) );
375 shape->SetEnd( ScalePos( end ) );
376 }
377 else
378 {
379 shape->SetStart( ScalePos( end ) );
380 shape->SetEnd( ScalePos( prevPt ) );
381 }
382
383 VECTOR2D delta = end - prevPt;
384 VECTOR2D mid = ( prevPt + delta / 2 );
385
386 double ha = angle / 2;
387 double hd = delta.EuclideanNorm() / 2;
388 double cdist = hd / tan( DEG2RAD( ha ) );
389 VECTOR2D center = mid + delta.Perpendicular().Resize( cdist );
390 shape->SetCenter( ScalePos( center ) );
391
392 shape->SetFilled( aClosed );
393
394 results.emplace_back( std::move( shape ) );
395
396 prevPt = end;
397 }
398 else if( str == wxS( "L" ) )
399 {
400 SHAPE_LINE_CHAIN chain;
401 chain.Append( ScalePos( prevPt ) );
402
403 while( i < polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
404 {
405 VECTOR2D pt;
406 pt.x = ( polyData.at( ++i ) );
407 pt.y = ( polyData.at( ++i ) );
408
409 chain.Append( ScalePos( pt ) );
410
411 prevPt = pt;
412 }
413
414 if( aClosed )
415 {
416 std::unique_ptr<PCB_SHAPE> shape =
417 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
418
419 wxASSERT( chain.PointCount() > 2 );
420
421 if( chain.PointCount() > 2 )
422 {
423 chain.SetClosed( true );
424 shape->SetFilled( true );
425 shape->SetPolyShape( chain );
426
427 results.emplace_back( std::move( shape ) );
428 }
429 }
430 else
431 {
432 for( int s = 0; s < chain.SegmentCount(); s++ )
433 {
434 SEG seg = chain.Segment( s );
435
436 std::unique_ptr<PCB_SHAPE> shape =
437 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
438
439 shape->SetStart( seg.A );
440 shape->SetEnd( seg.B );
441
442 results.emplace_back( std::move( shape ) );
443 }
444 }
445 }
446 }
447 else if( val.is_number() )
448 {
449 prevPt.x = ( polyData.at( i ) );
450 prevPt.y = ( polyData.at( ++i ) );
451 }
452 }
453
454 return results;
455}
456
457
459PCB_IO_EASYEDAPRO_PARSER::ParseContour( nlohmann::json polyData, bool aInFill,
460 double aArcAccuracy ) const
461{
462 SHAPE_LINE_CHAIN result;
463 VECTOR2D prevPt;
464
465 double bezierMinSegLen = polyData.size() < 300 ? aArcAccuracy : aArcAccuracy * 10;
466
467 for( int i = 0; i < polyData.size(); i++ )
468 {
469 nlohmann::json val = polyData.at( i );
470
471 if( val.is_string() )
472 {
473 wxString str = val;
474 if( str == wxS( "CIRCLE" ) )
475 {
476 VECTOR2D center;
477 center.x = ( polyData.at( ++i ) );
478 center.y = ( polyData.at( ++i ) );
479 double r = ( polyData.at( ++i ) );
480
482 ERROR_INSIDE );
483 }
484 else if( str == wxS( "R" ) )
485 {
486 VECTOR2D start, size;
487 start.x = ( polyData.at( ++i ) );
488 start.y = ( polyData.at( ++i ) );
489 size.x = ( polyData.at( ++i ) );
490 size.y = ( polyData.at( ++i ).get<double>() );
491 double angle = polyData.at( ++i );
492 double cr = ( i + 1 ) < polyData.size() ? polyData.at( ++i ).get<double>() : 0;
493
494 SHAPE_POLY_SET poly;
495
496 VECTOR2D kstart = ScalePos( start );
497 VECTOR2D ksize = ScaleSize( size );
498 VECTOR2D kcenter = kstart + ksize / 2;
499 RotatePoint( kcenter, kstart, EDA_ANGLE( angle, DEGREES_T ) );
500
502 poly, kcenter, ksize, EDA_ANGLE( angle, DEGREES_T ), ScaleSize( cr ), 0, 0,
504
505 result.Append( poly.Outline( 0 ) );
506 }
507 else if( str == wxS( "ARC" ) || str == wxS( "CARC" ) )
508 {
509 VECTOR2D end;
510 double angle = polyData.at( ++i ).get<double>();
511
512 if( aInFill ) // In .epcb fills, the angle is 10x for some reason
513 angle /= 10;
514
515 end.x = ( polyData.at( ++i ) );
516 end.y = ( polyData.at( ++i ) );
517
518 VECTOR2D arcStart, arcEnd;
519 arcStart = prevPt;
520 arcEnd = end;
521
522 VECTOR2D delta = end - prevPt;
523 VECTOR2D mid = ( prevPt + delta / 2 );
524
525 double ha = angle / 2;
526 double hd = delta.EuclideanNorm() / 2;
527 double cdist = hd / tan( DEG2RAD( ha ) );
528 VECTOR2D center = mid + delta.Perpendicular().Resize( cdist );
529
530 SHAPE_ARC sarc;
531 sarc.ConstructFromStartEndCenter( ScalePos( arcStart ), ScalePos( arcEnd ),
532 ScalePos( center ), angle >= 0, 0 );
533
534 result.Append( sarc, aArcAccuracy );
535
536 prevPt = end;
537 }
538 else if( str == wxS( "C" ) )
539 {
540 VECTOR2D pt1;
541 pt1.x = ( polyData.at( ++i ) );
542 pt1.y = ( polyData.at( ++i ) );
543
544 VECTOR2D pt2;
545 pt2.x = ( polyData.at( ++i ) );
546 pt2.y = ( polyData.at( ++i ) );
547
548 VECTOR2D pt3;
549 pt3.x = ( polyData.at( ++i ) );
550 pt3.y = ( polyData.at( ++i ) );
551
552 std::vector<VECTOR2I> ctrlPoints = { ScalePos( prevPt ), ScalePos( pt1 ),
553 ScalePos( pt2 ), ScalePos( pt3 ) };
554 BEZIER_POLY converter( ctrlPoints );
555
556 std::vector<VECTOR2I> bezierPoints;
557 converter.GetPoly( bezierPoints, bezierMinSegLen, 16 );
558
559 result.Append( bezierPoints );
560
561 prevPt = pt3;
562 }
563 else if( str == wxS( "L" ) )
564 {
565 result.Append( ScalePos( prevPt ) );
566
567 while( i < polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
568 {
569 VECTOR2D pt;
570 pt.x = ( polyData.at( ++i ) );
571 pt.y = ( polyData.at( ++i ) );
572
573 result.Append( ScalePos( pt ) );
574
575 prevPt = pt;
576 }
577 }
578 }
579 else if( val.is_number() )
580 {
581 prevPt.x = ( polyData.at( i ) );
582 prevPt.y = ( polyData.at( ++i ) );
583 }
584 }
585
586 return result;
587}
588
589
590std::unique_ptr<PAD> PCB_IO_EASYEDAPRO_PARSER::createPAD( FOOTPRINT* aFootprint,
591 const nlohmann::json& line )
592{
593 wxString uuid = line.at( 1 );
594
595 // if( line.at( 2 ).is_number() )
596 // int unk = line.at( 2 ).get<int>();
597 // else if( line.at( 2 ).is_string() )
598 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
599
600 wxString netname = line.at( 3 );
601 int layer = line.at( 4 ).get<int>();
602 PCB_LAYER_ID klayer = LayerToKi( layer );
603
604 wxString padNumber = line.at( 5 );
605
606 VECTOR2D center;
607 center.x = line.at( 6 );
608 center.y = line.at( 7 );
609
610 double orientation = line.at( 8 );
611
612 nlohmann::json padHole = line.at( 9 );
613 nlohmann::json padShape = line.at( 10 );
614
615 std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
616
617 pad->SetNumber( padNumber );
618 pad->SetPosition( ScalePos( center ) );
619 pad->SetOrientationDegrees( orientation );
620
621 if( !padHole.is_null() )
622 {
623 double drill_dir = 0;
624
625 if( line.at( 14 ).is_number() )
626 drill_dir = line.at( 14 );
627
628 if( padHole.at( 0 ) == wxS( "ROUND" ) || padHole.at( 0 ) == wxS( "SLOT" ) )
629 {
630 VECTOR2D drill;
631 drill.x = padHole.at( 1 );
632 drill.y = padHole.at( 2 );
633
634 double deg = EDA_ANGLE( drill_dir, DEGREES_T ).Normalize90().AsDegrees();
635
636 if( std::abs( deg ) >= 45 )
637 std::swap( drill.x, drill.y ); // KiCad doesn't support arbitrary hole direction
638
639 if( padHole.at( 0 ) == wxS( "SLOT" ) )
640 {
641 pad->SetDrillShape( PAD_DRILL_SHAPE_OBLONG );
642 }
643
644 pad->SetDrillSize( ScaleSize( drill ) );
645 pad->SetLayerSet( PAD::PTHMask() );
646 pad->SetAttribute( PAD_ATTRIB::PTH );
647 }
648 }
649 else
650 {
651 if( klayer == F_Cu )
652 {
653 pad->SetLayerSet( PAD::SMDMask() );
654 }
655 else if( klayer == B_Cu )
656 {
657 pad->SetLayerSet( FlipLayerMask( PAD::SMDMask() ) );
658 }
659
660 pad->SetAttribute( PAD_ATTRIB::SMD );
661 }
662
663 wxString padSh = padShape.at( 0 );
664 if( padSh == wxS( "RECT" ) )
665 {
666 VECTOR2D size;
667 size.x = padShape.at( 1 );
668 size.y = padShape.at( 2 );
669 double cr_p = padShape.size() > 3 ? padShape.at( 3 ).get<double>() : 0;
670
671 pad->SetSize( ScaleSize( size ) );
672
673 if( cr_p == 0 )
674 {
675 pad->SetShape( PAD_SHAPE::RECTANGLE );
676 }
677 else
678 {
679 pad->SetShape( PAD_SHAPE::ROUNDRECT );
680 pad->SetRoundRectRadiusRatio( cr_p / 100 );
681 }
682 }
683 else if( padSh == wxS( "ELLIPSE" ) )
684 {
685 VECTOR2D size;
686 size.x = padShape.at( 1 );
687 size.y = padShape.at( 2 );
688
689 pad->SetSize( ScaleSize( size ) );
690 pad->SetShape( PAD_SHAPE::CIRCLE );
691 }
692 else if( padSh == wxS( "OVAL" ) )
693 {
694 VECTOR2D size;
695 size.x = padShape.at( 1 );
696 size.y = padShape.at( 2 );
697
698 pad->SetSize( ScaleSize( size ) );
699 pad->SetShape( PAD_SHAPE::OVAL );
700 }
701 else if( padSh == wxS( "POLY" ) )
702 {
703 pad->SetShape( PAD_SHAPE::CUSTOM );
704 pad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
705 pad->SetSize( { 1, 1 } );
706
707 nlohmann::json polyData = padShape.at( 1 );
708
709 std::vector<std::unique_ptr<PCB_SHAPE>> results =
710 ParsePoly( aFootprint, polyData, true, false );
711
712 for( auto& shape : results )
713 {
714 shape->SetLayer( klayer );
715 shape->SetWidth( 0 );
716
717 shape->Move( -pad->GetPosition() );
718
719 pad->AddPrimitive( shape.release() );
720 }
721 }
722
723 pad->SetThermalSpokeAngle( ANGLE_90 );
724
725 return std::move( pad );
726}
727
728
730 const wxString& aFpUuid,
731 const std::vector<nlohmann::json>& aLines )
732{
733 std::unique_ptr<FOOTPRINT> footprintPtr = std::make_unique<FOOTPRINT>( m_board );
734 FOOTPRINT* footprint = footprintPtr.get();
735
736 const VECTOR2I defaultTextSize( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) );
737 const int defaultTextThickness( pcbIUScale.mmToIU( 0.15 ) );
738
739 for( PCB_FIELD* field : footprint->Fields() )
740 {
741 field->SetTextSize( defaultTextSize );
742 field->SetTextThickness( defaultTextThickness );
743 }
744
745 for( const nlohmann::json& line : aLines )
746 {
747 if( line.size() == 0 )
748 continue;
749
750 wxString type = line.at( 0 );
751
752 if( type == wxS( "POLY" ) || type == wxS( "PAD" ) || type == wxS( "FILL" )
753 || type == wxS( "ATTR" ) )
754 {
755 wxString uuid = line.at( 1 );
756
757 // if( line.at( 2 ).is_number() )
758 // int unk = line.at( 2 ).get<int>();
759 // else if( line.at( 2 ).is_string() )
760 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
761
762 wxString netname = line.at( 3 );
763 int layer = line.at( 4 ).get<int>();
764 PCB_LAYER_ID klayer = LayerToKi( layer );
765
766 if( type == wxS( "POLY" ) )
767 {
768 double thickness = ( line.at( 5 ) );
769 nlohmann::json polyData = line.at( 6 );
770
771 std::vector<std::unique_ptr<PCB_SHAPE>> results =
772 ParsePoly( footprint, polyData, false, false );
773
774 for( auto& shape : results )
775 {
776 shape->SetLayer( klayer );
777 shape->SetWidth( ScaleSize( thickness ) );
778
779 footprint->Add( shape.release(), ADD_MODE::APPEND );
780 }
781 }
782 else if( type == wxS( "PAD" ) )
783 {
784 std::unique_ptr<PAD> pad = createPAD( footprint, line );
785
786 footprint->Add( pad.release(), ADD_MODE::APPEND );
787 }
788 else if( type == wxS( "FILL" ) )
789 {
790 int layer = line.at( 4 ).get<int>();
791 PCB_LAYER_ID klayer = LayerToKi( layer );
792
793 double width = line.at( 5 );
794
795 nlohmann::json polyDataList = line.at( 7 );
796
797 if( !polyDataList.at( 0 ).is_array() )
798 polyDataList = nlohmann::json::array( { polyDataList } );
799
800 std::vector<SHAPE_LINE_CHAIN> contours;
801 for( nlohmann::json& polyData : polyDataList )
802 {
803 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
804 contour.SetClosed( true );
805
806 contours.push_back( contour );
807 }
808
809 SHAPE_POLY_SET polySet;
810
811 for( SHAPE_LINE_CHAIN& contour : contours )
812 polySet.AddOutline( contour );
813
814 polySet.RebuildHolesFromContours();
815
816 std::unique_ptr<PCB_GROUP> group;
817
818 if( polySet.OutlineCount() > 1 )
819 group = std::make_unique<PCB_GROUP>( footprint );
820
821 BOX2I polyBBox = polySet.BBox();
822
823 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
824 {
825 std::unique_ptr<PCB_SHAPE> shape =
826 std::make_unique<PCB_SHAPE>( footprint, SHAPE_T::POLY );
827
828 shape->SetFilled( true );
829 shape->SetPolyShape( poly );
830 shape->SetLayer( klayer );
831 shape->SetWidth( 0 );
832
833 if( group )
834 group->AddItem( shape.get() );
835
836 footprint->Add( shape.release(), ADD_MODE::APPEND );
837 }
838
839 if( group )
840 footprint->Add( group.release(), ADD_MODE::APPEND );
841 }
842 else if( type == wxS( "ATTR" ) )
843 {
844 EASYEDAPRO::PCB_ATTR attr = line;
845
846 if( attr.key == wxS( "Designator" ) )
847 footprint->GetField( REFERENCE_FIELD )->SetText( attr.value );
848 }
849 }
850 else if( type == wxS( "REGION" ) )
851 {
852 wxString uuid = line.at( 1 );
853
854 // if( line.at( 2 ).is_number() )
855 // int unk = line.at( 2 ).get<int>();
856 // else if( line.at( 2 ).is_string() )
857 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
858
859 int layer = line.at( 3 ).get<int>();
860 PCB_LAYER_ID klayer = LayerToKi( layer );
861
862 double width = line.at( 4 );
863 std::set<int> flags = line.at( 5 );
864 nlohmann::json polyDataList = line.at( 6 );
865
866 for( nlohmann::json& polyData : polyDataList )
867 {
868 SHAPE_POLY_SET polySet;
869
870 std::vector<std::unique_ptr<PCB_SHAPE>> results =
871 ParsePoly( nullptr, polyData, true, false );
872
873 for( auto& shape : results )
874 {
875 shape->SetFilled( true );
876 shape->TransformShapeToPolygon( polySet, klayer, 0, ARC_HIGH_DEF, ERROR_INSIDE,
877 true );
878 }
879
881
882 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( footprint );
883
884 zone->SetIsRuleArea( true );
885 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
886 zone->SetDoNotAllowCopperPour( !!flags.count( 7 ) || !!flags.count( 6 )
887 || !!flags.count( 8 ) );
888 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
889 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
890 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
891
892 zone->SetLayer( klayer );
893 zone->Outline()->Append( polySet );
894
895 footprint->Add( zone.release(), ADD_MODE::APPEND );
896 }
897 }
898 }
899
900 if( aProject.is_object() )
901 {
902 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at( "devices" );
903 std::map<wxString, wxString> compAttrs;
904
905 for( auto& [devUuid, devData] : devicesMap )
906 {
907 if( auto fp = get_opt( devData.attributes, "Footprint" ) )
908 {
909 if( *fp == aFpUuid )
910 {
911 compAttrs = devData.attributes;
912 break;
913 }
914 }
915 }
916
917 wxString modelUuid, modelTitle, modelTransform;
918
919 modelUuid = get_def( compAttrs, "3D Model", "" );
920 modelTitle = get_def( compAttrs, "3D Model Title", modelUuid );
921 modelTransform = get_def( compAttrs, "3D Model Transform", "" );
922
923 fillFootprintModelInfo( footprint, modelUuid, modelTitle, modelTransform );
924 }
925
926 // Heal board outlines
927 std::vector<PCB_SHAPE*> shapes;
928 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
929
930 for( BOARD_ITEM* item : footprint->GraphicalItems() )
931 {
932 if( !item->IsOnLayer( Edge_Cuts ) )
933 continue;
934
935 if( item->Type() == PCB_SHAPE_T )
936 shapes.push_back( static_cast<PCB_SHAPE*>( item ) );
937 }
938
939 ConnectBoardShapes( shapes, newShapes, SHAPE_JOIN_DISTANCE );
940
941 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
942 footprint->Add( ptr.release(), ADD_MODE::APPEND );
943
944 return footprintPtr.release();
945}
946
947
949 BOARD* aBoard, const nlohmann::json& aProject,
950 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
951 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
952 const std::multimap<wxString, EASYEDAPRO::POURED>& aPouredMap,
953 const std::vector<nlohmann::json>& aLines, const wxString& aFpLibName )
954{
955 std::map<wxString, std::vector<nlohmann::json>> componentLines;
956 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
957
959
960 for( const nlohmann::json& line : aLines )
961 {
962 if( line.size() == 0 )
963 continue;
964
965 wxString type = line.at( 0 );
966
967 if( type == wxS( "LAYER" ) )
968 {
969 int layer = line.at( 1 );
970 PCB_LAYER_ID klayer = LayerToKi( layer );
971
972 wxString layerType = line.at( 2 );
973 wxString layerName = line.at( 3 );
974 int layerFlag = line.at( 4 );
975
976 if( layerFlag != 0 )
977 {
978 LSET blayers = aBoard->GetEnabledLayers();
979 blayers.set( klayer );
980 aBoard->SetEnabledLayers( blayers );
981 aBoard->SetLayerName( klayer, layerName );
982 }
983 }
984 else if( type == wxS( "NET" ) )
985 {
986 wxString netname = line.at( 1 );
987
988 aBoard->Add( new NETINFO_ITEM( aBoard, netname, aBoard->GetNetCount() + 1 ),
989 ADD_MODE::APPEND );
990 }
991 else if( type == wxS( "RULE" ) )
992 {
993 wxString ruleType = line.at( 1 );
994 wxString ruleName = line.at( 2 );
995 int isDefault = line.at( 3 );
996 nlohmann::json ruleData = line.at( 4 );
997
998 if( ruleType == wxS( "3" ) && isDefault ) // Track width
999 {
1000 wxString units = ruleData.at( 0 );
1001 double minVal = ruleData.at( 1 );
1002 double optVal = ruleData.at( 2 );
1003 double maxVal = ruleData.at( 3 );
1004
1005 bds.m_TrackMinWidth = ScaleSize( minVal );
1006 }
1007 else if( ruleType == wxS( "1" ) && isDefault )
1008 {
1009 wxString units = ruleData.at( 0 );
1010 nlohmann::json table = ruleData.at( 1 );
1011
1012 int minVal = INT_MAX;
1013 for( const std::vector<int>& arr : table )
1014 {
1015 for( int val : arr )
1016 {
1017 if( val < minVal )
1018 minVal = val;
1019 }
1020 }
1021
1022 bds.m_MinClearance = ScaleSize( minVal );
1023 }
1024
1025 ruleLines[ruleType].push_back( line );
1026 }
1027 else if( type == wxS( "VIA" ) || type == wxS( "LINE" ) || type == wxS( "ARC" )
1028 || type == wxS( "POLY" ) || type == wxS( "FILL" ) || type == wxS( "POUR" ) )
1029 {
1030 wxString uuid = line.at( 1 );
1031
1032 // if( line.at( 2 ).is_number() )
1033 // int unk = line.at( 2 ).get<int>();
1034 // else if( line.at( 2 ).is_string() )
1035 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1036
1037 wxString netname = line.at( 3 );
1038
1039 if( type == wxS( "VIA" ) )
1040 {
1041 VECTOR2D center;
1042 center.x = line.at( 5 );
1043 center.y = line.at( 6 );
1044
1045 double drill = line.at( 7 );
1046 double dia = line.at( 8 );
1047
1048 std::unique_ptr<PCB_VIA> via = std::make_unique<PCB_VIA>( aBoard );
1049
1050 via->SetPosition( ScalePos( center ) );
1051 via->SetDrill( ScaleSize( drill ) );
1052 via->SetWidth( ScaleSize( dia ) );
1053
1054 via->SetNet( aBoard->FindNet( netname ) );
1055
1056 aBoard->Add( via.release(), ADD_MODE::APPEND );
1057 }
1058 else if( type == wxS( "LINE" ) )
1059 {
1060 int layer = line.at( 4 ).get<int>();
1061 PCB_LAYER_ID klayer = LayerToKi( layer );
1062
1063 VECTOR2D start;
1064 start.x = line.at( 5 );
1065 start.y = line.at( 6 );
1066
1067 VECTOR2D end;
1068 end.x = line.at( 7 );
1069 end.y = line.at( 8 );
1070
1071 double width = line.at( 9 );
1072
1073 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( aBoard );
1074
1075 track->SetLayer( klayer );
1076 track->SetStart( ScalePos( start ) );
1077 track->SetEnd( ScalePos( end ) );
1078 track->SetWidth( ScaleSize( width ) );
1079
1080 track->SetNet( aBoard->FindNet( netname ) );
1081
1082 aBoard->Add( track.release(), ADD_MODE::APPEND );
1083 }
1084 else if( type == wxS( "ARC" ) )
1085 {
1086 int layer = line.at( 4 ).get<int>();
1087 PCB_LAYER_ID klayer = LayerToKi( layer );
1088
1089 VECTOR2D start;
1090 start.x = line.at( 5 );
1091 start.y = line.at( 6 );
1092
1093 VECTOR2D end;
1094 end.x = line.at( 7 );
1095 end.y = line.at( 8 );
1096
1097 double angle = line.at( 9 );
1098 double width = line.at( 10 );
1099
1100 VECTOR2D delta = end - start;
1101 VECTOR2D mid = ( start + delta / 2 );
1102
1103 double ha = angle / 2;
1104 double hd = delta.EuclideanNorm() / 2;
1105 double cdist = hd / tan( DEG2RAD( ha ) );
1106 VECTOR2D center = mid + delta.Perpendicular().Resize( cdist );
1107
1108 SHAPE_ARC sarc;
1109 sarc.ConstructFromStartEndCenter( ScalePos( start ), ScalePos( end ),
1110 ScalePos( center ), angle >= 0, width );
1111
1112 std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( aBoard, &sarc );
1113 arc->SetWidth( ScaleSize( width ) );
1114
1115 arc->SetLayer( klayer );
1116 arc->SetNet( aBoard->FindNet( netname ) );
1117
1118 aBoard->Add( arc.release(), ADD_MODE::APPEND );
1119 }
1120 else if( type == wxS( "FILL" ) )
1121 {
1122 int layer = line.at( 4 ).get<int>();
1123 PCB_LAYER_ID klayer = LayerToKi( layer );
1124
1125 double width = line.at( 5 );
1126
1127 nlohmann::json polyDataList = line.at( 7 );
1128
1129 if( !polyDataList.at( 0 ).is_array() )
1130 polyDataList = nlohmann::json::array( { polyDataList } );
1131
1132 std::vector<SHAPE_LINE_CHAIN> contours;
1133 for( nlohmann::json& polyData : polyDataList )
1134 {
1135 SHAPE_LINE_CHAIN contour = ParseContour( polyData, true );
1136 contour.SetClosed( true );
1137
1138 contours.push_back( contour );
1139 }
1140
1141 SHAPE_POLY_SET zoneFillPoly;
1142
1143 for( SHAPE_LINE_CHAIN& contour : contours )
1144 zoneFillPoly.AddOutline( contour );
1145
1146 zoneFillPoly.RebuildHolesFromContours();
1148
1149 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1150
1151 zone->SetNet( aBoard->FindNet( netname ) );
1152 zone->SetLayer( klayer );
1153 zone->Outline()->Append( SHAPE_RECT( zoneFillPoly.BBox() ).Outline() );
1154 zone->SetFilledPolysList( klayer, zoneFillPoly );
1155 zone->SetAssignedPriority( 500 );
1156 zone->SetIsFilled( true );
1157 zone->SetNeedRefill( false );
1158
1159 zone->SetLocalClearance( bds.m_MinClearance );
1160 zone->SetMinThickness( bds.m_TrackMinWidth );
1161
1162 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1163 }
1164 else if( type == wxS( "POLY" ) )
1165 {
1166 int layer = line.at( 4 );
1167 PCB_LAYER_ID klayer = LayerToKi( layer );
1168
1169 double thickness = line.at( 5 );
1170 nlohmann::json polyData = line.at( 6 );
1171
1172 std::vector<std::unique_ptr<PCB_SHAPE>> results =
1173 ParsePoly( aBoard, polyData, false, false );
1174
1175 for( auto& shape : results )
1176 {
1177 shape->SetLayer( klayer );
1178 shape->SetWidth( ScaleSize( thickness ) );
1179
1180 aBoard->Add( shape.release(), ADD_MODE::APPEND );
1181 }
1182 }
1183 else if( type == wxS( "POUR" ) )
1184 {
1185 int layer = line.at( 4 ).get<int>();
1186 PCB_LAYER_ID klayer = LayerToKi( layer );
1187
1188 double lineWidth = line.at( 5 ); // Doesn't matter
1189 wxString pourname = line.at( 6 );
1190 int fillOrder = line.at( 7 ).get<int>();
1191 nlohmann::json polyDataList = line.at( 8 );
1192
1193 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1194
1195 zone->SetNet( aBoard->FindNet( netname ) );
1196 zone->SetLayer( klayer );
1197 zone->SetAssignedPriority( 500 - fillOrder );
1198 zone->SetLocalClearance( bds.m_MinClearance );
1199 zone->SetMinThickness( bds.m_TrackMinWidth );
1200
1201 for( nlohmann::json& polyData : polyDataList )
1202 {
1203 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1204 contour.SetClosed( true );
1205
1206 zone->Outline()->Append( contour );
1207 }
1208
1209 wxASSERT( zone->Outline()->OutlineCount() == 1 );
1210
1211 SHAPE_POLY_SET fillPolySet;
1212 SHAPE_POLY_SET thermalSpokes;
1213 int entryId = 0;
1214
1216 {
1217 auto range = aPouredMap.equal_range( uuid );
1218 for( auto& it = range.first; it != range.second; ++it )
1219 {
1220 const EASYEDAPRO::POURED& poured = it->second;
1221 int unki = poured.unki;
1222
1223 SHAPE_POLY_SET thisPoly;
1224
1225 for( int dataId = 0; dataId < poured.polyData.size(); dataId++ )
1226 {
1227 const nlohmann::json& fillData = poured.polyData[dataId];
1228 const double ptScale = 10;
1229
1230 SHAPE_LINE_CHAIN contour =
1231 ParseContour( fillData, false, ARC_HIGH_DEF / ptScale );
1232
1233 // Scale the fill
1234 for( int i = 0; i < contour.PointCount(); i++ )
1235 contour.SetPoint( i, contour.GetPoint( i ) * ptScale );
1236
1237 if( poured.isPoly )
1238 {
1239 contour.SetClosed( true );
1240
1241 // The contour can be self-intersecting
1242 SHAPE_POLY_SET simple( contour );
1244
1245 if( dataId == 0 )
1246 {
1247 thisPoly.Append( simple );
1248 }
1249 else
1250 {
1251 thisPoly.BooleanSubtract( simple,
1253 }
1254 }
1255 else
1256 {
1257 const int thermalWidth = pcbIUScale.mmToIU( 0.2 ); // Generic
1258
1259 for( int segId = 0; segId < contour.SegmentCount(); segId++ )
1260 {
1261 const SEG& seg = contour.CSegment( segId );
1262
1263 TransformOvalToPolygon( thermalSpokes, seg.A, seg.B,
1264 thermalWidth, ARC_LOW_DEF,
1265 ERROR_INSIDE );
1266 }
1267 }
1268 }
1269
1270 fillPolySet.Append( thisPoly );
1271
1272 entryId++;
1273 }
1274
1275 if( !fillPolySet.IsEmpty() )
1276 {
1278
1279 const int strokeWidth = pcbIUScale.MilsToIU( 8 ); // Seems to be 8 mils
1280
1281 fillPolySet.Inflate( strokeWidth / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
1282 ARC_HIGH_DEF, false );
1283
1284 fillPolySet.BooleanAdd( thermalSpokes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
1285
1287
1288 zone->SetFilledPolysList( klayer, fillPolySet );
1289 zone->SetNeedRefill( false );
1290 zone->SetIsFilled( true );
1291 }
1292 }
1293
1294 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1295 }
1296 }
1297 else if( type == wxS( "TEARDROP" ) )
1298 {
1299 wxString uuid = line.at( 1 );
1300 wxString netname = line.at( 2 );
1301 int layer = line.at( 3 ).get<int>();
1302 PCB_LAYER_ID klayer = LayerToKi( layer );
1303
1304 nlohmann::json polyData = line.at( 4 );
1305
1306 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1307 contour.SetClosed( true );
1308
1309 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1310
1311 zone->SetNet( aBoard->FindNet( netname ) );
1312 zone->SetLayer( klayer );
1313 zone->Outline()->Append( contour );
1314 zone->SetFilledPolysList( klayer, contour );
1315 zone->SetNeedRefill( false );
1316 zone->SetIsFilled( true );
1317
1318 zone->SetAssignedPriority( 600 );
1319 zone->SetLocalClearance( 0 );
1320 zone->SetMinThickness( 0 );
1321 zone->SetTeardropAreaType( TEARDROP_TYPE::TD_UNSPECIFIED );
1322
1323 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1324 }
1325 else if( type == wxS( "REGION" ) )
1326 {
1327 wxString uuid = line.at( 1 );
1328
1329 // if( line.at( 2 ).is_number() )
1330 // int unk = line.at( 2 ).get<int>();
1331 // else if( line.at( 2 ).is_string() )
1332 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1333
1334 int layer = line.at( 3 ).get<int>();
1335 PCB_LAYER_ID klayer = LayerToKi( layer );
1336
1337 double width = line.at( 4 );
1338 std::set<int> flags = line.at( 5 );
1339 nlohmann::json polyDataList = line.at( 6 );
1340
1341 for( nlohmann::json& polyData : polyDataList )
1342 {
1343 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1344 contour.SetClosed( true );
1345
1346 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1347
1348 zone->SetIsRuleArea( true );
1349 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1350 zone->SetDoNotAllowCopperPour( !!flags.count( 7 ) || !!flags.count( 6 )
1351 || !!flags.count( 8 ) );
1352 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1353 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1354 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1355
1356 zone->SetLayer( klayer );
1357 zone->Outline()->Append( contour );
1358
1359 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1360 }
1361 }
1362 else if( type == wxS( "PAD" ) )
1363 {
1364 wxString netname = line.at( 3 );
1365
1366 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aBoard );
1367 std::unique_ptr<PAD> pad = createPAD( footprint.get(), line );
1368
1369 pad->SetNet( aBoard->FindNet( netname ) );
1370
1371 VECTOR2I pos = pad->GetPosition();
1372 EDA_ANGLE orient = pad->GetOrientation();
1373
1374 pad->SetPosition( VECTOR2I() );
1375 pad->SetOrientation( ANGLE_0 );
1376
1377 footprint->Add( pad.release(), ADD_MODE::APPEND );
1378 footprint->SetPosition( pos );
1379 footprint->SetOrientation( orient );
1380
1381 wxString fpName = wxS( "Pad_" ) + line.at( 1 ).get<wxString>();
1382 LIB_ID fpID = EASYEDAPRO::ToKiCadLibID( wxEmptyString, fpName );
1383
1384 footprint->SetFPID( fpID );
1385 footprint->Reference().SetVisible( true );
1386 footprint->Value().SetVisible( true );
1387 footprint->AutoPositionFields();
1388
1389 aBoard->Add( footprint.release(), ADD_MODE::APPEND );
1390 }
1391 else if( type == wxS( "IMAGE" ) )
1392 {
1393 wxString uuid = line.at( 1 );
1394
1395 // if( line.at( 2 ).is_number() )
1396 // int unk = line.at( 2 ).get<int>();
1397 // else if( line.at( 2 ).is_string() )
1398 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1399
1400 int layer = line.at( 3 ).get<int>();
1401 PCB_LAYER_ID klayer = LayerToKi( layer );
1402
1403 VECTOR2D start( line.at( 4 ), line.at( 5 ) );
1404 VECTOR2D size( line.at( 6 ), line.at( 7 ) );
1405
1406 double angle = line.at( 8 ); // from top left corner
1407 int mirror = line.at( 9 );
1408 nlohmann::json polyDataList = line.at( 10 );
1409
1410 BOX2I bbox;
1411 std::vector<SHAPE_LINE_CHAIN> contours;
1412 for( nlohmann::json& polyData : polyDataList )
1413 {
1414 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1415 contour.SetClosed( true );
1416
1417 contours.push_back( contour );
1418
1419 bbox.Merge( contour.BBox() );
1420 }
1421
1422 VECTOR2D scale( ScaleSize( size.x ) / bbox.GetSize().x,
1423 ScaleSize( size.y ) / bbox.GetSize().y );
1424
1425 SHAPE_POLY_SET polySet;
1426
1427 for( SHAPE_LINE_CHAIN& contour : contours )
1428 {
1429 for( int i = 0; i < contour.PointCount(); i++ )
1430 {
1431 VECTOR2I pt = contour.CPoint( i );
1432 contour.SetPoint( i, VECTOR2I( pt.x * scale.x, pt.y * scale.y ) );
1433 }
1434
1435 polySet.AddOutline( contour );
1436 }
1437
1438 polySet.RebuildHolesFromContours();
1439
1440 std::unique_ptr<PCB_GROUP> group;
1441
1442 if( polySet.OutlineCount() > 1 )
1443 group = std::make_unique<PCB_GROUP>( aBoard );
1444
1445 BOX2I polyBBox = polySet.BBox();
1446
1447 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
1448 {
1449 std::unique_ptr<PCB_SHAPE> shape =
1450 std::make_unique<PCB_SHAPE>( aBoard, SHAPE_T::POLY );
1451
1452 shape->SetFilled( true );
1453 shape->SetPolyShape( poly );
1454 shape->SetLayer( klayer );
1455 shape->SetWidth( 0 );
1456
1457 shape->Move( ScalePos( start ) - polyBBox.GetOrigin() );
1458 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
1459
1460 if( IsBackLayer( klayer ) ^ !!mirror )
1461 shape->Mirror( ScalePos( start ), !IsBackLayer( klayer ) );
1462
1463 if( group )
1464 group->AddItem( shape.get() );
1465
1466 aBoard->Add( shape.release(), ADD_MODE::APPEND );
1467 }
1468
1469 if( group )
1470 aBoard->Add( group.release(), ADD_MODE::APPEND );
1471 }
1472 else if( type == wxS( "OBJ" ) )
1473 {
1474 VECTOR2D start, size;
1475 wxString mimeType, base64Data;
1476 double angle = 0;
1477 int flipped = 0;
1478
1479 if( !line.at( 3 ).is_number() )
1480 continue;
1481
1482 int layer = line.at( 3 ).get<int>();
1483 PCB_LAYER_ID klayer = LayerToKi( layer );
1484
1485 start = VECTOR2D( line.at( 5 ), line.at( 6 ) );
1486 size = VECTOR2D( line.at( 7 ), line.at( 8 ) );
1487 angle = line.at( 9 );
1488 flipped = line.at( 10 );
1489
1490 wxString imageUrl = line.at( 11 );
1491
1492 if( imageUrl.BeforeFirst( ':' ) == wxS( "blob" ) )
1493 {
1494 wxString objectId = imageUrl.AfterLast( ':' );
1495
1496 if( auto blob = get_opt( aBlobMap, objectId ) )
1497 {
1498 wxString blobUrl = blob->url;
1499
1500 if( blobUrl.BeforeFirst( ':' ) == wxS( "data" ) )
1501 {
1502 wxArrayString paramsArr =
1503 wxSplit( blobUrl.AfterFirst( ':' ).BeforeFirst( ',' ), ';', '\0' );
1504
1505 base64Data = blobUrl.AfterFirst( ',' );
1506
1507 if( paramsArr.size() > 0 )
1508 mimeType = paramsArr[0];
1509 }
1510 }
1511 }
1512
1513 VECTOR2D kstart = ScalePos( start );
1514 VECTOR2D ksize = ScaleSize( size );
1515
1516 if( mimeType.empty() || base64Data.empty() )
1517 continue;
1518
1519 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1520
1521 if( mimeType == wxS( "image/svg+xml" ) )
1522 {
1523 // Not yet supported by EasyEDA
1524 }
1525 else
1526 {
1527 VECTOR2D kcenter = kstart + ksize / 2;
1528
1529 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
1530 std::make_unique<PCB_REFERENCE_IMAGE>( aBoard, kcenter, klayer );
1531
1532 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1533 & ~wxImage::Load_Verbose );
1534
1535 if( bitmap->ReadImageFile( buf ) )
1536 {
1537 double scaleFactor = ScaleSize( size.x ) / bitmap->GetSize().x;
1538 bitmap->SetImageScale( scaleFactor );
1539
1540 // TODO: support non-90-deg angles
1541 bitmap->Rotate( kstart, EDA_ANGLE( angle, DEGREES_T ) );
1542
1543 if( flipped )
1544 {
1545 int x = bitmap->GetPosition().x;
1546 MIRROR( x, KiROUND( kstart.x ) );
1547 bitmap->SetX( x );
1548
1549 bitmap->MutableImage()->Mirror( false );
1550 }
1551
1552 aBoard->Add( bitmap.release(), ADD_MODE::APPEND );
1553 }
1554 }
1555 }
1556 else if( type == wxS( "STRING" ) )
1557 {
1558 wxString uuid = line.at( 1 );
1559
1560 // if( line.at( 2 ).is_number() )
1561 // int unk = line.at( 2 ).get<int>();
1562 // else if( line.at( 2 ).is_string() )
1563 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1564
1565 int layer = line.at( 3 ).get<int>();
1566 PCB_LAYER_ID klayer = LayerToKi( layer );
1567
1568 VECTOR2D location( line.at( 4 ), line.at( 5 ) );
1569 wxString string = line.at( 6 );
1570 wxString font = line.at( 7 );
1571
1572 double height = line.at( 8 );
1573 double strokew = line.at( 9 );
1574
1575 int align = line.at( 12 );
1576 double angle = line.at( 13 );
1577 int inverted = line.at( 14 );
1578 int mirror = line.at( 16 );
1579
1580 PCB_TEXT* text = new PCB_TEXT( aBoard );
1581
1582 text->SetText( string );
1583 text->SetLayer( klayer );
1584 text->SetPosition( ScalePos( location ) );
1585 text->SetIsKnockout( inverted );
1586 text->SetTextThickness( ScaleSize( strokew ) );
1587 text->SetTextSize( VECTOR2D( ScaleSize( height * 0.6 ), ScaleSize( height * 0.7 ) ) );
1588
1589 if( font != wxS( "default" ) )
1590 {
1591 text->SetFont( KIFONT::FONT::GetFont( font ) );
1592 //text->SetupRenderCache( text->GetShownText(), EDA_ANGLE( angle, DEGREES_T ) );
1593
1594 //text->AddRenderCacheGlyph();
1595 // TODO: import geometry cache
1596 }
1597
1598 AlignText( text, align );
1599
1600 if( IsBackLayer( klayer ) ^ !!mirror )
1601 {
1602 text->SetMirrored( true );
1603 text->SetTextAngleDegrees( -angle );
1604 }
1605 else
1606 {
1607 text->SetTextAngleDegrees( angle );
1608 }
1609
1610 aBoard->Add( text, ADD_MODE::APPEND );
1611 }
1612 else if( type == wxS( "COMPONENT" ) )
1613 {
1614 wxString compId = line.at( 1 );
1615 componentLines[compId].push_back( line );
1616 }
1617 else if( type == wxS( "ATTR" ) )
1618 {
1619 wxString compId = line.at( 3 );
1620 componentLines[compId].push_back( line );
1621 }
1622 else if( type == wxS( "PAD_NET" ) )
1623 {
1624 wxString compId = line.at( 1 );
1625 componentLines[compId].push_back( line );
1626 }
1627 }
1628
1629 for( auto const& [compId, lines] : componentLines )
1630 {
1631 wxString deviceId;
1632 wxString fpIdOverride;
1633 wxString fpDesignator;
1634 std::map<wxString, wxString> localCompAttribs;
1635
1636 for( auto& line : lines )
1637 {
1638 if( line.size() == 0 )
1639 continue;
1640
1641 wxString type = line.at( 0 );
1642
1643 if( type == wxS( "COMPONENT" ) )
1644 {
1645 localCompAttribs = line.at( 7 );
1646 }
1647 else if( type == wxS( "ATTR" ) )
1648 {
1649 EASYEDAPRO::PCB_ATTR attr = line;
1650
1651 if( attr.key == wxS( "Device" ) )
1652 deviceId = attr.value;
1653
1654 else if( attr.key == wxS( "Footprint" ) )
1655 fpIdOverride = attr.value;
1656
1657 else if( attr.key == wxS( "Designator" ) )
1658 fpDesignator = attr.value;
1659 }
1660 }
1661
1662 if( deviceId.empty() )
1663 continue;
1664
1665 nlohmann::json compAttrs = aProject.at( "devices" ).at( deviceId ).at( "attributes" );
1666
1667 wxString fpId;
1668
1669 if( !fpIdOverride.IsEmpty() )
1670 fpId = fpIdOverride;
1671 else
1672 fpId = compAttrs.at( "Footprint" ).get<wxString>();
1673
1674 auto it = aFootprintMap.find( fpId );
1675 if( it == aFootprintMap.end() )
1676 {
1677 wxLogError( "Footprint of '%s' with uuid '%s' not found.", fpDesignator, fpId );
1678 continue;
1679 }
1680
1681 std::unique_ptr<FOOTPRINT>& footprintOrig = it->second;
1682 std::unique_ptr<FOOTPRINT> footprint( static_cast<FOOTPRINT*>( footprintOrig->Clone() ) );
1683
1684 wxString modelUuid, modelTitle, modelTransform;
1685
1686 if( auto val = get_opt( localCompAttribs, "3D Model" ) )
1687 modelUuid = *val;
1688 else
1689 modelUuid = compAttrs.value<wxString>( "3D Model", "" );
1690
1691 if( auto val = get_opt( localCompAttribs, "3D Model Title" ) )
1692 modelTitle = val->Trim();
1693 else
1694 modelTitle = compAttrs.value<wxString>( "3D Model Title", modelUuid ).Trim();
1695
1696 if( auto val = get_opt( localCompAttribs, "3D Model Transform" ) )
1697 modelTransform = *val;
1698 else
1699 modelTransform = compAttrs.value<wxString>( "3D Model Transform", "" );
1700
1701 fillFootprintModelInfo( footprint.get(), modelUuid, modelTitle, modelTransform );
1702
1703 footprint->SetParent( aBoard );
1704
1705 for( auto& line : lines )
1706 {
1707 if( line.size() == 0 )
1708 continue;
1709
1710 wxString type = line.at( 0 );
1711
1712 if( type == wxS( "COMPONENT" ) )
1713 {
1714 int layer = line.at( 3 );
1715 PCB_LAYER_ID klayer = LayerToKi( layer );
1716
1717 VECTOR2D center( line.at( 4 ), line.at( 5 ) );
1718
1719 double orient = line.at( 6 );
1720 //std::map<wxString, wxString> props = line.at( 7 );
1721
1722 if( klayer == B_Cu )
1723 footprint->Flip( footprint->GetPosition(), false );
1724
1725 footprint->SetOrientationDegrees( orient );
1726 footprint->SetPosition( ScalePos( center ) );
1727 }
1728 else if( type == wxS( "ATTR" ) )
1729 {
1730 EASYEDAPRO::PCB_ATTR attr = line;
1731
1732 PCB_LAYER_ID klayer = LayerToKi( attr.layer );
1733
1734 PCB_TEXT* text = nullptr;
1735 bool add = false;
1736
1737 if( attr.key == wxS( "Designator" ) )
1738 {
1739 if( attr.key == wxS( "Designator" ) )
1740 {
1741 text = footprint->GetField( REFERENCE_FIELD );
1742 }
1743 else
1744 {
1745 text = new PCB_TEXT( footprint.get() );
1746 add = true;
1747 }
1748
1749 if( attr.fontName != wxS( "default" ) )
1750 text->SetFont( KIFONT::FONT::GetFont( attr.fontName ) );
1751
1752 if( attr.valVisible && attr.keyVisible )
1753 {
1754 text->SetText( attr.key + ':' + attr.value );
1755 }
1756 else if( attr.keyVisible )
1757 {
1758 text->SetText( attr.key );
1759 }
1760 else
1761 {
1762 text->SetText( attr.value );
1763 }
1764
1765 text->SetVisible( attr.keyVisible || attr.valVisible );
1766 text->SetLayer( klayer );
1767 text->SetPosition( ScalePos( attr.position ) );
1768 text->SetTextAngleDegrees( footprint->IsFlipped() ? -attr.rotation
1769 : attr.rotation );
1770 text->SetIsKnockout( attr.inverted );
1771 text->SetTextThickness( ScaleSize( attr.strokeWidth ) );
1772 text->SetTextSize( VECTOR2D( ScaleSize( attr.height * 0.55 ),
1773 ScaleSize( attr.height * 0.6 ) ) );
1774
1775 AlignText( text, attr.textOrigin );
1776
1777 if( add )
1778 footprint->Add( text, ADD_MODE::APPEND );
1779 }
1780 }
1781 else if( type == wxS( "PAD_NET" ) )
1782 {
1783 wxString padNumber = line.at( 2 );
1784 wxString padNet = line.at( 3 );
1785
1786 PAD* pad = footprint->FindPadByNumber( padNumber );
1787 if( pad )
1788 {
1789 pad->SetNet( aBoard->FindNet( padNet ) );
1790 }
1791 else
1792 {
1793 // Not a pad
1794 }
1795 }
1796 }
1797
1798 aBoard->Add( footprint.release(), ADD_MODE::APPEND );
1799 }
1800
1801 // Heal board outlines
1802 std::vector<PCB_SHAPE*> shapes;
1803 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
1804
1805 for( BOARD_ITEM* item : aBoard->Drawings() )
1806 {
1807 if( !item->IsOnLayer( Edge_Cuts ) )
1808 continue;
1809
1810 if( item->Type() == PCB_SHAPE_T )
1811 shapes.push_back( static_cast<PCB_SHAPE*>( item ) );
1812 }
1813
1814 ConnectBoardShapes( shapes, newShapes, SHAPE_JOIN_DISTANCE );
1815
1816 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
1817 aBoard->Add( ptr.release(), ADD_MODE::APPEND );
1818
1819 // Center the board
1820 BOX2I outlineBbox = aBoard->ComputeBoundingBox( true );
1821 PAGE_INFO pageInfo = aBoard->GetPageSettings();
1822
1823 VECTOR2D pageCenter( pcbIUScale.MilsToIU( pageInfo.GetWidthMils() / 2 ),
1824 pcbIUScale.MilsToIU( pageInfo.GetHeightMils() / 2 ) );
1825
1826 VECTOR2D offset = pageCenter - outlineBbox.GetCenter();
1827
1828 int alignGrid = pcbIUScale.mmToIU( 10 );
1829 offset.x = KiROUND( offset.x / alignGrid ) * alignGrid;
1830 offset.y = KiROUND( offset.y / alignGrid ) * alignGrid;
1831
1832 aBoard->Move( offset );
1833 bds.SetAuxOrigin( offset );
1834}
constexpr int ARC_HIGH_DEF
Definition: base_units.h:120
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
constexpr int ARC_LOW_DEF
Definition: base_units.h:119
Bezier curves to polygon converter.
Definition: bezier_curves.h:38
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMinSegLen=0, int aMaxSegCount=32)
Convert a Bezier curve to a polygon.
Container for design settings for a BOARD object.
void SetAuxOrigin(const VECTOR2I &aOrigin)
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:77
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:680
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:882
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:700
const PAGE_INFO & GetPageSettings() const
Definition: board.h:671
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
Definition: board.cpp:1810
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition: board.cpp:583
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: board.cpp:493
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1555
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:797
unsigned GetNetCount() const
Definition: board.h:884
const DRAWINGS & Drawings() const
Definition: board.h:325
const Vec & GetOrigin() const
Definition: box2.h:200
const SizeVec & GetSize() const
Definition: box2.h:196
const Vec GetCenter() const
Definition: box2.h:220
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:623
EDA_ANGLE Normalize90()
Definition: eda_angle.h:283
double AsDegrees() const
Definition: eda_angle.h:155
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:83
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:245
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:183
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: footprint.h:706
PCB_FIELD * GetFieldByName(const wxString &aFieldName)
Return a field in this symbol.
Definition: footprint.cpp:538
PCB_FIELD * AddField(const PCB_FIELD &aField)
Add a field to the symbol.
Definition: footprint.cpp:580
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:968
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:205
PCB_FIELDS & Fields()
Definition: footprint.h:188
PCB_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: footprint.cpp:504
DRAWINGS & GraphicalItems()
Definition: footprint.h:194
VECTOR3D m_Offset
3D model offset (mm)
Definition: footprint.h:98
VECTOR3D m_Rotation
3D model rotation (degrees)
Definition: footprint.h:97
wxString m_Filename
The 3D shape filename in 3D library.
Definition: footprint.h:100
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
Definition: font.cpp:146
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
Handle the data for a net.
Definition: netinfo.h:56
Definition: pad.h:59
static LSET PTHMask()
layer set for a through hole pad
Definition: pad.cpp:349
static LSET SMDMask()
layer set for a SMD pad on Front layer
Definition: pad.cpp:356
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition: page_info.h:59
double GetHeightMils() const
Definition: page_info.h:141
double GetWidthMils() const
Definition: page_info.h:136
SHAPE_LINE_CHAIN ParseContour(nlohmann::json polyData, bool aInFill, double aArcAccuracy=SHAPE_ARC::DefaultAccuracyForPCB()) const
static VECTOR2< T > ScalePos(VECTOR2< T > aValue)
PCB_IO_EASYEDAPRO_PARSER(BOARD *aBoard, PROGRESS_REPORTER *aProgressReporter)
std::vector< std::unique_ptr< PCB_SHAPE > > ParsePoly(BOARD_ITEM_CONTAINER *aContainer, nlohmann::json polyData, bool aClosed, bool aInFill) 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)
FOOTPRINT * ParseFootprint(const nlohmann::json &aProject, const wxString &aFpUuid, const std::vector< nlohmann::json > &aLines)
static double Convert(wxString aValue)
void fillFootprintModelInfo(FOOTPRINT *footprint, const wxString &modelUuid, const wxString &modelTitle, const wxString &modelTransform) const
A progress reporter interface for use in multi-threaded environments.
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
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.
Definition: shape_arc.cpp:212
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.
SEG Segment(int aIndex) const
Return a copy of the aIndex-th segment in the line chain.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the 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 BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
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 BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset union For aFastMode meaning, see function booleanOp.
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)
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
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.
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
Definition: shape_rect.h:179
T y
Definition: vector3.h:63
T z
Definition: vector3.h:64
T x
Definition: vector3.h:62
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.
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:437
@ DEGREES_T
Definition: eda_angle.h:31
void ConnectBoardShapes(std::vector< PCB_SHAPE * > &aShapeList, std::vector< std::unique_ptr< PCB_SHAPE > > &aNewShapes, int aChainingEpsilon)
Connects shapes to each other, making continious contours (adjacent shapes will have a common vertex)...
@ ERROR_INSIDE
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
Definition: layer_ids.h:978
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ In22_Cu
Definition: layer_ids.h:86
@ In11_Cu
Definition: layer_ids.h:75
@ In29_Cu
Definition: layer_ids.h:93
@ In30_Cu
Definition: layer_ids.h:94
@ In17_Cu
Definition: layer_ids.h:81
@ Edge_Cuts
Definition: layer_ids.h:113
@ Dwgs_User
Definition: layer_ids.h:109
@ F_Paste
Definition: layer_ids.h:101
@ In9_Cu
Definition: layer_ids.h:73
@ Cmts_User
Definition: layer_ids.h:110
@ User_6
Definition: layer_ids.h:128
@ User_7
Definition: layer_ids.h:129
@ In19_Cu
Definition: layer_ids.h:83
@ In7_Cu
Definition: layer_ids.h:71
@ In28_Cu
Definition: layer_ids.h:92
@ In26_Cu
Definition: layer_ids.h:90
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ User_5
Definition: layer_ids.h:127
@ F_Mask
Definition: layer_ids.h:107
@ In21_Cu
Definition: layer_ids.h:85
@ In23_Cu
Definition: layer_ids.h:87
@ B_Paste
Definition: layer_ids.h:100
@ In15_Cu
Definition: layer_ids.h:79
@ In2_Cu
Definition: layer_ids.h:66
@ F_Fab
Definition: layer_ids.h:120
@ In10_Cu
Definition: layer_ids.h:74
@ F_SilkS
Definition: layer_ids.h:104
@ In4_Cu
Definition: layer_ids.h:68
@ Eco2_User
Definition: layer_ids.h:112
@ In16_Cu
Definition: layer_ids.h:80
@ In24_Cu
Definition: layer_ids.h:88
@ In1_Cu
Definition: layer_ids.h:65
@ User_3
Definition: layer_ids.h:125
@ User_1
Definition: layer_ids.h:123
@ B_SilkS
Definition: layer_ids.h:103
@ In13_Cu
Definition: layer_ids.h:77
@ User_4
Definition: layer_ids.h:126
@ In8_Cu
Definition: layer_ids.h:72
@ In14_Cu
Definition: layer_ids.h:78
@ User_2
Definition: layer_ids.h:124
@ In12_Cu
Definition: layer_ids.h:76
@ In27_Cu
Definition: layer_ids.h:91
@ In6_Cu
Definition: layer_ids.h:70
@ In5_Cu
Definition: layer_ids.h:69
@ In3_Cu
Definition: layer_ids.h:67
@ In20_Cu
Definition: layer_ids.h:84
@ F_Cu
Definition: layer_ids.h:64
@ In18_Cu
Definition: layer_ids.h:82
@ In25_Cu
Definition: layer_ids.h:89
@ B_Fab
Definition: layer_ids.h:119
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount)
Calculate the mask layer when flipping a footprint.
Definition: lset.cpp:680
wxString get_def(const std::map< wxString, wxString > &aMap, const char *aKey, const char *aDefval="")
Definition: map_helpers.h:64
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
Definition: map_helpers.h:34
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
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:424
@ PAD_DRILL_SHAPE_OBLONG
Definition: pad_shapes.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 MODEL_SIZE_KEY
static const int SHAPE_JOIN_DISTANCE
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:...
nlohmann::json polyData
constexpr double IUTomm(int iu) const
Definition: base_units.h:86
constexpr int MilsToIU(int mils) const
Definition: base_units.h:93
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
constexpr 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
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:228
double DEG2RAD(double deg)
Definition: trigo.h:200
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:88
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118
VECTOR2< double > VECTOR2D
Definition: vector2d.h:587
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588