Remove dangerous SCH_FIELD::IsVoid() call.

This call didn't differentiate between GetText() and GetShownText() and
was used in instances where the difference matters.
This commit is contained in:
Jeff Young 2022-11-03 11:20:29 +00:00
parent e33c611488
commit 2dac73e421
5 changed files with 28 additions and 39 deletions

View File

@ -95,6 +95,7 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol,
wxString value;
wxString datasheet;
wxString footprint;
wxString candidate;
std::map<wxString, wxString> userFields;
if( aSymbol->GetUnitCount() > 1 )
@ -125,28 +126,21 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol,
int unit = symbol2->GetUnitSelection( aSheet );
// 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( !symbol2->GetValue( &sheetList[i], m_resolveTextVars ).IsEmpty()
&& ( unit < minUnit || value.IsEmpty() ) )
{
value = symbol2->GetValue( &sheetList[i], m_resolveTextVars );
}
candidate = symbol2->GetValue( &sheetList[i], m_resolveTextVars );
if( !symbol2->GetFootprint( &sheetList[i], m_resolveTextVars ).IsEmpty()
&& ( unit < minUnit || footprint.IsEmpty() ) )
{
footprint = symbol2->GetFootprint( &sheetList[i], m_resolveTextVars );
}
if( !candidate.IsEmpty() && ( unit < minUnit || value.IsEmpty() ) )
value = candidate;
if( !symbol2->GetField( DATASHEET_FIELD )->IsVoid()
&& ( unit < minUnit || datasheet.IsEmpty() ) )
{
if( m_resolveTextVars )
datasheet = symbol2->GetField( DATASHEET_FIELD )->GetShownText();
else
datasheet = symbol2->GetField( DATASHEET_FIELD )->GetText();
}
candidate = symbol2->GetFootprint( &sheetList[i], m_resolveTextVars );
if( !candidate.IsEmpty() && ( unit < minUnit || footprint.IsEmpty() ) )
footprint = candidate;
candidate = m_resolveTextVars ? symbol2->GetField( DATASHEET_FIELD )->GetShownText()
: symbol2->GetField( DATASHEET_FIELD )->GetText();
if( !candidate.IsEmpty() && ( unit < minUnit || datasheet.IsEmpty() ) )
datasheet = candidate;
for( int ii = MANDATORY_FIELDS; ii < symbol2->GetFieldCount(); ++ii )
{

View File

@ -339,7 +339,7 @@ void SCH_FIELD::Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset
VECTOR2I textpos;
int penWidth = GetEffectiveTextPenWidth( aSettings->GetDefaultPenWidth() );
if( ( !IsVisible() && !IsForceVisible() ) || IsVoid() )
if( ( !IsVisible() && !IsForceVisible() ) || GetShownText().IsEmpty() )
return;
COLOR4D bg = aSettings->GetBackgroundColor();
@ -575,12 +575,6 @@ GR_TEXT_V_ALIGN_T SCH_FIELD::GetEffectiveVertJustify() const
}
bool SCH_FIELD::IsVoid() const
{
return GetText().Len() == 0;
}
bool SCH_FIELD::Matches( const EDA_SEARCH_DATA& aSearchData, void* aAuxData ) const
{
bool searchHiddenFields = false;
@ -927,7 +921,7 @@ BITMAPS SCH_FIELD::GetMenuImage() const
bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
{
// Do not hit test hidden or empty fields.
if( !IsVisible() || IsVoid() )
if( !IsVisible() || GetShownText().IsEmpty() )
return false;
BOX2I rect = GetBoundingBox();
@ -947,7 +941,7 @@ bool SCH_FIELD::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
{
// Do not hit test hidden fields.
if( !IsVisible() || IsVoid() )
if( !IsVisible() || GetShownText().IsEmpty() )
return false;
BOX2I rect = aRect;
@ -969,7 +963,7 @@ bool SCH_FIELD::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) co
void SCH_FIELD::Plot( PLOTTER* aPlotter, bool aBackground ) const
{
if( IsVoid() || aBackground )
if( GetShownText().IsEmpty() || aBackground )
return;
RENDER_SETTINGS* settings = aPlotter->RenderSettings();

View File

@ -152,11 +152,6 @@ public:
bool CanAutoplace() const { return m_allowAutoPlace; }
void SetCanAutoplace( bool aCanPlace ) { m_allowAutoPlace = aCanPlace; }
/**
* @return true if the field is either empty or holds "~".
*/
bool IsVoid() const;
void SwapData( SCH_ITEM* aItem ) override;
/**

View File

@ -2269,7 +2269,9 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
return;
}
if( aField->IsVoid() )
wxString shownText = aField->GetShownText();
if( shownText.IsEmpty() )
return;
if( drawingShadows && !eeconfig()->m_Selection.draw_selected_children )
@ -2323,7 +2325,6 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed )
}
else
{
wxString shownText = aField->GetShownText();
VECTOR2I textpos = bbox.Centre();
TEXT_ATTRIBUTES attributes = aField->GetAttributes();

View File

@ -932,8 +932,13 @@ void SCH_SYMBOL::GetFields( std::vector<SCH_FIELD*>& aVector, bool aVisibleOnly
{
for( SCH_FIELD& field : m_fields )
{
if( !aVisibleOnly || ( field.IsVisible() && !field.IsVoid() ) )
aVector.push_back( &field );
if( aVisibleOnly )
{
if( !field.IsVisible() || field.GetShownText().IsEmpty() )
continue;
}
aVector.push_back( &field );
}
}