pcbnew: Add ability to reset layer/item colors to defaults

This commit is contained in:
Ian McInerney 2019-08-21 22:57:53 +02:00 committed by Wayne Stambaugh
parent b109aba663
commit 1bbd944277
12 changed files with 204 additions and 49 deletions

View File

@ -70,28 +70,35 @@ static const EDA_COLOR_T default_layer_color[] = {
// for color order, see enum GAL_LAYER_ID
static const EDA_COLOR_T default_items_color[] = {
LIGHTGRAY, // unused
CYAN, // LAYER_VIA_MICROVIA
BROWN, // LAYER_VIA_BBLIND
LIGHTGRAY, // LAYER_VIA_THROUGH
YELLOW, // LAYER_NON_PLATED
LIGHTGRAY, // LAYER_MOD_TEXT_FR
BLUE, // LAYER_MOD_TEXT_BK
DARKGRAY, // LAYER_MOD_TEXT_INVISIBLE
BLUE, // LAYER_ANCHOR
RED, // LAYER_PAD_FR
GREEN, // LAYER_PAD_BK
LIGHTGRAY, // LAYER_RATSNEST
DARKGRAY, // LAYER_GRID
LIGHTRED, // LAYER_GRID_AXES
BLUE, // LAYER_NO_CONNECTS
LIGHTGRAY, LIGHTGRAY, // LAYER_MOD_FR, LAYER_MOD_BK
LIGHTGRAY, LIGHTGRAY, // LAYER_MOD_VALUES, LAYER_MOD_REFERENCES
LIGHTGRAY, // LAYER_TRACKS
YELLOW, // LAYER_PADS
LIGHTGRAY, LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY, LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY, LIGHTGRAY, LIGHTGRAY
LIGHTGRAY, // unused (LAYER_VIAS = GAL_LAYER_ID_START)
CYAN, // LAYER_VIA_MICROVIA
BROWN, // LAYER_VIA_BBLIND
LIGHTGRAY, // LAYER_VIA_THROUGH
YELLOW, // LAYER_NON_PLATED
LIGHTGRAY, // LAYER_MOD_TEXT_FR
BLUE, // LAYER_MOD_TEXT_BK
DARKGRAY, // LAYER_MOD_TEXT_INVISIBLE
BLUE, // LAYER_ANCHOR
RED, // LAYER_PAD_FR
GREEN, // LAYER_PAD_BK
LIGHTGRAY, // LAYER_RATSNEST
DARKGRAY, // LAYER_GRID
LIGHTRED, // LAYER_GRID_AXES
BLUE, // LAYER_NO_CONNECTS
LIGHTGRAY, LIGHTGRAY, // LAYER_MOD_FR, LAYER_MOD_BK
LIGHTGRAY, LIGHTGRAY, // LAYER_MOD_VALUES, LAYER_MOD_REFERENCES
LIGHTGRAY, // LAYER_TRACKS
YELLOW, LIGHTGRAY, // LAYER_PADS, LAYER_PADS_PLATEDHOLES
LIGHTGRAY, // LAYER_VIAS_HOLES
LIGHTGRAY, // LAYER_DRC
DARKRED, // LAYER_WORKSHEET
LIGHTGRAY, // LAYER_GP_OVERLAY
LIGHTGRAY, // LAYER_SELECT_OVERLAY
BLACK, // LAYER_PCB_BACKGROUND
WHITE, // LAYER_CURSOR
WHITE, // LAYER_AUX_ITEMS
LIGHTGRAY, // LAYER_DRAW_BITMAPS
LIGHTGRAY // unused (GAL_LAYER_ID_BITMASK_END)
};
@ -112,16 +119,19 @@ COLORS_DESIGN_SETTINGS::COLORS_DESIGN_SETTINGS( FRAME_T aFrameType )
m_LayersColors[dst] = COLOR4D( default_items_color[src] );
}
m_LayersColors[ LAYER_PCB_BACKGROUND ] = BLACK;
m_LayersColors[ LAYER_CURSOR ] = WHITE;
m_LayersColors[ LAYER_AUX_ITEMS ] = WHITE;
m_LayersColors[ LAYER_WORKSHEET ] = DARKRED;
m_LayersColors[ LAYER_GRID ] = DARKGRAY;
setupConfigParams();
}
COLOR4D COLORS_DESIGN_SETTINGS::GetDefaultLayerColor( LAYER_NUM aLayer )
{
if( (unsigned) aLayer < arrayDim( default_layer_color ) )
return COLOR4D( default_layer_color[aLayer] );
return COLOR4D::UNSPECIFIED;
}
COLOR4D COLORS_DESIGN_SETTINGS::GetLayerColor( LAYER_NUM aLayer ) const
{
if( (unsigned) aLayer < arrayDim( m_LayersColors ) )
@ -138,6 +148,16 @@ void COLORS_DESIGN_SETTINGS::SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor )
}
COLOR4D COLORS_DESIGN_SETTINGS::GetDefaultItemColor( int aItemIdx )
{
unsigned int idx = (unsigned) aItemIdx - LAYER_VIAS;
if( idx < arrayDim( default_items_color ) )
return COLOR4D( default_items_color[idx] );
return COLOR4D::UNSPECIFIED;
}
COLOR4D COLORS_DESIGN_SETTINGS::GetItemColor( int aItemIdx ) const
{
if( (unsigned) aItemIdx < arrayDim( m_LayersColors ) )

View File

@ -24,7 +24,8 @@
#define ALPHA_MAX 100 // the max value returned by the alpha (opacity) slider
DIALOG_COLOR_PICKER::DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors )
bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors,
const KIGFX::COLOR4D& aDefaultColor )
: DIALOG_COLOR_PICKER_BASE( aParent )
{
m_allowMouseEvents = false;
@ -36,6 +37,7 @@ DIALOG_COLOR_PICKER::DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCu
m_bitmapRGB = nullptr;
m_bitmapHSV = nullptr;
m_selectedCursor = nullptr;
m_defaultColor = aDefaultColor;
if( !m_allowOpacityCtrl )
{
@ -50,6 +52,10 @@ DIALOG_COLOR_PICKER::DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCu
// Build the defined colors panel:
initDefinedColors( aUserColors );
// If there is no default color, don't give the option to reset to default
if( aDefaultColor == KIGFX::COLOR4D::UNSPECIFIED )
m_resetToDefault->Hide();
m_sdbSizerOK->SetDefault();
}
@ -794,3 +800,16 @@ void DIALOG_COLOR_PICKER::OnChangeBrightness( wxScrollEvent& event )
drawAll();
}
void DIALOG_COLOR_PICKER::OnResetButton( wxCommandEvent& aEvent )
{
m_newColor4D.r = m_defaultColor.r;
m_newColor4D.g = m_defaultColor.g;
m_newColor4D.b = m_defaultColor.b;
m_newColor4D.ToHSV( m_hue, m_sat, m_val, true );
SetEditVals( ALL_CHANGED );
drawAll();
}

