ADDED: User viewports for 3D viewer.

Fixes https://gitlab.com/kicad/code/kicad/issues/5724
This commit is contained in:
Jeff Young 2022-06-06 21:58:00 +01:00
parent 244042ce51
commit bf71cada4e
11 changed files with 458 additions and 37 deletions

View File

@ -4,7 +4,7 @@
* Copyright (C) 2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -25,6 +25,7 @@
*/
#include <wx/wupdlock.h>
#include <wx/choice.h>
#include <bitmaps.h>
#include <eda_3d_viewer_frame.h>
@ -50,6 +51,21 @@ void EDA_3D_VIEWER_FRAME::ReCreateMainToolbar()
m_mainToolBar->SetAuiManager( &m_auimgr );
}
m_viewportsLabel = new wxStaticText( this, wxID_ANY, _( "Viewports (Alt+Tab):" ) );
m_viewportsLabel->Wrap( -1 );
m_cbViewports = new wxChoice( this, wxID_ANY );
for( std::pair<const wxString, VIEWPORT3D>& pair : m_viewports )
m_cbViewports->Append( pair.first, static_cast<void*>( &pair.second ) );
m_cbViewports->Append( wxT( "-----" ) );
m_cbViewports->Append( _( "Save viewport..." ) );
m_cbViewports->Append( _( "Delete viewport..." ) );
m_cbViewports->SetSelection( m_cbViewports->GetCount() - 3 );
m_lastSelectedViewport = nullptr;
// Set up toolbar
m_mainToolBar->AddTool( ID_RELOAD3D_BOARD, wxEmptyString,
KiScaledBitmap( BITMAPS::import3d, this ), _( "Reload board" ) );
@ -99,5 +115,11 @@ void EDA_3D_VIEWER_FRAME::ReCreateMainToolbar()
m_mainToolBar->Add( EDA_3D_ACTIONS::showSMD, ACTION_TOOLBAR::TOGGLE );
m_mainToolBar->Add( EDA_3D_ACTIONS::showVirtual, ACTION_TOOLBAR::TOGGLE );
m_mainToolBar->AddScaledSeparator( this );
m_mainToolBar->AddControl( m_viewportsLabel );
m_mainToolBar->AddControl( m_cbViewports );
m_mainToolBar->KiRealize();
}

View File

