37#include <wx/wfstream.h>
38#include <wx/stdstream.h>
82 if( !aValue.ToCDouble( &value ) )
91 if( !aTable.is_array() || ( aTable.size() != 8 && aTable.size() != 10 ) )
97 static constexpr size_t legacy8ToV3[] = { 0, 1, 2, 3, 4, 5, 6, 11 };
98 static constexpr size_t legacy10ToV3[] = { 0, 1, 2, 3, 4, 5, 6, 7, 11, 12 };
99 const size_t* legacyToV3 = aTable.size() == 8 ? legacy8ToV3 : legacy10ToV3;
101 nlohmann::json
normalized = nlohmann::json::array();
103 for(
size_t i = 0; i < 13; ++i )
104 normalized.push_back( nlohmann::json::array() );
106 for(
size_t sourceRow = 0; sourceRow < aTable.size(); ++sourceRow )
108 if( !aTable.at( sourceRow ).is_array() )
111 for(
size_t sourceCol = 0; sourceCol < aTable.at( sourceRow ).size() && sourceCol < aTable.size(); ++sourceCol )
113 normalized[legacyToV3[sourceRow]][legacyToV3[sourceCol]] = aTable.at( sourceRow ).at( sourceCol );
144 case 9:
return F_Fab;
145 case 10:
return B_Fab;
182 case 48:
return F_Fab;
183 case 49:
return F_Fab;
244 const wxString& modelTitle,
245 const wxString& modelTransform )
const
248 const wxString easyedaModelDir = wxS(
"EASYEDA_MODELS" );
249 const wxString kicadModelPrefix = wxS(
"${KIPRJMOD}/" ) + easyedaModelDir + wxS(
"/" );
260 footprint->
Add( field );
265 wxArrayString arr = wxSplit( modelTransform,
',',
'\0' );
270 if( fitXmm > 0.0 && fitYmm > 0.0 )
275 field->
SetText( wxString::FromCDouble( fitXmm ) + wxS(
" " ) + wxString::FromCDouble( fitYmm ) );
276 footprint->
Add( field );
279 kmodelRotation.
z = -
Convert( arr[3] );
280 kmodelRotation.
x = -
Convert( arr[4] );
281 kmodelRotation.
y = -
Convert( arr[5] );
288 if( !modelTitle.IsEmpty() && footprint->
Models().empty() )
292 model.m_Offset = kmodelOffset;
293 model.m_Rotation = kmodelRotation;
302constexpr double NM_PER_UNIT = 25400.0;
307std::vector<VECTOR2D> chordsForUnstorableArc(
const VECTOR2D& aStart,
const VECTOR2D& aEnd,
double aAngle )
312 double ha = aAngle / 2;
313 double hd =
delta.EuclideanNorm() / 2;
314 double cdist = ha == 0 ? 0 : hd / tan(
DEG2RAD( ha ) );
317 const double radiusNm = std::hypot( cdist, hd ) * NM_PER_UNIT;
318 const double limit = std::numeric_limits<int>::max();
320 if( ha != 0 &&
std::abs(
center.x ) * NM_PER_UNIT + radiusNm <= limit
326 double radius = ha == 0 ? 0 : std::hypot( cdist, hd );
331 double startAngle = std::atan2( v.
y, v.
x );
332 auto rotated = [&](
double aRotation )
334 return center +
VECTOR2D( v.
x * std::cos( aRotation ) - v.
y * std::sin( aRotation ),
335 v.
x * std::sin( aRotation ) + v.
y * std::cos( aRotation ) );
338 bool curveFits =
radius > 0
340 std::abs( aEnd.
y ) } ) * NM_PER_UNIT <= limit;
342 for(
int quadrant = 0; quadrant < 4 && curveFits; quadrant++ )
344 double cardinal = quadrant *
M_PI / 2;
345 double turn =
sweep > 0 ? cardinal - startAngle : startAngle - cardinal;
346 double reach = std::fmod( turn, 2 *
M_PI );
360 double maxStep = curveFits ? 2 * std::acos( 1 - ( 500.0 / NM_PER_UNIT ) /
radius ) : 0;
361 int count = maxStep > 0 ? std::max( 1, (
int) std::ceil(
std::abs(
sweep ) / maxStep ) ) : 1;
363 std::vector<VECTOR2D> points;
365 for(
int step = 1; step <= count; step++ )
366 points.push_back( step == count ? aEnd : rotated(
sweep * step / count ) );
374 nlohmann::json polyData,
bool aClosed,
377 std::vector<std::unique_ptr<PCB_SHAPE>> results;
380 for(
int i = 0; i < (int) polyData.size(); i++ )
382 nlohmann::json val = polyData.at( i );
384 if( val.is_string() )
387 if( str == wxS(
"CIRCLE" ) )
390 center.x = ( polyData.at( ++i ) );
391 center.y = ( polyData.at( ++i ) );
392 double r = ( polyData.at( ++i ) );
394 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::CIRCLE );
398 shape->SetFilled( aClosed );
400 results.emplace_back( std::move( shape ) );
402 else if( str == wxS(
"R" ) )
405 start.
x = ( polyData.at( ++i ) );
406 start.
y = ( polyData.at( ++i ) );
407 size.
x = ( polyData.at( ++i ) );
408 size.
y = -( polyData.at( ++i ).get<double>() );
409 double angle = polyData.at( ++i );
410 double cr = ( i + 1 ) < (
int) polyData.size() ? polyData.at( ++i ).get<
double>() : 0;
414 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::RECTANGLE );
416 shape->SetStart(
ScalePos( start ) );
417 shape->SetEnd(
ScalePos( start + size ) );
418 shape->SetFilled( aClosed );
421 results.emplace_back( std::move( shape ) );
429 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::SEGMENT );
431 shape->SetStart(
ScalePos( aStart ) );
433 shape->SetFilled( aClosed );
436 results.emplace_back( std::move( shape ) );
441 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::ARC );
443 shape->SetStart(
ScalePos( aStart ) );
446 shape->SetFilled( aClosed );
449 results.emplace_back( std::move( shape ) );
457 addArc( {
end.x - cr, start.
y }, {
end.x, start.
y - cr }, {
end.x - cr, start.
y - cr } );
461 addArc( { start.
x + cr,
end.y }, { start.
x,
end.y + cr }, { start.
x + cr,
end.y + cr } );
463 addArc( { start.
x, start.
y - cr }, { start.
x + cr, start.
y }, { start.
x + cr, start.
y - cr } );
466 else if( str == wxS(
"ARC" ) || str == wxS(
"CARC" ) )
469 double angle = polyData.at( ++i ).get<
double>() / ( aInFill ? 10 : 1 );
470 end.x = ( polyData.at( ++i ) );
471 end.y = ( polyData.at( ++i ) );
476 double ha = angle / 2;
477 double hd =
delta.EuclideanNorm() / 2;
478 double cdist = ha == 0 ? 0 : hd / tan(
DEG2RAD( ha ) );
481 if( std::vector<VECTOR2D> chords = chordsForUnstorableArc( prevPt,
end, angle ); !chords.empty() )
485 std::unique_ptr<PCB_SHAPE> line = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::SEGMENT );
487 line->SetStart(
ScalePos( prevPt ) );
489 line->SetFilled( aClosed );
490 results.emplace_back( std::move( line ) );
498 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::ARC );
502 shape->SetStart(
ScalePos( prevPt ) );
508 shape->SetEnd(
ScalePos( prevPt ) );
513 shape->SetFilled( aClosed );
515 results.emplace_back( std::move( shape ) );
519 else if( str == wxS(
"L" ) )
524 while( i < (
int) polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
527 pt.
x = ( polyData.at( ++i ) );
528 pt.
y = ( polyData.at( ++i ) );
537 if(
chain.PointCount() > 2 )
539 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::POLY );
541 chain.SetClosed(
true );
542 shape->SetFilled(
true );
543 shape->SetPolyShape(
chain );
545 results.emplace_back( std::move( shape ) );
550 for(
int s = 0; s <
chain.SegmentCount(); s++ )
554 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aContainer,
SHAPE_T::SEGMENT );
556 shape->SetStart( seg.
A );
557 shape->SetEnd( seg.
B );
559 results.emplace_back( std::move( shape ) );
564 else if( val.is_number() )
566 prevPt.
x = ( polyData.at( i ) );
567 prevPt.
y = ( polyData.at( ++i ) );
581 for(
int i = 0; i < (int) polyData.size(); i++ )
583 nlohmann::json val = polyData.at( i );
585 if( val.is_string() )
588 if( str == wxS(
"CIRCLE" ) )
591 center.x = ( polyData.at( ++i ) );
592 center.y = ( polyData.at( ++i ) );
593 double r = ( polyData.at( ++i ) );
597 else if( str == wxS(
"R" ) )
600 start.
x = ( polyData.at( ++i ) );
601 start.
y = ( polyData.at( ++i ) );
602 size.
x = ( polyData.at( ++i ) );
603 size.
y = ( polyData.at( ++i ).get<double>() );
604 double angle = polyData.at( ++i );
605 double cr = ( i + 1 ) < (
int) polyData.size() ? polyData.at( ++i ).get<
double>() : 0;
611 VECTOR2D kcenter = kstart + ksize / 2;
622 else if( str == wxS(
"ARC" ) || str == wxS(
"CARC" ) )
625 double angle = polyData.at( ++i ).get<
double>();
630 end.x = ( polyData.at( ++i ) );
631 end.y = ( polyData.at( ++i ) );
633 if( std::vector<VECTOR2D> chords = chordsForUnstorableArc( prevPt,
end, angle ); !chords.empty() )
646 result.Append( sarc, aMaxError );
651 else if( str == wxS(
"C" ) )
654 pt1.
x = ( polyData.at( ++i ) );
655 pt1.
y = ( polyData.at( ++i ) );
658 pt2.
x = ( polyData.at( ++i ) );
659 pt2.
y = ( polyData.at( ++i ) );
662 pt3.
x = ( polyData.at( ++i ) );
663 pt3.
y = ( polyData.at( ++i ) );
669 std::vector<VECTOR2I> bezierPoints;
670 converter.
GetPoly( bezierPoints, aMaxError );
672 result.Append( bezierPoints );
676 else if( str == wxS(
"L" ) )
680 while( i < (
int) polyData.size() - 2 && polyData.at( i + 1 ).is_number() )
683 pt.
x = ( polyData.at( ++i ) );
684 pt.
y = ( polyData.at( ++i ) );
692 else if( val.is_number() )
694 prevPt.
x = ( polyData.at( i ) );
695 prevPt.
y = ( polyData.at( ++i ) );
705 if( !aBoard || aNetName.empty() )
724 if( size.
x > 0 && size.
y > 0 )
743 wxString uuid = line.at( 1 );
750 wxString netname = line.at( 3 );
751 int layer = line.at( 4 ).get<
int>();
754 wxString padNumber = line.at( 5 );
762 nlohmann::json padHole = line.at( 9 );
763 nlohmann::json padShape = line.at( 10 );
765 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( aFootprint );
767 pad->SetNumber( padNumber );
774 bool hasHole =
false;
776 if( !padHole.is_null() && !padHole.empty() )
778 wxString holeShape = padHole.at( 0 );
780 if( holeShape == wxS(
"ROUND" ) || holeShape == wxS(
"SLOT" ) )
783 drill.
x = padHole.at( 1 );
784 drill.
y = padHole.at( 2 );
787 if( drill.
x > 0 || drill.
y > 0 )
791 double drill_dir = 0;
793 if( line.at( 14 ).is_number() )
794 drill_dir = line.at( 14 );
799 std::swap( drill.
x, drill.
y );
801 if( holeShape == wxS(
"SLOT" ) )
820 else if( klayer ==
B_Cu )
828 wxString padSh = padShape.at( 0 );
830 if( padSh == wxS(
"RECT" ) )
833 size.
x = padShape.at( 1 );
834 size.
y = padShape.at( 2 );
835 double cr_p = padShape.size() > 3 ? padShape.at( 3 ).get<
double>() : 0;
849 else if( padSh == wxS(
"ELLIPSE" ) )
852 size.
x = padShape.at( 1 );
853 size.
y = padShape.at( 2 );
858 else if( padSh == wxS(
"OVAL" ) )
861 size.
x = padShape.at( 1 );
862 size.
y = padShape.at( 2 );
867 else if( padSh == wxS(
"POLY" ) || padSh == wxS(
"POLYGON" ) )
873 nlohmann::json polyData = padShape.at( 1 );
878 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aFootprint,
SHAPE_T::POLY );
883 shape->SetFilled(
true );
884 shape->SetPolyShape( contour );
885 shape->SetLayer( klayer );
886 shape->SetWidth( 0 );
887 shape->Move( -
pad->GetPosition() );
894 SizeHoleOnlyPad( *
pad, !( line.size() > 15 && line.at( 15 ).is_number() && line.at( 15 ).get<
int>() == 0 ) );
903 const wxString& aFpUuid,
904 const std::vector<nlohmann::json>& aLines )
906 std::unique_ptr<FOOTPRINT> footprintPtr = std::make_unique<FOOTPRINT>(
m_board );
907 FOOTPRINT* footprint = footprintPtr.get();
910 const int defaultTextThickness(
pcbIUScale.mmToIU( 0.15 ) );
915 field->SetTextSize( defaultTextSize );
916 field->SetTextThickness( defaultTextThickness );
919 for(
const nlohmann::json& line : aLines )
921 if( line.size() == 0 )
924 wxString type = line.at( 0 );
926 if( type == wxS(
"CANVAS" ) )
928 if( line.size() > 2 && line.at( 1 ).is_number() && line.at( 2 ).is_number() )
933 else if( type == wxS(
"POLY" ) || type == wxS(
"PAD" ) || type == wxS(
"FILL" ) || type == wxS(
"ATTR" ) )
935 wxString uuid = line.at( 1 );
942 wxString netname = line.at( 3 );
943 int layer = line.at( 4 ).get<
int>();
946 if( type == wxS(
"POLY" ) )
948 double thickness = ( line.at( 5 ) );
949 nlohmann::json polyData = line.at( 6 );
951 std::vector<std::unique_ptr<PCB_SHAPE>> results =
ParsePoly( footprint, polyData,
false,
false );
953 for(
auto& shape : results )
955 shape->SetLayer( klayer );
956 shape->SetWidth(
ScaleSize( thickness ) );
961 else if( type == wxS(
"PAD" ) )
963 std::unique_ptr<PAD>
pad =
createPAD( footprint, line );
967 else if( type == wxS(
"FILL" ) )
969 int fillLayer = line.at( 4 ).get<
int>();
972 nlohmann::json polyDataList = line.at( 7 );
974 if( !polyDataList.is_null() && !polyDataList.empty() )
976 if( !polyDataList.at( 0 ).is_array() )
977 polyDataList = nlohmann::json::array( { polyDataList } );
979 std::vector<SHAPE_LINE_CHAIN> contours;
980 for( nlohmann::json& polyData : polyDataList )
985 contours.push_back( contour );
995 std::unique_ptr<PCB_GROUP>
group;
998 group = std::make_unique<PCB_GROUP>( footprint );
1002 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint,
SHAPE_T::POLY );
1004 shape->SetFilled(
true );
1005 shape->SetPolyShape( poly );
1006 shape->SetLayer( fillKlayer );
1007 shape->SetWidth( 0 );
1010 group->AddItem( shape.get() );
1019 else if( type == wxS(
"ATTR" ) )
1023 if( attr.
key == wxS(
"Designator" ) )
1027 else if( type == wxS(
"REGION" ) )
1029 wxString uuid = line.at( 1 );
1036 int layer = line.at( 3 ).get<
int>();
1039 std::set<int> flags = line.at( 5 );
1040 nlohmann::json polyDataList = line.at( 6 );
1042 for( nlohmann::json& polyData : polyDataList )
1046 std::vector<std::unique_ptr<PCB_SHAPE>> results =
ParsePoly(
nullptr, polyData,
true,
false );
1048 for(
auto& shape : results )
1050 shape->SetFilled(
true );
1056 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( footprint );
1058 zone->SetIsRuleArea(
true );
1059 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1060 zone->SetDoNotAllowZoneFills( !!flags.count( 7 ) || !!flags.count( 6 ) || !!flags.count( 8 ) );
1061 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1062 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1063 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1065 zone->SetLayer( klayer );
1066 zone->Outline()->Append( polySet );
1073 if( aProject.is_object() && aProject.contains(
"devices" ) )
1075 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at(
"devices" );
1076 std::map<wxString, wxString> compAttrs;
1078 for(
auto& [devUuid, devData] : devicesMap )
1080 if(
auto fp =
get_opt( devData.attributes,
"Footprint" ) )
1082 if( *fp == aFpUuid )
1084 compAttrs = devData.attributes;
1090 wxString modelUuid, modelTitle, modelTransform;
1092 modelUuid =
get_def( compAttrs,
"3D Model",
"" );
1093 modelTitle =
get_def( compAttrs,
"3D Model Title", modelUuid );
1094 modelTransform =
get_def( compAttrs,
"3D Model Transform",
"" );
1100 std::vector<PCB_SHAPE*> edgeShapes;
1105 edgeShapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
1116 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( footprint,
SHAPE_T::RECTANGLE );
1121 shape->SetEnd( bbox.
GetEnd() );
1126 bool hasFabRef =
false;
1132 if(
static_cast<PCB_TEXT*
>( item )->GetText() == wxT(
"${REFERENCE}" ) )
1143 int c_refTextSize =
pcbIUScale.mmToIU( 0.5 );
1144 int c_refTextThickness =
pcbIUScale.mmToIU( 0.1 );
1145 std::unique_ptr<PCB_TEXT> refText = std::make_unique<PCB_TEXT>( footprint );
1147 refText->SetLayer(
F_Fab );
1148 refText->SetTextSize(
VECTOR2I( c_refTextSize, c_refTextSize ) );
1149 refText->SetTextThickness( c_refTextThickness );
1150 refText->SetText( wxT(
"${REFERENCE}" ) );
1157 return footprintPtr;
1162 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
1163 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
1164 const std::multimap<wxString, EASYEDAPRO::POURED>& aPouredMap,
1165 const std::vector<nlohmann::json>& aLines,
const wxString& aFpLibName )
1167 std::map<wxString, std::vector<nlohmann::json>> componentLines;
1168 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
1170 std::multimap<wxString, EASYEDAPRO::POURED> boardPouredMap = aPouredMap;
1171 std::map<wxString, ZONE*> poursToFill;
1177 auto zoneClearance =
1197 std::map<wxString, nlohmann::json> safeSpacingProfiles;
1198 std::map<wxString, wxString> pourSafeSpacingProfiles;
1200 for(
const nlohmann::json& line : aLines )
1202 if( line.empty() || !line.at( 0 ).is_string() )
1205 wxString type = line.at( 0 );
1207 if( type == wxS(
"RULE" ) && line.size() > 4 && line.at( 1 ).get<wxString>() == wxS(
"1" )
1208 && line.at( 3 ).get<
int>() != 2 && line.at( 4 ).is_array() && line.at( 4 ).size() > 1
1209 && line.at( 4 ).at( 1 ).is_array() )
1211 safeSpacingProfiles[line.at( 2 ).get<wxString>()] =
NormalizeSafeSpacing( line.at( 4 ).at( 1 ) );
1213 else if( type == wxS(
"RULE_SELECTOR" ) && line.size() > 3 && line.at( 1 ).is_array() && line.at( 1 ).size() > 1
1214 && line.at( 1 ).at( 0 ).is_string() && line.at( 1 ).at( 0 ).get<wxString>() == wxS(
"POUR" )
1215 && line.at( 1 ).at( 1 ).is_string() && line.at( 3 ).is_object() && line.at( 3 ).contains(
"1" )
1216 && line.at( 3 ).at(
"1" ).is_string() )
1218 pourSafeSpacingProfiles[line.at( 1 ).at( 1 ).get<wxString>()] = line.at( 3 ).at(
"1" ).get<wxString>();
1223 for(
const nlohmann::json& line : aLines )
1225 if( line.size() == 0 )
1228 wxString type = line.at( 0 );
1230 if( type == wxS(
"LAYER" ) )
1232 int layer = line.at( 1 );
1235 wxString layerType = line.at( 2 );
1236 wxString layerName = line.at( 3 );
1237 int layerFlag = line.at( 4 );
1239 if( layerFlag != 0 )
1242 blayers.
set( klayer );
1247 else if( type == wxS(
"NET" ) )
1249 wxString netname = line.at( 1 );
1253 else if( type == wxS(
"RULE" ) )
1255 wxString ruleType = line.at( 1 );
1256 wxString ruleName = line.at( 2 );
1257 int isDefault = line.at( 3 );
1258 nlohmann::json ruleData = line.at( 4 );
1260 if( ruleType == wxS(
"3" ) && isDefault )
1262 wxString units = ruleData.at( 0 );
1264 if( ruleData.at( 1 ).is_number() )
1267 double minVal = ruleData.at( 1 );
1277 nlohmann::json
table = ruleData.at( 1 );
1279 for(
auto& [key, arr] :
table.items() )
1281 double minVal = arr.at( 0 );
1290 else if( ruleType == wxS(
"1" ) && isDefault )
1292 wxString units = ruleData.at( 0 );
1293 nlohmann::json
table = ruleData.at( 1 );
1295 if(
table.is_array() )
1306 if( safeSpacing.is_array() && !safeSpacing.empty() && safeSpacing.at( 0 ).is_array()
1307 && !safeSpacing.at( 0 ).empty() && safeSpacing.at( 0 ).at( 0 ).is_number() )
1309 double trackClearance = safeSpacing.at( 0 ).at( 0 );
1311 if( trackClearance > 0 )
1320 double minEdgeClearance = 0;
1322 if( safeSpacing.is_array() && safeSpacing.size() > 11 && safeSpacing.at( 11 ).is_array() )
1324 for(
const nlohmann::json& value : safeSpacing.at( 11 ) )
1326 if( value.is_number() && value.get<
double>() > 0
1327 && ( minEdgeClearance == 0 || value.get<
double>() < minEdgeClearance ) )
1329 minEdgeClearance = value;
1334 if( minEdgeClearance > 0 )
1341 ruleLines[ruleType].push_back( line );
1343 else if( type == wxS(
"POURED" ) )
1345 if( !line.at( 2 ).is_string() )
1349 boardPouredMap.emplace( poured.
parentId, poured );
1351 else if( type == wxS(
"VIA" ) || type == wxS(
"LINE" ) || type == wxS(
"ARC" ) || type == wxS(
"POLY" )
1352 || type == wxS(
"FILL" ) || type == wxS(
"POUR" ) )
1354 wxString uuid = line.at( 1 );
1361 wxString netname = line.at( 3 );
1363 if( type == wxS(
"VIA" ) )
1369 double drill = line.at( 7 );
1370 double dia = line.at( 8 );
1372 std::unique_ptr<PCB_VIA>
via = std::make_unique<PCB_VIA>( aBoard );
1379 via->SetNet(
getNet( aBoard, netname ) );
1383 else if( type == wxS(
"LINE" ) )
1385 int layer = line.at( 4 ).get<
int>();
1389 start.
x = line.at( 5 );
1390 start.
y = line.at( 6 );
1393 end.x = line.at( 7 );
1394 end.y = line.at( 8 );
1396 double width = line.at( 9 );
1398 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( aBoard );
1400 track->SetLayer( klayer );
1401 track->SetStart(
ScalePos( start ) );
1405 track->SetNet(
getNet( aBoard, netname ) );
1409 else if( type == wxS(
"ARC" ) )
1411 int layer = line.at( 4 ).get<
int>();
1415 start.
x = line.at( 5 );
1416 start.
y = line.at( 6 );
1419 end.x = line.at( 7 );
1420 end.y = line.at( 8 );
1422 double angle = line.at( 9 );
1423 double width = line.at( 10 );
1428 double ha = angle / 2;
1429 double hd =
delta.EuclideanNorm() / 2;
1430 double cdist = hd / tan(
DEG2RAD( ha ) );
1437 std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( aBoard, &sarc );
1440 arc->SetLayer( klayer );
1441 arc->SetNet(
getNet( aBoard, netname ) );
1445 else if( type == wxS(
"FILL" ) )
1447 int layer = line.at( 4 ).get<
int>();
1450 nlohmann::json polyDataList = line.at( 7 );
1452 if( !polyDataList.at( 0 ).is_array() )
1453 polyDataList = nlohmann::json::array( { polyDataList } );
1455 std::vector<SHAPE_LINE_CHAIN> contours;
1456 for( nlohmann::json& polyData : polyDataList )
1461 contours.push_back( contour );
1473 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1475 zone->SetNet(
getNet( aBoard, netname ) );
1476 zone->SetLayer( klayer );
1478 zone->SetFilledPolysList( klayer, zoneFillPoly );
1479 zone->SetAssignedPriority( 500 );
1480 zone->SetIsFilled(
true );
1481 zone->SetNeedRefill(
false );
1483 zone->SetLocalClearance( zoneClearance() );
1484 zone->SetMinThickness( zoneMinThickness );
1488 else if( type == wxS(
"POLY" ) )
1490 int layer = line.at( 4 );
1493 double thickness = line.at( 5 );
1494 nlohmann::json polyData = line.at( 6 );
1496 std::vector<std::unique_ptr<PCB_SHAPE>> results =
ParsePoly( aBoard, polyData,
false,
false );
1498 for( std::unique_ptr<PCB_SHAPE>& shape : results )
1500 shape->SetLayer( klayer );
1501 shape->SetWidth(
ScaleSize( thickness ) );
1506 else if( type == wxS(
"POUR" ) )
1508 int layer = line.at( 4 ).get<
int>();
1511 wxString pourname = line.at( 6 );
1512 int fillOrder = line.at( 7 ).get<
int>();
1513 nlohmann::json polyDataList = line.at( 8 );
1515 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1517 zone->SetNet(
getNet( aBoard, netname ) );
1518 zone->SetLayer( klayer );
1519 zone->SetAssignedPriority( 500 - fillOrder );
1520 int localClearance = zoneClearance();
1522 if(
auto selector = pourSafeSpacingProfiles.find( uuid ); selector != pourSafeSpacingProfiles.end() )
1524 auto profile = safeSpacingProfiles.find( selector->second );
1526 if( profile != safeSpacingProfiles.end() && profile->second.size() > 7
1527 && profile->second.at( 7 ).is_array() && !profile->second.at( 7 ).empty()
1528 && profile->second.at( 7 ).at( 0 ).is_number() )
1530 const int profileClearance =
ScaleSize( profile->second.at( 7 ).at( 0 ).get<
double>() );
1532 if( profileClearance > 0 )
1533 localClearance = profileClearance;
1537 zone->SetLocalClearance( localClearance );
1538 zone->SetMinThickness( zoneMinThickness );
1540 for( nlohmann::json& polyData : polyDataList )
1545 zone->Outline()->Append( contour );
1548 wxASSERT( zone->Outline()->OutlineCount() == 1 );
1550 poursToFill.emplace( uuid, zone.get() );
1555 else if( type == wxS(
"TEARDROP" ) )
1557 wxString uuid = line.at( 1 );
1558 wxString netname = line.at( 2 );
1559 int layer = line.at( 3 ).get<
int>();
1562 nlohmann::json polyData = line.at( 4 );
1567 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1569 zone->SetNet(
getNet( aBoard, netname ) );
1570 zone->SetLayer( klayer );
1571 zone->Outline()->Append( contour );
1574 zone->SetFilledPolysList( klayer, teardropFill );
1575 zone->SetNeedRefill(
false );
1576 zone->SetIsFilled(
true );
1578 zone->SetAssignedPriority( 600 );
1579 zone->SetLocalClearance( 0 );
1580 zone->SetMinThickness( 0 );
1585 else if( type == wxS(
"REGION" ) )
1587 wxString uuid = line.at( 1 );
1594 int layer = line.at( 3 ).get<
int>();
1597 std::set<int> flags = line.at( 5 );
1598 nlohmann::json polyDataList = line.at( 6 );
1600 for( nlohmann::json& polyData : polyDataList )
1605 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1607 zone->SetIsRuleArea(
true );
1608 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1609 zone->SetDoNotAllowZoneFills( !!flags.count( 7 ) || !!flags.count( 6 ) || !!flags.count( 8 ) );
1610 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1611 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1612 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1614 zone->SetLayer( klayer );
1615 zone->Outline()->Append( contour );
1620 else if( type == wxS(
"PAD" ) )
1622 wxString netname = line.at( 3 );
1624 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aBoard );
1625 std::unique_ptr<PAD>
pad =
createPAD( footprint.get(), line );
1627 pad->SetNet(
getNet( aBoard, netname ) );
1636 footprint->SetPosition( pos );
1637 footprint->SetOrientation( orient );
1639 wxString fpName = wxS(
"Pad_" ) + line.at( 1 ).get<wxString>();
1642 footprint->SetFPID( fpID );
1643 footprint->Reference().SetVisible(
true );
1644 footprint->Value().SetVisible(
true );
1645 footprint->AutoPositionFields();
1649 else if( type == wxS(
"IMAGE" ) )
1651 wxString uuid = line.at( 1 );
1658 int layer = line.at( 3 ).get<
int>();
1661 VECTOR2D start( line.at( 4 ), line.at( 5 ) );
1662 VECTOR2D size( line.at( 6 ), line.at( 7 ) );
1664 double angle = line.at( 8 );
1665 int mirror = line.at( 9 );
1666 nlohmann::json polyDataList = line.at( 10 );
1669 std::vector<SHAPE_LINE_CHAIN> contours;
1670 for( nlohmann::json& polyData : polyDataList )
1675 contours.push_back( contour );
1686 for(
int i = 0; i < contour.PointCount(); i++ )
1697 std::unique_ptr<PCB_GROUP>
group;
1700 group = std::make_unique<PCB_GROUP>( aBoard );
1706 std::unique_ptr<PCB_SHAPE> shape = std::make_unique<PCB_SHAPE>( aBoard,
SHAPE_T::POLY );
1708 shape->SetFilled(
true );
1709 shape->SetPolyShape( poly );
1710 shape->SetLayer( klayer );
1711 shape->SetWidth( 0 );
1720 shape->Mirror(
ScalePos( start ), flipDirection );
1724 group->AddItem( shape.get() );
1732 else if( type == wxS(
"OBJ" ) )
1735 wxString mimeType, base64Data;
1739 if( !line.at( 3 ).is_number() )
1742 int layer = line.at( 3 ).get<
int>();
1745 start =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
1746 size =
VECTOR2D( line.at( 7 ), line.at( 8 ) );
1747 angle = line.at( 9 );
1748 flipped = line.at( 10 );
1750 wxString imageUrl = line.at( 11 );
1752 if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
1754 wxString objectId = imageUrl.AfterLast(
':' );
1756 if(
auto blob =
get_opt( aBlobMap, objectId ) )
1758 wxString blobUrl = blob->url;
1760 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
1762 wxArrayString paramsArr = wxSplit( blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
1764 base64Data = blobUrl.AfterFirst(
',' );
1766 if( paramsArr.size() > 0 )
1767 mimeType = paramsArr[0];
1775 if( mimeType.empty() || base64Data.empty() )
1778 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1780 if( mimeType == wxS(
"image/svg+xml" ) )
1786 VECTOR2D kcenter = kstart + ksize / 2;
1788 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
1789 std::make_unique<PCB_REFERENCE_IMAGE>( aBoard, kcenter, klayer );
1792 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags() & ~wxImage::Load_Verbose );
1804 int x = bitmap->GetPosition().x;
1815 else if( type == wxS(
"STRING" ) )
1817 wxString uuid = line.at( 1 );
1824 int layer = line.at( 3 ).get<
int>();
1828 wxString
string = line.at( 6 );
1829 wxString font = line.at( 7 );
1831 double height = line.at( 8 );
1832 double strokew = line.at( 9 );
1834 int align = line.at( 12 );
1835 double angle = line.at( 13 );
1836 int inverted = line.at( 14 );
1837 int mirror = line.at( 16 );
1841 text->SetText(
string );
1842 text->SetLayer( klayer );
1844 text->SetIsKnockout( inverted );
1848 if( font != wxS(
"default" ) )
1861 text->SetMirrored(
true );
1862 text->SetTextAngleDegrees( -angle );
1866 text->SetTextAngleDegrees( angle );
1871 else if( type == wxS(
"COMPONENT" ) )
1873 wxString compId = line.at( 1 );
1874 componentLines[compId].push_back( line );
1876 else if( type == wxS(
"ATTR" ) )
1878 wxString compId = line.at( 3 );
1879 componentLines[compId].push_back( line );
1881 else if( type == wxS(
"PAD_NET" ) )
1883 wxString compId = line.at( 1 );
1884 componentLines[compId].push_back( line );
1888 for(
auto const& [compId, lines] : componentLines )
1891 wxString fpIdOverride;
1892 wxString fpDesignator;
1893 std::map<wxString, wxString> localCompAttribs;
1895 for(
auto& line : lines )
1897 if( line.size() == 0 )
1900 wxString type = line.at( 0 );
1902 if( type == wxS(
"COMPONENT" ) )
1904 localCompAttribs = line.at( 7 );
1906 else if( type == wxS(
"ATTR" ) )
1910 if( attr.
key == wxS(
"Device" ) )
1911 deviceId = attr.
value;
1913 else if( attr.
key == wxS(
"Footprint" ) )
1914 fpIdOverride = attr.
value;
1916 else if( attr.
key == wxS(
"Designator" ) )
1917 fpDesignator = attr.
value;
1921 if( deviceId.empty() )
1924 nlohmann::json compAttrs = aProject.at(
"devices" ).at( deviceId ).at(
"attributes" );
1928 if( !fpIdOverride.IsEmpty() )
1929 fpId = fpIdOverride;
1931 fpId = compAttrs.at(
"Footprint" ).get<wxString>();
1933 auto it = aFootprintMap.find( fpId );
1934 if( it == aFootprintMap.end() )
1936 wxLogTrace(
traceEasyEdaIo,
"Footprint of '%s' with uuid '%s' not found.", fpDesignator, fpId );
1940 std::unique_ptr<FOOTPRINT>& footprintOrig = it->second;
1941 std::unique_ptr<FOOTPRINT> footprint(
static_cast<FOOTPRINT*
>( footprintOrig->Duplicate(
false ) ) );
1943 wxString modelUuid, modelTitle, modelTransform;
1945 if(
auto val =
get_opt( localCompAttribs,
"3D Model" ) )
1948 modelUuid = compAttrs.value<wxString>(
"3D Model",
"" );
1950 if(
auto val =
get_opt( localCompAttribs,
"3D Model Title" ) )
1951 modelTitle = val->Trim();
1953 modelTitle = compAttrs.value<wxString>(
"3D Model Title", modelUuid ).Trim();
1955 if(
auto val =
get_opt( localCompAttribs,
"3D Model Transform" ) )
1956 modelTransform = *val;
1958 modelTransform = compAttrs.value<wxString>(
"3D Model Transform",
"" );
1962 footprint->SetParent( aBoard );
1964 for(
auto& line : lines )
1966 if( line.size() == 0 )
1969 wxString type = line.at( 0 );
1971 if( type == wxS(
"COMPONENT" ) )
1973 int layer = line.at( 3 );
1978 double orient = line.at( 6 );
1981 if( klayer ==
B_Cu )
1984 footprint->SetOrientationDegrees( orient );
1987 else if( type == wxS(
"ATTR" ) )
1995 if( attr.
key == wxS(
"Designator" ) )
1997 if( attr.
key == wxS(
"Designator" ) )
2007 if( attr.
fontName != wxS(
"default" ) )
2034 else if( type == wxS(
"PAD_NET" ) )
2036 wxString padNumber = line.at( 2 );
2037 wxString padNet = line.at( 3 );
2039 for(
PAD*
pad : footprint->Pads() )
2041 if(
pad->GetNumber() == padNumber )
2042 pad->SetNet(
getNet( aBoard, padNet ) );
2053 for(
auto& [uuid, zone] : poursToFill )
2058 auto range = boardPouredMap.equal_range( uuid );
2059 for(
auto& it = range.first; it != range.second; ++it )
2065 for(
int dataId = 0; dataId < (int) poured.
polyData.size(); dataId++ )
2067 const nlohmann::json& fillData = poured.
polyData[dataId];
2068 const double ptScale = 10;
2073 for(
int i = 0; i < contour.
PointCount(); i++ )
2086 thisPoly.
Append( simple );
2095 const int thermalWidth =
pcbIUScale.mmToIU( 0.2 );
2097 for(
int segId = 0; segId < contour.
SegmentCount(); segId++ )
2107 fillPolySet.
Append( thisPoly );
2114 const int strokeWidth =
pcbIUScale.MilsToIU( 8 );
2122 zone->SetFilledPolysList( zone->GetFirstLayer(), fillPolySet );
2123 zone->SetNeedRefill(
false );
2124 zone->SetIsFilled(
true );
2130 std::vector<PCB_SHAPE*> shapes;
2138 shapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
2154 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
2155 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
2157 aBoard->
Move( offset );
static std::optional< VECTOR2D > normalized(const VECTOR2D &aVec)
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)
Bezier curves to polygon converter.
void GetPoly(std::vector< VECTOR2I > &aOutput, int aMaxError=10)
Convert a Bezier curve to a polygon.
void Mirror(FLIP_DIRECTION aFlipDirection)
Mirror image vertically (i.e.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
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)
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)
Handle the data for a net.
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
void SetAttribute(PAD_ATTRIB aAttribute)
static LSET PTHMask()
layer set for a through hole pad
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
VECTOR2I GetDrillSize() const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
PAD_DRILL_SHAPE GetDrillShape() const
static LSET SMDMask()
layer set for a SMD pad on Front layer
void SetLayerSet(const LSET &aLayers) override
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)
PCB_IO_EASYEDAPRO_PARSER(BOARD *aBoard, PROGRESS_REPORTER *aProgressReporter)
std::unique_ptr< FOOTPRINT > ParseFootprint(const nlohmann::json &aProject, const wxString &aFpUuid, const std::vector< nlohmann::json > &aLines)
std::vector< std::unique_ptr< PCB_SHAPE > > ParsePoly(BOARD_ITEM_CONTAINER *aContainer, nlohmann::json polyData, bool aClosed, bool aInFill) const
wxString GetSafeSpacingRules() const
SHAPE_LINE_CHAIN ParseContour(nlohmann::json polyData, bool aInFill, int aMaxError=SHAPE_ARC::DefaultAccuracyForPCB()) const
NETINFO_ITEM * getNet(BOARD *aBoard, const wxString &aNetName)
void FillFootprintModelInfo(FOOTPRINT *footprint, const wxString &modelUuid, const wxString &modelTitle, const wxString &modelTransform) const
void ParseBoard(BOARD *aBoard, const nlohmann::json &aProject, std::map< wxString, std::unique_ptr< FOOTPRINT > > &aFootprintMap, const std::map< wxString, EASYEDAPRO::BLOB > &aBlobMap, const std::multimap< wxString, EASYEDAPRO::POURED > &aPouredMap, const std::vector< nlohmann::json > &aLines, const wxString &aFpLibName)
std::unique_ptr< PAD > createPAD(FOOTPRINT *aFootprint, const nlohmann::json &line)
PCB_LAYER_ID LayerToKi(int aLayer)
static double Convert(wxString aValue)
nlohmann::json m_safeSpacing
~PCB_IO_EASYEDAPRO_PARSER()
wxString GenerateSafeSpacingRules() const
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 & ConstructFromStartEndAngle(const VECTOR2I &aStart, const VECTOR2I &aEnd, const EDA_ANGLE &aAngle, double aWidth=0)
Construct this arc from the given start, end and angle.
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual const VECTOR2I GetPoint(int aIndex) const override
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a set of closed polygons.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
void RebuildHolesFromContours()
Extract all contours from this polygon set, then recreate polygons with holes.
int OutlineCount() const
Return the number of outlines in the set.
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const std::vector< POLYGON > & CPolygons() const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
const SHAPE_LINE_CHAIN Outline() const
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aPosition, const VECTOR2I &aSize, const EDA_ANGLE &aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ ROUND_ALL_CORNERS
All angles are rounded.
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)...
#define THROW_IO_ERRORF(msg,...)
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)
static const bool IMPORT_POURED
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ 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 wxString MODEL_SIZE_KEY
static const int SHAPE_JOIN_DISTANCE
static void AlignText(EDA_TEXT *text, int align)
static const wxString QUERY_MODEL_UUID_KEY
static bool addSegment(VRML_LAYER &model, IDF_SEGMENT *seg, int icont, int iseg)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ USER
The field ID hasn't been set yet; field is invalid.
@ REFERENCE
Field Reference of part, i.e. "IC21".
static EDA_ORIENTATION orientation(double d)
static EDA_ANGLE deg(double d)
const SHAPE_LINE_CHAIN chain
static double sweep(float aStart, float aEnd)
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
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
VECTOR3< double > VECTOR3D