37#include <wx/mstream.h>
66 wxS(
"SMD Test Point" ),
67 wxS(
"TH Test Point" ),
69 wxS(
"Fill Region / Teardrop" ),
70 wxS(
"Copper / Plane Zone" ),
73 wxS(
"Text / Image" ),
74 wxS(
"Board Outline" ),
80 wxS(
"A.Type == 'Pad' && A.Pad_Type == 'SMD'" ),
81 wxS(
"A.Type == 'Pad' && A.Pad_Type == 'Through-hole'" ),
84 wxS(
"A.Type == 'Via'" ),
108 if( !aSafeSpacing.is_array() || aSafeSpacing.empty() )
109 return wxEmptyString;
111 wxString rules = wxS(
"(version 1)\n\n"
112 "# EasyEDA Pro safeSpacing values. Values are mils even when the\n"
113 "# source rule context reports unit \"mm\". Entries without a\n"
114 "# generated rule are source categories that KiCad's imported item\n"
115 "# model cannot distinguish; they remain here for lossless reference.\n" );
120 const nlohmann::json& values = aSafeSpacing.at( row );
122 if( !values.is_array() )
125 for(
size_t col = 0; col <= row && col < values.size(); ++col )
127 if( !values.at( col ).is_number() )
130 double value = values.at( col );
134 rules += wxString::Format( wxS(
"# %s ↔ %s: %s mil (%s mm)\n" ),
safeSpacingNames[row],
138 || ( row == 0 && col == 0 ) )
144 conditionB.Replace( wxS(
"A." ), wxS(
"B." ) );
146 rules += wxString::Format( wxS(
"\n(rule \"EasyEDA safe spacing: %s ↔ %s\"\n"
147 " (condition \"(%s) && (%s)\")\n"
148 " (constraint clearance (min %smm)))\n" ),
153 constexpr size_t boardOutline = 11;
155 if( boardOutline < aSafeSpacing.size() && aSafeSpacing.at( boardOutline ).is_array() )
157 const nlohmann::json& values = aSafeSpacing.at( boardOutline );
159 for(
size_t index : { 0u, 1u, 2u, 5u } )
161 if(
index >= values.size() || !values.at(
index ).is_number() || values.at(
index ).get<
double>() <= 0 )
168 rules += wxString::Format( wxS(
"\n(rule \"EasyEDA safe spacing: %s ↔ Board Outline\"\n"
169 " (condition \"(%s)\")\n"
170 " (constraint edge_clearance (min %smm)))\n" ),
206 nlohmann::json holeObj = aRow.
inner.value(
"hole", nlohmann::json() );
207 nlohmann::json padDef = aRow.
inner.value(
"defaultPad", nlohmann::json() );
209 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( aFootprint );
211 pad->SetNumber( padNumber );
217 bool hasHole =
false;
219 if( holeObj.is_object() )
221 wxString holeType =
V3GetString( holeObj,
"holeType", wxS(
"ROUND" ) );
223 if( holeType == wxS(
"RECT" ) )
224 holeType = wxS(
"SLOT" );
226 if( holeType != wxS(
"ROUND" ) && holeType != wxS(
"SLOT" ) )
227 holeType = wxS(
"ROUND" );
233 if( drill.
x > 0 || drill.
y > 0 )
242 std::swap( drill.
x, drill.
y );
244 if( holeType == wxS(
"SLOT" ) )
257 else if( klayer ==
B_Cu )
264 if( padDef.is_object() )
266 wxString padType =
V3GetString( padDef,
"padType", wxS(
"RECT" ) );
268 if( padType == wxS(
"RECT" ) )
274 double radiusRatio = std::clamp(
radius, 0.0, 100.0 ) / 100 / 2;
278 if( radiusRatio == 0 )
286 else if( padType == wxS(
"ELLIPSE" ) )
295 else if( padType == wxS(
"OVAL" ) )
304 else if( padType == wxS(
"POLY" ) || padType == wxS(
"POLYGON" ) )
310 nlohmann::json polyData = padDef.value(
"path", nlohmann::json() );
312 std::vector<std::unique_ptr<PCB_SHAPE>> results =
m_v2Parser.ParsePoly( aFootprint, polyData,
true,
false );
314 for(
auto& shape : results )
316 shape->SetLayer( klayer );
317 shape->SetWidth( 0 );
318 shape->Move( -
pad->GetPosition() );
353 wxString originStr =
V3GetString( aRow.
inner,
"origin", wxS(
"LEFT_BOTTOM" ) );
361 text->SetText(
string );
362 text->SetLayer( klayer );
364 text->SetIsKnockout( inverted );
369 if( font != wxS(
"default" ) )
376 text->SetMirrored(
true );
377 text->SetTextAngleDegrees( -angle );
381 text->SetTextAngleDegrees( angle );
388std::unique_ptr<FOOTPRINT>
392 std::unique_ptr<FOOTPRINT> footprintPtr = std::make_unique<FOOTPRINT>(
m_board );
393 FOOTPRINT* footprint = footprintPtr.get();
396 const int defaultTextThickness(
pcbIUScale.mmToIU( 0.15 ) );
401 field->SetTextSize( defaultTextSize );
402 field->SetTextThickness( defaultTextThickness );
407 if( row.
type == wxS(
"CANVAS" ) )
412 else if( row.
type == wxS(
"POLY" ) )
418 nlohmann::json polyData = row.
inner.value(
"path", nlohmann::json::array() );
420 std::vector<std::unique_ptr<PCB_SHAPE>> results =
m_v2Parser.ParsePoly( footprint, polyData,
false,
false );
422 for(
auto& shape : results )
424 shape->SetLayer( klayer );
429 else if( row.
type == wxS(
"PAD" ) )
434 else if( row.
type == wxS(
"FILL" ) )
439 nlohmann::json polyDataList = row.
inner.value(
"path", nlohmann::json::array() );
441 if( !polyDataList.is_null() && !polyDataList.empty() )
443 if( !polyDataList.at( 0 ).is_array() )
444 polyDataList = nlohmann::json::array( { polyDataList } );
446 std::vector<SHAPE_LINE_CHAIN> contours;
448 for( nlohmann::json& polyData : polyDataList )
452 contours.push_back( contour );
462 std::unique_ptr<PCB_GROUP>
group;
465 group = std::make_unique<PCB_GROUP>( footprint );
469 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint,
SHAPE_T::POLY );
471 shape->SetFilled(
true );
472 shape->SetPolyShape( poly );
473 shape->SetLayer( klayer );
474 shape->SetWidth( 0 );
477 group->AddItem( shape.get() );
486 else if( row.
type == wxS(
"ATTR" ) )
491 if( key == wxS(
"Designator" ) )
494 else if( row.
type == wxS(
"REGION" ) )
499 nlohmann::json polyDataList = row.
inner.value(
"path", nlohmann::json::array() );
500 nlohmann::json prohibitTypes = row.
inner.value(
"prohibitType", nlohmann::json::array() );
504 if( prohibitTypes.is_array() )
506 for(
const auto& pt : prohibitTypes )
511 ptStr = pt.get<std::string>();
513 if( ptStr == wxS(
"COMPONENT" ) )
515 else if( ptStr == wxS(
"TRACK" ) )
517 else if( ptStr == wxS(
"COPPER" ) )
519 else if( ptStr == wxS(
"VIA" ) )
521 else if( ptStr == wxS(
"FILL" ) || ptStr == wxS(
"PLANE" ) )
526 for( nlohmann::json& polyData : polyDataList )
530 std::vector<std::unique_ptr<PCB_SHAPE>> results =
531 m_v2Parser.ParsePoly(
nullptr, polyData,
true,
false );
533 for(
auto& shape : results )
535 shape->SetFilled(
true );
541 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( footprint );
543 zone->SetIsRuleArea(
true );
544 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
545 zone->SetDoNotAllowZoneFills( !!flags.count( 7 ) || !!flags.count( 6 ) || !!flags.count( 8 ) );
546 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
547 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
548 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
550 zone->SetLayer( klayer );
551 zone->Outline()->Append( polySet );
556 else if( row.
type == wxS(
"IMAGE" ) )
571 nlohmann::json polyDataList = row.
inner.value(
"path", nlohmann::json::array() );
574 std::vector<SHAPE_LINE_CHAIN> contours;
575 for( nlohmann::json& polyData : polyDataList )
580 contours.push_back( contour );
595 for(
int i = 0; i < contour.PointCount(); i++ )
606 std::unique_ptr<PCB_GROUP>
group;
609 group = std::make_unique<PCB_GROUP>( footprint );
615 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint,
SHAPE_T::POLY );
617 shape->SetFilled(
true );
618 shape->SetPolyShape( poly );
619 shape->SetLayer( klayer );
620 shape->SetWidth( 0 );
632 group->AddItem( shape.get() );
640 else if( row.
type == wxS(
"OBJ" ) )
657 if( imageUrl.empty() )
660 wxString mimeType, base64Data;
662 if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
664 wxString objectId = imageUrl.AfterLast(
':' );
666 if(
auto blob =
get_opt( aBlobMap, objectId ) )
668 wxString blobUrl = blob->url;
670 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
672 wxArrayString paramsArr = wxSplit( blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
674 base64Data = blobUrl.AfterFirst(
',' );
676 if( paramsArr.size() > 0 )
677 mimeType = paramsArr[0];
685 if( mimeType.empty() || base64Data.empty() )
688 wxMemoryBuffer buf = wxBase64Decode( base64Data );
690 if( mimeType == wxS(
"image/svg+xml" ) )
696 VECTOR2D kcenter = kstart + ksize / 2;
698 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
699 std::make_unique<PCB_REFERENCE_IMAGE>( footprint, kcenter, klayer );
702 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags() & ~wxImage::Load_Verbose );
714 int x = bitmap->GetPosition().x;
725 else if( row.
type == wxS(
"STRING" ) )
736 std::vector<PCB_SHAPE*> edgeShapes;
741 edgeShapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
752 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint,
SHAPE_T::RECTANGLE );
757 shape->SetEnd( bbox.
GetEnd() );
763 bool hasFabRef =
false;
769 if(
static_cast<PCB_TEXT*
>( item )->GetText() == wxT(
"${REFERENCE}" ) )
780 int c_refTextThickness =
pcbIUScale.mmToIU( 0.1 );
781 std::unique_ptr<PCB_TEXT> refText = std::make_unique<PCB_TEXT>( footprint );
783 refText->SetLayer(
F_Fab );
784 refText->SetTextSize(
VECTOR2I( c_refTextSize, c_refTextSize ) );
785 refText->SetTextThickness( c_refTextThickness );
786 refText->SetText( wxT(
"${REFERENCE}" ) );
843 if( aAlign == wxS(
"LEFT_TOP" ) )
845 if( aAlign == wxS(
"LEFT_CENTER" ) || aAlign == wxS(
"LEFT_MIDDLE" ) )
847 if( aAlign == wxS(
"LEFT_BOTTOM" ) )
849 if( aAlign == wxS(
"CENTER_TOP" ) )
851 if( aAlign == wxS(
"CENTER_MIDDLE" ) || aAlign == wxS(
"CENTER_CENTER" ) )
853 if( aAlign == wxS(
"CENTER_BOTTOM" ) )
855 if( aAlign == wxS(
"RIGHT_TOP" ) )
857 if( aAlign == wxS(
"RIGHT_CENTER" ) || aAlign == wxS(
"RIGHT_MIDDLE" ) )
859 if( aAlign == wxS(
"RIGHT_BOTTOM" ) )
867 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
868 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
869 const std::multimap<wxString, EASYEDAPRO::POURED>& aPouredMap,
870 const V3_DOC_RAW& aDoc,
const wxString& aFpLibName )
878 std::map<wxString, wxString> attrs;
890 bool keyVisible =
false;
891 bool valVisible =
false;
893 double fontSize = 45.0;
894 double strokeWidth = 6.0;
908 std::map<wxString, COMP_DATA> componentMap;
909 std::multimap<wxString, ATTR_DATA> attrMap;
910 std::multimap<wxString, PAD_NET_DATA> padNetMap;
912 std::multimap<wxString, EASYEDAPRO::POURED> boardPouredMap = aPouredMap;
913 std::map<wxString, ZONE*> poursToFill;
925 if( !idArr.is_array() || idArr.size() < 3 ||
V3JsonToString( idArr[1] ) != wxS(
"SAFE" ) )
928 nlohmann::json safeSpacing =
929 row.
inner.value(
"ruleContext", nlohmann::json() ).value(
"safeSpacing", nlohmann::json::array() );
931 if( safeSpacing.is_array() && !safeSpacing.empty() )
934 safeSpacing[0].value(
"content", nlohmann::json::array() ) );
959 if( row.
type == wxS(
"LAYER" ) )
967 if(
id.is_array() &&
id.size() > 1 )
972 if( layerId.ToLong( &parsedLayer ) )
988 blayers.
set( klayer );
991 if( !layerName.IsEmpty() )
995 else if( row.
type == wxS(
"NET" ) )
1000 if( idArr.is_array() && idArr.size() > 1 )
1003 if( !netname.IsEmpty() )
1008 else if( row.
type == wxS(
"RULE" ) )
1012 if( !idArr.is_array() || idArr.size() < 3 )
1016 bool isDefault =
V3GetString( row.
inner,
"ruleState" ) == wxS(
"DEFAULT" );
1018 nlohmann::json context = row.
inner.value(
"ruleContext", nlohmann::json() );
1020 if( ruleType == wxS(
"TRACK" ) && isDefault )
1022 nlohmann::json track = context.value(
"track", nlohmann::json() );
1023 nlohmann::json content = track.value(
"content", nlohmann::json::array() );
1025 if( content.is_array() && !content.empty() )
1027 double minVal =
V3GetDouble( content[0],
"stroMin" );
1032 else if( ruleType == wxS(
"SAFE" ) && isDefault )
1034 nlohmann::json safeSpacing = context.value(
"safeSpacing", nlohmann::json::array() );
1036 if( safeSpacing.is_array() && !safeSpacing.empty() )
1039 safeSpacing[0].value(
"content", nlohmann::json::array() ) );
1048 if( content.is_array() && !content.empty() && content.at( 0 ).is_array() && !content.at( 0 ).empty()
1049 && content.at( 0 ).at( 0 ).is_number() )
1051 double trackClearance = content.at( 0 ).at( 0 );
1053 if( trackClearance > 0 )
1062 double minEdgeClearance = 0;
1064 if( content.size() > 11 && content.at( 11 ).is_array() )
1066 for(
const nlohmann::json& value : content.at( 11 ) )
1068 if( value.is_number() && value.get<
double>() > 0
1069 && ( minEdgeClearance == 0 || value.get<
double>() < minEdgeClearance ) )
1071 minEdgeClearance = value;
1076 if( minEdgeClearance > 0 )
1084 else if( row.
type == wxS(
"VIA" ) )
1094 std::unique_ptr<PCB_VIA>
via = std::make_unique<PCB_VIA>( aBoard );
1104 else if( row.
type == wxS(
"LINE" ) )
1120 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( aBoard );
1122 track->SetLayer( klayer );
1126 track->SetNet( aBoard->
FindNet( netname ) );
1130 else if( row.
type == wxS(
"ARC" ) )
1150 double ha = angle / 2;
1151 double hd =
delta.EuclideanNorm() / 2;
1152 double cdist = hd / tan(
DEG2RAD( ha ) );
1160 std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( aBoard, &sarc );
1162 arc->SetLayer( klayer );
1163 arc->SetNet( aBoard->
FindNet( netname ) );
1167 else if( row.
type == wxS(
"POLY" ) )
1173 nlohmann::json polyData = row.
inner.value(
"path", nlohmann::json::array() );
1175 std::vector<std::unique_ptr<PCB_SHAPE>> results =
m_v2Parser.ParsePoly( aBoard, polyData,
false,
false );
1177 for(
auto& shape : results )
1179 shape->SetLayer( klayer );
1185 else if( row.
type == wxS(
"FILL" ) )
1192 nlohmann::json polyDataList = row.
inner.value(
"path", nlohmann::json::array() );
1194 if( polyDataList.is_null() || polyDataList.empty() )
1197 if( !polyDataList.at( 0 ).is_array() )
1198 polyDataList = nlohmann::json::array( { polyDataList } );
1200 std::vector<SHAPE_LINE_CHAIN> contours;
1202 for( nlohmann::json& polyData : polyDataList )
1206 contours.push_back( contour );
1218 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1220 zone->SetNet( aBoard->
FindNet( netname ) );
1221 zone->SetLayer( klayer );
1223 zone->SetFilledPolysList( klayer, zoneFillPoly );
1224 zone->SetAssignedPriority( 500 );
1225 zone->SetIsFilled(
true );
1226 zone->SetNeedRefill(
false );
1228 zone->SetLocalClearance( zoneClearance() );
1229 zone->SetMinThickness( zoneMinThickness );
1233 else if( row.
type == wxS(
"POUR" ) )
1241 nlohmann::json polyDataList = row.
inner.value(
"path", nlohmann::json::array() );
1243 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1245 zone->SetNet( aBoard->
FindNet( netname ) );
1246 zone->SetLayer( klayer );
1247 zone->SetAssignedPriority( 500 - fillOrder );
1248 zone->SetLocalClearance( zoneClearance() );
1249 zone->SetMinThickness( zoneMinThickness );
1251 for( nlohmann::json& polyData : polyDataList )
1255 zone->Outline()->Append( contour );
1258 wxASSERT( zone->Outline()->OutlineCount() == 1 );
1260 poursToFill.emplace( row.
id, zone.get() );
1264 else if( row.
type == wxS(
"TEARDROP" ) )
1270 nlohmann::json polyData = row.
inner.value(
"path", nlohmann::json::array() );
1275 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1277 zone->SetNet( aBoard->
FindNet( netname ) );
1278 zone->SetLayer( klayer );
1279 zone->Outline()->Append( contour );
1282 zone->SetFilledPolysList( klayer, teardropFill );
1283 zone->SetNeedRefill(
false );
1284 zone->SetIsFilled(
true );
1285 zone->SetAssignedPriority( 600 );
1286 zone->SetLocalClearance( 0 );
1287 zone->SetMinThickness( 0 );
1292 else if( row.
type == wxS(
"POURED" ) )
1297 if( idArr.is_array() && idArr.size() > 1 )
1300 nlohmann::json fills = row.
inner.value(
"pourFill", nlohmann::json::array() );
1302 if( !fills.is_array() )
1305 for(
const nlohmann::json& fill : fills )
1312 poured.
polyData = fill.value(
"path", nlohmann::json::array() );
1314 boardPouredMap.emplace( poured.
parentId, poured );
1317 else if( row.
type == wxS(
"REGION" ) )
1322 nlohmann::json polyDataList = row.
inner.value(
"path", nlohmann::json::array() );
1323 nlohmann::json prohibitTypes = row.
inner.value(
"prohibitType", nlohmann::json::array() );
1325 std::set<int> flags;
1327 if( prohibitTypes.is_array() )
1329 for(
const auto& pt : prohibitTypes )
1333 if( pt.is_string() )
1334 ptStr = pt.get<std::string>();
1336 if( ptStr == wxS(
"COMPONENT" ) )
1338 else if( ptStr == wxS(
"TRACK" ) )
1340 else if( ptStr == wxS(
"COPPER" ) )
1342 else if( ptStr == wxS(
"VIA" ) )
1344 else if( ptStr == wxS(
"FILL" ) || ptStr == wxS(
"PLANE" ) )
1349 for( nlohmann::json& polyData : polyDataList )
1354 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1356 zone->SetIsRuleArea(
true );
1357 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1358 zone->SetDoNotAllowZoneFills( !!flags.count( 7 ) || !!flags.count( 6 ) || !!flags.count( 8 ) );
1359 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1360 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1361 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1363 zone->SetLayer( klayer );
1364 zone->Outline()->Append( contour );
1369 else if( row.
type == wxS(
"STRING" ) )
1373 else if( row.
type == wxS(
"COMPONENT" ) )
1381 nlohmann::json attrsObj = row.
inner.value(
"attrs", nlohmann::json::object() );
1383 if( attrsObj.is_object() )
1385 for(
auto& [k, v] : attrsObj.items() )
1389 componentMap[row.
id] =
comp;
1391 else if( row.
type == wxS(
"ATTR" ) )
1416 attrMap.emplace( attr.parentId, attr );
1418 else if( row.
type == wxS(
"PAD_NET" ) )
1423 pn.compId = idArr.is_array() && idArr.size() > 1 ?
V3JsonToString( idArr[1] ) : wxString();
1424 pn.padNumber = idArr.is_array() && idArr.size() > 2 ?
V3JsonToString( idArr[2] ) : wxString();
1427 if( !pn.compId.IsEmpty() )
1428 padNetMap.emplace( pn.compId, pn );
1430 else if( row.
type == wxS(
"PAD" ) )
1434 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aBoard );
1446 footprint->SetPosition( pos );
1447 footprint->SetOrientation( orient );
1449 wxString fpName = wxS(
"Pad_" ) + row.
id;
1452 footprint->SetFPID( fpID );
1453 footprint->Reference().SetVisible(
true );
1454 footprint->Value().SetVisible(
true );
1455 footprint->AutoPositionFields();
1459 else if( row.
type == wxS(
"IMAGE" ) )
1474 nlohmann::json polyDataList = row.
inner.value(
"path", nlohmann::json::array() );
1477 std::vector<SHAPE_LINE_CHAIN> contours;
1478 for( nlohmann::json& polyData : polyDataList )
1483 contours.push_back( contour );
1498 for(
int i = 0; i < contour.PointCount(); i++ )
1509 std::unique_ptr<PCB_GROUP>
group;
1512 group = std::make_unique<PCB_GROUP>( aBoard );
1518 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aBoard,
SHAPE_T::POLY );
1520 shape->SetFilled(
true );
1521 shape->SetPolyShape( poly );
1522 shape->SetLayer( klayer );
1523 shape->SetWidth( 0 );
1535 group->AddItem( shape.get() );
1543 else if( row.
type == wxS(
"OBJ" ) )
1560 if( imageUrl.empty() )
1563 wxString mimeType, base64Data;
1565 if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
1567 wxString objectId = imageUrl.AfterLast(
':' );
1569 if(
auto blob =
get_opt( aBlobMap, objectId ) )
1571 wxString blobUrl = blob->url;
1573 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
1575 wxArrayString paramsArr = wxSplit( blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
1577 base64Data = blobUrl.AfterFirst(
',' );
1579 if( paramsArr.size() > 0 )
1580 mimeType = paramsArr[0];
1588 if( mimeType.empty() || base64Data.empty() )
1591 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1593 if( mimeType == wxS(
"image/svg+xml" ) )
1599 VECTOR2D kcenter = kstart + ksize / 2;
1601 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
1602 std::make_unique<PCB_REFERENCE_IMAGE>( aBoard, kcenter, klayer );
1605 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags() & ~wxImage::Load_Verbose );
1617 int x = bitmap->GetPosition().x;
1631 for(
auto const& [compId,
comp] : componentMap )
1634 wxString fpIdOverride;
1635 wxString fpDesignator;
1638 auto attrRange = attrMap.equal_range( compId );
1640 for(
auto it = attrRange.first; it != attrRange.second; ++it )
1642 const ATTR_DATA& attr = it->second;
1644 if( attr.key == wxS(
"Device" ) )
1645 deviceId = attr.value;
1646 else if( attr.key == wxS(
"Footprint" ) )
1647 fpIdOverride = attr.value;
1648 else if( attr.key == wxS(
"Designator" ) )
1649 fpDesignator = attr.value;
1654 const std::map<wxString, wxString>& deviceAttrs = deviceData.
attributes;
1656 wxString fpId = fpIdOverride;
1659 fpId =
get_def( deviceAttrs, wxS(
"Footprint" ), wxEmptyString );
1663 wxLogTrace(
traceEasyEdaIo, wxT(
"EasyEDA Pro v3 component '%s' (%s): no footprint mapping, skipping." ),
1664 compId, fpDesignator );
1668 auto it = aFootprintMap.find( fpId );
1670 if( it == aFootprintMap.end() )
1672 wxLogTrace(
traceEasyEdaIo,
"Footprint of '%s' with uuid '%s' not found.", fpDesignator, fpId );
1676 std::unique_ptr<FOOTPRINT>& footprintOrig = it->second;
1677 std::unique_ptr<FOOTPRINT> footprint(
static_cast<FOOTPRINT*
>( footprintOrig->Duplicate(
false ) ) );
1679 footprint->SetParent( aBoard );
1683 wxString libItemName = footprint->GetFPID().GetLibItemName();
1685 if( libItemName.empty() )
1688 footprint->SetFPID(
ToKiCadLibID( aFpLibName, libItemName ) );
1690 wxString modelUuid =
get_def( deviceAttrs, wxS(
"3D Model" ), wxEmptyString );
1691 wxString modelTitle =
get_def( deviceAttrs, wxS(
"3D Model Title" ), modelUuid ).Trim();
1692 wxString modelTransform =
get_def( deviceAttrs, wxS(
"3D Model Transform" ), wxEmptyString );
1694 m_v2Parser.FillFootprintModelInfo( footprint.get(), modelUuid, modelTitle, modelTransform );
1698 if( !valueText.empty() )
1699 footprint->SetValue( valueText );
1703 if( description.empty() )
1704 description =
get_def( deviceAttrs, wxS(
"Description" ), wxEmptyString );
1706 if( !description.empty() )
1713 [&](
const wxString& attrKey,
const wxString& value )
1717 if( attrKey == wxS(
"Datasheet" ) )
1720 field = footprint->GetField( attrKey );
1735 if( klayer ==
B_Cu )
1738 footprint->SetOrientationDegrees(
comp.angle );
1742 for(
auto attrIt = attrRange.first; attrIt != attrRange.second; ++attrIt )
1744 const ATTR_DATA& attr = attrIt->second;
1746 if( attr.key == wxS(
"Designator" ) )
1750 if( attr.fontName != wxS(
"default" ) )
1753 if( attr.valVisible && attr.keyVisible )
1754 field->
SetText( attr.key +
':' + attr.value );
1755 else if( attr.keyVisible )
1760 field->
SetVisible( attr.keyVisible || attr.valVisible );
1783 auto padNetRange = padNetMap.equal_range( compId );
1785 for(
auto pnIt = padNetRange.first; pnIt != padNetRange.second; ++pnIt )
1787 const PAD_NET_DATA& pn = pnIt->second;
1789 for(
PAD*
pad : footprint->Pads() )
1791 if(
pad->GetNumber() == pn.padNumber )
1802 for(
auto& [uuid, zone] : poursToFill )
1807 auto range = boardPouredMap.equal_range( uuid );
1809 for(
auto& pIt = range.first; pIt != range.second; ++pIt )
1815 for(
int dataId = 0; dataId < static_cast<int>( poured.
polyData.size() ); dataId++ )
1817 const nlohmann::json& fillData = poured.
polyData[dataId];
1818 const double ptScale = 10;
1823 for(
int i = 0; i < contour.
PointCount(); i++ )
1836 thisPoly.
Append( simple );
1845 const int thermalWidth =
pcbIUScale.mmToIU( 0.2 );
1847 for(
int segId = 0; segId < contour.
SegmentCount(); segId++ )
1857 fillPolySet.
Append( thisPoly );
1864 const int strokeWidth =
pcbIUScale.MilsToIU( 8 );
1871 zone->SetFilledPolysList( zone->GetFirstLayer(), fillPolySet );
1872 zone->SetNeedRefill(
false );
1873 zone->SetIsFilled(
true );
1879 std::vector<PCB_SHAPE*> shapes;
1887 shapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
1902 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
1903 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
1905 aBoard->
Move( offset );
constexpr int ARC_HIGH_DEF
constexpr EDA_IU_SCALE pcbIUScale
#define DEFAULT_COURTYARD_WIDTH
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
BASE_SET & set(size_t pos)
void Mirror(FLIP_DIRECTION aFlipDirection)
Mirror image vertically (i.e.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
int m_CopperEdgeClearance
void SetAuxOrigin(const VECTOR2I &aOrigin)
ZONE_SETTINGS & GetDefaultZoneSettings()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual void SetIsKnockout(bool aKnockout)
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Information pertinent to a Pcbnew printed circuit board.
bool m_LegacyDesignSettingsLoaded
True if the legacy board design settings were loaded from a file.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
NETINFO_ITEM * FindOrAddNet(const wxString &aNetName, int aNetCode=-1, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)
Return the net with the given name, adding it to the board if there is none.
const PAGE_INFO & GetPageSettings() const
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
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.
bool m_LegacyNetclassesLoaded
True if netclasses were loaded from the file.
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false, bool aPhysicalLayersOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
unsigned GetNetCount() const
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
BOARD_DESIGN_SETTINGS & GetDesignSettings()
const DRAWINGS & Drawings() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr const Vec GetEnd() const
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr const Vec GetCenter() const
constexpr const Vec & GetOrigin() const
constexpr const SizeVec & GetSize() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual void SetVisible(bool aVisible)
void SetTextAngleDegrees(double aOrientation)
void SetKeepUpright(bool aKeepUpright)
virtual void SetText(const wxString &aText)
void SetFont(KIFONT::FONT *aFont)
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
A logical library item identifier and consists of various portions much like a URI.
LSET is a set of PCB_LAYER_IDs.
void SetClearance(int aClearance)
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
@ NORMAL
Shape is the same on all layers.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
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 nlohmann::json NormalizeSafeSpacing(const nlohmann::json &aTable)
Map legacy eight- and ten-row safe-spacing matrices to the v3 category layout.
static T ScaleSize(T aValue)
static void SizeHoleOnlyPad(PAD &aPad, bool aPlated)
A hole with no copper around it takes the drill size, and stays unplated if the source says it is.
static VECTOR2< T > ScalePos(VECTOR2< T > aValue)
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 EASYEDAPRO::V3_DOC_RAW &aDoc, const wxString &aFpLibName)
PCB_IO_EASYEDAPRO_V3_PARSER(BOARD *aBoard, PROGRESS_REPORTER *aProgressReporter)
PCB_IO_EASYEDAPRO_PARSER m_v2Parser
nlohmann::json m_safeSpacing
std::unique_ptr< PAD > createV3PAD(FOOTPRINT *aFootprint, const EASYEDAPRO::V3_ROW &aRow)
wxString GenerateSafeSpacingRules() const
std::unique_ptr< FOOTPRINT > ParseFootprint(const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap, const EASYEDAPRO::V3_DOC_RAW &aDoc)
PCB_TEXT * createV3Text(BOARD_ITEM_CONTAINER *aContainer, const EASYEDAPRO::V3_ROW &aRow)
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
void SetPosition(const VECTOR2I &aPos) override
A progress reporter interface for use in multi-threaded environments.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
BITMAP_BASE & MutableImage() const
Only use this if you really need to modify the underlying image.
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
void SetImageScale(double aScale)
Set the image "zoom" value.
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual const VECTOR2I GetPoint(int aIndex) const override
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void RebuildHolesFromContours()
Extract all contours from this polygon set, then recreate polygons with holes.
int OutlineCount() const
Return the number of outlines in the set.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const std::vector< POLYGON > & CPolygons() const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
const SHAPE_LINE_CHAIN Outline() const
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ ROUND_ALL_CORNERS
All angles are rounded.
static bool empty(const wxTextEntryBase *aCtrl)
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
void ConnectBoardShapes(std::vector< PCB_SHAPE * > &aShapeList, int aChainingEpsilon)
Connects shapes to each other, making continious contours (adjacent shapes will have a common vertex)...
const wxChar *const traceEasyEdaIo
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
PCB_LAYER_ID
A quick note on layer IDs:
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)
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
@ LEFT_RIGHT
Flip left to right (around the Y axis)
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
LIB_ID ToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
bool V3GetBool(const nlohmann::json &aObj, const char *aKey, bool aDefault)
void ForEachImportedDeviceField(const std::map< wxString, wxString > &aDeviceAttributes, bool aIncludeValue, const std::function< void(const wxString &aKey, const wxString &aValue)> &aCallback)
Invoke aCallback for each non-empty whitelisted Device field (resolved + normalized).
wxString ResolveDeviceFieldVariables(const wxString &aInput, const std::map< wxString, wxString > &aDeviceAttributes)
Resolve EasyEDA ={Var} / ={A}text{B} field expressions against device attributes.
wxString NormalizeEasyEDAText(wxString aText)
Replace EasyEDA temperature glyph (℃) with °C.
V3_DEVICE_DATA GetV3DeviceData(const nlohmann::json &aProject, const wxString &aDeviceUuid)
static const bool IMPORT_POURED
nlohmann::json V3ParseIdArray(const wxString &aId)
bool V3IsNullOrMissing(const nlohmann::json &aObj, const char *aKey)
double V3GetDouble(const nlohmann::json &aObj, const char *aKey, double aDefault)
wxString V3JsonToString(const nlohmann::json &aValue, const wxString &aDefault)
wxString ResolveV3DeviceValueText(const std::map< wxString, wxString > &aDeviceAttributes)
Preferred Value text: Value attribute, else Name, with variables resolved.
int V3GetInt(const nlohmann::json &aObj, const char *aKey, int aDefault)
wxString V3GetString(const nlohmann::json &aObj, const char *aKey, const wxString &aDefault)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
Class to handle a set of BOARD_ITEMs.
static const int SHAPE_JOIN_DISTANCE
static wxString safeSpacingToMm(double aMil)
static int V3AlignToOriginCode(const wxString &aAlign)
static void V3AlignText(EDA_TEXT *text, int align)
static const wxString safeSpacingNames[]
static const wxString safeSpacingConditions[]
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
std::map< wxString, wxString > attributes
Raw parsed document from an EasyEDA Pro v3 .epru stream.
std::vector< V3_ROW > rows
One parsed row from an EasyEDA Pro v3 .epru document stream.
@ USER
The field ID hasn't been set yet; field is invalid.
@ DESCRIPTION
Field Description of part, i.e. "1/4W 1% Metal Film Resistor".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
static EDA_ORIENTATION orientation(double d)
static EDA_ANGLE deg(double d)
wxLogTrace helper definitions.
double DEG2RAD(double deg)
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D