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.

151 lines
5.2 KiB

  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, 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. #include <wx/dnd.h>
  28. class BITMAP2CMP_FRAME;
  29. class BITMAP2CMP_SETTINGS;
  30. class IMAGE_SIZE
  31. {
  32. public:
  33. IMAGE_SIZE();
  34. // Set the unit used for m_outputSize, and convert the old m_outputSize value
  35. // to the value in new unit
  36. void SetUnit( EDA_UNITS aUnit );
  37. void SetOriginalDPI( int aDPI ) { m_originalDPI = aDPI; }
  38. void SetOriginalSizePixels( int aPixels ) { m_originalSizePixels = aPixels; }
  39. int GetOriginalSizePixels() { return m_originalSizePixels; }
  40. double GetOutputSize() { return m_outputSize; }
  41. void SetOutputSize( double aSize, EDA_UNITS aUnit ) { m_outputSize = aSize; m_unit = aUnit; }
  42. // Set the m_outputSize value from the m_originalSizePixels and the selected unit
  43. void SetOutputSizeFromInitialImageSize();
  44. /** @return the pixels per inch value to build the output image.
  45. * It is used by potrace to build the polygonal image
  46. */
  47. int GetOutputDPI();
  48. private:
  49. EDA_UNITS m_unit; // The units for m_outputSize (mm, inch, dpi)
  50. double m_outputSize; // The size in m_unit of the output image, depending on
  51. // the user settings. Set to the initial image size
  52. int m_originalDPI; // The image DPI if specified in file, or 0 if unknown
  53. int m_originalSizePixels; // The original image size read from file, in pixels
  54. };
  55. class BITMAP2CMP_PANEL : public BITMAP2CMP_PANEL_BASE
  56. {
  57. public:
  58. BITMAP2CMP_PANEL( BITMAP2CMP_FRAME* aParent );
  59. ~BITMAP2CMP_PANEL() {}
  60. bool OpenProjectFiles( const std::vector<wxString>& aFilenames, int aCtl = 0 );
  61. void OnLoadFile( wxCommandEvent& event ) override;
  62. void LoadSettings( BITMAP2CMP_SETTINGS* aCfg );
  63. void SaveSettings( BITMAP2CMP_SETTINGS* aCfg );
  64. wxWindow* GetCurrentPage();
  65. IMAGE_SIZE GetOutputSizeX() const { return m_outputSizeX; }
  66. IMAGE_SIZE GetOutputSizeY() const { return m_outputSizeY; }
  67. void SetOutputSize( const IMAGE_SIZE& aSizeX, const IMAGE_SIZE& aSizeY );
  68. /**
  69. * generate a export data of the current bitmap.
  70. * @param aOutput is a string buffer to fill with data
  71. * @param aFormat is the format to generate
  72. */
  73. void ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat );
  74. private:
  75. // Event handlers
  76. void OnPaintInit( wxPaintEvent& event ) override;
  77. void OnPaintGreyscale( wxPaintEvent& event ) override;
  78. void OnPaintBW( wxPaintEvent& event ) override;
  79. void OnExportToFile( wxCommandEvent& event ) override;
  80. void OnExportToClipboard( wxCommandEvent& event ) override;
  81. void OnFormatChange( wxCommandEvent& event ) override;
  82. void OnNegativeClicked( wxCommandEvent& event ) override;
  83. void OnThresholdChange( wxScrollEvent& event ) override;
  84. void OnSizeChangeX( wxCommandEvent& event ) override;
  85. void OnSizeChangeY( wxCommandEvent& event ) override;
  86. void OnSizeUnitChange( wxCommandEvent& event ) override;
  87. void ToggleAspectRatioLock( wxCommandEvent& event ) override;
  88. OUTPUT_FMT_ID getOutputFormat();
  89. ///< @return the EDA_UNITS from the m_PixelUnit choice
  90. EDA_UNITS getUnitFromSelection();
  91. // return a string giving the output size, according to the selected unit
  92. wxString formatOutputSize( double aSize );
  93. void binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
  94. void negateGreyscaleImage();
  95. void updateImageInfo();
  96. private:
  97. BITMAP2CMP_FRAME* m_parentFrame;
  98. wxImage m_Pict_Image;
  99. wxBitmap m_Pict_Bitmap;
  100. wxImage m_Greyscale_Image;
  101. wxBitmap m_Greyscale_Bitmap;
  102. wxImage m_NB_Image;
  103. wxBitmap m_BN_Bitmap;
  104. IMAGE_SIZE m_outputSizeX;
  105. IMAGE_SIZE m_outputSizeY;
  106. bool m_negative;
  107. double m_aspectRatio;
  108. };
  109. class DROP_FILE : public wxFileDropTarget
  110. {
  111. public:
  112. DROP_FILE( BITMAP2CMP_PANEL* panel );
  113. DROP_FILE() = delete;
  114. bool OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames ) override;
  115. private:
  116. BITMAP2CMP_PANEL* m_panel;
  117. };
  118. #endif// BITMAP2CMP_PANEL