33#include <potracelib.h>
37#include <wx/clipbrd.h>
39#include <wx/filedlg.h>
41#include <wx/dcclient.h>
48#define DEFAULT_DPI 300
86 outputDPI = std::max( 1, outputDPI );
150 SetKiway(
this, aKiway );
152 for( wxString unit : {
_(
"mm" ),
_(
"Inch" ),
_(
"DPI" ) } )
153 m_PixelUnit->Append( unit );
157 m_outputSizeX.SetUnit( getUnitFromSelection() );
158 m_outputSizeY.SetUnit( getUnitFromSelection() );
159 m_outputSizeX.SetOutputSize( 0, getUnitFromSelection() );
160 m_outputSizeY.SetOutputSize( 0, getUnitFromSelection() );
162 m_UnitSizeX->ChangeValue( FormatOutputSize( m_outputSizeX.GetOutputSize() ) );
163 m_UnitSizeY->ChangeValue( FormatOutputSize( m_outputSizeY.GetOutputSize() ) );
167 wxIconBundle icon_bundle;
170 icon_bundle.AddIcon( icon );
172 icon_bundle.AddIcon( icon );
174 icon_bundle.AddIcon( icon );
176 SetIcons( icon_bundle );
180 GetSizer()->SetSizeHints(
this );
182 m_buttonExportFile->Enable(
false );
183 m_buttonExportClipboard->Enable(
false );
185 SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
187 if ( m_framePos == wxDefaultPosition )
213 wxMenuBar* oldMenuBar = GetMenuBar();
214 wxMenuBar* menuBar =
new wxMenuBar();
216 wxMenu* fileMenu =
new wxMenu;
218 wxMenuItem* item =
new wxMenuItem( fileMenu, wxID_OPEN,
_(
"Open..." ) + wxT(
"\tCtrl+O" ),
219 _(
"Load source image" ) );
221 fileMenu->Append( item );
225 fileMenu->AppendSeparator();
228 item =
new wxMenuItem( fileMenu, wxID_EXIT,
_(
"Quit" ) + wxT(
"\tCtrl+Q" ),
229 _(
"Quit Image Converter" ) );
231 if(
Pgm().GetCommonSettings()->m_Appearance.use_icons_in_menus )
234 fileMenu->Append( item );
236 menuBar->Append( fileMenu,
_(
"&File" ) );
238 SetMenuBar( menuBar );
260 if( u_select < 0 || u_select > 2 )
369 wxString
path = fn.GetPath();
371 if(
path.IsEmpty() || !wxDirExists(
path ) )
374 wxFileDialog fileDlg(
this,
_(
"Choose Image" ),
path, wxEmptyString,
375 _(
"Image Files" ) + wxS(
" " )+ wxImage::GetImageExtWildcard(),
376 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
378 int diag = fileDlg.ShowModal();
380 if( diag != wxID_OK )
383 wxString fullFilename = fileDlg.GetPath();
390 SetStatusText( fullFilename );
411 int imageDPIx =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
412 int imageDPIy =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
414 if( imageDPIx > 1 && imageDPIy > 1 )
416 if(
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
418 imageDPIx =
KiROUND( imageDPIx * 2.54 );
419 imageDPIy =
KiROUND( imageDPIy * 2.54 );
440 wxCommandEvent
dummy;
493 text.Printf( wxS(
"%.1f" ), aSize );
495 text.Printf( wxS(
"%.2f" ), aSize );
537 if(
m_UnitSizeX->GetValue().ToDouble( &new_size ) )
566 if(
m_UnitSizeY->GetValue().ToDouble( &new_size ) )
607 wxCommandEvent
dummy;
617 unsigned char threshold = aThreshold * 255;
618 unsigned char alpha_thresh = 0.7 * threshold;
620 for(
int y = 0; y < h; y++ )
622 for(
int x = 0; x < w; x++ )
624 unsigned char pixout;
629 if( pixin < threshold && alpha > alpha_thresh )
634 m_NB_Image.SetRGB( x, y, pixout, pixout, pixout );
648 for(
int y = 0; y < h; y++ )
650 for(
int x = 0; x < w; x++ )
703 if( wxTheClipboard->Open() )
707 wxTheClipboard->SetData(
new wxTextDataObject( buffer.c_str() ) );
708 wxTheClipboard->Flush();
709 wxTheClipboard->Close();
713 wxMessageBox(
_(
"Unable to export to the Clipboard") );
733 wxString
path = fn.GetPath();
735 if(
path.IsEmpty() || !wxDirExists(
path) )
738 wxFileDialog fileDlg(
this,
_(
"Create Logo File" ),
path, wxEmptyString,
740 int diag = fileDlg.ShowModal();
742 if( diag != wxID_OK )
745 fn = fileDlg.GetPath();
752 if( outfile ==
nullptr )
762 fputs( buffer.c_str(), outfile );
770 wxString
path = fn.GetPath();
772 if(
path.IsEmpty() || !wxDirExists(
path ) )
775 wxFileDialog fileDlg(
this,
_(
"Create PostScript File" ),
path, wxEmptyString,
778 if( fileDlg.ShowModal() != wxID_OK )
781 fn = fileDlg.GetPath();
782 fn.SetExt( wxT(
"ps" ) );
788 if( outfile ==
nullptr )
798 fputs( buffer.c_str(), outfile );
806 wxString
path = fn.GetPath();
808 if(
path.IsEmpty() || !wxDirExists(
path) )
811 wxFileDialog fileDlg(
this,
_(
"Create Symbol Library" ),
path, wxEmptyString,
814 if( fileDlg.ShowModal() != wxID_OK )
817 fn = fileDlg.GetPath();
823 if( outfile ==
nullptr )
833 fputs( buffer.c_str(), outfile );
841 wxString
path = fn.GetPath();
843 if(
path.IsEmpty() || !wxDirExists(
path ) )
846 wxFileDialog fileDlg(
this,
_(
"Create Footprint Library" ),
path, wxEmptyString,
849 if( fileDlg.ShowModal() != wxID_OK )
852 fn = fileDlg.GetPath();
858 if( outfile ==
nullptr )
868 fputs( buffer.c_str(), outfile );
879 potrace_bitmap_t* potrace_bitmap = bm_new( w, h );
881 if( !potrace_bitmap )
884 msg.Printf(
_(
"Error allocating memory for potrace bitmap" ) );
890 for(
int y = 0; y < h; y++ )
892 for(
int x = 0; x < w; x++ )
894 unsigned char pix =
m_NB_Image.GetGreen( x, y );
895 BM_PUT( potrace_bitmap, x, y, pix ? 0 : 1 );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
@ icon_bitmap2component_32
@ icon_bitmap2component_16
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
wxString m_BitmapFileName
wxString m_ConvertedFileName
std::string & GetErrorMessages()
int ConvertBitmap(potrace_bitmap_t *aPotrace_bitmap, OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y, BMP2CMP_MOD_LAYER aModLayer)
Run the conversion of the bitmap.
wxStaticText * m_InputYValueDPI
wxCheckBox * m_aspectRatioCheckbox
wxSlider * m_sliderThreshold
wxButton * m_buttonExportFile
wxStaticText * m_SizeXValue
wxStaticText * m_BPPValue
wxStaticText * m_InputXValueDPI
wxScrolledWindow * m_GreyscalePicturePanel
wxCheckBox * m_checkNegative
wxScrolledWindow * m_InitialPicturePanel
wxScrolledWindow * m_BNPicturePanel
wxButton * m_buttonExportClipboard
wxRadioBox * m_rbPCBLayer
wxRadioBox * m_rbOutputFormat
wxStaticText * m_SizeYValue
void OnSizeChangeX(wxCommandEvent &event) override
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void doReCreateMenuBar() override
void exportEeschemaFormat()
Generate a schematic library which contains one component: the logo.
void exportPostScriptFormat()
Generate a postscript file.
void OnPaintBW(wxPaintEvent &event) override
wxString FormatOutputSize(double aSize)
wxBitmap m_Greyscale_Bitmap
void OnThresholdChange(wxScrollEvent &event) override
void NegateGreyscaleImage()
void OnExportToFile(wxCommandEvent &event) override
void OnLoadFile(wxCommandEvent &event) override
bool OpenProjectFiles(const std::vector< wxString > &aFilenames, int aCtl=0) override
Open a project or set of files given by aFileList.
void OnSizeUnitChange(wxCommandEvent &event) override
void OnNegativeClicked(wxCommandEvent &event) override
void OnPaintInit(wxPaintEvent &event) override
void Binarize(double aThreshold)
wxString m_BitmapFileName
void ToggleAspectRatioLock(wxCommandEvent &event) override
void exportLogo()
Generate a file suitable to be copied into a drawing sheet (.kicad_wks) file.
void OnSizeChangeY(wxCommandEvent &event) override
wxImage m_Greyscale_Image
wxString m_ConvertedFileName
void OnFormatChange(wxCommandEvent &event) override
void ExportToBuffer(std::string &aOutput, OUTPUT_FMT_ID aFormat)
generate a export data of the current bitmap.
wxWindow * GetToolCanvas() const override
Canvas access.
EDA_UNITS getUnitFromSelection()
void OnPaintGreyscale(wxPaintEvent &event) override
void OnExit(wxCommandEvent &event)
void OnExportToClipboard(wxCommandEvent &event) override
void exportPcbnewFormat()
Generate a footprint in S expr format.
void exportBitmap(OUTPUT_FMT_ID aFormat)
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
void SetUnit(EDA_UNITS aUnit)
void SetOriginalDPI(int aDPI)
int GetOriginalSizePixels()
void SetOutputSizeFromInitialImageSize()
void SetOutputSize(double aSize, EDA_UNITS aUnit)
void SetOriginalSizePixels(int aPixels)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
const std::string KiCadSymbolLibFileExtension
const std::string KiCadFootprintFileExtension
const std::string DrawingSheetFileExtension
wxString KiCadFootprintLibFileWildcard()
wxString DrawingSheetFileWildcard()
wxString PSFileWildcard()
wxString KiCadSymbolLibFileWildcard()
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
std::vector< FAB_LAYER_COLOR > dummy
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition of file extensions used in Kicad.