32#include <potracelib.h>
35#include <wx/clipbrd.h>
39#include <wx/dcclient.h>
43#define DEFAULT_DPI 300
48 m_parentFrame( aParent ),
52 for(
const wxString& unit : {
_(
"mm" ),
_(
"Inch" ),
_(
"DPI" ) } )
195 int imageDPIx =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONX );
196 int imageDPIy =
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONY );
198 if( imageDPIx > 1 && imageDPIy > 1 )
200 if(
m_Pict_Image.GetOptionInt( wxIMAGE_OPTION_RESOLUTIONUNIT ) == wxIMAGE_RESOLUTION_CM )
202 imageDPIx =
KiROUND( imageDPIx * 2.54 );
203 imageDPIy =
KiROUND( imageDPIy * 2.54 );
224 wxCommandEvent
dummy;
277 text.Printf( wxS(
"%.1f" ), aSize );
279 text.Printf( wxS(
"%.2f" ), aSize );
305 case 1:
return EDA_UNITS::INCH;
306 case 2:
return EDA_UNITS::UNSCALED;
308 default:
return EDA_UNITS::MM;
317 if(
m_UnitSizeX->GetValue().ToDouble( &new_size ) )
346 if(
m_UnitSizeY->GetValue().ToDouble( &new_size ) )
398 wxCommandEvent
dummy;
406 unsigned char threshold = aThreshold * 255;
407 unsigned char alpha_thresh = 0.7 * threshold;
417 if( pixel < threshold && alpha > alpha_thresh )
422 m_NB_Image.SetRGB( x, y, pixel, pixel, pixel );
501 if( wxTheClipboard->Open() )
505 wxTheClipboard->SetData(
new wxTextDataObject( buffer.c_str() ) );
506 wxTheClipboard->Flush();
507 wxTheClipboard->Close();
511 wxMessageBox(
_(
"Unable to export to the Clipboard") );
521 if( !potrace_bitmap )
523 wxMessageBox(
_(
"Error allocating memory for potrace bitmap" ) );
528 for(
int y = 0; y <
m_NB_Image.GetHeight(); y++ )
530 for(
int x = 0; x <
m_NB_Image.GetWidth(); x++ )
532 unsigned char pixel =
m_NB_Image.GetGreen( x, y );
533 BM_PUT( potrace_bitmap, x, y, pixel ? 0 : 1 );
537 wxString layer = wxT(
"F.SilkS" );
543 case 0: layer = wxT(
"F.Cu" );
break;
544 case 1: layer = wxT(
"F.SilkS" );
break;
545 case 2: layer = wxT(
"F.Mask" );
break;
546 case 3: layer = wxT(
"Dwgs.User" );
break;
547 case 4: layer = wxT(
"Cmts.User" );
break;
548 case 5: layer = wxT(
"Eco1.User" );
break;
549 case 6: layer = wxT(
"Eco2.User" );
break;
550 case 7: layer = wxT(
"F.Fab" );
break;
587 wxString cap =
_(
"Replace Loaded File?" );
588 wxString msg =
_(
"There is already a file loaded. Do you want to replace it?" );
589 wxMessageDialog acceptFileDlg(
m_panel, msg, cap, wxYES_NO | wxICON_QUESTION | wxYES_DEFAULT );
590 int replace = acceptFileDlg.ShowModal();
592 if( replace == wxID_NO )
596 std::vector<wxString> fNameVec;
597 fNameVec.insert( fNameVec.begin(), filenames.begin(), filenames.end() );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
void ExportPcbnewFormat()
Generate a footprint in S expr format.
void ExportDrawingSheetFormat()
Generate a file suitable to be copied into a drawing sheet (.kicad_wks) file.
void ExportEeschemaFormat()
Generate a schematic library which contains one component: the logo.
void ExportPostScriptFormat()
Generate a postscript file.
Class BITMAP2CMP_PANEL_BASE.
wxStaticText * m_BPPValue
wxScrolledWindow * m_GreyscalePicturePanel
wxButton * m_buttonExportFile
wxScrolledWindow * m_BNPicturePanel
wxButton * m_buttonExportClipboard
wxSlider * m_sliderThreshold
wxCheckBox * m_aspectRatioCheckbox
wxRadioButton * m_rbPostscript
wxCheckBox * m_checkNegative
wxRadioButton * m_rbFootprint
wxRadioButton * m_rbWorksheet
wxStaticText * m_SizeXValue
wxRadioButton * m_rbSymbol
wxStaticText * m_layerLabel
wxStaticText * m_SizeYValue
wxStaticText * m_InputYValueDPI
wxStaticText * m_InputXValueDPI
wxScrolledWindow * m_InitialPicturePanel
void OnPaintGreyscale(wxPaintEvent &event) override
void binarize(double aThreshold)
void SetOutputSize(const IMAGE_SIZE &aSizeX, const IMAGE_SIZE &aSizeY)
void OnSizeUnitChange(wxCommandEvent &event) override
void OnSizeChangeX(wxCommandEvent &event) override
void OnPaintInit(wxPaintEvent &event) override
void OnExportToClipboard(wxCommandEvent &event) override
void LoadSettings(BITMAP2CMP_SETTINGS *aCfg)
wxImage m_Greyscale_Image
IMAGE_SIZE GetOutputSizeX() const
void negateGreyscaleImage()
void ToggleAspectRatioLock(wxCommandEvent &event) override
bool OpenProjectFiles(const std::vector< wxString > &aFilenames, int aCtl=0)
wxWindow * GetCurrentPage()
BITMAP2CMP_PANEL(BITMAP2CMP_FRAME *aParent)
void OnExportToFile(wxCommandEvent &event) override
void SaveSettings(BITMAP2CMP_SETTINGS *aCfg)
wxString formatOutputSize(double aSize)
void OnThresholdChange(wxScrollEvent &event) override
void ExportToBuffer(std::string &aOutput, OUTPUT_FMT_ID aFormat)
generate a export data of the current bitmap.
BITMAP2CMP_FRAME * m_parentFrame
void OnFormatChange(wxCommandEvent &event) override
void OnLoadFile(wxCommandEvent &event) override
wxBitmap m_Greyscale_Bitmap
EDA_UNITS getUnitFromSelection()
void OnNegativeClicked(wxCommandEvent &event) override
void OnPaintBW(wxPaintEvent &event) override
OUTPUT_FMT_ID getOutputFormat()
void OnSizeChangeY(wxCommandEvent &event) override
int ConvertBitmap(potrace_bitmap_t *aPotrace_bitmap, OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y, const wxString &aLayer)
Run the conversion of the bitmap.
BITMAP2CMP_PANEL * m_panel
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames) override
void SetUnit(EDA_UNITS aUnit)
void SetOriginalDPI(int aDPI)
int GetOriginalSizePixels()
void SetOutputSizeFromInitialImageSize()
void SetOutputSize(double aSize, EDA_UNITS aUnit)
void SetOriginalSizePixels(int aPixels)
A wrapper for reporting to a wxString object.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
const wxString & GetMessages() const
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
std::vector< FAB_LAYER_COLOR > dummy