Commit 65a585b5 authored by jean-pierre charras's avatar jean-pierre charras

bitmap2component: better user interface (using wxWidgets) and more bitmaps file format import

parents 6e859e26 5ecb22b5
...@@ -5,12 +5,17 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ...@@ -5,12 +5,17 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
set(BITMAP2COMPONENT_SRCS set(BITMAP2COMPONENT_SRCS
bitmap2component.cpp bitmap2component.cpp
bitmap2cmp_gui_base
bitmap2cmp_gui
) )
add_executable(bitmap2component WIN32 MACOSX_BUNDLE ${BITMAP2COMPONENT_SRCS} ${BITMAP2COMPONENT_RESOURCES}) add_executable(bitmap2component WIN32 MACOSX_BUNDLE ${BITMAP2COMPONENT_SRCS} ${BITMAP2COMPONENT_RESOURCES})
target_link_libraries( bitmap2component potrace kbool ) target_link_libraries( bitmap2component
${wxWidgets_LIBRARIES}
potrace
kbool )
install(TARGETS bitmap2component install(TARGETS bitmap2component
DESTINATION ${KICAD_PLUGINS} DESTINATION ${KICAD_PLUGINS}
......
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "bitmap2cmp_gui_base.h"
///////////////////////////////////////////////////////////////////////////
BM2CMP_FRAME_BASE::BM2CMP_FRAME_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
wxBoxSizer* bMainSizer;
bMainSizer = new wxBoxSizer( wxHORIZONTAL );
m_notebook1 = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
m_InitialPicturePanel = new wxScrolledWindow( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
m_InitialPicturePanel->SetScrollRate( 5, 5 );
m_InitialPicturePanel->SetMinSize( wxSize( 400,300 ) );
m_notebook1->AddPage( m_InitialPicturePanel, _("Original Picture"), true );
m_GreyscalePicturePanel = new wxScrolledWindow( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
m_GreyscalePicturePanel->SetScrollRate( 5, 5 );
m_GreyscalePicturePanel->SetMinSize( wxSize( 400,300 ) );
m_notebook1->AddPage( m_GreyscalePicturePanel, _("Greyscale Picture"), false );
m_BNPicturePanel = new wxScrolledWindow( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
m_BNPicturePanel->SetScrollRate( 5, 5 );
m_notebook1->AddPage( m_BNPicturePanel, _("Binary Picture"), false );
bMainSizer->Add( m_notebook1, 1, wxEXPAND, 5 );
wxBoxSizer* brightSizer;
brightSizer = new wxBoxSizer( wxVERTICAL );
m_gridInfo = new wxGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
// Grid
m_gridInfo->CreateGrid( 3, 1 );
m_gridInfo->EnableEditing( false );
m_gridInfo->EnableGridLines( true );
m_gridInfo->EnableDragGridSize( false );
m_gridInfo->SetMargins( 0, 0 );
// Columns
m_gridInfo->SetColSize( 0, 80 );
m_gridInfo->EnableDragColMove( false );
m_gridInfo->EnableDragColSize( true );
m_gridInfo->SetColLabelSize( 30 );
m_gridInfo->SetColLabelValue( 0, _("Value") );
m_gridInfo->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Rows
m_gridInfo->AutoSizeRows();
m_gridInfo->EnableDragRowSize( true );
m_gridInfo->SetRowLabelSize( 80 );
m_gridInfo->SetRowLabelValue( 0, _("Size X") );
m_gridInfo->SetRowLabelValue( 1, _("Size Y") );
m_gridInfo->SetRowLabelValue( 2, _("BPP") );
m_gridInfo->SetRowLabelAlignment( wxALIGN_RIGHT, wxALIGN_CENTRE );
// Label Appearance
// Cell Defaults
m_gridInfo->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
brightSizer->Add( m_gridInfo, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
m_buttonLoad = new wxButton( this, wxID_ANY, _("Load Bitmap"), wxDefaultPosition, wxDefaultSize, 0 );
brightSizer->Add( m_buttonLoad, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
m_buttonExportEeschema = new wxButton( this, wxID_ANY, _("Export to eeschema"), wxDefaultPosition, wxDefaultSize, 0 );
brightSizer->Add( m_buttonExportEeschema, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
m_buttonExportPcbnew = new wxButton( this, wxID_ANY, _("Export to Pcbnew"), wxDefaultPosition, wxDefaultSize, 0 );
brightSizer->Add( m_buttonExportPcbnew, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
wxString m_rbOptionsChoices[] = { _("Normal"), _("Negative") };
int m_rbOptionsNChoices = sizeof( m_rbOptionsChoices ) / sizeof( wxString );
m_rbOptions = new wxRadioBox( this, wxID_ANY, _("Options"), wxDefaultPosition, wxDefaultSize, m_rbOptionsNChoices, m_rbOptionsChoices, 1, wxRA_SPECIFY_COLS );
m_rbOptions->SetSelection( 0 );
brightSizer->Add( m_rbOptions, 0, wxALL|wxEXPAND, 5 );
m_ThresholdText = new wxStaticText( this, wxID_ANY, _("Threshold Value:"), wxDefaultPosition, wxDefaultSize, 0 );
m_ThresholdText->Wrap( -1 );
brightSizer->Add( m_ThresholdText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_sliderThreshold = new wxSlider( this, wxID_ANY, 5, 0, 10, wxDefaultPosition, wxDefaultSize, wxSL_AUTOTICKS|wxSL_HORIZONTAL|wxSL_LABELS|wxSL_TOP );
brightSizer->Add( m_sliderThreshold, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
bMainSizer->Add( brightSizer, 0, wxEXPAND, 5 );
this->SetSizer( bMainSizer );
this->Layout();
// Connect Events
m_InitialPicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this );
m_GreyscalePicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this );
m_BNPicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this );
m_buttonLoad->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnLoadFile ), NULL, this );
m_buttonExportEeschema->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnExportEeschema ), NULL, this );
m_buttonExportPcbnew->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnExportPcbnew ), NULL, this );
m_rbOptions->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnOptionsSelection ), NULL, this );
m_sliderThreshold->Connect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( BM2CMP_FRAME_BASE::OnThresholdChange ), NULL, this );
}
BM2CMP_FRAME_BASE::~BM2CMP_FRAME_BASE()
{
// Disconnect Events
m_InitialPicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this );
m_GreyscalePicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this );
m_BNPicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this );
m_buttonLoad->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnLoadFile ), NULL, this );
m_buttonExportEeschema->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnExportEeschema ), NULL, this );
m_buttonExportPcbnew->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnExportPcbnew ), NULL, this );
m_rbOptions->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnOptionsSelection ), NULL, this );
m_sliderThreshold->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( BM2CMP_FRAME_BASE::OnThresholdChange ), NULL, this );
}
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __bitmap2cmp_gui_base__
#define __bitmap2cmp_gui_base__
#include <wx/intl.h>
#include <wx/scrolwin.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/string.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/notebook.h>
#include <wx/grid.h>
#include <wx/button.h>
#include <wx/radiobox.h>
#include <wx/stattext.h>
#include <wx/slider.h>
#include <wx/sizer.h>
#include <wx/frame.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class BM2CMP_FRAME_BASE
///////////////////////////////////////////////////////////////////////////////
class BM2CMP_FRAME_BASE : public wxFrame
{
private:
protected:
wxNotebook* m_notebook1;
wxScrolledWindow* m_InitialPicturePanel;
wxScrolledWindow* m_GreyscalePicturePanel;
wxScrolledWindow* m_BNPicturePanel;
wxGrid* m_gridInfo;
wxButton* m_buttonLoad;
wxButton* m_buttonExportEeschema;
wxButton* m_buttonExportPcbnew;
wxRadioBox* m_rbOptions;
wxStaticText* m_ThresholdText;
wxSlider* m_sliderThreshold;
// Virtual event handlers, overide them in your derived class
virtual void OnPaint( wxPaintEvent& event ){ event.Skip(); }
virtual void OnLoadFile( wxCommandEvent& event ){ event.Skip(); }
virtual void OnExportEeschema( wxCommandEvent& event ){ event.Skip(); }
virtual void OnExportPcbnew( wxCommandEvent& event ){ event.Skip(); }
virtual void OnOptionsSelection( wxCommandEvent& event ){ event.Skip(); }
virtual void OnThresholdChange( wxScrollEvent& event ){ event.Skip(); }
public:
BM2CMP_FRAME_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Bitmap to Component Converter"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,419 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
~BM2CMP_FRAME_BASE();
};
#endif //__bitmap2cmp_gui_base__
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <vector> #include <vector>
#include "potracelib.h" #include "potracelib.h"
#include "bitmap_io.h" //#include "bitmap_io.h"
#include "auxiliary.h" #include "auxiliary.h"
...@@ -49,6 +49,13 @@ enum output_format { ...@@ -49,6 +49,13 @@ enum output_format {
PCBNEW_FMT, PCBNEW_FMT,
EESCHEMA_FMT EESCHEMA_FMT
}; };
/* free a potrace bitmap */
static void bm_free(potrace_bitmap_t *bm) {
if (bm != NULL) {
free(bm->map);
}
free(bm);
}
/* Helper class th handle useful info to convert a bitmpa to /* Helper class th handle useful info to convert a bitmpa to
...@@ -185,53 +192,11 @@ void ArmBoolEng( Bool_Engine* aBooleng, bool aConvertHoles ) ...@@ -185,53 +192,11 @@ void ArmBoolEng( Bool_Engine* aBooleng, bool aConvertHoles )
} }
int main( int argc, char* argv[] ) int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE * aOutfile, int aFormat )
{ {
potrace_bitmap_t* potrace_bitmap = NULL;
potrace_param_t* param; potrace_param_t* param;
potrace_state_t* st; potrace_state_t* st;
int error;
int fmt_option = '0';
FILE* infile, * outfile = NULL;
if( argc < 4 )
{
printf( "Usage:\nbitmap2component <infile_bitmap.ext> <outfile.ext> <0,1,2>\n" );
printf( " Allowed bitmap files formats are .bmp or .pgm\n" );
printf( "output format:\n 0 = pcbnew.emp, 1 = eeschema.lib, 2 = ps\n" );
return -1;
}
infile = fopen( argv[1], "r" );
if( infile == NULL )
{
printf( "File %s could not be opened\n", argv[1] );
return -2;
}
outfile = fopen( argv[2], "w" );
if( outfile == NULL )
{
printf( "File %s could not be opened\n", argv[2] );
return -2;
}
double threshold = 0.5; // = 0 to 1.0
error = bm_read( infile, threshold, &potrace_bitmap );
if( error != 0 )
{
printf( "Bitmap %s could not be read\n", argv[1] );
return -2;
}
if( !potrace_bitmap )
{
fprintf( stderr, "Error allocating bitmap: %s\n", strerror( errno ) );
return 1;
}
/* set tracing parameters, starting from defaults */ /* set tracing parameters, starting from defaults */
param = potrace_param_default(); param = potrace_param_default();
...@@ -243,7 +208,7 @@ int main( int argc, char* argv[] ) ...@@ -243,7 +208,7 @@ int main( int argc, char* argv[] )
param->turdsize = 0; param->turdsize = 0;
/* convert the bitmap to curves */ /* convert the bitmap to curves */
st = potrace_trace( param, potrace_bitmap ); st = potrace_trace( param, aPotrace_bitmap );
if( !st || st->status != POTRACE_STATUS_OK ) if( !st || st->status != POTRACE_STATUS_OK )
{ {
fprintf( stderr, "Error tracing bitmap: %s\n", strerror( errno ) ); fprintf( stderr, "Error tracing bitmap: %s\n", strerror( errno ) );
...@@ -251,41 +216,40 @@ int main( int argc, char* argv[] ) ...@@ -251,41 +216,40 @@ int main( int argc, char* argv[] )
} }
BITMAPCONV_INFO info; BITMAPCONV_INFO info;
info.m_PixmapWidth = potrace_bitmap->w; info.m_PixmapWidth = aPotrace_bitmap->w;
info.m_PixmapHeight = potrace_bitmap->h; // the bitmap size in pixels info.m_PixmapHeight = aPotrace_bitmap->h; // the bitmap size in pixels
info.m_Paths = st->plist; info.m_Paths = st->plist;
info.m_Outfile = outfile; info.m_Outfile = aOutfile;
if( argc >= 4 ) switch( aFormat )
fmt_option = argv[3][0];
switch( fmt_option )
{ {
case '2': case 2:
info.m_Format = POSTSCRIPT_FMT; info.m_Format = POSTSCRIPT_FMT;
info.m_ScaleX = info.m_ScaleY = 1.0; // the conversion scale info.m_ScaleX = info.m_ScaleY = 1.0; // the conversion scale
/* output vector data, e.g. as a rudimentary EPS file */ /* output vector data, e.g. as a rudimentary EPS file */
CreateOutputFile( info );
break; break;
case '1': case 1:
info.m_Format = EESCHEMA_FMT; info.m_Format = EESCHEMA_FMT;
info.m_ScaleX = info.m_ScaleY = 1000.0 / 300; // the conversion scale info.m_ScaleX = 1000.0 / 300; // the conversion scale
info.m_ScaleY = - info.m_ScaleX; // Y axis is bottom to Top for components in libs
CreateOutputFile( info );
break; break;
case '0': case 0:
info.m_Format = PCBNEW_FMT; info.m_Format = PCBNEW_FMT;
info.m_ScaleX = 10000.0 / 300; // the conversion scale info.m_ScaleX = 10000.0 / 300; // the conversion scale
info.m_ScaleY = -info.m_ScaleX; // Y axis is top to bottom in modedit info.m_ScaleY = info.m_ScaleX; // Y axis is top to bottom in modedit
CreateOutputFile( info );
break; break;
default: default:
printf( "Unknown output format\n" ); break;
break;
} }
CreateOutputFile( info );
bm_free( potrace_bitmap );
bm_free( aPotrace_bitmap );
potrace_state_free( st ); potrace_state_free( st );
potrace_param_free( param ); potrace_param_free( param );
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment