1 /*
2  * This program source code file is part of KICAD, a free EDA CAD application.
3  *
4  * Copyright (C) 2019-2021 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, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
22  */
23 #ifndef BITMOP2CMP_GUI_H_
24 #define BITMOP2CMP_GUI_H_
25 
26 #include "bitmap2component.h"
27 
28 #include "bitmap2cmp_gui_base.h"
29 #include <eda_units.h>
30 #include <potracelib.h>
31 
32 
33 class IMAGE_SIZE
34 {
35 public:
36     IMAGE_SIZE();
37 
38     // Set the unit used for m_outputSize, and convert the old m_outputSize value
39     // to the value in new unit
40     void SetUnit( EDA_UNITS aUnit );
41 
42     // Accessors:
SetOriginalDPI(int aDPI)43     void SetOriginalDPI( int aDPI )
44     {
45         m_originalDPI = aDPI;
46     }
47 
SetOriginalSizePixels(int aPixels)48     void SetOriginalSizePixels( int aPixels )
49     {
50         m_originalSizePixels = aPixels;
51     }
52 
GetOutputSize()53     double GetOutputSize()
54     {
55         return m_outputSize;
56     }
57 
SetOutputSize(double aSize,EDA_UNITS aUnit)58     void SetOutputSize( double aSize, EDA_UNITS aUnit )
59     {
60         m_unit = aUnit;
61         m_outputSize = aSize;
62     }
63 
GetOriginalSizePixels()64     int  GetOriginalSizePixels()
65     {
66         return m_originalSizePixels;
67     }
68 
69     // Set the m_outputSize value from the m_originalSizePixels and the selected unit
70     void SetOutputSizeFromInitialImageSize();
71 
72     /** @return the pixels per inch value to build the output image.
73      * It is used by potrace to build the polygonal image
74      */
75     int GetOutputDPI();
76 
77 private:
78     EDA_UNITS m_unit;                 // The units for m_outputSize (mm, inch, dpi)
79     double    m_outputSize;           // The size in m_unit of the output image, depending on
80                                       // the user settings. Set to the initial image size
81     int       m_originalDPI;          // The image DPI if specified in file, or 0 if unknown
82     int       m_originalSizePixels;   // The original image size read from file, in pixels
83 };
84 
85 class BM2CMP_FRAME : public BM2CMP_FRAME_BASE
86 {
87 public:
88     BM2CMP_FRAME( KIWAY* aKiway, wxWindow* aParent );
89     ~BM2CMP_FRAME();
90 
91     // overload KIWAY_PLAYER virtual
92     bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl = 0 ) override;
93 
94 private:
95     // Event handlers
96     void OnPaintInit( wxPaintEvent& event ) override;
97     void OnPaintGreyscale( wxPaintEvent& event ) override;
98     void OnPaintBW( wxPaintEvent& event ) override;
99     void OnLoadFile( wxCommandEvent& event ) override;
100     void OnExportToFile( wxCommandEvent& event ) override;
101     void OnExportToClipboard( wxCommandEvent& event ) override;
102 
103     ///< @return the EDA_UNITS from the m_PixelUnit choice
104     EDA_UNITS getUnitFromSelection();
105 
106     // return a string giving the output size, according to the selected unit
107     wxString FormatOutputSize( double aSize );
108 
109     /**
110      * Generate a schematic library which contains one component:
111      * the logo
112      */
113     void exportEeschemaFormat();
114 
115     /**
116      * Generate a footprint in S expr format
117      */
118     void exportPcbnewFormat();
119 
120     /**
121      * Generate a postscript file
122      */
123     void exportPostScriptFormat();
124 
125     /**
126      * Generate a file suitable to be copied into a drawing sheet (.kicad_wks) file
127      */
128     void OnExportLogo();
129 
130     void Binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
131     void OnNegativeClicked( wxCommandEvent& event ) override;
132     void OnThresholdChange( wxScrollEvent& event ) override;
133 
134     void OnSizeChangeX( wxCommandEvent& event ) override;
135     void OnSizeChangeY( wxCommandEvent& event ) override;
136     void OnSizeUnitChange( wxCommandEvent& event ) override;
137 
138     void ToggleAspectRatioLock( wxCommandEvent& event ) override;
139 
140 
141     void NegateGreyscaleImage();
142     /**
143      * generate a export data of the current bitmap.
144      * @param aOutput is a string buffer to fill with data
145      * @param aFormat is the format to generate
146      */
147     void ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat );
148 
149     void updateImageInfo();
150     void OnFormatChange( wxCommandEvent& event ) override;
151     void exportBitmap( OUTPUT_FMT_ID aFormat );
152 
153     void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
154     void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
155 
156     wxWindow* GetToolCanvas() const override;
157 
158 private:
159     wxImage    m_Pict_Image;
160     wxBitmap   m_Pict_Bitmap;
161     wxImage    m_Greyscale_Image;
162     wxBitmap   m_Greyscale_Bitmap;
163     wxImage    m_NB_Image;
164     wxBitmap   m_BN_Bitmap;
165     IMAGE_SIZE m_outputSizeX;
166     IMAGE_SIZE m_outputSizeY;
167     bool       m_Negative;
168     wxString   m_BitmapFileName;
169     wxString   m_ConvertedFileName;
170     bool       m_exportToClipboard;
171     bool       m_AspectRatioLocked;
172     double     m_AspectRatio;
173 };
174 #endif// BITMOP2CMP_GUI_H_
175