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.

280 lines
9.9 KiB

4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2023 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 PCBPLOT_H_
  24. #define PCBPLOT_H_
  25. #include <pad_shapes.h> // for PAD_DRILL_SHAPE_T
  26. #include <pcb_plot_params.h>
  27. #include <settings/color_settings.h>
  28. #include <settings/settings_manager.h>
  29. #include <board.h>
  30. #include <board_design_settings.h>
  31. #include <board_item.h>
  32. class EDA_TEXT;
  33. class PLOTTER;
  34. class PCB_TEXT;
  35. class PAD;
  36. class PCB_SHAPE;
  37. class PCB_DIMENSION_BASE;
  38. class FOOTPRINT;
  39. class PCB_TARGET;
  40. class ZONE;
  41. class REPORTER;
  42. class wxFileName;
  43. namespace KIFONT
  44. {
  45. class FONT;
  46. class METRICS;
  47. }
  48. // Define min and max reasonable values for plot/print scale
  49. #define PLOT_MIN_SCALE 0.01
  50. #define PLOT_MAX_SCALE 100.0
  51. // A helper class to plot board items
  52. class BRDITEMS_PLOTTER : public PCB_PLOT_PARAMS
  53. {
  54. public:
  55. BRDITEMS_PLOTTER( PLOTTER* aPlotter, BOARD* aBoard, const PCB_PLOT_PARAMS& aPlotOpts ) :
  56. PCB_PLOT_PARAMS( aPlotOpts ),
  57. m_plotter( aPlotter ),
  58. m_board( aBoard )
  59. { }
  60. /**
  61. * @return a 'width adjustment' for the postscript engine
  62. * (useful for controlling toner bleeding during direct transfer)
  63. * added to track width and via/pads size
  64. */
  65. int getFineWidthAdj() const
  66. {
  67. if( GetFormat() == PLOT_FORMAT::POST )
  68. return GetWidthAdjust();
  69. else
  70. return 0;
  71. }
  72. // Basic functions to plot a board item
  73. void SetLayerSet( LSET aLayerMask ) { m_layerMask = aLayerMask; }
  74. void PlotFootprintGraphicItems( const FOOTPRINT* aFootprint );
  75. void PlotFootprintTextItems( const FOOTPRINT* aFootprint );
  76. void PlotDimension( const PCB_DIMENSION_BASE* aDim );
  77. void PlotPcbTarget( const PCB_TARGET* aMire );
  78. void PlotZone( const ZONE* aZone, PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aPolysList );
  79. void PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout,
  80. const KIFONT::METRICS& aFontMetrics );
  81. void PlotShape( const PCB_SHAPE* aShape );
  82. /**
  83. * Plot a pad.
  84. *
  85. * Unlike other items, a pad had not a specific color and be drawn as a non filled item
  86. * although the plot mode is filled color and plot mode are needed by this function.
  87. */
  88. void PlotPad( const PAD* aPad, const COLOR4D& aColor, OUTLINE_MODE aPlotMode );
  89. /**
  90. * Plot items like text and graphics but not tracks and footprints.
  91. */
  92. void PlotBoardGraphicItem( const BOARD_ITEM* item );
  93. /**
  94. * Draw a drill mark for pads and vias.
  95. *
  96. * Must be called after all drawings, because it redraws the drill mark on a pad or via, as
  97. * a negative (i.e. white) shape in FILLED plot mode (for PS and PDF outputs).
  98. */
  99. void PlotDrillMarks();
  100. /**
  101. * White color is special because it cannot be seen on a white paper in B&W mode. It is
  102. * plotted as white but other colors are plotted in BLACK so the returned color is LIGHTGRAY
  103. * when the layer color is WHITE.
  104. *
  105. * @param aLayer is the layer id.
  106. * @return the layer color.
  107. */
  108. COLOR4D getColor( int aLayer ) const;
  109. private:
  110. /**
  111. * Helper function to plot a single drill mark.
  112. *
  113. * It compensate and clamp the drill mark size depending on the current plot options.
  114. */
  115. void plotOneDrillMark( PAD_DRILL_SHAPE_T aDrillShape, const VECTOR2I& aDrillPos,
  116. const VECTOR2I& aDrillSize, const VECTOR2I& aPadSize,
  117. const EDA_ANGLE& aOrientation, int aSmallDrill );
  118. PLOTTER* m_plotter;
  119. BOARD* m_board;
  120. LSET m_layerMask;
  121. };
  122. PLOTTER* StartPlotBoard( BOARD* aBoard, const PCB_PLOT_PARAMS* aPlotOpts, int aLayer,
  123. const wxString& aFullFileName, const wxString& aSheetName,
  124. const wxString& aSheetPath );
  125. /**
  126. * Plot a sequence of board layer IDs.
  127. *
  128. * @param aBoard is the board to plot.
  129. * @param aPlotter is the plotter to use.
  130. * @param aLayerSequence is the sequence of layer IDs to plot.
  131. * @param aPlotOptions are the plot options (files, sketch). Has meaning for some formats only.
  132. */
  133. void PlotBoardLayers( BOARD* aBoard, PLOTTER* aPlotter, const LSEQ& aLayerSequence,
  134. const PCB_PLOT_PARAMS& aPlotOptions );
  135. /**
  136. * Plot interactive items (hypertext links, properties, etc.).
  137. */
  138. void PlotInteractiveLayer( BOARD* aBoard, PLOTTER* aPlotter, const PCB_PLOT_PARAMS& aPlotOpt );
  139. /**
  140. * Plot one copper or technical layer.
  141. *
  142. * It prepares options and calls the specialized plot function according to the layer type.
  143. *
  144. * @param aBoard is the board to plot.
  145. * @param aPlotter is the plotter to use.
  146. * @param aLayer is the layer id to plot.
  147. * @param aPlotOpt is the plot options (files, sketch). Has meaning for some formats only.
  148. */
  149. void PlotOneBoardLayer( BOARD* aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
  150. const PCB_PLOT_PARAMS& aPlotOpt );
  151. /**
  152. * Plot copper or technical layers.
  153. *
  154. * This is not used for silk screen layers because these layers have specific requirements.
  155. * This is mainly for pads.
  156. *
  157. * @param aBoard is the board to plot.
  158. * @param aPlotter is the plotter to use.
  159. * @param aLayerMask is the mask to define the layers to plot.
  160. * @param aPlotOpt is the plot options (files, sketch). Has meaning for some formats only.
  161. *
  162. * aPlotOpt has 3 important options which are set depending on the layer type to plot:
  163. * SetEnablePlotVia( bool aEnable )
  164. * aEnable = true to plot vias, false to skip vias (has meaning only for solder mask layers)
  165. * SetSkipPlotNPTH_Pads( bool aSkip )
  166. * aSkip = true to skip NPTH Pads, when the pad size and the pad hole have the same size.
  167. * Used in GERBER format only.
  168. * SetDrillMarksType( DrillMarksType aVal )
  169. * aVal = no hole, small hole, actual hole size
  170. */
  171. void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
  172. const PCB_PLOT_PARAMS& aPlotOpt );
  173. /**
  174. * Plot copper outline of a copper layer.
  175. *
  176. * @param aBoard is the board to plot.
  177. * @param aPlotter is the plotter to use.
  178. * @param aLayerMask is the mask to define the layers to plot.
  179. * @param aPlotOpt is the plot options. Has meaning for some formats only.
  180. */
  181. void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
  182. const PCB_PLOT_PARAMS& aPlotOpt );
  183. /**
  184. * Complete a plot filename.
  185. *
  186. * It forces the output directory, adds a suffix to the name, and sets the specified extension.
  187. * The suffix is usually the layer name and replaces illegal file name character in the suffix
  188. * with an underscore character.
  189. *
  190. * @param aFilename is the file name to initialize that contains the base filename.
  191. * @param aOutputDir is the path.
  192. * @param aSuffix is the suffix to add to the base filename.
  193. * @param aExtension is the file extension.
  194. */
  195. void BuildPlotFileName( wxFileName* aFilename, const wxString& aOutputDir, const wxString& aSuffix,
  196. const wxString& aExtension );
  197. /**
  198. * @return the appropriate Gerber file extension for \a aLayer
  199. */
  200. const wxString GetGerberProtelExtension( int aLayer );
  201. /**
  202. * Return the "file function" attribute for \a aLayer, as defined in the
  203. * Gerber file format specification J1 (chapter 5).
  204. *
  205. * The returned string includes the "%TF.FileFunction" attribute prefix and the "*%" suffix.
  206. *
  207. * @param aBoard is the board, needed to get the total count of copper layers.
  208. * @param aLayer is the layer number to create the attribute for.
  209. * @return The attribute, as a text string
  210. */
  211. const wxString GetGerberFileFunctionAttribute( const BOARD* aBoard, int aLayer );
  212. /**
  213. * Calculate some X2 attributes as defined in the Gerber file format specification J4
  214. * (chapter 5) and add them the to the gerber file header.
  215. *
  216. * TF.GenerationSoftware
  217. * TF.CreationDate
  218. * TF.ProjectId
  219. * file format attribute is not added
  220. *
  221. * @param aPlotter is the current plotter.
  222. * @param aBoard is the board, needed to extract some info.
  223. * @param aUseX1CompatibilityMode set to false to generate X2 attributes, true to
  224. * use X1 compatibility (X2 attributes added as structured comments,
  225. * starting by "G04 #@! " followed by the X2 attribute
  226. */
  227. void AddGerberX2Header( PLOTTER* aPlotter, const BOARD* aBoard,
  228. bool aUseX1CompatibilityMode = false );
  229. /**
  230. * Calculate some X2 attributes as defined in the Gerber file format specification and add them
  231. * to the gerber file header.
  232. *
  233. * TF.GenerationSoftware
  234. * TF.CreationDate
  235. * TF.ProjectId
  236. * TF.FileFunction
  237. * TF.FilePolarity
  238. *
  239. * @param aPlotter is the current plotter.
  240. * @param aBoard is the board, needed to extract some info.
  241. * @param aLayer is the layer number to create the attribute for.
  242. * @param aUseX1CompatibilityMode set to false to generate X2 attributes, true to use X1
  243. * compatibility (X2 attributes added as structured comments, starting by "G04 #@! "
  244. * followed by the X2 attribute.
  245. */
  246. void AddGerberX2Attribute( PLOTTER* aPlotter, const BOARD* aBoard, int aLayer,
  247. bool aUseX1CompatibilityMode );
  248. #endif // PCBPLOT_H_