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.

113 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2014 Kicad Developers, see change_log.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 BITMAP2COMPONENT_H
  24. #define BITMAP2COMPONENT_H
  25. #include <geometry/shape_poly_set.h>
  26. #include <potracelib.h>
  27. // for consistency this enum should conform to the
  28. // indices in m_radioBoxFormat from bitmap2cmp_gui.cpp
  29. enum OUTPUT_FMT_ID
  30. {
  31. EESCHEMA_FMT = 0,
  32. PCBNEW_KICAD_MOD,
  33. POSTSCRIPT_FMT,
  34. KICAD_LOGO,
  35. FINAL_FMT = KICAD_LOGO
  36. };
  37. enum BMP2CMP_MOD_LAYER
  38. {
  39. MOD_LYR_FSILKS = 0,
  40. MOD_LYR_FSOLDERMASK,
  41. MOD_LYR_ECO1,
  42. MOD_LYR_ECO2,
  43. MOD_LYR_FINAL = MOD_LYR_ECO2
  44. };
  45. /* Helper class to handle useful info to convert a bitmap image to
  46. * a polygonal object description
  47. */
  48. class BITMAPCONV_INFO
  49. {
  50. private:
  51. enum OUTPUT_FMT_ID m_Format; // File format
  52. int m_PixmapWidth;
  53. int m_PixmapHeight; // the bitmap size in pixels
  54. double m_ScaleX;
  55. double m_ScaleY; // the conversion scale
  56. potrace_path_t* m_Paths; // the list of paths, from potrace (list of lines and bezier curves)
  57. std::string m_CmpName; // The string used as cmp/footprint name
  58. std::string& m_Data; // the buffer containing the conversion
  59. std::string m_errors; // a buffer to return error messages
  60. public:
  61. BITMAPCONV_INFO( std::string& aData );
  62. /**
  63. * Run the conversion of the bitmap
  64. */
  65. int ConvertBitmap( potrace_bitmap_t* aPotrace_bitmap,
  66. OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y,
  67. BMP2CMP_MOD_LAYER aModLayer );
  68. std::string& GetErrorMessages() {return m_errors; }
  69. private:
  70. /**
  71. * Creates the data specified by m_Format
  72. */
  73. void createOutputData( BMP2CMP_MOD_LAYER aModLayer = (BMP2CMP_MOD_LAYER) 0 );
  74. /**
  75. * Function outputDataHeader
  76. * write to file the header depending on file format
  77. */
  78. void outputDataHeader( const char * aBrdLayerName );
  79. /**
  80. * Function outputDataEnd
  81. * write to file the last strings depending on file format
  82. */
  83. void outputDataEnd();
  84. /**
  85. * @return the board layer name depending on the board layer selected
  86. * @param aChoice = the choice (MOD_LYR_FSILKS to MOD_LYR_FINAL)
  87. */
  88. const char * getBoardLayerName( BMP2CMP_MOD_LAYER aChoice );
  89. /**
  90. * Function outputOnePolygon
  91. * write one polygon to output file.
  92. * Polygon coordinates are expected scaled by the polygon extraction function
  93. */
  94. void outputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* aBrdLayerName );
  95. };
  96. #endif // BITMAP2COMPONENT_H