Use board layer names for properties grid.

Fixes https://gitlab.com/kicad/code/kicad/issues/13553
This commit is contained in:
Jeff Young 2023-01-22 15:47:02 +00:00
parent 0ff32d20cd
commit 729b2deb5c
2 changed files with 22 additions and 6 deletions

View File

@ -126,9 +126,9 @@ protected:
class PGPROPERTY_COLORENUM : public wxEnumProperty
{
public:
PGPROPERTY_COLORENUM( const wxString& aLabel, wxString& aName, const wxPGChoices& aChoices,
PGPROPERTY_COLORENUM( const wxString& aLabel, wxString& aName, wxPGChoices* aChoices,
int aValue = 0 ) :
wxEnumProperty( aLabel, aName, const_cast<wxPGChoices&>( aChoices ), aValue ),
wxEnumProperty( aLabel, aName, *aChoices, aValue ),
m_colorFunc( []( const wxString& aChoice ) { return wxNullColour; } )
{
SetFlag( wxPG_PROP_CUSTOMIMAGE );

View File

@ -116,15 +116,31 @@ wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProp
{
wxASSERT( aProperty->HasChoices() );
const wxPGChoices& canonicalLayers = aProperty->Choices();
wxArrayString boardLayerNames;
wxArrayInt boardLayerIDs;
for( int ii = 0; ii < (int) aProperty->Choices().GetCount(); ++ii )
{
int layer = canonicalLayers.GetValue( ii );
boardLayerNames.push_back( m_frame->GetBoard()->GetLayerName( ToLAYER_ID( layer ) ) );
boardLayerIDs.push_back( canonicalLayers.GetValue( ii ) );
}
auto ret = new PGPROPERTY_COLORENUM( wxPG_LABEL, wxPG_LABEL,
const_cast<wxPGChoices&>( aProperty->Choices() ) );
new wxPGChoices( boardLayerNames, boardLayerIDs ) );
ret->SetColorFunc(
[&]( const wxString& aChoice ) -> wxColour
{
PCB_LAYER_ID l = ENUM_MAP<PCB_LAYER_ID>::Instance().ToEnum( aChoice );
wxASSERT( IsPcbLayer( l ) );
return m_frame->GetColorSettings()->GetColor( l ).ToColour();
for( int layer = PCBNEW_LAYER_ID_START; layer < PCB_LAYER_ID_COUNT; ++layer )
{
if( m_frame->GetBoard()->GetLayerName( ToLAYER_ID( layer ) ) == aChoice )
return m_frame->GetColorSettings()->GetColor( layer ).ToColour();
}
return wxNullColour;
} );
ret->SetLabel( wxGetTranslation( aProperty->Name() ) );