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:
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 // 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
298protected:
299 void OnNotebookPageChanged( wxNotebookEvent& event ) override;
300 void OnSetFocus( wxFocusEvent& aEvent ) override;
301 void OnSize( wxSizeEvent& aEvent ) override;
302 void OnNetGridClick( wxGridEvent& event ) override;
303 void OnNetGridDoubleClick( wxGridEvent& event ) override;
304 void OnNetGridRightClick( wxGridEvent& event ) override;
305 void OnNetGridMouseEvent( wxMouseEvent& aEvent );
306 void OnLanguageChanged( wxCommandEvent& aEvent );
307
308private:
309 void createControls();
310
311 void rebuildLayers();
312
314
316
317 void rebuildObjects();
318
319 void syncObjectSettings();
320
321 void buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass, const wxString& aName );
322
323 void rebuildNets();
324
326
328
330
332
333 void onLayerLeftClick( wxMouseEvent& aEvent );
334
335 void rightClickHandler( wxMouseEvent& aEvent );
336
338
339 void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
340
341 void setVisibleLayers( const LSET& aLayers );
342
343 void setVisibleObjects( GAL_SET aObjects );
344
346
348
349 void onObjectOpacitySlider( int aLayer, float aOpacity );
350
351 void updateLayerPresetSelection( const wxString& aName );
352
353 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
354
355 void doApplyLayerPreset( const LAYER_PRESET& aPreset );
356
357 void updateViewportSelection( const wxString& aName );
358
359 void onViewportChanged( wxCommandEvent& aEvent ) override;
360
361 void doApplyViewport( const VIEWPORT& aViewport );
362
363 void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
364
365 void showNetclass( const wxString& aClassName, bool aShow = true );
366
367 void onNetContextMenu( wxCommandEvent& aEvent );
368
369 void onNetclassColorChanged( wxCommandEvent& aEvent );
370
371 wxString netclassNameFromEvent( wxEvent& aEvent );
372
373 void onNetColorMode( wxCommandEvent& aEvent );
374
375 void onRatsnestMode( wxCommandEvent& aEvent );
376
377 void onNetclassContextMenu( wxCommandEvent& aEvent );
378
380
381 void passOnFocus();
382
383 void idleFocusHandler( wxIdleEvent& aEvent );
384
385 void onReadOnlySwatch();
386
387 bool doesBoardItemNeedRebuild( BOARD_ITEM* aBoardItem );
388
389 bool doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems );
390
392
393 wxWindow* m_focusOwner;
394
396
398
400
402
403 // Nets grid view
405
407
409 wxGridCellCoords m_hoveredCell;
410
411 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
412 std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
413
414 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
415 std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
416
417 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
418 std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
419
420 // TODO(JE) Move preset storage to the PCB_CONTROL tool
421
422 std::map<wxString, LAYER_PRESET> m_layerPresets;
425 wxArrayString m_presetMRU;
426
427 std::map<wxString, VIEWPORT> m_viewports;
429 wxArrayString m_viewportMRU;
430
432
434 std::map<int, wxString> m_netclassIdMap;
435
438
441
442 // The built-in layer presets
451 // a LAYER_PRESET used only to store the objects visibility of the
452 // last selected built-in LAYER_PRESET preset
454
456
458
459 // Layer display options controls
463 wxRadioButton* m_rbHighContrastDim;
464 wxRadioButton* m_rbHighContrastOff;
466 wxCheckBox* m_cbFlipBoard;
467
468 // Net display options controls
470 wxStaticText* m_txtNetDisplayTitle;
471 wxRadioButton* m_rbNetColorAll;
472 wxRadioButton* m_rbNetColorRatsnest;
473 wxRadioButton* m_rbNetColorOff;
475 wxRadioButton* m_rbRatsnestAllLayers;
476 wxRadioButton* m_rbRatsnestVisLayers;
477 wxRadioButton* m_rbRatsnestNone;
478
480 {
481 ID_CHANGE_COLOR = wxID_HIGHEST,
503 };
504
506};
507
508#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)
void setVisibleLayers(const LSET &aLayers)
wxRadioButton * m_rbRatsnestAllLayers
wxBoxSizer * m_objectsOuterSizer
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 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 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
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
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.
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
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:317
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:393
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:104
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
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.
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