From 2dac73e4216711138fb9788da5fef97f1e8c9015 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 3 Nov 2022 11:20:29 +0000 Subject: [PATCH] Remove dangerous SCH_FIELD::IsVoid() call. This call didn't differentiate between GetText() and GetShownText() and was used in instances where the difference matters. --- .../netlist_exporter_xml.cpp | 34 ++++++++----------- eeschema/sch_field.cpp | 14 +++----- eeschema/sch_field.h | 5 --- eeschema/sch_painter.cpp | 5 +-- eeschema/sch_symbol.cpp | 9 +++-- 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/eeschema/netlist_exporters/netlist_exporter_xml.cpp b/eeschema/netlist_exporters/netlist_exporter_xml.cpp index e59d8963e5..d1fe1ddf7a 100644 --- a/eeschema/netlist_exporters/netlist_exporter_xml.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_xml.cpp @@ -95,6 +95,7 @@ void NETLIST_EXPORTER_XML::addSymbolFields( XNODE* aNode, SCH_SYMBOL* aSymbol, wxString value; wxString datasheet; wxString footprint; + wxString candidate; std::map 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 ) { diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 18b29723aa..93c40500ee 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -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(); diff --git a/eeschema/sch_field.h b/eeschema/sch_field.h index 6a0e30694e..b756e330be 100644 --- a/eeschema/sch_field.h +++ b/eeschema/sch_field.h @@ -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; /** diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index cae06ee418..20b2e95829 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -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(); diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index f58caa884f..c2bd8bc88b 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -932,8 +932,13 @@ void SCH_SYMBOL::GetFields( std::vector& 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 ); } }