From 9f62e8847781cb0c1e8e72733c1e39916fd4a405 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 8 May 2023 10:59:13 -0400 Subject: [PATCH] Symbol Fields Table / BOM Export: handle variable resolution --- eeschema/fields_data_model.cpp | 29 +++++++++++++++++++++++------ eeschema/sch_symbol.cpp | 12 ++++++++++++ eeschema/sch_symbol.h | 9 +++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/eeschema/fields_data_model.cpp b/eeschema/fields_data_model.cpp index aaa015467b..1331e0eb56 100644 --- a/eeschema/fields_data_model.cpp +++ b/eeschema/fields_data_model.cpp @@ -139,9 +139,21 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::GetValue( const DATA_MODEL_ROW& group, i return INDETERMINATE_STATE; } + wxString refFieldValue; + + if( resolveVars ) + { + SCH_FIELD* field = ref.GetSymbol()->GetFieldByName( m_cols[aCol].m_fieldName ); + + if( field != nullptr ) + refFieldValue = field->GetShownText( &ref.GetSheetPath(), false ); + } + else + refFieldValue = m_dataStore[symbolID][m_cols[aCol].m_fieldName]; + if( &ref == &group.m_Refs.front() ) - fieldValue = m_dataStore[symbolID][m_cols[aCol].m_fieldName]; - else if( fieldValue != m_dataStore[symbolID][m_cols[aCol].m_fieldName] ) + fieldValue = refFieldValue; + else if( fieldValue != refFieldValue ) return INDETERMINATE_STATE; } } @@ -307,9 +319,6 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::groupMatch( const SCH_REFERENCE& lhRef, matchFound = true; } - const KIID& lhRefID = lhRef.GetSymbol()->m_Uuid; - const KIID& rhRefID = rhRef.GetSymbol()->m_Uuid; - // Now check all the other columns. This must be done out of the dataStore // for the refresh button to work after editing. for( size_t i = 0; i < m_cols.size(); ++i ) @@ -322,10 +331,18 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::groupMatch( const SCH_REFERENCE& lhRef, continue; wxString fieldName = m_cols[i].m_fieldName; + SCH_FIELD* lhField = lhRef.GetSymbol()->GetFieldByName( m_cols[i].m_fieldName ); + SCH_FIELD* rhField = rhRef.GetSymbol()->GetFieldByName( m_cols[i].m_fieldName ); - if( m_dataStore[lhRefID][fieldName] != m_dataStore[rhRefID][fieldName] ) + if( lhField == nullptr || rhField == nullptr ) return false; + if( lhField->GetShownText( &lhRef.GetSheetPath(), false ) + != rhField->GetShownText( &rhRef.GetSheetPath(), false ) ) + { + return false; + } + matchFound = true; } diff --git a/eeschema/sch_symbol.cpp b/eeschema/sch_symbol.cpp index fd39ffc8ac..56b6d41d28 100644 --- a/eeschema/sch_symbol.cpp +++ b/eeschema/sch_symbol.cpp @@ -912,6 +912,18 @@ SCH_FIELD* SCH_SYMBOL::GetFieldById( int aFieldId ) } +SCH_FIELD* SCH_SYMBOL::GetFieldByName( const wxString& aFieldName ) +{ + for( size_t ii = 0; ii < m_fields.size(); ++ii ) + { + if( m_fields[ii].GetName() == aFieldName ) + return &m_fields[ii]; + } + + return nullptr; +} + + wxString SCH_SYMBOL::GetFieldText( const wxString& aFieldName ) const { for( const SCH_FIELD& field : m_fields ) diff --git a/eeschema/sch_symbol.h b/eeschema/sch_symbol.h index 63e7aad8c6..ecca105505 100644 --- a/eeschema/sch_symbol.h +++ b/eeschema/sch_symbol.h @@ -405,6 +405,15 @@ public: */ SCH_FIELD* GetFieldById( int aFieldId ); + /** + * Return a field in this symbol. + * + * @param aFieldName is the name of the field + * + * @return is the field with \a aFieldName or NULL if the field does not exist. + */ + SCH_FIELD* GetFieldByName( const wxString& aFieldName ); + /** * Search for a field named \a aFieldName and returns text associated with this field. *