PANEL_PREVIEW_3D_MODEL: fix incorrect values of offset for unit inch and mil.

Fixes #10104
https://gitlab.com/kicad/code/kicad/issues/10104
This commit is contained in:
jean-pierre charras 2021-12-28 10:36:37 +01:00
parent 987a6e125b
commit 49cb9586bd
1 changed files with 25 additions and 22 deletions

View File

@ -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 ) );
}