Properties: add color swatch to layer enum
This commit is contained in:
parent
239fd29da4
commit
f5597238fb
|
@ -27,6 +27,7 @@
|
||||||
#include <validators.h>
|
#include <validators.h>
|
||||||
#include <convert_to_biu.h>
|
#include <convert_to_biu.h>
|
||||||
#include <property.h>
|
#include <property.h>
|
||||||
|
#include <widgets/color_swatch.h>
|
||||||
|
|
||||||
// reg-ex describing a signed valid value with a unit
|
// reg-ex describing a signed valid value with a unit
|
||||||
static const wxChar REGEX_SIGNED_DISTANCE[] = wxT( "([-+]?[0-9]+[\\.?[0-9]*) *(mm|in)*" );
|
static const wxChar REGEX_SIGNED_DISTANCE[] = wxT( "([-+]?[0-9]+[\\.?[0-9]*) *(mm|in)*" );
|
||||||
|
@ -275,3 +276,30 @@ wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) c
|
||||||
wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE, wxEmptyString );
|
wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE, wxEmptyString );
|
||||||
return wxString::Format( wxT("%g\u00B0"), aVariant.GetDouble() / m_scale );
|
return wxString::Format( wxT("%g\u00B0"), aVariant.GetDouble() / m_scale );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxSize PGPROPERTY_COLORENUM::OnMeasureImage( int aItem ) const
|
||||||
|
{
|
||||||
|
// TODO(JE) calculate size from window metrics?
|
||||||
|
return wxSize( 16, 12 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect,
|
||||||
|
wxPGPaintData& aPaintData )
|
||||||
|
{
|
||||||
|
int index = aPaintData.m_choiceItem;
|
||||||
|
|
||||||
|
if( index < 0 )
|
||||||
|
index = GetIndex();
|
||||||
|
|
||||||
|
wxString layer = GetChoices().GetLabel( index );
|
||||||
|
wxColour color = GetColor( layer );
|
||||||
|
|
||||||
|
if( color == wxNullColour )
|
||||||
|
return;
|
||||||
|
|
||||||
|
aDC.SetPen( *wxTRANSPARENT_PEN );
|
||||||
|
aDC.SetBrush( wxBrush( color ) );
|
||||||
|
aDC.DrawRectangle( aRect );
|
||||||
|
}
|
||||||
|
|
|
@ -109,4 +109,34 @@ protected:
|
||||||
double m_scale;
|
double m_scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///> A wxEnumProperty that displays a color next to the enum value
|
||||||
|
class PGPROPERTY_COLORENUM : public wxEnumProperty
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PGPROPERTY_COLORENUM( const wxString& aLabel, wxString& aName, const wxPGChoices& aChoices,
|
||||||
|
int aValue = 0 ) :
|
||||||
|
wxEnumProperty( aLabel, aName, const_cast<wxPGChoices&>( aChoices ), aValue ),
|
||||||
|
m_colorFunc( []( const wxString& aChoice ) { return wxNullColour; } )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize OnMeasureImage( int aItem = -1 ) const override;
|
||||||
|
|
||||||
|
void OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData ) override;
|
||||||
|
|
||||||
|
void SetColorFunc( std::function<wxColour( const wxString& aChoice )> aFunc )
|
||||||
|
{
|
||||||
|
m_colorFunc = aFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxColour GetColor( const wxString& aChoice )
|
||||||
|
{
|
||||||
|
return m_colorFunc( aChoice );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::function<wxColour( const wxString& aChoice )> m_colorFunc;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* PG_PROPERTIES_H */
|
#endif /* PG_PROPERTIES_H */
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <board_connected_item.h>
|
#include <board_connected_item.h>
|
||||||
#include <pg_properties.h>
|
#include <pg_properties.h>
|
||||||
#include <pcb_shape.h>
|
#include <pcb_shape.h>
|
||||||
|
#include <settings/color_settings.h>
|
||||||
|
|
||||||
|
|
||||||
PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* aFrame )
|
PCB_PROPERTIES_PANEL::PCB_PROPERTIES_PANEL( wxWindow* aParent, PCB_EDIT_FRAME* aFrame )
|
||||||
|
@ -50,6 +51,29 @@ void PCB_PROPERTIES_PANEL::UpdateData()
|
||||||
|
|
||||||
wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProperty ) const
|
wxPGProperty* PCB_PROPERTIES_PANEL::createPGProperty( const PROPERTY_BASE* aProperty ) const
|
||||||
{
|
{
|
||||||
|
if( aProperty->TypeHash() == TYPE_HASH( PCB_LAYER_ID ) )
|
||||||
|
{
|
||||||
|
wxASSERT( aProperty->HasChoices() );
|
||||||
|
|
||||||
|
PGPROPERTY_COLORENUM* ret = new PGPROPERTY_COLORENUM( wxPG_LABEL, wxPG_LABEL,
|
||||||
|
const_cast<wxPGChoices&>( aProperty->Choices() ) );
|
||||||
|
|
||||||
|
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();
|
||||||
|
} );
|
||||||
|
|
||||||
|
ret->SetLabel( aProperty->Name() );
|
||||||
|
ret->SetName( aProperty->Name() );
|
||||||
|
ret->Enable( !aProperty->IsReadOnly() );
|
||||||
|
ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return PGPropertyFactory( aProperty );
|
return PGPropertyFactory( aProperty );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,29 +107,9 @@ void PCB_PROPERTIES_PANEL::updateLists( const BOARD* aBoard )
|
||||||
for( LSEQ layerSeq = aBoard->GetEnabledLayers().UIOrder(); layerSeq; ++layerSeq )
|
for( LSEQ layerSeq = aBoard->GetEnabledLayers().UIOrder(); layerSeq; ++layerSeq )
|
||||||
layersAll.Add( LSET::Name( *layerSeq ), *layerSeq );
|
layersAll.Add( LSET::Name( *layerSeq ), *layerSeq );
|
||||||
|
|
||||||
m_propMgr.GetProperty( TYPE_HASH( BOARD_ITEM ), _( "Layer" ) )->SetChoices( layersAll );
|
m_propMgr.GetProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Layer" ) )->SetChoices( layersAll );
|
||||||
|
m_propMgr.GetProperty( TYPE_HASH( PCB_SHAPE ), _HKI( "Layer" ) )->SetChoices( layersAll );
|
||||||
|
m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ) )->SetChoices( layersAll );
|
||||||
// Regenerate non-copper layers
|
|
||||||
for( LSEQ layerSeq = LSET( LSET::AllNonCuMask() & aBoard->GetEnabledLayers() ).UIOrder(); layerSeq; ++layerSeq )
|
|
||||||
layersNonCu.Add( LSET::Name( *layerSeq ), *layerSeq );
|
|
||||||
|
|
||||||
m_propMgr.GetProperty( TYPE_HASH( PCB_SHAPE ), _( "Layer" ) )->SetChoices( layersNonCu );
|
|
||||||
|
|
||||||
|
|
||||||
// Regenerate copper layers
|
|
||||||
for( LSEQ layerSeq = LSET( LSET::AllCuMask() & aBoard->GetEnabledLayers() ).UIOrder(); layerSeq; ++layerSeq )
|
|
||||||
layersCu.Add( LSET::Name( *layerSeq ), *layerSeq );
|
|
||||||
|
|
||||||
m_propMgr.GetProperty( TYPE_HASH( BOARD_CONNECTED_ITEM ), _( "Layer" ) )->SetChoices( layersCu );
|
|
||||||
|
|
||||||
|
|
||||||
// Regenerate non-copper layers
|
|
||||||
for( LSEQ layerSeq = LSET( LSET::AllNonCuMask() & aBoard->GetEnabledLayers() ).UIOrder(); layerSeq; ++layerSeq )
|
|
||||||
layersNonCu.Add( LSET::Name( *layerSeq ), *layerSeq );
|
|
||||||
|
|
||||||
m_propMgr.GetProperty( TYPE_HASH( PCB_SHAPE ), _( "Layer" ) )->SetChoices( layersNonCu );
|
|
||||||
|
|
||||||
|
|
||||||
// Regenerate nets
|
// Regenerate nets
|
||||||
for( const auto& netinfo : aBoard->GetNetInfo().NetsByNetcode() )
|
for( const auto& netinfo : aBoard->GetNetInfo().NetsByNetcode() )
|
||||||
|
|
Loading…
Reference in New Issue