KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright (C) 2010-2022 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>
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
57using KIGFX::COLOR4D;
58
77class LAYER_WIDGET : public wxPanel
78{
79public:
84 struct ROW
85 {
86 wxString rowName;
87 int id;
89 bool state;
90 wxString tooltip;
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
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
122public:
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
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
206 }
207
211 void ClearRenderRows();
212
216 void SelectLayerRow( int aRow );
217
221 void SelectLayer( int aLayer );
222
226 int GetSelectedLayer();
227
231 void SetLayerVisible( int aLayer, bool isVisible );
232
236 bool IsLayerVisible( int aLayer );
237
241 void SetLayerColor( int aLayer, const COLOR4D& aColor );
242
246 COLOR4D GetLayerColor( int aLayer ) const;
247
251 COLOR4D GetRenderColor( int aRow ) const;
252
262 void SetRenderState( int aId, bool isSet );
263
269 bool GetRenderState( int aId );
270
271 void UpdateLayouts();
272
279 void UpdateLayerIcons();
280
281/* did not help:
282 void Freeze()
283 {
284 LAYER_PANEL_BASE::Freeze();
285 m_LayerScrolledWindow->Freeze();
286 m_RenderScrolledWindow->Freeze();
287 }
288
289 void Thaw()
290 {
291 m_RenderScrolledWindow->Thaw();
292 m_LayerScrolledWindow->Thaw();
293 LAYER_PANEL_BASE::Thaw();
294 }
295*/
296
297 //-----<abstract functions>-------------------------------------------
298
307 virtual void OnLayerColorChange( int aLayer, const COLOR4D& aColor ) = 0;
308
316 virtual bool OnLayerSelect( int aLayer ) = 0;
317
327 virtual void OnLayerVisible( int aLayer, bool isVisible, bool isFinal = true ) = 0;
328
334 virtual void OnLayerRightClick( wxMenu& aMenu ) = 0;
335
343 virtual void OnRenderColorChange( int aId, const COLOR4D& aColor ) = 0;
344
353 virtual void OnRenderEnable( int aId, bool isEnabled ) = 0;
354
355protected:
363 virtual bool useAlternateBitmap(int aRow) { return false; }
364
369 virtual COLOR4D getBackgroundLayerColor() { return COLOR4D::BLACK; }
370
379 static int encodeId( int aColumn, int aId );
380
387 static int getDecodedId( int aControlId );
388
389 void OnLeftDownLayers( wxMouseEvent& event );
390
394 void OnRightDownLayer( wxMouseEvent& event, COLOR_SWATCH* aColorSwatch,
395 const wxString& aLayerName );
396
400 void OnLayerSwatchChanged( wxCommandEvent& aEvent );
401
406 void OnLayerCheckBox( wxCommandEvent& event );
407
411 void OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch,
412 const wxString& aRenderName );
413
417 void OnRenderSwatchChanged( wxCommandEvent& aEvent );
418
419 void OnRenderCheckBox( wxCommandEvent& event );
420
421 void OnTabChange( wxNotebookEvent& event );
422
423
432 wxWindow* getLayerComp( int aRow, int aColumn ) const;
433 wxWindow* getRenderComp( int aRow, int aColumn ) const;
434
438 int findLayerRow( int aLayer ) const;
439 int findRenderRow( int aId ) const;
440
444 void insertLayerRow( int aRow, const ROW& aSpec );
445
446 void insertRenderRow( int aRow, const ROW& aSpec );
447
448 void setLayerCheckbox( int aLayer, bool isVisible );
449
450 void updateLayerRow( int aRow, const wxString& aName );
451
455 void passOnFocus();
456
457 // popup menu ids.
459 {
460 ID_CHANGE_LAYER_COLOR = wxID_HIGHEST,
463 };
464
465 wxNotebook* m_notebook;
466 wxPanel* m_LayerPanel;
467 wxScrolledWindow* m_LayerScrolledWindow;
468 wxFlexGridSizer* m_LayersFlexGridSizer;
470 wxScrolledWindow* m_RenderScrolledWindow;
471 wxFlexGridSizer* m_RenderFlexGridSizer;
472
473 wxWindow* m_FocusOwner;
476
478
480};
481
482#endif // LAYERWIDGET_H_
A simple color swatch of the kind used to set layer colors.
Definition: color_swatch.h:57
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Manage a list of layers with the notion of a "current" layer, and layer specific visibility control.
Definition: layer_widget.h:78
static int getDecodedId(int aControlId)
Decode aControlId to original un-encoded value.
void SelectLayerRow(int aRow)
Change the row selection in the layer list to the given row.
wxWindow * m_FocusOwner
Definition: layer_widget.h:473
static int encodeId(int aColumn, int aId)
Allow saving a layer index within a control as its wxControl id.
void SetRenderState(int aId, bool isSet)
Set the state of the checkbox associated with aId within the Render tab group of the widget.
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 insertRenderRow(int aRow, const ROW &aSpec)
void insertLayerRow(int aRow, const ROW &aSpec)
Append or insert a new row in the layer portion of the widget.
void AppendRenderRows(const ROW *aRowsArray, int aRowCount)
Append new rows in the render portion of the widget.
Definition: layer_widget.h:200
void AppendLayerRows(const ROW *aRowsArray, int aRowCount)
Append new rows in the layer portion of the widget.
Definition: layer_widget.h:175
wxScrolledWindow * m_RenderScrolledWindow
Definition: layer_widget.h:470
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color of aLayer.
ROW_ICON_PROVIDER * m_IconProvider
Definition: layer_widget.h:477
bool GetRenderState(int aId)
Return the state of the checkbox associated with aId.
void OnLeftDownLayers(wxMouseEvent &event)
void setLayerCheckbox(int aLayer, bool isVisible)
int GetRenderRowCount() const
Return the number of rows in the render tab.
wxPanel * m_RenderingPanel
Definition: layer_widget.h:469
virtual void OnLayerVisible(int aLayer, bool isVisible, bool isFinal=true)=0
Notify client code about a layer visibility change.
wxFlexGridSizer * m_LayersFlexGridSizer
Definition: layer_widget.h:468
void SelectLayer(int aLayer)
Change the row selection in the layer list to aLayer provided.
void OnRenderSwatchChanged(wxCommandEvent &aEvent)
Called when user has changed the swatch color of a render entry.
int GetLayerRowCount() const
Return the number of rows in the layer tab.
virtual ~LAYER_WIDGET()
void UpdateLayouts()
void passOnFocus()
Give away the keyboard focus up to the main parent window.
COLOR4D GetRenderColor(int aRow) const
Return the color of the Render ROW in position aRow.
void updateLayerRow(int aRow, const wxString &aName)
void OnTabChange(wxNotebookEvent &event)
int findLayerRow(int aLayer) const
Return the row index that aLayer resides in, or -1 if not found.
static const wxEventType EVT_LAYER_COLOR_CHANGE
Definition: layer_widget.h:120
int findRenderRow(int aId) const
int GetSelectedLayer()
Return the selected layer or -1 if none.
virtual void OnLayerRightClick(wxMenu &aMenu)=0
Notify client code about a layer being right-clicked.
void AppendRenderRow(const ROW &aRow)
Append a new row in the render portion of the widget.
bool IsLayerVisible(int aLayer)
Return the visible state of the layer ROW associated with aLayer id.
int m_CurrentRow
selected row of layer list
Definition: layer_widget.h:474
@ ID_CHANGE_RENDER_COLOR
Definition: layer_widget.h:461
virtual COLOR4D getBackgroundLayerColor()
Subclasses can override this to provide accurate representation of transparent color swatches.
Definition: layer_widget.h:369
void SetLayerVisible(int aLayer, bool isVisible)
Set aLayer visible or not.
void ClearLayerRows()
Empty out the layer rows.
void OnLayerSwatchChanged(wxCommandEvent &aEvent)
Called when a user changes a swatch color.
wxWindow * getLayerComp(int aRow, int aColumn) const
Return the component within the m_LayersFlexGridSizer at aRow and aCol or NULL if these parameters ar...
void UpdateLayerIcons()
Update all layer manager icons (layers only).
void AppendLayerRow(const ROW &aRow)
Append a new row in the layer portion of the widget.
wxString m_smallestLayerString
Definition: layer_widget.h:479
void ClearRenderRows()
Empty out the render rows.
virtual void OnRenderColorChange(int aId, const COLOR4D &aColor)=0
Notify client code whenever the user changes a rendering color.
virtual void OnLayerColorChange(int aLayer, const COLOR4D &aColor)=0
Notify client code about a layer color change.
COLOR4D GetLayerColor(int aLayer) const
Return the color of the layer ROW associated with aLayer id.
void OnLayerCheckBox(wxCommandEvent &event)
Handle the "is layer visible" checkbox and propagates the event to the client's notification function...
void OnRenderCheckBox(wxCommandEvent &event)
void OnRightDownLayer(wxMouseEvent &event, COLOR_SWATCH *aColorSwatch, const wxString &aLayerName)
Called when user right-clicks a layer.
wxWindow * getRenderComp(int aRow, int aColumn) const
virtual bool useAlternateBitmap(int aRow)
Definition: layer_widget.h:363
void OnRightDownRender(wxMouseEvent &aEvent, COLOR_SWATCH *aColorSwatch, const wxString &aRenderName)
Notify when user right-clicks a render option.
virtual bool OnLayerSelect(int aLayer)=0
Notify client code whenever the user selects a different layer.
wxFlexGridSizer * m_RenderFlexGridSizer
Definition: layer_widget.h:471
wxPanel * m_LayerPanel
Definition: layer_widget.h:466
wxSize GetBestSize() const
Return the preferred minimum size, taking into consideration the dynamic content.
wxNotebook * m_notebook
Definition: layer_widget.h:465
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
wxScrolledWindow * m_LayerScrolledWindow
Definition: layer_widget.h:467
Icon provider for the "standard" row indicators, for example in layer selection lists.
Provide all the data needed to add a row to a LAYER_WIDGET.
Definition: layer_widget.h:85
COLOR4D color
COLOR4D::UNSPECIFIED if none.
Definition: layer_widget.h:88
bool spacer
if true, this row is a spacer
Definition: layer_widget.h:92
wxString tooltip
if not empty, use this tooltip on row
Definition: layer_widget.h:90
int id
either a layer or "visible element" id
Definition: layer_widget.h:87
bool state
initial wxCheckBox state
Definition: layer_widget.h:89
wxString rowName
the prompt or layername
Definition: layer_widget.h:86
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
bool changeable
if true, the state can be changed
Definition: layer_widget.h:91
COLOR4D defaultColor
The default color for the row.
Definition: layer_widget.h:93