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 The 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef _APPEARANCE_CONTROLS_H
22#define _APPEARANCE_CONTROLS_H
23
24#include <unordered_map>
25#include <vector>
26
27#include <board.h>
28#include <gal/color4d.h>
29#include <layer_ids.h>
32
33
34class BITMAP_TOGGLE;
35class COLOR_SWATCH;
36class INDICATOR_ICON;
37class PCB_BASE_FRAME;
38class PCBNEW_SETTINGS;
42class wxStaticLine;
43class wxSlider;
44class wxRadioButton;
45
46using KIGFX::COLOR4D;
47
48
50{
51 NET_GRID_ENTRY( int aCode, const wxString& aName, const COLOR4D& aColor, bool aVisible )
52 {
53 code = aCode;
54 name = aName;
55 color = aColor;
56 visible = aVisible;
57 }
58
59 int code;
60 wxString name;
62 bool visible;
63};
64
65
66class NET_GRID_TABLE : public wxGridTableBase
67{
68public:
76
77 static void* ColorToVoid( COLOR4D& aColor )
78 {
79 return static_cast<void*>( &aColor );
80 }
81
82 static COLOR4D VoidToColor( void* aColor )
83 {
84 return *static_cast<COLOR4D*>( aColor );
85 }
86
87public:
88 NET_GRID_TABLE( PCB_BASE_FRAME* aFrame, wxColor aBackgroundColor );
90
91 int GetNumberRows() override
92 {
93 return m_nets.size();
94 }
95
96 int GetNumberCols() override
97 {
98 return COL_SIZE;
99 }
100
101 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind ) override;
102
103 wxString GetValue( int aRow, int aCol ) override;
104
105 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
106
107 wxString GetTypeName( int aRow, int aCol ) override;
108
109 bool GetValueAsBool( int aRow, int aCol ) override;
110
111 void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
112
114 void SetVisibilityState( int aRow, bool aVisible );
115
116 void* GetValueAsCustom( int aRow, int aCol, const wxString& aTypeName ) override;
117
118 void SetValueAsCustom( int aRow, int aCol, const wxString& aTypeName, void* aValue ) override;
119
120 const NET_GRID_ENTRY& GetEntry( int aRow ) const;
121
122 int GetRowByNetcode( int aCode ) const;
123
124 void Rebuild();
125
126 void ShowAllNets();
127
128 void HideOtherNets( const NET_GRID_ENTRY& aNet );
129
130private:
131 void updateNetVisibility( const NET_GRID_ENTRY& aNet );
132
133 void updateNetColor( const NET_GRID_ENTRY& aNet );
134
135private:
137
138 std::vector<NET_GRID_ENTRY> m_nets;
139 std::unordered_map<int, int> m_netcodeToRow;
140
141 wxGridCellAttr* m_defaultAttr;
142 wxGridCellAttr* m_labelAttr;
143};
144
145
146
148{
149public:
150
155 {
156 int id;
157 wxString label;
158 wxString tooltip;
162 bool spacer;
163
164 wxPanel* ctl_panel;
168 wxStaticText* ctl_text;
169 wxSlider* ctl_opacity;
170
171 APPEARANCE_SETTING( const wxString& aLabel, int aId,
172 const wxString& aTooltip = wxEmptyString,
173 bool aCanControlOpacity = false,
174 bool aCanControlVisibility = true ) :
175 id( aId ),
176 label( aLabel ),
177 tooltip( aTooltip ),
178 visible( true ),
179 can_control_opacity( aCanControlOpacity ),
180 can_control_visibility( aCanControlVisibility ),
181 spacer( false ),
182 ctl_panel( nullptr ),
183 ctl_indicator( nullptr ),
184 ctl_visibility( nullptr ),
185 ctl_color( nullptr ),
186 ctl_text( nullptr ),
187 ctl_opacity( nullptr )
188 {
189 }
190
192 id( -1 ),
193 visible( false ),
194 can_control_opacity( false ),
196 spacer( true ),
197 ctl_panel( nullptr ),
198 ctl_indicator( nullptr ),
199 ctl_visibility( nullptr ),
200 ctl_color( nullptr ),
201 ctl_text( nullptr ),
202 ctl_opacity( nullptr )
203 {
204 }
205 };
206
207 APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFocusOwner, bool aFpEditor = false );
209
210 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
211 // will only land us in trouble.
214
215 wxSize GetBestSize() const;
216
218 void OnBoardChanged();
219
220 void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
221 void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aItem ) override;
222 void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
223 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aItem ) override;
224 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
225 void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aItem ) override;
226 void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
227 void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
228 std::vector<BOARD_ITEM*>& aRemovedItems,
229 std::vector<BOARD_ITEM*>& aChangedItems ) override;
230
232 void OnColorThemeChanged();
233
235 void OnDarkModeToggle();
236
238 void OnLayerChanged();
239
241 void OnNetVisibilityChanged( int aNetCode, bool aVisibility );
242
244 void SetLayerVisible( int aLayer, bool isVisible );
245
246 void SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible = true );
247
249
251 std::vector<LAYER_PRESET> GetUserLayerPresets() const;
252
254 void SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList );
255
256 void ApplyLayerPreset( const wxString& aPresetName );
257
258 void ApplyLayerPreset( const LAYER_PRESET& aPreset );
259
260 wxString GetActiveLayerPreset() const
261 {
262 if( m_currentPreset )
263 return m_currentPreset->name;
264 else
265 return wxEmptyString;
266 }
267
268 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
269
271 std::vector<VIEWPORT> GetUserViewports() const;
272
274 void SetUserViewports( std::vector<VIEWPORT>& aPresetList );
275
276 void ApplyViewport( const wxString& aPresetName );
277
278 void ApplyViewport( const VIEWPORT& aPreset );
279
280 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
281
282 void OnColorSwatchChanged( wxCommandEvent& aEvent );
283
284 void OnLayerContextMenu( wxCommandEvent& aEvent );
285
287 int GetTabIndex() const;
288
290 void SetTabIndex( int aTab );
291
296
299
302
303 void CommonSettingsChanged( int aFlag );
304
305protected:
306 void OnNotebookPageChanged( wxNotebookEvent& event ) override;
307 void OnSetFocus( wxFocusEvent& aEvent ) override;
308 void OnSize( wxSizeEvent& aEvent ) override;
309 void OnNetGridClick( wxGridEvent& event ) override;
310 void OnNetGridDoubleClick( wxGridEvent& event ) override;
311 void OnNetGridRightClick( wxGridEvent& event ) override;
312 void OnNetGridMouseEvent( wxMouseEvent& aEvent );
313 void OnLanguageChanged( wxCommandEvent& aEvent );
314
315private:
316 void createControls();
317
318 void rebuildLayers();
319
321
323
324 void rebuildObjects();
325
326 void syncObjectSettings();
327
328 void buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass, const wxString& aName );
329
330 void rebuildNets();
331
333
334 void rebuildLayerPresetsWidget( bool aReset );
335
337
339
340 void onLayerLeftClick( wxMouseEvent& aEvent );
341
342 void rightClickHandler( wxMouseEvent& aEvent );
343
345
346 void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
347
348 void setVisibleLayers( const LSET& aLayers );
349
350 bool isLayerEnabled( PCB_LAYER_ID aLayer ) const;
351
352 void setVisibleObjects( GAL_SET aObjects );
353
355
357
358 void onObjectOpacitySlider( int aLayer, float aOpacity );
359
360 void updateLayerPresetSelection( const wxString& aName );
361
362 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
363
364 void doApplyLayerPreset( const LAYER_PRESET& aPreset );
365
366 void updateViewportSelection( const wxString& aName );
367
368 void onViewportChanged( wxCommandEvent& aEvent ) override;
369
370 void doApplyViewport( const VIEWPORT& aViewport );
371
372 void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
373
374 void showNetclass( const wxString& aClassName, bool aShow = true );
375
376 void onNetContextMenu( wxCommandEvent& aEvent );
377
378 void onNetclassColorChanged( wxCommandEvent& aEvent );
379
380 wxString netclassNameFromEvent( wxEvent& aEvent );
381
382 void onNetColorMode( wxCommandEvent& aEvent );
383
384 void onRatsnestMode( wxCommandEvent& aEvent );
385
386 void onNetclassContextMenu( wxCommandEvent& aEvent );
387
389
390 void passOnFocus();
391
392 void idleFocusHandler( wxIdleEvent& aEvent );
393
394 void onReadOnlySwatch();
395
396 bool doesBoardItemNeedRebuild( BOARD_ITEM* aBoardItem );
397
398 bool doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems );
399
401
402 wxWindow* m_focusOwner;
403
405
407
409
411
412 // Nets grid view
414
416
418 wxGridCellCoords m_hoveredCell;
419
420 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
421 std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
422
423 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
424 std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
425
426 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
427 std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
428
429 // TODO(JE) Move preset storage to the PCB_CONTROL tool
430
431 std::map<wxString, LAYER_PRESET> m_layerPresets;
434 wxArrayString m_presetMRU;
435
436 std::map<wxString, VIEWPORT> m_viewports;
438 wxArrayString m_viewportMRU;
439
441
443 std::map<int, wxString> m_netclassIdMap;
444
447
450
451 // The built-in layer presets
460 // a LAYER_PRESET used only to store the objects visibility of the
461 // last selected built-in LAYER_PRESET preset
463
465
467
468 // Layer display options controls
472 wxRadioButton* m_rbHighContrastDim;
473 wxRadioButton* m_rbHighContrastOff;
475 wxCheckBox* m_cbFlipBoard;
476
477 // Net display options controls
479 wxStaticText* m_txtNetDisplayTitle;
480 wxRadioButton* m_rbNetColorAll;
481 wxRadioButton* m_rbNetColorRatsnest;
482 wxRadioButton* m_rbNetColorOff;
484 wxRadioButton* m_rbRatsnestAllLayers;
485 wxRadioButton* m_rbRatsnestVisLayers;
486 wxRadioButton* m_rbRatsnestNone;
487
488 // Bitmap caches
489 wxBitmapBundle m_visibleBitmapBundle;
491
517
519};
520
521#endif
APPEARANCE_CONTROLS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
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
wxBitmapBundle m_visibleBitmapBundle
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)
Update the current layer presets from those saved in the project file.
std::vector< LAYER_PRESET > GetUserLayerPresets() const
Return a list of the layer presets created by the user.
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)
bool isLayerEnabled(PCB_LAYER_ID aLayer) const
void setVisibleLayers(const LSET &aLayers)
wxRadioButton * m_rbRatsnestAllLayers
LAYER_PRESET * m_lastSelectedUserPreset
wxString m_contextMenuNetclass
The name of the netclass that was right-clicked.
wxRadioButton * m_rbNetColorRatsnest
void rebuildLayerPresetsWidget(bool aReset)
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
Return the index of the current tab (0-2).
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)
void OnLayerChanged()
Update the widget when the active board layer is changed.
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)
wxBitmapBundle m_notVisibileBitmapBundle
void OnNetGridRightClick(wxGridEvent &event) override
void OnBoardItemsChanged(BOARD &aBoard, std::vector< BOARD_ITEM * > &aItems) override
std::vector< std::unique_ptr< APPEARANCE_SETTING > > m_netclassSettings
wxRadioButton * m_rbHighContrastOff
const wxArrayString & GetLayerPresetsMRU()
void OnBoardCompositeUpdate(BOARD &aBoard, std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aChangedItems) override
void OnBoardItemsAdded(BOARD &aBoard, std::vector< BOARD_ITEM * > &aItems) override
void OnColorThemeChanged()
Update the colors on all the widgets from the new chosen color theme.
LAYER_PRESET * m_currentPreset
std::map< wxString, APPEARANCE_SETTING * > m_netclassSettingsMap
void OnSetFocus(wxFocusEvent &aEvent) override
void OnLanguageChanged(wxCommandEvent &aEvent)
static LAYER_PRESET presetAllCopper
void SetUserViewports(std::vector< VIEWPORT > &aPresetList)
Update the current viewports from those saved in the project file.
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 OnBoardChanged()
Update the panel contents from the application and board models.
APPEARANCE_CONTROLS(const APPEARANCE_CONTROLS &)=delete
void onLayerLeftClick(wxMouseEvent &aEvent)
std::vector< VIEWPORT > GetUserViewports() const
Return a list of viewports created by the user.
void SetTabIndex(int aTab)
Set the current notebook tab.
void CommonSettingsChanged(int aFlag)
std::map< int, wxString > m_netclassIdMap
Stores wxIDs for each netclass for control event mapping.
void OnLayerContextMenu(wxCommandEvent &aEvent)
void onNetColorMode(wxCommandEvent &aEvent)
APPEARANCE_CONTROLS & operator=(const APPEARANCE_CONTROLS &)=delete
void OnNetVisibilityChanged(int aNetCode, bool aVisibility)
Notifies the panel when a net has been hidden or shown via the external tool.
void OnDarkModeToggle()
Respond to change in OS's DarkMode.
static LAYER_PRESET presetAllLayers
void onNetclassContextMenu(wxCommandEvent &aEvent)
wxStaticText * m_txtNetDisplayTitle
wxStaticLine * m_layerDisplaySeparator
APPEARANCE_CONTROLS(PCB_BASE_FRAME *aParent, wxWindow *aFocusOwner, bool aFpEditor=false)
void SetObjectVisible(GAL_LAYER_ID aLayer, bool isVisible=true)
void OnNetGridDoubleClick(wxGridEvent &event) override
void SetLayerVisible(int aLayer, bool isVisible)
Manually update visibility for a given layer.
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.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
A simple color swatch of the kind used to set layer colors.
Helper for storing and iterating over GAL_LAYER_IDs.
Definition layer_ids.h:425
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
Represent 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:101
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
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)
void SetValueAsBool(int aRow, int aCol, bool aValue) override
void * GetValueAsCustom(int aRow, int aCol, const wxString &aTypeName) override
NET_GRID_TABLE(PCB_BASE_FRAME *aFrame, wxColor aBackgroundColor)
void updateNetVisibility(const NET_GRID_ENTRY &aNet)
wxString GetValue(int aRow, int aCol) override
wxGridCellAttr * m_labelAttr
PCB_BASE_FRAME * m_frame
void SetVisibilityState(int aRow, bool aVisible)
Update cached visibility without dispatching a ratsnest action.
void HideOtherNets(const NET_GRID_ENTRY &aNet)
std::unordered_map< int, int > m_netcodeToRow
wxGridCellAttr * m_defaultAttr
bool GetValueAsBool(int aRow, int aCol) override
const NET_GRID_ENTRY & GetEntry(int aRow) const
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:224
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
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.
NET_GRID_ENTRY(int aCode, const wxString &aName, const COLOR4D &aColor, bool aVisible)
COLOR4D color
int code
wxString name
bool visible