diff --git a/include/properties/pg_properties.h b/include/properties/pg_properties.h index 998adce135..f3b25138c5 100644 --- a/include/properties/pg_properties.h +++ b/include/properties/pg_properties.h @@ -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( aChoices ), aValue ), + wxEnumProperty( aLabel, aName, *aChoices, aValue ), m_colorFunc( []( const wxString& aChoice ) { return wxNullColour; } ) { SetFlag( wxPG_PROP_CUSTOMIMAGE ); diff --git a/pcbnew/widgets/pcb_properties_panel.cpp b/pcbnew/widgets/pcb_properties_panel.cpp index 7cc96ab211..ea53d3ac90 100644 --- a/pcbnew/widgets/pcb_properties_panel.cpp +++ b/pcbnew/widgets/pcb_properties_panel.cpp @@ -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( aProperty->Choices() ) ); + new wxPGChoices( boardLayerNames, boardLayerIDs ) ); ret->SetColorFunc( [&]( const wxString& aChoice ) -> wxColour { - PCB_LAYER_ID l = ENUM_MAP::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() ) );