From 8cb94f09c3a26c38e81b5fc525a7720fc6e9c5ab Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 4 Aug 2018 19:10:20 +0200 Subject: [PATCH] Allows bigger image size in DIALOG_IMAGE_EDITOR --- common/dialogs/dialog_image_editor.cpp | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/common/dialogs/dialog_image_editor.cpp b/common/dialogs/dialog_image_editor.cpp index 82bbe23d48..fdd6b180cc 100644 --- a/common/dialogs/dialog_image_editor.cpp +++ b/common/dialogs/dialog_image_editor.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -119,35 +120,45 @@ void DIALOG_IMAGE_EDITOR::OnHalfSize( wxCommandEvent& event ) /* Test params values correctness * Currently scale value must give an actual image - * > MIN_SIZE pixels and < MAX_SIZE pixels + * > MIN_SIZE pixels (mandatory to be able to see the image) + * and < MAX_SIZE pixels (if bigger, a confirmation will be asked) + * Note: The image definition is 300ppi in drawing routines. */ bool DIALOG_IMAGE_EDITOR::CheckValues() { - #define MIN_SIZE 16 - #define MAX_SIZE 6000 + #define MIN_SIZE 32 // Min size in pixels after scaling + #define MAX_SIZE 6000 // Max size in pixels after scaling double tmp; wxString msg = m_textCtrlScale->GetValue(); // Test number correctness - if( ! msg.ToDouble( &tmp ) ) + if( !msg.ToDouble( &tmp ) || tmp < 0.0 ) { wxMessageBox( _("Incorrect scale number" ) ); return false; } - // Test value correctness + // Test value correctness wxSize psize = m_workingImage->GetSizePixels(); + int size_min = (int)std::min( (psize.x * tmp), (psize.y * tmp) ); - if( (psize.x * tmp) < MIN_SIZE || (psize.y * tmp) < MIN_SIZE ) + if( size_min < MIN_SIZE ) // if the size is too small, the image will be hard to locate { - wxMessageBox( _("Scale is too small for this image" ) ); + wxMessageBox( wxString::Format( + _("This scale gives a too small image size (%.2f mm or %.1f mil)" ), + 25.4 / 300 * size_min, 1000.0/300.0 * size_min ) ); return false; } - if( (psize.x * tmp) > MAX_SIZE || (psize.y * tmp) > MAX_SIZE ) + int size_max = (int)std::max( (psize.x * tmp), (psize.y * tmp) ); + + if( size_max > MAX_SIZE ) { - wxMessageBox( _("Scale is too large for this image" ) ); - return false; + // the actual size is 25.4/300 * size_max in mm + if( !IsOK( this, wxString::Format( + _("This scale gives a very large image size (%.1f mm or %.2f in). Are you sure?" ), + 25.4 / 300 * size_max, size_max /300.0 ) ) ) + return false; } return true;