KiCad PCB EDA Suite
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 <jon@craftyjon.com>
5  * Copyright (C) 2020 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>
31 
32 
33 class BITMAP_TOGGLE;
34 class COLOR_SWATCH;
35 class INDICATOR_ICON;
36 class PCB_BASE_FRAME;
37 class ROW_ICON_PROVIDER;
40 class wxStaticLine;
41 
42 using KIGFX::COLOR4D;
43 
44 
46 {
47  NET_GRID_ENTRY( int aCode, const wxString& aName, const COLOR4D& aColor, bool aVisible )
48  {
49  code = aCode;
50  name = aName;
51  color = aColor;
52  visible = aVisible;
53  }
54 
55  int code;
56  wxString name;
58  bool visible;
59 };
60 
61 
62 class NET_GRID_TABLE : public wxGridTableBase
63 {
64 public:
65  enum COLUMNS
66  {
71  };
72 
73  static void* ColorToVoid( COLOR4D& aColor )
74  {
75  return static_cast<void*>( &aColor );
76  }
77 
78  static COLOR4D VoidToColor( void* aColor )
79  {
80  return *static_cast<COLOR4D*>( aColor );
81  }
82 
83 public:
84  NET_GRID_TABLE( PCB_BASE_FRAME* aFrame, wxColor aBackgroundColor );
86 
87  int GetNumberRows() override
88  {
89  return m_nets.size();
90  }
91 
92  int GetNumberCols() override
93  {
94  return COL_SIZE;
95  }
96 
97  wxGridCellAttr* GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind ) override;
98 
99  wxString GetValue( int aRow, int aCol ) override;
100 
101  void SetValue( int aRow, int aCol, const wxString& aValue ) override;
102 
103  wxString GetTypeName( int aRow, int aCol ) override;
104 
105  bool GetValueAsBool( int aRow, int aCol ) override;
106 
107  void SetValueAsBool( int aRow, int aCol, bool aValue ) override;
108 
109  void* GetValueAsCustom( int aRow, int aCol, const wxString& aTypeName ) override;
110 
111  void SetValueAsCustom( int aRow, int aCol, const wxString& aTypeName, void* aValue ) override;
112 
113  NET_GRID_ENTRY& GetEntry( int aRow );
114 
115  int GetRowByNetcode( int aCode ) const;
116 
117  void Rebuild();
118 
119  void ShowAllNets();
120 
121  void HideOtherNets( const NET_GRID_ENTRY& aNet );
122 
123 private:
124  void updateNetVisibility( const NET_GRID_ENTRY& aNet );
125 
126  void updateNetColor( const NET_GRID_ENTRY& aNet );
127 
128 private:
130 
131  std::vector<NET_GRID_ENTRY> m_nets;
132 
133  wxGridCellAttr* m_defaultAttr;
134  wxGridCellAttr* m_labelAttr;
135 };
136 
137 
138 
140 {
141 public:
142 
147  {
148  int id;
149  wxString label;
150  wxString tooltip;
151  bool visible;
153  bool spacer;
154 
155  wxPanel* ctl_panel;
159  wxStaticText* ctl_text;
160  wxSlider* ctl_opacity;
161 
162  APPEARANCE_SETTING( const wxString& aLabel, int aId,
163  const wxString& aTooltip = wxEmptyString,
164  bool aCanControlOpacity = false ) :
165  id( aId ),
166  label( aLabel ),
167  tooltip( aTooltip ),
168  visible( true ),
169  can_control_opacity( aCanControlOpacity ),
170  spacer( false ),
171  ctl_panel( nullptr ),
172  ctl_indicator( nullptr ),
173  ctl_visibility( nullptr ),
174  ctl_color( nullptr ),
175  ctl_text( nullptr ),
176  ctl_opacity( nullptr )
177  {
178  }
179 
181  id( -1 ),
182  label( "" ),
183  tooltip( "" ),
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 
203  void OnBoardChanged();
204 
205  void OnBoardNetSettingsChanged( BOARD& aBoard ) override;
206 
207  void OnBoardItemAdded( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
208 
209  void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
210 
211  void OnBoardItemChanged( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override;
212 
214  void OnColorThemeChanged();
215 
217  void OnLayerChanged();
218 
220  void SetLayerVisible( LAYER_NUM aLayer, bool isVisible );
221 
222  void SetObjectVisible( GAL_LAYER_ID aLayer, bool isVisible = true );
223 
225  void OnLayerAlphaChanged();
226 
227  void UpdateDisplayOptions();
228 
230  std::vector<LAYER_PRESET> GetUserLayerPresets() const;
231 
233  void SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList );
234 
235  void ApplyLayerPreset( const wxString& aPresetName );
236 
237  void ApplyLayerPreset( const LAYER_PRESET& aPreset );
238 
239  wxString GetActiveLayerPreset() const
240  {
241  if( m_currentPreset )
242  return m_currentPreset->name;
243  else
244  return wxEmptyString;
245  }
246 
247  const wxArrayString& GetLayerPresetsMRU()
248  {
249  return m_presetMRU;
250  }
251 
252  void OnColorSwatchChanged( wxCommandEvent& aEvent );
253 
254  void OnLayerContextMenu( wxCommandEvent& aEvent );
255 
257  int GetTabIndex() const;
258 
260  void SetTabIndex( int aTab );
261 
262 protected:
263 
264  void OnNotebookPageChanged( wxNotebookEvent& event ) override;
265 
266  void OnSetFocus( wxFocusEvent& aEvent ) override;
267 
268  void OnSize( wxSizeEvent& aEvent ) override;
269 
270  void OnNetGridClick( wxGridEvent& event ) override;
271 
272  void OnNetGridDoubleClick( wxGridEvent& event ) override;
273 
274  void OnNetGridRightClick( wxGridEvent& event ) override;
275 
276  void OnNetGridMouseEvent( wxMouseEvent& aEvent );
277 
278 private:
280 
281  wxWindow* m_focusOwner;
282 
284 
286 
288 
290 
291  // Nets grid view
293 
295 
297  wxGridCellCoords m_hoveredCell;
298 
299  std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_layerSettings;
300 
301  std::map<PCB_LAYER_ID, APPEARANCE_SETTING*> m_layerSettingsMap;
302 
303  std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_objectSettings;
304 
305  std::map<GAL_LAYER_ID, APPEARANCE_SETTING*> m_objectSettingsMap;
306 
307  std::vector<std::unique_ptr<APPEARANCE_SETTING>> m_netclassSettings;
308 
309  std::map<wxString, APPEARANCE_SETTING*> m_netclassSettingsMap;
310 
311  // TODO(JE) Move preset storage to the PCBNEW_CONTROL tool
312 
313  // Storage for all layer presets
314  std::map<wxString, LAYER_PRESET> m_layerPresets;
315 
317 
320 
321  wxArrayString m_presetMRU;
322 
324 
326  std::map<int, wxString> m_netclassIdMap;
327 
330 
331  wxBoxSizer* m_layersOuterSizer;
332  wxBoxSizer* m_objectsOuterSizer;
333 
334  // The built-in layer presets
335 
344 
346 
348 
349  // Layer display options controls
350 
353  wxRadioButton* m_rbHighContrastNormal;
354  wxRadioButton* m_rbHighContrastDim;
355  wxRadioButton* m_rbHighContrastOff;
356  wxStaticLine* m_layerDisplaySeparator;
357  wxCheckBox* m_cbFlipBoard;
358 
359  // Net display options controls
360 
362  wxStaticText* m_txtNetDisplayTitle;
363  wxRadioButton* m_rbNetColorAll;
364  wxRadioButton* m_rbNetColorRatsnest;
365  wxRadioButton* m_rbNetColorOff;
366  wxStaticText* m_txtRatsnestVisibility;
367  wxRadioButton* m_rbRatsnestAllLayers;
369 
370  enum POPUP_ID
371  {
372  ID_CHANGE_COLOR = wxID_HIGHEST,
393  };
394 
395  void createControls();
396 
397  void rebuildLayers();
398 
400 
402 
403  void rebuildObjects();
404 
405  void syncObjectSettings();
406 
407  void rebuildNets();
408 
410 
412 
414 
415  void onLayerClick( wxMouseEvent& aEvent );
416 
417  void onLayerVisibilityChanged( PCB_LAYER_ID aLayer, bool isVisible, bool isFinal );
418 
419  void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );
420 
421  void setVisibleLayers( LSET aLayers );
422 
423  void setVisibleObjects( GAL_SET aObjects );
424 
426 
428 
429  void onObjectOpacitySlider( int aLayer, float aOpacity );
430 
431  void updateLayerPresetSelection( const wxString& aName );
432 
433  void onLayerPresetChanged( wxCommandEvent& aEvent ) override;
434 
435  void doApplyLayerPreset( const LAYER_PRESET& aPreset );
436 
437  void onNetclassVisibilityChanged( wxCommandEvent& aEvent );
438 
439  void showNetclass( const wxString& aClassName, bool aShow = true );
440 
441  void onNetContextMenu( wxCommandEvent& aEvent );
442 
443  void onNetclassColorChanged( wxCommandEvent& aEvent );
444 
445  wxString netclassNameFromEvent( wxEvent& aEvent );
446 
447  void onNetColorModeChanged( wxCommandEvent& aEvent );
448 
449  void onRatsnestModeChanged( wxCommandEvent& aEvent );
450 
451  void onNetclassContextMenu( wxCommandEvent& aEvent );
452 
454 
455  void passOnFocus();
456 
457  void idleFocusHandler( wxIdleEvent& aEvent );
458 
459  void onReadOnlySwatch();
460 };
461 
462 #endif
void OnSize(wxSizeEvent &aEvent) override
static LAYER_PRESET presetFrontAssembly
A saved set of layers that are visible.
void onObjectOpacitySlider(int aLayer, float aOpacity)
std::map< PCB_LAYER_ID, APPEARANCE_SETTING * > m_layerSettingsMap
void OnNetGridMouseEvent(wxMouseEvent &aEvent)
Icon provider for the "standard" row indicators, for example in layer selection lists.
static COLOR4D VoidToColor(void *aColor)
Class APPEARANCE_CONTROLS_BASE.
void OnBoardItemRemoved(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
void * GetValueAsCustom(int aRow, int aCol, const wxString &aTypeName) override
void HideOtherNets(const NET_GRID_ENTRY &aNet)
void ApplyLayerPreset(const wxString &aPresetName)
WX_COLLAPSIBLE_PANE * m_paneLayerDisplayOptions
void SetValueAsCustom(int aRow, int aCol, const wxString &aTypeName, void *aValue) override
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
std::vector< std::unique_ptr< APPEARANCE_SETTING > > m_layerSettings
APPEARANCE_SETTING(const wxString &aLabel, int aId, const wxString &aTooltip=wxEmptyString, bool aCanControlOpacity=false)
void SetTabIndex(int aTab)
Sets the current notebook tab
LAYER_PRESET * m_lastSelectedUserPreset
The last user (non-read-only) preset selected by the user.
std::map< int, wxString > m_netclassIdMap
Stores wxIDs for each netclass for control event mapping.
void onNetColorModeChanged(wxCommandEvent &aEvent)
wxRadioButton * m_rbNetColorOff
wxStaticLine * m_layerDisplaySeparator
void idleFocusHandler(wxIdleEvent &aEvent)
wxRadioButton * m_rbRatsnestAllLayers
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
COLOR4D color
static void * ColorToVoid(COLOR4D &aColor)
NET_GRID_TABLE(PCB_BASE_FRAME *aFrame, wxColor aBackgroundColor)
wxRadioButton * m_rbHighContrastOff
wxGridCellAttr * m_defaultAttr
NET_GRID_ENTRY(int aCode, const wxString &aName, const COLOR4D &aColor, bool aVisible)
void OnNetGridClick(wxGridEvent &event) override
const wxArrayString & GetLayerPresetsMRU()
int code
void OnLayerChanged()
Updates the widget when the active board layer is changed
std::map< GAL_LAYER_ID, APPEARANCE_SETTING * > m_objectSettingsMap
A checkbox control except with custom bitmaps for the checked and unchecked states.
Definition: bitmap_toggle.h:41
bool visible
PCB_BASE_FRAME * m_frame
void OnBoardChanged()
Updates the panel contents from the application and board models
wxString name
A name for this layer set.
void onRatsnestModeChanged(wxCommandEvent &aEvent)
void showNetclass(const wxString &aClassName, bool aShow=true)
PCB_LAYER_ID
A quick note on layer IDs:
representing a row indicator icon for use in places like the layer widget
void OnBoardNetSettingsChanged(BOARD &aBoard) override
LSET is a set of PCB_LAYER_IDs.
static LAYER_PRESET presetNoLayers
void OnNetGridDoubleClick(wxGridEvent &event) override
GRID_BITMAP_TOGGLE_RENDERER * m_toggleGridRenderer
void onNetclassVisibilityChanged(wxCommandEvent &aEvent)
void OnBoardItemChanged(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
wxGridCellAttr * m_labelAttr
std::map< wxString, APPEARANCE_SETTING * > m_netclassSettingsMap
std::map< wxString, LAYER_PRESET > m_layerPresets
void OnSetFocus(wxFocusEvent &aEvent) override
ROW_ICON_PROVIDER * m_iconProvider
void setVisibleLayers(LSET aLayers)
void doApplyLayerPreset(const LAYER_PRESET &aPreset)
Helper for storing and iterating over GAL_LAYER_IDs.
LAYER_PRESET * m_currentPreset
wxRadioButton * m_rbHighContrastNormal
void onLayerClick(wxMouseEvent &aEvent)
wxStaticText * m_txtNetDisplayTitle
void onNetContextMenu(wxCommandEvent &aEvent)
wxBoxSizer * m_objectsOuterSizer
wxGridCellAttr * GetAttr(int aRow, int aCol, wxGridCellAttr::wxAttrKind) override
void SetUserLayerPresets(std::vector< LAYER_PRESET > &aPresetList)
Updates the current layer presets from those saved in the project file
int GetTabIndex() const
Returns the index of the current tab (0-2)
Container for an appearance setting (can control a single board layer, or GAL layer,...
APPEARANCE_CONTROLS(PCB_BASE_FRAME *aParent, wxWindow *aFocusOwner, bool aFpEditor=false)
std::vector< LAYER_PRESET > GetUserLayerPresets() const
Returns a list of the layer presets created by the user
void OnBoardItemAdded(BOARD &aBoard, BOARD_ITEM *aBoardItem) override
std::vector< std::unique_ptr< APPEARANCE_SETTING > > m_netclassSettings
int LAYER_NUM
This can be replaced with int and removed.
int GetNumberRows() override
void onLayerPresetChanged(wxCommandEvent &aEvent) override
wxRadioButton * m_rbHighContrastDim
NET_GRID_ENTRY & GetEntry(int aRow)
bool GetValueAsBool(int aRow, int aCol) override
int GetRowByNetcode(int aCode) const
void SetValueAsBool(int aRow, int aCol, bool aValue) override
int GetNumberCols() override
void updateLayerPresetSelection(const wxString &aName)
static LAYER_PRESET presetInnerCopper
Board layer functions and definitions.
static LAYER_PRESET presetBackAssembly
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:186
void setVisibleObjects(GAL_SET aObjects)
std::vector< std::unique_ptr< APPEARANCE_SETTING > > m_objectSettings
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
NET_GRID_TABLE * m_netsTable
wxString GetTypeName(int aRow, int aCol) override
wxString netclassNameFromEvent(wxEvent &aEvent)
wxString GetValue(int aRow, int aCol) override
Class representing a simple color swatch, of the kind used to set layer colors.
Definition: color_swatch.h:57
void SetValue(int aRow, int aCol, const wxString &aValue) override
void OnNotebookPageChanged(wxNotebookEvent &event) override
wxString GetActiveLayerPreset() const
void onObjectVisibilityChanged(GAL_LAYER_ID aLayer, bool isVisible, bool isFinal)
void onNetclassColorChanged(wxCommandEvent &aEvent)
wxString name
wxGridCellCoords m_hoveredCell
Grid cell that is being hovered over, for tooltips.
wxBoxSizer * m_layersOuterSizer
std::vector< NET_GRID_ENTRY > m_nets
void SetLayerVisible(LAYER_NUM aLayer, bool isVisible)
Manually update visibility for a given layer
wxString m_contextMenuNetclass
The name of the netclass that was right-clicked.
void onNetclassContextMenu(wxCommandEvent &aEvent)
void OnNetGridRightClick(wxGridEvent &event) override
PCB_BASE_FRAME * m_frame
void OnColorSwatchChanged(wxCommandEvent &aEvent)
void onLayerVisibilityChanged(PCB_LAYER_ID aLayer, bool isVisible, bool isFinal)
void OnLayerContextMenu(wxCommandEvent &aEvent)
static LAYER_PRESET presetFront
void OnColorThemeChanged()
Updates the colors on all the widgets from the new chosen color theme
wxStaticText * m_txtRatsnestVisibility
A better wxCollapsiblePane that.
static LAYER_PRESET presetAllCopper
void updateNetColor(const NET_GRID_ENTRY &aNet)
static const APPEARANCE_SETTING s_objectSettings[]
Template for object appearance settings.
void OnLayerAlphaChanged()
Updates the manual layer alpha overrides
static LAYER_PRESET presetAllLayers
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void updateNetVisibility(const NET_GRID_ENTRY &aNet)
wxStaticText * m_staticTextContrastModeTitle
void SetObjectVisible(GAL_LAYER_ID aLayer, bool isVisible=true)
WX_COLLAPSIBLE_PANE * m_paneNetDisplayOptions
wxRadioButton * m_rbRatsnestVisibleLayers
static LAYER_PRESET presetBack
wxRadioButton * m_rbNetColorRatsnest
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100
wxRadioButton * m_rbNetColorAll