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
215 void OnColorThemeChanged();
216
218 void OnDarkModeToggle();
219
221 void OnLayerChanged();
222
224 void OnNetVisibilityChanged( int aNetCode, bool aVisibility );
225
227 void SetLayerVisible( int aLayer, bool isVisible );
228
229 void SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible = true );
230
232
234 std::vector<LAYER_PRESET> GetUserLayerPresets() const;
235
237 void SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList );
238
239 void ApplyLayerPreset( const wxString& aPresetName );
240
241 void ApplyLayerPreset( const LAYER_PRESET& aPreset );
242
243 wxString GetActiveLayerPreset() const
244 {
245 if( m_currentPreset )
246 return m_currentPreset->name;
247 else
248 return wxEmptyString;
249 }
250
251 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
252
254 std::vector<VIEWPORT> GetUserViewports() const;
255
257 void SetUserViewports( std::vector<VIEWPORT>& aPresetList );
258
259 void ApplyViewport( const wxString& aPresetName );
260
261 void ApplyViewport( const VIEWPORT& aPreset );
262
263 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
264
265 void OnColorSwatchChanged( wxCommandEvent& aEvent );
266
267 void OnLayerContextMenu( wxCommandEvent& aEvent );
268
270 int GetTabIndex() const;
271
273 void SetTabIndex( int aTab );
274
279
282
285
286protected:
287 void OnNotebookPageChanged( wxNotebookEvent& event ) override;
288 void OnSetFocus( wxFocusEvent& aEvent ) override;
289 void OnSize( wxSizeEvent& aEvent ) override;
290 void OnNetGridClick( wxGridEvent& event ) override;
291 void OnNetGridDoubleClick( wxGridEvent& event ) override;
292 void OnNetGridRightClick( wxGridEvent& event ) override;
293 void OnNetGridMouseEvent( wxMouseEvent& aEvent );
294 void OnLanguageChanged( wxCommandEvent& aEvent );
295
296private:
297 void createControls();
298
299 void rebuildLayers();
300
302
304
305 void rebuildObjects();
306
307 void syncObjectSettings();
308
309 void buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass, const wxString& aName );
310
311 void rebuildNets();
312
314
316
318
320
321 void onLayerLeftClick( wxMouseEvent& aEvent );
322
323 void rightClickHandler( wxMouseEvent& aEvent );
324
326
327 void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
328
329 void setVisibleLayers( LSET aLayers );
330
331 void setVisibleObjects( GAL_SET aObjects );
332
334
336
337 void onObjectOpacitySlider( int aLayer, float aOpacity );
338
339 void updateLayerPresetSelection( const wxString& aName );
340
341 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
342
343 void doApplyLayerPreset( const LAYER_PRESET& aPreset );
344
345 void updateViewportSelection( const wxString& aName );
346
347 void onViewportChanged( wxCommandEvent& aEvent ) override;
348
349 void doApplyViewport( const VIEWPORT& aViewport );
350
351 void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
352
353 void showNetclass( const wxString& aClassName, bool aShow = true );
354
355 void onNetContextMenu( wxCommandEvent& aEvent );
356
357 void onNetclassColorChanged( wxCommandEvent& aEvent );
358
359 wxString netclassNameFromEvent( wxEvent& aEvent );
360
361 void onNetColorMode( wxCommandEvent& aEvent );
362
363 void onRatsnestMode( wxCommandEvent& aEvent );
364
365 void onNetclassContextMenu( wxCommandEvent& aEvent );
366
368
369 void passOnFocus();
370
371 void idleFocusHandler( wxIdleEvent& aEvent );
372
373 void onReadOnlySwatch();
374
375 bool doesBoardItemNeedRebuild( BOARD_ITEM* aBoardItem );
376
377 bool doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems );
378
380
381 wxWindow* m_focusOwner;
382
384
386
388
390
391 // Nets grid view
393
395
397 wxGridCellCoords m_hoveredCell;
398
399 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
400 std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
401
402 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
403 std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
404
405 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
406 std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
407
408 // TODO(JE) Move preset storage to the PCB_CONTROL tool
409
410 std::map<wxString, LAYER_PRESET> m_layerPresets;
413 wxArrayString m_presetMRU;
414
415 std::map<wxString, VIEWPORT> m_viewports;
417 wxArrayString m_viewportMRU;
418
420
422 std::map<int, wxString> m_netclassIdMap;
423
426
429
430 // The built-in layer presets
439 // a LAYER_PRESET used only to store the objects visibility of the
440 // last selected built-in LAYER_PRESET preset
442
444
446
447 // Layer display options controls
451 wxRadioButton* m_rbHighContrastDim;
452 wxRadioButton* m_rbHighContrastOff;
454 wxCheckBox* m_cbFlipBoard;
455
456 // Net display options controls
458 wxStaticText* m_txtNetDisplayTitle;
459 wxRadioButton* m_rbNetColorAll;
460 wxRadioButton* m_rbNetColorRatsnest;
461 wxRadioButton* m_rbNetColorOff;
463 wxRadioButton* m_rbRatsnestAllLayers;
464 wxRadioButton* m_rbRatsnestVisLayers;
465 wxRadioButton* m_rbRatsnestNone;
466
468 {
469 ID_CHANGE_COLOR = wxID_HIGHEST,
491 };
492
494};
495
496#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)
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
Update the colors on all the widgets from the new chosen color theme.
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:276
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:306
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:573
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:193
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