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 The KiCad Developers, see AUTHORS.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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef LAYERWIDGET_H_
22#define LAYERWIDGET_H_
23
24#include <wx/intl.h>
25#include <wx/statbmp.h>
26#include <wx/string.h>
27#include <wx/aui/auibook.h>
28#include <wx/notebook.h>
29#include <wx/sizer.h>
30#include <wx/gdicmn.h>
31#include <wx/scrolwin.h>
32#include <wx/font.h>
33#include <wx/colour.h>
34#include <wx/settings.h>
35#include <wx/panel.h>
36#include <wx/bitmap.h>
37#include <wx/image.h>
38#include <wx/icon.h>
39#include <layer_ids.h>
40#include <gal/color4d.h>
43
44#define LYR_COLUMN_COUNT 5
45#define RND_COLUMN_COUNT 2
46
47#define COLUMN_ICON_ACTIVE 0
48#define COLUMN_COLORBM 1
49#define COLUMN_COLOR_LYR_CB 2
50#define COLUMN_COLOR_LYRNAME 3
51#define COLUMN_ALPHA_INDICATOR 4
52
53using KIGFX::COLOR4D;
54
73class LAYER_WIDGET : public wxPanel
74{
75public:
80 struct ROW
81 {
82 wxString rowName;
83 int id;
85 bool state;
86 wxString tooltip;
88 bool spacer;
90
91 ROW( const wxString& aRowName, int aId, const COLOR4D& aColor = COLOR4D::UNSPECIFIED,
92 const wxString& aTooltip = wxEmptyString, bool aState = true,
93 bool aChangeable = true, const COLOR4D& aDefaultColor = COLOR4D::UNSPECIFIED )
94 {
95 rowName = aRowName;
96 id = aId;
97 color = aColor;
98 state = aState;
99 tooltip = aTooltip;
100 changeable = aChangeable;
101 spacer = false;
102 defaultColor = aDefaultColor;
103 }
104
106 {
107 id = 0;
109 state = true;
110 changeable = true;
111 spacer = true;
113 }
114 };
115
116 static const wxEventType EVT_LAYER_COLOR_CHANGE;
117
118public:
119
128 LAYER_WIDGET( wxWindow* aParent, wxWindow* aFocusOwner, wxWindowID id = wxID_ANY,
129 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
130 long style = wxTAB_TRAVERSAL );
131
132 virtual ~LAYER_WIDGET();
133
137 void SetSmallestLayerString( const wxString& aString )
138 {
139 m_smallestLayerString = aString;
140 }
141
147 wxSize GetBestSize() const;
148
152 int GetLayerRowCount() const;
153
157 int GetRenderRowCount() const;
158
164 void AppendLayerRow( const ROW& aRow );
165
171 void AppendLayerRows( const ROW* aRowsArray, int aRowCount )
172 {
173 for( int row=0; row<aRowCount; ++row )
174 AppendLayerRow( aRowsArray[row] );
175
177 }
178
182 void ClearLayerRows();
183
189 void AppendRenderRow( const ROW& aRow );
190
196 void AppendRenderRows( const ROW* aRowsArray, int aRowCount )
197 {
198 for( int row=0; row<aRowCount; ++row )
199 AppendRenderRow( aRowsArray[row] );
200
202 }
203
207 void ClearRenderRows();
208
212 void SelectLayerRow( int aRow );
213
217 void SelectLayer( int aLayer );
218
222 int GetSelectedLayer();
223
227 void SetLayerVisible( int aLayer, bool isVisible );
228
232 bool IsLayerVisible( int aLayer );
233
237 void SetLayerColor( int aLayer, const COLOR4D& aColor );
238
242 COLOR4D GetLayerColor( int aLayer ) const;
243
247 COLOR4D GetRenderColor( int aRow ) const;
248
258 void SetRenderState( int aId, bool isSet );
259
265 bool GetRenderState( int aId );
266
267 void UpdateLayouts();
268
275 void UpdateLayerIcons();
276
277/* did not help:
278 void Freeze()
279 {
280 LAYER_PANEL_BASE::Freeze();
281 m_LayerScrolledWindow->Freeze();
282 m_RenderScrolledWindow->Freeze();
283 }
284
285 void Thaw()
286 {
287 m_RenderScrolledWindow->Thaw();
288 m_LayerScrolledWindow->Thaw();
289 LAYER_PANEL_BASE::Thaw();
290 }
291*/
292
293 //-----<abstract functions>-------------------------------------------
294
303 virtual void OnLayerColorChange( int aLayer, const COLOR4D& aColor ) = 0;
304
312 virtual bool OnLayerSelect( int aLayer ) = 0;
313
323 virtual void OnLayerVisible( int aLayer, bool isVisible, bool isFinal = true ) = 0;
324
330 virtual void OnLayerRightClick( wxMenu& aMenu ) = 0;
331
339 virtual void OnRenderColorChange( int aId, const COLOR4D& aColor ) = 0;
340
349 virtual void OnRenderEnable( int aId, bool isEnabled ) = 0;
350
351protected:
359 virtual bool useAlternateBitmap(int aRow) { return false; }
360
366
375 static int encodeId( int aColumn, int aId );
376
383 static int getDecodedId( int aControlId );
384
385 void OnLeftDownLayers( wxMouseEvent& event );
386
390 void OnRightDownLayer( wxMouseEvent& event, COLOR_SWATCH* aColorSwatch,
391 const wxString& aLayerName );
392
396 void OnLayerSwatchChanged( wxCommandEvent& aEvent );
397
402 void OnLayerCheckBox( wxCommandEvent& event );
403
407 void OnRightDownRender( wxMouseEvent& aEvent, COLOR_SWATCH* aColorSwatch,
408 const wxString& aRenderName );
409
413 void OnRenderSwatchChanged( wxCommandEvent& aEvent );
414
415 void OnRenderCheckBox( wxCommandEvent& event );
416
417 void OnTabChange( wxNotebookEvent& event );
418
419
428 wxWindow* getLayerComp( int aRow, int aColumn ) const;
429 wxWindow* getRenderComp( int aRow, int aColumn ) const;
430
434 int findLayerRow( int aLayer ) const;
435 int findRenderRow( int aId ) const;
436
440 void insertLayerRow( int aRow, const ROW& aSpec );
441
442 void insertRenderRow( int aRow, const ROW& aSpec );
443
444 void setLayerCheckbox( int aLayer, bool isVisible );
445
446 void updateLayerRow( int aRow, const wxString& aName );
447
451 void passOnFocus();
452
453 // popup menu ids.
460
461 wxNotebook* m_notebook;
462 wxPanel* m_LayerPanel;
463 wxScrolledWindow* m_LayerScrolledWindow;
464 wxFlexGridSizer* m_LayersFlexGridSizer;
466 wxScrolledWindow* m_RenderScrolledWindow;
467 wxFlexGridSizer* m_RenderFlexGridSizer;
468
469 wxWindow* m_FocusOwner;
472
474
476};
477
478#endif // LAYERWIDGET_H_
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:398
static const COLOR4D BLACK
Definition color4d.h:402
A simple color swatch of the kind used to set layer colors.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
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
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.
void AppendLayerRows(const ROW *aRowsArray, int aRowCount)
Append new rows in the layer portion of the widget.
wxScrolledWindow * m_RenderScrolledWindow
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color of aLayer.
ROW_ICON_PROVIDER * m_IconProvider
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.
LAYER_WIDGET(wxWindow *aParent, wxWindow *aFocusOwner, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL)
wxPanel * m_RenderingPanel
virtual void OnLayerVisible(int aLayer, bool isVisible, bool isFinal=true)=0
Notify client code about a layer visibility change.
wxFlexGridSizer * m_LayersFlexGridSizer
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 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
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
virtual COLOR4D getBackgroundLayerColor()
Subclasses can override this to provide accurate representation of transparent color swatches.
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
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)
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
wxPanel * m_LayerPanel
wxSize GetBestSize() const
Return the preferred minimum size, taking into consideration the dynamic content.
wxNotebook * m_notebook
void SetSmallestLayerString(const wxString &aString)
Set the string that is used for determining the smallest string displayed in the layer's tab.
wxScrolledWindow * m_LayerScrolledWindow
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.
COLOR4D color
COLOR4D::UNSPECIFIED if none.
bool spacer
if true, this row is a spacer
wxString tooltip
if not empty, use this tooltip on row
int id
either a layer or "visible element" id
bool state
initial wxCheckBox state
wxString rowName
the prompt or layername
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)
bool changeable
if true, the state can be changed
COLOR4D defaultColor
The default color for the row.