KiCad PCB EDA Suite
PCB_LAYER_BOX_SELECTOR Class Reference

Class to display a pcb layer list in a wxBitmapComboBox. More...

#include <pcb_layer_box_selector.h>

Inheritance diagram for PCB_LAYER_BOX_SELECTOR:
LAYER_BOX_SELECTOR LAYER_SELECTOR

Public Member Functions

 PCB_LAYER_BOX_SELECTOR (wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=nullptr, int style=0)
 
void SetBoardFrame (PCB_BASE_FRAME *aFrame)
 
void SetNotAllowedLayerSet (LSET aMask)
 
void SetUndefinedLayerName (const wxString &aName)
 
void Resync () override
 
void ShowNonActivatedLayers (bool aShow)
 
int GetLayerSelection () const
 
int SetLayerSelection (int layer)
 
void ResyncBitmapOnly ()
 
bool SetLayersHotkeys (bool value)
 

Static Public Member Functions

static void DrawColorSwatch (wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
 

Protected Attributes

bool m_layerhotkeys
 

Private Member Functions

COLOR4D getLayerColor (int aLayer) const override
 
bool isLayerEnabled (int aLayer) const override
 
wxString getLayerName (int aLayer) const override
 
LSET getEnabledLayers () const
 
void onKeyDown (wxKeyEvent &aEvent)
 

Private Attributes

PCB_BASE_FRAMEm_boardFrame
 
LSET m_layerMaskDisable
 
bool m_showNotEnabledBrdlayers
 
wxString m_undefinedLayerName
 

Detailed Description

Class to display a pcb layer list in a wxBitmapComboBox.

Definition at line 35 of file pcb_layer_box_selector.h.

Constructor & Destructor Documentation

◆ PCB_LAYER_BOX_SELECTOR()

PCB_LAYER_BOX_SELECTOR::PCB_LAYER_BOX_SELECTOR ( wxWindow *  parent,
wxWindowID  id,
const wxString &  value = wxEmptyString,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
int  n = 0,
const wxString  choices[] = nullptr,
int  style = 0 
)
inline

Definition at line 41 of file pcb_layer_box_selector.h.

45 :
46 LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices )
47 {
48 m_boardFrame = nullptr;
50 }
LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=nullptr)

References m_boardFrame, and m_showNotEnabledBrdlayers.

Member Function Documentation

◆ DrawColorSwatch()

void LAYER_SELECTOR::DrawColorSwatch ( wxBitmap &  aLayerbmp,
const COLOR4D aBackground,
const COLOR4D aColor 
)
staticinherited

Definition at line 47 of file layer_box_selector.cpp.

49{
50 wxMemoryDC bmpDC;
51 wxBrush brush;
52
53 // Prepare Bitmap
54 bmpDC.SelectObject( aLayerbmp );
55
56 brush.SetStyle( wxBRUSHSTYLE_SOLID );
57
58 if( aBackground != COLOR4D::UNSPECIFIED )
59 {
60 brush.SetColour( aBackground.WithAlpha( 1.0 ).ToColour() );
61 bmpDC.SetBrush( brush );
62 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
63 }
64
65 brush.SetColour( aColor.ToColour() );
66 bmpDC.SetBrush( brush );
67 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
68
69 bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
70 bmpDC.SetPen( *wxBLACK_PEN );
71 bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
72}
COLOR4D WithAlpha(double aAlpha) const
Return a color with the same color, but the given alpha.
Definition: color4d.h:321

References KIGFX::COLOR4D::WithAlpha().

Referenced by PANEL_SETUP_BOARD_STACKUP::createColorBox(), GRID_CELL_LAYER_RENDERER::Draw(), PANEL_SETUP_BOARD_STACKUP::onColorSelected(), GBR_LAYER_BOX_SELECTOR::Resync(), Resync(), LAYER_BOX_SELECTOR::ResyncBitmapOnly(), and PANEL_SETUP_BOARD_STACKUP::synchronizeWithBoard().

◆ getEnabledLayers()

LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers ( ) const
private

Definition at line 147 of file pcb_layer_box_selector.cpp.

148{
149 static LSET footprintEditorLayers = LSET::AllLayersMask() & ~LSET::ForbiddenFootprintLayers();
150
151 if( m_boardFrame )
153 else
154 return footprintEditorLayers;
155}
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:526
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
static LSET AllLayersMask()
Definition: lset.cpp:808
BOARD * GetBoard() const

References LSET::AllLayersMask(), PCB_BASE_FRAME::GetBoard(), BOARD::GetEnabledLayers(), and m_boardFrame.

Referenced by isLayerEnabled(), and Resync().

◆ getLayerColor()

