44#include <wx/filename.h>
45#include <wx/xml/xml.h>
51wxXmlNode* findChild( wxXmlNode* aParent,
const wxString& aName )
53 for( wxXmlNode* child = aParent->GetChildren(); child; child = child->GetNext() )
55 if( child->GetName() == aName )
63wxXmlNode* findComponent( wxXmlNode* aRoot,
const wxString& aRef )
65 wxXmlNode* components = findChild( aRoot, wxT(
"components" ) );
69 for( wxXmlNode*
comp = components->GetChildren();
comp;
comp =
comp->GetNext() )
71 if(
comp->GetName() == wxT(
"comp" ) &&
comp->GetAttribute( wxT(
"ref" ) ) == aRef )
79wxString componentValue( wxXmlNode* aRoot,
const wxString& aRef )
81 wxXmlNode*
comp = findComponent( aRoot, aRef );
85 wxXmlNode* value = findChild(
comp, wxT(
"value" ) );
89 return value->GetNodeContent();
93bool hasProperty( wxXmlNode* aRoot,
const wxString& aRef,
const wxString& aName )
95 wxXmlNode*
comp = findComponent( aRoot, aRef );
99 for( wxXmlNode* prop =
comp->GetChildren(); prop; prop = prop->GetNext() )
101 if( prop->GetName() == wxT(
"property" ) && prop->GetAttribute( wxT(
"name" ) ) == aName )
109struct BOM_NETLIST_FIXTURE
111 BOM_NETLIST_FIXTURE()
119 m_netlistFile = wxFileName::CreateTempFileName( wxS(
"kicad_issue25119" ) );
123 ~BOM_NETLIST_FIXTURE()
125 if( wxFileExists( m_netlistFile ) )
126 wxRemoveFile( m_netlistFile );
129 void WriteBomNetlist( wxXmlDocument& aDoc )
132 NETLIST_EXPORTER_XML exporter( m_schematic );
141 wxString m_netlistFile;
149 m_schematic->SetCurrentVariant( wxS(
"H0" ) );
151 BOOST_REQUIRE_EQUAL( m_schematic->GetCurrentVariant(), wxS(
"H0" ) );
154 WriteBomNetlist( doc );
156 BOOST_CHECK_MESSAGE( !findChild( findComponent( doc.GetRoot(), wxS(
"R1" ) ), wxS(
"variants" ) ),
157 "resolved BOM netlist must not carry base-relative variant deltas" );
162 BOOST_CHECK_MESSAGE( hasProperty( doc.GetRoot(), wxS(
"R2" ), wxS(
"dnp" ) ),
"R2 should be DNP in variant H0" );
163 BOOST_CHECK_MESSAGE( hasProperty( doc.GetRoot(), wxS(
"R3" ), wxS(
"dnp" ) ),
"R3 should be DNP in variant H0" );
164 BOOST_CHECK_MESSAGE( !hasProperty( doc.GetRoot(), wxS(
"R1" ), wxS(
"dnp" ) ),
165 "R1 should not be DNP in variant H0" );
172 WriteBomNetlist( doc );
176 BOOST_CHECK( !hasProperty( doc.GetRoot(), wxS(
"R2" ), wxS(
"dnp" ) ) );
187 if(
static_cast<SCH_SYMBOL*
>( item )->GetRef( &sheet ) == wxS(
"R1" ) )
197 m_schematic->SetCurrentVariant( wxS(
"H0" ) );
198 BOOST_REQUIRE_EQUAL( m_schematic->GetCurrentVariant(), wxS(
"H0" ) );
201 WriteBomNetlist( doc );
203 BOOST_CHECK_MESSAGE( hasProperty( doc.GetRoot(), wxS(
"R1" ), wxS(
"exclude_from_board" ) ),
204 "R1 is excluded from the board in variant H0" );
206 m_schematic->SetCurrentVariant( wxEmptyString );
208 wxXmlDocument baseDoc;
209 WriteBomNetlist( baseDoc );
211 BOOST_CHECK_MESSAGE( !hasProperty( baseDoc.GetRoot(), wxS(
"R1" ), wxS(
"exclude_from_board" ) ),
212 "the base design must be unaffected" );
218 m_schematic->SetCurrentVariant( wxS(
"H0" ) );
219 BOOST_REQUIRE_EQUAL( m_schematic->GetCurrentVariant(), wxS(
"H0" ) );
226 wxFFile file( m_netlistFile, wxS(
"rb" ) );
232 BOOST_CHECK_MESSAGE(
netlist.Contains( wxS(
"(value \"6k2\")" ) ),
"board netlist must keep R1's base value" );
233 BOOST_CHECK_MESSAGE( !
netlist.Contains( wxS(
"(value \"10k\")" ) ),
234 "board netlist must not resolve the variant into the base value" );
236 BOOST_CHECK_MESSAGE(
netlist.Contains( wxS(
"(name \"Value\") \"10k\"" ) ),
237 "board netlist must still carry R1's variant override for pcbnew" );
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true, REPORTER *aRootReporter=nullptr)
EE_TYPE OfType(KICAD_T aType) const
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter)
Write to specified output file.
Generate the KiCad netlist format supported by Pcbnew.
Base class for any item which can be embedded within the SCHEMATIC container class,...
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
void SetExcludedFromBoard(bool aEnable, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
A wrapper for reporting to a wxString object.
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(Issue25119_BomNetlistFollowsCurrentVariant, BOM_NETLIST_FIXTURE)
IbisParser parser & reporter
BOOST_CHECK_EQUAL(result, "25.4")