Require client to specify whether they want resolved values or not.

Fixes https://gitlab.com/kicad/code/kicad/issues/6408
This commit is contained in:
Jeff Young 2020-11-17 21:36:17 +00:00
parent 54427fd594
commit c89676e39d
10 changed files with 51 additions and 44 deletions

View File

@ -215,13 +215,13 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
if( symbol->GetUnitCount() > 1 )
msg.Printf( _( "Updated %s (unit %s) from %s to %s" ),
symbol->GetValue( sheet ),
symbol->GetValue( sheet, true ),
LIB_PART::SubReference( symbol->GetUnit(), false ),
prevRef,
newRef );
else
msg.Printf( _( "Updated %s from %s to %s" ),
symbol->GetValue( sheet ),
symbol->GetValue( sheet, true ),
prevRef,
newRef );
}
@ -229,12 +229,12 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
{
if( symbol->GetUnitCount() > 1 )
msg.Printf( _( "Annotated %s (unit %s) as %s" ),
symbol->GetValue( sheet ),
symbol->GetValue( sheet, true ),
LIB_PART::SubReference( symbol->GetUnit(), false ),
newRef );
else
msg.Printf( _( "Annotated %s as %s" ),
symbol->GetValue( sheet ),
symbol->GetValue( sheet, true ),
newRef );
}

View File