COLOR4D PCB_LAYER_BOX_SELECTOR::getLayerColor ( int  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 159 of file pcb_layer_box_selector.cpp.

160{
161 if( m_boardFrame )
162 {
163 return m_boardFrame->GetColorSettings()->GetColor( aLayer );
164 }
165 else
166 {
167 SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
169 COLOR_SETTINGS* current = mgr.GetColorSettings( settings->m_ColorTheme );
170
171 return current->GetColor( aLayer );
172 }
173}
wxString m_ColorTheme
Active color theme name.
Definition: app_settings.h:196
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
virtual COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Helper to retrieve the current color settings.
T * GetAppSettings(bool aLoadNow=true)
Returns a handle to the a given settings by type If the settings have already been loaded,...
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References SETTINGS_MANAGER::GetAppSettings(), COLOR_SETTINGS::GetColor(), PCB_BASE_FRAME::GetColorSettings(), SETTINGS_MANAGER::GetColorSettings(), m_boardFrame, APP_SETTINGS_BASE::m_ColorTheme, and Pgm().

Referenced by Resync().

◆ getLayerName()

wxString PCB_LAYER_BOX_SELECTOR::getLayerName ( int  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 177 of file pcb_layer_box_selector.cpp.

178{
179 if( m_boardFrame )
180 return m_boardFrame->GetBoard()->GetLayerName( ToLAYER_ID( aLayer ) );
181 else
182 return BOARD::GetStandardLayerName( ToLAYER_ID( aLayer ) );
183}
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition: board.h:696
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:413
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:932

References PCB_BASE_FRAME::GetBoard(), BOARD::GetLayerName(), BOARD::GetStandardLayerName(), m_boardFrame, and ToLAYER_ID().

Referenced by Resync().

◆ GetLayerSelection()

◆ isLayerEnabled()

bool PCB_LAYER_BOX_SELECTOR::isLayerEnabled ( int  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 141 of file pcb_layer_box_selector.cpp.

142{
143 return getEnabledLayers().test( aLayer );
144}

References getEnabledLayers().

◆ onKeyDown()

void LAYER_BOX_SELECTOR::onKeyDown ( wxKeyEvent &  aEvent)
privateinherited

Definition at line 151 of file layer_box_selector.cpp.

152{
153#ifdef __WXOSX_MAC__
154 if( aEvent.GetKeyCode() == WXK_ESCAPE && IsPopupShown() )
155 {
156 Dismiss();
157 return;
158 }
159#endif
160
161 aEvent.Skip();
162}

Referenced by LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR(), and LAYER_BOX_SELECTOR::~LAYER_BOX_SELECTOR().

◆ Resync()

void PCB_LAYER_BOX_SELECTOR::Resync ( )
overridevirtual

Implements LAYER_BOX_SELECTOR.

Definition at line 82 of file pcb_layer_box_selector.cpp.

83{
84 Freeze();
85 Clear();
86
87 const int BM_SIZE = 14;
88
89 LSET show = LSET::AllLayersMask() & ~m_layerMaskDisable;
90 LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
91 wxString layerstatus;
92
93 for( PCB_LAYER_ID layerid : show.UIOrder() )
94 {
95 if( !m_showNotEnabledBrdlayers && !activated[layerid] )
96 continue;
97 else if( !activated[layerid] )
98 layerstatus = wxT( " " ) + _( "(not activated)" );
99 else
100 layerstatus.Empty();
101
102 wxBitmap bmp( BM_SIZE, BM_SIZE );
104
105 wxString layername = getLayerName( layerid ) + layerstatus;
106
107 if( m_layerhotkeys )
108 {
109 TOOL_ACTION* action = layer2action( layerid );
110
111 if( action )
112 layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
113 }
114
115 Append( layername, bmp, (void*)(intptr_t) layerid );
116 }
117
118 if( !m_undefinedLayerName.IsEmpty() )
119 Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
120
121 // Ensure the size of the widget is enough to show the text and the icon
122 // We have to have a selected item when doing this, because otherwise GTK
123 // will just choose a random size that might not fit the actual data
124 // (such as in cases where the font size is very large). So we select
125 // the first item, get the size of the control and make that the minimum size,
126 // then remove the selection (which was the initial state).
127 SetSelection( 0 );
128
129 SetMinSize( wxSize( -1, -1 ) );
130 wxSize bestSize = GetBestSize();
131
132 bestSize.x = GetBestSize().x + BM_SIZE + 10;
133 SetMinSize( bestSize );
134
135 SetSelection( wxNOT_FOUND );
136 Thaw();
137}
static void DrawColorSwatch(wxBitmap &aLayerbmp, const COLOR4D &aBackground, const COLOR4D &aColor)
LSEQ UIOrder() const
Definition: lset.cpp:922
COLOR4D getLayerColor(int aLayer) const override
wxString getLayerName(int aLayer) const override
Represent a single user action.
Definition: tool_action.h:68
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:111
#define _(s)
#define BM_SIZE
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
@ IS_COMMENT
Definition: hotkeys_basic.h:78
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
static TOOL_ACTION * layer2action(PCB_LAYER_ID aLayer)

References _, AddHotkeyName(), LSET::AllLayersMask(), BM_SIZE, LAYER_SELECTOR::DrawColorSwatch(), getEnabledLayers(), TOOL_ACTION::GetHotKey(), getLayerColor(), getLayerName(), IS_COMMENT, layer2action(), LAYER_PCB_BACKGROUND, LAYER_SELECTOR::m_layerhotkeys, m_showNotEnabledBrdlayers, m_undefinedLayerName, LSET::UIOrder(), and UNDEFINED_LAYER.

Referenced by GRID_CELL_LAYER_SELECTOR::BeginEdit(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists(), DIALOG_DIMENSION_PROPERTIES::DIALOG_DIMENSION_PROPERTIES(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS(), DIALOG_GRAPHIC_ITEM_PROPERTIES::DIALOG_GRAPHIC_ITEM_PROPERTIES(), DIALOG_IMAGE_PROPERTIES::DIALOG_IMAGE_PROPERTIES(), DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX(), DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_PROPERTIES(), DIALOG_TEXTBOX_PROPERTIES::DIALOG_TEXTBOX_PROPERTIES(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), FOOTPRINT_EDIT_FRAME::ReCreateHToolbar(), FOOTPRINT_EDIT_FRAME::ReCreateLayerBox(), and PCB_EDIT_FRAME::ReCreateLayerBox().

◆ ResyncBitmapOnly()

void LAYER_BOX_SELECTOR::ResyncBitmapOnly ( )
inherited

Definition at line 141 of file layer_box_selector.cpp.

142{
143 for( int i = 0; i < (int) GetCount(); ++i )
144 {
145 wxBitmap layerbmp( 14, 14 );
147 }
148}
virtual COLOR4D getLayerColor(int aLayer) const =0

References LAYER_SELECTOR::DrawColorSwatch(), LAYER_SELECTOR::getLayerColor(), and LAYER_PCB_BACKGROUND.

Referenced by LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR(), and GERBER_LAYER_WIDGET::OnLayerColorChange().

◆ SetBoardFrame()

◆ SetLayerSelection()

int LAYER_BOX_SELECTOR::SetLayerSelection ( int  layer)
inherited

Definition at line 117 of file layer_box_selector.cpp.

118{
119 for( int i = 0; i < (int) GetCount(); i++ )
120 {
121 if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
122 {
123 if( GetSelection() != i ) // Element (i) is not selected
124 {
125 SetSelection( i );
126 return i;
127 }
128 else
129 {
130 return i; // If element already selected; do nothing
131 }
132 }
133 }
134
135 // Not Found
136 SetSelection( -1 );
137 return -1;
138}

Referenced by GRID_CELL_LAYER_SELECTOR::BeginEdit(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists(), DIALOG_IMPORT_GFX::DIALOG_IMPORT_GFX(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), FOOTPRINT_EDIT_FRAME::OnUpdateLayerSelectBox(), PCB_EDIT_FRAME::OnUpdateLayerSelectBox(), DIALOG_TRACK_VIA_PROPERTIES::onViaEdit(), GRID_CELL_LAYER_SELECTOR::Reset(), DIALOG_DIMENSION_PROPERTIES::TransferDataToWindow(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataToWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), DIALOG_TEXTBOX_PROPERTIES::TransferDataToWindow(), and PCB_EDIT_FRAME::UpdateUserInterface().

◆ SetLayersHotkeys()

◆ SetNotAllowedLayerSet()

◆ SetUndefinedLayerName()

◆ ShowNonActivatedLayers()

Member Data Documentation

◆ m_boardFrame

PCB_BASE_FRAME* PCB_LAYER_BOX_SELECTOR::m_boardFrame
private

◆ m_layerhotkeys

bool LAYER_SELECTOR::m_layerhotkeys
protectedinherited

◆ m_layerMaskDisable

LSET PCB_LAYER_BOX_SELECTOR::m_layerMaskDisable
private

Definition at line 85 of file pcb_layer_box_selector.h.

Referenced by SetNotAllowedLayerSet().

◆ m_showNotEnabledBrdlayers

bool PCB_LAYER_BOX_SELECTOR::m_showNotEnabledBrdlayers
private

Definition at line 87 of file pcb_layer_box_selector.h.

Referenced by PCB_LAYER_BOX_SELECTOR(), Resync(), and ShowNonActivatedLayers().

◆ m_undefinedLayerName

wxString PCB_LAYER_BOX_SELECTOR::m_undefinedLayerName
private

Definition at line 89 of file pcb_layer_box_selector.h.

Referenced by Resync(), and SetUndefinedLayerName().


The documentation for this class was generated from the following files: