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-2020 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/colordlg.h>
26 #include <wx/colour.h>
27 #include <wx/string.h>
28 #include <wx/wupdlock.h>
29 #include <wx/clipbrd.h>
30 #include "eda_3d_viewer.h"
31 #include <3d_viewer_settings.h>
32 #include <3d_viewer_id.h>
33 #include "../common_ogl/cogl_att_list.h"
36 #include <bitmaps.h>
39 #include <class_board.h>
40 #include <dpi_scaling.h>
41 #include <gestfich.h>
43 #include <pgm_base.h>
44 #include <project.h>
47 #include <tool/common_control.h>
48 #include <tool/tool_manager.h>
49 #include <tool/tool_dispatcher.h>
50 #include <tool/action_toolbar.h>
52 
60 const wxChar * EDA_3D_VIEWER::m_logTrace = wxT( "KI_TRACE_EDA_3D_VIEWER" );
61 
62 
63 BEGIN_EVENT_TABLE( EDA_3D_VIEWER, EDA_BASE_FRAME )
64 
65  EVT_ACTIVATE( EDA_3D_VIEWER::OnActivate )
66  EVT_SET_FOCUS( EDA_3D_VIEWER::OnSetFocus )
67 
70 
72 
73  EVT_MENU( wxID_CLOSE, EDA_3D_VIEWER::Exit3DFrame )
76 
81 
82  EVT_CLOSE( EDA_3D_VIEWER::OnCloseWindow )
83 END_EVENT_TABLE()
84 
85 
86 EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, const wxString &aTitle,
87  long style ) :
88  KIWAY_PLAYER( aKiway, aParent, FRAME_PCB_DISPLAY3D, aTitle, wxDefaultPosition,
89  wxDefaultSize, style, QUALIFIED_VIEWER3D_FRAMENAME( aParent ) ),
90  m_mainToolBar( nullptr ),
91  m_canvas( nullptr ),
92  m_toolDispatcher( nullptr )
93 {
94  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::EDA_3D_VIEWER %s", aTitle );
95 
96  m_disable_ray_tracing = false;
97  m_AboutTitle = "3D Viewer";
98 
99  // Give it an icon
100  wxIcon icon;
101  icon.CopyFromBitmap( KiBitmap( icon_3d_xpm ) );
102  SetIcon( icon );
103 
104  auto config = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
105  LoadSettings( config );
106  SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
107 
108  // Create the status line
109  static const int status_dims[5] = { -1, -1, 130, 130, 170 };
110 
111  wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) );
112  SetStatusWidths( arrayDim( status_dims ), status_dims );
113 
114  m_canvas = new EDA_3D_CANVAS( this, COGL_ATT_LIST::GetAttributesList( true ),
115  aParent->GetBoard(), m_settings, Prj().Get3DCacheManager() );
116 
117  if( m_canvas )
118  m_canvas->SetStatusBar( status_bar );
119 
120  // Some settings need the canvas
121  loadCommonSettings();
122 
123  // Create the manager
124  m_toolManager = new TOOL_MANAGER;
125  m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, this );
126 
127  m_actions = new EDA_3D_ACTIONS();
128  m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions );
129  m_canvas->SetEventDispatcher( m_toolDispatcher );
130 
131  // Register tools
132  m_toolManager->RegisterTool( new COMMON_CONTROL );
133  m_toolManager->RegisterTool( new EDA_3D_VIEWER_CONTROL );
134  m_toolManager->InitTools();
135 
136  // Run the viewer control tool, it is supposed to be always active
137  m_toolManager->InvokeTool( "3DViewer.Control" );
138 
139  CreateMenuBar();
140  ReCreateMainToolbar();
141 
142  m_auimgr.SetManagedWindow( this );
143 
144  m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer( 6 ) );
145  m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
146 
147  m_auimgr.Update();
148 
149  // Fixes bug in Windows (XP and possibly others) where the canvas requires the focus
150  // in order to receive mouse events. Otherwise, the user has to click somewhere on
151  // the canvas before it will respond to mouse wheel events.
152  if( m_canvas )
153  m_canvas->SetFocus();
154 }
155 
156 
158 {
159  m_canvas->SetEventDispatcher( nullptr );
160 
161  m_auimgr.UnInit();
162 
163  // m_canvas delete will be called by wxWidget manager
164  //delete m_canvas;
165  //m_canvas = nullptr;
166 }
167 
168 
170 {
171  // This will schedule a request to load later
172  if( m_canvas )
173  m_canvas->ReloadRequest( GetBoard(), Prj().Get3DCacheManager() );
174 }
175 
176 
177 void EDA_3D_VIEWER::NewDisplay( bool aForceImmediateRedraw )
178 {
179  ReloadRequest();
180 
181  // After the ReloadRequest call, the refresh often takes a bit of time,
182  // and it is made here only on request.
183  if( aForceImmediateRedraw )
184  m_canvas->Refresh();
185 }
186 
187 
188 void EDA_3D_VIEWER::Exit3DFrame( wxCommandEvent &event )
189 {
190  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::Exit3DFrame" );
191 
192  Close( true );
193 }
194 
195 
196 void EDA_3D_VIEWER::OnCloseWindow( wxCloseEvent &event )
197 {
198  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnCloseWindow" );
199 
200  if( m_canvas )
201  m_canvas->Close();
202 
203  // m_canvas delete will be called by wxWidget manager
204  //delete m_canvas;
205  //m_canvas = nullptr;
206 
207  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
208  Pgm().GetSettingsManager().SaveColorSettings( colors, "3d_viewer" );
209 
210  Destroy();
211  event.Skip( true );
212 }
213 
214 
215 void EDA_3D_VIEWER::Process_Special_Functions( wxCommandEvent &event )
216 {
217  int id = event.GetId();
218  bool isChecked = event.IsChecked();
219 
220  wxLogTrace( m_logTrace,
221  "EDA_3D_VIEWER::Process_Special_Functions id %d isChecked %d",
222  id, isChecked );
223 
224  if( m_canvas == NULL )
225  return;
226 
227  switch( id )
228  {
229  case ID_RELOAD3D_BOARD:
230  NewDisplay( true );
231  break;
232 
236  takeScreenshot( event );
237  return;
238 
240  if( Set3DColorFromUser( m_settings.m_BgColorBot, _( "Background Color, Bottom" ),
241  nullptr ) )
242  {
245  else
246  NewDisplay( true );
247  }
248  return;
249 
251  if( Set3DColorFromUser( m_settings.m_BgColorTop, _( "Background Color, Top" ), nullptr ) )
252  {
255  else
256  NewDisplay( true );
257  }
258  return;
259 
262  return;
263 
266  return;
267 
270  return;
271 
274  break;
275 
278  break;
279 
282  NewDisplay( true );
283  break;
284 
287  NewDisplay( true );
288  return;
289 
292  NewDisplay( true );
293  return;
294 
297  NewDisplay( true );
298  return;
299 
301  {
302  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
303  cfg->ResetToDefaults();
304  LoadSettings( cfg );
305 
306  // Tell canvas that we (may have) changed the render engine
308 
309  NewDisplay( true );
310  }
311  return;
312 
313  default:
314  wxFAIL_MSG( "Invalid event in EDA_3D_VIEWER::Process_Special_Functions()" );
315  return;
316  }
317 }
318 
319 
320 void EDA_3D_VIEWER::OnRenderEngineSelection( wxCommandEvent &event )
321 {
322  const RENDER_ENGINE old_engine = m_settings.RenderEngineGet();
323 
324  if( old_engine == RENDER_ENGINE::OPENGL_LEGACY )
326  else
328 
329  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnRenderEngineSelection type %s ",
330  ( m_settings.RenderEngineGet() == RENDER_ENGINE::RAYTRACING ) ? "Ray Trace" :
331  "OpenGL Legacy" );
332 
333  if( old_engine != m_settings.RenderEngineGet() )
334  {
336  }
337 }
338 
339 
340 void EDA_3D_VIEWER::OnDisableRayTracing( wxCommandEvent& aEvent )
341 {
342  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::%s disabling ray tracing.", __WXFUNCTION__ );
343 
344  m_disable_ray_tracing = true;
346 }
347 
348 
349 void EDA_3D_VIEWER::OnActivate( wxActivateEvent &event )
350 {
351  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::OnActivate" );
352 
353  if( m_canvas )
354  {
355  // Reload data if 3D frame shows a board,
356  // because it can be changed since last frame activation
359 
360  // Activates again the focus of the canvas so it will catch mouse and key events
361  m_canvas->SetFocus();
362  }
363 
364  event.Skip(); // required under wxMAC
365 }
366 
367 
368 void EDA_3D_VIEWER::OnSetFocus(wxFocusEvent &event)
369 {
370  // Activates again the focus of the canvas so it will catch mouse and key events
371  if( m_canvas )
372  m_canvas->SetFocus();
373 
374  event.Skip();
375 }
376 
377 
379 {
381 
382  auto cfg = dynamic_cast<EDA_3D_VIEWER_SETTINGS*>( aCfg );
383  wxASSERT( cfg );
384 
385  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::LoadSettings" );
386 
387  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
388 
389  auto set_color = [] ( const COLOR4D& aColor, SFVEC3D& aTarget )
390  {
391  aTarget.r = aColor.r;
392  aTarget.g = aColor.g;
393  aTarget.b = aColor.b;
394  };
395 
396  set_color( colors->GetColor( LAYER_3D_BACKGROUND_BOTTOM ), m_settings.m_BgColorBot );
397  set_color( colors->GetColor( LAYER_3D_BACKGROUND_TOP ), m_settings.m_BgColorTop );
398  set_color( colors->GetColor( LAYER_3D_BOARD ), m_settings.m_BoardBodyColor );
399  set_color( colors->GetColor( LAYER_3D_COPPER ), m_settings.m_CopperColor );
402  set_color( colors->GetColor( LAYER_3D_SOLDERMASK ), m_settings.m_SolderMaskColorBot );
403  set_color( colors->GetColor( LAYER_3D_SOLDERMASK ), m_settings.m_SolderMaskColorTop );
404  set_color( colors->GetColor( LAYER_3D_SOLDERPASTE ), m_settings.m_SolderPasteColor );
405 
406  m_settings.SetFlag( FL_USE_REALISTIC_MODE, cfg->m_Render.realistic );
407 
408  m_settings.SetFlag( FL_SUBTRACT_MASK_FROM_SILK, cfg->m_Render.subtract_mask_from_silk );
409 
410  // OpenGL options
411  m_settings.SetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS, cfg->m_Render.opengl_copper_thickness );
412 
413  m_settings.SetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX, cfg->m_Render.opengl_show_model_bbox );
414 
415  // Raytracing options
416  m_settings.SetFlag( FL_RENDER_RAYTRACING_SHADOWS, cfg->m_Render.raytrace_shadows );
417 
418  m_settings.SetFlag( FL_RENDER_RAYTRACING_BACKFLOOR, cfg->m_Render.raytrace_backfloor );
419 
420  m_settings.SetFlag( FL_RENDER_RAYTRACING_REFRACTIONS, cfg->m_Render.raytrace_refractions );
421 
422  m_settings.SetFlag( FL_RENDER_RAYTRACING_REFLECTIONS, cfg->m_Render.raytrace_reflections );
423 
425  cfg->m_Render.raytrace_post_processing );
426 
427  m_settings.SetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING, cfg->m_Render.raytrace_anti_aliasing );
428 
430  cfg->m_Render.raytrace_procedural_textures );
431 
432  m_settings.SetFlag( FL_AXIS, cfg->m_Render.show_axis );
433 
434  m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL, cfg->m_Render.show_footprints_normal );
435 
436  m_settings.SetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT, cfg->m_Render.show_footprints_insert );
437 
438  m_settings.SetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL, cfg->m_Render.show_footprints_virtual );
439 
440  m_settings.SetFlag( FL_ZONE, cfg->m_Render.show_zones );
441 
442  m_settings.SetFlag( FL_ADHESIVE, cfg->m_Render.show_adhesive );
443 
444  m_settings.SetFlag( FL_SILKSCREEN, cfg->m_Render.show_silkscreen );
445 
446  m_settings.SetFlag( FL_SOLDERMASK, cfg->m_Render.show_soldermask );
447 
448  m_settings.SetFlag( FL_SOLDERPASTE, cfg->m_Render.show_solderpaste );
449 
450  m_settings.SetFlag( FL_COMMENTS, cfg->m_Render.show_comments );
451 
452  m_settings.SetFlag( FL_ECO, cfg->m_Render.show_eco );
453 
454  m_settings.SetFlag( FL_SHOW_BOARD_BODY, cfg->m_Render.show_board_body );
455 
456  m_settings.GridSet( static_cast<GRID3D_TYPE>( cfg->m_Render.grid_type ) );
457 
458  RENDER_ENGINE engine = static_cast<RENDER_ENGINE>( cfg->m_Render.engine );
459  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::LoadSettings render setting %s",
460  ( engine == RENDER_ENGINE::RAYTRACING ) ? "Ray Trace" : "OpenGL" );
461  m_settings.RenderEngineSet( engine );
462 
463  m_settings.MaterialModeSet( static_cast<MATERIAL_MODE>( cfg->m_Render.material_mode ) );
464 }
465 
466 
468 {
469  auto cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
470 
472 
473  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::SaveSettings" );
474 
475  COLOR_SETTINGS* colors = Pgm().GetSettingsManager().GetColorSettings();
476 
477  auto save_color = [colors] ( SFVEC3D& aSource, LAYER_3D_ID aTarget )
478  {
479  colors->SetColor( aTarget, COLOR4D( aSource.r, aSource.g, aSource.b, 1.0 ) );
480  };
481 
490 
491  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::SaveSettings render setting %s",
492  ( m_settings.RenderEngineGet() == RENDER_ENGINE::RAYTRACING ) ? "Ray Trace" :
493  "OpenGL" );
494 
495  cfg->m_Render.engine = static_cast<int>( m_settings.RenderEngineGet() );
496  cfg->m_Render.grid_type = static_cast<int>( m_settings.GridGet() );
497  cfg->m_Render.material_mode = static_cast<int>( m_settings.MaterialModeGet() );
498 
499  cfg->m_Render.opengl_copper_thickness = m_settings.GetFlag( FL_RENDER_OPENGL_COPPER_THICKNESS );
500  cfg->m_Render.opengl_show_model_bbox = m_settings.GetFlag( FL_RENDER_OPENGL_SHOW_MODEL_BBOX );
501  cfg->m_Render.raytrace_anti_aliasing = m_settings.GetFlag( FL_RENDER_RAYTRACING_ANTI_ALIASING );
502  cfg->m_Render.raytrace_backfloor = m_settings.GetFlag( FL_RENDER_RAYTRACING_BACKFLOOR );
503  cfg->m_Render.raytrace_post_processing =
505  cfg->m_Render.raytrace_procedural_textures =
507  cfg->m_Render.raytrace_reflections = m_settings.GetFlag( FL_RENDER_RAYTRACING_REFLECTIONS );
508  cfg->m_Render.raytrace_refractions = m_settings.GetFlag( FL_RENDER_RAYTRACING_REFRACTIONS );
509  cfg->m_Render.raytrace_shadows = m_settings.GetFlag( FL_RENDER_RAYTRACING_SHADOWS );
510  cfg->m_Render.realistic = m_settings.GetFlag( FL_USE_REALISTIC_MODE );
511  cfg->m_Render.show_adhesive = m_settings.GetFlag( FL_ADHESIVE );
512  cfg->m_Render.show_axis = m_settings.GetFlag( FL_AXIS );
513  cfg->m_Render.show_board_body = m_settings.GetFlag( FL_SHOW_BOARD_BODY );
514  cfg->m_Render.show_comments = m_settings.GetFlag( FL_COMMENTS );
515  cfg->m_Render.show_eco = m_settings.GetFlag( FL_ECO );
516  cfg->m_Render.show_footprints_insert = m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL_INSERT );
517  cfg->m_Render.show_footprints_normal = m_settings.GetFlag( FL_MODULE_ATTRIBUTES_NORMAL );
518  cfg->m_Render.show_footprints_virtual = m_settings.GetFlag( FL_MODULE_ATTRIBUTES_VIRTUAL );
519  cfg->m_Render.show_silkscreen = m_settings.GetFlag( FL_SILKSCREEN );
520  cfg->m_Render.show_soldermask = m_settings.GetFlag( FL_SOLDERMASK );
521  cfg->m_Render.show_solderpaste = m_settings.GetFlag( FL_SOLDERPASTE );
522  cfg->m_Render.show_zones = m_settings.GetFlag( FL_ZONE );
523  cfg->m_Render.subtract_mask_from_silk = m_settings.GetFlag( FL_SUBTRACT_MASK_FROM_SILK );
524 }
525 
526 
528 {
529  BOARD* brd = GetBoard();
530  const FAB_LAYER_COLOR* stdColors = GetColorStandardList();
531  wxColour color;
532  if( brd )
533  {
535 
536  for( BOARD_STACKUP_ITEM* stckpItem : stckp.GetList() )
537  {
538  wxString colorName = stckpItem->GetColor();
539 
540  if( colorName.StartsWith( "#" ) ) // This is a user defined color.
541  {
542  color.Set( colorName );
543  }
544  else
545  {
546  for( int i = 0; i < GetColorStandardListCount(); i++ )
547  {
548  if( stdColors[i].m_ColorName == colorName )
549  {
550  color = stdColors[i].m_Color;
551  break;
552  }
553  }
554  }
555 
556  if( color.IsOk() )
557  {
558  switch( stckpItem->GetBrdLayerId() )
559  {
560  case F_SilkS:
561  m_settings.m_SilkScreenColorTop.r = color.Red() / 255.0;
562  m_settings.m_SilkScreenColorTop.g = color.Green() / 255.0;
563  m_settings.m_SilkScreenColorTop.b = color.Blue() / 255.0;
564  break;
565  case B_SilkS:
566  m_settings.m_SilkScreenColorBot.r = color.Red() / 255.0;
567  m_settings.m_SilkScreenColorBot.g = color.Green() / 255.0;
568  m_settings.m_SilkScreenColorBot.b = color.Blue() / 255.0;
569  break;
570  case F_Mask:
571  m_settings.m_SolderMaskColorTop.r = color.Red() / 255.0;
572  m_settings.m_SolderMaskColorTop.g = color.Green() / 255.0;
573  m_settings.m_SolderMaskColorTop.b = color.Blue() / 255.0;
574  break;
575  case B_Mask:
576  m_settings.m_SolderMaskColorBot.r = color.Red() / 255.0;
577  m_settings.m_SolderMaskColorBot.g = color.Green() / 255.0;
578  m_settings.m_SolderMaskColorBot.b = color.Blue() / 255.0;
579  break;
580  default:
581  break;
582  }
583  }
584  }
585  }
586 }
587 
588 
589 void EDA_3D_VIEWER::CommonSettingsChanged( bool aEnvVarsChanged )
590 {
591  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::CommonSettingsChanged" );
592 
593  // Regen menu bars, etc
594  EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged );
595 
596  // There is no base class that handles toolbars for this frame
598 
600 
601  NewDisplay( true );
602 }
603 
604 
605 void EDA_3D_VIEWER::takeScreenshot( wxCommandEvent& event )
606 {
607  wxString fullFileName;
608  bool fmt_is_jpeg = false;
609 
610  if( event.GetId() == ID_MENU_SCREENCOPY_JPEG )
611  fmt_is_jpeg = true;
612 
613  if( event.GetId() != ID_TOOL_SCREENCOPY_TOCLIBBOARD )
614  {
615  // Remember path between saves during this session only.
616  const wxString wildcard = fmt_is_jpeg ? JpegFileWildcard() : PngFileWildcard();
617  const wxString ext = fmt_is_jpeg ? JpegFileExtension : PngFileExtension;
618 
619  // First time path is set to the project path.
620  if( !m_defaultSaveScreenshotFileName.IsOk() )
622 
623  m_defaultSaveScreenshotFileName.SetExt( ext );
624 
625  wxFileDialog dlg( this, _( "3D Image File Name" ),
627  m_defaultSaveScreenshotFileName.GetFullName(), wildcard,
628  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
629 
630  if( dlg.ShowModal() == wxID_CANCEL )
631  return;
632 
633  m_defaultSaveScreenshotFileName = dlg.GetPath();
634 
635  if( m_defaultSaveScreenshotFileName.GetExt().IsEmpty() )
636  m_defaultSaveScreenshotFileName.SetExt( ext );
637 
638  fullFileName = m_defaultSaveScreenshotFileName.GetFullPath();
639 
640  if( !wxFileName::IsFileWritable( fullFileName ) )
641  {
642  wxString msg;
643 
644  msg.Printf( _( "Insufficient permissions required to save file\n%s" ), fullFileName );
645  wxMessageBox( msg, _( "Error" ), wxOK | wxICON_ERROR, this );
646  return;
647  }
648 
649  // Be sure the screen area destroyed by the file dialog is redrawn
650  // before making a screen copy.
651  // Without this call, under Linux the screen refresh is made to late.
652  wxYield();
653  }
654 
655  // Be sure we have the latest 3D view (remember 3D view is buffered)
656  m_canvas->Request_refresh( true );
657  wxYield();
658 
659  // Build image from the 3D buffer
660  wxWindowUpdateLocker noUpdates( this );
661 
662  wxImage screenshotImage;
663 
664  if( m_canvas )
665  m_canvas->GetScreenshot( screenshotImage );
666 
667  if( event.GetId() == ID_TOOL_SCREENCOPY_TOCLIBBOARD )
668  {
669  wxBitmap bitmap( screenshotImage );
670 
671  if( wxTheClipboard->Open() )
672  {
673  wxBitmapDataObject* dobjBmp = new wxBitmapDataObject( bitmap );
674 
675  if( !wxTheClipboard->SetData( dobjBmp ) )
676  wxMessageBox( _( "Failed to copy image to clipboard" ) );
677 
678  wxTheClipboard->Flush(); /* the data in clipboard will stay
679  * available after the application exits */
680  wxTheClipboard->Close();
681  }
682  }
683  else
684  {
685  if( !screenshotImage.SaveFile( fullFileName,
686  fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
687  wxMessageBox( _( "Can't save file" ) );
688 
689  screenshotImage.Destroy();
690  }
691 
692 }
693 
694 
696 {
697  wxLogTrace( m_logTrace, "EDA_3D_VIEWER::RenderEngineChanged()" );
698 
699  if( m_canvas )
701 }
702 
703 
704 bool EDA_3D_VIEWER::Set3DColorFromUser( SFVEC3D &aColor, const wxString& aTitle,
705  CUSTOM_COLORS_LIST* aPredefinedColors )
706 {
707  KIGFX::COLOR4D newcolor;
708  KIGFX::COLOR4D oldcolor( aColor.r,aColor.g, aColor.b, 1.0 );
709 
710  DIALOG_COLOR_PICKER picker( this, oldcolor, false, aPredefinedColors );
711 
712  if( picker.ShowModal() != wxID_OK )
713  return false;
714 
715  newcolor = picker.GetColor();
716 
717  if( newcolor == oldcolor )
718  return false;
719 
720  aColor.r = newcolor.r;
721  aColor.g = newcolor.g;
722  aColor.b = newcolor.b;
723 
724  return true;
725 }
726 
727 
729 {
731 
732  colors.push_back( CUSTOM_COLOR_ITEM( 241.0/255.0, 241.0/255.0, 241.0/255.0, "White" ) );
733  colors.push_back( CUSTOM_COLOR_ITEM( 4.0/255.0, 18.0/255.0, 21.0/255.0, "Dark" ) );
734 
735  if( Set3DColorFromUser( m_settings.m_SilkScreenColorTop, _( "Silkscreen Color" ), &colors ) )
736  {
738  NewDisplay( true );
739  return true;
740  }
741 
742  return false;
743 }
744 
745 
747 {
749 
750  colors.push_back( CUSTOM_COLOR_ITEM( 20/255.0, 51/255.0, 36/255.0, "Green" ) );
751  colors.push_back( CUSTOM_COLOR_ITEM( 91/255.0, 168/255.0, 12/255.0, "Light Green" ) );
752  colors.push_back( CUSTOM_COLOR_ITEM( 13/255.0, 104/255.0, 11/255.0, "Saturated Green" ) );
753  colors.push_back( CUSTOM_COLOR_ITEM( 181/255.0, 19/255.0, 21/255.0, "Red" ) );
754  colors.push_back( CUSTOM_COLOR_ITEM( 239/255.0, 53/255.0, 41/255.0, "Red Light Orange" ) );
755  colors.push_back( CUSTOM_COLOR_ITEM( 210/255.0, 40/255.0, 14/255.0, "Red 2" ) );
756  colors.push_back( CUSTOM_COLOR_ITEM( 2/255.0, 59/255.0, 162/255.0, "Blue" ) );
757  colors.push_back( CUSTOM_COLOR_ITEM( 54/255.0, 79/255.0, 116/255.0, "Light blue 1" ) );
758  colors.push_back( CUSTOM_COLOR_ITEM( 61/255.0, 85/255.0, 130/255.0, "Light blue 2" ) );
759  colors.push_back( CUSTOM_COLOR_ITEM( 21/255.0, 70/255.0, 80/255.0, "Green blue (dark)" ) );
760  colors.push_back( CUSTOM_COLOR_ITEM( 11/255.0, 11/255.0, 11/255.0, "Black" ) );
761  colors.push_back( CUSTOM_COLOR_ITEM( 245/255.0, 245/255.0, 245/255.0, "White" ) );
762  colors.push_back( CUSTOM_COLOR_ITEM( 119/255.0, 31/255.0, 91/255.0, "Purple" ) );
763  colors.push_back( CUSTOM_COLOR_ITEM( 32/255.0, 2/255.0, 53/255.0, "Purple Dark" ) );
764 
765  if( Set3DColorFromUser( m_settings.m_SolderMaskColorTop, _( "Solder Mask Color" ), &colors ) )
766  {
768  NewDisplay( true );
769  return true;
770  }
771 
772  return false;
773 }
774 
775 
777 {
779 
780  colors.push_back( CUSTOM_COLOR_ITEM( 184/255.0, 115/255.0, 50/255.0, "Copper" ) );
781  colors.push_back( CUSTOM_COLOR_ITEM( 178/255.0, 156/255.0, 0.0, "Gold" ) );
782  colors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) );
783  colors.push_back( CUSTOM_COLOR_ITEM( 160/255.0, 160/255.0, 160/255.0, "Tin" ) );
784 
785  if( Set3DColorFromUser( m_settings.m_CopperColor, _( "Copper Color" ), &colors ) )
786  {
787  NewDisplay( true );
788  return true;
789  }
790 
791  return false;
792 }
793 
794 
796 {
798 
799  colors.push_back( CUSTOM_COLOR_ITEM( 51/255.0, 43/255.0, 22/255.0, "FR4 natural, dark" ) );
800  colors.push_back( CUSTOM_COLOR_ITEM( 109/255.0, 116/255.0, 75/255.0, "FR4 natural" ) );
801  colors.push_back( CUSTOM_COLOR_ITEM( 78/255.0, 14/255.0, 5/255.0, "brown/red" ) );
802  colors.push_back( CUSTOM_COLOR_ITEM( 146/255.0, 99/255.0, 47/255.0, "brown 1" ) );
803  colors.push_back( CUSTOM_COLOR_ITEM( 160/255.0, 123/255.0, 54/255.0, "brown 2" ) );
804  colors.push_back( CUSTOM_COLOR_ITEM( 146/255.0, 99/255.0, 47/255.0, "brown 3" ) );
805  colors.push_back( CUSTOM_COLOR_ITEM( 63/255.0, 126/255.0, 71/255.0, "green 1" ) );
806  colors.push_back( CUSTOM_COLOR_ITEM( 117/255.0, 122/255.0, 90/255.0, "green 2" ) );
807 
808  if( Set3DColorFromUser( m_settings.m_BoardBodyColor, _( "Board Body Color" ), &colors ) )
809  {
810  NewDisplay( true );
811  return true;
812  }
813 
814  return false;
815 }
816 
817 
819 {
821 
822  colors.push_back( CUSTOM_COLOR_ITEM( 128/255.0, 128/255.0, 128/255.0, "grey" ) );
823  colors.push_back( CUSTOM_COLOR_ITEM( 213/255.0, 213/255.0, 213/255.0, "Silver" ) );
824  colors.push_back( CUSTOM_COLOR_ITEM( 90/255.0, 90/255.0, 90/255.0, "grey 2" ) );
825 
826  if( Set3DColorFromUser( m_settings.m_SolderPasteColor, _( "Solder Paste Color" ), &colors ) )
827  {
828  NewDisplay( true );
829  return true;
830  }
831 
832  return false;
833 }
834 
835 
836 void EDA_3D_VIEWER::OnUpdateUIEngine( wxUpdateUIEvent& aEvent )
837 {
839 }
840 
841 
842 void EDA_3D_VIEWER::OnUpdateUIMaterial( wxUpdateUIEvent& aEvent )
843 {
844  // Set the state of toggle menus according to the current display options
845  switch( aEvent.GetId() )
846  {
848  aEvent.Check( m_settings.MaterialModeGet() == MATERIAL_MODE::NORMAL );
849  break;
850 
853  break;
854 
857  break;
858 
859  default:
860  wxFAIL_MSG( "Invalid event in EDA_3D_VIEWER::OnUpdateUIMaterial()" );
861  }
862 }
863 
864 
866 {
867  wxCHECK_RET( m_canvas, "Cannot load settings to null canvas" );
868 
869  COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
870 
871  const DPI_SCALING dpi{ settings, this };
872  m_canvas->SetScaleFactor( dpi.GetScaleFactor() );
874 }
Use a gray shading based on diffuse material.
void ResetToDefaults()
Resets all parameters to default values.
bool Set3DCopperColorFromUser()
Set the copper color from a set of colors.
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
static const int * GetAttributesList(bool aUseAntiAliasing)
Get a list of attributes to pass to wxGLCanvas.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:103
void CommonSettingsChanged(bool aEnvVarsChanged) override
Notification that common settings are updated.
std::vector< BOARD_STACKUP_ITEM * > & GetList()
const std::string JpegFileExtension
CINFO3D_VISU m_settings
This file is part of the common library TODO brief description.
void Install3DViewOptionDialog(wxCommandEvent &event)
this class manage the layers needed to make a physical board they are solder mask,...
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Saves common frame parameters to a configuration data file.
bool Set3DSolderMaskColorFromUser()
Set the solder mask color from a set of colors.
void GridSet(GRID3D_TYPE aGridType)
GridSet - set the current grid.
Definition: cinfo3d_visu.h:228
SFVEC3D m_CopperColor
in realistic mode: copper color
Definition: cinfo3d_visu.h:516
PROJECT & Prj()
Definition: kicad.cpp:317
SFVEC3D m_SolderMaskColorBot
in realistic mode: solder mask color ( bot )
Definition: cinfo3d_visu.h:511
int color
Definition: DXF_plotter.cpp:61
SFVEC3D m_SolderMaskColorTop
in realistic mode: solder mask color ( top )
Definition: cinfo3d_visu.h:512
EDA_3D_ACTIONS.
Definition: 3d_actions.h:41
LAYER_3D_ID
3D Viewer virtual layers for color settings
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Saves common frame parameters to a configuration data file.
void SetStatusBar(wxStatusBar *aStatusBar)
Definition: eda_3d_canvas.h:73
GRID3D_TYPE GridGet() const
GridGet - get the current grid.
Definition: cinfo3d_visu.h:222
Implement a canvas based on a wxGLCanvas.
Definition: eda_3d_canvas.h:46
bool IsReloadRequestPending() const
IsReloadRequestPending - Query if there is a pending reload request.
Definition: eda_3d_canvas.h:81
int GetColorStandardListCount()
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:512
double g
Green component.
Definition: color4d.h:303
a class to handle a custom color (predefined color) for the color picker dialog
wxString JpegFileWildcard()
wxAuiManager m_auimgr
SFVEC3D m_BgColorBot
background bottom color
Definition: cinfo3d_visu.h:508
SFVEC3D m_SilkScreenColorTop
in realistic mode: SilkScreen color ( top )
Definition: cinfo3d_visu.h:515
std::vector< CUSTOM_COLOR_ITEM > CUSTOM_COLORS_LIST
void Request_refresh(bool aRedrawImmediately=true)
Request_refresh - Schedule a refresh update of the canvas.
void ReloadRequest(BOARD *aBoard=NULL, S3D_CACHE *aCachePointer=NULL)
SFVEC3D m_BgColorTop
background top color
Definition: cinfo3d_visu.h:509
void Exit3DFrame(wxCommandEvent &event)
Called when user press the File->Exit.
void MaterialModeSet(MATERIAL_MODE aMaterialMode)
MaterialModeSet.
Definition: cinfo3d_visu.h:246
3D_VIEWER_CONTROL
bool GetFlag(DISPLAY3D_FLG aFlag) const
GetFlag - get a configuration status of a flag.
void loadCommonSettings()
Load configuration from common settings.
Class to handle configuration and automatic determination of the DPI scale to use for canvases.
Definition: dpi_scaling.h:36
SFVEC3D m_BoardBodyColor
in realistic mode: FR4 board color
Definition: cinfo3d_visu.h:510
double b
Blue component.
Definition: color4d.h:304
EDA_3D_CANVAS * m_canvas
bool Set3DColorFromUser(SFVEC3D &aColor, const wxString &aTitle, CUSTOM_COLORS_LIST *aPredefinedColors)
Get a SFVEC3D from a wx colour dialog.
Use only diffuse material properties.
ID_MENU3D_FL_RENDER_MATERIAL_MODE_CAD_MODE
MATERIAL_MODE MaterialModeGet() const
MaterialModeGet.
Definition: cinfo3d_visu.h:252
void RenderEngineSet(RENDER_ENGINE aRenderEngine)
RenderEngineSet.
Definition: cinfo3d_visu.h:234
TOOL_MANAGER.
Definition: tool_manager.h:50
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
void OnActivate(wxActivateEvent &event)
BOARD_STACKUP & GetStackupDescriptor()
void OnUpdateUIMaterial(wxUpdateUIEvent &aEvent)
void OnDisableRayTracing(wxCommandEvent &aEvent)
SFVEC3D m_SilkScreenColorBot
in realistic mode: SilkScreen color ( bot )
Definition: cinfo3d_visu.h:514
void SetEventDispatcher(TOOL_DISPATCHER *aEventDispatcher)
Function SetEventDispatcher() Sets 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:75
#define NULL
const BITMAP_OPAQUE icon_3d_xpm[1]
Definition: icon_3d.cpp:143
Use all material properties from model file.
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
void RenderEngineChanged()
RenderEngineChanged - Notify that the render engine was changed.
bool Set3DSilkScreenColorFromUser()
Set the silkscreen color from a set of colors.
void OnUpdateUIEngine(wxUpdateUIEvent &aEvent)
Definition of file extensions used in Kicad.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the s...
Definition: kiway.h:273
glm::dvec3 SFVEC3D
Definition: xv3d_types.h:48
void OnCloseWindow(wxCloseEvent &event)
void ReCreateMainToolbar()
Definition: 3d_toolbar.cpp:39
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:96
COMMON_CONTROL.
SFVEC3D m_SolderPasteColor
in realistic mode: solder paste color
Definition: cinfo3d_visu.h:513
bool Set3DSolderPasteColorFromUser()
Set the solder mask color from a set of colors.
this class manage one layer needed to make a physical board it can be a solder mask,...
Specialization of the wxAuiPaneInfo class for KiCad panels.
TOOL_DISPATCHER.
wxString PngFileWildcard()
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
void RenderEngineChanged()
RenderEngineChanged - Update toolbar icon and call canvas RenderEngineChanged.
RENDER_ENGINE RenderEngineGet() const
RenderEngineGet.
Definition: cinfo3d_visu.h:240
BOARD * GetBoard()
virtual void CommonSettingsChanged(bool aEnvVarsChanged)
Notification event that some of the common (suite-wide) settings have changed.
static const wxChar * m_logTrace
Trace mask used to enable or disable the trace output of this class.
void GetScreenshot(wxImage &aDstImage)
Request a screenshot and output it to the aDstImage.
see class PGM_BASE
Declaration of the eda_3d_viewer class.
Board layer functions and definitions.
PCB_EDIT_FRAME::OnUpdateSelectTrackWidth EVT_UPDATE_UI_RANGE(ID_POPUP_PCB_SELECT_VIASIZE1, ID_POPUP_PCB_SELECT_VIASIZE8, PCB_EDIT_FRAME::OnUpdateSelectViaSize) PCB_EDIT_FRAME
wxFileName m_defaultSaveScreenshotFileName
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
#define _(s)
Definition: 3d_actions.cpp:33
The base frame for deriving all KiCad main window classes.
void OnRenderEngineSelection(wxCommandEvent &event)
GERBVIEW_FRAME::OnZipFileHistory GERBVIEW_FRAME::OnToggleShowLayerManager GERBVIEW_FRAME::OnSelectHighlightChoice EVT_UPDATE_UI(ID_TOOLBARH_GERBVIEW_SELECT_ACTIVE_LAYER, GERBVIEW_FRAME::OnUpdateLayerSelectBox) EVT_UPDATE_UI_RANGE(ID_TB_OPTIONS_SHOW_GBR_MODE_0
PCB_BASE_FRAME * Parent() const
Definition: eda_3d_viewer.h:76
KIGFX::COLOR4D GetColor()
const FAB_LAYER_COLOR * GetColorStandardList()
const std::string PngFileExtension
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, EDA_BASE_FRAME *aFrame)
Sets the work environment (model, view, view controls and the parent window).
void SetScaleFactor(double aFactor)
Set the canvas scale factor, probably for a hi-DPI display.
RENDER_ENGINE
Render engine mode.
Definition: 3d_enums.h:88
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void OnSetFocus(wxFocusEvent &event)
Create and handle a window for the 3d viewer connected to a Kiway and a pcbboard.
Definition: eda_3d_viewer.h:65
void SynchroniseColoursWithBoard(void)
double r
Red component.
Definition: color4d.h:302
void SetFlag(DISPLAY3D_FLG aFlag, bool aState)
SetFlag - set the status of a flag.
void NewDisplay(bool aForceImmediateRedraw=false)
Reload and refresh (rebuild) the 3D scene.
#define QUALIFIED_VIEWER3D_FRAMENAME(parent)
Definition: eda_3d_viewer.h:50
static VRML_COLOR colors[VRML_COLOR_LAST]
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
BOARD * GetBoard()
Definition: eda_3d_viewer.h:78
bool m_disable_ray_tracing
bool Set3DBoardBodyColorFromUser()
Set the copper color from a set of colors.
void ReloadRequest()
Request reloading the 3D view.
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void Process_Special_Functions(wxCommandEvent &event)
EVT_TOOL_RANGE(ID_START_COMMAND_3D, ID_MENU_COMMAND_END, EDA_3D_VIEWER::Process_Special_Functions) EVT_UPDATE_UI_RANGE(ID_MENU3D_FL_RENDER_MATERIAL_MODE_NORMAL
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40
void takeScreenshot(wxCommandEvent &event)
Create a Screenshot of the current 3D view.