KiCad PCB EDA Suite
Loading...
Searching...
No Matches
appearance_controls.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) 2020 Jon Evans <[email protected]>
5 * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef _APPEARANCE_CONTROLS_H
22#define _APPEARANCE_CONTROLS_H
23
24#include <vector>
25
26#include <board.h>
27#include <gal/color4d.h>
28#include <layer_ids.h>
31
32
33class BITMAP_TOGGLE;
34class COLOR_SWATCH;
35class INDICATOR_ICON;
36class PCB_BASE_FRAME;
37class PCBNEW_SETTINGS;
41class wxStaticLine;
42class wxSlider;
43class wxRadioButton;
44
45using KIGFX::COLOR4D;
46
47
49{
50 NET_GRID_ENTRY( int aCode, const wxString& aName, const COLOR4D& aColor, bool aVisible )
51 {
52 code = aCode;
53 name = aName;
54 color = aColor;
55 visible = aVisible;
56 }
57
58 int code;
59 wxString name;
61 bool visible;
62};
63
64
65class NET_GRID_TABLE : public wxGridTableBase
66{
67public:
69 {
74 };
75
76 static void* ColorToVoid( COLOR4D& aColor )
77 {
78 return static_cast<void*>( &aColor );
79 }
80
81 static COLOR4D VoidToColor( void* aColor )
82 {
83 return *static_cast<COLOR4D*>( aColor );
84 }
85
86public:
87 NET_GRID_TABLE( PCB_BASE_FRAME* aFrame, wxColor aBackgroundColor );
89
90 int GetNumberRows() override
91 {
92 return m_nets.size();
93 }
94
95 int GetNumberCols() override
96 {
97 return COL_SIZE;
98 }
99
100 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind ) override;
101
102 wxString GetValue( int aRow, int aCol ) override;
103
104 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
105
106 wxString GetTypeName( int aRow, int aCol ) override;
107
108 bool GetValueAsBool( int aRow, int aCol ) override;
109
110 void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
111
112 void* GetValueAsCustom( int aRow, int aCol, const wxString& aTypeName ) override;
113
114 void SetValueAsCustom( int aRow, int aCol, const wxString& aTypeName, void* aValue ) override;
115
116 NET_GRID_ENTRY& GetEntry( int aRow );
117
118 int GetRowByNetcode( int aCode ) const;
119
120 void Rebuild();
121
122 void ShowAllNets();
123
124 void HideOtherNets( const NET_GRID_ENTRY& aNet );
125
126private:
127 void updateNetVisibility( const NET_GRID_ENTRY& aNet );
128
129 void updateNetColor( const NET_GRID_ENTRY& aNet );
130
131private:
133
134 std::vector<NET_GRID_ENTRY> m_nets;
135
136 wxGridCellAttr* m_defaultAttr;
137 wxGridCellAttr* m_labelAttr;
138};
139
140
141
143{
144public:
145
150 {
151 int id;
152 wxString label;
153 wxString tooltip;
157 bool spacer;
158
159 wxPanel* ctl_panel;
163 wxStaticText* ctl_text;
164 wxSlider* ctl_opacity;
165
166 APPEARANCE_SETTING( const wxString& aLabel, int aId,
167 const wxString& aTooltip = wxEmptyString,
168 bool aCanControlOpacity = false,
169 bool aCanControlVisibility = true ) :
170 id( aId ),
171 label( aLabel ),
172 tooltip( aTooltip ),
173 visible( true ),
174 can_control_opacity( aCanControlOpacity ),
175 can_control_visibility( aCanControlVisibility ),
176 spacer( false ),
177 ctl_panel( nullptr ),
178 ctl_indicator( nullptr ),
179 ctl_visibility( nullptr ),
180 ctl_color( nullptr ),
181 ctl_text( nullptr ),
182 ctl_opacity( nullptr )
183 {
184 }
185
187 id( -1 ),
188 visible( false ),
189 can_control_opacity( false ),
191 spacer( true ),
192 ctl_panel( nullptr ),
193 ctl_indicator( nullptr ),
194 ctl_visibility( nullptr ),
195 ctl_color( nullptr ),
196 ctl_text( nullptr ),
197 ctl_opacity( nullptr )
198 {
199 }
200 };
201
202 APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFocusOwner, bool aFpEditor = false );
204
205 wxSize GetBestSize() const;
206
208 void OnBoardChanged();
209
210 void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
211 void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aItem ) override;
212 void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
213 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aItem ) override;
214 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
215 void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aItem ) override;
216 void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
217 void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
218 std::vector<BOARD_ITEM*>& aRemovedItems,
219 std::vector<BOARD_ITEM*>& aDeletedItems ) override;
220
222 void OnColorThemeChanged();
223
225 void OnDarkModeToggle();
226
228 void OnLayerChanged();
229
231 void OnNetVisibilityChanged( int aNetCode, bool aVisibility );
232
234 void SetLayerVisible( int aLayer, bool isVisible );
235
236 void SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible = true );
237
239
241 std::vector<LAYER_PRESET> GetUserLayerPresets() const;
242
244 void SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList );
245
246 void ApplyLayerPreset( const wxString& aPresetName );
247
248 void ApplyLayerPreset( const LAYER_PRESET& aPreset );
249
250 wxString GetActiveLayerPreset() const
251 {
252 if( m_currentPreset )
253 return m_currentPreset->name;
254 else
255 return wxEmptyString;
256 }
257
258 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
259
261 std::vector<VIEWPORT> GetUserViewports() const;
262
264 void SetUserViewports( std::vector<VIEWPORT>& aPresetList );
265
266 void ApplyViewport( const wxString& aPresetName );
267
268 void ApplyViewport( const VIEWPORT& aPreset );
269
270 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
271
272 void OnColorSwatchChanged( wxCommandEvent& aEvent );
273
274 void OnLayerContextMenu( wxCommandEvent& aEvent );
275
277 int GetTabIndex() const;
278
280 void SetTabIndex( int aTab );
281
286
289
292
293protected:
294 void OnNotebookPageChanged( wxNotebookEvent& event ) override;
295 void OnSetFocus( wxFocusEvent& aEvent ) override;
296 void OnSize( wxSizeEvent& aEvent ) override;
297 void OnNetGridClick( wxGridEvent& event ) override;
298 void OnNetGridDoubleClick( wxGridEvent& event ) override;
299 void OnNetGridRightClick( wxGridEvent& event ) override;
300 void OnNetGridMouseEvent( wxMouseEvent& aEvent );
301 void OnLanguageChanged( wxCommandEvent& aEvent );
302
303private:
304 void createControls();
305
306 void rebuildLayers();
307
309
311
312 void rebuildObjects();
313
314 void syncObjectSettings();
315
316 void buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass, const wxString& aName );
317
318 void rebuildNets();
319
321
323
325
327
328 void onLayerLeftClick( wxMouseEvent& aEvent );
329
330 void rightClickHandler( wxMouseEvent& aEvent );
331
333
334 void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
335
336 void setVisibleLayers( LSET aLayers );
337
338 void setVisibleObjects( GAL_SET aObjects );
339
341
343
344 void onObjectOpacitySlider( int aLayer, float aOpacity );
345
346 void updateLayerPresetSelection( const wxString& aName );
347
348 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
349
350 void doApplyLayerPreset( const LAYER_PRESET& aPreset );
351
352 void updateViewportSelection( const wxString& aName );
353
354 void onViewportChanged( wxCommandEvent& aEvent ) override;
355
356 void doApplyViewport( const VIEWPORT& aViewport );
357
358 void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
359
360 void showNetclass( const wxString& aClassName, bool aShow = true );
361
362 void onNetContextMenu( wxCommandEvent& aEvent );
363
364 void onNetclassColorChanged( wxCommandEvent& aEvent );
365
366 wxString netclassNameFromEvent( wxEvent& aEvent );
367
368 void onNetColorMode( wxCommandEvent& aEvent );
369
370 void onRatsnestMode( wxCommandEvent& aEvent );
371
372 void onNetclassContextMenu( wxCommandEvent& aEvent );
373
375
376 void passOnFocus();
377
378 void idleFocusHandler( wxIdleEvent& aEvent );
379
380 void onReadOnlySwatch();
381
382 bool doesBoardItemNeedRebuild( BOARD_ITEM* aBoardItem );
383
384 bool doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems );
385
387
388 wxWindow* m_focusOwner;
389
391
393
395
397
398 // Nets grid view
400
402
404 wxGridCellCoords m_hoveredCell;
405
406 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
407 std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
408
409 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
410 std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
411
412 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
413 std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
414
415 // TODO(JE) Move preset storage to the PCB_CONTROL tool
416
417 std::map<wxString, LAYER_PRESET> m_layerPresets;
420 wxArrayString m_presetMRU;
421
422 std::map<wxString, VIEWPORT> m_viewports;
424 wxArrayString m_viewportMRU;
425
427
429 std::map<int, wxString> m_netclassIdMap;
430
433
436
437 // The built-in layer presets
446 // a LAYER_PRESET used only to store the objects visibility of the
447 // last selected built-in LAYER_PRESET preset
449
451
453
454 // Layer display options controls
458 wxRadioButton* m_rbHighContrastDim;
459 wxRadioButton* m_rbHighContrastOff;
461 wxCheckBox* m_cbFlipBoard;
462
463 // Net display options controls
465 wxStaticText* m_txtNetDisplayTitle;
466 wxRadioButton* m_rbNetColorAll;
467 wxRadioButton* m_rbNetColorRatsnest;
468 wxRadioButton* m_rbNetColorOff;
470 wxRadioButton* m_rbRatsnestAllLayers;
471 wxRadioButton* m_rbRatsnestVisLayers;
472 wxRadioButton* m_rbRatsnestNone;
473
475 {
476 ID_CHANGE_COLOR = wxID_HIGHEST,
498 };
499
501};
502
503#endif
Class APPEARANCE_CONTROLS_BASE.
void OnBoardNetSettingsChanged(BOARD &aBoard) override
void doApplyLayerPreset(const LAYER_PRESET &aPreset)
std::map< PCB_LAYER_ID, APPEARANCE_SETTING * > m_layerSettingsMap
wxStaticText * m_inactiveLayersLabel
std::map< GAL_LAYER_ID, APPEARANCE_SETTING * > m_objectSettingsMap
void ApplyLayerPreset(const wxString &aPresetName)
static LAYER_PRESET m_lastBuiltinPreset
wxRadioButton * m_rbHighContrastNormal
void onObjectVisibilityChanged(GAL_LAYER_ID aLayer, bool isVisible, bool isFinal)
static LAYER_PRESET presetFrontAssembly
void OnBoardItemAdded(BOARD &aBoard, BOARD_ITEM *aItem) override
static LAYER_PRESET presetBackAssembly
void OnNetGridClick(wxGridEvent &event) override
void setVisibleObjects(GAL_SET aObjects)
void OnBoardCompositeUpdate(BOARD &aBoard, std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aDeletedItems) override
Update the colors on all the widgets from the new chosen color theme.
wxRadioButton * m_rbRatsnestNone
WX_COLLAPSIBLE_PANE * m_paneLayerDisplayOptions
void buildNetClassMenu(wxMenu &aMenu, bool isDefaultClass, const wxString &aName)
void onLayerVisibilityToggled(PCB_LAYER_ID aLayer)
void onLayerPresetChanged(wxCommandEvent &aEvent) override
void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aItem) override
wxRadioButton * m_rbRatsnestVisLayers
wxRadioButton * m_rbNetColorAll
bool doesBoardItemNeedRebuild(BOARD_ITEM *aBoardItem)
void SetUserLayerPresets(std::vector< LAYER_PRESET > &aPresetList)
std::vector< LAYER_PRESET > GetUserLayerPresets() const
Update the current layer presets from those saved in the project file.
static LAYER_PRESET presetInnerCopper
void updateViewportSelection(const wxString &aName)
std::map< wxString, VIEWPORT > m_viewports
void onViewportChanged(wxCommandEvent &aEvent) override
NET_GRID_TABLE * m_netsTable
std::vector< std::unique_ptr< APPEARANCE_SETTING > > m_layerSettings
std::vector< std::unique_ptr< APPEARANCE_SETTING > > m_objectSettings
void onObjectOpacitySlider(int aLayer, float aOpacity)
wxRadioButton * m_rbRatsnestAllLayers
wxBoxSizer * m_objectsOuterSizer
wxSize GetBestSize() const
Update the panel contents from the application and board models.
void setVisibleLayers(LSET aLayers)
LAYER_PRESET * m_lastSelectedUserPreset
wxString m_contextMenuNetclass
The name of the netclass that was right-clicked.
wxRadioButton * m_rbNetColorRatsnest
void onRatsnestMode(wxCommandEvent &aEvent)
wxRadioButton * m_rbNetColorOff
static LAYER_PRESET presetFront
void doApplyViewport(const VIEWPORT &aViewport)
static const APPEARANCE_SETTING s_objectSettings[]
Template for object appearance settings.
const wxArrayString & GetViewportsMRU()
void OnNetGridMouseEvent(wxMouseEvent &aEvent)
WX_COLLAPSIBLE_PANE * m_paneNetDisplayOptions
void OnNotebookPageChanged(wxNotebookEvent &event) override
int GetTabIndex() const
Set the current notebook tab.
void onNetclassVisibilityChanged(wxCommandEvent &aEvent)
void OnBoardItemsRemoved(BOARD &aBoard, std::vector< BOARD_ITEM * > &aItems) override
void onNetContextMenu(wxCommandEvent &aEvent)
void OnColorSwatchChanged(wxCommandEvent &aEvent)
void updateLayerPresetSelection(const wxString &aName)
ROW_ICON_PROVIDER * m_iconProvider
std::map< wxString, LAYER_PRESET > m_layerPresets
static LAYER_PRESET presetBack
void RefreshCollapsiblePanes()
Function to force a redraw of the collapsible panes in this control.
static LAYER_PRESET presetNoLayers
void idleFocusHandler(wxIdleEvent &aEvent)
void rightClickHandler(wxMouseEvent &aEvent)
void OnNetGridRightClick(wxGridEvent &event) override
void OnBoardItemsChanged(BOARD &aBoard, std::vector< BOARD_ITEM * > &aItems) override
wxBoxSizer * m_layersOuterSizer
void UpdateDisplayOptions()
Return a list of the layer presets created by the user.
std::vector< std::unique_ptr< APPEARANCE_SETTING > > m_netclassSettings
wxRadioButton * m_rbHighContrastOff
const wxArrayString & GetLayerPresetsMRU()
Return a list of viewports created by the user.
void OnBoardItemsAdded(BOARD &aBoard, std::vector< BOARD_ITEM * > &aItems) override
void OnColorThemeChanged()
Respond to change in OS's DarkMode.
LAYER_PRESET * m_currentPreset
std::map< wxString, APPEARANCE_SETTING * > m_netclassSettingsMap
PCB_BASE_FRAME * m_frame
void OnSetFocus(wxFocusEvent &aEvent) override
void OnLanguageChanged(wxCommandEvent &aEvent)
static LAYER_PRESET presetAllCopper
void SetUserViewports(std::vector< VIEWPORT > &aPresetList)
wxRadioButton * m_rbHighContrastDim
void OnSize(wxSizeEvent &aEvent) override
wxString netclassNameFromEvent(wxEvent &aEvent)
bool IsTogglingNetRatsnestVisibility()
wxGridCellCoords m_hoveredCell
Grid cell that is being hovered over, for tooltips.
void showNetclass(const wxString &aClassName, bool aShow=true)
wxStaticText * m_txtRatsnestVisibility
wxString GetActiveLayerPreset() const
void onLayerLeftClick(wxMouseEvent &aEvent)
std::vector< VIEWPORT > GetUserViewports() const
Update the current viewports from those saved in the project file.
std::map< int, wxString > m_netclassIdMap
Stores wxIDs for each netclass for control event mapping.
void OnLayerContextMenu(wxCommandEvent &aEvent)
Return the index of the current tab (0-2).
void onNetColorMode(wxCommandEvent &aEvent)
void OnNetVisibilityChanged(int aNetCode, bool aVisibility)
Notifies the panel when a net has been hidden or shown via the external tool.
void OnDarkModeToggle()
Update the widget when the active board layer is changed.
static LAYER_PRESET presetAllLayers
void onNetclassContextMenu(wxCommandEvent &aEvent)
wxStaticText * m_txtNetDisplayTitle
wxStaticLine * m_layerDisplaySeparator
void SetObjectVisible(GAL_LAYER_ID aLayer, bool isVisible=true)
void OnNetGridDoubleClick(wxGridEvent &event) override
void SetLayerVisible(int aLayer, bool isVisible)
void OnBoardItemChanged(BOARD &aBoard, BOARD_ITEM *aItem) override
void onNetclassColorChanged(wxCommandEvent &aEvent)
void ApplyViewport(const wxString &aPresetName)
GRID_BITMAP_TOGGLE_RENDERER * m_toggleGridRenderer
A checkbox control except with custom bitmaps for the checked and unchecked states.
Definition: bitmap_toggle.h:45
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
A simple color swatch of the kind used to set layer colors.
Definition: color_swatch.h:57
Helper for storing and iterating over GAL_LAYER_IDs.
Definition: layer_ids.h:307
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
representing a row indicator icon for use in places like the layer widget
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
void SetValue(int aRow, int aCol, const wxString &aValue) override
void SetValueAsCustom(int aRow, int aCol, const wxString &aTypeName, void *aValue) override
std::vector< NET_GRID_ENTRY > m_nets
void updateNetColor(const NET_GRID_ENTRY &aNet)
NET_GRID_ENTRY & GetEntry(int aRow)
void SetValueAsBool(int aRow, int aCol, bool aValue) override
void * GetValueAsCustom(int aRow, int aCol, const wxString &aTypeName) override
void updateNetVisibility(const NET_GRID_ENTRY &aNet)
wxString GetValue(int aRow, int aCol) override
wxGridCellAttr * m_labelAttr
PCB_BASE_FRAME * m_frame
void HideOtherNets(const NET_GRID_ENTRY &aNet)
wxGridCellAttr * m_defaultAttr
bool GetValueAsBool(int aRow, int aCol) override
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind) override
int GetNumberCols() override
static void * ColorToVoid(COLOR4D &aColor)
int GetRowByNetcode(int aCode) const
int GetNumberRows() override
wxString GetTypeName(int aRow, int aCol) override
static COLOR4D VoidToColor(void *aColor)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
Icon provider for the "standard" row indicators, for example in layer selection lists.
A better wxCollapsiblePane that.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition: layer_ids.h:191
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
Container for an appearance setting (can control a single board layer, or GAL layer,...
APPEARANCE_SETTING(const wxString &aLabel, int aId, const wxString &aTooltip=wxEmptyString, bool aCanControlOpacity=false, bool aCanControlVisibility=true)
A saved set of layers that are visible.
wxString name
A name for this layer set.
NET_GRID_ENTRY(int aCode, const wxString &aName, const COLOR4D &aColor, bool aVisible)
COLOR4D color
int code
wxString name
bool visible