Update layer infrastructure in Image Converter.

(Also cleans up the interface a little.)
This commit is contained in:
Jeff Young 2025-01-18 12:01:28 +00:00
parent 3a3e2fe835
commit 24ec25a24c
11 changed files with 2614 additions and 2406 deletions

View File

@ -30,14 +30,13 @@
#include <bitmaps.h>
#include <common.h>
#include <id.h>
#include <kiface_base.h>
#include <pgm_base.h>
#include <widgets/wx_menubar.h>
#include <wildcards_and_files_ext.h>
#include <file_history.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
#include <tool/common_control.h>
#include <tool/action_manager.h>
#include <bitmap2cmp_control.h>
#include <tool/actions.h>
@ -333,8 +332,8 @@ void BITMAP2CMP_FRAME::ShowChangedLanguage()
mainSizer->Add( m_panel, 1, wxEXPAND, 5 );
Layout();
if( !m_bitmapFileName.IsEmpty() )
OpenProjectFiles( std::vector<wxString>( 1, m_bitmapFileName ) );
if( !m_srcFileName.IsEmpty() )
OpenProjectFiles( std::vector<wxString>( 1, m_srcFileName ) );
LoadSettings( config() );
m_panel->SetOutputSize( imageSizeX, imageSizeY );
@ -348,9 +347,9 @@ void BITMAP2CMP_FRAME::UpdateTitle()
{
wxString title;
if( !m_bitmapFileName.IsEmpty() )
if( !m_srcFileName.IsEmpty() )
{
wxFileName filename( m_bitmapFileName );
wxFileName filename( m_srcFileName );
title = filename.GetFullName() + wxT( " \u2014 " );
}
@ -364,12 +363,10 @@ void BITMAP2CMP_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
EDA_BASE_FRAME::LoadSettings( aCfg );
BITMAP2CMP_SETTINGS* cfg = dynamic_cast<BITMAP2CMP_SETTINGS*>( aCfg );
if( cfg )
if( BITMAP2CMP_SETTINGS* cfg = dynamic_cast<BITMAP2CMP_SETTINGS*>( aCfg ) )
{
m_bitmapFileName = cfg->m_BitmapFileName;
m_convertedFileName = cfg->m_ConvertedFileName;
m_srcFileName = cfg->m_BitmapFileName;
m_outFileName = cfg->m_ConvertedFileName;
m_panel->LoadSettings( cfg );
}
}
@ -379,12 +376,10 @@ void BITMAP2CMP_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{
EDA_BASE_FRAME::SaveSettings( aCfg );
BITMAP2CMP_SETTINGS* cfg = dynamic_cast<BITMAP2CMP_SETTINGS*>( aCfg );
if( cfg )
if( BITMAP2CMP_SETTINGS* cfg = dynamic_cast<BITMAP2CMP_SETTINGS*>( aCfg ) )
{
cfg->m_BitmapFileName = m_bitmapFileName;
cfg->m_ConvertedFileName = m_convertedFileName;
cfg->m_BitmapFileName = m_srcFileName;
cfg->m_ConvertedFileName = m_outFileName;
m_panel->SaveSettings( cfg );
}
}
@ -392,7 +387,7 @@ void BITMAP2CMP_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
void BITMAP2CMP_FRAME::OnLoadFile()
{
wxFileName fn( m_bitmapFileName );
wxFileName fn( m_srcFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists( path ) )
@ -402,9 +397,7 @@ void BITMAP2CMP_FRAME::OnLoadFile()
_( "Image Files" ) + wxS( " " )+ wxImage::GetImageExtWildcard(),
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
int diag = fileDlg.ShowModal();
if( diag != wxID_OK )
if( fileDlg.ShowModal() != wxID_OK )
return;
wxString fullFilename = fileDlg.GetPath();
@ -422,11 +415,11 @@ void BITMAP2CMP_FRAME::OnLoadFile()
bool BITMAP2CMP_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, int aCtl )
{
m_bitmapFileName = aFileSet[0];
m_srcFileName = aFileSet[0];
if( m_panel->OpenProjectFiles( aFileSet, aCtl ) )
{
UpdateFileHistory( m_bitmapFileName );
UpdateFileHistory( m_srcFileName );
return true;
}
@ -436,7 +429,7 @@ bool BITMAP2CMP_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet,
void BITMAP2CMP_FRAME::ExportDrawingSheetFormat()
{
wxFileName fn( m_convertedFileName );
wxFileName fn( m_outFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
@ -444,28 +437,24 @@ void BITMAP2CMP_FRAME::ExportDrawingSheetFormat()
wxFileDialog fileDlg( this, _( "Create Drawing Sheet File" ), path, wxEmptyString,
FILEEXT::DrawingSheetFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
int diag = fileDlg.ShowModal();
if( diag != wxID_OK )
if( fileDlg.ShowModal() != wxID_OK )
return;
fn = fileDlg.GetPath();
fn.SetExt( FILEEXT::DrawingSheetFileExtension );
m_convertedFileName = fn.GetFullPath();
m_outFileName = fn.GetFullPath();
FILE* outfile;
outfile = wxFopen( m_convertedFileName, wxT( "w" ) );
FILE* outfile = wxFopen( m_outFileName, wxT( "w" ) );
if( outfile == nullptr )
if( !outfile )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created." ), m_convertedFileName );
wxMessageBox( msg );
wxMessageBox( wxString::Format( _( "File '%s' could not be created." ), m_outFileName ) );
return;
}
std::string buffer;
m_panel->ExportToBuffer( buffer, KICAD_WKS_LOGO );
m_panel->ExportToBuffer( buffer, DRAWING_SHEET_FMT );
fputs( buffer.c_str(), outfile );
fclose( outfile );
}
@ -473,7 +462,7 @@ void BITMAP2CMP_FRAME::ExportDrawingSheetFormat()
void BITMAP2CMP_FRAME::ExportPostScriptFormat()
{
wxFileName fn( m_convertedFileName );
wxFileName fn( m_outFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists( path ) )
@ -487,16 +476,13 @@ void BITMAP2CMP_FRAME::ExportPostScriptFormat()
fn = fileDlg.GetPath();
fn.SetExt( wxT( "ps" ) );
m_convertedFileName = fn.GetFullPath();
m_outFileName = fn.GetFullPath();
FILE* outfile;
outfile = wxFopen( m_convertedFileName, wxT( "w" ) );
FILE* outfile = wxFopen( m_outFileName, wxT( "w" ) );
if( outfile == nullptr )
if( !outfile )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created." ), m_convertedFileName );
wxMessageBox( msg );
wxMessageBox( wxString::Format( _( "File '%s' could not be created." ), m_outFileName ) );
return;
}
@ -509,10 +495,10 @@ void BITMAP2CMP_FRAME::ExportPostScriptFormat()
void BITMAP2CMP_FRAME::ExportEeschemaFormat()
{
wxFileName fn( m_convertedFileName );
wxFileName fn( m_outFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
if( path.IsEmpty() || !wxDirExists( path ) )
path = ::wxGetCwd();
wxFileDialog fileDlg( this, _( "Create Symbol Library" ), path, wxEmptyString,
@ -523,20 +509,18 @@ void BITMAP2CMP_FRAME::ExportEeschemaFormat()
return;
fn = EnsureFileExtension( fileDlg.GetPath(), FILEEXT::KiCadSymbolLibFileExtension );
m_convertedFileName = fn.GetFullPath();
m_outFileName = fn.GetFullPath();
FILE* outfile = wxFopen( m_convertedFileName, wxT( "w" ) );
FILE* outfile = wxFopen( m_outFileName, wxT( "w" ) );
if( outfile == nullptr )
if( !outfile )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created." ), m_convertedFileName );
wxMessageBox( msg );
wxMessageBox( wxString::Format( _( "File '%s' could not be created." ), m_outFileName ) );
return;
}
std::string buffer;
m_panel->ExportToBuffer( buffer, EESCHEMA_FMT );
m_panel->ExportToBuffer( buffer, SYMBOL_FMT );
fputs( buffer.c_str(), outfile );
fclose( outfile );
}
@ -544,7 +528,7 @@ void BITMAP2CMP_FRAME::ExportEeschemaFormat()
void BITMAP2CMP_FRAME::ExportPcbnewFormat()
{
wxFileName fn( m_convertedFileName );
wxFileName fn( m_outFileName );
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists( path ) )
@ -558,20 +542,18 @@ void BITMAP2CMP_FRAME::ExportPcbnewFormat()
return;
fn = EnsureFileExtension( fileDlg.GetPath(), FILEEXT::KiCadFootprintFileExtension );
m_convertedFileName = fn.GetFullPath();
m_outFileName = fn.GetFullPath();
FILE* outfile = wxFopen( m_convertedFileName, wxT( "w" ) );
FILE* outfile = wxFopen( m_outFileName, wxT( "w" ) );
if( outfile == nullptr )
if( !outfile )
{
wxString msg;
msg.Printf( _( "File '%s' could not be created." ), m_convertedFileName );
wxMessageBox( msg );
wxMessageBox( wxString::Format( _( "File '%s' could not be created." ), m_outFileName ) );
return;
}
std::string buffer;
m_panel->ExportToBuffer( buffer, PCBNEW_KICAD_MOD );
m_panel->ExportToBuffer( buffer, FOOTPRINT_FMT );
fputs( buffer.c_str(), outfile );
fclose( outfile );
m_mruPath = fn.GetPath();

View File

@ -88,8 +88,8 @@ private:
BITMAP2CMP_PANEL* m_panel;
wxStatusBar* m_statusBar;
wxString m_bitmapFileName;
wxString m_convertedFileName;
wxString m_srcFileName;
wxString m_outFileName;
};
#endif// BITMOP2CMP_GUI_H_

View File

@ -27,11 +27,8 @@
#include <bitmap2cmp_panel.h>
#include <bitmap2cmp_settings.h>
#include <bitmap_io.h>
#include <bitmaps.h>
#include <common.h>
#include <kiface_base.h>
#include <math/util.h> // for KiROUND
#include <pgm_base.h>
#include <potracelib.h>
#include <wx/clipbrd.h>
#include <wx/rawbmp.h>
@ -44,10 +41,11 @@
BITMAP2CMP_PANEL::BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent ) :
BITMAP2CMP_PANEL_BASE( aParent ),
m_parentFrame( aParent ), m_negative( false ),
m_parentFrame( aParent ),
m_negative( false ),
m_aspectRatio( 1.0 )
{
for( wxString unit : { _( "mm" ), _( "Inch" ), _( "DPI" ) } )
for( const wxString& unit : { _( "mm" ), _( "Inch" ), _( "DPI" ) } )
m_PixelUnit->Append( unit );
m_outputSizeX.SetUnit( getUnitFromSelection() );
@ -55,19 +53,14 @@ BITMAP2CMP_PANEL::BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent ) :
m_outputSizeX.SetOutputSize( 0, getUnitFromSelection() );
m_outputSizeY.SetOutputSize( 0, getUnitFromSelection() );
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( formatOutputSize( m_outputSizeY.GetOutputSize() ) );
m_buttonExportFile->Enable( false );
m_buttonExportClipboard->Enable( false );
}
BITMAP2CMP_PANEL::~BITMAP2CMP_PANEL()
{
}
wxWindow* BITMAP2CMP_PANEL::GetCurrentPage()
{
return m_Notebook->GetCurrentPage();
@ -76,12 +69,8 @@ wxWindow* BITMAP2CMP_PANEL::GetCurrentPage()
void BITMAP2CMP_PANEL::LoadSettings( BITMAP2CMP_SETTINGS* cfg )
{
int u_select = cfg->m_Units;
if( u_select < 0 || u_select > 2 ) // Validity control
u_select = 0;
m_PixelUnit->SetSelection( u_select );
if( cfg->m_Units >= 0 && cfg->m_Units < (int) m_PixelUnit->GetCount() )
m_PixelUnit->SetSelection( cfg->m_Units );
m_sliderThreshold->SetValue( cfg->m_Threshold );
@ -91,32 +80,30 @@ void BITMAP2CMP_PANEL::LoadSettings( BITMAP2CMP_SETTINGS* cfg )
m_aspectRatio = 1.0;
m_aspectRatioCheckbox->SetValue( true );
int format = cfg->m_LastFormat;
switch( cfg->m_LastFormat )
{
default:
case FOOTPRINT_FMT: m_rbFootprint->SetValue( true ); break;
case SYMBOL_FMT: m_rbSymbol->SetValue( true ); break;
case POSTSCRIPT_FMT: m_rbPostscript->SetValue( true ); break;
case DRAWING_SHEET_FMT: m_rbWorksheet->SetValue( true ); break;
}
if( format < 0 || format > FINAL_FMT )
format = PCBNEW_KICAD_MOD;
m_layerLabel->Enable( cfg->m_LastFormat == FOOTPRINT_FMT );
m_layerCtrl->Enable( cfg->m_LastFormat == FOOTPRINT_FMT );
m_rbOutputFormat->SetSelection( format );
bool enable = format == PCBNEW_KICAD_MOD;
m_chPCBLayer->Enable( enable );
int last_layer = cfg->m_LastModLayer;
if( last_layer < 0 || last_layer > static_cast<int>( MOD_LYR_FINAL ) ) // Out of range
last_layer = MOD_LYR_FSILKS;
m_chPCBLayer->SetSelection( last_layer );
if( cfg->m_LastLayer >= 0 && cfg->m_LastLayer < (int) m_layerCtrl->GetCount() )
m_layerCtrl->SetSelection( cfg->m_LastLayer );
}
void BITMAP2CMP_PANEL::SaveSettings( BITMAP2CMP_SETTINGS* cfg )
{
cfg->m_Threshold = m_sliderThreshold->GetValue();
cfg->m_Negative = m_checkNegative->IsChecked();
cfg->m_LastFormat = m_rbOutputFormat->GetSelection();
cfg->m_LastModLayer = m_chPCBLayer->GetSelection();
cfg->m_Units = m_PixelUnit->GetSelection();
cfg->m_Threshold = m_sliderThreshold->GetValue();
cfg->m_Negative = m_checkNegative->IsChecked();
cfg->m_LastFormat = getOutputFormat();
cfg->m_LastLayer = m_layerCtrl->GetSelection();
cfg->m_Units = m_PixelUnit->GetSelection();
}
@ -244,9 +231,9 @@ bool BITMAP2CMP_PANEL::OpenProjectFiles( const std::vector<wxString>& aFileSet,
{
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() )
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 );
}
@ -255,26 +242,26 @@ bool BITMAP2CMP_PANEL::OpenProjectFiles( const std::vector<wxString>& aFileSet,
}
if( m_negative )
NegateGreyscaleImage( );
negateGreyscaleImage();
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
m_NB_Image = m_Greyscale_Image;
Binarize( (double) m_sliderThreshold->GetValue() / m_sliderThreshold->GetMax() );
binarize( (double)m_sliderThreshold->GetValue() / m_sliderThreshold->GetMax() );
m_buttonExportFile->Enable( true );
m_buttonExportClipboard->Enable( true );
m_outputSizeX.SetOutputSizeFromInitialImageSize();
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_outputSizeY.SetOutputSizeFromInitialImageSize();
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( formatOutputSize( m_outputSizeY.GetOutputSize() ) );
return true;
}
// return a string giving the output size, according to the selected unit
wxString BITMAP2CMP_PANEL::FormatOutputSize( double aSize )
wxString BITMAP2CMP_PANEL::formatOutputSize( double aSize )
{
wxString text;
@ -295,13 +282,9 @@ void BITMAP2CMP_PANEL::updateImageInfo()
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 ) );
m_SizeXValue->SetLabel( wxString::Format( wxT( "%d" ), m_Pict_Bitmap.GetWidth() ) );
m_SizeYValue->SetLabel( wxString::Format( wxT( "%d" ), m_Pict_Bitmap.GetHeight() ) );
m_BPPValue->SetLabel( wxString::Format( wxT( "%d" ), m_Pict_Bitmap.GetDepth() ) );
}
}
@ -338,7 +321,7 @@ void BITMAP2CMP_PANEL::OnSizeChangeX( wxCommandEvent& event )
}
m_outputSizeY.SetOutputSize( calculatedY, getUnitFromSelection() );
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( formatOutputSize( m_outputSizeY.GetOutputSize() ) );
}
m_outputSizeX.SetOutputSize( new_size, getUnitFromSelection() );
@ -367,7 +350,7 @@ void BITMAP2CMP_PANEL::OnSizeChangeY( wxCommandEvent& event )
}
m_outputSizeX.SetOutputSize( calculatedX, getUnitFromSelection() );
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
}
m_outputSizeY.SetOutputSize( new_size, getUnitFromSelection() );
@ -383,8 +366,8 @@ void BITMAP2CMP_PANEL::OnSizeUnitChange( wxCommandEvent& event )
m_outputSizeY.SetUnit( getUnitFromSelection() );
updateImageInfo();
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( formatOutputSize( m_outputSizeY.GetOutputSize() ) );
}
@ -394,8 +377,8 @@ void BITMAP2CMP_PANEL::SetOutputSize( const IMAGE_SIZE& aSizeX, const IMAGE_SIZE
m_outputSizeY = aSizeY;
updateImageInfo();
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( formatOutputSize( m_outputSizeY.GetOutputSize() ) );
}
@ -410,28 +393,25 @@ void BITMAP2CMP_PANEL::ToggleAspectRatioLock( wxCommandEvent& event )
}
void BITMAP2CMP_PANEL::Binarize( double aThreshold )
void BITMAP2CMP_PANEL::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++ )
for( int y = 0; y < m_Greyscale_Image.GetHeight(); y++ )
{
for( int x = 0; x < w; x++ )
for( int x = 0; x < m_Greyscale_Image.GetWidth(); x++ )
{
unsigned char pixout;
unsigned char pixin = m_Greyscale_Image.GetGreen( x, y );
unsigned char pixel = m_Greyscale_Image.GetGreen( x, y );
unsigned char alpha = m_Greyscale_Image.HasAlpha() ? m_Greyscale_Image.GetAlpha( x, y )
: wxALPHA_OPAQUE;
if( pixin < threshold && alpha > alpha_thresh )
pixout = 0;
if( pixel < threshold && alpha > alpha_thresh )
pixel = 0;
else
pixout = 255;
pixel = 255;
m_NB_Image.SetRGB( x, y, pixout, pixout, pixout );
m_NB_Image.SetRGB( x, y, pixel, pixel, pixel );
}
}
@ -439,19 +419,15 @@ void BITMAP2CMP_PANEL::Binarize( double aThreshold )
}
void BITMAP2CMP_PANEL::NegateGreyscaleImage( )
void BITMAP2CMP_PANEL::negateGreyscaleImage( )
{
unsigned char pix;
int h = m_Greyscale_Image.GetHeight();
int w = m_Greyscale_Image.GetWidth();
for( int y = 0; y < h; y++ )
for( int y = 0; y < m_Greyscale_Image.GetHeight(); y++ )
{
for( int x = 0; x < w; x++ )
for( int x = 0; x < m_Greyscale_Image.GetWidth(); x++ )
{
pix = m_Greyscale_Image.GetGreen( x, y );
pix = ~pix;
m_Greyscale_Image.SetRGB( x, y, pix, pix, pix );
unsigned char pixel = m_Greyscale_Image.GetGreen( x, y );
pixel = ~pixel;
m_Greyscale_Image.SetRGB( x, y, pixel, pixel, pixel );
}
}
}
@ -461,10 +437,10 @@ void BITMAP2CMP_PANEL::OnNegativeClicked( wxCommandEvent& )
{
if( m_checkNegative->GetValue() != m_negative )
{
NegateGreyscaleImage();
negateGreyscaleImage();
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
binarize( (double)m_sliderThreshold->GetValue() / m_sliderThreshold->GetMax() );
m_negative = m_checkNegative->GetValue();
Refresh();
@ -474,28 +450,40 @@ void BITMAP2CMP_PANEL::OnNegativeClicked( wxCommandEvent& )
void BITMAP2CMP_PANEL::OnThresholdChange( wxScrollEvent& event )
{
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
binarize( (double)m_sliderThreshold->GetValue() / m_sliderThreshold->GetMax() );
Refresh();
}
void BITMAP2CMP_PANEL::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 );
switch( getOutputFormat() )
{
case SYMBOL_FMT: m_parentFrame->ExportEeschemaFormat(); break;
case FOOTPRINT_FMT: m_parentFrame->ExportPcbnewFormat(); break;
case POSTSCRIPT_FMT: m_parentFrame->ExportPostScriptFormat(); break;
case DRAWING_SHEET_FMT: m_parentFrame->ExportDrawingSheetFormat(); break;
}
}
OUTPUT_FMT_ID BITMAP2CMP_PANEL::getOutputFormat()
{
if( m_rbSymbol->GetValue() )
return SYMBOL_FMT;
else if( m_rbPostscript->GetValue() )
return POSTSCRIPT_FMT;
else if( m_rbWorksheet->GetValue() )
return DRAWING_SHEET_FMT;
else
return FOOTPRINT_FMT;
}
void BITMAP2CMP_PANEL::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 );
ExportToBuffer( buffer, getOutputFormat() );
wxLogNull doNotLog; // disable logging of failed clipboard actions
@ -515,61 +503,57 @@ void BITMAP2CMP_PANEL::OnExportToClipboard( wxCommandEvent& event )
}
void BITMAP2CMP_PANEL::exportBitmap( OUTPUT_FMT_ID aFormat )
{
switch( aFormat )
{
case EESCHEMA_FMT: m_parentFrame->ExportEeschemaFormat(); break;
case PCBNEW_KICAD_MOD: m_parentFrame->ExportPcbnewFormat(); break;
case POSTSCRIPT_FMT: m_parentFrame->ExportPostScriptFormat(); break;
case KICAD_WKS_LOGO: m_parentFrame->ExportDrawingSheetFormat(); break;
}
}
void BITMAP2CMP_PANEL::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 );
potrace_bitmap_t* potrace_bitmap = bm_new( m_NB_Image.GetWidth(), m_NB_Image.GetHeight() );
if( !potrace_bitmap )
{
wxString msg;
msg.Printf( _( "Error allocating memory for potrace bitmap" ) );
wxMessageBox( msg );
wxMessageBox( _( "Error allocating memory for potrace bitmap" ) );
return;
}
/* fill the bitmap with data */
for( int y = 0; y < h; y++ )
for( int y = 0; y < m_NB_Image.GetHeight(); y++ )
{
for( int x = 0; x < w; x++ )
for( int x = 0; x < m_NB_Image.GetWidth(); x++ )
{
unsigned char pix = m_NB_Image.GetGreen( x, y );
BM_PUT( potrace_bitmap, x, y, pix ? 0 : 1 );
unsigned char pixel = m_NB_Image.GetGreen( x, y );
BM_PUT( potrace_bitmap, x, y, pixel ? 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;
wxString layer = wxT( "F.SilkS" );
if( aFormat == PCBNEW_KICAD_MOD )
modLayer = (BMP2CMP_MOD_LAYER) m_chPCBLayer->GetSelection();
if( aFormat == FOOTPRINT_FMT )
{
switch( m_layerCtrl->GetSelection() )
{
case 0: layer = wxT( "F.Cu" ); break;
case 1: layer = wxT( "F.SilkS" ); break;
case 2: layer = wxT( "F.Mask" ); break;
case 3: layer = wxT( "Dwgs.User" ); break;
case 4: layer = wxT( "Cmts.User" ); break;
case 5: layer = wxT( "Eco1.User" ); break;
case 6: layer = wxT( "Eco2.User" ); break;
case 7: layer = wxT( "F.Fab" ); break;
}
}
WX_STRING_REPORTER reporter;
BITMAPCONV_INFO converter( aOutput, reporter );
BITMAPCONV_INFO converter( aOutput );
converter.ConvertBitmap( potrace_bitmap, aFormat, m_outputSizeX.GetOutputDPI(),
m_outputSizeY.GetOutputDPI(), modLayer );
m_outputSizeY.GetOutputDPI(), layer );
if( !converter.GetErrorMessages().empty() )
wxMessageBox( converter.GetErrorMessages().c_str(), _( "Errors" ) );
if( reporter.HasMessage() )
wxMessageBox( reporter.GetMessages(), _( "Errors" ) );
}
void BITMAP2CMP_PANEL::OnFormatChange( wxCommandEvent& event )
{
bool enable = m_rbOutputFormat->GetSelection() == PCBNEW_KICAD_MOD;
m_chPCBLayer->Enable( enable );
m_layerLabel->Enable( m_rbFootprint->GetValue() );
m_layerCtrl->Enable( m_rbFootprint->GetValue() );
}

View File

@ -40,32 +40,13 @@ public:
// to the value in new unit
void SetUnit( EDA_UNITS aUnit );
// Accessors:
void SetOriginalDPI( int aDPI )
{
m_originalDPI = aDPI;
}
void SetOriginalDPI( int aDPI ) { m_originalDPI = aDPI; }
void SetOriginalSizePixels( int aPixels )
{
m_originalSizePixels = aPixels;
}
void SetOriginalSizePixels( int aPixels ) { m_originalSizePixels = aPixels; }
int GetOriginalSizePixels() { return m_originalSizePixels; }
double GetOutputSize()
{
return m_outputSize;
}
void SetOutputSize( double aSize, EDA_UNITS aUnit )
{
m_unit = aUnit;
m_outputSize = aSize;
}
int GetOriginalSizePixels()
{
return m_originalSizePixels;
}
double GetOutputSize() { return m_outputSize; }
void SetOutputSize( double aSize, EDA_UNITS aUnit ) { m_outputSize = aSize; m_unit = aUnit; }
// Set the m_outputSize value from the m_originalSizePixels and the selected unit
void SetOutputSizeFromInitialImageSize();
@ -88,7 +69,7 @@ class BITMAP2CMP_PANEL : public BITMAP2CMP_PANEL_BASE
{
public:
BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent );
~BITMAP2CMP_PANEL();
~BITMAP2CMP_PANEL() {}
bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl = 0 );
@ -117,28 +98,27 @@ private:
void OnPaintBW( wxPaintEvent& event ) override;
void OnExportToFile( wxCommandEvent& event ) override;
void OnExportToClipboard( wxCommandEvent& event ) override;
void OnFormatChange( wxCommandEvent& event ) override;
void OnNegativeClicked( wxCommandEvent& event ) override;
void OnThresholdChange( wxScrollEvent& event ) override;
void OnSizeChangeX( wxCommandEvent& event ) override;
void OnSizeChangeY( wxCommandEvent& event ) override;
void OnSizeUnitChange( wxCommandEvent& event ) override;
void ToggleAspectRatioLock( wxCommandEvent& event ) override;
OUTPUT_FMT_ID getOutputFormat();
///< @return the EDA_UNITS from the m_PixelUnit choice
EDA_UNITS getUnitFromSelection();
// return a string giving the output size, according to the selected unit
wxString FormatOutputSize( double aSize );
wxString formatOutputSize( double aSize );
void Binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
void OnNegativeClicked( wxCommandEvent& event ) override;
void OnThresholdChange( wxScrollEvent& event ) override;
void binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
void OnSizeChangeX( wxCommandEvent& event ) override;
void OnSizeChangeY( wxCommandEvent& event ) override;
void OnSizeUnitChange( wxCommandEvent& event ) override;
void ToggleAspectRatioLock( wxCommandEvent& event ) override;
void NegateGreyscaleImage();
void negateGreyscaleImage();
void updateImageInfo();
void OnFormatChange( wxCommandEvent& event ) override;
void exportBitmap( OUTPUT_FMT_ID aFormat );
private:
BITMAP2CMP_FRAME* m_parentFrame;

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -27,7 +27,7 @@ BITMAP2CMP_PANEL_BASE::BITMAP2CMP_PANEL_BASE( wxWindow* parent, wxWindowID id, c
m_BNPicturePanel->SetScrollRate( 5, 5 );
m_Notebook->AddPage( m_BNPicturePanel, _("Black && White Picture"), true );
bMainSizer->Add( m_Notebook, 1, wxEXPAND|wxBOTTOM|wxLEFT, 5 );
bMainSizer->Add( m_Notebook, 1, wxEXPAND|wxBOTTOM|wxLEFT, 10 );
wxBoxSizer* brightSizer;
brightSizer = new wxBoxSizer( wxVERTICAL );
@ -96,7 +96,7 @@ BITMAP2CMP_PANEL_BASE::BITMAP2CMP_PANEL_BASE( wxWindow* parent, wxWindowID id, c
brightSizer->Add( sbSizerInfo, 0, wxEXPAND|wxALL, 5 );
m_buttonLoad = new wxButton( this, wxID_ANY, _("Load Source Image"), wxDefaultPosition, wxDefaultSize, 0 );
brightSizer->Add( m_buttonLoad, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
brightSizer->Add( m_buttonLoad, 0, wxEXPAND|wxALL, 5 );
brightSizer->Add( 0, 0, 1, wxEXPAND, 5 );
@ -104,35 +104,35 @@ BITMAP2CMP_PANEL_BASE::BITMAP2CMP_PANEL_BASE( wxWindow* parent, wxWindowID id, c
wxStaticBoxSizer* sbSizerImgPrms;
sbSizerImgPrms = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Output Size") ), wxVERTICAL );
m_aspectRatioCheckbox = new wxCheckBox( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("Lock height / width ratio"), wxDefaultPosition, wxDefaultSize, 0 );
sbSizerImgPrms->Add( m_aspectRatioCheckbox, 0, wxBOTTOM, 5 );
wxBoxSizer* bSizerRes;
bSizerRes = new wxBoxSizer( wxHORIZONTAL );
m_staticTextOSize = new wxStaticText( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextOSize->Wrap( -1 );
bSizerRes->Add( m_staticTextOSize, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT|wxTOP, 5 );
m_sizeLabel = new wxStaticText( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_sizeLabel->Wrap( -1 );
bSizerRes->Add( m_sizeLabel, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
m_UnitSizeX = new wxTextCtrl( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("300"), wxDefaultPosition, wxDefaultSize, 0 );
m_UnitSizeX->SetMinSize( wxSize( 60,-1 ) );
bSizerRes->Add( m_UnitSizeX, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
bSizerRes->Add( m_UnitSizeX, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
m_UnitSizeY = new wxTextCtrl( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("300"), wxDefaultPosition, wxDefaultSize, 0 );
m_UnitSizeY->SetMinSize( wxSize( 60,-1 ) );
bSizerRes->Add( m_UnitSizeY, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 );
bSizerRes->Add( m_UnitSizeY, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
wxArrayString m_PixelUnitChoices;
m_PixelUnit = new wxChoice( sbSizerImgPrms->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_PixelUnitChoices, 0 );
m_PixelUnit->SetSelection( 0 );
m_PixelUnit->SetMinSize( wxSize( 80,-1 ) );
bSizerRes->Add( m_PixelUnit, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxTOP, 5 );
bSizerRes->Add( m_PixelUnit, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 );
sbSizerImgPrms->Add( bSizerRes, 0, wxEXPAND, 5 );
sbSizerImgPrms->Add( bSizerRes, 0, wxEXPAND|wxBOTTOM, 5 );
m_aspectRatioCheckbox = new wxCheckBox( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("Lock height / width ratio"), wxDefaultPosition, wxDefaultSize, 0 );
sbSizerImgPrms->Add( m_aspectRatioCheckbox, 0, wxALL, 5 );
brightSizer->Add( sbSizerImgPrms, 0, wxALL|wxEXPAND, 5 );
@ -142,7 +142,7 @@ BITMAP2CMP_PANEL_BASE::BITMAP2CMP_PANEL_BASE( wxWindow* parent, wxWindowID id, c
m_ThresholdText = new wxStaticText( sbSizer2->GetStaticBox(), wxID_ANY, _("Black / white threshold:"), wxDefaultPosition, wxDefaultSize, 0 );
m_ThresholdText->Wrap( -1 );
sbSizer2->Add( m_ThresholdText, 0, wxLEFT, 5 );
sbSizer2->Add( m_ThresholdText, 0, wxRIGHT|wxLEFT, 5 );
m_sliderThreshold = new wxSlider( sbSizer2->GetStaticBox(), wxID_ANY, 50, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS );
m_sliderThreshold->SetToolTip( _("Adjust the level to convert the greyscale picture to a black and white picture.") );
@ -150,29 +150,54 @@ BITMAP2CMP_PANEL_BASE::BITMAP2CMP_PANEL_BASE( wxWindow* parent, wxWindowID id, c
sbSizer2->Add( m_sliderThreshold, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 );
m_checkNegative = new wxCheckBox( sbSizer2->GetStaticBox(), wxID_ANY, _("Negative"), wxDefaultPosition, wxDefaultSize, 0 );
sbSizer2->Add( m_checkNegative, 0, wxBOTTOM, 5 );
sbSizer2->Add( m_checkNegative, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
brightSizer->Add( sbSizer2, 0, wxALL|wxEXPAND, 5 );
m_sizerPcbLayer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Pcb Layer for Graphics") ), wxVERTICAL );
wxStaticBoxSizer* sbOutputFormat;
sbOutputFormat = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Output Format") ), wxVERTICAL );
wxString m_chPCBLayerChoices[] = { _("Front silk screen"), _("Front solder mask"), _("Front Fab layer"), _("User layer drawings"), _("User layer comments"), _("User layer Eco1"), _("User layer Eco2") };
int m_chPCBLayerNChoices = sizeof( m_chPCBLayerChoices ) / sizeof( wxString );
m_chPCBLayer = new wxChoice( m_sizerPcbLayer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_chPCBLayerNChoices, m_chPCBLayerChoices, 0 );
m_chPCBLayer->SetSelection( 0 );
m_sizerPcbLayer->Add( m_chPCBLayer, 0, wxALL|wxEXPAND, 5 );
wxFlexGridSizer* fgSizer2;
fgSizer2 = new wxFlexGridSizer( 5, 1, 2, 0 );
fgSizer2->SetFlexibleDirection( wxBOTH );
fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_rbSymbol = new wxRadioButton( sbOutputFormat->GetStaticBox(), wxID_ANY, _("Symbol (.kicad_sym file)"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_rbSymbol, 0, wxBOTTOM|wxRIGHT, 5 );
m_rbFootprint = new wxRadioButton( sbOutputFormat->GetStaticBox(), wxID_ANY, _("Footprint (.kicad_mod file)"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_rbFootprint, 0, wxTOP|wxRIGHT, 5 );
wxBoxSizer* bSizer4;
bSizer4 = new wxBoxSizer( wxHORIZONTAL );
m_layerLabel = new wxStaticText( sbOutputFormat->GetStaticBox(), wxID_ANY, _("Layer:"), wxDefaultPosition, wxDefaultSize, 0 );
m_layerLabel->Wrap( -1 );
bSizer4->Add( m_layerLabel, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 28 );
wxString m_layerCtrlChoices[] = { _("F.Cu"), _("F.Silkscreen"), _("F.Mask"), _("User.Drawings"), _("User.Comments"), _("User.Eco1"), _("User.Eco2"), _("F.Fab") };
int m_layerCtrlNChoices = sizeof( m_layerCtrlChoices ) / sizeof( wxString );
m_layerCtrl = new wxChoice( sbOutputFormat->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_layerCtrlNChoices, m_layerCtrlChoices, 0 );
m_layerCtrl->SetSelection( 0 );
bSizer4->Add( m_layerCtrl, 1, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 );
brightSizer->Add( m_sizerPcbLayer, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 );
fgSizer2->Add( bSizer4, 1, wxEXPAND, 5 );
wxString m_rbOutputFormatChoices[] = { _("Symbol (.kicad_sym file)"), _("Footprint (.kicad_mod file)"), _("Postscript (.ps file)"), _("Drawing Sheet (.kicad_wks file)") };
int m_rbOutputFormatNChoices = sizeof( m_rbOutputFormatChoices ) / sizeof( wxString );
m_rbOutputFormat = new wxRadioBox( this, wxID_ANY, _("Output Format"), wxDefaultPosition, wxDefaultSize, m_rbOutputFormatNChoices, m_rbOutputFormatChoices, 1, wxRA_SPECIFY_COLS );
m_rbOutputFormat->SetSelection( 0 );
brightSizer->Add( m_rbOutputFormat, 0, wxEXPAND|wxALL, 5 );
m_rbPostscript = new wxRadioButton( sbOutputFormat->GetStaticBox(), wxID_ANY, _("Postscript (.ps file)"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_rbPostscript, 0, wxTOP|wxBOTTOM|wxRIGHT, 5 );
m_buttonExportFile = new wxButton( this, wxID_ANY, _("Export to File"), wxDefaultPosition, wxDefaultSize, 0 );
m_rbWorksheet = new wxRadioButton( sbOutputFormat->GetStaticBox(), wxID_ANY, _("Drawing Sheet (.kicad_wks file)"), wxDefaultPosition, wxDefaultSize, 0 );
fgSizer2->Add( m_rbWorksheet, 0, wxTOP|wxRIGHT, 5 );
sbOutputFormat->Add( fgSizer2, 1, wxEXPAND|wxRIGHT|wxLEFT, 5 );
brightSizer->Add( sbOutputFormat, 1, wxEXPAND|wxALL, 5 );
m_buttonExportFile = new wxButton( this, wxID_ANY, _("Export to File..."), wxDefaultPosition, wxDefaultSize, 0 );
brightSizer->Add( m_buttonExportFile, 0, wxEXPAND|wxALL, 5 );
m_buttonExportClipboard = new wxButton( this, wxID_ANY, _("Export to Clipboard"), wxDefaultPosition, wxDefaultSize, 0 );
@ -191,14 +216,17 @@ BITMAP2CMP_PANEL_BASE::BITMAP2CMP_PANEL_BASE( wxWindow* parent, wxWindowID id, c
m_GreyscalePicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintGreyscale ), NULL, this );
m_BNPicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintBW ), NULL, this );
m_buttonLoad->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnLoadFile ), NULL, this );
m_aspectRatioCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::ToggleAspectRatioLock ), NULL, this );
m_UnitSizeX->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnSizeChangeX ), NULL, this );
m_UnitSizeY->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnSizeChangeY ), NULL, this );
m_PixelUnit->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnSizeUnitChange ), NULL, this );
m_aspectRatioCheckbox->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::ToggleAspectRatioLock ), NULL, this );
m_sliderThreshold->Connect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( BITMAP2CMP_PANEL_BASE::OnThresholdChange ), NULL, this );
m_sliderThreshold->Connect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( BITMAP2CMP_PANEL_BASE::OnThresholdChange ), NULL, this );
m_checkNegative->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnNegativeClicked ), NULL, this );
m_rbOutputFormat->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbSymbol->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbFootprint->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbPostscript->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbWorksheet->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_buttonExportFile->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnExportToFile ), NULL, this );
m_buttonExportClipboard->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnExportToClipboard ), NULL, this );
}
@ -210,14 +238,17 @@ BITMAP2CMP_PANEL_BASE::~BITMAP2CMP_PANEL_BASE()
m_GreyscalePicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintGreyscale ), NULL, this );
m_BNPicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintBW ), NULL, this );
m_buttonLoad->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnLoadFile ), NULL, this );
m_aspectRatioCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::ToggleAspectRatioLock ), NULL, this );
m_UnitSizeX->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnSizeChangeX ), NULL, this );
m_UnitSizeY->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnSizeChangeY ), NULL, this );
m_PixelUnit->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnSizeUnitChange ), NULL, this );
m_aspectRatioCheckbox->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::ToggleAspectRatioLock ), NULL, this );
m_sliderThreshold->Disconnect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( BITMAP2CMP_PANEL_BASE::OnThresholdChange ), NULL, this );
m_sliderThreshold->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( BITMAP2CMP_PANEL_BASE::OnThresholdChange ), NULL, this );
m_checkNegative->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnNegativeClicked ), NULL, this );
m_rbOutputFormat->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbSymbol->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbFootprint->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbPostscript->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_rbWorksheet->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnFormatChange ), NULL, this );
m_buttonExportFile->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnExportToFile ), NULL, this );
m_buttonExportClipboard->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BITMAP2CMP_PANEL_BASE::OnExportToClipboard ), NULL, this );

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b)
// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
@ -24,23 +24,23 @@
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/textctrl.h>
#include <wx/valtext.h>
#include <wx/choice.h>
#include <wx/checkbox.h>
#include <wx/slider.h>
#include <wx/radiobox.h>
#include <wx/radiobut.h>
#include <wx/panel.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class BITMAP2CMP_PANEL_BASE
///////////////////////////////////////////////////////////////////////////////
class BITMAP2CMP_PANEL_BASE : public wxPanel
{
private:
wxStaticText* m_sizeLabel;
protected:
wxNotebook* m_Notebook;
@ -59,17 +59,19 @@ class BITMAP2CMP_PANEL_BASE : public wxPanel
wxStaticText* m_BPPValue;
wxStaticText* m_BPPunits;
wxButton* m_buttonLoad;
wxCheckBox* m_aspectRatioCheckbox;
wxStaticText* m_staticTextOSize;
wxTextCtrl* m_UnitSizeX;
wxTextCtrl* m_UnitSizeY;
wxChoice* m_PixelUnit;
wxCheckBox* m_aspectRatioCheckbox;
wxStaticText* m_ThresholdText;
wxSlider* m_sliderThreshold;
wxCheckBox* m_checkNegative;
wxStaticBoxSizer* m_sizerPcbLayer;
wxChoice* m_chPCBLayer;
wxRadioBox* m_rbOutputFormat;
wxRadioButton* m_rbSymbol;
wxRadioButton* m_rbFootprint;
wxStaticText* m_layerLabel;
wxChoice* m_layerCtrl;
wxRadioButton* m_rbPostscript;
wxRadioButton* m_rbWorksheet;
wxButton* m_buttonExportFile;
wxButton* m_buttonExportClipboard;
@ -78,10 +80,10 @@ class BITMAP2CMP_PANEL_BASE : public wxPanel
virtual void OnPaintGreyscale( wxPaintEvent& event ) { event.Skip(); }
virtual void OnPaintBW( wxPaintEvent& event ) { event.Skip(); }
virtual void OnLoadFile( wxCommandEvent& event ) { event.Skip(); }
virtual void ToggleAspectRatioLock( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSizeChangeX( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSizeChangeY( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSizeUnitChange( wxCommandEvent& event ) { event.Skip(); }
virtual void ToggleAspectRatioLock( wxCommandEvent& event ) { event.Skip(); }
virtual void OnThresholdChange( wxScrollEvent& event ) { event.Skip(); }
virtual void OnNegativeClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnFormatChange( wxCommandEvent& event ) { event.Skip(); }

View File

@ -27,28 +27,45 @@
///! Update the schema version whenever a migration is required
const int bitmap2cmpSchemaVersion = 0;
const int bitmap2cmpSchemaVersion = 1;
BITMAP2CMP_SETTINGS::BITMAP2CMP_SETTINGS() :
APP_SETTINGS_BASE( "bitmap2component", bitmap2cmpSchemaVersion ),
m_BitmapFileName(), m_ConvertedFileName(), m_Units(), m_Threshold(), m_Negative(),
m_LastFormat(), m_LastModLayer()
m_BitmapFileName(),
m_ConvertedFileName(),
m_Units(),
m_Threshold(),
m_Negative(),
m_LastFormat(),
m_LastLayer()
{
m_params.emplace_back( new PARAM<wxString>( "bitmap_file_name", &m_BitmapFileName, "" ) );
m_params.emplace_back(
new PARAM<wxString>( "converted_file_name", &m_ConvertedFileName, "" ) );
m_params.emplace_back( new PARAM<wxString>( "converted_file_name", &m_ConvertedFileName, "" ) );
m_params.emplace_back( new PARAM<int>( "units", &m_Units, 0 ) );
m_params.emplace_back( new PARAM<int>( "threshold", &m_Threshold, 50 ) );
m_params.emplace_back( new PARAM<bool>( "negative", &m_Negative, false ) );
m_params.emplace_back( new PARAM<int>( "last_format", &m_LastFormat, 0 ) );
m_params.emplace_back( new PARAM<int>( "last_mod_layer", &m_LastLayer, 0 ) );
m_params.emplace_back( new PARAM<int>( "last_mod_layer", &m_LastModLayer, 0 ) );
registerMigration( 0, 1,
[&]() -> bool
{
// Version 1 introduced a new layer (F.Cu), and changed the ordering to
// be consistent with PCBNew.
switch( Get<int>( "last_mod_layer" ).value_or( 0 ) )
{
default:
case 0: Set( "last_mod_layer", 1 ); break;
case 1: Set( "last_mod_layer", 2 ); break;
case 2: Set( "last_mod_layer", 7 ); break;
case 3: Set( "last_mod_layer", 3 ); break;
case 4: Set( "last_mod_layer", 4 ); break;
case 5: Set( "last_mod_layer", 5 ); break;
case 6: Set( "last_mod_layer", 6 ); break;
}
return true;
} );
}

View File

@ -35,22 +35,16 @@ public:
virtual bool MigrateFromLegacy( wxConfigBase* aLegacyConfig ) override;
public:
wxString m_BitmapFileName;
wxString m_ConvertedFileName;
int m_Units;
int m_Threshold;
bool m_Negative;
int m_LastFormat;
int m_LastModLayer;
int m_Units;
int m_Threshold;
bool m_Negative;
int m_LastFormat;
int m_LastLayer;
protected:
virtual std::string getLegacyFrameName() const override { return "Bmconverter_"; }
};

View File

@ -33,12 +33,11 @@
#include <kiid.h>
#include <build_version.h>
#include <layer_ids.h>
#include <locale_io.h>
#include <potracelib.h>
#include <reporter.h>
#include <fmt/format.h>
#include <wx/translation.h>
#include "bitmap2component.h"
@ -46,23 +45,21 @@
/* free a potrace bitmap */
static void bm_free( potrace_bitmap_t* bm )
{
if( bm != nullptr )
{
if( bm )
free( bm->map );
}
free( bm );
}
static void BezierToPolyline( std::vector <potrace_dpoint_t>& aCornersBuffer,
potrace_dpoint_t p1,
potrace_dpoint_t p2,
potrace_dpoint_t p3,
potrace_dpoint_t p4 );
potrace_dpoint_t p1, potrace_dpoint_t p2,
potrace_dpoint_t p3, potrace_dpoint_t p4 );
BITMAPCONV_INFO::BITMAPCONV_INFO( std::string& aData ):
m_Data( aData )
BITMAPCONV_INFO::BITMAPCONV_INFO( std::string& aData, REPORTER& aReporter ):
m_Data( aData ),
m_reporter( aReporter )
{
m_Format = POSTSCRIPT_FMT;
m_PixmapWidth = 0;
@ -75,7 +72,7 @@ BITMAPCONV_INFO::BITMAPCONV_INFO( std::string& aData ):
int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, OUTPUT_FMT_ID aFormat,
int aDpi_X, int aDpi_Y, BMP2CMP_MOD_LAYER aModLayer )
int aDpi_X, int aDpi_Y, const wxString& aLayer )
{
potrace_param_t* param;
potrace_state_t* st;
@ -85,7 +82,8 @@ int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, OUTPUT_FM
if( !param )
{
m_errors += fmt::format( "Error allocating parameters: {}\n", strerror( errno ) );
m_reporter.Report( fmt::format( "Error allocating parameters: {}\n", strerror( errno ) ),
RPT_SEVERITY_ERROR );
return 1;
}
@ -100,57 +98,47 @@ int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, OUTPUT_FM
if( !st || st->status != POTRACE_STATUS_OK )
{
if( st )
{
potrace_state_free( st );
}
potrace_param_free( param );
m_errors += fmt::format( "Error tracing bitmap: {}\n", strerror( errno ) );
m_reporter.Report( fmt::format( "Error tracing bitmap: {}\n", strerror( errno ) ),
RPT_SEVERITY_ERROR );
return 1;
}
m_PixmapWidth = aPotrace_bitmap->w;
m_PixmapHeight = aPotrace_bitmap->h; // the bitmap size in pixels
m_Paths = st->plist;
m_Paths = st->plist;
m_Format = aFormat;
switch( aFormat )
{
case KICAD_WKS_LOGO:
m_Format = KICAD_WKS_LOGO;
case DRAWING_SHEET_FMT:
m_ScaleX = PL_IU_PER_MM * 25.4 / aDpi_X; // the conversion scale from PPI to micron
m_ScaleY = PL_IU_PER_MM * 25.4 / aDpi_Y; // Y axis is top to bottom
createOutputData();
break;
case POSTSCRIPT_FMT:
m_Format = POSTSCRIPT_FMT;
m_ScaleX = 1.0; // the conversion scale
m_ScaleY = m_ScaleX;
// output vector data, e.g. as a rudimentary EPS file (mainly for tests)
createOutputData();
break;
case EESCHEMA_FMT:
m_Format = EESCHEMA_FMT;
case SYMBOL_FMT:
m_ScaleX = SCH_IU_PER_MM * 25.4 / aDpi_X; // the conversion scale from PPI to eeschema iu
m_ScaleY = -SCH_IU_PER_MM * 25.4 / aDpi_Y; // Y axis is bottom to Top for components in libs
createOutputData();
break;
case PCBNEW_KICAD_MOD:
m_Format = PCBNEW_KICAD_MOD;
case FOOTPRINT_FMT:
m_ScaleX = PCB_IU_PER_MM * 25.4 / aDpi_X; // the conversion scale from PPI to IU
m_ScaleY = PCB_IU_PER_MM * 25.4 / aDpi_Y; // Y axis is top to bottom in Footprint Editor
createOutputData( aModLayer );
break;
default:
createOutputData( aLayer );
break;
}
bm_free( aPotrace_bitmap );
potrace_state_free( st );
potrace_param_free( param );
@ -159,131 +147,83 @@ int BITMAPCONV_INFO::ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, OUTPUT_FM
}
const char* BITMAPCONV_INFO::getBoardLayerName( BMP2CMP_MOD_LAYER aChoice )
void BITMAPCONV_INFO::outputDataHeader( const wxString& aBrdLayerName )
{
const char* layerName = "F.SilkS";
switch( aChoice )
{
case MOD_LYR_FSOLDERMASK:
layerName = "F.Mask";
break;
case MOD_LYR_FAB:
layerName = "F.Fab";
break;
case MOD_LYR_DRAWINGS:
layerName = "Dwgs.User";
break;
case MOD_LYR_COMMENTS:
layerName = "Cmts.User";
break;
case MOD_LYR_ECO1:
layerName = "Eco1.User";
break;
case MOD_LYR_ECO2:
layerName = "Eco2.User";
break;
case MOD_LYR_FSILKS:
break;
}
return layerName;
}
void BITMAPCONV_INFO::outputDataHeader( const char * aBrdLayerName )
{
double Ypos = ( m_PixmapHeight / 2 * m_ScaleY ); // fields Y position in mm
double Ypos = ( m_PixmapHeight / 2.0 * m_ScaleY ); // fields Y position in mm
double fieldSize; // fields text size in mm
std::string strbuf;
switch( m_Format )
{
case POSTSCRIPT_FMT:
/* output vector data, e.g. as a rudimentary EPS file */
m_Data += "%!PS-Adobe-3.0 EPSF-3.0\n";
strbuf = fmt::format( "%%BoundingBox: 0 0 {} {}\n", m_PixmapWidth, m_PixmapHeight );
m_Data += strbuf;
m_Data += fmt::format( "%%BoundingBox: 0 0 {} {}\n", m_PixmapWidth, m_PixmapHeight );
m_Data += "gsave\n";
break;
case PCBNEW_KICAD_MOD:
case FOOTPRINT_FMT:
// fields text size = 1.5 mm
// fields text thickness = 1.5 / 5 = 0.3mm
strbuf = fmt::format( "(footprint \"{}\" (version 20221018) (generator \"bitmap2component\") (generator_version \"{}\")\n"
" (layer \"F.Cu\")\n",
m_CmpName.c_str(), GetMajorMinorVersion().ToStdString() );
m_Data += fmt::format( "(footprint \"{}\" (version 20221018) (generator \"bitmap2component\") (generator_version \"{}\")\n"
" (layer \"F.Cu\")\n",
m_CmpName.c_str(),
GetMajorMinorVersion().ToStdString() );
m_Data += strbuf;
strbuf = fmt::format(
" (attr board_only exclude_from_pos_files exclude_from_bom)\n" );
m_Data += strbuf;
strbuf = fmt::format(
" (fp_text reference \"G***\" (at 0 0) (layer \"{}\")\n"
" (effects (font (size 1.5 1.5) (thickness 0.3)))\n"
" (uuid {})\n )\n",
aBrdLayerName, KIID().AsString().ToStdString().c_str() );
m_Data += fmt::format( " (attr board_only exclude_from_pos_files exclude_from_bom)\n" );
m_Data += fmt::format( " (fp_text reference \"G***\" (at 0 0) (layer \"{}\")\n"
" (effects (font (size 1.5 1.5) (thickness 0.3)))\n"
" (uuid {})\n )\n",
aBrdLayerName.ToStdString().c_str(),
KIID().AsString().ToStdString().c_str() );
m_Data += strbuf;
strbuf = fmt::format(
" (fp_text value \"{}\" (at 0.75 0) (layer \"{}\") hide\n"
" (effects (font (size 1.5 1.5) (thickness 0.3)))\n"
" (uuid {})\n )\n",
m_CmpName.c_str(), aBrdLayerName, KIID().AsString().ToStdString().c_str() );
m_Data += strbuf;
m_Data += fmt::format( " (fp_text value \"{}\" (at 0.75 0) (layer \"{}\") hide\n"
" (effects (font (size 1.5 1.5) (thickness 0.3)))\n"
" (uuid {})\n )\n",
m_CmpName.c_str(),
aBrdLayerName.ToStdString().c_str(),
KIID().AsString().ToStdString().c_str() );
break;
case KICAD_WKS_LOGO:
m_Data += fmt::format("(kicad_wks (version 20220228) (generator \"bitmap2component\") (generator_version \"{}\")\n", GetMajorMinorVersion().ToStdString() );
case DRAWING_SHEET_FMT:
m_Data += fmt::format( "(kicad_wks (version 20220228) (generator \"bitmap2component\") (generator_version \"{}\")\n",
GetMajorMinorVersion().ToStdString() );
m_Data += " (setup (textsize 1.5 1.5)(linewidth 0.15)(textlinewidth 0.15)\n";
m_Data += " (left_margin 10)(right_margin 10)(top_margin 10)(bottom_margin 10))\n";
m_Data += " (polygon (name \"\") (pos 0 0) (linewidth 0.01)\n";
break;
case EESCHEMA_FMT:
case SYMBOL_FMT:
fieldSize = 1.27; // fields text size in mm (= 50 mils)
Ypos /= SCH_IU_PER_MM;
Ypos += fieldSize / 2;
// snprintf( strbuf, sizeof(strbuf), "# pixmap size w = %d, h = %d\n#\n", m_PixmapWidth, m_PixmapHeight );
strbuf = fmt::format(
"(kicad_symbol_lib (version 20220914) (generator \"bitmap2component\") (generator_version \"{}\")\n"
" (symbol \"{}\" (pin_names (offset 1.016)) (in_bom yes) (on_board yes)\n",
GetMajorMinorVersion().ToStdString(), m_CmpName.c_str() );
m_Data += strbuf;
m_Data += fmt::format( "(kicad_symbol_lib (version 20220914) (generator \"bitmap2component\") (generator_version \"{}\")\n"
" (symbol \"{}\" (pin_names (offset 1.016)) (in_bom yes) (on_board yes)\n",
GetMajorMinorVersion().ToStdString(),
m_CmpName.c_str() );
strbuf = fmt::format(
" (property \"Reference\" \"#G\" (at 0 {:g} 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
-Ypos, fieldSize, fieldSize );
m_Data += strbuf;
m_Data += fmt::format( " (property \"Reference\" \"#G\" (at 0 {:g} 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
-Ypos,
fieldSize,
fieldSize );
strbuf = fmt::format(
" (property \"Value\" \"{}\" (at 0 {:g} 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
m_CmpName.c_str(), Ypos, fieldSize, fieldSize );
m_Data += strbuf;
m_Data += fmt::format( " (property \"Value\" \"{}\" (at 0 {:g} 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
m_CmpName.c_str(),
Ypos,
fieldSize,
fieldSize );
strbuf = fmt::format(
" (property \"Footprint\" \"\" (at 0 0 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
fieldSize, fieldSize );
m_Data += strbuf;
m_Data += fmt::format( " (property \"Footprint\" \"\" (at 0 0 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
fieldSize,
fieldSize );
strbuf = fmt::format(
" (property \"Datasheet\" \"\" (at 0 0 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
fieldSize, fieldSize );
m_Data += strbuf;
m_Data += fmt::format( " (property \"Datasheet\" \"\" (at 0 0 0)\n"
" (effects (font (size {:g} {:g})) hide)\n )\n",
fieldSize,
fieldSize );
strbuf = fmt::format( " (symbol \"{}_0_0\"\n", m_CmpName.c_str() );
m_Data += strbuf;
m_Data += fmt::format( " (symbol \"{}_0_0\"\n", m_CmpName.c_str() );
break;
}
}
@ -298,15 +238,15 @@ void BITMAPCONV_INFO::outputDataEnd()
m_Data += "%%EOF\n";
break;
case PCBNEW_KICAD_MOD:
case FOOTPRINT_FMT:
m_Data += ")\n";
break;
case KICAD_WKS_LOGO:
case DRAWING_SHEET_FMT:
m_Data += " )\n)\n";
break;
case EESCHEMA_FMT:
case SYMBOL_FMT:
m_Data += " )\n"; // end symbol_0_0
m_Data += " )\n"; // end symbol
m_Data += ")\n"; // end lib
@ -315,16 +255,14 @@ void BITMAPCONV_INFO::outputDataEnd()
}
void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char* aBrdLayerName )
void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const wxString& aBrdLayerName )
{
// write one polygon to output file.
// coordinates are expected in target unit.
int ii, jj;
int ii, jj;
VECTOR2I currpoint;
std::string strbuf;
int offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX );
int offsetY = (int)( m_PixmapHeight / 2 * m_ScaleY );
int offsetX = KiROUND( m_PixmapWidth / 2.0 * m_ScaleX );
int offsetY = KiROUND( m_PixmapHeight / 2.0 * m_ScaleY );
const VECTOR2I startpoint = aPolygon.CPoint( 0 );
@ -332,15 +270,13 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char*
{
case POSTSCRIPT_FMT:
offsetY = (int)( m_PixmapHeight * m_ScaleY );
strbuf = fmt::format( "newpath\n{} {} moveto\n", startpoint.x, offsetY - startpoint.y );
m_Data += strbuf;
m_Data += fmt::format( "newpath\n{} {} moveto\n", startpoint.x, offsetY - startpoint.y );
jj = 0;
for( ii = 1; ii < aPolygon.PointCount(); ii++ )
{
currpoint = aPolygon.CPoint( ii );
strbuf = fmt::format( " {} {} lineto", currpoint.x, offsetY - currpoint.y );
m_Data += strbuf;
m_Data += fmt::format( " {} {} lineto", currpoint.x, offsetY - currpoint.y );
if( jj++ > 6 )
{
@ -352,9 +288,7 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char*
m_Data += "\nclosepath fill\n";
break;
case PCBNEW_KICAD_MOD:
{
double width = 0.0; // outline thickness in mm: no thickness
case FOOTPRINT_FMT:
m_Data += " (fp_poly\n (pts\n";
jj = 0;
@ -362,23 +296,20 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char*
for( ii = 0; ii < aPolygon.PointCount(); ii++ )
{
currpoint = aPolygon.CPoint( ii );
strbuf = fmt::format( " (xy {} {})\n",
( currpoint.x - offsetX ) / PCB_IU_PER_MM,
( currpoint.y - offsetY ) / PCB_IU_PER_MM );
m_Data += strbuf;
m_Data += fmt::format( " (xy {} {})\n",
( currpoint.x - offsetX ) / PCB_IU_PER_MM,
( currpoint.y - offsetY ) / PCB_IU_PER_MM );
}
// No need to close polygon
m_Data += " )\n\n";
strbuf = fmt::format(
" (stroke (width {:f}) (type solid)) (fill solid) (layer \"{}\") (uuid {}))\n",
width, aBrdLayerName, KIID().AsString().ToStdString().c_str() );
m_Data += fmt::format( " (stroke (width {:f}) (type solid)) (fill solid) (layer \"{}\") (uuid {}))\n",
0.0,
aBrdLayerName.ToStdString().c_str(),
KIID().AsString().ToStdString().c_str() );
break;
m_Data += strbuf;
}
break;
case KICAD_WKS_LOGO:
case DRAWING_SHEET_FMT:
m_Data += " (pts";
// Internal units = micron, file unit = mm
@ -387,10 +318,9 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char*
for( ii = 0; ii < aPolygon.PointCount(); ii++ )
{
currpoint = aPolygon.CPoint( ii );
strbuf = fmt::format( " (xy {:.3f} {:.3f})",
( currpoint.x - offsetX ) / PL_IU_PER_MM,
( currpoint.y - offsetY ) / PL_IU_PER_MM );
m_Data += strbuf;
m_Data += fmt::format( " (xy {:.3f} {:.3f})",
( currpoint.x - offsetX ) / PL_IU_PER_MM,
( currpoint.y - offsetY ) / PL_IU_PER_MM );
if( jj++ > 4 )
{
@ -400,13 +330,12 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char*
}
// Close polygon
strbuf = fmt::format( " (xy {:.3f} {:.3f}) )\n",
m_Data += fmt::format( " (xy {:.3f} {:.3f}) )\n",
( startpoint.x - offsetX ) / PL_IU_PER_MM,
( startpoint.y - offsetY ) / PL_IU_PER_MM );
m_Data += strbuf;
break;
case EESCHEMA_FMT:
case SYMBOL_FMT:
// The polygon outline thickness is fixed here to 0.01 ( 0.0 is the default thickness)
#define SCH_LINE_THICKNESS_MM 0.01
//snprintf( strbuf, sizeof(strbuf), "P %d 0 0 %d", (int) aPolygon.PointCount() + 1, EE_LINE_THICKNESS );
@ -415,31 +344,27 @@ void BITMAPCONV_INFO::outputOnePolygon( SHAPE_LINE_CHAIN& aPolygon, const char*
for( ii = 0; ii < aPolygon.PointCount(); ii++ )
{
currpoint = aPolygon.CPoint( ii );
strbuf = fmt::format( " (xy {:f} {:f})\n",
( currpoint.x - offsetX ) / SCH_IU_PER_MM,
( currpoint.y - offsetY ) / SCH_IU_PER_MM );
m_Data += strbuf;
m_Data += fmt::format( " (xy {:f} {:f})\n",
( currpoint.x - offsetX ) / SCH_IU_PER_MM,
( currpoint.y - offsetY ) / SCH_IU_PER_MM );
}
// Close polygon
strbuf = fmt::format( " (xy {:f} {:f})\n",
( startpoint.x - offsetX ) / SCH_IU_PER_MM,
( startpoint.y - offsetY ) / SCH_IU_PER_MM );
m_Data += strbuf;
m_Data += fmt::format( " (xy {:f} {:f})\n",
( startpoint.x - offsetX ) / SCH_IU_PER_MM,
( startpoint.y - offsetY ) / SCH_IU_PER_MM );
m_Data += " )\n"; // end pts
strbuf = fmt::format(
" (stroke (width {:g}) (type default))\n (fill (type outline))\n",
SCH_LINE_THICKNESS_MM );
m_Data += strbuf;
m_Data += fmt::format( " (stroke (width {:g}) (type default))\n"
" (fill (type outline))\n",
SCH_LINE_THICKNESS_MM );
m_Data += " )\n"; // end polyline
break;
}
}
void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer )
void BITMAPCONV_INFO::createOutputData( const wxString& aLayer )
{
std::vector <potrace_dpoint_t> cornersBuffer;
@ -456,7 +381,7 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer )
// The layer name has meaning only for .kicad_mod files.
// For these files the header creates 2 invisible texts: value and ref
// (needed but not useful) on silk screen layer
outputDataHeader( getBoardLayerName( MOD_LYR_FSILKS ) );
outputDataHeader( "F.SilkS" );
bool main_outline = true;
@ -465,9 +390,10 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer )
*/
potrace_path_t* paths = m_Paths; // the list of paths
if(!m_Paths)
if( !m_Paths )
{
m_errors += "No shape in black and white image to convert: no outline created\n";
m_reporter.Report( _( "No shape in black and white image to convert: no outline created." ),
RPT_SEVERITY_ERROR );
}
while( paths != nullptr )
@ -501,10 +427,11 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer )
// build the current main polygon
polyset_areas.NewOutline();
for( unsigned int i = 0; i < cornersBuffer.size(); i++ )
for( const potrace_dpoint_s& pt : cornersBuffer )
{
polyset_areas.Append( int( cornersBuffer[i].x * m_ScaleX ),
int( cornersBuffer[i].y * m_ScaleY ) );
polyset_areas.Append( int( pt.x * m_ScaleX ),
int( pt.y * m_ScaleY ) );
}
}
else
@ -512,10 +439,10 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer )
// Add current hole in polyset_holes
polyset_holes.NewOutline();
for( unsigned int i = 0; i < cornersBuffer.size(); i++ )
for( const potrace_dpoint_s& pt : cornersBuffer )
{
polyset_holes.Append( int( cornersBuffer[i].x * m_ScaleX ),
int( cornersBuffer[i].y * m_ScaleY ) );
polyset_holes.Append( int( pt.x * m_ScaleX ),
int( pt.y * m_ScaleY ) );
}
}
@ -538,7 +465,7 @@ void BITMAPCONV_INFO::createOutputData( BMP2CMP_MOD_LAYER aModLayer )
for( int ii = 0; ii < polyset_areas.OutlineCount(); ii++ )
{
SHAPE_LINE_CHAIN& poly = polyset_areas.Outline( ii );
outputOnePolygon( poly, getBoardLayerName( aModLayer ));
outputOnePolygon( poly, aLayer );
}
polyset_areas.RemoveAllContours();

