KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_3d_viewer_frame.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) 2015-2016 Mario Luzeiro <[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <wx/filename.h>
27#include <wx/msgdlg.h>
28#include <wx/string.h>
29#include <wx/wupdlock.h>
30#include <wx/clipbrd.h>
31#include <wx/filedlg.h>
32#include <wx/dialog.h>
33#include "eda_3d_viewer_frame.h"
37#include <3d_viewer_id.h>
41#include <board.h>
42#include <advanced_config.h>
43#include <bitmaps.h>
45#include <core/arraydim.h>
46#include <dpi_scaling_common.h>
47#include <pgm_base.h>
48#include <project.h>
52#include <tool/action_manager.h>
53#include <tool/common_control.h>
54#include <tool/tool_manager.h>
56#include <tool/action_toolbar.h>
57#include <widgets/wx_infobar.h>
60#include <project_pcb.h>
61#include <toolbars_3d.h>
62
64
72const wxChar* EDA_3D_VIEWER_FRAME::m_logTrace = wxT( "KI_TRACE_EDA_3D_VIEWER" );
73
74
75BEGIN_EVENT_TABLE( EDA_3D_VIEWER_FRAME, KIWAY_PLAYER )
76
78 EVT_SET_FOCUS( EDA_3D_VIEWER_FRAME::OnSetFocus )
79
81 EDA_3D_VIEWER_FRAME::Process_Special_Functions )
82
83 EVT_MENU( wxID_CLOSE, EDA_3D_VIEWER_FRAME::Exit3DFrame )
84 EVT_MENU( ID_DISABLE_RAY_TRACING, EDA_3D_VIEWER_FRAME::onDisableRayTracing )
85
86 EVT_CLOSE( EDA_3D_VIEWER_FRAME::OnCloseWindow )
87END_EVENT_TABLE()
88
89
91 const wxString& aTitle, long style ) :
92 KIWAY_PLAYER( aKiway, aParent, FRAME_PCB_DISPLAY3D, aTitle, wxDefaultPosition,
93 wxDefaultSize, style, QUALIFIED_VIEWER3D_FRAMENAME( aParent ), unityScale ),
94 m_canvas( nullptr ),
95 m_currentCamera( m_trackBallCamera ),
96 m_trackBallCamera( 2 * RANGE_SCALE_3D )
97{
98 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME %s" ), aTitle );
99
100 m_disable_ray_tracing = false;
101 m_aboutTitle = _HKI( "KiCad 3D Viewer" );
102
103 // Give it an icon
104 wxIcon icon;
105 icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_3d ) );
106 SetIcon( icon );
107
108 // Create the status line
109 static const int status_dims[5] = { -1, 170, 130, 130, 130 };
110
111 wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) );
112 SetStatusWidths( arrayDim( status_dims ), status_dims );
113
115 EDA_3D_VIEWER_SETTINGS* cfg = GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" );
116
117 if( cfg )
118 aaMode = static_cast<ANTIALIASING_MODE>( cfg->m_Render.opengl_AA_mode );
119
120 m_canvas = new EDA_3D_CANVAS( this, OGL_ATT_LIST::GetAttributesList( aaMode, true ), m_boardAdapter,
121 m_currentCamera, PROJECT_PCB::Get3DCacheManager( &Prj() ) );
122
123 m_appearancePanel = new APPEARANCE_CONTROLS_3D( this, GetCanvas() );
124
125 LoadSettings( GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ) );
126 loadCommonSettings();
127
128 m_appearancePanel->SetUserViewports( Prj().GetProjectFile().m_Viewports3D );
129
130 // Create the manager
131 m_toolManager = new TOOL_MANAGER;
132 m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr,
133 GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ), this );
134
135 m_actions = new EDA_3D_ACTIONS();
136 m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
137 m_canvas->SetEventDispatcher( m_toolDispatcher );
138
139 // Register tools
140 m_toolManager->RegisterTool( new COMMON_CONTROL );
141 m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
142 m_toolManager->InitTools();
143
144 setupUIConditions();
145
146 if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
147 ctrlTool->SetRotationIncrement( cfg ? cfg->m_Camera.rotation_increment : 10.0 );
148
149 // Run the viewer control tool, it is supposed to be always active
150 m_toolManager->InvokeTool( "3DViewer.Control" );
151
152 ReCreateMenuBar();
153
154 m_toolbarSettings = Pgm().GetSettingsManager().GetToolbarSettings<EDA_3D_VIEWER_TOOLBAR_SETTINGS>( "3d_viewer-toolbars" );
155 configureToolbars();
156 RecreateToolbars();
157
158 m_infoBar = new WX_INFOBAR( this, &m_auimgr );
159
160 m_auimgr.SetManagedWindow( this );
161
162 m_auimgr.AddPane( m_tbTopMain, EDA_PANE().HToolbar().Name( wxS( "TopMainToolbar" ) )
163 .Top().Layer( 6 ) );
164 m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( wxS( "InfoBar" ) )
165 .Top().Layer( 1 ) );
166 m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( "LayersManager" )
167 .Right().Layer( 3 )
168 .Caption( _( "Appearance" ) ).PaneBorder( false )
169 .MinSize( 180, -1 ).BestSize( 190, -1 ) );
170 m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
171 .Center() );
172
173 wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
174
175 if( cfg && cfg->m_AuiPanels.right_panel_width > 0 )
176 SetAuiPaneSize( m_auimgr, layersManager, cfg->m_AuiPanels.right_panel_width, -1 );
177
178 if( cfg )
179 layersManager.Show( cfg->m_AuiPanels.show_layer_manager );
180
181 // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
182 // hiding it.
183 m_auimgr.Update();
184
185 // We don't want the infobar displayed right away
186 m_auimgr.GetPane( wxS( "InfoBar" ) ).Hide();
187 m_auimgr.Update();
188
189 m_canvas->SetInfoBar( m_infoBar );
190 m_canvas->SetStatusBar( status_bar );
191
192 try
193 {
194 m_spaceMouse = std::make_unique<NL_3D_VIEWER_PLUGIN>( m_canvas );
195 }
196 catch( const std::system_error& e )
197 {
198 wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
199 }
200
201 // Fixes bug in Windows (XP and possibly others) where the canvas requires the focus
202 // in order to receive mouse events. Otherwise, the user has to click somewhere on
203 // the canvas before it will respond to mouse wheel events.
204 m_canvas->SetFocus();
205}
206
207
209{
211
212 m_canvas->SetEventDispatcher( nullptr );
213
214 m_auimgr.UnInit();
215}
216
217
219{
221
224
225// Helper to define check conditions
226#define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) )
227
228 auto raytracing =
229 [this]( const SELECTION& aSel )
230 {
231 return m_boardAdapter.m_Cfg->m_Render.engine != RENDER_ENGINE::OPENGL;
232 };
233 auto showTH =
234 [this]( const SELECTION& aSel )
235 {
237 };
238 auto showSMD =
239 [this]( const SELECTION& aSel )
240 {
242 };
243 auto showVirtual =
244 [this]( const SELECTION& aSel )
245 {
247 };
248 auto show_NotInPosfile =
249 [this]( const SELECTION& aSel )
250 {
252 };
253 auto show_DNP =
254 [this]( const SELECTION& aSel )
255 {
257 };
258 auto showBBoxes =
259 [this]( const SELECTION& aSel )
260 {
262 };
263 auto showNavig = [this]( const SELECTION& aSel )
264 {
266 };
267 auto ortho =
268 [this]( const SELECTION& )
269 {
270 return m_currentCamera.GetProjection() == PROJECTION_TYPE::ORTHO;
271 };
272
273 auto appearances =
274 [this]( const SELECTION& aSel )
275 {
277 };
278
280
285 ACTION_CONDITIONS().Check( show_NotInPosfile ) );
287
290
291 mgr->SetConditions( EDA_3D_ACTIONS::noGrid, GridSizeCheck( GRID3D_TYPE::NONE ) );
292 mgr->SetConditions( EDA_3D_ACTIONS::show10mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_10MM ) );
293 mgr->SetConditions( EDA_3D_ACTIONS::show5mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_5MM ) );
294 mgr->SetConditions( EDA_3D_ACTIONS::show2_5mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_2P5MM ) );
295 mgr->SetConditions( EDA_3D_ACTIONS::show1mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_1MM ) );
297
299 ACTION_CONDITIONS().Check( appearances ) );
300
301#undef GridSizeCheck
302}
303
304
305bool EDA_3D_VIEWER_FRAME::TryBefore( wxEvent& aEvent )
306{
307 static bool s_presetSwitcherShown = false;
308 static bool s_viewportSwitcherShown = false;
309
310 // wxWidgets generates no key events for the tab key when the ctrl key is held down. One
311 // way around this is to look at all events and inspect the keyboard state of the tab key.
312 // However, this runs into issues on some linux VMs where querying the keyboard state is
313 // very slow. Fortunately we only use ctrl-tab on Mac, so we implement this lovely hack:
314#ifdef __WXMAC__
315 if( wxGetKeyState( WXK_TAB ) )
316#else
317 if( ( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
318 && static_cast<wxKeyEvent&>( aEvent ).GetKeyCode() == WXK_TAB )
319#endif
320 {
321 if( !s_presetSwitcherShown && wxGetKeyState( PRESET_SWITCH_KEY ) )
322 {
323 if( m_appearancePanel && this->IsActive() )
324 {
325 wxArrayString mru = m_appearancePanel->GetLayerPresetsMRU();
326
327 if( mru.size() > 0 )
328 {
329 for( wxString& str : mru )
330 {
331 if( str == FOLLOW_PCB )
332 str = _( "Follow PCB Editor" );
333 else if( str == FOLLOW_PLOT_SETTINGS )
334 str = _( "Follow PCB Plot Settings" );
335 }
336
337 EDA_VIEW_SWITCHER switcher( this, mru, PRESET_SWITCH_KEY );
338
339 s_presetSwitcherShown = true;
340 switcher.ShowModal();
341 s_presetSwitcherShown = false;
342
343 int idx = switcher.GetSelection();
344
345 if( idx >= 0 && idx < (int) mru.size() )
346 {
347 wxString internalName = m_appearancePanel->GetLayerPresetsMRU()[idx];
348 m_appearancePanel->ApplyLayerPreset( internalName );
349 }
350
351 return true;
352 }
353 }
354 }
355 else if( !s_viewportSwitcherShown && wxGetKeyState( VIEWPORT_SWITCH_KEY ) )
356 {
357 if( this->IsActive() )
358 {
359 const wxArrayString& viewportMRU = m_appearancePanel->GetViewportsMRU();
360
361 if( viewportMRU.size() > 0 )
362 {
363 EDA_VIEW_SWITCHER switcher( this, viewportMRU, VIEWPORT_SWITCH_KEY );
364
365 s_viewportSwitcherShown = true;
366 switcher.ShowModal();
367 s_viewportSwitcherShown = false;
368
369 int idx = switcher.GetSelection();
370
371 if( idx >= 0 && idx < (int) viewportMRU.size() )
372 m_appearancePanel->ApplyViewport( viewportMRU[idx] );
373
374 return true;
375 }
376 }
377 }
378 }
379
380 return wxFrame::TryBefore( aEvent );
381}
382
383
384void EDA_3D_VIEWER_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
385{
387
388 if( m_spaceMouse && aEvent.IsIconized() )
389 m_spaceMouse->SetFocus( false );
390}
391
392
394{
395 // This will schedule a request to load later
396 // ReloadRequest also updates the board pointer so always call it first
397 if( m_canvas )
399
402}
403
404
405void EDA_3D_VIEWER_FRAME::NewDisplay( bool aForceImmediateRedraw )
406{
407 if( m_canvas )
409
410 // After the ReloadRequest call, the refresh often takes a bit of time,
411 // and it is made here only on request.
412 if( m_canvas && aForceImmediateRedraw )
413 m_canvas->Refresh();
414}
415
416
418{
419 // Only update in OpenGL for an interactive interaction
420 if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL )
421 m_canvas->Request_refresh( true );
422}
423
424
426{
427 if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL )
429 else
430 NewDisplay( true );
431}
432
433
434void EDA_3D_VIEWER_FRAME::Exit3DFrame( wxCommandEvent &event )
435{
436 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::Exit3DFrame" ) );
437
438 Close( true );
439}
440
441
442void EDA_3D_VIEWER_FRAME::OnCloseWindow( wxCloseEvent &event )
443{
444 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::OnCloseWindow" ) );
445
446 // Do not show the layer manager during closing to avoid flicker on some platforms (Windows)
447 // that generate useless redraw of items in the Layer Manager
448 if( m_auimgr.GetPane( wxS( "LayersManager" ) ).IsShown() )
449 m_auimgr.GetPane( wxS( "LayersManager" ) ).Show( false );
450
451 if( m_canvas )
452 m_canvas->Close();
453
454 Destroy();
455 event.Skip( true );
456}
457
458
460{
461 if( m_canvas == nullptr )
462 return;
463
464 switch( event.GetId() )
465 {
467 {
469
470 if( EDA_3D_VIEWER_SETTINGS* cfg = GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ) )
471 cfg->ResetToDefaults();
472
473 LoadSettings( GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ) );
474
475 // Tell canvas that we (may have) changed the render engine
477 NewDisplay( true );
478 return;
479 }
480
481 default:
482 wxFAIL_MSG( wxT( "Invalid event in EDA_3D_VIEWER_FRAME::Process_Special_Functions()" ) );
483 return;
484 }
485}
486
487
488void EDA_3D_VIEWER_FRAME::onDisableRayTracing( wxCommandEvent& aEvent )
489{
490 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::%s disabling ray tracing." ), __WXFUNCTION__ );
491
493 m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL;
494}
495
496
497void EDA_3D_VIEWER_FRAME::OnActivate( wxActivateEvent &aEvent )
498{
499 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::OnActivate" ) );
500
501 if( aEvent.GetActive() && m_canvas )
502 {
503 // Reload data if 3D frame shows a board,
504 // because it can be changed since last frame activation
507
508 // Activates again the focus of the canvas so it will catch mouse and key events
509 m_canvas->SetFocus();
510 }
511
512 if( m_spaceMouse )
513 m_spaceMouse->SetFocus( aEvent.GetActive() );
514
515 aEvent.Skip(); // required under wxMAC
516}
517
518
519void EDA_3D_VIEWER_FRAME::OnSetFocus( wxFocusEvent& aEvent )
520{
521 // Activates again the focus of the canvas so it will catch mouse and key events
522 if( m_canvas )
523 m_canvas->SetFocus();
524
525 aEvent.Skip();
526}
527
528
530{
532
533 // Dynamic_cast here will fail on Mac when called from CvPCB.
534 EDA_3D_VIEWER_SETTINGS* cfg = static_cast<EDA_3D_VIEWER_SETTINGS*>( aCfg );
535
536 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::LoadSettings" ) );
537
538 if( cfg )
539 {
540 applySettings( cfg );
541
543
544 // When opening the 3D viewer, we use the OpenGL mode, never the ray tracing engine
545 // because the ray tracing is very time consuming, and can be seen as not working
546 // (freeze window) with large boards.
547 m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL;
548
550 {
551 wxString legacyColorsPresetName = _( "legacy colors" );
552
553 cfg->m_UseStackupColors = false;
554
555 if( !cfg->FindPreset( legacyColorsPresetName ) )
556 {
557 cfg->m_LayerPresets.emplace_back( legacyColorsPresetName,
558 GetAdapter().GetDefaultVisibleLayers(),
559 GetAdapter().GetDefaultColors() );
560 }
561
563 }
564
565 m_boardAdapter.InitSettings( nullptr, nullptr );
566
569 }
570}
571
572
574{
575 EDA_BASE_FRAME::SaveSettings( GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ) );
576
577 if( EDA_3D_VIEWER_SETTINGS* cfg = GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ) )
578 {
579 cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
580
581 cfg->m_Camera.animation_enabled = m_canvas->GetAnimationEnabled();
582 cfg->m_Camera.moving_speed_multiplier = m_canvas->GetMovingSpeedMultiplier();
583 cfg->m_Camera.projection_mode = m_canvas->GetProjectionMode();
584
585 if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
586 cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement();
587 }
588}
589
590
592{
593 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::CommonSettingsChanged" ) );
594
595 // Regen menu bars, etc
597
599 applySettings( GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ) );
600
602
603 NewDisplay( true );
604}
605
606
608{
610
611 SetTitle( _( "3D Viewer" ) );
613
615 {
616 wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_appearancePanel );
617 lm_pane_info.Caption( _( "Appearance" ) );
618 }
619
620 SetStatusText( wxEmptyString, ACTIVITY );
621 SetStatusText( wxEmptyString, HOVERED_ITEM );
622}
623
624
626{
627 wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
628
629 if( EDA_3D_VIEWER_SETTINGS* cfg = GetAppSettings<EDA_3D_VIEWER_SETTINGS>( "3d_viewer" ) )
630 {
631 // show auxiliary Vertical layers and visibility manager toolbar
632 cfg->m_AuiPanels.show_layer_manager = !cfg->m_AuiPanels.show_layer_manager;
633
634 layersManager.Show( cfg->m_AuiPanels.show_layer_manager );
635
636 if( cfg->m_AuiPanels.show_layer_manager )
637 {
638 SetAuiPaneSize( m_auimgr, layersManager, cfg->m_AuiPanels.right_panel_width, -1 );
639 }
640 else
641 {
642 cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
643 m_auimgr.Update();
644 }
645 }
646}
647
648
650{
653}
654
655
657{
658 wxString fullFileName;
659 bool fmt_is_jpeg = false;
660
661 if( aFormat == EDA_3D_VIEWER_EXPORT_FORMAT::JPEG )
662 fmt_is_jpeg = true;
663
664 if( aFormat != EDA_3D_VIEWER_EXPORT_FORMAT::CLIPBOARD )
665 {
666 // Remember path between saves during this session only.
667 const wxString wildcard =
669 const wxString ext = fmt_is_jpeg ? FILEEXT::JpegFileExtension : FILEEXT::PngFileExtension;
670
671 // First time path is set to the project path.
674
676
677 wxFileDialog dlg( this, _( "3D Image File Name" ),
679 m_defaultSaveScreenshotFileName.GetFullName(), wildcard,
680 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
681
682 if( dlg.ShowModal() == wxID_CANCEL )
683 return;
684
685 m_defaultSaveScreenshotFileName = dlg.GetPath();
686
687 if( m_defaultSaveScreenshotFileName.GetExt().IsEmpty() )
689
690 fullFileName = m_defaultSaveScreenshotFileName.GetFullPath();
691
692 wxFileName fn = fullFileName;
693
694 if( !fn.IsDirWritable() )
695 {
696 wxString msg;
697
698 msg.Printf( _( "Insufficient permissions to save file '%s'." ), fullFileName );
699 wxMessageBox( msg, _( "Error" ), wxOK | wxICON_ERROR, this );
700 return;
701 }
702
703 // Be sure the screen area destroyed by the file dialog is redrawn
704 // before making a screen copy.
705 // Without this call, under Linux the screen refresh is made to late.
706 wxYield();
707 }
708
709 // Be sure we have the latest 3D view (remember 3D view is buffered)
710 // Also ensure any highlighted item is not highlighted when creating screen shot
712 bool allow_highlight = cfg.highlight_on_rollover;
713 cfg.highlight_on_rollover = false;
714
715 m_canvas->DoRePaint(); // init first buffer
716 m_canvas->DoRePaint(); // init second buffer
717
718 // Build image from the 3D buffer
719 wxWindowUpdateLocker noUpdates( this );
720
721 wxImage screenshotImage;
722
723 if( m_canvas )
724 m_canvas->GetScreenshot( screenshotImage );
725
726 cfg.highlight_on_rollover = allow_highlight;
727
728 if( aFormat == EDA_3D_VIEWER_EXPORT_FORMAT::CLIPBOARD )
729 {
730 wxBitmap bitmap( screenshotImage );
731
732 wxLogNull doNotLog; // disable logging of failed clipboard actions
733
734 if( wxTheClipboard->Open() )
735 {
736 wxBitmapDataObject* dobjBmp = new wxBitmapDataObject( bitmap );
737
738 if( !wxTheClipboard->SetData( dobjBmp ) )
739 wxMessageBox( _( "Failed to copy image to clipboard" ) );
740
741 wxTheClipboard->Flush(); /* the data in clipboard will stay
742 * available after the application exits */
743 wxTheClipboard->Close();
744 }
745 }
746 else
747 {
748 if( !screenshotImage.SaveFile( fullFileName,
749 fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
750 wxMessageBox( _( "Can't save file" ) );
751
752 screenshotImage.Destroy();
753 }
754}
755
756
758{
759 wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::RenderEngineChanged()" ) );
760
761 if( m_canvas )
763}
764
765
767{
768 wxCHECK_RET( m_canvas, wxT( "Cannot load settings to null canvas" ) );
769
770 COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
771
772 // TODO(JE) use all control options
774}
775
776
778{
779 m_boardAdapter.m_Cfg = cfg;
780
784
786}
@ ID_DISABLE_RAY_TRACING
Definition: 3d_viewer_id.h:43
@ ID_START_COMMAND_3D
Definition: 3d_viewer_id.h:36
@ ID_MENU_COMMAND_END
Definition: 3d_viewer_id.h:41
@ ID_MENU3D_RESET_DEFAULTS
Definition: 3d_viewer_id.h:38
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:115
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:104
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
Definition: board_adapter.h:66
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
std::vector< VIEWPORT3D > GetUserViewports() const
Return a list of viewports created by the user.
void ApplyViewport(const wxString &aPresetName)
const wxArrayString & GetViewportsMRU()
void ApplyLayerPreset(const wxString &aPresetName)
const wxArrayString & GetLayerPresetsMRU()
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:108
void InitSettings(REPORTER *aStatusReporter, REPORTER *aWarningReporter)
Function to be called by the render when it need to reload the settings for the board.
void SetBoard(BOARD *aBoard) noexcept
Set current board to be rendered.
void SetLayerColors(const std::map< int, COLOR4D > &aColors)
EDA_3D_VIEWER_SETTINGS * m_Cfg
bool m_MousewheelPanning
std::map< int, COLOR4D > GetDefaultColors() const
PROJECTION_TYPE GetProjection()
Definition: camera.h:205
Handle actions that are shared between different applications.
int ShowModal() override
EDA_3D_ACTIONS.
static TOOL_ACTION showNavigator
static TOOL_ACTION showLayersManager
static TOOL_ACTION showNotInPosFile
static TOOL_ACTION showTHT
static TOOL_ACTION noGrid
static TOOL_ACTION show2_5mmGrid
static TOOL_ACTION show1mmGrid
static TOOL_ACTION showDNP
static TOOL_ACTION toggleOrtho
static TOOL_ACTION show10mmGrid
static TOOL_ACTION toggleRaytacing
static TOOL_ACTION show5mmGrid
static TOOL_ACTION showSMD
static TOOL_ACTION showVirtual
static TOOL_ACTION showBBoxes
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:51
int GetMovingSpeedMultiplier() const
void SetProjectionMode(int aMode)
void SetAnimationEnabled(bool aEnable)
Enable or disable camera animation when switching to a pre-defined view.
int GetProjectionMode() const
void DoRePaint()
The actual function to repaint the canvas.
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
bool IsReloadRequestPending() const
Query if there is a pending reload request.
Definition: eda_3d_canvas.h:93
bool GetAnimationEnabled() const
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
void SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
void RenderEngineChanged()
Notify that the render engine was changed.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
Handle view actions for various 3D canvases.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
void OnSetFocus(wxFocusEvent &event)
void onDisableRayTracing(wxCommandEvent &aEvent)
void CommonSettingsChanged(int aFlags) override
Notification that common settings are updated.
void applySettings(EDA_3D_VIEWER_SETTINGS *aSettings)
PCB_BASE_FRAME * Parent() const
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void OnActivate(wxActivateEvent &event)
bool TryBefore(wxEvent &aEvent) override
EDA_3D_CANVAS * m_canvas
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
BOARD_ADAPTER m_boardAdapter
std::unique_ptr< NL_3D_VIEWER_PLUGIN > m_spaceMouse
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
void Process_Special_Functions(wxCommandEvent &event)
void OnCloseWindow(wxCloseEvent &event)
void ShowChangedLanguage() override
void ReloadRequest()
Request reloading the 3D view.
wxFileName m_defaultSaveScreenshotFileName
BOARD_ADAPTER & GetAdapter()
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void loadCommonSettings()
Load configuration from common settings.
void TakeScreenshot(EDA_3D_VIEWER_EXPORT_FORMAT aFormat)
Create a Screenshot of the current 3D view.
void handleIconizeEvent(wxIconizeEvent &aEvent) override
Handle a window iconize event.
LAYER_PRESET_3D * FindPreset(const wxString &aName)
std::vector< LAYER_PRESET_3D > m_LayerPresets
Toolbar configuration for the 3D viewer.
Definition: toolbars_3d.h:29
virtual void handleIconizeEvent(wxIconizeEvent &aEvent)
Handle a window iconize event.
APPEARANCE_CONTROLS_3D * m_appearancePanel
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
wxAuiManager m_auimgr
virtual void RecreateToolbars()
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
static KIGFX::VC_SETTINGS GetVcSettings()
Gets a populated View Controls settings object dervived from our program settings.
Specialization of the wxAuiPaneInfo class for KiCad panels.
int GetSelection() const
void SetVcSettings(const KIGFX::VC_SETTINGS &aVcSettings)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:65
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:286
static const wxGLAttributes GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode, bool aAlpha=false)
Get a list of attributes to pass to wxGLCanvas.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:556
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
std::vector< VIEWPORT3D > m_Viewports3D
List of stored viewports (pos + zoom)
Definition: project_file.h:209
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
Definition: project_pcb.cpp:77
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:142
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:204
T * GetToolbarSettings(const wxString &aFilename)
Return a handle to the given toolbar settings.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:171
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
Master controller class:
Definition: tool_manager.h:62
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:306
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:76
#define _HKI(x)
#define _(s)
#define GridSizeCheck(x)
EVT_TOOL_RANGE(ID_START_COMMAND_3D, ID_MENU_COMMAND_END, EDA_3D_VIEWER_FRAME::Process_Special_Functions) EDA_3D_VIEWER_FRAME
Declaration of the eda_3d_viewer class.
EDA_3D_VIEWER_EXPORT_FORMAT
@ ACTIVITY
@ HOVERED_ITEM
#define FOLLOW_PLOT_SETTINGS
#define LEGACY_PRESET_FLAG
#define FOLLOW_PCB
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
#define VIEWPORT_SWITCH_KEY
#define PRESET_SWITCH_KEY
@ FRAME_PCB_DISPLAY3D
Definition: frame_type.h:47
static const std::string JpegFileExtension
static const std::string PngFileExtension
static wxString PngFileWildcard()
static wxString JpegFileWildcard()
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
PROJECT & Prj()
Definition: kicad.cpp:596
Declaration of the NL_3D_VIEWER_PLUGIN class.
ANTIALIASING_MODE
Anti-aliasing options.
Definition: ogl_attr_list.h:37
BOARD * GetBoard()
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:893
see class PGM_BASE
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
ACTION_CONDITIONS & Check(const SELECTION_CONDITION &aCondition)
Definition of file extensions used in Kicad.
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.