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 if( padHole.at( 0 ) == wxS(
"ROUND" ) || padHole.at( 0 ) == wxS(
"SLOT" ) )
631 drill.
x = padHole.at( 1 );
632 drill.
y = padHole.at( 2 );
637 std::swap( drill.
x, drill.
y );
639 if( padHole.at( 0 ) == wxS(
"SLOT" ) )
646 pad->SetAttribute( PAD_ATTRIB::PTH );
655 else if( klayer ==
B_Cu )
660 pad->SetAttribute( PAD_ATTRIB::SMD );
663 wxString padSh = padShape.at( 0 );
664 if( padSh == wxS(
"RECT" ) )
667 size.
x = padShape.at( 1 );
668 size.
y = padShape.at( 2 );
669 double cr_p = padShape.size() > 3 ? padShape.at( 3 ).get<
double>() : 0;
675 pad->SetShape( PAD_SHAPE::RECTANGLE );
679 pad->SetShape( PAD_SHAPE::ROUNDRECT );
680 pad->SetRoundRectRadiusRatio( cr_p / 100 );
683 else if( padSh == wxS(
"ELLIPSE" ) )
686 size.
x = padShape.at( 1 );
687 size.
y = padShape.at( 2 );
690 pad->SetShape( PAD_SHAPE::CIRCLE );
692 else if( padSh == wxS(
"OVAL" ) )
695 size.
x = padShape.at( 1 );
696 size.
y = padShape.at( 2 );
699 pad->SetShape( PAD_SHAPE::OVAL );
701 else if( padSh == wxS(
"POLY" ) )
703 pad->SetShape( PAD_SHAPE::CUSTOM );
704 pad->SetAnchorPadShape( PAD_SHAPE::CIRCLE );
705 pad->SetSize( { 1, 1 } );
707 nlohmann::json polyData = padShape.at( 1 );
709 std::vector<std::unique_ptr<PCB_SHAPE>> results =
710 ParsePoly( aFootprint, polyData,
true,
false );
712 for(
auto& shape : results )
714 shape->SetLayer( klayer );
715 shape->SetWidth( 0 );
717 shape->Move( -
pad->GetPosition() );
719 pad->AddPrimitive( shape.release() );
725 return std::move(
pad );
730 const wxString& aFpUuid,
731 const std::vector<nlohmann::json>& aLines )
733 std::unique_ptr<FOOTPRINT> footprintPtr = std::make_unique<FOOTPRINT>(
m_board );
734 FOOTPRINT* footprint = footprintPtr.get();
741 field->SetTextSize( defaultTextSize );
742 field->SetTextThickness( defaultTextThickness );
745 for(
const nlohmann::json& line : aLines )
747 if( line.size() == 0 )
750 wxString type = line.at( 0 );
752 if( type == wxS(
"POLY" ) || type == wxS(
"PAD" ) || type == wxS(
"FILL" )
753 || type == wxS(
"ATTR" ) )
755 wxString uuid = line.at( 1 );
762 wxString netname = line.at( 3 );
763 int layer = line.at( 4 ).get<
int>();
766 if( type == wxS(
"POLY" ) )
768 double thickness = ( line.at( 5 ) );
769 nlohmann::json polyData = line.at( 6 );
771 std::vector<std::unique_ptr<PCB_SHAPE>> results =
772 ParsePoly( footprint, polyData,
false,
false );
774 for(
auto& shape : results )
776 shape->SetLayer( klayer );
777 shape->SetWidth(
ScaleSize( thickness ) );
779 footprint->
Add( shape.release(), ADD_MODE::APPEND );
782 else if( type == wxS(
"PAD" ) )
784 std::unique_ptr<PAD>
pad =
createPAD( footprint, line );
786 footprint->
Add(
pad.release(), ADD_MODE::APPEND );
788 else if( type == wxS(
"FILL" ) )
790 int layer = line.at( 4 ).get<
int>();
793 double width = line.at( 5 );
795 nlohmann::json polyDataList = line.at( 7 );
797 if( !polyDataList.at( 0 ).is_array() )
798 polyDataList = nlohmann::json::array( { polyDataList } );
800 std::vector<SHAPE_LINE_CHAIN> contours;
801 for( nlohmann::json& polyData : polyDataList )
806 contours.push_back( contour );
816 std::unique_ptr<PCB_GROUP>
group;
819 group = std::make_unique<PCB_GROUP>( footprint );
825 std::unique_ptr<PCB_SHAPE> shape =
826 std::make_unique<PCB_SHAPE>( footprint, SHAPE_T::POLY );
828 shape->SetFilled(
true );
829 shape->SetPolyShape( poly );
830 shape->SetLayer( klayer );
831 shape->SetWidth( 0 );
834 group->AddItem( shape.get() );
836 footprint->
Add( shape.release(), ADD_MODE::APPEND );
840 footprint->
Add(
group.release(), ADD_MODE::APPEND );
842 else if( type == wxS(
"ATTR" ) )
846 if( attr.
key == wxS(
"Designator" ) )
850 else if( type == wxS(
"REGION" ) )
852 wxString uuid = line.at( 1 );
859 int layer = line.at( 3 ).get<
int>();
862 double width = line.at( 4 );
863 std::set<int> flags = line.at( 5 );
864 nlohmann::json polyDataList = line.at( 6 );
866 for( nlohmann::json& polyData : polyDataList )
870 std::vector<std::unique_ptr<PCB_SHAPE>> results =
871 ParsePoly(
nullptr, polyData,
true,
false );
873 for(
auto& shape : results )
875 shape->SetFilled(
true );
882 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( footprint );
884 zone->SetIsRuleArea(
true );
885 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
886 zone->SetDoNotAllowCopperPour( !!flags.count( 7 ) || !!flags.count( 6 )
887 || !!flags.count( 8 ) );
888 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
889 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
890 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
892 zone->SetLayer( klayer );
893 zone->Outline()->Append( polySet );
895 footprint->
Add( zone.release(), ADD_MODE::APPEND );
900 if( aProject.is_object() )
902 std::map<wxString, EASYEDAPRO::PRJ_DEVICE> devicesMap = aProject.at(
"devices" );
903 std::map<wxString, wxString> compAttrs;
905 for(
auto& [devUuid, devData] : devicesMap )
907 if(
auto fp =
get_opt( devData.attributes,
"Footprint" ) )
911 compAttrs = devData.attributes;
917 wxString modelUuid, modelTitle, modelTransform;
919 modelUuid =
get_def( compAttrs,
"3D Model",
"" );
920 modelTitle =
get_def( compAttrs,
"3D Model Title", modelUuid );
921 modelTransform =
get_def( compAttrs,
"3D Model Transform",
"" );
927 std::vector<PCB_SHAPE*> shapes;
928 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
936 shapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
941 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
942 footprint->
Add( ptr.release(), ADD_MODE::APPEND );
944 return footprintPtr.release();
949 BOARD* aBoard,
const nlohmann::json& aProject,
950 std::map<wxString, std::unique_ptr<FOOTPRINT>>& aFootprintMap,
951 const std::map<wxString, EASYEDAPRO::BLOB>& aBlobMap,
952 const std::multimap<wxString, EASYEDAPRO::POURED>& aPouredMap,
953 const std::vector<nlohmann::json>& aLines,
const wxString& aFpLibName )
955 std::map<wxString, std::vector<nlohmann::json>> componentLines;
956 std::map<wxString, std::vector<nlohmann::json>> ruleLines;
960 for(
const nlohmann::json& line : aLines )
962 if( line.size() == 0 )
965 wxString type = line.at( 0 );
967 if( type == wxS(
"LAYER" ) )
969 int layer = line.at( 1 );
972 wxString layerType = line.at( 2 );
973 wxString layerName = line.at( 3 );
974 int layerFlag = line.at( 4 );
979 blayers.set( klayer );
984 else if( type == wxS(
"NET" ) )
986 wxString netname = line.at( 1 );
991 else if( type == wxS(
"RULE" ) )
993 wxString ruleType = line.at( 1 );
994 wxString ruleName = line.at( 2 );
995 int isDefault = line.at( 3 );
996 nlohmann::json ruleData = line.at( 4 );
998 if( ruleType == wxS(
"3" ) && isDefault )
1000 wxString units = ruleData.at( 0 );
1001 double minVal = ruleData.at( 1 );
1002 double optVal = ruleData.at( 2 );
1003 double maxVal = ruleData.at( 3 );
1007 else if( ruleType == wxS(
"1" ) && isDefault )
1009 wxString units = ruleData.at( 0 );
1010 nlohmann::json table = ruleData.at( 1 );
1012 int minVal = INT_MAX;
1013 for(
const std::vector<int>& arr : table )
1015 for(
int val : arr )
1025 ruleLines[ruleType].push_back( line );
1027 else if( type == wxS(
"VIA" ) || type == wxS(
"LINE" ) || type == wxS(
"ARC" )
1028 || type == wxS(
"POLY" ) || type == wxS(
"FILL" ) || type == wxS(
"POUR" ) )
1030 wxString uuid = line.at( 1 );
1037 wxString netname = line.at( 3 );
1039 if( type == wxS(
"VIA" ) )
1042 center.
x = line.at( 5 );
1043 center.
y = line.at( 6 );
1045 double drill = line.at( 7 );
1046 double dia = line.at( 8 );
1048 std::unique_ptr<PCB_VIA>
via = std::make_unique<PCB_VIA>( aBoard );
1056 aBoard->
Add(
via.release(), ADD_MODE::APPEND );
1058 else if( type == wxS(
"LINE" ) )
1060 int layer = line.at( 4 ).get<
int>();
1064 start.
x = line.at( 5 );
1065 start.
y = line.at( 6 );
1068 end.
x = line.at( 7 );
1069 end.
y = line.at( 8 );
1071 double width = line.at( 9 );
1073 std::unique_ptr<PCB_TRACK> track = std::make_unique<PCB_TRACK>( aBoard );
1075 track->SetLayer( klayer );
1076 track->SetStart(
ScalePos( start ) );
1080 track->SetNet( aBoard->
FindNet( netname ) );
1082 aBoard->
Add( track.release(), ADD_MODE::APPEND );
1084 else if( type == wxS(
"ARC" ) )
1086 int layer = line.at( 4 ).get<
int>();
1090 start.
x = line.at( 5 );
1091 start.
y = line.at( 6 );
1094 end.
x = line.at( 7 );
1095 end.
y = line.at( 8 );
1097 double angle = line.at( 9 );
1098 double width = line.at( 10 );
1103 double ha = angle / 2;
1104 double hd =
delta.EuclideanNorm() / 2;
1105 double cdist = hd / tan(
DEG2RAD( ha ) );
1106 VECTOR2D center = mid +
delta.Perpendicular().Resize( cdist );
1110 ScalePos( center ), angle >= 0, width );
1112 std::unique_ptr<PCB_ARC> arc = std::make_unique<PCB_ARC>( aBoard, &sarc );
1115 arc->SetLayer( klayer );
1116 arc->SetNet( aBoard->
FindNet( netname ) );
1118 aBoard->
Add( arc.release(), ADD_MODE::APPEND );
1120 else if( type == wxS(
"FILL" ) )
1122 int layer = line.at( 4 ).get<
int>();
1125 double width = line.at( 5 );
1127 nlohmann::json polyDataList = line.at( 7 );
1129 if( !polyDataList.at( 0 ).is_array() )
1130 polyDataList = nlohmann::json::array( { polyDataList } );
1132 std::vector<SHAPE_LINE_CHAIN> contours;
1133 for( nlohmann::json& polyData : polyDataList )
1138 contours.push_back( contour );
1149 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1151 zone->SetNet( aBoard->
FindNet( netname ) );
1152 zone->SetLayer( klayer );
1154 zone->SetFilledPolysList( klayer, zoneFillPoly );
1155 zone->SetAssignedPriority( 500 );
1156 zone->SetIsFilled(
true );
1157 zone->SetNeedRefill(
false );
1162 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1164 else if( type == wxS(
"POLY" ) )
1166 int layer = line.at( 4 );
1169 double thickness = line.at( 5 );
1170 nlohmann::json polyData = line.at( 6 );
1172 std::vector<std::unique_ptr<PCB_SHAPE>> results =
1173 ParsePoly( aBoard, polyData,
false,
false );
1175 for(
auto& shape : results )
1177 shape->SetLayer( klayer );
1178 shape->SetWidth(
ScaleSize( thickness ) );
1180 aBoard->
Add( shape.release(), ADD_MODE::APPEND );
1183 else if( type == wxS(
"POUR" ) )
1185 int layer = line.at( 4 ).get<
int>();
1188 double lineWidth = line.at( 5 );
1189 wxString pourname = line.at( 6 );
1190 int fillOrder = line.at( 7 ).get<
int>();
1191 nlohmann::json polyDataList = line.at( 8 );
1193 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1195 zone->SetNet( aBoard->
FindNet( netname ) );
1196 zone->SetLayer( klayer );
1197 zone->SetAssignedPriority( 500 - fillOrder );
1201 for( nlohmann::json& polyData : polyDataList )
1206 zone->Outline()->Append( contour );
1209 wxASSERT( zone->Outline()->OutlineCount() == 1 );
1217 auto range = aPouredMap.equal_range( uuid );
1218 for(
auto& it = range.first; it != range.second; ++it )
1221 int unki = poured.
unki;
1225 for(
int dataId = 0; dataId < poured.
polyData.size(); dataId++ )
1227 const nlohmann::json& fillData = poured.
polyData[dataId];
1228 const double ptScale = 10;
1234 for(
int i = 0; i < contour.
PointCount(); i++ )
1247 thisPoly.
Append( simple );
1259 for(
int segId = 0; segId < contour.
SegmentCount(); segId++ )
1270 fillPolySet.
Append( thisPoly );
1281 fillPolySet.
Inflate( strokeWidth / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS,
1288 zone->SetFilledPolysList( klayer, fillPolySet );
1289 zone->SetNeedRefill(
false );
1290 zone->SetIsFilled(
true );
1294 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1297 else if( type == wxS(
"TEARDROP" ) )
1299 wxString uuid = line.at( 1 );
1300 wxString netname = line.at( 2 );
1301 int layer = line.at( 3 ).get<
int>();
1304 nlohmann::json polyData = line.at( 4 );
1309 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1311 zone->SetNet( aBoard->
FindNet( netname ) );
1312 zone->SetLayer( klayer );
1313 zone->Outline()->Append( contour );
1314 zone->SetFilledPolysList( klayer, contour );
1315 zone->SetNeedRefill(
false );
1316 zone->SetIsFilled(
true );
1318 zone->SetAssignedPriority( 600 );
1319 zone->SetLocalClearance( 0 );
1320 zone->SetMinThickness( 0 );
1321 zone->SetTeardropAreaType( TEARDROP_TYPE::TD_UNSPECIFIED );
1323 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1325 else if( type == wxS(
"REGION" ) )
1327 wxString uuid = line.at( 1 );
1334 int layer = line.at( 3 ).get<
int>();
1337 double width = line.at( 4 );
1338 std::set<int> flags = line.at( 5 );
1339 nlohmann::json polyDataList = line.at( 6 );
1341 for( nlohmann::json& polyData : polyDataList )
1346 std::unique_ptr<ZONE> zone = std::make_unique<ZONE>( aBoard );
1348 zone->SetIsRuleArea(
true );
1349 zone->SetDoNotAllowFootprints( !!flags.count( 2 ) );
1350 zone->SetDoNotAllowCopperPour( !!flags.count( 7 ) || !!flags.count( 6 )
1351 || !!flags.count( 8 ) );
1352 zone->SetDoNotAllowPads( !!flags.count( 7 ) );
1353 zone->SetDoNotAllowTracks( !!flags.count( 7 ) || !!flags.count( 5 ) );
1354 zone->SetDoNotAllowVias( !!flags.count( 7 ) );
1356 zone->SetLayer( klayer );
1357 zone->Outline()->Append( contour );
1359 aBoard->
Add( zone.release(), ADD_MODE::APPEND );
1362 else if( type == wxS(
"PAD" ) )
1364 wxString netname = line.at( 3 );
1366 std::unique_ptr<FOOTPRINT> footprint = std::make_unique<FOOTPRINT>( aBoard );
1367 std::unique_ptr<PAD>
pad =
createPAD( footprint.get(), line );
1377 footprint->Add(
pad.release(), ADD_MODE::APPEND );
1378 footprint->SetPosition( pos );
1379 footprint->SetOrientation( orient );
1381 wxString fpName = wxS(
"Pad_" ) + line.at( 1 ).get<wxString>();
1384 footprint->SetFPID( fpID );
1385 footprint->Reference().SetVisible(
true );
1386 footprint->Value().SetVisible(
true );
1387 footprint->AutoPositionFields();
1389 aBoard->
Add( footprint.release(), ADD_MODE::APPEND );
1391 else if( type == wxS(
"IMAGE" ) )
1393 wxString uuid = line.at( 1 );
1400 int layer = line.at( 3 ).get<
int>();
1403 VECTOR2D start( line.at( 4 ), line.at( 5 ) );
1404 VECTOR2D size( line.at( 6 ), line.at( 7 ) );
1406 double angle = line.at( 8 );
1407 int mirror = line.at( 9 );
1408 nlohmann::json polyDataList = line.at( 10 );
1411 std::vector<SHAPE_LINE_CHAIN> contours;
1412 for( nlohmann::json& polyData : polyDataList )
1417 contours.push_back( contour );
1429 for(
int i = 0; i < contour.PointCount(); i++ )
1440 std::unique_ptr<PCB_GROUP>
group;
1443 group = std::make_unique<PCB_GROUP>( aBoard );
1449 std::unique_ptr<PCB_SHAPE> shape =
1450 std::make_unique<PCB_SHAPE>( aBoard, SHAPE_T::POLY );
1452 shape->SetFilled(
true );
1453 shape->SetPolyShape( poly );
1454 shape->SetLayer( klayer );
1455 shape->SetWidth( 0 );
1464 group->AddItem( shape.get() );
1466 aBoard->
Add( shape.release(), ADD_MODE::APPEND );
1470 aBoard->
Add(
group.release(), ADD_MODE::APPEND );
1472 else if( type == wxS(
"OBJ" ) )
1475 wxString mimeType, base64Data;
1479 if( !line.at( 3 ).is_number() )
1482 int layer = line.at( 3 ).get<
int>();
1485 start =
VECTOR2D( line.at( 5 ), line.at( 6 ) );
1486 size =
VECTOR2D( line.at( 7 ), line.at( 8 ) );
1487 angle = line.at( 9 );
1488 flipped = line.at( 10 );
1490 wxString imageUrl = line.at( 11 );
1492 if( imageUrl.BeforeFirst(
':' ) == wxS(
"blob" ) )
1494 wxString objectId = imageUrl.AfterLast(
':' );
1496 if(
auto blob =
get_opt( aBlobMap, objectId ) )
1498 wxString blobUrl = blob->url;
1500 if( blobUrl.BeforeFirst(
':' ) == wxS(
"data" ) )
1502 wxArrayString paramsArr =
1503 wxSplit( blobUrl.AfterFirst(
':' ).BeforeFirst(
',' ),
';',
'\0' );
1505 base64Data = blobUrl.AfterFirst(
',' );
1507 if( paramsArr.size() > 0 )
1508 mimeType = paramsArr[0];
1516 if( mimeType.empty() || base64Data.empty() )
1519 wxMemoryBuffer buf = wxBase64Decode( base64Data );
1521 if( mimeType == wxS(
"image/svg+xml" ) )
1527 VECTOR2D kcenter = kstart + ksize / 2;
1529 std::unique_ptr<PCB_REFERENCE_IMAGE> bitmap =
1530 std::make_unique<PCB_REFERENCE_IMAGE>( aBoard, kcenter, klayer );
1532 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1533 & ~wxImage::Load_Verbose );
1535 if( bitmap->ReadImageFile( buf ) )
1537 double scaleFactor =
ScaleSize( size.
x ) / bitmap->GetSize().x;
1538 bitmap->SetImageScale( scaleFactor );
1545 int x = bitmap->GetPosition().x;
1549 bitmap->MutableImage()->Mirror(
false );
1552 aBoard->
Add( bitmap.release(), ADD_MODE::APPEND );
1556 else if( type == wxS(
"STRING" ) )
1558 wxString uuid = line.at( 1 );
1565 int layer = line.at( 3 ).get<
int>();
1568 VECTOR2D location( line.at( 4 ), line.at( 5 ) );
1569 wxString
string = line.at( 6 );
1570 wxString font = line.at( 7 );
1572 double height = line.at( 8 );
1573 double strokew = line.at( 9 );
1575 int align = line.at( 12 );
1576 double angle = line.at( 13 );
1577 int inverted = line.at( 14 );
1578 int mirror = line.at( 16 );
1582 text->SetText(
string );
1583 text->SetLayer( klayer );
1585 text->SetIsKnockout( inverted );
1589 if( font != wxS(
"default" ) )
1602 text->SetMirrored(
true );
1603 text->SetTextAngleDegrees( -angle );
1607 text->SetTextAngleDegrees( angle );
1610 aBoard->
Add(
text, ADD_MODE::APPEND );
1612 else if( type == wxS(
"COMPONENT" ) )
1614 wxString compId = line.at( 1 );
1615 componentLines[compId].push_back( line );
1617 else if( type == wxS(
"ATTR" ) )
1619 wxString compId = line.at( 3 );
1620 componentLines[compId].push_back( line );
1622 else if( type == wxS(
"PAD_NET" ) )
1624 wxString compId = line.at( 1 );
1625 componentLines[compId].push_back( line );
1629 for(
auto const& [compId, lines] : componentLines )
1632 wxString fpIdOverride;
1633 wxString fpDesignator;
1634 std::map<wxString, wxString> localCompAttribs;
1636 for(
auto& line : lines )
1638 if( line.size() == 0 )
1641 wxString type = line.at( 0 );
1643 if( type == wxS(
"COMPONENT" ) )
1645 localCompAttribs = line.at( 7 );
1647 else if( type == wxS(
"ATTR" ) )
1651 if( attr.
key == wxS(
"Device" ) )
1652 deviceId = attr.
value;
1654 else if( attr.
key == wxS(
"Footprint" ) )
1655 fpIdOverride = attr.
value;
1657 else if( attr.
key == wxS(
"Designator" ) )
1658 fpDesignator = attr.
value;
1662 if( deviceId.empty() )
1665 nlohmann::json compAttrs = aProject.at(
"devices" ).at( deviceId ).at(
"attributes" );
1669 if( !fpIdOverride.IsEmpty() )
1670 fpId = fpIdOverride;
1672 fpId = compAttrs.at(
"Footprint" ).get<wxString>();
1674 auto it = aFootprintMap.find( fpId );
1675 if( it == aFootprintMap.end() )
1677 wxLogError(
"Footprint of '%s' with uuid '%s' not found.", fpDesignator, fpId );
1681 std::unique_ptr<FOOTPRINT>& footprintOrig = it->second;
1682 std::unique_ptr<FOOTPRINT> footprint(
static_cast<FOOTPRINT*
>( footprintOrig->Clone() ) );
1684 wxString modelUuid, modelTitle, modelTransform;
1686 if(
auto val =
get_opt( localCompAttribs,
"3D Model" ) )
1689 modelUuid = compAttrs.value<wxString>(
"3D Model",
"" );
1691 if(
auto val =
get_opt( localCompAttribs,
"3D Model Title" ) )
1692 modelTitle = val->Trim();
1694 modelTitle = compAttrs.value<wxString>(
"3D Model Title", modelUuid ).Trim();
1696 if(
auto val =
get_opt( localCompAttribs,
"3D Model Transform" ) )
1697 modelTransform = *val;
1699 modelTransform = compAttrs.value<wxString>(
"3D Model Transform",
"" );
1703 footprint->SetParent( aBoard );
1705 for(
auto& line : lines )
1707 if( line.size() == 0 )
1710 wxString type = line.at( 0 );
1712 if( type == wxS(
"COMPONENT" ) )
1714 int layer = line.at( 3 );
1717 VECTOR2D center( line.at( 4 ), line.at( 5 ) );
1719 double orient = line.at( 6 );
1722 if( klayer ==
B_Cu )
1723 footprint->Flip( footprint->GetPosition(),
false );
1725 footprint->SetOrientationDegrees( orient );
1726 footprint->SetPosition(
ScalePos( center ) );
1728 else if( type == wxS(
"ATTR" ) )
1737 if( attr.
key == wxS(
"Designator" ) )
1739 if( attr.
key == wxS(
"Designator" ) )
1749 if( attr.
fontName != wxS(
"default" ) )
1766 text->SetLayer( klayer );
1768 text->SetTextAngleDegrees( footprint->IsFlipped() ? -attr.
rotation
1778 footprint->Add(
text, ADD_MODE::APPEND );
1781 else if( type == wxS(
"PAD_NET" ) )
1783 wxString padNumber = line.at( 2 );
1784 wxString padNet = line.at( 3 );
1786 PAD*
pad = footprint->FindPadByNumber( padNumber );
1798 aBoard->
Add( footprint.release(), ADD_MODE::APPEND );
1802 std::vector<PCB_SHAPE*> shapes;
1803 std::vector<std::unique_ptr<PCB_SHAPE>> newShapes;
1811 shapes.push_back(
static_cast<PCB_SHAPE*
>( item ) );
1816 for( std::unique_ptr<PCB_SHAPE>& ptr : newShapes )
1817 aBoard->
Add( ptr.release(), ADD_MODE::APPEND );
1829 offset.
x =
KiROUND( offset.
x / alignGrid ) * alignGrid;
1830 offset.
y =
KiROUND( offset.
y / alignGrid ) * alignGrid;
1832 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.
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.
BOX2I ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Calculate the bounding box containing all board items (or board edge segments).
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