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;
156 bool spacer;
157
158 wxPanel* ctl_panel;
162 wxStaticText* ctl_text;
163 wxSlider* ctl_opacity;
164
165 APPEARANCE_SETTING( const wxString& aLabel, int aId,
166 const wxString& aTooltip = wxEmptyString,
167 bool aCanControlOpacity = false ) :
168 id( aId ),
169 label( aLabel ),
170 tooltip( aTooltip ),
171 visible( true ),
172 can_control_opacity( aCanControlOpacity ),
173 spacer( false ),
174 ctl_panel( nullptr ),
175 ctl_indicator( nullptr ),
176 ctl_visibility( nullptr ),
177 ctl_color( nullptr ),
178 ctl_text( nullptr ),
179 ctl_opacity( nullptr )
180 {
181 }
182
184 id( -1 ),
185 visible( false ),
186 can_control_opacity( false ),
187 spacer( true ),
188 ctl_panel( nullptr ),
189 ctl_indicator( nullptr ),
190 ctl_visibility( nullptr ),
191 ctl_color( nullptr ),
192 ctl_text( nullptr ),
193 ctl_opacity( nullptr )
194 {
195 }
196 };
197
198 APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFocusOwner, bool aFpEditor = false );
200
201 wxSize GetBestSize() const;
202
204 void OnBoardChanged();
205
206 void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
207 void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aItem ) override;
208 void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
209 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aItem ) override;
210 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
211 void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aItem ) override;
212 void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
213 void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
214 std::vector<BOARD_ITEM*>& aRemovedItems,
215 std::vector<BOARD_ITEM*>& aDeletedItems ) override;
216
218 void OnColorThemeChanged();
219
221 void OnDarkModeToggle();
222
224 void OnLayerChanged();
225
227 void OnNetVisibilityChanged( int aNetCode, bool aVisibility );
228
230 void SetLayerVisible( int aLayer, bool isVisible );
231
232 void SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible = true );
233
235
237 std::vector<LAYER_PRESET> GetUserLayerPresets() const;
238
240 void SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList );
241
242 void ApplyLayerPreset( const wxString& aPresetName );
243
244 void ApplyLayerPreset( const LAYER_PRESET& aPreset );
245
246 wxString GetActiveLayerPreset() const
247 {
248 if( m_currentPreset )
249 return m_currentPreset->name;
250 else
251 return wxEmptyString;
252 }
253
254 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
255
257 std::vector<VIEWPORT> GetUserViewports() const;
258
260 void SetUserViewports( std::vector<VIEWPORT>& aPresetList );
261
262 void ApplyViewport( const wxString& aPresetName );
263
264 void ApplyViewport( const VIEWPORT& aPreset );
265
266 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
267
268 void OnColorSwatchChanged( wxCommandEvent& aEvent );
269
270 void OnLayerContextMenu( wxCommandEvent& aEvent );
271
273 int GetTabIndex() const;
274
276 void SetTabIndex( int aTab );
277
282
285
288
289protected:
290 void OnNotebookPageChanged( wxNotebookEvent& event ) override;
291 void OnSetFocus( wxFocusEvent& aEvent ) override;
292 void OnSize( wxSizeEvent& aEvent ) override;
293 void OnNetGridClick( wxGridEvent& event ) override;
294 void OnNetGridDoubleClick( wxGridEvent& event ) override;
295 void OnNetGridRightClick( wxGridEvent& event ) override;
296 void OnNetGridMouseEvent( wxMouseEvent& aEvent );
297 void OnLanguageChanged( wxCommandEvent& aEvent );
298
299private:
300 void createControls();
301
302 void rebuildLayers();
303
305
307
308 void rebuildObjects();
309
310 void syncObjectSettings();
311
312 void buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass, const wxString& aName );
313
314 void rebuildNets();
315
317
319
321
323
324 void onLayerLeftClick( wxMouseEvent& aEvent );
325
326 void rightClickHandler( wxMouseEvent& aEvent );
327
329
330 void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
331
332 void setVisibleLayers( LSET aLayers );
333
334 void setVisibleObjects( GAL_SET aObjects );
335
337
339
340 void onObjectOpacitySlider( int aLayer, float aOpacity );
341
342 void updateLayerPresetSelection( const wxString& aName );
343
344 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
345
346 void doApplyLayerPreset( const LAYER_PRESET& aPreset );
347
348 void updateViewportSelection( const wxString& aName );
349
350 void onViewportChanged( wxCommandEvent& aEvent ) override;
351
352 void doApplyViewport( const VIEWPORT& aViewport );
353
354 void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
355
356 void showNetclass( const wxString& aClassName, bool aShow = true );
357
358 void onNetContextMenu( wxCommandEvent& aEvent );
359
360 void onNetclassColorChanged( wxCommandEvent& aEvent );
361
362 wxString netclassNameFromEvent( wxEvent& aEvent );
363
364 void onNetColorMode( wxCommandEvent& aEvent );
365
366 void onRatsnestMode( wxCommandEvent& aEvent );
367
368 void onNetclassContextMenu( wxCommandEvent& aEvent );
369
371
372 void passOnFocus();
373
374 void idleFocusHandler( wxIdleEvent& aEvent );
375
376 void onReadOnlySwatch();
377
378 bool doesBoardItemNeedRebuild( BOARD_ITEM* aBoardItem );
379
380 bool doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems );
381
383
384 wxWindow* m_focusOwner;
385
387
389
391
393
394 // Nets grid view
396
398
400 wxGridCellCoords m_hoveredCell;
401
402 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
403 std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
404
405 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
406 std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
407
408 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
409 std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
410
411 // TODO(JE) Move preset storage to the PCB_CONTROL tool
412
413 std::map<wxString, LAYER_PRESET> m_layerPresets;
416 wxArrayString m_presetMRU;
417
418 std::map<wxString, VIEWPORT> m_viewports;
420 wxArrayString m_viewportMRU;
421
423
425 std::map<int, wxString> m_netclassIdMap;
426
429
432
433 // The built-in layer presets
442 // a LAYER_PRESET used only to store the objects visibility of the
443 // last selected built-in LAYER_PRESET preset
445
447
449
450 // Layer display options controls
454 wxRadioButton* m_rbHighContrastDim;
455 wxRadioButton* m_rbHighContrastOff;
457 wxCheckBox* m_cbFlipBoard;
458
459 // Net display options controls
461 wxStaticText* m_txtNetDisplayTitle;
462 wxRadioButton* m_rbNetColorAll;
463 wxRadioButton* m_rbNetColorRatsnest;
464 wxRadioButton* m_rbNetColorOff;
466 wxRadioButton* m_rbRatsnestAllLayers;
467 wxRadioButton* m_rbRatsnestVisLayers;
468 wxRadioButton* m_rbRatsnestNone;
469
471 {
472 ID_CHANGE_COLOR = wxID_HIGHEST,
494 };
495
497};
498
499#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:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:281
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: layer_ids.h:574
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:194
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)
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