KiCad PCB EDA Suite
LAYER_WIDGET Class Referenceabstract

Class LAYER_WIDGET is abstract and is used to manage a list of layers, with the notion of a "current" layer, and layer specific visibility control. More...

#include <layer_widget.h>

Inheritance diagram for LAYER_WIDGET:
GERBER_LAYER_WIDGET PCB_LAYER_WIDGET

Classes

struct  ROW
 Struct ROW provides all the data needed to add a row to a LAYER_WIDGET. More...
 

Public Member Functions

 LAYER_WIDGET (wxWindow *aParent, wxWindow *aFocusOwner, int aPointSize=-1, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
 Constructor. More...
 
virtual ~LAYER_WIDGET ()
 
wxSize GetBestSize () const
 Function GetBestSize returns the preferred minimum size, taking into consideration the dynamic content. More...
 
int GetLayerRowCount () const
 Function GetLayerRowCount returns the number of rows in the layer tab. More...
 
int GetRenderRowCount () const
 Function GetRenderRowCount returns the number of rows in the render tab. More...
 
void AppendLayerRow (const ROW &aRow)
 Function AppendLayerRow appends a new row in the layer portion of the widget. More...
 
void AppendLayerRows (const ROW *aRowsArray, int aRowCount)
 Function AppendLayerRows appends new rows in the layer portion of the widget. More...
 
void ClearLayerRows ()
 Function ClearLayerRows empties out the layer rows. More...
 
void AppendRenderRow (const ROW &aRow)
 Function AppendRenderRow appends a new row in the render portion of the widget. More...
 
void AppendRenderRows (const ROW *aRowsArray, int aRowCount)
 Function AppendRenderRows appends new rows in the render portion of the widget. More...
 
void ClearRenderRows ()
 Function ClearRenderRows empties out the render rows. More...
 
void SelectLayerRow (int aRow)
 Function SelectLayerRow changes the row selection in the layer list to the given row. More...
 
void SelectLayer (LAYER_NUM aLayer)
 Function SelectLayer changes the row selection in the layer list to aLayer provided. More...
 
LAYER_NUM GetSelectedLayer ()
 Function GetSelectedLayer returns the selected layer or -1 if none. More...
 
void SetLayerVisible (LAYER_NUM aLayer, bool isVisible)
 Function SetLayerVisible sets aLayer visible or not. More...
 
bool IsLayerVisible (LAYER_NUM aLayer)
 Function IsLayerVisible returns the visible state of the layer ROW associated with aLayer id. More...
 
void SetLayerColor (LAYER_NUM aLayer, COLOR4D aColor)
 Function SetLayerColor changes the color of aLayer. More...
 
COLOR4D GetLayerColor (LAYER_NUM aLayer) const
 Function GetLayerColor returns the color of the layer ROW associated with aLayer id. More...
 
void SetRenderState (int aId, bool isSet)
 Function SetRenderState sets the state of the checkbox associated with aId within the Render tab group of the widget. More...
 
bool GetRenderState (int aId)
 Function GetRenderState returns the state of the checkbox associated with aId. More...
 
void UpdateLayouts ()
 
void UpdateLayerIcons ()
 Function UpdateLayerIcons Update all layer manager icons (layers only) Useful when loading a file or clearing a layer because they change, and the indicator arrow icon needs to be updated. More...
 
virtual void OnLayerColorChange (int aLayer, COLOR4D aColor)=0
 Function OnLayerColorChange is called to notify client code about a layer color change. More...
 
virtual bool OnLayerSelect (int aLayer)=0
 Function OnLayerSelect is called to notify client code whenever the user selects a different layer. More...
 
virtual void OnLayerVisible (LAYER_NUM aLayer, bool isVisible, bool isFinal=true)=0
 Function OnLayerVisible is called to notify client code about a layer visibility change. More...
 
virtual void OnRenderColorChange (int aId, COLOR4D aColor)=0
 Function OnRenderColorChange is called to notify client code whenever the user changes a rendering color. More...
 
virtual void OnRenderEnable (int aId, bool isEnabled)=0
 Function OnRenderEnable is called to notify client code whenever the user changes an rendering enable in one of the rendering checkboxes. More...
 

Static Public Attributes

static const wxEventType EVT_LAYER_COLOR_CHANGE = wxNewEventType()
 

Protected Member Functions

virtual bool useAlternateBitmap (int aRow)
 Virtual Function useAlternateBitmap. More...
 
virtual bool AreArbitraryColorsAllowed ()
 Subclasses can override this to provide logic for allowing arbitrary color selection via wxColourPicker instead of DisplayColorFrame. More...
 
void OnLeftDownLayers (wxMouseEvent &event)
 
void OnLayerSwatchChanged (wxCommandEvent &aEvent)
 Function OnSwatchChanged() is called when a user changes a swatch color. More...
 
void OnLayerCheckBox (wxCommandEvent &event)
 Function OnLayerCheckBox handles the "is layer visible" checkbox and propogates the event to the client's notification function. More...
 
void OnRenderSwatchChanged (wxCommandEvent &aEvent)
 Function OnRenderSwatchChanged Called when user has changed the swatch color of a render entry. More...
 
void OnRenderCheckBox (wxCommandEvent &event)
 
void OnTabChange (wxNotebookEvent &event)
 
wxWindow * getLayerComp (int aRow, int aColumn) const
 Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL if these parameters are out of range. More...
 
wxWindow * getRenderComp (int aRow, int aColumn) const
 
int findLayerRow (LAYER_NUM aLayer) const
 Function findLayerRow returns the row index that aLayer resides in, or -1 if not found. More...
 
int findRenderRow (int aId) const
 
void insertLayerRow (int aRow, const ROW &aSpec)
 Function insertLayerRow appends or inserts a new row in the layer portion of the widget. More...
 
void insertRenderRow (int aRow, const ROW &aSpec)
 
void passOnFocus ()
 Function passOnFocus gives away the keyboard focus up to the main parent window. More...
 

Static Protected Member Functions

static int encodeId (int aColumn, int aId)
 Function encodeId is here to allow saving a layer index within a control as its wxControl id, but to do so in a way that all child wxControl ids within a wxWindow are unique, since this is required by Windows. More...
 
static LAYER_NUM getDecodedId (int aControlId)
 Function getDecodedId decodes aControlId to original un-encoded value. More...
 

Protected Attributes

wxAuiNotebook * m_notebook
 
wxPanel * m_LayerPanel
 
wxScrolledWindow * m_LayerScrolledWindow
 
wxFlexGridSizer * m_LayersFlexGridSizer
 
wxPanel * m_RenderingPanel
 
wxScrolledWindow * m_RenderScrolledWindow
 
wxFlexGridSizer * m_RenderFlexGridSizer
 
wxWindow * m_FocusOwner
 
int m_CurrentRow
 selected row of layer list More...
 
int m_PointSize
 

Detailed Description

Class LAYER_WIDGET is abstract and is used to manage a list of layers, with the notion of a "current" layer, and layer specific visibility control.

You must derive from it to use it so you can implement the abstract functions which recieve the events. Each layer is given its own color, and that color can be changed within the UI provided here. This widget knows nothing of the client code, meaning it has no knowledge of a BOARD or anything. To use it you must derive from this class and implement the abstract functions:

void OnLayerColorChange( int aLayer, int aColor );

bool OnLayerSelect( int aLayer );

void OnLayerVisible( int aLayer, bool isVisible );

void OnRenderColorChange( int id, int aColor );

void OnRenderEnable( int id, bool isEnabled );

Please note that even if designed toward layers, it is used to contain other stuff, too (the second page in pcbnew contains render items, for example)

Definition at line 76 of file layer_widget.h.

Constructor & Destructor Documentation

LAYER_WIDGET::LAYER_WIDGET ( wxWindow *  aParent,
wxWindow *  aFocusOwner,
int  aPointSize = -1,
wxWindowID  id = wxID_ANY,
const wxPoint pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = wxTAB_TRAVERSAL 
)

Constructor.

Parameters
aParentis the parent window
aFocusOwneris the window that should be sent the focus after
aPointSizeis the font point size to use within the widget. This effectively sets the overal size of the widget via the row height and bitmap button sizes.
idis the wxWindow id ( default = wxID_ANY)
posis the window position
sizeis the window size
styleis the window style every operation.

Definition at line 342 of file layer_widget.cpp.

References m_CurrentRow, m_FocusOwner, m_LayerPanel, m_LayerScrolledWindow, m_LayersFlexGridSizer, m_notebook, m_PointSize, m_RenderFlexGridSizer, m_RenderingPanel, m_RenderScrolledWindow, and OnTabChange().

343  :
344  wxPanel( aParent, id, pos, size, style )
345 {
346  wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL );
347 
348  m_notebook = new wxAuiNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP );
349 
350  wxFont font = m_notebook->GetFont();
351 
352  if( aPointSize == -1 )
353  {
354  m_PointSize = font.GetPointSize();
355  }
356  else
357  {
358  m_PointSize = aPointSize;
359 
360  // change the font size on the notebook's tabs to match aPointSize
361  font.SetPointSize( aPointSize );
362  m_notebook->SetFont( font );
363  m_notebook->SetNormalFont( font );
364  m_notebook->SetSelectedFont( font );
365  m_notebook->SetMeasuringFont( font );
366  }
367 
368  m_LayerPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
369 
370  wxBoxSizer* bSizer3;
371  bSizer3 = new wxBoxSizer( wxVERTICAL );
372 
373  m_LayerScrolledWindow = new wxScrolledWindow( m_LayerPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
374  m_LayerScrolledWindow->SetScrollRate( 5, 5 );
375  m_LayersFlexGridSizer = new wxFlexGridSizer( 0, 4, 0, 1 );
376  m_LayersFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
377  m_LayersFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
378 
380  m_LayerScrolledWindow->Layout();
382  bSizer3->Add( m_LayerScrolledWindow, 1, wxBOTTOM|wxEXPAND|wxLEFT|wxTOP, 2 );
383 
384  m_LayerPanel->SetSizer( bSizer3 );
385  m_LayerPanel->Layout();
386  bSizer3->Fit( m_LayerPanel );
387  m_notebook->AddPage( m_LayerPanel, _( "Layer" ), true );
388  m_RenderingPanel = new wxPanel( m_notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
389 
390  wxBoxSizer* bSizer4;
391  bSizer4 = new wxBoxSizer( wxVERTICAL );
392 
393  m_RenderScrolledWindow = new wxScrolledWindow( m_RenderingPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER );
394  m_RenderScrolledWindow->SetScrollRate( 5, 5 );
395  m_RenderFlexGridSizer = new wxFlexGridSizer( 0, 2, 0, 1 );
396  m_RenderFlexGridSizer->SetFlexibleDirection( wxHORIZONTAL );
397  m_RenderFlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE );
398 
400  m_RenderScrolledWindow->Layout();
402  bSizer4->Add( m_RenderScrolledWindow, 1, wxALL|wxEXPAND, 5 );
403 
404  m_RenderingPanel->SetSizer( bSizer4 );
405  m_RenderingPanel->Layout();
406  bSizer4->Fit( m_RenderingPanel );
407  m_notebook->AddPage( m_RenderingPanel, _( "Render" ), false );
408 
409  boxSizer->Add( m_notebook, 1, wxEXPAND | wxALL, 5 );
410 
411  SetSizer( boxSizer );
412 
413  m_FocusOwner = aFocusOwner;
414 
415  m_CurrentRow = -1; // hide the arrow initially
416 
417  // trap the tab changes so that we can call passOnFocus().
418  m_notebook->Bind( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, &LAYER_WIDGET::OnTabChange, this );
419 
420  Layout();
421 }
wxAuiNotebook * m_notebook
Definition: layer_widget.h:109
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:118
void OnTabChange(wxNotebookEvent &event)
wxScrolledWindow * m_RenderScrolledWindow
Definition: layer_widget.h:114
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:115
wxPanel * m_RenderingPanel
Definition: layer_widget.h:113
wxScrolledWindow * m_LayerScrolledWindow
Definition: layer_widget.h:111
wxWindow * m_FocusOwner
Definition: layer_widget.h:117
wxPanel * m_LayerPanel
Definition: layer_widget.h:110
LAYER_WIDGET::~LAYER_WIDGET ( )
virtual

