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-2022 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;
40class wxStaticLine;
41class wxSlider;
42class wxRadioButton;
43
44using KIGFX::COLOR4D;
45
46
48{
49 NET_GRID_ENTRY( int aCode, const wxString& aName, const COLOR4D& aColor, bool aVisible )
50 {
51 code = aCode;
52 name = aName;
53 color = aColor;
54 visible = aVisible;
55 }
56
57 int code;
58 wxString name;
60 bool visible;
61};
62
63
64class NET_GRID_TABLE : public wxGridTableBase
65{
66public:
68 {
73 };
74
75 static void* ColorToVoid( COLOR4D& aColor )
76 {
77 return static_cast<void*>( &aColor );
78 }
79
80 static COLOR4D VoidToColor( void* aColor )
81 {
82 return *static_cast<COLOR4D*>( aColor );
83 }
84
85public:
86 NET_GRID_TABLE( PCB_BASE_FRAME* aFrame, wxColor aBackgroundColor );
88
89 int GetNumberRows() override
90 {
91 return m_nets.size();
92 }
93
94 int GetNumberCols() override
95 {
96 return COL_SIZE;
97 }
98
99 wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind ) override;
100
101 wxString GetValue( int aRow, int aCol ) override;
102
103 void SetValue( int aRow, int aCol, const wxString& aValue ) override;
104
105 wxString GetTypeName( int aRow, int aCol ) override;
106
107 bool GetValueAsBool( int aRow, int aCol ) override;
108
109 void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
110
111 void* GetValueAsCustom( int aRow, int aCol, const wxString& aTypeName ) override;
112
113 void SetValueAsCustom( int aRow, int aCol, const wxString& aTypeName, void* aValue ) override;
114
115 NET_GRID_ENTRY& GetEntry( int aRow );
116
117 int GetRowByNetcode( int aCode ) const;
118
119 void Rebuild();
120
121 void ShowAllNets();
122
123 void HideOtherNets( const NET_GRID_ENTRY& aNet );
124
125private:
126 void updateNetVisibility( const NET_GRID_ENTRY& aNet );
127
128 void updateNetColor( const NET_GRID_ENTRY& aNet );
129
130private:
132
133 std::vector<NET_GRID_ENTRY> m_nets;
134
135 wxGridCellAttr* m_defaultAttr;
136 wxGridCellAttr* m_labelAttr;
137};
138
139
140
142{
143public:
144
149 {
150 int id;
151 wxString label;
152 wxString tooltip;
155 bool spacer;
156
157 wxPanel* ctl_panel;
161 wxStaticText* ctl_text;
162 wxSlider* ctl_opacity;
163
164 APPEARANCE_SETTING( const wxString& aLabel, int aId,
165 const wxString& aTooltip = wxEmptyString,
166 bool aCanControlOpacity = false ) :
167 id( aId ),
168 label( aLabel ),
169 tooltip( aTooltip ),
170 visible( true ),
171 can_control_opacity( aCanControlOpacity ),
172 spacer( false ),
173 ctl_panel( nullptr ),
174 ctl_indicator( nullptr ),
175 ctl_visibility( nullptr ),
176 ctl_color( nullptr ),
177 ctl_text( nullptr ),
178 ctl_opacity( nullptr )
179 {
180 }
181
183 id( -1 ),
184 visible( false ),
185 can_control_opacity( false ),
186 spacer( true ),
187 ctl_panel( nullptr ),
188 ctl_indicator( nullptr ),
189 ctl_visibility( nullptr ),
190 ctl_color( nullptr ),
191 ctl_text( nullptr ),
192 ctl_opacity( nullptr )
193 {
194 }
195 };
196
197 APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFocusOwner, bool aFpEditor = false );
199
200 wxSize GetBestSize() const;
201
202 void OnLanguageChanged();
203
205 void OnBoardChanged();
206
207 void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
208 void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aItem ) override;
209 void OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
210 void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aItem ) override;
211 void OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
212 void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aItem ) override;
213 void OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems ) override;
214
216 void OnColorThemeChanged();
217
219 void OnDarkModeToggle();
220
222 void OnLayerChanged();
223
225 void OnNetVisibilityChanged( int aNetCode, bool aVisibility );
226
228 void SetLayerVisible( int aLayer, bool isVisible );
229
230 void SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible = true );
231
233
235 std::vector<LAYER_PRESET> GetUserLayerPresets() const;
236
238 void SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList );
239
240 void ApplyLayerPreset( const wxString& aPresetName );
241
242 void ApplyLayerPreset( const LAYER_PRESET& aPreset );
243
244 wxString GetActiveLayerPreset() const
245 {
246 if( m_currentPreset )
247 return m_currentPreset->name;
248 else
249 return wxEmptyString;
250 }
251
252 const wxArrayString& GetLayerPresetsMRU() { return m_presetMRU; }
253
255 std::vector<VIEWPORT> GetUserViewports() const;
256
258 void SetUserViewports( std::vector<VIEWPORT>& aPresetList );
259
260 void ApplyViewport( const wxString& aPresetName );
261
262 void ApplyViewport( const VIEWPORT& aPreset );
263
264 const wxArrayString& GetViewportsMRU() { return m_viewportMRU; }
265
266 void OnColorSwatchChanged( wxCommandEvent& aEvent );
267
268 void OnLayerContextMenu( wxCommandEvent& aEvent );
269
271 int GetTabIndex() const;
272
274 void SetTabIndex( int aTab );
275
280
281protected:
282 void OnNotebookPageChanged( wxNotebookEvent& event ) override;
283 void OnSetFocus( wxFocusEvent& aEvent ) override;
284 void OnSize( wxSizeEvent& aEvent ) override;
285 void OnNetGridClick( wxGridEvent& event ) override;
286 void OnNetGridDoubleClick( wxGridEvent& event ) override;
287 void OnNetGridRightClick( wxGridEvent& event ) override;
288 void OnNetGridMouseEvent( wxMouseEvent& aEvent );
289
290private:
291 void createControls();
292
293 void rebuildLayers();
294
296
298
299 void rebuildObjects();
300
301 void syncObjectSettings();
302
303 void buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass, const wxString& aName );
304
305 void rebuildNets();
306
308
310
312
314
315 void onLayerLeftClick( wxMouseEvent& aEvent );
316
317 void rightClickHandler( wxMouseEvent& aEvent );
318
320
321 void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
322
323 void setVisibleLayers( LSET aLayers );
324
325 void setVisibleObjects( GAL_SET aObjects );
326
328
330
331 void onObjectOpacitySlider( int aLayer, float aOpacity );
332
333 void updateLayerPresetSelection( const wxString& aName );
334
335 void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
336
337 void doApplyLayerPreset( const LAYER_PRESET& aPreset );
338
339 void updateViewportSelection( const wxString& aName );
340
341 void onViewportChanged( wxCommandEvent& aEvent ) override;
342
343 void doApplyViewport( const VIEWPORT& aViewport );
344
345 void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
346
347 void showNetclass( const wxString& aClassName, bool aShow = true );
348
349 void onNetContextMenu( wxCommandEvent& aEvent );
350
351 void onNetclassColorChanged( wxCommandEvent& aEvent );
352
353 wxString netclassNameFromEvent( wxEvent& aEvent );
354
355 void onNetColorMode( wxCommandEvent& aEvent );
356
357 void onRatsnestMode( wxCommandEvent& aEvent );
358
359 void onNetclassContextMenu( wxCommandEvent& aEvent );
360
362
363 void passOnFocus();
364
365 void idleFocusHandler( wxIdleEvent& aEvent );
366
367 void onReadOnlySwatch();
368
369 bool doesBoardItemNeedRebuild( BOARD_ITEM* aBoardItem );
370
371 bool doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems );
372
374
375 wxWindow* m_focusOwner;
376
378
380
382
384
385 // Nets grid view
387
389
391 wxGridCellCoords m_hoveredCell;
392
393 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
394 std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
395
396 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
397 std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
398
399 std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
400 std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
401
402 // TODO(JE) Move preset storage to the PCB_CONTROL tool
403
404 std::map<wxString, LAYER_PRESET> m_layerPresets;
407 wxArrayString m_presetMRU;
408
409 std::map<wxString, VIEWPORT> m_viewports;
411 wxArrayString m_viewportMRU;
412
414
416 std::map<int, wxString> m_netclassIdMap;
417
420
423
424 // The built-in layer presets
433 // a LAYER_PRESET used only to store the objects visibility of the
434 // last selected built-in LAYER_PRESET preset
436
438
440
441 // Layer display options controls
445 wxRadioButton* m_rbHighContrastDim;
446 wxRadioButton* m_rbHighContrastOff;
448 wxCheckBox* m_cbFlipBoard;
449
450 // Net display options controls
452 wxStaticText* m_txtNetDisplayTitle;
453 wxRadioButton* m_rbNetColorAll;
454 wxRadioButton* m_rbNetColorRatsnest;
455 wxRadioButton* m_rbNetColorOff;
457 wxRadioButton* m_rbRatsnestAllLayers;
458 wxRadioButton* m_rbRatsnestVisLayers;
459 wxRadioButton* m_rbRatsnestNone;
460
462 {
463 ID_CHANGE_COLOR = wxID_HIGHEST,
484 };
485};
486
487#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
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
static LAYER_PRESET presetAllCopper
void SetUserViewports(std::vector< VIEWPORT > &aPresetList)
wxRadioButton * m_rbHighContrastDim
void OnSize(wxSizeEvent &aEvent) override
wxString netclassNameFromEvent(wxEvent &aEvent)
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.
void OnLanguageChanged()
Update the panel contents from the application and board models.
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:44
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:271
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:300
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:552
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:191
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