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 Resync () override
 
void ShowNonActivatedLayers (bool aShow)
 
int GetChoice ()
 
LAYER_NUM GetLayerSelection () const
 
int SetLayerSelection (LAYER_NUM layer)
 
void ResyncBitmapOnly ()
 
bool SetLayersOrdered (bool value)
 
bool SetLayersHotkeys (bool value)
 

Public Attributes

EDA_HOTKEY_CONFIGm_hotkeys
 

Protected Member Functions

void SetBitmapLayer (wxBitmap &aLayerbmp, LAYER_NUM aLayer)
 

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
 

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

58  :
59  LAYER_BOX_SELECTOR( parent, id, pos, size, n, choices )
60  {
61  m_boardFrame = NULL;
62  m_hotkeys = NULL;
64  }
EDA_HOTKEY_CONFIG * m_hotkeys
LAYER_BOX_SELECTOR(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, int n=0, const wxString choices[]=NULL)

Member Function Documentation

int LAYER_BOX_SELECTOR::GetChoice ( )
inherited

Definition at line 105 of file layer_box_selector.cpp.

106 {
107  return GetSelection();
108 }
LSET PCB_LAYER_BOX_SELECTOR::getEnabledLayers ( ) const
private

Definition at line 138 of file pcb_layer_box_selector.cpp.

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

Referenced by Resync(), and ShowNonActivatedLayers().

139 {
140  wxASSERT( m_boardFrame != NULL );
141  BOARD* board = m_boardFrame->GetBoard();
142  wxASSERT( board != NULL );
143 
144  return board->GetEnabledLayers();
145 }
BOARD * GetBoard() const
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
COLOR4D PCB_LAYER_BOX_SELECTOR::GetLayerColor ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 149 of file pcb_layer_box_selector.cpp.

References PCB_GENERAL_SETTINGS::Colors(), COLORS_DESIGN_SETTINGS::GetLayerColor(), m_boardFrame, PCB_BASE_FRAME::Settings(), and ToLAYER_ID().

Referenced by ShowNonActivatedLayers().

150 {
151  wxASSERT( m_boardFrame );
152 
153  return m_boardFrame->Settings().Colors().GetLayerColor( ToLAYER_ID( aLayer ) );
154 }
PCB_GENERAL_SETTINGS & Settings()
COLORS_DESIGN_SETTINGS & Colors()
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
wxString PCB_LAYER_BOX_SELECTOR::GetLayerName ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 158 of file pcb_layer_box_selector.cpp.

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

Referenced by Resync(), and ShowNonActivatedLayers().

159 {
160  wxASSERT( m_boardFrame );
161  BOARD* board = m_boardFrame->GetBoard();
162  wxASSERT( board );
163 
164  return board->GetLayerName( ToLAYER_ID( aLayer ) );
165 }
BOARD * GetBoard() const
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Function GetLayerName returns the name of a layer given by aLayer.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
bool PCB_LAYER_BOX_SELECTOR::IsLayerEnabled ( LAYER_NUM  aLayer) const
overrideprivatevirtual

Implements LAYER_SELECTOR.

Definition at line 128 of file pcb_layer_box_selector.cpp.

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

Referenced by ShowNonActivatedLayers().

129 {
130  wxASSERT( m_boardFrame != NULL );
131  BOARD* board = m_boardFrame->GetBoard();
132  wxASSERT( board != NULL );
133 
134  return board->IsLayerEnabled( ToLAYER_ID( aLayer ) );
135 }
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:439
BOARD * GetBoard() const
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
void PCB_LAYER_BOX_SELECTOR::Resync ( )
overridevirtual

Implements LAYER_BOX_SELECTOR.

Definition at line 75 of file pcb_layer_box_selector.cpp.