Definition at line 424 of file layer_widget.cpp.

425 {
426 }

Member Function Documentation

void LAYER_WIDGET::AppendLayerRow ( const ROW aRow)

Function AppendLayerRow appends a new row in the layer portion of the widget.

The user must ensure that ROW::id is unique for all existing rows on Windows.

Definition at line 498 of file layer_widget.cpp.

References GetLayerRowCount(), insertLayerRow(), and UpdateLayouts().

Referenced by AppendLayerRows(), PCB_LAYER_WIDGET::ReFill(), and GERBER_LAYER_WIDGET::ReFill().

499 {
500  int nextRow = GetLayerRowCount();
501  insertLayerRow( nextRow, aRow );
502  UpdateLayouts();
503 }
void UpdateLayouts()
int GetLayerRowCount() const
Function GetLayerRowCount returns the number of rows in the layer tab.
void insertLayerRow(int aRow, const ROW &aSpec)
Function insertLayerRow appends or inserts a new row in the layer portion of the widget.
void LAYER_WIDGET::AppendLayerRows ( const ROW aRowsArray,
int  aRowCount 
)
inline

Function AppendLayerRows appends new rows in the layer portion of the widget.

The user must ensure that ROW::id is unique for all existing rows on Windows.

Definition at line 265 of file layer_widget.h.

References AppendLayerRow().

266  {
267  for( int row=0; row<aRowCount; ++row )
268  AppendLayerRow( aRowsArray[row] );
269  }
void AppendLayerRow(const ROW &aRow)
Function AppendLayerRow appends a new row in the layer portion of the widget.
void LAYER_WIDGET::AppendRenderRow ( const ROW aRow)

