27#include <boost/test/unit_test.hpp>
146 prodVariant.
SetDNP(
false );
157 debugVariant.
SetDNP(
true );
178 prodVariant.
SetDNP(
true );
182 wxString token = wxS(
"DNP" );
186 token = wxS(
"DNP" );
190 token = wxS(
"EXCLUDE_FROM_SIM" );
194 token = wxS(
"EXCLUDE_FROM_SIM" );
302 prodVariant.
SetDNP(
true );
335 prodVariant.
SetDNP(
false );
358 prodVariant.
SetDNP(
false );
376 prodVariant.
SetDNP(
true );
431 wxString variantToken = wxT(
"VARIANT" );
435 wxString descToken = wxT(
"VARIANT_DESC" );
440 wxString defaultToken = wxT(
"VARIANT" );
449 "(export (version 1)\n"
453 " (footprint Resistor_SMD:R_0603_1608Metric)\n"
454 " (libsource (lib Device) (part R))\n"
456 " (variant (name Alt)\n"
457 " (property (name dnp) (value 1))\n"
458 " (property (name exclude_from_bom) (value 0))\n"
459 " (property (name exclude_from_sim) (value 1))\n"
461 " (field (name Value) \"22K\")\n"
462 " (field (name Footprint) \"Resistor_SMD:R_0805_2012Metric\")\n"
489 auto valueIt = variant->
m_fields.find(
"Value" );
493 auto fpIt = variant->
m_fields.find(
"Footprint" );
560 wxString unicodeValue = wxT(
"1kΩ ±5% 日本語" );
570 wxString specialChars = wxT(
"R<1K>\"test\"'value'" );
579 wxString unicodeDesc = wxT(
"Variante für Produktion — 测试" );
659 bool foundAlpha =
false;
660 bool foundBeta =
false;
661 bool foundZebra =
false;
663 for(
size_t i = 1; i < names.GetCount(); i++ )
665 if( names[i] == wxT(
"Alpha" ) )
667 else if( names[i] == wxT(
"Beta" ) )
669 else if( names[i] == wxT(
"Zebra" ) )
760 LIB_ID fpid( wxT(
"Resistor_SMD" ), wxT(
"R_0805_2012Metric" ) );
761 wxString reference = wxT(
"R1" );
762 wxString value = wxT(
"10K" );
764 std::vector<KIID> kiids;
771 variantA.
m_dnp =
true;
779 variantA.
m_fields[wxT(
"Datasheet" )] = wxT(
"https://example.com/datasheet.pdf" );
784 variantB.
m_dnp =
false;
792 variantB.
m_fields[wxT(
"Value" )] = wxT(
"22K" );
796 for(
const auto& [variantName, componentVariant] : component.
GetVariants() )
801 if( componentVariant.m_hasDnp )
802 fpVariant->
SetDNP( componentVariant.m_dnp );
804 if( componentVariant.m_hasExcludedFromBOM )
807 if( componentVariant.m_hasExcludedFromSim )
810 if( componentVariant.m_hasExcludedFromPosFiles )
813 for(
const auto& [fieldName, fieldValue] : componentVariant.m_fields )
826 wxT(
"https://example.com/datasheet.pdf" ) );
872 initialVariant.
SetDNP(
true );
879 LIB_ID fpid( wxT(
"Resistor_SMD" ), wxT(
"R_0805_2012Metric" ) );
881 std::vector<KIID> kiids;
882 COMPONENT component( fpid, wxT(
"R1" ), wxT(
"10K" ),
path, kiids );
885 partialVariant.
m_dnp =
true;
891 for(
const auto& [variantName, componentVariant] : component.
GetVariants() )
897 bool targetDnp = componentVariant.m_hasDnp ? componentVariant.m_dnp : fp.
IsDNP();
898 fpVariant->
SetDNP( targetDnp );
900 bool targetBOM = componentVariant.m_hasExcludedFromBOM
901 ? componentVariant.m_excludedFromBOM
905 bool targetSim = componentVariant.m_hasExcludedFromSim
906 ? componentVariant.m_excludedFromSim
910 bool targetPos = componentVariant.m_hasExcludedFromPosFiles
911 ? componentVariant.m_excludedFromPosFiles
939 fp.
SetFPID(
LIB_ID( wxT(
"Resistor_SMD" ), wxT(
"R_0805" ) ) );
952 fpVariant->
SetDNP(
true );
979 fpVariant->
SetDNP( targetDnp );
986 "DNP should be reset to base value (false) when no explicit override" );
988 "ExcludedFromBOM should be reset to base value (false) when no override" );
990 "ExcludedFromSim should be reset to base value (false) when no override" );
992 "ExcludedFromPosFiles should be reset to base (false) when no override" );
1012 std::unique_ptr<BOARD> board = pcbIo.
LoadBoard( dataPath );
1021 for(
FOOTPRINT* fp : board->Footprints() )
1023 if( fp->GetReference() == wxT(
"R2" ) )
1025 wxString fpName = fp->GetFPID().GetLibItemName();
1027 if( fpName.Contains( wxT(
"C_1210" ) ) )
1029 else if( fpName.Contains( wxT(
"C_3640" ) ) )
1048 if( c1210_variantA )
1056 BOOST_CHECK_MESSAGE( !c1210_variantA->
GetDNP(),
1057 "C_1210 Variant A DNP should be false (no schematic override)" );
1059 "C_1210 Variant A ExcludedFromBOM should be false (no override)" );
1061 "C_1210 Variant A ExcludedFromPosFiles should be false (no override)" );
1078 "C_3640 must have Variant A data to hide it when Variant A is active" );
1086 BOOST_CHECK_MESSAGE( c3640_variantA->
GetDNP(),
1087 "C_3640 Variant A DNP should be true (it is not active for Variant A)" );
1099 std::unique_ptr<BOARD> board = pcbIo.
LoadBoard( dataPath );
1113 for(
FOOTPRINT* fp : board->Footprints() )
1115 const wxString& ref = fp->GetReference();
1117 if( ref == wxT(
"R1" ) )
1128 else if( ref == wxT(
"R2" ) )
1130 wxString fpName = fp->GetFPID().GetLibItemName();
1132 if( fpName.Contains( wxT(
"C_3640" ) ) )
1140 else if( fpName.Contains( wxT(
"C_1210" ) ) )
1151 else if( ref == wxT(
"R3" ) )
1187 auto runExport = [&](
const wxString& aVariant,
bool aCsv ) -> std::string
1205 std::string defaultAscii = runExport( wxEmptyString,
false );
1206 BOOST_CHECK( defaultAscii.find(
"10K" ) != std::string::npos );
1207 BOOST_CHECK( defaultAscii.find(
"22K" ) == std::string::npos );
1209 std::string altPopAscii = runExport( wxS(
"AltPop" ),
false );
1210 BOOST_CHECK( altPopAscii.find(
"22K" ) != std::string::npos );
1211 BOOST_CHECK( altPopAscii.find(
"10K" ) == std::string::npos );
1214 std::string defaultCsv = runExport( wxEmptyString,
true );
1215 BOOST_CHECK( defaultCsv.find(
"10K" ) != std::string::npos );
1216 BOOST_CHECK( defaultCsv.find(
"22K" ) == std::string::npos );
1218 std::string altPopCsv = runExport( wxS(
"AltPop" ),
true );
1219 BOOST_CHECK( altPopCsv.find(
"22K" ) != std::string::npos );
1220 BOOST_CHECK( altPopCsv.find(
"10K" ) == std::string::npos );
1223 auto runReport = [&](
const wxString& aVariant ) -> std::string
1226 true,
true,
false,
false,
false );
1231 std::string defaultReport = runReport( wxEmptyString );
1232 BOOST_CHECK( defaultReport.find(
"10K" ) != std::string::npos );
1233 BOOST_CHECK( defaultReport.find(
"22K" ) == std::string::npos );
1235 std::string altPopReport = runReport( wxS(
"AltPop" ) );
1236 BOOST_CHECK( altPopReport.find(
"22K" ) != std::string::npos );
1237 BOOST_CHECK( altPopReport.find(
"10K" ) == std::string::npos );
1255 fp.
SetFPID(
LIB_ID( wxT(
"Capacitor_SMD" ), wxT(
"C_0805" ) ) );
1265 fpVariant->
SetDNP(
true );
1277 std::set<wxString> excessVariants;
1280 excessVariants.insert( variantName );
1285 BOOST_CHECK( excessVariants.count(
"TestVariant" ) == 1 );
1287 for(
const wxString& excess : excessVariants )
1290 BOOST_CHECK_MESSAGE( fp.
GetVariant(
"TestVariant" ) ==
nullptr,
1291 "Stale variant must be removed when netlist has no variant data" );
1293 "All variants should be cleaned up" );
1306 fp.
SetFPID(
LIB_ID( wxT(
"Package_SO" ), wxT(
"SOIC-8" ) ) );
1315 prodVariant->
SetDNP(
true );
1325 std::set<wxString> excessVariants;
1328 excessVariants.insert( variantName );
1331 excessVariants.erase(
"Production" );
1334 BOOST_CHECK( excessVariants.count(
"Debug" ) == 1 );
1336 for(
const wxString& excess : excessVariants )
1339 BOOST_CHECK_MESSAGE( fp.
GetVariant(
"Production" ) !=
nullptr,
1340 "Production variant should be preserved (in netlist)" );
1341 BOOST_CHECK_MESSAGE( fp.
GetVariant(
"Debug" ) ==
nullptr,
1342 "Debug variant should be removed (not in netlist)" );
1366 std::unique_ptr<BOARD> board = std::make_unique<BOARD>();
1367 board->SetProject( &settingsManager.
Prj() );
1368 board->AddVariant(
"Variant A" );
1381 board->Add( baseFp );
1385 variantFp->
SetFPID( variantFpid );
1386 board->Add( variantFp );
1392 netlist.AddVariant(
"Variant A" );
1395 std::vector<KIID>{
KIID() } );
1399 variantA.m_dnp =
false;
1400 variantA.m_hasDnp =
true;
1402 netlist.AddComponent( component );
1405 toolMgr.
SetEnvironment( board.get(),
nullptr,
nullptr,
nullptr,
nullptr );
1418 "Base FP must be visible in the default variant" );
1420 "Variant A FP must be hidden in the default variant (globally DNP)" );
1425 "Variant A FP must be visible when Variant A is active" );
1427 "Base FP must be hidden when Variant A is active (issue #23298)" );
1439 mgr.
SetEnvironment( &board,
nullptr,
nullptr,
nullptr,
nullptr );
1446 existing->
SetFPID(
LIB_ID(
"Resistor_SMD",
"R_0805_2012Metric" ) );
1457 unit.
m_pins = {
"1",
"2" };
1460 board.
Add( existing );
1471 commit.
Push( wxT(
"Update Footprint" ) );
General utilities for PCB file IO for QA programs.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
Update the BOARD with a new netlist.
bool UpdateNetlist(NETLIST &aNetlist)
Update the board's components according to the new netlist.
void SetWillDrag(bool aWillDrag)
void SetIsDryRun(bool aEnabled)
Enable dry run mode (just report, no changes to PCB).
void SetDeleteUnusedFootprints(bool aEnabled)
void SetReplaceFootprints(bool aEnabled)
Information pertinent to a Pcbnew printed circuit board.
void SetCurrentVariant(const wxString &aVariant)
const std::vector< wxString > & GetVariantNames() const
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
wxArrayString GetVariantNamesForUI() const
Return the variant names for UI display.
void DeleteVariant(const wxString &aVariantName)
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
bool ResolveTextVar(wxString *token, int aDepth) const
void ExchangeFootprint(FOOTPRINT *aExisting, FOOTPRINT *aNew, BOARD_COMMIT &aCommit, FLIP_DIRECTION aFlipDirection, bool aMatchPadPositions, bool aDeleteExtraTexts=true, bool aResetTextLayers=true, bool aResetTextEffects=true, bool aResetTextPositions=true, bool aResetTextContent=true, bool aResetFabricationAttrs=true, bool aResetClearanceOverrides=true, bool aReset3DModels=true, bool aResetTransform=false, bool *aUpdated=nullptr, bool *aShifted=nullptr)
Replace aExisting with aNew, preserving connectivity and metadata.
bool HasVariant(const wxString &aVariantName) const
void AddVariant(const wxString &aVariantName)
wxString GetVariantDescription(const wxString &aVariantName) const
wxString GetCurrentVariant() const
void RenameVariant(const wxString &aOldName, const wxString &aNewName)
void SetVariantDescription(const wxString &aVariantName, const wxString &aDescription)
Store all of the related component information found in a netlist.
void AddVariant(const COMPONENT_VARIANT &aVariant)
const COMPONENT_VARIANT * GetVariant(const wxString &aVariantName) const
const CASE_INSENSITIVE_MAP< COMPONENT_VARIANT > & GetVariants() const
The parser for reading the KiCad s-expression netlist format.
void Parse()
Function Parse parse the full netlist.
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
unsigned GetCount() const
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
A PCB_IO derivation for saving and loading Pcbnew s-expression formatted files.
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...
The ASCII format of the kicad place file is:
std::string GenPositionData()
build a string filled with the position data
void SetVariant(const wxString &aVariant)
Set the variant name for variant-aware export.
std::string GenReportData()
build a string filled with the pad report data This report does not used options aForceSmdItems,...
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true, bool aOverrideLock=false)
Load a project or sets up a new project with a specified path.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
bool m_excludedFromPosFiles
bool m_hasExcludedFromBOM
bool m_hasExcludedFromSim
bool m_hasExcludedFromPosFiles
nlohmann::ordered_map< wxString, wxString > m_fields
wxString GetDefaultFieldName(FIELD_T aFieldId, TRANSLATION aTranslation)
Return a default symbol field name for a mandatory field type.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
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_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_AUTO_TEST_CASE(FootprintVariantBasics)
Test FOOTPRINT_VARIANT class basic operations.