@ -28,7 +28,12 @@
#include <wx/wupdlock.h>
#include <wx/clipbrd.h>
#include <wx/filedlg.h>
#include <wx/choice.h>
#include <wx/dialog.h>
#include "eda_3d_viewer_frame.h"
#include "eda_list_dialog.h"
#include "wx/generic/textdlgg.h"
#include <dialogs/eda_view_switcher.h>
#include <eda_3d_viewer_settings.h>
#include <3d_viewer_id.h>
#include <3d_viewer/tools/eda_3d_actions.h>
@ -40,6 +45,7 @@
#include <gal/dpi_scaling.h>
#include <pgm_base.h>
#include <project.h>
#include <project/project_file.h>
#include <settings/common_settings.h>
#include <settings/settings_manager.h>
#include <tool/action_manager.h>
@ -73,8 +79,8 @@ BEGIN_EVENT_TABLE( EDA_3D_VIEWER_FRAME, EDA_BASE_FRAME )
EDA_3D_VIEWER_FRAME::Process_Special_Functions )
EVT_MENU( wxID_CLOSE, EDA_3D_VIEWER_FRAME::Exit3DFrame )
EVT_MENU( ID_RENDER_CURRENT_VIEW, EDA_3D_VIEWER_FRAME::OnRenderEngineSelection )
EVT_MENU( ID_DISABLE_RAY_TRACING, EDA_3D_VIEWER_FRAME::OnDisableRayTracing )
EVT_MENU( ID_RENDER_CURRENT_VIEW, EDA_3D_VIEWER_FRAME::onRenderEngineSelection )
EVT_MENU( ID_DISABLE_RAY_TRACING, EDA_3D_VIEWER_FRAME::onDisableRayTracing )
EVT_CLOSE( EDA_3D_VIEWER_FRAME::OnCloseWindow )
END_EVENT_TABLE()
@ -85,6 +91,8 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent
KIWAY_PLAYER( aKiway, aParent, FRAME_PCB_DISPLAY3D, aTitle, wxDefaultPosition,
wxDefaultSize, style, QUALIFIED_VIEWER3D_FRAMENAME( aParent ) ),
m_mainToolBar( nullptr ), m_canvas( nullptr ), m_currentCamera( m_trackBallCamera ),
m_viewportsLabel( nullptr ),
m_cbViewports( nullptr ),
m_trackBallCamera( 2 * RANGE_SCALE_3D ), m_spaceMouse( nullptr )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME %s" ), aTitle );
@ -113,6 +121,8 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent
LoadSettings( cfg );
loadCommonSettings();
SetUserViewports( Prj().GetProjectFile().m_Viewports3D );
// Create the manager
m_toolManager = new TOOL_MANAGER;
m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, cfg, this );
@ -171,6 +181,13 @@ EDA_3D_VIEWER_FRAME::EDA_3D_VIEWER_FRAME( KIWAY* aKiway, PCB_BASE_FRAME* aParent
// in order to receive mouse events. Otherwise, the user has to click somewhere on
// the canvas before it will respond to mouse wheel events.
m_canvas->SetFocus();
m_cbViewports->Connect( wxEVT_COMMAND_CHOICE_SELECTED,
wxCommandEventHandler( EDA_3D_VIEWER_FRAME::onViewportChanged ),
nullptr, this );
m_cbViewports->Connect( wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( EDA_3D_VIEWER_FRAME::onUpdateViewportsCb ),
nullptr, this );
}
@ -183,6 +200,15 @@ EDA_3D_VIEWER_FRAME::~EDA_3D_VIEWER_FRAME()
}
#endif
Prj().GetProjectFile().m_Viewports3D = GetUserViewports();
m_cbViewports->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED,
wxCommandEventHandler( EDA_3D_VIEWER_FRAME::onViewportChanged ),
nullptr, this );
m_cbViewports->Disconnect( wxEVT_UPDATE_UI,
wxUpdateUIEventHandler( EDA_3D_VIEWER_FRAME::onUpdateViewportsCb ),
nullptr, this );
m_canvas->SetEventDispatcher( nullptr );
m_auimgr.UnInit();
@ -255,6 +281,45 @@ void EDA_3D_VIEWER_FRAME::setupUIConditions()
}
bool EDA_3D_VIEWER_FRAME::TryBefore( wxEvent& aEvent )
{
static bool s_viewportSwitcherShown = false;
#ifdef __WXMAC__
wxKeyCode viewSwitchKey = WXK_ALT;
#else
wxKeyCode viewSwitchKey = WXK_WINDOWS_LEFT;
#endif
if( aEvent.GetEventType() != wxEVT_CHAR && aEvent.GetEventType() != wxEVT_CHAR_HOOK )
return wxFrame::TryBefore( aEvent );
if( !s_viewportSwitcherShown && wxGetKeyState( viewSwitchKey ) && wxGetKeyState( WXK_TAB ) )
{
if( this->IsActive() )
{
if( m_viewportMRU.size() > 0 )
{
EDA_VIEW_SWITCHER switcher( this, m_viewportMRU, viewSwitchKey );
s_viewportSwitcherShown = true;
switcher.ShowModal();
s_viewportSwitcherShown = false;
int idx = switcher.GetSelection();
if( idx >= 0 && idx < (int) m_viewportMRU.size() )
applyViewport( m_viewportMRU[idx] );
return true;
}
}
}
return wxFrame::TryBefore( aEvent );
}
void EDA_3D_VIEWER_FRAME::handleIconizeEvent( wxIconizeEvent& aEvent )
{
KIWAY_PLAYER::handleIconizeEvent( aEvent );
@ -369,27 +434,192 @@ void EDA_3D_VIEWER_FRAME::Process_Special_Functions( wxCommandEvent &event )
}
void EDA_3D_VIEWER_FRAME::OnRenderEngineSelection( wxCommandEvent &event )
std::vector<VIEWPORT3D> EDA_3D_VIEWER_FRAME::GetUserViewports() const
{
RENDER_ENGINE old_engine = m_boardAdapter.m_Cfg->m_Render.engine;
std::vector<VIEWPORT3D> ret;
for( const std::pair<const wxString, VIEWPORT3D>& pair : m_viewports )
ret.emplace_back( pair.second );
return ret;
}
void EDA_3D_VIEWER_FRAME::SetUserViewports( std::vector<VIEWPORT3D>& aViewportList )
{
m_viewports.clear();
for( const VIEWPORT3D& viewport : aViewportList )
{
if( m_viewports.count( viewport.name ) )
continue;
m_viewports[viewport.name] = viewport;
m_viewportMRU.Add( viewport.name );
}
}
void EDA_3D_VIEWER_FRAME::applyViewport( const wxString& aViewportName )
{
int idx = m_cbViewports->FindString( aViewportName );
if( idx >= 0 && m_cbViewports->GetSelection() != idx )
{
m_cbViewports->SetSelection( idx );
m_lastSelectedViewport = static_cast<VIEWPORT3D*>( m_cbViewports->GetClientData( idx ) );
m_currentCamera.SetViewMatrix( m_lastSelectedViewport->matrix );
if( m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::OPENGL )
m_canvas->Request_refresh();
else
m_canvas->RenderRaytracingRequest();
}
else
{
m_cbViewports->SetSelection( -1 ); // separator
m_lastSelectedViewport = nullptr;
}
}
void EDA_3D_VIEWER_FRAME::onViewportChanged( wxCommandEvent& aEvent )
{
int count = m_cbViewports->GetCount();
int index = m_cbViewports->GetSelection();
if( index >= 0 && index < count - 3 )
{
VIEWPORT3D* viewport = static_cast<VIEWPORT3D*>( m_cbViewports->GetClientData( index ) );
wxCHECK( viewport, /* void */ );
applyViewport( viewport->name );
if( !viewport->name.IsEmpty() )
{
m_viewportMRU.Remove( viewport->name );
m_viewportMRU.Insert( viewport->name, 0 );
}
}
else if( index == count - 2 )
{
// Save current state to new preset
wxString name;
wxTextEntryDialog dlg( this, _( "Viewport name:" ), _( "Save Viewport" ), name );
if( dlg.ShowModal() != wxID_OK )
{
if( m_lastSelectedViewport )
m_cbViewports->SetStringSelection( m_lastSelectedViewport->name );
else
m_cbViewports->SetSelection( -1 );
return;
}
name = dlg.GetValue();
bool exists = m_viewports.count( name );
if( !exists )
{
m_viewports[name] = VIEWPORT3D( name, m_currentCamera.GetViewMatrix() );
index = m_cbViewports->Insert( name, index-1, static_cast<void*>( &m_viewports[name] ) );
}
else
{
index = m_cbViewports->FindString( name );
m_viewportMRU.Remove( name );
}
m_cbViewports->SetSelection( index );
m_viewportMRU.Insert( name, 0 );
return;
}
else if( index == count - 1 )
{
// Delete an existing viewport
wxArrayString headers;
std::vector<wxArrayString> items;
headers.Add( _( "Viewports" ) );
for( std::pair<const wxString, VIEWPORT3D>& pair : m_viewports )
{
wxArrayString item;
item.Add( pair.first );
items.emplace_back( item );
}
EDA_LIST_DIALOG dlg( this, _( "Delete Viewport" ), headers, items );
dlg.SetListLabel( _( "Select viewport:" ) );
if( dlg.ShowModal() == wxID_OK )
{
wxString viewportName = dlg.GetTextSelection();
int idx = m_cbViewports->FindString( viewportName );
if( idx != wxNOT_FOUND )
{
m_viewports.erase( viewportName );
m_cbViewports->Delete( idx );
m_viewportMRU.Remove( viewportName );
}
}
if( m_lastSelectedViewport )
m_cbViewports->SetStringSelection( m_lastSelectedViewport->name );
else
m_cbViewports->SetSelection( -1 );
return;
}
passOnFocus();
}
void EDA_3D_VIEWER_FRAME::onUpdateViewportsCb( wxUpdateUIEvent& aEvent )
{
int count = m_cbViewports->GetCount();
int index = m_cbViewports->GetSelection();
if( index >= 0 && index < count - 3 )
{
VIEWPORT3D* viewport = static_cast<VIEWPORT3D*>( m_cbViewports->GetClientData( index ) );
wxCHECK( viewport, /* void */ );
if( m_currentCamera.GetViewMatrix() != viewport->matrix )
m_cbViewports->SetSelection( -1 );
}
}
void EDA_3D_VIEWER_FRAME::onRenderEngineSelection( wxCommandEvent &event )
{
RENDER_ENGINE& engine = m_boardAdapter.m_Cfg->m_Render.engine;
RENDER_ENGINE old_engine = engine;
if( old_engine == RENDER_ENGINE::OPENGL )
m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::RAYTRACING;
engine = RENDER_ENGINE::RAYTRACING;
else
m_boardAdapter.m_Cfg->m_Render.engine = RENDER_ENGINE::OPENGL;
engine = RENDER_ENGINE::OPENGL;
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::OnRenderEngineSelection type %s " ),
m_boardAdapter.m_Cfg->m_Render.engine == RENDER_ENGINE::RAYTRACING ?
wxT( "raytracing" )
:
wxT( "realtime" ) );
engine == RENDER_ENGINE::RAYTRACING ? wxT( "raytracing" ) : wxT( "realtime" ) );
if( old_engine != m_boardAdapter.m_Cfg->m_Render.engine )
if( old_engine != engine )
RenderEngineChanged();
}
void EDA_3D_VIEWER_FRAME::OnDisableRayTracing( wxCommandEvent& aEvent )
void EDA_3D_VIEWER_FRAME::onDisableRayTracing( wxCommandEvent& aEvent )
{
wxLogTrace( m_logTrace, wxT( "EDA_3D_VIEWER_FRAME::%s disabling ray tracing." ),
__WXFUNCTION__ );
@ -435,6 +665,13 @@ void EDA_3D_VIEWER_FRAME::OnSetFocus( wxFocusEvent& aEvent )
}
void EDA_3D_VIEWER_FRAME::passOnFocus()
{
if( m_canvas )
m_canvas->SetFocus();
}
void EDA_3D_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE *aCfg )
{
EDA_BASE_FRAME::LoadSettings( aCfg );

View File

@ -4,7 +4,7 @@
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -106,6 +106,9 @@ public:
EDA_3D_CANVAS* GetCanvas() { return m_canvas; }
std::vector<VIEWPORT3D> GetUserViewports() const;
void SetUserViewports( std::vector<VIEWPORT3D>& aViewportList );
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
@ -122,22 +125,26 @@ protected:
void handleIconizeEvent( wxIconizeEvent& aEvent ) override;
void applyViewport( const wxString& aViewportName );
private:
/// Called when user press the File->Exit
void Exit3DFrame( wxCommandEvent& event );
void OnCloseWindow( wxCloseEvent& event );
bool TryBefore( wxEvent& aEvent ) override;
void Process_Special_Functions( wxCommandEvent& event );
void OnRenderEngineSelection( wxCommandEvent& event );
void OnDisableRayTracing( wxCommandEvent& aEvent );
void onRenderEngineSelection( wxCommandEvent& event );
void onDisableRayTracing( wxCommandEvent& aEvent );
void onViewportChanged( wxCommandEvent& aEvent );
void onUpdateViewportsCb( wxUpdateUIEvent& aEvent );
void OnActivate( wxActivateEvent& event );
void OnSetFocus( wxFocusEvent& event );
void Install3DViewOptionDialog( wxCommandEvent& event );
void passOnFocus();
void CreateMenuBar();
void ReCreateMainToolbar();
@ -162,17 +169,24 @@ private:
*/
void loadCommonSettings();
wxFileName m_defaultSaveScreenshotFileName;
private:
wxFileName m_defaultSaveScreenshotFileName;
ACTION_TOOLBAR* m_mainToolBar;
EDA_3D_CANVAS* m_canvas;
BOARD_ADAPTER m_boardAdapter;
CAMERA& m_currentCamera;
TRACK_BALL m_trackBallCamera;
ACTION_TOOLBAR* m_mainToolBar;
wxStaticText* m_viewportsLabel;
wxChoice* m_cbViewports;
EDA_3D_CANVAS* m_canvas;
BOARD_ADAPTER m_boardAdapter;
CAMERA& m_currentCamera;
TRACK_BALL m_trackBallCamera;
bool m_disable_ray_tracing;
bool m_disable_ray_tracing;
NL_3D_VIEWER_PLUGIN* m_spaceMouse;
NL_3D_VIEWER_PLUGIN* m_spaceMouse;
std::map<wxString, VIEWPORT3D> m_viewports;
VIEWPORT3D* m_lastSelectedViewport;
wxArrayString m_viewportMRU;
/**
* Trace mask used to enable or disable the trace output of this class.

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
@ -26,7 +26,7 @@
#include <plugins/3dapi/xv3d_types.h>
#include <settings/app_settings.h>
#include <settings/parameters.h>
#include "render_settings.h"
class EDA_3D_VIEWER_SETTINGS : public APP_SETTINGS_BASE
{

View File

@ -11,6 +11,7 @@ include_directories(
3d_viewer
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include/gal/opengl
${CMAKE_SOURCE_DIR}/common/dialogs
${INC_AFTER}
)

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
@ -187,6 +187,118 @@ void PARAM_VIEWPORT::jsonToViewports( const nlohmann::json& aJson )
if( viewport.contains( "h" ) )
v.rect.SetHeight( viewport.at( "h" ).get<double>() );
m_viewports->emplace_back( v );
}
}
}
PARAM_VIEWPORT3D::PARAM_VIEWPORT3D( const std::string& aPath,
std::vector<VIEWPORT3D>* aViewportList ) :
PARAM_LAMBDA<nlohmann::json>( aPath,
std::bind( &PARAM_VIEWPORT3D::viewportsToJson, this ),
std::bind( &PARAM_VIEWPORT3D::jsonToViewports, this, _1 ),
{} ),
m_viewports( aViewportList )
{
wxASSERT( aViewportList );
}
nlohmann::json PARAM_VIEWPORT3D::viewportsToJson()
{
nlohmann::json ret = nlohmann::json::array();
for( const VIEWPORT3D& viewport : *m_viewports )
{
nlohmann::json js = {
{ "name", viewport.name },
{ "xx", viewport.matrix[0].x },
{ "xy", viewport.matrix[0].y },
{ "xz", viewport.matrix[0].z },
{ "xw", viewport.matrix[0].w },
{ "yx", viewport.matrix[1].x },
{ "yy", viewport.matrix[1].y },
{ "yz", viewport.matrix[1].z },
{ "yw", viewport.matrix[1].w },
{ "zx", viewport.matrix[2].x },
{ "zy", viewport.matrix[2].y },
{ "zz", viewport.matrix[2].z },
{ "zw", viewport.matrix[2].w },
{ "wx", viewport.matrix[3].x },
{ "wy", viewport.matrix[3].y },
{ "wz", viewport.matrix[3].z },
{ "ww", viewport.matrix[3].w }
};
ret.push_back( js );
}
return ret;
}
void PARAM_VIEWPORT3D::jsonToViewports( const nlohmann::json& aJson )
{
if( aJson.empty() || !aJson.is_array() )
return;
m_viewports->clear();
for( const nlohmann::json& viewport : aJson )
{
if( viewport.contains( "name" ) )
{
VIEWPORT3D v( viewport.at( "name" ).get<wxString>() );
if( viewport.contains( "xx" ) )
v.matrix[0].x = viewport.at( "xx" ).get<double>();
if( viewport.contains( "xy" ) )
v.matrix[0].y = viewport.at( "xy" ).get<double>();
if( viewport.contains( "xz" ) )
v.matrix[0].z = viewport.at( "xz" ).get<double>();
if( viewport.contains( "xw" ) )
v.matrix[0].w = viewport.at( "xw" ).get<double>();
if( viewport.contains( "yx" ) )
v.matrix[1].x = viewport.at( "yx" ).get<double>();
if( viewport.contains( "yy" ) )
v.matrix[1].y = viewport.at( "yy" ).get<double>();
if( viewport.contains( "yz" ) )
v.matrix[1].z = viewport.at( "yz" ).get<double>();
if( viewport.contains( "yw" ) )
v.matrix[1].w = viewport.at( "yw" ).get<double>();
if( viewport.contains( "zx" ) )
v.matrix[2].x = viewport.at( "zx" ).get<double>();
if( viewport.contains( "zy" ) )
v.matrix[2].y = viewport.at( "zy" ).get<double>();
if( viewport.contains( "zz" ) )
v.matrix[2].z = viewport.at( "zz" ).get<double>();
if( viewport.contains( "zw" ) )
v.matrix[2].w = viewport.at( "zw" ).get<double>();
if( viewport.contains( "wx" ) )
v.matrix[3].x = viewport.at( "wx" ).get<double>();
if( viewport.contains( "wy" ) )
v.matrix[3].y = viewport.at( "wy" ).get<double>();
if( viewport.contains( "wz" ) )
v.matrix[3].z = viewport.at( "wz" ).get<double>();
if( viewport.contains( "ww" ) )
v.matrix[3].w = viewport.at( "ww" ).get<double>();
m_viewports->emplace_back( v );
}
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com>
*
* This program is free software: you can redistribute it and/or modify it
@ -111,6 +111,8 @@ PROJECT_FILE::PROJECT_FILE( const wxString& aFullPath ) :
m_params.emplace_back( new PARAM_LAYER_PRESET( "board.layer_presets", &m_LayerPresets ) );
m_params.emplace_back( new PARAM_VIEWPORT( "board.viewports", &m_Viewports ) );
m_params.emplace_back( new PARAM_VIEWPORT3D( "board.3dviewports", &m_Viewports3D ) );
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
*
* 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
@ -27,6 +27,7 @@
// Can be removed by refactoring PARAM_LAYER_PRESET
#include <nlohmann/json.hpp>
#include <math/box2.h>
#include <glm/glm.hpp>
/**
* This file contains data structures that are saved in the project file or project local settings
@ -212,4 +213,35 @@ private:
std::vector<VIEWPORT>* m_viewports;
};
struct VIEWPORT3D
{
VIEWPORT3D( const wxString& aName = wxEmptyString ) :
name( aName )
{ }
VIEWPORT3D( const wxString& aName, glm::mat4 aViewMatrix ) :
name( aName ),
matrix( aViewMatrix )
{ }
wxString name;
glm::mat4 matrix;
};
class PARAM_VIEWPORT3D : public PARAM_LAMBDA<nlohmann::json>
{
public:
PARAM_VIEWPORT3D( const std::string& aPath, std::vector<VIEWPORT3D>* aViewportList );
private:
nlohmann::json viewportsToJson();
void jsonToViewports( const nlohmann::json & aJson );
std::vector<VIEWPORT3D>* m_viewports;
};
#endif // KICAD_BOARD_PROJECT_SETTINGS_H

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 CERN
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com>
*
* This program is free software: you can redistribute it and/or modify it
@ -170,6 +170,7 @@ public:
std::vector<LAYER_PRESET> m_LayerPresets; /// List of stored layer presets
std::vector<VIEWPORT> m_Viewports; /// List of stored viewports (pos + zoom)
std::vector<VIEWPORT3D> m_Viewports3D; /// List of stored 3D viewports (view matrixes)
private:
/// An list of schematic sheets in this project

View File

@ -113,7 +113,7 @@ bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
{
const wxArrayString& mru = m_appearancePanel->GetLayerPresetsMRU();
if( mru.size() > 1 )
if( mru.size() > 0 )
{
EDA_VIEW_SWITCHER switcher( this, mru, presetSwitchKey );
@ -136,7 +136,7 @@ bool PCB_BASE_EDIT_FRAME::TryBefore( wxEvent& aEvent )
{
const wxArrayString& mru = m_appearancePanel->GetViewportsMRU();
if( mru.size() > 1 )
if( mru.size() > 0 )
{
EDA_VIEW_SWITCHER switcher( this, mru, viewSwitchKey );

View File

@ -2720,7 +2720,7 @@ void APPEARANCE_CONTROLS::onViewportChanged( wxCommandEvent& aEvent )
}
else if( index == count - 1 )
{
// Delete an existing preset
// Delete an existing viewport
wxArrayString headers;
std::vector<wxArrayString> items;
@ -2743,7 +2743,7 @@ void APPEARANCE_CONTROLS::onViewportChanged( wxCommandEvent& aEvent )
if( idx != wxNOT_FOUND )
{
m_layerPresets.erase( viewportName );
m_viewports.erase( viewportName );
m_cbViewports->Delete( idx );
m_viewportMRU.Remove( viewportName );
}