2011-08-31 14:59:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
2018-07-27 11:41:54 +00:00
|
|
|
* Copyright (C) 2018 jean-pierre.charras
|
2020-12-17 16:43:46 +00:00
|
|
|
* Copyright (C) 2011-2020 Kicad Developers, see AUTHORS.txt for contributors.
|
2011-08-31 14:59:20 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/dcclient.h>
|
2018-08-04 17:10:20 +00:00
|
|
|
#include <confirm.h>
|
2018-01-29 08:39:13 +00:00
|
|
|
#include <bitmap_base.h>
|
2022-02-08 19:29:54 +00:00
|
|
|
#include <pcb_base_edit_frame.h>
|
|
|
|
#include <pcb_bitmap.h>
|
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/actions.h>
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
#include <dialogs/panel_image_editor.h>
|
2011-08-31 14:59:20 +00:00
|
|
|
|
2020-07-11 09:37:22 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
PANEL_IMAGE_EDITOR::PANEL_IMAGE_EDITOR( wxWindow* aParent, BITMAP_BASE* aItem ) :
|
|
|
|
PANEL_IMAGE_EDITOR_BASE( aParent )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2019-06-19 10:31:21 +00:00
|
|
|
m_workingImage = new BITMAP_BASE( *aItem );
|
2011-08-31 14:59:20 +00:00
|
|
|
wxString msg;
|
2016-07-11 19:48:46 +00:00
|
|
|
msg.Printf( wxT( "%f" ), m_workingImage->GetScale() );
|
2015-01-17 08:01:16 +00:00
|
|
|
m_textCtrlScale->SetValue( msg );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
void PANEL_IMAGE_EDITOR::OnGreyScaleConvert( wxCommandEvent& event )
|
2011-09-02 19:43:56 +00:00
|
|
|
{
|
2023-01-03 03:14:22 +00:00
|
|
|
m_workingImage->ConvertToGreyscale();
|
2011-09-02 19:43:56 +00:00
|
|
|
m_panelDraw->Refresh();
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2019-06-19 10:31:21 +00:00
|
|
|
/*
|
|
|
|
* Test params values correctness
|
|
|
|
* Currently scale value must give an actual image > MIN_SIZE pixels (mandatory to be able to
|
|
|
|
* see the image) and < MAX_SIZE pixels (if bigger, a confirmation will be asked)
|
2018-08-04 17:10:20 +00:00
|
|
|
* Note: The image definition is 300ppi in drawing routines.
|
2011-09-02 19:43:56 +00:00
|
|
|
*/
|
2022-07-07 14:17:21 +00:00
|
|
|
bool PANEL_IMAGE_EDITOR::CheckValues()
|
2011-09-02 19:43:56 +00:00
|
|
|
{
|
2022-07-07 14:17:21 +00:00
|
|
|
#define MIN_SIZE 15 // Min size in pixels after scaling (50 mils)
|
|
|
|
#define MAX_SIZE 6000 // Max size in pixels after scaling (20 inches)
|
|
|
|
double tmp;
|
2011-09-02 19:43:56 +00:00
|
|
|
wxString msg = m_textCtrlScale->GetValue();
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2011-09-02 19:43:56 +00:00
|
|
|
// Test number correctness
|
2018-08-04 17:10:20 +00:00
|
|
|
if( !msg.ToDouble( &tmp ) || tmp < 0.0 )
|
2011-09-02 19:43:56 +00:00
|
|
|
{
|
2019-06-19 10:31:21 +00:00
|
|
|
wxMessageBox( _( "Incorrect scale number" ) );
|
2011-09-02 19:43:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-04 17:10:20 +00:00
|
|
|
// Test value correctness
|
2011-09-02 19:43:56 +00:00
|
|
|
wxSize psize = m_workingImage->GetSizePixels();
|
2022-07-07 14:17:21 +00:00
|
|
|
int size_min = (int) std::min( ( psize.x * tmp ), ( psize.y * tmp ) );
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
if( size_min < MIN_SIZE ) // if the size is too small, the image will be hard to locate
|
2011-09-02 19:43:56 +00:00
|
|
|
{
|
2019-06-19 10:31:21 +00:00
|
|
|
wxMessageBox( wxString::Format( _( "This scale results in an image which is too small "
|
|
|
|
"(%.2f mm or %.1f mil)." ),
|
2022-07-07 14:17:21 +00:00
|
|
|
25.4 / 300 * size_min, 1000.0 / 300.0 * size_min ) );
|
2011-09-02 19:43:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
int size_max = (int) std::max( ( psize.x * tmp ), ( psize.y * tmp ) );
|
2018-08-04 17:10:20 +00:00
|
|
|
|
|
|
|
if( size_max > MAX_SIZE )
|
2011-09-02 19:43:56 +00:00
|
|
|
{
|
2018-08-04 17:10:20 +00:00
|
|
|
// the actual size is 25.4/300 * size_max in mm
|
2019-06-19 10:31:21 +00:00
|
|
|
if( !IsOK( this, wxString::Format( _( "This scale results in an image which is very large "
|
|
|
|
"(%.1f mm or %.2f in). Are you sure?" ),
|
2022-07-07 14:17:21 +00:00
|
|
|
25.4 / 300 * size_max, size_max / 300.0 ) ) )
|
2021-10-14 19:45:38 +00:00
|
|
|
{
|
2018-08-04 17:10:20 +00:00
|
|
|
return false;
|
2021-10-14 19:45:38 +00:00
|
|
|
}
|
2011-09-02 19:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
bool PANEL_IMAGE_EDITOR::TransferDataFromWindow()
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
2018-07-27 11:41:54 +00:00
|
|
|
return CheckValues();
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
void PANEL_IMAGE_EDITOR::OnRedrawPanel( wxPaintEvent& event )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
|
|
|
wxPaintDC dc( m_panelDraw );
|
2022-07-07 14:17:21 +00:00
|
|
|
wxSize size = m_panelDraw->GetClientSize();
|
|
|
|
dc.SetDeviceOrigin( size.x / 2, size.y / 2 );
|
2011-08-31 14:59:20 +00:00
|
|
|
|
|
|
|
double scale = 1.0 / m_workingImage->GetScalingFactor();
|
|
|
|
dc.SetUserScale( scale, scale );
|
2018-08-03 09:04:57 +00:00
|
|
|
m_workingImage->DrawBitmap( &dc, wxPoint( 0, 0 ) );
|
2011-08-31 14:59:20 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 19:48:46 +00:00
|
|
|
|
2022-07-07 14:17:21 +00:00
|
|
|
void PANEL_IMAGE_EDITOR::TransferToImage( BITMAP_BASE* aItem )
|
2011-08-31 14:59:20 +00:00
|
|
|
{
|
|
|
|
wxString msg = m_textCtrlScale->GetValue();
|
2022-07-07 14:17:21 +00:00
|
|
|
double scale = 1.0;
|
2016-07-11 19:48:46 +00:00
|
|
|
msg.ToDouble( &scale );
|
|
|
|
m_workingImage->SetScale( scale );
|
2011-08-31 14:59:20 +00:00
|
|
|
aItem->ImportData( m_workingImage );
|
|
|
|
}
|