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 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/wx.h>
30 #include <wx/statbmp.h>
31 #include <wx/string.h>
32 #include <wx/aui/auibook.h>
33 #include <wx/notebook.h>
34 #include <wx/sizer.h>
35 #include <wx/gdicmn.h>
36 #include <wx/scrolwin.h>
37 #include <wx/font.h>
38 #include <wx/colour.h>
39 #include <wx/settings.h>
40 #include <wx/panel.h>
41 #include <wx/bitmap.h>
42 #include <wx/image.h>
43 #include <wx/icon.h>
45 #include <gal/color4d.h>
46 #include <widgets/color_swatch.h>
47 #include <widgets/indicator_icon.h>
48 
49 #define LYR_COLUMN_COUNT 5
50 #define RND_COLUMN_COUNT 2
51 
52 #define COLUMN_ICON_ACTIVE 0
53 #define COLUMN_COLORBM 1
54 #define COLUMN_COLOR_LYR_CB 2
55 #define COLUMN_COLOR_LYRNAME 3
56 #define COLUMN_ALPHA_INDICATOR 4
57 
58 using KIGFX::COLOR4D;
59 
79 class LAYER_WIDGET : public wxPanel
80 {
81 public:
87  struct ROW
88  {
89  wxString rowName;
90  int id;
92  bool state;
93  wxString tooltip;
94  bool changeable;
95  bool spacer;
97 
98  ROW( const wxString& aRowName, int aId, COLOR4D aColor = COLOR4D::UNSPECIFIED,
99  const wxString& aTooltip = wxEmptyString, bool aState = true,
100  bool aChangeable = true, COLOR4D aDefaultColor = COLOR4D::UNSPECIFIED )
101  {
102  rowName = aRowName;
103  id = aId;
104  color = aColor;
105  state = aState;
106  tooltip = aTooltip;
107  changeable = aChangeable;
108  spacer = false;
109  defaultColor = aDefaultColor;
110  }
111 
112  ROW()
113  {
114  id = 0;
115  color = COLOR4D::UNSPECIFIED;
116  state = true;
117  changeable = true;
118  spacer = true;
119  defaultColor = COLOR4D::UNSPECIFIED;
120  }
121  };
122 
123  static const wxEventType EVT_LAYER_COLOR_CHANGE;
124 
125 protected:
126 
127  wxAuiNotebook* m_notebook;
128  wxPanel* m_LayerPanel;
129  wxScrolledWindow* m_LayerScrolledWindow;
130  wxFlexGridSizer* m_LayersFlexGridSizer;
132  wxScrolledWindow* m_RenderScrolledWindow;
133  wxFlexGridSizer* m_RenderFlexGridSizer;
134 
135  wxWindow* m_FocusOwner;
138 
140 
149  virtual bool useAlternateBitmap(int aRow) { return false; }
150 
156 
164  static int encodeId( int aColumn, int aId );
165 
172  static LAYER_NUM getDecodedId( int aControlId );
173 
174  void OnLeftDownLayers( wxMouseEvent& event );
175 
180  void OnRightDownLayer( wxMouseEvent& event, COLOR_SWATCH* aColorSwatch, const wxString& aLayerName );
181 
186  void OnLayerSwatchChanged( wxCommandEvent& aEvent );
187 
193  void OnLayerCheckBox( wxCommandEvent& event );
194 
199  void OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch, const wxString& aRenderName );
200 
205  void OnRenderSwatchChanged( wxCommandEvent& aEvent );
206 
207  void OnRenderCheckBox( wxCommandEvent& event );
208 
209  void OnTabChange( wxNotebookEvent& event );
210 
211 
221  wxWindow* getLayerComp( int aRow, int aColumn ) const;
222  wxWindow* getRenderComp( int aRow, int aColumn ) const;
223 
228  int findLayerRow( LAYER_NUM aLayer ) const;
229  int findRenderRow( int aId ) const;
230 
235  void insertLayerRow( int aRow, const ROW& aSpec );
236 
237  void insertRenderRow( int aRow, const ROW& aSpec );
238 
239  void setLayerCheckbox( LAYER_NUM aLayer, bool isVisible );
240 
241  void updateLayerRow( int aRow, const wxString& aName );
242 
247  void passOnFocus();
248 
249  // popup menu ids.
250  enum POPUP_ID
251  {
252  ID_CHANGE_LAYER_COLOR = wxID_HIGHEST,
255  };
256 
257 public:
258 
268  LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID id = wxID_ANY,
269  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
270  long style = wxTAB_TRAVERSAL );
271 
272  virtual ~LAYER_WIDGET();
273 
280  wxSize GetBestSize() const;
281 
286  int GetLayerRowCount() const;
287 
292  int GetRenderRowCount() const;
293 
299  void AppendLayerRow( const ROW& aRow );
300 
306  void AppendLayerRows( const ROW* aRowsArray, int aRowCount )
307  {
308  for( int row=0; row<aRowCount; ++row )
309  AppendLayerRow( aRowsArray[row] );
310 
311  UpdateLayouts();
312  }
313 
318  void ClearLayerRows();
319 
325  void AppendRenderRow( const ROW& aRow );
326 
332  void AppendRenderRows( const ROW* aRowsArray, int aRowCount )
333  {
334  for( int row=0; row<aRowCount; ++row )
335  AppendRenderRow( aRowsArray[row] );
336 
337  UpdateLayouts();
338  }
339 
344  void ClearRenderRows();
345 
350  void SelectLayerRow( int aRow );
351 
356  void SelectLayer( LAYER_NUM aLayer );
357 
363 
368  void SetLayerVisible( LAYER_NUM aLayer, bool isVisible );
369 
374  bool IsLayerVisible( LAYER_NUM aLayer );
375 
380  void SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor );
381 
386  COLOR4D GetLayerColor( LAYER_NUM aLayer ) const;
387 
397  void SetRenderState( int aId, bool isSet );
398 
404  bool GetRenderState( int aId );
405 
406  void UpdateLayouts();
407 
414  void UpdateLayerIcons();
415 
416 /* did not help:
417  void Freeze()
418  {
419  LAYER_PANEL_BASE::Freeze();
420  m_LayerScrolledWindow->Freeze();
421  m_RenderScrolledWindow->Freeze();
422  }
423 
424  void Thaw()
425  {
426  m_RenderScrolledWindow->Thaw();
427  m_LayerScrolledWindow->Thaw();
428  LAYER_PANEL_BASE::Thaw();
429  }
430 */
431 
432  //-----<abstract functions>-------------------------------------------
433 
441  virtual void OnLayerColorChange( int aLayer, COLOR4D aColor ) = 0;
442 
450  virtual bool OnLayerSelect( int aLayer ) = 0;
451 
462  virtual void OnLayerVisible( LAYER_NUM aLayer, bool isVisible, bool isFinal = true ) = 0;
463 
471  virtual void OnLayerRightClick( wxMenu& aMenu ) = 0;
472 
481  virtual void OnRenderColorChange( int aId, COLOR4D aColor ) = 0;
482 
491  virtual void OnRenderEnable( int aId, bool isEnabled ) = 0;
492 
493  //-----</abstract functions>------------------------------------------
494 };
495 
496 #endif // LAYERWIDGET_H_
COLOR4D defaultColor
The default color for the row.
Definition: layer_widget.h:96
void OnLeftDownLayers(wxMouseEvent &event)
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
wxAuiNotebook * m_notebook
Definition: layer_widget.h:127
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:136
void insertRenderRow(int aRow, const ROW &aSpec)
wxSize GetBestSize() const
Function GetBestSize returns the preferred minimum size, taking into consideration the dynamic conten...
Icon provider for the "standard" row indicators, for example in layer selection lists.
Struct ROW provides all the data needed to add a row to a LAYER_WIDGET.
Definition: layer_widget.h:87
bool spacer
if true, this row is a spacer
Definition: layer_widget.h:95
virtual void OnRenderColorChange(int aId, COLOR4D aColor)=0
Function OnRenderColorChange is called to notify client code whenever the user changes a rendering co...
bool GetRenderState(int aId)
Function GetRenderState returns the state of the checkbox associated with aId.
void UpdateLayouts()
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.
void OnTabChange(wxNotebookEvent &event)
bool changeable
if true, the state can be changed
Definition: layer_widget.h:94
static const wxEventType EVT_LAYER_COLOR_CHANGE
Definition: layer_widget.h:123
wxScrolledWindow * m_RenderScrolledWindow
Definition: layer_widget.h:132
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:130
virtual bool useAlternateBitmap(int aRow)
Virtual Function useAlternateBitmap.
Definition: layer_widget.h:149
int findRenderRow(int aId) const
wxWindow * getLayerComp(int aRow, int aColumn) const
Function getLayerComp returns the component within the m_LayersFlexGridSizer at aRow and aCol or NULL...
Definition: color4d.h:44
void updateLayerRow(int aRow, const wxString &aName)
void AppendLayerRows(const ROW *aRowsArray, int aRowCount)
Function AppendLayerRows appends new rows in the layer portion of the widget.
Definition: layer_widget.h:306
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor returns the color of the layer ROW associated with aLayer id.
void ClearRenderRows()
Function ClearRenderRows empties out the render rows.
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:133
bool state
initial wxCheckBox state
Definition: layer_widget.h:92
void ClearLayerRows()
Function ClearLayerRows empties out the layer rows.
wxString tooltip
if not empty, use this tooltip on row
Definition: layer_widget.h:93
virtual void OnLayerColorChange(int aLayer, COLOR4D aColor)=0
Function OnLayerColorChange is called to notify client code about a layer color change.
void OnRenderCheckBox(wxCommandEvent &event)
void OnLayerCheckBox(wxCommandEvent &event)
Function OnLayerCheckBox handles the "is layer visible" checkbox and propogates the event to the clie...
void AppendRenderRow(const ROW &aRow)
Function AppendRenderRow appends a new row in the render portion of the widget.
static int encodeId(int aColumn, int aId)
Function encodeId is here to allow saving a layer index within a control as its wxControl id,...
COLOR4D color
COLOR4D::UNSPECIFIED if none.
Definition: layer_widget.h:91
void OnRightDownRender(wxMouseEvent &aEvent, COLOR_SWATCH *aColorSwatch, const wxString &aRenderName)
Function OnRightDownRender Called when user right-clicks a render option.
void setLayerCheckbox(LAYER_NUM aLayer, bool isVisible)
void SetLayerColor(LAYER_NUM aLayer, COLOR4D aColor)
Function SetLayerColor changes the color of aLayer.
wxWindow * getRenderComp(int aRow, int aColumn) const
wxPanel * m_RenderingPanel
Definition: layer_widget.h:131
void AppendLayerRow(const ROW &aRow)
Function AppendLayerRow appends a new row in the layer portion of the widget.
void UpdateLayerIcons()
Function UpdateLayerIcons Update all layer manager icons (layers only) Useful when loading a file or ...
wxScrolledWindow * m_LayerScrolledWindow
Definition: layer_widget.h:129
virtual void OnRenderEnable(int aId, bool isEnabled)=0
Function OnRenderEnable is called to notify client code whenever the user changes an rendering enable...
void SelectLayerRow(int aRow)
Function SelectLayerRow changes the row selection in the layer list to the given row.
void AppendRenderRows(const ROW *aRowsArray, int aRowCount)
Function AppendRenderRows appends new rows in the render portion of the widget.
Definition: layer_widget.h:332
void OnRenderSwatchChanged(wxCommandEvent &aEvent)
Function OnRenderSwatchChanged Called when user has changed the swatch color of a render entry.
static LAYER_NUM getDecodedId(int aControlId)
Function getDecodedId decodes aControlId to original un-encoded value.
virtual ~LAYER_WIDGET()
wxWindow * m_FocusOwner
Definition: layer_widget.h:135
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
LAYER_WIDGET(wxWindow *aParent, wxWindow *aFocusOwner, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
Constructor.
int GetLayerRowCount() const
Function GetLayerRowCount returns the number of rows in the layer tab.
void passOnFocus()
Function passOnFocus gives away the keyboard focus up to the main parent window.
LAYER_NUM GetSelectedLayer()
Function GetSelectedLayer returns the selected layer or -1 if none.
bool IsLayerVisible(LAYER_NUM aLayer)
Function IsLayerVisible returns the visible state of the layer ROW associated with aLayer id.
LAYER_WIDGET is abstract and is used to manage a list of layers, with the notion of a "current" layer...
Definition: layer_widget.h:79
Board layer functions and definitions.
void OnRightDownLayer(wxMouseEvent &event, COLOR_SWATCH *aColorSwatch, const wxString &aLayerName)
Function OnRightDownLayer Called when user right-clicks a layer.
wxString rowName
the prompt or layername
Definition: layer_widget.h:89
virtual COLOR4D getBackgroundLayerColor()
Subclasses can override this to provide accurate representation of transparent colour swatches.
Definition: layer_widget.h:155
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:38
virtual void OnLayerRightClick(wxMenu &aMenu)=0
Function OnLayerRightClick is called to notify client code about a layer being right-clicked.
int GetRenderRowCount() const
Function GetRenderRowCount returns the number of rows in the render tab.
void insertLayerRow(int aRow, const ROW &aSpec)
Function insertLayerRow appends or inserts a new row in the layer portion of the widget.
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
Function SetLayerVisible sets aLayer visible or not.
void OnLayerSwatchChanged(wxCommandEvent &aEvent)
Function OnSwatchChanged() is called when a user changes a swatch color.
virtual bool OnLayerSelect(int aLayer)=0
Function OnLayerSelect is called to notify client code whenever the user selects a different layer.
ROW(const wxString &aRowName, int aId, COLOR4D aColor=COLOR4D::UNSPECIFIED, const wxString &aTooltip=wxEmptyString, bool aState=true, bool aChangeable=true, COLOR4D aDefaultColor=COLOR4D::UNSPECIFIED)
Definition: layer_widget.h:98
void SetRenderState(int aId, bool isSet)
Function SetRenderState sets the state of the checkbox associated with aId within the Render tab grou...
void SelectLayer(LAYER_NUM aLayer)
Function SelectLayer changes the row selection in the layer list to aLayer provided.
int id
either a layer or "visible element" id
Definition: layer_widget.h:90
ROW_ICON_PROVIDER * m_IconProvider
Definition: layer_widget.h:139
wxPanel * m_LayerPanel
Definition: layer_widget.h:128
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99