@ -665,11 +665,11 @@ SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aSymbol, LIB_PART* aLibPart,
{
wxASSERT( aSymbol != NULL );
m_rootSymbol = aSymbol;
m_libPart = aLibPart; // Warning: can be nullptr for orphan components
// (i.e. with a symbol library not found)
m_rootSymbol = aSymbol;
m_libPart = aLibPart; // Warning: can be nullptr for orphan components
// (i.e. with a symbol library not found)
m_unit = aSymbol->GetUnitSelection( &aSheetPath );
m_footprint = aSymbol->GetFootprint( &aSheetPath );
m_footprint = aSymbol->GetFootprint( &aSheetPath, true );
m_sheetPath = aSheetPath;
m_isNew = false;
m_flag = 0;
@ -685,10 +685,10 @@ SCH_REFERENCE::SCH_REFERENCE( SCH_COMPONENT* aSymbol, LIB_PART* aLibPart,
m_numRef = -1;
if( aSymbol->GetValue( &aSheetPath ).IsEmpty() )
if( aSymbol->GetValue( &aSheetPath, false ).IsEmpty() )
aSymbol->SetValue( &aSheetPath, wxT( "~" ) );
m_value = aSymbol->GetValue( &aSheetPath );
m_value = aSymbol->GetValue( &aSheetPath, false );
}

View File

@ -72,7 +72,7 @@ DIALOG_CHANGE_SYMBOLS::DIALOG_CHANGE_SYMBOLS( SCH_EDIT_FRAME* aParent, SCH_COMPO
m_newId->AppendText( FROM_UTF8( m_symbol->GetLibId().Format().c_str() ) );
m_specifiedReference->ChangeValue( m_symbol->GetRef( currentSheet ) );
m_specifiedValue->ChangeValue( m_symbol->GetValue( currentSheet ) );
m_specifiedValue->ChangeValue( m_symbol->GetValue( currentSheet, false ) );
m_specifiedId->ChangeValue( FROM_UTF8( m_symbol->GetLibId().Format().c_str() ) );
}
else
@ -352,13 +352,13 @@ bool DIALOG_CHANGE_SYMBOLS::isMatch( SCH_COMPONENT* aSymbol, SCH_SHEET_PATH* aIn
}
else if( m_matchByReference->GetValue() )
{
return WildCompareString( m_specifiedReference->GetValue(), aSymbol->GetRef( aInstance ),
false );
return WildCompareString( m_specifiedReference->GetValue(),
aSymbol->GetRef( aInstance, false ), false );
}
else if( m_matchByValue->GetValue() )
{
return WildCompareString( m_specifiedValue->GetValue(), aSymbol->GetValue( aInstance ),
false );
return WildCompareString( m_specifiedValue->GetValue(),
aSymbol->GetValue( aInstance, false ), false );
}
else if( m_matchById )
{

View File

@ -87,7 +87,7 @@ bool NETLIST_EXPORTER_CADSTAR::WriteNetlist( const wxString& aOutFileName, unsig
ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
ret |= fprintf( f, "%s", TO_UTF8( msg ) );
msg = symbol->GetValue( &sheetList[i] );
msg = symbol->GetValue( &sheetList[i], true );
msg.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
ret |= fprintf( f, " \"%s\"", TO_UTF8( footprint ) );

View File

@ -82,7 +82,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
if( comp->GetPartRef() && comp->GetPartRef()->GetFootprints().GetCount() != 0 )
cmpList.push_back( SCH_REFERENCE( comp, comp->GetPartRef().get(), sheet ) );
footprint = comp->GetFootprint( &sheet );
footprint = comp->GetFootprint( &sheet, true );
footprint.Replace( wxT( " " ), wxT( "_" ) );
if( footprint.IsEmpty() )
@ -96,7 +96,7 @@ bool NETLIST_EXPORTER_ORCADPCB2::WriteNetlist( const wxString& aOutFileName,
ret |= fprintf( f, " %s", TO_UTF8( field ) );
field = comp->GetValue( &sheet );
field = comp->GetValue( &sheet, true );
field.Replace( wxT( " " ), wxT( "_" ) );
ret |= fprintf( f, " %s", TO_UTF8( field ) );

View File

@ -121,22 +121,16 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_COMPONENT* aSymbol
// The lowest unit number wins. User should only set fields in any one unit.
// remark: IsVoid() returns true for empty strings or the "~" string (empty
// field value)
if( !comp2->GetValue( &sheetList[i] ).IsEmpty()
if( !comp2->GetValue( &sheetList[i], m_resolveTextVars ).IsEmpty()
&& ( unit < minUnit || fields.value.IsEmpty() ) )
{
if( m_resolveTextVars )
fields.value = comp2->GetValue( &sheetList[i] );
else
fields.value = comp2->GetField( VALUE_FIELD )->GetText();
fields.value = comp2->GetValue( &sheetList[i], m_resolveTextVars );
}
if( !comp2->GetFootprint( &sheetList[i] ).IsEmpty()
if( !comp2->GetFootprint( &sheetList[i], m_resolveTextVars ).IsEmpty()
&& ( unit < minUnit || fields.footprint.IsEmpty() ) )
{
if( m_resolveTextVars )
fields.footprint = comp2->GetFootprint( &sheetList[i] );
else
fields.footprint = comp2->GetField( FOOTPRINT_FIELD )->GetText();
fields.footprint = comp2->GetFootprint( &sheetList[i], m_resolveTextVars );
}
if( !comp2->GetField( DATASHEET_FIELD )->IsVoid()

View File

@ -567,7 +567,7 @@ void SCH_COMPONENT::SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSel
}
const wxString SCH_COMPONENT::GetValue( const SCH_SHEET_PATH* sheet ) const
const wxString SCH_COMPONENT::GetValue( const SCH_SHEET_PATH* sheet, bool aResolve ) const
{
KIID_PATH path = sheet->Path();
@ -575,12 +575,18 @@ const wxString SCH_COMPONENT::GetValue( const SCH_SHEET_PATH* sheet ) const
{
if( instance.m_Path == path && !instance.m_Value.IsEmpty() )
{
if( !aResolve )
return instance.m_Value;
SCH_FIELD dummy( wxDefaultPosition, VALUE_FIELD, const_cast<SCH_COMPONENT*>( this ) );
dummy.SetText( instance.m_Value );
return dummy.GetShownText();
}
}
if( !aResolve )
return GetField( VALUE_FIELD )->GetText();
return GetField( VALUE_FIELD )->GetShownText();
}
@ -614,7 +620,7 @@ void SCH_COMPONENT::SetValue( const SCH_SHEET_PATH* sheet, const wxString& aValu
}
const wxString SCH_COMPONENT::GetFootprint( const SCH_SHEET_PATH* sheet ) const
const wxString SCH_COMPONENT::GetFootprint( const SCH_SHEET_PATH* sheet, bool aResolve ) const
{
KIID_PATH path = sheet->Path();
@ -622,12 +628,18 @@ const wxString SCH_COMPONENT::GetFootprint( const SCH_SHEET_PATH* sheet ) const
{
if( instance.m_Path == path && !instance.m_Footprint.IsEmpty() )
{
if( !aResolve )
return instance.m_Footprint;
SCH_FIELD dummy( wxDefaultPosition, FOOTPRINT_FIELD, const_cast<SCH_COMPONENT*>( this ) );
dummy.SetText( instance.m_Footprint );
return dummy.GetShownText();
}
}
if( !aResolve )
return GetField( FOOTPRINT_FIELD )->GetText();
return GetField( FOOTPRINT_FIELD )->GetShownText();
}
@ -915,9 +927,9 @@ bool SCH_COMPONENT::ResolveTextVar( wxString* token, int aDepth ) const
if( i == REFERENCE_FIELD && schematic )
*token = GetRef( &schematic->CurrentSheet(), true );
else if( i == VALUE_FIELD && schematic )
*token = GetValue( &schematic->CurrentSheet() );
*token = GetValue( &schematic->CurrentSheet(), true );
else if( i == FOOTPRINT_FIELD && schematic )
*token = GetFootprint( &schematic->CurrentSheet() );
*token = GetFootprint( &schematic->CurrentSheet(), true );
else
*token = m_fields[ i ].GetShownText( aDepth + 1 );
@ -940,7 +952,7 @@ bool SCH_COMPONENT::ResolveTextVar( wxString* token, int aDepth ) const
wxString footprint;
if( schematic )
footprint = GetFootprint( &schematic->CurrentSheet() );
footprint = GetFootprint( &schematic->CurrentSheet(), true );
else
footprint = m_fields[ FOOTPRINT_FIELD ].GetShownText();
@ -954,7 +966,7 @@ bool SCH_COMPONENT::ResolveTextVar( wxString* token, int aDepth ) const
wxString footprint;
if( schematic )
footprint = GetFootprint( &schematic->CurrentSheet() );
footprint = GetFootprint( &schematic->CurrentSheet(), true );
else
footprint = m_fields[ FOOTPRINT_FIELD ].GetShownText();
@ -1343,7 +1355,7 @@ void SCH_COMPONENT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aL
msg = m_part->IsPower() ? _( "Power symbol" ) : _( "Value" );
aList.push_back( MSG_PANEL_ITEM( msg, GetValue( currentSheet ), DARKCYAN ) );
aList.push_back( MSG_PANEL_ITEM( msg, GetValue( currentSheet, true ), DARKCYAN ) );
#if 0 // Display component flags, for debug only
aList.push_back( MSG_PANEL_ITEM( _( "flags" ),
@ -1375,7 +1387,7 @@ void SCH_COMPONENT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aL
}
// Display the current associated footprint, if exists.
msg = GetFootprint( currentSheet );
msg = GetFootprint( currentSheet, true );
if( msg.IsEmpty() )
msg = _( "<Unknown>" );
@ -1392,7 +1404,7 @@ void SCH_COMPONENT::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aL
{
aList.push_back( MSG_PANEL_ITEM( _( "Reference" ), GetRef( currentSheet ), DARKCYAN ) );
aList.push_back( MSG_PANEL_ITEM( _( "Value" ), GetValue( currentSheet ), DARKCYAN ) );
aList.push_back( MSG_PANEL_ITEM( _( "Value" ), GetValue( currentSheet, true ), DARKCYAN ) );
aList.push_back( MSG_PANEL_ITEM( _( "Name" ), GetLibId().GetLibItemName(), BROWN ) );
wxString libNickname = GetLibId().GetLibNickname();

View File

@ -554,7 +554,7 @@ public:
void SetUnitSelection( const SCH_SHEET_PATH* aSheet, int aUnitSelection );
// Returns the instance-specific value for the given sheet path.
const wxString GetValue( const SCH_SHEET_PATH* sheet ) const;
const wxString GetValue( const SCH_SHEET_PATH* sheet, bool aResolve ) const;
void SetValue( const SCH_SHEET_PATH* sheet, const wxString& aValue );
// Set the value for all instances (the default GUI behaviour)
@ -564,7 +564,7 @@ public:
}
// Returns the instance-specific footprint assignment for the given sheet path.
const wxString GetFootprint( const SCH_SHEET_PATH* sheet ) const;
const wxString GetFootprint( const SCH_SHEET_PATH* sheet, bool aResolve ) const;
void SetFootprint( const SCH_SHEET_PATH* sheet, const wxString& aFootprint );
// Set the value for all instances (the default GUI behaviour)

View File

@ -201,7 +201,8 @@ void SCH_PIN::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList )
SCH_SHEET_PATH* currentSheet = schframe ? &schframe->GetCurrentSheet() : nullptr;
SCH_COMPONENT* symbol = GetParentSymbol();
aList.emplace_back( symbol->GetRef( currentSheet ), symbol->GetValue( currentSheet ), DARKCYAN );
aList.emplace_back( symbol->GetRef( currentSheet ), symbol->GetValue( currentSheet, true ),
DARKCYAN );
#if defined(DEBUG)

View File

@ -249,12 +249,12 @@ wxString SCH_SHEET_PATH::PathHumanReadable( bool aUseShortRootName ) const
void SCH_SHEET_PATH::UpdateAllScreenReferences()
{
for( auto item : LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
{
auto component = static_cast<SCH_COMPONENT*>( item );
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
component->GetField( REFERENCE_FIELD )->SetText( component->GetRef( this ) );
component->GetField( VALUE_FIELD )->SetText( component->GetValue( this ) );
component->GetField( FOOTPRINT_FIELD )->SetText( component->GetFootprint( this ) );
component->GetField( VALUE_FIELD )->SetText( component->GetValue( this, false ) );
component->GetField( FOOTPRINT_FIELD )->SetText( component->GetFootprint( this, false ) );
component->UpdateUnit( component->GetUnitSelection( this ) );
}
}