Symbol Fields Table: API cleanups for non-modal window

This commit is contained in:
Mike Williams 2023-08-14 10:36:18 -04:00
parent f45760062b
commit 1c52a60270
4 changed files with 49 additions and 31 deletions

View File

@ -22,22 +22,24 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::AddColumn( const wxString& aFieldName, const
m_cols.push_back( { aFieldName, aLabel, aAddedByUser, false, false } ); m_cols.push_back( { aFieldName, aLabel, aAddedByUser, false, false } );
for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i ) for( unsigned i = 0; i < m_symbolsList.GetCount(); ++i )
{
if( SCH_SYMBOL* symbol = m_symbolsList[i].GetSymbol() ) if( SCH_SYMBOL* symbol = m_symbolsList[i].GetSymbol() )
{ updateDataStoreSymbolField( *symbol, aFieldName );
if( SCH_FIELD* field = symbol->GetFieldByName( aFieldName ) ) }
m_dataStore[symbol->m_Uuid][aFieldName] = field->GetText();
void FIELDS_EDITOR_GRID_DATA_MODEL::updateDataStoreSymbolField( const SCH_SYMBOL& aSymbol,
const wxString& aFieldName )
{
if( const SCH_FIELD* field = aSymbol.GetFieldByName( aFieldName ) )
m_dataStore[aSymbol.m_Uuid][aFieldName] = field->GetText();
else if( isAttribute( aFieldName ) ) else if( isAttribute( aFieldName ) )
m_dataStore[symbol->m_Uuid][aFieldName] = m_dataStore[aSymbol.m_Uuid][aFieldName] = getAttributeValue( aSymbol, aFieldName );
getAttributeValue( m_symbolsList[i], aFieldName );
// Handle fields with variables as names that are not present in the symbol // Handle fields with variables as names that are not present in the symbol
// by giving them the correct value // by giving them the correct value
else if( IsTextVar( aFieldName ) ) else if( IsTextVar( aFieldName ) )
m_dataStore[symbol->m_Uuid][aFieldName] = aFieldName; m_dataStore[aSymbol.m_Uuid][aFieldName] = aFieldName;
else else
m_dataStore[symbol->m_Uuid][aFieldName] = wxEmptyString; m_dataStore[aSymbol.m_Uuid][aFieldName] = wxEmptyString;
}
}
} }
@ -417,36 +419,36 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::isAttribute( const wxString& aFieldName )
} }
wxString FIELDS_EDITOR_GRID_DATA_MODEL::getAttributeValue( const SCH_REFERENCE& aRef, wxString FIELDS_EDITOR_GRID_DATA_MODEL::getAttributeValue( const SCH_SYMBOL& aSymbol,
const wxString& aAttributeName ) const wxString& aAttributeName )
{ {
if( aAttributeName == wxS( "${DNP}" ) ) if( aAttributeName == wxS( "${DNP}" ) )
return aRef.GetSymbol()->GetDNP() ? wxS( "1" ) : wxS( "0" ); return aSymbol.GetDNP() ? wxS( "1" ) : wxS( "0" );
if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) ) if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) )
return aRef.GetSymbol()->GetExcludedFromBoard() ? wxS( "1" ) : wxS( "0" ); return aSymbol.GetExcludedFromBoard() ? wxS( "1" ) : wxS( "0" );
if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) ) if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) )
return aRef.GetSymbol()->GetExcludedFromBOM() ? wxS( "1" ) : wxS( "0" ); return aSymbol.GetExcludedFromBOM() ? wxS( "1" ) : wxS( "0" );
if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) ) if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) )
return aRef.GetSymbol()->GetExcludedFromSim() ? wxS( "1" ) : wxS( "0" ); return aSymbol.GetExcludedFromSim() ? wxS( "1" ) : wxS( "0" );
return wxS( "0" ); return wxS( "0" );
} }
void FIELDS_EDITOR_GRID_DATA_MODEL::setAttributeValue( const SCH_REFERENCE& aRef, void FIELDS_EDITOR_GRID_DATA_MODEL::setAttributeValue( SCH_SYMBOL& aSymbol,
const wxString& aAttributeName, const wxString& aAttributeName,
const wxString& aValue ) const wxString& aValue )
{ {
if( aAttributeName == wxS( "${DNP}" ) ) if( aAttributeName == wxS( "${DNP}" ) )
aRef.GetSymbol()->SetDNP( aValue == wxS( "1" ) ); aSymbol.SetDNP( aValue == wxS( "1" ) );
else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) ) else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) )
aRef.GetSymbol()->SetExcludedFromBoard( aValue == wxS( "1" ) ); aSymbol.SetExcludedFromBoard( aValue == wxS( "1" ) );
else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) ) else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) )
aRef.GetSymbol()->SetExcludedFromBOM( aValue == wxS( "1" ) ); aSymbol.SetExcludedFromBOM( aValue == wxS( "1" ) );
else if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) ) else if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) )
aRef.GetSymbol()->SetExcludedFromSim( aValue == wxS( "1" ) ); aSymbol.SetExcludedFromSim( aValue == wxS( "1" ) );
} }
@ -658,7 +660,7 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyData(
// Attributes bypass the field logic, so handle them first // Attributes bypass the field logic, so handle them first
if( isAttribute( srcName ) ) if( isAttribute( srcName ) )
{ {
setAttributeValue( m_symbolsList[i], srcName, srcValue ); setAttributeValue( *m_symbolsList[i].GetSymbol(), srcName, srcValue );
continue; continue;
} }

View File

@ -219,8 +219,8 @@ private:
// Helper functions to deal with translating wxGrid values to and from // Helper functions to deal with translating wxGrid values to and from
// named field values like ${DNP} // named field values like ${DNP}
bool isAttribute( const wxString& aFieldName ); bool isAttribute( const wxString& aFieldName );
wxString getAttributeValue( const SCH_REFERENCE& aRef, const wxString& aAttributeName ); wxString getAttributeValue( const SCH_SYMBOL&, const wxString& aAttributeName );
void setAttributeValue( const SCH_REFERENCE& aRef, const wxString& aAttributeName, void setAttributeValue( SCH_SYMBOL& aSymbol, const wxString& aAttributeName,
const wxString& aValue ); const wxString& aValue );
/* Helper function to get the resolved field value. /* Helper function to get the resolved field value.
@ -231,6 +231,8 @@ private:
void Sort(); void Sort();
void updateDataStoreSymbolField( const SCH_SYMBOL& aSymbol, const wxString& aFieldName );
protected: protected:
SCH_REFERENCE_LIST m_symbolsList; SCH_REFERENCE_LIST m_symbolsList;

View File

@ -882,6 +882,18 @@ SCH_FIELD* SCH_SYMBOL::GetFieldByName( const wxString& aFieldName )
} }
const SCH_FIELD* SCH_SYMBOL::GetFieldByName( const wxString& aFieldName ) const
{
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 wxString SCH_SYMBOL::GetFieldText( const wxString& aFieldName ) const
{ {
for( const SCH_FIELD& field : m_fields ) for( const SCH_FIELD& field : m_fields )

View File

@ -399,6 +399,8 @@ public:
*/ */
SCH_FIELD* GetFieldByName( const wxString& aFieldName ); SCH_FIELD* GetFieldByName( const wxString& aFieldName );
const SCH_FIELD* GetFieldByName( const wxString& aFieldName ) const;
/** /**
* Search for a field named \a aFieldName and returns text associated with this field. * Search for a field named \a aFieldName and returns text associated with this field.
* *