Fields Editor Table: add checkboxes for fields representing attributes
DNP, Exclude from ..., etc. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/15300
This commit is contained in:
parent
8fb316f995
commit
37fdcce0a0
|
@ -163,6 +163,26 @@ BOM_PRESET BOM_PRESET::GroupedByValueFootprint()
|
|||
}
|
||||
|
||||
|
||||
BOM_PRESET BOM_PRESET::Attributes()
|
||||
{
|
||||
BOM_PRESET p{
|
||||
_HKI( "Attributes" ), true, {}, _( "Reference" ), true, "", true, false
|
||||
};
|
||||
|
||||
p.fieldsOrdered = std::vector<BOM_FIELD>{
|
||||
{ "Reference", "Reference", true, false },
|
||||
{ "Value", "Value", true, true },
|
||||
{ "Datasheet", "Datasheet", false, false },
|
||||
{ "Footprint", "Footprint", false, true },
|
||||
{ "${DNP}", "Do Not Place", true, false },
|
||||
{ "${EXCLUDE_FROM_BOM}", "Exclude from BOM", true, false },
|
||||
{ "${EXCLUDE_FROM_BOARD}", "Exclude from Board", true, false },
|
||||
{ "${EXCLUDE_FROM_SIM}", "Exclude from Simulation", true, false },
|
||||
};
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//Implementations for BOM_FMT_PRESET
|
||||
bool BOM_FMT_PRESET::operator==( const BOM_FMT_PRESET& rhs ) const
|
||||
{
|
||||
|
|
|
@ -1279,7 +1279,8 @@ void DIALOG_SYMBOL_FIELDS_TABLE::loadDefaultBomPresets()
|
|||
|
||||
// Load the read-only defaults
|
||||
for( const BOM_PRESET& preset : { BOM_PRESET::GroupedByValue(),
|
||||
BOM_PRESET::GroupedByValueFootprint() } )
|
||||
BOM_PRESET::GroupedByValueFootprint(),
|
||||
BOM_PRESET::Attributes() } )
|
||||
{
|
||||
m_bomPresets[preset.name] = preset;
|
||||
m_bomPresets[preset.name].readOnly = true;
|
||||
|
|
|
@ -27,6 +27,9 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::AddColumn( const wxString& aFieldName, const
|
|||
{
|
||||
if( SCH_FIELD* field = symbol->GetFieldByName( aFieldName ) )
|
||||
m_dataStore[symbol->m_Uuid][aFieldName] = field->GetText();
|
||||
else if( isAttribute( aFieldName ) )
|
||||
m_dataStore[symbol->m_Uuid][aFieldName] =
|
||||
getAttributeValue( m_symbolsList[i], aFieldName );
|
||||
// Handle fields with variables as names that are not present in the symbol
|
||||
// by giving them the correct value
|
||||
else if( IsTextVar( aFieldName ) )
|
||||
|
@ -208,8 +211,11 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::SetValue( int aRow, int aCol, const wxString
|
|||
wxCHECK_RET( aCol >= 0 && aCol < (int) m_cols.size(), wxS( "Invalid column number" ) );
|
||||
|
||||
// Can't modify references or text variables column, e.g. ${QUANTITY}
|
||||
if( ColIsReference( aCol ) || IsTextVar( m_cols[aCol].m_fieldName ) )
|
||||
if( ColIsReference( aCol )
|
||||
|| ( IsTextVar( m_cols[aCol].m_fieldName ) && !ColIsAttribute( aCol ) ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DATA_MODEL_ROW& rowGroup = m_rows[aRow];
|
||||
|
||||
|
@ -238,6 +244,12 @@ bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsItemNumber( int aCol )
|
|||
return m_cols[aCol].m_fieldName == ITEM_NUMBER_VARIABLE;
|
||||
}
|
||||
|
||||
bool FIELDS_EDITOR_GRID_DATA_MODEL::ColIsAttribute( int aCol )
|
||||
{
|
||||
wxCHECK( aCol >= 0 && aCol < (int) m_cols.size(), false );
|
||||
return isAttribute( m_cols[aCol].m_fieldName );
|
||||
}
|
||||
|
||||
|
||||
bool FIELDS_EDITOR_GRID_DATA_MODEL::cmp( const DATA_MODEL_ROW& lhGroup,
|
||||
const DATA_MODEL_ROW& rhGroup,
|
||||
|
@ -396,6 +408,48 @@ wxString FIELDS_EDITOR_GRID_DATA_MODEL::getFieldShownText( const SCH_REFERENCE&
|
|||
}
|
||||
|
||||
|
||||
bool FIELDS_EDITOR_GRID_DATA_MODEL::isAttribute( const wxString& aFieldName )
|
||||
{
|
||||
return aFieldName == wxS( "${DNP}" )
|
||||
|| aFieldName == wxS( "${EXCLUDE_FROM_BOARD}" )
|
||||
|| aFieldName == wxS( "${EXCLUDE_FROM_BOM}" )
|
||||
|| aFieldName == wxS( "${EXCLUDE_FROM_SIM}" );
|
||||
}
|
||||
|
||||
|
||||
wxString FIELDS_EDITOR_GRID_DATA_MODEL::getAttributeValue( const SCH_REFERENCE& aRef,
|
||||
const wxString& aAttributeName )
|
||||
{
|
||||
if( aAttributeName == wxS( "${DNP}" ) )
|
||||
return aRef.GetSymbol()->GetDNP() ? wxS( "1" ) : wxS( "0" );
|
||||
|
||||
if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) )
|
||||
return aRef.GetSymbol()->GetExcludedFromBoard() ? wxS( "1" ) : wxS( "0" );
|
||||
|
||||
if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) )
|
||||
return aRef.GetSymbol()->GetExcludedFromBOM() ? wxS( "1" ) : wxS( "0" );
|
||||
|
||||
if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) )
|
||||
return aRef.GetSymbol()->GetExcludeFromSim() ? wxS( "1" ) : wxS( "0" );
|
||||
|
||||
return wxS( "0" );
|
||||
}
|
||||
|
||||
void FIELDS_EDITOR_GRID_DATA_MODEL::setAttributeValue( const SCH_REFERENCE& aRef,
|
||||
const wxString& aAttributeName,
|
||||
const wxString& aValue )
|
||||
{
|
||||
if( aAttributeName == wxS( "${DNP}" ) )
|
||||
aRef.GetSymbol()->SetDNP( aValue == wxS( "1" ) );
|
||||
else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOARD}" ) )
|
||||
aRef.GetSymbol()->SetExcludedFromBoard( aValue == wxS( "1" ) );
|
||||
else if( aAttributeName == wxS( "${EXCLUDE_FROM_BOM}" ) )
|
||||
aRef.GetSymbol()->SetExcludedFromBOM( aValue == wxS( "1" ) );
|
||||
else if( aAttributeName == wxS( "${EXCLUDE_FROM_SIM}" ) )
|
||||
aRef.GetSymbol()->SetExcludeFromSim( aValue == wxS( "1" ) );
|
||||
}
|
||||
|
||||
|
||||
void FIELDS_EDITOR_GRID_DATA_MODEL::EnableRebuilds()
|
||||
{
|
||||
m_rebuildsEnabled = true;
|
||||
|
@ -589,12 +643,21 @@ void FIELDS_EDITOR_GRID_DATA_MODEL::ApplyData(
|
|||
|
||||
for( const std::pair<wxString, wxString> srcData : fieldStore )
|
||||
{
|
||||
// Skip special fields with variables as names (e.g. ${QUANTITY})
|
||||
if( IsTextVar( srcData.first ) )
|
||||
continue;
|
||||
|
||||
const wxString& srcName = srcData.first;
|
||||
const wxString& srcValue = srcData.second;
|
||||
|
||||
// Attributes bypass the field logic, so handle them first
|
||||
if( isAttribute( srcName ) )
|
||||
{
|
||||
setAttributeValue( m_symbolsList[i], srcName, srcValue );
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip special fields with variables as names (e.g. ${QUANTITY}),
|
||||
// they can't be edited
|
||||
if( IsTextVar( srcName ) )
|
||||
continue;
|
||||
|
||||
SCH_FIELD* destField = symbol.FindField( srcName );
|
||||
int col = GetFieldNameCol( srcName );
|
||||
bool userAdded = ( col != -1 && m_cols[col].m_userAdded );
|
||||
|
|
|
@ -126,6 +126,7 @@ public:
|
|||
bool ColIsReference( int aCol );
|
||||
bool ColIsQuantity( int aCol );
|
||||
bool ColIsItemNumber( int aCol );
|
||||
bool ColIsAttribute( int aCol );
|
||||
|
||||
void SetSorting( int aCol, bool ascending )
|
||||
{
|
||||
|
@ -202,6 +203,13 @@ private:
|
|||
bool unitMatch( const SCH_REFERENCE& lhRef, const SCH_REFERENCE& rhRef );
|
||||
bool groupMatch( const SCH_REFERENCE& lhRef, const SCH_REFERENCE& rhRef );
|
||||
|
||||
// Helper functions to deal with translating wxGrid values to and from
|
||||
// named field values like ${DNP}
|
||||
bool isAttribute( const wxString& aFieldName );
|
||||
wxString getAttributeValue( const SCH_REFERENCE& aRef, const wxString& aAttributeName );
|
||||
void setAttributeValue( const SCH_REFERENCE& aRef, const wxString& aAttributeName,
|
||||
const wxString& aValue );
|
||||
|
||||
/* Helper function to get the resolved field value.
|
||||
* Handles symbols that are missing fields that would have a variable
|
||||
* in their value because their name is the same as a variable.
|
||||
|
|
|
@ -61,6 +61,7 @@ struct BOM_PRESET
|
|||
|
||||
static BOM_PRESET GroupedByValue();
|
||||
static BOM_PRESET GroupedByValueFootprint();
|
||||
static BOM_PRESET Attributes();
|
||||
};
|
||||
|
||||
bool operator!=( const BOM_PRESET& lhs, const BOM_PRESET& rhs );
|
||||
|
|
Loading…
Reference in New Issue