30#include <nlohmann/json.hpp>
35#include <wx/wfstream.h>
36#include <wx/stdstream.h>
74 if( !aValue.ToCDouble( &value ) )
75 THROW_IO_ERROR( wxString::Format(
_(
"Failed to parse value: '%s'" ), aValue ) );
104 case 9:
return F_Fab;
105 case 10:
return B_Fab;
204 const wxString& modelTitle,
205 const wxString& modelTransform )
const
208 const wxString easyedaModelDir = wxS(
"EASYEDA_MODELS" );
209 const wxString kicadModelPrefix = wxS(
"${KIPRJMOD}/" ) + easyedaModelDir + wxS(
"/" );
225 wxArrayString arr = wxSplit( modelTransform,
',',
'\0' );
230 if( fitXmm > 0.0 && fitYmm > 0.0 )
235 field.
SetText( wxString::FromCDouble( fitXmm ) + wxS(
" " )
236 + wxString::FromCDouble( fitYmm ) );
241 kmodelRotation.
z = -
Convert( arr[3] );
248 if( !modelTitle.IsEmpty() && footprint->
Models().empty() )
252 +
EscapeString( modelTitle, ESCAPE_CONTEXT::CTX_FILENAME )
256 footprint->
Models().push_back( model );
261std::vector<std::unique_ptr<PCB_SHAPE>>
263 bool aClosed,
bool aInFill )
const
265 std::vector<std::unique_ptr<PCB_SHAPE>> results;
268 for(
int i = 0; i < polyData.size(); i++ )
270 nlohmann::json val = polyData.at( i );
272 if( val.is_string() )
275 if( str == wxS(
"CIRCLE" ) )
278 center.
x = ( polyData.at( ++i ) );
279 center.
y = ( polyData.at( ++i ) );
280 double r = ( polyData.at( ++i ) );
282 std::unique_ptr<PCB_SHAPE> shape =
283 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::CIRCLE );
285 shape->SetCenter(
ScalePos( center ) );
287 shape->SetFilled( aClosed );
289 results.emplace_back( std::move( shape ) );
291 else if( str == wxS(
"R" ) )
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;
303 std::unique_ptr<PCB_SHAPE> shape =
304 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::RECTANGLE );
306 shape->SetStart(
ScalePos( start ) );
307 shape->SetEnd(
ScalePos( start + size ) );
308 shape->SetFilled( aClosed );
311 results.emplace_back( std::move( shape ) );
319 std::unique_ptr<PCB_SHAPE> shape =
320 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
322 shape->SetStart(
ScalePos( aStart ) );
324 shape->SetFilled( aClosed );
327 results.emplace_back( std::move( shape ) );
332 std::unique_ptr<PCB_SHAPE> shape =
333 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::ARC );
335 shape->SetStart(
ScalePos( aStart ) );
337 shape->SetCenter(
ScalePos( center ) );
338 shape->SetFilled( aClosed );
341 results.emplace_back( std::move( shape ) );
349 addArc( { end.
x - cr, start.
y }, { end.
x, start.
y - cr },
350 { end.
x - cr, start.
y - cr } );
352 addArc( { end.
x, end.
y + cr }, { end.
x - cr, end.
y },
353 { end.
x - cr, end.
y + cr } );
355 addArc( { start.
x + cr, end.
y }, { start.
x, end.
y + cr },
356 { start.
x + cr, end.
y + cr } );
358 addArc( { start.
x, start.
y - cr }, { start.
x + cr, start.
y },
359 { start.
x + cr, start.
y - cr } );
362 else if( str == wxS(
"ARC" ) || str == wxS(
"CARC" ) )
365 double angle = polyData.at( ++i ).get<
double>() / ( aInFill ? 10 : 1 );
366 end.
x = ( polyData.at( ++i ) );
367 end.
y = ( polyData.at( ++i ) );
369 std::unique_ptr<PCB_SHAPE> shape =
370 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::ARC );
374 shape->SetStart(
ScalePos( prevPt ) );
380 shape->SetEnd(
ScalePos( prevPt ) );
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 ) );
392 shape->SetFilled( aClosed );
394 results.emplace_back( std::move( shape ) );
398 else if( str == wxS(
"L" ) )
403 while( i < polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
406 pt.
x = ( polyData.at( ++i ) );
407 pt.
y = ( polyData.at( ++i ) );
416 std::unique_ptr<PCB_SHAPE> shape =
417 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::POLY );
424 shape->SetFilled(
true );
425 shape->SetPolyShape( chain );
427 results.emplace_back( std::move( shape ) );
436 std::unique_ptr<PCB_SHAPE> shape =
437 std::make_unique<PCB_SHAPE>( aContainer, SHAPE_T::SEGMENT );
439 shape->SetStart( seg.
A );
440 shape->SetEnd( seg.
B );
442 results.emplace_back( std::move( shape ) );
447 else if( val.is_number() )
449 prevPt.
x = ( polyData.at( i ) );
450 prevPt.
y = ( polyData.at( ++i ) );
460 double aArcAccuracy )
const
465 double bezierMinSegLen = polyData.size() < 300 ? aArcAccuracy : aArcAccuracy * 10;
467 for(
int i = 0; i < polyData.size(); i++ )
469 nlohmann::json val = polyData.at( i );
471 if( val.is_string() )
474 if( str == wxS(
"CIRCLE" ) )
477 center.
x = ( polyData.at( ++i ) );
478 center.
y = ( polyData.at( ++i ) );
479 double r = ( polyData.at( ++i ) );
484 else if( str == wxS(
"R" ) )
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;
498 VECTOR2D kcenter = kstart + ksize / 2;
505 result.
Append( poly.Outline( 0 ) );
507 else if( str == wxS(
"ARC" ) || str == wxS(
"CARC" ) )
510 double angle = polyData.at( ++i ).get<
double>();
515 end.
x = ( polyData.at( ++i ) );
516 end.
y = ( polyData.at( ++i ) );
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 );
532 ScalePos( center ), angle >= 0, 0 );
534 result.
Append( sarc, aArcAccuracy );
538 else if( str == wxS(
"C" ) )
541 pt1.
x = ( polyData.at( ++i ) );
542 pt1.
y = ( polyData.at( ++i ) );
545 pt2.
x = ( polyData.at( ++i ) );
546 pt2.
y = ( polyData.at( ++i ) );
549 pt3.
x = ( polyData.at( ++i ) );
550 pt3.
y = ( polyData.at( ++i ) );
556 std::vector<VECTOR2I> bezierPoints;
557 converter.
GetPoly( bezierPoints, bezierMinSegLen, 16 );
559 result.
Append( bezierPoints );
563 else if( str == wxS(
"L" ) )
567 while( i < polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
570 pt.
x = ( polyData.at( ++i ) );
571 pt.
y = ( polyData.at( ++i ) );
579 else if( val.is_number() )
581 prevPt.
x = ( polyData.at( i ) );
582 prevPt.
y = ( polyData.at( ++i ) );
591 const nlohmann::json& line )
593 wxString uuid = line.at( 1 );
600 wxString netname = line.at( 3 );
601 int layer = line.at( 4 ).get<
int>();
604 wxString padNumber = line.at( 5 );
607 center.
x = line.at( 6 );
608 center.
y = line.at( 7 );
610 double orientation = line.at( 8 );
612 nlohmann::json padHole = line.at( 9 );
613 nlohmann::json padShape = line.at( 10 );
615 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( aFootprint );
617 pad->SetNumber( padNumber );
619 pad->SetOrientationDegrees( orientation );
621 if( !padHole.is_null() )
623 double drill_dir = 0;
625 if( line.at( 14 ).is_number() )
626 drill_dir = line.at( 14 );
628 wxString holeShape = padHole.at( 0 );
630 if( holeShape == wxS(
"ROUND" ) || holeShape == wxS(
"SLOT" ) )
633 drill.
x = padHole.at( 1 );
634 drill.
y = padHole.at( 2 );
639 std::swap( drill.
x, drill.
y );
641 if( holeShape == wxS(
"SLOT" ) )
643 pad->SetDrillShape( PAD_DRILL_SHAPE::OBLONG );
648 pad->SetAttribute( PAD_ATTRIB::PTH );
657 else if( klayer ==
B_Cu )
662 pad->SetAttribute( PAD_ATTRIB::SMD );
665 wxString padSh = padShape.at( 0 );
666 if( padSh == wxS(
"RECT" ) )
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;
677 pad->SetShape( PAD_SHAPE::RECTANGLE );
681 pad->SetShape( PAD_SHAPE::ROUNDRECT );
682 pad->SetRoundRectRadiusRatio( cr_p / 100 );
685 else if( padSh == wxS(
"ELLIPSE" ) )
688 size.
x = padShape.at( 1 );
689 size.
y = padShape.at( 2 );
692 pad->SetShape( PAD_SHAPE::CIRCLE );
694 else if( padSh == wxS(
"OVAL" ) )
697 size.
x = padShape.at( 1 );
698 size.
y = padShape.at( 2 );
701 pad->SetShape( PAD_SHAPE::OVAL );
703 else if( padSh == wxS(
"POLY" ) )
705 pad->SetShape( PAD_SHAPE::CUSTOM );
706 pad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
707 pad->SetSize( { 1, 1 } );
709 nlohmann::json polyData = padShape.at( 1 );
711 std::vector<std::unique_ptr<PCB_SHAPE>> results =
712 ParsePoly( aFootprint, polyData,
true,
false );
714 for(
auto& shape : results )
716 shape->SetLayer( klayer );
717 shape->SetWidth( 0 );
719 shape->Move( -
pad->GetPosition() );
721 pad->AddPrimitive( shape.release() );
727 return std::move(
pad );
732 const wxString& aFpUuid,
733 const std::vector<nlohmann::json>& aLines )
735 std::unique_ptr<FOOTPRINT> footprintPtr = std::make_unique<FOOTPRINT>(
m_board );
736 FOOTPRINT* footprint = footprintPtr.get();
743 field->SetTextSize( defaultTextSize );
744 field->SetTextThickness( defaultTextThickness );
747 for(
const nlohmann::json& line : aLines )
749 if( line.size() == 0 )
752 wxString type = line.at( 0 );
754 if( type == wxS(
"POLY" ) || type == wxS(
"PAD" ) || type == wxS(
"FILL" )
755 || type == wxS(
"ATTR" ) )
757 wxString uuid = line.at( 1 );
764 wxString netname = line.at( 3 );
765 int layer = line.at( 4 ).get<
int>();
768 if( type == wxS(
"POLY" ) )
770 double thickness = ( line.at( 5 ) );
771 nlohmann::json polyData = line.at( 6 );
773 std::vector<std::unique_ptr<PCB_SHAPE>> results =
774 ParsePoly( footprint, polyData,
false,
false );
776 for(
auto& shape : results )
778 shape->SetLayer( klayer );
779 shape->SetWidth(
ScaleSize( thickness ) );
781 footprint->
Add( shape.release(), ADD_MODE::APPEND );
784 else if( type == wxS(
"PAD" ) )
786 std::unique_ptr<PAD>
pad =
createPAD( footprint, line );
788 footprint->
Add(
pad.release(), ADD_MODE::APPEND );
790 else if( type == wxS(
"FILL" ) )
792 int layer = line.at( 4 ).get<
int>();
795 double width = line.at( 5 );
797 nlohmann::json polyDataList = line.at( 7 );
799 if( !polyDataList.at( 0 ).is_array() )
800 polyDataList = nlohmann::json::array( { polyDataList } );
802 std::vector<SHAPE_LINE_CHAIN> contours;
803 for( nlohmann::json& polyData : polyDataList )
808 contours.push_back( contour );
818 std::unique_ptr<PCB_GROUP>
group;
821 group = std::make_unique<PCB_GROUP>( footprint );
827 std::unique_ptr<PCB_SHAPE> shape =
828 std::make_unique<PCB_SHAPE>( footprint, SHAPE_T::POLY );
830 shape->SetFilled(
true );
831 shape->SetPolyShape( poly );
832 shape->SetLayer( klayer );
833 shape->SetWidth( 0 );
836 group->AddItem( shape.get() );
838 footprint->
Add( shape.release(), ADD_MODE::APPEND );
842 footprint->
Add(
group.release(), ADD_MODE::APPEND );
844 else if( type == wxS(
"ATTR" ) )
848 if( attr.
key == wxS(
"Designator" ) )
852 else if( type == wxS(
"REGION" ) )
854 wxString uuid = line.at( 1 );
861 int layer = line.at( 3 ).get<
int>();
864 double width = line.at( 4 );
865 std::set<int> flags = line.at( 5 );
866 nlohmann::json polyDataList = line.at( 6 );
868 for( nlohmann::json& polyData : polyDataList )
872 std::vector<std::unique_ptr<PCB_SHAPE>> results =
873 ParsePoly(
nullptr, polyData,
true,
false );
875 for(
auto& shape : results )
877 shape->SetFilled(
true );
884 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( footprint );
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 ) );
894 zone->SetLayer( klayer );
895 zone->Outline()->Append( polySet );
897 footprint->
Add( zone.release(), ADD_MODE::APPEND );
902 if( aProject.is_object() )
904 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at(
"devices" );
905 std::map<wxString, wxString> compAttrs;
907 for(
auto& [devUuid, devData] : devicesMap )
909 if(
auto fp =
get_opt( devData.attributes,
"Footprint" ) )
913 compAttrs = devData.attributes;
919 wxString modelUuid, modelTitle, modelTransform;
921 modelUuid =
get_def( compAttrs,
"3D Model",
"" );
922 modelTitle =
get_def( compAttrs,
"3D Model Title", modelUuid );
923 modelTransform =
get_def( compAttrs,
"3D Model Transform",
"" );
929 std::vector<PCB_SHAPE*> shapes;
930 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
938 shapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
943 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
944 footprint->
Add( ptr.release(), ADD_MODE::APPEND );
946 return footprintPtr.release();
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 )
957 std::map<wxString, std::vector<nlohmann::json>> componentLines;
958 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
962 for(
const nlohmann::json& line : aLines )
964 if( line.size() == 0 )
967 wxString type = line.at( 0 );
969 if( type == wxS(
"LAYER" ) )
971 int layer = line.at( 1 );
974 wxString layerType = line.at( 2 );
975 wxString layerName = line.at( 3 );
976 int layerFlag = line.at( 4 );
981 blayers.set( klayer );
986 else if( type == wxS(
"NET" ) )
988 wxString netname = line.at( 1 );
993 else if( type == wxS(
"RULE" ) )
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 );
1000 if( ruleType == wxS(
"3" ) && isDefault )
1002 wxString units = ruleData.at( 0 );
1003 double minVal = ruleData.at( 1 );
1004 double optVal = ruleData.at( 2 );
1005 double maxVal = ruleData.at( 3 );
1009 else if( ruleType == wxS(
"1" ) && isDefault )
1011 wxString units = ruleData.at( 0 );
1012 nlohmann::json table = ruleData.at( 1 );
1014 int minVal = INT_MAX;
1015 for(
const std::vector<int>& arr : table )
1017 for(
int val : arr )
1027 ruleLines[ruleType].push_back( line );
1029 else if( type == wxS(
"VIA" ) || type == wxS(
"LINE" ) || type == wxS(
"ARC" )
1030 || type == wxS(
"POLY" ) || type == wxS(
"FILL" ) || type == wxS(
"POUR" ) )
1032 wxString uuid = line.at( 1 );
1039 wxString netname = line.at( 3 );
1041 if( type == wxS(
"VIA" ) )
1044 center.
x = line.at( 5 );
1045 center.
y = line.at( 6 );
1047 double drill = line.at( 7 );
1048 double dia = line.at( 8 );
1050 std::unique_ptr<PCB_VIA>
via = std::make_unique<PCB_VIA>( aBoard );
1058 aBoard->
Add(
via.release(), ADD_MODE::APPEND );
1060 else if( type == wxS(
"LINE" ) )
1062 int layer = line.at( 4 ).get<
int>();
1066 start.
x = line.at( 5 );
1067 start.
y = line.at( 6 );
1070 end.
x = line.at( 7 );
1071 end.
y = line.at( 8 );
1073 double width = line.at( 9 );
1075 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( aBoard );
1077 track->SetLayer( klayer );
1078 track->SetStart(
ScalePos( start ) );
1082 track->SetNet( aBoard->
FindNet( netname ) );
1084 aBoard->
Add( track.release(), ADD_MODE::APPEND );
1086 else if( type == wxS(
"ARC" ) )
1088 int layer = line.at( 4 ).get<
int>();
1092 start.
x = line.at( 5 );
1093 start.
y = line.at( 6 );
1096 end.
x = line.at( 7 );
1097 end.
y = line.at( 8 );
1099 double angle = line.at( 9 );
1100 double width = line.at( 10 );
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 );
1112 ScalePos( center ), angle >= 0, width );
1114 std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( aBoard, &sarc );
1117 arc->SetLayer( klayer );
1118 arc->SetNet( aBoard->
FindNet( netname ) );
1120 aBoard->
Add( arc.release(), ADD_MODE::APPEND );
1122 else if( type == wxS(
"FILL" ) )
1124 int layer = line.at( 4 ).get<
int>();
1127 double width = line.at( 5 );
1129 nlohmann::json polyDataList = line.at( 7 );
1131 if( !polyDataList.at( 0 ).is_array() )
1132 polyDataList = nlohmann::json::array( { polyDataList } );
1134 std::vector<SHAPE_LINE_CHAIN> contours;
1135 for( nlohmann::json& polyData : polyDataList )
1140 contours.push_back( contour );
1151 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1153 zone->SetNet( aBoard->
FindNet( netname ) );
1154 zone->SetLayer( klayer );
1156 zone->SetFilledPolysList( klayer, zoneFillPoly );
1157 zone->SetAssignedPriority( 500 );
1158 zone->SetIsFilled(
true );
1159 zone->SetNeedRefill(
false );
1164 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1166 else if( type == wxS(
"POLY" ) )
1168 int layer = line.at( 4 );
1171 double thickness = line.at( 5 );
1172 nlohmann::json polyData = line.at( 6 );
1174 std::vector<std::unique_ptr<PCB_SHAPE>> results =
1175 ParsePoly( aBoard, polyData,
false,
false );
1177 for(
auto& shape : results )
1179 shape->SetLayer( klayer );
1180 shape->SetWidth(
ScaleSize( thickness ) );
1182 aBoard->
Add( shape.release(), ADD_MODE::APPEND );
1185 else if( type == wxS(
"POUR" ) )
1187 int layer = line.at( 4 ).get<
int>();
1190 double lineWidth = line.at( 5 );
1191 wxString pourname = line.at( 6 );
1192 int fillOrder = line.at( 7 ).get<
int>();
1193 nlohmann::json polyDataList = line.at( 8 );
1195 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1197 zone->SetNet( aBoard->
FindNet( netname ) );
1198 zone->SetLayer( klayer );
1199 zone->SetAssignedPriority( 500 - fillOrder );
1203 for( nlohmann::json& polyData : polyDataList )
1208 zone->Outline()->Append( contour );
1211 wxASSERT( zone->Outline()->OutlineCount() == 1 );
1219 auto range = aPouredMap.equal_range( uuid );
1220 for(
auto& it = range.first; it != range.second; ++it )
1223 int unki = poured.
unki;
1227 for(
int dataId = 0; dataId < poured.
polyData.size(); dataId++ )
1229 const nlohmann::json& fillData = poured.
polyData[dataId];
1230 const double ptScale = 10;
1236 for(
int i = 0; i < contour.
PointCount(); i++ )
1249 thisPoly.
Append( simple );
1261 for(
int segId = 0; segId < contour.
SegmentCount(); segId++ )
1272 fillPolySet.
Append( thisPoly );
1283 fillPolySet.
Inflate( strokeWidth / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
1290 zone->SetFilledPolysList( klayer, fillPolySet );
1291 zone->SetNeedRefill(
false );
1292 zone->SetIsFilled(
true );
1296 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1299 else if( type == wxS(
"TEARDROP" ) )
1301 wxString uuid = line.at( 1 );
1302 wxString netname = line.at( 2 );
1303 int layer = line.at( 3 ).get<
int>();
1306 nlohmann::json polyData = line.at( 4 );
1311 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
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 );
1320 zone->SetAssignedPriority( 600 );
1321 zone->SetLocalClearance( 0 );
1322 zone->SetMinThickness( 0 );
1323 zone->SetTeardropAreaType( TEARDROP_TYPE::TD_UNSPECIFIED );
1325 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1327 else if( type == wxS(
"REGION" ) )
1329 wxString uuid = line.at( 1 );
1336 int layer = line.at( 3 ).get<
int>();
1339 double width = line.at( 4 );
1340 std::set<int> flags = line.at( 5 );
1341 nlohmann::json polyDataList = line.at( 6 );
1343 for( nlohmann::json& polyData : polyDataList )
1348 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
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 ) );
1358 zone->SetLayer( klayer );
1359 zone->Outline()->Append( contour );
1361 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1364 else if( type == wxS(
"PAD" ) )
1366 wxString netname = line.at( 3 );
1368 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aBoard );
1369 std::unique_ptr<PAD>
pad =
createPAD( footprint.get(), line );
1379 footprint->Add(
pad.release(), ADD_MODE::APPEND );
1380 footprint->SetPosition( pos );
1381 footprint->SetOrientation( orient );
1383 wxString fpName = wxS(
"Pad_" ) + line.at( 1 ).get<wxString>();
1386 footprint->SetFPID( fpID );
1387 footprint->Reference().SetVisible(
true );
1388 footprint->Value().SetVisible(
true );
1389 footprint->AutoPositionFields();
1391 aBoard->
Add( footprint.release(), ADD_MODE::APPEND );
1393 else if( type == wxS(
"IMAGE" ) )
1395 wxString uuid = line.at( 1 );
1402 int layer = line.at( 3 ).get<
int>();
1405 VECTOR2D start( line.at( 4 ), line.at( 5 ) );
1406 VECTOR2D size( line.at( 6 ), line.at( 7 ) );
1408 double angle = line.at( 8 );
1409 int mirror = line.at( 9 );
1410 nlohmann::json polyDataList = line.at( 10 );
1413 std::vector<SHAPE_LINE_CHAIN> contours;
1414 for( nlohmann::json& polyData : polyDataList )
1419 contours.push_back( contour );
1431 for(
int i = 0; i < contour.PointCount(); i++ )
1442 std::unique_ptr<PCB_GROUP>
group;
1445 group = std::make_unique<PCB_GROUP>( aBoard );
1451 std::unique_ptr<PCB_SHAPE> shape =
1452 std::make_unique<PCB_SHAPE>( aBoard, SHAPE_T::POLY );
1454 shape->SetFilled(
true );
1455 shape->SetPolyShape( poly );
1456 shape->SetLayer( klayer );
1457 shape->SetWidth( 0 );
1466 group->AddItem( shape.get() );
1468 aBoard->
Add( shape.release(), ADD_MODE::APPEND );
1472 aBoard->
Add(
group.release(), ADD_MODE::APPEND );
1474 else if( type == wxS(
"OBJ" ) )
1477 wxString mimeType, base64Data;
1481 if( !line.at( 3 ).is_number() )
1484 int layer = line.at( 3 ).get<
int>();
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 );
1492 wxString imageUrl = line.at( 11 );
1494 if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
1496 wxString objectId = imageUrl.AfterLast(
':' );
1498 if(
auto blob =
get_opt( aBlobMap, objectId ) )
1500 wxString blobUrl = blob->url;
1502 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
1504 wxArrayString paramsArr =
1505 wxSplit( blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
1507 base64Data = blobUrl.AfterFirst(
',' );
1509 if( paramsArr.size() > 0 )
1510 mimeType = paramsArr[0];
1518 if( mimeType.empty() || base64Data.empty() )
1521 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1523 if( mimeType == wxS(
"image/svg+xml" ) )
1529 VECTOR2D kcenter = kstart + ksize / 2;
1531 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
1532 std::make_unique<PCB_REFERENCE_IMAGE>( aBoard, kcenter, klayer );
1534 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1535 & ~wxImage::Load_Verbose );
1537 if( bitmap->ReadImageFile( buf ) )
1539 double scaleFactor =
ScaleSize( size.
x ) / bitmap->GetSize().x;
1540 bitmap->SetImageScale( scaleFactor );
1547 int x = bitmap->GetPosition().x;
1551 bitmap->MutableImage()->Mirror(
false );
1554 aBoard->
Add( bitmap.release(), ADD_MODE::APPEND );
1558 else if( type == wxS(
"STRING" ) )
1560 wxString uuid = line.at( 1 );
1567 int layer = line.at( 3 ).get<
int>();
1570 VECTOR2D location( line.at( 4 ), line.at( 5 ) );
1571 wxString
string = line.at( 6 );
1572 wxString font = line.at( 7 );
1574 double height = line.at( 8 );
1575 double strokew = line.at( 9 );
1577 int align = line.at( 12 );
1578 double angle = line.at( 13 );
1579 int inverted = line.at( 14 );
1580 int mirror = line.at( 16 );
1584 text->SetText(
string );
1585 text->SetLayer( klayer );
1587 text->SetIsKnockout( inverted );
1591 if( font != wxS(
"default" ) )
1604 text->SetMirrored(
true );
1605 text->SetTextAngleDegrees( -angle );
1609 text->SetTextAngleDegrees( angle );
1612 aBoard->
Add(
text, ADD_MODE::APPEND );
1614 else if( type == wxS(
"COMPONENT" ) )
1616 wxString compId = line.at( 1 );
1617 componentLines[compId].push_back( line );
1619 else if( type == wxS(
"ATTR" ) )
1621 wxString compId = line.at( 3 );
1622 componentLines[compId].push_back( line );
1624 else if( type == wxS(
"PAD_NET" ) )
1626 wxString compId = line.at( 1 );
1627 componentLines[compId].push_back( line );
1631 for(
auto const& [compId, lines] : componentLines )
1634 wxString fpIdOverride;
1635 wxString fpDesignator;
1636 std::map<wxString, wxString> localCompAttribs;
1638 for(
auto& line : lines )
1640 if( line.size() == 0 )
1643 wxString type = line.at( 0 );
1645 if( type == wxS(
"COMPONENT" ) )
1647 localCompAttribs = line.at( 7 );
1649 else if( type == wxS(
"ATTR" ) )
1653 if( attr.
key == wxS(
"Device" ) )
1654 deviceId = attr.
value;
1656 else if( attr.
key == wxS(
"Footprint" ) )
1657 fpIdOverride = attr.
value;
1659 else if( attr.
key == wxS(
"Designator" ) )
1660 fpDesignator = attr.
value;
1664 if( deviceId.empty() )
1667 nlohmann::json compAttrs = aProject.at(
"devices" ).at( deviceId ).at(
"attributes" );
1671 if( !fpIdOverride.IsEmpty() )
1672 fpId = fpIdOverride;
1674 fpId = compAttrs.at(
"Footprint" ).get<wxString>();
1676 auto it = aFootprintMap.find( fpId );
1677 if( it == aFootprintMap.end() )
1679 wxLogError(
"Footprint of '%s' with uuid '%s' not found.", fpDesignator, fpId );
1683 std::unique_ptr<FOOTPRINT>& footprintOrig = it->second;
1684 std::unique_ptr<FOOTPRINT> footprint(
static_cast<FOOTPRINT*
>( footprintOrig->Clone() ) );
1686 wxString modelUuid, modelTitle, modelTransform;
1688 if(
auto val =
get_opt( localCompAttribs,
"3D Model" ) )
1691 modelUuid = compAttrs.value<wxString>(
"3D Model",
"" );
1693 if(
auto val =
get_opt( localCompAttribs,
"3D Model Title" ) )
1694 modelTitle = val->Trim();
1696 modelTitle = compAttrs.value<wxString>(
"3D Model Title", modelUuid ).Trim();
1698 if(
auto val =
get_opt( localCompAttribs,
"3D Model Transform" ) )
1699 modelTransform = *val;
1701 modelTransform = compAttrs.value<wxString>(
"3D Model Transform",
"" );
1705 footprint->SetParent( aBoard );
1707 for(
auto& line : lines )
1709 if( line.size() == 0 )
1712 wxString type = line.at( 0 );
1714 if( type == wxS(
"COMPONENT" ) )
1716 int layer = line.at( 3 );
1719 VECTOR2D center( line.at( 4 ), line.at( 5 ) );
1721 double orient = line.at( 6 );
1724 if( klayer ==
B_Cu )
1725 footprint->Flip( footprint->GetPosition(),
false );
1727 footprint->SetOrientationDegrees( orient );
1728 footprint->SetPosition(
ScalePos( center ) );
1730 else if( type == wxS(
"ATTR" ) )
1739 if( attr.
key == wxS(
"Designator" ) )
1741 if( attr.
key == wxS(
"Designator" ) )
1751 if( attr.
fontName != wxS(
"default" ) )
1768 text->SetLayer( klayer );
1770 text->SetTextAngleDegrees( footprint->IsFlipped() ? -attr.
rotation
1780 footprint->Add(
text, ADD_MODE::APPEND );
1783 else if( type == wxS(
"PAD_NET" ) )
1785 wxString padNumber = line.at( 2 );
1786 wxString padNet = line.at( 3 );
1788 PAD*
pad = footprint->FindPadByNumber( padNumber );
1800 aBoard->
Add( footprint.release(), ADD_MODE::APPEND );
1804 std::vector<PCB_SHAPE*> shapes;
1805 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
1813 shapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
1818 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
1819 aBoard->
Add( ptr.release(), ADD_MODE::APPEND );
1831 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
1832 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
1834 aBoard->
Move( offset );
constexpr int ARC_HIGH_DEF
constexpr EDA_IU_SCALE pcbIUScale
constexpr int ARC_LOW_DEF
Bezier curves to polygon converter.
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...
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
const PAGE_INFO & GetPageSettings() const
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aIncludeHiddenText=false) const
Calculate the bounding box containing all board items (or board edge segments).
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
unsigned GetNetCount() const
const DRAWINGS & Drawings() const
const Vec & GetOrigin() const
const SizeVec & GetSize() const
const Vec GetCenter() const
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
VECTOR3D m_Offset
3D model offset (mm)
VECTOR3D m_Rotation
3D model rotation (degrees)
wxString m_Filename
The 3D shape filename in 3D library.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false)
A logical library item identifier and consists of various portions much like a URI.
LSET is a set of PCB_LAYER_IDs.
Handle the data for a net.
static LSET PTHMask()
layer set for a through hole pad
static LSET SMDMask()
layer set for a SMD pad on Front layer
Describe the page size and margins of a paper page on which to eventually print or plot.
double GetHeightMils() const
double GetWidthMils() const
static T ScaleSize(T aValue)
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
~PCB_IO_EASYEDAPRO_PARSER()
A progress reporter interface for use in multi-threaded environments.
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual const VECTOR2I GetPoint(int aIndex) const override
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
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
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.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
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)...
#define THROW_IO_ERROR(msg)
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
PCB_LAYER_ID
A quick note on layer IDs:
LSET FlipLayerMask(LSET aMask, int aCopperLayersCount)
Calculate the mask layer when flipping a footprint.
wxString get_def(const std::map< wxString, wxString > &aMap, const char *aKey, const char *aDefval="")
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
static const bool IMPORT_POURED
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
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)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
constexpr double IUTomm(int iu) const
constexpr int MilsToIU(int mils) const
constexpr int mmToIU(double mm) const
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
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.
double DEG2RAD(double deg)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
VECTOR2< double > VECTOR2D