20#include <boost/test/unit_test.hpp>
31#include <wx/imagpng.h>
32#include <wx/mstream.h>
62#include <nlohmann/json.hpp>
121 DOWNGRADE_TARGET future = { wxT(
"future" ), wxT(
"future" ), 20260623, 20260629, 20260629 };
134 board.
Add( ellipse );
152 board.
Add( ellipse );
163 BOOST_CHECK_CLOSE( areaMM,
M_PI * 5.0 * 3.0, 2.0 );
187 BOOST_CHECK_GT( areaMM, 1.5 );
188 BOOST_CHECK_LT( areaMM, 2.6 );
198 board.
Add( textbox );
214 table->SetColCount( 1 );
218 table->AddCell( cell );
246 table->SetColCount( 1 );
250 table->AddCell( cell );
284 BOOST_CHECK_CLOSE( areaMM, 60.0 - ( 4.0 -
M_PI ), 2.0 );
353 const std::string src = ( tmp.
Path() /
"source.kicad_pcb" ).string();
357 std::unique_ptr<BOARD> current( io.
LoadBoard( src,
nullptr ) );
359 const auto& loadedDefaults = current->GetDesignSettings().m_ZoneLayerProperties;
363 BOOST_CHECK( current->GetDesignSettings().GetDefaultZoneSettings().m_LayerProperties.empty() );
368 const std::string dest = ( tmp.
Path() / ( target.m_id.ToStdString() +
".kicad_pcb" ) ).string();
370 std::unique_ptr<BOARD> reloaded( io.
LoadBoard( dest,
nullptr ) );
372 const auto& defaults = reloaded->GetDesignSettings().m_ZoneLayerProperties;
374 if( target.m_id == wxT(
"9.0" ) )
384 BOOST_CHECK( defaults.at(
F_Cu ).hatching_offset == loadedDefaults.at(
F_Cu ).hatching_offset );
385 BOOST_CHECK( defaults.at(
B_Cu ).hatching_offset == loadedDefaults.at(
B_Cu ).hatching_offset );
413 via->Padstack().Drill().is_capped =
true;
445 group->SetDesignBlockLibId(
LIB_ID( wxT(
"Lib" ), wxT(
"Block" ) ) );
511 const wxString dest = ( tmp.
Path() /
"out.kicad_pcb" ).wstring();
512 const wxString victim = ( tmp.
Path() /
"victim.txt" ).wstring();
515 wxFFile file( victim, wxT(
"wb" ) );
517 file.Write( wxT(
"untouched" ) );
520 const wxString decoy =
521 dest + wxString::Format( wxT(
".downgrade_tmp.%lu" ), (
unsigned long) wxGetProcessId() );
523 std::filesystem::create_symlink( victim.ToStdString(), decoy.ToStdString(), ec );
531 wxFFile file( victim, wxT(
"rb" ) );
538 const wxString reference = ( tmp.
Path() /
"reference.kicad_pcb" ).wstring();
540 std::unique_ptr<BOARD> board( io.
LoadBoard( dest,
nullptr ) );
544 BOOST_CHECK( std::filesystem::status( dest.ToStdString() ).permissions()
545 == std::filesystem::status( reference.ToStdString() ).permissions() );
563 const wxString src = ( tmp.
Path() /
"src.kicad_pcb" ).wstring();
564 const wxString dest = ( tmp.
Path() /
"out.kicad_pcb" ).wstring();
608 BOOST_CHECK( !
pad->Padstack().FrontPostMachining().mode.has_value() );
655 const std::string dest = ( tmp.
Path() /
"out.kicad_pcb" ).string();
662 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
667 for(
size_t i = 0; i <
source->Footprints().size(); i++ )
670 FOOTPRINT* b = exported->Footprints()[i];
678 for(
size_t p = 0; p < a->
Pads().size(); p++ )
692 const std::string dest = ( tmp.
Path() /
"out.kicad_pcb" ).string();
699 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
704 for(
size_t i = 0; i <
source->Footprints().size(); i++ )
707 FOOTPRINT* b = exported->Footprints()[i];
713 for(
size_t pd = 0; pd < a->
Pads().size(); pd++ )
758 board.
Add( barcode );
790 BOOST_CHECK_GT( polyCount, 1 );
791 BOOST_CHECK_GT( areaMM, 5.0 );
792 BOOST_CHECK_CLOSE( areaMM, expectedMM, 0.1 );
799 wxString projectPath = ( tmp.
Path() /
"source.kicad_pro" ).string();
800 wxString boardPath = ( tmp.
Path() /
"source.kicad_pcb" ).string();
801 wxString outputPath = ( tmp.
Path() /
"output.kicad_pcb" ).string();
804 std::ofstream
project( projectPath.ToStdString() );
805 project << R
"({"meta":{"version":3},"text_variables":{"SERIAL":"SERIAL123"}})";
819 board.
Add( barcode );
826 double expectedArea =
expected.Area();
834 int polygonCount = 0;
835 double resultArea = 0;
851 BOOST_CHECK_CLOSE( resultArea, expectedArea, 0.01 );
882 BOOST_CHECK_GT( polyCount, 1 );
894 std::unique_ptr<FOOTPRINT> fp( loader.
ImportFootprint( src, nameOut ) );
900 const wxString dest = ( tmp.
Path() /
"out.kicad_mod" ).wstring();
905 std::ifstream out( dest.ToStdString() );
906 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
907 BOOST_CHECK( content.find(
"(version " + std::to_string(
kicad9.m_boardVersion ) +
")" ) != std::string::npos );
911 std::unique_ptr<FOOTPRINT> reloaded( reader.
ImportFootprint( dest, reloadName ) );
925 std::unique_ptr<FOOTPRINT> fp( loader.
ImportFootprint( src, nameOut ) );
931 const wxString dest = ( tmp.
Path() /
"out.kicad_mod" ).wstring();
935 std::ifstream out( dest.ToStdString() );
936 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
937 BOOST_CHECK( content.find(
"(version " + std::to_string(
kicad10.m_boardVersion ) +
")" ) != std::string::npos );
941 std::unique_ptr<FOOTPRINT> reloaded( reader.
ImportFootprint( dest, reloadName ) );
971 std::string dest = ( tmp.
Path() /
"out.kicad_pcb" ).string();
976 std::unique_ptr<BOARD> reloaded( reader.
LoadBoard( dest,
nullptr ) );
988 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>(
nullptr );
989 fp->GetFields().push_back(
nullptr );
992 const wxString dest = ( tmp.
Path() /
"out.kicad_mod" ).wstring();
996 BOOST_CHECK( std::filesystem::exists( dest.ToStdString() ) );
1008 board.
Add( onBoard );
1013 group->AddItem( onBoard );
1014 group->AddItem( stale );
1018 const std::string dest = ( tmp.
Path() /
"out.kicad_pcb" ).string();
1022 std::ifstream out( dest );
1023 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
1045 const std::string dest = ( tmp.
Path() /
"out.kicad_pcb" ).string();
1049 std::ifstream out( dest );
1050 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
1052 BOOST_CHECK( content.find(
"(remove_unused_layers yes)" ) != std::string::npos );
1053 BOOST_CHECK( content.find(
"(keep_end_layers yes)" ) != std::string::npos );
1056 std::unique_ptr<BOARD> reloaded( reader.
LoadBoard( dest,
nullptr ) );
1060 const PCB_VIA* reloadedVia =
static_cast<const PCB_VIA*
>( reloaded->Tracks().front() );
1077 board.
Add( otherImage );
1093 const std::string dest = ( tmp.
Path() /
"out.kicad_pcb" ).string();
1098 std::ifstream out( dest );
1099 std::string content( ( std::istreambuf_iterator<char>( out ) ), std::istreambuf_iterator<char>() );
1102 BOOST_CHECK_CLOSE( written, originalScale * legacyPPI / ppi, 0.1 );
1104 0.5 * legacyPPI / ppi, 0.1 );
1132 image->GetReferenceImage().SetOpacity( 0.4 );
1152 == wxT(
"transform" ) );
1169 const wxString rules = wxT(
"(version 2)\n"
1171 "(rule \"clearance_ok\"\n"
1172 " # chamfer runs at 45deg here\n"
1173 " (constraint clearance (min 0.2mm))\n"
1174 " (condition \"A.NetClass == 'HV'\"))\n"
1175 "(rule \"mask_check\"\n"
1176 " (constraint bridged_mask))\n"
1177 "(rule \"chain_check\"\n"
1178 " (condition \"inNetChain('x')\")\n"
1179 " (constraint clearance (min 0.1mm)))\n"
1180 "(rule \"delay_check\"\n"
1181 " (constraint skew (max 5ps)))\n" );
1195 "# (rule \"mask_check\"\n# (constraint bridged_mask))\n" ) ) );
1196 BOOST_CHECK(
result.m_text.Contains( wxT(
"# (rule \"chain_check\"\n# (condition \"inNetChain('x')\")\n" ) ) );
1197 BOOST_CHECK(
result.m_text.Contains( wxT(
"# (rule \"delay_check\"\n# (constraint skew (max 5ps)))\n" ) ) );
1204 const wxString rules = wxT(
"(version 1)\n"
1205 "(rule \"line_width\" (layer F.SilkS) (constraint line_width (min 0.2mm)))\n" );
1213 "(rule \"line_width\" (layer F.SilkS) "
1214 "(constraint text_thickness (min 0.2mm)))\n" ) ) );
1223 std::vector<std::shared_ptr<DRC_RULE>> rules;
1226 return rules.size();
1232 const wxString rules = wxT(
"(version 2)\n"
1233 "(rule \"keep\" (constraint clearance (min 0.2mm)))\n"
1234 "# why the chain rule exists\n"
1236 " (constraint net_chain_length (max 10mm)))\n"
1237 "(rule \"glued\" (constraint net_chain_length (max 1mm)))"
1238 "(rule \"after\" (constraint clearance (min 0.1mm)))\n" );
1246 const wxString marker = wxT(
"# Not supported by " ) + target.m_name + wxT(
":\n" );
1247 const wxString
expected = wxT(
"(version 1)\n"
1248 "(rule \"keep\" (constraint clearance (min 0.2mm)))\n"
1249 "# why the chain rule exists\n" )
1251 + wxT(
"# (rule \"chain\"\n"
1252 "# (constraint net_chain_length (max 10mm)))\n" )
1254 + wxT(
"# (rule \"glued\" (constraint net_chain_length (max 1mm)))\n"
1255 "(rule \"after\" (constraint clearance (min 0.1mm)))\n" );
1264 const wxString rules = wxT(
"(version 2)"
1265 "(rule \"first\" (constraint net_chain_length (max 1mm)))"
1266 "(rule \"kept\" (constraint clearance (min 0.2mm)))"
1267 "(rule \"last\" (constraint net_chain_length (max 1mm)))" );
1274 const wxString marker = wxT(
"# Not supported by " ) + target.m_name + wxT(
":\n" );
1275 const wxString
expected = wxT(
"(version 1)\n" ) + marker
1276 + wxT(
"# (rule \"first\" (constraint net_chain_length (max 1mm)))\n"
1277 "(rule \"kept\" (constraint clearance (min 0.2mm)))\n" )
1278 + marker + wxT(
"# (rule \"last\" (constraint net_chain_length (max 1mm)))\n" );
1287 const wxString rules = wxT(
"(version 2)\r\n"
1288 " (rule \"messy\"\r\n"
1289 " # ) \" ( unmatched in a comment\r\n"
1290 " (condition \"A.NetName == 'a'\")\r\n"
1291 " (constraint net_chain_length (max 1mm)))\r\n"
1292 "(rule \"kept\" (constraint clearance (min 0.2mm)))\r\n" );
1301 const wxString
expected = wxT(
"(version 1)\r\n # Not supported by " ) + target.m_name
1303 "# (rule \"messy\"\r\n"
1304 "# # ) \" ( unmatched in a comment\r\n"
1305 "# (condition \"A.NetName == 'a'\")\r\n"
1306 "# (constraint net_chain_length (max 1mm)))\r\n"
1307 "(rule \"kept\" (constraint clearance (min 0.2mm)))\r\n" );
1316 const wxString rules = wxT(
"(version 2)\n"
1317 "(future_block \"x\" (constraint clearance (min 1mm)))\n"
1318 "(rule \"kept\" (constraint clearance (min 0.2mm)))\n" );
1325 BOOST_CHECK(
result.m_text.Contains( wxT(
"# (future_block \"x\" (constraint clearance (min 1mm)))\n"
1326 "(rule \"kept\"" ) ) );
1334 const wxString rules = wxT(
"(version 2)\n"
1335 "# why the chain rule exists\n"
1338 " (constraint net_chain_length (max 10mm)))\n"
1339 "(rule \"after\" (constraint clearance (min 0.1mm)))"
1340 "(rule \"last\" (constraint net_chain_length (max 1mm)))\n"
1341 "# trailing note\n" );
1348 BOOST_CHECK( first.
m_text.EndsWith( wxT(
"# (rule \"last\" (constraint net_chain_length (max 1mm)))\n"
1349 "# trailing note\n" ) ) );
1361 const wxString rules = wxT(
"(version 1)\n"
1362 "(rule \"return_path\" (constraint clearance (min 0.2mm)))\n"
1363 "(rule inNetChain (constraint clearance (min 0.2mm)))\n"
1364 "(rule \"literal\" (condition \"A.NetName == 'hasNetChain() 100 ps .Parent.'\")\n"
1365 " (constraint clearance (min 0.2mm)))\n" );
1379 const wxString rules = wxT(
"(version 1)\n"
1380 "(rule \"time\" (constraint length (min \"100 ps\")))\n"
1381 "(rule \"femtoseconds\" (constraint length (max \"2 * 100 fs\")))\n"
1382 "(rule \"angle\" (constraint track_angle (max \"90 deg\")))\n"
1383 "(rule \"ordinary\" (constraint clearance (min \"0.2 mm\")))\n" );
1400 const wxString rules = wxT(
"(version 2)\n"
1401 "(rule \"mask_check\" (constraint bridged_mask))\n"
1402 "(rule \"delay_check\" (constraint skew (max 5ps)))\n"
1403 "(rule \"chain_check\" (constraint net_chain_length (max 10mm)))\n" );
1418 const wxString kept = wxT(
"(rule \"clearance # literal\"\n"
1419 " # unmatched: ) (( \" \\\n"
1420 " (condition \"A.NetName == 'SIGNAL#1'\")\n"
1421 " # inNetChain('x')\n"
1422 " (constraint clearance (min 0.2mm))\n"
1425 "(rule \"second\" (constraint track_width (min 0.25mm)))" );
1426 const wxString input = wxT(
"(version 2)\n" ) + kept
1427 + wxT(
"\n(rule \"unsupported\"\n # ) \" (\n"
1428 " (constraint net_chain_length (max 10mm)))\n" );
1440 std::vector<std::shared_ptr<DRC_RULE>> rules;
1452 const wxString rules = wxT(
"# project rules\n"
1454 "(rule \"a\" (constraint clearance (min 0.2mm)))\n" );
1460 "(rule \"a\" (constraint clearance (min 0.2mm)))\n" ) );
1467 const wxString rules = wxT(
"# intro\n"
1468 "(rule \"a\" (constraint net_chain_length (max 1mm)))\n" );
1474 "# Not supported by KiCad 9.0:\n"
1475 "# (rule \"a\" (constraint net_chain_length (max 1mm)))\n" ) );
1482 const wxString rules = wxT(
"(version 2)(rule \"kept\" (constraint clearance (min 0.2mm)))" );
1486 BOOST_CHECK_EQUAL(
result.m_text, wxString(
"(version 1)(rule \"kept\" (constraint clearance (min 0.2mm)))\n" ) );
1493 const wxString rules = wxT(
"(version 1) # note\n(rule \"a\" (constraint clearance (min 0.2mm)))\n" );
1502 const wxString rules = wxT(
"(version 1)(rule \"c\" (condition \"A.Width > 5ps\") "
1503 "(constraint clearance (min 0.2mm)))" );
1512 const wxString rules = wxT(
"(version 1)\n"
1515 " (constraint clearance (min 0.2mm)))\n" );
1523 const wxString rules = wxT(
"(version 1)(rule \"f\" (condition \"A.InsideCourtyard('x')\") "
1524 "(constraint clearance (min 0.2mm)))" );
1533 const wxString rules = wxT(
"(version 1)(rule \"hv\" (condition \"A.memberOfFootprint('${Class:HV}')\") "
1534 "(constraint clearance (min 1mm)))" );
1543 const wxString parent = wxT(
"(version 1)(rule \"x\" (condition A.Parent.Reference==B.Reference) "
1544 "(constraint clearance (min 1mm)))" );
1545 const wxString assertion = wxT(
"(version 1)(rule \"x\" (constraint assertion A.Parent.Reference==B.Reference))" );
1546 const wxString plain = wxT(
"(version 1)(rule \"x\" (condition A.NetClass=='HV') "
1547 "(constraint clearance (min 1mm)))" );
1560 const wxString newItem = wxT(
"(version 1)(rule \"y\" (constraint disallow \"blind_via\"))" );
1561 const wxString oldItem = wxT(
"(version 1)(rule \"y\" (constraint disallow \"via\"))" );
1562 const wxString connection = wxT(
"(version 1)(rule \"z\" (constraint zone_connection \"thermal_reliefs\"))" );
1577 const wxString rules = wxT(
"(version 1)\n(rule \"a\" (condition \"A.NetClass ==\n 'HV'\") "
1578 "(constraint clearance (min 0.2mm)))\n" );
1587 const wxString rules = wxT(
"(version 1)\n"
1589 "# the head comes after this comment\n"
1590 "rule \"a\" (constraint clearance (min 0.2mm)))\n"
1592 "# so does this one\n"
1593 "rule \"b\" (constraint net_chain_length (max 1mm)))\n" );
1608 for(
const wxString& input : { wxT(
"(version 1)\n(rule \"inline\" # )\n (constraint clearance (min 0.2mm)))" ),
1609 wxT(
"(version 1)\n(rule \"missing_close\" (constraint clearance (min 0.2mm))" ),
1610 wxT(
"(version 1)\n(rule \"missing_quote" ) } )
1627 const std::string release = target.m_id == wxT(
"9.0" ) ?
"v9" :
"v10";
1632 release ==
"v9" ? 1 : 2 );
1662 nlohmann::json doc = {
1663 {
"meta", { {
"filename",
"p.kicad_pro" }, {
"version", 3 } } },
1664 {
"board", { {
"layer_presets", { { {
"name",
"P" }, {
"renderLayers", {
"tracks",
"vias" } } } } } } },
1666 { {
"meta", { {
"version", 5 } } },
1667 {
"classes", { { {
"name",
"Default" }, {
"priority", 0 }, {
"tuning_profile",
"tp" } } } },
1668 {
"net_chain_classes", { { {
"name",
"chainA" } } } } } },
1669 {
"tuning_profiles",
1670 { {
"meta", { {
"version", 1 } } },
1671 {
"tuning_profiles_impedance_geometric",
1672 { { {
"name",
"tp" }, {
"frequency", 1e9 }, {
"model_solder_mask",
false } } } } } },
1673 {
"component_class_settings", { {
"meta", { {
"version", 0 } } } } },
1675 { {
"top_level_sheets", {
"aaaa" } },
1676 {
"bus_aliases", nlohmann::json::array() },
1677 {
"variants", nlohmann::json::array() } } },
1687 const nlohmann::json& preset = doc[
"board"][
"layer_presets"][0];
1694 BOOST_CHECK( !doc[
"net_settings"][
"classes"][0].contains(
"tuning_profile" ) );
1695 BOOST_CHECK( doc[
"net_settings"][
"classes"][0].contains(
"name" ) );
1696 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
1697 BOOST_CHECK( !doc.contains(
"tuning_profiles" ) );
1698 BOOST_CHECK( !doc.contains(
"component_class_settings" ) );
1699 BOOST_CHECK( !doc[
"schematic"].contains(
"top_level_sheets" ) );
1700 BOOST_CHECK( !doc[
"schematic"].contains(
"bus_aliases" ) );
1701 BOOST_CHECK( !doc[
"schematic"].contains(
"variants" ) );
1711 const nlohmann::json
empty = nlohmann::json::array();
1712 const std::vector<nlohmann::json> tuningDefaults = {
1714 nlohmann::json::object(),
1715 { {
"meta", { {
"version", 2 } } } },
1716 { {
"meta", { {
"version", 2 } } }, {
"tuning_profiles_impedance_geometric",
empty } },
1718 const std::vector<nlohmann::json> componentDefaults = {
1720 nlohmann::json::object(),
1721 { {
"meta", { {
"version", 0 } } } },
1722 { {
"assignments",
empty }, {
"sheet_component_classes", nlohmann::json::object() } },
1723 { {
"meta", { {
"version", 0 } } },
1724 {
"assignments",
empty },
1725 {
"sheet_component_classes", { {
"enabled",
false } } } },
1730 for(
const auto& tuning : tuningDefaults )
1732 for(
const auto& components : componentDefaults )
1734 nlohmann::json doc = {
1735 {
"meta", { {
"version", 4 } } },
1736 {
"board", { {
"design_settings", { {
"meta", { {
"version", 3 } } } } } } },
1737 {
"erc", { {
"meta", { {
"version", 1 } } }, {
"erc_exclusions",
empty } } },
1739 { {
"meta", { {
"version", 5 } } },
1740 {
"classes", { { {
"name",
"Default" }, {
"tuning_profile",
"" } } } } } },
1741 {
"tuning_profiles", tuning },
1742 {
"component_class_settings", components },
1752 BOOST_CHECK_EQUAL( doc[
"board"][
"design_settings"][
"meta"][
"version"].get<int>(), 2 );
1754 BOOST_CHECK_EQUAL( doc.contains(
"tuning_profiles" ), target.m_id == wxT(
"10.0" ) );
1755 BOOST_CHECK_EQUAL( doc.contains(
"component_class_settings" ), target.m_id == wxT(
"10.0" ) );
1757 const nlohmann::json once = doc;
1770 const nlohmann::json
empty = nlohmann::json::array();
1771 const nlohmann::json profile = {
1772 {
"profile_name",
"Default" },
1773 {
"frequency", 1e9 },
1774 {
"model_solder_mask",
false },
1775 {
"net_chain_bridge_prop_delay", 0 },
1777 const std::vector<nlohmann::json> meaningful = {
1778 { {
"tuning_profiles", { {
"tuning_profiles_impedance_geometric", { profile } } } } },
1779 { {
"net_settings", { {
"classes", { { {
"tuning_profile",
"Saved" } } } } } } },
1780 { {
"tuning_profiles", { {
"tuning_profiles_impedance_geometric",
empty } } },
1781 {
"net_settings", { {
"classes", { { {
"tuning_profile",
"Saved" } } } } } } },
1782 { {
"tuning_profiles", { {
"tuning_profiles_impedance_geometric", { profile } } } },
1784 { {
"classes", { { {
"tuning_profile",
"Default" } }, { {
"tuning_profile",
"Default" } } } } } } },
1785 { {
"component_class_settings",
1787 { { {
"component_class",
"Fast" }, {
"conditions_operator",
"ALL" }, {
"conditions",
empty } } } },
1788 {
"sheet_component_classes", { {
"enabled",
false } } } } } },
1789 { {
"component_class_settings",
1790 { {
"assignments",
empty }, {
"sheet_component_classes", { {
"enabled",
true } } } } } },
1793 for(
const auto&
source : meaningful )
1797 nlohmann::json doc =
source;
1804 const nlohmann::json once = doc;
1816 const nlohmann::json
source = {
1817 {
"meta", { {
"version", 4 } } },
1818 {
"component_class_settings", { {
"meta", { {
"version", 1 } } } } },
1823 nlohmann::json doc =
source;
1836 nlohmann::json metaIsString = {
1837 {
"meta",
"not an object" },
1838 {
"net_settings", { {
"meta",
"also a string" }, {
"classes",
"not an array" } } },
1839 {
"schematic",
"a string" },
1842 nlohmann::json profilesWrong = {
1843 {
"tuning_profiles",
1844 { {
"meta", 7 }, {
"tuning_profiles_impedance_geometric", {
"just",
"strings" } } } },
1856 nlohmann::json doc = {
1857 {
"net_settings", { {
"net_chain_classes", nlohmann::json::array() } } },
1863 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
1870 nlohmann::json doc = {
1871 {
"tuning_profiles",
1872 { {
"meta", { {
"version", 1 } } },
1873 {
"tuning_profiles_impedance_geometric",
1874 { { {
"profile_name",
"5 GHz" }, {
"frequency", 5e9 }, {
"model_solder_mask",
true } },
1875 { {
"profile_name",
"Default" }, {
"frequency", 1e9 }, {
"model_solder_mask",
false } } } } } }
1883 for(
const auto& profile : doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"] )
1886 BOOST_CHECK( !profile.contains(
"model_solder_mask" ) );
1897 nlohmann::json doc = {
1898 {
"meta", { {
"version", 3 } } },
1900 { {
"meta", { {
"version", 5 } } },
1901 {
"classes", { { {
"name",
"Default" }, {
"priority", 0 }, {
"tuning_profile",
"tp" } } } },
1902 {
"net_chain_classes", { { {
"name",
"chainA" } } } } } },
1903 {
"tuning_profiles",
1904 { {
"meta", { {
"version", 1 } } },
1905 {
"tuning_profiles_impedance_geometric",
1906 { { {
"name",
"tp" }, {
"frequency", 1e9 }, {
"model_solder_mask",
false } } } } } },
1915 BOOST_CHECK( doc[
"net_settings"][
"classes"][0].contains(
"tuning_profile" ) );
1916 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
1919 BOOST_CHECK( !doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"][0].contains(
"frequency" ) );
1920 BOOST_CHECK( !doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"][0].contains(
"model_solder_mask" ) );
1952 BOOST_CHECK_GT( areaMM, 4.0 );
1953 BOOST_CHECK_LT( areaMM, 15.0 );
1977 BOOST_CHECK_CLOSE( ref.
GetImageScale(), 2.0 * legacyPPI / ppi, 0.1 );
1984 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>(
nullptr );
1999 BOOST_CHECK_CLOSE( ref.
GetImageScale(), 2.0 * legacyPPI / ppi, 0.1 );
2026 const wxString src = ( tmp.
Path() /
"src.kicad_mod" ).wstring();
2027 const wxString dest = ( tmp.
Path() /
"out.kicad_mod" ).wstring();
2030 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>(
nullptr );
2048 std::unique_ptr<FOOTPRINT> srcAgain( reader.
ImportFootprint( src, nameOut ) );
2049 std::unique_ptr<FOOTPRINT> converted( reader.
ImportFootprint( dest, nameOut ) );
2055 BOOST_CHECK_EQUAL( converted->Zones()[0]->GetLayerSet().count(), srcAgain->Zones()[0]->GetLayerSet().count() );
2064 const wxString dir = tmp.
Path().wstring();
2066 auto writeFile = [&](
const wxString& aName,
const wxString& aContent )
2068 wxFFile file( dir + wxFileName::GetPathSeparator() + aName, wxT(
"wb" ) );
2070 file.Write( aContent );
2073 writeFile( wxT(
"a.fake_mod" ), wxT(
"old a" ) );
2074 writeFile( wxT(
"b.fake_mod" ), wxT(
"old b" ) );
2076 auto noForbidden = [](
const wxString& )
2083 wxFFile out( aTmp, wxT(
"wb" ) );
2084 out.Write( wxT(
"(version 123) converted" ) );
2090 wxFFile check( dir + wxFileName::GetPathSeparator() + wxT(
"a.fake_mod" ), wxT(
"rb" ) );
2092 BOOST_REQUIRE( check.IsOpened() && check.ReadAll( &content ) );
2093 BOOST_CHECK( content.Contains( wxT(
"converted" ) ) );
2098 if( aFile.Contains( wxT(
"b.fake_mod" ) ) )
2101 wxFFile out( aTmp, wxT(
"wb" ) );
2102 out.Write( wxT(
"(version 123) second pass" ) );
2107 BOOST_CHECK( bad.Contains( wxT(
"b.fake_mod" ) ) );
2109 wxArrayString leftovers;
2110 wxDir::GetAllFiles( dir, &leftovers );
2113 wxFFile recheck( dir + wxFileName::GetPathSeparator() + wxT(
"a.fake_mod" ), wxT(
"rb" ) );
2115 BOOST_REQUIRE( recheck.IsOpened() && recheck.ReadAll( &unchanged ) );
2116 BOOST_CHECK( !unchanged.Contains( wxT(
"second pass" ) ) );
2160 for(
bool footprintOnly : {
false,
true } )
2177 parent->
Add( shape );
2178 group->AddItem( shape );
2182 parent->
Add( barcode );
2183 group->AddItem( barcode );
2186 textbox->
SetText( wxT(
"Do not retain as plain text" ) );
2187 parent->
Add( textbox );
2188 group->AddItem( textbox );
2191 parent->
Add( supported );
2192 group->AddItem( supported );
2193 const KIID supportedUuid = supported->
m_Uuid;
2201 for(
size_t i = 0; i <
normal.Entries().size(); ++i )
2206 BOOST_CHECK( !omit.Entries()[i].m_detail.IsEmpty() );
2234 parent->Add( hatch );
2236 table->SetColCount( 2 );
2239 knockout->
SetText( wxT(
"knockout" ) );
2240 table->AddCell( knockout );
2242 plain->
SetText( wxT(
"supported" ) );
2243 table->AddCell( plain );
2244 parent->Add(
table );
2270 for(
int ii = 0; ii < 3; ++ii )
2281 board.
Add( copper );
2283 for(
bool drop : {
false,
true } )
2299 for(
bool drop : {
false,
true } )
2307 std::vector<PCB_SHAPE*> copper;
2308 std::vector<PCB_SHAPE*> silk;
2316 parent->Add( onCopper );
2317 copper.push_back( onCopper );
2322 parent->Add( onSilk );
2323 silk.push_back( onSilk );
2340 for(
bool footprintOnly : {
false,
true } )
2351 pad->AddPrimitive(
F_Cu, rounded );
2353 pad->AddPrimitive(
F_Cu, supported );
2370 for(
bool drop : {
false,
true } )
2380 board.
Add( buried );
2382 board.
Add( supported );
2411 board.
Add( textbox );
2415 board.
Add( buried );
2447 const wxString board =
directory + wxT(
"/board.kicad_pcb" );
2449 auto write = [](
const wxString& aPath,
const wxString& aContent )
2451 wxFFile file( aPath, wxT(
"wb" ) );
2452 BOOST_REQUIRE( file.IsOpened() && file.Write( aContent ) && file.Close() );
2455 auto read = [](
const wxString& aPath )
2457 wxFFile file( aPath, wxT(
"rb" ) );
2459 BOOST_REQUIRE( file.IsOpened() && file.ReadAll( &content ) );
2463 auto noForbidden = [](
const wxString& )
2467 auto convert = [&](
const wxString&,
const wxString& aTemporary )
2469 write( aTemporary, wxT(
"(version 123) converted" ) );
2473 write(
library, wxT(
"original library" ) );
2474 write( board, wxT(
"original board" ) );
2493 wxString stagedBoard = transaction.
Stage( board );
2495 write( stagedBoard, wxT(
"converted board" ) );
2501 wxArrayString files;
2502 wxDir::GetAllFiles(
directory, &files );
2511 const wxString first =
directory + wxT(
"/first.kicad_pcb" );
2512 const wxString second =
directory + wxT(
"/second.kicad_pcb" );
2515 wxFFile file( first, wxT(
"wb" ) );
2516 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT(
"original" ) ) && file.Close() );
2521 wxString stagedFirst = transaction.
Stage( first );
2522 wxString stagedSecond = transaction.
Stage( second );
2523 BOOST_REQUIRE( !stagedFirst.IsEmpty() && !stagedSecond.IsEmpty() );
2525 for(
const wxString& file : { stagedFirst, stagedSecond } )
2527 wxFFile output( file, wxT(
"wb" ) );
2528 BOOST_REQUIRE( output.IsOpened() && output.Write( wxT(
"converted" ) ) && output.Close() );
2532 BOOST_CHECK( wxFileName( transaction.
Commit() ).SameAs( wxFileName( second ) ) );
2536 wxFFile input( first, wxT(
"rb" ) );
2538 BOOST_REQUIRE( input.IsOpened() && input.ReadAll( &content ) );
2541 wxArrayString files;
2542 wxDir::GetAllFiles(
directory, &files );
2550 const wxString destination = temporary.
Path().wstring() + wxT(
"/board.kicad_pcb" );
2555 wxString firstTemporary = first.
Stage( destination );
2556 wxString secondTemporary = second.
Stage( destination );
2557 BOOST_REQUIRE( !firstTemporary.IsEmpty() && !secondTemporary.IsEmpty() );
2561 first.
Discard( firstTemporary );
2574 const auto original = temporary.
Path() / u8
"original-μ.kicad_mod";
2575 const auto alias = temporary.
Path() /
"alias.kicad_mod";
2576 const auto danglingAlias = temporary.
Path() /
"dangling.kicad_mod";
2579 wxFFile file( original.wstring(), wxT(
"wb" ) );
2580 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT(
"original source" ) ) && file.Close() );
2583 std::error_code error;
2584 std::filesystem::create_symlink( original.filename(), alias, error );
2592 std::filesystem::create_symlink(
"missing.kicad_mod", danglingAlias, error );
2598 for(
const auto& destination : { alias, danglingAlias } )
2600 wxString staged = transaction.
Stage( destination.wstring() );
2602 wxFFile file( staged, wxT(
"wb" ) );
2603 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT(
"converted output" ) ) && file.Close() );
2609 wxFFile file( original.wstring(), wxT(
"rb" ) );
2611 BOOST_REQUIRE( file.IsOpened() && file.ReadAll( &content ) );
2613 BOOST_CHECK( !std::filesystem::is_symlink( alias ) );
2614 BOOST_CHECK( !std::filesystem::is_symlink( danglingAlias ) );
2616 std::filesystem::directory_iterator() ),
2626 if( entry.m_feature == aName )
2635 BOOST_ERROR(
"Missing compatibility feature: " + aName.ToStdString() );
2643 for(
bool drop : {
false,
true } )
2649 std::vector<PCB_SHAPE*> shapes;
2657 parent->Add( shape );
2658 shapes.push_back( shape );
2661 parent->Add( constraint );
2685 for(
bool drop : {
false,
true } )
2712 for(
bool drop : {
false,
true } )
2726 group->AddItem( live );
2757 const std::string src = ( tmp.
Path() /
"stackup.kicad_pcb" ).string();
2782 std::ifstream file( src );
2783 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
2784 BOOST_REQUIRE( content.find(
"(stackup_table" ) != std::string::npos );
2791 const std::string dest = ( tmp.
Path() / (
"out-" + target.m_id.ToStdString() +
".kicad_pcb" ) ).string();
2796 std::ifstream file( dest );
2797 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
2799 BOOST_CHECK( content.find(
"(stackup_table" ) == std::string::npos );
2800 BOOST_CHECK( content.find(
"(table" ) != std::string::npos );
2803 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
2807 BOARD_ITEM* item = *exported->Drawings().begin();
2820 for(
bool drop : {
false,
true } )
2827 board.
Add( stitch );
2831 std::vector<PCB_VIA*> vias;
2837 via->SetPosition(
VECTOR2I( 1000000 * ( vias.size() + 1 ), 2000000 ) );
2838 via->SetWidth(
F_Cu, 600000 );
2839 via->SetDrill( 300000 );
2841 generator->AddItem(
via );
2842 vias.push_back(
via );
2853 for(
size_t ii = 0; ii < vias.size(); ++ii )
2858 BOOST_CHECK( vias[ii]->GetParentGroup() == outer );
2867 const std::string src =
2879 const auto copperById = [](
const BOARD& aBoard )
2881 std::map<KIID, const PCB_TRACK*> items;
2883 for(
const PCB_TRACK* item : aBoard.Tracks() )
2884 BOOST_REQUIRE( items.emplace( item->m_Uuid, item ).second );
2888 const auto memberIds = [](
const PCB_GROUP& aGroup )
2892 for(
const EDA_ITEM* member : aGroup.GetItems() )
2897 const auto serializeNative = [](
BOARD* aBoard )
2905 const auto sourceCopper = copperById( *
source );
2907 std::set<KIID> plainVias;
2908 std::set<KIID> generatedVias;
2909 size_t sourceVias = 0;
2910 size_t sourceSegments = 0;
2911 size_t sourceMicrovias = 0;
2913 for(
const auto& [
id, item] : sourceCopper )
2925 if( !
via->GetParentGroup() )
2926 plainVias.insert(
id );
2949 BOOST_REQUIRE(
source->FindNet( viaStitch->GetNetCode() )->GetNetname() == wxT(
"GND" ) );
2975 for(
BOARD_ITEM* member : generator->GetBoardItems() )
2979 BOOST_REQUIRE( sourceCopper.count( member->m_Uuid ) == 1u );
2980 BOOST_REQUIRE( generatedVias.insert( member->m_Uuid ).second );
2989 const auto stitchMembers = memberIds( *stitch );
2992 const wxString outerName = outer->
GetName();
2997 const std::string sourceModel = serializeNative(
source.get() );
3002 const bool preTen = target.m_boardVersion ==
kicad9.m_boardVersion;
3004 for(
bool drop : {
false,
true } )
3013 const std::string dest =
3015 / ( target.m_id.ToStdString() + ( drop ?
"-drop.kicad_pcb" :
"-lower.kicad_pcb" ) ) )
3018 wxString unsupportedToken;
3034 for(
size_t ii = 0; ii < preview.
Entries().size(); ++ii )
3043 BOOST_CHECK( outputBytes.find(
"(generated" ) == std::string::npos );
3047 for(
const char* token : {
"(filling",
"(capping",
"(covering",
"(plugging" } )
3048 BOOST_CHECK( outputBytes.find( token ) == std::string::npos );
3051 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
3053 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3058 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3060 const auto exportedCopper = copperById( *exported );
3062 PCB_GROUP* exportedOuter = *exported->Groups().begin();
3065 BOOST_CHECK( memberIds( *exportedOuter ) == stitchMembers );
3067 for(
const auto& [
id, original] : sourceCopper )
3069 const auto found = exportedCopper.find(
id );
3078 if(
const PCB_VIA* originalVia =
dynamic_cast<const PCB_VIA*
>( original ) )
3105 const PADSTACK& originalStack = originalVia->Padstack();
3118 if( plainVias.count(
id ) )
3127 if( stitchMembers.count(
id ) )
3137 const auto found = std::find_if( exported->Drawings().begin(), exported->Drawings().end(),
3140 return aItem->m_Uuid == drawing->m_Uuid;
3165 std::unique_ptr<BOARD> lengthFixture( io.
LoadBoard( lengthPath,
nullptr ) );
3166 std::unique_ptr<BOARD> timeFixture( io.
LoadBoard( timePath,
nullptr ) );
3174 if( generator->m_Uuid ==
KIID(
"2acf841f-25ce-450c-b8df-dbbc34cc96ac" ) )
3184 auto length =
dynamic_cast<PCB_TUNING_PATTERN*
>( ( *lengthFixture->Generators().begin() )->DeepClone() );
3188 BOOST_REQUIRE_GT( length->GetItems().size(), 1u );
3190 const auto addCopper = [&](
PCB_TRACK* aTrack )
3196 net =
new NETINFO_ITEM( &board, aTrack->GetNetname() );
3202 board.
Add( aTrack );
3207 for(
BOARD_ITEM* member : pattern->GetBoardItems() )
3214 board.
Add( pattern );
3219 for(
PCB_TRACK* track : timeFixture->Tracks() )
3223 originalControl = track;
3229 auto control =
static_cast<PCB_TRACK*
>( originalControl->
Clone() );
3230 control->SetParentGroup(
nullptr );
3231 addCopper( control );
3233 outer->
SetName( wxT(
"Native tuning ownership" ) );
3239 double patternLength = 0;
3241 for(
BOARD_ITEM* member : length->GetBoardItems() )
3242 patternLength +=
static_cast<PCB_TRACK*
>( member )->GetLength();
3247 for(
const char* key : {
"tuning_mode",
"initial_side",
"last_status" } )
3251 lengthProperties[key] = wxAny( wxString::FromUTF8( value ) );
3254 lengthProperties[
"last_tuning_length"] = wxAny( patternLength /
pcbIUScale.IU_PER_MM );
3255 length->SetProperties( lengthProperties );
3256 const wxString tuningInfo = length->GetRowData().back().second.GetString();
3258 const auto memberIds = [](
const PCB_GROUP& aGroup )
3262 for(
const EDA_ITEM* member : aGroup.GetItems() )
3267 const auto serializeNative = [](
BOARD* aBoard )
3274 std::map<KIID, const PCB_TRACK*> copper;
3277 BOOST_REQUIRE( copper.emplace( track->m_Uuid, track ).second );
3279 const auto lengthMembers = memberIds( *length );
3280 const auto timeMembers = memberIds( *time );
3284 const std::string src = ( tmp.
Path() /
"native-source.kicad_pcb" ).string();
3287 const std::string sourceModel = serializeNative( &board );
3291 const bool preTen = target.m_boardVersion ==
kicad9.m_boardVersion;
3293 for(
bool drop : {
false,
true } )
3302 const std::string dest =
3304 / ( target.m_id.ToStdString() + ( drop ?
"-drop.kicad_pcb" :
"-lower.kicad_pcb" ) ) )
3307 wxString unsupported;
3324 for(
const char* token : {
"(is_time_domain",
"(target_delay",
"(last_tuning_length" } )
3325 BOOST_CHECK( outputBytes.find( token ) == std::string::npos );
3328 BOOST_CHECK( outputBytes.find(
"(last_tuning " + quoting.
Quotew( tuningInfo ) +
")" )
3329 != std::string::npos );
3333 BOOST_CHECK( outputBytes.find(
"(is_time_domain yes)" ) != std::string::npos );
3334 BOOST_CHECK( outputBytes.find(
"(last_tuning_length " ) != std::string::npos );
3335 BOOST_CHECK( outputBytes.find(
"(last_tuning " ) == std::string::npos );
3338 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
3340 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3343 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3344 PCB_GROUP* exportedOuter = *exported->Groups().begin();
3346 std::set<KIID> expectedOuter{ length->m_Uuid };
3349 expectedOuter.insert( timeMembers.begin(), timeMembers.end() );
3351 expectedOuter.insert( time->m_Uuid );
3353 BOOST_CHECK( memberIds( *exportedOuter ) == expectedOuter );
3356 for(
const PCB_TRACK* track : exported->Tracks() )
3358 const auto found = copper.find( track->m_Uuid );
3360 const PCB_TRACK* original = found->second;
3368 if(
const PCB_ARC* arc =
dynamic_cast<const PCB_ARC*
>( original ) )
3370 const PCB_ARC* exportedArc =
dynamic_cast<const PCB_ARC*
>( track );
3375 if( timeMembers.count( track->m_Uuid ) && preTen )
3377 else if( track->m_Uuid == control->m_Uuid )
3386 BOOST_CHECK( pattern->m_Uuid == length->m_Uuid || ( !preTen && pattern->m_Uuid == time->m_Uuid ) );
3387 const bool isTime = pattern->m_Uuid == time->m_Uuid;
3388 BOOST_CHECK( pattern->GetSettings().m_isTimeDomain == isTime );
3389 BOOST_CHECK( memberIds( *pattern ) == ( isTime ? timeMembers : lengthMembers ) );
3394 for(
const char* key :
3395 {
"target_length",
"target_length_min",
"target_length_max",
"target_skew",
"target_skew_min",
3396 "target_skew_max",
"min_spacing",
"max_amplitude",
"min_amplitude" } )
3399 double originalValue = 0;
3401 BOOST_REQUIRE( originalProperties.get_to( key, originalValue ) );
3407 for(
const char* key :
3408 {
"target_delay",
"target_delay_min",
"target_delay_max",
"last_tuning_length" } )
3411 double originalValue = 0;
3413 BOOST_REQUIRE( originalProperties.get_to( key, originalValue ) );
3439 properties.
set(
"future_tuning_setting",
true );
3445 auto pattern =
new UNREVIEWED_TUNING_PATTERN( &board );
3447 track->SetStart(
VECTOR2I( 1000000, 2000000 ) );
3448 track->SetEnd(
VECTOR2I( 3000000, 2000000 ) );
3450 board.
Add( pattern );
3451 pattern->AddItem( track );
3455 for(
bool drop : {
false,
true } )
3468 const wxString
path = ( tmp.
Path() / ( target.m_id.ToStdString() +
".kicad_pcb" ) ).wstring();
3478 pattern->SetTargetDelay( 100000 );
3480 track->SetStart(
VECTOR2I( 1000000, 2000000 ) );
3481 track->SetEnd(
VECTOR2I( 3000000, 2000000 ) );
3483 board.
Add( pattern );
3484 pattern->AddItem( track );
3488 for(
const char* token :
3489 {
"is_time_domain",
"target_delay",
"target_delay_min",
"target_delay_max",
"last_tuning_length" } )
3491 const wxString value = wxString::FromUTF8(
"(kicad_pcb (generated (" + std::string( token ) +
" 0)))" );
3502 for(
bool stack : {
false,
true } )
3511 const std::string kind = stack ?
"via-stack" :
"via-stitch";
3517 const auto absent = tmp.
Path() / ( kind +
"-" + target.m_id.ToStdString() +
"-absent.kicad_pcb" );
3521 const auto existing = tmp.
Path() / ( kind +
"-" + target.m_id.ToStdString() +
"-existing.kicad_pcb" );
3524 std::ofstream sentinel( existing, std::ios::binary );
3525 sentinel <<
"existing destination";
3540 const std::string src =
3542 wxFileName projectFile( wxString::FromUTF8( src ) );
3543 projectFile.SetExt( wxT(
"kicad_pro" ) );
3554 std::map<KIID, const PCB_TEXT*> sourceNotes;
3559 BOOST_REQUIRE( sourceNotes.emplace( note->m_Uuid, note ).second );
3563 std::map<KIID, const ZONE*> sourceZones;
3564 int placementAreas = 0;
3565 int filledOutlines = 0;
3569 BOOST_REQUIRE( sourceZones.emplace( zone->m_Uuid, zone ).second );
3579 filledOutlines += zone->GetFilledPolysList( layer )->OutlineCount();
3583 BOOST_REQUIRE_GT( filledOutlines, 0 );
3584 const auto memberIds = [](
const PCB_GROUP& aGroup )
3588 for(
const EDA_ITEM* member : aGroup.GetItems() )
3597 for(
int outline = 0; outline < aOriginal.
OutlineCount(); ++outline )
3599 BOOST_CHECK( aExported.COutline( outline ).CompareGeometry( aOriginal.
COutline( outline ) ) );
3602 for(
int hole = 0; hole < aOriginal.
HoleCount( outline ); ++hole )
3603 BOOST_CHECK( aExported.CHole( outline, hole ).CompareGeometry( aOriginal.
CHole( outline, hole ) ) );
3606 const auto serializeNative = [](
BOARD* aBoard )
3613 const std::string sourceModel = serializeNative(
source.get() );
3621 const bool preTen = target.m_boardVersion ==
kicad9.m_boardVersion;
3623 for(
bool drop : {
false,
true } )
3632 const std::string dest =
3634 / ( target.m_id.ToStdString() + ( drop ?
"-drop.kicad_pcb" :
"-lower.kicad_pcb" ) ) )
3637 wxString unsupported;
3651 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
3653 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3657 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3659 for(
const auto& [
id, original] : sourceNotes )
3661 const auto found = std::find_if( exported->Drawings().begin(), exported->Drawings().end(),
3664 return aItem->m_Uuid == id;
3674 for(
const ZONE* zone : exported->Zones() )
3676 const auto found = sourceZones.find( zone->m_Uuid );
3678 const ZONE* original = found->second;
3689 checkPolygons( original->
GetBoardOutline(), zone->GetBoardOutline() );
3694 const auto exportedFill = zone->GetFilledPolysList( layer );
3695 checkPolygons( *originalFill, *exportedFill );
3697 for(
int outline = 0; outline < originalFill->OutlineCount(); ++outline )
3704 BOOST_CHECK( zone->GetPlacementAreaSource().IsEmpty() );
3717 const auto original = std::find_if(
source->Groups().begin(),
source->Groups().end(),
3720 return aGroup->m_Uuid == group->m_Uuid;
3727 std::map<KIID, const PAD*> sourcePads;
3735 for(
const PAD*
pad : exported->GetPads() )
3737 const auto found = sourcePads.find(
pad->m_Uuid );
3739 const PAD* original = found->second;
3762 for(
bool drop : {
false,
true } )
3765 auto footprint =
new FOOTPRINT( &board );
3766 auto zone =
new ZONE( footprint );
3767 zone->SetIsRuleArea(
true );
3768 zone->SetPlacementAreaEnabled(
true );
3770 zone->SetPlacementAreaSource( wxT(
"Repeated group" ) );
3771 zone->SetDoNotAllowTracks(
true );
3772 footprint->Add( zone );
3773 board.
Add( footprint );
3782 == ( target.m_id ==
kicad10.m_id ? wxT(
"Repeated group" ) : wxEmptyString ) );
3791 == wxT(
"placement/group" ) );
3800 for(
bool drop : {
false,
true } )
3803 auto emptyRuleArea =
new ZONE( &board );
3804 emptyRuleArea->SetIsRuleArea(
true );
3806 board.
Add( emptyRuleArea );
3807 auto ordinaryZone =
new ZONE( &board );
3809 ordinaryZone->SetPlacementAreaEnabled(
true );
3810 ordinaryZone->SetPlacementAreaSource( wxT(
"Unused by ordinary copper zones" ) );
3811 board.
Add( ordinaryZone );
3827 explicit FUTURE_GENERATOR(
BOARD* aBoard ) :
3831 wxString
GetGeneratorType()
const override {
return wxT(
"future_generator" ); }
3835 board.
Add(
new FUTURE_GENERATOR( &board ) );
3837 for(
bool drop : {
false,
true } )
3844 for(
bool drop : {
false,
true } )
3849 std::vector<PCB_SHAPE*> shapes;
3850 double expectedArea = 0;
3861 parent->Add( shape );
3862 shapes.push_back( shape );
3866 expectedArea += ink.
Area();
3888 area +=
static_cast<PCB_SHAPE*
>( item )->GetPolyShape().Area();
3891 area +=
static_cast<PCB_SHAPE*
>( item )->GetPolyShape().Area();
3893 BOOST_CHECK_CLOSE( area, expectedArea, 0.05 );
3919 for(
bool footprintOnly : {
false,
true } )
3925 fp->
Value().
SetText( wxT(
"${PROPERTY.Reference}/${REFERENCE}" ) );
3928 escaped->
SetText( wxT(
"\\${PROPERTY.Serial}" ) );
3931 expression->
SetText( wxT(
"@{${PROPERTY.Reference}+1}/${REFERENCE}" ) );
3932 fp->
Add( expression );
3959 for(
bool drop : {
false,
true } )
3967 const wxString projectPath = ( tmp.
Path() /
"source.kicad_pro" ).string();
3970 std::ofstream
project( projectPath.ToStdString() );
3971 project << R
"({"meta":{"version":4},"text_variables":{"SERIAL":"${PROPERTY.Reference}","ALIAS":"${SERIAL}","UNUSED":"${PROPERTY.Missing}"}})";
3979 std::vector<FOOTPRINT*> footprints;
3981 for(
const wxString& serial : { wxT(
"42" ), wxT(
"73" ) } )
3988 footprints.push_back( fp );
3993 BOOST_CHECK_EQUAL( footprints[0]->Value().GetText(), wxString(
"42/${REFERENCE}" ) );
3994 BOOST_CHECK_EQUAL( footprints[1]->Value().GetText(), wxString(
"73/${REFERENCE}" ) );
3996 footprints[0]->Value().SetText( wxT(
"${UNUSED}" ) );
4005 board.
SetProperties( { { wxT(
"SERIAL" ), wxT(
"${PROPERTY.Reference}" ) },
4006 { wxT(
"UNUSED" ), wxT(
"${PROPERTY.Missing}" ) } } );
4009 fp->
Value().
SetText( wxT(
"${SERIAL}/${REFERENCE}" ) );
4023 fp->
SetKeywords( wxT(
"\\${REFERENCE}/\\@{1+2}" ) );
4024 fp->
Value().
SetText( wxT(
"${PROPERTY.Reference}/\\${U1:PROPERTY.Missing}/${REFERENCE}" ) );
4026 text->SetText( wxT(
"${PROPERTY.Keywords}/${REFERENCE}" ) );
4043 fp->
Value().
SetText( wxT(
"@{1000mils}/${REFERENCE}" ) );
4053 for(
const wxString& raw :
4054 { wxT(
"@{${PROPERTY.Reference}+${MISSING}}" ), wxT(
"@{unknown_function(${PROPERTY.Reference})}" ) } )
4063 for(
bool drop : {
false,
true } )
4071 for(
bool inProperty : {
false,
true } )
4076 const wxString literal = wxT(
"\\${REFERENCE}/\\@{1+2}" );
4078 fp->
Value().
SetText( inProperty ? wxString( wxT(
"${PROPERTY.Keywords}" ) ) : literal );
4082 for(
bool drop : {
false,
true } )
4096 for(
bool drop : {
false,
true } )
4119 for(
bool drop : {
false,
true } )
4127 const wxString projectPath = ( temporary.
Path() /
"source.kicad_pro" ).string();
4130 std::ofstream
project( projectPath.ToStdString() );
4131 project << R
"({"meta":{"version":4},"text_variables":{"TITLE":"${PROPERTY.Reference}"}})";
4145 for(
bool drop : {
false,
true } )
4162 table->SetColCount( 1 );
4163 table->SetColWidth( 0, 10000000 );
4164 table->SetRowHeight( 0, 6000000 );
4166 cell->
SetText( wxT(
"@{${PROPERTY.Reference}+${ROW}}/${COL}/${REFERENCE}" ) );
4167 table->AddCell( cell );
4179 const wxString
source = ( temporary.
Path() /
"source.kicad_mod" ).string();
4182 footprint.
Value().
SetText( wxT(
"${PROPERTY.Reference}/${REFERENCE}" ) );
4191 footprint.
Add( line );
4194 footprint.
Add( constraint );
4200 for(
bool drop : {
false,
true } )
4202 const wxString destination = ( temporary.
Path() /
"out.kicad_mod" ).string();
4211 BOOST_CHECK_EQUAL( converted->Value().GetText(), wxString(
"42/${REFERENCE}" ) );
4214 for(
BOARD_ITEM* item : converted->GraphicalItems() )
4228 for(
bool drop : {
false,
true } )
4253 std::vector<EDA_TEXT*> bold;
4255 text->SetText( wxT(
"board bold" ) );
4257 bold.push_back(
text );
4259 bold.push_back( &fp->
Value() );
4261 fpText->
SetText( wxT(
"graphic bold" ) );
4263 bold.push_back( fpText );
4265 table->SetColCount( 1 );
4266 table->SetColWidth( 0, 10000000 );
4267 table->SetRowHeight( 0, 5000000 );
4269 cell->
SetText( wxT(
"cell bold" ) );
4270 table->AddCell( cell );
4272 bold.push_back( cell );
4278 board.
Add( dimension );
4279 bold.push_back( dimension );
4283 item->SetBold(
true );
4284 item->SetTextThickness( 100000 );
4288 automatic->
SetText( wxT(
"auto bold" ) );
4291 board.
Add( automatic );
4293 outline->
SetText( wxT(
"outline bold" ) );
4297 board.
Add( outline );
4303 const std::string first = ( temporary.
Path() / ( target.m_id.ToStdString() +
"-first.kicad_pcb" ) ).string();
4304 const std::string second = ( temporary.
Path() / ( target.m_id.ToStdString() +
"-second.kicad_pcb" ) ).string();
4308 BOOST_CHECK( content.find(
"(thickness 0.16)" ) != std::string::npos );
4320 reloaded->RunOnChildren(
4325 if( !reloadedText || !reloadedText->
IsBold() )
4328 if( reloadedText->
GetText() == wxT(
"auto bold" ) )
4330 else if( reloadedText->
GetText() != wxT(
"outline bold" ) || outlineAvailable )
4365 const std::string
path = ( temporary.
Path() /
"out.kicad_pcb" ).string();
4369 BOOST_REQUIRE( reloaded && reloaded->Footprints().size() == 1 );
4371 const PAD*
result = reloaded->Footprints()[0]->Pads()[0];
4382 const nlohmann::json exclusion = { {
"marker",
4383 { {
"error_type",
"DRCET_CLEARANCE" },
4384 {
"position", { {
"x_nm",
"123" }, {
"y_nm",
"-456" } } },
4386 { { {
"value",
"11111111-1111-1111-1111-111111111111" } },
4387 { {
"value",
"22222222-2222-2222-2222-222222222222" } } } } } },
4388 {
"comment",
"accepted" } };
4392 nlohmann::json doc = {
4393 {
"meta", { {
"version", 4 } } },
4395 { {
"design_settings", { {
"meta", { {
"version", 3 } } }, {
"drc_exclusions", { exclusion } } } } } }
4400 const auto& settings = doc[
"board"][
"design_settings"];
4404 settings[
"drc_exclusions"][0][0].get<std::string>(),
4405 "clearance|123|-456|11111111-1111-1111-1111-111111111111|22222222-2222-2222-2222-222222222222" );
4406 BOOST_CHECK_EQUAL( settings[
"drc_exclusions"][0][1].get<std::string>(),
"accepted" );
4408 const auto migrated = doc;
4420 const nlohmann::json exclusion = { {
"marker",
4421 { {
"error_type",
"DRCET_LINE_WIDTH" },
4422 {
"position", { {
"x_nm",
"1" }, {
"y_nm",
"2" } } },
4423 {
"items", { { {
"value",
"11111111-1111-1111-1111-111111111111" } } } } } } };
4427 nlohmann::json doc = {
4428 {
"meta", { {
"version", 4 } } },
4430 { {
"design_settings",
4431 { {
"meta", { {
"version", 4 } } },
4432 {
"rule_severities", { {
"line_width",
"ignore" } } },
4433 {
"rules", { {
"min_silk_line_width", 0.2 } } },
4434 {
"drc_exclusions", { exclusion } } } } } }
4439 const auto& settings = doc[
"board"][
"design_settings"];
4441 BOOST_CHECK_EQUAL( settings[
"rule_severities"].value(
"text_thickness",
"" ),
"ignore" );
4442 BOOST_CHECK( !settings[
"rule_severities"].contains(
"line_width" ) );
4444 BOOST_CHECK( !settings[
"rules"].contains(
"min_silk_line_width" ) );
4446 BOOST_CHECK( settings[
"drc_exclusions"][0][0].get<std::string>().starts_with(
"text_thickness|1|2|" ) );
4453 nlohmann::json multiple = { {
"marker",
4454 { {
"error_type",
"DRCET_CLEARANCE" },
4455 {
"position", { {
"x_nm",
"123" }, {
"y_nm",
"-456" } } },
4457 { { {
"value",
"11111111-1111-1111-1111-111111111111" } },
4458 { {
"value",
"22222222-2222-2222-2222-222222222222" } },
4459 { {
"value",
"33333333-3333-3333-3333-333333333333" } } } } } },
4460 {
"comment",
"three items" } };
4461 nlohmann::json
unknown = multiple;
4462 unknown[
"marker"][
"error_type"] =
"DRCET_MICROVIA_STACK_DEPTH";
4463 unknown[
"marker"][
"items"].erase( 2 );
4467 nlohmann::json doc = {
4469 { {
"design_settings",
4470 { {
"meta", { {
"version", 3 } } }, {
"drc_exclusions", { multiple,
unknown,
"malformed" } } } } } }
4485 doc[
"net_settings"][
"net_chain_netclasses"] = { { {
"name",
"fast" } } };
4486 doc[
"board"][
"design_settings"][
"via_stack_presets"] = { { {
"name",
"fanout" } } };
4487 doc[
"board"][
"design_settings"][
"teardrop_parameters"] = {
4488 { {
"td_target_name",
"td_track_end" }, {
"td_enabled",
true }, {
"td_max_len", 1.0 } },
4489 { {
"td_enabled",
false } }
4493 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_netclasses" ) );
4494 const auto& settings = doc[
"board"][
"design_settings"];
4495 BOOST_CHECK( !settings.contains(
"via_stack_presets" ) );
4496 BOOST_CHECK( !settings[
"teardrop_parameters"][0].contains(
"td_enabled" ) );
4497 BOOST_CHECK( !settings[
"teardrop_parameters"][1].contains(
"td_enabled" ) );
4498 BOOST_CHECK_EQUAL( settings[
"teardrop_parameters"][0][
"td_max_len"].get<double>(), 1.0 );
4504 nlohmann::json defaults;
4505 defaults[
"net_settings"][
"net_chain_netclasses"] = nlohmann::json::array();
4506 defaults[
"board"][
"design_settings"][
"via_stack_presets"] = nlohmann::json::array();
4507 defaults[
"board"][
"design_settings"][
"teardrop_parameters"] = { { {
"td_enabled",
false } } };
4517 nlohmann::json doc = {
4518 {
"tuning_profiles",
4519 { {
"meta", { {
"version", 2 } } },
4520 {
"tuning_profiles_impedance_geometric",
4521 { { {
"net_chain_bridge_prop_delay", 25 } }, { {
"net_chain_bridge_prop_delay", 0 } } } } } }
4528 for(
const auto& profile : doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"] )
4529 BOOST_CHECK( !profile.contains(
"net_chain_bridge_prop_delay" ) );
4538 doc[
"net_settings"][
"net_chain_classes"] = { {
"clock",
"Fast" } };
4541 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
4546 doc[
"net_settings"][
"net_chain_classes"] = nlohmann::json::object();
4565 const wxString
name = wxString::FromUTF8( vocabulary->
m_functions[i] );
4568 [&](
const char* aBreak )
4570 return name == aBreak;
4574 const wxString rule = wxT(
"(version 1)(rule \"f\" (condition \"A." ) +
name
4575 + wxT(
"('x')\") (constraint clearance (min 0.2mm)))" );
4578 target.m_id +
" dropped a rule calling " +
name );
4584 const wxString rule = wxT(
"(version 1)(rule \"p\" (condition \"A." ) +
name
4585 + wxT(
" == 1\") (constraint clearance (min 0.2mm)))" );
4588 target.m_id +
" dropped a rule reading " +
name );
4600 target.m_name +
" has no entry in include/drc_rules_release_vocabulary.h" );
4611 for(
const wxString& property : { wxT(
"A.Priority > 1" ), wxT(
"A.Hatch_Orientation == 0" ),
4612 wxT(
"A.Line_Color == 'red'" ) } )
4615 + wxT(
"\") (constraint clearance (min 0.2mm)))" ),
4617 BOOST_CHECK_MESSAGE(
result.m_dropped.size() == 1, target.m_id +
" kept " + property );
4620 const auto kept =
FilterDrcRulesForTarget( wxT(
"(version 1)(rule \"enum\" (condition \"A.Pad_Type == 'PTH'\") "
4621 "(constraint clearance (min 0.2mm)))" ),
4634 wxT(
"(version 1)(rule \"spaced\" (constraint clearance (min 0.2 mm) (opt 0.3 mil) (max 1 in)))" ),
4636 BOOST_CHECK_MESSAGE( kept.m_dropped.empty(), target.m_id +
" dropped a rule with a spaced unit" );
4640 wxT(
"(version 1)(rule \"delay\" (constraint skew (max 5 ps)))" ), target );
4641 BOOST_CHECK_EQUAL( dropped.m_dropped.size(), target.m_id == wxT(
"9.0" ) ? 1 : 0 );
4651 const bool old = target.m_id == wxT(
"9.0" );
4654 wxT(
"(version 1)(rule \"a\" (constraint track_angle (max 45deg)))" ), target );
4660 for(
const wxString& rule : { wxT(
"(rule \"v\" (constraint clearance (min ${GAP})))" ),
4661 wxT(
"(rule \"c\" (condition \"A.NetName == '${NET}'\") "
4662 "(constraint clearance (min 0.2mm)))" ) } )
4673 for(
const wxString& expression : { wxT(
"A.hasExactNetclass('x')" ), wxT(
"A.Column_Width == 1" ),
4674 wxT(
"A.Visible == 1" ) } )
4676 const wxString rule = wxT(
"(version 1)(rule \"r\" (condition \"" ) + expression
4677 + wxT(
"\") (constraint clearance (min 0.2mm)))" );
4679 "9.0 kept " + expression +
" which not every 9.0.x release reads" );
4682 for(
const wxString& expression : { wxT(
"A.intersectsKeepout('x')" ), wxT(
"A.Origin_X == 1" ) } )
4684 const wxString rule = wxT(
"(version 1)(rule \"r\" (condition \"" ) + expression
4685 + wxT(
"\") (constraint clearance (min 0.2mm)))" );
4687 "10.0 kept " + expression +
" which not every 10.0.x release reads" );
4697 for(
const wxString& layer : { wxT(
"MyCustomLayer" ), wxT(
"F.Cu" ), wxT(
"\"In1.Cu\"" ), wxT(
"outer" ) } )
4700 + wxT(
") (constraint clearance (min 0.2mm)))" ),
4702 BOOST_CHECK_MESSAGE(
result.m_dropped.empty(), target.m_id +
" dropped a rule on layer " + layer );
4712 unknown.m_name = wxT(
"KiCad 0.0" );
4726 for(
const wxString& keyword : { wxT(
"hole_aspect_ratio" ), wxT(
"microvia_stack_depth" ) } )
4728 const wxString rule =
"(version 1)(rule \"new\" (constraint " + keyword +
" (max 2)))";
4734 for(
const wxString& call :
4735 { wxT(
"A.intersectsKeepout('x')" ), wxT(
"A.intersectsArea('x')" ), wxT(
"A.isStackedVia()" ),
4736 wxT(
"A.ISSTACKEDVIA()" ), wxT(
"A.customProperty('Owner') == 'Team'" ),
4737 wxT(
"A.hasCustomProperty('Owner')" ) } )
4739 for(
const wxString& expression : { wxT(
"condition" ), wxT(
"assertion" ) } )
4741 const wxString rule =
4742 expression == wxT(
"condition" )
4743 ?
"(rule \"new\" (condition \"" + call +
"\") (constraint clearance (min 0.2mm)))"
4744 :
"(rule \"new\" (constraint assertion \"" + call +
"\"))";
4751 const wxString kept = wxT(
"(rule \"customProperty\" (condition \"A.NetName == 'isStackedVia()'\") "
4752 "(constraint clearance (min 0.2mm)))\n"
4753 "(rule \"literal\" (condition \"A.NetName == 'intersectsArea()'\") "
4754 "(constraint clearance (min 0.2mm)))\n"
4755 "(rule \"uppercase literal\" (condition \"A.NetName == 'ISSTACKEDVIA()'\") "
4756 "(constraint clearance (min 0.2mm)))\n"
4757 "(rule \"legacy\" (condition \"A.insideArea('x')\") "
4758 "(constraint clearance (min 0.2mm)))\n"
4759 "(rule \"position\" (condition \"A.Start_X > 1mm && A.Start_Y > 1mm\") "
4760 "(constraint clearance (min 0.2mm)))" );
4773 for(
const wxString& kind : { wxT(
"condition" ), wxT(
"assertion" ) } )
4775 const wxString expression = wxT(
"A.Parent == A.Parent && A.NetName != 'A.parent.Reference'" );
4776 const wxString body =
4777 kind == wxT(
"condition" )
4778 ? wxT(
"(condition \"" ) + expression + wxT(
"\") (constraint clearance (min 0.2mm))" )
4779 : wxT(
"(constraint assertion \"" ) + expression + wxT(
"\")" );
4786 for(
const wxString& property :
4787 { wxT(
"A.Start_Shape" ), wxT(
"A.start_shape" ), wxT(
"B.End_Width" ), wxT(
"AB.Scale_X" ),
4788 wxT(
"A.parent.Reference" ), wxT(
"A . PARENT . Reference" ), wxT(
"A.Major_Radius" ),
4789 wxT(
"A.Exclude_From_Simulation" ), wxT(
"A.Automatically_Update_Net" ), wxT(
"A.Grid_Type" ) } )
4791 for(
const wxString& kind : { wxT(
"condition" ), wxT(
"assertion" ) } )
4793 const wxString expression =
4794 property + (
property.Contains( wxT(
"Reference" ) ) ? wxT(
" == 'U1'" ) : wxT(
" == 1" ) );
4795 const wxString body =
4796 kind == wxT(
"condition" )
4797 ? wxT(
"(condition \"" ) + expression + wxT(
"\") (constraint clearance (min 0.2mm))" )
4798 : wxT(
"(constraint assertion \"" ) + expression + wxT(
"\")" );
4806 for(
const wxString& property :
4807 { wxT(
"A.Corner_Radius" ), wxT(
"A.Auto_Thickness" ), wxT(
"A.Target_Delay" ) } )
4809 for(
const wxString& kind : { wxT(
"condition" ), wxT(
"assertion" ) } )
4811 const wxString expression =
property + wxT(
" == 1" );
4812 const wxString body =
4813 kind == wxT(
"condition" )
4814 ? wxT(
"(condition \"" ) + expression + wxT(
"\") (constraint clearance (min 0.2mm))" )
4815 : wxT(
"(constraint assertion \"" ) + expression + wxT(
"\")" );
4823 const wxString kept = wxT(
"(rule \"literal\" (condition \"A.NetName == 'A.Start_Shape' && A.Start_X > 1mm "
4824 "&& A.End_Y > 1mm && A.Radius > 1mm\") (constraint clearance (min 0.2mm)))" );
constexpr EDA_IU_SCALE pcbIUScale
COMPATIBILITY_REPORT ClassifyBoardForDowngrade(const BOARD *aBoard, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Report what a board would lose if exported to an older KiCad.
void SaveFootprintForTarget(FOOTPRINT *aFootprint, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a single .kicad_mod footprint file for the target.
int BoardDowngradeCoveredVersion()
The format the denylist was generated against. A format bump forces a review.
void SaveBoardForTarget(BOARD *aBoard, const wxString &aPath, const DOWNGRADE_TARGET &aTarget)
Save a board stamped for the target, using the writer for that version.
void FlattenBoardVariant(BOARD *aBoard, const wxString &aVariantName)
Bake a variant's overrides into the base footprint attributes.
int FootprintLibDowngradeCoveredVersion()
The footprint library format the rules were reviewed against. Moves independently of the board.
bool ExportBoardToOlderVersion(const wxString &aSrcFile, const wxString &aDestFile, const DOWNGRADE_TARGET &aTarget, COMPATIBILITY_REPORT &aReport, wxString *aUnsupportedToken, const wxString &aVariant, bool aDropInsteadOfApproximate)
Load a board, downgrade the copy, and write it stamped for the target.
DOWNGRADE_FILE_RESULT DowngradeFootprintFileToTemp(const wxString &aSrcFile, const wxString &aTmpFile, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Load one .kicad_mod, classify it against the rule table, and write the downgraded copy to aTmpFile.
void DowngradeBoardInPlace(BOARD *aBoard, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Approximate or remove, in place, what the target cannot represent.
void DowngradeFootprintInPlace(FOOTPRINT *aFootprint, const DOWNGRADE_TARGET &aTarget, bool aDropInsteadOfApproximate)
Footprint-scoped downgrade for standalone .kicad_mod files the board pass never sees.
wxString FindUnsupportedBoardToken(const wxString &aSerialized, const DOWNGRADE_TARGET &aTarget)
Scan serialized board text for tokens the target cannot parse.
General utilities for PCB file IO for QA programs.
@ BS_ITEM_TYPE_DIELECTRIC
int GetLegacyPPI() const
Recompute the PPI the way it was computed before the pixels/cm truncation fix.
wxString GetNetname() const
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
std::map< PCB_LAYER_ID, ZONE_LAYER_PROPERTIES > m_ZoneLayerProperties
DRILL_SYMBOL_PROFILE & GetDrillSymbolProfile()
BOARD_STACKUP & GetStackupDescriptor()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)=0
Adds an item to the container.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual bool IsKnockout() const
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void SetIsKnockout(bool aKnockout)
Manage one layer needed to make a physical board.
DIELECTRIC_MODEL GetDielectricModel(int aDielectricSubLayer=0) const
void SetDielectricModel(DIELECTRIC_MODEL aModel, int aDielectricSubLayer=0)
void Add(BOARD_STACKUP_ITEM *aItem)
Add a new item in stackup layer.
Information pertinent to a Pcbnew printed circuit board.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
const GENERATORS & Generators() const
void SetProperties(const std::map< wxString, wxString > &aProps)
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
TITLE_BLOCK & GetTitleBlock()
const TRACKS & Tracks() const
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
void SetCopperLayerCount(int aCount)
void SetProject(PROJECT *aProject, bool aReferenceOnly=false)
Link a board to a given project.
wxString GroupsSanityCheck(bool repair=false)
Consistency check of internal m_groups structure.
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
BOARD_DESIGN_SETTINGS & GetDesignSettings()
const DRAWINGS & Drawings() const
What an export to a given target will keep, approximate, drop, or block.
bool IsLossy() const
True if anything is approximated or dropped. This is what triggers the lossy warning.
bool IsBlocked() const
True if some feature makes the target impossible. The user cannot export anyway.
int Count(DOWNGRADE_BUCKET aBucket) const
const std::vector< COMPAT_ENTRY > & Entries() const
Stage related design and library files together, retaining originals until every write is ready.
const wxString & GetRecoveryError() const
Recovery details are nonempty only if restoring an original or removing a new output failed.
wxString Commit()
Replace all destinations, rolling back earlier replacements if a rename fails.
wxString Stage(const wxString &aDestination)
Return an exclusively-created sibling staging file, or empty if it cannot be created.
void Discard(const wxString &aTemporary)
Forget a skipped conversion without exposing its empty staging file as an output.
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
Grouping rules and symbol assignments, shared by reference so a chart and its map can never disagree ...
void SetName(const wxString &aName)
A set of EDA_ITEMs (i.e., without duplicates).
std::unordered_set< EDA_ITEM * > & GetItems()
void AddItem(EDA_ITEM *aItem)
Add item to group.
void SetName(const wxString &aName)
A base class for most all the KiCad significant classes used in schematics and boards.
virtual EDA_GROUP * GetParentGroup() const
KICAD_T Type() const
Returns the type of object.
bool HasCustomProperties() const
void SetCustomProperty(const wxString &aKey, const wxString &aValue)
void SetEndEnding(const LINE_ENDING &aEnding)
FILL_T GetFillMode() const
void TransformWithLineEndingsToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the shape body shortened for line endings plus line-ending geometry to polygons.
void SetLineStyle(const LINE_STYLE aStyle)
SHAPE_POLY_SET & GetPolyShape()
void SetEndEndingStyle(LINE_ENDING_STYLE aStyle)
LINE_STYLE GetLineStyle() const
LINE_ENDING_STYLE GetEndEndingStyle() const
void SetFillMode(FILL_T aFill)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
virtual const wxString & GetText() const
Return the string associated with the text object.
KIFONT::FONT * GetFont() const
void SetBold(bool aBold)
Set the text to be bold - this will also update the font if needed.
virtual int GetTextThickness() const
virtual void SetText(const wxString &aText)
void SetFont(KIFONT::FONT *aFont)
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
virtual bool IsOutline() const
wxString AsString() const
std::string AsStdString() const
const std::filesystem::path & Path() const
Get the path to the temporary directory as a std::filesystem::path.
A logical library item identifier and consists of various portions much like a URI.
Decorative shape (arrowhead, circle, square) at the start or end of a graphic line,...
LSET is a set of PCB_LAYER_IDs.
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.
Handle the data for a net.
void SetParent(BOARD *aParent)
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
MASK_LAYER_PROPS & FrontOuterLayers()
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
@ CUSTOM
Shapes can be defined on arbitrary layers.
MASK_LAYER_PROPS & BackOuterLayers()
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
VECTOR2I GetPosition() const override
double GetRoundRectRadiusRatio(PCB_LAYER_ID aLayer) const
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
const VECTOR2I & GetMid() const
wxString GetShownText(RESOLUTION_CONTEXT aContext) const
void SetShowText(bool aShow)
void SetBarcodeText(const wxString &aText)
void SetWidth(int aWidth)
void SetBarcodeKind(BARCODE_T aKind)
void SetHeight(int aHeight)
void SetLayer(PCB_LAYER_ID aLayer) override
Set the drawing layer for the barcode and its text.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the barcode (text + symbol shapes) to polygonal geometry suitable for filling/collision tests...
A geometric constraint between board items (issue #2329).
void AddMember(const KIID &aItem, CONSTRAINT_ANCHOR aAnchor=CONSTRAINT_ANCHOR::WHOLE, int aIndex=-1)
virtual void SetEnd(const VECTOR2I &aPoint)
virtual void SetStart(const VECTOR2I &aPoint)
void ChangeOverrideText(const wxString &aValue)
For better understanding of the points that make a dimension:
void SetHeight(int aHeight)
Set the distance from the feature points to the crossbar line.
A drill chart placed on the board, kept in step with the holes.
Turns on drill symbols at the holes, for one layer.
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void RebuildCells(const BOARD &aBoard, GENERATED_TABLE_REFRESH *aRefresh=nullptr)
Regenerate the cells from the board.
PCB_GENERATOR * DeepClone() const
A set of BOARD_ITEMs (i.e., without duplicates).
A PCB_IO derivation for saving and loading Pcbnew s-expression formatted files.
std::unique_ptr< 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 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 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 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::unique_ptr< BOARD > LoadBoard(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PCB_IO implementation knows about into new BOA...
Object to handle a bitmap image that can be inserted in a PCB.
REFERENCE_IMAGE & GetReferenceImage()
void SetEllipseCenter(const VECTOR2I &aPt) override
void SetCornerRadius(int aCornerRadius) override
void SetWidth(int aWidth) override
void SetEllipseStartAngle(const EDA_ANGLE &aA) override
void SetEllipseEndAngle(const EDA_ANGLE &aA) override
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetEllipseMinorRadius(int aR) override
void SetStart(const VECTOR2I &aStart) override
void SetEllipseMajorRadius(int aR) override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
A board stackup table placed on the board, kept in step with the stackup.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
PCB_TABLECELL * GetCell(int aRow, int aCol) const
void AddCell(PCB_TABLECELL *aCell)
void SetColCount(int aCount)
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
VECTOR2I GetPosition() const override
int GetTextThickness() const override
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
const VECTOR2I & GetStart() const
const VECTOR2I & GetEnd() const
virtual int GetWidth() const
const STRING_ANY_MAP GetProperties() const override
PCB_TUNING_PATTERN(BOARD_ITEM *aParent=nullptr, PCB_LAYER_ID aLayer=F_Cu, LENGTH_TUNING_MODE aMode=LENGTH_TUNING_MODE::SINGLE)
PNS::MEANDER_SETTINGS & GetSettings()
A microvia stack: several single hop microvias, plus connecting traces for staggered stacks,...
VIA_STACK_STYLE GetStyle() const
PCB_LAYER_ID GetStartLayer() const
PCB_LAYER_ID GetEndLayer() const
wxString GetGeneratorType() const override
PCB_VIA_STITCH(BOARD_ITEM *aParent=nullptr)
int GetGuardedNetCode() const
Net being guarded in GUARD mode.
const PADSTACK & Padstack() const
void SetViaType(VIATYPE aViaType)
VIATYPE GetViaType() const
bool m_isTimeDomain
Calculate tuning in the time domain.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
const BITMAP_BASE & GetImage() const
Get the underlying image.
double GetImageScale() const
void SetImageScale(double aScale)
Set the image "zoom" value.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true, bool aOverrideLock=false)
Load a project or sets up a new project with a specified path.
double Area(bool aAbsolute=true) const
Return the area of this chain.
Represent a set of closed polygons.
double Area()
Return the area of this poly set.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
A name/value tuple with unique names and wxAny values.
bool get_to(const std::string &aKey, T &aVar) const
void set(const std::string &aKey, const T &aVar)
void SetComment(int aIdx, const wxString &aComment)
void SetTitle(const wxString &aTitle)
const wxString & GetTitle() const
A wrapper for reporting to a wxString object.
Handle a list of polygons defining a copper zone.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
bool GetDoNotAllowVias() const
bool AppendCorner(const VECTOR2I &aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
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
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
SHAPE_POLY_SET * Outline()
bool IsIsland(PCB_LAYER_ID aLayer, int aPolyIdx) const
Check if a given filled polygon is an insulated island.
bool IsCopperThieving() const
const wxString & GetZoneName() const
SHAPE_POLY_SET GetBoardOutline() const
void SetFillMode(ZONE_FILL_MODE aFillMode)
void SetLayerSet(const LSET &aLayerSet) override
bool GetPlacementAreaEnabled() const
bool GetDoNotAllowFootprints() const
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
bool GetDoNotAllowZoneFills() const
DOWNGRADE_BUCKET
What happens to a feature when we export to an older KiCad.
@ BLOCK
Cannot be represented at all, export to this target is not possible.
@ LOWER
Approximated down to a simpler equivalent.
@ DROP
No equivalent, left out.
static bool empty(const wxTextEntryBase *aCtrl)
wxString DowngradeLibraryFilesInPlace(const wxString &aDir, const wxString &aGlob, int aStampVersion, const std::function< wxString(const wxString &)> &aFindForbidden, const std::function< DOWNGRADE_FILE_RESULT(const wxString &, const wxString &)> &aConvert, DOWNGRADE_FILE_TRANSACTION *aTransaction=nullptr, wxString *aRecoveryError=nullptr)
Downgrade every library file matching aGlob under aDir in place.
bool IsDowngradeDesignFile(const wxString &aPath)
Files the project export carries over.
DOWNGRADE_FILE_RESULT
What a per-file converter did with one library file.
@ REFUSED
The target cannot represent this file.
@ CONVERTED
The temp file holds the downgraded copy.
const std::vector< DOWNGRADE_TARGET > & GetDowngradeTargets()
Supported downgrade targets, newest first.
constexpr const char * DRC_RULE_SEMANTIC_BREAKS[]
A function a release parses but answers differently, which the vocabulary cannot say.
const DRC_RULE_VOCABULARY * FindDrcRuleVocabulary(const DOWNGRADE_TARGET &aTarget)
The vocabulary a target release could parse, generated from its release tags by tools/generate_drc_ru...
DRC_RULES_FILTER_RESULT FilterDrcRulesForTarget(const wxString &aRulesText, const DOWNGRADE_TARGET &aTarget)
Filter a .kicad_dru file for the target.
static constexpr EDA_ANGLE ANGLE_0
static constexpr EDA_ANGLE ANGLE_90
static constexpr EDA_ANGLE ANGLE_360
@ FILLED_SHAPE
Fill with object color.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
PCB_LAYER_ID
A quick note on layer IDs:
Test utilities for timestamps.
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::string ReadGoldenText(const std::string &aPath)
wxMemoryBuffer MakePngWithFractionalPixelsPerCm()
A tiny PNG whose embedded resolution gives a fractional pixels/cm, so the legacy truncating PPI diffe...
void DumpBoardToFile(BOARD &board, const std::filesystem::path &aFilename)
Utility function to simply write a Board out to a file.
double SerializedImageScale(const std::string &aContent, const std::string &aUuid)
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
@ PTH
Plated through hole pad.
@ PRESSFIT
a PTH with a hole diameter with tight tolerances for press fit pin
@ NONE
no special fabrication property
@ REMOVE_EXCEPT_START_AND_END
BARCODE class definition.
@ HORIZONTAL
A segment (or two points) is horizontal.
Class to handle a set of BOARD_ITEMs.
#define SEXPR_FOOTPRINT_LIB_FILE_VERSION
#define SEXPR_BOARD_FILE_VERSION
Current s-expression file format version. 2 was the last legacy format version.
@ STITCH
Fill the outline with vias with a pattern.
@ GUARD
Place vias to guard a net contained within.
void DowngradeProjectFileJson(nlohmann::json &aDoc, const DOWNGRADE_TARGET &aTarget, COMPATIBILITY_REPORT &aReport)
Migrate a .kicad_pro document down to what the target release expects.
One line in the compatibility report.
An older KiCad release we can export a project back to.
wxString m_text
The filtered rules file text.
wxString m_error
Invalid source syntax, do not write m_text.
std::vector< wxString > m_dropped
Names of the rules the target cannot parse.
Everything a rules file could name in one release.
const char *const * m_properties
const char *const * m_functions
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_plugging
True if the drill hole should be plugged on this side.
std::optional< VECTOR2I > hatching_offset
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(EmptyBoardIsClean)
static size_t ParsedDrcRuleCount(const wxString &aText, const wxString &aSource)
static void checkFeature(const COMPATIBILITY_REPORT &aReport, const wxString &aName, DOWNGRADE_BUCKET aBucket, int aCount)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
VECTOR3I expected(15, 30, 45)
static const DOWNGRADE_TARGET & kicad10
static const DOWNGRADE_TARGET & kicad9
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
Class ZONE_SETTINGS used to handle zones parameters in dialogs.