28 #include <bitmap_io.h> 33 #include <potracelib.h> 35 #include <wx/clipbrd.h> 36 #include <wx/rawbmp.h> 37 #include <wx/filedlg.h> 38 #include <wx/rawbmp.h> 39 #include <wx/msgdlg.h> 40 #include <wx/dcclient.h> 47 #define DEFAULT_DPI 300 // the image DPI used in formats that do not define a DPI 98 outputDPI = std::max( 1, outputDPI );
159 for( wxString unit : {
_(
"mm" ),
_(
"Inch" ),
_(
"DPI" ) } )
179 wxIconBundle icon_bundle;
182 icon_bundle.AddIcon( icon );
184 icon_bundle.AddIcon( icon );
186 icon_bundle.AddIcon( icon );
188 SetIcons( icon_bundle );
190 GetSizer()->SetSizeHints(
this );
223 auto cfg = static_cast<BITMAP2CMP_SETTINGS*>( aCfg );
228 int u_select = cfg->m_Units;
230 if( u_select < 0 || u_select > 2 )
242 int format = cfg->m_LastFormat;
254 int last_layer = cfg->m_LastModLayer;
267 auto cfg = static_cast<BITMAP2CMP_SETTINGS*>( aCfg );
338 wxString
path = fn.GetPath();
340 if(
path.IsEmpty() || !wxDirExists(
path ) )
343 wxFileDialog fileDlg(
this,
_(
"Choose Image" ),
path, wxEmptyString,
344 _(
"Image Files" ) + wxS(
" " )+ wxImage::GetImageExtWildcard(),
345 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
347 int diag = fileDlg.ShowModal();
349 if( diag != wxID_OK )
352 wxString fullFilename = fileDlg.GetPath();
359 SetStatusText( fullFilename );
380 int imageDPIx =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
381 int imageDPIy =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
383 if( imageDPIx > 1 && imageDPIy > 1 )
385 if(
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
387 imageDPIx =
KiROUND( imageDPIx * 2.54 );
388 imageDPIy =
KiROUND( imageDPIy * 2.54 );
409 auto fakeEvent = wxCommandEvent();
463 text.Printf(
"%.1f", aSize );
467 text.Printf(
"%.2f", aSize );
520 if(
m_UnitSizeX->GetValue().ToDouble( &new_size ) )
549 if(
m_UnitSizeY->GetValue().ToDouble( &new_size ) )
593 auto fakeEvent = wxCommandEvent();
608 unsigned char threshold = aThreshold * 255;
609 unsigned char alpha_thresh = 0.7 * threshold;
611 for(
int y = 0; y < h; y++ )
612 for(
int x = 0; x < w; x++ )
614 unsigned char pixout;
619 if( pixin < threshold && alpha > alpha_thresh )
624 m_NB_Image.SetRGB( x, y, pixout, pixout, pixout );
639 for(
int y = 0; y < h; y++ )
640 for(
int x = 0; x < w; x++ )
696 if( wxTheClipboard->Open() )
700 wxTheClipboard->SetData(
new wxTextDataObject( buffer.c_str() ) );
701 wxTheClipboard->Flush();
702 wxTheClipboard->Close();
706 wxMessageBox(
_(
"Unable to export to the Clipboard") );
737 wxString
path = fn.GetPath();
739 if(
path.IsEmpty() || !wxDirExists(
path) )
742 wxFileDialog fileDlg(
this,
_(
"Create Logo File" ),
path, wxEmptyString,
744 int diag = fileDlg.ShowModal();
746 if( diag != wxID_OK )
749 fn = fileDlg.GetPath();
756 if( outfile ==
nullptr )
766 fputs( buffer.c_str(), outfile );
774 wxString
path = fn.GetPath();
776 if(
path.IsEmpty() || !wxDirExists(
path ) )
779 wxFileDialog fileDlg(
this,
_(
"Create PostScript File" ),
782 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
784 int diag = fileDlg.ShowModal();
786 if( diag != wxID_OK )
789 fn = fileDlg.GetPath();
790 fn.SetExt( wxT(
"ps" ) );
796 if( outfile ==
nullptr )
806 fputs( buffer.c_str(), outfile );
814 wxString
path = fn.GetPath();
816 if(
path.IsEmpty() || !wxDirExists(
path) )
819 wxFileDialog fileDlg(
this,
_(
"Create Symbol Library" ),
822 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
824 int diag = fileDlg.ShowModal();
826 if( diag != wxID_OK )
829 fn = fileDlg.GetPath();
835 if( outfile ==
nullptr )
845 fputs( buffer.c_str(), outfile );
853 wxString
path = fn.GetPath();
855 if(
path.IsEmpty() || !wxDirExists(
path ) )
858 wxFileDialog fileDlg(
this,
_(
"Create Footprint Library" ),
861 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
863 int diag = fileDlg.ShowModal();
865 if( diag != wxID_OK )
868 fn = fileDlg.GetPath();
874 if( outfile ==
nullptr )
884 fputs( buffer.c_str(), outfile );
895 potrace_bitmap_t* potrace_bitmap = bm_new( w, h );
897 if( !potrace_bitmap )
900 msg.Printf(
_(
"Error allocating memory for potrace bitmap" ) );
906 for(
int y = 0; y < h; y++ )
908 for(
int x = 0; x < w; x++ )
911 BM_PUT( potrace_bitmap, x, y, pix ? 0 : 1 );
wxBitmap m_Greyscale_Bitmap
std::string & GetErrorMessages()
void SetKiway(wxWindow *aDest, KIWAY *aKiway)
It is only used for debugging, since "this" is not a wxWindow*.
wxImage m_Greyscale_Image
void OnExportToFile(wxCommandEvent &event) override
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void exportPcbnewFormat()
Generate a footprint in S expr format.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
const std::string KiCadFootprintFileExtension
void OnPaintInit(wxPaintEvent &event) override
void SetOriginalSizePixels(int aPixels)
wxStaticText * m_BPPValue
void OnExportLogo()
Generate a file suitable to be copied into a drawing sheet (.kicad_wks) file.
void SetUnit(EDA_UNITS aUnit)
void OnPaintGreyscale(wxPaintEvent &event) override
wxRadioBox * m_rbPCBLayer
wxButton * m_buttonExportClipboard
int GetOriginalSizePixels()
wxString m_ConvertedFileName
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void SetOutputSize(double aSize, EDA_UNITS aUnit)
wxStaticText * m_InputXValueDPI
void OnExportToClipboard(wxCommandEvent &event) override
void OnPaintBW(wxPaintEvent &event) override
wxString PSFileWildcard()
void SetOriginalDPI(int aDPI)
wxStaticText * m_SizeXValue
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void OnFormatChange(wxCommandEvent &event) override
void OnThresholdChange(wxScrollEvent &event) override
void OnLoadFile(wxCommandEvent &event) override
Definition of file extensions used in Kicad.
void exportEeschemaFormat()
Generate a schematic library which contains one component: the logo.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
wxSlider * m_sliderThreshold
wxString KiCadSymbolLibFileWildcard()
wxCheckBox * m_checkNegative
wxString FormatOutputSize(double aSize)
void OnSizeUnitChange(wxCommandEvent &event) override
void OnSizeChangeY(wxCommandEvent &event) override
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
wxRadioBox * m_rbOutputFormat
EDA_UNITS getUnitFromSelection()
BM2CMP_FRAME(KIWAY *aKiway, wxWindow *aParent)
wxStaticText * m_InputYValueDPI
void OnSizeChangeX(wxCommandEvent &event) override
wxButton * m_buttonExportFile
void ToggleAspectRatioLock(wxCommandEvent &event) override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
void NegateGreyscaleImage()
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
wxString m_BitmapFileName
void Binarize(double aThreshold)
wxBitmapButton * m_AspectRatioLockButton
void SetOutputSizeFromInitialImageSize()
const std::string DrawingSheetFileExtension
void exportBitmap(OUTPUT_FMT_ID aFormat)
bool OpenProjectFiles(const std::vector< wxString > &aFilenames, int aCtl=0) override
Open a project or set of files given by aFileList.
wxScrolledWindow * m_GreyscalePicturePanel
wxScrolledWindow * m_InitialPicturePanel
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
wxWindow * GetToolCanvas() const override
Canvas access.
wxString DrawingSheetFileWildcard()
void ExportToBuffer(std::string &aOutput, OUTPUT_FMT_ID aFormat)
generate a export data of the current bitmap.
wxStaticText * m_SizeYValue
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.
wxString KiCadFootprintLibFileWildcard()
void exportPostScriptFormat()
Generate a postscript file.
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
void OnNegativeClicked(wxCommandEvent &event) override
wxScrolledWindow * m_BNPicturePanel
const std::string KiCadSymbolLibFileExtension