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.

157 lines
5.0 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 BITMAP2CMP_PANEL_H
  24. #define BITMAP2CMP_PANEL_H
  25. #include <bitmap2cmp_panel_base.h>
  26. #include <eda_units.h>
  27. class BITMAP2CMP_FRAME;
  28. class BITMAP2CMP_SETTINGS;
  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 BITMAP2CMP_PANEL : public BITMAP2CMP_PANEL_BASE
  72. {
  73. public:
  74. BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent );
  75. ~BITMAP2CMP_PANEL();
  76. bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl = 0 );
  77. void OnLoadFile( wxCommandEvent& event ) override;
  78. void LoadSettings( BITMAP2CMP_SETTINGS* aCfg );
  79. void SaveSettings( BITMAP2CMP_SETTINGS* aCfg );
  80. wxWindow* GetCurrentPage();
  81. IMAGE_SIZE GetOutputSizeX() const { return m_outputSizeX; }
  82. IMAGE_SIZE GetOutputSizeY() const { return m_outputSizeY; }
  83. void SetOutputSize( const IMAGE_SIZE& aSizeX, const IMAGE_SIZE& aSizeY );
  84. /**
  85. * generate a export data of the current bitmap.
  86. * @param aOutput is a string buffer to fill with data
  87. * @param aFormat is the format to generate
  88. */
  89. void ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat );
  90. private:
  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. ///< @return the EDA_UNITS from the m_PixelUnit choice
  98. EDA_UNITS getUnitFromSelection();
  99. // return a string giving the output size, according to the selected unit
  100. wxString FormatOutputSize( double aSize );
  101. void Binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
  102. void OnNegativeClicked( wxCommandEvent& event ) override;
  103. void OnThresholdChange( wxScrollEvent& event ) override;
  104. void OnSizeChangeX( wxCommandEvent& event ) override;
  105. void OnSizeChangeY( wxCommandEvent& event ) override;
  106. void OnSizeUnitChange( wxCommandEvent& event ) override;
  107. void ToggleAspectRatioLock( wxCommandEvent& event ) override;
  108. void NegateGreyscaleImage();
  109. void updateImageInfo();
  110. void OnFormatChange( wxCommandEvent& event ) override;
  111. void exportBitmap( OUTPUT_FMT_ID aFormat );
  112. private:
  113. BITMAP2CMP_FRAME* m_parentFrame;
  114. wxImage m_Pict_Image;
  115. wxBitmap m_Pict_Bitmap;
  116. wxImage m_Greyscale_Image;
  117. wxBitmap m_Greyscale_Bitmap;
  118. wxImage m_NB_Image;
  119. wxBitmap m_BN_Bitmap;
  120. IMAGE_SIZE m_outputSizeX;
  121. IMAGE_SIZE m_outputSizeY;
  122. bool m_negative;
  123. double m_aspectRatio;
  124. };
  125. #endif// BITMAP2CMP_PANEL