diff --git a/common/properties/pg_properties.cpp b/common/properties/pg_properties.cpp index e2e6cc2937..e6fa7917ae 100644 --- a/common/properties/pg_properties.cpp +++ b/common/properties/pg_properties.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 2020 CERN - * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.TXT for contributors. * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -21,9 +21,7 @@ #include #include -#include -#include #include #include #include @@ -147,8 +145,8 @@ wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty ) } else { - wxFAIL_MSG( wxString::Format( "Property '" + aProperty->Name() + - "' is not supported by PGPropertyFactory" ) ); + wxFAIL_MSG( wxString::Format( wxS( "Property %s not supported by PGPropertyFactory" ), + aProperty->Name() ) ); ret = new wxPropertyCategory(); ret->Enable( false ); } @@ -185,7 +183,7 @@ bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& int aArgFlags ) const { // TODO(JE): Are there actual use cases for this? - wxCHECK_MSG( false, false, wxT( "PGPROPERTY_DISTANCE::StringToDistance should not be used." ) ); + wxCHECK_MSG( false, false, wxS( "PGPROPERTY_DISTANCE::StringToDistance should not be used." ) ); } @@ -203,16 +201,16 @@ wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aArgFla switch( PROPERTY_MANAGER::Instance().GetUnits() ) { case EDA_UNITS::INCHES: - return wxString::Format( wxT( "%g in" ), pcbIUScale.IUToMils( distanceIU ) / 1000.0 ); + return wxString::Format( wxS( "%g in" ), pcbIUScale.IUToMils( distanceIU ) / 1000.0 ); case EDA_UNITS::MILS: - return wxString::Format( wxT( "%d mils" ), pcbIUScale.IUToMils( distanceIU ) ); + return wxString::Format( wxS( "%d mils" ), pcbIUScale.IUToMils( distanceIU ) ); case EDA_UNITS::MILLIMETRES: - return wxString::Format( wxT( "%g mm" ), pcbIUScale.IUTomm( distanceIU ) ); + return wxString::Format( wxS( "%g mm" ), pcbIUScale.IUTomm( distanceIU ) ); case EDA_UNITS::UNSCALED: - return wxString::Format( wxT( "%li" ), distanceIU ); + return wxString::Format( wxS( "%li" ), distanceIU ); default: // DEGREEs are handled by PGPROPERTY_ANGLE @@ -278,9 +276,9 @@ wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) c if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE ) { // TODO(JE) Is this still needed? - return wxString::Format( wxT( "%g\u00B0" ), aVariant.GetDouble() / m_scale ); + return wxString::Format( wxS( "%g\u00B0" ), aVariant.GetDouble() / m_scale ); } - else if( aVariant.GetType() == wxT( "EDA_ANGLE" ) ) + else if( aVariant.GetType() == wxS( "EDA_ANGLE" ) ) { wxString ret; static_cast( aVariant.GetData() )->Write( ret ); @@ -288,7 +286,7 @@ wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) c } else { - wxCHECK_MSG( false, wxEmptyString, "Unexpected variant type in PGPROPERTY_ANGLE" ); + wxCHECK_MSG( false, wxEmptyString, wxS( "Unexpected variant type in PGPROPERTY_ANGLE" ) ); } } @@ -318,8 +316,7 @@ void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect, if( index < 0 || index >= static_cast( GetChoices().GetCount() ) ) return; - wxString layer = GetChoices().GetLabel( index ); - wxColour color = GetColor( layer ); + wxColour color = GetColor( GetChoices().GetValue( index ) ); if( color == wxNullColour ) return; diff --git a/include/properties/pg_properties.h b/include/properties/pg_properties.h index 7e2a9d449c..bc9df374b7 100644 --- a/include/properties/pg_properties.h +++ b/include/properties/pg_properties.h @@ -129,7 +129,7 @@ public: PGPROPERTY_COLORENUM( const wxString& aLabel, wxString& aName, wxPGChoices* aChoices, int aValue = 0 ) : wxEnumProperty( aLabel, aName, *aChoices, aValue ), - m_colorFunc( []( const wxString& aChoice ) { return wxNullColour; } ) + m_colorFunc( []( int aValue ) { return wxNullColour; } ) { SetFlag( wxPG_PROP_CUSTOMIMAGE ); } @@ -138,18 +138,18 @@ public: void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override; - void SetColorFunc( std::function aFunc ) + void SetColorFunc( std::function aFunc ) { m_colorFunc = aFunc; } - wxColour GetColor( const wxString& aChoice ) + wxColour GetColor( int aValue ) { - return m_colorFunc( aChoice ); + return m_colorFunc( aValue ); } protected: - std::function m_colorFunc; + std::function m_colorFunc; }; diff --git a/pcbnew/widgets/pcb_properties_panel.cpp b/pcbnew/widgets/pcb_properties_panel.cpp index 16c92dc873..0adf68ed3a 100644 --- a/pcbnew/widgets/pcb_properties_panel.cpp +++ b/pcbnew/widgets/pcb_properties_panel.cpp @@ -165,15 +165,9 @@ wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProp new wxPGChoices( boardLayerNames, boardLayerIDs ) ); ret->SetColorFunc( - [&]( const wxString& aChoice ) -> wxColour + [&]( int aValue ) -> wxColour { - 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; + return m_frame->GetColorSettings()->GetColor( ToLAYER_ID( aValue ) ).ToColour(); } ); ret->SetLabel( wxGetTranslation( aProperty->Name() ) );