Function AppendRenderRow appends a new row in the render portion of the widget.

The user must ensure that ROW::id is unique for all existing rows on Windows.

Definition at line 512 of file layer_widget.cpp.

References GetRenderRowCount(), insertRenderRow(), and UpdateLayouts().

Referenced by AppendRenderRows(), and PCB_LAYER_WIDGET::ReFillRender().

513 {
514  int nextRow = GetRenderRowCount();
515  insertRenderRow( nextRow, aRow );
516  UpdateLayouts();
517 }
void insertRenderRow(int aRow, const ROW &aSpec)
void UpdateLayouts()
int GetRenderRowCount() const
Function GetRenderRowCount returns the number of rows in the render tab.
void LAYER_WIDGET::AppendRenderRows ( const ROW aRowsArray,
int  aRowCount 
)
inline

Function AppendRenderRows appends new rows in the render portion of the widget.

The user must ensure that ROW::id is unique for all existing rows on Windows.

Definition at line 289 of file layer_widget.h.

References AppendRenderRow().

Referenced by GERBER_LAYER_WIDGET::ReFillRender().

290  {
291  for( int row=0; row<aRowCount; ++row )
292  AppendRenderRow( aRowsArray[row] );
293  }
void AppendRenderRow(const ROW &aRow)
Function AppendRenderRow appends a new row in the render portion of the widget.
virtual bool LAYER_WIDGET::AreArbitraryColorsAllowed ( )
inlineprotectedvirtual

Subclasses can override this to provide logic for allowing arbitrary color selection via wxColourPicker instead of DisplayColorFrame.

Reimplemented in PCB_LAYER_WIDGET.

Definition at line 135 of file layer_widget.h.

Referenced by insertLayerRow(), and insertRenderRow().

135 { return false; }
void LAYER_WIDGET::ClearLayerRows ( )

Function ClearLayerRows empties out the layer rows.

Definition at line 506 of file layer_widget.cpp.

References m_LayersFlexGridSizer.

Referenced by PCB_LAYER_WIDGET::ReFill(), and GERBER_LAYER_WIDGET::ReFill().

507 {
508  m_LayersFlexGridSizer->Clear( true );
509 }
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
void LAYER_WIDGET::ClearRenderRows ( )

Function ClearRenderRows empties out the render rows.

Definition at line 520 of file layer_widget.cpp.

References m_RenderFlexGridSizer.

Referenced by PCB_LAYER_WIDGET::ReFillRender(), and GERBER_LAYER_WIDGET::ReFillRender().

521 {
522  m_RenderFlexGridSizer->Clear( true );
523 }
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:115
int LAYER_WIDGET::encodeId ( int  aColumn,
int  aId 
)
staticprotected

Function encodeId is here to allow saving a layer index within a control as its wxControl id, but to do so in a way that all child wxControl ids within a wxWindow are unique, since this is required by Windows.

See also
getDecodedId()

Definition at line 67 of file layer_widget.cpp.

References LYR_COLUMN_COUNT.

Referenced by insertLayerRow(), and insertRenderRow().

68 {
69  int id = aId * LYR_COLUMN_COUNT + aColumn;
70  return id;
71 }
#define LYR_COLUMN_COUNT
Layer tab column count.
Definition: layer_widget.h:47
int LAYER_WIDGET::findLayerRow ( LAYER_NUM  aLayer) const
protected

Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.

Definition at line 201 of file layer_widget.cpp.

References getDecodedId(), getLayerComp(), and GetLayerRowCount().

Referenced by GetLayerColor(), IsLayerVisible(), OnLeftDownLayers(), SelectLayer(), SetLayerColor(), and SetLayerVisible().

202 {
203  int count = GetLayerRowCount();
204 
205  for( int row = 0; row < count; ++row )
206  {
207  // column 0 in the layer scroll window has a wxStaticBitmap, get its ID.
208  wxWindow* w = getLayerComp( row, 0 );
209  wxASSERT( w );
210 
211  if( aLayer == getDecodedId( w->GetId() ))
212  return row;
213  }
214 
215  return -1;
216 }
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
int GetLayerRowCount() const
Function GetLayerRowCount returns the number of rows in the layer tab.
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
int LAYER_WIDGET::findRenderRow ( int  aId) const
protected

Definition at line 230 of file layer_widget.cpp.

References getDecodedId(), getRenderComp(), and GetRenderRowCount().

Referenced by GetRenderState(), and SetRenderState().

231 {
232  int count = GetRenderRowCount();
233 
234  for( int row = 0; row < count; ++row )
235  {
236  // column 0 in the layer scroll window has a wxStaticBitmap, get its ID.
237  wxWindow* w = getRenderComp( row, 0 );
238  wxASSERT( w );
239 
240  if( aId == getDecodedId( w->GetId() ))
241  return row;
242  }
243 
244  return -1;
245 }
int GetRenderRowCount() const
Function GetRenderRowCount returns the number of rows in the render tab.
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
wxWindow * getRenderComp(int aRow, int aColumn) const
wxSize LAYER_WIDGET::GetBestSize ( ) const

Function GetBestSize returns the preferred minimum size, taking into consideration the dynamic content.

Nothing in wxWidgets was reliable enough so this overrides one of their functions.

Definition at line 429 of file layer_widget.cpp.

References LYR_COLUMN_COUNT, m_LayerPanel, m_LayersFlexGridSizer, m_RenderFlexGridSizer, m_RenderingPanel, max, and RND_COLUMN_COUNT.

Referenced by GERBVIEW_FRAME::GERBVIEW_FRAME(), and GERBVIEW_FRAME::ReFillLayerWidget().

430 {
431  // size of m_LayerScrolledWindow --------------
432  wxArrayInt widths = m_LayersFlexGridSizer->GetColWidths();
433  int totWidth = 0;
434 
435  if( widths.GetCount() )
436  {
437  for( int i = 0; i < LYR_COLUMN_COUNT; ++i )
438  {
439  totWidth += widths[i] + m_LayersFlexGridSizer->GetHGap();
440  // printf("widths[%d]:%d\n", i, widths[i] );
441  }
442  }
443 
444  // Account for the parent's frame:
445  totWidth += 10;
446 
447 
448  /* The minimum height is a small size to properly force computation
449  * of the panel's scrollbars (otherwise it will assume it *has* all
450  * this space) */
451  unsigned totHeight = 32;
452 
453  wxSize layerz( totWidth, totHeight );
454 
455  layerz += m_LayerPanel->GetWindowBorderSize();
456 
457 
458  // size of m_RenderScrolledWindow --------------
459  widths = m_RenderFlexGridSizer->GetColWidths();
460  totWidth = 0;
461 
462  if( widths.GetCount() )
463  {
464  for( int i = 0; i < RND_COLUMN_COUNT; ++i )
465  {
466  totWidth += widths[i] + m_RenderFlexGridSizer->GetHGap();
467  // printf("widths[%d]:%d\n", i, widths[i] );
468  }
469  }
470  // account for the parent's frame, this one has void space of 10 PLUS a border:
471  totWidth += 20;
472 
473  // For totHeight re-use the previous small one
474  wxSize renderz( totWidth, totHeight );
475 
476  renderz += m_RenderingPanel->GetWindowBorderSize();
477 
478  wxSize clientz( std::max(renderz.x,layerz.x), std::max(renderz.y,layerz.y) );
479 
480  return clientz;
481 }
#define LYR_COLUMN_COUNT
Layer tab column count.
Definition: layer_widget.h:47
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
#define RND_COLUMN_COUNT
Rendering tab column count.
Definition: layer_widget.h:48
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:115
wxPanel * m_RenderingPanel
Definition: layer_widget.h:113
#define max(a, b)
Definition: auxiliary.h:86
wxPanel * m_LayerPanel
Definition: layer_widget.h:110
LAYER_NUM LAYER_WIDGET::getDecodedId ( int  aControlId)
staticprotected

