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[]=NULL, 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 GetChoice ()
 
LAYER_NUM GetLayerSelection () const
 
int SetLayerSelection (LAYER_NUM layer)
 
void ResyncBitmapOnly ()
 
bool SetLayersHotkeys (bool value)
 

Static Public Member Functions

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

Protected Attributes

bool m_layerhotkeys
 

Private Member Functions

COLOR4D getLayerColor (LAYER_NUM aLayer) const override
 
bool isLayerEnabled (LAYER_NUM aLayer) const override
 
wxString getLayerName (LAYER_NUM aLayer) const override
 
LSET getEnabledLayers () const
 

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[] = NULL,
int  style = 0 
)
inline

Definition at line 50 of file pcb_layer_box_selector.h.

54  :
55  LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices )
56  {
59  }
LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=NULL)
#define NULL

References m_boardFrame, m_showNotEnabledBrdlayers, and NULL.

Member Function Documentation

◆ DrawColorSwatch()

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

Definition at line 47 of file layer_box_selector.cpp.

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

References KIGFX::COLOR4D::WithAlpha().

Referenced by PANEL_SETUP_BOARD_STACKUP::createBmComboBox(), 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().

◆ GetChoice()

int LAYER_BOX_SELECTOR::GetChoice ( )
inherited

Definition at line 109 of file layer_box_selector.cpp.

110 {
111  return GetSelection();
112 }

◆ getEnabledLayers()

LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers ( ) const
private

Definition at line 154 of file pcb_layer_box_selector.cpp.

155 {
156  BOARD* board = m_boardFrame->GetBoard();
157 
158  return board->GetEnabledLayers();
159 }
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
BOARD * GetBoard() const

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

Referenced by Resync().

◆ getLayerColor()

COLOR4D PCB_LAYER_BOX_SELECTOR::getLayerColor ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 163 of file pcb_layer_box_selector.cpp.

164 {
165  wxASSERT( m_boardFrame );
166 
167  return m_boardFrame->GetColorSettings()->GetColor( aLayer );
168 }
virtual COLOR_SETTINGS * GetColorSettings() override
Helper to retrieve the current color settings.
COLOR4D GetColor(int aLayer) const

References COLOR_SETTINGS::GetColor(), PCB_BASE_FRAME::GetColorSettings(), and m_boardFrame.

Referenced by Resync().

◆ getLayerName()

wxString PCB_LAYER_BOX_SELECTOR::getLayerName ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 172 of file pcb_layer_box_selector.cpp.

173 {
174  BOARD* board = m_boardFrame->GetBoard();
175 
176  return board->GetLayerName( ToLAYER_ID( aLayer ) );
177 }
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer.
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
BOARD * GetBoard() const
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:849

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

Referenced by Resync().

◆ GetLayerSelection()

◆ isLayerEnabled()

bool PCB_LAYER_BOX_SELECTOR::isLayerEnabled ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 146 of file pcb_layer_box_selector.cpp.

147 {
148  BOARD* board = m_boardFrame->GetBoard();
149 
150  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
151 }
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
Function IsLayerEnabled is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:463
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
BOARD * GetBoard() const
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:849

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

◆ Resync()

void PCB_LAYER_BOX_SELECTOR::Resync ( )
overridevirtual

Implements LAYER_BOX_SELECTOR.

Definition at line 84 of file pcb_layer_box_selector.cpp.