View File

@ -27,71 +27,52 @@
#include <geometry/shape_poly_set.h>
#include <potracelib.h>
// for consistency this enum should conform to the
// indices in m_radioBoxFormat from bitmap2cmp_gui.cpp
class REPORTER;
enum OUTPUT_FMT_ID
{
EESCHEMA_FMT = 0,
PCBNEW_KICAD_MOD,
SYMBOL_FMT,
FOOTPRINT_FMT,
POSTSCRIPT_FMT,
KICAD_WKS_LOGO,
FINAL_FMT = KICAD_WKS_LOGO
DRAWING_SHEET_FMT,
};
// for consistency this enum should conform to the
// indices in m_cbPcbLayer from bitmap2cmp_gui.cpp
enum BMP2CMP_MOD_LAYER
{
MOD_LYR_FSILKS = 0,
MOD_LYR_FSOLDERMASK,
MOD_LYR_FAB,
MOD_LYR_DRAWINGS,
MOD_LYR_COMMENTS,
MOD_LYR_ECO1,
MOD_LYR_ECO2,
MOD_LYR_FINAL = MOD_LYR_ECO2
};
/* Helper class to handle useful info to convert a bitmap image to
* a polygonal object description
*/
class BITMAPCONV_INFO
{
private:
enum OUTPUT_FMT_ID m_Format; // File format
int m_PixmapWidth;
int m_PixmapHeight; // the bitmap size in pixels
enum OUTPUT_FMT_ID m_Format; // File format
int m_PixmapWidth;
int m_PixmapHeight; // the bitmap size in pixels
double m_ScaleX;
double m_ScaleY; // the conversion scale
potrace_path_t* m_Paths; // the list of paths, from potrace (list of lines and bezier curves)
std::string m_CmpName; // The string used as cmp/footprint name
std::string& m_Data; // the buffer containing the conversion
std::string m_errors; // a buffer to return error messages
double m_ScaleY; // the conversion scale
potrace_path_t* m_Paths; // the list of paths, from potrace (list of lines and bezier curves)
std::string m_CmpName; // The string used as cmp/footprint name
std::string& m_Data; // the buffer containing the conversion
REPORTER& m_reporter;
public:
BITMAPCONV_INFO( std::string& aData );
BITMAPCONV_INFO( std::string& aData, REPORTER& aReporter );
/**
* Run the conversion of the bitmap
*/
int ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap,
OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y,
BMP2CMP_MOD_LAYER aModLayer );
std::string& GetErrorMessages() {return m_errors; }
int ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap, OUTPUT_FMT_ID aFormat, int aDpi_X,
int aDpi_Y, const wxString& aLayer );
private:
/**
* Creates the data specified by m_Format
*/
void createOutputData( BMP2CMP_MOD_LAYER aModLayer = (BMP2CMP_MOD_LAYER) 0 );
void createOutputData( const wxString& aBrdLayerName = wxT( "F.SilkS" ) );
/**
* Function outputDataHeader
* write to file the header depending on file format
*/
void outputDataHeader( const char * aBrdLayerName );
void outputDataHeader( const wxString& aBrdLayerName );
/**
* Function outputDataEnd
@ -99,20 +80,12 @@ private:
*/
void outputDataEnd();
/**
* @return the board layer name depending on the board layer selected
* @param aChoice = the choice (MOD_LYR_FSILKS to MOD_LYR_FINAL)
*/
const char * getBoardLayerName( BMP2CMP_MOD_LAYER aChoice );
/**
* Function outputOnePolygon
* write one polygon to output file.
* Polygon coordinates are expected scaled by the polygon extraction function
*/
void outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* aBrdLayerName );
void outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const wxString& aBrdLayerName );
};
#endif // BITMAP2COMPONENT_H