View File

@ -76,7 +76,8 @@ public:
* @param aUserColors: if not null is a list of defined colors replacing the dialog predefined colors
*/
DIALOG_COLOR_PICKER( wxWindow* aParent, KIGFX::COLOR4D& aCurrentColor,
bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors = nullptr );
bool aAllowOpacityControl, CUSTOM_COLORS_LIST* aUserColors = nullptr,
const KIGFX::COLOR4D& aDefaultColor = KIGFX::COLOR4D::UNSPECIFIED );
~DIALOG_COLOR_PICKER();
KIGFX::COLOR4D GetColor() { return m_newColor4D; };
@ -95,6 +96,8 @@ private:
///< false to keep alpha channel = 1.0
KIGFX::COLOR4D m_previousColor4D; ///< the inital color4d
KIGFX::COLOR4D m_newColor4D; ///< the current color4d
KIGFX::COLOR4D m_defaultColor; ///< The default color4d
/// the list of color4d ordered by button ID, for predefined colors
std::vector<KIGFX::COLOR4D> m_Color4DList;
int m_cursorsSize;
@ -145,6 +148,9 @@ private:
void onHSVMouseClick( wxMouseEvent& event ) override;
void onHSVMouseDrag( wxMouseEvent& event ) override;
///< Event handler for the reset button press
void OnResetButton( wxCommandEvent& aEvent ) override;
/** manage the Hue and Saturation settings when the mouse cursor
* is at aMouseCursor.
* @param aMouseCursor is the mouse cursor position on the HSV bitmap

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Mar 28 2019)
// C++ code generated with wxFormBuilder (version Aug 21 2019)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -206,6 +206,9 @@ DIALOG_COLOR_PICKER_BASE::DIALOG_COLOR_PICKER_BASE( wxWindow* parent, wxWindowID
bButtonsSizer->Add( m_NewColorRect, 0, wxALIGN_CENTER_VERTICAL, 5 );
m_resetToDefault = new wxButton( this, wxID_ANY, _("Reset to Default"), wxDefaultPosition, wxDefaultSize, 0 );
bButtonsSizer->Add( m_resetToDefault, 0, wxALL, 5 );
m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK );
m_sdbSizer->AddButton( m_sdbSizerOK );
@ -253,6 +256,7 @@ DIALOG_COLOR_PICKER_BASE::DIALOG_COLOR_PICKER_BASE( wxWindow* parent, wxWindowID
m_sliderTransparency->Connect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Connect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Connect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_resetToDefault->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_PICKER_BASE::OnResetButton ), NULL, this );
}
DIALOG_COLOR_PICKER_BASE::~DIALOG_COLOR_PICKER_BASE()
@ -285,5 +289,6 @@ DIALOG_COLOR_PICKER_BASE::~DIALOG_COLOR_PICKER_BASE()
m_sliderTransparency->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Disconnect( wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_sliderTransparency->Disconnect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( DIALOG_COLOR_PICKER_BASE::OnChangeAlpha ), NULL, this );
m_resetToDefault->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_COLOR_PICKER_BASE::OnResetButton ), NULL, this );
}

View File

@ -1640,6 +1640,79 @@
<property name="window_style"></property>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>
<property name="proportion">0</property>
<object class="wxButton" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
<property name="TopDockable">1</property>
<property name="aui_layer"></property>
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
<property name="caption"></property>
<property name="caption_visible">1</property>
<property name="center_pane">0</property>
<property name="close_button">1</property>
<property name="context_help"></property>
<property name="context_menu">1</property>
<property name="current"></property>
<property name="default">0</property>
<property name="default_pane">0</property>
<property name="disabled"></property>
<property name="dock">Dock</property>
<property name="dock_fixed">0</property>
<property name="docking">Left</property>
<property name="enabled">1</property>
<property name="fg"></property>
<property name="floatable">1</property>
<property name="focus"></property>
<property name="font"></property>
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Reset to Default</property>
<property name="margins"></property>
<property name="markup">0</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
<property name="min_size"></property>
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_resetToDefault</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
<property name="permission">protected</property>
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="position"></property>
<property name="pressed"></property>
<property name="resize">Resizable</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnResetButton</event>
</object>
</object>
<object class="sizeritem" expanded="1">
<property name="border">5</property>
<property name="flag">wxALL</property>

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Mar 28 2019)
// C++ code generated with wxFormBuilder (version Aug 21 2019)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -68,6 +68,7 @@ class DIALOG_COLOR_PICKER_BASE : public DIALOG_SHIM
wxStaticText* m_staticTextOldColor;
wxStaticBitmap* m_OldColorRect;
wxStaticBitmap* m_NewColorRect;
wxButton* m_resetToDefault;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel;
@ -84,6 +85,7 @@ class DIALOG_COLOR_PICKER_BASE : public DIALOG_SHIM
virtual void OnChangeEditSat( wxSpinEvent& event ) { event.Skip(); }
virtual void OnChangeBrightness( wxScrollEvent& event ) { event.Skip(); }
virtual void OnChangeAlpha( wxScrollEvent& event ) { event.Skip(); }
virtual void OnResetButton( wxCommandEvent& event ) { event.Skip(); }
public:

View File

@ -79,10 +79,12 @@ static std::unique_ptr<wxStaticBitmap> makeColorSwatch( wxWindow* aParent, COLOR
}
COLOR_SWATCH::COLOR_SWATCH( wxWindow* aParent, COLOR4D aColor, int aID, COLOR4D aBackground ):
COLOR_SWATCH::COLOR_SWATCH( wxWindow* aParent, COLOR4D aColor, int aID, COLOR4D aBackground,
const COLOR4D aDefault ) :
wxPanel( aParent, aID ),
m_color( aColor ),
m_background( aBackground )
m_background( aBackground ),
m_default( aDefault )
{
auto sizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( sizer );
@ -157,7 +159,7 @@ void COLOR_SWATCH::GetNewSwatchColor()
{
COLOR4D newColor = COLOR4D::UNSPECIFIED;
DIALOG_COLOR_PICKER dialog( ::wxGetTopLevelParent( this ), m_color, true );
DIALOG_COLOR_PICKER dialog( ::wxGetTopLevelParent( this ), m_color, true, nullptr, m_default );
if( dialog.ShowModal() == wxID_OK )
newColor = dialog.GetColor();

View File

@ -59,29 +59,46 @@ public:
virtual void Load( wxConfigBase *aConfig ) override;
virtual void Save( wxConfigBase *aConfig ) override;
/**
* Function GetDefaultLayerColor
* @return the default color for aLayer which is one of the item indices given in
* enum PCB_LAYER_ID
*/
static COLOR4D GetDefaultLayerColor( LAYER_NUM aLayer );
/**
* Function GetLayerColor
* @return the color for aLayer which
* @return the color for aLayer which is one of the item indices given in
* enum PCB_LAYER_ID
*/
COLOR4D GetLayerColor( LAYER_NUM aLayer ) const;
/**
* Function SetLayerColor
* sets the color for aLayer
* sets the color for aLayer which is one of the item indices given in
* enum PCB_LAYER_ID
*/
void SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor );
/**
* Function GetDefaultItemColor
* @return the default color for the an item which is one of the item
* indices given in enum GAL_LAYER_ID
*/
static COLOR4D GetDefaultItemColor( int aItemIdx );
/**
* Function GetItemColor
* @return the color for an item which is one of the item indices given
* in enum PCB_LAYER_ID
* in enum GAL_LAYER_ID
*/
COLOR4D GetItemColor( int aItemIdx ) const;
/**
* Function SetItemColor
* sets the color for an item which is one of the item indices given
* in enum PCB_LAYER_ID
* in enum GAL_LAYER_ID
*/
void SetItemColor( int aItemIdx, COLOR4D aColor );

