39 fn.AppendDir( wxS(
"variant_field_resolution" ) );
40 fn.SetName( wxS(
"variant_field_resolution" ) );
55 if( sym->
GetRef( &hierarchy[0] ) == wxS(
"R1" ) )
67 auto& instances =
const_cast<std::vector<SCH_SYMBOL_INSTANCE>&
>(
72 if( inst.m_Path ==
path )
80 const wxString& aLibIdStr )
92 const wxString& aFieldName,
const wxString& aValue )
97 inst->
m_Variants[aVariantName].m_Fields[aFieldName] = aValue;
122 r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0], wxEmptyString );
129 SetVariantField( r1, wxS(
"ExplicitOnly" ), wxS(
"Value" ), wxS(
"220R" ) );
131 wxString value = r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0],
132 wxS(
"ExplicitOnly" ) );
139 SetVariantField( r1, wxS(
"Multi" ), wxS(
"Value" ), wxS(
"470R" ) );
140 SetVariantField( r1, wxS(
"Multi" ), wxS(
"MPN" ), wxS(
"CUSTOM-MPN-123" ) );
142 wxString value = r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0],
145 r1->
GetFieldText( wxS(
"MPN" ), &m_schematic->Hierarchy()[0], wxS(
"Multi" ) );
154 SetVariantField( r1, wxS(
"RefTest" ), wxS(
"Value" ), wxS(
"999R" ) );
156 wxString ref = r1->
GetFieldText( wxS(
"Reference" ), &m_schematic->Hierarchy()[0],
165 SetupVariantWithSymbolOverride( r1, wxS(
"BadAlt" ),
166 wxS(
"nonexistent_lib:no_such_symbol" ) );
168 wxString value = r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0],
177 wxString value = r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0],
178 wxS(
"NoSuchVariant" ) );
185 SetVariantField( r1, wxS(
"FPTest" ), wxS(
"Footprint" ),
186 wxS(
"Resistor_SMD:R_0805_2012Metric" ) );
188 wxString fp = r1->
GetFieldText( wxS(
"Footprint" ), &m_schematic->Hierarchy()[0],
196 SetVariantField( r1, wxS(
"NoFP" ), wxS(
"Value" ), wxS(
"330R" ) );
198 wxString fp = r1->
GetFieldText( wxS(
"Footprint" ), &m_schematic->Hierarchy()[0],
206 SetVariantField( r1, wxS(
"VarA" ), wxS(
"Value" ), wxS(
"1K" ) );
207 SetVariantField( r1, wxS(
"VarB" ), wxS(
"Value" ), wxS(
"10K" ) );
210 r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0], wxS(
"VarA" ) );
212 r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0], wxS(
"VarB" ) );
221 SetVariantField( r1, wxS(
"CacheA" ), wxS(
"Value" ), wxS(
"FIRST" ) );
223 wxString value1 = r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0],
228 SetVariantField( r1, wxS(
"CacheA" ), wxS(
"Value" ), wxS(
"SECOND" ) );
230 wxString value2 = r1->
GetFieldText( wxS(
"Value" ), &m_schematic->Hierarchy()[0],
250 SetupVariantWithSymbolOverride( r1, wxS(
"RoundTrip" ), wxS(
"variant_test_lib:R_10K" ) );
252 wxString resolved = r1->
GetFieldText( wxS(
"Value" ), &sheet, wxS(
"RoundTrip" ) );
253 r1->
SetFieldText( wxS(
"Value" ), resolved, &sheet, wxS(
"RoundTrip" ) );
255 std::optional<SCH_SYMBOL_VARIANT> variant = r1->
GetVariant( sheet, wxS(
"RoundTrip" ) );
257 BOOST_CHECK( !variant->m_Fields.contains( wxS(
"Value" ) ) );
262 r1->
SetFieldText( wxS(
"Value" ), wxS(
"EDITED" ), &sheet, wxS(
"RoundTrip" ) );
264 std::optional<SCH_SYMBOL_VARIANT> variant = r1->
GetVariant( sheet, wxS(
"RoundTrip" ) );
266 BOOST_CHECK( variant->m_Fields.contains( wxS(
"Value" ) ) );
268 wxString baseValue = r1->
GetFieldText( wxS(
"Value" ), &sheet, wxEmptyString );
269 r1->
SetFieldText( wxS(
"Value" ), baseValue, &sheet, wxS(
"RoundTrip" ) );
271 variant = r1->
GetVariant( sheet, wxS(
"RoundTrip" ) );
273 BOOST_CHECK( !variant->m_Fields.contains( wxS(
"Value" ) ) );
291 SetVariantField( r1, wxS(
"TextVars" ), wxS(
"Value" ), wxS(
"${MPN}-ALT" ) );
292 SetVariantField( r1, wxS(
"TextVars" ), wxS(
"Description" ), wxS(
"${MPN}-DESC" ) );
294 const wxString mpn = r1->
GetFieldText( wxS(
"MPN" ), &sheet, wxEmptyString );
303 m_schematic->AddVariant( wxS(
"TextVars" ) );
304 SetVariantField( r1, wxS(
"TextVars" ), wxS(
"MPN" ), wxS(
"REQUESTED-MPN" ) );
306 description->
SetText( wxS(
"${MPN}-BASE-DESC" ) );
308 for(
const wxString& active : { wxString(), wxString(
"TextVars" ) } )
310 m_schematic->SetCurrentVariant( active );
312 for(
const wxString& requested : { wxString(), wxString(
"TextVars" ) } )
316 const wxString expectedMpn = requested.empty() ? mpn : wxString(
"REQUESTED-MPN" );
317 const wxString expectedValue = expectedMpn + ( requested.empty() ?
"-BASE" :
"-ALT" );
318 const wxString expectedDescription = expectedMpn + ( requested.empty() ?
"-BASE-DESC" :
"-DESC" );
EE_TYPE OfType(KICAD_T aType) const
A generic fixture for loading schematics and associated settings for qa tests.
std::unique_ptr< SCHEMATIC > m_schematic
virtual void LoadSchematic(const wxFileName &aFn)
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.
virtual const wxString & GetText() const override
Return the string associated with the text object.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
EE_RTREE & Items()
Get the full RTree, usually for iterating.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Variant information for a schematic symbol.
std::optional< LIB_ID > m_SymbolOverride
Alternate library symbol to substitute for the base symbol in this variant, if any.
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
void SetFieldText(const wxString &aFieldName, const wxString &aFieldText, const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariantName=wxEmptyString)
wxString GetFieldText(const wxString &aFieldName, const SCH_SHEET_PATH *aPath=nullptr, const wxString &aVariantName=wxEmptyString) const
void ClearCaches() override
std::optional< SCH_SYMBOL_VARIANT > GetVariant(const SCH_SHEET_PATH &aInstance, const wxString &aVariantName) const
const wxString GetValue(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const override
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
void SetVariantField(SCH_SYMBOL *aSymbol, const wxString &aVariantName, const wxString &aFieldName, const wxString &aValue)
void SetupVariantWithSymbolOverride(SCH_SYMBOL *aSymbol, const wxString &aVariantName, const wxString &aLibIdStr)
SCH_SYMBOL_INSTANCE * GetMutableInstance(SCH_SYMBOL *aSymbol)
void ClearVariants(SCH_SYMBOL *aSymbol)
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_FIXTURE_TEST_CASE(VariantFieldResolution, TEST_VARIANT_FIELD_RESOLUTION_FIXTURE)
Definition of file extensions used in Kicad.