85 {
86  Clear();
87 
88  // Tray to fix a minimum width fot the BitmapComboBox
89  int minwidth = 80;
90 
91  wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
92 
93  const int BM_SIZE = 14;
94 
96  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
97  wxString layerstatus;
98 
99  for( LSEQ seq = show.UIOrder(); seq; ++seq )
100  {
101  PCB_LAYER_ID layerid = *seq;
102 
103  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
104  continue;
105  else if( !activated[layerid] )
106  layerstatus = wxT( " " ) + _( "(not activated)" );
107  else
108  layerstatus.Empty();
109 
110  wxBitmap bmp( BM_SIZE, BM_SIZE );
112 
113  wxString layername = getLayerName( layerid ) + layerstatus;
114 
115  if( m_layerhotkeys )
116  {
117  TOOL_ACTION* action = layer2action( layerid );
118 
119  if( action )
120  layername = AddHotkeyName( layername, action->GetHotKey(), IS_COMMENT );
121  }
122 
123  Append( layername, bmp, (void*)(intptr_t) layerid );
124 
125  int w, h;
126  dc.GetTextExtent ( layername, &w, &h );
127  minwidth = std::max( minwidth, w );
128  }
129 
130  if( !m_undefinedLayerName.IsEmpty() )
131  {
132  Append( m_undefinedLayerName, wxNullBitmap, (void*)(intptr_t)UNDEFINED_LAYER );
133 
134  int w, h;
135  dc.GetTextExtent ( m_undefinedLayerName, &w, &h );
136  minwidth = std::max( minwidth, w );
137  }
138 
139  // Approximate bitmap size and margins
140  minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
141  SetMinSize( wxSize( minwidth, -1 ) );
142 }
static TOOL_ACTION * layer2action(PCB_LAYER_ID aLayer)
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
AddHotkeyName.
COLOR4D getLayerColor(LAYER_NUM aLayer) const override
PCB_LAYER_ID
A quick note on layer IDs:
LSET is a set of PCB_LAYER_IDs.
wxString getLayerName(LAYER_NUM aLayer) const override
static LSET AllLayersMask()
Definition: lset.cpp:749
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)
#define BM_SIZE
#define _(s)
Definition: 3d_actions.cpp:33
TOOL_ACTION.
Definition: tool_action.h:46
LSEQ UIOrder() const
Definition: lset.cpp:839
int GetHotKey() const
Function GetHotKey() Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:90

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_layerMaskDisable, m_showNotEnabledBrdlayers, m_undefinedLayerName, LSET::UIOrder(), and UNDEFINED_LAYER.

Referenced by GRID_CELL_LAYER_SELECTOR::BeginEdit(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildFilterLists(), 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_IMPORT_GFX::DIALOG_IMPORT_GFX(), DIALOG_TEXT_PROPERTIES::DIALOG_TEXT_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 150 of file layer_box_selector.cpp.

151 {
152  int elements = GetCount();
153 
154  for( LAYER_NUM i = 0; i < elements; ++i )
155  {
156  wxBitmap layerbmp( 14, 14 );
158  }
159 }
virtual COLOR4D getLayerColor(LAYER_NUM aLayer) const =0
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
static void DrawColorSwatch(wxBitmap &aLayerbmp, COLOR4D aBackground, COLOR4D aColor)

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 ( LAYER_NUM  layer)
inherited

Definition at line 126 of file layer_box_selector.cpp.

127 {
128  int elements = GetCount();
129 
130  for( int i = 0; i < elements; i++ )
131  {
132  if( GetClientData( (unsigned) i ) == (void*)(intptr_t) layer )
133  {
134  if( GetSelection() != i ) // Element (i) is not selected
135  {
136  SetSelection( i );
137  return i;
138  }
139  else
140  return i; //If element already selected; do nothing
141  }
142  }
143 
144  // Not Found
145  SetSelection( -1 );
146  return -1;
147 }

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_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow(), and DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::TransferDataToWindow().

◆ SetLayersHotkeys()

◆ SetNotAllowedLayerSet()

◆ SetUndefinedLayerName()

◆ ShowNonActivatedLayers()

void PCB_LAYER_BOX_SELECTOR::ShowNonActivatedLayers ( bool  aShow)
inline

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 39 of file pcb_layer_box_selector.h.

Referenced by Resync(), and SetNotAllowedLayerSet().

◆ m_showNotEnabledBrdlayers

bool PCB_LAYER_BOX_SELECTOR::m_showNotEnabledBrdlayers
private

Definition at line 41 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 43 of file pcb_layer_box_selector.h.

Referenced by Resync(), and SetUndefinedLayerName().


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