From 5cfa37da0980e19743be10ee0986e1d6d8856f55 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 1 Feb 2019 08:36:32 -0800 Subject: [PATCH] bitmap2component: Handle mask/alpha Use alpha and mask components of bitmaps to set boundaries for the image tracing. Fixes: lp:1815216 * https://bugs.launchpad.net/kicad/+bug/1815216 --- bitmap2component/bitmap2cmp_gui.cpp | 101 ++- bitmap2component/bitmap2cmp_gui_base.cpp | 116 ++-- bitmap2component/bitmap2cmp_gui_base.fbp | 744 ++--------------------- bitmap2component/bitmap2cmp_gui_base.h | 24 +- bitmap2component/bitmap2component.cpp | 5 +- 5 files changed, 185 insertions(+), 805 deletions(-) diff --git a/bitmap2component/bitmap2cmp_gui.cpp b/bitmap2component/bitmap2cmp_gui.cpp index 5aa689326a..3a0e84b94d 100644 --- a/bitmap2component/bitmap2cmp_gui.cpp +++ b/bitmap2component/bitmap2cmp_gui.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 1992-2010 jean-pierre.charras - * Copyright (C) 1992-2017 Kicad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2019 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 @@ -35,6 +35,7 @@ #include #include +#include #include #include "bitmap2component.h" @@ -91,7 +92,9 @@ public: private: // Event handlers - void OnPaint( wxPaintEvent& event ) override; + void OnPaintInit( wxPaintEvent& event ) override; + void OnPaintGreyscale( wxPaintEvent& event ) override; + void OnPaintBW( wxPaintEvent& event ) override; void OnLoadFile( wxCommandEvent& event ) override; void OnExport( wxCommandEvent& event ) override; @@ -230,30 +233,59 @@ BM2CMP_FRAME::~BM2CMP_FRAME() } -void BM2CMP_FRAME::OnPaint( wxPaintEvent& event ) +void BM2CMP_FRAME::OnPaintInit( wxPaintEvent& event ) { #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 wxPaintDC pict_dc( m_InitialPicturePanel ); - wxPaintDC greyscale_dc( m_GreyscalePicturePanel ); - wxPaintDC nb_dc( m_BNPicturePanel ); #endif m_InitialPicturePanel->PrepareDC( pict_dc ); - m_GreyscalePicturePanel->PrepareDC( greyscale_dc ); - m_BNPicturePanel->PrepareDC( nb_dc ); // 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 ); - } + if( m_Pict_Bitmap.IsOk() ) + pict_dc.DrawBitmap( m_Pict_Bitmap, 0, 0, !!m_Pict_Bitmap.GetMask() ); + + event.Skip(); +} + + +void BM2CMP_FRAME::OnPaintGreyscale( wxPaintEvent& event ) +{ +#ifdef __WXMAC__ + // Otherwise fails due: using wxPaintDC without being in a native paint event + wxClientDC greyscale_dc( m_GreyscalePicturePanel ); +#else + wxPaintDC greyscale_dc( m_GreyscalePicturePanel ); +#endif + + m_GreyscalePicturePanel->PrepareDC( greyscale_dc ); + + // OSX crashes with empty bitmaps (on initial refreshes) + if( m_Greyscale_Bitmap.IsOk() ) + greyscale_dc.DrawBitmap( m_Greyscale_Bitmap, 0, 0, !!m_Greyscale_Bitmap.GetMask() ); + + event.Skip(); +} + + +void BM2CMP_FRAME::OnPaintBW( wxPaintEvent& event ) +{ +#ifdef __WXMAC__ + // Otherwise fails due: using wxPaintDC without being in a native paint event + wxClientDC nb_dc( m_BNPicturePanel ); +#else + wxPaintDC nb_dc( m_BNPicturePanel ); +#endif + + m_BNPicturePanel->PrepareDC( nb_dc ); + + if( m_BN_Bitmap.IsOk() ) + nb_dc.DrawBitmap( m_BN_Bitmap, 0, 0, !!m_BN_Bitmap.GetMask() ); + + event.Skip(); } @@ -288,8 +320,7 @@ void BM2CMP_FRAME::OnLoadFile( wxCommandEvent& event ) bool BM2CMP_FRAME::OpenProjectFiles( const std::vector& aFileSet, int aCtl ) { - // Prj().MaybeLoadProjectSettings(); - + m_Pict_Image.Destroy(); m_BitmapFileName = aFileSet[0]; if( !m_Pict_Image.LoadFile( m_BitmapFileName ) ) @@ -336,11 +367,26 @@ bool BM2CMP_FRAME::OpenProjectFiles( const std::vector& aFileSet, int m_Greyscale_Image.Destroy(); m_Greyscale_Image = m_Pict_Image.ConvertToGreyscale( ); + if( m_Pict_Bitmap.GetMask() ) + { + for( int x = 0; x < m_Pict_Bitmap.GetWidth(); x++ ) + { + for( int y = 0; y < m_Pict_Bitmap.GetHeight(); y++ ) + { + if( m_Pict_Image.GetRed( x, y ) == m_Pict_Image.GetMaskRed() && + m_Pict_Image.GetGreen( x, y ) == m_Pict_Image.GetMaskGreen() && + m_Pict_Image.GetBlue( x, y ) == m_Pict_Image.GetMaskBlue() ) + { + m_Greyscale_Image.SetRGB( x, y, 255, 255, 255 ); + } + } + } + } + if( m_Negative ) NegateGreyscaleImage( ); m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image ); - m_NB_Image = m_Greyscale_Image; Binarize( (double) m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() ); @@ -391,26 +437,30 @@ void BM2CMP_FRAME::OnResolutionChange( wxCommandEvent& event ) void BM2CMP_FRAME::Binarize( double aThreshold ) { - unsigned int pixin; - unsigned char pixout; int h = m_Greyscale_Image.GetHeight(); int w = m_Greyscale_Image.GetWidth(); - unsigned int threshold = (int)(aThreshold * 256); + unsigned char threshold = aThreshold * 255; + unsigned char alpha_thresh = 0.7 * threshold; for( int y = 0; y < h; y++ ) for( int x = 0; x < w; x++ ) { - pixin = m_Greyscale_Image.GetGreen( x, y ); + unsigned char pixout; + auto pixin = m_Greyscale_Image.GetGreen( x, y ); + auto alpha = m_Greyscale_Image.HasAlpha() ? + m_Greyscale_Image.GetAlpha( x, y ) : wxALPHA_OPAQUE; - if( pixin < threshold ) + if( pixin < threshold || alpha < alpha_thresh ) pixout = 0; else pixout = 255; m_NB_Image.SetRGB( x, y, pixout, pixout, pixout ); + } m_BN_Bitmap = wxBitmap( m_NB_Image ); + } @@ -435,6 +485,7 @@ void BM2CMP_FRAME::OnNegativeClicked( wxCommandEvent& ) if( m_checkNegative->GetValue() != m_Negative ) { NegateGreyscaleImage(); + m_Greyscale_Bitmap = wxBitmap( m_Greyscale_Image ); Binarize( (double)m_sliderThreshold->GetValue()/m_sliderThreshold->GetMax() ); m_Negative = m_checkNegative->GetValue(); @@ -647,8 +698,8 @@ void BM2CMP_FRAME::ExportFile( FILE* aOutfile, OUTPUT_FMT_ID aFormat ) { 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 ); + auto pix = m_NB_Image.GetGreen( x, y ); + BM_PUT( potrace_bitmap, x, y, pix ? 0 : 1 ); } } diff --git a/bitmap2component/bitmap2cmp_gui_base.cpp b/bitmap2component/bitmap2cmp_gui_base.cpp index 7504b12b10..0d724d490a 100644 --- a/bitmap2component/bitmap2cmp_gui_base.cpp +++ b/bitmap2component/bitmap2cmp_gui_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jun 5 2018) +// C++ code generated with wxFormBuilder (version Jan 17 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,167 +12,167 @@ BM2CMP_FRAME_BASE::BM2CMP_FRAME_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : KIWAY_PLAYER( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - + wxBoxSizer* bMainSizer; bMainSizer = new wxBoxSizer( wxHORIZONTAL ); - + m_Notebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); m_InitialPicturePanel = new wxScrolledWindow( m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); m_InitialPicturePanel->SetScrollRate( 5, 5 ); m_InitialPicturePanel->SetMinSize( wxSize( 400,300 ) ); - + m_Notebook->AddPage( m_InitialPicturePanel, _("Original Picture"), true ); m_GreyscalePicturePanel = new wxScrolledWindow( m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); m_GreyscalePicturePanel->SetScrollRate( 5, 5 ); m_GreyscalePicturePanel->SetMinSize( wxSize( 400,300 ) ); - + m_Notebook->AddPage( m_GreyscalePicturePanel, _("Greyscale Picture"), false ); m_BNPicturePanel = new wxScrolledWindow( m_Notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL ); m_BNPicturePanel->SetScrollRate( 5, 5 ); m_Notebook->AddPage( m_BNPicturePanel, _("Black&&White Picture"), false ); - + bMainSizer->Add( m_Notebook, 1, wxEXPAND, 5 ); - + m_panelRight = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxBoxSizer* brightSizer; brightSizer = new wxBoxSizer( wxVERTICAL ); - + wxStaticBoxSizer* sbSizerInfo; sbSizerInfo = new wxStaticBoxSizer( new wxStaticBox( m_panelRight, wxID_ANY, _("Bitmap Info:") ), wxVERTICAL ); - + wxFlexGridSizer* fgSizerInfo; fgSizerInfo = new wxFlexGridSizer( 0, 4, 0, 0 ); fgSizerInfo->AddGrowableCol( 1 ); fgSizerInfo->AddGrowableCol( 2 ); fgSizerInfo->SetFlexibleDirection( wxBOTH ); fgSizerInfo->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + m_staticTextSize = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextSize->Wrap( -1 ); fgSizerInfo->Add( m_staticTextSize, 0, wxALIGN_RIGHT|wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - + m_SizeXValue = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 ); m_SizeXValue->Wrap( -1 ); fgSizerInfo->Add( m_SizeXValue, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); - + m_SizeYValue = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 ); m_SizeYValue->Wrap( -1 ); fgSizerInfo->Add( m_SizeYValue, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); - + m_SizePixUnits = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("pixels"), wxDefaultPosition, wxDefaultSize, 0 ); m_SizePixUnits->Wrap( -1 ); fgSizerInfo->Add( m_SizePixUnits, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT, 5 ); - + m_staticTextSize1 = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("Size:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextSize1->Wrap( -1 ); fgSizerInfo->Add( m_staticTextSize1, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_RIGHT, 5 ); - + m_SizeXValue_mm = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 ); m_SizeXValue_mm->Wrap( -1 ); fgSizerInfo->Add( m_SizeXValue_mm, 0, wxBOTTOM|wxRIGHT, 5 ); - + m_SizeYValue_mm = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 ); m_SizeYValue_mm->Wrap( -1 ); fgSizerInfo->Add( m_SizeYValue_mm, 0, wxBOTTOM|wxRIGHT, 5 ); - + m_Size_mmxUnits = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_Size_mmxUnits->Wrap( -1 ); fgSizerInfo->Add( m_Size_mmxUnits, 0, wxBOTTOM|wxRIGHT, 5 ); - + m_staticTextBPP = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("BPP:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextBPP->Wrap( -1 ); fgSizerInfo->Add( m_staticTextBPP, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); - + m_BPPValue = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("0000"), wxDefaultPosition, wxDefaultSize, 0 ); m_BPPValue->Wrap( -1 ); fgSizerInfo->Add( m_BPPValue, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - + m_BPPunits = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("bits"), wxDefaultPosition, wxDefaultSize, 0 ); m_BPPunits->Wrap( -1 ); fgSizerInfo->Add( m_BPPunits, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); - - + + fgSizerInfo->Add( 0, 0, 1, wxEXPAND, 5 ); - + m_staticTextBPI = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("Resolution:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextBPI->Wrap( -1 ); fgSizerInfo->Add( m_staticTextBPI, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 ); - + m_DPIValueX = new wxTextCtrl( sbSizerInfo->GetStaticBox(), wxID_ANY, _("300"), wxDefaultPosition, wxDefaultSize, 0 ); m_DPIValueX->SetMinSize( wxSize( 40,-1 ) ); - + fgSizerInfo->Add( m_DPIValueX, 0, wxBOTTOM|wxRIGHT, 5 ); - + m_DPIValueY = new wxTextCtrl( sbSizerInfo->GetStaticBox(), wxID_ANY, _("300"), wxDefaultPosition, wxDefaultSize, 0 ); m_DPIValueY->SetMinSize( wxSize( 40,-1 ) ); - + fgSizerInfo->Add( m_DPIValueY, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - + m_DPI_Units = new wxStaticText( sbSizerInfo->GetStaticBox(), wxID_ANY, _("DPI"), wxDefaultPosition, wxDefaultSize, 0 ); m_DPI_Units->Wrap( -1 ); fgSizerInfo->Add( m_DPI_Units, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 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, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 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") ); - + brightSizer->Add( m_buttonExport, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + wxString m_radioBoxFormatChoices[] = { _("Eeschema (.lib file)"), _("Pcbnew (.kicad_mod file)"), _("Postscript (.ps file)"), _("Logo for title block (.kicad_wks file)") }; 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( 1 ); brightSizer->Add( m_radioBoxFormat, 0, wxEXPAND|wxALL, 5 ); - + wxStaticBoxSizer* sbSizer2; sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( m_panelRight, wxID_ANY, _("Image Options:") ), wxVERTICAL ); - + m_ThresholdText = new wxStaticText( sbSizer2->GetStaticBox(), wxID_ANY, _("Black / White Threshold:"), wxDefaultPosition, wxDefaultSize, 0 ); m_ThresholdText->Wrap( -1 ); sbSizer2->Add( m_ThresholdText, 0, 0, 5 ); - + m_sliderThreshold = new wxSlider( sbSizer2->GetStaticBox(), 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.") ); - + sbSizer2->Add( m_sliderThreshold, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + m_checkNegative = new wxCheckBox( sbSizer2->GetStaticBox(), wxID_ANY, _("Negative"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizer2->Add( m_checkNegative, 0, wxBOTTOM|wxTOP, 10 ); - - + + brightSizer->Add( sbSizer2, 0, wxALL|wxEXPAND, 5 ); - + wxString m_radio_PCBLayerChoices[] = { _("Front silk screen"), _("Front solder mask"), _("User layer Eco1"), _("User layer Eco2") }; int m_radio_PCBLayerNChoices = sizeof( m_radio_PCBLayerChoices ) / sizeof( wxString ); m_radio_PCBLayer = new wxRadioBox( m_panelRight, wxID_ANY, _("Board Layer for Outline:"), wxDefaultPosition, wxDefaultSize, m_radio_PCBLayerNChoices, m_radio_PCBLayerChoices, 1, wxRA_SPECIFY_COLS ); m_radio_PCBLayer->SetSelection( 3 ); m_radio_PCBLayer->SetToolTip( _("Choose the board layer to place the outline.\nThe 2 invisible fields reference and value are always placed on the silk screen layer.") ); - + brightSizer->Add( m_radio_PCBLayer, 0, wxALL|wxEXPAND, 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 ); - + m_statusBar = this->CreateStatusBar( 1, wxSTB_SIZEGRIP, wxID_ANY ); + // Connect Events - m_InitialPicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this ); - 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_InitialPicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaintInit ), NULL, this ); + m_GreyscalePicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaintGreyscale ), NULL, this ); + m_BNPicturePanel->Connect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaintBW ), NULL, this ); m_DPIValueX->Connect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BM2CMP_FRAME_BASE::UpdatePPITextValueX ), NULL, this ); m_DPIValueX->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnResolutionChange ), NULL, this ); m_DPIValueY->Connect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BM2CMP_FRAME_BASE::UpdatePPITextValueY ), NULL, this ); @@ -187,9 +187,9 @@ BM2CMP_FRAME_BASE::BM2CMP_FRAME_BASE( wxWindow* parent, wxWindowID id, const wxS BM2CMP_FRAME_BASE::~BM2CMP_FRAME_BASE() { // Disconnect Events - m_InitialPicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaint ), NULL, this ); - 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_InitialPicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaintInit ), NULL, this ); + m_GreyscalePicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaintGreyscale ), NULL, this ); + m_BNPicturePanel->Disconnect( wxEVT_PAINT, wxPaintEventHandler( BM2CMP_FRAME_BASE::OnPaintBW ), NULL, this ); m_DPIValueX->Disconnect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BM2CMP_FRAME_BASE::UpdatePPITextValueX ), NULL, this ); m_DPIValueX->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnResolutionChange ), NULL, this ); m_DPIValueY->Disconnect( wxEVT_LEAVE_WINDOW, wxMouseEventHandler( BM2CMP_FRAME_BASE::UpdatePPITextValueY ), NULL, this ); @@ -199,5 +199,5 @@ BM2CMP_FRAME_BASE::~BM2CMP_FRAME_BASE() m_radioBoxFormat->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnFormatChange ), NULL, this ); m_sliderThreshold->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( BM2CMP_FRAME_BASE::OnThresholdChange ), NULL, this ); m_checkNegative->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( BM2CMP_FRAME_BASE::OnNegativeClicked ), NULL, this ); - + } diff --git a/bitmap2component/bitmap2cmp_gui_base.fbp b/bitmap2component/bitmap2cmp_gui_base.fbp index cc95e427f3..ba627ab720 100644 --- a/bitmap2component/bitmap2cmp_gui_base.fbp +++ b/bitmap2component/bitmap2cmp_gui_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -54,41 +54,6 @@ wxTAB_TRAVERSAL 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bMainSizer @@ -151,31 +116,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - Original Picture @@ -233,29 +173,7 @@ wxHSCROLL|wxVSCROLL - - - - - - - - - - - - - - - - - OnPaint - - - - - - + OnPaintInit @@ -315,29 +233,7 @@ wxHSCROLL|wxVSCROLL - - - - - - - - - - - - - - - - - OnPaint - - - - - - + OnPaintGreyscale @@ -397,29 +293,7 @@ wxHSCROLL|wxVSCROLL - - - - - - - - - - - - - - - - - OnPaint - - - - - - + OnPaintBW @@ -479,29 +353,6 @@ wxTAB_TRAVERSAL - - - - - - - - - - - - - - - - - - - - - - - brightSizer @@ -519,7 +370,6 @@ wxVERTICAL 1 none - 5 wxEXPAND|wxBOTTOM @@ -569,6 +419,7 @@ 0 wxID_ANY Size: + 0 0 @@ -594,29 +445,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -652,6 +480,7 @@ 0 wxID_ANY 0000 + 0 0 @@ -677,29 +506,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -735,6 +541,7 @@ 0 wxID_ANY 0000 + 0 0 @@ -760,29 +567,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -818,6 +602,7 @@ 0 wxID_ANY pixels + 0 0 @@ -843,29 +628,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -901,6 +663,7 @@ 0 wxID_ANY Size: + 0 0 @@ -926,29 +689,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -984,6 +724,7 @@ 0 wxID_ANY 0000 + 0 0 @@ -1009,29 +750,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1067,6 +785,7 @@ 0 wxID_ANY 0000 + 0 0 @@ -1092,29 +811,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1150,6 +846,7 @@ 0 wxID_ANY mm + 0 0 @@ -1175,29 +872,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1233,6 +907,7 @@ 0 wxID_ANY BPP: + 0 0 @@ -1258,29 +933,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1316,6 +968,7 @@ 0 wxID_ANY 0000 + 0 0 @@ -1341,29 +994,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1399,6 +1029,7 @@ 0 wxID_ANY bits + 0 0 @@ -1424,29 +1055,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1492,6 +1100,7 @@ 0 wxID_ANY Resolution: + 0 0 @@ -1517,29 +1126,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1604,33 +1190,8 @@ - - - - - - UpdatePPITextValueX - - - - - - - - - - - - - - - OnResolutionChange - - - - @@ -1695,33 +1256,8 @@ - - - - - - UpdatePPITextValueY - - - - - - - - - - - - - - - OnResolutionChange - - - - @@ -1757,6 +1293,7 @@ 0 wxID_ANY DPI + 0 0 @@ -1782,29 +1319,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1826,25 +1340,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Load Bitmap + + 0 0 @@ -1859,6 +1379,8 @@ protected 1 + + Resizable 1 @@ -1874,29 +1396,6 @@ OnLoadFile - - - - - - - - - - - - - - - - - - - - - - - @@ -1914,25 +1413,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Export + + 0 0 @@ -1947,6 +1452,8 @@ protected 1 + + Resizable 1 @@ -1962,29 +1469,6 @@ OnExport - - - - - - - - - - - - - - - - - - - - - - - @@ -2051,30 +1535,7 @@ - - - - - - - - - - - - - - - - - OnFormatChange - - - - - - @@ -2089,7 +1550,6 @@ wxVERTICAL 1 none - 5 @@ -2123,6 +1583,7 @@ 0 wxID_ANY Black / White Threshold: + 0 0 @@ -2148,29 +1609,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -2236,49 +1674,7 @@ - - - - - - - - - OnThresholdChange - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2343,30 +1739,7 @@ - OnNegativeClicked - - - - - - - - - - - - - - - - - - - - - - @@ -2435,30 +1808,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -2481,35 +1830,12 @@ protected - wxST_SIZEGRIP + wxSTB_SIZEGRIP - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bitmap2component/bitmap2cmp_gui_base.h b/bitmap2component/bitmap2cmp_gui_base.h index ecc9c4d37e..a0500cbc15 100644 --- a/bitmap2component/bitmap2cmp_gui_base.h +++ b/bitmap2component/bitmap2cmp_gui_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Jun 5 2018) +// C++ code generated with wxFormBuilder (version Jan 17 2019) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __BITMAP2CMP_GUI_BASE_H__ -#define __BITMAP2CMP_GUI_BASE_H__ +#pragma once #include #include @@ -43,7 +42,7 @@ class BM2CMP_FRAME_BASE : public KIWAY_PLAYER { private: - + protected: wxNotebook* m_Notebook; wxScrolledWindow* m_InitialPicturePanel; @@ -73,9 +72,11 @@ class BM2CMP_FRAME_BASE : public KIWAY_PLAYER wxCheckBox* m_checkNegative; wxRadioBox* m_radio_PCBLayer; wxStatusBar* m_statusBar; - + // Virtual event handlers, overide them in your derived class - virtual void OnPaint( wxPaintEvent& event ) { event.Skip(); } + virtual void OnPaintInit( wxPaintEvent& event ) { event.Skip(); } + virtual void OnPaintGreyscale( wxPaintEvent& event ) { event.Skip(); } + virtual void OnPaintBW( wxPaintEvent& event ) { event.Skip(); } virtual void UpdatePPITextValueX( wxMouseEvent& event ) { event.Skip(); } virtual void OnResolutionChange( wxCommandEvent& event ) { event.Skip(); } virtual void UpdatePPITextValueY( wxMouseEvent& event ) { event.Skip(); } @@ -84,14 +85,13 @@ class BM2CMP_FRAME_BASE : public KIWAY_PLAYER virtual void OnFormatChange( wxCommandEvent& event ) { event.Skip(); } virtual void OnThresholdChange( wxScrollEvent& event ) { event.Skip(); } virtual void OnNegativeClicked( wxCommandEvent& 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( 733,634 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxTAB_TRAVERSAL ); - + ~BM2CMP_FRAME_BASE(); - + }; -#endif //__BITMAP2CMP_GUI_BASE_H__ diff --git a/bitmap2component/bitmap2component.cpp b/bitmap2component/bitmap2component.cpp index 32efdc59bc..5ff61a67b2 100644 --- a/bitmap2component/bitmap2component.cpp +++ b/bitmap2component/bitmap2component.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KICAD, a free EDA CAD application. * * Copyright (C) 1992-2013 jean-pierre.charras - * Copyright (C) 1992-2013 Kicad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2019 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 @@ -155,6 +155,7 @@ int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile, return 1; } + printf("Step 1\n"); BITMAPCONV_INFO info; info.m_PixmapWidth = aPotrace_bitmap->w; info.m_PixmapHeight = aPotrace_bitmap->h; // the bitmap size in pixels @@ -434,6 +435,8 @@ void BITMAPCONV_INFO::CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer ) * Bezier curves are approximated by a polyline */ potrace_path_t* paths = m_Paths; // the list of paths + if(!m_Paths) + printf("NULL Paths!\n"); while( paths != NULL ) { int cnt = paths->curve.n;