From 16047b74191282774c862ca601def55eb828e003 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 17 Jun 2021 12:21:06 +0100 Subject: [PATCH] 3D preferences bug fixes. 1) Make sure prefs get saved when closing parent frame. 2) Add camera projection mode to settings. Fixes https://gitlab.com/kicad/code/kicad/issues/8110 Fixes https://gitlab.com/kicad/code/kicad/issues/8626 --- 3d-viewer/3d_canvas/eda_3d_canvas.h | 28 +++++-------------- 3d-viewer/3d_rendering/camera.h | 3 +- 3d-viewer/3d_viewer/3d_viewer_settings.cpp | 2 ++ 3d-viewer/3d_viewer/3d_viewer_settings.h | 1 + .../dialogs/panel_3D_display_options.cpp | 12 ++++---- 3d-viewer/3d_viewer/eda_3d_viewer.cpp | 10 ++++--- include/pcb_base_frame.h | 17 ++++------- pcbnew/footprint_edit_frame.cpp | 2 +- pcbnew/pcb_base_frame.cpp | 13 +++++++++ pcbnew/pcb_edit_frame.cpp | 2 +- 10 files changed, 45 insertions(+), 45 deletions(-) diff --git a/3d-viewer/3d_canvas/eda_3d_canvas.h b/3d-viewer/3d_canvas/eda_3d_canvas.h index 278b93d67c..52e8d98433 100644 --- a/3d-viewer/3d_canvas/eda_3d_canvas.h +++ b/3d-viewer/3d_canvas/eda_3d_canvas.h @@ -118,34 +118,20 @@ public: /** * Enable or disable camera animation when switching to a pre-defined view. - * - * @param aAnimationEnabled animation enabled state to set. */ - void AnimationEnabledSet( bool aAnimationEnabled ) { m_animation_enabled = aAnimationEnabled; } - - /** - * Return whether camera animation is enabled when switching to a pre-defined view. - * - * @return true if animation is enabled. - */ - bool AnimationEnabledGet() const { return m_animation_enabled; } + void SetAnimationEnabled( bool aEnable ) { m_animation_enabled = aEnable; } + bool GetAnimationEnabled() const { return m_animation_enabled; } /** * Set the camera animation moving speed multiplier option. * - * @param aMovingSpeedMultiplier one of the possible integer options: [1,2,3,4,5]. + * @param aMultiplier one of the possible integer options: [1,2,3,4,5]. */ - void MovingSpeedMultiplierSet( int aMovingSpeedMultiplier ) - { - m_moving_speed_multiplier = aMovingSpeedMultiplier; - } + void SetMovingSpeedMultiplier( int aMultiplier ) { m_moving_speed_multiplier = aMultiplier; } + int GetMovingSpeedMultiplier() const { return m_moving_speed_multiplier; } - /** - * Return the current camera animation moving speed multiplier option. - * - * @return current moving speed multiplier option, one of [1,2,3,4,5]. - */ - int MovingSpeedMultiplierGet() const { return m_moving_speed_multiplier; } + int GetProjectionMode() const { return (int) m_camera.GetProjection(); }; + void SetProjectionMode( int aMode ) { m_camera.SetProjection( (PROJECTION_TYPE) aMode ); } /** * Notify that the render engine was changed. diff --git a/3d-viewer/3d_rendering/camera.h b/3d-viewer/3d_rendering/camera.h index da9c4b0c0f..8b38cba497 100644 --- a/3d-viewer/3d_rendering/camera.h +++ b/3d-viewer/3d_rendering/camera.h @@ -36,7 +36,7 @@ enum class PROJECTION_TYPE { - ORTHO, + ORTHO = 0, PERSPECTIVE }; @@ -158,6 +158,7 @@ public: void ToggleProjection(); PROJECTION_TYPE GetProjection() { return m_projectionType; } + void SetProjection( PROJECTION_TYPE aProjection ) { m_projectionType = aProjection; } /** * Update the windows size of the camera. diff --git a/3d-viewer/3d_viewer/3d_viewer_settings.cpp b/3d-viewer/3d_viewer/3d_viewer_settings.cpp index 5a2052042f..a499a833fd 100644 --- a/3d-viewer/3d_viewer/3d_viewer_settings.cpp +++ b/3d-viewer/3d_viewer/3d_viewer_settings.cpp @@ -193,6 +193,8 @@ EDA_3D_VIEWER_SETTINGS::EDA_3D_VIEWER_SETTINGS() &m_Camera.moving_speed_multiplier, 3 ) ); m_params.emplace_back( new PARAM( "camera.rotation_increment", &m_Camera.rotation_increment, 10.0 ) ); + m_params.emplace_back( new PARAM( "camera.projection_mode", + &m_Camera.projection_mode, 1 ) ); } diff --git a/3d-viewer/3d_viewer/3d_viewer_settings.h b/3d-viewer/3d_viewer/3d_viewer_settings.h index 507f9aaaed..fd36bae3a5 100644 --- a/3d-viewer/3d_viewer/3d_viewer_settings.h +++ b/3d-viewer/3d_viewer/3d_viewer_settings.h @@ -93,6 +93,7 @@ public: bool animation_enabled; int moving_speed_multiplier; double rotation_increment; + int projection_mode; }; EDA_3D_VIEWER_SETTINGS(); diff --git a/3d-viewer/3d_viewer/dialogs/panel_3D_display_options.cpp b/3d-viewer/3d_viewer/dialogs/panel_3D_display_options.cpp index 908c99cc5a..e9c882a633 100644 --- a/3d-viewer/3d_viewer/dialogs/panel_3D_display_options.cpp +++ b/3d-viewer/3d_viewer/dialogs/panel_3D_display_options.cpp @@ -76,10 +76,10 @@ bool PANEL_3D_DISPLAY_OPTIONS::TransferDataToWindow() } // Camera Options - m_checkBoxEnableAnimation->SetValue( m_canvas->AnimationEnabledGet() ); - m_sliderAnimationSpeed->SetValue( m_canvas->MovingSpeedMultiplierGet() ); - m_staticAnimationSpeed->Enable( m_canvas->AnimationEnabledGet() ); - m_sliderAnimationSpeed->Enable( m_canvas->AnimationEnabledGet() ); + m_checkBoxEnableAnimation->SetValue( m_canvas->GetAnimationEnabled() ); + m_sliderAnimationSpeed->SetValue( m_canvas->GetMovingSpeedMultiplier() ); + m_staticAnimationSpeed->Enable( m_canvas->GetAnimationEnabled() ); + m_sliderAnimationSpeed->Enable( m_canvas->GetAnimationEnabled() ); EDA_3D_CONTROLLER* ctrlTool = m_frame->GetToolManager()->GetTool(); m_spinCtrlRotationAngle->SetValue( ctrlTool->GetRotationIncrement() ); @@ -123,8 +123,8 @@ bool PANEL_3D_DISPLAY_OPTIONS::TransferDataFromWindow() m_settings.SetFlag( FL_ECO, m_checkBoxECO->GetValue( ) ); // Camera Options - m_canvas->AnimationEnabledSet( m_checkBoxEnableAnimation->GetValue() ); - m_canvas->MovingSpeedMultiplierSet( m_sliderAnimationSpeed->GetValue() ); + m_canvas->SetAnimationEnabled( m_checkBoxEnableAnimation->GetValue()); + m_canvas->SetMovingSpeedMultiplier( m_sliderAnimationSpeed->GetValue()); EDA_3D_CONTROLLER* ctrlTool = m_frame->GetToolManager()->GetTool(); ctrlTool->SetRotationIncrement( m_spinCtrlRotationAngle->GetValue() ); diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.cpp b/3d-viewer/3d_viewer/eda_3d_viewer.cpp index cb252c0140..5c9d0e0cac 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer.cpp @@ -531,8 +531,9 @@ void EDA_3D_VIEWER::LoadSettings( APP_SETTINGS_BASE *aCfg ) m_boardAdapter.SetMaterialMode( static_cast( cfg->m_Render.material_mode ) ); - m_canvas->AnimationEnabledSet( cfg->m_Camera.animation_enabled ); - m_canvas->MovingSpeedMultiplierSet( cfg->m_Camera.moving_speed_multiplier ); + 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 ); #undef TRANSFER_SETTING } @@ -630,8 +631,9 @@ void EDA_3D_VIEWER::SaveSettings( APP_SETTINGS_BASE *aCfg ) save_color( m_boardAdapter.m_OpenGlSelectionColor, cfg->m_Render.opengl_selection_color ); - cfg->m_Camera.animation_enabled = m_canvas->AnimationEnabledGet(); - cfg->m_Camera.moving_speed_multiplier = m_canvas->MovingSpeedMultiplierGet(); + 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(); if( EDA_3D_CONTROLLER* ctrlTool = GetToolManager()->GetTool() ) cfg->m_Camera.rotation_increment = ctrlTool->GetRotationIncrement(); diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 61a2ac03b3..f7254b1c59 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -350,15 +350,8 @@ public: virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer ); - virtual void SetActiveLayer( PCB_LAYER_ID aLayer ) - { - GetScreen()->m_Active_Layer = aLayer; - } - - virtual PCB_LAYER_ID GetActiveLayer() const - { - return GetScreen()->m_Active_Layer; - } + virtual void SetActiveLayer( PCB_LAYER_ID aLayer ) { GetScreen()->m_Active_Layer = aLayer; } + virtual PCB_LAYER_ID GetActiveLayer() const { return GetScreen()->m_Active_Layer; } SEVERITY GetSeverity( int aErrorCode ) const override; @@ -395,6 +388,7 @@ public: virtual bool GetAutoZoom() { return false; } protected: + bool canCloseWindow( wxCloseEvent& aCloseEvent ) override; /** * Attempts to load \a aFootprintId from the footprint library table. @@ -407,12 +401,13 @@ protected: */ FOOTPRINT* loadFootprint( const LIB_ID& aFootprintId ); + virtual void unitsChangeRefresh() override; + +protected: BOARD* m_pcb; PCB_DISPLAY_OPTIONS m_displayOptions; PCB_ORIGIN_TRANSFORMS m_originTransforms; PCBNEW_SETTINGS* m_settings; // No ownership, just a shortcut - - virtual void unitsChangeRefresh() override; }; #endif // PCB_BASE_FRAME_H diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index aec3f6d437..59fe456c78 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -632,7 +632,7 @@ bool FOOTPRINT_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) } } - return true; + return PCB_BASE_EDIT_FRAME::canCloseWindow( aEvent ); } diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index fc2655f26b..1d04ed3ac0 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -83,6 +83,19 @@ PCB_BASE_FRAME::~PCB_BASE_FRAME() } +bool PCB_BASE_FRAME::canCloseWindow( wxCloseEvent& aEvent ) +{ + // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or + // board. + wxWindow* viewer3D = Get3DViewerFrame(); + + if( viewer3D ) + viewer3D->Close( true ); + + return true; +} + + EDA_3D_VIEWER* PCB_BASE_FRAME::Get3DViewerFrame() { return dynamic_cast( FindWindowByName( QUALIFIED_VIEWER3D_FRAMENAME( this ) ) ); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index e69dbce9e7..0ff86b99ea 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -840,7 +840,7 @@ bool PCB_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) if( open_dlg ) open_dlg->Close( true ); - return true; + return PCB_BASE_EDIT_FRAME::canCloseWindow( aEvent ); }