KiCad PCB EDA Suite
Loading...
Searching...
No Matches
appearance_controls.cpp
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
22
23#include <bitmaps.h>
24#include <board.h>
27#include <pad.h>
28#include <pcb_track.h>
29#include <eda_list_dialog.h>
30#include <string_utils.h>
32#include <confirm.h>
33#include <pcb_display_options.h>
34#include <pcb_edit_frame.h>
35#include <pcb_painter.h>
36#include <pcbnew_settings.h>
39#include <project.h>
43#include <tool/tool_manager.h>
44#include <tools/pcb_actions.h>
53#include <widgets/wx_infobar.h>
54#include <widgets/wx_grid.h>
56#include <wx/checkbox.h>
57#include <wx/hyperlink.h>
58#include <wx/msgdlg.h>
59#include <wx/radiobut.h>
60#include <wx/sizer.h>
61#include <wx/slider.h>
62#include <wx/statline.h>
63#include <wx/textdlg.h>
64#include <wx/bmpbuttn.h> // needed on wxMSW for OnSetFocus()
65#include <core/profile.h>
66#include <pgm_base.h>
67
68
69NET_GRID_TABLE::NET_GRID_TABLE( PCB_BASE_FRAME* aFrame, wxColor aBackgroundColor ) :
70 wxGridTableBase(),
71 m_frame( aFrame )
72{
73 m_defaultAttr = new wxGridCellAttr;
74 m_defaultAttr->SetBackgroundColour( aBackgroundColor );
75
76 m_labelAttr = new wxGridCellAttr;
78 m_labelAttr->SetBackgroundColour( aBackgroundColor );
79}
80
81
83{
84 m_defaultAttr->DecRef();
85 m_labelAttr->DecRef();
86}
87
88
89wxGridCellAttr* NET_GRID_TABLE::GetAttr( int aRow, int aCol, wxGridCellAttr::wxAttrKind )
90{
91 wxGridCellAttr* attr = nullptr;
92
93 switch( aCol )
94 {
95 case COL_COLOR: attr = m_defaultAttr; break;
96 case COL_VISIBILITY: attr = m_defaultAttr; break;
97 case COL_LABEL: attr = m_labelAttr; break;
98 default: wxFAIL;
99 }
100
101 if( attr )
102 attr->IncRef();
103
104 return attr;
105}
106
107
108wxString NET_GRID_TABLE::GetValue( int aRow, int aCol )
109{
110 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
111
112 switch( aCol )
113 {
114 case COL_COLOR: return m_nets[aRow].color.ToCSSString();
115 case COL_VISIBILITY: return m_nets[aRow].visible ? wxT( "1" ) : wxT( "0" );
116 case COL_LABEL: return m_nets[aRow].name;
117 default: return wxEmptyString;
118 }
119}
120
121
122void NET_GRID_TABLE::SetValue( int aRow, int aCol, const wxString& aValue )
123{
124 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
125
126 NET_GRID_ENTRY& net = m_nets[aRow];
127
128 switch( aCol )
129 {
130 case COL_COLOR:
131 net.color.SetFromWxString( aValue );
132 updateNetColor( net );
133 break;
134
135 case COL_VISIBILITY:
136 net.visible = ( aValue != wxT( "0" ) );
137 updateNetVisibility( net );
138 break;
139
140 case COL_LABEL:
141 net.name = aValue;
142 break;
143
144 default:
145 break;
146 }
147}
148
149
150wxString NET_GRID_TABLE::GetTypeName( int aRow, int aCol )
151{
152 switch( aCol )
153 {
154 case COL_COLOR: return wxT( "COLOR4D" );
155 case COL_VISIBILITY: return wxGRID_VALUE_BOOL;
156 case COL_LABEL: return wxGRID_VALUE_STRING;
157 default: return wxGRID_VALUE_STRING;
158 }
159}
160
161
162bool NET_GRID_TABLE::GetValueAsBool( int aRow, int aCol )
163{
164 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
165 wxASSERT( aCol == COL_VISIBILITY );
166
167 return m_nets[aRow].visible;
168}
169
170
171void NET_GRID_TABLE::SetValueAsBool( int aRow, int aCol, bool aValue )
172{
173 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
174 wxASSERT( aCol == COL_VISIBILITY );
175
176 SetVisibilityState( aRow, aValue );
178}
179
180
181void NET_GRID_TABLE::SetVisibilityState( int aRow, bool aVisible )
182{
183 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
184
185 m_nets[aRow].visible = aVisible;
186}
187
188
189void* NET_GRID_TABLE::GetValueAsCustom( int aRow, int aCol, const wxString& aTypeName )
190{
191 wxASSERT( aCol == COL_COLOR );
192 wxASSERT( aTypeName == wxT( "COLOR4D" ) );
193 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
194
195 return ColorToVoid( m_nets[aRow].color );
196}
197
198
199void NET_GRID_TABLE::SetValueAsCustom( int aRow, int aCol, const wxString& aTypeName, void* aValue )
200{
201 wxASSERT( aCol == COL_COLOR );
202 wxASSERT( aTypeName == wxT( "COLOR4D" ) );
203 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
204
205 m_nets[aRow].color = VoidToColor( aValue );
206 updateNetColor( m_nets[aRow] );
207}
208
209
211{
212 wxASSERT( static_cast<size_t>( aRow ) < m_nets.size() );
213 return m_nets[aRow];
214}
215
216
218{
219 auto it = m_netcodeToRow.find( aCode );
220 return it != m_netcodeToRow.end() ? it->second : -1;
221}
222
223
225{
226 BOARD* board = m_frame->GetBoard();
227
228 if( !board )
229 return;
230
231 const NETNAMES_MAP& nets = board->GetNetInfo().NetsByName();
232 KIGFX::RENDER_SETTINGS* renderSettings = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
233 KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( renderSettings );
234
235 std::set<int>& hiddenNets = rs->GetHiddenNets();
236 std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
237
238 int deleted = (int) m_nets.size();
239 m_nets.clear();
240 m_netcodeToRow.clear();
241
242 if( GetView() )
243 {
244 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_DELETED, 0, deleted );
245 GetView()->ProcessTableMessage( msg );
246 }
247
248 for( const std::pair<const wxString, NETINFO_ITEM*>& pair : nets )
249 {
250 int netCode = pair.second->GetNetCode();
251
252 if( netCode > 0 && !pair.first.StartsWith( wxT( "unconnected-(" ) ) )
253 {
254 COLOR4D color = netColors.count( netCode ) ? netColors.at( netCode )
256
257 bool visible = hiddenNets.count( netCode ) == 0;
258
259 m_nets.emplace_back( NET_GRID_ENTRY( netCode, pair.first, color, visible ) );
260 }
261 }
262
263 // TODO(JE) move to ::Compare so we can re-sort easily
264 std::sort( m_nets.begin(), m_nets.end(),
265 []( const NET_GRID_ENTRY& a, const NET_GRID_ENTRY& b )
266 {
267 return a.name < b.name;
268 } );
269
270 m_netcodeToRow.reserve( m_nets.size() );
271
272 for( size_t row = 0; row < m_nets.size(); ++row )
273 {
274 m_netcodeToRow.emplace( m_nets[row].code, static_cast<int>( row ) );
275 }
276
277 if( GetView() )
278 {
279 wxGridTableMessage msg( this, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, (int) m_nets.size() );
280 GetView()->ProcessTableMessage( msg );
281 }
282}
283
284
286{
287 for( NET_GRID_ENTRY& net : m_nets )
288 {
289 net.visible = true;
290 updateNetVisibility( net );
291 }
292
293 if( GetView() )
294 GetView()->ForceRefresh();
295}
296
297
299{
300 for( NET_GRID_ENTRY& net : m_nets )
301 {
302 net.visible = ( net.code == aNet.code );
303 updateNetVisibility( net );
304 }
305
306 if( GetView() )
307 GetView()->ForceRefresh();
308}
309
310
312{
315
316 m_frame->GetToolManager()->RunAction( action, aNet.code );
317}
318
319
321{
322 KIGFX::RENDER_SETTINGS* rs = m_frame->GetCanvas()->GetView()->GetPainter()->GetSettings();
323 KIGFX::PCB_RENDER_SETTINGS* renderSettings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( rs );
324
325 std::map<int, KIGFX::COLOR4D>& netColors = renderSettings->GetNetColorMap();
326
327 if( aNet.color != COLOR4D::UNSPECIFIED )
328 netColors[aNet.code] = aNet.color;
329 else
330 netColors.erase( aNet.code );
331
332 m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
333 m_frame->GetCanvas()->RedrawRatsnest();
334 m_frame->GetCanvas()->Refresh();
335}
336
337
340
341#define RR APPEARANCE_CONTROLS::APPEARANCE_SETTING // Render Row abbreviation to reduce source width
342
343 // clang-format off
344
345 // text id tooltip opacity slider visibility checkbox
346 RR( _HKI( "Tracks" ), LAYER_TRACKS, _HKI( "Show tracks" ), true ),
347 RR( _HKI( "Vias" ), LAYER_VIAS, _HKI( "Show all vias" ), true ),
348 RR( _HKI( "Pads" ), LAYER_PADS, _HKI( "Show all pads" ), true ),
349 RR( _HKI( "Zones" ), LAYER_ZONES, _HKI( "Show copper zones" ), true ),
350 RR( _HKI( "Filled Shapes" ), LAYER_FILLED_SHAPES, _HKI( "Opacity of filled shapes" ), true, false ),
351 RR( _HKI( "Images" ), LAYER_DRAW_BITMAPS, _HKI( "Show user images" ), true ),
352 RR( _HKI( "Outside Group" ), LAYER_OUTSIDE_GROUP_OPACITY, _HKI( "Opacity of items outside the entered group" ), true, false ),
353 RR(),
354 RR( _HKI( "Footprints Front" ), LAYER_FOOTPRINTS_FR, _HKI( "Show footprints that are on board's front" ) ),
355 RR( _HKI( "Footprints Back" ), LAYER_FOOTPRINTS_BK, _HKI( "Show footprints that are on board's back" ) ),
356 RR( _HKI( "Values" ), LAYER_FP_VALUES, _HKI( "Show footprint values" ) ),
357 RR( _HKI( "References" ), LAYER_FP_REFERENCES, _HKI( "Show footprint references" ) ),
358 RR( _HKI( "Footprint Text" ), LAYER_FP_TEXT, _HKI( "Show all footprint text" ) ),
359 RR(),
360 RR(),
361 RR( _HKI( "Ratsnest" ), LAYER_RATSNEST, _HKI( "Show unconnected nets as a ratsnest") ),
362 RR( _HKI( "DRC Warnings" ), LAYER_DRC_WARNING, _HKI( "DRC violations with a Warning severity" ) ),
363 RR( _HKI( "DRC Errors" ), LAYER_DRC_ERROR, _HKI( "DRC violations with an Error severity" ) ),
364 RR( _HKI( "DRC Exclusions" ), LAYER_DRC_EXCLUSION, _HKI( "DRC violations which have been individually excluded" ) ),
365 RR( _HKI( "Anchors" ), LAYER_ANCHOR, _HKI( "Show footprint and text origins as a cross" ) ),
366 RR( _HKI( "Points" ), LAYER_POINTS, _HKI( "Show explicit snap points as crosses" ) ),
367 RR( _HKI( "Grids" ), LAYER_SUBGRIDS, _HKI( "Show custom routing/placement grids" ) ),
368 RR( _HKI( "Via Stitching" ), LAYER_VIA_STITCHING, _HKI( "Show via stitching generator outlines" ) ),
369 RR( _HKI( "Locked Item Shadow" ), LAYER_LOCKED_ITEM_SHADOW, _HKI( "Show a shadow on locked items" ) ),
370 RR( _HKI( "Colliding Courtyards" ), LAYER_CONFLICTS_SHADOW, _HKI( "Show colliding footprint courtyards" ) ),
371 RR( _HKI( "Constrained Item Shadow" ), LAYER_CONSTRAINT_SHADOW, _HKI( "Show a shadow on constrained items" ) ),
372 RR( _HKI( "Board Area Shadow" ), LAYER_BOARD_OUTLINE_AREA, _HKI( "Show board area shadow" ) ),
373 RR( _HKI( "Drawing Sheet" ), LAYER_DRAWINGSHEET, _HKI( "Show drawing sheet borders and title block" ) ),
374 RR( _HKI( "Grid" ), LAYER_GRID, _HKI( "Show the (x,y) grid dots" ) )
375 // clang-format on
376};
377
395
396// These are the built-in layer presets that cannot be deleted
397
399
401 LSET::AllLayersMask(), false );
402
404 LSET( LSET::AllCuMask() ).set( Edge_Cuts ), false );
405
407 LSET( LSET::InternalCuMask() ).set( Edge_Cuts ), false );
408
410 LSET( LSET::FrontMask() ).set( Edge_Cuts ), false );
411
414
416 LSET( LSET::BackMask() ).set( Edge_Cuts ), true );
417
420
421// this one is only used to store the object visibility settings of the last used
422// built-in layer preset
424
425
426APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFocusOwner, bool aFpEditorMode ) :
427 APPEARANCE_CONTROLS_BASE( aParent ),
428 m_frame( aParent ),
429 m_focusOwner( aFocusOwner ),
430 m_board( nullptr ),
431 m_isFpEditor( aFpEditorMode ),
432 m_currentPreset( nullptr ),
433 m_lastSelectedUserPreset( nullptr ),
434 m_layerContextMenu( nullptr ),
436{
437 // Correct the min size from wxformbuilder not using fromdip
438 SetMinSize( FromDIP( GetMinSize() ) );
439
440 // We pregenerate the visibility bundles to reuse to reduce gdi exhaustion on windows
441 // We can get a crazy amount of nets and netclasses
444
445 int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
447 m_pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
448 m_layerPanelColour = m_panelLayers->GetBackgroundColour().ChangeLightness( 110 );
449 SetBorders( true, false, false, false );
450
451 m_layersOuterSizer = new wxBoxSizer( wxVERTICAL );
453 m_windowLayers->SetScrollRate( 0, 5 );
454 m_windowLayers->Bind( wxEVT_SET_FOCUS, &APPEARANCE_CONTROLS::OnSetFocus, this );
455
456 m_objectsOuterSizer = new wxBoxSizer( wxVERTICAL );
458 m_windowObjects->SetScrollRate( 0, 5 );
459 m_windowObjects->Bind( wxEVT_SET_FOCUS, &APPEARANCE_CONTROLS::OnSetFocus, this );
460
461 wxFont infoFont = KIUI::GetInfoFont( this );
462 m_staticTextNets->SetFont( infoFont );
463 m_staticTextNetClasses->SetFont( infoFont );
464 m_panelLayers->SetFont( infoFont );
465 m_windowLayers->SetFont( infoFont );
466 m_windowObjects->SetFont( infoFont );
467 m_presetsLabel->SetFont( infoFont );
468 m_viewportsLabel->SetFont( infoFont );
469
470 m_cbLayerPresets->SetToolTip( wxString::Format( _( "Save and restore layer visibility combinations.\n"
471 "Use %s+Tab to activate selector.\n"
472 "Successive Tabs while holding %s down will "
473 "cycle through presets in the popup." ),
476
477 m_cbViewports->SetToolTip( wxString::Format( _( "Save and restore view location and zoom.\n"
478 "Use %s+Tab to activate selector.\n"
479 "Successive Tabs while holding %s down will "
480 "cycle through viewports in the popup." ),
483
485
487 m_btnNetInspector->SetPadding( 2 );
488
490 m_btnConfigureNetClasses->SetPadding( 2 );
491
492 m_txtNetFilter->SetHint( _( "Filter nets" ) );
493
494 if( screenHeight <= 900 && m_pointSize >= FromDIP( KIUI::c_IndicatorSizeDIP ) )
495 m_pointSize = m_pointSize * 8 / 10;
496
497 wxFont font = m_notebook->GetFont();
498
499#ifdef __WXMAC__
500 font.SetPointSize( m_pointSize );
501 m_notebook->SetFont( font );
502#endif
503
504 auto setHighContrastMode =
505 [&]( HIGH_CONTRAST_MODE aMode )
506 {
507 PCB_DISPLAY_OPTIONS opts = m_frame->GetDisplayOptions();
508 opts.m_ContrastModeDisplay = aMode;
509
510 m_frame->SetDisplayOptions( opts );
511 passOnFocus();
512 };
513
514 m_rbHighContrastNormal->Bind( wxEVT_RADIOBUTTON,
515 [=]( wxCommandEvent& aEvent )
516 {
517 setHighContrastMode( HIGH_CONTRAST_MODE::NORMAL );
518 } );
519
520 m_rbHighContrastDim->Bind( wxEVT_RADIOBUTTON,
521 [=]( wxCommandEvent& aEvent )
522 {
523 setHighContrastMode( HIGH_CONTRAST_MODE::DIMMED );
524 } );
525
526 m_rbHighContrastOff->Bind( wxEVT_RADIOBUTTON,
527 [=]( wxCommandEvent& aEvent )
528 {
529 setHighContrastMode( HIGH_CONTRAST_MODE::HIDDEN );
530 } );
531
533
534 m_btnNetInspector->Bind( wxEVT_BUTTON,
535 [&]( wxCommandEvent& aEvent )
536 {
537 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::showNetInspector );
538 } );
539
540 m_btnConfigureNetClasses->Bind( wxEVT_BUTTON,
541 [&]( wxCommandEvent& aEvent )
542 {
543 // This panel should only be visible in the PCB_EDIT_FRAME anyway
544 if( PCB_EDIT_FRAME* editframe = dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
545 editframe->ShowBoardSetupDialog( _( "Net Classes" ) );
546
547 passOnFocus();
548 } );
549
550 m_cbFlipBoard->SetValue( m_frame->GetDisplayOptions().m_FlipBoardView );
551 m_cbFlipBoard->Bind( wxEVT_CHECKBOX,
552 [&]( wxCommandEvent& aEvent )
553 {
554 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::flipBoard );
556 } );
557
560
561 m_netsGrid->RegisterDataType( wxT( "bool" ), m_toggleGridRenderer, new wxGridCellBoolEditor );
562
563 m_netsGrid->RegisterDataType( wxT( "COLOR4D" ),
566
567 m_netsTable = new NET_GRID_TABLE( m_frame, m_panelNets->GetBackgroundColour() );
568 m_netsGrid->SetTable( m_netsTable, true );
569 m_netsGrid->SetColLabelSize( 0 );
570
571 m_netsGrid->SetSelectionMode( wxGrid::wxGridSelectRows );
572 m_netsGrid->SetSelectionForeground( m_netsGrid->GetDefaultCellTextColour() );
573 m_netsGrid->SetSelectionBackground( m_panelNets->GetBackgroundColour() );
574
575 const int cellPadding = 6;
576#ifdef __WXMAC__
577 const int rowHeightPadding = 5;
578#else
579 const int rowHeightPadding = 3;
580#endif
581
582 wxSize size = ConvertDialogToPixels( SWATCH_SIZE_SMALL_DU );
583 m_netsGrid->SetColSize( NET_GRID_TABLE::COL_COLOR, size.x + cellPadding );
584
585 size = m_visibleBitmapBundle.GetPreferredBitmapSizeFor( this );
586 m_netsGrid->SetColSize( NET_GRID_TABLE::COL_VISIBILITY, size.x + cellPadding );
587
588 m_netsGrid->SetDefaultCellFont( font );
589 m_netsGrid->SetDefaultRowSize( font.GetPixelSize().y + rowHeightPadding );
590
591 m_netsGrid->GetGridWindow()->Bind( wxEVT_MOTION, &APPEARANCE_CONTROLS::OnNetGridMouseEvent, this );
592
593 // To handle middle click on color swatches
594 m_netsGrid->GetGridWindow()->Bind( wxEVT_MIDDLE_UP, &APPEARANCE_CONTROLS::OnNetGridMouseEvent, this );
595
596 m_netsGrid->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT );
597 m_netclassScrolledWindow->ShowScrollbars( wxSHOW_SB_NEVER, wxSHOW_SB_DEFAULT );
598
599 if( m_isFpEditor )
600 m_notebook->RemovePage( 2 );
601
602 if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
603 {
604 if( cfg->m_AuiPanels.appearance_expand_layer_display )
606
607 if( cfg->m_AuiPanels.appearance_expand_net_display )
608 m_paneNetDisplayOptions->Expand();
609 }
610
615
616 // Grid visibility is loaded and set to the GAL before we are constructed
617 SetObjectVisible( LAYER_GRID, m_frame->IsGridVisible() );
618
619 Bind( wxEVT_COMMAND_MENU_SELECTED, &APPEARANCE_CONTROLS::OnLayerContextMenu, this,
621
622 m_frame->Bind( EDA_LANG_CHANGED, &APPEARANCE_CONTROLS::OnLanguageChanged, this );
623}
624
625
627{
628 m_frame->Unbind( EDA_LANG_CHANGED, &APPEARANCE_CONTROLS::OnLanguageChanged, this );
629
630 delete m_iconProvider;
631}
632
633
635{
636 int hotkey;
637 wxString msg;
638 wxFont infoFont = KIUI::GetInfoFont( this );
639
640 // Create layer display options
641 m_paneLayerDisplayOptions = new WX_COLLAPSIBLE_PANE( m_panelLayers, wxID_ANY, _( "Layer Display Options" ) );
642 m_paneLayerDisplayOptions->Collapse();
643 m_paneLayerDisplayOptions->SetBackgroundColour( m_notebook->GetThemeBackgroundColour() );
644
645 wxWindow* layerDisplayPane = m_paneLayerDisplayOptions->GetPane();
646
647 wxBoxSizer* layerDisplayOptionsSizer;
648 layerDisplayOptionsSizer = new wxBoxSizer( wxVERTICAL );
649
650 hotkey = PCB_ACTIONS::highContrastModeCycle.GetHotKey();
651
652 if( hotkey )
653 msg = wxString::Format( _( "Inactive layers (%s):" ), KeyNameFromKeyCode( hotkey ) );
654 else
655 msg = _( "Inactive layers:" );
656
657 m_inactiveLayersLabel = new wxStaticText( layerDisplayPane, wxID_ANY, msg );
658 m_inactiveLayersLabel->SetFont( infoFont );
659 m_inactiveLayersLabel->Wrap( -1 );
660 layerDisplayOptionsSizer->Add( m_inactiveLayersLabel, 0, wxEXPAND | wxBOTTOM, 2 );
661
662 wxBoxSizer* contrastModeSizer;
663 contrastModeSizer = new wxBoxSizer( wxHORIZONTAL );
664
665 m_rbHighContrastNormal = new wxRadioButton( layerDisplayPane, wxID_ANY, _( "Normal" ),
666 wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
667 m_rbHighContrastNormal->SetFont( infoFont );
668 m_rbHighContrastNormal->SetValue( true );
669 m_rbHighContrastNormal->SetToolTip( _( "Inactive layers will be shown in full color" ) );
670
671 contrastModeSizer->Add( m_rbHighContrastNormal, 0, wxRIGHT, 5 );
672 contrastModeSizer->AddStretchSpacer();
673
674 m_rbHighContrastDim = new wxRadioButton( layerDisplayPane, wxID_ANY, _( "Dim" ) );
675 m_rbHighContrastDim->SetFont( infoFont );
676 m_rbHighContrastDim->SetToolTip( _( "Inactive layers will be dimmed" ) );
677
678 contrastModeSizer->Add( m_rbHighContrastDim, 0, wxRIGHT, 5 );
679 contrastModeSizer->AddStretchSpacer();
680
681 m_rbHighContrastOff = new wxRadioButton( layerDisplayPane, wxID_ANY, _( "Hide" ) );
682 m_rbHighContrastOff->SetFont( infoFont );
683 m_rbHighContrastOff->SetToolTip( _( "Inactive layers will be hidden" ) );
684
685 contrastModeSizer->Add( m_rbHighContrastOff, 0, 0, 5 );
686 contrastModeSizer->AddStretchSpacer();
687
688 layerDisplayOptionsSizer->Add( contrastModeSizer, 0, wxEXPAND, 5 );
689
690 m_layerDisplaySeparator = new wxStaticLine( layerDisplayPane, wxID_ANY, wxDefaultPosition,
691 wxDefaultSize, wxLI_HORIZONTAL );
692 layerDisplayOptionsSizer->Add( m_layerDisplaySeparator, 0, wxEXPAND | wxTOP, 4 );
693
694 m_cbFlipBoard = new wxCheckBox( layerDisplayPane, wxID_ANY, _( "Flip board view" ) );
695 m_cbFlipBoard->SetFont( infoFont );
696 layerDisplayOptionsSizer->Add( m_cbFlipBoard, 0, wxTOP | wxBOTTOM, 3 );
697
698 layerDisplayPane->SetSizer( layerDisplayOptionsSizer );
699 layerDisplayPane->Layout();
700 layerDisplayOptionsSizer->Fit( layerDisplayPane );
701
702 m_panelLayersSizer->Add( m_paneLayerDisplayOptions, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 3 );
703
705 [&]( wxCommandEvent& aEvent )
706 {
707 Freeze();
708 m_panelLayers->Fit();
709 m_sizerOuter->Layout();
710 Thaw();
711 } );
712
713 // Create net display options
714
715 m_paneNetDisplayOptions = new WX_COLLAPSIBLE_PANE( m_panelNetsAndClasses, wxID_ANY, _( "Net Display Options" ) );
716 m_paneNetDisplayOptions->Collapse();
717 m_paneNetDisplayOptions->SetBackgroundColour( m_notebook->GetThemeBackgroundColour() );
718
719 wxWindow* netDisplayPane = m_paneNetDisplayOptions->GetPane();
720 wxBoxSizer* netDisplayOptionsSizer = new wxBoxSizer( wxVERTICAL );
721
723
724 hotkey = PCB_ACTIONS::netColorModeCycle.GetHotKey();
725
726 if( hotkey )
727 msg = wxString::Format( _( "Net colors (%s):" ), KeyNameFromKeyCode( hotkey ) );
728 else
729 msg = _( "Net colors:" );
730
731 m_txtNetDisplayTitle = new wxStaticText( netDisplayPane, wxID_ANY, msg );
732 m_txtNetDisplayTitle->SetFont( infoFont );
733 m_txtNetDisplayTitle->Wrap( -1 );
734 m_txtNetDisplayTitle->SetToolTip( _( "Choose when to show net and netclass colors" ) );
735
736 netDisplayOptionsSizer->Add( m_txtNetDisplayTitle, 0, wxEXPAND | wxBOTTOM | wxLEFT, 2 );
737
738 wxBoxSizer* netColorSizer = new wxBoxSizer( wxHORIZONTAL );
739
740 m_rbNetColorAll = new wxRadioButton( netDisplayPane, wxID_ANY, _( "All" ), wxDefaultPosition,
741 wxDefaultSize, wxRB_GROUP );
742 m_rbNetColorAll->SetFont( infoFont );
743 m_rbNetColorAll->SetToolTip( _( "Net and netclass colors are shown on all copper items" ) );
744
745 netColorSizer->Add( m_rbNetColorAll, 0, wxRIGHT, 5 );
746 netColorSizer->AddStretchSpacer();
747
748 m_rbNetColorRatsnest = new wxRadioButton( netDisplayPane, wxID_ANY, _( "Ratsnest" ) );
749 m_rbNetColorRatsnest->SetFont( infoFont );
750 m_rbNetColorRatsnest->SetValue( true );
751 m_rbNetColorRatsnest->SetToolTip( _( "Net and netclass colors are shown on the ratsnest only" ) );
752
753 netColorSizer->Add( m_rbNetColorRatsnest, 0, wxRIGHT, 5 );
754 netColorSizer->AddStretchSpacer();
755
756 m_rbNetColorOff = new wxRadioButton( netDisplayPane, wxID_ANY, _( "None" ) );
757 m_rbNetColorOff->SetFont( infoFont );
758 m_rbNetColorOff->SetToolTip( _( "Net and netclass colors are not shown" ) );
759
760 netColorSizer->Add( m_rbNetColorOff, 0, 0, 5 );
761
762 netDisplayOptionsSizer->Add( netColorSizer, 0, wxEXPAND | wxBOTTOM, 5 );
763
765
766 hotkey = PCB_ACTIONS::ratsnestModeCycle.GetHotKey();
767
768 if( hotkey )
769 msg = wxString::Format( _( "Ratsnest display (%s):" ), KeyNameFromKeyCode( hotkey ) );
770 else
771 msg = _( "Ratsnest display:" );
772
773 m_txtRatsnestVisibility = new wxStaticText( netDisplayPane, wxID_ANY, msg );
774 m_txtRatsnestVisibility->SetFont( infoFont );
775 m_txtRatsnestVisibility->Wrap( -1 );
776 m_txtRatsnestVisibility->SetToolTip( _( "Choose which ratsnest lines to display" ) );
777
778 netDisplayOptionsSizer->Add( m_txtRatsnestVisibility, 0, wxEXPAND | wxBOTTOM | wxLEFT, 2 );
779
780 wxBoxSizer* ratsnestDisplayModeSizer = new wxBoxSizer( wxHORIZONTAL );
781
782 m_rbRatsnestAllLayers = new wxRadioButton( netDisplayPane, wxID_ANY, _( "All" ),
783 wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
784 m_rbRatsnestAllLayers->SetFont( infoFont );
785 m_rbRatsnestAllLayers->SetValue( true );
786 m_rbRatsnestAllLayers->SetToolTip( _( "Show ratsnest lines to items on all layers" ) );
787
788 ratsnestDisplayModeSizer->Add( m_rbRatsnestAllLayers, 0, wxRIGHT, 5 );
789 ratsnestDisplayModeSizer->AddStretchSpacer();
790
791 m_rbRatsnestVisLayers = new wxRadioButton( netDisplayPane, wxID_ANY, _( "Visible layers" ) );
792 m_rbRatsnestVisLayers->SetFont( infoFont );
793 m_rbRatsnestVisLayers->SetToolTip( _( "Show ratsnest lines to items on visible layers" ) );
794
795 ratsnestDisplayModeSizer->Add( m_rbRatsnestVisLayers, 0, wxRIGHT, 5 );
796 ratsnestDisplayModeSizer->AddStretchSpacer();
797
798 m_rbRatsnestNone = new wxRadioButton( netDisplayPane, wxID_ANY, _( "None" ) );
799 m_rbRatsnestNone->SetFont( infoFont );
800 m_rbRatsnestNone->SetToolTip( _( "Hide all ratsnest lines" ) );
801
802 ratsnestDisplayModeSizer->Add( m_rbRatsnestNone, 0, 0, 5 );
803
804 netDisplayOptionsSizer->Add( ratsnestDisplayModeSizer, 0, wxEXPAND | wxBOTTOM, 5 );
805
807
808 netDisplayPane->SetSizer( netDisplayOptionsSizer );
809 netDisplayPane->Layout();
810 netDisplayOptionsSizer->Fit( netDisplayPane );
811
812 m_netsTabOuterSizer->Add( m_paneNetDisplayOptions, 0, wxEXPAND | wxTOP, 5 );
813
815 [&]( wxCommandEvent& aEvent )
816 {
817 Freeze();
819 m_sizerOuter->Layout();
820 passOnFocus();
821 Thaw();
822 } );
823
824 m_rbNetColorAll->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onNetColorMode, this );
825 m_rbNetColorOff->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onNetColorMode, this );
826 m_rbNetColorRatsnest->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onNetColorMode, this );
827
828 m_rbRatsnestAllLayers->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onRatsnestMode, this );
829 m_rbRatsnestVisLayers->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onRatsnestMode, this );
830 m_rbRatsnestNone->Bind( wxEVT_RADIOBUTTON, &APPEARANCE_CONTROLS::onRatsnestMode, this );
831}
832
833
835{
836 DPI_SCALING_COMMON dpi( nullptr, m_frame );
837 wxSize size( 220 * dpi.GetScaleFactor(), 480 * dpi.GetScaleFactor() );
838 return size;
839}
840
841
846
847
852
853
854void APPEARANCE_CONTROLS::OnNotebookPageChanged( wxNotebookEvent& aEvent )
855{
856 // Work around wxMac issue where the notebook pages are blank
857#ifdef __WXMAC__
858 int page = aEvent.GetSelection();
859
860 if( page >= 0 )
861 m_notebook->ChangeSelection( static_cast<unsigned>( page ) );
862#endif
863
864#ifndef __WXMSW__
865 // Because wxWidgets is broken and will send click events to children of the collapsible
866 // panes even if they are collapsed without this
867 Freeze();
868 m_panelLayers->Fit();
870 m_sizerOuter->Layout();
871 Thaw();
872#endif
873
874 Bind( wxEVT_IDLE, &APPEARANCE_CONTROLS::idleFocusHandler, this );
875}
876
877
878void APPEARANCE_CONTROLS::idleFocusHandler( wxIdleEvent& aEvent )
879{
880 passOnFocus();
881 Unbind( wxEVT_IDLE, &APPEARANCE_CONTROLS::idleFocusHandler, this );
882}
883
884
885void APPEARANCE_CONTROLS::OnSetFocus( wxFocusEvent& aEvent )
886{
887#ifdef __WXMSW__
888 // In wxMSW, buttons won't process events unless they have focus, so we'll let it take the
889 // focus and give it back to the parent in the button event handler.
890 if( wxBitmapButton* btn = dynamic_cast<wxBitmapButton*>( aEvent.GetEventObject() ) )
891 {
892 wxCommandEvent evt( wxEVT_BUTTON );
893 wxPostEvent( btn, evt );
894 }
895#endif
896
897 passOnFocus();
898 aEvent.Skip();
899}
900
901
902void APPEARANCE_CONTROLS::OnSize( wxSizeEvent& aEvent )
903{
904 aEvent.Skip();
905}
906
907
908void APPEARANCE_CONTROLS::OnNetGridClick( wxGridEvent& event )
909{
910 int row = event.GetRow();
911 int col = event.GetCol();
912
913 switch( col )
914 {
916 m_netsTable->SetValueAsBool( row, col, !m_netsTable->GetValueAsBool( row, col ) );
917 m_netsGrid->ForceRefresh();
918 break;
919
920 default:
921 break;
922 }
923}
924
925
927{
928 int row = event.GetRow();
929 int col = event.GetCol();
930
931 switch( col )
932 {
934 {
935 wxGridCellEditor* editor = m_netsGrid->GetCellEditor( row, col );
936
937 if( editor )
938 {
939 editor->BeginEdit( row, col, m_netsGrid );
940 editor->DecRef();
941 }
942
943 break;
944 }
945
946 default:
947 break;
948 }
949}
950
951
953{
954 m_netsGrid->SelectRow( event.GetRow() );
955
956 wxString netName = UnescapeString( m_netsGrid->GetCellValue( event.GetRow(),
958 wxMenu menu;
959
960 menu.Append( new wxMenuItem( &menu, ID_SET_NET_COLOR, _( "Set Net Color" ), wxEmptyString,
961 wxITEM_NORMAL ) );
962 menu.Append( new wxMenuItem( &menu, ID_CLEAR_NET_COLOR, _( "Clear Net Color" ), wxEmptyString,
963 wxITEM_NORMAL ) );
964
965 menu.AppendSeparator();
966
967 menu.Append( new wxMenuItem( &menu, ID_HIGHLIGHT_NET,
968 wxString::Format( _( "Highlight %s" ), netName ), wxEmptyString,
969 wxITEM_NORMAL ) );
970 menu.Append( new wxMenuItem( &menu, ID_SELECT_NET,
971 wxString::Format( _( "Select Tracks and Vias in %s" ), netName ),
972 wxEmptyString, wxITEM_NORMAL ) );
973 menu.Append( new wxMenuItem( &menu, ID_DESELECT_NET,
974 wxString::Format( _( "Unselect Tracks and Vias in %s" ), netName ),
975 wxEmptyString, wxITEM_NORMAL ) );
976
977 menu.AppendSeparator();
978
979 menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_NETS, _( "Show All Nets" ), wxEmptyString,
980 wxITEM_NORMAL ) );
981 menu.Append( new wxMenuItem( &menu, ID_HIDE_OTHER_NETS, _( "Hide All Other Nets" ),
982 wxEmptyString, wxITEM_NORMAL ) );
983
984 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, &APPEARANCE_CONTROLS::onNetContextMenu, this );
985
986 PopupMenu( &menu );
987}
988
989
991{
992 wxPoint pos = m_netsGrid->CalcUnscrolledPosition( aEvent.GetPosition() );
993 wxGridCellCoords cell = m_netsGrid->XYToCell( pos );
994
995 if( aEvent.Moving() || aEvent.Entering() )
996 {
997 aEvent.Skip();
998
999 if( !cell )
1000 {
1001 m_netsGrid->GetGridWindow()->UnsetToolTip();
1002 return;
1003 }
1004
1005 if( cell == m_hoveredCell )
1006 return;
1007
1008 m_hoveredCell = cell;
1009
1010 const NET_GRID_ENTRY& net = m_netsTable->GetEntry( cell.GetRow() );
1011
1012 wxString name = net.name;
1013 wxString showOrHide = net.visible ? _( "Click to hide ratsnest for %s" )
1014 : _( "Click to show ratsnest for %s" );
1015 wxString tip;
1016
1017 if( cell.GetCol() == NET_GRID_TABLE::COL_VISIBILITY )
1018 tip.Printf( showOrHide, name );
1019 else if( cell.GetCol() == NET_GRID_TABLE::COL_COLOR )
1020 tip = _( "Double click (or middle click) to change color; right click for more actions" );
1021
1022 m_netsGrid->GetGridWindow()->SetToolTip( tip );
1023 }
1024 else if( aEvent.Leaving() )
1025 {
1026 m_netsGrid->UnsetToolTip();
1027 aEvent.Skip();
1028 }
1029 else if( aEvent.Dragging() )
1030 {
1031 // not allowed
1032 CallAfter( [this]()
1033 {
1034 m_netsGrid->ClearSelection();
1035 } );
1036 }
1037 else if( aEvent.ButtonUp( wxMOUSE_BTN_MIDDLE ) && !!cell )
1038 {
1039 int row = cell.GetRow();
1040 int col = cell.GetCol();
1041
1042 if( col == NET_GRID_TABLE::COL_COLOR )
1043 {
1044 wxGridCellEditor* editor = m_netsGrid->GetCellEditor( row, col );
1045
1046 if( editor )
1047 {
1048 editor->BeginEdit( row, col, m_netsGrid );
1049 editor->DecRef();
1050 }
1051 }
1052
1053 aEvent.Skip();
1054 }
1055 else
1056 {
1057 aEvent.Skip();
1058 }
1059}
1060
1061
1062void APPEARANCE_CONTROLS::OnLanguageChanged( wxCommandEvent& aEvent )
1063{
1064 m_notebook->SetPageText( 0, _( "Layers" ) );
1065 m_notebook->SetPageText( 1, _( "Objects" ) );
1066
1067 if( m_notebook->GetPageCount() >= 3 )
1068 m_notebook->SetPageText( 2, _( "Nets" ) );
1069
1070 m_netsGrid->ClearSelection();
1071
1072 Freeze();
1073 rebuildLayers();
1078 rebuildNets();
1079
1083
1085
1086 Thaw();
1087 Refresh();
1088
1089 aEvent.Skip();
1090}
1091
1093{
1094 if( aFlags & HOTKEYS_CHANGED )
1095 rebuildLayers();
1096}
1097
1099{
1100 if( !m_frame->GetBoard() )
1101 return;
1102
1103 m_netsGrid->ClearSelection();
1104
1105 Freeze();
1106 rebuildLayers();
1110 rebuildNets();
1114
1116
1117 m_board = m_frame->GetBoard();
1118
1119 if( m_board )
1120 m_board->AddListener( this );
1121
1122 Thaw();
1123 Refresh();
1124}
1125
1126
1131
1132
1133void APPEARANCE_CONTROLS::OnNetVisibilityChanged( int aNetCode, bool aVisibility )
1134{
1136 return;
1137
1138 int row = m_netsTable->GetRowByNetcode( aNetCode );
1139
1140 if( row >= 0 )
1141 {
1142 m_netsTable->SetVisibilityState( row, aVisibility );
1143 m_netsGrid->ForceRefresh();
1144 }
1145}
1146
1147
1149{
1150 return aBoardItem->Type() == PCB_NETINFO_T;
1151}
1152
1153
1154bool APPEARANCE_CONTROLS::doesBoardItemNeedRebuild( std::vector<BOARD_ITEM*>& aBoardItems )
1155{
1156 bool rebuild = std::any_of( aBoardItems.begin(), aBoardItems.end(),
1157 []( const BOARD_ITEM* a )
1158 {
1159 return a->Type() == PCB_NETINFO_T;
1160 } );
1161
1162 return rebuild;
1163}
1164
1165
1171
1172
1173void APPEARANCE_CONTROLS::OnBoardItemsAdded( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems )
1174{
1175 if( doesBoardItemNeedRebuild( aItems ) )
1177}
1178
1179
1185
1186
1187void APPEARANCE_CONTROLS::OnBoardItemsRemoved( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems )
1188{
1189 if( doesBoardItemNeedRebuild( aItems ) )
1191}
1192
1193
1199
1200
1201void APPEARANCE_CONTROLS::OnBoardItemsChanged( BOARD& aBoard, std::vector<BOARD_ITEM*>& aItems )
1202{
1203 if( doesBoardItemNeedRebuild( aItems ) )
1205}
1206
1207
1209 std::vector<BOARD_ITEM*>& aAddedItems,
1210 std::vector<BOARD_ITEM*>& aRemovedItems,
1211 std::vector<BOARD_ITEM*>& aChangedItems )
1212{
1213 if( doesBoardItemNeedRebuild( aAddedItems ) || doesBoardItemNeedRebuild( aRemovedItems )
1214 || doesBoardItemNeedRebuild( aChangedItems ) )
1215 {
1217 }
1218}
1219
1220
1222{
1223 if( !m_frame->GetBoard() )
1224 return;
1225
1226 m_netsGrid->ClearSelection();
1227
1228 Freeze();
1229 rebuildNets();
1230 Thaw();
1231}
1232
1233
1235{
1236 if( !m_frame->GetBoard() )
1237 return;
1238
1241}
1242
1243
1245{
1246 // This is essentially a list of hacks because DarkMode isn't yet implemented inside
1247 // wxWidgets.
1248 //
1249 // The individual wxPanels, COLOR_SWATCHes and GRID_CELL_COLOR_RENDERERs should really be
1250 // overriding some virtual method or responding to some wxWidgets event so that the parent
1251 // doesn't have to know what it contains. But, that's not where we are, so... :shrug:
1252
1253 m_layerPanelColour = m_panelLayers->GetBackgroundColour().ChangeLightness( 110 );
1254
1255 m_windowLayers->SetBackgroundColour( m_layerPanelColour );
1256
1257 for( wxSizerItem* child : m_layersOuterSizer->GetChildren() )
1258 {
1259 if( child && child->GetWindow() )
1260 child->GetWindow()->SetBackgroundColour( m_layerPanelColour );
1261 }
1262
1263 // Easier than calling OnDarkModeToggle on all the GRID_CELL_COLOR_RENDERERs:
1264 m_netsGrid->RegisterDataType( wxT( "COLOR4D" ),
1267
1268 for( const std::pair<const wxString, APPEARANCE_SETTING*>& pair : m_netclassSettingsMap )
1269 {
1270 if( pair.second->ctl_color )
1271 pair.second->ctl_color->OnDarkModeToggle();
1272 }
1273
1274 OnLayerChanged(); // Update selected highlighting
1275}
1276
1277
1279{
1280 for( const std::unique_ptr<APPEARANCE_SETTING>& setting : m_layerSettings )
1281 {
1282 setting->ctl_panel->SetBackgroundColour( m_layerPanelColour );
1283 setting->ctl_indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::OFF );
1284 }
1285
1286 wxChar r = m_layerPanelColour.Red();
1287 wxChar g = m_layerPanelColour.Green();
1288 wxChar b = m_layerPanelColour.Blue();
1289
1290 if( r < 240 || g < 240 || b < 240 )
1291 {
1292 r = wxChar( std::min( (int) r + 15, 255 ) );
1293 g = wxChar( std::min( (int) g + 15, 255 ) );
1294 b = wxChar( std::min( (int) b + 15, 255 ) );
1295 }
1296 else
1297 {
1298 r = wxChar( std::max( (int) r - 15, 0 ) );
1299 g = wxChar( std::max( (int) g - 15, 0 ) );
1300 b = wxChar( std::max( (int) b - 15, 0 ) );
1301 }
1302
1303 PCB_LAYER_ID current = m_frame->GetActiveLayer();
1304
1305 if( !m_layerSettingsMap.count( current ) )
1306 {
1307 wxASSERT( m_layerSettingsMap.count( F_Cu ) );
1308 current = F_Cu;
1309 }
1310
1311 APPEARANCE_SETTING* newSetting = m_layerSettingsMap[ current ];
1312
1313 newSetting->ctl_panel->SetBackgroundColour( wxColour( r, g, b ) );
1314 newSetting->ctl_indicator->SetIndicatorState( ROW_ICON_PROVIDER::STATE::ON );
1315
1316 Refresh();
1317}
1318
1319
1320void APPEARANCE_CONTROLS::SetLayerVisible( int aLayer, bool isVisible )
1321{
1322 LSET visible = getVisibleLayers();
1323 PCB_LAYER_ID layer = ToLAYER_ID( aLayer );
1324
1325 if( visible.test( layer ) == isVisible )
1326 return;
1327
1328 visible.set( layer, isVisible );
1329 setVisibleLayers( visible );
1330
1331 m_frame->GetCanvas()->GetView()->SetLayerVisible( layer, isVisible );
1332
1334}
1335
1336
1338{
1339 if( m_objectSettingsMap.count( aLayer ) )
1340 {
1341 APPEARANCE_SETTING* setting = m_objectSettingsMap.at( aLayer );
1342
1343 if( setting->can_control_visibility )
1344 setting->ctl_visibility->SetValue( isVisible );
1345 }
1346
1347 BOARD* board = m_frame->GetBoard();
1348
1349 if( !board )
1350 return;
1351
1352 board->SetElementVisibility( aLayer, isVisible );
1353
1354 m_frame->Update3DView( true, m_frame->GetPcbNewSettings()->m_Display.m_Live3DRefresh );
1355
1356 m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, isVisible );
1357 m_frame->GetCanvas()->Refresh();
1358}
1359
1360
1362{
1363 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
1364
1365 if( m_isFpEditor )
1366 {
1367 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
1368 view->SetLayerVisible( layer, aLayers.Contains( layer ) );
1369 }
1370 else if( BOARD* board = m_frame->GetBoard() )
1371 {
1372 const LSET before = board->GetVisibleLayers();
1373 const LSET changed = before ^ aLayers;
1374
1375 board->SetVisibleLayers( aLayers );
1376
1377 // A retained scene tracks layer visibility itself, so only items on changed layers need
1378 // repainting. Holes also depend on whether any physical layer is left.
1379 const bool anyPhysicalBefore = ( before & LSET::PhysicalLayersMask() ).any();
1380 const bool anyPhysicalAfter = ( aLayers & LSET::PhysicalLayersMask() ).any();
1381 const bool narrow = view->GetGAL() && view->GetGAL()->HasRetainedScene()
1382 && anyPhysicalBefore == anyPhysicalAfter;
1383
1384 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
1385 // they won't be found in the view layer's itemset for repainting.
1387 [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
1388 {
1389 // Items rendered to composite layers (such as LAYER_PAD_TH) must be redrawn
1390 // whether they're optionally flashed or not (as the layer being hidden/shown
1391 // might be the last layer the item is visible on).
1392 if( !aItem->IsBOARD_ITEM() )
1393 return false;
1394
1395 const BOARD_ITEM* item = static_cast<const BOARD_ITEM*>( aItem );
1396
1397 if( item->Type() != PCB_VIA_T && item->Type() != PCB_PAD_T )
1398 return false;
1399
1400 return !narrow || ( item->GetLayerSet() & changed ).any();
1401 } );
1402
1403 m_frame->Update3DView( true, m_frame->GetPcbNewSettings()->m_Display.m_Live3DRefresh );
1404 }
1405}
1406
1407
1409{
1410 // This used to be used for disabling some layers in the footprint editor, but
1411 // now all layers are enabled in the footprint editor.
1412 // But this function is the place to add logic if you do need to grey out a layer
1413 // from the appearance panel for some reason.
1414 return true;
1415}
1416
1417
1419{
1420 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
1421
1422 if( m_isFpEditor )
1423 {
1424 for( size_t i = 0; i < GAL_LAYER_INDEX( LAYER_ZONE_START ); i++ )
1425 view->SetLayerVisible( GAL_LAYER_ID_START + GAL_LAYER_ID( i ), aLayers.test( i ) );
1426 }
1427 else
1428 {
1429 // Ratsnest visibility is controlled by the ratsnest option, and not by the preset
1430 if( m_frame->IsType( FRAME_PCB_EDITOR ) )
1431 aLayers.set( LAYER_RATSNEST, m_frame->GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest );
1432
1433 BOARD* board = m_frame->GetBoard();
1434
1435 if( !board )
1436 return;
1437
1438 m_frame->SetGridVisibility( aLayers.test( LAYER_GRID - GAL_LAYER_ID_START ) );
1439 board->SetVisibleElements( aLayers );
1440
1441 // Update VIEW layer visibility to stay in sync with board settings
1442 for( size_t i = 0; i < GAL_LAYER_INDEX( LAYER_ZONE_START ) && i < aLayers.size(); i++ )
1443 {
1444 // Warning: all GAL layers are not handled by the apparence panel (i.e. LAYER_SELECT_OVERLAY)
1445 // but only some, only set visiblity if the layer is handled by the APPEARANCE_CONTROLS
1447
1448 if( gal_ly == LAYER_RATSNEST )
1449 continue;
1450
1451 for( const APPEARANCE_SETTING& s_setting : s_objectSettings )
1452 {
1453 // See if this gal layer is handled
1454 if( s_setting.id == gal_ly )
1455 {
1456 view->SetLayerVisible( gal_ly, aLayers.test( i ) );
1457 break;
1458 }
1459 }
1460 }
1461
1462 m_frame->Update3DView( true, m_frame->GetPcbNewSettings()->m_Display.m_Live3DRefresh );
1463 }
1464}
1465
1466
1468{
1469 if( m_isFpEditor )
1470 {
1471 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
1472 LSET set;
1473
1474 for( PCB_LAYER_ID layer : LSET::AllLayersMask().Seq() )
1475 set.set( layer, view->IsLayerVisible( layer ) );
1476
1477 return set;
1478 }
1479 else if( BOARD* board = m_frame->GetBoard() )
1480 {
1481 return board->GetVisibleLayers();
1482 }
1483
1484 return LSET();
1485}
1486
1487
1489{
1490 if( m_isFpEditor )
1491 {
1492 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
1493 GAL_SET set;
1494 set.reset();
1495
1496 for( size_t i = 0; i < set.size(); i++ )
1497 set.set( i, view->IsLayerVisible( GAL_LAYER_ID_START + GAL_LAYER_ID( i ) ) );
1498
1499 return set;
1500 }
1501 else if( BOARD* board = m_frame->GetBoard() )
1502 {
1503 return board->GetVisibleElements();
1504 }
1505
1506 return GAL_SET();
1507}
1508
1509
1511{
1512 const PCB_DISPLAY_OPTIONS& options = m_frame->GetDisplayOptions();
1513
1514 switch( options.m_ContrastModeDisplay )
1515 {
1516 case HIGH_CONTRAST_MODE::NORMAL: m_rbHighContrastNormal->SetValue( true ); break;
1517 case HIGH_CONTRAST_MODE::DIMMED: m_rbHighContrastDim->SetValue( true ); break;
1518 case HIGH_CONTRAST_MODE::HIDDEN: m_rbHighContrastOff->SetValue( true ); break;
1519 }
1520
1521 switch( options.m_NetColorMode )
1522 {
1523 case NET_COLOR_MODE::ALL: m_rbNetColorAll->SetValue( true ); break;
1524 case NET_COLOR_MODE::RATSNEST: m_rbNetColorRatsnest->SetValue( true ); break;
1525 case NET_COLOR_MODE::OFF: m_rbNetColorOff->SetValue( true ); break;
1526 }
1527
1528 m_cbFlipBoard->SetValue( m_frame->GetDisplayOptions().m_FlipBoardView );
1529
1530 if( !m_isFpEditor )
1531 {
1532 if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
1533 {
1534 if( !cfg->m_Display.m_ShowGlobalRatsnest )
1535 m_rbRatsnestNone->SetValue( true );
1536 else if( cfg->m_Display.m_RatsnestMode == RATSNEST_MODE::ALL )
1537 m_rbRatsnestAllLayers->SetValue( true );
1538 else
1539 m_rbRatsnestVisLayers->SetValue( true );
1540
1541 wxASSERT( m_objectSettingsMap.count( LAYER_RATSNEST ) );
1543 ratsnest->ctl_visibility->SetValue( cfg->m_Display.m_ShowGlobalRatsnest );
1544 }
1545 }
1546}
1547
1548
1549std::vector<LAYER_PRESET> APPEARANCE_CONTROLS::GetUserLayerPresets() const
1550{
1551 std::vector<LAYER_PRESET> ret;
1552
1553 for( const std::pair<const wxString, LAYER_PRESET>& pair : m_layerPresets )
1554 {
1555 if( !pair.second.readOnly )
1556 ret.emplace_back( pair.second );
1557 }
1558
1559 return ret;
1560}
1561
1562
1563void APPEARANCE_CONTROLS::SetUserLayerPresets( std::vector<LAYER_PRESET>& aPresetList )
1564{
1565 // Points into the map about to be rebuilt
1566 m_lastSelectedUserPreset = nullptr;
1567
1568 // Reset to defaults
1570
1571 for( const LAYER_PRESET& preset : aPresetList )
1572 {
1573 if( m_layerPresets.count( preset.name ) )
1574 continue;
1575
1576 m_layerPresets[preset.name] = preset;
1577
1578 m_presetMRU.Add( preset.name );
1579 }
1580
1582
1583 // The reset selects All Layers, which a later save would persist over what is actually shown
1585}
1586
1587
1589{
1590 m_layerPresets.clear();
1591
1592 // Load the read-only defaults
1593 for( const LAYER_PRESET& preset : { presetAllLayers,
1599 presetBack,
1601 {
1602 m_layerPresets[preset.name] = preset;
1603 m_layerPresets[preset.name].readOnly = true;
1604 }
1605}
1606
1607
1608void APPEARANCE_CONTROLS::ApplyLayerPreset( const wxString& aPresetName )
1609{
1610 updateLayerPresetSelection( aPresetName );
1611
1612 wxCommandEvent dummy;
1614}
1615
1616
1618{
1619 if( m_layerPresets.count( aPreset.name ) )
1621 else
1622 m_currentPreset = nullptr;
1623
1625 : nullptr;
1626
1628 doApplyLayerPreset( aPreset );
1629}
1630
1631
1632std::vector<VIEWPORT> APPEARANCE_CONTROLS::GetUserViewports() const
1633{
1634 std::vector<VIEWPORT> ret;
1635
1636 for( const std::pair<const wxString, VIEWPORT>& pair : m_viewports )
1637 ret.emplace_back( pair.second );
1638
1639 return ret;
1640}
1641
1642
1643void APPEARANCE_CONTROLS::SetUserViewports( std::vector<VIEWPORT>& aViewportList )
1644{
1645 m_viewports.clear();
1646 m_viewportMRU.clear();
1647
1648 for( const VIEWPORT& viewport : aViewportList )
1649 {
1650 if( m_viewports.count( viewport.name ) )
1651 continue;
1652
1653 m_viewports[viewport.name] = viewport;
1654
1655 m_viewportMRU.Add( viewport.name );
1656 }
1657
1659}
1660
1661
1662void APPEARANCE_CONTROLS::ApplyViewport( const wxString& aViewportName )
1663{
1664 updateViewportSelection( aViewportName );
1665
1666 wxCommandEvent dummy;
1668}
1669
1670
1672{
1673 updateViewportSelection( aViewport.name );
1674 doApplyViewport( aViewport );
1675}
1676
1677
1679{
1680 BOARD* board = m_frame->GetBoard();
1681
1682 if( !board )
1683 return;
1684
1685 LSET enabled = board->GetEnabledLayers();
1686 LSET visible = getVisibleLayers();
1687
1688 COLOR_SETTINGS* theme = m_frame->GetColorSettings();
1689 COLOR4D bgColor = theme->GetColor( LAYER_PCB_BACKGROUND );
1690 bool readOnly = theme->IsReadOnly();
1691
1693
1694#ifdef __WXMAC__
1695 wxSizerItem* m_windowLayersSizerItem = m_panelLayersSizer->GetItem( m_windowLayers );
1696 m_windowLayersSizerItem->SetFlag( m_windowLayersSizerItem->GetFlag() & ~wxTOP );
1697#endif
1698
1699 auto appendLayer =
1700 [&]( std::unique_ptr<APPEARANCE_SETTING>& aSetting )
1701 {
1702 int layer = aSetting->id;
1703
1704 wxPanel* panel = new wxPanel( m_windowLayers, layer );
1705 wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
1706 panel->SetSizer( sizer );
1707
1708 panel->SetBackgroundColour( m_layerPanelColour );
1709
1710 aSetting->visible = visible[layer];
1711
1712 // TODO(JE) consider restyling this indicator
1713 INDICATOR_ICON* indicator = new INDICATOR_ICON( panel, *m_iconProvider,
1714 ROW_ICON_PROVIDER::STATE::OFF, layer );
1715
1716 COLOR_SWATCH* swatch = new COLOR_SWATCH( panel, COLOR4D::UNSPECIFIED, layer, bgColor,
1717 theme->GetColor( layer ), SWATCH_SMALL );
1718 swatch->SetToolTip( _( "Double click or middle click for color change, right click for menu" ) );
1719
1720 BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE( panel, layer,
1723 aSetting->visible );
1724 btn_visible->SetToolTip( _( "Show or hide this layer" ) );
1725
1726 wxStaticText* label = new wxStaticText( panel, layer, aSetting->label );
1727 label->Wrap( -1 );
1728 label->SetToolTip( aSetting->tooltip );
1729
1730 sizer->AddSpacer( 1 );
1731 sizer->Add( indicator, 0, wxALIGN_CENTER_VERTICAL | wxTOP, 2 );
1732 sizer->AddSpacer( 5 );
1733 sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL | wxTOP, 2 );
1734 sizer->AddSpacer( 6 );
1735 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL | wxTOP, 2 );
1736 sizer->AddSpacer( 5 );
1737 sizer->Add( label, 1, wxALIGN_CENTER_VERTICAL | wxTOP, 2 );
1738
1739 m_layersOuterSizer->Add( panel, 0, wxEXPAND, 0 );
1740
1741 aSetting->ctl_panel = panel;
1742 aSetting->ctl_indicator = indicator;
1743 aSetting->ctl_visibility = btn_visible;
1744 aSetting->ctl_color = swatch;
1745 aSetting->ctl_text = label;
1746
1747 panel->Bind( wxEVT_LEFT_DOWN, &APPEARANCE_CONTROLS::onLayerLeftClick, this );
1748 indicator->Bind( wxEVT_LEFT_DOWN, &APPEARANCE_CONTROLS::onLayerLeftClick, this );
1749 swatch->Bind( wxEVT_LEFT_DOWN, &APPEARANCE_CONTROLS::onLayerLeftClick, this );
1750 label->Bind( wxEVT_LEFT_DOWN, &APPEARANCE_CONTROLS::onLayerLeftClick, this );
1751
1752 btn_visible->Bind( TOGGLE_CHANGED,
1753 [&]( wxCommandEvent& aEvent )
1754 {
1755 wxObject* btn = aEvent.GetEventObject();
1756 int layerId = static_cast<wxWindow*>( btn )->GetId();
1757
1758 onLayerVisibilityToggled( static_cast<PCB_LAYER_ID>( layerId ) );
1759 } );
1760
1761 swatch->Bind( COLOR_SWATCH_CHANGED, &APPEARANCE_CONTROLS::OnColorSwatchChanged, this );
1762 swatch->SetReadOnlyCallback( std::bind( &APPEARANCE_CONTROLS::onReadOnlySwatch, this ) );
1763 swatch->SetReadOnly( readOnly );
1764
1765 panel->Bind( wxEVT_RIGHT_DOWN, &APPEARANCE_CONTROLS::rightClickHandler, this );
1766 indicator->Bind( wxEVT_RIGHT_DOWN, &APPEARANCE_CONTROLS::rightClickHandler, this );
1767 swatch->Bind( wxEVT_RIGHT_DOWN, &APPEARANCE_CONTROLS::rightClickHandler, this );
1768 btn_visible->Bind( wxEVT_RIGHT_DOWN, &APPEARANCE_CONTROLS::rightClickHandler, this );
1769 label->Bind( wxEVT_RIGHT_DOWN, &APPEARANCE_CONTROLS::rightClickHandler, this );
1770 };
1771
1772 auto updateLayer =
1773 [&]( std::unique_ptr<APPEARANCE_SETTING>& aSetting )
1774 {
1775 int layer = aSetting->id;
1776 aSetting->visible = visible[layer];
1777 aSetting->ctl_panel->Show();
1778 aSetting->ctl_panel->SetId( layer );
1779 aSetting->ctl_indicator->SetWindowID( layer );
1780 aSetting->ctl_color->SetWindowID( layer );
1781 aSetting->ctl_color->SetSwatchColor( theme->GetColor( layer ), false );
1782 aSetting->ctl_visibility->SetWindowID( layer );
1783 aSetting->ctl_text->SetLabelText( aSetting->label );
1784 aSetting->ctl_text->SetId( layer );
1785 aSetting->ctl_text->SetToolTip( aSetting->tooltip );
1786 };
1787
1788 // technical layers are shown in this order:
1789 // Because they are static, wxGetTranslation must be explicitly
1790 // called for tooltips.
1791 static const struct {
1792 PCB_LAYER_ID layerId;
1793 wxString tooltip;
1794 } non_cu_seq[] = {
1795 { F_Adhes, _HKI( "Adhesive on board's front" ) },
1796 { B_Adhes, _HKI( "Adhesive on board's back" ) },
1797 { F_Paste, _HKI( "Solder paste on board's front" ) },
1798 { B_Paste, _HKI( "Solder paste on board's back" ) },
1799 { F_SilkS, _HKI( "Silkscreen on board's front" ) },
1800 { B_SilkS, _HKI( "Silkscreen on board's back" ) },
1801 { F_Mask, _HKI( "Solder mask on board's front" ) },
1802 { B_Mask, _HKI( "Solder mask on board's back" ) },
1803 { Dwgs_User, _HKI( "Explanatory drawings" ) },
1804 { Cmts_User, _HKI( "Explanatory comments" ) },
1805 { Eco1_User, _HKI( "User defined meaning" ) },
1806 { Eco2_User, _HKI( "User defined meaning" ) },
1807 { Edge_Cuts, _HKI( "Board's perimeter definition" ) },
1808 { Margin, _HKI( "Board's edge setback outline" ) },
1809 { F_CrtYd, _HKI( "Footprint courtyards on board's front" ) },
1810 { B_CrtYd, _HKI( "Footprint courtyards on board's back" ) },
1811 { F_Fab, _HKI( "Footprint assembly on board's front" ) },
1812 { B_Fab, _HKI( "Footprint assembly on board's back" ) },
1813 { User_1, _HKI( "User defined layer 1" ) },
1814 { User_2, _HKI( "User defined layer 2" ) },
1815 { User_3, _HKI( "User defined layer 3" ) },
1816 { User_4, _HKI( "User defined layer 4" ) },
1817 { User_5, _HKI( "User defined layer 5" ) },
1818 { User_6, _HKI( "User defined layer 6" ) },
1819 { User_7, _HKI( "User defined layer 7" ) },
1820 { User_8, _HKI( "User defined layer 8" ) },
1821 { User_9, _HKI( "User defined layer 9" ) },
1822 { User_10, _HKI( "User defined layer 10" ) },
1823 { User_11, _HKI( "User defined layer 11" ) },
1824 { User_12, _HKI( "User defined layer 12" ) },
1825 { User_13, _HKI( "User defined layer 13" ) },
1826 { User_14, _HKI( "User defined layer 14" ) },
1827 { User_15, _HKI( "User defined layer 15" ) },
1828 { User_16, _HKI( "User defined layer 16" ) },
1829 { User_17, _HKI( "User defined layer 17" ) },
1830 { User_18, _HKI( "User defined layer 18" ) },
1831 { User_19, _HKI( "User defined layer 19" ) },
1832 { User_20, _HKI( "User defined layer 20" ) },
1833 { User_21, _HKI( "User defined layer 21" ) },
1834 { User_22, _HKI( "User defined layer 22" ) },
1835 { User_23, _HKI( "User defined layer 23" ) },
1836 { User_24, _HKI( "User defined layer 24" ) },
1837 { User_25, _HKI( "User defined layer 25" ) },
1838 { User_26, _HKI( "User defined layer 26" ) },
1839 { User_27, _HKI( "User defined layer 27" ) },
1840 { User_28, _HKI( "User defined layer 28" ) },
1841 { User_29, _HKI( "User defined layer 29" ) },
1842 { User_30, _HKI( "User defined layer 30" ) },
1843 { User_31, _HKI( "User defined layer 31" ) },
1844 { User_32, _HKI( "User defined layer 32" ) },
1845 { User_33, _HKI( "User defined layer 33" ) },
1846 { User_34, _HKI( "User defined layer 34" ) },
1847 { User_35, _HKI( "User defined layer 35" ) },
1848 { User_36, _HKI( "User defined layer 36" ) },
1849 { User_37, _HKI( "User defined layer 37" ) },
1850 { User_38, _HKI( "User defined layer 38" ) },
1851 { User_39, _HKI( "User defined layer 39" ) },
1852 { User_40, _HKI( "User defined layer 40" ) },
1853 { User_41, _HKI( "User defined layer 41" ) },
1854 { User_42, _HKI( "User defined layer 42" ) },
1855 { User_43, _HKI( "User defined layer 43" ) },
1856 { User_44, _HKI( "User defined layer 44" ) },
1857 { User_45, _HKI( "User defined layer 45" ) },
1858 };
1859
1860 // There is a spacer added to the end of the list that we need to remove and re-add
1861 // after possibly adding additional layers
1862 if( m_layersOuterSizer->GetItemCount() > 0 )
1863 {
1864 m_layersOuterSizer->Detach( m_layersOuterSizer->GetItemCount() - 1 );
1865 }
1866 // Otherwise, this is the first time we are updating the control, so we need to attach
1867 // the handler
1868 else
1869 {
1870 // Add right click handling to show the context menu when clicking to the free area in
1871 // m_windowLayers (below the layer items)
1872 m_windowLayers->Bind( wxEVT_RIGHT_DOWN, &APPEARANCE_CONTROLS::rightClickHandler, this );
1873 }
1874
1875 std::size_t total_layers = enabled.CuStack().size();
1876
1877 for( const auto& entry : non_cu_seq )
1878 {
1879 if( enabled[entry.layerId] )
1880 total_layers++;
1881 }
1882
1883 // Adds layers to the panel until we have enough to hold our total count
1884 while( total_layers > m_layerSettings.size() )
1885 m_layerSettings.push_back( std::make_unique<APPEARANCE_SETTING>() );
1886
1887 // We never delete layers from the panel, only hide them. This saves us
1888 // having to recreate the (possibly) later with minimal overhead
1889 for( std::size_t ii = total_layers; ii < m_layerSettings.size(); ++ii )
1890 {
1891 if( m_layerSettings[ii]->ctl_panel )
1892 m_layerSettings[ii]->ctl_panel->Show( false );
1893 }
1894
1895 auto layer_it = m_layerSettings.begin();
1896
1897 // show all coppers first, with front on top, back on bottom, then technical layers
1898 for( PCB_LAYER_ID layer : enabled.CuStack() )
1899 {
1900 wxString dsc;
1901
1902 switch( layer )
1903 {
1904 case F_Cu: dsc = _( "Front copper layer" ); break;
1905 case B_Cu: dsc = _( "Back copper layer" ); break;
1906 default: dsc = _( "Inner copper layer" ); break;
1907 }
1908
1909 std::unique_ptr<APPEARANCE_SETTING>& setting = *layer_it;
1910
1911 setting->label = board->GetLayerName( layer );
1912 setting->id = layer;
1913 setting->tooltip = dsc;
1914
1915 if( setting->ctl_panel == nullptr )
1916 appendLayer( setting );
1917 else
1918 updateLayer( setting );
1919
1920 m_layerSettingsMap[layer] = setting.get();
1921
1922 if( !isLayerEnabled( layer ) )
1923 {
1924 setting->ctl_text->Disable();
1925 setting->ctl_color->SetToolTip( wxEmptyString );
1926 }
1927
1928 ++layer_it;
1929 }
1930
1931 for( const auto& entry : non_cu_seq )
1932 {
1933 PCB_LAYER_ID layer = entry.layerId;
1934
1935 if( !enabled[layer] )
1936 continue;
1937
1938 std::unique_ptr<APPEARANCE_SETTING>& setting = *layer_it;
1939
1940 if( m_isFpEditor )
1941 {
1942 wxString canonicalName = LSET::Name( static_cast<PCB_LAYER_ID>( layer ) );
1943
1944 if( cfg->m_DesignSettings.m_UserLayerNames.contains( canonicalName.ToStdString() ) )
1945 setting->label = cfg->m_DesignSettings.m_UserLayerNames[canonicalName.ToStdString()];
1946 else
1947 setting->label = board->GetStandardLayerName( layer );
1948 }
1949 else
1950 {
1951 setting->label = board->GetLayerName( layer );
1952 }
1953
1954 setting->id = layer;
1955 // Because non_cu_seq is created static, we must explicitly call wxGetTranslation for
1956 // texts which are internationalized
1957 setting->tooltip = wxGetTranslation( entry.tooltip );
1958
1959 if( setting->ctl_panel == nullptr )
1960 appendLayer( setting );
1961 else
1962 updateLayer( setting );
1963
1964 m_layerSettingsMap[layer] = setting.get();
1965
1966 if( !isLayerEnabled( layer ) )
1967 {
1968 setting->ctl_text->Disable();
1969 setting->ctl_color->SetToolTip( wxEmptyString );
1970 }
1971
1972 ++layer_it;
1973 }
1974
1975 m_layersOuterSizer->AddSpacer( 10 );
1976 m_windowLayers->SetBackgroundColour( m_layerPanelColour );
1977 m_windowLayers->FitInside(); // Updates virtual size to fit subwindows, also auto-layouts.
1978
1979 m_paneLayerDisplayOptions->SetLabel( _( "Layer Display Options" ) );
1980
1981 int hotkey = PCB_ACTIONS::highContrastModeCycle.GetHotKey();
1982 wxString msg;
1983
1984 if( hotkey )
1985 msg = wxString::Format( _( "Inactive layers (%s):" ), KeyNameFromKeyCode( hotkey ) );
1986 else
1987 msg = _( "Inactive layers:" );
1988
1989 m_inactiveLayersLabel->SetLabel( msg );
1990
1991 m_rbHighContrastNormal->SetLabel( _( "Normal" ) );
1992 m_rbHighContrastNormal->SetToolTip( _( "Inactive layers will be shown in full color" ) );
1993
1994 m_rbHighContrastDim->SetLabel( _( "Dim" ) );
1995 m_rbHighContrastDim->SetToolTip( _( "Inactive layers will be dimmed" ) );
1996
1997 m_rbHighContrastOff->SetLabel( _( "Hide" ) );
1998 m_rbHighContrastOff->SetToolTip( _( "Inactive layers will be hidden" ) );
1999
2000 m_cbFlipBoard->SetLabel( _( "Flip board view" ) );
2001}
2002
2003
2005{
2006 delete m_layerContextMenu;
2007 m_layerContextMenu = new wxMenu;
2008
2009 KIUI::AddMenuItem( m_layerContextMenu, ID_SHOW_ALL_COPPER_LAYERS, _( "Show All Copper Layers" ),
2011 KIUI::AddMenuItem( m_layerContextMenu, ID_HIDE_ALL_COPPER_LAYERS, _( "Hide All Copper Layers" ),
2013
2014 m_layerContextMenu->AppendSeparator();
2015
2016 KIUI::AddMenuItem( m_layerContextMenu, ID_HIDE_ALL_BUT_ACTIVE, _( "Hide All Layers But Active" ),
2018
2019 m_layerContextMenu->AppendSeparator();
2020
2021 KIUI::AddMenuItem( m_layerContextMenu, ID_SHOW_ALL_NON_COPPER, _( "Show All Non Copper Layers" ),
2023
2024 KIUI::AddMenuItem( m_layerContextMenu, ID_HIDE_ALL_NON_COPPER, _( "Hide All Non Copper Layers" ),
2026
2027 m_layerContextMenu->AppendSeparator();
2028
2031
2034
2035 m_layerContextMenu->AppendSeparator();
2036
2037 KIUI::AddMenuItem( m_layerContextMenu, ID_PRESET_FRONT_ASSEMBLY, _( "Show Only Front Assembly Layers" ),
2039
2040 KIUI::AddMenuItem( m_layerContextMenu, ID_PRESET_FRONT, _( "Show Only Front Layers" ),
2042
2043 // Only show the internal layer option if internal layers are enabled
2044 if( m_frame->GetBoard() && m_frame->GetBoard()->GetCopperLayerCount() > 2 )
2045 {
2046 KIUI::AddMenuItem( m_layerContextMenu, ID_PRESET_INNER_COPPER, _( "Show Only Inner Layers" ),
2048 }
2049
2050 KIUI::AddMenuItem( m_layerContextMenu, ID_PRESET_BACK, _( "Show Only Back Layers" ),
2052
2053 KIUI::AddMenuItem( m_layerContextMenu, ID_PRESET_BACK_ASSEMBLY, _( "Show Only Back Assembly Layers" ),
2055}
2056
2057
2058void APPEARANCE_CONTROLS::OnLayerContextMenu( wxCommandEvent& aEvent )
2059{
2060 BOARD* board = m_frame->GetBoard();
2061
2062 if( !board )
2063 return;
2064
2065 LSET visible = getVisibleLayers();
2066
2067 PCB_LAYER_ID current = m_frame->GetActiveLayer();
2068
2069 // The new preset. We keep the visibility state of objects:
2070 LAYER_PRESET preset;
2072 preset.flipBoard = m_frame->GetDisplayOptions().m_FlipBoardView;
2073
2074 switch( aEvent.GetId() )
2075 {
2077 preset.layers = presetNoLayers.layers;
2078 ApplyLayerPreset( preset );
2079 return;
2080
2082 preset.layers = presetAllLayers.layers;
2083 ApplyLayerPreset( preset );
2084 return;
2085
2087 visible |= presetAllCopper.layers;
2088 setVisibleLayers( visible );
2089 break;
2090
2092 preset.layers = presetNoLayers.layers | LSET( { current } );
2093 ApplyLayerPreset( preset );
2094 break;
2095
2097 visible &= ~presetAllCopper.layers;
2098
2099 if( !visible.test( current ) && visible.count() > 0 )
2100 m_frame->SetActiveLayer( *visible.Seq().begin() );
2101
2102 setVisibleLayers( visible );
2103 break;
2104
2106 visible &= presetAllCopper.layers;
2107
2108 if( !visible.test( current ) && visible.count() > 0 )
2109 m_frame->SetActiveLayer( *visible.Seq().begin() );
2110
2111 setVisibleLayers( visible );
2112 break;
2113
2115 visible |= ~presetAllCopper.layers;
2116
2117 setVisibleLayers( visible );
2118 break;
2119
2121 preset.layers = presetFrontAssembly.layers;
2122 ApplyLayerPreset( preset );
2123 return;
2124
2125 case ID_PRESET_FRONT:
2126 preset.layers = presetFront.layers;
2127 ApplyLayerPreset( preset );
2128 return;
2129
2131 preset.layers = presetInnerCopper.layers;
2132 ApplyLayerPreset( preset );
2133 return;
2134
2135 case ID_PRESET_BACK:
2136 preset.layers = presetBack.layers;
2137 ApplyLayerPreset( preset );
2138 return;
2139
2141 preset.layers = presetBackAssembly.layers;
2142 ApplyLayerPreset( preset );
2143 return;
2144 }
2145
2148
2149 if( !m_isFpEditor )
2150 m_frame->GetCanvas()->SyncLayersVisibility( board );
2151
2152 m_frame->GetCanvas()->Refresh();
2153}
2154
2155
2157{
2158 return m_notebook->GetSelection();
2159}
2160
2161
2163{
2164 size_t max = m_notebook->GetPageCount();
2165
2166 if( aTab >= 0 && static_cast<size_t>( aTab ) < max )
2167 m_notebook->SetSelection( aTab );
2168}
2169
2170
2172{
2173 COLOR_SETTINGS* theme = m_frame->GetColorSettings();
2174 bool readOnly = theme->IsReadOnly();
2175 LSET visible = getVisibleLayers();
2176 GAL_SET objects = getVisibleObjects();
2177
2178 Freeze();
2179
2180 for( std::unique_ptr<APPEARANCE_SETTING>& setting : m_layerSettings )
2181 {
2182 int layer = setting->id;
2183
2184 if( setting->ctl_visibility )
2185 setting->ctl_visibility->SetValue( visible[layer] );
2186
2187 if( setting->ctl_color )
2188 {
2189 const COLOR4D& color = theme->GetColor( layer );
2190 setting->ctl_color->SetSwatchColor( color, false );
2191 setting->ctl_color->SetReadOnly( readOnly );
2192 }
2193 }
2194
2195 for( std::unique_ptr<APPEARANCE_SETTING>& setting : m_objectSettings )
2196 {
2197 GAL_LAYER_ID layer = static_cast<GAL_LAYER_ID>( setting->id );
2198
2199 if( setting->ctl_visibility )
2200 setting->ctl_visibility->SetValue( objects.Contains( layer ) );
2201
2202 if( setting->ctl_color )
2203 {
2204 const COLOR4D& color = theme->GetColor( layer );
2205 setting->ctl_color->SetSwatchColor( color, false );
2206 setting->ctl_color->SetReadOnly( readOnly );
2207 }
2208 }
2209
2210 // Update indicators and panel background colors
2212
2213 Thaw();
2214
2215 m_windowLayers->Refresh();
2216}
2217
2218
2219void APPEARANCE_CONTROLS::onLayerLeftClick( wxMouseEvent& aEvent )
2220{
2221 wxWindow* eventSource = static_cast<wxWindow*>( aEvent.GetEventObject() );
2222
2223 PCB_LAYER_ID layer = ToLAYER_ID( eventSource->GetId() );
2224
2225 if( !isLayerEnabled( layer ) )
2226 return;
2227
2228 m_frame->SetActiveLayer( layer );
2229 passOnFocus();
2230}
2231
2232
2233void APPEARANCE_CONTROLS::rightClickHandler( wxMouseEvent& aEvent )
2234{
2235 wxASSERT( m_layerContextMenu );
2236 PopupMenu( m_layerContextMenu );
2237 passOnFocus();
2238};
2239
2240
2242{
2243 LSET visibleLayers = getVisibleLayers();
2244
2245 visibleLayers.set( aLayer, !visibleLayers.test( aLayer ) );
2246 setVisibleLayers( visibleLayers );
2247 m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, visibleLayers.test( aLayer ) );
2248
2250 m_frame->GetCanvas()->Refresh();
2251}
2252
2253
2254void APPEARANCE_CONTROLS::onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal )
2255{
2256 // Special-case controls
2257 switch( aLayer )
2258 {
2259 case LAYER_RATSNEST:
2260 {
2261 // don't touch the layers. ratsnest is enabled on per-item basis.
2262 m_frame->GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
2263 m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, true );
2264
2265 if( m_frame->IsType( FRAME_PCB_EDITOR ) )
2266 {
2267 m_frame->GetPcbNewSettings()->m_Display.m_ShowGlobalRatsnest = isVisible;
2268
2269 if( m_frame->GetBoard() )
2270 m_frame->GetBoard()->SetElementVisibility( aLayer, isVisible );
2271
2272 m_frame->OnDisplayOptionsChanged();
2273 m_frame->GetCanvas()->RedrawRatsnest();
2274 }
2275
2276 break;
2277 }
2278
2279 case LAYER_GRID:
2280 m_frame->SetGridVisibility( isVisible );
2281 m_frame->GetCanvas()->Refresh();
2283 break;
2284
2285 case LAYER_FP_TEXT:
2286 // Because Footprint Text is a meta-control that also can disable values/references,
2287 // drag them along here so that the user is less likely to be confused.
2288 if( isFinal )
2289 {
2290 // Should only trigger when you actually click the Footprint Text button
2291 // Otherwise it goes into infinite recursive loop with the following case section
2293 onObjectVisibilityChanged( LAYER_FP_VALUES, isVisible, false );
2294 m_objectSettingsMap[LAYER_FP_REFERENCES]->ctl_visibility->SetValue( isVisible );
2295 m_objectSettingsMap[LAYER_FP_VALUES]->ctl_visibility->SetValue( isVisible );
2296 }
2297 break;
2298
2300 case LAYER_FP_VALUES:
2301 // In case that user changes Footprint Value/References when the Footprint Text
2302 // meta-control is disabled, we should put it back on.
2303 if( isVisible )
2304 {
2305 onObjectVisibilityChanged( LAYER_FP_TEXT, isVisible, false );
2306 m_objectSettingsMap[LAYER_FP_TEXT]->ctl_visibility->SetValue( isVisible );
2307 }
2308 break;
2309
2310 default:
2311 break;
2312 }
2313
2314 GAL_SET visible = getVisibleObjects();
2315
2316 if( visible.Contains( aLayer ) != isVisible )
2317 {
2318 visible.set( aLayer, isVisible );
2319 setVisibleObjects( visible );
2320 m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, isVisible );
2322 }
2323
2324 if( isFinal )
2325 {
2326 m_frame->GetCanvas()->Refresh();
2327 passOnFocus();
2328 }
2329}
2330
2331
2333{
2334 COLOR_SETTINGS* theme = m_frame->GetColorSettings();
2335 COLOR4D bgColor = theme->GetColor( LAYER_PCB_BACKGROUND );
2336 GAL_SET visible = getVisibleObjects();
2337 int swatchWidth = m_windowObjects->ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
2338 int labelWidth = 0;
2339
2340 int btnWidth = m_visibleBitmapBundle.GetPreferredLogicalSizeFor( m_windowObjects ).x;
2341
2342 m_objectSettings.clear();
2343 m_objectsOuterSizer->Clear( true );
2344 m_objectsOuterSizer->AddSpacer( 5 );
2345
2346 auto appendObject =
2347 [&]( const std::unique_ptr<APPEARANCE_SETTING>& aSetting )
2348 {
2349 wxPanel* panel = new wxPanel( m_windowObjects, wxID_ANY );
2350 wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
2351 panel->SetSizer( sizer );
2352 int layer = aSetting->id;
2353
2354 aSetting->visible = visible.Contains( ToGalLayer( layer ) );
2355 COLOR4D color = theme->GetColor( layer );
2356 COLOR4D defColor = theme->GetDefaultColor( layer );
2357
2358 if( color != COLOR4D::UNSPECIFIED || defColor != COLOR4D::UNSPECIFIED )
2359 {
2360 COLOR_SWATCH* swatch = new COLOR_SWATCH( panel, color, layer,
2361 bgColor, defColor, SWATCH_SMALL );
2362 swatch->SetToolTip( _( "Left double click or middle click for color change, "
2363 "right click for menu" ) );
2364
2365 sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 );
2366 aSetting->ctl_color = swatch;
2367
2368 swatch->Bind( COLOR_SWATCH_CHANGED, &APPEARANCE_CONTROLS::OnColorSwatchChanged, this );
2369
2370 swatch->SetReadOnlyCallback( std::bind( &APPEARANCE_CONTROLS::onReadOnlySwatch, this ) );
2371 }
2372 else
2373 {
2374 sizer->AddSpacer( swatchWidth );
2375 }
2376
2377 BITMAP_TOGGLE* btn_visible = nullptr;
2378 wxString tip;
2379
2380 if( aSetting->can_control_visibility )
2381 {
2382 btn_visible = new BITMAP_TOGGLE( panel, layer,
2385 aSetting->visible );
2386
2387 tip.Printf( _( "Show or hide %s" ), aSetting->label.Lower() );
2388 btn_visible->SetToolTip( tip );
2389
2390 aSetting->ctl_visibility = btn_visible;
2391
2392 btn_visible->Bind( TOGGLE_CHANGED,
2393 [&]( wxCommandEvent& aEvent )
2394 {
2395 int id = static_cast<wxWindow*>( aEvent.GetEventObject() )->GetId();
2396 bool isVisible = aEvent.GetInt();
2397 onObjectVisibilityChanged( ToGalLayer( id ), isVisible, true );
2398 } );
2399 }
2400
2401 sizer->AddSpacer( 5 );
2402
2403 wxStaticText* label = new wxStaticText( panel, layer, aSetting->label );
2404 label->Wrap( -1 );
2405 label->SetToolTip( aSetting->tooltip );
2406
2407 if( aSetting->can_control_opacity )
2408 {
2409 label->SetMinSize( wxSize( labelWidth, -1 ) );
2410#ifdef __WXMAC__
2411 if( btn_visible )
2412 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, 10 );
2413 else
2414 sizer->AddSpacer( btnWidth );
2415
2416 sizer->AddSpacer( 5 );
2417 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, 10 );
2418#else
2419 if( btn_visible )
2420 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
2421 else
2422 sizer->AddSpacer( btnWidth );
2423
2424 sizer->AddSpacer( 5 );
2425 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL, 0 );
2426#endif
2427
2428 wxSlider* slider = new wxSlider( panel, wxID_ANY, 100, 0, 100,
2429 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
2430#ifdef __WXMAC__
2431 slider->SetMinSize( wxSize( 80, 16 ) );
2432#else
2433 slider->SetMinSize( wxSize( 80, -1 ) );
2434#endif
2435
2436 tip.Printf( _( "Set opacity of %s" ), aSetting->label.Lower() );
2437 slider->SetToolTip( tip );
2438
2439 sizer->Add( slider, 1, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5 );
2440 aSetting->ctl_opacity = slider;
2441
2442 auto opacitySliderHandler =
2443 [this, layer]( wxCommandEvent& aEvent )
2444 {
2445 wxSlider* ctrl = static_cast<wxSlider*>( aEvent.GetEventObject() );
2446 int value = ctrl->GetValue();
2447 onObjectOpacitySlider( layer, value / 100.0f );
2448 };
2449
2450 slider->Bind( wxEVT_SCROLL_CHANGED, opacitySliderHandler );
2451 slider->Bind( wxEVT_SCROLL_THUMBTRACK, opacitySliderHandler );
2452 slider->Bind( wxEVT_SET_FOCUS, &APPEARANCE_CONTROLS::OnSetFocus, this );
2453 }
2454 else
2455 {
2456 if( btn_visible )
2457 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
2458 else
2459 sizer->AddSpacer( btnWidth );
2460
2461 sizer->AddSpacer( 5 );
2462 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL, 0 );
2463 }
2464
2465 aSetting->ctl_text = label;
2466 m_objectsOuterSizer->Add( panel, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
2467
2468 if( !aSetting->can_control_opacity )
2469 m_objectsOuterSizer->AddSpacer( 2 );
2470 };
2471
2472 for( const APPEARANCE_SETTING& s_setting : s_objectSettings )
2473 {
2474 if( m_isFpEditor && !s_allowedInFpEditor.count( s_setting.id ) )
2475 continue;
2476
2477 m_objectSettings.emplace_back( std::make_unique<APPEARANCE_SETTING>( s_setting ) );
2478
2479 std::unique_ptr<APPEARANCE_SETTING>& setting = m_objectSettings.back();
2480
2481 // Because s_render_rows is created static, we must explicitly call wxGetTranslation
2482 // for texts which are internationalized (tool tips and item names)
2483 setting->tooltip = wxGetTranslation( s_setting.tooltip );
2484 setting->label = wxGetTranslation( s_setting.label );
2485
2486 if( setting->can_control_opacity )
2487 {
2488 int width = m_windowObjects->GetTextExtent( setting->label ).x + 5;
2489 labelWidth = std::max( labelWidth, width );
2490 }
2491
2492 if( !s_setting.spacer )
2493 m_objectSettingsMap[ToGalLayer( setting->id )] = setting.get();
2494 }
2495
2496 for( const std::unique_ptr<APPEARANCE_SETTING>& setting : m_objectSettings )
2497 {
2498 if( setting->spacer )
2499 m_objectsOuterSizer->AddSpacer( m_pointSize / 2 );
2500 else
2501 appendObject( setting );
2502 }
2503
2504 m_objectsOuterSizer->Layout();
2505 m_windowObjects->FitInside();
2506}
2507
2508
2510{
2511 GAL_SET visible = getVisibleObjects();
2512
2513 const PCB_DISPLAY_OPTIONS& opts = m_frame->GetDisplayOptions();
2514
2515 for( std::unique_ptr<APPEARANCE_SETTING>& setting : m_objectSettings )
2516 {
2517 if( setting->spacer )
2518 continue;
2519
2520 GAL_LAYER_ID layer = ToGalLayer( setting->id );
2521
2522 if( setting->ctl_visibility )
2523 setting->ctl_visibility->SetValue( visible.Contains( layer ) );
2524
2525 if( setting->ctl_color )
2526 {
2527 COLOR4D color = m_frame->GetColorSettings()->GetColor( setting->id );
2528 setting->ctl_color->SetSwatchColor( color, false );
2529 }
2530 }
2531
2532 wxASSERT( m_objectSettingsMap.count( LAYER_TRACKS )
2539
2540 m_objectSettingsMap[LAYER_TRACKS]->ctl_opacity->SetValue( opts.m_TrackOpacity * 100 );
2541 m_objectSettingsMap[LAYER_VIAS]->ctl_opacity->SetValue( opts.m_ViaOpacity * 100 );
2542 m_objectSettingsMap[LAYER_PADS]->ctl_opacity->SetValue( opts.m_PadOpacity * 100 );
2543 m_objectSettingsMap[LAYER_ZONES]->ctl_opacity->SetValue( opts.m_ZoneOpacity * 100 );
2544 m_objectSettingsMap[LAYER_DRAW_BITMAPS]->ctl_opacity->SetValue( opts.m_ImageOpacity * 100 );
2545 m_objectSettingsMap[LAYER_FILLED_SHAPES]->ctl_opacity->SetValue( opts.m_FilledShapeOpacity * 100 );
2546 m_objectSettingsMap[LAYER_OUTSIDE_GROUP_OPACITY]->ctl_opacity->SetValue( opts.m_OutsideGroupOpacity * 100 );
2547}
2548
2549
2550void APPEARANCE_CONTROLS::buildNetClassMenu( wxMenu& aMenu, bool isDefaultClass,
2551 const wxString& aName )
2552{
2553 BOARD* board = m_frame->GetBoard();
2554
2555 if( !board )
2556 return;
2557
2558 std::shared_ptr<NET_SETTINGS>& netSettings = board->GetDesignSettings().m_NetSettings;
2559
2560 if( !isDefaultClass)
2561 {
2562 aMenu.Append( new wxMenuItem( &aMenu, ID_SET_NET_COLOR, _( "Set Netclass Color" ),
2563 wxEmptyString, wxITEM_NORMAL ) );
2564
2565 wxMenuItem* schematicColor = new wxMenuItem( &aMenu, ID_USE_SCHEMATIC_NET_COLOR,
2566 _( "Use Color from Schematic" ),
2567 wxEmptyString, wxITEM_NORMAL );
2568 std::shared_ptr<NETCLASS> nc = netSettings->GetNetClassByName( aName );
2569 const KIGFX::COLOR4D ncColor = nc->GetSchematicColor();
2570 aMenu.Append( schematicColor );
2571
2572 if( ncColor == KIGFX::COLOR4D::UNSPECIFIED )
2573 schematicColor->Enable( false );
2574
2575 aMenu.Append( new wxMenuItem( &aMenu, ID_CLEAR_NET_COLOR, _( "Clear Netclass Color" ),
2576 wxEmptyString, wxITEM_NORMAL ) );
2577 aMenu.AppendSeparator();
2578 }
2579
2580 wxString name = UnescapeString( aName );
2581
2582 aMenu.Append( new wxMenuItem( &aMenu, ID_HIGHLIGHT_NET,
2583 wxString::Format( _( "Highlight Nets in %s" ), name ),
2584 wxEmptyString, wxITEM_NORMAL ) );
2585 aMenu.Append( new wxMenuItem( &aMenu, ID_SELECT_NET,
2586 wxString::Format( _( "Select Tracks and Vias in %s" ), name ),
2587 wxEmptyString, wxITEM_NORMAL ) );
2588 aMenu.Append( new wxMenuItem( &aMenu, ID_DESELECT_NET,
2589 wxString::Format( _( "Unselect Tracks and Vias in %s" ), name ),
2590 wxEmptyString, wxITEM_NORMAL ) );
2591
2592 aMenu.AppendSeparator();
2593
2594 aMenu.Append( new wxMenuItem( &aMenu, ID_SHOW_ALL_NETS, _( "Show All Netclasses" ),
2595 wxEmptyString, wxITEM_NORMAL ) );
2596 aMenu.Append( new wxMenuItem( &aMenu, ID_HIDE_OTHER_NETS, _( "Hide All Other Netclasses" ),
2597 wxEmptyString, wxITEM_NORMAL ) );
2598
2599 aMenu.Bind( wxEVT_COMMAND_MENU_SELECTED, &APPEARANCE_CONTROLS::onNetclassContextMenu, this );
2600
2601}
2602
2603
2605{
2606 BOARD* board = m_frame->GetBoard();
2607
2608 if( !board || !board->GetProject() )
2609 return;
2610
2611 COLOR_SETTINGS* theme = m_frame->GetColorSettings();
2612 COLOR4D bgColor = theme->GetColor( LAYER_PCB_BACKGROUND );
2613
2614 m_staticTextNets->SetLabel( _( "Nets" ) );
2615 m_staticTextNetClasses->SetLabel( _( "Net Classes" ) );
2616
2617 std::shared_ptr<NET_SETTINGS>& netSettings = board->GetDesignSettings().m_NetSettings;
2618
2619 const std::set<wxString>& hiddenClasses = m_frame->Prj().GetLocalSettings().m_HiddenNetclasses;
2620
2621 m_netclassSettings.clear();
2622 m_netclassSettingsMap.clear();
2623 m_netclassOuterSizer->Clear( true );
2624
2625 auto appendNetclass =
2626 [&]( int aId, const std::shared_ptr<NETCLASS>& aClass, bool isDefaultClass = false )
2627 {
2628 wxString name = aClass->GetName();
2629
2630 m_netclassSettings.emplace_back( std::make_unique<APPEARANCE_SETTING>() );
2631 APPEARANCE_SETTING* setting = m_netclassSettings.back().get();
2632 m_netclassSettingsMap[name] = setting;
2633
2634 setting->ctl_panel = new wxPanel( m_netclassScrolledWindow, aId );
2635 wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
2636 setting->ctl_panel->SetSizer( sizer );
2637
2638 COLOR4D color = netSettings->HasNetclass( name )
2639 ? netSettings->GetNetClassByName( name )->GetPcbColor()
2641
2642 setting->ctl_color = new COLOR_SWATCH( setting->ctl_panel, color, aId, bgColor,
2644 setting->ctl_color->SetToolTip( _( "Left double click or middle click for color "
2645 "change, right click for menu" ) );
2646
2647 setting->ctl_color->Bind( COLOR_SWATCH_CHANGED,
2649
2650 // Default netclass can't have an override color
2651 if( isDefaultClass )
2652 setting->ctl_color->Hide();
2653
2654 setting->ctl_visibility = new BITMAP_TOGGLE( setting->ctl_panel, aId,
2657 !hiddenClasses.count( name ) );
2658
2659 wxString tip;
2660 tip.Printf( _( "Show or hide ratsnest for nets in %s" ), name );
2661 setting->ctl_visibility->SetToolTip( tip );
2662
2663 setting->ctl_text = new wxStaticText( setting->ctl_panel, aId, name );
2664 setting->ctl_text->Wrap( -1 );
2665
2666 int flags = wxALIGN_CENTER_VERTICAL;
2667
2668 sizer->Add( setting->ctl_color, 0, flags | wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5 );
2669 sizer->AddSpacer( 7 );
2670 sizer->Add( setting->ctl_visibility, 0, flags, 5 );
2671 sizer->AddSpacer( 3 );
2672 sizer->Add( setting->ctl_text, 1, flags, 5 );
2673
2674 m_netclassOuterSizer->Add( setting->ctl_panel, 0, wxEXPAND, 5 );
2675 m_netclassOuterSizer->AddSpacer( 2 );
2676
2677 setting->ctl_visibility->Bind( TOGGLE_CHANGED,
2679 this );
2680
2681 auto menuHandler =
2682 [&, name, isDefaultClass]( wxMouseEvent& aEvent )
2683 {
2684 wxMenu menu;
2685 buildNetClassMenu( menu, isDefaultClass, name );
2686
2688 PopupMenu( &menu );
2689 };
2690
2691 setting->ctl_panel->Bind( wxEVT_RIGHT_DOWN, menuHandler );
2692 setting->ctl_visibility->Bind( wxEVT_RIGHT_DOWN, menuHandler );
2693 setting->ctl_color->Bind( wxEVT_RIGHT_DOWN, menuHandler );
2694 setting->ctl_text->Bind( wxEVT_RIGHT_DOWN, menuHandler );
2695 };
2696
2697 std::vector<wxString> names;
2698
2699 for( const auto& [name, netclass] : netSettings->GetNetclasses() )
2700 names.emplace_back( name );
2701
2702 std::sort( names.begin(), names.end() );
2703
2704 m_netclassIdMap.clear();
2705
2706 int idx = wxID_HIGHEST;
2707
2708 m_netclassIdMap[idx] = netSettings->GetDefaultNetclass()->GetName();
2709 appendNetclass( idx++, netSettings->GetDefaultNetclass(), true );
2710
2711 for( const wxString& name : names )
2712 {
2713 m_netclassIdMap[idx] = name;
2714 appendNetclass( idx++, netSettings->GetNetclasses().at( name ) );
2715 }
2716
2717 int hotkey;
2718 wxString msg;
2719
2720 m_paneNetDisplayOptions->SetLabel( _( "Net Display Options" ) );
2721
2722 hotkey = PCB_ACTIONS::netColorModeCycle.GetHotKey();
2723
2724 if( hotkey )
2725 msg = wxString::Format( _( "Net colors (%s):" ), KeyNameFromKeyCode( hotkey ) );
2726 else
2727 msg = _( "Net colors:" );
2728
2729 m_txtNetDisplayTitle->SetLabel( msg );
2730 m_txtNetDisplayTitle->SetToolTip( _( "Choose when to show net and netclass colors" ) );
2731
2732 m_rbNetColorAll->SetLabel( _( "All" ) );
2733 m_rbNetColorAll->SetToolTip( _( "Net and netclass colors are shown on all copper items" ) );
2734
2735 m_rbNetColorRatsnest->SetLabel( _( "Ratsnest" ) );
2736 m_rbNetColorRatsnest->SetToolTip( _( "Net and netclass colors are shown on the ratsnest only" ) );
2737
2738 m_rbNetColorOff->SetLabel( _( "None" ) );
2739 m_rbNetColorOff->SetToolTip( _( "Net and netclass colors are not shown" ) );
2740
2741 hotkey = PCB_ACTIONS::ratsnestModeCycle.GetHotKey();
2742
2743 if( hotkey )
2744 msg = wxString::Format( _( "Ratsnest display (%s):" ), KeyNameFromKeyCode( hotkey ) );
2745 else
2746 msg = _( "Ratsnest display:" );
2747
2748 m_txtRatsnestVisibility->SetLabel( msg );
2749 m_txtRatsnestVisibility->SetToolTip( _( "Choose which ratsnest lines to display" ) );
2750
2751 m_rbRatsnestAllLayers->SetLabel( _( "All" ) );
2752 m_rbRatsnestAllLayers->SetToolTip( _( "Show ratsnest lines to items on all layers" ) );
2753
2754 m_rbRatsnestVisLayers->SetLabel( _( "Visible layers" ) );
2755 m_rbRatsnestVisLayers->SetToolTip( _( "Show ratsnest lines to items on visible layers" ) );
2756
2757 m_rbRatsnestNone->SetLabel( _( "None" ) );
2758 m_rbRatsnestNone->SetToolTip( _( "Hide all ratsnest lines" ) );
2759
2760 m_netclassOuterSizer->Layout();
2761
2762 m_netsTable->Rebuild();
2763 m_panelNets->GetSizer()->Layout();
2764}
2765
2766
2768{
2769 m_presetsLabel->SetLabel( wxString::Format( _( "Presets (%s+Tab):" ), KeyNameFromKeyCode( PRESET_SWITCH_KEY ) ) );
2770
2771 m_cbLayerPresets->Clear();
2772
2773 if( aReset )
2774 m_presetMRU.clear();
2775
2776 // Build the layers preset list.
2777 // By default, the presetAllLayers will be selected
2778 int idx = 0;
2779 int default_idx = 0;
2780 std::vector<std::pair<wxString, void*>> userPresets;
2781
2782 // m_layerPresets is alphabetical: m_presetMRU should also be alphabetical, but m_cbLayerPresets
2783 // is split into build-in and user sections.
2784 for( auto& [name, preset] : m_layerPresets )
2785 {
2786 const wxString translatedName = wxGetTranslation( name );
2787 void* userData = static_cast<void*>( &preset );
2788
2789 if( preset.readOnly )
2790 m_cbLayerPresets->Append( translatedName, userData );
2791 else
2792 userPresets.push_back( { name, userData } );
2793
2794 if( aReset )
2795 m_presetMRU.push_back( translatedName );
2796
2797 if( name == presetAllLayers.name )
2798 default_idx = idx;
2799
2800 idx++;
2801 }
2802
2803 if( !userPresets.empty() )
2804 {
2805 m_cbLayerPresets->Append( wxT( "---" ) );
2806
2807 for( auto& [name, userData] : userPresets )
2808 m_cbLayerPresets->Append( name, userData );
2809 }
2810
2811 m_cbLayerPresets->Append( wxT( "---" ) );
2812 m_cbLayerPresets->Append( _( "Save preset..." ) );
2813 m_cbLayerPresets->Append( _( "Delete preset..." ) );
2814
2815 // At least the built-in presets should always be present
2816 wxASSERT( !m_layerPresets.empty() );
2817
2818 if( aReset )
2819 {
2820 // Default preset: all layers
2821 m_cbLayerPresets->SetSelection( default_idx );
2823 }
2824}
2825
2826
2828{
2829 LSET visibleLayers = getVisibleLayers();
2830 GAL_SET visibleObjects = getVisibleObjects();
2831 bool flipBoard = m_cbFlipBoard->GetValue();
2832
2833 auto it = std::find_if( m_layerPresets.begin(), m_layerPresets.end(),
2834 [&]( const std::pair<const wxString, LAYER_PRESET>& aPair )
2835 {
2836 // see onLayerPresetChanged logic for built-in presets
2837 const GAL_SET& presetObjects = aPair.second.readOnly
2838 ? m_lastBuiltinPreset.renderLayers
2839 : aPair.second.renderLayers;
2840
2841 return ( aPair.second.layers == visibleLayers
2842 && presetObjects == visibleObjects
2843 && aPair.second.flipBoard == flipBoard );
2844 } );
2845
2846 if( it != m_layerPresets.end() )
2847 {
2848 // Select the right m_cbLayersPresets item.
2849 // but these items are translated if they are predefined items.
2850 bool do_translate = it->second.readOnly;
2851 wxString text = do_translate ? wxGetTranslation( it->first ) : it->first;
2852
2853 m_cbLayerPresets->SetStringSelection( text );
2854 }
2855 else
2856 {
2857 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 ); // separator
2858 }
2859
2860 m_currentPreset = static_cast<LAYER_PRESET*>( m_cbLayerPresets->GetClientData( m_cbLayerPresets->GetSelection() ) );
2861}
2862
2863
2865{
2866 // look at m_layerPresets to know if aName is a read only preset, or a user preset.
2867 // Read only presets have translated names in UI, so we have to use
2868 // a translated name in UI selection.
2869 // But for a user preset name we should search for aName (not translated)
2870 wxString ui_label = aName;
2871
2872 for( std::pair<const wxString, LAYER_PRESET>& pair : m_layerPresets )
2873 {
2874 if( pair.first != aName )
2875 continue;
2876
2877 if( pair.second.readOnly == true )
2878 ui_label = wxGetTranslation( aName );
2879
2880 break;
2881 }
2882
2883 int idx = m_cbLayerPresets->FindString( ui_label );
2884
2885 if( idx >= 0 && m_cbLayerPresets->GetSelection() != idx )
2886 {
2887 m_cbLayerPresets->SetSelection( idx );
2888 m_currentPreset = static_cast<LAYER_PRESET*>( m_cbLayerPresets->GetClientData( idx ) );
2889 }
2890 else if( idx < 0 )
2891 {
2892 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 ); // separator
2893 }
2894}
2895
2896
2897void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent )
2898{
2899 int count = m_cbLayerPresets->GetCount();
2900 int index = m_cbLayerPresets->GetSelection();
2901
2902 auto resetSelection =
2903 [&]()
2904 {
2905 if( m_currentPreset )
2906 m_cbLayerPresets->SetStringSelection( m_currentPreset->name );
2907 else
2908 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 );
2909 };
2910
2911 if( index == count - 2 )
2912 {
2913 // Save current state to new preset
2914 wxString name;
2915
2918
2919 wxTextEntryDialog dlg( wxGetTopLevelParent( this ), _( "Layer preset name:" ),
2920 _( "Save Layer Preset" ), name );
2921
2922 if( dlg.ShowModal() != wxID_OK )
2923 {
2924 resetSelection();
2925 return;
2926 }
2927
2928 name = dlg.GetValue();
2929 bool exists = m_layerPresets.count( name );
2930
2931 if( !exists )
2932 {
2934 UNSELECTED_LAYER, m_cbFlipBoard->GetValue() );
2935 }
2936
2937 LAYER_PRESET* preset = &m_layerPresets[name];
2938
2939 if( !exists )
2940 {
2942 index = m_cbLayerPresets->FindString( name );
2943 }
2944 else if( preset->readOnly )
2945 {
2946 wxMessageBox( _( "Default presets cannot be modified.\nPlease use a different name." ),
2947 _( "Error" ), wxOK | wxICON_ERROR, wxGetTopLevelParent( this ) );
2948 resetSelection();
2949 return;
2950 }
2951 else
2952 {
2953 // Ask the user if they want to overwrite the existing preset
2954 if( !IsOK( wxGetTopLevelParent( this ), _( "Overwrite existing preset?" ) ) )
2955 {
2956 resetSelection();
2957 return;
2958 }
2959
2960 preset->layers = getVisibleLayers();
2961 preset->renderLayers = getVisibleObjects();
2962 preset->flipBoard = m_cbFlipBoard->GetValue();
2963
2964 index = m_cbLayerPresets->FindString( name );
2965
2966 if( m_presetMRU.Index( name ) != wxNOT_FOUND )
2967 m_presetMRU.Remove( name );
2968 }
2969
2970 m_currentPreset = preset;
2971 m_cbLayerPresets->SetSelection( index );
2972 m_presetMRU.Insert( name, 0 );
2973
2974 return;
2975 }
2976 else if( index == count - 1 )
2977 {
2978 // Delete a preset
2979 wxArrayString headers;
2980 std::vector<wxArrayString> items;
2981
2982 headers.Add( _( "Presets" ) );
2983
2984 for( std::pair<const wxString, LAYER_PRESET>& pair : m_layerPresets )
2985 {
2986 if( !pair.second.readOnly )
2987 {
2988 wxArrayString item;
2989 item.Add( pair.first );
2990 items.emplace_back( item );
2991 }
2992 }
2993
2994 EDA_LIST_DIALOG dlg( m_frame, _( "Delete Preset" ), headers, items );
2995 dlg.SetListLabel( _( "Select preset:" ) );
2996
2997 if( dlg.ShowModal() == wxID_OK )
2998 {
2999 wxString presetName = dlg.GetTextSelection();
3000 int idx = m_cbLayerPresets->FindString( presetName );
3001
3002 if( idx != wxNOT_FOUND )
3003 {
3004 if( m_lastSelectedUserPreset && m_lastSelectedUserPreset->name == presetName )
3005 m_lastSelectedUserPreset = nullptr;
3006
3007 if( m_currentPreset && m_currentPreset->name == presetName )
3008 m_currentPreset = nullptr;
3009
3010 m_layerPresets.erase( presetName );
3011
3012 m_cbLayerPresets->Delete( idx );
3013 }
3014
3015 if( m_presetMRU.Index( presetName ) != wxNOT_FOUND )
3016 m_presetMRU.Remove( presetName );
3017 }
3018
3019 resetSelection();
3020 return;
3021 }
3022 else if( m_cbLayerPresets->GetString( index ) == wxT( "---" ) )
3023 {
3024 // Separator: reject the selection
3025 resetSelection();
3026 return;
3027 }
3028
3029 // Store the objects visibility settings if the preset is not a user preset,
3030 // to be reused when selecting a new built-in layer preset, even if a previous
3031 // user preset has changed the object visibility
3032 if( !m_currentPreset || m_currentPreset->readOnly )
3033 {
3034 m_lastBuiltinPreset.renderLayers = getVisibleObjects();
3035 }
3036
3037 LAYER_PRESET* preset = static_cast<LAYER_PRESET*>( m_cbLayerPresets->GetClientData( index ) );
3038 m_currentPreset = preset;
3039
3040 m_lastSelectedUserPreset = ( !preset || preset->readOnly ) ? nullptr : preset;
3041
3042 if( preset )
3043 {
3044 // Change board layers visibility, but do not change objects visibility
3045 LAYER_PRESET curr_layers_choice = *preset;
3046
3047 // For predefined presets that do not manage objects visibility, use
3048 // the objects visibility settings of the last used predefined preset.
3049 if( curr_layers_choice.readOnly )
3050 curr_layers_choice.renderLayers = m_lastBuiltinPreset.renderLayers;
3051
3052 doApplyLayerPreset( curr_layers_choice );
3053 }
3054
3055 if( !m_currentPreset->name.IsEmpty() )
3056 {
3057 const wxString translatedName = wxGetTranslation( m_currentPreset->name );
3058
3059 if( m_presetMRU.Index( translatedName ) != wxNOT_FOUND )
3060 m_presetMRU.Remove( translatedName );
3061
3062 m_presetMRU.Insert( translatedName, 0 );
3063 }
3064
3065 passOnFocus();
3066}
3067
3068
3070{
3071 BOARD* board = m_frame->GetBoard();
3072
3073 if( !board )
3074 return;
3075
3076 setVisibleLayers( aPreset.layers );
3078
3079 // If the preset doesn't have an explicit active layer to restore, we can at least
3080 // force the active layer to be something in the preset's layer set
3081 PCB_LAYER_ID activeLayer = UNSELECTED_LAYER;
3082
3083 if( aPreset.activeLayer != UNSELECTED_LAYER )
3084 activeLayer = aPreset.activeLayer;
3085 else if( aPreset.layers.any() && !aPreset.layers.test( m_frame->GetActiveLayer() ) )
3086 activeLayer = *aPreset.layers.Seq().begin();
3087
3088 LSET boardLayers = board->GetLayerSet();
3089
3090 if( activeLayer != UNSELECTED_LAYER && boardLayers.Contains( activeLayer ) )
3091 m_frame->SetActiveLayer( activeLayer );
3092
3093 if( !m_isFpEditor )
3094 m_frame->GetCanvas()->SyncLayersVisibility( board );
3095
3096 PCB_DISPLAY_OPTIONS options = m_frame->GetDisplayOptions();
3097 options.m_FlipBoardView = aPreset.flipBoard;
3098 m_frame->SetDisplayOptions( options, false );
3099
3100 m_frame->GetCanvas()->Refresh();
3101
3104}
3105
3106
3108{
3109 m_viewportsLabel->SetLabel( wxString::Format( _( "Viewports (%s+Tab):" ),
3111
3112 m_cbViewports->Clear();
3113
3114 for( std::pair<const wxString, VIEWPORT>& pair : m_viewports )
3115 m_cbViewports->Append( pair.first, static_cast<void*>( &pair.second ) );
3116
3117 m_cbViewports->Append( wxT( "---" ) );
3118 m_cbViewports->Append( _( "Save viewport..." ) );
3119 m_cbViewports->Append( _( "Delete viewport..." ) );
3120
3121 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 );
3122 m_lastSelectedViewport = nullptr;
3123}
3124
3125
3127{
3128 int idx = m_cbViewports->FindString( aName );
3129
3130 if( idx >= 0 && idx < (int)m_cbViewports->GetCount() - 3 /* separator */ )
3131 {
3132 m_cbViewports->SetSelection( idx );
3133 m_lastSelectedViewport = static_cast<VIEWPORT*>( m_cbViewports->GetClientData( idx ) );
3134 }
3135 else if( idx < 0 )
3136 {
3137 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 ); // separator
3138 m_lastSelectedViewport = nullptr;
3139 }
3140}
3141
3142
3143void APPEARANCE_CONTROLS::onViewportChanged( wxCommandEvent& aEvent )
3144{
3145 int count = m_cbViewports->GetCount();
3146 int index = m_cbViewports->GetSelection();
3147
3148 if( index >= 0 && index < count - 3 )
3149 {
3150 VIEWPORT* viewport = static_cast<VIEWPORT*>( m_cbViewports->GetClientData( index ) );
3151
3152 wxCHECK( viewport, /* void */ );
3153
3154 doApplyViewport( *viewport );
3155
3156 if( !viewport->name.IsEmpty() )
3157 {
3158 if( m_viewportMRU.Index( viewport->name ) != wxNOT_FOUND )
3159 m_viewportMRU.Remove( viewport->name );
3160
3161 m_viewportMRU.Insert( viewport->name, 0 );
3162 }
3163 }
3164 else if( index == count - 2 )
3165 {
3166 // Save current state to new preset
3167 wxString name;
3168
3169 wxTextEntryDialog dlg( wxGetTopLevelParent( this ), _( "Viewport name:" ), _( "Save Viewport" ), name );
3170
3171 if( dlg.ShowModal() != wxID_OK )
3172 {
3174 m_cbViewports->SetStringSelection( m_lastSelectedViewport->name );
3175 else
3176 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 );
3177
3178 return;
3179 }
3180
3181 name = dlg.GetValue();
3182 bool exists = m_viewports.count( name );
3183
3184 if( !exists )
3185 {
3186 m_viewports[name] = VIEWPORT( name, m_frame->GetCanvas()->GetView()->GetViewport() );
3187
3188 index = m_cbViewports->Insert( name, index-1, static_cast<void*>( &m_viewports[name] ) );
3189 }
3190 else
3191 {
3192 m_viewports[name].rect = m_frame->GetCanvas()->GetView()->GetViewport();
3193 index = m_cbViewports->FindString( name );
3194
3195 if( m_viewportMRU.Index( name ) != wxNOT_FOUND )
3196 m_viewportMRU.Remove( name );
3197 }
3198
3199 m_cbViewports->SetSelection( index );
3200 m_viewportMRU.Insert( name, 0 );
3201
3202 return;
3203 }
3204 else if( index == count - 1 )
3205 {
3206 // Delete an existing viewport
3207 wxArrayString headers;
3208 std::vector<wxArrayString> items;
3209
3210 headers.Add( _( "Viewports" ) );
3211
3212 for( std::pair<const wxString, VIEWPORT>& pair : m_viewports )
3213 {
3214 wxArrayString item;
3215 item.Add( pair.first );
3216 items.emplace_back( item );
3217 }
3218
3219 EDA_LIST_DIALOG dlg( m_frame, _( "Delete Viewport" ), headers, items );
3220 dlg.SetListLabel( _( "Select viewport:" ) );
3221
3222 if( dlg.ShowModal() == wxID_OK )
3223 {
3224 wxString viewportName = dlg.GetTextSelection();
3225 int idx = m_cbViewports->FindString( viewportName );
3226
3227 if( idx != wxNOT_FOUND )
3228 {
3229 if( m_lastSelectedViewport && m_lastSelectedViewport->name == viewportName )
3230 m_lastSelectedViewport = nullptr;
3231
3232 m_viewports.erase( viewportName );
3233 m_cbViewports->Delete( idx );
3234 }
3235
3236 if( m_viewportMRU.Index( viewportName ) != wxNOT_FOUND )
3237 m_viewportMRU.Remove( viewportName );
3238 }
3239
3241 m_cbViewports->SetStringSelection( m_lastSelectedViewport->name );
3242 else
3243 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 );
3244
3245 return;
3246 }
3247
3248 passOnFocus();
3249}
3250
3251
3253{
3254 m_frame->GetCanvas()->GetView()->SetViewport( aViewport.rect );
3255 m_frame->GetCanvas()->Refresh();
3256}
3257
3258
3259void APPEARANCE_CONTROLS::OnColorSwatchChanged( wxCommandEvent& aEvent )
3260{
3261 COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
3262 COLOR4D newColor = swatch->GetSwatchColor();
3263 int layer = swatch->GetId();
3264
3265 COLOR_SETTINGS* cs = m_frame->GetColorSettings();
3266
3267 cs->SetColor( layer, newColor );
3268 m_frame->GetSettingsManager()->SaveColorSettings( cs, "board" );
3269
3270 m_frame->GetCanvas()->UpdateColors();
3271
3272 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
3273 view->UpdateLayerColor( layer );
3274 view->UpdateLayerColor( GetNetnameLayer( layer ) );
3275
3276 if( IsCopperLayer( layer ) )
3277 {
3278 view->UpdateLayerColor( ZONE_LAYER_FOR( layer ) );
3279 view->UpdateLayerColor( VIA_COPPER_LAYER_FOR( layer ) );
3280 view->UpdateLayerColor( PAD_COPPER_LAYER_FOR( layer ) );
3281 view->UpdateLayerColor( CLEARANCE_LAYER_FOR( layer ) );
3282 }
3283
3284 // Update the bitmap of the layer box
3285 if( m_frame->IsType( FRAME_PCB_EDITOR ) )
3286 static_cast<PCB_EDIT_FRAME*>( m_frame )->ReCreateLayerBox( false );
3287
3288 m_frame->GetCanvas()->Refresh();
3289
3290 if( layer == LAYER_PCB_BACKGROUND )
3291 m_frame->SetDrawBgColor( newColor );
3292
3293 passOnFocus();
3294}
3295
3296
3297void APPEARANCE_CONTROLS::onObjectOpacitySlider( int aLayer, float aOpacity )
3298{
3299 PCB_DISPLAY_OPTIONS options = m_frame->GetDisplayOptions();
3300
3301 switch( aLayer )
3302 {
3303 case static_cast<int>( LAYER_TRACKS ): options.m_TrackOpacity = aOpacity; break;
3304 case static_cast<int>( LAYER_VIAS ): options.m_ViaOpacity = aOpacity; break;
3305 case static_cast<int>( LAYER_PADS ): options.m_PadOpacity = aOpacity; break;
3306 case static_cast<int>( LAYER_ZONES ): options.m_ZoneOpacity = aOpacity; break;
3307 case static_cast<int>( LAYER_DRAW_BITMAPS ): options.m_ImageOpacity = aOpacity; break;
3308 case static_cast<int>( LAYER_FILLED_SHAPES ): options.m_FilledShapeOpacity = aOpacity; break;
3309 case static_cast<int>( LAYER_OUTSIDE_GROUP_OPACITY ): options.m_OutsideGroupOpacity = aOpacity; break;
3310 default: return;
3311 }
3312
3313 m_frame->SetDisplayOptions( options );
3314 passOnFocus();
3315}
3316
3317
3318void APPEARANCE_CONTROLS::onNetContextMenu( wxCommandEvent& aEvent )
3319{
3320 wxASSERT( m_netsGrid->GetSelectedRows().size() == 1 );
3321
3322 int row = m_netsGrid->GetSelectedRows()[0];
3323 const NET_GRID_ENTRY& net = m_netsTable->GetEntry( row );
3324
3325 m_netsGrid->ClearSelection();
3326
3327 switch( aEvent.GetId() )
3328 {
3329 case ID_SET_NET_COLOR:
3330 {
3331 wxGridCellEditor* editor = m_netsGrid->GetCellEditor( row, NET_GRID_TABLE::COL_COLOR );
3332
3333 if( editor )
3334 {
3335 editor->BeginEdit( row, NET_GRID_TABLE::COL_COLOR, m_netsGrid );
3336 editor->DecRef();
3337 }
3338
3339 break;
3340 }
3341
3342 case ID_CLEAR_NET_COLOR:
3343 m_netsGrid->SetCellValue( row, NET_GRID_TABLE::COL_COLOR, wxS( "rgba(0,0,0,0)" ) );
3344 break;
3345
3346 case ID_HIGHLIGHT_NET:
3347 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::highlightNet, net.code );
3348 m_frame->GetCanvas()->Refresh();
3349 break;
3350
3351 case ID_SELECT_NET:
3352 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::selectNet, net.code );
3353 m_frame->GetCanvas()->Refresh();
3354 break;
3355
3356 case ID_DESELECT_NET:
3357 m_frame->GetToolManager()->RunAction( PCB_ACTIONS::deselectNet, net.code );
3358 m_frame->GetCanvas()->Refresh();
3359 break;
3360
3361 case ID_SHOW_ALL_NETS:
3362 m_netsTable->ShowAllNets();
3363 break;
3364
3365 case ID_HIDE_OTHER_NETS:
3366 m_netsTable->HideOtherNets( net );
3367 break;
3368
3369 default:
3370 break;
3371 }
3372
3373 passOnFocus();
3374}
3375
3376
3378{
3379 wxString className = netclassNameFromEvent( aEvent );
3380 bool show = aEvent.GetInt();
3381 showNetclass( className, show );
3382 passOnFocus();
3383}
3384
3385
3386void APPEARANCE_CONTROLS::showNetclass( const wxString& aClassName, bool aShow )
3387{
3388 BOARD* board = m_frame->GetBoard();
3389
3390 if( !board )
3391 return;
3392
3394
3395 for( NETINFO_ITEM* net : board->GetNetInfo() )
3396 {
3397 if( net->GetNetClass()->ContainsNetclassWithName( aClassName ) )
3398 {
3399 m_frame->GetToolManager()->RunAction( aShow ? PCB_ACTIONS::showNetInRatsnest
3401 net->GetNetCode() );
3402
3403 int row = m_netsTable->GetRowByNetcode( net->GetNetCode() );
3404
3405 if( row >= 0 )
3406 m_netsTable->SetVisibilityState( row, aShow );
3407 }
3408 }
3409
3410 PROJECT_LOCAL_SETTINGS& localSettings = m_frame->Prj().GetLocalSettings();
3411
3412 if( !aShow )
3413 localSettings.m_HiddenNetclasses.insert( aClassName );
3414 else
3415 localSettings.m_HiddenNetclasses.erase( aClassName );
3416
3417 m_netsGrid->ForceRefresh();
3418 m_frame->GetCanvas()->RedrawRatsnest();
3419 m_frame->GetCanvas()->Refresh();
3421}
3422
3423
3425{
3426 BOARD* board = m_frame->GetBoard();
3427
3428 if( !board )
3429 return;
3430
3431 COLOR_SWATCH* swatch = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
3432 wxString netclassName = netclassNameFromEvent( aEvent );
3433
3434 std::shared_ptr<NET_SETTINGS>& netSettings = board->GetDesignSettings().m_NetSettings;
3435 std::shared_ptr<NETCLASS> nc = netSettings->GetNetClassByName( netclassName );
3436
3437 nc->SetPcbColor( swatch->GetSwatchColor() );
3438 netSettings->RecomputeEffectiveNetclasses();
3439
3440 m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
3441 m_frame->GetCanvas()->RedrawRatsnest();
3442 m_frame->GetCanvas()->Refresh();
3443}
3444
3445
3447{
3448 COLOR_SWATCH* s = static_cast<COLOR_SWATCH*>( aEvent.GetEventObject() );
3449 int classId = s->GetId();
3450
3451 wxASSERT( m_netclassIdMap.count( classId ) );
3452 return m_netclassIdMap.at( classId );
3453}
3454
3455
3456void APPEARANCE_CONTROLS::onNetColorMode( wxCommandEvent& aEvent )
3457{
3458 PCB_DISPLAY_OPTIONS options = m_frame->GetDisplayOptions();
3459
3460 if( m_rbNetColorAll->GetValue() )
3462 else if( m_rbNetColorRatsnest->GetValue() )
3464 else
3466
3467 m_frame->SetDisplayOptions( options );
3468 m_frame->GetCanvas()->GetView()->UpdateAllLayersColor();
3469 passOnFocus();
3470}
3471
3472
3473void APPEARANCE_CONTROLS::onRatsnestMode( wxCommandEvent& aEvent )
3474{
3475 if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
3476 {
3477 if( m_rbRatsnestAllLayers->GetValue() )
3478 {
3479 cfg->m_Display.m_ShowGlobalRatsnest = true;
3480 cfg->m_Display.m_RatsnestMode = RATSNEST_MODE::ALL;
3481 }
3482 else if( m_rbRatsnestVisLayers->GetValue() )
3483 {
3484 cfg->m_Display.m_ShowGlobalRatsnest = true;
3485 cfg->m_Display.m_RatsnestMode = RATSNEST_MODE::VISIBLE;
3486 }
3487 else
3488 {
3489 cfg->m_Display.m_ShowGlobalRatsnest = false;
3490 }
3491 }
3492
3493 if( PCB_EDIT_FRAME* editframe = dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
3494 {
3495 if( PCBNEW_SETTINGS* cfg = m_frame->GetPcbNewSettings() )
3496 editframe->SetElementVisibility( LAYER_RATSNEST, cfg->m_Display.m_ShowGlobalRatsnest );
3497
3498 editframe->OnDisplayOptionsChanged();
3499 editframe->GetCanvas()->RedrawRatsnest();
3500 editframe->GetCanvas()->Refresh();
3501 }
3502
3503 passOnFocus();
3504}
3505
3506
3508{
3509 BOARD* board = m_frame->GetBoard();
3510
3511 if( !board )
3512 return;
3513
3514 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
3516 static_cast<KIGFX::PCB_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
3517
3518 std::shared_ptr<NET_SETTINGS>& netSettings = board->GetDesignSettings().m_NetSettings;
3519 APPEARANCE_SETTING* setting = nullptr;
3520
3522
3523 if( it != m_netclassSettingsMap.end() )
3524 setting = it->second;
3525
3526 auto runOnNetsOfClass =
3527 [&]( const wxString& netClassName, std::function<void( NETINFO_ITEM* )> aFunction )
3528 {
3529 for( NETINFO_ITEM* net : board->GetNetInfo() )
3530 {
3531 if( net->GetNetClass()->ContainsNetclassWithName( netClassName ) )
3532 aFunction( net );
3533 }
3534 };
3535
3536 switch( aEvent.GetId() )
3537 {
3538 case ID_SET_NET_COLOR:
3539 {
3540 if( setting )
3541 {
3542 setting->ctl_color->GetNewSwatchColor();
3543
3544 COLOR4D color = setting->ctl_color->GetSwatchColor();
3545
3546 if( color != COLOR4D::UNSPECIFIED )
3547 {
3548 netSettings->GetNetClassByName( m_contextMenuNetclass )->SetPcbColor( color );
3549 netSettings->RecomputeEffectiveNetclasses();
3550 }
3551
3552 view->UpdateAllLayersColor();
3553 }
3554
3555 break;
3556 }
3557
3558 case ID_CLEAR_NET_COLOR:
3559 {
3560 if( setting )
3561 {
3562 setting->ctl_color->SetSwatchColor( COLOR4D( 0, 0, 0, 0 ), true );
3563
3564 netSettings->GetNetClassByName( m_contextMenuNetclass )->SetPcbColor( COLOR4D::UNSPECIFIED );
3565 netSettings->RecomputeEffectiveNetclasses();
3566
3567 view->UpdateAllLayersColor();
3568 }
3569
3570 break;
3571 }
3572
3574 {
3575 if( setting )
3576 {
3577 std::shared_ptr<NETCLASS> nc = netSettings->GetNetClassByName( m_contextMenuNetclass );
3578 const KIGFX::COLOR4D ncColor = nc->GetSchematicColor();
3579
3580 setting->ctl_color->SetSwatchColor( ncColor, true );
3581
3582 netSettings->GetNetClassByName( m_contextMenuNetclass )->SetPcbColor( ncColor );
3583 netSettings->RecomputeEffectiveNetclasses();
3584
3585 view->UpdateAllLayersColor();
3586 }
3587
3588 break;
3589 }
3590
3591 case ID_HIGHLIGHT_NET:
3592 {
3593 if( !m_contextMenuNetclass.IsEmpty() )
3594 {
3595 board->ResetNetHighLight();
3596 rs->SetHighlight( false );
3597
3598 runOnNetsOfClass( m_contextMenuNetclass,
3599 [&]( const NETINFO_ITEM* aItem )
3600 {
3601 int code = aItem->GetNetCode();
3602
3603 board->SetHighLightNet( code, true );
3604 rs->SetHighlight( true, code, true );
3605 } );
3606
3607 view->UpdateAllLayersColor();
3608 board->HighLightON();
3609 }
3610
3611 break;
3612 }
3613
3614 case ID_SELECT_NET:
3615 case ID_DESELECT_NET:
3616 {
3617 if( !m_contextMenuNetclass.IsEmpty() )
3618 {
3619 TOOL_MANAGER* toolMgr = m_frame->GetToolManager();
3620 TOOL_ACTION& action = aEvent.GetId() == ID_SELECT_NET ? PCB_ACTIONS::selectNet
3622
3623 runOnNetsOfClass( m_contextMenuNetclass,
3624 [&]( NETINFO_ITEM* aItem )
3625 {
3626 toolMgr->RunAction( action, aItem->GetNetCode() );
3627 } );
3628 }
3629 break;
3630 }
3631
3632
3633 case ID_SHOW_ALL_NETS:
3634 {
3636 wxASSERT( m_netclassSettingsMap.count( NETCLASS::Default ) );
3637 m_netclassSettingsMap.at( NETCLASS::Default )->ctl_visibility->SetValue( true );
3638
3639 for( const auto& [name, netclass] : netSettings->GetNetclasses() )
3640 {
3641 showNetclass( name );
3642
3643 if( m_netclassSettingsMap.count( name ) )
3644 m_netclassSettingsMap.at( name )->ctl_visibility->SetValue( true );
3645 }
3646
3647 break;
3648 }
3649
3650 case ID_HIDE_OTHER_NETS:
3651 {
3652 bool showDefault = m_contextMenuNetclass == NETCLASS::Default;
3653 showNetclass( NETCLASS::Default, showDefault );
3654 wxASSERT( m_netclassSettingsMap.count( NETCLASS::Default ) );
3655 m_netclassSettingsMap.at( NETCLASS::Default )->ctl_visibility->SetValue( showDefault );
3656
3657 for( const auto& [name, netclass] : netSettings->GetNetclasses() )
3658 {
3659 bool show = ( name == m_contextMenuNetclass );
3660
3661 showNetclass( name, show );
3662
3663 if( m_netclassSettingsMap.count( name ) )
3664 m_netclassSettingsMap.at( name )->ctl_visibility->SetValue( show );
3665 }
3666
3667 break;
3668 }
3669
3670 default:
3671 break;
3672 }
3673
3674 m_frame->GetCanvas()->RedrawRatsnest();
3675 m_frame->GetCanvas()->Refresh();
3676
3677 m_contextMenuNetclass.clear();
3678}
3679
3680
3682{
3683 m_focusOwner->SetFocus();
3684}
3685
3686
3688{
3689 WX_INFOBAR* infobar = m_frame->GetInfoBar();
3690
3691 infobar->RemoveAllButtons();
3692 infobar->AddLink( _( "Open Preferences" ),
3693 [&]( wxHyperlinkEvent& aEvent )
3694 {
3695 m_frame->ShowPreferences( wxEmptyString, wxEmptyString );
3696 } );
3697 infobar->AddCloseButton();
3698
3699 infobar->ShowMessageFor( _( "The current color theme is read-only. Create a new theme in Preferences to "
3700 "enable color editing." ),
3701 10000, wxICON_INFORMATION );
3702}
3703
3704
3709
3710
int index
const char * name
static std::set< int > s_allowedInFpEditor
These GAL layers are shown in the Objects tab in the footprint editor.
#define RR
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition bitmap.cpp:100
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
@ show_all_back_layers
@ show_front_assembly_layers
@ options_generic
@ show_back_assembly_layers
@ show_all_front_layers
@ show_no_copper_layers
@ show_all_layers
@ show_all_copper_layers
HIGH_CONTRAST_MODE
Determine how inactive layers should be displayed.
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
@ HIDDEN
Inactive layers are hidden.
@ DIMMED
Inactive layers are dimmed (old high-contrast mode)
@ RATSNEST
Net/netclass colors are shown on ratsnest lines only.
@ ALL
Net/netclass colors are shown on all net copper.
@ OFF
Net (and netclass) colors are not shown.
@ VISIBLE
Ratsnest lines are drawn to items on visible layers only.
@ ALL
Ratsnest lines are drawn to items on all layers (default)
static TOOL_ACTION highContrastModeCycle
Definition actions.h:153
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)
wxScrolledWindow * m_netclassScrolledWindow
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.
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
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)
wxGridCellCoords m_hoveredCell
Grid cell that is being hovered over, for tooltips.
void showNetclass(const wxString &aClassName, bool aShow=true)
wxStaticText * m_txtRatsnestVisibility
void OnBoardChanged()
Update the panel contents from the application and board models.
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)
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
BASE_SET & set(size_t pos)
Definition base_set.h:126
A checkbox control except with custom bitmaps for the checked and unchecked states.
void SetValue(bool aValue)
Set the checkbox state.
std::shared_ptr< NET_SETTINGS > m_NetSettings
std::map< std::string, wxString > m_UserLayerNames
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:369
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Return an "English Standard" name of a PCB layer when given aLayerNumber.
Definition board.h:1131
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition board.h:908
void SetHighLightNet(int aNetCode, bool aMulti=false)
Select the netcode to be highlighted.
Definition board.cpp:3940
void ResetNetHighLight()
Reset all high light data to the init state.
Definition board.cpp:3931
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Change the visibility of an element category.
Definition board.cpp:1275
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:960
PROJECT * GetProject() const
Definition board.h:774
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1202
void HighLightON(bool aValue=true)
Enable or disable net highlighting.
Definition board.cpp:3955
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
void SetVisibleElements(const GAL_SET &aMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1242
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
Color settings are a bit different than most of the settings objects in that there can be more than o...
COLOR4D GetColor(int aLayer) const
COLOR4D GetDefaultColor(int aLayer)
A simple color swatch of the kind used to set layer colors.
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
void GetNewSwatchColor()
Prompt for a new colour, using the colour picker dialog.
KIGFX::COLOR4D GetSwatchColor() const
void SetReadOnlyCallback(std::function< void()> aCallback)
Register a handler for when the user tries to interact with a read-only swatch.
void SetReadOnly(bool aReadOnly=true)
int ShowModal() override
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
double GetScaleFactor() const override
Get the DPI scale from all known sources in order:
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
A dialog which shows:
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
void SetListLabel(const wxString &aLabel)
BOARD_DESIGN_SETTINGS m_DesignSettings
Only some of these settings are actually used for footprint editing.
Helper for storing and iterating over GAL_LAYER_IDs.
Definition layer_ids.h:434
bool Contains(GAL_LAYER_ID aPos)
Definition layer_ids.h:468
GAL_SET & set()
Definition layer_ids.h:450
static GAL_SET DefaultVisible()
Definition lset.cpp:782
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
A text renderer that can unescape text for display This is useful where it's desired to keep the unde...
Represent a row indicator icon for use in places like the layer widget.
void SetIndicatorState(ICON_ID aIconId)
Set the row indicator to the given state.
bool IsReadOnly() const
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
bool SetFromWxString(const wxString &aColorString)
Set color values by parsing a string using wxColour::Set().
Definition color4d.cpp:127
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:400
virtual bool HasRetainedScene() const
Return true if the backend keeps cached groups in a persistent scene that it patches in place,...
PCB specific render settings.
Definition pcb_painter.h:94
std::set< int > & GetHiddenNets()
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
bool IsBOARD_ITEM() const
Definition view_item.h:98
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
void UpdateAllLayersColor()
Apply the new coloring scheme to all layers.
Definition view.cpp:1171
void SetLayerVisible(int aLayer, bool aVisible=true)
Control the visibility of a particular layer.
Definition view.h:431
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:224
void UpdateLayerColor(int aLayer)
Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
Definition view.cpp:1126
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition view.h:457
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition view.cpp:2491
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & FrontMask()
Return a mask holding all technical layers and the external CU layer on front side.
Definition lset.cpp:718
static const LSET & BackAssembly()
Return a complete set of all bottom assembly layers which is all B_SilkS and B_Mask.
Definition lset.cpp:566
static const LSET & BackMask()
Return a mask holding all technical layers and the external CU layer on back side.
Definition lset.cpp:725
static const LSET & FrontAssembly()
Return a complete set of all top assembly layers which is all F_SilkS and F_Mask.
Definition lset.cpp:559
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition lset.cpp:259
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
static const LSET & AllLayersMask()
Definition lset.cpp:637
static const LSET & PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition lset.cpp:693
static const LSET & InternalCuMask()
Return a complete set of internal copper layers which is all Cu layers except F_Cu and B_Cu.
Definition lset.cpp:573
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition lset.cpp:184
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
static const char Default[]
the name of the default NETCLASS
Definition netclass.h:46
Handle the data for a net.
Definition netinfo.h:50
int GetNetCode() const
Definition netinfo.h:104
const NETNAMES_MAP & NetsByName() const
Return the name map, at least for python.
Definition netinfo.h:258
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
static void * ColorToVoid(COLOR4D &aColor)
int GetRowByNetcode(int aCode) const
wxString GetTypeName(int aRow, int aCol) override
static COLOR4D VoidToColor(void *aColor)
static TOOL_ACTION highlightNet
static TOOL_ACTION hideNetInRatsnest
static TOOL_ACTION showNetInRatsnest
static TOOL_ACTION showNetInspector
static TOOL_ACTION ratsnestModeCycle
static TOOL_ACTION netColorModeCycle
static TOOL_ACTION selectNet
Select all connections belonging to a single net.
Definition pcb_actions.h:82
static TOOL_ACTION flipBoard
static TOOL_ACTION deselectNet
Remove all connections belonging to a single net from the active selection.
Definition pcb_actions.h:85
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
double m_TrackOpacity
Opacity override for all tracks.
bool m_FlipBoardView
true if the board is flipped to show the mirrored view
double m_FilledShapeOpacity
Opacity override for graphic shapes.
double m_ZoneOpacity
Opacity override for filled zone areas.
double m_OutsideGroupOpacity
Opacity override for items outside the entered group.
double m_ImageOpacity
Opacity override for user images.
double m_PadOpacity
Opacity override for SMD pads and PTHs.
double m_ViaOpacity
Opacity override for all types of via.
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
The main frame for Pcbnew.
The project local settings are things that are attached to a particular project, but also might be pa...
std::set< wxString > m_HiddenNetclasses
Icon provider for the "standard" row indicators, for example in layer selection lists.
Represent a single user action.
Master controller class:
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
A better wxCollapsiblePane that.
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
void AddLink(const wxString &aLinkText, const std::function< void(wxHyperlinkEvent &)> &aFn)
Add a hypertext link to the infobar.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
Definition wx_panel.h:35
A type-safe container of any type.
Definition ki_any.h:92
static const wxSize SWATCH_SIZE_SMALL_DU(8, 6)
@ SWATCH_SMALL
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
This file is part of the common library.
#define _(s)
#define VIEWPORT_SWITCH_KEY
#define PRESET_SWITCH_KEY
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
GAL_LAYER_ID ToGalLayer(int aInteger)
Definition layer_ids.h:413
int GetNetnameLayer(int aLayer)
Return a netname layer corresponding to the given layer.
Definition layer_ids.h:921
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
Definition layer_ids.h:224
@ LAYER_GRID
Definition layer_ids.h:250
@ LAYER_POINTS
PCB reference/manual snap points visibility.
Definition layer_ids.h:317
@ GAL_LAYER_ID_START
Definition layer_ids.h:225
@ LAYER_LOCKED_ITEM_SHADOW
Shadow layer for locked items.
Definition layer_ids.h:303
@ LAYER_FILLED_SHAPES
Copper graphic shape opacity/visibility (color ignored).
Definition layer_ids.h:309
@ LAYER_CONFLICTS_SHADOW
Shadow layer for items flagged conflicting.
Definition layer_ids.h:306
@ LAYER_FOOTPRINTS_FR
Show footprints on front.
Definition layer_ids.h:255
@ LAYER_VIA_STITCHING
Outline of via stitching generators.
Definition layer_ids.h:326
@ LAYER_OUTSIDE_GROUP_OPACITY
Opacity slider for items outside the entered group.
Definition layer_ids.h:351
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_DRAW_BITMAPS
Draw images.
Definition layer_ids.h:280
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_BOARD_OUTLINE_AREA
PCB board outline.
Definition layer_ids.h:314
@ LAYER_DRC_EXCLUSION
Layer for DRC markers which have been individually excluded.
Definition layer_ids.h:300
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition layer_ids.h:277
@ LAYER_ZONES
Control for copper zone opacity/visibility (color ignored).
Definition layer_ids.h:291
@ LAYER_PADS
Meta control for all pads opacity/visibility (color ignored).
Definition layer_ids.h:288
@ LAYER_DRC_WARNING
Layer for DRC markers with RPT_SEVERITY_WARNING.
Definition layer_ids.h:297
@ LAYER_TRACKS
Definition layer_ids.h:263
@ LAYER_CONSTRAINT_SHADOW
Shadow layer for items bound to a constraint.
Definition layer_ids.h:320
@ LAYER_RATSNEST
Definition layer_ids.h:249
@ LAYER_ZONE_START
Virtual layers for stacking zones and tracks on a given copper layer.
Definition layer_ids.h:354
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FOOTPRINTS_BK
Show footprints on back.
Definition layer_ids.h:256
@ LAYER_ANCHOR
Anchor of items having an anchor point (texts, footprints).
Definition layer_ids.h:244
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
@ LAYER_SUBGRIDS
Routing/placement subgrids (PCB_GRID_ITEM) visibility and color.
Definition layer_ids.h:323
@ LAYER_DRC_ERROR
Layer for DRC markers with RPT_SEVERITY_ERROR.
Definition layer_ids.h:273
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition layer_ids.h:228
#define CLEARANCE_LAYER_FOR(boardLayer)
Definition layer_ids.h:399
#define VIA_COPPER_LAYER_FOR(boardLayer)
Definition layer_ids.h:398
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ User_16
Definition layer_ids.h:135
@ User_29
Definition layer_ids.h:148
@ User_40
Definition layer_ids.h:159
@ User_15
Definition layer_ids.h:134
@ User_8
Definition layer_ids.h:127
@ F_CrtYd
Definition layer_ids.h:112
@ User_11
Definition layer_ids.h:130
@ User_25
Definition layer_ids.h:144
@ User_34
Definition layer_ids.h:153
@ User_45
Definition layer_ids.h:164
@ B_Adhes
Definition layer_ids.h:99
@ User_36
Definition layer_ids.h:155
@ Edge_Cuts
Definition layer_ids.h:108
@ Dwgs_User
Definition layer_ids.h:103
@ F_Paste
Definition layer_ids.h:100
@ Cmts_User
Definition layer_ids.h:104
@ User_6
Definition layer_ids.h:125
@ User_7
Definition layer_ids.h:126
@ User_19
Definition layer_ids.h:138
@ User_23
Definition layer_ids.h:142
@ F_Adhes
Definition layer_ids.h:98
@ User_41
Definition layer_ids.h:160
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ User_14
Definition layer_ids.h:133
@ User_39
Definition layer_ids.h:158
@ User_5
Definition layer_ids.h:124
@ User_20
Definition layer_ids.h:139
@ Eco1_User
Definition layer_ids.h:105
@ F_Mask
Definition layer_ids.h:93
@ User_42
Definition layer_ids.h:161
@ User_43
Definition layer_ids.h:162
@ B_Paste
Definition layer_ids.h:101
@ User_10
Definition layer_ids.h:129
@ User_9
Definition layer_ids.h:128
@ User_27
Definition layer_ids.h:146
@ User_28
Definition layer_ids.h:147
@ UNSELECTED_LAYER
Definition layer_ids.h:58
@ F_Fab
Definition layer_ids.h:115
@ Margin
Definition layer_ids.h:109
@ F_SilkS
Definition layer_ids.h:96
@ B_CrtYd
Definition layer_ids.h:111
@ Eco2_User
Definition layer_ids.h:106
@ User_35
Definition layer_ids.h:154
@ User_31
Definition layer_ids.h:150
@ User_3
Definition layer_ids.h:122
@ User_1
Definition layer_ids.h:120
@ User_12
Definition layer_ids.h:131
@ B_SilkS
Definition layer_ids.h:97
@ User_30
Definition layer_ids.h:149
@ User_37
Definition layer_ids.h:156
@ User_22
Definition layer_ids.h:141
@ User_38
Definition layer_ids.h:157
@ User_4
Definition layer_ids.h:123
@ User_21
Definition layer_ids.h:140
@ User_24
Definition layer_ids.h:143
@ User_13
Definition layer_ids.h:132
@ User_2
Definition layer_ids.h:121
@ User_17
Definition layer_ids.h:136
@ User_33
Definition layer_ids.h:152
@ User_26
Definition layer_ids.h:145
@ User_32
Definition layer_ids.h:151
@ User_18
Definition layer_ids.h:137
@ User_44
Definition layer_ids.h:163
@ F_Cu
Definition layer_ids.h:60
@ B_Fab
Definition layer_ids.h:114
#define ZONE_LAYER_FOR(boardLayer)
Definition layer_ids.h:396
#define PAD_COPPER_LAYER_FOR(boardLayer)
Definition layer_ids.h:397
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
Definition layer_ids.h:392
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition lset.cpp:750
@ ALL
All except INITIAL_ADD.
Definition view_item.h:55
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:34
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
KICOMMON_API wxMenuItem * AddMenuItem(wxMenu *aMenu, int aId, const wxString &aText, const wxBitmapBundle &aImage, wxItemKind aType=wxITEM_NORMAL)
Create and insert a menu item with an icon into aMenu.
const int c_IndicatorSizeDIP
Definition ui_common.h:54
std::map< wxString, NETINFO_ITEM * > NETNAMES_MAP
Definition netinfo.h:225
#define _HKI(x)
Definition page_info.cpp:40
see class PGM_BASE
T * GetAppSettings(const char *aFilename)
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
Container for an appearance setting (can control a single board layer, or GAL layer,...
A saved set of layers that are visible.
GAL_SET renderLayers
Render layers (e.g. object types) that are visible.
wxString name
A name for this layer set.
bool flipBoard
True if the flip board is enabled.
LSET layers
Board layers that are visible.
bool readOnly
True if this is a read-only (built-in) preset.
PCB_LAYER_ID activeLayer
Optional layer to set active when this preset is loaded.
COLOR4D color
int code
wxString name
bool visible
struct DROP_TABLE cs
#define HOTKEYS_CHANGED
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_NETINFO_T
class NETINFO_ITEM, a description of a net
Definition typeinfo.h:102
const KICOMMON_API wxEventTypeTag< wxCommandEvent > WX_COLLAPSIBLE_PANE_CHANGED