From 552e8af6afe2b6116128e5ab760ba7cca6476d15 Mon Sep 17 00:00:00 2001 From: Simon Schaak <9246423-sschaak@users.noreply.gitlab.com> Date: Tue, 26 Oct 2021 16:57:59 +0200 Subject: [PATCH] Properly handle limits --- 3d-viewer/dialogs/panel_preview_3d_model.cpp | 11 +++++++++-- 3d-viewer/dialogs/panel_preview_3d_model.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/3d-viewer/dialogs/panel_preview_3d_model.cpp b/3d-viewer/dialogs/panel_preview_3d_model.cpp index 926b8c22e2..71bc774f2e 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.cpp +++ b/3d-viewer/dialogs/panel_preview_3d_model.cpp @@ -378,8 +378,12 @@ void PANEL_PREVIEW_3D_MODEL::onOpacitySlider( wxCommandEvent& event ) void PANEL_PREVIEW_3D_MODEL::updateBoardThickness( wxCommandEvent& event ) { + double curr_value = DoubleValueFromString( m_userUnits, boardthickness->GetValue() ); + curr_value = std::min( MAX_BOARD_THICKNESS * IU_PER_MM, curr_value ); + curr_value = std::max( curr_value, MIN_BOARD_THICKNESS * IU_PER_MM ); + m_boardAdapter.GetBoard()->GetDesignSettings().SetBoardThickness( - ValueFromString( m_userUnits, boardthickness->GetValue() ) ); + static_cast( curr_value ) ); m_previewPane->ReloadRequest(); m_previewPane->Request_refresh(); @@ -469,8 +473,11 @@ void PANEL_PREVIEW_3D_MODEL::doIncrementBoardThickness( wxSpinEvent& aEvent, dou double curr_value = DoubleValueFromString( m_userUnits, textCtrl->GetValue() ) / IU_PER_MM; + // avoid keeping the lower limit as offset after hitting it (0.4 -> 0.2 -> 0.01 -> 0.2 -> 0.4) + if (curr_value <= MIN_BOARD_THICKNESS) + curr_value = 0; curr_value += ( step * aSign ); - curr_value = std::max( 0.0, curr_value ); + curr_value = std::max( MIN_BOARD_THICKNESS, curr_value ); curr_value = std::min( curr_value, MAX_BOARD_THICKNESS ); textCtrl->SetValue( formatBoardThicknessValue( curr_value ) ); diff --git a/3d-viewer/dialogs/panel_preview_3d_model.h b/3d-viewer/dialogs/panel_preview_3d_model.h index 5eafeabf27..07a13dcde5 100644 --- a/3d-viewer/dialogs/panel_preview_3d_model.h +++ b/3d-viewer/dialogs/panel_preview_3d_model.h @@ -48,6 +48,7 @@ #define MAX_SCALE 10000.0 #define MAX_ROTATION 180.0 #define MAX_OFFSET 1000.0 +#define MIN_BOARD_THICKNESS 0.01 #define MAX_BOARD_THICKNESS 100.0 #define SCALE_INCREMENT_FINE 0.02