Function getDecodedId decodes aControlId to original un-encoded value.

This of course holds iff encodedId was called with a LAYER_NUM (this box is used for other things than layers, too)

Definition at line 74 of file layer_widget.cpp.

References LYR_COLUMN_COUNT.

Referenced by findLayerRow(), findRenderRow(), GetSelectedLayer(), OnLayerCheckBox(), OnLayerSwatchChanged(), OnLeftDownLayers(), GERBER_LAYER_WIDGET::onPopupSelection(), PCB_LAYER_WIDGET::onPopupSelection(), OnRenderCheckBox(), OnRenderSwatchChanged(), and PCB_LAYER_WIDGET::SyncLayerVisibilities().

75 {
76  int id = aControlId / LYR_COLUMN_COUNT; // rounding is OK.
77  return id;
78 }
#define LYR_COLUMN_COUNT
Layer tab column count.
Definition: layer_widget.h:47
COLOR4D LAYER_WIDGET::GetLayerColor ( LAYER_NUM  aLayer) const

Function GetLayerColor returns the color of the layer ROW associated with aLayer id.

Definition at line 611 of file layer_widget.cpp.

References ColorFromInt(), findLayerRow(), getLayerComp(), and TO_UTF8.

612 {
613  int row = findLayerRow( aLayer );
614  if( row >= 0 )
615  {
616  int col = 1; // bitmap button is column 1
617  wxBitmapButton* bmb = (wxBitmapButton*) getLayerComp( row, col );
618  wxASSERT( bmb );
619 
620  wxString colorTxt = bmb->GetName();
621  return ColorFromInt( strtoul( TO_UTF8(colorTxt), NULL, 0 ) );
622  }
623 
624  return COLOR4D::UNSPECIFIED; // it's caller fault, gave me a bad layer
625 }
EDA_COLOR_T ColorFromInt(int aColor)
Checked cast. Use only when necessary (usually I/O)
Definition: colors.h:81
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
wxWindow * LAYER_WIDGET::getLayerComp ( int  aRow,
int  aColumn 
) const
protected

Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL if these parameters are out of range.

Parameters
aRowis the row index
aColumnis the column
Returns
wxWindow - the component installed within the sizer at given grid coordinate.

Definition at line 190 of file layer_widget.cpp.

References LYR_COLUMN_COUNT, and m_LayersFlexGridSizer.

Referenced by findLayerRow(), GetLayerColor(), GetSelectedLayer(), GERBER_LAYER_WIDGET::installRightLayerClickHandler(), PCB_LAYER_WIDGET::installRightLayerClickHandler(), IsLayerVisible(), OnLeftDownLayers(), GERBER_LAYER_WIDGET::onPopupSelection(), PCB_LAYER_WIDGET::onPopupSelection(), PCB_LAYER_WIDGET::ReFill(), SelectLayerRow(), SetLayerColor(), SetLayerVisible(), PCB_LAYER_WIDGET::SyncLayerVisibilities(), and UpdateLayerIcons().

191 {
192  unsigned ndx = aRow * LYR_COLUMN_COUNT + aColumn;
193 
194  if( ndx < m_LayersFlexGridSizer->GetChildren().GetCount() )
195  return m_LayersFlexGridSizer->GetChildren()[ndx]->GetWindow();
196 
197  return NULL;
198 }
#define LYR_COLUMN_COUNT
Layer tab column count.
Definition: layer_widget.h:47
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
int LAYER_WIDGET::GetLayerRowCount ( ) const

Function GetLayerRowCount returns the number of rows in the layer tab.

Definition at line 484 of file layer_widget.cpp.

References LYR_COLUMN_COUNT, and m_LayersFlexGridSizer.

Referenced by AppendLayerRow(), findLayerRow(), GERBER_LAYER_WIDGET::installRightLayerClickHandler(), PCB_LAYER_WIDGET::installRightLayerClickHandler(), OnLeftDownLayers(), GERBER_LAYER_WIDGET::onPopupSelection(), PCB_LAYER_WIDGET::onPopupSelection(), PCB_LAYER_WIDGET::ReFill(), PCB_LAYER_WIDGET::SyncLayerVisibilities(), and UpdateLayerIcons().

485 {
486  int controlCount = m_LayersFlexGridSizer->GetChildren().GetCount();
487  return controlCount / LYR_COLUMN_COUNT;
488 }
#define LYR_COLUMN_COUNT
Layer tab column count.
Definition: layer_widget.h:47
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
wxWindow * LAYER_WIDGET::getRenderComp ( int  aRow,
int  aColumn 
) const
protected

Definition at line 219 of file layer_widget.cpp.

References m_RenderFlexGridSizer, and RND_COLUMN_COUNT.

Referenced by findRenderRow(), GetRenderState(), and SetRenderState().

220 {
221  int ndx = aRow * RND_COLUMN_COUNT + aColumn;
222 
223  if( (unsigned) ndx < m_RenderFlexGridSizer->GetChildren().GetCount() )
224  return m_RenderFlexGridSizer->GetChildren()[ndx]->GetWindow();
225 
226  return NULL;
227 }
#define RND_COLUMN_COUNT
Rendering tab column count.
Definition: layer_widget.h:48
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:115
int LAYER_WIDGET::GetRenderRowCount ( ) const

Function GetRenderRowCount returns the number of rows in the render tab.

Definition at line 491 of file layer_widget.cpp.

References m_RenderFlexGridSizer, and RND_COLUMN_COUNT.

Referenced by AppendRenderRow(), and findRenderRow().

492 {
493  int controlCount = m_RenderFlexGridSizer->GetChildren().GetCount();
494  return controlCount / RND_COLUMN_COUNT;
495 }
#define RND_COLUMN_COUNT
Rendering tab column count.
Definition: layer_widget.h:48
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:115
bool LAYER_WIDGET::GetRenderState ( int  aId)

Function GetRenderState returns the state of the checkbox associated with aId.

Returns
bool - true if checked, else false.

Definition at line 642 of file layer_widget.cpp.

References findRenderRow(), and getRenderComp().

