Streamline color lookup (and a bit of wxS).
This commit is contained in:
parent
09cb222252
commit
bf8762c57c
|
@ -2,7 +2,7 @@
|
||||||
* This program source code file is part of KICAD, a free EDA CAD application.
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2020 CERN
|
* 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 <maciej.suminski@cern.ch>
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -21,9 +21,7 @@
|
||||||
|
|
||||||
#include <wx/dc.h>
|
#include <wx/dc.h>
|
||||||
#include <wx/propgrid/propgrid.h>
|
#include <wx/propgrid/propgrid.h>
|
||||||
#include <wx/regex.h>
|
|
||||||
|
|
||||||
#include <common.h>
|
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
#include <validators.h>
|
#include <validators.h>
|
||||||
#include <eda_units.h>
|
#include <eda_units.h>
|
||||||
|
@ -147,8 +145,8 @@ wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxFAIL_MSG( wxString::Format( "Property '" + aProperty->Name() +
|
wxFAIL_MSG( wxString::Format( wxS( "Property %s not supported by PGPropertyFactory" ),
|
||||||
"' is not supported by PGPropertyFactory" ) );
|
aProperty->Name() ) );
|
||||||
ret = new wxPropertyCategory();
|
ret = new wxPropertyCategory();
|
||||||
ret->Enable( false );
|
ret->Enable( false );
|
||||||
}
|
}
|
||||||
|
@ -185,7 +183,7 @@ bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString&
|
||||||
int aArgFlags ) const
|
int aArgFlags ) const
|
||||||
{
|
{
|
||||||
// TODO(JE): Are there actual use cases for this?
|
// 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() )
|
switch( PROPERTY_MANAGER::Instance().GetUnits() )
|
||||||
{
|
{
|
||||||
case EDA_UNITS::INCHES:
|
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:
|
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:
|
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:
|
case EDA_UNITS::UNSCALED:
|
||||||
return wxString::Format( wxT( "%li" ), distanceIU );
|
return wxString::Format( wxS( "%li" ), distanceIU );
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// DEGREEs are handled by PGPROPERTY_ANGLE
|
// 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 )
|
if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
|
||||||
{
|
{
|
||||||
// TODO(JE) Is this still needed?
|
// 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;
|
wxString ret;
|
||||||
static_cast<EDA_ANGLE_VARIANT_DATA*>( aVariant.GetData() )->Write( ret );
|
static_cast<EDA_ANGLE_VARIANT_DATA*>( aVariant.GetData() )->Write( ret );
|
||||||
|
@ -288,7 +286,7 @@ wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) c
|
||||||
}
|
}
|
||||||
else
|
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<int>( GetChoices().GetCount() ) )
|
if( index < 0 || index >= static_cast<int>( GetChoices().GetCount() ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxString layer = GetChoices().GetLabel( index );
|
wxColour color = GetColor( GetChoices().GetValue( index ) );
|
||||||
wxColour color = GetColor( layer );
|
|
||||||
|
|
||||||
if( color == wxNullColour )
|
if( color == wxNullColour )
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -129,7 +129,7 @@ public:
|
||||||
PGPROPERTY_COLORENUM( const wxString& aLabel, wxString& aName, wxPGChoices* aChoices,
|
PGPROPERTY_COLORENUM( const wxString& aLabel, wxString& aName, wxPGChoices* aChoices,
|
||||||
int aValue = 0 ) :
|
int aValue = 0 ) :
|
||||||
wxEnumProperty( aLabel, aName, *aChoices, aValue ),
|
wxEnumProperty( aLabel, aName, *aChoices, aValue ),
|
||||||
m_colorFunc( []( const wxString& aChoice ) { return wxNullColour; } )
|
m_colorFunc( []( int aValue ) { return wxNullColour; } )
|
||||||
{
|
{
|
||||||
SetFlag( wxPG_PROP_CUSTOMIMAGE );
|
SetFlag( wxPG_PROP_CUSTOMIMAGE );
|
||||||
}
|
}
|
||||||
|
@ -138,18 +138,18 @@ public:
|
||||||
|
|
||||||
void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
|
void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
|
||||||
|
|
||||||
void SetColorFunc( std::function<wxColour( const wxString& aChoice )> aFunc )
|
void SetColorFunc( std::function<wxColour( int aValue )> aFunc )
|
||||||
{
|
{
|
||||||
m_colorFunc = aFunc;
|
m_colorFunc = aFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxColour GetColor( const wxString& aChoice )
|
wxColour GetColor( int aValue )
|
||||||
{
|
{
|
||||||
return m_colorFunc( aChoice );
|
return m_colorFunc( aValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::function<wxColour( const wxString& aChoice )> m_colorFunc;
|
std::function<wxColour( int aValue )> m_colorFunc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -165,15 +165,9 @@ wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProp
|
||||||
new wxPGChoices( boardLayerNames, boardLayerIDs ) );
|
new wxPGChoices( boardLayerNames, boardLayerIDs ) );
|
||||||
|
|
||||||
ret->SetColorFunc(
|
ret->SetColorFunc(
|
||||||
[&]( const wxString& aChoice ) -> wxColour
|
[&]( int aValue ) -> wxColour
|
||||||
{
|
{
|
||||||
for( int layer = PCBNEW_LAYER_ID_START; layer < PCB_LAYER_ID_COUNT; ++layer )
|
return m_frame->GetColorSettings()->GetColor( ToLAYER_ID( aValue ) ).ToColour();
|
||||||
{
|
|
||||||
if( m_frame->GetBoard()->GetLayerName( ToLAYER_ID( layer ) ) == aChoice )
|
|
||||||
return m_frame->GetColorSettings()->GetColor( layer ).ToColour();
|
|
||||||
}
|
|
||||||
|
|
||||||
return wxNullColour;
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
|
ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
|
||||||
|
|
Loading…
Reference in New Issue