References AddHotkeyName(), LSET::AllLayersMask(), BM_SIZE, getEnabledLayers(), GetLayerName(), IS_COMMENT, layer2hotkey_id(), m_hotkeys, LAYER_SELECTOR::m_layerhotkeys, m_layerMaskDisable, m_showNotEnabledBrdlayers, max, LAYER_SELECTOR::SetBitmapLayer(), and LSET::UIOrder().

Referenced by DIALOG_DIMENSION_EDITOR::DIALOG_DIMENSION_EDITOR(), DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), PCB_EDIT_FRAME::ReCreateLayerBox(), SetNotAllowedLayerSet(), DIALOG_EDIT_FPTEXT::TransferDataToWindow(), DIALOG_PCB_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataToWindow(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow().

76 {
77  Clear();
78 
79  // Tray to fix a minimum width fot the BitmapComboBox
80  int minwidth = 80;
81 
82  wxClientDC dc( GetParent() ); // The DC for "this" is not always initialized
83 
84  const int BM_SIZE = 14;
85 
87  LSET activated = getEnabledLayers() & ~m_layerMaskDisable;
88  wxString layerstatus;
89 
90  for( LSEQ seq = show.UIOrder(); seq; ++seq )
91  {
92  PCB_LAYER_ID layerid = *seq;
93 
94  if( !m_showNotEnabledBrdlayers && !activated[layerid] )
95  continue;
96  else if( !activated[layerid] )
97  layerstatus = wxT( " " ) + _( "(not activated)" );
98  else
99  layerstatus.Empty();
100 
101  wxBitmap layerbmp( BM_SIZE, BM_SIZE );
102  SetBitmapLayer( layerbmp, layerid );
103 
104  wxString layername = GetLayerName( layerid ) + layerstatus;
105 
106  if( m_layerhotkeys && m_hotkeys )
107  {
108  int id = layer2hotkey_id( layerid );
109 
110  if( id != -1 )
111  layername = AddHotkeyName( layername, m_hotkeys, id, IS_COMMENT );
112  }
113 
114  Append( layername, layerbmp, (void*)(intptr_t) layerid );
115 
116  int w, h;
117  dc.GetTextExtent ( layername, &w, &h );
118  minwidth = std::max( minwidth, w );
119  }
120 
121  // Approximate bitmap size and margins
122  minwidth += BM_SIZE + 32 + ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
123  SetMinSize( wxSize( minwidth, -1 ) );
124 }
EDA_HOTKEY_CONFIG * m_hotkeys
void SetBitmapLayer(wxBitmap &aLayerbmp, LAYER_NUM aLayer)
PCB_LAYER_ID
A quick note on layer IDs:
Class LSET is a set of PCB_LAYER_IDs.
static LSET AllLayersMask()
Definition: lset.cpp:710
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
static int layer2hotkey_id(PCB_LAYER_ID aLayer)
#define BM_SIZE
wxString AddHotkeyName(const wxString &aText, EDA_HOTKEY **aList, int aCommandId, HOTKEY_ACTION_TYPE aShortCutType)
Function AddHotkeyName Add the key name from the Command id value ( m_Idcommand member value) ...
#define max(a, b)
Definition: auxiliary.h:86
wxString GetLayerName(LAYER_NUM aLayer) const override
LSEQ UIOrder() const
Definition: lset.cpp:786
void LAYER_BOX_SELECTOR::ResyncBitmapOnly ( )
inherited

Definition at line 146 of file layer_box_selector.cpp.

References i, and LAYER_SELECTOR::SetBitmapLayer().

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

147 {
148  int elements = GetCount();
149 
150  for( LAYER_NUM i = 0; i < elements; ++i )
151  {
152  wxBitmap layerbmp( 14, 14 );
153  SetBitmapLayer( layerbmp, i );
154  }
155 }
void SetBitmapLayer(wxBitmap &aLayerbmp, LAYER_NUM aLayer)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
size_t i
Definition: json11.cpp:597
void LAYER_SELECTOR::SetBitmapLayer ( wxBitmap &  aLayerbmp,
LAYER_NUM  aLayer 
)
protectedinherited

Definition at line 48 of file layer_box_selector.cpp.

References LAYER_SELECTOR::GetLayerColor(), LAYER_PCB_BACKGROUND, and KIGFX::COLOR4D::WithAlpha().

Referenced by GBR_LAYER_BOX_SELECTOR::Resync(), Resync(), and LAYER_BOX_SELECTOR::ResyncBitmapOnly().

49 {
50  wxMemoryDC bmpDC;
51  wxBrush brush;
52 
53  // Prepare Bitmap
54  bmpDC.SelectObject( aLayerbmp );
55 
56  brush.SetStyle( wxBRUSHSTYLE_SOLID );
57  COLOR4D backgroundColor = GetLayerColor( LAYER_PCB_BACKGROUND );
58  if( backgroundColor != COLOR4D::UNSPECIFIED )
59  {
60  brush.SetColour( backgroundColor.WithAlpha(1.0).ToColour() );
61  bmpDC.SetBrush( brush );
62  bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
63  }
64 
65  brush.SetColour( GetLayerColor( aLayer ).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 }
virtual COLOR4D GetLayerColor(LAYER_NUM aLayer) const =0
COLOR4D WithAlpha(double aAlpha) const
Function WithAlpha Returns a colour with the same colour, but the given alpha.
Definition: color4d.h:237
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
int LAYER_BOX_SELECTOR::SetLayerSelection ( LAYER_NUM  layer)
inherited

Definition at line 122 of file layer_box_selector.cpp.

References i.

Referenced by DIALOG_DIMENSION_EDITOR::DIALOG_DIMENSION_EDITOR(), DIALOG_DXF_IMPORT::DIALOG_DXF_IMPORT(), DIALOG_TRACK_VIA_PROPERTIES::DIALOG_TRACK_VIA_PROPERTIES(), PCB_EDIT_FRAME::OnUpdateLayerSelectBox(), DIALOG_TRACK_VIA_PROPERTIES::onViaEdit(), DIALOG_EDIT_FPTEXT::TransferDataToWindow(), DIALOG_PCB_TEXT_PROPERTIES::TransferDataToWindow(), DIALOG_MODEDIT_FP_BODY_ITEM_PROPERTIES::TransferDataToWindow(), and DIALOG_GRAPHIC_ITEM_PROPERTIES::TransferDataToWindow().

123 {
124  int elements = GetCount();
125 
126  for( int i = 0; i < elements; i++ )
127  {
128  if( GetClientData( i ) == (void*)(intptr_t) layer )
129  {
130  if( GetSelection() != i ) // Element (i) is not selected
131  {
132  SetSelection( i );
133  return i;
134  }
135  else
136  return i; //If element already selected; do nothing
137  }
138  }
139 
140  // Not Found
141  SetSelection( -1 );
142  return -1;
143 }
size_t i
Definition: json11.cpp:597
bool LAYER_SELECTOR::SetLayersOrdered ( bool  value)
inherited
void PCB_LAYER_BOX_SELECTOR::ShowNonActivatedLayers ( bool  aShow)
inline

Member Data Documentation

PCB_BASE_FRAME* PCB_LAYER_BOX_SELECTOR::m_boardFrame
private
EDA_HOTKEY_CONFIG* PCB_LAYER_BOX_SELECTOR::m_hotkeys

Definition at line 46 of file pcb_layer_box_selector.h.

Referenced by PCB_EDIT_FRAME::ReCreateLayerBox(), and Resync().

bool LAYER_SELECTOR::m_layerhotkeys
protectedinherited
LSET PCB_LAYER_BOX_SELECTOR::m_layerMaskDisable
private

Definition at line 39 of file pcb_layer_box_selector.h.

Referenced by Resync().

bool PCB_LAYER_BOX_SELECTOR::m_showNotEnabledBrdlayers
private

Definition at line 41 of file pcb_layer_box_selector.h.

Referenced by Resync().


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