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 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:
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 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
206 // will only land us in trouble.
209
210 wxSize GetBestSize() const;
211
213 void OnBoardChanged();
214
215 void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
216 void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aItem ) override;
217 void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
218 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aItem ) override;
219 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
220 void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aItem ) override;
221 void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
222 void OnBoardCompositeUpdate( BOARD& aBoard, std::vector<BOARD_ITEM*>& aAddedItems,
223 std::vector<BOARD_ITEM*>& aRemovedItems,
224 std::vector<BOARD_ITEM*>& aChangedItems ) override;
225
227 void OnColorThemeChanged();
228
230 void OnDarkModeToggle();
231
233 void OnLayerChanged();
234
236 void OnNetVisibilityChanged( int aNetCode, bool aVisibility );
237
239 void SetLayerVisible( int aLayer, bool isVisible );
240
241 void SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible = true );
242
244
246 std::vector<LAYER_PRESET> GetUserLayerPresets() const;
247
249 void SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList );
250
251 void ApplyLayerPreset( const wxString& aPresetName );
252
253 void ApplyLayerPreset( const LAYER_PRESET& aPreset );
254
255 wxString GetActiveLayerPreset() const
256 {
257 if( m_currentPreset )
258 return m_currentPreset->name;
259 else
260 return wxEmptyString;
261 }
262
263 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
264
266 std::vector<VIEWPORT> GetUserViewports() const;
267
269 void SetUserViewports( std::vector<VIEWPORT>& aPresetList );
270
271 void ApplyViewport( const wxString& aPresetName );
272
273 void ApplyViewport( const VIEWPORT& aPreset );
274
275 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
276
277 void OnColorSwatchChanged( wxCommandEvent& aEvent );
278
279 void OnLayerContextMenu( wxCommandEvent& aEvent );
280
282 int GetTabIndex() const;
283
285 void SetTabIndex( int aTab );
286
291
294
297
298 void CommonSettingsChanged( int aFlag );
299
300protected:
301 void OnNotebookPageChanged( wxNotebookEvent& event ) override;
302 void OnSetFocus( wxFocusEvent& aEvent ) override;
303 void OnSize( wxSizeEvent& aEvent ) override;
304 void OnNetGridClick( wxGridEvent& event ) override;
305 void OnNetGridDoubleClick( wxGridEvent& event ) override;
306 void OnNetGridRightClick( wxGridEvent& event ) override;
307 void OnNetGridMouseEvent( wxMouseEvent& aEvent );
308 void OnLanguageChanged( wxCommandEvent& aEvent );
309
310private:
311 void createControls();
312
313 void rebuildLayers();
314
316
318
319 void rebuildObjects();
320
321 void syncObjectSettings();
322
323 void buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass, const wxString& aName );
324
325 void rebuildNets();
326
328
329 void rebuildLayerPresetsWidget( bool aReset );
332
334
335 void onLayerLeftClick( wxMouseEvent& aEvent );
336
337 void rightClickHandler( wxMouseEvent& aEvent );
338
340
341 void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
342
343 void setVisibleLayers( const LSET& aLayers );
344
345 bool isLayerEnabled( PCB_LAYER_ID aLayer ) const;
346
347 void setVisibleObjects( GAL_SET aObjects );
348
350
352
353 void onObjectOpacitySlider( int aLayer, float aOpacity );
354
355 void updateLayerPresetSelection( const wxString& aName );
356
357 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
358
359 void doApplyLayerPreset( const LAYER_PRESET& aPreset );
360
361 void updateViewportSelection( const wxString& aName );
362
363 void onViewportChanged( wxCommandEvent& aEvent ) override;
364
365 void doApplyViewport( const VIEWPORT& aViewport );
366
367 void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
368
369 void showNetclass( const wxString& aClassName, bool aShow = true );
370
371 void onNetContextMenu( wxCommandEvent& aEvent );
372
373 void onNetclassColorChanged( wxCommandEvent& aEvent );
374
375 wxString netclassNameFromEvent( wxEvent& aEvent );
376
377 void onNetColorMode( wxCommandEvent& aEvent );
378
379 void onRatsnestMode( wxCommandEvent& aEvent );
380
381 void onNetclassContextMenu( wxCommandEvent& aEvent );
382
384
385 void passOnFocus();
386
387 void idleFocusHandler( wxIdleEvent& aEvent );
388
389 void onReadOnlySwatch();
390
391 bool doesBoardItemNeedRebuild( BOARD_ITEM* aBoardItem );
392
393 bool doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems );
394
396
397 wxWindow* m_focusOwner;
398
400
402
404
406
407 // Nets grid view
409
411
413 wxGridCellCoords m_hoveredCell;
414
415 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
416 std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
417
418 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
419 std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
420
421 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
422 std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
423
424 // TODO(JE) Move preset storage to the PCB_CONTROL tool
425
426 std::map<wxString, LAYER_PRESET> m_layerPresets;
429 wxArrayString m_presetMRU;
430
431 std::map<wxString, VIEWPORT> m_viewports;
433 wxArrayString m_viewportMRU;
434
436
438 std::map<int, wxString> m_netclassIdMap;
439
442
445
446 // The built-in layer presets
455 // a LAYER_PRESET used only to store the objects visibility of the
456 // last selected built-in LAYER_PRESET preset
458
460
462
463 // Layer display options controls
467 wxRadioButton* m_rbHighContrastDim;
468 wxRadioButton* m_rbHighContrastOff;
470 wxCheckBox* m_cbFlipBoard;
471
472 // Net display options controls
474 wxStaticText* m_txtNetDisplayTitle;
475 wxRadioButton* m_rbNetColorAll;
476 wxRadioButton* m_rbNetColorRatsnest;
477 wxRadioButton* m_rbNetColorOff;
479 wxRadioButton* m_rbRatsnestAllLayers;
480 wxRadioButton* m_rbRatsnestVisLayers;
481 wxRadioButton* m_rbRatsnestNone;
482
483 // Bitmap caches
484 wxBitmapBundle m_visibleBitmapBundle;
486
512
514};
515
516#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)
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)
bool isLayerEnabled(PCB_LAYER_ID aLayer) const
void setVisibleLayers(const LSET &aLayers)
wxRadioButton * m_rbRatsnestAllLayers
wxSize GetBestSize() const
Update the panel contents from the application and board models.
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
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)
wxBitmapBundle m_notVisibileBitmapBundle
void OnNetGridRightClick(wxGridEvent &event) override
void OnBoardItemsChanged(BOARD &aBoard, std::vector< BOARD_ITEM * > &aItems) override
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 OnBoardCompositeUpdate(BOARD &aBoard, std::vector< BOARD_ITEM * > &aAddedItems, std::vector< BOARD_ITEM * > &aRemovedItems, std::vector< BOARD_ITEM * > &aChangedItems) override
Update the colors on all the widgets from the new chosen color theme.
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
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
APPEARANCE_CONTROLS(const APPEARANCE_CONTROLS &)=delete
void onLayerLeftClick(wxMouseEvent &aEvent)
std::vector< VIEWPORT > GetUserViewports() const
Update the current viewports from those saved in the project file.
void CommonSettingsChanged(int aFlag)
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)
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()
Update the widget when the active board layer is changed.
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)
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:323
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:405
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:105
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)
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
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 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:228
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.
NET_GRID_ENTRY(int aCode, const wxString &aName, const COLOR4D &aColor, bool aVisible)
COLOR4D color
int code
wxString name
bool visible