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" ) ) );
1205 std::vector<std::shared_ptr<DRC_RULE>> rules;
1208 return rules.size();
1214 const wxString rules = wxT(
"(version 2)\n"
1215 "(rule \"keep\" (constraint clearance (min 0.2mm)))\n"
1216 "# why the chain rule exists\n"
1218 " (constraint net_chain_length (max 10mm)))\n"
1219 "(rule \"glued\" (constraint net_chain_length (max 1mm)))"
1220 "(rule \"after\" (constraint clearance (min 0.1mm)))\n" );
1228 const wxString marker = wxT(
"# Not supported by " ) + target.m_name + wxT(
":\n" );
1229 const wxString
expected = wxT(
"(version 1)\n"
1230 "(rule \"keep\" (constraint clearance (min 0.2mm)))\n"
1231 "# why the chain rule exists\n" )
1233 + wxT(
"# (rule \"chain\"\n"
1234 "# (constraint net_chain_length (max 10mm)))\n" )
1236 + wxT(
"# (rule \"glued\" (constraint net_chain_length (max 1mm)))\n"
1237 "(rule \"after\" (constraint clearance (min 0.1mm)))\n" );
1246 const wxString rules = wxT(
"(version 2)"
1247 "(rule \"first\" (constraint net_chain_length (max 1mm)))"
1248 "(rule \"kept\" (constraint clearance (min 0.2mm)))"
1249 "(rule \"last\" (constraint net_chain_length (max 1mm)))" );
1256 const wxString marker = wxT(
"# Not supported by " ) + target.m_name + wxT(
":\n" );
1257 const wxString
expected = wxT(
"(version 1)\n" ) + marker
1258 + wxT(
"# (rule \"first\" (constraint net_chain_length (max 1mm)))\n"
1259 "(rule \"kept\" (constraint clearance (min 0.2mm)))\n" )
1260 + marker + wxT(
"# (rule \"last\" (constraint net_chain_length (max 1mm)))\n" );
1269 const wxString rules = wxT(
"(version 2)\r\n"
1270 " (rule \"messy\"\r\n"
1271 " # ) \" ( unmatched in a comment\r\n"
1272 " (condition \"A.NetName == 'a'\")\r\n"
1273 " (constraint net_chain_length (max 1mm)))\r\n"
1274 "(rule \"kept\" (constraint clearance (min 0.2mm)))\r\n" );
1283 const wxString
expected = wxT(
"(version 1)\r\n # Not supported by " ) + target.m_name
1285 "# (rule \"messy\"\r\n"
1286 "# # ) \" ( unmatched in a comment\r\n"
1287 "# (condition \"A.NetName == 'a'\")\r\n"
1288 "# (constraint net_chain_length (max 1mm)))\r\n"
1289 "(rule \"kept\" (constraint clearance (min 0.2mm)))\r\n" );
1298 const wxString rules = wxT(
"(version 2)\n"
1299 "(future_block \"x\" (constraint clearance (min 1mm)))\n"
1300 "(rule \"kept\" (constraint clearance (min 0.2mm)))\n" );
1307 BOOST_CHECK(
result.m_text.Contains( wxT(
"# (future_block \"x\" (constraint clearance (min 1mm)))\n"
1308 "(rule \"kept\"" ) ) );
1316 const wxString rules = wxT(
"(version 2)\n"
1317 "# why the chain rule exists\n"
1320 " (constraint net_chain_length (max 10mm)))\n"
1321 "(rule \"after\" (constraint clearance (min 0.1mm)))"
1322 "(rule \"last\" (constraint net_chain_length (max 1mm)))\n"
1323 "# trailing note\n" );
1330 BOOST_CHECK( first.
m_text.EndsWith( wxT(
"# (rule \"last\" (constraint net_chain_length (max 1mm)))\n"
1331 "# trailing note\n" ) ) );
1343 const wxString rules = wxT(
"(version 1)\n"
1344 "(rule \"return_path\" (constraint clearance (min 0.2mm)))\n"
1345 "(rule inNetChain (constraint clearance (min 0.2mm)))\n"
1346 "(rule \"literal\" (condition \"A.NetName == 'hasNetChain() 100 ps .Parent.'\")\n"
1347 " (constraint clearance (min 0.2mm)))\n" );
1361 const wxString rules = wxT(
"(version 1)\n"
1362 "(rule \"time\" (constraint length (min \"100 ps\")))\n"
1363 "(rule \"femtoseconds\" (constraint length (max \"2 * 100 fs\")))\n"
1364 "(rule \"angle\" (constraint track_angle (max \"90 deg\")))\n"
1365 "(rule \"ordinary\" (constraint clearance (min \"0.2 mm\")))\n" );
1382 const wxString rules = wxT(
"(version 2)\n"
1383 "(rule \"mask_check\" (constraint bridged_mask))\n"
1384 "(rule \"delay_check\" (constraint skew (max 5ps)))\n"
1385 "(rule \"chain_check\" (constraint net_chain_length (max 10mm)))\n" );
1400 const wxString kept = wxT(
"(rule \"clearance # literal\"\n"
1401 " # unmatched: ) (( \" \\\n"
1402 " (condition \"A.NetName == 'SIGNAL#1'\")\n"
1403 " # inNetChain('x')\n"
1404 " (constraint clearance (min 0.2mm))\n"
1407 "(rule \"second\" (constraint track_width (min 0.25mm)))" );
1408 const wxString input = wxT(
"(version 2)\n" ) + kept
1409 + wxT(
"\n(rule \"unsupported\"\n # ) \" (\n"
1410 " (constraint net_chain_length (max 10mm)))\n" );
1422 std::vector<std::shared_ptr<DRC_RULE>> rules;
1434 const wxString rules = wxT(
"# project rules\n"
1436 "(rule \"a\" (constraint clearance (min 0.2mm)))\n" );
1442 "(rule \"a\" (constraint clearance (min 0.2mm)))\n" ) );
1449 const wxString rules = wxT(
"# intro\n"
1450 "(rule \"a\" (constraint net_chain_length (max 1mm)))\n" );
1456 "# Not supported by KiCad 9.0:\n"
1457 "# (rule \"a\" (constraint net_chain_length (max 1mm)))\n" ) );
1464 const wxString rules = wxT(
"(version 2)(rule \"kept\" (constraint clearance (min 0.2mm)))" );
1468 BOOST_CHECK_EQUAL(
result.m_text, wxString(
"(version 1)(rule \"kept\" (constraint clearance (min 0.2mm)))\n" ) );
1475 const wxString rules = wxT(
"(version 1) # note\n(rule \"a\" (constraint clearance (min 0.2mm)))\n" );
1484 const wxString rules = wxT(
"(version 1)(rule \"c\" (condition \"A.Width > 5ps\") "
1485 "(constraint clearance (min 0.2mm)))" );
1494 const wxString rules = wxT(
"(version 1)\n"
1497 " (constraint clearance (min 0.2mm)))\n" );
1505 const wxString rules = wxT(
"(version 1)(rule \"f\" (condition \"A.InsideCourtyard('x')\") "
1506 "(constraint clearance (min 0.2mm)))" );
1515 const wxString rules = wxT(
"(version 1)(rule \"hv\" (condition \"A.memberOfFootprint('${Class:HV}')\") "
1516 "(constraint clearance (min 1mm)))" );
1525 const wxString parent = wxT(
"(version 1)(rule \"x\" (condition A.Parent.Reference==B.Reference) "
1526 "(constraint clearance (min 1mm)))" );
1527 const wxString assertion = wxT(
"(version 1)(rule \"x\" (constraint assertion A.Parent.Reference==B.Reference))" );
1528 const wxString plain = wxT(
"(version 1)(rule \"x\" (condition A.NetClass=='HV') "
1529 "(constraint clearance (min 1mm)))" );
1542 const wxString newItem = wxT(
"(version 1)(rule \"y\" (constraint disallow \"blind_via\"))" );
1543 const wxString oldItem = wxT(
"(version 1)(rule \"y\" (constraint disallow \"via\"))" );
1544 const wxString connection = wxT(
"(version 1)(rule \"z\" (constraint zone_connection \"thermal_reliefs\"))" );
1559 const wxString rules = wxT(
"(version 1)\n(rule \"a\" (condition \"A.NetClass ==\n 'HV'\") "
1560 "(constraint clearance (min 0.2mm)))\n" );
1569 const wxString rules = wxT(
"(version 1)\n"
1571 "# the head comes after this comment\n"
1572 "rule \"a\" (constraint clearance (min 0.2mm)))\n"
1574 "# so does this one\n"
1575 "rule \"b\" (constraint net_chain_length (max 1mm)))\n" );
1590 for(
const wxString& input : { wxT(
"(version 1)\n(rule \"inline\" # )\n (constraint clearance (min 0.2mm)))" ),
1591 wxT(
"(version 1)\n(rule \"missing_close\" (constraint clearance (min 0.2mm))" ),
1592 wxT(
"(version 1)\n(rule \"missing_quote" ) } )
1609 const std::string release = target.m_id == wxT(
"9.0" ) ?
"v9" :
"v10";
1614 release ==
"v9" ? 1 : 2 );
1644 nlohmann::json doc = {
1645 {
"meta", { {
"filename",
"p.kicad_pro" }, {
"version", 3 } } },
1646 {
"board", { {
"layer_presets", { { {
"name",
"P" }, {
"renderLayers", {
"tracks",
"vias" } } } } } } },
1648 { {
"meta", { {
"version", 5 } } },
1649 {
"classes", { { {
"name",
"Default" }, {
"priority", 0 }, {
"tuning_profile",
"tp" } } } },
1650 {
"net_chain_classes", { { {
"name",
"chainA" } } } } } },
1651 {
"tuning_profiles",
1652 { {
"meta", { {
"version", 1 } } },
1653 {
"tuning_profiles_impedance_geometric",
1654 { { {
"name",
"tp" }, {
"frequency", 1e9 }, {
"model_solder_mask",
false } } } } } },
1655 {
"component_class_settings", { {
"meta", { {
"version", 0 } } } } },
1657 { {
"top_level_sheets", {
"aaaa" } },
1658 {
"bus_aliases", nlohmann::json::array() },
1659 {
"variants", nlohmann::json::array() } } },
1669 const nlohmann::json& preset = doc[
"board"][
"layer_presets"][0];
1676 BOOST_CHECK( !doc[
"net_settings"][
"classes"][0].contains(
"tuning_profile" ) );
1677 BOOST_CHECK( doc[
"net_settings"][
"classes"][0].contains(
"name" ) );
1678 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
1679 BOOST_CHECK( !doc.contains(
"tuning_profiles" ) );
1680 BOOST_CHECK( !doc.contains(
"component_class_settings" ) );
1681 BOOST_CHECK( !doc[
"schematic"].contains(
"top_level_sheets" ) );
1682 BOOST_CHECK( !doc[
"schematic"].contains(
"bus_aliases" ) );
1683 BOOST_CHECK( !doc[
"schematic"].contains(
"variants" ) );
1693 const nlohmann::json
empty = nlohmann::json::array();
1694 const std::vector<nlohmann::json> tuningDefaults = {
1696 nlohmann::json::object(),
1697 { {
"meta", { {
"version", 2 } } } },
1698 { {
"meta", { {
"version", 2 } } }, {
"tuning_profiles_impedance_geometric",
empty } },
1700 const std::vector<nlohmann::json> componentDefaults = {
1702 nlohmann::json::object(),
1703 { {
"meta", { {
"version", 0 } } } },
1704 { {
"assignments",
empty }, {
"sheet_component_classes", nlohmann::json::object() } },
1705 { {
"meta", { {
"version", 0 } } },
1706 {
"assignments",
empty },
1707 {
"sheet_component_classes", { {
"enabled",
false } } } },
1712 for(
const auto& tuning : tuningDefaults )
1714 for(
const auto& components : componentDefaults )
1716 nlohmann::json doc = {
1717 {
"meta", { {
"version", 4 } } },
1718 {
"board", { {
"design_settings", { {
"meta", { {
"version", 3 } } } } } } },
1719 {
"erc", { {
"meta", { {
"version", 1 } } }, {
"erc_exclusions",
empty } } },
1721 { {
"meta", { {
"version", 5 } } },
1722 {
"classes", { { {
"name",
"Default" }, {
"tuning_profile",
"" } } } } } },
1723 {
"tuning_profiles", tuning },
1724 {
"component_class_settings", components },
1734 BOOST_CHECK_EQUAL( doc[
"board"][
"design_settings"][
"meta"][
"version"].get<int>(), 2 );
1736 BOOST_CHECK_EQUAL( doc.contains(
"tuning_profiles" ), target.m_id == wxT(
"10.0" ) );
1737 BOOST_CHECK_EQUAL( doc.contains(
"component_class_settings" ), target.m_id == wxT(
"10.0" ) );
1739 const nlohmann::json once = doc;
1752 const nlohmann::json
empty = nlohmann::json::array();
1753 const nlohmann::json profile = {
1754 {
"profile_name",
"Default" },
1755 {
"frequency", 1e9 },
1756 {
"model_solder_mask",
false },
1757 {
"net_chain_bridge_prop_delay", 0 },
1759 const std::vector<nlohmann::json> meaningful = {
1760 { {
"tuning_profiles", { {
"tuning_profiles_impedance_geometric", { profile } } } } },
1761 { {
"net_settings", { {
"classes", { { {
"tuning_profile",
"Saved" } } } } } } },
1762 { {
"tuning_profiles", { {
"tuning_profiles_impedance_geometric",
empty } } },
1763 {
"net_settings", { {
"classes", { { {
"tuning_profile",
"Saved" } } } } } } },
1764 { {
"tuning_profiles", { {
"tuning_profiles_impedance_geometric", { profile } } } },
1766 { {
"classes", { { {
"tuning_profile",
"Default" } }, { {
"tuning_profile",
"Default" } } } } } } },
1767 { {
"component_class_settings",
1769 { { {
"component_class",
"Fast" }, {
"conditions_operator",
"ALL" }, {
"conditions",
empty } } } },
1770 {
"sheet_component_classes", { {
"enabled",
false } } } } } },
1771 { {
"component_class_settings",
1772 { {
"assignments",
empty }, {
"sheet_component_classes", { {
"enabled",
true } } } } } },
1775 for(
const auto&
source : meaningful )
1779 nlohmann::json doc =
source;
1786 const nlohmann::json once = doc;
1798 const nlohmann::json
source = {
1799 {
"meta", { {
"version", 4 } } },
1800 {
"component_class_settings", { {
"meta", { {
"version", 1 } } } } },
1805 nlohmann::json doc =
source;
1818 nlohmann::json metaIsString = {
1819 {
"meta",
"not an object" },
1820 {
"net_settings", { {
"meta",
"also a string" }, {
"classes",
"not an array" } } },
1821 {
"schematic",
"a string" },
1824 nlohmann::json profilesWrong = {
1825 {
"tuning_profiles",
1826 { {
"meta", 7 }, {
"tuning_profiles_impedance_geometric", {
"just",
"strings" } } } },
1838 nlohmann::json doc = {
1839 {
"net_settings", { {
"net_chain_classes", nlohmann::json::array() } } },
1845 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
1852 nlohmann::json doc = {
1853 {
"tuning_profiles",
1854 { {
"meta", { {
"version", 1 } } },
1855 {
"tuning_profiles_impedance_geometric",
1856 { { {
"profile_name",
"5 GHz" }, {
"frequency", 5e9 }, {
"model_solder_mask",
true } },
1857 { {
"profile_name",
"Default" }, {
"frequency", 1e9 }, {
"model_solder_mask",
false } } } } } }
1865 for(
const auto& profile : doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"] )
1868 BOOST_CHECK( !profile.contains(
"model_solder_mask" ) );
1879 nlohmann::json doc = {
1880 {
"meta", { {
"version", 3 } } },
1882 { {
"meta", { {
"version", 5 } } },
1883 {
"classes", { { {
"name",
"Default" }, {
"priority", 0 }, {
"tuning_profile",
"tp" } } } },
1884 {
"net_chain_classes", { { {
"name",
"chainA" } } } } } },
1885 {
"tuning_profiles",
1886 { {
"meta", { {
"version", 1 } } },
1887 {
"tuning_profiles_impedance_geometric",
1888 { { {
"name",
"tp" }, {
"frequency", 1e9 }, {
"model_solder_mask",
false } } } } } },
1897 BOOST_CHECK( doc[
"net_settings"][
"classes"][0].contains(
"tuning_profile" ) );
1898 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
1901 BOOST_CHECK( !doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"][0].contains(
"frequency" ) );
1902 BOOST_CHECK( !doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"][0].contains(
"model_solder_mask" ) );
1934 BOOST_CHECK_GT( areaMM, 4.0 );
1935 BOOST_CHECK_LT( areaMM, 15.0 );
1959 BOOST_CHECK_CLOSE( ref.
GetImageScale(), 2.0 * legacyPPI / ppi, 0.1 );
1966 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>(
nullptr );
1981 BOOST_CHECK_CLOSE( ref.
GetImageScale(), 2.0 * legacyPPI / ppi, 0.1 );
2008 const wxString src = ( tmp.
Path() /
"src.kicad_mod" ).wstring();
2009 const wxString dest = ( tmp.
Path() /
"out.kicad_mod" ).wstring();
2012 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>(
nullptr );
2030 std::unique_ptr<FOOTPRINT> srcAgain( reader.
ImportFootprint( src, nameOut ) );
2031 std::unique_ptr<FOOTPRINT> converted( reader.
ImportFootprint( dest, nameOut ) );
2037 BOOST_CHECK_EQUAL( converted->Zones()[0]->GetLayerSet().count(), srcAgain->Zones()[0]->GetLayerSet().count() );
2046 const wxString dir = tmp.
Path().wstring();
2048 auto writeFile = [&](
const wxString& aName,
const wxString& aContent )
2050 wxFFile file( dir + wxFileName::GetPathSeparator() + aName, wxT(
"wb" ) );
2052 file.Write( aContent );
2055 writeFile( wxT(
"a.fake_mod" ), wxT(
"old a" ) );
2056 writeFile( wxT(
"b.fake_mod" ), wxT(
"old b" ) );
2058 auto noForbidden = [](
const wxString& )
2065 wxFFile out( aTmp, wxT(
"wb" ) );
2066 out.Write( wxT(
"(version 123) converted" ) );
2072 wxFFile check( dir + wxFileName::GetPathSeparator() + wxT(
"a.fake_mod" ), wxT(
"rb" ) );
2074 BOOST_REQUIRE( check.IsOpened() && check.ReadAll( &content ) );
2075 BOOST_CHECK( content.Contains( wxT(
"converted" ) ) );
2080 if( aFile.Contains( wxT(
"b.fake_mod" ) ) )
2083 wxFFile out( aTmp, wxT(
"wb" ) );
2084 out.Write( wxT(
"(version 123) second pass" ) );
2089 BOOST_CHECK( bad.Contains( wxT(
"b.fake_mod" ) ) );
2091 wxArrayString leftovers;
2092 wxDir::GetAllFiles( dir, &leftovers );
2095 wxFFile recheck( dir + wxFileName::GetPathSeparator() + wxT(
"a.fake_mod" ), wxT(
"rb" ) );
2097 BOOST_REQUIRE( recheck.IsOpened() && recheck.ReadAll( &unchanged ) );
2098 BOOST_CHECK( !unchanged.Contains( wxT(
"second pass" ) ) );
2142 for(
bool footprintOnly : {
false,
true } )
2159 parent->
Add( shape );
2160 group->AddItem( shape );
2164 parent->
Add( barcode );
2165 group->AddItem( barcode );
2168 textbox->
SetText( wxT(
"Do not retain as plain text" ) );
2169 parent->
Add( textbox );
2170 group->AddItem( textbox );
2173 parent->
Add( supported );
2174 group->AddItem( supported );
2175 const KIID supportedUuid = supported->
m_Uuid;
2183 for(
size_t i = 0; i <
normal.Entries().size(); ++i )
2188 BOOST_CHECK( !omit.Entries()[i].m_detail.IsEmpty() );
2216 parent->Add( hatch );
2218 table->SetColCount( 2 );
2221 knockout->
SetText( wxT(
"knockout" ) );
2222 table->AddCell( knockout );
2224 plain->
SetText( wxT(
"supported" ) );
2225 table->AddCell( plain );
2226 parent->Add(
table );
2252 for(
int ii = 0; ii < 3; ++ii )
2263 board.
Add( copper );
2265 for(
bool drop : {
false,
true } )
2281 for(
bool drop : {
false,
true } )
2289 std::vector<PCB_SHAPE*> copper;
2290 std::vector<PCB_SHAPE*> silk;
2298 parent->Add( onCopper );
2299 copper.push_back( onCopper );
2304 parent->Add( onSilk );
2305 silk.push_back( onSilk );
2322 for(
bool footprintOnly : {
false,
true } )
2333 pad->AddPrimitive(
F_Cu, rounded );
2335 pad->AddPrimitive(
F_Cu, supported );
2352 for(
bool drop : {
false,
true } )
2362 board.
Add( buried );
2364 board.
Add( supported );
2393 board.
Add( textbox );
2397 board.
Add( buried );
2429 const wxString board =
directory + wxT(
"/board.kicad_pcb" );
2431 auto write = [](
const wxString& aPath,
const wxString& aContent )
2433 wxFFile file( aPath, wxT(
"wb" ) );
2434 BOOST_REQUIRE( file.IsOpened() && file.Write( aContent ) && file.Close() );
2437 auto read = [](
const wxString& aPath )
2439 wxFFile file( aPath, wxT(
"rb" ) );
2441 BOOST_REQUIRE( file.IsOpened() && file.ReadAll( &content ) );
2445 auto noForbidden = [](
const wxString& )
2449 auto convert = [&](
const wxString&,
const wxString& aTemporary )
2451 write( aTemporary, wxT(
"(version 123) converted" ) );
2455 write(
library, wxT(
"original library" ) );
2456 write( board, wxT(
"original board" ) );
2475 wxString stagedBoard = transaction.
Stage( board );
2477 write( stagedBoard, wxT(
"converted board" ) );
2483 wxArrayString files;
2484 wxDir::GetAllFiles(
directory, &files );
2493 const wxString first =
directory + wxT(
"/first.kicad_pcb" );
2494 const wxString second =
directory + wxT(
"/second.kicad_pcb" );
2497 wxFFile file( first, wxT(
"wb" ) );
2498 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT(
"original" ) ) && file.Close() );
2503 wxString stagedFirst = transaction.
Stage( first );
2504 wxString stagedSecond = transaction.
Stage( second );
2505 BOOST_REQUIRE( !stagedFirst.IsEmpty() && !stagedSecond.IsEmpty() );
2507 for(
const wxString& file : { stagedFirst, stagedSecond } )
2509 wxFFile output( file, wxT(
"wb" ) );
2510 BOOST_REQUIRE( output.IsOpened() && output.Write( wxT(
"converted" ) ) && output.Close() );
2514 BOOST_CHECK( wxFileName( transaction.
Commit() ).SameAs( wxFileName( second ) ) );
2518 wxFFile input( first, wxT(
"rb" ) );
2520 BOOST_REQUIRE( input.IsOpened() && input.ReadAll( &content ) );
2523 wxArrayString files;
2524 wxDir::GetAllFiles(
directory, &files );
2532 const wxString destination = temporary.
Path().wstring() + wxT(
"/board.kicad_pcb" );
2537 wxString firstTemporary = first.
Stage( destination );
2538 wxString secondTemporary = second.
Stage( destination );
2539 BOOST_REQUIRE( !firstTemporary.IsEmpty() && !secondTemporary.IsEmpty() );
2543 first.
Discard( firstTemporary );
2556 const auto original = temporary.
Path() / u8
"original-μ.kicad_mod";
2557 const auto alias = temporary.
Path() /
"alias.kicad_mod";
2558 const auto danglingAlias = temporary.
Path() /
"dangling.kicad_mod";
2561 wxFFile file( original.wstring(), wxT(
"wb" ) );
2562 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT(
"original source" ) ) && file.Close() );
2565 std::error_code error;
2566 std::filesystem::create_symlink( original.filename(), alias, error );
2574 std::filesystem::create_symlink(
"missing.kicad_mod", danglingAlias, error );
2580 for(
const auto& destination : { alias, danglingAlias } )
2582 wxString staged = transaction.
Stage( destination.wstring() );
2584 wxFFile file( staged, wxT(
"wb" ) );
2585 BOOST_REQUIRE( file.IsOpened() && file.Write( wxT(
"converted output" ) ) && file.Close() );
2591 wxFFile file( original.wstring(), wxT(
"rb" ) );
2593 BOOST_REQUIRE( file.IsOpened() && file.ReadAll( &content ) );
2595 BOOST_CHECK( !std::filesystem::is_symlink( alias ) );
2596 BOOST_CHECK( !std::filesystem::is_symlink( danglingAlias ) );
2598 std::filesystem::directory_iterator() ),
2608 if( entry.m_feature == aName )
2617 BOOST_ERROR(
"Missing compatibility feature: " + aName.ToStdString() );
2625 for(
bool drop : {
false,
true } )
2631 std::vector<PCB_SHAPE*> shapes;
2639 parent->Add( shape );
2640 shapes.push_back( shape );
2643 parent->Add( constraint );
2667 for(
bool drop : {
false,
true } )
2694 for(
bool drop : {
false,
true } )
2708 group->AddItem( live );
2739 const std::string src = ( tmp.
Path() /
"stackup.kicad_pcb" ).string();
2764 std::ifstream file( src );
2765 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
2766 BOOST_REQUIRE( content.find(
"(stackup_table" ) != std::string::npos );
2773 const std::string dest = ( tmp.
Path() / (
"out-" + target.m_id.ToStdString() +
".kicad_pcb" ) ).string();
2778 std::ifstream file( dest );
2779 std::string content( ( std::istreambuf_iterator<char>( file ) ), std::istreambuf_iterator<char>() );
2781 BOOST_CHECK( content.find(
"(stackup_table" ) == std::string::npos );
2782 BOOST_CHECK( content.find(
"(table" ) != std::string::npos );
2785 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
2789 BOARD_ITEM* item = *exported->Drawings().begin();
2802 for(
bool drop : {
false,
true } )
2809 board.
Add( stitch );
2813 std::vector<PCB_VIA*> vias;
2819 via->SetPosition(
VECTOR2I( 1000000 * ( vias.size() + 1 ), 2000000 ) );
2820 via->SetWidth(
F_Cu, 600000 );
2821 via->SetDrill( 300000 );
2823 generator->AddItem(
via );
2824 vias.push_back(
via );
2835 for(
size_t ii = 0; ii < vias.size(); ++ii )
2840 BOOST_CHECK( vias[ii]->GetParentGroup() == outer );
2849 const std::string src =
2861 const auto copperById = [](
const BOARD& aBoard )
2863 std::map<KIID, const PCB_TRACK*> items;
2865 for(
const PCB_TRACK* item : aBoard.Tracks() )
2866 BOOST_REQUIRE( items.emplace( item->m_Uuid, item ).second );
2870 const auto memberIds = [](
const PCB_GROUP& aGroup )
2874 for(
const EDA_ITEM* member : aGroup.GetItems() )
2879 const auto serializeNative = [](
BOARD* aBoard )
2887 const auto sourceCopper = copperById( *
source );
2889 std::set<KIID> plainVias;
2890 std::set<KIID> generatedVias;
2891 size_t sourceVias = 0;
2892 size_t sourceSegments = 0;
2893 size_t sourceMicrovias = 0;
2895 for(
const auto& [
id, item] : sourceCopper )
2907 if( !
via->GetParentGroup() )
2908 plainVias.insert(
id );
2931 BOOST_REQUIRE(
source->FindNet( viaStitch->GetNetCode() )->GetNetname() == wxT(
"GND" ) );
2957 for(
BOARD_ITEM* member : generator->GetBoardItems() )
2961 BOOST_REQUIRE( sourceCopper.count( member->m_Uuid ) == 1u );
2962 BOOST_REQUIRE( generatedVias.insert( member->m_Uuid ).second );
2971 const auto stitchMembers = memberIds( *stitch );
2974 const wxString outerName = outer->
GetName();
2979 const std::string sourceModel = serializeNative(
source.get() );
2984 const bool preTen = target.m_boardVersion ==
kicad9.m_boardVersion;
2986 for(
bool drop : {
false,
true } )
2995 const std::string dest =
2997 / ( target.m_id.ToStdString() + ( drop ?
"-drop.kicad_pcb" :
"-lower.kicad_pcb" ) ) )
3000 wxString unsupportedToken;
3016 for(
size_t ii = 0; ii < preview.
Entries().size(); ++ii )
3025 BOOST_CHECK( outputBytes.find(
"(generated" ) == std::string::npos );
3029 for(
const char* token : {
"(filling",
"(capping",
"(covering",
"(plugging" } )
3030 BOOST_CHECK( outputBytes.find( token ) == std::string::npos );
3033 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
3035 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3040 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3042 const auto exportedCopper = copperById( *exported );
3044 PCB_GROUP* exportedOuter = *exported->Groups().begin();
3047 BOOST_CHECK( memberIds( *exportedOuter ) == stitchMembers );
3049 for(
const auto& [
id, original] : sourceCopper )
3051 const auto found = exportedCopper.find(
id );
3060 if(
const PCB_VIA* originalVia =
dynamic_cast<const PCB_VIA*
>( original ) )
3087 const PADSTACK& originalStack = originalVia->Padstack();
3100 if( plainVias.count(
id ) )
3109 if( stitchMembers.count(
id ) )
3119 const auto found = std::find_if( exported->Drawings().begin(), exported->Drawings().end(),
3122 return aItem->m_Uuid == drawing->m_Uuid;
3147 std::unique_ptr<BOARD> lengthFixture( io.
LoadBoard( lengthPath,
nullptr ) );
3148 std::unique_ptr<BOARD> timeFixture( io.
LoadBoard( timePath,
nullptr ) );
3156 if( generator->m_Uuid ==
KIID(
"2acf841f-25ce-450c-b8df-dbbc34cc96ac" ) )
3166 auto length =
dynamic_cast<PCB_TUNING_PATTERN*
>( ( *lengthFixture->Generators().begin() )->DeepClone() );
3170 BOOST_REQUIRE_GT( length->GetItems().size(), 1u );
3172 const auto addCopper = [&](
PCB_TRACK* aTrack )
3178 net =
new NETINFO_ITEM( &board, aTrack->GetNetname() );
3184 board.
Add( aTrack );
3189 for(
BOARD_ITEM* member : pattern->GetBoardItems() )
3196 board.
Add( pattern );
3201 for(
PCB_TRACK* track : timeFixture->Tracks() )
3205 originalControl = track;
3211 auto control =
static_cast<PCB_TRACK*
>( originalControl->
Clone() );
3212 control->SetParentGroup(
nullptr );
3213 addCopper( control );
3215 outer->
SetName( wxT(
"Native tuning ownership" ) );
3221 double patternLength = 0;
3223 for(
BOARD_ITEM* member : length->GetBoardItems() )
3224 patternLength +=
static_cast<PCB_TRACK*
>( member )->GetLength();
3229 for(
const char* key : {
"tuning_mode",
"initial_side",
"last_status" } )
3233 lengthProperties[key] = wxAny( wxString::FromUTF8( value ) );
3236 lengthProperties[
"last_tuning_length"] = wxAny( patternLength /
pcbIUScale.IU_PER_MM );
3237 length->SetProperties( lengthProperties );
3238 const wxString tuningInfo = length->GetRowData().back().second.GetString();
3240 const auto memberIds = [](
const PCB_GROUP& aGroup )
3244 for(
const EDA_ITEM* member : aGroup.GetItems() )
3249 const auto serializeNative = [](
BOARD* aBoard )
3256 std::map<KIID, const PCB_TRACK*> copper;
3259 BOOST_REQUIRE( copper.emplace( track->m_Uuid, track ).second );
3261 const auto lengthMembers = memberIds( *length );
3262 const auto timeMembers = memberIds( *time );
3266 const std::string src = ( tmp.
Path() /
"native-source.kicad_pcb" ).string();
3269 const std::string sourceModel = serializeNative( &board );
3273 const bool preTen = target.m_boardVersion ==
kicad9.m_boardVersion;
3275 for(
bool drop : {
false,
true } )
3284 const std::string dest =
3286 / ( target.m_id.ToStdString() + ( drop ?
"-drop.kicad_pcb" :
"-lower.kicad_pcb" ) ) )
3289 wxString unsupported;
3306 for(
const char* token : {
"(is_time_domain",
"(target_delay",
"(last_tuning_length" } )
3307 BOOST_CHECK( outputBytes.find( token ) == std::string::npos );
3310 BOOST_CHECK( outputBytes.find(
"(last_tuning " + quoting.
Quotew( tuningInfo ) +
")" )
3311 != std::string::npos );
3315 BOOST_CHECK( outputBytes.find(
"(is_time_domain yes)" ) != std::string::npos );
3316 BOOST_CHECK( outputBytes.find(
"(last_tuning_length " ) != std::string::npos );
3317 BOOST_CHECK( outputBytes.find(
"(last_tuning " ) == std::string::npos );
3320 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
3322 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3325 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3326 PCB_GROUP* exportedOuter = *exported->Groups().begin();
3328 std::set<KIID> expectedOuter{ length->m_Uuid };
3331 expectedOuter.insert( timeMembers.begin(), timeMembers.end() );
3333 expectedOuter.insert( time->m_Uuid );
3335 BOOST_CHECK( memberIds( *exportedOuter ) == expectedOuter );
3338 for(
const PCB_TRACK* track : exported->Tracks() )
3340 const auto found = copper.find( track->m_Uuid );
3342 const PCB_TRACK* original = found->second;
3350 if(
const PCB_ARC* arc =
dynamic_cast<const PCB_ARC*
>( original ) )
3352 const PCB_ARC* exportedArc =
dynamic_cast<const PCB_ARC*
>( track );
3357 if( timeMembers.count( track->m_Uuid ) && preTen )
3359 else if( track->m_Uuid == control->m_Uuid )
3368 BOOST_CHECK( pattern->m_Uuid == length->m_Uuid || ( !preTen && pattern->m_Uuid == time->m_Uuid ) );
3369 const bool isTime = pattern->m_Uuid == time->m_Uuid;
3370 BOOST_CHECK( pattern->GetSettings().m_isTimeDomain == isTime );
3371 BOOST_CHECK( memberIds( *pattern ) == ( isTime ? timeMembers : lengthMembers ) );
3376 for(
const char* key :
3377 {
"target_length",
"target_length_min",
"target_length_max",
"target_skew",
"target_skew_min",
3378 "target_skew_max",
"min_spacing",
"max_amplitude",
"min_amplitude" } )
3381 double originalValue = 0;
3383 BOOST_REQUIRE( originalProperties.get_to( key, originalValue ) );
3389 for(
const char* key :
3390 {
"target_delay",
"target_delay_min",
"target_delay_max",
"last_tuning_length" } )
3393 double originalValue = 0;
3395 BOOST_REQUIRE( originalProperties.get_to( key, originalValue ) );
3421 properties.
set(
"future_tuning_setting",
true );
3427 auto pattern =
new UNREVIEWED_TUNING_PATTERN( &board );
3429 track->SetStart(
VECTOR2I( 1000000, 2000000 ) );
3430 track->SetEnd(
VECTOR2I( 3000000, 2000000 ) );
3432 board.
Add( pattern );
3433 pattern->AddItem( track );
3437 for(
bool drop : {
false,
true } )
3450 const wxString
path = ( tmp.
Path() / ( target.m_id.ToStdString() +
".kicad_pcb" ) ).wstring();
3460 pattern->SetTargetDelay( 100000 );
3462 track->SetStart(
VECTOR2I( 1000000, 2000000 ) );
3463 track->SetEnd(
VECTOR2I( 3000000, 2000000 ) );
3465 board.
Add( pattern );
3466 pattern->AddItem( track );
3470 for(
const char* token :
3471 {
"is_time_domain",
"target_delay",
"target_delay_min",
"target_delay_max",
"last_tuning_length" } )
3473 const wxString value = wxString::FromUTF8(
"(kicad_pcb (generated (" + std::string( token ) +
" 0)))" );
3484 for(
bool stack : {
false,
true } )
3493 const std::string kind = stack ?
"via-stack" :
"via-stitch";
3499 const auto absent = tmp.
Path() / ( kind +
"-" + target.m_id.ToStdString() +
"-absent.kicad_pcb" );
3503 const auto existing = tmp.
Path() / ( kind +
"-" + target.m_id.ToStdString() +
"-existing.kicad_pcb" );
3506 std::ofstream sentinel( existing, std::ios::binary );
3507 sentinel <<
"existing destination";
3522 const std::string src =
3524 wxFileName projectFile( wxString::FromUTF8( src ) );
3525 projectFile.SetExt( wxT(
"kicad_pro" ) );
3536 std::map<KIID, const PCB_TEXT*> sourceNotes;
3541 BOOST_REQUIRE( sourceNotes.emplace( note->m_Uuid, note ).second );
3545 std::map<KIID, const ZONE*> sourceZones;
3546 int placementAreas = 0;
3547 int filledOutlines = 0;
3551 BOOST_REQUIRE( sourceZones.emplace( zone->m_Uuid, zone ).second );
3561 filledOutlines += zone->GetFilledPolysList( layer )->OutlineCount();
3565 BOOST_REQUIRE_GT( filledOutlines, 0 );
3566 const auto memberIds = [](
const PCB_GROUP& aGroup )
3570 for(
const EDA_ITEM* member : aGroup.GetItems() )
3579 for(
int outline = 0; outline < aOriginal.
OutlineCount(); ++outline )
3581 BOOST_CHECK( aExported.COutline( outline ).CompareGeometry( aOriginal.
COutline( outline ) ) );
3584 for(
int hole = 0; hole < aOriginal.
HoleCount( outline ); ++hole )
3585 BOOST_CHECK( aExported.CHole( outline, hole ).CompareGeometry( aOriginal.
CHole( outline, hole ) ) );
3588 const auto serializeNative = [](
BOARD* aBoard )
3595 const std::string sourceModel = serializeNative(
source.get() );
3603 const bool preTen = target.m_boardVersion ==
kicad9.m_boardVersion;
3605 for(
bool drop : {
false,
true } )
3614 const std::string dest =
3616 / ( target.m_id.ToStdString() + ( drop ?
"-drop.kicad_pcb" :
"-lower.kicad_pcb" ) ) )
3619 wxString unsupported;
3633 std::unique_ptr<BOARD> exported( io.
LoadBoard( dest,
nullptr ) );
3635 BOOST_CHECK_EQUAL( exported->GetFileFormatVersionAtLoad(), target.m_boardVersion );
3639 BOOST_CHECK( exported->GroupsSanityCheck().IsEmpty() );
3641 for(
const auto& [
id, original] : sourceNotes )
3643 const auto found = std::find_if( exported->Drawings().begin(), exported->Drawings().end(),
3646 return aItem->m_Uuid == id;
3656 for(
const ZONE* zone : exported->Zones() )
3658 const auto found = sourceZones.find( zone->m_Uuid );
3660 const ZONE* original = found->second;
3671 checkPolygons( original->
GetBoardOutline(), zone->GetBoardOutline() );
3676 const auto exportedFill = zone->GetFilledPolysList( layer );
3677 checkPolygons( *originalFill, *exportedFill );
3679 for(
int outline = 0; outline < originalFill->OutlineCount(); ++outline )
3686 BOOST_CHECK( zone->GetPlacementAreaSource().IsEmpty() );
3699 const auto original = std::find_if(
source->Groups().begin(),
source->Groups().end(),
3702 return aGroup->m_Uuid == group->m_Uuid;
3709 std::map<KIID, const PAD*> sourcePads;
3717 for(
const PAD*
pad : exported->GetPads() )
3719 const auto found = sourcePads.find(
pad->m_Uuid );
3721 const PAD* original = found->second;
3744 for(
bool drop : {
false,
true } )
3747 auto footprint =
new FOOTPRINT( &board );
3748 auto zone =
new ZONE( footprint );
3749 zone->SetIsRuleArea(
true );
3750 zone->SetPlacementAreaEnabled(
true );
3752 zone->SetPlacementAreaSource( wxT(
"Repeated group" ) );
3753 zone->SetDoNotAllowTracks(
true );
3754 footprint->Add( zone );
3755 board.
Add( footprint );
3764 == ( target.m_id ==
kicad10.m_id ? wxT(
"Repeated group" ) : wxEmptyString ) );
3773 == wxT(
"placement/group" ) );
3782 for(
bool drop : {
false,
true } )
3785 auto emptyRuleArea =
new ZONE( &board );
3786 emptyRuleArea->SetIsRuleArea(
true );
3788 board.
Add( emptyRuleArea );
3789 auto ordinaryZone =
new ZONE( &board );
3791 ordinaryZone->SetPlacementAreaEnabled(
true );
3792 ordinaryZone->SetPlacementAreaSource( wxT(
"Unused by ordinary copper zones" ) );
3793 board.
Add( ordinaryZone );
3809 explicit FUTURE_GENERATOR(
BOARD* aBoard ) :
3813 wxString
GetGeneratorType()
const override {
return wxT(
"future_generator" ); }
3817 board.
Add(
new FUTURE_GENERATOR( &board ) );
3819 for(
bool drop : {
false,
true } )
3826 for(
bool drop : {
false,
true } )
3831 std::vector<PCB_SHAPE*> shapes;
3832 double expectedArea = 0;
3843 parent->Add( shape );
3844 shapes.push_back( shape );
3848 expectedArea += ink.
Area();
3870 area +=
static_cast<PCB_SHAPE*
>( item )->GetPolyShape().Area();
3873 area +=
static_cast<PCB_SHAPE*
>( item )->GetPolyShape().Area();
3875 BOOST_CHECK_CLOSE( area, expectedArea, 0.05 );
3901 for(
bool footprintOnly : {
false,
true } )
3907 fp->
Value().
SetText( wxT(
"${PROPERTY.Reference}/${REFERENCE}" ) );
3910 escaped->
SetText( wxT(
"\\${PROPERTY.Serial}" ) );
3913 expression->
SetText( wxT(
"@{${PROPERTY.Reference}+1}/${REFERENCE}" ) );
3914 fp->
Add( expression );
3941 for(
bool drop : {
false,
true } )
3949 const wxString projectPath = ( tmp.
Path() /
"source.kicad_pro" ).string();
3952 std::ofstream
project( projectPath.ToStdString() );
3953 project << R
"({"meta":{"version":4},"text_variables":{"SERIAL":"${PROPERTY.Reference}","ALIAS":"${SERIAL}","UNUSED":"${PROPERTY.Missing}"}})";
3961 std::vector<FOOTPRINT*> footprints;
3963 for(
const wxString& serial : { wxT(
"42" ), wxT(
"73" ) } )
3970 footprints.push_back( fp );
3975 BOOST_CHECK_EQUAL( footprints[0]->Value().GetText(), wxString(
"42/${REFERENCE}" ) );
3976 BOOST_CHECK_EQUAL( footprints[1]->Value().GetText(), wxString(
"73/${REFERENCE}" ) );
3978 footprints[0]->Value().SetText( wxT(
"${UNUSED}" ) );
3987 board.
SetProperties( { { wxT(
"SERIAL" ), wxT(
"${PROPERTY.Reference}" ) },
3988 { wxT(
"UNUSED" ), wxT(
"${PROPERTY.Missing}" ) } } );
3991 fp->
Value().
SetText( wxT(
"${SERIAL}/${REFERENCE}" ) );
4005 fp->
SetKeywords( wxT(
"\\${REFERENCE}/\\@{1+2}" ) );
4006 fp->
Value().
SetText( wxT(
"${PROPERTY.Reference}/\\${U1:PROPERTY.Missing}/${REFERENCE}" ) );
4008 text->SetText( wxT(
"${PROPERTY.Keywords}/${REFERENCE}" ) );
4025 fp->
Value().
SetText( wxT(
"@{1000mils}/${REFERENCE}" ) );
4035 for(
const wxString& raw :
4036 { wxT(
"@{${PROPERTY.Reference}+${MISSING}}" ), wxT(
"@{unknown_function(${PROPERTY.Reference})}" ) } )
4045 for(
bool drop : {
false,
true } )
4053 for(
bool inProperty : {
false,
true } )
4058 const wxString literal = wxT(
"\\${REFERENCE}/\\@{1+2}" );
4060 fp->
Value().
SetText( inProperty ? wxString( wxT(
"${PROPERTY.Keywords}" ) ) : literal );
4064 for(
bool drop : {
false,
true } )
4078 for(
bool drop : {
false,
true } )
4101 for(
bool drop : {
false,
true } )
4109 const wxString projectPath = ( temporary.
Path() /
"source.kicad_pro" ).string();
4112 std::ofstream
project( projectPath.ToStdString() );
4113 project << R
"({"meta":{"version":4},"text_variables":{"TITLE":"${PROPERTY.Reference}"}})";
4127 for(
bool drop : {
false,
true } )
4144 table->SetColCount( 1 );
4145 table->SetColWidth( 0, 10000000 );
4146 table->SetRowHeight( 0, 6000000 );
4148 cell->
SetText( wxT(
"@{${PROPERTY.Reference}+${ROW}}/${COL}/${REFERENCE}" ) );
4149 table->AddCell( cell );
4161 const wxString
source = ( temporary.
Path() /
"source.kicad_mod" ).string();
4164 footprint.
Value().
SetText( wxT(
"${PROPERTY.Reference}/${REFERENCE}" ) );
4173 footprint.
Add( line );
4176 footprint.
Add( constraint );
4182 for(
bool drop : {
false,
true } )
4184 const wxString destination = ( temporary.
Path() /
"out.kicad_mod" ).string();
4193 BOOST_CHECK_EQUAL( converted->Value().GetText(), wxString(
"42/${REFERENCE}" ) );
4196 for(
BOARD_ITEM* item : converted->GraphicalItems() )
4210 for(
bool drop : {
false,
true } )
4235 std::vector<EDA_TEXT*> bold;
4237 text->SetText( wxT(
"board bold" ) );
4239 bold.push_back(
text );
4241 bold.push_back( &fp->
Value() );
4243 fpText->
SetText( wxT(
"graphic bold" ) );
4245 bold.push_back( fpText );
4247 table->SetColCount( 1 );
4248 table->SetColWidth( 0, 10000000 );
4249 table->SetRowHeight( 0, 5000000 );
4251 cell->
SetText( wxT(
"cell bold" ) );
4252 table->AddCell( cell );
4254 bold.push_back( cell );
4260 board.
Add( dimension );
4261 bold.push_back( dimension );
4265 item->SetBold(
true );
4266 item->SetTextThickness( 100000 );
4270 automatic->
SetText( wxT(
"auto bold" ) );
4273 board.
Add( automatic );
4275 outline->
SetText( wxT(
"outline bold" ) );
4279 board.
Add( outline );
4285 const std::string first = ( temporary.
Path() / ( target.m_id.ToStdString() +
"-first.kicad_pcb" ) ).string();
4286 const std::string second = ( temporary.
Path() / ( target.m_id.ToStdString() +
"-second.kicad_pcb" ) ).string();
4290 BOOST_CHECK( content.find(
"(thickness 0.16)" ) != std::string::npos );
4302 reloaded->RunOnChildren(
4307 if( !reloadedText || !reloadedText->
IsBold() )
4310 if( reloadedText->
GetText() == wxT(
"auto bold" ) )
4312 else if( reloadedText->
GetText() != wxT(
"outline bold" ) || outlineAvailable )
4347 const std::string
path = ( temporary.
Path() /
"out.kicad_pcb" ).string();
4351 BOOST_REQUIRE( reloaded && reloaded->Footprints().size() == 1 );
4353 const PAD*
result = reloaded->Footprints()[0]->Pads()[0];
4364 const nlohmann::json exclusion = { {
"marker",
4365 { {
"error_type",
"DRCET_CLEARANCE" },
4366 {
"position", { {
"x_nm",
"123" }, {
"y_nm",
"-456" } } },
4368 { { {
"value",
"11111111-1111-1111-1111-111111111111" } },
4369 { {
"value",
"22222222-2222-2222-2222-222222222222" } } } } } },
4370 {
"comment",
"accepted" } };
4374 nlohmann::json doc = {
4375 {
"meta", { {
"version", 4 } } },
4377 { {
"design_settings", { {
"meta", { {
"version", 3 } } }, {
"drc_exclusions", { exclusion } } } } } }
4382 const auto& settings = doc[
"board"][
"design_settings"];
4386 settings[
"drc_exclusions"][0][0].get<std::string>(),
4387 "clearance|123|-456|11111111-1111-1111-1111-111111111111|22222222-2222-2222-2222-222222222222" );
4388 BOOST_CHECK_EQUAL( settings[
"drc_exclusions"][0][1].get<std::string>(),
"accepted" );
4390 const auto migrated = doc;
4401 nlohmann::json multiple = { {
"marker",
4402 { {
"error_type",
"DRCET_CLEARANCE" },
4403 {
"position", { {
"x_nm",
"123" }, {
"y_nm",
"-456" } } },
4405 { { {
"value",
"11111111-1111-1111-1111-111111111111" } },
4406 { {
"value",
"22222222-2222-2222-2222-222222222222" } },
4407 { {
"value",
"33333333-3333-3333-3333-333333333333" } } } } } },
4408 {
"comment",
"three items" } };
4409 nlohmann::json
unknown = multiple;
4410 unknown[
"marker"][
"error_type"] =
"DRCET_MICROVIA_STACK_DEPTH";
4411 unknown[
"marker"][
"items"].erase( 2 );
4415 nlohmann::json doc = {
4417 { {
"design_settings",
4418 { {
"meta", { {
"version", 3 } } }, {
"drc_exclusions", { multiple,
unknown,
"malformed" } } } } } }
4433 doc[
"net_settings"][
"net_chain_netclasses"] = { { {
"name",
"fast" } } };
4434 doc[
"board"][
"design_settings"][
"via_stack_presets"] = { { {
"name",
"fanout" } } };
4435 doc[
"board"][
"design_settings"][
"teardrop_parameters"] = {
4436 { {
"td_target_name",
"td_track_end" }, {
"td_enabled",
true }, {
"td_max_len", 1.0 } },
4437 { {
"td_enabled",
false } }
4441 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_netclasses" ) );
4442 const auto& settings = doc[
"board"][
"design_settings"];
4443 BOOST_CHECK( !settings.contains(
"via_stack_presets" ) );
4444 BOOST_CHECK( !settings[
"teardrop_parameters"][0].contains(
"td_enabled" ) );
4445 BOOST_CHECK( !settings[
"teardrop_parameters"][1].contains(
"td_enabled" ) );
4446 BOOST_CHECK_EQUAL( settings[
"teardrop_parameters"][0][
"td_max_len"].get<double>(), 1.0 );
4452 nlohmann::json defaults;
4453 defaults[
"net_settings"][
"net_chain_netclasses"] = nlohmann::json::array();
4454 defaults[
"board"][
"design_settings"][
"via_stack_presets"] = nlohmann::json::array();
4455 defaults[
"board"][
"design_settings"][
"teardrop_parameters"] = { { {
"td_enabled",
false } } };
4465 nlohmann::json doc = {
4466 {
"tuning_profiles",
4467 { {
"meta", { {
"version", 2 } } },
4468 {
"tuning_profiles_impedance_geometric",
4469 { { {
"net_chain_bridge_prop_delay", 25 } }, { {
"net_chain_bridge_prop_delay", 0 } } } } } }
4476 for(
const auto& profile : doc[
"tuning_profiles"][
"tuning_profiles_impedance_geometric"] )
4477 BOOST_CHECK( !profile.contains(
"net_chain_bridge_prop_delay" ) );
4486 doc[
"net_settings"][
"net_chain_classes"] = { {
"clock",
"Fast" } };
4489 BOOST_CHECK( !doc[
"net_settings"].contains(
"net_chain_classes" ) );
4494 doc[
"net_settings"][
"net_chain_classes"] = nlohmann::json::object();
4513 const wxString
name = wxString::FromUTF8( vocabulary->
m_functions[i] );
4516 [&](
const char* aBreak )
4518 return name == aBreak;
4522 const wxString rule = wxT(
"(version 1)(rule \"f\" (condition \"A." ) +
name
4523 + wxT(
"('x')\") (constraint clearance (min 0.2mm)))" );
4526 target.m_id +
" dropped a rule calling " +
name );
4532 const wxString rule = wxT(
"(version 1)(rule \"p\" (condition \"A." ) +
name
4533 + wxT(
" == 1\") (constraint clearance (min 0.2mm)))" );
4536 target.m_id +
" dropped a rule reading " +
name );
4548 target.m_name +
" has no entry in include/drc_rules_release_vocabulary.h" );
4559 for(
const wxString& property : { wxT(
"A.Priority > 1" ), wxT(
"A.Hatch_Orientation == 0" ),
4560 wxT(
"A.Line_Color == 'red'" ) } )
4563 + wxT(
"\") (constraint clearance (min 0.2mm)))" ),
4565 BOOST_CHECK_MESSAGE(
result.m_dropped.size() == 1, target.m_id +
" kept " + property );
4568 const auto kept =
FilterDrcRulesForTarget( wxT(
"(version 1)(rule \"enum\" (condition \"A.Pad_Type == 'PTH'\") "
4569 "(constraint clearance (min 0.2mm)))" ),
4582 wxT(
"(version 1)(rule \"spaced\" (constraint clearance (min 0.2 mm) (opt 0.3 mil) (max 1 in)))" ),
4584 BOOST_CHECK_MESSAGE( kept.m_dropped.empty(), target.m_id +
" dropped a rule with a spaced unit" );
4588 wxT(
"(version 1)(rule \"delay\" (constraint skew (max 5 ps)))" ), target );
4589 BOOST_CHECK_EQUAL( dropped.m_dropped.size(), target.m_id == wxT(
"9.0" ) ? 1 : 0 );
4599 const bool old = target.m_id == wxT(
"9.0" );
4602 wxT(
"(version 1)(rule \"a\" (constraint track_angle (max 45deg)))" ), target );
4608 for(
const wxString& rule : { wxT(
"(rule \"v\" (constraint clearance (min ${GAP})))" ),
4609 wxT(
"(rule \"c\" (condition \"A.NetName == '${NET}'\") "
4610 "(constraint clearance (min 0.2mm)))" ) } )
4621 for(
const wxString& expression : { wxT(
"A.hasExactNetclass('x')" ), wxT(
"A.Column_Width == 1" ),
4622 wxT(
"A.Visible == 1" ) } )
4624 const wxString rule = wxT(
"(version 1)(rule \"r\" (condition \"" ) + expression
4625 + wxT(
"\") (constraint clearance (min 0.2mm)))" );
4627 "9.0 kept " + expression +
" which not every 9.0.x release reads" );
4630 for(
const wxString& expression : { wxT(
"A.intersectsKeepout('x')" ), wxT(
"A.Origin_X == 1" ) } )
4632 const wxString rule = wxT(
"(version 1)(rule \"r\" (condition \"" ) + expression
4633 + wxT(
"\") (constraint clearance (min 0.2mm)))" );
4635 "10.0 kept " + expression +
" which not every 10.0.x release reads" );
4645 for(
const wxString& layer : { wxT(
"MyCustomLayer" ), wxT(
"F.Cu" ), wxT(
"\"In1.Cu\"" ), wxT(
"outer" ) } )
4648 + wxT(
") (constraint clearance (min 0.2mm)))" ),
4650 BOOST_CHECK_MESSAGE(
result.m_dropped.empty(), target.m_id +
" dropped a rule on layer " + layer );
4660 unknown.m_name = wxT(
"KiCad 0.0" );
4674 for(
const wxString& keyword : { wxT(
"hole_aspect_ratio" ), wxT(
"microvia_stack_depth" ) } )
4676 const wxString rule =
"(version 1)(rule \"new\" (constraint " + keyword +
" (max 2)))";
4682 for(
const wxString& call :
4683 { wxT(
"A.intersectsKeepout('x')" ), wxT(
"A.intersectsArea('x')" ), wxT(
"A.isStackedVia()" ),
4684 wxT(
"A.ISSTACKEDVIA()" ), wxT(
"A.customProperty('Owner') == 'Team'" ),
4685 wxT(
"A.hasCustomProperty('Owner')" ) } )
4687 for(
const wxString& expression : { wxT(
"condition" ), wxT(
"assertion" ) } )
4689 const wxString rule =
4690 expression == wxT(
"condition" )
4691 ?
"(rule \"new\" (condition \"" + call +
"\") (constraint clearance (min 0.2mm)))"
4692 :
"(rule \"new\" (constraint assertion \"" + call +
"\"))";
4699 const wxString kept = wxT(
"(rule \"customProperty\" (condition \"A.NetName == 'isStackedVia()'\") "
4700 "(constraint clearance (min 0.2mm)))\n"
4701 "(rule \"literal\" (condition \"A.NetName == 'intersectsArea()'\") "
4702 "(constraint clearance (min 0.2mm)))\n"
4703 "(rule \"uppercase literal\" (condition \"A.NetName == 'ISSTACKEDVIA()'\") "
4704 "(constraint clearance (min 0.2mm)))\n"
4705 "(rule \"legacy\" (condition \"A.insideArea('x')\") "
4706 "(constraint clearance (min 0.2mm)))\n"
4707 "(rule \"position\" (condition \"A.Start_X > 1mm && A.Start_Y > 1mm\") "
4708 "(constraint clearance (min 0.2mm)))" );
4721 for(
const wxString& kind : { wxT(
"condition" ), wxT(
"assertion" ) } )
4723 const wxString expression = wxT(
"A.Parent == A.Parent && A.NetName != 'A.parent.Reference'" );
4724 const wxString body =
4725 kind == wxT(
"condition" )
4726 ? wxT(
"(condition \"" ) + expression + wxT(
"\") (constraint clearance (min 0.2mm))" )
4727 : wxT(
"(constraint assertion \"" ) + expression + wxT(
"\")" );
4734 for(
const wxString& property :
4735 { wxT(
"A.Start_Shape" ), wxT(
"A.start_shape" ), wxT(
"B.End_Width" ), wxT(
"AB.Scale_X" ),
4736 wxT(
"A.parent.Reference" ), wxT(
"A . PARENT . Reference" ), wxT(
"A.Major_Radius" ),
4737 wxT(
"A.Exclude_From_Simulation" ), wxT(
"A.Automatically_Update_Net" ), wxT(
"A.Grid_Type" ) } )
4739 for(
const wxString& kind : { wxT(
"condition" ), wxT(
"assertion" ) } )
4741 const wxString expression =
4742 property + (
property.Contains( wxT(
"Reference" ) ) ? wxT(
" == 'U1'" ) : wxT(
" == 1" ) );
4743 const wxString body =
4744 kind == wxT(
"condition" )
4745 ? wxT(
"(condition \"" ) + expression + wxT(
"\") (constraint clearance (min 0.2mm))" )
4746 : wxT(
"(constraint assertion \"" ) + expression + wxT(
"\")" );
4754 for(
const wxString& property :
4755 { wxT(
"A.Corner_Radius" ), wxT(
"A.Auto_Thickness" ), wxT(
"A.Target_Delay" ) } )
4757 for(
const wxString& kind : { wxT(
"condition" ), wxT(
"assertion" ) } )
4759 const wxString expression =
property + wxT(
" == 1" );
4760 const wxString body =
4761 kind == wxT(
"condition" )
4762 ? wxT(
"(condition \"" ) + expression + wxT(
"\") (constraint clearance (min 0.2mm))" )
4763 : wxT(
"(constraint assertion \"" ) + expression + wxT(
"\")" );
4771 const wxString kept = wxT(
"(rule \"literal\" (condition \"A.NetName == 'A.Start_Shape' && A.Start_X > 1mm "
4772 "&& 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.