View File

@ -46,7 +46,8 @@ public:
* @param aColor initial swatch color
* @param aID id to use when sending swatch events
*/
COLOR_SWATCH( wxWindow* aParent, KIGFX::COLOR4D aColor, int aID, KIGFX::COLOR4D aBackground );
COLOR_SWATCH( wxWindow* aParent, KIGFX::COLOR4D aColor, int aID, KIGFX::COLOR4D aBackground,
const KIGFX::COLOR4D aDefault = KIGFX::COLOR4D::UNSPECIFIED );
/**
* Set the current swatch color directly.
@ -85,6 +86,9 @@ private:
///> The background colour to show the swatch over
KIGFX::COLOR4D m_background;
///> The default color for the swatch
KIGFX::COLOR4D m_default;
///> Handle of the actual swatch shown
wxStaticBitmap* m_swatch;
};

View File

@ -328,7 +328,7 @@ void LAYER_WIDGET::insertLayerRow( int aRow, const ROW& aSpec )
col = COLUMN_COLORBM;
auto bmb = new COLOR_SWATCH( m_LayerScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
getBackgroundLayerColor() );
getBackgroundLayerColor(), aSpec.defaultColor );
bmb->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this );
bmb->SetToolTip( _("Left double click or middle click for color change, right click for menu" ) );
@ -403,7 +403,7 @@ void LAYER_WIDGET::insertRenderRow( int aRow, const ROW& aSpec )
if( aSpec.color != COLOR4D::UNSPECIFIED )
{
auto bmb = new COLOR_SWATCH( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
getBackgroundLayerColor() );
getBackgroundLayerColor(), aSpec.defaultColor );
bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnRenderSwatchChanged, this );
bmb->SetToolTip( _( "Left double click or middle click for color change" ) );
m_RenderFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );

View File

@ -93,9 +93,11 @@ public:
wxString tooltip; ///< if not empty, use this tooltip on row
bool changeable; ///< if true, the state can be changed
bool spacer; ///< if true, this row is a spacer
COLOR4D defaultColor; ///< The default color for the row
ROW( const wxString& aRowName, int aId, COLOR4D aColor = COLOR4D::UNSPECIFIED,
const wxString& aTooltip = wxEmptyString, bool aState = true, bool aChangeable = true )
const wxString& aTooltip = wxEmptyString, bool aState = true,
bool aChangeable = true, COLOR4D aDefaultColor = COLOR4D::UNSPECIFIED )
{
rowName = aRowName;
id = aId;
@ -104,6 +106,7 @@ public:
tooltip = aTooltip;
changeable = aChangeable;
spacer = false;
defaultColor = aDefaultColor;
}
ROW()
@ -113,6 +116,7 @@ public:
state = true;
changeable = true;
spacer = true;
defaultColor = COLOR4D::UNSPECIFIED;
}
};

View File

@ -404,6 +404,8 @@ void PCB_LAYER_WIDGET::ReFillRender()
// this window frame must have an established BOARD, i.e. after SetBoard()
renderRow.color = myframe->Settings().Colors().GetItemColor(
static_cast<GAL_LAYER_ID>( renderRow.id ) );
renderRow.defaultColor = myframe->Settings().Colors().GetDefaultItemColor(
static_cast<GAL_LAYER_ID>( renderRow.id ) );
}
if( renderRow.id == LAYER_RATSNEST )
@ -506,9 +508,9 @@ void PCB_LAYER_WIDGET::ReFill()
break;
}
AppendLayerRow( LAYER_WIDGET::ROW(
brd->GetLayerName( layer ), layer, myframe->Settings().Colors().GetLayerColor( layer ),
dsc, true ) );
AppendLayerRow( LAYER_WIDGET::ROW( brd->GetLayerName( layer ), layer,
myframe->Settings().Colors().GetLayerColor( layer ), dsc, true, true,
myframe->Settings().Colors().GetDefaultLayerColor( layer ) ) );
if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) )
{
@ -554,9 +556,10 @@ void PCB_LAYER_WIDGET::ReFill()
if( !enabled[layer] )
continue;
AppendLayerRow( LAYER_WIDGET::ROW(
brd->GetLayerName( layer ), layer, myframe->Settings().Colors().GetLayerColor( layer ),
wxGetTranslation( non_cu_seq[i].tooltip ), true ) );
AppendLayerRow( LAYER_WIDGET::ROW( brd->GetLayerName( layer ), layer,
myframe->Settings().Colors().GetLayerColor( layer ),
wxGetTranslation( non_cu_seq[i].tooltip ), true, true,
myframe->Settings().Colors().GetDefaultLayerColor( layer ) ) );
if( m_fp_editor_mode && LSET::ForbiddenFootprintLayers().test( layer ) )
{