2019-06-19 14:18:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2010 jean-pierre.charras
|
2022-02-09 14:01:30 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-06-19 14:18:30 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bitmap2cmp_gui.h"
|
|
|
|
#include "bitmap2component.h"
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <bitmap2cmp_settings.h>
|
2019-06-19 14:18:30 +00:00
|
|
|
#include <bitmap_io.h>
|
|
|
|
#include <bitmaps.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/util.h> // for KiROUND
|
2019-06-19 14:18:30 +00:00
|
|
|
#include <kiway.h>
|
|
|
|
#include <potracelib.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
2022-11-19 19:39:32 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/common_control.h>
|
2019-06-19 14:18:30 +00:00
|
|
|
#include <wx/clipbrd.h>
|
|
|
|
#include <wx/rawbmp.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/dcclient.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
#include "bitmap2cmp_gui_base.h"
|
2022-11-19 19:39:32 +00:00
|
|
|
#include "pgm_base.h"
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
#define DEFAULT_DPI 300 // the image DPI used in formats that do not define a DPI
|
|
|
|
|
|
|
|
IMAGE_SIZE::IMAGE_SIZE()
|
|
|
|
{
|
|
|
|
m_outputSize = 0.0;
|
|
|
|
m_originalDPI = DEFAULT_DPI;
|
|
|
|
m_originalSizePixels = 0;
|
2019-12-20 14:11:39 +00:00
|
|
|
m_unit = EDA_UNITS::MILLIMETRES;
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IMAGE_SIZE::SetOutputSizeFromInitialImageSize()
|
|
|
|
{
|
2020-01-15 18:33:19 +00:00
|
|
|
// Safety-check to guarantee no divide-by-zero
|
|
|
|
m_originalDPI = std::max( 1, m_originalDPI );
|
|
|
|
|
2019-06-19 14:18:30 +00:00
|
|
|
// Set the m_outputSize value from the m_originalSizePixels and the selected unit
|
2019-12-20 14:11:39 +00:00
|
|
|
if( m_unit == EDA_UNITS::MILLIMETRES )
|
2019-06-19 14:18:30 +00:00
|
|
|
m_outputSize = (double)GetOriginalSizePixels() / m_originalDPI * 25.4;
|
2019-12-20 14:11:39 +00:00
|
|
|
else if( m_unit == EDA_UNITS::INCHES )
|
2019-06-19 14:18:30 +00:00
|
|
|
m_outputSize = (double)GetOriginalSizePixels() / m_originalDPI;
|
|
|
|
else
|
|
|
|
m_outputSize = m_originalDPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int IMAGE_SIZE::GetOutputDPI()
|
|
|
|
{
|
|
|
|
int outputDPI;
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
if( m_unit == EDA_UNITS::MILLIMETRES )
|
2019-06-19 14:18:30 +00:00
|
|
|
outputDPI = GetOriginalSizePixels() / ( m_outputSize / 25.4 );
|
2019-12-20 14:11:39 +00:00
|
|
|
else if( m_unit == EDA_UNITS::INCHES )
|
2019-06-19 14:18:30 +00:00
|
|
|
outputDPI = GetOriginalSizePixels() / m_outputSize;
|
|
|
|
else
|
|
|
|
outputDPI = KiROUND( m_outputSize );
|
|
|
|
|
2020-01-15 18:33:19 +00:00
|
|
|
// Zero is not a DPI, and may cause divide-by-zero errors...
|
|
|
|
outputDPI = std::max( 1, outputDPI );
|
|
|
|
|
2019-06-19 14:18:30 +00:00
|
|
|
return outputDPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
void IMAGE_SIZE::SetUnit( EDA_UNITS aUnit )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
// Set the unit used for m_outputSize, and convert the old m_outputSize value
|
|
|
|
// to the value in new unit
|
|
|
|
if( aUnit == m_unit )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Convert m_outputSize to mm:
|
|
|
|
double size_mm;
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
if( m_unit == EDA_UNITS::MILLIMETRES )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
size_mm = m_outputSize;
|
|
|
|
}
|
2019-12-20 14:11:39 +00:00
|
|
|
else if( m_unit == EDA_UNITS::INCHES )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
size_mm = m_outputSize * 25.4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// m_outputSize is the DPI, not an image size
|
|
|
|
// the image size is m_originalSizePixels / m_outputSize (in inches)
|
|
|
|
if( m_outputSize )
|
|
|
|
size_mm = m_originalSizePixels / m_outputSize * 25.4;
|
|
|
|
else
|
|
|
|
size_mm = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert m_outputSize to new value:
|
2019-12-20 14:11:39 +00:00
|
|
|
if( aUnit == EDA_UNITS::MILLIMETRES )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
m_outputSize = size_mm;
|
|
|
|
}
|
2019-12-20 14:11:39 +00:00
|
|
|
else if( aUnit == EDA_UNITS::INCHES )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
m_outputSize = size_mm / 25.4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( size_mm )
|
|
|
|
m_outputSize = m_originalSizePixels / size_mm * 25.4;
|
|
|
|
else
|
|
|
|
m_outputSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_unit = aUnit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-19 19:39:32 +00:00
|
|
|
BEGIN_EVENT_TABLE( BM2CMP_FRAME, BM2CMP_FRAME_BASE )
|
|
|
|
EVT_MENU( wxID_EXIT, BM2CMP_FRAME::OnExit )
|
|
|
|
EVT_MENU( wxID_OPEN, BM2CMP_FRAME::OnLoadFile )
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
BM2CMP_FRAME::BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
|
|
|
BM2CMP_FRAME_BASE( aParent )
|
|
|
|
{
|
|
|
|
SetKiway( this, aKiway );
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
for( wxString unit : { _( "mm" ), _( "Inch" ), _( "DPI" ) } )
|
|
|
|
m_PixelUnit->Append( unit );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
LoadSettings( config() );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
m_outputSizeX.SetUnit( getUnitFromSelection() );
|
|
|
|
m_outputSizeY.SetUnit( getUnitFromSelection() );
|
|
|
|
m_outputSizeX.SetOutputSize( 0, getUnitFromSelection() );
|
|
|
|
m_outputSizeY.SetOutputSize( 0, getUnitFromSelection() );
|
|
|
|
|
|
|
|
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
|
|
|
|
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
|
|
|
|
|
|
|
|
// Give an icon
|
|
|
|
wxIcon icon;
|
2020-12-22 19:41:32 +00:00
|
|
|
wxIconBundle icon_bundle;
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_bitmap2component ) );
|
2020-12-22 19:41:32 +00:00
|
|
|
icon_bundle.AddIcon( icon );
|
2021-03-08 02:59:07 +00:00
|
|
|
icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_bitmap2component_32 ) );
|
2020-12-22 19:41:32 +00:00
|
|
|
icon_bundle.AddIcon( icon );
|
2021-03-08 02:59:07 +00:00
|
|
|
icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_bitmap2component_16 ) );
|
2020-12-22 19:41:32 +00:00
|
|
|
icon_bundle.AddIcon( icon );
|
|
|
|
|
|
|
|
SetIcons( icon_bundle );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2022-11-19 19:39:32 +00:00
|
|
|
ReCreateMenuBar();
|
|
|
|
|
2019-06-19 14:18:30 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
|
|
|
|
|
|
|
m_buttonExportFile->Enable( false );
|
|
|
|
m_buttonExportClipboard->Enable( false );
|
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
if ( m_framePos == wxDefaultPosition )
|
2019-06-19 14:18:30 +00:00
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BM2CMP_FRAME::~BM2CMP_FRAME()
|
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
SaveSettings( config() );
|
2019-06-19 14:18:30 +00:00
|
|
|
/*
|
|
|
|
* This needed for OSX: avoids further OnDraw processing after this
|
|
|
|
* destructor and before the native window is destroyed
|
|
|
|
*/
|
2021-02-09 16:35:43 +00:00
|
|
|
Freeze();
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-24 01:01:23 +00:00
|
|
|
wxWindow* BM2CMP_FRAME::GetToolCanvas() const
|
|
|
|
{
|
|
|
|
return m_Notebook->GetCurrentPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-16 21:37:32 +00:00
|
|
|
void BM2CMP_FRAME::doReCreateMenuBar()
|
2022-11-19 19:39:32 +00:00
|
|
|
{
|
|
|
|
// wxWidgets handles the Mac Application menu behind the scenes, but that means
|
|
|
|
// we always have to start from scratch with a new wxMenuBar.
|
|
|
|
wxMenuBar* oldMenuBar = GetMenuBar();
|
|
|
|
wxMenuBar* menuBar = new wxMenuBar();
|
|
|
|
|
|
|
|
wxMenu* fileMenu = new wxMenu;
|
|
|
|
|
|
|
|
wxMenuItem* item = new wxMenuItem( fileMenu, wxID_OPEN, _( "Open..." ) + wxT( "\tCtrl+O" ),
|
|
|
|
_( "Load source image" ) );
|
|
|
|
|
|
|
|
fileMenu->Append( item );
|
|
|
|
|
|
|
|
#ifndef __WXMAC__
|
|
|
|
// Mac moves Quit to the App menu so we don't need a separator on Mac
|
|
|
|
fileMenu->AppendSeparator();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
item = new wxMenuItem( fileMenu, wxID_EXIT, _( "Quit" ) + wxT( "\tCtrl+Q" ),
|
|
|
|
_( "Quit Image Converter" ) );
|
|
|
|
|
|
|
|
if( Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus )
|
|
|
|
item->SetBitmap( KiBitmap( BITMAPS::exit ) );
|
|
|
|
|
|
|
|
fileMenu->Append( item );
|
|
|
|
|
|
|
|
menuBar->Append( fileMenu, _( "&File" ) );
|
|
|
|
|
|
|
|
SetMenuBar( menuBar );
|
|
|
|
delete oldMenuBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnExit( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void BM2CMP_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
EDA_BASE_FRAME::LoadSettings( aCfg );
|
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
BITMAP2CMP_SETTINGS* cfg = static_cast<BITMAP2CMP_SETTINGS*>( aCfg );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_BitmapFileName = cfg->m_BitmapFileName;
|
|
|
|
m_ConvertedFileName = cfg->m_ConvertedFileName;
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
int u_select = cfg->m_Units;
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
if( u_select < 0 || u_select > 2 ) // Validity control
|
|
|
|
u_select = 0;
|
|
|
|
|
|
|
|
m_PixelUnit->SetSelection( u_select );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_sliderThreshold->SetValue( cfg->m_Threshold );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_Negative = cfg->m_Negative;
|
|
|
|
m_checkNegative->SetValue( cfg->m_Negative );
|
2022-11-19 19:39:32 +00:00
|
|
|
|
|
|
|
m_AspectRatio = 1.0;
|
|
|
|
m_aspectRatioCheckbox->SetValue( true );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
int format = cfg->m_LastFormat;
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
if( format < 0 || format > FINAL_FMT )
|
|
|
|
format = PCBNEW_KICAD_MOD;
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_rbOutputFormat->SetSelection( format );
|
|
|
|
|
|
|
|
if( format == PCBNEW_KICAD_MOD )
|
2019-06-19 14:18:30 +00:00
|
|
|
m_rbPCBLayer->Enable( true );
|
|
|
|
else
|
|
|
|
m_rbPCBLayer->Enable( false );
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
int last_layer = cfg->m_LastModLayer;
|
|
|
|
|
|
|
|
if( last_layer > static_cast<int>( MOD_LYR_FINAL ) ) // Out of range
|
|
|
|
m_rbPCBLayer->SetSelection( MOD_LYR_FSILKS );
|
|
|
|
else
|
|
|
|
m_rbPCBLayer->SetSelection( last_layer );
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void BM2CMP_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
EDA_BASE_FRAME::SaveSettings( aCfg );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
BITMAP2CMP_SETTINGS* cfg = static_cast<BITMAP2CMP_SETTINGS*>( aCfg );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
cfg->m_BitmapFileName = m_BitmapFileName;
|
|
|
|
cfg->m_ConvertedFileName = m_ConvertedFileName;
|
|
|
|
cfg->m_Threshold = m_sliderThreshold->GetValue();
|
|
|
|
cfg->m_Negative = m_checkNegative->IsChecked();
|
|
|
|
cfg->m_LastFormat = m_rbOutputFormat->GetSelection();
|
|
|
|
cfg->m_LastModLayer = m_rbPCBLayer->GetSelection();
|
|
|
|
cfg->m_Units = m_PixelUnit->GetSelection();
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnPaintInit( wxPaintEvent& event )
|
|
|
|
{
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Otherwise fails due: using wxPaintDC without being in a native paint event
|
|
|
|
wxClientDC pict_dc( m_InitialPicturePanel );
|
|
|
|
#else
|
|
|
|
wxPaintDC pict_dc( m_InitialPicturePanel );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_InitialPicturePanel->PrepareDC( pict_dc );
|
|
|
|
|
|
|
|
// OSX crashes with empty bitmaps (on initial refreshes)
|
|
|
|
if( m_Pict_Bitmap.IsOk() )
|
|
|
|
pict_dc.DrawBitmap( m_Pict_Bitmap, 0, 0, !!m_Pict_Bitmap.GetMask() );
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnPaintGreyscale( wxPaintEvent& event )
|
|
|
|
{
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Otherwise fails due: using wxPaintDC without being in a native paint event
|
|
|
|
wxClientDC greyscale_dc( m_GreyscalePicturePanel );
|
|
|
|
#else
|
|
|
|
wxPaintDC greyscale_dc( m_GreyscalePicturePanel );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_GreyscalePicturePanel->PrepareDC( greyscale_dc );
|
|
|
|
|
|
|
|
// OSX crashes with empty bitmaps (on initial refreshes)
|
|
|
|
if( m_Greyscale_Bitmap.IsOk() )
|
|
|
|
greyscale_dc.DrawBitmap( m_Greyscale_Bitmap, 0, 0, !!m_Greyscale_Bitmap.GetMask() );
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnPaintBW( wxPaintEvent& event )
|
|
|
|
{
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Otherwise fails due: using wxPaintDC without being in a native paint event
|
|
|
|
wxClientDC nb_dc( m_BNPicturePanel );
|
|
|
|
#else
|
|
|
|
wxPaintDC nb_dc( m_BNPicturePanel );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_BNPicturePanel->PrepareDC( nb_dc );
|
|
|
|
|
|
|
|
if( m_BN_Bitmap.IsOk() )
|
|
|
|
nb_dc.DrawBitmap( m_BN_Bitmap, 0, 0, !!m_BN_Bitmap.GetMask() );
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxFileName fn( m_BitmapFileName );
|
|
|
|
wxString path = fn.GetPath();
|
|
|
|
|
|
|
|
if( path.IsEmpty() || !wxDirExists( path ) )
|
|
|
|
path = m_mruPath;
|
|
|
|
|
|
|
|
wxFileDialog fileDlg( this, _( "Choose Image" ), path, wxEmptyString,
|
2020-10-20 19:05:04 +00:00
|
|
|
_( "Image Files" ) + wxS( " " )+ wxImage::GetImageExtWildcard(),
|
2019-06-19 14:18:30 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
|
|
|
int diag = fileDlg.ShowModal();
|
|
|
|
|
|
|
|
if( diag != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxString fullFilename = fileDlg.GetPath();
|
|
|
|
|
|
|
|
if( !OpenProjectFiles( std::vector<wxString>( 1, fullFilename ) ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
fn = fullFilename;
|
|
|
|
m_mruPath = fn.GetPath();
|
|
|
|
SetStatusText( fullFilename );
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BM2CMP_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
|
|
|
|
{
|
|
|
|
m_Pict_Image.Destroy();
|
|
|
|
m_BitmapFileName = aFileSet[0];
|
|
|
|
|
|
|
|
if( !m_Pict_Image.LoadFile( m_BitmapFileName ) )
|
|
|
|
{
|
|
|
|
// LoadFile has its own UI, no need for further failure notification here
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Pict_Bitmap = wxBitmap( m_Pict_Image );
|
|
|
|
|
|
|
|
// Determine image resolution in DPI (does not existing in all formats).
|
|
|
|
// the resolution can be given in bit per inches or bit per cm in file
|
|
|
|
|
|
|
|
int imageDPIx = m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
|
|
|
|
int imageDPIy = m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
|
|
|
|
|
|
|
|
if( imageDPIx > 1 && imageDPIy > 1 )
|
|
|
|
{
|
|
|
|
if( m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
|
|
|
|
{
|
|
|
|
imageDPIx = KiROUND( imageDPIx * 2.54 );
|
|
|
|
imageDPIy = KiROUND( imageDPIy * 2.54 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // fallback to a default value (DEFAULT_DPI)
|
|
|
|
{
|
|
|
|
imageDPIx = imageDPIy = DEFAULT_DPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_InputXValueDPI->SetLabel( wxString::Format( wxT( "%d" ), imageDPIx ) );
|
|
|
|
m_InputYValueDPI->SetLabel( wxString::Format( wxT( "%d" ), imageDPIy ) );
|
|
|
|
|
|
|
|
int h = m_Pict_Bitmap.GetHeight();
|
|
|
|
int w = m_Pict_Bitmap.GetWidth();
|
|
|
|
m_AspectRatio = (double) w / h;
|
|
|
|
|
|
|
|
m_outputSizeX.SetOriginalDPI( imageDPIx );
|
|
|
|
m_outputSizeX.SetOriginalSizePixels( w );
|
|
|
|
m_outputSizeY.SetOriginalDPI( imageDPIy );
|
|
|
|
m_outputSizeY.SetOriginalSizePixels( h );
|
|
|
|
|
|
|
|
// Update display to keep aspect ratio
|
2022-10-16 16:45:10 +00:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
OnSizeChangeX( dummy );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
updateImageInfo();
|
|
|
|
|
|
|
|
m_InitialPicturePanel->SetVirtualSize( w, h );
|
|
|
|
m_GreyscalePicturePanel->SetVirtualSize( w, h );
|
|
|
|
m_BNPicturePanel->SetVirtualSize( w, h );
|
|
|
|
|
|
|
|
m_Greyscale_Image.Destroy();
|
|
|
|
m_Greyscale_Image = m_Pict_Image.ConvertToGreyscale( );
|
|
|
|
|
|
|
|
if( m_Pict_Bitmap.GetMask() )
|
|
|
|
{
|
|
|
|
for( int x = 0; x < m_Pict_Bitmap.GetWidth(); x++ )
|
|
|
|
{
|
|
|
|
for( int y = 0; y < m_Pict_Bitmap.GetHeight(); y++ )
|
|
|
|
{
|
|
|
|
if( m_Pict_Image.GetRed( x, y ) == m_Pict_Image.GetMaskRed() &&
|
|
|
|
m_Pict_Image.GetGreen( x, y ) == m_Pict_Image.GetMaskGreen() &&
|
|
|
|
m_Pict_Image.GetBlue( x, y ) == m_Pict_Image.GetMaskBlue() )
|
|
|
|
{
|
|
|
|
m_Greyscale_Image.SetRGB( x, y, 255, 255, 255 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_Negative )
|
|
|
|
NegateGreyscaleImage( );
|
|
|
|
|
|
|
|
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
|
|
|
|
m_NB_Image = m_Greyscale_Image;
|
2021-07-16 20:13:26 +00:00
|
|
|
Binarize( (double) m_sliderThreshold->GetValue() / m_sliderThreshold->GetMax() );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
m_buttonExportFile->Enable( true );
|
|
|
|
m_buttonExportClipboard->Enable( true );
|
|
|
|
|
|
|
|
m_outputSizeX.SetOutputSizeFromInitialImageSize();
|
|
|
|
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
|
|
|
|
m_outputSizeY.SetOutputSizeFromInitialImageSize();
|
|
|
|
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return a string giving the output size, according to the selected unit
|
|
|
|
wxString BM2CMP_FRAME::FormatOutputSize( double aSize )
|
|
|
|
{
|
|
|
|
wxString text;
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
if( getUnitFromSelection() == EDA_UNITS::MILLIMETRES )
|
2019-06-19 14:18:30 +00:00
|
|
|
text.Printf( "%.1f", aSize );
|
2019-12-20 14:11:39 +00:00
|
|
|
else if( getUnitFromSelection() == EDA_UNITS::INCHES )
|
2019-06-19 14:18:30 +00:00
|
|
|
text.Printf( "%.2f", aSize );
|
|
|
|
else
|
2022-02-09 14:01:30 +00:00
|
|
|
text.Printf( wxT( "%d" ), KiROUND( aSize ) );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::updateImageInfo()
|
|
|
|
{
|
2022-11-19 19:39:32 +00:00
|
|
|
// Note: the image resolution text controls are not modified here, to avoid a race between
|
|
|
|
// text change when entered by user and a text change if it is modified here.
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
if( m_Pict_Bitmap.IsOk() )
|
|
|
|
{
|
|
|
|
int h = m_Pict_Bitmap.GetHeight();
|
|
|
|
int w = m_Pict_Bitmap.GetWidth();
|
|
|
|
int nb = m_Pict_Bitmap.GetDepth();
|
|
|
|
|
|
|
|
m_SizeXValue->SetLabel( wxString::Format( wxT( "%d" ), w ) );
|
|
|
|
m_SizeYValue->SetLabel( wxString::Format( wxT( "%d" ), h ) );
|
|
|
|
m_BPPValue->SetLabel( wxString::Format( wxT( "%d" ), nb ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
EDA_UNITS BM2CMP_FRAME::getUnitFromSelection()
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
// return the EDA_UNITS from the m_PixelUnit choice
|
2019-06-19 14:18:30 +00:00
|
|
|
switch( m_PixelUnit->GetSelection() )
|
|
|
|
{
|
2022-11-19 19:39:32 +00:00
|
|
|
case 1: return EDA_UNITS::INCHES;
|
|
|
|
case 2: return EDA_UNITS::UNSCALED;
|
2019-06-19 14:18:30 +00:00
|
|
|
case 0:
|
2022-11-19 19:39:32 +00:00
|
|
|
default: return EDA_UNITS::MILLIMETRES;
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnSizeChangeX( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
double new_size;
|
|
|
|
|
|
|
|
if( m_UnitSizeX->GetValue().ToDouble( &new_size ) )
|
|
|
|
{
|
2022-11-19 19:39:32 +00:00
|
|
|
if( m_aspectRatioCheckbox->GetValue() )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
double calculatedY = new_size / m_AspectRatio;
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
if( getUnitFromSelection() == EDA_UNITS::UNSCALED )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
// for units in DPI, keeping aspect ratio cannot use m_AspectRatioLocked.
|
2021-07-16 20:13:26 +00:00
|
|
|
// just re-scale the other dpi
|
2019-06-19 14:18:30 +00:00
|
|
|
double ratio = new_size / m_outputSizeX.GetOutputSize();
|
|
|
|
calculatedY = m_outputSizeY.GetOutputSize() * ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputSizeY.SetOutputSize( calculatedY, getUnitFromSelection() );
|
|
|
|
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputSizeX.SetOutputSize( new_size, getUnitFromSelection() );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateImageInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnSizeChangeY( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
double new_size;
|
|
|
|
|
|
|
|
if( m_UnitSizeY->GetValue().ToDouble( &new_size ) )
|
|
|
|
{
|
2022-11-19 19:39:32 +00:00
|
|
|
if( m_aspectRatioCheckbox->GetValue() )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
double calculatedX = new_size * m_AspectRatio;
|
|
|
|
|
2019-12-20 14:11:39 +00:00
|
|
|
if( getUnitFromSelection() == EDA_UNITS::UNSCALED )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
// for units in DPI, keeping aspect ratio cannot use m_AspectRatioLocked.
|
2021-07-16 20:13:26 +00:00
|
|
|
// just re-scale the other dpi
|
2019-06-19 14:18:30 +00:00
|
|
|
double ratio = new_size / m_outputSizeX.GetOutputSize();
|
|
|
|
calculatedX = m_outputSizeX.GetOutputSize() * ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputSizeX.SetOutputSize( calculatedX, getUnitFromSelection() );
|
|
|
|
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_outputSizeY.SetOutputSize( new_size, getUnitFromSelection() );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateImageInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnSizeUnitChange( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_outputSizeX.SetUnit( getUnitFromSelection() );
|
|
|
|
m_outputSizeY.SetUnit( getUnitFromSelection() );
|
|
|
|
updateImageInfo();
|
|
|
|
|
|
|
|
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
|
|
|
|
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::ToggleAspectRatioLock( wxCommandEvent& event )
|
|
|
|
{
|
2022-11-19 19:39:32 +00:00
|
|
|
if( m_aspectRatioCheckbox->GetValue() )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
2022-11-19 19:39:32 +00:00
|
|
|
// Force display update when aspect ratio is locked
|
2022-10-16 16:45:10 +00:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
OnSizeChangeX( dummy );
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::Binarize( double aThreshold )
|
|
|
|
{
|
|
|
|
int h = m_Greyscale_Image.GetHeight();
|
|
|
|
int w = m_Greyscale_Image.GetWidth();
|
|
|
|
unsigned char threshold = aThreshold * 255;
|
|
|
|
unsigned char alpha_thresh = 0.7 * threshold;
|
|
|
|
|
|
|
|
for( int y = 0; y < h; y++ )
|
2022-10-16 16:45:10 +00:00
|
|
|
{
|
2019-06-19 14:18:30 +00:00
|
|
|
for( int x = 0; x < w; x++ )
|
|
|
|
{
|
|
|
|
unsigned char pixout;
|
2022-10-16 16:45:10 +00:00
|
|
|
unsigned char pixin = m_Greyscale_Image.GetGreen( x, y );
|
|
|
|
unsigned char alpha = m_Greyscale_Image.HasAlpha() ? m_Greyscale_Image.GetAlpha( x, y )
|
|
|
|
: wxALPHA_OPAQUE;
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
if( pixin < threshold && alpha > alpha_thresh )
|
|
|
|
pixout = 0;
|
|
|
|
else
|
|
|
|
pixout = 255;
|
|
|
|
|
|
|
|
m_NB_Image.SetRGB( x, y, pixout, pixout, pixout );
|
|
|
|
}
|
2022-10-16 16:45:10 +00:00
|
|
|
}
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
m_BN_Bitmap = wxBitmap( m_NB_Image );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::NegateGreyscaleImage( )
|
|
|
|
{
|
2022-10-16 16:45:10 +00:00
|
|
|
unsigned char pix;
|
|
|
|
int h = m_Greyscale_Image.GetHeight();
|
|
|
|
int w = m_Greyscale_Image.GetWidth();
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
for( int y = 0; y < h; y++ )
|
2022-10-16 16:45:10 +00:00
|
|
|
{
|
2019-06-19 14:18:30 +00:00
|
|
|
for( int x = 0; x < w; x++ )
|
|
|
|
{
|
|
|
|
pix = m_Greyscale_Image.GetGreen( x, y );
|
|
|
|
pix = ~pix;
|
|
|
|
m_Greyscale_Image.SetRGB( x, y, pix, pix, pix );
|
|
|
|
}
|
2022-10-16 16:45:10 +00:00
|
|
|
}
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnNegativeClicked( wxCommandEvent& )
|
|
|
|
{
|
|
|
|
if( m_checkNegative->GetValue() != m_Negative )
|
|
|
|
{
|
|
|
|
NegateGreyscaleImage();
|
|
|
|
|
|
|
|
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
|
|
|
|
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
|
|
|
|
m_Negative = m_checkNegative->GetValue();
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnThresholdChange( wxScrollEvent& event )
|
|
|
|
{
|
|
|
|
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnExportToFile( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// choices of m_rbOutputFormat are expected to be in same order as
|
|
|
|
// OUTPUT_FMT_ID. See bitmap2component.h
|
|
|
|
OUTPUT_FMT_ID format = (OUTPUT_FMT_ID) m_rbOutputFormat->GetSelection();
|
|
|
|
exportBitmap( format );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnExportToClipboard( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// choices of m_rbOutputFormat are expected to be in same order as
|
|
|
|
// OUTPUT_FMT_ID. See bitmap2component.h
|
|
|
|
OUTPUT_FMT_ID format = (OUTPUT_FMT_ID) m_rbOutputFormat->GetSelection();
|
|
|
|
|
|
|
|
std::string buffer;
|
|
|
|
ExportToBuffer( buffer, format );
|
|
|
|
|
2021-01-29 19:13:12 +00:00
|
|
|
wxLogNull doNotLog; // disable logging of failed clipboard actions
|
|
|
|
|
2019-06-19 14:18:30 +00:00
|
|
|
// Write buffer to the clipboard
|
2021-07-16 20:13:26 +00:00
|
|
|
if( wxTheClipboard->Open() )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
// This data objects are held by the clipboard,
|
|
|
|
// so do not delete them in the app.
|
|
|
|
wxTheClipboard->SetData( new wxTextDataObject( buffer.c_str() ) );
|
2021-05-01 22:00:08 +00:00
|
|
|
wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
|
2019-06-19 14:18:30 +00:00
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
else
|
2021-07-16 20:13:26 +00:00
|
|
|
{
|
2019-06-19 14:18:30 +00:00
|
|
|
wxMessageBox( _( "Unable to export to the Clipboard") );
|
2021-07-16 20:13:26 +00:00
|
|
|
}
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::exportBitmap( OUTPUT_FMT_ID aFormat )
|
|
|
|
{
|
|
|
|
switch( aFormat )
|
|
|
|
{
|
2022-11-19 19:39:32 +00:00
|
|
|
case EESCHEMA_FMT: exportEeschemaFormat(); break;
|
|
|
|
case PCBNEW_KICAD_MOD: exportPcbnewFormat(); break;
|
|
|
|
case POSTSCRIPT_FMT: exportPostScriptFormat(); break;
|
|
|
|
case KICAD_WKS_LOGO: exportLogo(); break;
|
2019-06-19 14:18:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-19 19:39:32 +00:00
|
|
|
void BM2CMP_FRAME::exportLogo()
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
wxFileName fn( m_ConvertedFileName );
|
|
|
|
wxString path = fn.GetPath();
|
|
|
|
|
|
|
|
if( path.IsEmpty() || !wxDirExists(path) )
|
|
|
|
path = ::wxGetCwd();
|
|
|
|
|
|
|
|
wxFileDialog fileDlg( this, _( "Create Logo File" ), path, wxEmptyString,
|
2021-05-30 22:56:24 +00:00
|
|
|
DrawingSheetFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2019-06-19 14:18:30 +00:00
|
|
|
int diag = fileDlg.ShowModal();
|
|
|
|
|
|
|
|
if( diag != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
fn = fileDlg.GetPath();
|
2021-05-30 22:56:24 +00:00
|
|
|
fn.SetExt( DrawingSheetFileExtension );
|
2019-06-19 14:18:30 +00:00
|
|
|
m_ConvertedFileName = fn.GetFullPath();
|
|
|
|
|
|
|
|
FILE* outfile;
|
|
|
|
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( outfile == nullptr )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName );
|
2019-06-19 14:18:30 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string buffer;
|
2021-08-10 08:52:33 +00:00
|
|
|
ExportToBuffer( buffer, KICAD_WKS_LOGO );
|
2019-06-19 14:18:30 +00:00
|
|
|
fputs( buffer.c_str(), outfile );
|
|
|
|
fclose( outfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::exportPostScriptFormat()
|
|
|
|
{
|
|
|
|
wxFileName fn( m_ConvertedFileName );
|
|
|
|
wxString path = fn.GetPath();
|
|
|
|
|
|
|
|
if( path.IsEmpty() || !wxDirExists( path ) )
|
|
|
|
path = ::wxGetCwd();
|
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
wxFileDialog fileDlg( this, _( "Create PostScript File" ), path, wxEmptyString,
|
|
|
|
PSFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
if( fileDlg.ShowModal() != wxID_OK )
|
2019-06-19 14:18:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fn = fileDlg.GetPath();
|
|
|
|
fn.SetExt( wxT( "ps" ) );
|
|
|
|
m_ConvertedFileName = fn.GetFullPath();
|
|
|
|
|
|
|
|
FILE* outfile;
|
|
|
|
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( outfile == nullptr )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName );
|
2019-06-19 14:18:30 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string buffer;
|
|
|
|
ExportToBuffer( buffer, POSTSCRIPT_FMT );
|
|
|
|
fputs( buffer.c_str(), outfile );
|
|
|
|
fclose( outfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::exportEeschemaFormat()
|
|
|
|
{
|
|
|
|
wxFileName fn( m_ConvertedFileName );
|
|
|
|
wxString path = fn.GetPath();
|
|
|
|
|
|
|
|
if( path.IsEmpty() || !wxDirExists(path) )
|
|
|
|
path = ::wxGetCwd();
|
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
wxFileDialog fileDlg( this, _( "Create Symbol Library" ), path, wxEmptyString,
|
|
|
|
KiCadSymbolLibFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
if( fileDlg.ShowModal() != wxID_OK )
|
2019-06-19 14:18:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fn = fileDlg.GetPath();
|
2021-08-10 08:52:33 +00:00
|
|
|
fn.SetExt( KiCadSymbolLibFileExtension );
|
2019-06-19 14:18:30 +00:00
|
|
|
m_ConvertedFileName = fn.GetFullPath();
|
|
|
|
|
|
|
|
FILE* outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( outfile == nullptr )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName );
|
2019-06-19 14:18:30 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string buffer;
|
|
|
|
ExportToBuffer( buffer, EESCHEMA_FMT );
|
|
|
|
fputs( buffer.c_str(), outfile );
|
|
|
|
fclose( outfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::exportPcbnewFormat()
|
|
|
|
{
|
|
|
|
wxFileName fn( m_ConvertedFileName );
|
|
|
|
wxString path = fn.GetPath();
|
|
|
|
|
|
|
|
if( path.IsEmpty() || !wxDirExists( path ) )
|
|
|
|
path = m_mruPath;
|
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
wxFileDialog fileDlg( this, _( "Create Footprint Library" ), path, wxEmptyString,
|
|
|
|
KiCadFootprintLibFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
2022-10-16 16:45:10 +00:00
|
|
|
if( fileDlg.ShowModal() != wxID_OK )
|
2019-06-19 14:18:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fn = fileDlg.GetPath();
|
|
|
|
fn.SetExt( KiCadFootprintFileExtension );
|
|
|
|
m_ConvertedFileName = fn.GetFullPath();
|
|
|
|
|
|
|
|
FILE* outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( outfile == nullptr )
|
2019-06-19 14:18:30 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "File '%s' could not be created." ), m_ConvertedFileName );
|
2019-06-19 14:18:30 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string buffer;
|
|
|
|
ExportToBuffer( buffer, PCBNEW_KICAD_MOD );
|
|
|
|
fputs( buffer.c_str(), outfile );
|
|
|
|
fclose( outfile );
|
|
|
|
m_mruPath = fn.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat )
|
|
|
|
{
|
|
|
|
// Create a potrace bitmap
|
|
|
|
int h = m_NB_Image.GetHeight();
|
|
|
|
int w = m_NB_Image.GetWidth();
|
|
|
|
potrace_bitmap_t* potrace_bitmap = bm_new( w, h );
|
|
|
|
|
|
|
|
if( !potrace_bitmap )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error allocating memory for potrace bitmap" ) );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the bitmap with data */
|
|
|
|
for( int y = 0; y < h; y++ )
|
|
|
|
{
|
|
|
|
for( int x = 0; x < w; x++ )
|
|
|
|
{
|
2022-10-16 16:45:10 +00:00
|
|
|
unsigned char pix = m_NB_Image.GetGreen( x, y );
|
2019-06-19 14:18:30 +00:00
|
|
|
BM_PUT( potrace_bitmap, x, y, pix ? 0 : 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// choices of m_rbPCBLayer are expected to be in same order as
|
|
|
|
// BMP2CMP_MOD_LAYER. See bitmap2component.h
|
|
|
|
BMP2CMP_MOD_LAYER modLayer = MOD_LYR_FSILKS;
|
|
|
|
|
|
|
|
if( aFormat == PCBNEW_KICAD_MOD )
|
|
|
|
modLayer = (BMP2CMP_MOD_LAYER) m_rbPCBLayer->GetSelection();
|
|
|
|
|
|
|
|
BITMAPCONV_INFO converter( aOutput );
|
|
|
|
converter.ConvertBitmap( potrace_bitmap, aFormat, m_outputSizeX.GetOutputDPI(),
|
2021-07-16 20:13:26 +00:00
|
|
|
m_outputSizeY.GetOutputDPI(), modLayer );
|
2019-06-19 14:18:30 +00:00
|
|
|
|
|
|
|
if( !converter.GetErrorMessages().empty() )
|
|
|
|
wxMessageBox( converter.GetErrorMessages().c_str(), _( "Errors" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnFormatChange( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( m_rbOutputFormat->GetSelection() == PCBNEW_KICAD_MOD )
|
|
|
|
m_rbPCBLayer->Enable( true );
|
|
|
|
else
|
|
|
|
m_rbPCBLayer->Enable( false );
|
|
|
|
}
|