KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bitmap2cmp_panel.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19#ifndef BITMAP2CMP_PANEL_H
20#define BITMAP2CMP_PANEL_H
21
23#include <eda_units.h>
24#include <wx/dnd.h>
25
28
29
31{
32public:
33 IMAGE_SIZE();
34
35 // Set the unit used for m_outputSize, and convert the old m_outputSize value
36 // to the value in new unit
37 void SetUnit( EDA_UNITS aUnit );
38
39 void SetOriginalDPI( int aDPI ) { m_originalDPI = aDPI; }
40
41 void SetOriginalSizePixels( int aPixels ) { m_originalSizePixels = aPixels; }
43
44 double GetOutputSize() { return m_outputSize; }
45 void SetOutputSize( double aSize, EDA_UNITS aUnit ) { m_outputSize = aSize; m_unit = aUnit; }
46
47 // Set the m_outputSize value from the m_originalSizePixels and the selected unit
49
53 int GetOutputDPI();
54
55private:
56 EDA_UNITS m_unit; // The units for m_outputSize (mm, inch, dpi)
57 double m_outputSize; // The size in m_unit of the output image, depending on
58 // the user settings. Set to the initial image size
59 int m_originalDPI; // The image DPI if specified in file, or 0 if unknown
60 int m_originalSizePixels; // The original image size read from file, in pixels
61};
62
63
65{
66public:
69
70 bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl = 0 );
71
72 void OnLoadFile( wxCommandEvent& event ) override;
73
76
77 wxWindow* GetCurrentPage();
78
81 void SetOutputSize( const IMAGE_SIZE& aSizeX, const IMAGE_SIZE& aSizeY );
82
88 void ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat );
89
90private:
91 // Event handlers
92 void OnPaintInit( wxPaintEvent& event ) override;
93 void OnPaintGreyscale( wxPaintEvent& event ) override;
94 void OnPaintBW( wxPaintEvent& event ) override;
95 void OnExportToFile( wxCommandEvent& event ) override;
96 void OnExportToClipboard( wxCommandEvent& event ) override;
97 void OnFormatChange( wxCommandEvent& event ) override;
98 void OnNegativeClicked( wxCommandEvent& event ) override;
99 void OnThresholdChange( wxScrollEvent& event ) override;
100 void OnSizeChangeX( wxCommandEvent& event ) override;
101 void OnSizeChangeY( wxCommandEvent& event ) override;
102 void OnSizeUnitChange( wxCommandEvent& event ) override;
103 void ToggleAspectRatioLock( wxCommandEvent& event ) override;
104
106
109
110 // return a string giving the output size, according to the selected unit
111 wxString formatOutputSize( double aSize );
112
113 void binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
114
116
117 void updateImageInfo();
118
119private:
121
126 wxImage m_NB_Image;
127 wxBitmap m_BN_Bitmap;
132};
133
134
135class DROP_FILE : public wxFileDropTarget
136{
137public:
138 DROP_FILE( BITMAP2CMP_PANEL* panel );
139 DROP_FILE() = delete;
140
141 bool OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames ) override;
142
143private:
145};
146
147#endif// BITMAP2CMP_PANEL
OUTPUT_FMT_ID
BITMAP2CMP_PANEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
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)
IMAGE_SIZE GetOutputSizeX() const
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)
IMAGE_SIZE GetOutputSizeY() const
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
EDA_UNITS getUnitFromSelection()
void OnNegativeClicked(wxCommandEvent &event) override
void OnPaintBW(wxPaintEvent &event) override
OUTPUT_FMT_ID getOutputFormat()
void OnSizeChangeY(wxCommandEvent &event) override
BITMAP2CMP_PANEL * m_panel
DROP_FILE(BITMAP2CMP_PANEL *panel)
DROP_FILE()=delete
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames) override
void SetUnit(EDA_UNITS aUnit)
double m_outputSize
double GetOutputSize()
EDA_UNITS m_unit
void SetOriginalDPI(int aDPI)
int GetOriginalSizePixels()
void SetOutputSizeFromInitialImageSize()
void SetOutputSize(double aSize, EDA_UNITS aUnit)
void SetOriginalSizePixels(int aPixels)
EDA_UNITS
Definition eda_units.h:44