From f7c7791b6c96fb1bbcec46ca1af1d3cc3421c2e8 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 23 May 2024 17:00:55 +0100 Subject: [PATCH] Honour shift-key for spin buttons in 3D preview. Fixes https://gitlab.com/kicad/code/kicad/-/issues/17541 --- 3d-viewer/dialogs/panel_preview_3d_model.cpp | 32 +++++++++++++++----- 3d-viewer/dialogs/panel_preview_3d_model.h | 5 ++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index 4244508603..707778cae2 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -426,10 +426,15 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementScale( wxSpinEvent& event, double aSign else if( spinCtrl == m_spinZscale ) textCtrl = zscale; + double step = SCALE_INCREMENT; + + if( wxGetMouseState().ShiftDown( ) ) + step = SCALE_INCREMENT_FINE; + double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, EDA_UNITS::UNSCALED, textCtrl->GetValue() ); - curr_value += ( SCALE_INCREMENT * aSign ); + curr_value += ( step * aSign ); curr_value = std::max( 1/MAX_SCALE, curr_value ); curr_value = std::min( curr_value, MAX_SCALE ); @@ -447,10 +452,15 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementRotation( wxSpinEvent& aEvent, double aS else if( spinCtrl == m_spinZrot ) textCtrl = zrot; + double step = ROTATION_INCREMENT; + + if( wxGetMouseState().ShiftDown( ) ) + step = ROTATION_INCREMENT_FINE; + double curr_value = EDA_UNIT_UTILS::UI::DoubleValueFromString( unityScale, EDA_UNITS::DEGREES, textCtrl->GetValue() ); - curr_value += ( ROTATION_INCREMENT * aSign ); + curr_value += ( step * aSign ); curr_value = std::max( -MAX_ROTATION, curr_value ); curr_value = std::min( curr_value, MAX_ROTATION ); @@ -470,16 +480,22 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign textCtrl = zoff; double step_mm = OFFSET_INCREMENT_MM; - double curr_value_mm = - EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, - textCtrl->GetValue() ) - / pcbIUScale.IU_PER_MM; + + if( wxGetMouseState().ShiftDown( ) ) + step_mm = OFFSET_INCREMENT_MM_FINE; if( m_userUnits == EDA_UNITS::MILS || m_userUnits == EDA_UNITS::INCHES ) { step_mm = 25.4*OFFSET_INCREMENT_MIL/1000; + + if( wxGetMouseState().ShiftDown( ) ) + step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000;; } + double curr_value_mm = EDA_UNIT_UTILS::UI::DoubleValueFromString( pcbIUScale, m_userUnits, + textCtrl->GetValue() ) + / pcbIUScale.IU_PER_MM; + curr_value_mm += ( step_mm * aSign ); curr_value_mm = std::max( -MAX_OFFSET, curr_value_mm ); curr_value_mm = std::min( curr_value_mm, MAX_OFFSET ); @@ -515,10 +531,10 @@ void PANEL_PREVIEW_3D_MODEL::onMouseWheelRot( wxMouseEvent& event ) { wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject(); - double step = ROTATION_INCREMENT_WHEEL; + double step = ROTATION_INCREMENT; if( event.ShiftDown( ) ) - step = ROTATION_INCREMENT_WHEEL_FINE; + step = ROTATION_INCREMENT_FINE; if( event.GetWheelRotation() >= 0 ) step = -step; diff --git a/3d-viewer/dialogs/panel_preview_3d_model.h b/3d-viewer/dialogs/panel_preview_3d_model.h index 3fcba6aa1e..b60a56143c 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.h +++ b/3d-viewer/dialogs/panel_preview_3d_model.h @@ -43,9 +43,8 @@ #define SCALE_INCREMENT_FINE 0.02 #define SCALE_INCREMENT 0.1 -#define ROTATION_INCREMENT 90 // in degrees, for spin button command -#define ROTATION_INCREMENT_WHEEL 90 // in degrees, for mouse wheel command -#define ROTATION_INCREMENT_WHEEL_FINE 1 // in degrees, for mouse wheel command +#define ROTATION_INCREMENT 90 // in degrees +#define ROTATION_INCREMENT_FINE 1 // in degrees #define OFFSET_INCREMENT_MM 0.5 #define OFFSET_INCREMENT_MM_FINE 0.1