643 {
644  int row = findRenderRow( aId );
645 
646  if( row >= 0 )
647  {
648  int col = 1; // checkbox is column 1
649  wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col );
650  wxASSERT( cb );
651  return cb->GetValue();
652  }
653 
654  return false; // the value of a non-existent row
655 }
int findRenderRow(int aId) const
wxWindow * getRenderComp(int aRow, int aColumn) const
LAYER_NUM LAYER_WIDGET::GetSelectedLayer ( )

Function GetSelectedLayer returns the selected layer or -1 if none.

Definition at line 562 of file layer_widget.cpp.

References getDecodedId(), getLayerComp(), m_CurrentRow, and UNDEFINED_LAYER.

563 {
564  wxWindow* w = getLayerComp( m_CurrentRow, 0 );
565  if( w )
566  return getDecodedId( w->GetId() );
567 
568  return UNDEFINED_LAYER;
569 }
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:118
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
void LAYER_WIDGET::insertLayerRow ( int  aRow,
const ROW aSpec 
)
protected

Function insertLayerRow appends or inserts a new row in the layer portion of the widget.

Definition at line 248 of file layer_widget.cpp.

References alternativeRowIcons, AreArbitraryColorsAllowed(), LAYER_WIDGET::ROW::color, COLUMN_COLOR_LYR_CB, COLUMN_COLOR_LYRNAME, COLUMN_COLORBM, COLUMN_ICON_ACTIVE, defaultRowIcons, encodeId(), LAYER_WIDGET::ROW::id, LYR_COLUMN_COUNT, m_LayerScrolledWindow, m_LayersFlexGridSizer, m_PointSize, OFF, OnLayerCheckBox(), OnLayerSwatchChanged(), OnLeftDownLayers(), LAYER_WIDGET::ROW::rowName, shrinkFont(), LAYER_WIDGET::ROW::state, LAYER_WIDGET::ROW::tooltip, and useAlternateBitmap().

Referenced by AppendLayerRow().

249 {
250  wxASSERT( aRow >= 0 );
251 
252  int col;
253  int index = aRow * LYR_COLUMN_COUNT;
254  const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT;
255 
256  auto& iconProvider = useAlternateBitmap(aRow) ? alternativeRowIcons : defaultRowIcons;
257 
258  // column 0
259  col = COLUMN_ICON_ACTIVE;
260  auto sbm = new INDICATOR_ICON( m_LayerScrolledWindow, iconProvider,
262  encodeId( col, aSpec.id ) );
263  sbm->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
264  m_LayersFlexGridSizer->wxSizer::Insert( index+col, sbm, 0, flags );
265 
266  // column 1 (COLUMN_COLORBM)
267  col = COLUMN_COLORBM;
268 
269  auto bmb = new COLOR_SWATCH( m_LayerScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
271  bmb->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
272  bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnLayerSwatchChanged, this );
273  bmb->SetToolTip( _("Left double click or middle click for color change, right click for menu" ) );
274  m_LayersFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );
275 
276  // column 2 (COLUMN_COLOR_LYR_CB)
277  col = COLUMN_COLOR_LYR_CB;
278  wxCheckBox* cb = new wxCheckBox( m_LayerScrolledWindow, encodeId( col, aSpec.id ), wxEmptyString );
279  cb->SetValue( aSpec.state );
280  cb->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED, &LAYER_WIDGET::OnLayerCheckBox, this );
281  cb->SetToolTip( _( "Enable this for visibility" ) );
282  m_LayersFlexGridSizer->wxSizer::Insert( index+col, cb, 0, flags );
283 
284  // column 3 (COLUMN_COLOR_LYRNAME)
285  col = COLUMN_COLOR_LYRNAME;
286  wxStaticText* st = new wxStaticText( m_LayerScrolledWindow, encodeId( col, aSpec.id ), aSpec.rowName );
287  shrinkFont( st, m_PointSize );
288  st->Bind( wxEVT_LEFT_DOWN, &LAYER_WIDGET::OnLeftDownLayers, this );
289  st->SetToolTip( aSpec.tooltip );
290  m_LayersFlexGridSizer->wxSizer::Insert( index+col, st, 0, flags );
291 }
#define COLUMN_COLOR_LYRNAME
Definition: layer_widget.h:53
void OnLeftDownLayers(wxMouseEvent &event)
#define LYR_COLUMN_COUNT
Layer tab column count.
Definition: layer_widget.h:47
#define OFF
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
virtual bool useAlternateBitmap(int aRow)
Virtual Function useAlternateBitmap.
Definition: layer_widget.h:129
static void shrinkFont(wxWindow *aControl, int aPointSize)
Function shrinkFont reduces the size of the wxFont associated with aControl.
void OnLayerCheckBox(wxCommandEvent &event)
Function OnLayerCheckBox handles the "is layer visible" checkbox and propogates the event to the clie...
static int encodeId(int aColumn, int aId)
Function encodeId is here to allow saving a layer index within a control as its wxControl id...
Class representing a row indicator icon for use in places like the layer widget.
#define COLUMN_ICON_ACTIVE
Definition: layer_widget.h:50
#define COLUMN_COLORBM
Definition: layer_widget.h:51
static ROW_ICON_PROVIDER alternativeRowIcons(true)
virtual bool AreArbitraryColorsAllowed()
Subclasses can override this to provide logic for allowing arbitrary color selection via wxColourPick...
Definition: layer_widget.h:135
wxScrolledWindow * m_LayerScrolledWindow
Definition: layer_widget.h:111
static ROW_ICON_PROVIDER defaultRowIcons(false)
#define COLUMN_COLOR_LYR_CB
Definition: layer_widget.h:52
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:38
void OnLayerSwatchChanged(wxCommandEvent &aEvent)
Function OnSwatchChanged() is called when a user changes a swatch color.
void LAYER_WIDGET::insertRenderRow ( int  aRow,
const ROW aSpec 
)
protected

Definition at line 294 of file layer_widget.cpp.

References AreArbitraryColorsAllowed(), LAYER_WIDGET::ROW::changeable, LAYER_WIDGET::ROW::color, encodeId(), LAYER_WIDGET::ROW::id, m_PointSize, m_RenderFlexGridSizer, m_RenderScrolledWindow, OnRenderCheckBox(), OnRenderSwatchChanged(), RND_COLUMN_COUNT, LAYER_WIDGET::ROW::rowName, shrinkFont(), LAYER_WIDGET::ROW::state, and LAYER_WIDGET::ROW::tooltip.

Referenced by AppendRenderRow().

