KiCad PCB EDA Suite
eda_3d_viewer.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 <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU 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, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <wx/filename.h>
26 #include <wx/msgdlg.h>
27 #include <wx/string.h>
28 #include <wx/wupdlock.h>
29 #include <wx/clipbrd.h>
30 #include <wx/filedlg.h>
31 #include <wx/treebook.h>
32 #include "eda_3d_viewer.h"
33 #include <eda_3d_viewer_settings.h>
34 #include <3d_viewer_id.h>
38 #include <bitmaps.h>
39 #include <board_design_settings.h>
41 #include <core/arraydim.h>
43 #include <gal/dpi_scaling.h>
44 #include <pgm_base.h>
45 #include <project.h>
48 #include <tool/action_manager.h>
49 #include <tool/common_control.h>
50 #include <tool/tool_manager.h>
51 #include <tool/tool_dispatcher.h>
52 #include <tool/action_toolbar.h>
53 #include <widgets/infobar.h>
54 #include <widgets/paged_dialog.h>
59 #include <panel_hotkeys_editor.h>
61 
69 const wxChar* EDA_3D_VIEWER_FRAME::m_logTrace = wxT( "KI_TRACE_EDA_3D_VIEWER" );
70 
71 
72 BEGIN_EVENT_TABLE( EDA_3D_VIEWER_FRAME, EDA_BASE_FRAME )
73 
74  EVT_ACTIVATE( EDA_3D_VIEWER_FRAME::OnActivate )
75  EVT_SET_FOCUS( EDA_3D_VIEWER_FRAME::OnSetFocus )
76 
78  EDA_3D_VIEWER_FRAME::Process_Special_Functions )
79 
80  EVT_MENU( wxID_CLOSE, EDA_3D_VIEWER_FRAME::Exit3DFrame )
81  EVT_MENU( ID_RENDER_CURRENT_VIEW, EDA_3D_VIEWER_FRAME::OnRenderEngineSelection )
82  EVT_MENU( ID_DISABLE_RAY_TRACING, EDA_3D_VIEWER_FRAME::OnDisableRayTracing )
83 
84  EVT_CLOSE( EDA_3D_VIEWER_FRAME::OnCloseWindow )
85 END_EVENT_TABLE()
86 
87 
89  const wxString &aTitle, long style ) :
90  KIWAY_PLAYER( aKiway, aParent, FRAME_PCB_DISPLAY3D, aTitle, wxDefaultPosition,
91  wxDefaultSize, style, QUALIFIED_VIEWER3D_FRAMENAME( aParent ) ),
92  m_mainToolBar( nullptr ),
93  m_canvas( nullptr ),
94  m_currentCamera( m_trackBallCamera ),
95  m_trackBallCamera( RANGE_SCALE_3D, 0.66f )
96 {
97  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME %s", aTitle );
98 
99  m_disable_ray_tracing = false;
100  m_aboutTitle = _( "KiCad 3D Viewer" );
101 
102  // Give it an icon
103  wxIcon icon;
104  icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_3d ) );
105  SetIcon( icon );
106 
107  // Create the status line
108  static const int status_dims[4] = { -1, 170, 130, 130 };
109 
110  wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) );
111  SetStatusWidths( arrayDim( status_dims ), status_dims );
112 
113  m_canvas = new EDA_3D_CANVAS( this,
114  OGL_ATT_LIST::GetAttributesList( m_boardAdapter.GetAntiAliasingMode() ),
115  m_boardAdapter, m_currentCamera,
116  Prj().Get3DCacheManager() );
117 
118  auto config = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
119  LoadSettings( config );
120 
121  // Some settings need the canvas
122  loadCommonSettings();
123 
124  // Create the manager
125  m_toolManager = new TOOL_MANAGER;
126  m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, config, this );
127 
128  m_actions = new EDA_3D_ACTIONS();
129  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
130  m_canvas->SetEventDispatcher( m_toolDispatcher );
131 
132  // Register tools
133  m_toolManager->RegisterTool( new COMMON_CONTROL );
134  m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
135  m_toolManager->InitTools();
136 
137  setupUIConditions();
138 
139  if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
140  ctrlTool->SetRotationIncrement( config->m_Camera.rotation_increment );
141 
142  // Run the viewer control tool, it is supposed to be always active
143  m_toolManager->InvokeTool( "3DViewer.Control" );
144 
145  CreateMenuBar();
146  ReCreateMainToolbar();
147 
148  m_infoBar = new WX_INFOBAR( this, &m_auimgr );
149 
150  m_auimgr.SetManagedWindow( this );
151 
152  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer( 6 ) );
153  m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) );
154  m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
155 
156  // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
157  // hiding it.
158  m_auimgr.Update();
159 
160  // We don't want the infobar displayed right away
161  m_auimgr.GetPane( "InfoBar" ).Hide();
162  m_auimgr.Update();
163 
164  m_canvas->SetInfoBar( m_infoBar );
165  m_canvas->SetStatusBar( status_bar );
166 
167  // Fixes bug in Windows (XP and possibly others) where the canvas requires the focus
168  // in order to receive mouse events. Otherwise, the user has to click somewhere on
169  // the canvas before it will respond to mouse wheel events.
170  m_canvas->SetFocus();
171 }
172 
173 
175 {
176  m_canvas->SetEventDispatcher( nullptr );
177 
178  m_auimgr.UnInit();
179 
180  // m_canvas delete will be called by wxWidget manager
181  //delete m_canvas;
182  //m_canvas = nullptr;
183 }
184 
185 
187 {
189 
192 
193 // Helper to define check conditions
194 #define FlagCheck( x ) ACTION_CONDITIONS().Check( cond.Flag( x ) )
195 #define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) )
196 
197  auto raytracingCondition = [this]( const SELECTION& aSel )
198  {
200  };
201 
203  ACTION_CONDITIONS().Check( raytracingCondition ) );
204 
211 
215  FlagCheck( FL_AXIS ) );
216 
222 
223 
224  auto orthoCondition =
225  [this]( const SELECTION& )
226  {
228  };
229 
230  mgr->SetConditions( EDA_3D_ACTIONS::toggleOrtho, ACTION_CONDITIONS().Check( orthoCondition ) );
231 
232 #undef FlagCheck
233 #undef GridSizeCheck
234 }
235 
236 
238  PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
239 {
240  wxTreebook* book = aParent->GetTreebook();
241 
242  book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
243  book->AddSubPage( new PANEL_3D_DISPLAY_OPTIONS( this, book ), _( "Display Options" ) );
244  book->AddSubPage( new PANEL_3D_OPENGL_OPTIONS( this, book ), _( "OpenGL" ) );
245  book->AddSubPage( new PANEL_3D_RAYTRACING_OPTIONS( this, book ), _( "Raytracing" ) );
246  book->AddSubPage( new PANEL_3D_COLORS( this, book ), _( "Colors" ) );
247 
248  aHotkeysPanel->AddHotKeys( GetToolManager() );
249 }
250 
251 
253 {
254  // This will schedule a request to load later
255  if( m_canvas )
256  m_canvas->ReloadRequest( GetBoard(), Prj().Get3DCacheManager() );
257 }
258 
259 
260 void EDA_3D_VIEWER_FRAME::NewDisplay( bool aForceImmediateRedraw )
261 {
262  ReloadRequest();
263 
264  // After the ReloadRequest call, the refresh often takes a bit of time,
265  // and it is made here only on request.
266  if( aForceImmediateRedraw )
267  m_canvas->Refresh();
268 }
269 
270 
272 {
273  // Only update in OpenGL for an interactive interaction
275  m_canvas->Request_refresh( true );
276 }
277 
278 
280 {
283  else
284  NewDisplay( true );
285 }
286 
287 
288 void EDA_3D_VIEWER_FRAME::Exit3DFrame( wxCommandEvent &event )
289 {
290  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::Exit3DFrame" );
291 
292  Close( true );
293 }
294 
295 
296 void EDA_3D_VIEWER_FRAME::OnCloseWindow( wxCloseEvent &event )
297 {
298  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::OnCloseWindow" );
299 
300  if( m_canvas )
301  m_canvas->Close();
302 
303  // m_canvas delete will be called by wxWidget manager
304  //delete m_canvas;
305  //m_canvas = nullptr;
306 
307  Destroy();
308  event.Skip( true );
309 }
310 
311 
313 {
314  int id = event.GetId();
315  bool isChecked = event.IsChecked();
316 
317  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::Process_Special_Functions id %d isChecked %d",
318  id,
319  isChecked );
320 
321  if( m_canvas == nullptr )
322  return;
323 
324  switch( id )
325  {
326  case ID_RELOAD3D_BOARD:
327  NewDisplay( true );
328  break;
329 
333  takeScreenshot( event );
334  return;
335 
337  {
338  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
339  cfg->ResetToDefaults();
340  LoadSettings( cfg );
341 
342  // Tell canvas that we (may have) changed the render engine
344 
345  NewDisplay( true );
346  }
347  return;
348 
349  default:
350  wxFAIL_MSG( "Invalid event in EDA_3D_VIEWER_FRAME::Process_Special_Functions()" );
351  return;
352  }
353 }
354 
355 
356 void EDA_3D_VIEWER_FRAME::OnRenderEngineSelection( wxCommandEvent &event )
357 {
358  const RENDER_ENGINE old_engine = m_boardAdapter.GetRenderEngine();
359 
360  if( old_engine == RENDER_ENGINE::OPENGL_LEGACY )
362  else
364 
365  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::OnRenderEngineSelection type %s ",
367  "OpenGL" );
368 
369  if( old_engine != m_boardAdapter.GetRenderEngine() )
371 }
372 
373 
374 void EDA_3D_VIEWER_FRAME::OnDisableRayTracing( wxCommandEvent& aEvent )
375 {
376  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::%s disabling ray tracing.", __WXFUNCTION__ );
377 
378  m_disable_ray_tracing = true;
380 }
381 
382 
383 void EDA_3D_VIEWER_FRAME::OnActivate( wxActivateEvent &aEvent )
384 {
385  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::OnActivate" );
386 
387  if( aEvent.GetActive() && m_canvas )
388  {
389  // Reload data if 3D frame shows a board,
390  // because it can be changed since last frame activation
393 
394  // Activates again the focus of the canvas so it will catch mouse and key events
395  m_canvas->SetFocus();
396  }
397 
398  aEvent.Skip(); // required under wxMAC
399 }
400 
401 
402 void EDA_3D_VIEWER_FRAME::OnSetFocus( wxFocusEvent& aEvent )
403 {
404  // Activates again the focus of the canvas so it will catch mouse and key events
405  if( m_canvas )
406  m_canvas->SetFocus();
407 
408  aEvent.Skip();
409 }
410 
411 
413 {
415 
416  EDA_3D_VIEWER_SETTINGS* cfg = dynamic_cast<EDA_3D_VIEWER_SETTINGS*>( aCfg );
417  wxASSERT( cfg );
418 
419  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::LoadSettings" );
420 
421  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
422 
423  auto set_color =
424  [] ( const COLOR4D& aColor, SFVEC4F& aTarget )
425  {
426  aTarget.r = aColor.r;
427  aTarget.g = aColor.g;
428  aTarget.b = aColor.b;
429  aTarget.a = aColor.a;
430  };
431 
434  set_color( colors->GetColor( LAYER_3D_BOARD ), m_boardAdapter.m_BoardBodyColor );
435  set_color( colors->GetColor( LAYER_3D_COPPER ), m_boardAdapter.m_CopperColor );
436  set_color( colors->GetColor( LAYER_3D_SILKSCREEN_BOTTOM ),
442 
443  if( cfg )
444  {
451 
454 
455  for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i )
456  {
459 
460  SFVEC2F sphericalCoord =
461  SFVEC2F( ( cfg->m_Render.raytrace_lightElevation[i] + 90.0f ) / 180.0f,
462  cfg->m_Render.raytrace_lightAzimuth[i] / 180.0f );
463 
464  sphericalCoord.x = glm::clamp( sphericalCoord.x, 0.0f, 1.0f );
465  sphericalCoord.y = glm::clamp( sphericalCoord.y, 0.0f, 2.0f );
466 
467  m_boardAdapter.m_RtLightSphericalCoords[i] = sphericalCoord;
468  }
469 
470 #define TRANSFER_SETTING( flag, field ) m_boardAdapter.SetFlag( flag, cfg->m_Render.field )
471 
473  TRANSFER_SETTING( FL_SUBTRACT_MASK_FROM_SILK, subtract_mask_from_silk );
474 
475  // OpenGL options
476  TRANSFER_SETTING( FL_RENDER_OPENGL_COPPER_THICKNESS, opengl_copper_thickness );
477  TRANSFER_SETTING( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, opengl_show_model_bbox );
478  TRANSFER_SETTING( FL_HIGHLIGHT_ROLLOVER_ITEM, opengl_highlight_on_rollover );
479  TRANSFER_SETTING( FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE, opengl_AA_disableOnMove );
481  opengl_thickness_disableOnMove );
482  TRANSFER_SETTING( FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE, opengl_vias_disableOnMove );
483  TRANSFER_SETTING( FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE, opengl_holes_disableOnMove );
484 
485  // Raytracing options
486  TRANSFER_SETTING( FL_RENDER_RAYTRACING_SHADOWS, raytrace_shadows );
487  TRANSFER_SETTING( FL_RENDER_RAYTRACING_BACKFLOOR, raytrace_backfloor );
488  TRANSFER_SETTING( FL_RENDER_RAYTRACING_REFRACTIONS, raytrace_refractions );
489  TRANSFER_SETTING( FL_RENDER_RAYTRACING_REFLECTIONS, raytrace_reflections );
490  TRANSFER_SETTING( FL_RENDER_RAYTRACING_POST_PROCESSING, raytrace_post_processing );
491  TRANSFER_SETTING( FL_RENDER_RAYTRACING_ANTI_ALIASING, raytrace_anti_aliasing );
492  TRANSFER_SETTING( FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES, raytrace_procedural_textures );
493 
494  TRANSFER_SETTING( FL_AXIS, show_axis );
495  TRANSFER_SETTING( FL_FP_ATTRIBUTES_NORMAL, show_footprints_normal );
496  TRANSFER_SETTING( FL_FP_ATTRIBUTES_NORMAL_INSERT, show_footprints_insert );
497  TRANSFER_SETTING( FL_FP_ATTRIBUTES_VIRTUAL, show_footprints_virtual );
498  TRANSFER_SETTING( FL_ZONE, show_zones );
499  TRANSFER_SETTING( FL_ADHESIVE, show_adhesive );
500  TRANSFER_SETTING( FL_SILKSCREEN, show_silkscreen );
501  TRANSFER_SETTING( FL_SOLDERMASK, show_soldermask );
502  TRANSFER_SETTING( FL_SOLDERPASTE, show_solderpaste );
503  TRANSFER_SETTING( FL_COMMENTS, show_comments );
504  TRANSFER_SETTING( FL_ECO, show_eco );
505  TRANSFER_SETTING( FL_SHOW_BOARD_BODY, show_board_body );
506  TRANSFER_SETTING( FL_CLIP_SILK_ON_VIA_ANNULUS, clip_silk_on_via_annulus );
507  TRANSFER_SETTING( FL_RENDER_PLATED_PADS_AS_PLATED, renderPlatedPadsAsPlated );
508 
509  m_boardAdapter.SetGridType( static_cast<GRID3D_TYPE>( cfg->m_Render.grid_type ) );
511  static_cast<ANTIALIASING_MODE>( cfg->m_Render.opengl_AA_mode ) );
512 
515 
519 
523 
528 
529  // When opening the 3D viewer, we use the opengl mode, not the ray tracing engine
530  // because the ray tracing is very time consumming, and can be seen as not working
531  // (freeze window) with large boards.
532 #if 0
533  RENDER_ENGINE engine = static_cast<RENDER_ENGINE>( cfg->m_Render.engine );
534  wxLogTrace( m_logTrace, engine == RENDER_ENGINE::RAYTRACING ?
535  "EDA_3D_VIEWER_FRAME::LoadSettings render setting Ray Trace" :
536  "EDA_3D_VIEWER_FRAME::LoadSettings render setting OpenGL" );
537 #else
539 #endif
540 
541  m_boardAdapter.SetMaterialMode( static_cast<MATERIAL_MODE>( cfg->m_Render.material_mode ) );
542 
546 
547 #undef TRANSFER_SETTING
548  }
549 }
550 
551 
553 {
554  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
555 
557 
558  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::SaveSettings" );
559 
560  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
561 
562  auto save_color =
563  [colors] ( SFVEC4F& aSource, LAYER_3D_ID aTarget )
564  {
565  // You could think just copy the new color in config is enough.
566  // unfortunately, SFVEC4F uses floats, and COLOR4D uses doubles,
567  // and the conversion SFVEC4F from/to COLOR4D creates small diffs.
568  //
569  // This has no matter to draw colors, but creates slight differences
570  // in config file, that appears always modified.
571  // So we must compare the SFVEC4F old and new values and update only
572  // actual changes.
573  SFVEC4F newSFVEC4Fcolor( float( colors->GetColor( aTarget ).r ),
574  float( colors->GetColor( aTarget ).g ),
575  float( colors->GetColor( aTarget ).b ),
576  float( colors->GetColor( aTarget ).a ) );
577 
578  if( aSource != newSFVEC4Fcolor )
579  colors->SetColor( aTarget, COLOR4D( aSource.r, aSource.g, aSource.b,
580  aSource.a ) );
581  };
582 
591 
592  Pgm().GetSettingsManager().SaveColorSettings( colors, "3d_viewer" );
593 
595  "EDA_3D_VIEWER_FRAME::SaveSettings render setting Ray Trace" :
596  "EDA_3D_VIEWER_FRAME::SaveSettings render setting OpenGL" );
597 
598  if( cfg )
599  {
600 
601  auto save_color =
602  [] ( const SFVEC3F& aSource, COLOR4D& aTarget )
603  {
604  aTarget = COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 );
605  };
606 
607  save_color( m_boardAdapter.m_RtCameraLightColor, cfg->m_Render.raytrace_lightColorCamera );
608  save_color( m_boardAdapter.m_RtLightColorTop, cfg->m_Render.raytrace_lightColorTop );
609  save_color( m_boardAdapter.m_RtLightColorBottom, cfg->m_Render.raytrace_lightColorBottom );
610 
611  for( size_t i = 0; i < cfg->m_Render.raytrace_lightColor.size(); ++i )
612  {
613  save_color( m_boardAdapter.m_RtLightColor[i], cfg->m_Render.raytrace_lightColor[i] );
614 
615  cfg->m_Render.raytrace_lightElevation[i] =
616  (int)( m_boardAdapter.m_RtLightSphericalCoords[i].x * 180.0f - 90.0f );
617  cfg->m_Render.raytrace_lightAzimuth[i] =
618  (int)( m_boardAdapter.m_RtLightSphericalCoords[i].y * 180.0f );
619  }
620 
621  cfg->m_Render.raytrace_nrsamples_shadows = m_boardAdapter.m_RtShadowSampleCount;
622  cfg->m_Render.raytrace_nrsamples_reflections = m_boardAdapter.m_RtReflectionSampleCount;
623  cfg->m_Render.raytrace_nrsamples_refractions = m_boardAdapter.m_RtRefractionSampleCount;
624 
625  cfg->m_Render.raytrace_spread_shadows = m_boardAdapter.m_RtSpreadShadows;
626  cfg->m_Render.raytrace_spread_reflections = m_boardAdapter.m_RtSpreadReflections;
627  cfg->m_Render.raytrace_spread_refractions = m_boardAdapter.m_RtSpreadRefractions;
628 
629  cfg->m_Render.raytrace_recursivelevel_refractions =
631  cfg->m_Render.raytrace_recursivelevel_reflections =
633 
634 #define TRANSFER_SETTING( field, flag ) cfg->m_Render.field = m_boardAdapter.GetFlag( flag )
635 
636  cfg->m_Render.engine = static_cast<int>( m_boardAdapter.GetRenderEngine() );
637  cfg->m_Render.grid_type = static_cast<int>( m_boardAdapter.GetGridType() );
638  cfg->m_Render.material_mode = static_cast<int>( m_boardAdapter.GetMaterialMode() );
639  cfg->m_Render.opengl_AA_mode = static_cast<int>( m_boardAdapter.GetAntiAliasingMode() );
640 
641  save_color( m_boardAdapter.m_OpenGlSelectionColor, cfg->m_Render.opengl_selection_color );
642 
643  cfg->m_Camera.animation_enabled = m_canvas->GetAnimationEnabled();
644  cfg->m_Camera.moving_speed_multiplier = m_canvas->GetMovingSpeedMultiplier();
645  cfg->m_Camera.projection_mode = m_canvas->GetProjectionMode();
646 
647  if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
648  cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement();
649 
650  TRANSFER_SETTING( opengl_AA_disableOnMove, FL_RENDER_OPENGL_AA_DISABLE_ON_MOVE );
651  TRANSFER_SETTING( opengl_copper_thickness, FL_RENDER_OPENGL_COPPER_THICKNESS );
652  TRANSFER_SETTING( opengl_show_model_bbox, FL_RENDER_OPENGL_SHOW_MODEL_BBOX );
653  TRANSFER_SETTING( opengl_highlight_on_rollover, FL_HIGHLIGHT_ROLLOVER_ITEM );
654  TRANSFER_SETTING( opengl_thickness_disableOnMove, FL_RENDER_OPENGL_THICKNESS_DISABLE_ON_MOVE );
655  TRANSFER_SETTING( opengl_vias_disableOnMove, FL_RENDER_OPENGL_VIAS_DISABLE_ON_MOVE );
656  TRANSFER_SETTING( opengl_holes_disableOnMove, FL_RENDER_OPENGL_HOLES_DISABLE_ON_MOVE );
657 
658  TRANSFER_SETTING( raytrace_anti_aliasing, FL_RENDER_RAYTRACING_ANTI_ALIASING );
659  TRANSFER_SETTING( raytrace_backfloor, FL_RENDER_RAYTRACING_BACKFLOOR );
660  TRANSFER_SETTING( raytrace_post_processing, FL_RENDER_RAYTRACING_POST_PROCESSING );
661  TRANSFER_SETTING( raytrace_procedural_textures, FL_RENDER_RAYTRACING_PROCEDURAL_TEXTURES );
662  TRANSFER_SETTING( raytrace_reflections, FL_RENDER_RAYTRACING_REFLECTIONS );
663  TRANSFER_SETTING( raytrace_refractions, FL_RENDER_RAYTRACING_REFRACTIONS );
664  TRANSFER_SETTING( raytrace_shadows, FL_RENDER_RAYTRACING_SHADOWS );
665 
667  TRANSFER_SETTING( show_adhesive, FL_ADHESIVE );
668  TRANSFER_SETTING( show_axis, FL_AXIS );
669  TRANSFER_SETTING( show_board_body, FL_SHOW_BOARD_BODY );
670  TRANSFER_SETTING( clip_silk_on_via_annulus, FL_CLIP_SILK_ON_VIA_ANNULUS );
671  TRANSFER_SETTING( renderPlatedPadsAsPlated, FL_RENDER_PLATED_PADS_AS_PLATED );
672  TRANSFER_SETTING( show_comments, FL_COMMENTS );
673  TRANSFER_SETTING( show_eco, FL_ECO );
674  TRANSFER_SETTING( show_footprints_insert, FL_FP_ATTRIBUTES_NORMAL_INSERT );
675  TRANSFER_SETTING( show_footprints_normal, FL_FP_ATTRIBUTES_NORMAL );
676  TRANSFER_SETTING( show_footprints_virtual, FL_FP_ATTRIBUTES_VIRTUAL );
677  TRANSFER_SETTING( show_silkscreen, FL_SILKSCREEN );
678  TRANSFER_SETTING( show_soldermask, FL_SOLDERMASK );
679  TRANSFER_SETTING( show_solderpaste, FL_SOLDERPASTE );
680  TRANSFER_SETTING( show_zones, FL_ZONE );
681  TRANSFER_SETTING( subtract_mask_from_silk, FL_SUBTRACT_MASK_FROM_SILK );
682 
683 #undef TRANSFER_SETTING
684  }
685 }
686 
687 
688 void EDA_3D_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
689 {
690  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::CommonSettingsChanged" );
691 
692  // Regen menu bars, etc
693  EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
694 
695  // There is no base class that handles toolbars for this frame
697 
699 
700  NewDisplay( true );
701 }
702 
703 
704 void EDA_3D_VIEWER_FRAME::takeScreenshot( wxCommandEvent& event )
705 {
706  wxString fullFileName;
707  bool fmt_is_jpeg = false;
708 
709  if( event.GetId() == ID_MENU_SCREENCOPY_JPEG )
710  fmt_is_jpeg = true;
711 
712  if( event.GetId() != ID_TOOL_SCREENCOPY_TOCLIBBOARD )
713  {
714  // Remember path between saves during this session only.
715  const wxString wildcard = fmt_is_jpeg ? JpegFileWildcard() : PngFileWildcard();
716  const wxString ext = fmt_is_jpeg ? JpegFileExtension : PngFileExtension;
717 
718  // First time path is set to the project path.
719  if( !m_defaultSaveScreenshotFileName.IsOk() )
721 
722  m_defaultSaveScreenshotFileName.SetExt( ext );
723 
724  wxFileDialog dlg( this, _( "3D Image File Name" ),
726  m_defaultSaveScreenshotFileName.GetFullName(), wildcard,
727  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
728 
729  if( dlg.ShowModal() == wxID_CANCEL )
730  return;
731 
732  m_defaultSaveScreenshotFileName = dlg.GetPath();
733 
734  if( m_defaultSaveScreenshotFileName.GetExt().IsEmpty() )
735  m_defaultSaveScreenshotFileName.SetExt( ext );
736 
737  fullFileName = m_defaultSaveScreenshotFileName.GetFullPath();
738 
739  wxFileName fn = fullFileName;
740 
741  if( !fn.IsDirWritable() )
742  {
743  wxString msg;
744 
745  msg.Printf( _( "Insufficient permissions to save file '%s'." ), fullFileName );
746  wxMessageBox( msg, _( "Error" ), wxOK | wxICON_ERROR, this );
747  return;
748  }
749 
750  // Be sure the screen area destroyed by the file dialog is redrawn
751  // before making a screen copy.
752  // Without this call, under Linux the screen refresh is made to late.
753  wxYield();
754  }
755 
756  // Be sure we have the latest 3D view (remember 3D view is buffered)
757  m_canvas->Request_refresh( true );
758  wxYield();
759 
760  // Build image from the 3D buffer
761  wxWindowUpdateLocker noUpdates( this );
762 
763  wxImage screenshotImage;
764 
765  if( m_canvas )
766  m_canvas->GetScreenshot( screenshotImage );
767 
768  if( event.GetId() == ID_TOOL_SCREENCOPY_TOCLIBBOARD )
769  {
770  wxBitmap bitmap( screenshotImage );
771 
772  wxLogNull doNotLog; // disable logging of failed clipboard actions
773 
774  if( wxTheClipboard->Open() )
775  {
776  wxBitmapDataObject* dobjBmp = new wxBitmapDataObject( bitmap );
777 
778  if( !wxTheClipboard->SetData( dobjBmp ) )
779  wxMessageBox( _( "Failed to copy image to clipboard" ) );
780 
781  wxTheClipboard->Flush(); /* the data in clipboard will stay
782  * available after the application exits */
783  wxTheClipboard->Close();
784  }
785  }
786  else
787  {
788  if( !screenshotImage.SaveFile( fullFileName,
789  fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
790  wxMessageBox( _( "Can't save file" ) );
791 
792  screenshotImage.Destroy();
793  }
794 
795 }
796 
797 
799 {
800  wxLogTrace( m_logTrace, "EDA_3D_VIEWER_FRAME::RenderEngineChanged()" );
801 
802  if( m_canvas )
804 }
805 
806 
808 {
809  wxCHECK_RET( m_canvas, "Cannot load settings to null canvas" );
810 
811  COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
812 
813  const DPI_SCALING dpi{ settings, this };
814  m_canvas->SetScaleFactor( dpi.GetScaleFactor() );
815  // TODO(JE) use all control options
817 }
void ResetToDefaults()
Resets all parameters to default values.
GRID3D_TYPE GetGridType() const noexcept
Get the current grid.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
SFVEC4F GetColor(COLOR4D aColor) const
int GetMovingSpeedMultiplier() const
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
int m_RtShadowSampleCount
SFVEC4F m_SilkScreenColorBot
in realistic mode: SilkScreen color ( bot )
PROJECTION_TYPE GetProjection()
Definition: camera.h:160
const std::string JpegFileExtension
static TOOL_ACTION show10mmGrid
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
BOARD_ADAPTER m_boardAdapter
static TOOL_ACTION showBoundingBoxes
void SetAntiAliasingMode(ANTIALIASING_MODE aAAmode)
Set the current antialiasing mode value.
PCB_BASE_FRAME * Parent() const
Definition: eda_3d_viewer.h:70
void OnSetFocus(wxFocusEvent &event)
PROJECT & Prj()
Definition: kicad.cpp:403
glm::vec4 SFVEC4F
Definition: xv3d_types.h:46
void ReCreateMainToolbar()
Definition: 3d_toolbar.cpp:36
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
Set the status of a flag.
SFVEC4F m_SolderMaskColorTop
in realistic mode: solder mask color ( top )
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
EDA_3D_ACTIONS.
LAYER_3D_ID
3D Viewer virtual layers for color settings
void SetProjectionMode(int aMode)
void Process_Special_Functions(wxCommandEvent &event)
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
static TOOL_ACTION attributesVirtual
EDA_3D_CANVAS * m_canvas
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification that common settings are updated.
void OnDisableRayTracing(wxCommandEvent &aEvent)
virtual void RegisterUIUpdateHandler(int aID, const ACTION_CONDITIONS &aConditions) override
Register a UI update handler for the control with ID aID.
std::vector< SFVEC2F > m_RtLightSphericalCoords
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:48
bool IsReloadRequestPending() const
Query if there is a pending reload request.
Definition: eda_3d_canvas.h:91
SFVEC4F m_BoardBodyColor
in realistic mode: FR4 board color
SFVEC4F m_SolderPasteColor
in realistic mode: solder paste color
double g
Green component.
Definition: color4d.h:364
void AddHotKeys(TOOL_MANAGER *aToolMgr)
SFVEC4F m_SolderMaskColorBot
in realistic mode: solder mask color ( bot )
wxString JpegFileWildcard()
void SetGridType(GRID3D_TYPE aGridType) noexcept
Set the current grid.
wxAuiManager m_auimgr
Manage TOOL_ACTION objects.
wxFileName m_defaultSaveScreenshotFileName
void loadCommonSettings()
Load configuration from common settings.
void Request_refresh(bool aRedrawImmediately=true)
Schedule a refresh update of the canvas.
void SetAnimationEnabled(bool aEnable)
Enable or disable camera animation when switching to a pre-defined view.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
static const int * GetAttributesList(ANTIALIASING_MODE aAntiAliasingMode)
Get a list of attributes to pass to wxGLCanvas.
float m_RtSpreadRefractions
SFVEC3F m_RtCameraLightColor
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:36
double b
Blue component.
Definition: color4d.h:365
void InstallPreferences(PAGED_DIALOG *aParent, PANEL_HOTKEYS_EDITOR *aHotkeysPanel) override
Allow a frame to load its preference panels (if any) into the preferences dialog.
RENDER_ENGINE GetRenderEngine() const noexcept
wxTreebook * GetTreebook()
Definition: paged_dialog.h:37
void OnCloseWindow(wxCloseEvent &event)
Master controller class:
Definition: tool_manager.h:54
double a
Alpha component.
Definition: color4d.h:366
int m_RtRecursiveReflectionCount
float m_RtSpreadReflections
SFVEC4F m_BgColorTop
background top color
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Set a dispatcher that processes events and forwards them to tools.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
static TOOL_ACTION show5mmGrid
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
Definition: eda_3d_viewer.h:62
#define TRANSFER_SETTING(flag, field)
EVT_TOOL_RANGE(ID_START_COMMAND_3D, ID_MENU_COMMAND_END, EDA_3D_VIEWER_FRAME::Process_Special_Functions) EDA_3D_VIEWER_FRAME
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
void RenderEngineChanged()
Notify that the render engine was changed.
EDA_3D_CONTROLLER.
MATERIAL_MODE GetMaterialMode() const noexcept
SFVEC3F m_RtLightColorTop
void SetMaterialMode(MATERIAL_MODE aMaterialMode) noexcept
Definition of file extensions used in Kicad.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
#define _(s)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Returns # of elements in an array.
Definition: arraydim.h:31
SFVEC4F m_BgColorBot
background bottom color
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:116
int m_RtRecursiveRefractionCount
std::vector< SFVEC3F > m_RtLightColor
static TOOL_ACTION showAxis
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:105
Handle actions that are shared between different applications.
int m_RtRefractionSampleCount
Specialization of the wxAuiPaneInfo class for KiCad panels.
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...
void SetMovingSpeedMultiplier(int aMultiplier)
Set the camera animation moving speed multiplier option.
void SetRenderEngine(RENDER_ENGINE aRenderEngine) noexcept
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
wxString PngFileWildcard()
BOARD * GetBoard()
static TOOL_ACTION attributesSMD
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
COLOR4D GetColor(int aLayer) const
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
void takeScreenshot(wxCommandEvent &event)
Create a Screenshot of the current 3D view.
void ReloadRequest()
Request reloading the 3D view.
static TOOL_ACTION show2_5mmGrid
static TOOL_ACTION show1mmGrid
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:158
see class PGM_BASE
Declaration of the eda_3d_viewer class.
int GetProjectionMode() const
Board layer functions and definitions.
static TOOL_ACTION attributesTHT
ANTIALIASING_MODE GetAntiAliasingMode() const
Get the current antialiasing mode value.
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).
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
SFVEC4F m_CopperColor
in realistic mode: copper color
The base frame for deriving all KiCad main window classes.
#define GridSizeCheck(x)
bool GetAnimationEnabled() const
const std::string PngFileExtension
void SetScaleFactor(double aFactor)
Set the canvas scale factor, probably for a hi-DPI display.
std::vector< KIGFX::COLOR4D > raytrace_lightColor
RENDER_ENGINE
Render engine mode.
Definition: 3d_enums.h:110
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:199
static TOOL_ACTION noGrid
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
SFVEC3F m_OpenGlSelectionColor
void ReloadRequest(BOARD *aBoard=nullptr, S3D_CACHE *aCachePointer=nullptr)
Color settings are a bit different than most of the settings objects in that there can be more than o...
SFVEC4F m_SilkScreenColorTop
in realistic mode: SilkScreen color ( top )
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
double r
Red component.
Definition: color4d.h:363
static TOOL_ACTION toggleOrtho
#define FlagCheck(x)
SFVEC3F m_RtLightColorBottom
float m_RtSpreadShadows
#define RANGE_SCALE_3D
This defines the range that all coord will have to be rendered.
Definition: board_adapter.h:61
int m_RtReflectionSampleCount
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void OnRenderEngineSelection(wxCommandEvent &event)
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
void OnActivate(wxActivateEvent &event)
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
void SetColor(int aLayer, COLOR4D aColor)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103