29#include <wx/mstream.h>
75using namespace PCB_KEYS_T;
100 THROW_IO_ERROR( wxString::Format(
_(
"Cannot create footprint library '%s'." ),
106 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' is read only." ),
113 std::unique_ptr<FOOTPRINT>& footprint = fpCacheEntry->
GetFootprint();
115 if( aFootprintFilter && footprint.get() != aFootprintFilter )
120 if( footprint->GetAreFontsEmbedded() )
121 footprint->EmbedFonts();
123 footprint->GetEmbeddedFiles()->ClearEmbeddedFonts();
136 m_owner->SetOutputFormatter( &formatter );
137 m_owner->Format( footprint.get() );
147 if( !aFootprintFilter )
159 if( !dir.IsOpened() )
161 wxString msg = wxString::Format(
_(
"Footprint library '%s' not found." ),
173 if( dir.GetFirst( &fullName, fileSpec ) )
188 wxString fpName = fn.
GetName();
199 if( !cacheError.IsEmpty() )
200 cacheError += wxT(
"\n\n" );
202 cacheError += wxString::Format(
_(
"Warning in file '%s'" ) +
'\n',
204 cacheError += warning;
209 if( !cacheError.IsEmpty() )
210 cacheError += wxT(
"\n\n" );
212 cacheError += wxString::Format(
_(
"Unable to read file '%s'" ) +
'\n',
214 cacheError += ioe.
What();
216 }
while( dir.GetNext( &fullName ) );
220 if( !cacheError.IsEmpty() )
232 wxString msg = wxString::Format(
_(
"Library '%s' has no footprint '%s'." ),
239 wxString fullPath = it->second->GetFileName().GetFullPath();
241 wxRemoveFile( fullPath );
258 footprint.second->SetFilePath( aPath );
299 const std::map<std::string, UTF8>* aProperties )
306 _(
"Internal Group Data Error" ), wxICON_ERROR,
307 wxString::Format(
_(
"Please report this bug. Error validating group "
308 "structure: %s\n\nSave anyway?" ), sanityResult ),
309 _(
"Save Anyway" ) ) )
322 const std::map<std::string, UTF8>* aProperties )
330 if(
m_board->GetAreFontsEmbedded() )
333 m_board->GetEmbeddedFiles()->ClearEmbeddedFonts();
337 m_out->Print(
"(kicad_pcb (version %d) (generator \"pcbnew\") (generator_version %s)",
351 std::string input =
TO_UTF8( aClipboardSourceInput );
358 return parser.
Parse();
372 switch( aItem->
Type() )
407 format(
static_cast<const PAD*
>( aItem ) );
449 wxFAIL_MSG( wxT(
"Cannot format item " ) + aItem->
GetClass() );
481 m_out->Print(
"(layer %s %s)",
483 aIsKnockout ?
"knockout" :
"" );
490 m_out->Print(
"(pts" );
492 for(
int ii = 0; ii < outline.
PointCount(); ++ii )
498 m_out->Print(
"(xy %s)",
504 m_out->Print(
"(arc (start %s) (mid %s) (end %s))",
528 m_out->Print(
"(render_cache %s %s",
529 m_out->Quotew( resolvedText ).c_str(),
538 m_out->Print(
"(polygon" );
544 callback_gal.DrawGlyphs( *cache );
553 m_out->Print(
"(setup" );
563 m_out->Print(
"(pad_to_mask_clearance %s)",
568 m_out->Print(
"(solder_mask_min_width %s)",
574 m_out->Print(
"(pad_to_paste_clearance %s)",
580 m_out->Print(
"(pad_to_paste_clearance_ratio %s)",
587 m_out->Print( 0,
" (tenting " );
590 m_out->Print( 0,
")" );
592 m_out->Print( 0,
" (covering " );
595 m_out->Print( 0,
")" );
597 m_out->Print( 0,
" (plugging " );
600 m_out->Print( 0,
")" );
608 m_out->Print( 0,
" (zone_defaults" );
611 format( properties, 0, layer );
613 m_out->Print( 0,
")\n" );
620 m_out->Print(
"(aux_axis_origin %s %s)",
629 m_out->Print(
"(grid_origin %s %s)",
644 m_out->Print(
"(general" );
646 m_out->Print(
"(thickness %s)",
660 m_out->Print(
"(layers" );
666 m_out->Print(
"(%d %s %s %s)",
672 :
m_out->Quotew(
m_board->GetLayerName( layer ) ).c_str() );
681 bool print_type =
false;
695 m_out->Print(
"(%d %s %s %s)",
703 :
m_out->Quotew(
m_board->GetLayerName( layer ) ).c_str() );
712 for(
const std::pair<const wxString, wxString>& prop : aBoard->
GetProperties() )
714 m_out->Print(
"(property %s %s)",
715 m_out->Quotew( prop.first ).c_str(),
716 m_out->Quotew( prop.second ).c_str() );
725 if( variantNames.empty() )
728 m_out->Print(
"(variants" );
730 for(
const wxString& variantName : variantNames )
732 m_out->Print(
"(variant (name %s)",
m_out->Quotew( variantName ).c_str() );
736 if( !description.IsEmpty() )
737 m_out->Print(
"(description %s)",
m_out->Quotew( description ).c_str() );
782 m_out->Print(
"(teardrops (best_length_ratio %s) (max_length %s) (best_width_ratio %s) "
791 m_out->Print(
"(filter_ratio %s)",
803 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_footprints( aBoard->
Footprints().begin(),
805 std::set<BOARD_ITEM*, BOARD::cmp_drawings> sorted_drawings( aBoard->
Drawings().begin(),
807 std::set<PCB_TRACK*, PCB_TRACK::cmp_tracks> sorted_tracks( aBoard->
Tracks().begin(),
809 std::set<PCB_POINT*, PCB_POINT::cmp_points> sorted_points( aBoard->
Points().begin(),
811 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_zones( aBoard->
Zones().begin(),
812 aBoard->
Zones().end() );
813 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_groups( aBoard->
Groups().begin(),
815 std::set<BOARD_ITEM*, BOARD_ITEM::ptr_cmp> sorted_generators( aBoard->
Generators().begin(),
820 for(
BOARD_ITEM* footprint : sorted_footprints )
838 for(
auto zone : sorted_zones )
855 files_to_write.
AddFile( file.second );
862 files_to_write.
AddFile( file.second );
865 m_out->Print(
"(embedded_fonts %s)",
868 if( !files_to_write.
IsEmpty() )
884 m_out->Print(
"(dimension" );
888 m_out->Print(
"(type orthogonal)" );
890 m_out->Print(
"(type aligned)" );
892 m_out->Print(
"(type leader)" );
894 m_out->Print(
"(type center)" );
896 m_out->Print(
"(type radial)" );
898 wxFAIL_MSG( wxT(
"Cannot format unknown dimension type!" ) );
907 m_out->Print(
"(pts (xy %s %s) (xy %s %s))",
918 m_out->Print(
"(leader_length %s)",
923 m_out->Print(
"(orientation %d)",
static_cast<int>(
ortho->GetOrientation() ) );
927 m_out->Print(
"(format (prefix %s) (suffix %s) (units %d) (units_format %d) (precision %d)",
936 m_out->Print(
"(override_value %s)",
946 m_out->Print(
"(style (thickness %s) (arrow_length %s) (text_position_mode %d)",
951 if(
ortho || aligned )
956 m_out->Print(
"(arrow_direction outward)" );
959 m_out->Print(
"(arrow_direction inward)" );
967 m_out->Print(
"(extension_height %s)",
974 m_out->Print(
"(extension_offset %s)",
994 std::string prefix = parentFP ?
"fp" :
"gr";
999 m_out->Print(
"(%s_line (start %s) (end %s)",
1006 m_out->Print(
"(%s_rect (start %s) (end %s)",
1016 m_out->Print(
"(%s_circle (center %s) (end %s)",
1023 m_out->Print(
"(%s_arc (start %s) (mid %s) (end %s)",
1036 m_out->Print(
"(%s_poly", prefix.c_str() );
1047 m_out->Print(
"(%s_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
1070 m_out->Print(
"(fill hatch)" );
1074 m_out->Print(
"(fill reverse_hatch)" );
1078 m_out->Print(
"(fill cross_hatch)" );
1103 m_out->Print(
"(solder_mask_margin %s)",
1111 m_out->Print(
")" );
1117 wxCHECK_RET( aBitmap !=
nullptr &&
m_out !=
nullptr,
"" );
1123 wxCHECK_RET(
image !=
nullptr,
"wxImage* is NULL" );
1125 m_out->Print(
"(image (at %s %s)",
1137 wxMemoryOutputStream ostream;
1143 m_out->Print(
")" );
1149 m_out->Print(
"(point (at %s) (size %s)",
1157 m_out->Print(
")" );
1163 m_out->Print(
"(target %s (at %s) (size %s)",
1164 ( aTarget->
GetShape() ) ?
"x" :
"plus",
1173 m_out->Print(
")" );
1183 if( initial_comments )
1185 for(
unsigned i = 0; i < initial_comments->GetCount(); ++i )
1186 m_out->Print(
"%s\n",
TO_UTF8( (*initial_comments)[i] ) );
1192 m_out->Print(
"(footprint %s",
1197 m_out->Print(
"(footprint %s",
1203 m_out->Print(
"(version %d) (generator \"pcbnew\") (generator_version %s)",
1221 m_out->Print(
"(at %s %s)",
1239 m_out->Print(
"(property %s %s",
1240 m_out->Quotew( field->GetCanonicalName() ).c_str(),
1241 m_out->Quotew( field->GetText() ).c_str() );
1245 m_out->Print(
")" );
1250 if( !compClass->IsEmpty() )
1252 m_out->Print(
"(component_classes" );
1255 m_out->Print(
"(class %s)",
m_out->Quotew( constituent->GetName() ).c_str() );
1257 m_out->Print(
")" );
1263 m_out->Print(
"(property ki_fp_filters %s)",
1279 m_out->Print(
"(units" );
1283 m_out->Print(
"(unit (name %s)",
m_out->Quotew( u.m_unitName ).c_str() );
1284 m_out->Print(
"(pins" );
1286 for(
const wxString& n : u.m_pins )
1287 m_out->Print(
" %s",
m_out->Quotew( n ).c_str() );
1289 m_out->Print(
")" );
1290 m_out->Print(
")" );
1293 m_out->Print(
")" );
1298 m_out->Print(
"(solder_mask_margin %s)",
1304 m_out->Print(
"(solder_paste_margin %s)",
1310 m_out->Print(
"(solder_paste_margin_ratio %s)",
1316 m_out->Print(
"(clearance %s)",
1322 m_out->Print(
"(zone_connect %d)",
1331 m_out->Print(
"(attr" );
1334 m_out->Print(
" smd" );
1337 m_out->Print(
" through_hole" );
1340 m_out->Print(
" board_only" );
1343 m_out->Print(
" exclude_from_pos_files" );
1346 m_out->Print(
" exclude_from_bom" );
1349 m_out->Print(
" allow_missing_courtyard" );
1352 m_out->Print(
" dnp" );
1355 m_out->Print(
" allow_soldermask_bridges" );
1357 m_out->Print(
")" );
1363 m_out->Print(
"(stackup" );
1368 wxString canonicalName(
LSET::Name( layer ) );
1369 m_out->Print(
"(layer %s)",
m_out->Quotew( canonicalName ).c_str() );
1372 m_out->Print(
")" );
1377 m_out->Print(
"(private_layers" );
1381 wxString canonicalName(
LSET::Name( layer ) );
1382 m_out->Print(
" %s",
m_out->Quotew( canonicalName ).c_str() );
1385 m_out->Print(
")" );
1390 m_out->Print(
"(net_tie_pad_groups" );
1395 m_out->Print(
")" );
1401 const std::vector<std::set<wxString>>& jumperGroups = aFootprint->
JumperPadGroups();
1403 if( !jumperGroups.empty() )
1405 m_out->Print(
"(jumper_pad_groups" );
1407 for(
const std::set<wxString>&
group : jumperGroups )
1409 m_out->Print(
"(" );
1411 for(
const wxString& padName :
group )
1412 m_out->Print(
"%s ",
m_out->Quotew( padName ).c_str() );
1414 m_out->Print(
")" );
1417 m_out->Print(
")" );
1423 std::set<PAD*, FOOTPRINT::cmp_pads> sorted_pads( aFootprint->
Pads().begin(),
1424 aFootprint->
Pads().end() );
1425 std::set<BOARD_ITEM*, FOOTPRINT::cmp_drawings> sorted_drawings(
1428 std::set<PCB_POINT*, PCB_POINT::cmp_points> sorted_points(
1429 aFootprint->
Points().begin(),
1430 aFootprint->
Points().end() );
1431 std::set<ZONE*, FOOTPRINT::cmp_zones> sorted_zones( aFootprint->
Zones().begin(),
1432 aFootprint->
Zones().end() );
1433 std::set<BOARD_ITEM*, PCB_GROUP::ptr_cmp> sorted_groups( aFootprint->
Groups().begin(),
1434 aFootprint->
Groups().end() );
1445 for(
PAD*
pad : sorted_pads )
1457 const bool baseDnp = aFootprint->
IsDNP();
1461 for(
const auto& [variantName, variant] : aFootprint->
GetVariants() )
1463 m_out->Print(
"(variant (name %s)",
m_out->Quotew( variantName ).c_str() );
1465 if( variant.GetDNP() != baseDnp )
1468 if( variant.GetExcludedFromBOM() != baseExcludedFromBOM )
1471 if( variant.GetExcludedFromPosFiles() != baseExcludedFromPosFiles )
1474 variant.GetExcludedFromPosFiles() );
1477 for(
const auto& [fieldName, fieldValue] : variant.GetFields() )
1480 const wxString baseValue = baseField ? baseField->
GetText() : wxString();
1482 if( fieldValue == baseValue )
1485 m_out->Print(
"(field (name %s) (value %s))",
1486 m_out->Quotew( fieldName ).c_str(),
1487 m_out->Quotew( fieldValue ).c_str() );
1490 m_out->Print(
")" );
1500 auto bs3D = aFootprint->
Models().begin();
1501 auto es3D = aFootprint->
Models().end();
1503 while( bs3D != es3D )
1505 if( !bs3D->m_Filename.IsEmpty() )
1507 m_out->Print(
"(model %s",
m_out->Quotew( bs3D->m_Filename ).c_str() );
1512 if( bs3D->m_Opacity != 1.0 )
1513 m_out->Print(
"%s", fmt::format(
"(opacity {:.4f})", bs3D->m_Opacity).c_str() );
1515 m_out->Print(
"(offset (xyz %s %s %s))",
1520 m_out->Print(
"(scale (xyz %s %s %s))",
1525 m_out->Print(
"(rotate (xyz %s %s %s))",
1530 m_out->Print(
")" );
1536 m_out->Print(
")" );
1555 if( !aEnumerateLayers )
1558 if( ( aLayerMask & cu_board_mask ) == cu_board_mask )
1565 aLayerMask &= ~cu_all;
1567 else if( ( aLayerMask & cu_board_mask ) == fr_bk )
1574 aLayerMask &= ~fr_bk;
1577 if( ( aLayerMask & adhes ) == adhes )
1580 aLayerMask &= ~adhes;
1589 if( ( aLayerMask & silks ) == silks )
1592 aLayerMask &= ~silks;
1595 if( ( aLayerMask & mask ) == mask )
1598 aLayerMask &= ~mask;
1601 if( ( aLayerMask & crt_yd ) == crt_yd )
1604 aLayerMask &= ~crt_yd;
1607 if( ( aLayerMask & fab ) == fab )
1617 if( aLayerMask[layer] )
1658 THROW_IO_ERROR( wxString::Format( wxT(
"unknown pad attribute: %d" ),
1662 const char*
property =
nullptr;
1677 THROW_IO_ERROR( wxString::Format( wxT(
"unknown pad property: %d" ),
1681 m_out->Print(
"(pad %s %s %s",
1686 m_out->Print(
"(at %s %s)",
1697 m_out->Print(
"(rect_delta %s)",
1703 bool forceShapeOffsetOutput =
false;
1708 if( aPad->
GetOffset( layer ) != shapeoffset )
1709 forceShapeOffsetOutput =
true;
1712 if( drill.
x > 0 || drill.
y > 0 || shapeoffset.
x != 0 || shapeoffset.
y != 0 || forceShapeOffsetOutput )
1714 m_out->Print(
"(drill" );
1717 m_out->Print(
" oval" );
1722 if( drill.
y > 0 && drill.
x != drill.
y )
1729 if( shapeoffset.
x != 0 || shapeoffset.
y != 0 || forceShapeOffsetOutput )
1732 m_out->Print(
")" );
1737 m_out->Print(
"(backdrill (size %s) (layers %s %s))",
1745 m_out->Print(
"(tertiary_drill (size %s) (layers %s %s))",
1751 auto formatPostMachining =
1757 m_out->Print(
"(%s %s",
1762 if( aProps.size > 0 )
1765 if( aProps.depth > 0 )
1768 if( aProps.angle > 0 )
1771 m_out->Print(
")" );
1779 m_out->Print(
"(property %s)", property );
1793 m_out->Print(
"(zone_layer_connections" );
1801 m_out->Print(
")" );
1806 auto formatCornerProperties =
1813 m_out->Print(
"(roundrect_rratio %s)",
1820 m_out->Print(
"(chamfer_ratio %s)",
1823 m_out->Print(
"(chamfer" );
1826 m_out->Print(
" top_left" );
1829 m_out->Print(
" top_right" );
1832 m_out->Print(
" bottom_left" );
1835 m_out->Print(
" bottom_right" );
1837 m_out->Print(
")" );
1863 m_out->Print(
"(die_length %s)",
1869 m_out->Print(
"(die_delay %s)",
1875 m_out->Print(
"(solder_mask_margin %s)",
1881 m_out->Print(
"(solder_paste_margin %s)",
1887 m_out->Print(
"(solder_paste_margin_ratio %s)",
1893 m_out->Print(
"(clearance %s)",
1899 m_out->Print(
"(zone_connect %d)",
1905 m_out->Print(
"(thermal_bridge_width %s)",
1915 defaultThermalSpokeAngle =
ANGLE_45;
1920 m_out->Print(
"(thermal_bridge_angle %s)",
1926 m_out->Print(
"(thermal_gap %s)",
1941 auto formatPrimitives =
1944 m_out->Print(
"(primitives" );
1947 for(
const std::shared_ptr<PCB_SHAPE>& primitive : aPad->
GetPrimitives( aLayer ) )
1949 switch( primitive->GetShape() )
1952 if( primitive->IsProxyItem() )
1954 m_out->Print(
"(gr_vector (start %s) (end %s)",
1960 m_out->Print(
"(gr_line (start %s) (end %s)",
1967 if( primitive->IsProxyItem() )
1969 m_out->Print(
"(gr_bbox (start %s) (end %s)",
1975 m_out->Print(
"(gr_rect (start %s) (end %s)",
1979 if( primitive->GetCornerRadius() > 0 )
1981 m_out->Print(
" (radius %s)",
1988 m_out->Print(
"(gr_arc (start %s) (mid %s) (end %s)",
1995 m_out->Print(
"(gr_circle (center %s) (end %s)",
2001 m_out->Print(
"(gr_curve (pts (xy %s) (xy %s) (xy %s) (xy %s))",
2009 if( primitive->IsPolyShapeValid() )
2014 m_out->Print(
"(gr_poly" );
2023 if( !primitive->IsProxyItem() )
2035 m_out->Print(
")" );
2038 m_out->Print(
")" );
2043 m_out->Print(
"(options" );
2046 m_out->Print(
"(clearance convexhull)" );
2048 m_out->Print(
"(clearance outline)" );
2065 m_out->Print( 0,
" (tenting " );
2070 m_out->Print( 0,
")" );
2076 auto formatPadLayer =
2081 m_out->Print(
"(shape %s)", shapeName( aLayer ) );
2089 shapeoffset = aPad->
GetOffset( aLayer );
2091 if( shapeoffset.
x != 0 || shapeoffset.
y != 0 )
2094 formatCornerProperties( aLayer );
2098 m_out->Print(
"(options" );
2101 m_out->Print(
"(anchor %s)", anchorShape( aLayer ) );
2103 m_out->Print(
")" );
2106 formatPrimitives( aLayer );
2120 if( layerSpokeAngle != defaultLayerAngle )
2122 m_out->Print(
"(thermal_bridge_angle %s)",
2126 if( padstack.
ThermalGap( aLayer ).has_value() )
2128 m_out->Print(
"(thermal_gap %s)",
2134 m_out->Print(
"(thermal_bridge_width %s)",
2138 if( padstack.
Clearance( aLayer ).has_value() )
2140 m_out->Print(
"(clearance %s)",
2146 m_out->Print(
"(zone_connect %d)",
2156 m_out->Print(
"(padstack (mode front_inner_back)" );
2158 m_out->Print(
"(layer \"Inner\"" );
2160 m_out->Print(
")" );
2161 m_out->Print(
"(layer \"B.Cu\"" );
2162 formatPadLayer(
B_Cu );
2163 m_out->Print(
")" );
2167 m_out->Print(
"(padstack (mode custom)" );
2177 formatPadLayer( layer );
2178 m_out->Print(
")" );
2182 m_out->Print(
")" );
2185 m_out->Print(
")" );
2191 wxCHECK_RET( aBarcode !=
nullptr &&
m_out !=
nullptr,
"" );
2193 m_out->Print(
"(barcode" );
2198 m_out->Print(
"(at %s %s)",
2204 m_out->Print(
"(size %s %s)",
2212 const char* typeStr =
"code39";
2223 m_out->Print(
"(type %s)", typeStr );
2228 const char* eccStr =
"L";
2237 m_out->Print(
"(ecc_level %s)", eccStr );
2251 m_out->Print(
")" );
2282 m_out->Print(
"(%s_text %s %s",
2291 m_out->Print(
"(at %s %s)",
2309 aText->EDA_TEXT::Format(
m_out, ctl_flags );
2315 m_out->Print(
")" );
2323 m_out->Print(
"(%s %s",
2325 : parentFP ?
"fp_text_box"
2334 m_out->Print(
"(start %s) (end %s)",
2350 m_out->Print(
"(margins %s %s %s %s)",
2357 m_out->Print(
"(span %d %d)", cell->GetColSpan(), cell->GetRowSpan() );
2374 aTextBox->EDA_TEXT::Format(
m_out, 0 );
2387 m_out->Print(
")" );
2393 wxCHECK_RET( aTable !=
nullptr &&
m_out !=
nullptr,
"" );
2404 m_out->Print(
"(border" );
2411 m_out->Print(
")" );
2413 m_out->Print(
"(separators" );
2420 m_out->Print(
")" );
2422 m_out->Print(
"(column_widths" );
2424 for(
int col = 0; col < aTable->
GetColCount(); ++col )
2427 m_out->Print(
")" );
2429 m_out->Print(
"(row_heights" );
2431 for(
int row = 0; row < aTable->
GetRowCount(); ++row )
2434 m_out->Print(
")" );
2436 m_out->Print(
"(cells" );
2441 m_out->Print(
")" );
2442 m_out->Print(
")" );
2448 wxArrayString memberIds;
2452 const auto& cache =
m_board->GetItemByIdCache();
2454 std::unordered_set<const EDA_ITEM*> validPtrs;
2456 for(
const auto& [uuid, item] : cache )
2457 validPtrs.insert( item );
2461 if( validPtrs.count( member ) )
2462 memberIds.Add( member->m_Uuid.AsString() );
2468 memberIds.Add( member->m_Uuid.AsString() );
2471 if( memberIds.empty() )
2486 m_out->Print(
"(members" );
2488 for(
const wxString& memberId : memberIds )
2489 m_out->Print(
" %s",
m_out->Quotew( memberId ).c_str() );
2491 m_out->Print(
")" );
2492 m_out->Print(
")" );
2500 && aGenerator->
GetItems().empty() )
2505 m_out->Print(
"(generated" );
2509 m_out->Print(
"(type %s) (name %s) (layer %s)",
2517 for(
const auto& [key, value] : aGenerator->
GetProperties() )
2519 if( value.CheckType<
double>() || value.CheckType<
int>() || value.CheckType<
long>()
2520 || value.CheckType<
long long>() )
2524 if( !value.GetAs( &val ) )
2527 std::string buf = fmt::format(
"{:.10g}", val );
2530 m_out->Print(
"(%s %s)", key.c_str(), buf.c_str() );
2532 else if( value.CheckType<
bool>() )
2535 value.GetAs( &val );
2539 else if( value.CheckType<
VECTOR2I>() )
2542 value.GetAs( &val );
2544 m_out->Print(
"(%s (xy %s))",
2551 value.GetAs( &val );
2553 m_out->Print(
"(%s ", key.c_str() );
2555 m_out->Print(
")" );
2561 if( value.CheckType<wxString>() )
2563 value.GetAs( &val );
2565 else if( value.CheckType<std::string>() )
2568 value.GetAs( &str );
2570 val = wxString::FromUTF8( str );
2573 m_out->Print(
"(%s %s)", key.c_str(),
m_out->Quotew( val ).c_str() );
2577 wxArrayString memberIds;
2580 memberIds.Add( member->m_Uuid.AsString() );
2584 m_out->Print(
"(members" );
2586 for(
const wxString& memberId : memberIds )
2587 m_out->Print(
" %s",
m_out->Quotew( memberId ).c_str() );
2589 m_out->Print(
")" );
2590 m_out->Print(
")" );
2601 const BOARD* board =
via->GetBoard();
2603 wxCHECK_RET( board !=
nullptr, wxT(
"Via has no parent." ) );
2605 m_out->Print(
"(via" );
2607 via->LayerPair( &layer1, &layer2 );
2609 switch(
via->GetViaType() )
2615 m_out->Print(
" blind " );
2619 m_out->Print(
" buried " );
2623 m_out->Print(
" micro " );
2630 m_out->Print(
"(at %s) (size %s)",
2644 if(
via->Padstack().SecondaryDrill().size.x > 0 )
2646 m_out->Print(
"(backdrill (size %s) (layers %s %s))",
2652 if(
via->Padstack().TertiaryDrill().size.x > 0 )
2654 m_out->Print(
"(tertiary_drill (size %s) (layers %s %s))",
2665 m_out->Print(
"(%s %s", aName,
2668 if( aProps.size > 0 )
2671 if( aProps.depth > 0 )
2674 if( aProps.angle > 0 )
2677 m_out->Print(
")" );
2680 formatPostMachining(
"front_post_machining",
via->Padstack().FrontPostMachining() );
2681 formatPostMachining(
"back_post_machining",
via->Padstack().BackPostMachining() );
2683 m_out->Print(
"(layers %s %s)",
2687 switch(
via->Padstack().UnconnectedLayerMode() )
2707 if(
via->IsLocked() )
2710 if(
via->GetIsFree() )
2713 if(
via->GetRemoveUnconnected() )
2715 m_out->Print(
"(zone_layer_connections" );
2723 m_out->Print(
")" );
2731 m_out->Print( 0,
" (tenting " );
2736 m_out->Print( 0,
")" );
2745 m_out->Print( 0,
" (covering " );
2750 m_out->Print( 0,
")" );
2756 m_out->Print( 0,
" (plugging " );
2761 m_out->Print( 0,
")" );
2769 m_out->Print(
"(padstack" );
2773 m_out->Print(
"(mode front_inner_back)" );
2775 m_out->Print(
"(layer \"Inner\"" );
2776 m_out->Print(
"(size %s)",
2778 m_out->Print(
")" );
2779 m_out->Print(
"(layer \"B.Cu\"" );
2780 m_out->Print(
"(size %s)",
2782 m_out->Print(
")" );
2786 m_out->Print(
"(mode custom)" );
2794 m_out->Print(
"(size %s)",
2796 m_out->Print(
")" );
2800 m_out->Print(
")" );
2812 m_out->Print(
"(arc (start %s) (mid %s) (end %s) (width %s)",
2820 m_out->Print(
"(segment (start %s) (end %s) (width %s)",
2838 m_out->Print(
"(solder_mask_margin %s)",
2846 m_out->Print(
")" );
2852 m_out->Print(
"(zone" );
2867 if( layers.count() > 1 )
2889 m_out->Print(
"(hatch %s %s)", hatch.c_str(),
2900 m_out->Print(
"(attr (teardrop (type %s)))",
2905 m_out->Print(
"(connect_pads" );
2914 m_out->Print(
" thru_hole_only" );
2918 m_out->Print(
" yes" );
2922 m_out->Print(
" no" );
2926 m_out->Print(
"(clearance %s)",
2929 m_out->Print(
")" );
2931 m_out->Print(
"(min_thickness %s)",
2937 m_out->Print(
"(keepout (tracks %s) (vias %s) (pads %s) (copperpour %s) (footprints %s))",
2945 m_out->Print(
"(placement" );
2964 m_out->Print(
")" );
2967 m_out->Print(
"(fill" );
2971 m_out->Print(
" yes" );
2975 m_out->Print(
"(mode hatch)" );
2979 m_out->Print(
"(thermal_gap %s) (thermal_bridge_width %s)",
2989 m_out->Print(
"(smoothing chamfer)" );
2993 m_out->Print(
"(smoothing fillet)" );
2997 THROW_IO_ERROR( wxString::Format(
_(
"unknown zone corner smoothing type %d" ),
3005 m_out->Print(
"(island_removal_mode %d)",
3010 m_out->Print(
"(island_area_min %s)",
3016 m_out->Print(
"(hatch_thickness %s) (hatch_gap %s) (hatch_orientation %s)",
3023 m_out->Print(
"(hatch_smoothing_level %d) (hatch_smoothing_value %s)",
3028 m_out->Print(
"(hatch_border_algorithm %s) (hatch_min_hole_area %s)",
3033 m_out->Print(
")" );
3037 format( properties, 0, layer );
3046 m_out->Print(
"(polygon" );
3048 m_out->Print(
")" );
3057 for(
int ii = 0; ii < fv->OutlineCount(); ++ii )
3059 m_out->Print(
"(filled_polygon" );
3068 m_out->Print(
")" );
3072 m_out->Print(
")" );
3083 m_out->Print( aNestLevel,
"(property\n" );
3088 m_out->Print( aNestLevel,
"(hatch_position (xy %s))",
3092 m_out->Print( aNestLevel,
")\n" );
3098 m_ctl( aControlFlags )
3112 const std::map<std::string, UTF8>* aProperties,
3117 unsigned lineCount = 0;
3146 const std::map<std::string, UTF8>* aProperties,
3149 init( aProperties );
3152 aProgressReporter, aLineCount );
3157 board =
dynamic_cast<BOARD*
>( parser.
Parse() );
3176 parser.CurLine(), parser.CurLineNumber(), parser.CurOffset() );
3211 const wxString& aLibPath,
bool aBestEfforts,
3212 const std::map<std::string, UTF8>* aProperties )
3214 wxDir dir( aLibPath );
3217 init( aProperties );
3225 errorMsg = ioe.
What();
3231 for(
const auto& footprint :
m_cache->GetFootprints() )
3232 aFootprintNames.Add( footprint.first );
3234 if( !errorMsg.IsEmpty() && !aBestEfforts )
3240 const wxString& aFootprintName,
3241 const std::map<std::string, UTF8>* aProperties,
3242 bool checkModified )
3244 init( aProperties );
3255 auto it =
m_cache->GetFootprints().find( aFootprintName );
3257 if( it ==
m_cache->GetFootprints().end() )
3260 return it->second->GetFootprint().get();
3265 const wxString& aFootprintName,
3266 const std::map<std::string, UTF8>* aProperties )
3268 return getFootprint( aLibraryPath, aFootprintName, aProperties,
false );
3273 const wxString& aFootprintName,
3274 const std::map<std::string, UTF8>* aProperties )
3285 return footprintFile.Exists();
3290 wxString& aFootprintNameOut,
3291 const std::map<std::string, UTF8>* aProperties )
3294 wxFFile f( aFootprintPath );
3302 f.ReadAll( &fcontents );
3304 aFootprintNameOut = wxFileName( aFootprintPath ).GetName();
3311 const wxString& aFootprintName,
3313 const std::map<std::string, UTF8>* aProperties )
3329 copy->SetParent(
nullptr );
3338 const std::map<std::string, UTF8>* aProperties )
3340 init( aProperties );
3348 wxString libPath = aLibraryPath;
3349 wxString singleFileBaseName;
3350 bool saveSingleFile =
false;
3353 wxFileName asFile( aLibraryPath );
3357 saveSingleFile =
true;
3358 libPath = asFile.GetPath();
3359 singleFileBaseName = asFile.GetName();
3363 validateCache( libPath, !aProperties || !aProperties->contains(
"skip_cache_validation" ) );
3369 const wxString msg = wxString::Format(
_(
"Library '%s' does not exist.\n"
3370 "Would you like to create it?"),
3373 if( !
Pgm().IsGUI() || wxMessageBox( msg,
_(
"Library Not Found" ), wxYES_NO | wxICON_QUESTION ) != wxYES )
3381 wxString msg = wxString::Format(
_(
"Library '%s' is read only." ), libPath );
3387 wxString footprintName = saveSingleFile ? singleFileBaseName
3390 wxString fpName = saveSingleFile ? singleFileBaseName
3402 THROW_IO_ERROR( wxString::Format(
_(
"Footprint file name '%s' is not valid." ), fn.GetFullPath() ) );
3405 if( fn.FileExists() && !fn.IsFileWritable() )
3407 THROW_IO_ERROR( wxString::Format(
_(
"Insufficient permissions to delete '%s'." ),
3408 fn.GetFullPath() ) );
3411 wxString fullPath = fn.GetFullPath();
3412 wxString fullName = fn.GetFullName();
3413 auto it =
m_cache->GetFootprints().find( footprintName );
3415 if( it !=
m_cache->GetFootprints().end() )
3418 m_cache->GetFootprints().erase( footprintName );
3419 wxRemoveFile( fullPath );
3442 wxLogTrace(
traceKicadPcbPlugin, wxT(
"Creating s-expr footprint file '%s'." ), fullPath );
3443 m_cache->GetFootprints().insert( footprintName,
3451 const wxString& aFootprintName,
3452 const std::map<std::string, UTF8>* aProperties )
3454 init( aProperties );
3461 aLibraryPath.GetData() ) );
3464 m_cache->Remove( aFootprintName );
3485 const std::map<std::string, UTF8>* aProperties )
3487 if( wxDir::Exists( aLibraryPath ) )
3489 THROW_IO_ERROR( wxString::Format(
_(
"Cannot overwrite library path '%s'." ),
3490 aLibraryPath.GetData() ) );
3493 init( aProperties );
3502 const std::map<std::string, UTF8>* aProperties )
3505 fn.SetPath( aLibraryPath );
3508 if( !fn.DirExists() )
3511 if( !fn.IsDirWritable() )
3513 THROW_IO_ERROR( wxString::Format(
_(
"Insufficient permissions to delete folder '%s'." ),
3514 aLibraryPath.GetData() ) );
3517 wxDir dir( aLibraryPath );
3519 if( dir.HasSubDirs() )
3521 THROW_IO_ERROR( wxString::Format(
_(
"Library folder '%s' has unexpected sub-folders." ),
3522 aLibraryPath.GetData() ) );
3526 if( dir.HasFiles() )
3530 wxArrayString files;
3532 wxDir::GetAllFiles( aLibraryPath, &files );
3534 for( i = 0; i < files.GetCount(); i++ )
3540 THROW_IO_ERROR( wxString::Format(
_(
"Unexpected file '%s' found in library "
3543 aLibraryPath.GetData() ) );
3547 for( i = 0; i < files.GetCount(); i++ )
3548 wxRemoveFile( files[i] );
3552 aLibraryPath.GetData() );
3556 if( !wxRmdir( aLibraryPath ) )
3558 THROW_IO_ERROR( wxString::Format(
_(
"Footprint library '%s' cannot be deleted." ),
3559 aLibraryPath.GetData() ) );
3566 wxMilliSleep( 250L );
constexpr EDA_IU_SCALE pcbIUScale
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
bool SaveImageData(wxOutputStream &aOutStream) const
Write the bitmap data to aOutStream.
wxString GetNetname() const
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
TEARDROP_PARAMETERS & GetTeardropParams()
Container for design settings for a BOARD object.
std::map< PCB_LAYER_ID, ZONE_LAYER_PROPERTIES > m_ZoneLayerProperties
const VECTOR2I & GetGridOrigin() const
int GetBoardThickness() const
The full thickness of the board including copper and masks.
bool m_AllowSoldermaskBridgesInFPs
const VECTOR2I & GetAuxOrigin() const
int m_SolderMaskExpansion
BOARD_STACKUP & GetStackupDescriptor()
double m_SolderPasteMarginRatio
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual bool IsKnockout() const
bool IsLocked() const override
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
FOOTPRINT * GetParentFootprint() const
VECTOR2I GetFPRelativePosition() const
Manage layers needed to make a physical board.
void FormatBoardStackup(OUTPUTFORMATTER *aFormatter, const BOARD *aBoard) const
Write the stackup info on board file.
Information pertinent to a Pcbnew printed circuit board.
EMBEDDED_FILES * GetEmbeddedFiles() override
const std::vector< wxString > & GetVariantNames() const
const GENERATORS & Generators() const
void SetFileName(const wxString &aFileName)
const PCB_POINTS & Points() const
const PAGE_INFO & GetPageSettings() const
const ZONES & Zones() const
const GROUPS & Groups() const
The groups must maintain the following invariants.
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Return the type of the copper layer given by aLayer.
TITLE_BLOCK & GetTitleBlock()
int GetCopperLayerCount() const
const std::map< wxString, wxString > & GetProperties() const
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
wxString GetVariantDescription(const wxString &aVariantName) const
const PCB_PLOT_PARAMS & GetPlotOptions() const
bool LegacyTeardrops() const
wxString GroupsSanityCheck(bool repair=false)
Consistency check of internal m_groups structure.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
const DRAWINGS & Drawings() const
A lightweight representation of a component class.
const std::vector< COMPONENT_CLASS * > & GetConstituentClasses() const
Fetches a vector of the constituent classes for this (effective) class.
const LIB_ID & GetDesignBlockLibId() const
std::unordered_set< EDA_ITEM * > & GetItems()
bool HasDesignBlockLink() const
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
virtual void SetParentGroup(EDA_GROUP *aGroup)
virtual void SetParent(EDA_ITEM *aParent)
const VECTOR2I & GetBezierC2() const
FILL_T GetFillMode() const
SHAPE_POLY_SET & GetPolyShape()
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
wxString SHAPE_T_asString() const
const VECTOR2I & GetBezierC1() const
int GetCornerRadius() const
bool IsPolyShapeValid() const
VECTOR2I GetArcMid() const
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
const VECTOR2I & GetTextPos() const
const EDA_ANGLE & GetTextAngle() const
virtual const wxString & GetText() const
Return the string associated with the text object.
bool IsKeepUpright() const
virtual bool IsVisible() const
KIFONT::FONT * GetFont() const
std::vector< std::unique_ptr< KIFONT::GLYPH > > * GetRenderCache(const KIFONT::FONT *aFont, const wxString &forResolvedText, const VECTOR2I &aOffset={ 0, 0 }) const
virtual EDA_ANGLE GetDrawRotation() const
virtual wxString GetShownText(bool aAllowExtraText, int aDepth=0) const
Return the string actually shown after processing of the base text.
int GetTextThickness() const
void WriteEmbeddedFiles(OUTPUTFORMATTER &aOut, bool aWriteData) const
Output formatter for the embedded files.
void ClearEmbeddedFiles(bool aDeleteFiles=true)
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
const std::map< wxString, EMBEDDED_FILE * > & EmbeddedFileMap() const
bool GetAreFontsEmbedded() const
A LINE_READER that reads from an open file.
void Rewind()
Rewind the file and resets the line number back to zero.
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
RAII class to set and restore the fontconfig reporter.
Helper class for creating a footprint library cache.
std::unique_ptr< FOOTPRINT > m_footprint
FP_CACHE_ENTRY(FOOTPRINT *aFootprint, const WX_FILENAME &aFileName)
const WX_FILENAME & GetFileName() const
std::unique_ptr< FOOTPRINT > & GetFootprint()
static long long GetTimestamp(const wxString &aLibPath)
Generate a timestamp representing all source files in the cache (including the parent directory).
boost::ptr_map< wxString, FP_CACHE_ENTRY > m_footprints
PCB_IO_KICAD_SEXPR * m_owner
bool IsModified()
Return true if the cache is not up-to-date.
long long m_cache_timestamp
void SetPath(const wxString &aPath)
bool IsPath(const wxString &aPath) const
Check if aPath is the same as the current cache path.
void Save(FOOTPRINT *aFootprintFilter=nullptr)
Save the footprint cache or a single footprint from it to disk.
FP_CACHE(PCB_IO_KICAD_SEXPR *aOwner, const wxString &aLibraryPath)
boost::ptr_map< wxString, FP_CACHE_ENTRY > & GetFootprints()
void Remove(const wxString &aFootprintName)
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
APP_SETTINGS_BASE * KifaceSettings() const
virtual bool IsOutline() const
virtual void SetLineWidth(float aLineWidth)
Set the line width.
virtual wxString GetClass() const =0
Return the class name.
wxString AsString() const
A logical library item identifier and consists of various portions much like a URI.
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
const UTF8 & GetLibItemName() const
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
static LOAD_INFO_REPORTER & GetInstance()
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
LSEQ TechAndUserUIOrder() const
Return the technical and user layers in the order shown in layer widget.
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
std::optional< int > & Clearance(PCB_LAYER_ID aLayer=F_Cu)
MASK_LAYER_PROPS & FrontOuterLayers()
void ForEachUniqueLayer(const std::function< void(PCB_LAYER_ID)> &aMethod) const
Runs the given callable for each active unique copper layer in this padstack, meaning F_Cu for MODE::...
std::optional< int > & ThermalSpokeWidth(PCB_LAYER_ID aLayer=F_Cu)
EDA_ANGLE ThermalSpokeAngle(PCB_LAYER_ID aLayer=F_Cu) const
POST_MACHINING_PROPS & FrontPostMachining()
std::optional< int > & ThermalGap(PCB_LAYER_ID aLayer=F_Cu)
DRILL_PROPS & TertiaryDrill()
const VECTOR2I & Size(PCB_LAYER_ID aLayer) const
@ NORMAL
Shape is the same on all layers.
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
DRILL_PROPS & SecondaryDrill()
POST_MACHINING_PROPS & BackPostMachining()
MASK_LAYER_PROPS & BackOuterLayers()
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
static constexpr PCB_LAYER_ID INNER_LAYERS
! The layer identifier to use for "inner layers" on top/inner/bottom padstacks
std::optional< ZONE_CONNECTION > & ZoneConnection(PCB_LAYER_ID aLayer=F_Cu)
PAD_PROP GetProperty() const
bool GetRemoveUnconnected() const
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
const ZONE_LAYER_OVERRIDE & GetZoneLayerOverride(PCB_LAYER_ID aLayer) const
std::optional< double > GetLocalSolderPasteMarginRatio() const
const wxString & GetPinType() const
const VECTOR2I & GetDrillSize() const
PAD_ATTRIB GetAttribute() const
const wxString & GetPinFunction() const
const wxString & GetNumber() const
const VECTOR2I & GetDelta(PCB_LAYER_ID aLayer) const
EDA_ANGLE GetThermalSpokeAngle() const
double GetRoundRectRadiusRatio(PCB_LAYER_ID aLayer) const
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
bool GetKeepTopBottom() const
int GetPadToDieDelay() const
std::optional< int > GetLocalClearance() const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
const PADSTACK & Padstack() const
const VECTOR2I & GetOffset(PCB_LAYER_ID aLayer) const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
PAD_DRILL_SHAPE GetDrillShape() const
int GetChamferPositions(PCB_LAYER_ID aLayer) const
std::optional< int > GetLocalSolderPasteMargin() const
std::optional< int > GetLocalSolderMaskMargin() const
double GetChamferRectRatio(PCB_LAYER_ID aLayer) const
std::optional< int > GetLocalThermalSpokeWidthOverride() const
ZONE_CONNECTION GetLocalZoneConnection() const
CUSTOM_SHAPE_ZONE_MODE GetCustomShapeInZoneOpt() const
int GetLocalThermalGapOverride(wxString *aSource) const
PAD_SHAPE GetAnchorPadShape(PCB_LAYER_ID aLayer) const
int GetPadToDieLength() const
const VECTOR2I & GetSize(PCB_LAYER_ID aLayer) const
void Format(OUTPUTFORMATTER *aFormatter) const
Output the page class to aFormatter in s-expression form.
FLIP_DIRECTION m_FlipDirection
const VECTOR2I & GetMid() const
const VECTOR2I & GetMargin() const
Get the barcode margin (in internal units).
VECTOR2I GetPosition() const override
Get the position (center) of the barcode in internal units.
bool IsKnockout() const override
int GetHeight() const
Get the barcode height (in internal units).
BARCODE_ECC_T GetErrorCorrection() const
EDA_ANGLE GetAngle() const
BARCODE_T GetKind() const
Returns the type of the barcode (QR, CODE_39, etc.).
int GetWidth() const
Get the barcode width (in internal units).
wxString GetOverrideText() const
wxString GetSuffix() const
int GetLineThickness() const
DIM_TEXT_POSITION GetTextPositionMode() const
bool GetKeepTextAligned() const
DIM_PRECISION GetPrecision() const
wxString GetPrefix() const
DIM_UNITS_MODE GetUnitsMode() const
DIM_UNITS_FORMAT GetUnitsFormat() const
virtual const VECTOR2I & GetStart() const
The dimension's origin is the first feature point for the dimension.
DIM_ARROW_DIRECTION GetArrowDirection() const
bool GetSuppressZeroes() const
int GetExtensionOffset() const
int GetArrowLength() const
bool GetOverrideTextEnabled() const
virtual const VECTOR2I & GetEnd() const
For better understanding of the points that make a dimension:
int GetExtensionHeight() const
Mark the center of a circle or arc with a cross shape.
A leader is a dimension-like object pointing to a specific point.
DIM_TEXT_BORDER GetTextBorder() const
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
A radial dimension indicates either the radius or diameter of an arc or circle.
int GetLeaderLength() const
virtual const STRING_ANY_MAP GetProperties() const
virtual wxString GetGeneratorType() const
A set of BOARD_ITEMs (i.e., without duplicates).
Read a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object...
const std::vector< wxString > & GetParseWarnings() const
Return any non-fatal parse warnings that occurred during parsing.
bool IsTooRecent()
Return whether a version number, if any was parsed, was too recent.
bool IsValidBoardHeader()
Partially parse the input and check if it matches expected header.
wxString GetRequiredVersion()
Return a string representing the version of KiCad required to open this file.
A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
BOARD * DoLoad(LINE_READER &aReader, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties, PROGRESS_REPORTER *aProgressReporter, unsigned aLineCount)
bool CanReadBoard(const wxString &aFileName) const override
Checks if this PCB_IO can read the specified board file.
void formatProperties(const BOARD *aBoard) const
formats the Nets and Netclasses
FOOTPRINT * ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete aFootprintName from the library at aLibraryPath.
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void formatTeardropParameters(const TEARDROP_PARAMETERS &tdParams) const
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
const FOOTPRINT * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
void CreateLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Return a list of footprint names contained within the library at aLibraryPath.
void formatPolyPts(const SHAPE_LINE_CHAIN &outline, const FOOTPRINT *aParentFP=nullptr) const
FP_CACHE * m_cache
Footprint library cache.
void formatBoardLayers(const BOARD *aBoard) const
formats the board layer information
FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr) override
Load information from some input file format that this PCB_IO implementation knows about into either ...
bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Check for the existence of a footprint.
void FootprintSave(const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aFootprint to an existing library located at aLibraryPath.
void format(const BOARD *aBoard) const
void SaveBoard(const wxString &aFileName, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
void formatLayers(LSET aLayerMask, bool aEnumerateLayers, bool aIsZone=false) const
void formatGeneral(const BOARD *aBoard) const
formats the General section of the file
void formatVariants(const BOARD *aBoard) const
formats the board variant registry
void ClearCachedFootprints(const wxString &aLibraryPath) override
Clear any cached footprint data for the given library path.
void formatSetup(const BOARD *aBoard) const
formats the board setup information
void FormatBoardToFormatter(OUTPUTFORMATTER *aOut, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr)
Serialize a BOARD to an OUTPUTFORMATTER without file I/O or Prettify.
std::function< bool(wxString aTitle, int aIcon, wxString aMsg, wxString aAction)> m_queryUserCallback
BOARD_ITEM * Parse(const wxString &aClipboardSourceInput)
void init(const std::map< std::string, UTF8 > *aProperties)
void Format(const BOARD_ITEM *aItem) const
Output aItem to aFormatter in s-expression format.
void formatLayer(PCB_LAYER_ID aLayer, bool aIsKnockout=false) const
void formatHeader(const BOARD *aBoard) const
writes everything that comes before the board_items, like settings and layers etc
const FOOTPRINT * getFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties, bool checkModified)
PCB_IO_KICAD_SEXPR(int aControlFlags=CTL_FOR_BOARD)
OUTPUTFORMATTER * m_out
output any Format()s to this, no ownership
void validateCache(const wxString &aLibraryPath, bool checkModified=true)
virtual ~PCB_IO_KICAD_SEXPR()
void formatRenderCache(const EDA_TEXT *aText) const
LINE_READER * m_reader
no ownership
BOARD * m_board
The board BOARD being worked on, no ownership here.
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
PCB_IO(const wxString &aName)
const std::map< std::string, UTF8 > * m_props
Properties passed via Save() or Load(), no ownership, may be NULL.
void Format(OUTPUTFORMATTER *aFormatter) const
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
VECTOR2I GetPosition() const override
Object to handle a bitmap image that can be inserted in a PCB.
VECTOR2I GetPosition() const override
Get the position of the image (this is the center of the image).
REFERENCE_IMAGE & GetReferenceImage()
std::optional< int > GetLocalSolderMaskMargin() const
bool HasSolderMask() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
STROKE_PARAMS GetStroke() const override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
bool StrokeHeaderSeparator() const
bool StrokeColumns() const
bool StrokeExternal() const
std::vector< PCB_TABLECELL * > GetCells() const
const STROKE_PARAMS & GetSeparatorsStroke() const
const STROKE_PARAMS & GetBorderStroke() const
int GetColWidth(int aCol) const
int GetRowHeight(int aRow) const
VECTOR2I GetPosition() const override
bool IsBorderEnabled() const
Disables the border, this is done by changing the stroke internally.
int GetMarginBottom() const
int GetMarginLeft() const
int GetMarginRight() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
bool HasSolderMask() const
std::optional< int > GetLocalSolderMaskMargin() const
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
virtual int GetWidth() const
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
const VECTOR2I & GetArcMid() const
const VECTOR2I & GetP1() const
const VECTOR2I & GetP0() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_ARC & Arc(size_t aArc) const
int PointCount() const
Return the number of points (vertices) in this line chain.
ssize_t ArcIndex(size_t aSegment) const
Return the arc index for the given segment index.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
POLYGON & Polygon(int aIndex)
Return the aIndex-th subpolygon in the set.
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.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
void Format(OUTPUTFORMATTER *out, const EDA_IU_SCALE &aIuScale) const
TEARDROP_PARAMETARS is a helper class to handle parameters needed to build teardrops for a board thes...
double m_BestWidthRatio
The height of a teardrop as ratio between height and size of pad/via.
int m_TdMaxLen
max allowed length for teardrops in IU. <= 0 to disable
bool m_AllowUseTwoTracks
True to create teardrops using 2 track segments if the first in too small.
int m_TdMaxWidth
max allowed height for teardrops in IU. <= 0 to disable
double m_BestLengthRatio
The length of a teardrop as ratio between length and size of pad/via.
double m_WidthtoSizeFilterRatio
The ratio (H/D) between the via/pad size and the track width max value to create a teardrop 1....
bool m_TdOnPadsInZones
A filter to exclude pads inside zone fills.
bool m_Enabled
Flag to enable teardrops.
bool m_CurvedEdges
True if the teardrop should be curved.
virtual void Format(OUTPUTFORMATTER *aFormatter) const
Output the object to aFormatter in s-expression form.
const char * c_str() const
A wrapper around a wxFileName which is much more performant with a subset of the API.
void SetFullName(const wxString &aFileNameAndExtension)
static void ResolvePossibleSymlinks(wxFileName &aFilename)
wxString GetFullPath() const
Handle a list of polygons defining a copper zone.
int GetHatchBorderAlgorithm() const
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
std::optional< int > GetLocalClearance() const override
bool GetDoNotAllowVias() const
ZONE_LAYER_PROPERTIES & LayerProperties(PCB_LAYER_ID aLayer)
wxString GetPlacementAreaSource() const
std::shared_ptr< SHAPE_POLY_SET > GetFilledPolysList(PCB_LAYER_ID aLayer) const
bool GetDoNotAllowPads() const
PLACEMENT_SOURCE_T GetPlacementAreaSourceType() const
bool GetDoNotAllowTracks() const
ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
SHAPE_POLY_SET * Outline()
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
long long int GetMinIslandArea() const
const wxString & GetZoneName() const
int GetMinThickness() const
ZONE_CONNECTION GetPadConnection() const
int GetHatchThickness() const
double GetHatchHoleMinArea() const
bool GetPlacementAreaEnabled() const
bool IsTeardropArea() const
int GetThermalReliefSpokeWidth() const
int GetBorderHatchPitch() const
HatchBorder related methods.
ZONE_BORDER_DISPLAY_STYLE GetHatchStyle() const
EDA_ANGLE GetHatchOrientation() const
bool GetDoNotAllowFootprints() const
ZONE_FILL_MODE GetFillMode() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
TEARDROP_TYPE GetTeardropAreaType() const
double GetHatchSmoothingValue() const
bool GetDoNotAllowZoneFills() const
int GetHatchSmoothingLevel() const
unsigned int GetCornerRadius() const
int GetCornerSmoothingType() const
bool IsOnCopperLayer() const override
PCB_LAYER_ID GetFirstLayer() const
int GetThermalReliefGap() const
unsigned GetAssignedPriority() const
int GetNumCorners(void) const
Access to m_Poly parameters.
This file is part of the common library.
@ RECT_CHAMFER_BOTTOM_RIGHT
@ RECT_CHAMFER_BOTTOM_LEFT
#define CTL_OMIT_HYPERLINK
Omit the hyperlink attribute in .kicad_xxx files.
#define CTL_OMIT_UUIDS
Omit component unique ids (useless in library)
#define CTL_OMIT_FOOTPRINT_VERSION
Omit the version string from the (footprint) sexpr group.
#define CTL_OMIT_INITIAL_COMMENTS
Omit FOOTPRINT initial comments.
#define CTL_OMIT_LIBNAME
Omit lib alias when saving (used for board/not library).
#define CTL_OMIT_PATH
Omit component sheet time stamp (useless in library).
#define CTL_OMIT_AT
Omit position and rotation.
#define CTL_OMIT_PAD_NETS
Omit pads net names (useless in library).
#define CTL_OMIT_COLOR
Omit the color attribute in .kicad_xxx files.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_45
#define IGNORE_PARENT_GROUP
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
@ FILLED_SHAPE
Fill with object color.
EDA_DATA_TYPE
The type of unit.
static const std::string KiCadFootprintFileExtension
const wxChar *const traceKicadPcbPlugin
Flag to enable KiCad PCB plugin debug output.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
bool IsExternalCopperLayer(int aLayerId)
Test whether a layer is an external (F_Cu or B_Cu) copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
KICOMMON_API std::string FormatAngle(const EDA_ANGLE &aAngle)
Convert aAngle from board units to a string appropriate for writing to file.
KICOMMON_API std::string FormatInternalUnits(const EDA_IU_SCALE &aIuScale, int aValue, EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
Converts aValue from internal units to a string appropriate for writing to file.
@ 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.
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
@ FIDUCIAL_LOCAL
a fiducial (usually a smd) local to the parent footprint
@ FIDUCIAL_GLBL
a fiducial (usually a smd) for the full board
@ MECHANICAL
a pad used for mechanical support
@ PRESSFIT
a PTH with a hole diameter with tight tolerances for press fit pin
@ HEATSINK
a pad used as heat sink, usually in SMD footprints
@ NONE
no special fabrication property
@ TESTPOINT
a test point pad
@ CASTELLATED
a pad with a castellated through hole
@ BGA
Smd pad, used in BGA footprints.
@ REMOVE_EXCEPT_START_AND_END
BARCODE class definition.
Class to handle a set of BOARD_ITEMs.
bool isDefaultTeardropParameters(const TEARDROP_PARAMETERS &tdParams)
std::string formatInternalUnits(const int aValue, const EDA_DATA_TYPE aDataType=EDA_DATA_TYPE::DISTANCE)
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
#define CTL_FOR_BOARD
The zero arg constructor when PCB_PLUGIN is used for PLUGIN::Load() and PLUGIN::Save()ing a BOARD fil...
#define CTL_FOR_LIBRARY
Format output for a footprint library instead of clipboard or BOARD.
Pcbnew s-expression file format parser definition.
#define UNDEFINED_DRILL_DIAMETER
PGM_BASE & Pgm()
The global program "get" accessor.
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
bool ReplaceIllegalFileNameChars(std::string &aName, int aReplaceChar)
Checks aName for illegal file name characters.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
VECTOR2I size
Drill diameter (x == y) or slot dimensions (x != y)
std::optional< bool > is_capped
True if the drill hole should be capped.
std::optional< bool > is_filled
True if the drill hole should be filled completely.
std::optional< bool > has_covering
True if the pad on this side should have covering.
std::optional< bool > has_solder_mask
True if this outer layer has mask (is not tented)
std::optional< bool > has_plugging
True if the drill hole should be plugged on this side.
A filename or source description, a problem input line, a line number, a byte offset,...
std::optional< VECTOR2I > hatching_offset
const SHAPE_LINE_CHAIN chain
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.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
@ PCB_ZONE_T
class ZONE, a copper pour area
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.
@ THERMAL
Use thermal relief for pads.
@ THT_THERMAL
Thermal relief only for THT pads.
@ NONE
Pads are not covered.
@ FULL
pads are covered by copper