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.

175 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 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 <common.h> // for EDA_UNITS
  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. private:
  79. // Event handlers
  80. void OnPaintInit( wxPaintEvent& event ) override;
  81. void OnPaintGreyscale( wxPaintEvent& event ) override;
  82. void OnPaintBW( wxPaintEvent& event ) override;
  83. void OnLoadFile( wxCommandEvent& event ) override;
  84. void OnExportToFile( wxCommandEvent& event ) override;
  85. void OnExportToClipboard( wxCommandEvent& event ) override;
  86. ///> @return the EDA_UNITS from the m_PixelUnit choice
  87. EDA_UNITS getUnitFromSelection();
  88. // return a string giving the output size, according to the selected unit
  89. wxString FormatOutputSize( double aSize );
  90. /**
  91. * Generate a schematic library which contains one component:
  92. * the logo
  93. */
  94. void exportEeschemaFormat();
  95. /**
  96. * Generate a module in S expr format
  97. */
  98. void exportPcbnewFormat();
  99. /**
  100. * Generate a postscript file
  101. */
  102. void exportPostScriptFormat();
  103. /**
  104. * Generate a file suitable to be copied into a page layout
  105. * description file (.kicad_wks file
  106. */
  107. void OnExportLogo();
  108. void Binarize( double aThreshold ); // aThreshold = 0.0 (black level) to 1.0 (white level)
  109. void OnNegativeClicked( wxCommandEvent& event ) override;
  110. void OnThresholdChange( wxScrollEvent& event ) override;
  111. void OnSizeChangeX( wxCommandEvent& event ) override;
  112. void OnSizeChangeY( wxCommandEvent& event ) override;
  113. void OnSizeUnitChange( wxCommandEvent& event ) override;
  114. void ToggleAspectRatioLock( wxCommandEvent& event ) override;
  115. void NegateGreyscaleImage();
  116. /**
  117. * generate a export data of the current bitmap.
  118. * @param aOutput is a string buffer to fill with data
  119. * @param aFormat is the format to generate
  120. */
  121. void ExportToBuffer( std::string& aOutput, OUTPUT_FMT_ID aFormat );
  122. void updateImageInfo();
  123. void OnFormatChange( wxCommandEvent& event ) override;
  124. void exportBitmap( OUTPUT_FMT_ID aFormat );
  125. void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
  126. void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
  127. wxWindow* GetToolCanvas() const override;
  128. private:
  129. wxImage m_Pict_Image;
  130. wxBitmap m_Pict_Bitmap;
  131. wxImage m_Greyscale_Image;
  132. wxBitmap m_Greyscale_Bitmap;
  133. wxImage m_NB_Image;
  134. wxBitmap m_BN_Bitmap;
  135. IMAGE_SIZE m_outputSizeX;
  136. IMAGE_SIZE m_outputSizeY;
  137. bool m_Negative;
  138. wxString m_BitmapFileName;
  139. wxString m_ConvertedFileName;
  140. bool m_exportToClipboard;
  141. bool m_AspectRatioLocked;
  142. double m_AspectRatio;
  143. };
  144. #endif// BITMOP2CMP_GUI_H_