295 {
296  wxASSERT( aRow >= 0 );
297 
298  int col;
299  int index = aRow * RND_COLUMN_COUNT;
300  const int flags = wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT;
301 
302  // column 0
303  col = 0;
304  if( aSpec.color != COLOR4D::UNSPECIFIED )
305  {
306  auto bmb = new COLOR_SWATCH( m_RenderScrolledWindow, aSpec.color, encodeId( col, aSpec.id ),
308  bmb->Bind( COLOR_SWATCH_CHANGED, &LAYER_WIDGET::OnRenderSwatchChanged, this );
309  bmb->SetToolTip( _( "Left double click or middle click for color change" ) );
310  m_RenderFlexGridSizer->wxSizer::Insert( index+col, bmb, 0, flags );
311 
312  // could add a left click handler on the color button that toggles checkbox.
313  }
314  else // == -1, no color selection wanted
315  {
316  // need a place holder within the sizer to keep grid full.
317  wxPanel* invisible = new wxPanel( m_RenderScrolledWindow, encodeId( col, aSpec.id ) );
318  m_RenderFlexGridSizer->wxSizer::Insert( index+col, invisible, 0, flags );
319  }
320 
321  // column 1
322  col = 1;
323  wxCheckBox* cb = new wxCheckBox( m_RenderScrolledWindow, encodeId( col, aSpec.id ),
324  aSpec.rowName, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );
325  shrinkFont( cb, m_PointSize );
326  cb->SetValue( aSpec.state );
327  cb->Enable( aSpec.changeable );
328  cb->Bind( wxEVT_COMMAND_CHECKBOX_CLICKED, &LAYER_WIDGET::OnRenderCheckBox, this );
329  cb->SetToolTip( aSpec.tooltip );
330  m_RenderFlexGridSizer->wxSizer::Insert( index+col, cb, 0, flags );
331 }
wxScrolledWindow * m_RenderScrolledWindow
Definition: layer_widget.h:114
static void shrinkFont(wxWindow *aControl, int aPointSize)
Function shrinkFont reduces the size of the wxFont associated with aControl.
#define RND_COLUMN_COUNT
Rendering tab column count.
Definition: layer_widget.h:48
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:115
void OnRenderCheckBox(wxCommandEvent &event)
static int encodeId(int aColumn, int aId)
Function encodeId is here to allow saving a layer index within a control as its wxControl id...
virtual bool AreArbitraryColorsAllowed()
Subclasses can override this to provide logic for allowing arbitrary color selection via wxColourPick...
Definition: layer_widget.h:135
void OnRenderSwatchChanged(wxCommandEvent &aEvent)
Function OnRenderSwatchChanged Called when user has changed the swatch color of a render entry...
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:38
bool LAYER_WIDGET::IsLayerVisible ( LAYER_NUM  aLayer)

Function IsLayerVisible returns the visible state of the layer ROW associated with aLayer id.

Definition at line 584 of file layer_widget.cpp.

References COLUMN_COLOR_LYR_CB, findLayerRow(), and getLayerComp().

Referenced by GERBVIEW_FRAME::IsLayerVisible().

585 {
586  int row = findLayerRow( aLayer );
587  if( row >= 0 )
588  {
589  wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
590  wxASSERT( cb );
591  return cb->GetValue();
592  }
593  return false;
594 }
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
#define COLUMN_COLOR_LYR_CB
Definition: layer_widget.h:52
void LAYER_WIDGET::OnLayerCheckBox ( wxCommandEvent &  event)
protected

Function OnLayerCheckBox handles the "is layer visible" checkbox and propogates the event to the client's notification function.

Definition at line 148 of file layer_widget.cpp.

References getDecodedId(), OnLayerVisible(), and passOnFocus().

Referenced by insertLayerRow().

149 {
150  wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
151  LAYER_NUM layer = getDecodedId( eventSource->GetId() );
152  OnLayerVisible( layer, eventSource->IsChecked() );
153  passOnFocus();
154 }
virtual void OnLayerVisible(LAYER_NUM aLayer, bool isVisible, bool isFinal=true)=0
Function OnLayerVisible is called to notify client code about a layer visibility change.
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
virtual void LAYER_WIDGET::OnLayerColorChange ( int  aLayer,
COLOR4D  aColor 
)
pure virtual

Function OnLayerColorChange is called to notify client code about a layer color change.

Derived classes will handle this accordingly.

Parameters
aLayeris the board layer to change
aColoris the new color

Implemented in GERBER_LAYER_WIDGET, and PCB_LAYER_WIDGET.

Referenced by OnLayerSwatchChanged().

virtual bool LAYER_WIDGET::OnLayerSelect ( int  aLayer)
pure virtual

Function OnLayerSelect is called to notify client code whenever the user selects a different layer.

Derived classes will handle this accordingly, and can deny the change by returning false.

Parameters
aLayeris the board layer to select

Implemented in GERBER_LAYER_WIDGET, and PCB_LAYER_WIDGET.

Referenced by OnLeftDownLayers().

void LAYER_WIDGET::OnLayerSwatchChanged ( wxCommandEvent &  aEvent)
protected

Function OnSwatchChanged() is called when a user changes a swatch color.

Definition at line 129 of file layer_widget.cpp.

References EVT_LAYER_COLOR_CHANGE, getDecodedId(), OnLayerColorChange(), and passOnFocus().

Referenced by insertLayerRow().

130 {
131  auto eventSource = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
132 
133  COLOR4D newColor = eventSource->GetSwatchColor();
134 
135  LAYER_NUM layer = getDecodedId( eventSource->GetId() );
136 
137  // tell the client code.
138  OnLayerColorChange( layer, newColor );
139 
140  // notify others
141  wxCommandEvent event( EVT_LAYER_COLOR_CHANGE );
142  wxPostEvent( this, event );
143 
144  passOnFocus();
145 }
static const wxEventType EVT_LAYER_COLOR_CHANGE
Definition: layer_widget.h:105
virtual void OnLayerColorChange(int aLayer, COLOR4D aColor)=0
Function OnLayerColorChange is called to notify client code about a layer color change.
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:38
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
virtual void LAYER_WIDGET::OnLayerVisible ( LAYER_NUM  aLayer,
bool  isVisible,
bool  isFinal = true 
)
pure virtual

Function OnLayerVisible is called to notify client code about a layer visibility change.

Parameters
aLayeris the board layer to select
isVisibleis the new visible state
isFinalis true when this is the last of potentially several such calls, and can be used to decide when to update the screen only one time instead of several times in the midst of a multiple layer change.

Implemented in GERBER_LAYER_WIDGET, and PCB_LAYER_WIDGET.

Referenced by OnLayerCheckBox().

void LAYER_WIDGET::OnLeftDownLayers ( wxMouseEvent &  event)
protected

Definition at line 81 of file layer_widget.cpp.

References findLayerRow(), getDecodedId(), getLayerComp(), GetLayerRowCount(), m_LayerScrolledWindow, m_LayersFlexGridSizer, OnLayerSelect(), passOnFocus(), and SelectLayerRow().

Referenced by insertLayerRow().

82 {
83  int row;
84  LAYER_NUM layer;
85 
86  wxWindow* eventSource = (wxWindow*) event.GetEventObject();
87 
88  // if mouse event is coming from the m_LayerScrolledWindow and not one
89  // of its children, we have to find the row manually based on y coord.
90  if( eventSource == m_LayerScrolledWindow )
91  {
92  int y = event.GetY();
93 
94  wxArrayInt heights = m_LayersFlexGridSizer->GetRowHeights();
95 
96  int height = 0;
97 
98  int rowCount = GetLayerRowCount();
99  for( row = 0; row<rowCount; ++row )
100  {
101  if( y < height + heights[row] )
102  break;
103 
104  height += heights[row];
105  }
106 
107  if( row >= rowCount )
108  row = rowCount - 1;
109 
110  layer = getDecodedId( getLayerComp( row, 0 )->GetId() );
111  }
112 
113  else
114  {
115  // all nested controls on a given row will have their ID encoded with
116  // encodeId(), and the corresponding decoding is getDecodedId()
117  int id = eventSource->GetId();
118  layer = getDecodedId( id );
119  row = findLayerRow( layer );
120  }
121 
122  if( OnLayerSelect( layer ) ) // if client allows this change.
123  SelectLayerRow( row );
124 
125  passOnFocus();
126 }
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
wxScrolledWindow * m_LayerScrolledWindow
Definition: layer_widget.h:111
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
int GetLayerRowCount() const
Function GetLayerRowCount returns the number of rows in the layer tab.
void SelectLayerRow(int aRow)
Function SelectLayerRow changes the row selection in the layer list to the given row.
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
virtual bool OnLayerSelect(int aLayer)=0
Function OnLayerSelect is called to notify client code whenever the user selects a different layer...
void LAYER_WIDGET::OnRenderCheckBox ( wxCommandEvent &  event)
protected

Definition at line 172 of file layer_widget.cpp.

References getDecodedId(), OnRenderEnable(), and passOnFocus().

Referenced by insertRenderRow().

173 {
174  wxCheckBox* eventSource = (wxCheckBox*) event.GetEventObject();
175  LAYER_NUM id = getDecodedId( eventSource->GetId() );
176  OnRenderEnable( id, eventSource->IsChecked() );
177  passOnFocus();
178 }
virtual void OnRenderEnable(int aId, bool isEnabled)=0
Function OnRenderEnable is called to notify client code whenever the user changes an rendering enable...
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
virtual void LAYER_WIDGET::OnRenderColorChange ( int  aId,
COLOR4D  aColor 
)
pure virtual

Function OnRenderColorChange is called to notify client code whenever the user changes a rendering color.

Parameters
aIdis the same id that was established in a Rendering row via the AddRenderRow() function.
aColoris the new color

Implemented in GERBER_LAYER_WIDGET, and PCB_LAYER_WIDGET.

Referenced by OnRenderSwatchChanged().

virtual void LAYER_WIDGET::OnRenderEnable ( int  aId,
bool  isEnabled 
)
pure virtual

Function OnRenderEnable is called to notify client code whenever the user changes an rendering enable in one of the rendering checkboxes.

Parameters
aIdis the same id that was established in a Rendering row via the AddRenderRow() function.
isEnabledis the state of the checkbox, true if checked.

Implemented in GERBER_LAYER_WIDGET, and PCB_LAYER_WIDGET.

Referenced by OnRenderCheckBox().

void LAYER_WIDGET::OnRenderSwatchChanged ( wxCommandEvent &  aEvent)
protected

Function OnRenderSwatchChanged Called when user has changed the swatch color of a render entry.

Definition at line 157 of file layer_widget.cpp.

References getDecodedId(), OnRenderColorChange(), and passOnFocus().

Referenced by insertRenderRow().

158 {
159  auto eventSource = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
160 
161  COLOR4D newColor = eventSource->GetSwatchColor();
162 
163  LAYER_NUM id = getDecodedId( eventSource->GetId() );
164 
165  // tell the client code.
166  OnRenderColorChange( id, newColor );
167 
168  passOnFocus();
169 }
virtual void OnRenderColorChange(int aId, COLOR4D aColor)=0
Function OnRenderColorChange is called to notify client code whenever the user changes a rendering co...
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:38
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
void LAYER_WIDGET::OnTabChange ( wxNotebookEvent &  event)
protected

Definition at line 181 of file layer_widget.cpp.

References passOnFocus().

Referenced by LAYER_WIDGET().

182 {
183 // wxFocusEvent event( wxEVT_SET_FOCUS );
184 // m_FocusOwner->AddPendingEvent( event );
185 
186  passOnFocus(); // does not work in this context, probably because we have receive control here too early.
187 }
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
void LAYER_WIDGET::passOnFocus ( )
protected

Function passOnFocus gives away the keyboard focus up to the main parent window.

Definition at line 334 of file layer_widget.cpp.

References m_FocusOwner.

Referenced by OnLayerCheckBox(), OnLayerSwatchChanged(), OnLeftDownLayers(), OnRenderCheckBox(), OnRenderSwatchChanged(), GERBER_LAYER_WIDGET::onRightDownLayers(), PCB_LAYER_WIDGET::onRightDownLayers(), OnTabChange(), and SelectLayerRow().

335 {
336  m_FocusOwner->SetFocus();
337 }
wxWindow * m_FocusOwner
Definition: layer_widget.h:117
void LAYER_WIDGET::SelectLayer ( LAYER_NUM  aLayer)

Function SelectLayer changes the row selection in the layer list to aLayer provided.

Definition at line 555 of file layer_widget.cpp.

References findLayerRow(), and SelectLayerRow().

Referenced by GERBVIEW_FRAME::setActiveLayer(), and GERBVIEW_FRAME::syncLayerWidget().

556 {
557  int row = findLayerRow( aLayer );
558  SelectLayerRow( row );
559 }
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
void SelectLayerRow(int aRow)
Function SelectLayerRow changes the row selection in the layer list to the given row.
void LAYER_WIDGET::SelectLayerRow ( int  aRow)

Function SelectLayerRow changes the row selection in the layer list to the given row.

Definition at line 526 of file layer_widget.cpp.

References getLayerComp(), m_CurrentRow, m_notebook, OFF, ON, passOnFocus(), and INDICATOR_ICON::SetIndicatorState().

Referenced by OnLeftDownLayers(), and SelectLayer().

527 {
528  // enable the layer tab at index 0
529  m_notebook->SetSelection( 0 );
530 
531  INDICATOR_ICON* oldIndicator = (INDICATOR_ICON*) getLayerComp( m_CurrentRow, 0 );
532  if( oldIndicator )
534 
535  INDICATOR_ICON* newIndicator = (INDICATOR_ICON*) getLayerComp( aRow, 0 );
536  if( newIndicator )
537  {
539 
540  // Make sure the desired layer row is visible.
541  // It seems that as of 2.8.2, setting the focus does this.
542  // I don't expect the scrolling to be needed at all because
543  // the minimum window size may end up being established so that the
544  // scroll bars will not be visible.
545  getLayerComp( aRow, 1 )->SetFocus();
546  }
547 
548  m_CurrentRow = aRow;
549 
550  // give the focus back to the app.
551  passOnFocus();
552 }
void SetIndicatorState(ICON_ID aIconId)
Sets the row indiciator to the given state.
wxAuiNotebook * m_notebook
Definition: layer_widget.h:109
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:118
#define OFF
Class representing a row indicator icon for use in places like the layer widget.
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
#define ON
void LAYER_WIDGET::SetLayerColor ( LAYER_NUM  aLayer,
COLOR4D  aColor 
)

Function SetLayerColor changes the color of aLayer.

Definition at line 597 of file layer_widget.cpp.

References findLayerRow(), and getLayerComp().

598 {
599  int row = findLayerRow( aLayer );
600  if( row >= 0 )
601  {
602  int col = 1; // bitmap button is column 1
603  auto bmb = static_cast<COLOR_SWATCH*>( getLayerComp( row, col ) );
604  wxASSERT( bmb );
605 
606  bmb->SetSwatchColor( aColor, false );
607  }
608 }
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:38
void LAYER_WIDGET::SetLayerVisible ( LAYER_NUM  aLayer,
bool  isVisible 
)

Function SetLayerVisible sets aLayer visible or not.

This does not invoke OnLayerVisible().

Definition at line 572 of file layer_widget.cpp.

References COLUMN_COLOR_LYR_CB, findLayerRow(), and getLayerComp().

Referenced by PCB_LAYER_WIDGET::SyncLayerVisibilities().

573 {
574  int row = findLayerRow( aLayer );
575  if( row >= 0 )
576  {
577  wxCheckBox* cb = (wxCheckBox*) getLayerComp( row, COLUMN_COLOR_LYR_CB );
578  wxASSERT( cb );
579  cb->SetValue( isVisible ); // does not fire an event
580  }
581 }
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
#define COLUMN_COLOR_LYR_CB
Definition: layer_widget.h:52
void LAYER_WIDGET::SetRenderState ( int  aId,
bool  isSet 
)

Function SetRenderState sets the state of the checkbox associated with aId within the Render tab group of the widget.

Does not fire an event, i.e. does not invoke OnRenderEnable().

Parameters
aIdis the same unique id used when adding a ROW to the Render tab.
isSet= the new checkbox state

Definition at line 628 of file layer_widget.cpp.

References findRenderRow(), and getRenderComp().

Referenced by GERBVIEW_FRAME::SetElementVisibility(), FOOTPRINT_EDIT_FRAME::SetElementVisibility(), GERBVIEW_FRAME::SetGridVisibility(), and PCB_LAYER_WIDGET::SyncRenderStates().

629 {
630  int row = findRenderRow( aId );
631 
632  if( row >= 0 )
633  {
634  int col = 1; // checkbox is column 1
635  wxCheckBox* cb = (wxCheckBox*) getRenderComp( row, col );
636  wxASSERT( cb );
637  cb->SetValue( isSet ); // does not fire an event
638  }
639 }
int findRenderRow(int aId) const
wxWindow * getRenderComp(int aRow, int aColumn) const
void LAYER_WIDGET::UpdateLayerIcons ( )

Function UpdateLayerIcons Update all layer manager icons (layers only) Useful when loading a file or clearing a layer because they change, and the indicator arrow icon needs to be updated.

Definition at line 668 of file layer_widget.cpp.

References COLUMN_ICON_ACTIVE, getLayerComp(), GetLayerRowCount(), m_CurrentRow, OFF, ON, and INDICATOR_ICON::SetIndicatorState().

Referenced by GERBVIEW_FRAME::LoadExcellonFiles(), GERBVIEW_FRAME::LoadGerberFiles(), and GERBVIEW_FRAME::LoadZipArchiveFile().

669 {
670  int rowCount = GetLayerRowCount();
671 
672  for( int row = 0; row < rowCount ; row++ )
673  {
675 
676  if( indicator )
677  {
678  auto state = ( row == m_CurrentRow ) ? ROW_ICON_PROVIDER::STATE::ON
680  indicator->SetIndicatorState( state );
681  }
682  }
683 }
void SetIndicatorState(ICON_ID aIconId)
Sets the row indiciator to the given state.
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:118
#define OFF
Class representing a row indicator icon for use in places like the layer widget.
#define COLUMN_ICON_ACTIVE
Definition: layer_widget.h:50
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
int GetLayerRowCount() const
Function GetLayerRowCount returns the number of rows in the layer tab.
#define ON
void LAYER_WIDGET::UpdateLayouts ( )

Definition at line 658 of file layer_widget.cpp.

References m_LayerPanel, m_LayersFlexGridSizer, m_RenderFlexGridSizer, and m_RenderingPanel.

Referenced by AppendLayerRow(), and AppendRenderRow().

659 {
660  m_LayersFlexGridSizer->Layout();
661  m_RenderFlexGridSizer->Layout();
662  m_LayerPanel->Layout();
663  m_RenderingPanel->Layout();
664  FitInside();
665 }
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:112
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:115
wxPanel * m_RenderingPanel
Definition: layer_widget.h:113
wxPanel * m_LayerPanel
Definition: layer_widget.h:110
virtual bool LAYER_WIDGET::useAlternateBitmap ( int  aRow)
inlineprotectedvirtual

Virtual Function useAlternateBitmap.

Returns
true if bitmaps shown in Render layer list are alternate bitmaps, or false if they are "normal" bitmaps This is a virtual function because Pcbnew uses normal bitmaps but GerbView uses both bitmaps (alternate bitmaps to show layers in use, normal fo others)

Reimplemented in GERBER_LAYER_WIDGET.

Definition at line 129 of file layer_widget.h.

Referenced by insertLayerRow().

129 { return false; }

Member Data Documentation

const wxEventType LAYER_WIDGET::EVT_LAYER_COLOR_CHANGE = wxNewEventType()
static

Definition at line 105 of file layer_widget.h.

Referenced by OnLayerSwatchChanged().

int LAYER_WIDGET::m_CurrentRow
protected

selected row of layer list

Definition at line 118 of file layer_widget.h.

Referenced by GetSelectedLayer(), LAYER_WIDGET(), SelectLayerRow(), and UpdateLayerIcons().

wxWindow* LAYER_WIDGET::m_FocusOwner
protected

Definition at line 117 of file layer_widget.h.

Referenced by LAYER_WIDGET(), and passOnFocus().

wxPanel* LAYER_WIDGET::m_LayerPanel
protected

Definition at line 110 of file layer_widget.h.

Referenced by GetBestSize(), LAYER_WIDGET(), and UpdateLayouts().

wxScrolledWindow* LAYER_WIDGET::m_LayerScrolledWindow
protected
wxFlexGridSizer* LAYER_WIDGET::m_LayersFlexGridSizer
protected
wxAuiNotebook* LAYER_WIDGET::m_notebook
protected
int LAYER_WIDGET::m_PointSize
protected

Definition at line 119 of file layer_widget.h.

Referenced by insertLayerRow(), insertRenderRow(), and LAYER_WIDGET().

wxFlexGridSizer* LAYER_WIDGET::m_RenderFlexGridSizer
protected
wxPanel* LAYER_WIDGET::m_RenderingPanel
protected

Definition at line 113 of file layer_widget.h.

Referenced by GetBestSize(), LAYER_WIDGET(), and UpdateLayouts().

wxScrolledWindow* LAYER_WIDGET::m_RenderScrolledWindow
protected

Definition at line 114 of file layer_widget.h.

Referenced by insertRenderRow(), and LAYER_WIDGET().


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