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 wxString holeShape = padHole.at( 0 );
629
630 if( holeShape == wxS( "ROUND" ) || holeShape == wxS( "SLOT" ) )
631 {
632 VECTOR2D drill;
633 drill.x = padHole.at( 1 );
634 drill.y = padHole.at( 2 );
635
636 double deg = EDA_ANGLE( drill_dir, DEGREES_T ).Normalize90().AsDegrees();
637
638 if( std::abs( deg ) >= 45 )
639 std::swap( drill.x, drill.y ); // KiCad doesn't support arbitrary hole direction
640
641 if( holeShape == wxS( "SLOT" ) )
642 {
643 pad->SetDrillShape( PAD_DRILL_SHAPE::OBLONG );
644 }
645
646 pad->SetDrillSize( ScaleSize( drill ) );
647 pad->SetLayerSet( PAD::PTHMask() );
648 pad->SetAttribute( PAD_ATTRIB::PTH );
649 }
650 }
651 else
652 {
653 if( klayer == F_Cu )
654 {
655 pad->SetLayerSet( PAD::SMDMask() );
656 }
657 else if( klayer == B_Cu )
658 {
659 pad->SetLayerSet( FlipLayerMask( PAD::SMDMask() ) );
660 }
661
662 pad->SetAttribute( PAD_ATTRIB::SMD );
663 }
664
665 wxString padSh = padShape.at( 0 );
666 if( padSh == wxS( "RECT" ) )
667 {
668 VECTOR2D size;
669 size.x = padShape.at( 1 );
670 size.y = padShape.at( 2 );
671 double cr_p = padShape.size() > 3 ? padShape.at( 3 ).get<double>() : 0;
672
673 pad->SetSize( ScaleSize( size ) );
674
675 if( cr_p == 0 )
676 {
677 pad->SetShape( PAD_SHAPE::RECTANGLE );
678 }
679 else
680 {
681 pad->SetShape( PAD_SHAPE::ROUNDRECT );
682 pad->SetRoundRectRadiusRatio( cr_p / 100 );
683 }
684 }
685 else if( padSh == wxS( "ELLIPSE" ) )
686 {
687 VECTOR2D size;
688 size.x = padShape.at( 1 );
689 size.y = padShape.at( 2 );
690
691 pad->SetSize( ScaleSize( size ) );
692 pad->SetShape( PAD_SHAPE::CIRCLE );
693 }
694 else if( padSh == wxS( "OVAL" ) )
695 {
696 VECTOR2D size;
697 size.x = padShape.at( 1 );
698 size.y = padShape.at( 2 );
699
700 pad->SetSize( ScaleSize( size ) );
701 pad->SetShape( PAD_SHAPE::OVAL );
702 }
703 else if( padSh == wxS( "POLY" ) )
704 {
705 pad->SetShape( PAD_SHAPE::CUSTOM );
706 pad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
707 pad->SetSize( { 1, 1 } );
708
709 nlohmann::json polyData = padShape.at( 1 );
710
711 std::vector<std::unique_ptr<PCB_SHAPE>> results =
712 ParsePoly( aFootprint, polyData, true, false );
713
714 for( auto& shape : results )
715 {
716 shape->SetLayer( klayer );
717 shape->SetWidth( 0 );
718
719 shape->Move( -pad->GetPosition() );
720
721 pad->AddPrimitive( shape.release() );
722 }
723 }
724
725 pad->SetThermalSpokeAngle( ANGLE_90 );
726
727 return std::move( pad );
728}
729
730
732 const wxString& aFpUuid,
733 const std::vector<nlohmann::json>& aLines )
734{
735 std::unique_ptr<FOOTPRINT> footprintPtr = std::make_unique<FOOTPRINT>( m_board );
736 FOOTPRINT* footprint = footprintPtr.get();
737
738 const VECTOR2I defaultTextSize( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) );
739 const int defaultTextThickness( pcbIUScale.mmToIU( 0.15 ) );
740
741 for( PCB_FIELD* field : footprint->Fields() )
742 {
743 field->SetTextSize( defaultTextSize );
744 field->SetTextThickness( defaultTextThickness );
745 }
746
747 for( const nlohmann::json& line : aLines )
748 {
749 if( line.size() == 0 )
750 continue;
751
752 wxString type = line.at( 0 );
753
754 if( type == wxS( "POLY" ) || type == wxS( "PAD" ) || type == wxS( "FILL" )
755 || type == wxS( "ATTR" ) )
756 {
757 wxString uuid = line.at( 1 );
758
759 // if( line.at( 2 ).is_number() )
760 // int unk = line.at( 2 ).get<int>();
761 // else if( line.at( 2 ).is_string() )
762 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
763
764 wxString netname = line.at( 3 );
765 int layer = line.at( 4 ).get<int>();
766 PCB_LAYER_ID klayer = LayerToKi( layer );
767
768 if( type == wxS( "POLY" ) )
769 {
770 double thickness = ( line.at( 5 ) );
771 nlohmann::json polyData = line.at( 6 );
772
773 std::vector<std::unique_ptr<PCB_SHAPE>> results =
774 ParsePoly( footprint, polyData, false, false );
775
776 for( auto& shape : results )
777 {
778 shape->SetLayer( klayer );
779 shape->SetWidth( ScaleSize( thickness ) );
780
781 footprint->Add( shape.release(), ADD_MODE::APPEND );
782 }
783 }
784 else if( type == wxS( "PAD" ) )
785 {
786 std::unique_ptr<PAD> pad = createPAD( footprint, line );
787
788 footprint->Add( pad.release(), ADD_MODE::APPEND );
789 }
790 else if( type == wxS( "FILL" ) )
791 {
792 int layer = line.at( 4 ).get<int>();
793 PCB_LAYER_ID klayer = LayerToKi( layer );
794
795 double width = line.at( 5 );
796
797 nlohmann::json polyDataList = line.at( 7 );
798
799 if( !polyDataList.at( 0 ).is_array() )
800 polyDataList = nlohmann::json::array( { polyDataList } );
801
802 std::vector<SHAPE_LINE_CHAIN> contours;
803 for( nlohmann::json& polyData : polyDataList )
804 {
805 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
806 contour.SetClosed( true );
807
808 contours.push_back( contour );
809 }
810
811 SHAPE_POLY_SET polySet;
812
813 for( SHAPE_LINE_CHAIN& contour : contours )
814 polySet.AddOutline( contour );
815
816 polySet.RebuildHolesFromContours();
817
818 std::unique_ptr<PCB_GROUP> group;
819
820 if( polySet.OutlineCount() > 1 )
821 group = std::make_unique<PCB_GROUP>( footprint );
822
823 BOX2I polyBBox = polySet.BBox();
824
825 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
826 {
827 std::unique_ptr<PCB_SHAPE> shape =
828 std::make_unique<PCB_SHAPE>( footprint, SHAPE_T::POLY );
829
830 shape->SetFilled( true );
831 shape->SetPolyShape( poly );
832 shape->SetLayer( klayer );
833 shape->SetWidth( 0 );
834
835 if( group )
836 group->AddItem( shape.get() );
837
838 footprint->Add( shape.release(), ADD_MODE::APPEND );
839 }
840
841 if( group )
842 footprint->Add( group.release(), ADD_MODE::APPEND );
843 }
844 else if( type == wxS( "ATTR" ) )
845 {
846 EASYEDAPRO::PCB_ATTR attr = line;
847
848 if( attr.key == wxS( "Designator" ) )
849 footprint->GetField( REFERENCE_FIELD )->SetText( attr.value );
850 }
851 }
852 else if( type == wxS( "REGION" ) )
853 {
854 wxString uuid = line.at( 1 );
855
856 // if( line.at( 2 ).is_number() )
857 // int unk = line.at( 2 ).get<int>();
858 // else if( line.at( 2 ).is_string() )
859 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
860
861 int layer = line.at( 3 ).get<int>();
862 PCB_LAYER_ID klayer = LayerToKi( layer );
863
864 double width = line.at( 4 );
865 std::set<int> flags = line.at( 5 );
866 nlohmann::json polyDataList = line.at( 6 );
867
868 for( nlohmann::json& polyData : polyDataList )
869 {
870 SHAPE_POLY_SET polySet;
871
872 std::vector<std::unique_ptr<PCB_SHAPE>> results =
873 ParsePoly( nullptr, polyData, true, false );
874
875 for( auto& shape : results )
876 {
877 shape->SetFilled( true );
878 shape->TransformShapeToPolygon( polySet, klayer, 0, ARC_HIGH_DEF, ERROR_INSIDE,
879 true );
880 }
881
883
884 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( footprint );
885
886 zone->SetIsRuleArea( true );
887 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
888 zone->SetDoNotAllowCopperPour( !!flags.count( 7 ) || !!flags.count( 6 )
889 || !!flags.count( 8 ) );
890 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
891 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
892 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
893
894 zone->SetLayer( klayer );
895 zone->Outline()->Append( polySet );
896
897 footprint->Add( zone.release(), ADD_MODE::APPEND );
898 }
899 }
900 }
901
902 if( aProject.is_object() )
903 {
904 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at( "devices" );
905 std::map<wxString, wxString> compAttrs;
906
907 for( auto& [devUuid, devData] : devicesMap )
908 {
909 if( auto fp = get_opt( devData.attributes, "Footprint" ) )
910 {
911 if( *fp == aFpUuid )
912 {
913 compAttrs = devData.attributes;
914 break;
915 }
916 }
917 }
918
919 wxString modelUuid, modelTitle, modelTransform;
920
921 modelUuid = get_def( compAttrs, "3D Model", "" );
922 modelTitle = get_def( compAttrs, "3D Model Title", modelUuid );
923 modelTransform = get_def( compAttrs, "3D Model Transform", "" );
924
925 fillFootprintModelInfo( footprint, modelUuid, modelTitle, modelTransform );
926 }
927
928 // Heal board outlines
929 std::vector<PCB_SHAPE*> shapes;
930 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
931
932 for( BOARD_ITEM* item : footprint->GraphicalItems() )
933 {
934 if( !item->IsOnLayer( Edge_Cuts ) )
935 continue;
936
937 if( item->Type() == PCB_SHAPE_T )
938 shapes.push_back( static_cast<PCB_SHAPE*>( item ) );
939 }
940
941 ConnectBoardShapes( shapes, newShapes, SHAPE_JOIN_DISTANCE );
942
943 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
944 footprint->Add( ptr.release(), ADD_MODE::APPEND );
945
946 return footprintPtr.release();
947}
948
949
951 BOARD* aBoard, const nlohmann::json& aProject,
952 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
953 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
954 const std::multimap<wxString, EASYEDAPRO::POURED>& aPouredMap,
955 const std::vector<nlohmann::json>& aLines, const wxString& aFpLibName )
956{
957 std::map<wxString, std::vector<nlohmann::json>> componentLines;
958 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
959
961
962 for( const nlohmann::json& line : aLines )
963 {
964 if( line.size() == 0 )
965 continue;
966
967 wxString type = line.at( 0 );
968
969 if( type == wxS( "LAYER" ) )
970 {
971 int layer = line.at( 1 );
972 PCB_LAYER_ID klayer = LayerToKi( layer );
973
974 wxString layerType = line.at( 2 );
975 wxString layerName = line.at( 3 );
976 int layerFlag = line.at( 4 );
977
978 if( layerFlag != 0 )
979 {
980 LSET blayers = aBoard->GetEnabledLayers();
981 blayers.set( klayer );
982 aBoard->SetEnabledLayers( blayers );
983 aBoard->SetLayerName( klayer, layerName );
984 }
985 }
986 else if( type == wxS( "NET" ) )
987 {
988 wxString netname = line.at( 1 );
989
990 aBoard->Add( new NETINFO_ITEM( aBoard, netname, aBoard->GetNetCount() + 1 ),
991 ADD_MODE::APPEND );
992 }
993 else if( type == wxS( "RULE" ) )
994 {
995 wxString ruleType = line.at( 1 );
996 wxString ruleName = line.at( 2 );
997 int isDefault = line.at( 3 );
998 nlohmann::json ruleData = line.at( 4 );
999
1000 if( ruleType == wxS( "3" ) && isDefault ) // Track width
1001 {
1002 wxString units = ruleData.at( 0 );
1003 double minVal = ruleData.at( 1 );
1004 double optVal = ruleData.at( 2 );
1005 double maxVal = ruleData.at( 3 );
1006
1007 bds.m_TrackMinWidth = ScaleSize( minVal );
1008 }
1009 else if( ruleType == wxS( "1" ) && isDefault )
1010 {
1011 wxString units = ruleData.at( 0 );
1012 nlohmann::json table = ruleData.at( 1 );
1013
1014 int minVal = INT_MAX;
1015 for( const std::vector<int>& arr : table )
1016 {
1017 for( int val : arr )
1018 {
1019 if( val < minVal )
1020 minVal = val;
1021 }
1022 }
1023
1024 bds.m_MinClearance = ScaleSize( minVal );
1025 }
1026
1027 ruleLines[ruleType].push_back( line );
1028 }
1029 else if( type == wxS( "VIA" ) || type == wxS( "LINE" ) || type == wxS( "ARC" )
1030 || type == wxS( "POLY" ) || type == wxS( "FILL" ) || type == wxS( "POUR" ) )
1031 {
1032 wxString uuid = line.at( 1 );
1033
1034 // if( line.at( 2 ).is_number() )
1035 // int unk = line.at( 2 ).get<int>();
1036 // else if( line.at( 2 ).is_string() )
1037 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1038
1039 wxString netname = line.at( 3 );
1040
1041 if( type == wxS( "VIA" ) )
1042 {
1043 VECTOR2D center;
1044 center.x = line.at( 5 );
1045 center.y = line.at( 6 );
1046
1047 double drill = line.at( 7 );
1048 double dia = line.at( 8 );
1049
1050 std::unique_ptr<PCB_VIA> via = std::make_unique<PCB_VIA>( aBoard );
1051
1052 via->SetPosition( ScalePos( center ) );
1053 via->SetDrill( ScaleSize( drill ) );
1054 via->SetWidth( ScaleSize( dia ) );
1055
1056 via->SetNet( aBoard->FindNet( netname ) );
1057
1058 aBoard->Add( via.release(), ADD_MODE::APPEND );
1059 }
1060 else if( type == wxS( "LINE" ) )
1061 {
1062 int layer = line.at( 4 ).get<int>();
1063 PCB_LAYER_ID klayer = LayerToKi( layer );
1064
1065 VECTOR2D start;
1066 start.x = line.at( 5 );
1067 start.y = line.at( 6 );
1068
1069 VECTOR2D end;
1070 end.x = line.at( 7 );
1071 end.y = line.at( 8 );
1072
1073 double width = line.at( 9 );
1074
1075 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( aBoard );
1076
1077 track->SetLayer( klayer );
1078 track->SetStart( ScalePos( start ) );
1079 track->SetEnd( ScalePos( end ) );
1080 track->SetWidth( ScaleSize( width ) );
1081
1082 track->SetNet( aBoard->FindNet( netname ) );
1083
1084 aBoard->Add( track.release(), ADD_MODE::APPEND );
1085 }
1086 else if( type == wxS( "ARC" ) )
1087 {
1088 int layer = line.at( 4 ).get<int>();
1089 PCB_LAYER_ID klayer = LayerToKi( layer );
1090
1091 VECTOR2D start;
1092 start.x = line.at( 5 );
1093 start.y = line.at( 6 );
1094
1095 VECTOR2D end;
1096 end.x = line.at( 7 );
1097 end.y = line.at( 8 );
1098
1099 double angle = line.at( 9 );
1100 double width = line.at( 10 );
1101
1102 VECTOR2D delta = end - start;
1103 VECTOR2D mid = ( start + delta / 2 );
1104
1105 double ha = angle / 2;
1106 double hd = delta.EuclideanNorm() / 2;
1107 double cdist = hd / tan( DEG2RAD( ha ) );
1108 VECTOR2D center = mid + delta.Perpendicular().Resize( cdist );
1109
1110 SHAPE_ARC sarc;
1111 sarc.ConstructFromStartEndCenter( ScalePos( start ), ScalePos( end ),
1112 ScalePos( center ), angle >= 0, width );
1113
1114 std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( aBoard, &sarc );
1115 arc->SetWidth( ScaleSize( width ) );
1116
1117 arc->SetLayer( klayer );
1118 arc->SetNet( aBoard->FindNet( netname ) );
1119
1120 aBoard->Add( arc.release(), ADD_MODE::APPEND );
1121 }
1122 else if( type == wxS( "FILL" ) )
1123 {
1124 int layer = line.at( 4 ).get<int>();
1125 PCB_LAYER_ID klayer = LayerToKi( layer );
1126
1127 double width = line.at( 5 );
1128
1129 nlohmann::json polyDataList = line.at( 7 );
1130
1131 if( !polyDataList.at( 0 ).is_array() )
1132 polyDataList = nlohmann::json::array( { polyDataList } );
1133
1134 std::vector<SHAPE_LINE_CHAIN> contours;
1135 for( nlohmann::json& polyData : polyDataList )
1136 {
1137 SHAPE_LINE_CHAIN contour = ParseContour( polyData, true );
1138 contour.SetClosed( true );
1139
1140 contours.push_back( contour );
1141 }
1142
1143 SHAPE_POLY_SET zoneFillPoly;
1144
1145 for( SHAPE_LINE_CHAIN& contour : contours )
1146 zoneFillPoly.AddOutline( contour );
1147
1148 zoneFillPoly.RebuildHolesFromContours();
1150
1151 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1152
1153 zone->SetNet( aBoard->FindNet( netname ) );
1154 zone->SetLayer( klayer );
1155 zone->Outline()->Append( SHAPE_RECT( zoneFillPoly.BBox() ).Outline() );
1156 zone->SetFilledPolysList( klayer, zoneFillPoly );
1157 zone->SetAssignedPriority( 500 );
1158 zone->SetIsFilled( true );
1159 zone->SetNeedRefill( false );
1160
1161 zone->SetLocalClearance( bds.m_MinClearance );
1162 zone->SetMinThickness( bds.m_TrackMinWidth );
1163
1164 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1165 }
1166 else if( type == wxS( "POLY" ) )
1167 {
1168 int layer = line.at( 4 );
1169 PCB_LAYER_ID klayer = LayerToKi( layer );
1170
1171 double thickness = line.at( 5 );
1172 nlohmann::json polyData = line.at( 6 );
1173
1174 std::vector<std::unique_ptr<PCB_SHAPE>> results =
1175 ParsePoly( aBoard, polyData, false, false );
1176
1177 for( auto& shape : results )
1178 {
1179 shape->SetLayer( klayer );
1180 shape->SetWidth( ScaleSize( thickness ) );
1181
1182 aBoard->Add( shape.release(), ADD_MODE::APPEND );
1183 }
1184 }
1185 else if( type == wxS( "POUR" ) )
1186 {
1187 int layer = line.at( 4 ).get<int>();
1188 PCB_LAYER_ID klayer = LayerToKi( layer );
1189
1190 double lineWidth = line.at( 5 ); // Doesn't matter
1191 wxString pourname = line.at( 6 );
1192 int fillOrder = line.at( 7 ).get<int>();
1193 nlohmann::json polyDataList = line.at( 8 );
1194
1195 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1196
1197 zone->SetNet( aBoard->FindNet( netname ) );
1198 zone->SetLayer( klayer );
1199 zone->SetAssignedPriority( 500 - fillOrder );
1200 zone->SetLocalClearance( bds.m_MinClearance );
1201 zone->SetMinThickness( bds.m_TrackMinWidth );
1202
1203 for( nlohmann::json& polyData : polyDataList )
1204 {
1205 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1206 contour.SetClosed( true );
1207
1208 zone->Outline()->Append( contour );
1209 }
1210
1211 wxASSERT( zone->Outline()->OutlineCount() == 1 );
1212
1213 SHAPE_POLY_SET fillPolySet;
1214 SHAPE_POLY_SET thermalSpokes;
1215 int entryId = 0;
1216
1218 {
1219 auto range = aPouredMap.equal_range( uuid );
1220 for( auto& it = range.first; it != range.second; ++it )
1221 {
1222 const EASYEDAPRO::POURED& poured = it->second;
1223 int unki = poured.unki;
1224
1225 SHAPE_POLY_SET thisPoly;
1226
1227 for( int dataId = 0; dataId < poured.polyData.size(); dataId++ )
1228 {
1229 const nlohmann::json& fillData = poured.polyData[dataId];
1230 const double ptScale = 10;
1231
1232 SHAPE_LINE_CHAIN contour =
1233 ParseContour( fillData, false, ARC_HIGH_DEF / ptScale );
1234
1235 // Scale the fill
1236 for( int i = 0; i < contour.PointCount(); i++ )
1237 contour.SetPoint( i, contour.GetPoint( i ) * ptScale );
1238
1239 if( poured.isPoly )
1240 {
1241 contour.SetClosed( true );
1242
1243 // The contour can be self-intersecting
1244 SHAPE_POLY_SET simple( contour );
1246
1247 if( dataId == 0 )
1248 {
1249 thisPoly.Append( simple );
1250 }
1251 else
1252 {
1253 thisPoly.BooleanSubtract( simple,
1255 }
1256 }
1257 else
1258 {
1259 const int thermalWidth = pcbIUScale.mmToIU( 0.2 ); // Generic
1260
1261 for( int segId = 0; segId < contour.SegmentCount(); segId++ )
1262 {
1263 const SEG& seg = contour.CSegment( segId );
1264
1265 TransformOvalToPolygon( thermalSpokes, seg.A, seg.B,
1266 thermalWidth, ARC_LOW_DEF,
1267 ERROR_INSIDE );
1268 }
1269 }
1270 }
1271
1272 fillPolySet.Append( thisPoly );
1273
1274 entryId++;
1275 }
1276
1277 if( !fillPolySet.IsEmpty() )
1278 {
1280
1281 const int strokeWidth = pcbIUScale.MilsToIU( 8 ); // Seems to be 8 mils
1282
1283 fillPolySet.Inflate( strokeWidth / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
1284 ARC_HIGH_DEF, false );
1285
1286 fillPolySet.BooleanAdd( thermalSpokes, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
1287
1289
1290 zone->SetFilledPolysList( klayer, fillPolySet );
1291 zone->SetNeedRefill( false );
1292 zone->SetIsFilled( true );
1293 }
1294 }
1295
1296 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1297 }
1298 }
1299 else if( type == wxS( "TEARDROP" ) )
1300 {
1301 wxString uuid = line.at( 1 );
1302 wxString netname = line.at( 2 );
1303 int layer = line.at( 3 ).get<int>();
1304 PCB_LAYER_ID klayer = LayerToKi( layer );
1305
1306 nlohmann::json polyData = line.at( 4 );
1307
1308 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1309 contour.SetClosed( true );
1310
1311 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1312
1313 zone->SetNet( aBoard->FindNet( netname ) );
1314 zone->SetLayer( klayer );
1315 zone->Outline()->Append( contour );
1316 zone->SetFilledPolysList( klayer, contour );
1317 zone->SetNeedRefill( false );
1318 zone->SetIsFilled( true );
1319
1320 zone->SetAssignedPriority( 600 );
1321 zone->SetLocalClearance( 0 );
1322 zone->SetMinThickness( 0 );
1323 zone->SetTeardropAreaType( TEARDROP_TYPE::TD_UNSPECIFIED );
1324
1325 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1326 }
1327 else if( type == wxS( "REGION" ) )
1328 {
1329 wxString uuid = line.at( 1 );
1330
1331 // if( line.at( 2 ).is_number() )
1332 // int unk = line.at( 2 ).get<int>();
1333 // else if( line.at( 2 ).is_string() )
1334 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1335
1336 int layer = line.at( 3 ).get<int>();
1337 PCB_LAYER_ID klayer = LayerToKi( layer );
1338
1339 double width = line.at( 4 );
1340 std::set<int> flags = line.at( 5 );
1341 nlohmann::json polyDataList = line.at( 6 );
1342
1343 for( nlohmann::json& polyData : polyDataList )
1344 {
1345 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1346 contour.SetClosed( true );
1347
1348 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1349
1350 zone->SetIsRuleArea( true );
1351 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1352 zone->SetDoNotAllowCopperPour( !!flags.count( 7 ) || !!flags.count( 6 )
1353 || !!flags.count( 8 ) );
1354 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1355 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1356 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1357
1358 zone->SetLayer( klayer );
1359 zone->Outline()->Append( contour );
1360
1361 aBoard->Add( zone.release(), ADD_MODE::APPEND );
1362 }
1363 }
1364 else if( type == wxS( "PAD" ) )
1365 {
1366 wxString netname = line.at( 3 );
1367
1368 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aBoard );
1369 std::unique_ptr<PAD> pad = createPAD( footprint.get(), line );
1370
1371 pad->SetNet( aBoard->FindNet( netname ) );
1372
1373 VECTOR2I pos = pad->GetPosition();
1374 EDA_ANGLE orient = pad->GetOrientation();
1375
1376 pad->SetPosition( VECTOR2I() );
1377 pad->SetOrientation( ANGLE_0 );
1378
1379 footprint->Add( pad.release(), ADD_MODE::APPEND );
1380 footprint->SetPosition( pos );
1381 footprint->SetOrientation( orient );
1382
1383 wxString fpName = wxS( "Pad_" ) + line.at( 1 ).get<wxString>();
1384 LIB_ID fpID = EASYEDAPRO::ToKiCadLibID( wxEmptyString, fpName );
1385
1386 footprint->SetFPID( fpID );
1387 footprint->Reference().SetVisible( true );
1388 footprint->Value().SetVisible( true );
1389 footprint->AutoPositionFields();
1390
1391 aBoard->Add( footprint.release(), ADD_MODE::APPEND );
1392 }
1393 else if( type == wxS( "IMAGE" ) )
1394 {
1395 wxString uuid = line.at( 1 );
1396
1397 // if( line.at( 2 ).is_number() )
1398 // int unk = line.at( 2 ).get<int>();
1399 // else if( line.at( 2 ).is_string() )
1400 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1401
1402 int layer = line.at( 3 ).get<int>();
1403 PCB_LAYER_ID klayer = LayerToKi( layer );
1404
1405 VECTOR2D start( line.at( 4 ), line.at( 5 ) );
1406 VECTOR2D size( line.at( 6 ), line.at( 7 ) );
1407
1408 double angle = line.at( 8 ); // from top left corner
1409 int mirror = line.at( 9 );
1410 nlohmann::json polyDataList = line.at( 10 );
1411
1412 BOX2I bbox;
1413 std::vector<SHAPE_LINE_CHAIN> contours;
1414 for( nlohmann::json& polyData : polyDataList )
1415 {
1416 SHAPE_LINE_CHAIN contour = ParseContour( polyData, false );
1417 contour.SetClosed( true );
1418
1419 contours.push_back( contour );
1420
1421 bbox.Merge( contour.BBox() );
1422 }
1423
1424 VECTOR2D scale( ScaleSize( size.x ) / bbox.GetSize().x,
1425 ScaleSize( size.y ) / bbox.GetSize().y );
1426
1427 SHAPE_POLY_SET polySet;
1428
1429 for( SHAPE_LINE_CHAIN& contour : contours )
1430 {
1431 for( int i = 0; i < contour.PointCount(); i++ )
1432 {
1433 VECTOR2I pt = contour.CPoint( i );
1434 contour.SetPoint( i, VECTOR2I( pt.x * scale.x, pt.y * scale.y ) );
1435 }
1436
1437 polySet.AddOutline( contour );
1438 }
1439
1440 polySet.RebuildHolesFromContours();
1441
1442 std::unique_ptr<PCB_GROUP> group;
1443
1444 if( polySet.OutlineCount() > 1 )
1445 group = std::make_unique<PCB_GROUP>( aBoard );
1446
1447 BOX2I polyBBox = polySet.BBox();
1448
1449 for( const SHAPE_POLY_SET::POLYGON& poly : polySet.CPolygons() )
1450 {
1451 std::unique_ptr<PCB_SHAPE> shape =
1452 std::make_unique<PCB_SHAPE>( aBoard, SHAPE_T::POLY );
1453
1454 shape->SetFilled( true );
1455 shape->SetPolyShape( poly );
1456 shape->SetLayer( klayer );
1457 shape->SetWidth( 0 );
1458
1459 shape->Move( ScalePos( start ) - polyBBox.GetOrigin() );
1460 shape->Rotate( ScalePos( start ), EDA_ANGLE( angle, DEGREES_T ) );
1461
1462 if( IsBackLayer( klayer ) ^ !!mirror )
1463 shape->Mirror( ScalePos( start ), !IsBackLayer( klayer ) );
1464
1465 if( group )
1466 group->AddItem( shape.get() );
1467
1468 aBoard->Add( shape.release(), ADD_MODE::APPEND );
1469 }
1470
1471 if( group )
1472 aBoard->Add( group.release(), ADD_MODE::APPEND );
1473 }
1474 else if( type == wxS( "OBJ" ) )
1475 {
1476 VECTOR2D start, size;
1477 wxString mimeType, base64Data;
1478 double angle = 0;
1479 int flipped = 0;
1480
1481 if( !line.at( 3 ).is_number() )
1482 continue;
1483
1484 int layer = line.at( 3 ).get<int>();
1485 PCB_LAYER_ID klayer = LayerToKi( layer );
1486
1487 start = VECTOR2D( line.at( 5 ), line.at( 6 ) );
1488 size = VECTOR2D( line.at( 7 ), line.at( 8 ) );
1489 angle = line.at( 9 );
1490 flipped = line.at( 10 );
1491
1492 wxString imageUrl = line.at( 11 );
1493
1494 if( imageUrl.BeforeFirst( ':' ) == wxS( "blob" ) )
1495 {
1496 wxString objectId = imageUrl.AfterLast( ':' );
1497
1498 if( auto blob = get_opt( aBlobMap, objectId ) )
1499 {
1500 wxString blobUrl = blob->url;
1501
1502 if( blobUrl.BeforeFirst( ':' ) == wxS( "data" ) )
1503 {
1504 wxArrayString paramsArr =
1505 wxSplit( blobUrl.AfterFirst( ':' ).BeforeFirst( ',' ), ';', '\0' );
1506
1507 base64Data = blobUrl.AfterFirst( ',' );
1508
1509 if( paramsArr.size() > 0 )
1510 mimeType = paramsArr[0];
1511 }
1512 }
1513 }
1514
1515 VECTOR2D kstart = ScalePos( start );
1516 VECTOR2D ksize = ScaleSize( size );
1517
1518 if( mimeType.empty() || base64Data.empty() )
1519 continue;
1520
1521 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1522
1523 if( mimeType == wxS( "image/svg+xml" ) )
1524 {
1525 // Not yet supported by EasyEDA
1526 }
1527 else
1528 {
1529 VECTOR2D kcenter = kstart + ksize / 2;
1530
1531 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
1532 std::make_unique<PCB_REFERENCE_IMAGE>( aBoard, kcenter, klayer );
1533
1534 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1535 & ~wxImage::Load_Verbose );
1536
1537 if( bitmap->ReadImageFile( buf ) )
1538 {
1539 double scaleFactor = ScaleSize( size.x ) / bitmap->GetSize().x;
1540 bitmap->SetImageScale( scaleFactor );
1541
1542 // TODO: support non-90-deg angles
1543 bitmap->Rotate( kstart, EDA_ANGLE( angle, DEGREES_T ) );
1544
1545 if( flipped )
1546 {
1547 int x = bitmap->GetPosition().x;
1548 MIRROR( x, KiROUND( kstart.x ) );
1549 bitmap->SetX( x );
1550
1551 bitmap->MutableImage()->Mirror( false );
1552 }
1553
1554 aBoard->Add( bitmap.release(), ADD_MODE::APPEND );
1555 }
1556 }
1557 }
1558 else if( type == wxS( "STRING" ) )
1559 {
1560 wxString uuid = line.at( 1 );
1561
1562 // if( line.at( 2 ).is_number() )
1563 // int unk = line.at( 2 ).get<int>();
1564 // else if( line.at( 2 ).is_string() )
1565 // int unk = wxAtoi( line.at( 2 ).get<wxString>() );
1566
1567 int layer = line.at( 3 ).get<int>();
1568 PCB_LAYER_ID klayer = LayerToKi( layer );
1569
1570 VECTOR2D location( line.at( 4 ), line.at( 5 ) );
1571 wxString string = line.at( 6 );
1572 wxString font = line.at( 7 );
1573
1574 double height = line.at( 8 );
1575 double strokew = line.at( 9 );
1576
1577 int align = line.at( 12 );
1578 double angle = line.at( 13 );
1579 int inverted = line.at( 14 );
1580 int mirror = line.at( 16 );
1581
1582 PCB_TEXT* text = new PCB_TEXT( aBoard );
1583
1584 text->SetText( string );
1585 text->SetLayer( klayer );
1586 text->SetPosition( ScalePos( location ) );
1587 text->SetIsKnockout( inverted );
1588 text->SetTextThickness( ScaleSize( strokew ) );
1589 text->SetTextSize( VECTOR2D( ScaleSize( height * 0.6 ), ScaleSize( height * 0.7 ) ) );
1590
1591 if( font != wxS( "default" ) )
1592 {
1593 text->SetFont( KIFONT::FONT::GetFont( font ) );
1594 //text->SetupRenderCache( text->GetShownText(), EDA_ANGLE( angle, DEGREES_T ) );
1595
1596 //text->AddRenderCacheGlyph();
1597 // TODO: import geometry cache
1598 }
1599
1600 AlignText( text, align );
1601
1602 if( IsBackLayer( klayer ) ^ !!mirror )
1603 {
1604 text->SetMirrored( true );
1605 text->SetTextAngleDegrees( -angle );
1606 }
1607 else
1608 {
1609 text->SetTextAngleDegrees( angle );
1610 }
1611
1612 aBoard->Add( text, ADD_MODE::APPEND );
1613 }
1614 else if( type == wxS( "COMPONENT" ) )
1615 {
1616 wxString compId = line.at( 1 );
1617 componentLines[compId].push_back( line );
1618 }
1619 else if( type == wxS( "ATTR" ) )
1620 {
1621 wxString compId = line.at( 3 );
1622 componentLines[compId].push_back( line );
1623 }
1624 else if( type == wxS( "PAD_NET" ) )
1625 {
1626 wxString compId = line.at( 1 );
1627 componentLines[compId].push_back( line );
1628 }
1629 }
1630
1631 for( auto const& [compId, lines] : componentLines )
1632 {
1633 wxString deviceId;
1634 wxString fpIdOverride;
1635 wxString fpDesignator;
1636 std::map<wxString, wxString> localCompAttribs;
1637
1638 for( auto& line : lines )
1639 {
1640 if( line.size() == 0 )
1641 continue;
1642
1643 wxString type = line.at( 0 );
1644
1645 if( type == wxS( "COMPONENT" ) )
1646 {
1647 localCompAttribs = line.at( 7 );
1648 }
1649 else if( type == wxS( "ATTR" ) )
1650 {
1651 EASYEDAPRO::PCB_ATTR attr = line;
1652
1653 if( attr.key == wxS( "Device" ) )
1654 deviceId = attr.value;
1655
1656 else if( attr.key == wxS( "Footprint" ) )
1657 fpIdOverride = attr.value;
1658
1659 else if( attr.key == wxS( "Designator" ) )
1660 fpDesignator = attr.value;
1661 }
1662 }
1663
1664 if( deviceId.empty() )
1665 continue;
1666
1667 nlohmann::json compAttrs = aProject.at( "devices" ).at( deviceId ).at( "attributes" );
1668
1669 wxString fpId;
1670
1671 if( !fpIdOverride.IsEmpty() )
1672 fpId = fpIdOverride;
1673 else
1674 fpId = compAttrs.at( "Footprint" ).get<wxString>();
1675
1676 auto it = aFootprintMap.find( fpId );
1677 if( it == aFootprintMap.end() )
1678 {
1679 wxLogError( "Footprint of '%s' with uuid '%s' not found.", fpDesignator, fpId );
1680 continue;
1681 }
1682
1683 std::unique_ptr<FOOTPRINT>& footprintOrig = it->second;
1684 std::unique_ptr<FOOTPRINT> footprint( static_cast<FOOTPRINT*>( footprintOrig->Clone() ) );
1685
1686 wxString modelUuid, modelTitle, modelTransform;
1687
1688 if( auto val = get_opt( localCompAttribs, "3D Model" ) )
1689 modelUuid = *val;
1690 else
1691 modelUuid = compAttrs.value<wxString>( "3D Model", "" );
1692
1693 if( auto val = get_opt( localCompAttribs, "3D Model Title" ) )
1694 modelTitle = val->Trim();
1695 else
1696 modelTitle = compAttrs.value<wxString>( "3D Model Title", modelUuid ).Trim();
1697
1698 if( auto val = get_opt( localCompAttribs, "3D Model Transform" ) )
1699 modelTransform = *val;
1700 else
1701 modelTransform = compAttrs.value<wxString>( "3D Model Transform", "" );
1702
1703 fillFootprintModelInfo( footprint.get(), modelUuid, modelTitle, modelTransform );
1704
1705 footprint->SetParent( aBoard );
1706
1707 for( auto& line : lines )
1708 {
1709 if( line.size() == 0 )
1710 continue;
1711
1712 wxString type = line.at( 0 );
1713
1714 if( type == wxS( "COMPONENT" ) )
1715 {
1716 int layer = line.at( 3 );
1717 PCB_LAYER_ID klayer = LayerToKi( layer );
1718
1719 VECTOR2D center( line.at( 4 ), line.at( 5 ) );
1720
1721 double orient = line.at( 6 );
1722 //std::map<wxString, wxString> props = line.at( 7 );
1723
1724 if( klayer == B_Cu )
1725 footprint->Flip( footprint->GetPosition(), false );
1726
1727 footprint->SetOrientationDegrees( orient );
1728 footprint->SetPosition( ScalePos( center ) );
1729 }
1730 else if( type == wxS( "ATTR" ) )
1731 {
1732 EASYEDAPRO::PCB_ATTR attr = line;
1733
1734 PCB_LAYER_ID klayer = LayerToKi( attr.layer );
1735
1736 PCB_TEXT* text = nullptr;
1737 bool add = false;
1738
1739 if( attr.key == wxS( "Designator" ) )
1740 {
1741 if( attr.key == wxS( "Designator" ) )
1742 {
1743 text = footprint->GetField( REFERENCE_FIELD );
1744 }
1745 else
1746 {
1747 text = new PCB_TEXT( footprint.get() );
1748 add = true;
1749 }
1750
1751 if( attr.fontName != wxS( "default" ) )
1752 text->SetFont( KIFONT::FONT::GetFont( attr.fontName ) );
1753
1754 if( attr.valVisible && attr.keyVisible )
1755 {
1756 text->SetText( attr.key + ':' + attr.value );
1757 }
1758 else if( attr.keyVisible )
1759 {
1760 text->SetText( attr.key );
1761 }
1762 else
1763 {
1764 text->SetText( attr.value );
1765 }
1766
1767 text->SetVisible( attr.keyVisible || attr.valVisible );
1768 text->SetLayer( klayer );
1769 text->SetPosition( ScalePos( attr.position ) );
1770 text->SetTextAngleDegrees( footprint->IsFlipped() ? -attr.rotation
1771 : attr.rotation );
1772 text->SetIsKnockout( attr.inverted );
1773 text->SetTextThickness( ScaleSize( attr.strokeWidth ) );
1774 text->SetTextSize( VECTOR2D( ScaleSize( attr.height * 0.55 ),
1775 ScaleSize( attr.height * 0.6 ) ) );
1776
1777 AlignText( text, attr.textOrigin );
1778
1779 if( add )
1780 footprint->Add( text, ADD_MODE::APPEND );
1781 }
1782 }
1783 else if( type == wxS( "PAD_NET" ) )
1784 {
1785 wxString padNumber = line.at( 2 );
1786 wxString padNet = line.at( 3 );
1787
1788 PAD* pad = footprint->FindPadByNumber( padNumber );
1789 if( pad )
1790 {
1791 pad->SetNet( aBoard->FindNet( padNet ) );
1792 }
1793 else
1794 {
1795 // Not a pad
1796 }
1797 }
1798 }
1799
1800 aBoard->Add( footprint.release(), ADD_MODE::APPEND );
1801 }
1802
1803 // Heal board outlines
1804 std::vector<PCB_SHAPE*> shapes;
1805 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
1806
1807 for( BOARD_ITEM* item : aBoard->Drawings() )
1808 {
1809 if( !item->IsOnLayer( Edge_Cuts ) )
1810 continue;
1811
1812 if( item->Type() == PCB_SHAPE_T )
1813 shapes.push_back( static_cast<PCB_SHAPE*>( item ) );
1814 }
1815
1816 ConnectBoardShapes( shapes, newShapes, SHAPE_JOIN_DISTANCE );
1817
1818 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
1819 aBoard->Add( ptr.release(), ADD_MODE::APPEND );
1820
1821 // Center the board
1822 BOX2I outlineBbox = aBoard->ComputeBoundingBox( true, false );
1823 PAGE_INFO pageInfo = aBoard->GetPageSettings();
1824
1825 VECTOR2D pageCenter( pcbIUScale.MilsToIU( pageInfo.GetWidthMils() / 2 ),
1826 pcbIUScale.MilsToIU( pageInfo.GetHeightMils() / 2 ) );
1827
1828 VECTOR2D offset = pageCenter - outlineBbox.GetCenter();
1829
1830 int alignGrid = pcbIUScale.mmToIU( 10 );
1831 offset.x = KiROUND( offset.x / alignGrid ) * alignGrid;
1832 offset.y = KiROUND( offset.y / alignGrid ) * alignGrid;
1833
1834 aBoard->Move( offset );
1835 bds.SetAuxOrigin( offset );
1836}
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:677
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:697
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:1803
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aIncludeHiddenText=false) const
Calculate the bounding box containing all board items (or board edge segments).
Definition: board.cpp:1552
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition: board.cpp:580
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: board.cpp:490
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:794
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:243
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:181
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:53
static LSET PTHMask()
layer set for a through hole pad
Definition: pad.cpp:312
static LSET SMDMask()
layer set for a SMD pad on Front layer
Definition: pad.cpp:319
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
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:601
VECTOR2< int > VECTOR2I
Definition: vector2d.h:602