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

View File

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

View File

@ -27,11 +27,8 @@
#include <bitmap2cmp_panel.h> #include <bitmap2cmp_panel.h>
#include <bitmap2cmp_settings.h> #include <bitmap2cmp_settings.h>
#include <bitmap_io.h> #include <bitmap_io.h>
#include <bitmaps.h>
#include <common.h> #include <common.h>
#include <kiface_base.h>
#include <math/util.h> // for KiROUND #include <math/util.h> // for KiROUND
#include <pgm_base.h>
#include <potracelib.h> #include <potracelib.h>
#include <wx/clipbrd.h> #include <wx/clipbrd.h>
#include <wx/rawbmp.h> #include <wx/rawbmp.h>
@ -44,10 +41,11 @@
BITMAP2CMP_PANEL::BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent ) : BITMAP2CMP_PANEL::BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent ) :
BITMAP2CMP_PANEL_BASE( aParent ), BITMAP2CMP_PANEL_BASE( aParent ),
m_parentFrame( aParent ), m_negative( false ), m_parentFrame( aParent ),
m_negative( false ),
m_aspectRatio( 1.0 ) m_aspectRatio( 1.0 )
{ {
for( wxString unit : { _( "mm" ), _( "Inch" ), _( "DPI" ) } ) for( const wxString& unit : { _( "mm" ), _( "Inch" ), _( "DPI" ) } )
m_PixelUnit->Append( unit ); m_PixelUnit->Append( unit );
m_outputSizeX.SetUnit( getUnitFromSelection() ); m_outputSizeX.SetUnit( getUnitFromSelection() );
@ -55,19 +53,14 @@ BITMAP2CMP_PANEL::BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent ) :
m_outputSizeX.SetOutputSize( 0, getUnitFromSelection() ); m_outputSizeX.SetOutputSize( 0, getUnitFromSelection() );
m_outputSizeY.SetOutputSize( 0, getUnitFromSelection() ); m_outputSizeY.SetOutputSize( 0, getUnitFromSelection() );
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) ); m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) ); m_UnitSizeY->ChangeValue( formatOutputSize( m_outputSizeY.GetOutputSize() ) );
m_buttonExportFile->Enable( false ); m_buttonExportFile->Enable( false );
m_buttonExportClipboard->Enable( false ); m_buttonExportClipboard->Enable( false );
} }
BITMAP2CMP_PANEL::~BITMAP2CMP_PANEL()
{
}
wxWindow* BITMAP2CMP_PANEL::GetCurrentPage() wxWindow* BITMAP2CMP_PANEL::GetCurrentPage()
{ {
return m_Notebook->GetCurrentPage(); return m_Notebook->GetCurrentPage();
@ -76,12 +69,8 @@ wxWindow* BITMAP2CMP_PANEL::GetCurrentPage()
void BITMAP2CMP_PANEL::LoadSettings( BITMAP2CMP_SETTINGS* cfg ) void BITMAP2CMP_PANEL::LoadSettings( BITMAP2CMP_SETTINGS* cfg )
{ {
int u_select = cfg->m_Units; if( cfg->m_Units >= 0 && cfg->m_Units < (int) m_PixelUnit->GetCount() )
m_PixelUnit->SetSelection( cfg->m_Units );
if( u_select < 0 || u_select > 2 ) // Validity control
u_select = 0;
m_PixelUnit->SetSelection( u_select );
m_sliderThreshold->SetValue( cfg->m_Threshold ); m_sliderThreshold->SetValue( cfg->m_Threshold );
@ -91,32 +80,30 @@ void BITMAP2CMP_PANEL::LoadSettings( BITMAP2CMP_SETTINGS* cfg )
m_aspectRatio = 1.0; m_aspectRatio = 1.0;
m_aspectRatioCheckbox->SetValue( true ); 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 ) m_layerLabel->Enable( cfg->m_LastFormat == FOOTPRINT_FMT );
format = PCBNEW_KICAD_MOD; m_layerCtrl->Enable( cfg->m_LastFormat == FOOTPRINT_FMT );
m_rbOutputFormat->SetSelection( format ); if( cfg->m_LastLayer >= 0 && cfg->m_LastLayer < (int) m_layerCtrl->GetCount() )
m_layerCtrl->SetSelection( cfg->m_LastLayer );
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 );
} }
void BITMAP2CMP_PANEL::SaveSettings( BITMAP2CMP_SETTINGS* cfg ) void BITMAP2CMP_PANEL::SaveSettings( BITMAP2CMP_SETTINGS* cfg )
{ {
cfg->m_Threshold = m_sliderThreshold->GetValue(); cfg->m_Threshold = m_sliderThreshold->GetValue();
cfg->m_Negative = m_checkNegative->IsChecked(); cfg->m_Negative = m_checkNegative->IsChecked();
cfg->m_LastFormat = m_rbOutputFormat->GetSelection(); cfg->m_LastFormat = getOutputFormat();
cfg->m_LastModLayer = m_chPCBLayer->GetSelection(); cfg->m_LastLayer = m_layerCtrl->GetSelection();
cfg->m_Units = m_PixelUnit->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++ ) for( int y = 0; y < m_Pict_Bitmap.GetHeight(); y++ )
{ {
if( m_Pict_Image.GetRed( x, y ) == m_Pict_Image.GetMaskRed() && if( m_Pict_Image.GetRed( x, y ) == m_Pict_Image.GetMaskRed()
m_Pict_Image.GetGreen( x, y ) == m_Pict_Image.GetMaskGreen() && && m_Pict_Image.GetGreen( x, y ) == m_Pict_Image.GetMaskGreen()
m_Pict_Image.GetBlue( x, y ) == m_Pict_Image.GetMaskBlue() ) && m_Pict_Image.GetBlue( x, y ) == m_Pict_Image.GetMaskBlue() )
{ {
m_Greyscale_Image.SetRGB( x, y, 255, 255, 255 ); 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 ) if( m_negative )
NegateGreyscaleImage( ); negateGreyscaleImage();
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image ); m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
m_NB_Image = 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_buttonExportFile->Enable( true );
m_buttonExportClipboard->Enable( true ); m_buttonExportClipboard->Enable( true );
m_outputSizeX.SetOutputSizeFromInitialImageSize(); m_outputSizeX.SetOutputSizeFromInitialImageSize();
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) ); m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_outputSizeY.SetOutputSizeFromInitialImageSize(); m_outputSizeY.SetOutputSizeFromInitialImageSize();
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) ); m_UnitSizeY->ChangeValue( formatOutputSize( m_outputSizeY.GetOutputSize() ) );
return true; return true;
} }
// return a string giving the output size, according to the selected unit // 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; wxString text;
@ -295,13 +282,9 @@ void BITMAP2CMP_PANEL::updateImageInfo()
if( m_Pict_Bitmap.IsOk() ) if( m_Pict_Bitmap.IsOk() )
{ {
int h = m_Pict_Bitmap.GetHeight(); m_SizeXValue->SetLabel( wxString::Format( wxT( "%d" ), m_Pict_Bitmap.GetWidth() ) );
int w = m_Pict_Bitmap.GetWidth(); m_SizeYValue->SetLabel( wxString::Format( wxT( "%d" ), m_Pict_Bitmap.GetHeight() ) );
int nb = m_Pict_Bitmap.GetDepth(); m_BPPValue->SetLabel( wxString::Format( wxT( "%d" ), 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 ) );
} }
} }
@ -338,7 +321,7 @@ void BITMAP2CMP_PANEL::OnSizeChangeX( wxCommandEvent& event )
} }
m_outputSizeY.SetOutputSize( calculatedY, getUnitFromSelection() ); 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() ); m_outputSizeX.SetOutputSize( new_size, getUnitFromSelection() );
@ -367,7 +350,7 @@ void BITMAP2CMP_PANEL::OnSizeChangeY( wxCommandEvent& event )
} }
m_outputSizeX.SetOutputSize( calculatedX, getUnitFromSelection() ); 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() ); m_outputSizeY.SetOutputSize( new_size, getUnitFromSelection() );
@ -383,8 +366,8 @@ void BITMAP2CMP_PANEL::OnSizeUnitChange( wxCommandEvent& event )
m_outputSizeY.SetUnit( getUnitFromSelection() ); m_outputSizeY.SetUnit( getUnitFromSelection() );
updateImageInfo(); updateImageInfo();
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) ); m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.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; m_outputSizeY = aSizeY;
updateImageInfo(); updateImageInfo();
m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) ); m_UnitSizeX->ChangeValue( formatOutputSize( m_outputSizeX.GetOutputSize() ) );
m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.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 threshold = aThreshold * 255;
unsigned char alpha_thresh = 0.7 * threshold; 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 pixel = m_Greyscale_Image.GetGreen( x, y );
unsigned char pixin = m_Greyscale_Image.GetGreen( x, y );
unsigned char alpha = m_Greyscale_Image.HasAlpha() ? m_Greyscale_Image.GetAlpha( x, y ) unsigned char alpha = m_Greyscale_Image.HasAlpha() ? m_Greyscale_Image.GetAlpha( x, y )
: wxALPHA_OPAQUE; : wxALPHA_OPAQUE;
if( pixin < threshold && alpha > alpha_thresh ) if( pixel < threshold && alpha > alpha_thresh )
pixout = 0; pixel = 0;
else 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; for( int y = 0; y < m_Greyscale_Image.GetHeight(); y++ )
int h = m_Greyscale_Image.GetHeight();
int w = m_Greyscale_Image.GetWidth();
for( int y = 0; y < h; 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 ); unsigned char pixel = m_Greyscale_Image.GetGreen( x, y );
pix = ~pix; pixel = ~pixel;
m_Greyscale_Image.SetRGB( x, y, pix, pix, pix ); m_Greyscale_Image.SetRGB( x, y, pixel, pixel, pixel );
} }
} }
} }
@ -461,10 +437,10 @@ void BITMAP2CMP_PANEL::OnNegativeClicked( wxCommandEvent& )
{ {
if( m_checkNegative->GetValue() != m_negative ) if( m_checkNegative->GetValue() != m_negative )
{ {
NegateGreyscaleImage(); negateGreyscaleImage();
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image ); 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(); m_negative = m_checkNegative->GetValue();
Refresh(); Refresh();
@ -474,28 +450,40 @@ void BITMAP2CMP_PANEL::OnNegativeClicked( wxCommandEvent& )
void BITMAP2CMP_PANEL::OnThresholdChange( wxScrollEvent& event ) void BITMAP2CMP_PANEL::OnThresholdChange( wxScrollEvent& event )
{ {
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() ); binarize( (double)m_sliderThreshold->GetValue() / m_sliderThreshold->GetMax() );
Refresh(); Refresh();
} }
void BITMAP2CMP_PANEL::OnExportToFile( wxCommandEvent& event ) void BITMAP2CMP_PANEL::OnExportToFile( wxCommandEvent& event )
{ {
// choices of m_rbOutputFormat are expected to be in same order as switch( getOutputFormat() )
// OUTPUT_FMT_ID. See bitmap2component.h {
OUTPUT_FMT_ID format = (OUTPUT_FMT_ID) m_rbOutputFormat->GetSelection(); case SYMBOL_FMT: m_parentFrame->ExportEeschemaFormat(); break;
exportBitmap( format ); 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 ) 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; std::string buffer;
ExportToBuffer( buffer, format ); ExportToBuffer( buffer, getOutputFormat() );
wxLogNull doNotLog; // disable logging of failed clipboard actions 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 ) void BITMAP2CMP_PANEL::ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat )
{ {
// Create a potrace bitmap // Create a potrace bitmap
int h = m_NB_Image.GetHeight(); potrace_bitmap_t* potrace_bitmap = bm_new( m_NB_Image.GetWidth(), m_NB_Image.GetHeight() );
int w = m_NB_Image.GetWidth();
potrace_bitmap_t* potrace_bitmap = bm_new( w, h );
if( !potrace_bitmap ) if( !potrace_bitmap )
{ {
wxString msg; wxMessageBox( _( "Error allocating memory for potrace bitmap" ) );
msg.Printf( _( "Error allocating memory for potrace bitmap" ) );
wxMessageBox( msg );
return; return;
} }
/* fill the bitmap with data */ /* 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 ); unsigned char pixel = m_NB_Image.GetGreen( x, y );
BM_PUT( potrace_bitmap, x, y, pix ? 0 : 1 ); BM_PUT( potrace_bitmap, x, y, pixel ? 0 : 1 );
} }
} }
// choices of m_rbPCBLayer are expected to be in same order as wxString layer = wxT( "F.SilkS" );
// BMP2CMP_MOD_LAYER. See bitmap2component.h
BMP2CMP_MOD_LAYER modLayer = MOD_LYR_FSILKS;
if( aFormat == PCBNEW_KICAD_MOD ) if( aFormat == FOOTPRINT_FMT )
modLayer = (BMP2CMP_MOD_LAYER) m_chPCBLayer->GetSelection(); {
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(), converter.ConvertBitmap( potrace_bitmap, aFormat, m_outputSizeX.GetOutputDPI(),
m_outputSizeY.GetOutputDPI(), modLayer ); m_outputSizeY.GetOutputDPI(), layer );
if( !converter.GetErrorMessages().empty() ) if( reporter.HasMessage() )
wxMessageBox( converter.GetErrorMessages().c_str(), _( "Errors" ) ); wxMessageBox( reporter.GetMessages(), _( "Errors" ) );
} }
void BITMAP2CMP_PANEL::OnFormatChange( wxCommandEvent& event ) void BITMAP2CMP_PANEL::OnFormatChange( wxCommandEvent& event )
{ {
bool enable = m_rbOutputFormat->GetSelection() == PCBNEW_KICAD_MOD; m_layerLabel->Enable( m_rbFootprint->GetValue() );
m_chPCBLayer->Enable( enable ); m_layerCtrl->Enable( m_rbFootprint->GetValue() );
} }

View File

@ -40,32 +40,13 @@ public:
// to the value in new unit // to the value in new unit
void SetUnit( EDA_UNITS aUnit ); void SetUnit( EDA_UNITS aUnit );
// Accessors: void SetOriginalDPI( int aDPI ) { m_originalDPI = aDPI; }
void SetOriginalDPI( int aDPI )
{
m_originalDPI = aDPI;
}
void SetOriginalSizePixels( int aPixels ) void SetOriginalSizePixels( int aPixels ) { m_originalSizePixels = aPixels; }
{ int GetOriginalSizePixels() { return m_originalSizePixels; }
m_originalSizePixels = aPixels;
}
double GetOutputSize() double GetOutputSize() { return m_outputSize; }
{ void SetOutputSize( double aSize, EDA_UNITS aUnit ) { m_outputSize = aSize; m_unit = aUnit; }
return m_outputSize;
}
void SetOutputSize( double aSize, EDA_UNITS aUnit )
{
m_unit = aUnit;
m_outputSize = aSize;
}
int GetOriginalSizePixels()
{
return m_originalSizePixels;
}
// Set the m_outputSize value from the m_originalSizePixels and the selected unit // Set the m_outputSize value from the m_originalSizePixels and the selected unit
void SetOutputSizeFromInitialImageSize(); void SetOutputSizeFromInitialImageSize();
@ -88,7 +69,7 @@ class BITMAP2CMP_PANEL : public BITMAP2CMP_PANEL_BASE
{ {
public: public:
BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent ); BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent );
~BITMAP2CMP_PANEL(); ~BITMAP2CMP_PANEL() {}
bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl = 0 ); bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl = 0 );
@ -117,28 +98,27 @@ private:
void OnPaintBW( wxPaintEvent& event ) override; void OnPaintBW( wxPaintEvent& event ) override;
void OnExportToFile( wxCommandEvent& event ) override; void OnExportToFile( wxCommandEvent& event ) override;
void OnExportToClipboard( 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 ///< @return the EDA_UNITS from the m_PixelUnit choice
EDA_UNITS getUnitFromSelection(); EDA_UNITS getUnitFromSelection();
// return a string giving the output size, according to the selected unit // 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 binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
void OnNegativeClicked( wxCommandEvent& event ) override;
void OnThresholdChange( wxScrollEvent& event ) override;
void OnSizeChangeX( wxCommandEvent& event ) override; void negateGreyscaleImage();
void OnSizeChangeY( wxCommandEvent& event ) override;
void OnSizeUnitChange( wxCommandEvent& event ) override;
void ToggleAspectRatioLock( wxCommandEvent& event ) override;
void NegateGreyscaleImage();
void updateImageInfo(); void updateImageInfo();
void OnFormatChange( wxCommandEvent& event ) override;
void exportBitmap( OUTPUT_FMT_ID aFormat );
private: private:
BITMAP2CMP_FRAME* m_parentFrame; 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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // 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_BNPicturePanel->SetScrollRate( 5, 5 );
m_Notebook->AddPage( m_BNPicturePanel, _("Black && White Picture"), true ); 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; wxBoxSizer* brightSizer;
brightSizer = new wxBoxSizer( wxVERTICAL ); 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 ); brightSizer->Add( sbSizerInfo, 0, wxEXPAND|wxALL, 5 );
m_buttonLoad = new wxButton( this, wxID_ANY, _("Load Source Image"), wxDefaultPosition, wxDefaultSize, 0 ); 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 ); brightSizer->Add( 0, 0, 1, wxEXPAND, 5 );
@ -104,35 +104,35 @@ BITMAP2CMP_PANEL_BASE::BITMAP2CMP_PANEL_BASE( wxWindow* parent, wxWindowID id, c
wxStaticBoxSizer* sbSizerImgPrms; wxStaticBoxSizer* sbSizerImgPrms;
sbSizerImgPrms = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Output Size") ), wxVERTICAL ); 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; wxBoxSizer* bSizerRes;
bSizerRes = new wxBoxSizer( wxHORIZONTAL ); bSizerRes = new wxBoxSizer( wxHORIZONTAL );
m_staticTextOSize = new wxStaticText( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 ); m_sizeLabel = new wxStaticText( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextOSize->Wrap( -1 ); m_sizeLabel->Wrap( -1 );
bSizerRes->Add( m_staticTextOSize, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT|wxTOP, 5 ); 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 = new wxTextCtrl( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("300"), wxDefaultPosition, wxDefaultSize, 0 );
m_UnitSizeX->SetMinSize( wxSize( 60,-1 ) ); 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 = new wxTextCtrl( sbSizerImgPrms->GetStaticBox(), wxID_ANY, _("300"), wxDefaultPosition, wxDefaultSize, 0 );
m_UnitSizeY->SetMinSize( wxSize( 60,-1 ) ); 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; wxArrayString m_PixelUnitChoices;
m_PixelUnit = new wxChoice( sbSizerImgPrms->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_PixelUnitChoices, 0 ); m_PixelUnit = new wxChoice( sbSizerImgPrms->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_PixelUnitChoices, 0 );
m_PixelUnit->SetSelection( 0 ); m_PixelUnit->SetSelection( 0 );
m_PixelUnit->SetMinSize( wxSize( 80,-1 ) ); 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 ); 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 = new wxStaticText( sbSizer2->GetStaticBox(), wxID_ANY, _("Black / white threshold:"), wxDefaultPosition, wxDefaultSize, 0 );
m_ThresholdText->Wrap( -1 ); 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 = 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.") ); 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 ); sbSizer2->Add( m_sliderThreshold, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 );
m_checkNegative = new wxCheckBox( sbSizer2->GetStaticBox(), wxID_ANY, _("Negative"), wxDefaultPosition, wxDefaultSize, 0 ); 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 ); 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") }; wxFlexGridSizer* fgSizer2;
int m_chPCBLayerNChoices = sizeof( m_chPCBLayerChoices ) / sizeof( wxString ); fgSizer2 = new wxFlexGridSizer( 5, 1, 2, 0 );
m_chPCBLayer = new wxChoice( m_sizerPcbLayer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_chPCBLayerNChoices, m_chPCBLayerChoices, 0 ); fgSizer2->SetFlexibleDirection( wxBOTH );
m_chPCBLayer->SetSelection( 0 ); fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
m_sizerPcbLayer->Add( m_chPCBLayer, 0, wxALL|wxEXPAND, 5 );
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)") }; m_rbPostscript = new wxRadioButton( sbOutputFormat->GetStaticBox(), wxID_ANY, _("Postscript (.ps file)"), wxDefaultPosition, wxDefaultSize, 0 );
int m_rbOutputFormatNChoices = sizeof( m_rbOutputFormatChoices ) / sizeof( wxString ); fgSizer2->Add( m_rbPostscript, 0, wxTOP|wxBOTTOM|wxRIGHT, 5 );
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_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 ); brightSizer->Add( m_buttonExportFile, 0, wxEXPAND|wxALL, 5 );
m_buttonExportClipboard = new wxButton( this, wxID_ANY, _("Export to Clipboard"), wxDefaultPosition, wxDefaultSize, 0 ); 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_GreyscalePicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintGreyscale ), NULL, this );
m_BNPicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintBW ), 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_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_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_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_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_CHANGED, wxScrollEventHandler( BITMAP2CMP_PANEL_BASE::OnThresholdChange ), NULL, this );
m_sliderThreshold->Connect( wxEVT_SCROLL_THUMBTRACK, 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_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_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 ); 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_GreyscalePicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintGreyscale ), NULL, this );
m_BNPicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BITMAP2CMP_PANEL_BASE::OnPaintBW ), 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_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_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_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_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_CHANGED, wxScrollEventHandler( BITMAP2CMP_PANEL_BASE::OnThresholdChange ), NULL, this );
m_sliderThreshold->Disconnect( wxEVT_SCROLL_THUMBTRACK, 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_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_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 ); 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/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -24,23 +24,23 @@
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/statbox.h> #include <wx/statbox.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/checkbox.h>
#include <wx/textctrl.h> #include <wx/textctrl.h>
#include <wx/valtext.h> #include <wx/valtext.h>
#include <wx/choice.h> #include <wx/choice.h>
#include <wx/checkbox.h>
#include <wx/slider.h> #include <wx/slider.h>
#include <wx/radiobox.h> #include <wx/radiobut.h>
#include <wx/panel.h> #include <wx/panel.h>
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
/// Class BITMAP2CMP_PANEL_BASE /// Class BITMAP2CMP_PANEL_BASE
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class BITMAP2CMP_PANEL_BASE : public wxPanel class BITMAP2CMP_PANEL_BASE : public wxPanel
{ {
private: private:
wxStaticText* m_sizeLabel;
protected: protected:
wxNotebook* m_Notebook; wxNotebook* m_Notebook;
@ -59,17 +59,19 @@ class BITMAP2CMP_PANEL_BASE : public wxPanel
wxStaticText* m_BPPValue; wxStaticText* m_BPPValue;
wxStaticText* m_BPPunits; wxStaticText* m_BPPunits;
wxButton* m_buttonLoad; wxButton* m_buttonLoad;
wxCheckBox* m_aspectRatioCheckbox;
wxStaticText* m_staticTextOSize;
wxTextCtrl* m_UnitSizeX; wxTextCtrl* m_UnitSizeX;
wxTextCtrl* m_UnitSizeY; wxTextCtrl* m_UnitSizeY;
wxChoice* m_PixelUnit; wxChoice* m_PixelUnit;
wxCheckBox* m_aspectRatioCheckbox;
wxStaticText* m_ThresholdText; wxStaticText* m_ThresholdText;
wxSlider* m_sliderThreshold; wxSlider* m_sliderThreshold;
wxCheckBox* m_checkNegative; wxCheckBox* m_checkNegative;
wxStaticBoxSizer* m_sizerPcbLayer; wxRadioButton* m_rbSymbol;
wxChoice* m_chPCBLayer; wxRadioButton* m_rbFootprint;
wxRadioBox* m_rbOutputFormat; wxStaticText* m_layerLabel;
wxChoice* m_layerCtrl;
wxRadioButton* m_rbPostscript;
wxRadioButton* m_rbWorksheet;
wxButton* m_buttonExportFile; wxButton* m_buttonExportFile;
wxButton* m_buttonExportClipboard; wxButton* m_buttonExportClipboard;
@ -78,10 +80,10 @@ class BITMAP2CMP_PANEL_BASE : public wxPanel
virtual void OnPaintGreyscale( wxPaintEvent& event ) { event.Skip(); } virtual void OnPaintGreyscale( wxPaintEvent& event ) { event.Skip(); }
virtual void OnPaintBW( wxPaintEvent& event ) { event.Skip(); } virtual void OnPaintBW( wxPaintEvent& event ) { event.Skip(); }
virtual void OnLoadFile( wxCommandEvent& 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 OnSizeChangeX( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSizeChangeY( wxCommandEvent& event ) { event.Skip(); } virtual void OnSizeChangeY( wxCommandEvent& event ) { event.Skip(); }
virtual void OnSizeUnitChange( 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 OnThresholdChange( wxScrollEvent& event ) { event.Skip(); }
virtual void OnNegativeClicked( wxCommandEvent& event ) { event.Skip(); } virtual void OnNegativeClicked( wxCommandEvent& event ) { event.Skip(); }
virtual void OnFormatChange( 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 ///! Update the schema version whenever a migration is required
const int bitmap2cmpSchemaVersion = 0; const int bitmap2cmpSchemaVersion = 1;
BITMAP2CMP_SETTINGS::BITMAP2CMP_SETTINGS() : BITMAP2CMP_SETTINGS::BITMAP2CMP_SETTINGS() :
APP_SETTINGS_BASE( "bitmap2component", bitmap2cmpSchemaVersion ), APP_SETTINGS_BASE( "bitmap2component", bitmap2cmpSchemaVersion ),
m_BitmapFileName(), m_ConvertedFileName(), m_Units(), m_Threshold(), m_Negative(), m_BitmapFileName(),
m_LastFormat(), m_LastModLayer() 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>( "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>( "units", &m_Units, 0 ) );
m_params.emplace_back( new PARAM<int>( "threshold", &m_Threshold, 50 ) ); 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<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_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; virtual bool MigrateFromLegacy( wxConfigBase* aLegacyConfig ) override;
public:
wxString m_BitmapFileName; wxString m_BitmapFileName;
wxString m_ConvertedFileName; wxString m_ConvertedFileName;
int m_Units;
int m_Units; int m_Threshold;
bool m_Negative;
int m_Threshold; int m_LastFormat;
int m_LastLayer;
bool m_Negative;
int m_LastFormat;
int m_LastModLayer;
protected: protected:
virtual std::string getLegacyFrameName() const override { return "Bmconverter_"; } virtual std::string getLegacyFrameName() const override { return "Bmconverter_"; }
}; };

View File

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

View File

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