Commit 3b423cb1 authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew fix Bug #1192203 (I hope ...)

Bitmap2component: add export for .kicad_mod new footprint file format, and export polygon descr for page layout description (.kicad_wks file)
parent 4536e274
......@@ -46,6 +46,7 @@
#define KEYWORD_FRAME_SIZEY wxT( "Bmconverter_Size_y" )
#define KEYWORD_LAST_INPUT_FILE wxT( "Last_input" )
#define KEYWORD_LAST_OUTPUT_FILE wxT( "Last_output" )
#define KEYWORD_LAST_FORMAT wxT( "Last_format" )
#define KEYWORD_BINARY_THRESHOLD wxT( "Threshold" )
#define KEYWORD_BW_NEGATIVE wxT( "Negative_choice" )
......@@ -79,8 +80,32 @@ private:
void OnPaint( wxPaintEvent& event );
void OnLoadFile( wxCommandEvent& event );
bool LoadFile( wxString& aFullFileName );
void OnExportEeschema( wxCommandEvent& event );
void OnExportPcbnew( wxCommandEvent& event );
void OnExport( wxCommandEvent& event );
/**
* Generate a schematic library which comtains one component:
* the logo
*/
void OnExportEeschema();
/**
* Depending on the option:
* Legacy format: generate a module library which comtains one component
* New kicad_mod format: generate a module in S expr format
*/
void OnExportPcbnew( bool aLegacyFormat );
/**
* Generate a postscript file
*/
void OnExportPostScript();
/**
* Generate a file suitable to be copied into a page layout
* description file (.kicad_wks file
*/
void OnExportLogo();
void Binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
void OnOptionsSelection( wxCommandEvent& event );
void OnThresholdChange( wxScrollEvent& event );
......@@ -104,6 +129,9 @@ BM2CMP_FRAME::BM2CMP_FRAME() : BM2CMP_FRAME_BASE( NULL )
if( m_Config->Read( KEYWORD_BW_NEGATIVE, &tmp ) )
m_rbOptions->SetSelection( tmp ? 1 : 0 );
m_Config->Read( KEYWORD_LAST_FORMAT, &tmp );
m_radioBoxFormat->SetSelection( tmp );
// Give an icon
wxIcon icon;
......@@ -114,8 +142,7 @@ BM2CMP_FRAME::BM2CMP_FRAME() : BM2CMP_FRAME_BASE( NULL )
SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y );
m_buttonExportEeschema->Enable( false );
m_buttonExportPcbnew->Enable( false );
m_buttonExport->Enable( false );
if ( m_FramePos == wxDefaultPosition )
Centre();
......@@ -138,6 +165,7 @@ BM2CMP_FRAME::~BM2CMP_FRAME()
m_Config->Write( KEYWORD_LAST_OUTPUT_FILE, m_ConvertedFileName );
m_Config->Write( KEYWORD_BINARY_THRESHOLD, m_sliderThreshold->GetValue() );
m_Config->Write( KEYWORD_BW_NEGATIVE, m_rbOptions->GetSelection() );
m_Config->Write( KEYWORD_LAST_FORMAT, m_radioBoxFormat->GetSelection() );
delete m_Config;
......@@ -198,8 +226,7 @@ void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event )
if( ! LoadFile( fullFilename ) )
return;
m_buttonExportEeschema->Enable( true );
m_buttonExportPcbnew->Enable( true );
m_buttonExport->Enable( true );
SetStatusText( fullFilename );
Refresh();
}
......@@ -300,8 +327,103 @@ void BM2CMP_FRAME::OnThresholdChange( wxScrollEvent& event )
Refresh();
}
void BM2CMP_FRAME::OnExport( wxCommandEvent& event )
{
int sel = m_radioBoxFormat->GetSelection();
switch( sel )
{
case 0:
OnExportEeschema();
break;
case 1:
OnExportPcbnew( true );
break;
case 2:
OnExportPcbnew( false );
break;
case 3:
OnExportPostScript();
break;
case 4:
OnExportLogo();
break;
}
}
void BM2CMP_FRAME::OnExportLogo()
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
path = ::wxGetCwd();
wxString msg = _( "Logo file (*.kicad_wks)|*.kicad_wks" );
wxFileDialog FileDlg( this, _( "Create a logo file" ), path, wxEmptyString,
msg,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
int diag = FileDlg.ShowModal();
if( diag != wxID_OK )
return;
m_ConvertedFileName = FileDlg.GetPath();
FILE* outfile;
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
if( outfile == NULL )
{
wxString msg;
msg.Printf( _( "File %s could not be created" ), m_ConvertedFileName.c_str() );
wxMessageBox( msg );
return;
}
ExportFile( outfile, 4 );
fclose( outfile );
}
void BM2CMP_FRAME::OnExportPostScript()
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
if( path.IsEmpty() || !wxDirExists(path) )
path = ::wxGetCwd();
wxString msg = _( "Postscript file (*.ps)|*.ps" );
wxFileDialog FileDlg( this, _( "Create a Postscript file" ), path, wxEmptyString,
msg,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
int diag = FileDlg.ShowModal();
if( diag != wxID_OK )
return;
m_ConvertedFileName = FileDlg.GetPath();
FILE* outfile;
outfile = wxFopen( m_ConvertedFileName, wxT( "w" ) );
if( outfile == NULL )
{
wxString msg;
msg.Printf( _( "File %s could not be created" ), m_ConvertedFileName.c_str() );
wxMessageBox( msg );
return;
}
ExportFile( outfile, 3 );
fclose( outfile );
}
void BM2CMP_FRAME::OnExportEeschema( wxCommandEvent& event )
void BM2CMP_FRAME::OnExportEeschema()
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
......@@ -331,12 +453,12 @@ void BM2CMP_FRAME::OnExportEeschema( wxCommandEvent& event )
return;
}
ExportFile( outfile, 1 );
ExportFile( outfile, 2 );
fclose( outfile );
}
void BM2CMP_FRAME::OnExportPcbnew( wxCommandEvent& event )
void BM2CMP_FRAME::OnExportPcbnew( bool aLegacyFormat )
{
wxFileName fn(m_ConvertedFileName);
wxString path = fn.GetPath();
......@@ -344,7 +466,9 @@ void BM2CMP_FRAME::OnExportPcbnew( wxCommandEvent& event )
if( path.IsEmpty() || !wxDirExists(path) )
path = ::wxGetCwd();
wxString msg = _( "Footprint file (*.mod;*.emp)|*.mod;*.emp" );
wxString msg = aLegacyFormat ?
_( "Footprint file (*.emp)|*.emp" ) :
_( "Footprint file (*.kicad_mod)|*.kicad_mod" );
wxFileDialog FileDlg( this, _( "Create a footprint file for PcbNew" ),
path, wxEmptyString,
msg,
......@@ -368,7 +492,7 @@ void BM2CMP_FRAME::OnExportPcbnew( wxCommandEvent& event )
return;
}
ExportFile( outfile, 0 );
ExportFile( outfile, aLegacyFormat ? 0 : 1 );
fclose( outfile );
}
......
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// C++ code generated with wxFormBuilder (version Oct 8 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
......@@ -47,77 +47,82 @@ BM2CMP_FRAME_BASE::BM2CMP_FRAME_BASE( wxWindow* parent, wxWindowID id, const wxS
m_staticTextSizeX = new wxStaticText( m_panelRight, wxID_ANY, _("Size X:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextSizeX->Wrap( -1 );
fgSizerInfo->Add( m_staticTextSizeX, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_staticTextSizeX, 0, wxALIGN_RIGHT|wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_SizeXValue = new wxStaticText( m_panelRight, wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 );
m_SizeXValue->Wrap( -1 );
fgSizerInfo->Add( m_SizeXValue, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_SizeXValue, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_SizeXunits = new wxStaticText( m_panelRight, wxID_ANY, _("pixels"), wxDefaultPosition, wxDefaultSize, 0 );
m_SizeXunits->Wrap( -1 );
fgSizerInfo->Add( m_SizeXunits, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_SizeXunits, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
m_staticTextSizeY = new wxStaticText( m_panelRight, wxID_ANY, _("Size Y:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextSizeY->Wrap( -1 );
fgSizerInfo->Add( m_staticTextSizeY, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_staticTextSizeY, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
m_SizeYValue = new wxStaticText( m_panelRight, wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 );
m_SizeYValue->Wrap( -1 );
fgSizerInfo->Add( m_SizeYValue, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_SizeYValue, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
m_SizeYunits = new wxStaticText( m_panelRight, wxID_ANY, _("pixels"), wxDefaultPosition, wxDefaultSize, 0 );
m_SizeYunits->Wrap( -1 );
fgSizerInfo->Add( m_SizeYunits, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_SizeYunits, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
m_staticTextBPP = new wxStaticText( m_panelRight, wxID_ANY, _("BPP:"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticTextBPP->Wrap( -1 );
fgSizerInfo->Add( m_staticTextBPP, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_staticTextBPP, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
m_BPPValue = new wxStaticText( m_panelRight, wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 );
m_BPPValue->Wrap( -1 );
fgSizerInfo->Add( m_BPPValue, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_BPPValue, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
m_BPPunits = new wxStaticText( m_panelRight, wxID_ANY, _("bits"), wxDefaultPosition, wxDefaultSize, 0 );
m_BPPunits->Wrap( -1 );
fgSizerInfo->Add( m_BPPunits, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
fgSizerInfo->Add( m_BPPunits, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
sbSizerInfo->Add( fgSizerInfo, 0, wxEXPAND|wxBOTTOM, 5 );
brightSizer->Add( sbSizerInfo, 0, wxEXPAND|wxALL, 5 );
m_buttonLoad = new wxButton( m_panelRight, wxID_ANY, _("Load Bitmap"), wxDefaultPosition, wxDefaultSize, 0 );
brightSizer->Add( m_buttonLoad, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
brightSizer->Add( sbSizerInfo, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_buttonExportEeschema = new wxButton( m_panelRight, wxID_ANY, _("Export to Eeschema"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonExportEeschema->SetToolTip( _("Create a library file for Eeschema\nThis library contains only one component: logo") );
m_buttonLoad = new wxButton( m_panelRight, wxID_ANY, _("Load Bitmap"), wxDefaultPosition, wxDefaultSize, 0 );
brightSizer->Add( m_buttonLoad, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
brightSizer->Add( m_buttonExportEeschema, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
m_buttonExport = new wxButton( m_panelRight, wxID_ANY, _("Export"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonExport->SetToolTip( _("Create a library file for Eeschema\nThis library contains only one component: logo") );
m_buttonExportPcbnew = new wxButton( m_panelRight, wxID_ANY, _("Export to Pcbnew"), wxDefaultPosition, wxDefaultSize, 0 );
m_buttonExportPcbnew->SetToolTip( _("Create a footprint file for PcbNew\nThis footprint contains only one footprint: logo") );
brightSizer->Add( m_buttonExport, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
brightSizer->Add( m_buttonExportPcbnew, 0, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 5 );
wxString m_radioBoxFormatChoices[] = { _("Eeschema"), _("Pcbnew old fmt (.emp)"), _("Pcbnew kicad_mod"), _("Postscript"), _("Logo for title block") };
int m_radioBoxFormatNChoices = sizeof( m_radioBoxFormatChoices ) / sizeof( wxString );
m_radioBoxFormat = new wxRadioBox( m_panelRight, wxID_ANY, _("Format"), wxDefaultPosition, wxDefaultSize, m_radioBoxFormatNChoices, m_radioBoxFormatChoices, 1, wxRA_SPECIFY_COLS );
m_radioBoxFormat->SetSelection( 4 );
brightSizer->Add( m_radioBoxFormat, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
wxString m_rbOptionsChoices[] = { _("Normal"), _("Negative") };
int m_rbOptionsNChoices = sizeof( m_rbOptionsChoices ) / sizeof( wxString );
m_rbOptions = new wxRadioBox( m_panelRight, 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 );
brightSizer->Add( m_rbOptions, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_ThresholdText = new wxStaticText( m_panelRight, wxID_ANY, _("Threshold Value:"), wxDefaultPosition, wxDefaultSize, 0 );
m_ThresholdText->Wrap( -1 );
brightSizer->Add( m_ThresholdText, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
brightSizer->Add( m_ThresholdText, 0, wxRIGHT|wxLEFT, 5 );
m_sliderThreshold = new wxSlider( m_panelRight, wxID_ANY, 25, 0, 50, wxDefaultPosition, wxDefaultSize, wxSL_AUTOTICKS|wxSL_HORIZONTAL|wxSL_TOP );
m_sliderThreshold = new wxSlider( m_panelRight, 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.") );
brightSizer->Add( m_sliderThreshold, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_panelRight->SetSizer( brightSizer );
m_panelRight->Layout();
brightSizer->Fit( m_panelRight );
bMainSizer->Add( m_panelRight, 0, wxEXPAND, 0 );
this->SetSizer( bMainSizer );
this->Layout();
m_statusBar = this->CreateStatusBar( 1, wxST_SIZEGRIP, wxID_ANY );
......@@ -127,8 +132,7 @@ BM2CMP_FRAME_BASE::BM2CMP_FRAME_BASE( wxWindow* parent, wxWindowID id, const wxS
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_buttonExport->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnExport ), 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 );
}
......@@ -140,8 +144,7 @@ BM2CMP_FRAME_BASE::~BM2CMP_FRAME_BASE()
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_buttonExport->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnExport ), 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 source diff could not be displayed because it is too large. You can view the blob instead.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep 8 2010)
// C++ code generated with wxFormBuilder (version Oct 8 2012)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __bitmap2cmp_gui_base__
#define __bitmap2cmp_gui_base__
#ifndef __BITMAP2CMP_GUI_BASE_H__
#define __BITMAP2CMP_GUI_BASE_H__
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/intl.h>
#include <wx/scrolwin.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
......@@ -56,8 +57,8 @@ class BM2CMP_FRAME_BASE : public wxFrame
wxStaticText* m_BPPValue;
wxStaticText* m_BPPunits;
wxButton* m_buttonLoad;
wxButton* m_buttonExportEeschema;
wxButton* m_buttonExportPcbnew;
wxButton* m_buttonExport;
wxRadioBox* m_radioBoxFormat;
wxRadioBox* m_rbOptions;
wxStaticText* m_ThresholdText;
wxSlider* m_sliderThreshold;
......@@ -66,17 +67,17 @@ class BM2CMP_FRAME_BASE : public wxFrame
// 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 OnExport( 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|wxRESIZE_BORDER|wxTAB_TRAVERSAL );
BM2CMP_FRAME_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Bitmap to Component Converter"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 527,470 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxTAB_TRAVERSAL );
~BM2CMP_FRAME_BASE();
};
#endif //__bitmap2cmp_gui_base__
#endif //__BITMAP2CMP_GUI_BASE_H__
/*
* 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.
* Copyright (C) 1992-2013 jean-pierre.charras
* Copyright (C) 1992-2013 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
......@@ -22,8 +22,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <cmath>
#include <algorithm> // std::max
// For some unknown reasons, polygon.hpp shoul be included first
// For some unknown reasons, polygon.hpp should be included first
#include <boost/polygon/polygon.hpp>
#include <wx/wx.h>
......@@ -38,13 +39,6 @@
#include <auxiliary.h>
#ifndef max
#define max( a, b ) ( ( (a) > (b) ) ? (a) : (b) )
#endif
#ifndef min
#define min( a, b ) ( ( (a) < (b) ) ? (a) : (b) )
#endif
// Define some types used here from boost::polygon
namespace bpl = boost::polygon; // bpl = boost polygon library
using namespace bpl::operators; // +, -, =, ...
......@@ -58,9 +52,12 @@ typedef bpl::point_data<coordinate_type> KPolyPoint; // define a corner o
enum output_format {
POSTSCRIPT_FMT = 1,
PCBNEW_FMT,
EESCHEMA_FMT
PCBNEW_LEGACY_EMP,
PCBNEW_KICAD_MOD,
EESCHEMA_FMT,
KICAD_LOGO
};
/* free a potrace bitmap */
static void bm_free( potrace_bitmap_t* bm )
{
......@@ -172,22 +169,37 @@ int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile, int aFo
switch( aFormat )
{
case 2:
case 4:
info.m_Format = KICAD_LOGO;
info.m_ScaleX = 1e3 * 25.4 / 300; // the conversion scale from PPI to micro
info.m_ScaleY = info.m_ScaleX; // Y axis is top to bottom
info.CreateOutputFile();
break;
case 3:
info.m_Format = POSTSCRIPT_FMT;
info.m_ScaleX = info.m_ScaleY = 1.0; // the conversion scale
info.m_ScaleX = 1.0; // the conversion scale
info.m_ScaleY = info.m_ScaleX;
// output vector data, e.g. as a rudimentary EPS file (mainly for tests)
info.CreateOutputFile();
break;
case 1:
case 2:
info.m_Format = EESCHEMA_FMT;
info.m_ScaleX = 1000.0 / 300; // the conversion scale
info.m_ScaleX = 1000.0 / 300; // the conversion scale from PPI to UI
info.m_ScaleY = -info.m_ScaleX; // Y axis is bottom to Top for components in libs
info.CreateOutputFile();
break;
case 1:
info.m_Format = PCBNEW_KICAD_MOD;
info.m_ScaleX = 1e6 * 25.4 / 300; // the conversion scale from PPI to UI
info.m_ScaleY = info.m_ScaleX; // Y axis is top to bottom in modedit
info.CreateOutputFile();
break;
case 0:
info.m_Format = PCBNEW_FMT;
info.m_Format = PCBNEW_LEGACY_EMP;
info.m_ScaleX = 10000.0 / 300; // the conversion scale
info.m_ScaleY = info.m_ScaleX; // Y axis is top to bottom in modedit
info.CreateOutputFile();
......@@ -221,7 +233,7 @@ void BITMAPCONV_INFO::OuputFileHeader()
fprintf( m_Outfile, "gsave\n" );
break;
case PCBNEW_FMT:
case PCBNEW_LEGACY_EMP:
#define FIELD_LAYER 21
fieldSize = 600; // fields text size = 60 mils
Ypos += fieldSize / 2;
......@@ -240,6 +252,22 @@ void BITMAPCONV_INFO::OuputFileHeader()
-Ypos, fieldSize, fieldSize, fieldSize / 5, FIELD_LAYER, m_CmpName );
break;
case PCBNEW_KICAD_MOD:
// fields text size = 1.5 mm
// fields text thickness = 1.5 / 5 = 0.3mm
fprintf( m_Outfile, "(module %s (layer F.Cu)\n (at 0 0)\n",
m_CmpName );
fprintf( m_Outfile, " (fp_text reference \"G***\" (at 0 0) (layer F.SilkS) hide\n"
" (effects (font (thickness 0.3)))\n )\n" );
fprintf( m_Outfile, " (fp_text value \"%s\" (at 0.75 0) (layer F.SilkS) hide\n"
" (effects (font (thickness 0.3)))\n )\n",
m_CmpName );
break;
case KICAD_LOGO:
fprintf( m_Outfile, "(polygon (pos 0 0 rbcorner) (rotate 0) (linewidth 0.01)\n" );
break;
case EESCHEMA_FMT:
fprintf( m_Outfile, "EESchema-LIBRARY Version 2.3\n" );
fprintf( m_Outfile, "#\n# %s\n", m_CmpName );
......@@ -267,11 +295,19 @@ void BITMAPCONV_INFO::OuputFileEnd()
fprintf( m_Outfile, "%%EOF\n" );
break;
case PCBNEW_FMT:
case PCBNEW_LEGACY_EMP:
fprintf( m_Outfile, "$EndMODULE %s\n", m_CmpName );
fprintf( m_Outfile, "$EndLIBRARY\n" );
break;
case PCBNEW_KICAD_MOD:
fprintf( m_Outfile, ")\n" );
break;
case KICAD_LOGO:
fprintf( m_Outfile, ")\n" );
break;
case EESCHEMA_FMT:
fprintf( m_Outfile, "ENDDRAW\n" );
fprintf( m_Outfile, "ENDDEF\n" );
......@@ -282,11 +318,11 @@ void BITMAPCONV_INFO::OuputFileEnd()
/**
* Function OuputOnePolygon
* write one polygon to output file.
* Polygon coordinates are expected scaled by the polugon extraction function
* Polygon coordinates are expected scaled by the polygon extraction function
*/
void BITMAPCONV_INFO::OuputOnePolygon( KPolygon & aPolygon )
{
unsigned ii;
unsigned ii, jj;
KPolyPoint currpoint;
int offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX );
......@@ -297,19 +333,27 @@ void BITMAPCONV_INFO::OuputOnePolygon( KPolygon & aPolygon )
switch( m_Format )
{
case POSTSCRIPT_FMT:
fprintf( m_Outfile, "%d %d moveto\n",
startpoint.x(), startpoint.y() );
offsetY = (int)( m_PixmapHeight * m_ScaleY );
fprintf( m_Outfile, "newpath\n%d %d moveto\n",
startpoint.x(), offsetY - startpoint.y() );
jj = 0;
for( ii = 1; ii < aPolygon.size(); ii++ )
{
currpoint = *(aPolygon.begin() + ii);
fprintf( m_Outfile, "%d %d lineto\n",
currpoint.x(), currpoint.y() );
fprintf( m_Outfile, " %d %d lineto",
currpoint.x(), offsetY - currpoint.y() );
if( jj++ > 6 )
{
jj = 0;
fprintf( m_Outfile, ("\n") );
}
}
fprintf( m_Outfile, "0 setgray fill\n" );
fprintf( m_Outfile, "\nclosepath fill\n" );
break;
case PCBNEW_FMT:
case PCBNEW_LEGACY_EMP:
{
LAYER_NUM layer = SILKSCREEN_N_FRONT;
int width = 1;
......@@ -330,6 +374,54 @@ void BITMAPCONV_INFO::OuputOnePolygon( KPolygon & aPolygon )
}
break;
case PCBNEW_KICAD_MOD:
{
double width = 0.1;
fprintf( m_Outfile, " (fp_poly (pts" );
jj = 0;
for( ii = 0; ii < aPolygon.size(); ii++ )
{
currpoint = *( aPolygon.begin() + ii );
fprintf( m_Outfile, " (xy %f %f)",
(currpoint.x() - offsetX) / 1e6,
(currpoint.y() - offsetY) / 1e6 );
if( jj++ > 6 )
{
jj = 0;
fprintf( m_Outfile, ("\n ") );
}
}
// Close polygon
fprintf( m_Outfile, " (xy %f %f) )",
(startpoint.x() - offsetX) / 1e6, (startpoint.y() - offsetY) / 1e6 );
fprintf( m_Outfile, "(layer F.SilkS) (width %f)\n )\n", width );
}
break;
case KICAD_LOGO:
fprintf( m_Outfile, " (pts" );
// Internal units = micron, file unit = mm
jj = 0;
for( ii = 0; ii < aPolygon.size(); ii++ )
{
currpoint = *( aPolygon.begin() + ii );
fprintf( m_Outfile, " (xy %.3f %.3f)",
(currpoint.x() - offsetX) / 1e3,
(currpoint.y() - offsetY) / 1e3 );
if( jj++ > 4 )
{
jj = 0;
fprintf( m_Outfile, ("\n ") );
}
}
// Close polygon
fprintf( m_Outfile, " (xy %.3f %.3f) )\n",
(startpoint.x() - offsetX) / 1e3, (startpoint.y() - offsetY) / 1e3 );
break;
case EESCHEMA_FMT:
fprintf( m_Outfile, "P %d 0 0 1", (int) aPolygon.size() + 1 );
for( ii = 0; ii < aPolygon.size(); ii++ )
......@@ -363,6 +455,9 @@ void BITMAPCONV_INFO::CreateOutputFile()
KPolygonSet polyset_holes;
potrace_dpoint_t( *c )[3];
setlocale( LC_NUMERIC, "C" ); // Switch the locale to standard C
OuputFileHeader();
bool main_outline = true;
......@@ -451,6 +546,8 @@ void BITMAPCONV_INFO::CreateOutputFile()
}
OuputFileEnd();
setlocale( LC_NUMERIC, "" ); // revert to the current locale
}
......
......@@ -954,8 +954,9 @@ wxString ZONE_CONTAINER::GetSelectMenuText() const
}
}
text.Printf( _( "Zone Outline %s on %s" ), GetChars( text ),
wxString msg;
msg.Printf( _( "Zone Outline %s on %s" ), GetChars( text ),
GetChars( GetLayerName() ) );
return text;
return msg;
}
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