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 
48 #define LYR_COLUMN_COUNT 4
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 
56 using KIGFX::COLOR4D;
57 
77 class LAYER_WIDGET : public wxPanel
78 {
79 public:
85  struct ROW
86  {
87  wxString rowName;
88  int id;
90  bool state;
91  wxString tooltip;
92  bool changeable;
93 
94  ROW( const wxString& aRowName, int aId, COLOR4D aColor = COLOR4D::UNSPECIFIED,
95  const wxString& aTooltip = wxEmptyString, bool aState = true, bool aChangeable = true )
96  {
97  rowName = aRowName;
98  id = aId;
99  color = aColor;
100  state = aState;
101  tooltip = aTooltip;
102  changeable = aChangeable;
103  }
104  };
105 
106  static const wxEventType EVT_LAYER_COLOR_CHANGE;
107 
108 protected:
109 
110  wxAuiNotebook* m_notebook;
111  wxPanel* m_LayerPanel;
112  wxScrolledWindow* m_LayerScrolledWindow;
113  wxFlexGridSizer* m_LayersFlexGridSizer;
115  wxScrolledWindow* m_RenderScrolledWindow;
116  wxFlexGridSizer* m_RenderFlexGridSizer;
117 
118  wxWindow* m_FocusOwner;
121 
130  virtual bool useAlternateBitmap(int aRow) { return false; }
131 
136  virtual bool AreArbitraryColorsAllowed() { return false; }
137 
145  static int encodeId( int aColumn, int aId );
146 
153  static LAYER_NUM getDecodedId( int aControlId );
154 
155  void OnLeftDownLayers( wxMouseEvent& event );
156 
161  void OnRightDownLayer( wxMouseEvent& event, COLOR_SWATCH* aColorSwatch, const wxString& aLayerName );
162 
167  void OnLayerSwatchChanged( wxCommandEvent& aEvent );
168 
174  void OnLayerCheckBox( wxCommandEvent& event );
175 
180  void OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch, const wxString& aRenderName );
181 
186  void OnRenderSwatchChanged( wxCommandEvent& aEvent );
187 
188  void OnRenderCheckBox( wxCommandEvent& event );
189 
190  void OnTabChange( wxNotebookEvent& event );
191 
192 
202  wxWindow* getLayerComp( int aRow, int aColumn ) const;
203  wxWindow* getRenderComp( int aRow, int aColumn ) const;
204 
209  int findLayerRow( LAYER_NUM aLayer ) const;
210  int findRenderRow( int aId ) const;
211 
216  void insertLayerRow( int aRow, const ROW& aSpec );
217 
218  void insertRenderRow( int aRow, const ROW& aSpec );
219 
224  void passOnFocus();
225 
226  // popup menu ids.
227  enum POPUP_ID
228  {
229  ID_CHANGE_LAYER_COLOR = wxID_HIGHEST,
232  };
233 
234 public:
235 
248  LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, int aPointSize = -1,
249  wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
250  const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL );
251 
252  virtual ~LAYER_WIDGET();
253 
260  wxSize GetBestSize() const;
261 
266  int GetLayerRowCount() const;
267 
272  int GetRenderRowCount() const;
273 
279  void AppendLayerRow( const ROW& aRow );
280 
286  void AppendLayerRows( const ROW* aRowsArray, int aRowCount )
287  {
288  for( int row=0; row<aRowCount; ++row )
289  AppendLayerRow( aRowsArray[row] );
290  }
291 
296  void ClearLayerRows();
297 
303  void AppendRenderRow( const ROW& aRow );
304 
310  void AppendRenderRows( const ROW* aRowsArray, int aRowCount )
311  {
312  for( int row=0; row<aRowCount; ++row )
313  AppendRenderRow( aRowsArray[row] );
314  }
315 
320  void ClearRenderRows();
321 
326  void SelectLayerRow( int aRow );
327 
332  void SelectLayer( LAYER_NUM aLayer );
333 
339 
344  void SetLayerVisible( LAYER_NUM aLayer, bool isVisible );
345 
350  bool IsLayerVisible( LAYER_NUM aLayer );
351 
356  void SetLayerColor( LAYER_NUM aLayer, COLOR4D aColor );
357 
362  COLOR4D GetLayerColor( LAYER_NUM aLayer ) const;
363 
373  void SetRenderState( int aId, bool isSet );
374 
380  bool GetRenderState( int aId );
381 
382  void UpdateLayouts();
383 
390  void UpdateLayerIcons();
391 
392 /* did not help:
393  void Freeze()
394  {
395  LAYER_PANEL_BASE::Freeze();
396  m_LayerScrolledWindow->Freeze();
397  m_RenderScrolledWindow->Freeze();
398  }
399 
400  void Thaw()
401  {
402  m_RenderScrolledWindow->Thaw();
403  m_LayerScrolledWindow->Thaw();
404  LAYER_PANEL_BASE::Thaw();
405  }
406 */
407 
408  //-----<abstract functions>-------------------------------------------
409 
417  virtual void OnLayerColorChange( int aLayer, COLOR4D aColor ) = 0;
418 
426  virtual bool OnLayerSelect( int aLayer ) = 0;
427 
438  virtual void OnLayerVisible( LAYER_NUM aLayer, bool isVisible, bool isFinal = true ) = 0;
439 
447  virtual void OnLayerRightClick( wxMenu& aMenu ) = 0;
448 
457  virtual void OnRenderColorChange( int aId, COLOR4D aColor ) = 0;
458 
467  virtual void OnRenderEnable( int aId, bool isEnabled ) = 0;
468 
469  //-----</abstract functions>------------------------------------------
470 };
471 
472 #endif // LAYERWIDGET_H_
void OnLeftDownLayers(wxMouseEvent &event)
wxAuiNotebook * m_notebook
Definition: layer_widget.h:110
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:119
void insertRenderRow(int aRow, const ROW &aSpec)
Struct ROW provides all the data needed to add a row to a LAYER_WIDGET.
Definition: layer_widget.h:85
int findRenderRow(int aId) const
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.
ROW(const wxString &aRowName, int aId, COLOR4D aColor=COLOR4D::UNSPECIFIED, const wxString &aTooltip=wxEmptyString, bool aState=true, bool aChangeable=true)
Definition: layer_widget.h:94
void OnTabChange(wxNotebookEvent &event)
bool changeable
if true, the state can be changed
Definition: layer_widget.h:92
static const wxEventType EVT_LAYER_COLOR_CHANGE
Definition: layer_widget.h:106
COLOR4D GetLayerColor(LAYER_NUM aLayer) const
Function GetLayerColor returns the color of the layer ROW associated with aLayer id.
wxScrolledWindow * m_RenderScrolledWindow
Definition: layer_widget.h:115
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:113
virtual bool useAlternateBitmap(int aRow)
Virtual Function useAlternateBitmap.
Definition: layer_widget.h:130
int findLayerRow(LAYER_NUM aLayer) const
Function findLayerRow returns the row index that aLayer resides in, or -1 if not found.
wxSize GetBestSize() const
Function GetBestSize returns the preferred minimum size, taking into consideration the dynamic conten...
void AppendLayerRows(const ROW *aRowsArray, int aRowCount)
Function AppendLayerRows appends new rows in the layer portion of the widget.
Definition: layer_widget.h:286
void ClearRenderRows()
Function ClearRenderRows empties out the render rows.
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:116
bool state
initial wxCheckBox state
Definition: layer_widget.h:90
void ClearLayerRows()
Function ClearLayerRows empties out the layer rows.
wxString tooltip
if not empty, use this tooltip on row
Definition: layer_widget.h:91
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:89
void OnRightDownRender(wxMouseEvent &aEvent, COLOR_SWATCH *aColorSwatch, const wxString &aRenderName)
Function OnRightDownRender Called when user right-clicks a render option.
int GetRenderRowCount() const
Function GetRenderRowCount returns the number of rows in the render tab.
void SetLayerColor(LAYER_NUM aLayer, COLOR4D aColor)
Function SetLayerColor changes the color of aLayer.
virtual bool AreArbitraryColorsAllowed()
Subclasses can override this to provide logic for allowing arbitrary color selection via wxColourPick...
Definition: layer_widget.h:136
wxPanel * m_RenderingPanel
Definition: layer_widget.h:114
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:112
virtual void OnRenderEnable(int aId, bool isEnabled)=0
Function OnRenderEnable is called to notify client code whenever the user changes an rendering enable...
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.
void AppendRenderRows(const ROW *aRowsArray, int aRowCount)
Function AppendRenderRows appends new rows in the render portion of the widget.
Definition: layer_widget.h:310
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:118
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.
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...
Class LAYER_WIDGET is abstract and is used to manage a list of layers, with the notion of a "current"...
Definition: layer_widget.h:77
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:87
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.
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...
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:88
wxPanel * m_LayerPanel
Definition: layer_widget.h:111
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.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxWindow * getRenderComp(int aRow, int aColumn) const