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.

275 lines
9.7 KiB

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