You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.4 KiB

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