2010-06-15 18:45:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1992-2010 jean-pierre.charras
|
|
|
|
* Copyright (C) 1992-2010 Kicad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
2011-08-16 18:32:56 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
#include <wx/config.h>
|
|
|
|
#include <wx/filename.h>
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <bitmap2cmp_gui_base.h>
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <potracelib.h>
|
|
|
|
#include <bitmap_io.h>
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <colors_selection.h>
|
|
|
|
#include <build_version.h>
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2010-06-21 16:15:05 +00:00
|
|
|
#define KEYWORD_FRAME_POSX wxT( "Bmconverter_Pos_x" )
|
|
|
|
#define KEYWORD_FRAME_POSY wxT( "Bmconverter_Pos_y" )
|
|
|
|
#define KEYWORD_FRAME_SIZEX wxT( "Bmconverter_Size_x" )
|
|
|
|
#define KEYWORD_FRAME_SIZEY wxT( "Bmconverter_Size_y" )
|
|
|
|
#define KEYWORD_LAST_INPUT_FILE wxT( "Last_input" )
|
|
|
|
#define KEYWORD_LAST_OUTPUT_FILE wxT( "Last_output" )
|
2011-10-26 09:53:42 +00:00
|
|
|
#define KEYWORD_BINARY_THRESHOLD wxT( "Threshold" )
|
|
|
|
#define KEYWORD_BW_NEGATIVE wxT( "Negative_choice" )
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
extern int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile, int aFormat );
|
|
|
|
|
|
|
|
/* Class BM2CMP_FRAME_BASE
|
|
|
|
This is the main frame for this application
|
|
|
|
*/
|
|
|
|
class BM2CMP_FRAME : public BM2CMP_FRAME_BASE
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
wxImage m_Pict_Image;
|
|
|
|
wxBitmap m_Pict_Bitmap;
|
|
|
|
wxImage m_Greyscale_Image;
|
|
|
|
wxBitmap m_Greyscale_Bitmap;
|
|
|
|
wxImage m_NB_Image;
|
|
|
|
wxBitmap m_BN_Bitmap;
|
2010-06-21 16:15:05 +00:00
|
|
|
wxString m_BitmapFileName;
|
|
|
|
wxString m_ConvertedFileName;
|
2010-06-15 18:45:22 +00:00
|
|
|
wxSize m_FrameSize;
|
|
|
|
wxPoint m_FramePos;
|
|
|
|
wxConfig * m_Config;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BM2CMP_FRAME();
|
|
|
|
~BM2CMP_FRAME();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
void OnPaint( wxPaintEvent& event );
|
|
|
|
void OnLoadFile( wxCommandEvent& event );
|
2010-07-11 16:24:44 +00:00
|
|
|
bool LoadFile( wxString& aFullFileName );
|
2010-06-15 18:45:22 +00:00
|
|
|
void OnExportEeschema( wxCommandEvent& event );
|
|
|
|
void OnExportPcbnew( wxCommandEvent& event );
|
2010-06-25 19:02:39 +00:00
|
|
|
void Binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
|
2012-01-23 04:33:36 +00:00
|
|
|
void OnOptionsSelection( wxCommandEvent& event );
|
|
|
|
void OnThresholdChange( wxScrollEvent& event );
|
2010-06-15 18:45:22 +00:00
|
|
|
void NegateGreyscaleImage( );
|
|
|
|
void ExportFile( FILE* aOutfile, int aFormat );
|
|
|
|
};
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
BM2CMP_FRAME::BM2CMP_FRAME() : BM2CMP_FRAME_BASE( NULL )
|
|
|
|
{
|
2011-10-26 09:53:42 +00:00
|
|
|
int tmp;
|
2010-06-15 18:45:22 +00:00
|
|
|
m_Config = new wxConfig();
|
|
|
|
m_Config->Read( KEYWORD_FRAME_POSX, & m_FramePos.x, -1 );
|
|
|
|
m_Config->Read( KEYWORD_FRAME_POSY, & m_FramePos.y, -1 );
|
|
|
|
m_Config->Read( KEYWORD_FRAME_SIZEX, & m_FrameSize.x, -1 );
|
|
|
|
m_Config->Read( KEYWORD_FRAME_SIZEY, & m_FrameSize.y, -1 );
|
2010-06-21 16:15:05 +00:00
|
|
|
m_Config->Read( KEYWORD_LAST_INPUT_FILE, &m_BitmapFileName );
|
|
|
|
m_Config->Read( KEYWORD_LAST_OUTPUT_FILE, &m_ConvertedFileName );
|
2011-10-26 09:53:42 +00:00
|
|
|
if( m_Config->Read( KEYWORD_BINARY_THRESHOLD, &tmp ) )
|
|
|
|
m_sliderThreshold->SetValue( tmp );
|
|
|
|
if( m_Config->Read( KEYWORD_BW_NEGATIVE, &tmp ) )
|
|
|
|
m_rbOptions->SetSelection( tmp ? 1 : 0 );
|
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2011-09-09 19:30:59 +00:00
|
|
|
// Give an icon
|
|
|
|
wxIcon icon;
|
|
|
|
icon.CopyFromBitmap( KiBitmap( icon_bitmap2component_xpm ) );
|
|
|
|
SetIcon( icon );
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
GetSizer()->SetSizeHints( this );
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
m_buttonExportEeschema->Enable( false );
|
|
|
|
m_buttonExportPcbnew->Enable( false );
|
2010-07-11 16:24:44 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
if ( m_FramePos == wxDefaultPosition )
|
|
|
|
Centre();
|
|
|
|
}
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
BM2CMP_FRAME::~BM2CMP_FRAME()
|
|
|
|
{
|
|
|
|
if( ( m_Config == NULL ) || IsIconized() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_FrameSize = GetSize();
|
|
|
|
m_FramePos = GetPosition();
|
|
|
|
|
|
|
|
m_Config->Write( KEYWORD_FRAME_POSX, (long) m_FramePos.x );
|
|
|
|
m_Config->Write( KEYWORD_FRAME_POSY, (long) m_FramePos.y );
|
|
|
|
m_Config->Write( KEYWORD_FRAME_SIZEX, (long) m_FrameSize.x );
|
|
|
|
m_Config->Write( KEYWORD_FRAME_SIZEY, (long) m_FrameSize.y );
|
2010-06-21 16:15:05 +00:00
|
|
|
m_Config->Write( KEYWORD_LAST_INPUT_FILE, m_BitmapFileName );
|
|
|
|
m_Config->Write( KEYWORD_LAST_OUTPUT_FILE, m_ConvertedFileName );
|
2011-10-26 09:53:42 +00:00
|
|
|
m_Config->Write( KEYWORD_BINARY_THRESHOLD, m_sliderThreshold->GetValue() );
|
|
|
|
m_Config->Write( KEYWORD_BW_NEGATIVE, m_rbOptions->GetSelection() );
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
delete m_Config;
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
/* This needed for OSX: avoids further OnDraw processing after this
|
2010-06-15 18:45:22 +00:00
|
|
|
* destructor and before the native window is destroyed
|
|
|
|
*/
|
|
|
|
this->Freeze( );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnPaint( wxPaintEvent& event )
|
|
|
|
{
|
2010-12-27 14:01:52 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
// Otherwise fails due: using wxPaintDC without being in a native paint event
|
|
|
|
wxClientDC pict_dc( m_InitialPicturePanel );
|
|
|
|
wxClientDC greyscale_dc( m_GreyscalePicturePanel );
|
|
|
|
wxClientDC nb_dc( m_BNPicturePanel );
|
|
|
|
#else
|
2010-06-15 18:45:22 +00:00
|
|
|
wxPaintDC pict_dc( m_InitialPicturePanel );
|
|
|
|
wxPaintDC greyscale_dc( m_GreyscalePicturePanel );
|
|
|
|
wxPaintDC nb_dc( m_BNPicturePanel );
|
2010-12-27 14:01:52 +00:00
|
|
|
#endif
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
m_InitialPicturePanel->PrepareDC( pict_dc );
|
|
|
|
m_GreyscalePicturePanel->PrepareDC( greyscale_dc );
|
|
|
|
m_BNPicturePanel->PrepareDC( nb_dc );
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-12-27 14:01:52 +00:00
|
|
|
// OSX crashes with empty bitmaps (on initial refreshes)
|
|
|
|
if(m_Pict_Bitmap.IsOk() && m_Greyscale_Bitmap.IsOk() && m_BN_Bitmap.IsOk())
|
|
|
|
{
|
|
|
|
pict_dc.DrawBitmap( m_Pict_Bitmap, 0, 0, false );
|
|
|
|
greyscale_dc.DrawBitmap( m_Greyscale_Bitmap, 0, 0, false );
|
|
|
|
nb_dc.DrawBitmap( m_BN_Bitmap, 0, 0, false );
|
|
|
|
}
|
2010-06-15 18:45:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
/* Called to load a bitmap file
|
|
|
|
*/
|
|
|
|
void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event )
|
|
|
|
{
|
2010-06-21 16:15:05 +00:00
|
|
|
wxFileName fn(m_BitmapFileName);
|
|
|
|
wxString path = fn.GetPath();
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-21 16:15:05 +00:00
|
|
|
if( path.IsEmpty() || !wxDirExists(path) )
|
|
|
|
path = wxGetCwd();
|
|
|
|
|
|
|
|
wxFileDialog FileDlg( this, _( "Choose Image" ), path, wxEmptyString,
|
2010-06-15 18:45:22 +00:00
|
|
|
_( "Image Files " ) + wxImage::GetImageExtWildcard(),
|
|
|
|
wxFD_OPEN );
|
|
|
|
int diag = FileDlg.ShowModal();
|
|
|
|
|
|
|
|
if( diag != wxID_OK )
|
|
|
|
return;
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
wxString fullFilename = FileDlg.GetPath();
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
if( ! LoadFile( fullFilename ) )
|
|
|
|
return;
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
m_buttonExportEeschema->Enable( true );
|
|
|
|
m_buttonExportPcbnew->Enable( true );
|
2010-07-11 16:24:44 +00:00
|
|
|
SetStatusText( fullFilename );
|
|
|
|
Refresh();
|
|
|
|
}
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
bool BM2CMP_FRAME::LoadFile( wxString& aFullFileName )
|
|
|
|
{
|
|
|
|
m_BitmapFileName = aFullFileName;
|
2010-06-21 16:15:05 +00:00
|
|
|
|
|
|
|
if( !m_Pict_Image.LoadFile( m_BitmapFileName ) )
|
2010-06-15 18:45:22 +00:00
|
|
|
{
|
2010-06-21 16:15:05 +00:00
|
|
|
wxMessageBox( _( "Couldn't load image from <%s>" ), m_BitmapFileName.c_str() );
|
2010-07-11 16:24:44 +00:00
|
|
|
return false;
|
2010-06-15 18:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_Pict_Bitmap = wxBitmap( m_Pict_Image );
|
|
|
|
|
|
|
|
int h = m_Pict_Bitmap.GetHeight();
|
|
|
|
int w = m_Pict_Bitmap.GetWidth();
|
|
|
|
int nb = m_Pict_Bitmap.GetDepth();
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "%d" ), w );
|
2010-07-11 16:24:44 +00:00
|
|
|
m_SizeXValue->SetLabel(msg);
|
|
|
|
msg.Printf( wxT( "%d" ), h );
|
|
|
|
m_SizeYValue->SetLabel(msg);
|
2010-06-15 18:45:22 +00:00
|
|
|
msg.Printf( wxT( "%d" ), nb );
|
2010-07-11 16:24:44 +00:00
|
|
|
m_BPPValue->SetLabel(msg);
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
m_InitialPicturePanel->SetVirtualSize( w, h );
|
|
|
|
m_GreyscalePicturePanel->SetVirtualSize( w, h );
|
|
|
|
m_BNPicturePanel->SetVirtualSize( w, h );
|
|
|
|
|
|
|
|
m_Greyscale_Image.Destroy();
|
|
|
|
m_Greyscale_Image = m_Pict_Image.ConvertToGreyscale( );
|
|
|
|
if( m_rbOptions->GetSelection() > 0 )
|
|
|
|
NegateGreyscaleImage( );
|
|
|
|
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
|
|
|
|
|
|
|
|
m_NB_Image = m_Greyscale_Image;
|
2010-06-25 19:02:39 +00:00
|
|
|
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2010-07-11 16:24:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-25 19:02:39 +00:00
|
|
|
void BM2CMP_FRAME::Binarize( double aThreshold )
|
2010-06-15 18:45:22 +00:00
|
|
|
{
|
|
|
|
unsigned int pixin;
|
|
|
|
unsigned char pixout;
|
|
|
|
int h = m_Greyscale_Image.GetHeight();
|
|
|
|
int w = m_Greyscale_Image.GetWidth();
|
2010-06-25 19:02:39 +00:00
|
|
|
unsigned int threshold = (int)(aThreshold * 256);
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
for( int y = 1; y < h; y++ )
|
|
|
|
for( int x = 1; x < w; x++ )
|
|
|
|
{
|
|
|
|
pixin = m_Greyscale_Image.GetGreen( x, y );
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
if( pixin < threshold )
|
|
|
|
pixout = 0;
|
|
|
|
else
|
|
|
|
pixout = 255;
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
m_NB_Image.SetRGB( x, y, pixout, pixout, pixout );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_BN_Bitmap = wxBitmap( m_NB_Image );
|
|
|
|
}
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::NegateGreyscaleImage( )
|
|
|
|
{
|
|
|
|
unsigned char pix;
|
|
|
|
int h = m_Greyscale_Image.GetHeight();
|
|
|
|
int w = m_Greyscale_Image.GetWidth();
|
|
|
|
|
|
|
|
for( int y = 1; y < h; y++ )
|
|
|
|
for( int x = 1; x < w; x++ )
|
|
|
|
{
|
|
|
|
pix = m_Greyscale_Image.GetGreen( x, y );
|
|
|
|
pix = ~pix;
|
|
|
|
m_Greyscale_Image.SetRGB( x, y, pix, pix, pix );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called on Normal/Negative change option */
|
|
|
|
void BM2CMP_FRAME::OnOptionsSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
NegateGreyscaleImage( );
|
|
|
|
m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image );
|
2010-06-25 19:02:39 +00:00
|
|
|
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
|
2010-06-15 18:45:22 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnThresholdChange( wxScrollEvent& event )
|
|
|
|
{
|
2010-06-25 19:02:39 +00:00
|
|
|
Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() );
|
2010-06-15 18:45:22 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnExportEeschema( wxCommandEvent& event )
|
|
|
|
{
|
2010-06-21 16:15:05 +00:00
|
|
|
wxFileName fn(m_ConvertedFileName);
|
|
|
|
wxString path = fn.GetPath();
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-21 16:15:05 +00:00
|
|
|
if( path.IsEmpty() || !wxDirExists(path) )
|
|
|
|
path = ::wxGetCwd();
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
wxString msg = _( "Schematic lib file (*.lib)|*.lib" );
|
2010-07-11 16:24:44 +00:00
|
|
|
wxFileDialog FileDlg( this, _( "Create a lib file for Eeschema" ), path, wxEmptyString,
|
2010-06-15 18:45:22 +00:00
|
|
|
msg,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
int diag = FileDlg.ShowModal();
|
|
|
|
|
|
|
|
if( diag != wxID_OK )
|
|
|
|
return;
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-21 16:15:05 +00:00
|
|
|
m_ConvertedFileName = FileDlg.GetPath();
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
FILE* outfile;
|
2010-06-21 16:15:05 +00:00
|
|
|
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
if( outfile == NULL )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2010-06-21 16:15:05 +00:00
|
|
|
msg.Printf( _( "File %s could not be created" ), m_ConvertedFileName.c_str() );
|
2010-06-15 18:45:22 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExportFile( outfile, 1 );
|
|
|
|
fclose( outfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::OnExportPcbnew( wxCommandEvent& event )
|
|
|
|
{
|
2010-06-21 16:15:05 +00:00
|
|
|
wxFileName fn(m_ConvertedFileName);
|
|
|
|
wxString path = fn.GetPath();
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-21 16:15:05 +00:00
|
|
|
if( path.IsEmpty() || !wxDirExists(path) )
|
|
|
|
path = ::wxGetCwd();
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2011-10-25 16:24:56 +00:00
|
|
|
wxString msg = _( "Footprint file (*.mod;*.emp)|*.mod;*.emp" );
|
2010-07-11 16:24:44 +00:00
|
|
|
wxFileDialog FileDlg( this, _( "Create a footprint file for PcbNew" ),
|
|
|
|
path, wxEmptyString,
|
2010-06-15 18:45:22 +00:00
|
|
|
msg,
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
int diag = FileDlg.ShowModal();
|
|
|
|
|
|
|
|
if( diag != wxID_OK )
|
|
|
|
return;
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-21 16:15:05 +00:00
|
|
|
m_ConvertedFileName = FileDlg.GetPath();
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
FILE* outfile;
|
2010-06-21 16:15:05 +00:00
|
|
|
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
if( outfile == NULL )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2010-06-21 16:15:05 +00:00
|
|
|
msg.Printf( _( "File %s could not be created" ), m_ConvertedFileName.c_str() );
|
2010-06-15 18:45:22 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExportFile( outfile, 0 );
|
|
|
|
fclose( outfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
void BM2CMP_FRAME::ExportFile( FILE* aOutfile, int aFormat )
|
|
|
|
{
|
|
|
|
// Create a potrace bitmap
|
|
|
|
int h = m_NB_Image.GetHeight();
|
|
|
|
int w = m_NB_Image.GetWidth();
|
|
|
|
potrace_bitmap_t* potrace_bitmap = bm_new( w, h );
|
2011-09-06 14:09:40 +00:00
|
|
|
|
2010-06-15 18:45:22 +00:00
|
|
|
if( !potrace_bitmap )
|
|
|
|
{
|
|
|
|
wxString msg;
|
2010-06-15 20:17:33 +00:00
|
|
|
msg.Printf( wxT( "Error allocating memory for potrace bitmap" ) );
|
2010-06-15 18:45:22 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill the bitmap with data */
|
|
|
|
for( int y = 0; y<h; y++ )
|
|
|
|
{
|
|
|
|
for( int x = 0; x<w; x++ )
|
|
|
|
{
|
|
|
|
unsigned char pix = m_NB_Image.GetGreen( x, y );
|
|
|
|
BM_PUT( potrace_bitmap, x, y, pix ? 1 : 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmap2component( potrace_bitmap, aOutfile, aFormat );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-26 09:53:42 +00:00
|
|
|
// EDA_APP
|
2010-06-15 18:45:22 +00:00
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
IMPLEMENT_APP( EDA_APP )
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
///-----------------------------------------------------------------------------
|
2011-10-26 09:53:42 +00:00
|
|
|
// EDA_APP
|
2010-06-15 18:45:22 +00:00
|
|
|
// main program
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2011-09-06 14:09:40 +00:00
|
|
|
bool EDA_APP::OnInit()
|
2010-06-15 18:45:22 +00:00
|
|
|
{
|
|
|
|
wxInitAllImageHandlers();
|
|
|
|
|
2011-08-16 18:32:56 +00:00
|
|
|
InitEDA_Appl( wxT( "BMP2CMP" ) );
|
2010-06-15 18:45:22 +00:00
|
|
|
|
|
|
|
wxFrame* frame = new BM2CMP_FRAME();
|
2011-08-16 18:32:56 +00:00
|
|
|
SetTopWindow( frame );
|
2010-06-15 18:45:22 +00:00
|
|
|
frame->Show( true );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-26 09:53:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
void EDA_APP::MacOpenFile(const wxString &fileName)
|
|
|
|
{
|
|
|
|
}
|