2016-07-19 17:35:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2023-08-11 17:40:13 +00:00
|
|
|
* Copyright (C) 2023 CERN
|
2023-01-28 19:08:38 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-07-19 17:35:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-03-21 20:19:55 +00:00
|
|
|
#include <wx/filename.h>
|
2021-06-06 12:41:16 +00:00
|
|
|
#include <wx/msgdlg.h>
|
2020-03-18 22:48:36 +00:00
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/wupdlock.h>
|
|
|
|
#include <wx/clipbrd.h>
|
2021-06-11 09:17:52 +00:00
|
|
|
#include <wx/filedlg.h>
|
2022-06-06 20:58:00 +00:00
|
|
|
#include <wx/dialog.h>
|
2021-08-05 12:03:59 +00:00
|
|
|
#include "eda_3d_viewer_frame.h"
|
2023-08-11 17:40:13 +00:00
|
|
|
#include "dialogs/appearance_controls_3D.h"
|
2022-06-06 20:58:00 +00:00
|
|
|
#include <dialogs/eda_view_switcher.h>
|
2021-06-19 17:28:45 +00:00
|
|
|
#include <eda_3d_viewer_settings.h>
|
2020-03-18 22:48:36 +00:00
|
|
|
#include <3d_viewer_id.h>
|
2021-06-19 17:28:45 +00:00
|
|
|
#include <3d_viewer/tools/eda_3d_actions.h>
|
|
|
|
#include <3d_viewer/tools/eda_3d_controller.h>
|
|
|
|
#include <3d_viewer/tools/eda_3d_conditions.h>
|
2023-04-07 17:08:43 +00:00
|
|
|
#include <advanced_config.h>
|
2019-04-08 09:49:18 +00:00
|
|
|
#include <bitmaps.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/arraydim.h>
|
2023-09-23 03:17:53 +00:00
|
|
|
#include <dpi_scaling_common.h>
|
2019-04-08 09:49:18 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <project.h>
|
2022-06-06 20:58:00 +00:00
|
|
|
#include <project/project_file.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <settings/common_settings.h>
|
|
|
|
#include <settings/settings_manager.h>
|
2020-07-27 22:42:23 +00:00
|
|
|
#include <tool/action_manager.h>
|
2019-06-10 22:17:45 +00:00
|
|
|
#include <tool/common_control.h>
|
2020-01-22 22:38:30 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-03-18 22:48:36 +00:00
|
|
|
#include <tool/tool_dispatcher.h>
|
|
|
|
#include <tool/action_toolbar.h>
|
2022-12-28 22:03:03 +00:00
|
|
|
#include <widgets/wx_infobar.h>
|
2023-08-11 17:40:13 +00:00
|
|
|
#include <widgets/wx_aui_utils.h>
|
2020-01-22 22:38:30 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2023-09-28 03:15:54 +00:00
|
|
|
#include <project_pcb.h>
|
2018-12-08 13:20:32 +00:00
|
|
|
|
2021-06-24 08:47:28 +00:00
|
|
|
#include <3d_navlib/nl_3d_viewer_plugin.h>
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
/**
|
2018-12-08 13:20:32 +00:00
|
|
|
* Flag to enable 3D viewer main frame window debug tracing.
|
|
|
|
*
|
|
|
|
* Use "KI_TRACE_EDA_3D_VIEWER" to enable.
|
|
|
|
*
|
|
|
|
* @ingroup trace_env_vars
|
2016-07-19 17:35:25 +00:00
|
|
|
*/
|
2021-06-19 17:28:45 +00:00
|
|
|
const wxChar* EDA_3D_VIEWER_FRAME::m_logTrace = wxT( "KI_TRACE_EDA_3D_VIEWER" );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
|
2023-01-28 19:08:38 +00:00
|
|
|
BEGIN_EVENT_TABLE( EDA_3D_VIEWER_FRAME, KIWAY_PLAYER )
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
EVT_ACTIVATE( EDA_3D_VIEWER_FRAME::OnActivate )
|
|
|
|
EVT_SET_FOCUS( EDA_3D_VIEWER_FRAME::OnSetFocus )
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2017-12-28 08:29:56 +00:00
|
|
|
EVT_TOOL_RANGE( ID_START_COMMAND_3D, ID_MENU_COMMAND_END,
|
2021-06-19 17:28:45 +00:00
|
|
|
EDA_3D_VIEWER_FRAME::Process_Special_Functions )
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
EVT_MENU( wxID_CLOSE, EDA_3D_VIEWER_FRAME::Exit3DFrame )
|
2022-06-06 20:58:00 +00:00
|
|
|
EVT_MENU( ID_RENDER_CURRENT_VIEW, EDA_3D_VIEWER_FRAME::onRenderEngineSelection )
|
|
|
|
EVT_MENU( ID_DISABLE_RAY_TRACING, EDA_3D_VIEWER_FRAME::onDisableRayTracing )
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
EVT_CLOSE( EDA_3D_VIEWER_FRAME::OnCloseWindow )
|
2016-07-19 17:35:25 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2021-06-24 08:47:28 +00:00
|
|
|
EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent,
|
|
|
|
const wxString& aTitle, long style ) :
|
2020-03-18 22:48:36 +00:00
|
|
|
KIWAY_PLAYER( aKiway, aParent, FRAME_PCB_DISPLAY3D, aTitle, wxDefaultPosition,
|
2022-09-19 16:09:59 +00:00
|
|
|
wxDefaultSize, style, QUALIFIED_VIEWER3D_FRAMENAME( aParent ), unityScale ),
|
2023-08-11 17:40:13 +00:00
|
|
|
m_mainToolBar( nullptr ),
|
|
|
|
m_canvas( nullptr ),
|
|
|
|
m_currentCamera( m_trackBallCamera ),
|
|
|
|
m_trackBallCamera( 2 * RANGE_SCALE_3D ),
|
2023-08-20 16:58:38 +00:00
|
|
|
m_spaceMouse( nullptr )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME %s" ), aTitle );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-01-19 13:02:10 +00:00
|
|
|
m_disable_ray_tracing = false;
|
2022-12-31 23:39:04 +00:00
|
|
|
m_aboutTitle = _HKI( "KiCad 3D Viewer" );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// Give it an icon
|
|
|
|
wxIcon icon;
|
2021-03-08 02:59:07 +00:00
|
|
|
icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_3d ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
SetIcon( icon );
|
|
|
|
|
|
|
|
// Create the status line
|
2023-09-01 17:51:50 +00:00
|
|
|
static const int status_dims[5] = { -1, 170, 130, 130, 130 };
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2019-01-06 16:43:12 +00:00
|
|
|
wxStatusBar *status_bar = CreateStatusBar( arrayDim( status_dims ) );
|
|
|
|
SetStatusWidths( arrayDim( status_dims ), status_dims );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
EDA_3D_VIEWER_SETTINGS* cfg = mgr.GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
|
|
|
|
ANTIALIASING_MODE aaMode = static_cast<ANTIALIASING_MODE>( cfg->m_Render.opengl_AA_mode );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
m_canvas = new EDA_3D_CANVAS( this, OGL_ATT_LIST::GetAttributesList( aaMode ), m_boardAdapter,
|
2023-09-28 00:53:46 +00:00
|
|
|
m_currentCamera,
|
2023-09-28 03:15:54 +00:00
|
|
|
PROJECT_PCB::Get3DCacheManager( &Prj() ) );
|
2023-08-11 17:40:13 +00:00
|
|
|
|
|
|
|
m_appearancePanel = new APPEARANCE_CONTROLS_3D( this, GetCanvas() );
|
2020-04-24 23:58:50 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
LoadSettings( cfg );
|
2019-04-08 09:49:18 +00:00
|
|
|
loadCommonSettings();
|
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
m_appearancePanel->SetUserViewports( Prj().GetProjectFile().m_Viewports3D );
|
2022-06-06 20:58:00 +00:00
|
|
|
|
2019-06-10 22:17:45 +00:00
|
|
|
// Create the manager
|
|
|
|
m_toolManager = new TOOL_MANAGER;
|
2021-08-30 20:30:18 +00:00
|
|
|
m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, cfg, this );
|
2020-03-18 22:48:36 +00:00
|
|
|
|
|
|
|
m_actions = new EDA_3D_ACTIONS();
|
2021-03-27 20:02:34 +00:00
|
|
|
m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
|
2020-03-18 22:48:36 +00:00
|
|
|
m_canvas->SetEventDispatcher( m_toolDispatcher );
|
2019-06-10 22:17:45 +00:00
|
|
|
|
|
|
|
// Register tools
|
|
|
|
m_toolManager->RegisterTool( new COMMON_CONTROL );
|
2020-03-24 01:01:23 +00:00
|
|
|
m_toolManager->RegisterTool( new EDA_3D_CONTROLLER );
|
2019-06-10 22:17:45 +00:00
|
|
|
m_toolManager->InitTools();
|
|
|
|
|
2020-07-27 22:42:23 +00:00
|
|
|
setupUIConditions();
|
|
|
|
|
2020-06-07 10:42:28 +00:00
|
|
|
if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
|
2021-08-30 20:30:18 +00:00
|
|
|
ctrlTool->SetRotationIncrement( cfg->m_Camera.rotation_increment );
|
2020-06-07 10:42:28 +00:00
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
// Run the viewer control tool, it is supposed to be always active
|
|
|
|
m_toolManager->InvokeTool( "3DViewer.Control" );
|
|
|
|
|
2023-08-23 13:04:31 +00:00
|
|
|
ReCreateMenuBar();
|
2019-01-19 13:02:10 +00:00
|
|
|
ReCreateMainToolbar();
|
|
|
|
|
2020-12-26 22:59:47 +00:00
|
|
|
m_infoBar = new WX_INFOBAR( this, &m_auimgr );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_auimgr.SetManagedWindow( this );
|
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( wxS( "MainToolbar" ) )
|
|
|
|
.Top().Layer( 6 ) );
|
|
|
|
m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( wxS( "InfoBar" ) )
|
|
|
|
.Top().Layer( 1 ) );
|
|
|
|
m_auimgr.AddPane( m_appearancePanel, EDA_PANE().Name( "LayersManager" )
|
|
|
|
.Right().Layer( 3 )
|
|
|
|
.Caption( _( "Appearance" ) ).PaneBorder( false )
|
|
|
|
.MinSize( 180, -1 ).BestSize( 190, -1 ) );
|
|
|
|
m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( wxS( "DrawFrame" ) )
|
|
|
|
.Center() );
|
|
|
|
|
|
|
|
wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
|
|
|
|
|
|
|
|
if( cfg->m_AuiPanels.right_panel_width > 0 )
|
|
|
|
SetAuiPaneSize( m_auimgr, layersManager, cfg->m_AuiPanels.right_panel_width, -1 );
|
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
layersManager.Show( cfg->m_AuiPanels.show_layer_manager );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-26 22:59:47 +00:00
|
|
|
// Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
|
2021-06-09 19:32:58 +00:00
|
|
|
// hiding it.
|
2020-12-26 22:59:47 +00:00
|
|
|
m_auimgr.Update();
|
|
|
|
|
|
|
|
// We don't want the infobar displayed right away
|
2023-01-17 00:07:41 +00:00
|
|
|
m_auimgr.GetPane( wxS( "InfoBar" ) ).Hide();
|
2020-12-26 22:59:47 +00:00
|
|
|
m_auimgr.Update();
|
2020-06-03 23:00:40 +00:00
|
|
|
|
2020-12-11 12:09:37 +00:00
|
|
|
m_canvas->SetInfoBar( m_infoBar );
|
|
|
|
m_canvas->SetStatusBar( status_bar );
|
2020-06-03 23:00:40 +00:00
|
|
|
|
2023-06-13 16:44:22 +00:00
|
|
|
try
|
2021-07-02 09:29:22 +00:00
|
|
|
{
|
2023-06-13 16:44:22 +00:00
|
|
|
m_spaceMouse = new NL_3D_VIEWER_PLUGIN( m_canvas );
|
|
|
|
}
|
|
|
|
catch( const std::system_error& e )
|
|
|
|
{
|
|
|
|
wxLogTrace( wxT( "KI_TRACE_NAVLIB" ), e.what() );
|
2021-07-02 09:29:22 +00:00
|
|
|
}
|
2021-06-24 08:47:28 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Fixes bug in Windows (XP and possibly others) where the canvas requires the focus
|
|
|
|
// in order to receive mouse events. Otherwise, the user has to click somewhere on
|
|
|
|
// the canvas before it will respond to mouse wheel events.
|
2020-12-16 23:54:17 +00:00
|
|
|
m_canvas->SetFocus();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
EDA_3D_VIEWER_FRAME::~EDA_3D_VIEWER_FRAME()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-04-07 17:08:43 +00:00
|
|
|
delete m_spaceMouse;
|
2021-06-24 08:47:28 +00:00
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
Prj().GetProjectFile().m_Viewports3D = m_appearancePanel->GetUserViewports();
|
2022-06-06 20:58:00 +00:00
|
|
|
|
2020-03-18 22:48:36 +00:00
|
|
|
m_canvas->SetEventDispatcher( nullptr );
|
2018-05-10 10:49:20 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
m_auimgr.UnInit();
|
|
|
|
}
|
|
|
|
|
2017-05-13 06:17:06 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::setupUIConditions()
|
2020-07-27 22:42:23 +00:00
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::setupUIConditions();
|
|
|
|
|
|
|
|
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
|
|
|
|
EDA_3D_CONDITIONS cond( &m_boardAdapter );
|
|
|
|
|
|
|
|
// Helper to define check conditions
|
2020-08-05 22:00:26 +00:00
|
|
|
#define GridSizeCheck( x ) ACTION_CONDITIONS().Check( cond.GridSize( x ) )
|
2020-07-27 22:42:23 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
auto raytracing =
|
2021-08-05 12:03:59 +00:00
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
return m_boardAdapter.m_Cfg->m_Render.engine != RENDER_ENGINE::OPENGL;
|
|
|
|
};
|
|
|
|
auto showTH =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_boardAdapter.m_Cfg->m_Render.show_footprints_normal;
|
|
|
|
};
|
|
|
|
auto showSMD =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_boardAdapter.m_Cfg->m_Render.show_footprints_insert;
|
|
|
|
};
|
|
|
|
auto showVirtual =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_boardAdapter.m_Cfg->m_Render.show_footprints_virtual;
|
|
|
|
};
|
2022-09-24 09:25:02 +00:00
|
|
|
auto show_NotInPosfile =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_boardAdapter.m_Cfg->m_Render.show_footprints_not_in_posfile;
|
|
|
|
};
|
2023-04-10 17:10:42 +00:00
|
|
|
auto show_DNP =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_boardAdapter.m_Cfg->m_Render.show_footprints_dnp;
|
|
|
|
};
|
2021-08-30 20:30:18 +00:00
|
|
|
auto showBBoxes =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2023-09-21 12:07:10 +00:00
|
|
|
return m_boardAdapter.m_Cfg->m_Render.show_model_bbox;
|
2021-08-30 20:30:18 +00:00
|
|
|
};
|
|
|
|
auto showAxes =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_boardAdapter.m_Cfg->m_Render.show_axis;
|
|
|
|
};
|
|
|
|
auto ortho =
|
|
|
|
[this]( const SELECTION& )
|
|
|
|
{
|
|
|
|
return m_currentCamera.GetProjection() == PROJECTION_TYPE::ORTHO;
|
2021-08-05 12:03:59 +00:00
|
|
|
};
|
2020-07-27 22:42:23 +00:00
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
auto appearances =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_boardAdapter.m_Cfg->m_AuiPanels.show_layer_manager;
|
|
|
|
};
|
2020-07-27 22:42:23 +00:00
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
RegisterUIUpdateHandler( ID_RENDER_CURRENT_VIEW, ACTION_CONDITIONS().Check( raytracing ) );
|
2022-09-24 09:25:02 +00:00
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showTHT, ACTION_CONDITIONS().Check( showTH ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showSMD, ACTION_CONDITIONS().Check( showSMD ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showVirtual, ACTION_CONDITIONS().Check( showVirtual ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showNotInPosFile, ACTION_CONDITIONS().Check( show_NotInPosfile ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showDNP, ACTION_CONDITIONS().Check( show_DNP ) );
|
2021-07-21 15:55:27 +00:00
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showBBoxes, ACTION_CONDITIONS().Check( showBBoxes ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showAxis, ACTION_CONDITIONS().Check( showAxes ) );
|
2020-07-27 22:42:23 +00:00
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::noGrid, GridSizeCheck( GRID3D_TYPE::NONE ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::show10mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_10MM ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::show5mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_5MM ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::show2_5mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_2P5MM ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::show1mmGrid, GridSizeCheck( GRID3D_TYPE::GRID_1MM ) );
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::toggleOrtho, ACTION_CONDITIONS().Check( ortho ) );
|
|
|
|
|
|
|
|
mgr->SetConditions( EDA_3D_ACTIONS::showLayersManager, ACTION_CONDITIONS().Check( appearances ) );
|
2020-07-27 22:42:23 +00:00
|
|
|
|
|
|
|
#undef GridSizeCheck
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-06 20:58:00 +00:00
|
|
|
bool EDA_3D_VIEWER_FRAME::TryBefore( wxEvent& aEvent )
|
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
static bool s_presetSwitcherShown = false;
|
2022-06-06 20:58:00 +00:00
|
|
|
static bool s_viewportSwitcherShown = false;
|
|
|
|
|
2022-10-27 10:32:52 +00:00
|
|
|
// wxWidgets generates no key events for the tab key when the ctrl key is held down. One
|
|
|
|
// way around this is to look at all events and inspect the keyboard state of the tab key.
|
|
|
|
// However, this runs into issues on some linux VMs where querying the keyboard state is
|
|
|
|
// very slow. Fortunately we only use ctrl-tab on Mac, so we implement this lovely hack:
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
if( wxGetKeyState( WXK_TAB ) )
|
|
|
|
#else
|
|
|
|
if( ( aEvent.GetEventType() == wxEVT_CHAR || aEvent.GetEventType() == wxEVT_CHAR_HOOK )
|
|
|
|
&& static_cast<wxKeyEvent&>( aEvent ).GetKeyCode() == WXK_TAB )
|
|
|
|
#endif
|
2022-06-06 20:58:00 +00:00
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
if( !s_presetSwitcherShown && wxGetKeyState( PRESET_SWITCH_KEY ) )
|
|
|
|
{
|
|
|
|
if( m_appearancePanel && this->IsActive() )
|
|
|
|
{
|
|
|
|
wxArrayString mru = m_appearancePanel->GetLayerPresetsMRU();
|
|
|
|
|
|
|
|
if( mru.size() > 0 )
|
|
|
|
{
|
|
|
|
for( wxString& str : mru )
|
|
|
|
{
|
|
|
|
if( str == FOLLOW_PCB )
|
|
|
|
str = _( "Follow PCB Editor" );
|
|
|
|
else if( str == FOLLOW_PLOT_SETTINGS )
|
|
|
|
str = _( "Follow PCB Plot Settings" );
|
|
|
|
}
|
|
|
|
|
|
|
|
EDA_VIEW_SWITCHER switcher( this, mru, PRESET_SWITCH_KEY );
|
|
|
|
|
|
|
|
s_presetSwitcherShown = true;
|
|
|
|
switcher.ShowModal();
|
|
|
|
s_presetSwitcherShown = false;
|
|
|
|
|
|
|
|
int idx = switcher.GetSelection();
|
|
|
|
|
|
|
|
if( idx >= 0 && idx < (int) mru.size() )
|
|
|
|
{
|
|
|
|
wxString internalName = m_appearancePanel->GetLayerPresetsMRU()[idx];
|
|
|
|
m_appearancePanel->ApplyLayerPreset( internalName );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !s_viewportSwitcherShown && wxGetKeyState( VIEWPORT_SWITCH_KEY ) )
|
2022-06-06 20:58:00 +00:00
|
|
|
{
|
2022-10-27 10:32:52 +00:00
|
|
|
if( this->IsActive() )
|
2022-06-06 20:58:00 +00:00
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
const wxArrayString& viewportMRU = m_appearancePanel->GetViewportsMRU();
|
|
|
|
|
|
|
|
if( viewportMRU.size() > 0 )
|
2022-10-27 10:32:52 +00:00
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
EDA_VIEW_SWITCHER switcher( this, viewportMRU, VIEWPORT_SWITCH_KEY );
|
2022-06-06 20:58:00 +00:00
|
|
|
|
2022-10-27 10:32:52 +00:00
|
|
|
s_viewportSwitcherShown = true;
|
|
|
|
switcher.ShowModal();
|
|
|
|
s_viewportSwitcherShown = false;
|
2022-06-06 20:58:00 +00:00
|
|
|
|
2022-10-27 10:32:52 +00:00
|
|
|
int idx = switcher.GetSelection();
|
2022-06-06 20:58:00 +00:00
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
if( idx >= 0 && idx < (int) viewportMRU.size() )
|
|
|
|
m_appearancePanel->ApplyViewport( viewportMRU[idx] );
|
2022-06-06 20:58:00 +00:00
|
|
|
|
2022-10-27 10:32:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-06-06 20:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return wxFrame::TryBefore( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-31 19:03:41 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
|
|
|
|
{
|
|
|
|
KIWAY_PLAYER::handleIconizeEvent( aEvent );
|
|
|
|
|
2023-06-13 16:44:22 +00:00
|
|
|
if( m_spaceMouse && aEvent.IsIconized() )
|
2022-03-31 19:03:41 +00:00
|
|
|
m_spaceMouse->SetFocus( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::ReloadRequest()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
if( m_appearancePanel )
|
|
|
|
m_appearancePanel->UpdateLayerCtls();
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// This will schedule a request to load later
|
|
|
|
if( m_canvas )
|
2023-09-28 03:15:54 +00:00
|
|
|
m_canvas->ReloadRequest( GetBoard(), PROJECT_PCB::Get3DCacheManager( &Prj() ) );
|
2017-05-13 06:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::NewDisplay( bool aForceImmediateRedraw )
|
2017-05-13 06:17:06 +00:00
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
if( m_canvas )
|
2023-09-28 03:15:54 +00:00
|
|
|
m_canvas->ReloadRequest( GetBoard(), PROJECT_PCB::Get3DCacheManager( &Prj() ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2017-05-13 06:17:06 +00:00
|
|
|
// After the ReloadRequest call, the refresh often takes a bit of time,
|
|
|
|
// and it is made here only on request.
|
2023-08-17 08:06:02 +00:00
|
|
|
if( m_canvas && aForceImmediateRedraw )
|
2017-05-13 06:17:06 +00:00
|
|
|
m_canvas->Refresh();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::Redraw()
|
2020-09-02 16:54:57 +00:00
|
|
|
{
|
|
|
|
// Only update in OpenGL for an interactive interaction
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL )
|
2020-09-04 00:00:56 +00:00
|
|
|
m_canvas->Request_refresh( true );
|
2020-09-02 16:54:57 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::refreshRender()
|
2020-09-29 08:37:00 +00:00
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL )
|
2020-09-29 08:37:00 +00:00
|
|
|
m_canvas->Request_refresh();
|
|
|
|
else
|
|
|
|
NewDisplay( true );
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:10:42 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::Exit3DFrame( wxCommandEvent &event )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::Exit3DFrame" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
Close( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::OnCloseWindow( wxCloseEvent &event )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::OnCloseWindow" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-19 21:28:54 +00:00
|
|
|
// Do not show the layer manager during closing to avoid flicker on some platforms (Windows)
|
|
|
|
// that generate useless redraw of items in the Layer Manager
|
2023-08-20 16:58:38 +00:00
|
|
|
if( m_auimgr.GetPane( wxS( "LayersManager" ) ).IsShown() )
|
2023-08-11 17:40:13 +00:00
|
|
|
m_auimgr.GetPane( wxS( "LayersManager" ) ).Show( false );
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->Close();
|
|
|
|
|
|
|
|
Destroy();
|
|
|
|
event.Skip( true );
|
|
|
|
}
|
|
|
|
|
2020-03-16 16:45:09 +00:00
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::Process_Special_Functions( wxCommandEvent &event )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
int id = event.GetId();
|
|
|
|
bool isChecked = event.IsChecked();
|
|
|
|
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::Process_Special_Functions id %d "
|
|
|
|
"isChecked %d" ),
|
2021-06-19 17:28:45 +00:00
|
|
|
id,
|
|
|
|
isChecked );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
if( m_canvas == nullptr )
|
2016-07-19 17:35:25 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
|
|
|
case ID_RELOAD3D_BOARD:
|
2018-04-06 16:00:58 +00:00
|
|
|
NewDisplay( true );
|
2016-07-19 17:35:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_TOOL_SCREENCOPY_TOCLIBBOARD:
|
|
|
|
case ID_MENU_SCREENCOPY_PNG:
|
|
|
|
case ID_MENU_SCREENCOPY_JPEG:
|
|
|
|
takeScreenshot( event );
|
|
|
|
return;
|
|
|
|
|
|
|
|
case ID_MENU3D_RESET_DEFAULTS:
|
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
|
|
|
|
cfg->ResetToDefaults();
|
|
|
|
LoadSettings( cfg );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-04-06 16:00:58 +00:00
|
|
|
// Tell canvas that we (may have) changed the render engine
|
2016-07-19 17:35:25 +00:00
|
|
|
RenderEngineChanged();
|
|
|
|
|
2018-04-06 16:00:58 +00:00
|
|
|
NewDisplay( true );
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
2022-02-04 20:21:07 +00:00
|
|
|
wxFAIL_MSG( wxT( "Invalid event in EDA_3D_VIEWER_FRAME::Process_Special_Functions()" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-06 20:58:00 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::onRenderEngineSelection( wxCommandEvent &event )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-06-06 20:58:00 +00:00
|
|
|
RENDER_ENGINE& engine = m_boardAdapter.m_Cfg->m_Render.engine;
|
|
|
|
RENDER_ENGINE old_engine = engine;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-10-21 13:29:19 +00:00
|
|
|
if( old_engine == RENDER_ENGINE::OPENGL )
|
2022-06-06 20:58:00 +00:00
|
|
|
engine = RENDER_ENGINE::RAYTRACING;
|
2019-01-19 13:02:10 +00:00
|
|
|
else
|
2022-06-06 20:58:00 +00:00
|
|
|
engine = RENDER_ENGINE::OPENGL;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::OnRenderEngineSelection type %s " ),
|
2022-06-06 20:58:00 +00:00
|
|
|
engine == RENDER_ENGINE::RAYTRACING ? wxT( "raytracing" ) : wxT( "realtime" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-06-06 20:58:00 +00:00
|
|
|
if( old_engine != engine )
|
2016-07-19 17:35:25 +00:00
|
|
|
RenderEngineChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-06 20:58:00 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::onDisableRayTracing( wxCommandEvent& aEvent )
|
2019-01-19 13:02:10 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::%s disabling ray tracing." ),
|
|
|
|
__WXFUNCTION__ );
|
2019-01-19 13:02:10 +00:00
|
|
|
|
|
|
|
m_disable_ray_tracing = true;
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL;
|
2019-01-19 13:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::OnActivate( wxActivateEvent &aEvent )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::OnActivate" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-10-27 23:35:55 +00:00
|
|
|
if( aEvent.GetActive() && m_canvas )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Reload data if 3D frame shows a board,
|
|
|
|
// because it can be changed since last frame activation
|
|
|
|
if( m_canvas->IsReloadRequestPending() )
|
|
|
|
m_canvas->Request_refresh();
|
|
|
|
|
|
|
|
// Activates again the focus of the canvas so it will catch mouse and key events
|
|
|
|
m_canvas->SetFocus();
|
|
|
|
}
|
|
|
|
|
2023-06-13 16:44:22 +00:00
|
|
|
if( m_spaceMouse )
|
2021-06-24 08:47:28 +00:00
|
|
|
m_spaceMouse->SetFocus( aEvent.GetActive() );
|
|
|
|
|
2020-10-27 23:35:55 +00:00
|
|
|
aEvent.Skip(); // required under wxMAC
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::OnSetFocus( wxFocusEvent& aEvent )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
// Activates again the focus of the canvas so it will catch mouse and key events
|
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->SetFocus();
|
|
|
|
|
2020-10-27 23:35:55 +00:00
|
|
|
aEvent.Skip();
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE *aCfg )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::LoadSettings( aCfg );
|
|
|
|
|
2020-03-25 13:13:03 +00:00
|
|
|
EDA_3D_VIEWER_SETTINGS* cfg = dynamic_cast<EDA_3D_VIEWER_SETTINGS*>( aCfg );
|
2020-01-13 01:44:19 +00:00
|
|
|
wxASSERT( cfg );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::LoadSettings" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-25 13:13:03 +00:00
|
|
|
if( cfg )
|
|
|
|
{
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_Cfg = cfg;
|
2023-08-11 17:40:13 +00:00
|
|
|
m_boardAdapter.SetBoard( GetBoard() );
|
2020-09-04 15:12:01 +00:00
|
|
|
|
2022-03-04 15:07:10 +00:00
|
|
|
// When opening the 3D viewer, we use the OpenGL mode, never the ray tracing engine
|
|
|
|
// because the ray tracing is very time consuming, and can be seen as not working
|
2020-05-16 11:17:49 +00:00
|
|
|
// (freeze window) with large boards.
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL;
|
2020-03-25 13:13:03 +00:00
|
|
|
|
2021-06-17 11:21:06 +00:00
|
|
|
m_canvas->SetAnimationEnabled( cfg->m_Camera.animation_enabled );
|
|
|
|
m_canvas->SetMovingSpeedMultiplier( cfg->m_Camera.moving_speed_multiplier );
|
|
|
|
m_canvas->SetProjectionMode( cfg->m_Camera.projection_mode );
|
2023-09-07 00:07:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
m_canvas->SetVcSettings( EDA_DRAW_PANEL_GAL::GetVcSettings() );
|
2023-08-11 17:40:13 +00:00
|
|
|
|
|
|
|
if( cfg->m_CurrentPreset == LEGACY_PRESET_FLAG )
|
|
|
|
{
|
2023-08-23 13:04:31 +00:00
|
|
|
wxString legacyColorsPresetName = _( "legacy colors" );
|
2023-08-11 17:40:13 +00:00
|
|
|
|
2023-08-23 13:04:31 +00:00
|
|
|
if( !cfg->FindPreset( legacyColorsPresetName ) )
|
2023-08-11 17:40:13 +00:00
|
|
|
{
|
2023-08-23 13:04:31 +00:00
|
|
|
cfg->m_LayerPresets.emplace_back( legacyColorsPresetName,
|
|
|
|
GetAdapter().GetVisibleLayers(),
|
|
|
|
GetAdapter().GetLayerColors() );
|
2023-08-11 17:40:13 +00:00
|
|
|
}
|
2023-08-23 13:04:31 +00:00
|
|
|
|
|
|
|
if( Pgm().GetSettingsManager().GetColorSettings()->GetUseBoardStackupColors() )
|
|
|
|
cfg->m_CurrentPreset = FOLLOW_PCB;
|
|
|
|
else
|
|
|
|
cfg->m_CurrentPreset = legacyColorsPresetName;
|
2023-08-11 17:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_boardAdapter.InitSettings( nullptr, nullptr );
|
|
|
|
|
|
|
|
if( m_appearancePanel )
|
|
|
|
m_appearancePanel->CommonSettingsChanged();
|
2020-03-25 13:13:03 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE *aCfg )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
EDA_BASE_FRAME::SaveSettings( cfg );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::SaveSettings" ) );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2021-08-30 20:30:18 +00:00
|
|
|
wxLogTrace( m_logTrace, m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::RAYTRACING ?
|
2022-02-04 20:21:07 +00:00
|
|
|
wxT( "EDA_3D_VIEWER_FRAME::SaveSettings render setting Ray Trace" )
|
|
|
|
:
|
|
|
|
wxT( "EDA_3D_VIEWER_FRAME::SaveSettings render setting OpenGL" ) );
|
2020-03-25 13:13:03 +00:00
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
{
|
2023-08-11 17:40:13 +00:00
|
|
|
cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
|
|
|
|
|
2021-06-17 11:21:06 +00:00
|
|
|
cfg->m_Camera.animation_enabled = m_canvas->GetAnimationEnabled();
|
|
|
|
cfg->m_Camera.moving_speed_multiplier = m_canvas->GetMovingSpeedMultiplier();
|
|
|
|
cfg->m_Camera.projection_mode = m_canvas->GetProjectionMode();
|
2020-04-24 23:58:50 +00:00
|
|
|
|
2020-06-07 10:42:28 +00:00
|
|
|
if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool<EDA_3D_CONTROLLER>() )
|
|
|
|
cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement();
|
2020-03-25 13:13:03 +00:00
|
|
|
}
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
|
2019-04-08 09:49:18 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::CommonSettingsChanged" ) );
|
2019-04-08 09:49:18 +00:00
|
|
|
|
|
|
|
// Regen menu bars, etc
|
2020-07-17 20:04:14 +00:00
|
|
|
EDA_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2019-04-08 12:19:17 +00:00
|
|
|
// There is no base class that handles toolbars for this frame
|
|
|
|
ReCreateMainToolbar();
|
|
|
|
|
2019-04-08 09:49:18 +00:00
|
|
|
loadCommonSettings();
|
2021-08-29 23:33:08 +00:00
|
|
|
LoadSettings( Pgm().GetSettingsManager().GetAppSettings<EDA_3D_VIEWER_SETTINGS>() );
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
m_appearancePanel->CommonSettingsChanged();
|
|
|
|
|
2019-04-08 09:49:18 +00:00
|
|
|
NewDisplay( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-23 13:04:31 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::ShowChangedLanguage()
|
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::ShowChangedLanguage();
|
|
|
|
|
|
|
|
SetTitle( _( "3D Viewer" ) );
|
|
|
|
ReCreateMainToolbar();
|
|
|
|
|
|
|
|
if( m_appearancePanel )
|
|
|
|
{
|
|
|
|
wxAuiPaneInfo& lm_pane_info = m_auimgr.GetPane( m_appearancePanel );
|
|
|
|
lm_pane_info.Caption( _( "Appearance" ) );
|
|
|
|
|
|
|
|
m_appearancePanel->OnLanguageChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetStatusText( wxEmptyString, ACTIVITY );
|
|
|
|
SetStatusText( wxEmptyString, HOVERED_ITEM );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-11 17:40:13 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::ToggleAppearanceManager()
|
|
|
|
{
|
|
|
|
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();
|
|
|
|
EDA_3D_VIEWER_SETTINGS* cfg = mgr.GetAppSettings<EDA_3D_VIEWER_SETTINGS>();
|
|
|
|
wxAuiPaneInfo& layersManager = m_auimgr.GetPane( "LayersManager" );
|
|
|
|
|
|
|
|
// show auxiliary Vertical layers and visibility manager toolbar
|
2023-08-20 16:58:38 +00:00
|
|
|
cfg->m_AuiPanels.show_layer_manager = !cfg->m_AuiPanels.show_layer_manager;
|
2023-08-11 17:40:13 +00:00
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
layersManager.Show( cfg->m_AuiPanels.show_layer_manager );
|
2023-08-11 17:40:13 +00:00
|
|
|
|
2023-08-20 16:58:38 +00:00
|
|
|
if( cfg->m_AuiPanels.show_layer_manager )
|
2023-08-11 17:40:13 +00:00
|
|
|
{
|
|
|
|
SetAuiPaneSize( m_auimgr, layersManager, cfg->m_AuiPanels.right_panel_width, -1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cfg->m_AuiPanels.right_panel_width = m_appearancePanel->GetSize().x;
|
|
|
|
m_auimgr.Update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EDA_3D_VIEWER_FRAME::OnDarkModeToggle()
|
|
|
|
{
|
|
|
|
if( m_appearancePanel )
|
|
|
|
m_appearancePanel->OnDarkModeToggle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::takeScreenshot( wxCommandEvent& event )
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
|
|
|
wxString fullFileName;
|
|
|
|
bool fmt_is_jpeg = false;
|
|
|
|
|
|
|
|
if( event.GetId() == ID_MENU_SCREENCOPY_JPEG )
|
|
|
|
fmt_is_jpeg = true;
|
|
|
|
|
|
|
|
if( event.GetId() != ID_TOOL_SCREENCOPY_TOCLIBBOARD )
|
|
|
|
{
|
|
|
|
// Remember path between saves during this session only.
|
2018-12-08 13:20:32 +00:00
|
|
|
const wxString wildcard = fmt_is_jpeg ? JpegFileWildcard() : PngFileWildcard();
|
|
|
|
const wxString ext = fmt_is_jpeg ? JpegFileExtension : PngFileExtension;
|
2016-07-19 17:35:25 +00:00
|
|
|
|
|
|
|
// First time path is set to the project path.
|
2018-12-08 13:20:32 +00:00
|
|
|
if( !m_defaultSaveScreenshotFileName.IsOk() )
|
|
|
|
m_defaultSaveScreenshotFileName = Parent()->Prj().GetProjectFullName();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-12-08 13:20:32 +00:00
|
|
|
m_defaultSaveScreenshotFileName.SetExt( ext );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-12-08 13:20:32 +00:00
|
|
|
wxFileDialog dlg( this, _( "3D Image File Name" ),
|
|
|
|
m_defaultSaveScreenshotFileName.GetPath(),
|
|
|
|
m_defaultSaveScreenshotFileName.GetFullName(), wildcard,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2018-12-08 13:20:32 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2016-07-19 17:35:25 +00:00
|
|
|
return;
|
|
|
|
|
2018-12-08 13:20:32 +00:00
|
|
|
m_defaultSaveScreenshotFileName = dlg.GetPath();
|
|
|
|
|
|
|
|
if( m_defaultSaveScreenshotFileName.GetExt().IsEmpty() )
|
|
|
|
m_defaultSaveScreenshotFileName.SetExt( ext );
|
|
|
|
|
|
|
|
fullFileName = m_defaultSaveScreenshotFileName.GetFullPath();
|
2016-07-19 17:35:25 +00:00
|
|
|
|
2020-03-21 20:19:55 +00:00
|
|
|
wxFileName fn = fullFileName;
|
|
|
|
|
|
|
|
if( !fn.IsDirWritable() )
|
2020-03-16 16:45:09 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
|
2021-06-27 13:24:02 +00:00
|
|
|
msg.Printf( _( "Insufficient permissions to save file '%s'." ), fullFileName );
|
2020-03-16 16:45:09 +00:00
|
|
|
wxMessageBox( msg, _( "Error" ), wxOK | wxICON_ERROR, this );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
// Be sure the screen area destroyed by the file dialog is redrawn
|
|
|
|
// before making a screen copy.
|
|
|
|
// Without this call, under Linux the screen refresh is made to late.
|
|
|
|
wxYield();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Be sure we have the latest 3D view (remember 3D view is buffered)
|
2019-04-09 05:45:31 +00:00
|
|
|
m_canvas->Request_refresh( true );
|
2016-07-19 17:35:25 +00:00
|
|
|
wxYield();
|
|
|
|
|
|
|
|
// Build image from the 3D buffer
|
|
|
|
wxWindowUpdateLocker noUpdates( this );
|
|
|
|
|
|
|
|
wxImage screenshotImage;
|
|
|
|
|
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->GetScreenshot( screenshotImage );
|
|
|
|
|
|
|
|
if( event.GetId() == ID_TOOL_SCREENCOPY_TOCLIBBOARD )
|
|
|
|
{
|
|
|
|
wxBitmap bitmap( screenshotImage );
|
|
|
|
|
2021-01-29 19:13:12 +00:00
|
|
|
wxLogNull doNotLog; // disable logging of failed clipboard actions
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
wxBitmapDataObject* dobjBmp = new wxBitmapDataObject( bitmap );
|
|
|
|
|
|
|
|
if( !wxTheClipboard->SetData( dobjBmp ) )
|
|
|
|
wxMessageBox( _( "Failed to copy image to clipboard" ) );
|
|
|
|
|
|
|
|
wxTheClipboard->Flush(); /* the data in clipboard will stay
|
|
|
|
* available after the application exits */
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !screenshotImage.SaveFile( fullFileName,
|
2020-12-16 22:10:42 +00:00
|
|
|
fmt_is_jpeg ? wxBITMAP_TYPE_JPEG : wxBITMAP_TYPE_PNG ) )
|
2016-07-19 17:35:25 +00:00
|
|
|
wxMessageBox( _( "Can't save file" ) );
|
|
|
|
|
|
|
|
screenshotImage.Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::RenderEngineChanged()
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::RenderEngineChanged()" ) );
|
2019-01-13 19:04:34 +00:00
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
if( m_canvas )
|
|
|
|
m_canvas->RenderEngineChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-19 17:28:45 +00:00
|
|
|
void EDA_3D_VIEWER_FRAME::loadCommonSettings()
|
2019-04-08 09:49:18 +00:00
|
|
|
{
|
2022-02-04 20:21:07 +00:00
|
|
|
wxCHECK_RET( m_canvas, wxT( "Cannot load settings to null canvas" ) );
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
|
2019-04-08 09:49:18 +00:00
|
|
|
|
2023-09-23 03:17:53 +00:00
|
|
|
const DPI_SCALING_COMMON dpi{ settings, this };
|
2020-01-13 01:44:19 +00:00
|
|
|
m_canvas->SetScaleFactor( dpi.GetScaleFactor() );
|
2022-03-04 15:07:10 +00:00
|
|
|
|
2020-05-17 00:19:48 +00:00
|
|
|
// TODO(JE) use all control options
|
2021-08-30 20:30:18 +00:00
|
|
|
m_boardAdapter.m_MousewheelPanning = settings->m_Input.scroll_modifier_zoom != 0;
|
2019-04-09 05:45:31 +00:00
|
|
|
}
|