Properly handle limits

This commit is contained in:
Simon Schaak 2021-10-26 16:57:59 +02:00 committed by Wayne Stambaugh
parent 798cd567d5
commit 552e8af6af
2 changed files with 10 additions and 2 deletions

View File

@ -378,8 +378,12 @@ void PANEL_PREVIEW_3D_MODEL::onOpacitySlider( wxCommandEvent& event )
void PANEL_PREVIEW_3D_MODEL::updateBoardThickness( 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( m_boardAdapter.GetBoard()->GetDesignSettings().SetBoardThickness(
ValueFromString( m_userUnits, boardthickness->GetValue() ) ); static_cast<int>( curr_value ) );
m_previewPane->ReloadRequest(); m_previewPane->ReloadRequest();
m_previewPane->Request_refresh(); 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; 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 += ( 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 ); curr_value = std::min( curr_value, MAX_BOARD_THICKNESS );
textCtrl->SetValue( formatBoardThicknessValue( curr_value ) ); textCtrl->SetValue( formatBoardThicknessValue( curr_value ) );

View File

@ -48,6 +48,7 @@
#define MAX_SCALE 10000.0 #define MAX_SCALE 10000.0
#define MAX_ROTATION 180.0 #define MAX_ROTATION 180.0
#define MAX_OFFSET 1000.0 #define MAX_OFFSET 1000.0
#define MIN_BOARD_THICKNESS 0.01
#define MAX_BOARD_THICKNESS 100.0 #define MAX_BOARD_THICKNESS 100.0
#define SCALE_INCREMENT_FINE 0.02 #define SCALE_INCREMENT_FINE 0.02