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.

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