KiCad PCB EDA Suite
layer_widget.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
5  * Copyright (C) 2010-2021 KiCad Developers, see change_log.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef LAYERWIDGET_H_
26 #define LAYERWIDGET_H_
27 
28 #include <wx/intl.h>
29 #include <wx/statbmp.h>
30 #include <wx/string.h>
31 #include <wx/aui/auibook.h>
32 #include <wx/notebook.h>
33 #include <wx/sizer.h>
34 #include <wx/gdicmn.h>
35 #include <wx/scrolwin.h>
36 #include <wx/font.h>
37 #include <wx/colour.h>
38 #include <wx/settings.h>
39 #include <wx/panel.h>
40 #include <wx/bitmap.h>
41 #include <wx/image.h>
42 #include <wx/icon.h>
43 #include <layer_ids.h>
44 #include <gal/color4d.h>
45 #include <widgets/color_swatch.h>
46 #include <widgets/indicator_icon.h>
47 
48 #define LYR_COLUMN_COUNT 5
49 #define RND_COLUMN_COUNT 2
50 
51 #define COLUMN_ICON_ACTIVE 0
52 #define COLUMN_COLORBM 1
53 #define COLUMN_COLOR_LYR_CB 2
54 #define COLUMN_COLOR_LYRNAME 3
55 #define COLUMN_ALPHA_INDICATOR 4
56 
57 using KIGFX::COLOR4D;
58 
77 class LAYER_WIDGET : public wxPanel
78 {
79 public:
84  struct ROW
85  {
86  wxString rowName;
87  int id;
89  bool state;
90  wxString tooltip;
91  bool changeable;
92  bool spacer;
94 
95  ROW( const wxString& aRowName, int aId, const COLOR4D& aColor = COLOR4D::UNSPECIFIED,
96  const wxString& aTooltip = wxEmptyString, bool aState = true,
97  bool aChangeable = true, const COLOR4D& aDefaultColor = COLOR4D::UNSPECIFIED )
98  {
99  rowName = aRowName;
100  id = aId;
101  color = aColor;
102  state = aState;
103  tooltip = aTooltip;
104  changeable = aChangeable;
105  spacer = false;
106  defaultColor = aDefaultColor;
107  }
108 
109  ROW()
110  {
111  id = 0;
112  color = COLOR4D::UNSPECIFIED;
113  state = true;
114  changeable = true;
115  spacer = true;
116  defaultColor = COLOR4D::UNSPECIFIED;
117  }
118  };
119 
120  static const wxEventType EVT_LAYER_COLOR_CHANGE;
121 
122 public:
123 
132  LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID id = wxID_ANY,
133  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
134  long style = wxTAB_TRAVERSAL );
135 
136  virtual ~LAYER_WIDGET();
137 
141  void SetSmallestLayerString( const wxString& aString )
142  {
143  m_smallestLayerString = aString;
144  }
145 
151  wxSize GetBestSize() const;
152 
156  int GetLayerRowCount() const;
157 
161  int GetRenderRowCount() const;
162 
168  void AppendLayerRow( const ROW& aRow );
169 
175  void AppendLayerRows( const ROW* aRowsArray, int aRowCount )
176  {
177  for( int row=0; row<aRowCount; ++row )
178  AppendLayerRow( aRowsArray[row] );
179 
180  UpdateLayouts();
181  }
182 
186  void ClearLayerRows();
187 
193  void AppendRenderRow( const ROW& aRow );
194 
200  void AppendRenderRows( const ROW* aRowsArray, int aRowCount )
201  {
202  for( int row=0; row<aRowCount; ++row )
203  AppendRenderRow( aRowsArray[row] );
204 
205  UpdateLayouts();
206  }
207 
211  void ClearRenderRows();
212 
216  void SelectLayerRow( int aRow );
217 
221  void SelectLayer( LAYER_NUM aLayer );
222 
227 
231  void SetLayerVisible( LAYER_NUM aLayer, bool isVisible );
232 
236  bool IsLayerVisible( LAYER_NUM aLayer );
237 
241  void SetLayerColor( LAYER_NUM aLayer, const COLOR4D& aColor );
242 
246  COLOR4D GetLayerColor( LAYER_NUM aLayer ) const;
247 
257  void SetRenderState( int aId, bool isSet );
258 
264  bool GetRenderState( int aId );
265 
266  void UpdateLayouts();
267 
274  void UpdateLayerIcons();
275 
276 /* did not help:
277  void Freeze()
278  {
279  LAYER_PANEL_BASE::Freeze();
280  m_LayerScrolledWindow->Freeze();
281  m_RenderScrolledWindow->Freeze();
282  }
283 
284  void Thaw()
285  {
286  m_RenderScrolledWindow->Thaw();
287  m_LayerScrolledWindow->Thaw();
288  LAYER_PANEL_BASE::Thaw();
289  }
290 */
291 
292  //-----<abstract functions>-------------------------------------------
293 
302  virtual void OnLayerColorChange( int aLayer, const COLOR4D& aColor ) = 0;
303 
311  virtual bool OnLayerSelect( int aLayer ) = 0;
312 
322  virtual void OnLayerVisible( LAYER_NUM aLayer, bool isVisible, bool isFinal = true ) = 0;
323 
329  virtual void OnLayerRightClick( wxMenu& aMenu ) = 0;
330 
338  virtual void OnRenderColorChange( int aId, const COLOR4D& aColor ) = 0;
339 
348  virtual void OnRenderEnable( int aId, bool isEnabled ) = 0;
349 
350 protected:
358  virtual bool useAlternateBitmap(int aRow) { return false; }
359 
365 
374  static int encodeId( int aColumn, int aId );
375 
382  static LAYER_NUM getDecodedId( int aControlId );
383 
384  void OnLeftDownLayers( wxMouseEvent& event );
385 
389  void OnRightDownLayer( wxMouseEvent& event, COLOR_SWATCH* aColorSwatch,
390  const wxString& aLayerName );
391 
395  void OnLayerSwatchChanged( wxCommandEvent& aEvent );
396 
401  void OnLayerCheckBox( wxCommandEvent& event );
402 
406  void OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch,
407  const wxString& aRenderName );
408 
412  void OnRenderSwatchChanged( wxCommandEvent& aEvent );
413 
414  void OnRenderCheckBox( wxCommandEvent& event );
415 
416  void OnTabChange( wxNotebookEvent& event );
417 
418 
427  wxWindow* getLayerComp( int aRow, int aColumn ) const;
428  wxWindow* getRenderComp( int aRow, int aColumn ) const;
429 
433  int findLayerRow( LAYER_NUM aLayer ) const;
434  int findRenderRow( int aId ) const;
435 
439  void insertLayerRow( int aRow, const ROW& aSpec );
440 
441  void insertRenderRow( int aRow, const ROW& aSpec );
442 
443  void setLayerCheckbox( LAYER_NUM aLayer, bool isVisible );
444 
445  void updateLayerRow( int aRow, const wxString& aName );
446 
450  void passOnFocus();
451 
452  // popup menu ids.
453  enum POPUP_ID
454  {
455  ID_CHANGE_LAYER_COLOR = wxID_HIGHEST,
458  };
459 
460  wxNotebook* m_notebook;
461  wxPanel* m_LayerPanel;
462  wxScrolledWindow* m_LayerScrolledWindow;
463  wxFlexGridSizer* m_LayersFlexGridSizer;
465  wxScrolledWindow* m_RenderScrolledWindow;
466  wxFlexGridSizer* m_RenderFlexGridSizer;
467 
468  wxWindow* m_FocusOwner;
471 
473 
475 };
476 
477 #endif // LAYERWIDGET_H_
COLOR4D defaultColor
The default color for the row.
Definition: layer_widget.h:93
void OnLeftDownLayers(wxMouseEvent &event)
int findLayerRow(LAYER_NUM aLayer) const
Return the row index that aLayer resides in, or -1 if not found.
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:469
virtual void OnLayerColorChange(int aLayer, const COLOR4D &aColor)=0
Notify client code about a layer color change.
void insertRenderRow(int aRow, const ROW &aSpec)
wxSize GetBestSize() const
Return the preferred minimum size, taking into consideration the dynamic content.
Icon provider for the "standard" row indicators, for example in layer selection lists.
wxString m_smallestLayerString
Definition: layer_widget.h:474
Provide all the data needed to add a row to a LAYER_WIDGET.
Definition: layer_widget.h:84
bool spacer
if true, this row is a spacer
Definition: layer_widget.h:92
bool GetRenderState(int aId)
Return the state of the checkbox associated with aId.
void UpdateLayouts()
virtual void OnLayerVisible(LAYER_NUM aLayer, bool isVisible, bool isFinal=true)=0
Notify client code about a layer visibility change.
wxNotebook * m_notebook
Definition: layer_widget.h:460
void OnTabChange(wxNotebookEvent &event)
bool changeable
if true, the state can be changed
Definition: layer_widget.h:91
static const wxEventType EVT_LAYER_COLOR_CHANGE
Definition: layer_widget.h:120
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:40
wxScrolledWindow * m_RenderScrolledWindow
Definition: layer_widget.h:465
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:463
virtual bool useAlternateBitmap(int aRow)
Definition: layer_widget.h:358
int findRenderRow(int aId) const
wxWindow * getLayerComp(int aRow, int aColumn) const
Return the component within the m_LayersFlexGridSizer at aRow and aCol or NULL if these parameters ar...
Definition: color4d.h:44
void updateLayerRow(int aRow, const wxString &aName)
void AppendLayerRows(const ROW *aRowsArray, int aRowCount)
Append new rows in the layer portion of the widget.
Definition: layer_widget.h:175
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Return the color of the layer ROW associated with aLayer id.
void ClearRenderRows()
Empty out the render rows.
void SetSmallestLayerString(const wxString &aString)
Set the string that is used for determining the smallest string displayed in the layer's tab.
Definition: layer_widget.h:141
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:466
bool state
initial wxCheckBox state
Definition: layer_widget.h:89
virtual void OnRenderColorChange(int aId, const COLOR4D &aColor)=0
Notify client code whenever the user changes a rendering color.
void ClearLayerRows()
Empty out the layer rows.
wxString tooltip
if not empty, use this tooltip on row
Definition: layer_widget.h:90
ROW(const wxString &aRowName, int aId, const COLOR4D &aColor=COLOR4D::UNSPECIFIED, const wxString &aTooltip=wxEmptyString, bool aState=true, bool aChangeable=true, const COLOR4D &aDefaultColor=COLOR4D::UNSPECIFIED)
Definition: layer_widget.h:95
void OnRenderCheckBox(wxCommandEvent &event)
void OnLayerCheckBox(wxCommandEvent &event)
Handle the "is layer visible" checkbox and propagates the event to the client's notification function...
void AppendRenderRow(const ROW &aRow)
Append a new row in the render portion of the widget.
static int encodeId(int aColumn, int aId)
Allow saving a layer index within a control as its wxControl id.
COLOR4D color
COLOR4D::UNSPECIFIED if none.
Definition: layer_widget.h:88
void OnRightDownRender(wxMouseEvent &aEvent, COLOR_SWATCH *aColorSwatch, const wxString &aRenderName)
Notify when user right-clicks a render option.
void setLayerCheckbox(LAYER_NUM aLayer, bool isVisible)
wxWindow * getRenderComp(int aRow, int aColumn) const
wxPanel * m_RenderingPanel
Definition: layer_widget.h:464
void AppendLayerRow(const ROW &aRow)
Append a new row in the layer portion of the widget.
void UpdateLayerIcons()
Update all layer manager icons (layers only).
wxScrolledWindow * m_LayerScrolledWindow
Definition: layer_widget.h:462
virtual void OnRenderEnable(int aId, bool isEnabled)=0
Notify client code whenever the user changes an rendering enable in one of the rendering checkboxes.
void SelectLayerRow(int aRow)
Change the row selection in the layer list to the given row.
void SetLayerColor(LAYER_NUM aLayer, const COLOR4D &aColor)
Change the color of aLayer.
void AppendRenderRows(const ROW *aRowsArray, int aRowCount)
Append new rows in the render portion of the widget.
Definition: layer_widget.h:200
void OnRenderSwatchChanged(wxCommandEvent &aEvent)
Called when user has changed the swatch color of a render entry.
static LAYER_NUM getDecodedId(int aControlId)
Decode aControlId to original un-encoded value.
virtual ~LAYER_WIDGET()
wxWindow * m_FocusOwner
Definition: layer_widget.h:468
LAYER_WIDGET(wxWindow *aParent, wxWindow *aFocusOwner, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
int GetLayerRowCount() const
Return the number of rows in the layer tab.
void passOnFocus()
Give away the keyboard focus up to the main parent window.
LAYER_NUM GetSelectedLayer()
Return the selected layer or -1 if none.
bool IsLayerVisible(LAYER_NUM aLayer)
Return the visible state of the layer ROW associated with aLayer id.
Manage a list of layers with the notion of a "current" layer, and layer specific visibility control.
Definition: layer_widget.h:77
void OnRightDownLayer(wxMouseEvent &event, COLOR_SWATCH *aColorSwatch, const wxString &aLayerName)
Called when user right-clicks a layer.
wxString rowName
the prompt or layername
Definition: layer_widget.h:86
virtual COLOR4D getBackgroundLayerColor()
Subclasses can override this to provide accurate representation of transparent color swatches.
Definition: layer_widget.h:364
A simple color swatch of the kind used to set layer colors.
Definition: color_swatch.h:56
virtual void OnLayerRightClick(wxMenu &aMenu)=0
Notify client code about a layer being right-clicked.
int GetRenderRowCount() const
Return the number of rows in the render tab.
void insertLayerRow(int aRow, const ROW &aSpec)
Append or insert a new row in the layer portion of the widget.
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
Set aLayer visible or not.
void OnLayerSwatchChanged(wxCommandEvent &aEvent)
Called when a user changes a swatch color.
virtual bool OnLayerSelect(int aLayer)=0
Notify client code whenever the user selects a different layer.
void SetRenderState(int aId, bool isSet)
Set the state of the checkbox associated with aId within the Render tab group of the widget.
void SelectLayer(LAYER_NUM aLayer)
Change the row selection in the layer list to aLayer provided.
int id
either a layer or "visible element" id
Definition: layer_widget.h:87
ROW_ICON_PROVIDER * m_IconProvider
Definition: layer_widget.h:472
wxPanel * m_LayerPanel
Definition: layer_widget.h:461
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103