From 49cb9586bdf74ab851d1f29afe811790983741e4 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 28 Dec 2021 10:36:37 +0100 Subject: [PATCH] PANEL_PREVIEW_3D_MODEL: fix incorrect values of offset for unit inch and mil. Fixes #10104 https://gitlab.com/kicad/code/kicad/issues/10104 --- 3d-viewer/dialogs/panel_preview_3d_model.cpp | 47 +++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index 836267bca6..1cec37df5a 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -251,9 +251,11 @@ wxString PANEL_PREVIEW_3D_MODEL::formatOffsetValue( double aValue ) { // Convert from internal units (mm) to user units if( m_userUnits == EDA_UNITS::INCHES ) - aValue /= 25.4f; + aValue /= 25.4; + else if( m_userUnits == EDA_UNITS::MILS ) + aValue /= 25.4 / 1e3; - return wxString::Format( "%.4f%s", aValue, GetAbbreviatedUnitsLabel( m_userUnits ) ); + return wxString::Format( "%.6f%s", aValue, GetAbbreviatedUnitsLabel( m_userUnits ) ); } @@ -393,18 +395,19 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementOffset( wxSpinEvent& event, double aSign else if( spinCtrl == m_spinZoffset ) textCtrl = zoff; - double step = OFFSET_INCREMENT_MM; + double step_mm = OFFSET_INCREMENT_MM; + double curr_value_mm = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM; - if( m_userUnits == EDA_UNITS::INCHES ) - step = OFFSET_INCREMENT_MIL/1000.0; + if( m_userUnits == EDA_UNITS::MILS || m_userUnits == EDA_UNITS::INCHES ) + { + step_mm = 25.4*OFFSET_INCREMENT_MIL/1000; + } - double curr_value = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / 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 ); - curr_value += ( step * aSign ); - curr_value = std::max( -MAX_OFFSET, curr_value ); - curr_value = std::min( curr_value, MAX_OFFSET ); - - textCtrl->SetValue( formatOffsetValue( curr_value ) ); + textCtrl->SetValue( formatOffsetValue( curr_value_mm ) ); } @@ -456,29 +459,29 @@ void PANEL_PREVIEW_3D_MODEL::onMouseWheelOffset( wxMouseEvent& event ) { wxTextCtrl* textCtrl = (wxTextCtrl*) event.GetEventObject(); - double step = OFFSET_INCREMENT_MM; + double step_mm = OFFSET_INCREMENT_MM; if( event.ShiftDown( ) ) - step = OFFSET_INCREMENT_MM_FINE; + step_mm = OFFSET_INCREMENT_MM_FINE; - if( m_userUnits == EDA_UNITS::INCHES ) + if( m_userUnits == EDA_UNITS::MILS || m_userUnits == EDA_UNITS::INCHES ) { - step = OFFSET_INCREMENT_MIL/1000.0; + step_mm = 25.4*OFFSET_INCREMENT_MIL/1000.0; if( event.ShiftDown( ) ) - step = OFFSET_INCREMENT_MIL_FINE/1000.0; + step_mm = 25.4*OFFSET_INCREMENT_MIL_FINE/1000.0; } if( event.GetWheelRotation() >= 0 ) - step = -step; + step_mm = -step_mm; - double curr_value = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM; + double curr_value_mm = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM; - curr_value += step; - curr_value = std::max( -MAX_OFFSET, curr_value ); - curr_value = std::min( curr_value, MAX_OFFSET ); + curr_value_mm += step_mm; + curr_value_mm = std::max( -MAX_OFFSET, curr_value_mm ); + curr_value_mm = std::min( curr_value_mm, MAX_OFFSET ); - textCtrl->SetValue( formatOffsetValue( curr_value ) ); + textCtrl->SetValue( formatOffsetValue( curr_value_mm ) ); }