KiCad PCB EDA Suite
Loading...
Searching...
No Matches
appearance_controls_3D.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) 2023 CERN
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
21#include <../3d_rendering/opengl/render_3d_opengl.h> // Must be included before any GL header
22
24
25#include <bitmaps.h>
27#include <confirm.h>
28#include <pgm_base.h>
29#include <dpi_scaling_common.h>
30#include <eda_list_dialog.h>
31#include <pcb_display_options.h>
32#include <eda_3d_viewer_frame.h>
33#include <pcbnew_settings.h>
34#include <project.h>
35#include <board.h>
36#include <layer_range.h>
37#include <tool/tool_manager.h>
38#include <tools/pcb_actions.h>
42#include <widgets/wx_infobar.h>
45#include <wx/bmpbuttn.h>
46#include <wx/sizer.h>
47#include <wx/textdlg.h>
48#include <wx/checkbox.h>
49#include <wx/menu.h>
50
51#include <algorithm>
52
53static constexpr int ID_SHOW_ALL_COPPER_LAYERS = wxID_HIGHEST + 1;
57
59static constexpr int REBUILD_DELAY_MS = 250;
60
62#define RR APPEARANCE_CONTROLS_3D::APPEARANCE_SETTING_3D
63
66
67 // text id tooltip
68 RR( _HKI( "Board Body" ), LAYER_3D_BOARD, _HKI( "Show board body" ) ),
69 RR( _HKI( "Plated Barrels" ),LAYER_3D_PLATED_BARRELS, _HKI( "Show barrels of plated through-holes and vias" ) ),
70 RR( wxS( "F.Cu" ), LAYER_3D_COPPER_TOP, _HKI( "Show front copper / surface finish color" ) ),
71 RR( wxS( "B.Cu" ), LAYER_3D_COPPER_BOTTOM, _HKI( "Show back copper / surface finish color" ) ),
72 RR( _HKI( "Adhesive" ), LAYER_3D_ADHESIVE, _HKI( "Show adhesive" ) ),
73 RR( _HKI( "Solder Paste" ), LAYER_3D_SOLDERPASTE, _HKI( "Show solder paste" ) ),
74 RR( wxS( "F.Silkscreen" ), LAYER_3D_SILKSCREEN_TOP, _HKI( "Show front silkscreen" ) ),
75 RR( wxS( "B.Silkscreen" ), LAYER_3D_SILKSCREEN_BOTTOM, _HKI( "Show back silkscreen" ) ),
76 RR( wxS( "F.Mask" ), LAYER_3D_SOLDERMASK_TOP, _HKI( "Show front solder mask" ) ),
77 RR( wxS( "B.Mask" ), LAYER_3D_SOLDERMASK_BOTTOM, _HKI( "Show back solder mask" ) ),
78 RR( wxS( "User.Drawings" ), LAYER_3D_USER_DRAWINGS, _HKI( "Show user drawings layer" ) ),
79 RR( wxS( "User.Comments" ), LAYER_3D_USER_COMMENTS, _HKI( "Show user comments layer" ) ),
80 RR( wxS( "User.Eco1" ), LAYER_3D_USER_ECO1, _HKI( "Show user ECO1 layer" ) ),
81 RR( wxS( "User.Eco2" ), LAYER_3D_USER_ECO2, _HKI( "Show user ECO2 layer" ) ),
82 RR( wxS( "F.Fab" ), LAYER_3D_F_FAB, _HKI( "Show front fabrication layer" ) ),
83 RR( wxS( "B.Fab" ), LAYER_3D_B_FAB, _HKI( "Show back fabrication layer" ) ),
84 RR( wxS( "F.Courtyard" ), LAYER_3D_F_COURTYARD, _HKI( "Show front courtyard layer" ) ),
85 RR( wxS( "B.Courtyard" ), LAYER_3D_B_COURTYARD, _HKI( "Show back courtyard layer" ) ),
86 RR( wxS( "User.1" ), LAYER_3D_USER_1, _HKI( "Show user defined layer 1" ) ),
87 RR( wxS( "User.2" ), LAYER_3D_USER_2, _HKI( "Show user defined layer 2" ) ),
88 RR( wxS( "User.3" ), LAYER_3D_USER_3, _HKI( "Show user defined layer 3" ) ),
89 RR( wxS( "User.4" ), LAYER_3D_USER_4, _HKI( "Show user defined layer 4" ) ),
90 RR( wxS( "User.5" ), LAYER_3D_USER_5, _HKI( "Show user defined layer 5" ) ),
91 RR( wxS( "User.6" ), LAYER_3D_USER_6, _HKI( "Show user defined layer 6" ) ),
92 RR( wxS( "User.7" ), LAYER_3D_USER_7, _HKI( "Show user defined layer 7" ) ),
93 RR( wxS( "User.8" ), LAYER_3D_USER_8, _HKI( "Show user defined layer 8" ) ),
94 RR( wxS( "User.9" ), LAYER_3D_USER_9, _HKI( "Show user defined layer 9" ) ),
95 RR( wxS( "User.10" ), LAYER_3D_USER_10, _HKI( "Show user defined layer 10" ) ),
96 RR( wxS( "User.11" ), LAYER_3D_USER_11, _HKI( "Show user defined layer 11" ) ),
97 RR( wxS( "User.12" ), LAYER_3D_USER_12, _HKI( "Show user defined layer 12" ) ),
98 RR( wxS( "User.13" ), LAYER_3D_USER_13, _HKI( "Show user defined layer 13" ) ),
99 RR( wxS( "User.14" ), LAYER_3D_USER_14, _HKI( "Show user defined layer 14" ) ),
100 RR( wxS( "User.15" ), LAYER_3D_USER_15, _HKI( "Show user defined layer 15" ) ),
101 RR( wxS( "User.16" ), LAYER_3D_USER_16, _HKI( "Show user defined layer 16" ) ),
102 RR( wxS( "User.17" ), LAYER_3D_USER_17, _HKI( "Show user defined layer 17" ) ),
103 RR( wxS( "User.18" ), LAYER_3D_USER_18, _HKI( "Show user defined layer 18" ) ),
104 RR( wxS( "User.19" ), LAYER_3D_USER_19, _HKI( "Show user defined layer 19" ) ),
105 RR( wxS( "User.20" ), LAYER_3D_USER_20, _HKI( "Show user defined layer 20" ) ),
106 RR( wxS( "User.21" ), LAYER_3D_USER_21, _HKI( "Show user defined layer 21" ) ),
107 RR( wxS( "User.22" ), LAYER_3D_USER_22, _HKI( "Show user defined layer 22" ) ),
108 RR( wxS( "User.23" ), LAYER_3D_USER_23, _HKI( "Show user defined layer 23" ) ),
109 RR( wxS( "User.24" ), LAYER_3D_USER_24, _HKI( "Show user defined layer 24" ) ),
110 RR( wxS( "User.25" ), LAYER_3D_USER_25, _HKI( "Show user defined layer 25" ) ),
111 RR( wxS( "User.26" ), LAYER_3D_USER_26, _HKI( "Show user defined layer 26" ) ),
112 RR( wxS( "User.27" ), LAYER_3D_USER_27, _HKI( "Show user defined layer 27" ) ),
113 RR( wxS( "User.28" ), LAYER_3D_USER_28, _HKI( "Show user defined layer 28" ) ),
114 RR( wxS( "User.29" ), LAYER_3D_USER_29, _HKI( "Show user defined layer 29" ) ),
115 RR( wxS( "User.30" ), LAYER_3D_USER_30, _HKI( "Show user defined layer 30" ) ),
116 RR( wxS( "User.31" ), LAYER_3D_USER_31, _HKI( "Show user defined layer 31" ) ),
117 RR( wxS( "User.32" ), LAYER_3D_USER_32, _HKI( "Show user defined layer 32" ) ),
118 RR( wxS( "User.33" ), LAYER_3D_USER_33, _HKI( "Show user defined layer 33" ) ),
119 RR( wxS( "User.34" ), LAYER_3D_USER_34, _HKI( "Show user defined layer 34" ) ),
120 RR( wxS( "User.35" ), LAYER_3D_USER_35, _HKI( "Show user defined layer 35" ) ),
121 RR( wxS( "User.36" ), LAYER_3D_USER_36, _HKI( "Show user defined layer 36" ) ),
122 RR( wxS( "User.37" ), LAYER_3D_USER_37, _HKI( "Show user defined layer 37" ) ),
123 RR( wxS( "User.38" ), LAYER_3D_USER_38, _HKI( "Show user defined layer 38" ) ),
124 RR( wxS( "User.39" ), LAYER_3D_USER_39, _HKI( "Show user defined layer 39" ) ),
125 RR( wxS( "User.40" ), LAYER_3D_USER_40, _HKI( "Show user defined layer 40" ) ),
126 RR( wxS( "User.41" ), LAYER_3D_USER_41, _HKI( "Show user defined layer 41" ) ),
127 RR( wxS( "User.42" ), LAYER_3D_USER_42, _HKI( "Show user defined layer 42" ) ),
128 RR( wxS( "User.43" ), LAYER_3D_USER_43, _HKI( "Show user defined layer 43" ) ),
129 RR( wxS( "User.44" ), LAYER_3D_USER_44, _HKI( "Show user defined layer 44" ) ),
130 RR( wxS( "User.45" ), LAYER_3D_USER_45, _HKI( "Show user defined layer 45" ) ),
131 RR(),
132 RR( _HKI( "Through-hole Models" ), LAYER_3D_TH_MODELS, EDA_3D_ACTIONS::showTHT ),
136 RR( _HKI( "Models marked DNP" ), LAYER_3D_MODELS_MARKED_DNP, EDA_3D_ACTIONS::showDNP ),
137 RR( _HKI( "Model Bounding Boxes" ), LAYER_3D_BOUNDING_BOXES, EDA_3D_ACTIONS::showBBoxes ),
138 RR(),
139 RR( _HKI( "Values" ), LAYER_FP_VALUES, _HKI( "Show footprint values" ) ),
140 RR( _HKI( "References" ), LAYER_FP_REFERENCES, _HKI( "Show footprint references" ) ),
141 RR( _HKI( "Footprint Text" ), LAYER_FP_TEXT, _HKI( "Show all footprint text" ) ),
142 RR( _HKI( "Off-board Silkscreen" ), LAYER_3D_OFF_BOARD_SILK, _HKI( "Do not clip silk layers to board outline" ) ),
143 RR(),
145 RR( _HKI( "Background Start" ), LAYER_3D_BACKGROUND_TOP, _HKI( "Background gradient start color" ) ),
146 RR( _HKI( "Background End" ), LAYER_3D_BACKGROUND_BOTTOM, _HKI( "Background gradient end color" ) ),
147};
148
149
150// The 3D viewer uses a single color for all copper layers.
151static bool isCopperLayer3D( int aLayer )
152{
153 return aLayer == LAYER_3D_COPPER_TOP
154 || aLayer == LAYER_3D_COPPER_BOTTOM
155 || aLayer == LAYER_3D_PLATED_BARRELS
157}
158
159
160// Layers that can have colors coming from the board stackup, and cannot be modified if
161// use colors from stackup is activated.
162static bool isStackupColorLayer3D( int aLayer )
163{
164 return aLayer == LAYER_3D_BOARD
165 || aLayer == LAYER_3D_SOLDERPASTE
166 || aLayer == LAYER_3D_SILKSCREEN_TOP
167 || aLayer == LAYER_3D_SILKSCREEN_BOTTOM
168 || aLayer == LAYER_3D_SOLDERMASK_TOP
169 || aLayer == LAYER_3D_SOLDERMASK_BOTTOM
170 || isCopperLayer3D( aLayer );
171}
172
173
176 m_frame( aParent ),
177 m_focusOwner( aFocusOwner ),
178 m_lastSelectedViewport( nullptr )
179{
180 DPI_SCALING_COMMON dpi( nullptr, m_frame );
181
182 int screenHeight = wxSystemSettings::GetMetric( wxSYS_SCREEN_Y );
183 m_pointSize = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ).GetPointSize();
184
185 m_layerPanelColour = m_panelLayers->GetBackgroundColour().ChangeLightness( 110 );
186 SetBorders( true, false, false, false );
187
188 m_layersOuterSizer = new wxBoxSizer( wxVERTICAL );
190 m_windowLayers->SetScrollRate( 0, 5 );
191 m_windowLayers->Bind( wxEVT_SET_FOCUS, &APPEARANCE_CONTROLS_3D::OnSetFocus, this );
192 m_panelLayers->Bind( wxEVT_CONTEXT_MENU, &APPEARANCE_CONTROLS_3D::OnLayerContextMenu, this );
193
194 m_envOuterSizer = new wxBoxSizer( wxVERTICAL );
195
196 wxFont infoFont = KIUI::GetInfoFont( this );
197 m_panelLayers->SetFont( infoFont );
198 m_windowLayers->SetFont( infoFont );
199 m_presetsLabel->SetFont( infoFont );
200 m_viewportsLabel->SetFont( infoFont );
201
202 // Create display options
203 m_cbUseBoardStackupColors = new wxCheckBox( m_panelLayers, wxID_ANY,
204 _( "Use board stackup colors" ) );
205 m_cbUseBoardStackupColors->SetFont( infoFont );
206
207 m_cbUseBoardStackupColors->Bind( wxEVT_CHECKBOX,
208 [this]( wxCommandEvent& aEvent )
209 {
210 EDA_3D_VIEWER_SETTINGS* cfg = m_frame->GetAdapter().m_Cfg;
211 cfg->m_UseStackupColors = aEvent.IsChecked();
212
214 m_frame->NewDisplay( true );
215 } );
216
217 m_cbUseBoardEditorCopperColors = new wxCheckBox( m_panelLayers, wxID_ANY,
218 _( "Use PCB editor copper colors" ) );
219 m_cbUseBoardEditorCopperColors->SetFont( infoFont );
220 m_cbUseBoardEditorCopperColors->SetToolTip( _( "Use the board editor layer colors for copper "
221 "layers (realtime renderer only)" ) );
222
223 m_cbUseBoardEditorCopperColors->Bind( wxEVT_CHECKBOX,
224 [this]( wxCommandEvent& aEvent )
225 {
226 EDA_3D_VIEWER_SETTINGS* cfg = m_frame->GetAdapter().m_Cfg;
227 cfg->m_Render.use_board_editor_copper_colors = aEvent.IsChecked();
228
230 m_frame->NewDisplay( true );
231 } );
232
233 m_panelLayersSizer->Add( m_cbUseBoardStackupColors, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5 );
235 wxEXPAND | wxALL, 5 );
236
237 m_cbLayerPresets->SetToolTip( wxString::Format( _( "Save and restore color and visibility combinations.\n"
238 "Use %s+Tab to activate selector.\n"
239 "Successive Tabs while holding %s down will cycle through "
240 "presets in the popup." ),
243
244 m_cbViewports->SetToolTip( wxString::Format( _( "Save and restore camera position and zoom.\n"
245 "Use %s+Tab to activate selector.\n"
246 "Successive Tabs while holding %s down will cycle through "
247 "viewports in the popup." ),
250
251 if( screenHeight <= 900 && m_pointSize >= FromDIP( KIUI::c_IndicatorSizeDIP ) )
252 m_pointSize = m_pointSize * 8 / 10;
253
255
258
260 m_btnResetLayerScale->SetToolTip( _( "Reset layer spacing to the default" ) );
261 Layout();
262
263 m_redrawTriggerTimer.SetOwner( this );
264 Bind( wxEVT_TIMER, &APPEARANCE_CONTROLS_3D::OnRedrawTriggerTimer, this, m_redrawTriggerTimer.GetId() );
265
266 m_frame->Bind( EDA_LANG_CHANGED, &APPEARANCE_CONTROLS_3D::OnLanguageChanged, this );
267}
268
269
275
276
278{
279 DPI_SCALING_COMMON dpi( nullptr, m_frame );
280 wxSize size( 220 * dpi.GetScaleFactor(), 480 * dpi.GetScaleFactor() );
281 return size;
282}
283
284
285void APPEARANCE_CONTROLS_3D::OnLayerContextMenu( wxContextMenuEvent& aEvent )
286{
287 wxMenu menu;
288
289 menu.Append( ID_SHOW_ALL_COPPER_LAYERS, _( "Show All Copper Layers" ) );
290 menu.Append( ID_HIDE_ALL_COPPER_LAYERS, _( "Hide All Copper Layers" ) );
291 menu.AppendSeparator();
292 menu.Append( ID_SHOW_ALL_INNER_LAYERS, _( "Show All Inner Layers" ) );
293 menu.Append( ID_HIDE_ALL_INNER_LAYERS, _( "Hide All Inner Layers" ) );
294
295 BOARD* board = m_frame->GetBoard();
296 bool hasInnerLayers = board && board->GetCopperLayerCount() > 2;
297
298 menu.Enable( ID_SHOW_ALL_INNER_LAYERS, hasInnerLayers );
299 menu.Enable( ID_HIDE_ALL_INNER_LAYERS, hasInnerLayers );
300
301 std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
302
303 auto setInnerCopperLayers =
304 [&]( bool aVisible )
305 {
306 if( !board )
307 return;
308
309 for( PCB_LAYER_ID layer : LAYER_RANGE( F_Cu, B_Cu, board->GetCopperLayerCount() ) )
310 {
311 if( IsInnerCopperLayer( layer ) )
312 visibleLayers.set( MapPCBLayerTo3DLayer( layer ), aVisible );
313 }
314 };
315
316 switch( GetPopupMenuSelectionFromUser( menu ) )
317 {
319 visibleLayers.set( LAYER_3D_COPPER_TOP );
320 visibleLayers.set( LAYER_3D_COPPER_BOTTOM );
321 setInnerCopperLayers( true );
322 break;
323
325 visibleLayers.reset( LAYER_3D_COPPER_TOP );
326 visibleLayers.reset( LAYER_3D_COPPER_BOTTOM );
327 setInnerCopperLayers( false );
328 break;
329
331 setInnerCopperLayers( true );
332 break;
333
335 setInnerCopperLayers( false );
336 break;
337
338 default:
339 return;
340 }
341
342 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
345}
346
347
349{
350 EDA_3D_VIEWER_SETTINGS& cfg = *m_frame->GetAdapter().m_Cfg;
351
352 cfg.m_Render.board_layer_thickness_scale = static_cast<float>( m_layerScaleCtrl->GetValue() );
353
354 // Rebuilding the scene is expensive and briefly clears the view, so wait until the user
355 // stops changing the value before triggering a rebuild.
357}
358
359
360void APPEARANCE_CONTROLS_3D::OnLayerScaleChange( wxSpinDoubleEvent& aEvent )
361{
363}
364
365
367{
368 m_layerScaleCtrl->SetValue( 1.0 );
370}
371
372
374{
375 m_frame->NewDisplay( true );
376}
377
378
379void APPEARANCE_CONTROLS_3D::OnSetFocus( wxFocusEvent& aEvent )
380{
381#ifdef __WXMSW__
382 // In wxMSW, buttons won't process events unless they have focus, so we'll let it take the
383 // focus and give it back to the parent in the button event handler.
384 if( wxBitmapButton* btn = dynamic_cast<wxBitmapButton*>( aEvent.GetEventObject() ) )
385 {
386 wxCommandEvent evt( wxEVT_BUTTON );
387 wxPostEvent( btn, evt );
388 }
389#endif
390
391 passOnFocus();
392 aEvent.Skip();
393}
394
395
396void APPEARANCE_CONTROLS_3D::OnSize( wxSizeEvent& aEvent )
397{
398 aEvent.Skip();
399}
400
401
403{
404 Freeze();
405
407 m_cbUseBoardStackupColors->SetLabel( _( "Use board stackup colors" ) );
410
411 Thaw();
412 Refresh();
413}
414
415
416void APPEARANCE_CONTROLS_3D::OnLanguageChanged( wxCommandEvent& aEvent )
417{
419
420 aEvent.Skip();
421}
422
423
425{
426 // This is essentially a list of hacks because DarkMode isn't yet implemented inside
427 // wxWidgets.
428 //
429 // The individual wxPanels, COLOR_SWATCHes and GRID_CELL_COLOR_RENDERERs should really be
430 // overriding some virtual method or responding to some wxWidgets event so that the parent
431 // doesn't have to know what it contains. But, that's not where we are, so... :shrug:
432
433 m_layerPanelColour = m_panelLayers->GetBackgroundColour().ChangeLightness( 110 );
434
435 m_windowLayers->SetBackgroundColour( m_layerPanelColour );
436
437 for( wxSizerItem* child : m_layersOuterSizer->GetChildren() )
438 {
439 if( child && child->GetWindow() )
440 child->GetWindow()->SetBackgroundColour( m_layerPanelColour );
441 }
442}
443
444
446{
448
449 if( EDA_3D_VIEWER_SETTINGS* cfg = m_frame->GetAdapter().m_Cfg )
450 m_layerScaleCtrl->SetValue( cfg->m_Render.board_layer_thickness_scale );
451
453
454 const wxString& currentPreset = m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
455
456 if( currentPreset == FOLLOW_PCB || currentPreset == FOLLOW_PLOT_SETTINGS )
457 updateLayerPresetWidget( currentPreset );
458 else
460}
461
462
463void APPEARANCE_CONTROLS_3D::ApplyLayerPreset( const wxString& aPresetName )
464{
465 doApplyLayerPreset( aPresetName );
466
467 // Move to front of MRU list
468 if( m_presetMRU.Index( aPresetName ) != wxNOT_FOUND )
469 m_presetMRU.Remove( aPresetName );
470
471 m_presetMRU.Insert( aPresetName, 0 );
472
473 updateLayerPresetWidget( aPresetName );
474}
475
476
477std::vector<VIEWPORT3D> APPEARANCE_CONTROLS_3D::GetUserViewports() const
478{
479 std::vector<VIEWPORT3D> ret;
480
481 for( const auto& [name, viewport] : m_viewports )
482 ret.emplace_back( viewport );
483
484 return ret;
485}
486
487
488void APPEARANCE_CONTROLS_3D::SetUserViewports( std::vector<VIEWPORT3D>& aViewportList )
489{
490 m_viewports.clear();
491 m_viewportMRU.clear();
492
493 for( const VIEWPORT3D& viewport : aViewportList )
494 {
495 if( m_viewports.count( viewport.name ) )
496 continue;
497
498 m_viewports[viewport.name] = viewport;
499
500 m_viewportMRU.Add( viewport.name );
501 }
502
504
505 // Now is as good a time as any to initialize the layer presets as well.
507
508 m_presetMRU.clear();
509 m_presetMRU.Add( FOLLOW_PCB );
511
512 for( const LAYER_PRESET_3D& preset : m_frame->GetAdapter().m_Cfg->m_LayerPresets )
513 m_presetMRU.Add( preset.name );
514}
515
516
517void APPEARANCE_CONTROLS_3D::ApplyViewport( const wxString& aViewportName )
518{
519 int idx = m_cbViewports->FindString( aViewportName );
520
521 if( idx >= 0 && idx < (int)m_cbViewports->GetCount() - 3 /* separator */ )
522 {
523 m_cbViewports->SetSelection( idx );
524 m_lastSelectedViewport = static_cast<VIEWPORT3D*>( m_cbViewports->GetClientData( idx ) );
525 }
526 else
527 {
528 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 ); // separator
529 m_lastSelectedViewport = nullptr;
530 }
531
534}
535
536
537void APPEARANCE_CONTROLS_3D::OnLayerVisibilityChanged( int aLayer, bool isVisible )
538{
539 std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
540 const std::map<int, COLOR4D>& colors = m_frame->GetAdapter().GetLayerColors();
541 bool killFollow = false;
542 bool doFastRefresh = false; // true to just refresh the display
543
544 // Special-case controls
545 switch( aLayer )
546 {
547 case LAYER_FP_TEXT:
548 // Because Footprint Text is a meta-control that also can disable values/references,
549 // drag them along here so that the user is less likely to be confused.
550 if( !isVisible )
551 {
552 visibleLayers.set( LAYER_FP_REFERENCES, false );
553 visibleLayers.set( LAYER_FP_VALUES, false );
554 }
555
556 visibleLayers.set( LAYER_FP_TEXT, isVisible );
557 killFollow = true;
558 break;
559
561 case LAYER_FP_VALUES:
562 // In case that user changes Footprint Value/References when the Footprint Text
563 // meta-control is disabled, we should put it back on.
564 if( isVisible )
565 visibleLayers.set( LAYER_FP_TEXT, true );
566
567 visibleLayers.set( aLayer, isVisible );
568 killFollow = true;
569 break;
570
571 case LAYER_3D_BOARD:
585 case LAYER_3D_F_FAB:
586 case LAYER_3D_B_FAB:
589 visibleLayers.set( aLayer, isVisible );
590 killFollow = true;
591 break;
592
598 doFastRefresh = true;
599 visibleLayers.set( aLayer, isVisible );
600 break;
601
602 default:
603 visibleLayers.set( aLayer, isVisible );
604
605 if( ( aLayer >= LAYER_3D_USER_1 && aLayer <= LAYER_3D_USER_45 )
606 || ( aLayer >= LAYER_3D_COPPER_INNER_1 && aLayer <= LAYER_3D_COPPER_INNER_30 ) )
607 {
608 killFollow = true;
609 }
610
611 break;
612 }
613
614 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
615 m_frame->GetAdapter().SetLayerColors( colors );
616
617 const wxString& currentPreset = m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
618
619 if( ( currentPreset != FOLLOW_PCB && currentPreset != FOLLOW_PLOT_SETTINGS ) || killFollow )
621
623
624 if( doFastRefresh && m_frame->GetAdapter().m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL )
625 {
626 RENDER_3D_OPENGL* renderer = static_cast<RENDER_3D_OPENGL*>( m_frame->GetCanvas()->GetCurrentRender() );
627 renderer->Load3dModelsIfNeeded();
628 renderer->RebuildHitTestAsync();
629 m_frame->GetCanvas()->Request_refresh();
630 }
631 else
632 {
633 m_frame->NewDisplay( true );
634 }
635}
636
637
639{
640 std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
641 std::map<int, COLOR4D> colors = m_frame->GetAdapter().GetLayerColors();
642
643 m_frame->GetAdapter().SetVisibleLayers( visibleLayers );
644
645 int layer = aSwatch->GetId();
646 COLOR4D newColor = aSwatch->GetSwatchColor();
647
648 // The internals of the 3D viewer only supports a single color for copper, which must
649 // be applied to all copper layers.
650 if( isCopperLayer3D( layer ) )
651 {
652 for( const auto& [index, setting] : m_layerSettingsMap )
653 {
654 if( !isCopperLayer3D( index ) )
655 continue;
656
657 if( colors.count( index ) )
658 colors[index] = newColor;
659
660 if( setting->m_Ctl_color )
661 {
662 // Don't send an event, because that will cause an event loop
663 setting->m_Ctl_color->SetSwatchColor( newColor, false );
664 }
665 }
666 }
667 else
668 {
669 colors[layer] = newColor;
670 }
671
672 m_frame->GetAdapter().SetLayerColors( colors );
673
674 const wxString& currentPreset = m_frame->GetAdapter().m_Cfg->m_CurrentPreset;
675
676 if( currentPreset == FOLLOW_PCB || currentPreset == FOLLOW_PLOT_SETTINGS )
677 updateLayerPresetWidget( currentPreset );
678 else
680
681 m_frame->NewDisplay( true );
682}
683
684
686{
687 int swatchWidth = m_windowLayers->ConvertDialogToPixels( wxSize( 8, 0 ) ).x;
688
689 std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
690 std::map<int, COLOR4D> colors = m_frame->GetAdapter().GetLayerColors();
691 std::map<int, COLOR4D> defaultColors = m_frame->GetAdapter().GetDefaultColors();
692 LSET enabled = m_frame->GetBoard()->GetEnabledLayers();
693
694 m_layerSettings.clear();
695 m_layerSettingsMap.clear();
696 m_layersOuterSizer->Clear( true );
697 m_layersOuterSizer->AddSpacer( 5 );
698
699 m_envOuterSizer->Clear( true );
700
701 const auto appendLayer =
702 [&]( const std::unique_ptr<APPEARANCE_SETTING_3D>& aSetting, int aColorLayer )
703 {
704 wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
705 int layer = aSetting->m_Id;
706
707 aSetting->m_Visible = visibleLayers.test( layer );
708
709 if( colors.count( aColorLayer ) )
710 {
711 COLOR_SWATCH* swatch = new COLOR_SWATCH( m_windowLayers, colors[ aColorLayer ], layer,
712 COLOR4D::WHITE, defaultColors[ aColorLayer ],
713 SWATCH_SMALL );
714 swatch->SetToolTip( _( "Left double click or middle click to change color" ) );
715
716 swatch->SetReadOnlyCallback(
717 [this]()
718 {
719 WX_INFOBAR* infobar = m_frame->GetInfoBar();
720
721 infobar->RemoveAllButtons();
722 infobar->AddCloseButton();
723
724 infobar->ShowMessageFor( _( "Uncheck 'Use board stackup colors' to "
725 "allow color editing." ),
726 10000, wxICON_INFORMATION );
727 } );
728
729 sizer->Add( swatch, 0, wxALIGN_CENTER_VERTICAL, 0 );
730 aSetting->m_Ctl_color = swatch;
731
732 swatch->Bind( COLOR_SWATCH_CHANGED,
733 [this]( wxCommandEvent& event )
734 {
735 auto swatch = static_cast<COLOR_SWATCH*>( event.GetEventObject() );
736 onColorSwatchChanged( swatch );
737
738 passOnFocus();
739 } );
740 }
741 else
742 {
743 sizer->AddSpacer( swatchWidth );
744 }
745
746 sizer->AddSpacer( 5 );
747
748 wxString layerName = aSetting->GetLabel();
749 PCB_LAYER_ID boardLayer = Map3DLayerToPCBLayer( layer );
750
751 if( boardLayer != UNDEFINED_LAYER )
752 layerName = m_frame->GetBoard()->GetLayerName( boardLayer );
753
754 wxStaticText* label = new wxStaticText( m_windowLayers, layer, layerName );
755 label->Wrap( -1 );
756 label->SetToolTip( aSetting->GetTooltip() );
757
758 if( layer == LAYER_3D_BACKGROUND_TOP || layer == LAYER_3D_BACKGROUND_BOTTOM )
759 {
760 sizer->AddSpacer( swatchWidth );
761 }
762 else
763 {
764 BITMAP_TOGGLE* btn_visible = new BITMAP_TOGGLE( m_windowLayers, layer,
767 aSetting->m_Visible );
768
769 btn_visible->Bind( TOGGLE_CHANGED,
770 [this]( wxCommandEvent& aEvent )
771 {
772 int id = static_cast<wxWindow*>( aEvent.GetEventObject() )->GetId();
773 bool isVisible = aEvent.GetInt();
774 OnLayerVisibilityChanged( id, isVisible );
775
776 passOnFocus();
777 } );
778
779 wxString tip;
780 tip.Printf( _( "Show or hide %s" ), aSetting->GetLabel().Lower() );
781 btn_visible->SetToolTip( tip );
782
783 aSetting->m_Ctl_visibility = btn_visible;
784 sizer->Add( btn_visible, 0, wxALIGN_CENTER_VERTICAL, 0 );
785 }
786
787 sizer->AddSpacer( 5 );
788 sizer->Add( label, 0, wxALIGN_CENTER_VERTICAL, 0 );
789
790 m_layersOuterSizer->Add( sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, 5 );
791 m_layersOuterSizer->AddSpacer( 2 );
792 };
793
794 const auto appendInnerLayers =
795 [&]()
796 {
797 BOARD& board = *m_frame->GetBoard();
798
799 for( PCB_LAYER_ID boardLayer : LAYER_RANGE( F_Cu, B_Cu, board.GetCopperLayerCount() ) )
800 {
801 if( !IsInnerCopperLayer( boardLayer ) || !enabled.test( boardLayer ) )
802 continue;
803
804 int layerId = MapPCBLayerTo3DLayer( boardLayer );
805 wxString label = board.GetLayerName( boardLayer );
806 wxString tooltip = wxString::Format( _( "Show %s" ), label );
807
808 m_layerSettings.emplace_back(
809 std::make_unique<APPEARANCE_SETTING_3D>( label, layerId, tooltip ) );
810 appendLayer( m_layerSettings.back(), LAYER_3D_COPPER_TOP );
811 m_layerSettingsMap[layerId] = m_layerSettings.back().get();
812 }
813 };
814
815 for( const APPEARANCE_SETTING_3D& s_setting : s_layerSettings )
816 {
817 m_layerSettings.emplace_back( std::make_unique<APPEARANCE_SETTING_3D>( s_setting ) );
818 std::unique_ptr<APPEARANCE_SETTING_3D>& setting = m_layerSettings.back();
819
820 if( setting->m_Spacer )
821 {
822 m_layersOuterSizer->AddSpacer( m_pointSize );
823 }
824 else if( setting->m_Id >= LAYER_3D_USER_1 && setting->m_Id <= LAYER_3D_USER_45 )
825 {
826 if( enabled.test( Map3DLayerToPCBLayer( setting->m_Id ) ) )
827 appendLayer( setting, setting->m_Id );
828 }
829 else
830 {
831 appendLayer( setting, setting->m_Id );
832 }
833
834 m_layerSettingsMap[setting->m_Id] = setting.get();
835
836 // Keep the inner copper rows next to the outer copper rows, in stack order.
837 if( setting->m_Id == LAYER_3D_COPPER_TOP )
838 appendInnerLayers();
839 }
840
841 m_sizerOuter->Layout();
842}
843
844
846{
847 EDA_3D_VIEWER_SETTINGS* cfg = m_frame->GetAdapter().m_Cfg;
848 std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
849 std::map<int, COLOR4D> colors = m_frame->GetAdapter().GetLayerColors();
850
851 for( std::unique_ptr<APPEARANCE_SETTING_3D>& setting : m_layerSettings )
852 {
853 if( setting->m_Spacer )
854 continue;
855
856 if( setting->m_Ctl_visibility )
857 setting->m_Ctl_visibility->SetValue( visibleLayers.test( setting->m_Id ) );
858
859 if( setting->m_Ctl_color )
860 {
861 bool isCopper = isCopperLayer3D( setting->m_Id );
862 int colorLayer = isCopper ? LAYER_3D_COPPER_TOP : setting->m_Id;
863
864 setting->m_Ctl_color->SetSwatchColor( colors[colorLayer], false );
865
866 // if cfg->m_UseStackupColors is set, board colors cannot be modified locally, but
867 // other colors can be
868 if( isStackupColorLayer3D( setting->m_Id ) && cfg )
869 setting->m_Ctl_color->SetReadOnly( cfg->m_UseStackupColors );
870 }
871 }
872
873 if( cfg )
874 {
877 }
878}
879
880
882{
883 m_presetsLabel->SetLabel( wxString::Format( _( "Presets (%s+Tab):" ),
885
886 m_cbLayerPresets->Clear();
887
888 // Build the layers preset list.
889
890 m_cbLayerPresets->Append( _( "Follow PCB Editor" ) );
891 m_cbLayerPresets->Append( _( "Follow PCB Plot Settings" ) );
892
893 if( !m_frame->GetAdapter().m_Cfg->m_LayerPresets.empty() )
894 m_cbLayerPresets->Append( wxT( "---" ) );
895
896 for( const LAYER_PRESET_3D& preset : m_frame->GetAdapter().m_Cfg->m_LayerPresets )
897 m_cbLayerPresets->Append( preset.name );
898
899 m_cbLayerPresets->Append( wxT( "---" ) );
900 m_cbLayerPresets->Append( _( "Save preset..." ) );
901 m_cbLayerPresets->Append( _( "Delete preset..." ) );
902
903 if( aReset )
904 updateLayerPresetWidget( m_frame->GetAdapter().m_Cfg->m_CurrentPreset );
905}
906
907
909{
910 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = wxEmptyString;
911
912 std::vector<LAYER_PRESET_3D>& presets = m_frame->GetAdapter().m_Cfg->m_LayerPresets;
913 std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
914 std::map<int, COLOR4D> colors = m_frame->GetAdapter().GetLayerColors();
915
916 auto it = std::find_if(
917 presets.begin(), presets.end(),
918 [&]( const LAYER_PRESET_3D& aPreset )
919 {
920 if( aPreset.name.Lower() == _( "legacy colors" ) && m_cbUseBoardStackupColors->GetValue() )
921 return false;
922
923 for( int layer = LAYER_3D_BOARD; layer < LAYER_3D_END; ++layer )
924 {
925 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
926 return false;
927 }
928
929 for( int layer : { LAYER_FP_REFERENCES, LAYER_FP_VALUES, LAYER_FP_TEXT } )
930 {
931 if( aPreset.layers.test( layer ) != visibleLayers.test( layer ) )
932 return false;
933 }
934
935 for( int layer = LAYER_3D_START + 1; layer < LAYER_3D_END; ++layer )
936 {
937 auto it1 = aPreset.colors.find( layer );
938 auto it2 = colors.find( layer );
939
940 if( it1 != aPreset.colors.end() && it2 != colors.end() && *it1 != *it2 )
941 return false;
942 }
943
944 return true;
945 } );
946
947 if( it != presets.end() )
948 {
949 m_frame->GetAdapter().m_Cfg->m_CurrentPreset = it->name;
950 m_cbLayerPresets->SetStringSelection( it->name );
951 }
952 else
953 {
954 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 ); // separator
955 }
956}
957
958
960{
961 if( aName == FOLLOW_PCB )
962 m_cbLayerPresets->SetSelection( 0 );
963 else if( aName == FOLLOW_PLOT_SETTINGS )
964 m_cbLayerPresets->SetSelection( 1 );
965 else if( !m_cbLayerPresets->SetStringSelection( aName ) )
966 m_cbLayerPresets->SetSelection( m_cbLayerPresets->GetCount() - 3 ); // separator
967}
968
969
971{
972 EDA_3D_VIEWER_SETTINGS* cfg = m_frame->GetAdapter().m_Cfg;
973 int count = m_cbLayerPresets->GetCount();
974 int index = m_cbLayerPresets->GetSelection();
975 wxString name;
976
977 auto resetSelection =
978 [&]()
979 {
981 };
982
983 if( index == 0 )
984 {
986 }
987 else if( index == 1 )
988 {
990 }
991 else if( index == count - 2 )
992 {
993 wxTextEntryDialog dlg( wxGetTopLevelParent( this ), _( "Layer preset name:" ),
994 _( "Save Layer Preset" ) );
995
996 if( dlg.ShowModal() != wxID_OK )
997 {
998 resetSelection();
999 return;
1000 }
1001
1002 std::bitset<LAYER_3D_END> visibleLayers = m_frame->GetAdapter().GetVisibleLayers();
1003 std::map<int, COLOR4D> colors = m_frame->GetAdapter().GetLayerColors();
1004
1005 name = dlg.GetValue();
1006
1007 if( LAYER_PRESET_3D* preset = cfg->FindPreset( name ) )
1008 {
1009 if( !IsOK( wxGetTopLevelParent( this ), _( "Overwrite existing preset?" ) ) )
1010 {
1011 resetSelection();
1012 return;
1013 }
1014
1015 preset->layers = visibleLayers;
1016 preset->colors = colors;
1017 m_cbLayerPresets->SetSelection( m_cbLayerPresets->FindString( name ) );
1018 }
1019 else
1020 {
1021 cfg->m_LayerPresets.emplace_back( name, visibleLayers, colors );
1023 m_cbLayerPresets->SetStringSelection( name );
1024 }
1025
1026 cfg->m_CurrentPreset = name;
1027 m_presetMRU.Insert( name, 0 );
1028
1029 return;
1030 }
1031 else if( index == count - 1 )
1032 {
1033 wxArrayString headers;
1034 std::vector<wxArrayString> items;
1035
1036 headers.Add( _( "Presets" ) );
1037
1038 for( LAYER_PRESET_3D& preset : cfg->m_LayerPresets )
1039 {
1040 wxArrayString item;
1041 item.Add( preset.name );
1042 items.emplace_back( item );
1043 }
1044
1045 EDA_LIST_DIALOG dlg( m_frame, _( "Delete Preset" ), headers, items );
1046 dlg.SetListLabel( _( "Select preset:" ) );
1047
1048 if( dlg.ShowModal() == wxID_OK )
1049 {
1050 name = dlg.GetTextSelection();
1051
1052 if( m_cbLayerPresets->FindString( name ) != wxNOT_FOUND )
1053 m_cbLayerPresets->Delete( m_cbLayerPresets->FindString( name ) );
1054
1055 std::erase_if( cfg->m_LayerPresets,
1056 [name]( const LAYER_PRESET_3D& preset )
1057 {
1058 return preset.name == name;
1059 } );
1060
1061 if( cfg->m_CurrentPreset == name )
1062 cfg->m_CurrentPreset = wxEmptyString;
1063
1064 if( m_presetMRU.Index( name ) >= 0 )
1065 m_presetMRU.Remove( name );
1066 }
1067
1068 resetSelection();
1069 return;
1070 }
1071 else if( m_cbLayerPresets->GetString( index ) == wxT( "---" ) )
1072 {
1073 // Separator: reject the selection
1074 resetSelection();
1075 return;
1076 }
1077 else
1078 {
1079 doApplyLayerPreset( m_cbLayerPresets->GetStringSelection() );
1080 }
1081
1082 // Move to front of MRU list
1083 if( m_presetMRU.Index( name ) != wxNOT_FOUND )
1084 m_presetMRU.Remove( name );
1085
1086 m_presetMRU.Insert( name, 0 );
1087
1088 passOnFocus();
1089}
1090
1091
1092void APPEARANCE_CONTROLS_3D::doApplyLayerPreset( const wxString& aPresetName )
1093{
1094 BOARD_ADAPTER& adapter = m_frame->GetAdapter();
1095
1096 if( aPresetName == FOLLOW_PCB || aPresetName == FOLLOW_PLOT_SETTINGS )
1097 {
1098 adapter.m_Cfg->m_CurrentPreset = aPresetName;
1099 adapter.SetVisibleLayers( adapter.GetVisibleLayers() );
1100 }
1101 else if( LAYER_PRESET_3D* preset = adapter.m_Cfg->FindPreset( aPresetName ) )
1102 {
1103 adapter.m_Cfg->m_CurrentPreset = aPresetName;
1104 adapter.SetVisibleLayers( preset->layers );
1105 adapter.SetLayerColors( preset->colors );
1106
1107 if( preset->name.Lower() == _( "legacy colors" ) )
1108 adapter.m_Cfg->m_UseStackupColors = false;
1109 }
1110 else
1111 {
1112 return;
1113 }
1114
1116 m_frame->NewDisplay( true );
1117}
1118
1119
1121{
1122 m_viewportsLabel->SetLabel( wxString::Format( _( "Viewports (%s+Tab):" ),
1124
1125 m_cbViewports->Clear();
1126
1127 for( std::pair<const wxString, VIEWPORT3D>& pair : m_viewports )
1128 m_cbViewports->Append( pair.first, static_cast<void*>( &pair.second ) );
1129
1130 m_cbViewports->Append( wxT( "---" ) );
1131 m_cbViewports->Append( _( "Save viewport..." ) );
1132 m_cbViewports->Append( _( "Delete viewport..." ) );
1133
1134 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 );
1135 m_lastSelectedViewport = nullptr;
1136}
1137
1138
1139void APPEARANCE_CONTROLS_3D::onViewportChanged( wxCommandEvent& aEvent )
1140{
1141 int count = m_cbViewports->GetCount();
1142 int index = m_cbViewports->GetSelection();
1143
1144 if( index >= 0 && index < count - 3 )
1145 {
1146 VIEWPORT3D* viewport = static_cast<VIEWPORT3D*>( m_cbViewports->GetClientData( index ) );
1147
1148 wxCHECK( viewport, /* void */ );
1149
1150 doApplyViewport( *viewport );
1151
1152 if( !viewport->name.IsEmpty() )
1153 {
1154 if( m_viewportMRU.Index( viewport->name ) != wxNOT_FOUND )
1155 m_viewportMRU.Remove( viewport->name );
1156
1157 m_viewportMRU.Insert( viewport->name, 0 );
1158 }
1159 }
1160 else if( index == count - 2 )
1161 {
1162 // Save current state to new preset
1163 wxString name;
1164
1165 wxTextEntryDialog dlg( wxGetTopLevelParent( this ), _( "Viewport name:" ),
1166 _( "Save Viewport" ), name );
1167
1168 if( dlg.ShowModal() != wxID_OK )
1169 {
1171 m_cbViewports->SetStringSelection( m_lastSelectedViewport->name );
1172 else
1173 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 );
1174
1175 return;
1176 }
1177
1178 name = dlg.GetValue();
1179 bool exists = m_viewports.count( name );
1180
1181 if( !exists )
1182 {
1183 m_viewports[name] = VIEWPORT3D( name, m_frame->GetCurrentCamera().GetViewMatrix() );
1184
1185 index = m_cbViewports->Insert( name, index-1, static_cast<void*>( &m_viewports[name] ) );
1186 }
1187 else
1188 {
1189 m_viewports[name].matrix = m_frame->GetCurrentCamera().GetViewMatrix();
1190 index = m_cbViewports->FindString( name );
1191
1192 if( m_viewportMRU.Index( name ) != wxNOT_FOUND )
1193 m_viewportMRU.Remove( name );
1194 }
1195
1196 m_cbViewports->SetSelection( index );
1197 m_viewportMRU.Insert( name, 0 );
1198
1199 return;
1200 }
1201 else if( index == count - 1 )
1202 {
1203 // Delete an existing viewport
1204 wxArrayString headers;
1205 std::vector<wxArrayString> items;
1206
1207 headers.Add( _( "Viewports" ) );
1208
1209 for( std::pair<const wxString, VIEWPORT3D>& pair : m_viewports )
1210 {
1211 wxArrayString item;
1212 item.Add( pair.first );
1213 items.emplace_back( item );
1214 }
1215
1216 EDA_LIST_DIALOG dlg( m_frame, _( "Delete Viewport" ), headers, items );
1217 dlg.SetListLabel( _( "Select viewport:" ) );
1218
1219 if( dlg.ShowModal() == wxID_OK )
1220 {
1221 wxString viewportName = dlg.GetTextSelection();
1222 int idx = m_cbViewports->FindString( viewportName );
1223
1224 if( idx != wxNOT_FOUND )
1225 {
1226 m_viewports.erase( viewportName );
1227 m_cbViewports->Delete( idx );
1228 }
1229
1230 if( m_viewportMRU.Index( viewportName ) != wxNOT_FOUND )
1231 m_viewportMRU.Remove( viewportName );
1232 }
1233
1235 m_cbViewports->SetStringSelection( m_lastSelectedViewport->name );
1236 else
1237 m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 );
1238
1239 return;
1240 }
1241
1242 passOnFocus();
1243}
1244
1245
1246void APPEARANCE_CONTROLS_3D::onUpdateViewportsCb( wxUpdateUIEvent& aEvent )
1247{
1248 int count = m_cbViewports->GetCount();
1249 int index = m_cbViewports->GetSelection();
1250
1251 if( index >= 0 && index < count - 3 )
1252 {
1253 VIEWPORT3D* viewport = static_cast<VIEWPORT3D*>( m_cbViewports->GetClientData( index ) );
1254
1255 wxCHECK( viewport, /* void */ );
1256
1257 if( m_frame->GetCurrentCamera().GetViewMatrix() != viewport->matrix )
1258 m_cbViewports->SetSelection( -1 );
1259 }
1260}
1261
1262
1264{
1265 m_frame->GetCurrentCamera().SetViewMatrix( aViewport.matrix );
1266
1267 if( m_frame->GetAdapter().m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL )
1268 m_frame->GetCanvas()->Request_refresh();
1269 else
1270 m_frame->GetCanvas()->RenderRaytracingRequest();
1271}
1272
1273
1275{
1276 m_focusOwner->SetFocus();
1277}
int index
const char * name
static constexpr int REBUILD_DELAY_MS
Debounce delay for rebuilding the 3D view after control changes.
static bool isCopperLayer3D(int aLayer)
#define RR
Render Row abbreviation to reduce source width.
static constexpr int ID_HIDE_ALL_COPPER_LAYERS
static bool isStackupColorLayer3D(int aLayer)
static constexpr int ID_SHOW_ALL_COPPER_LAYERS
static constexpr int ID_HIDE_ALL_INNER_LAYERS
static constexpr int ID_SHOW_ALL_INNER_LAYERS
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
Container for an appearance setting (can control a layer class, object type, etc.)
APPEARANCE_CONTROLS_3D_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
void OnLanguageChanged(wxCommandEvent &aEvent)
GRID_BITMAP_TOGGLE_RENDERER * m_toggleGridRenderer
void onLayerPresetChanged(wxCommandEvent &aEvent) override
void updateLayerPresetWidget(const wxString &aName)
std::vector< VIEWPORT3D > GetUserViewports() const
Return a list of viewports created by the user.
void OnRedrawTriggerTimer(wxTimerEvent &aEvent)
void ApplyViewport(const wxString &aPresetName)
wxTimer m_redrawTriggerTimer
A timer used to rate-limit redraws when UI controls change.
void rebuildLayerPresetsWidget(bool aReset)
void onColorSwatchChanged(COLOR_SWATCH *aSwatch)
APPEARANCE_CONTROLS_3D(EDA_3D_VIEWER_FRAME *aParent, wxWindow *aFocusOwner)
std::vector< std::unique_ptr< APPEARANCE_SETTING_3D > > m_layerSettings
std::map< int, APPEARANCE_SETTING_3D * > m_layerSettingsMap
static const APPEARANCE_SETTING_3D s_layerSettings[]
Template for object appearance settings.
void doApplyLayerPreset(const wxString &aPresetName)
EDA_3D_VIEWER_FRAME * m_frame
void onUpdateViewportsCb(wxUpdateUIEvent &aEvent) override
void OnSetFocus(wxFocusEvent &aEvent) override
void OnResetLayerSpacing(wxCommandEvent &aEvent) override
void OnLayerVisibilityChanged(int aLayer, bool isVisible)
void OnLayerContextMenu(wxContextMenuEvent &aEvent)
void OnSize(wxSizeEvent &aEvent) override
void doApplyViewport(const VIEWPORT3D &aViewport)
std::map< wxString, VIEWPORT3D > m_viewports
void ApplyLayerPreset(const wxString &aPresetName)
void onViewportChanged(wxCommandEvent &aEvent) override
void OnLayerScaleChange(wxSpinDoubleEvent &aEvent) override
void SetUserViewports(std::vector< VIEWPORT3D > &aPresetList)
Update the current viewports from those saved in the project file.
A checkbox control except with custom bitmaps for the checked and unchecked states.
Helper class to handle information needed to display 3D board.
void SetVisibleLayers(const std::bitset< LAYER_3D_END > &aLayers)
std::bitset< LAYER_3D_END > GetVisibleLayers() const
void SetLayerColors(const std::map< int, COLOR4D > &aColors)
EDA_3D_VIEWER_SETTINGS * m_Cfg
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
int GetCopperLayerCount() const
Definition board.cpp:1155
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition board.cpp:960
static const COLOR4D WHITE
Definition color4d.h:403
A simple color swatch of the kind used to set layer colors.
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.
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:
static TOOL_ACTION showNavigator
static TOOL_ACTION showNotInPosFile
static TOOL_ACTION showTHT
static TOOL_ACTION showDNP
static TOOL_ACTION showSMD
static TOOL_ACTION showVirtual
static TOOL_ACTION showBBoxes
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
LAYER_PRESET_3D * FindPreset(const wxString &aName)
std::vector< LAYER_PRESET_3D > m_LayerPresets
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)
A toggle button renderer for a wxGrid, similar to BITMAP_TOGGLE.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Object to render the board using openGL.
void RebuildHitTestAsync()
Rebuild the raytracing hit-test scene in the background after a visibility change.
void Load3dModelsIfNeeded()
Load footprint models if they are not already loaded, i.e.
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 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
@ 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)
Declaration of the eda_3d_viewer class.
#define FOLLOW_PLOT_SETTINGS
#define FOLLOW_PCB
#define VIEWPORT_SWITCH_KEY
#define PRESET_SWITCH_KEY
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
PCB_LAYER_ID Map3DLayerToPCBLayer(int aLayer)
Definition layer_id.cpp:280
int MapPCBLayerTo3DLayer(PCB_LAYER_ID aLayer)
Definition layer_id.cpp:355
@ LAYER_3D_COPPER_INNER_30
Definition layer_ids.h:687
@ LAYER_3D_USER_1
Definition layer_ids.h:602
@ LAYER_3D_SOLDERMASK_TOP
Definition layer_ids.h:591
@ LAYER_3D_USER_8
Definition layer_ids.h:609
@ LAYER_3D_USER_22
Definition layer_ids.h:623
@ LAYER_3D_USER_44
Definition layer_ids.h:645
@ LAYER_3D_USER_23
Definition layer_ids.h:624
@ LAYER_3D_NAVIGATOR
Definition layer_ids.h:652
@ LAYER_3D_USER_28
Definition layer_ids.h:629
@ LAYER_3D_BOUNDING_BOXES
Definition layer_ids.h:653
@ LAYER_3D_START
Definition layer_ids.h:581
@ LAYER_3D_USER_32
Definition layer_ids.h:633
@ LAYER_3D_USER_19
Definition layer_ids.h:620
@ LAYER_3D_USER_25
Definition layer_ids.h:626
@ LAYER_3D_ADHESIVE
Definition layer_ids.h:593
@ LAYER_3D_USER_3
Definition layer_ids.h:604
@ LAYER_3D_USER_21
Definition layer_ids.h:622
@ LAYER_3D_USER_26
Definition layer_ids.h:627
@ LAYER_3D_SMD_MODELS
Definition layer_ids.h:648
@ LAYER_3D_USER_24
Definition layer_ids.h:625
@ LAYER_3D_USER_43
Definition layer_ids.h:644
@ LAYER_3D_BACKGROUND_TOP
Definition layer_ids.h:584
@ LAYER_3D_USER_COMMENTS
Definition layer_ids.h:594
@ LAYER_3D_SOLDERMASK_BOTTOM
Definition layer_ids.h:590
@ LAYER_3D_USER_11
Definition layer_ids.h:612
@ LAYER_3D_USER_41
Definition layer_ids.h:642
@ LAYER_3D_USER_17
Definition layer_ids.h:618
@ LAYER_3D_BOARD
Definition layer_ids.h:585
@ LAYER_3D_PLATED_BARRELS
Definition layer_ids.h:655
@ LAYER_3D_USER_ECO1
Definition layer_ids.h:596
@ LAYER_3D_COPPER_INNER_1
Definition layer_ids.h:658
@ LAYER_3D_USER_20
Definition layer_ids.h:621
@ LAYER_3D_USER_31
Definition layer_ids.h:632
@ LAYER_3D_USER_ECO2
Definition layer_ids.h:597
@ LAYER_3D_TH_MODELS
Definition layer_ids.h:647
@ LAYER_3D_B_FAB
Definition layer_ids.h:599
@ LAYER_3D_USER_15
Definition layer_ids.h:616
@ LAYER_3D_USER_38
Definition layer_ids.h:639
@ LAYER_3D_USER_13
Definition layer_ids.h:614
@ LAYER_3D_USER_33
Definition layer_ids.h:634
@ LAYER_3D_USER_35
Definition layer_ids.h:636
@ LAYER_3D_USER_29
Definition layer_ids.h:630
@ LAYER_3D_USER_40
Definition layer_ids.h:641
@ LAYER_3D_SILKSCREEN_TOP
Definition layer_ids.h:589
@ LAYER_3D_B_COURTYARD
Definition layer_ids.h:601
@ LAYER_3D_VIRTUAL_MODELS
Definition layer_ids.h:649
@ LAYER_3D_MODELS_MARKED_DNP
Definition layer_ids.h:651
@ LAYER_3D_USER_7
Definition layer_ids.h:608
@ LAYER_3D_COPPER_TOP
Definition layer_ids.h:586
@ LAYER_3D_USER_12
Definition layer_ids.h:613
@ LAYER_3D_SOLDERPASTE
Definition layer_ids.h:592
@ LAYER_3D_USER_30
Definition layer_ids.h:631
@ LAYER_3D_USER_36
Definition layer_ids.h:637
@ LAYER_3D_USER_2
Definition layer_ids.h:603
@ LAYER_3D_USER_18
Definition layer_ids.h:619
@ LAYER_3D_OFF_BOARD_SILK
Definition layer_ids.h:654
@ LAYER_3D_USER_14
Definition layer_ids.h:615
@ LAYER_3D_USER_5
Definition layer_ids.h:606
@ LAYER_3D_USER_37
Definition layer_ids.h:638
@ LAYER_3D_USER_10
Definition layer_ids.h:611
@ LAYER_3D_MODELS_NOT_IN_POS
Definition layer_ids.h:650
@ LAYER_3D_USER_42
Definition layer_ids.h:643
@ LAYER_3D_USER_45
Definition layer_ids.h:646
@ LAYER_3D_USER_6
Definition layer_ids.h:607
@ LAYER_3D_USER_4
Definition layer_ids.h:605
@ LAYER_3D_USER_27
Definition layer_ids.h:628
@ LAYER_3D_USER_DRAWINGS
Definition layer_ids.h:595
@ LAYER_3D_COPPER_BOTTOM
Definition layer_ids.h:587
@ LAYER_3D_USER_39
Definition layer_ids.h:640
@ LAYER_3D_USER_9
Definition layer_ids.h:610
@ LAYER_3D_BACKGROUND_BOTTOM
Definition layer_ids.h:583
@ LAYER_3D_USER_16
Definition layer_ids.h:617
@ LAYER_3D_SILKSCREEN_BOTTOM
Definition layer_ids.h:588
@ LAYER_3D_F_COURTYARD
Definition layer_ids.h:600
@ LAYER_3D_USER_34
Definition layer_ids.h:635
@ LAYER_3D_END
Definition layer_ids.h:689
@ LAYER_3D_F_FAB
Definition layer_ids.h:598
@ LAYER_FP_REFERENCES
Show footprints references (when texts are visible).
Definition layer_ids.h:262
@ LAYER_FP_TEXT
Definition layer_ids.h:236
@ LAYER_FP_VALUES
Show footprints values (when texts are visible).
Definition layer_ids.h:259
bool IsInnerCopperLayer(int aLayerId)
Test whether a layer is an inner (In1_Cu to In30_Cu) copper layer.
Definition layer_ids.h:766
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
const int c_IndicatorSizeDIP
Definition ui_common.h:54
#define _HKI(x)
Definition page_info.cpp:40
see class PGM_BASE
static bool isCopper(const PNS::ITEM *aItem)
wxString name
A name for this layer set.