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.

279 lines
10 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
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2022 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_item.h>
  30. class PLOTTER;
  31. class PCB_TEXT;
  32. class PAD;
  33. class PCB_SHAPE;
  34. class PCB_DIMENSION_BASE;
  35. class FOOTPRINT;
  36. class FP_SHAPE;
  37. class PCB_TARGET;
  38. class FP_TEXT;
  39. class ZONE;
  40. class BOARD;
  41. class BOARD_ITEM;
  42. class REPORTER;
  43. class wxFileName;
  44. // Define min and max reasonable values for plot/print scale
  45. #define PLOT_MIN_SCALE 0.01
  46. #define PLOT_MAX_SCALE 100.0
  47. // A helper class to plot board items
  48. class BRDITEMS_PLOTTER : public PCB_PLOT_PARAMS
  49. {
  50. public:
  51. BRDITEMS_PLOTTER( PLOTTER* aPlotter, BOARD* aBoard, const PCB_PLOT_PARAMS& aPlotOpts )
  52. : PCB_PLOT_PARAMS( aPlotOpts )
  53. {
  54. m_plotter = aPlotter;
  55. m_board = aBoard;
  56. }
  57. /**
  58. * @return a 'width adjustment' for the postscript engine
  59. * (useful for controlling toner bleeding during direct transfer)
  60. * added to track width and via/pads size
  61. */
  62. int getFineWidthAdj() const
  63. {
  64. if( GetFormat() == PLOT_FORMAT::POST )
  65. return GetWidthAdjust();
  66. else
  67. return 0;
  68. }
  69. // Basic functions to plot a board item
  70. void SetLayerSet( LSET aLayerMask ) { m_layerMask = aLayerMask; }
  71. void PlotFootprintGraphicItems( const FOOTPRINT* aFootprint );
  72. void PlotFootprintShape( const FP_SHAPE* aShape );
  73. void PlotFootprintTextItem( const FP_TEXT* aText, const COLOR4D& aColor );
  74. /*
  75. * Reference, Value, and other fields are plotted only if the corresponding option is enabled.
  76. * Invisible text fields are plotted only if PlotInvisibleText option is set.
  77. */
  78. void PlotFootprintTextItems( const FOOTPRINT* aFootprint );
  79. void PlotDimension( const PCB_DIMENSION_BASE* aDim );
  80. void PlotPcbTarget( const PCB_TARGET* aMire );
  81. void PlotFilledAreas( const ZONE* aZone, PCB_LAYER_ID aLayer,
  82. const SHAPE_POLY_SET& aPolysList );
  83. void PlotPcbText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout );
  84. void PlotPcbShape( const PCB_SHAPE* aShape );
  85. /**
  86. * Plot a pad.
  87. *
  88. * Unlike other items, a pad had not a specific color and be drawn as a non filled item
  89. * although the plot mode is filled color and plot mode are needed by this function.
  90. */
  91. void PlotPad( const PAD* aPad, const COLOR4D& aColor, OUTLINE_MODE aPlotMode );
  92. /**
  93. * Plot items like text and graphics but not tracks and footprints.
  94. */
  95. void PlotBoardGraphicItems();
  96. void PlotPcbGraphicItem( const BOARD_ITEM* item );
  97. /**
  98. * Draw a drill mark for pads and vias.
  99. *
  100. * Must be called after all drawings, because it redraws the drill mark on a pad or via, as
  101. * a negative (i.e. white) shape in FILLED plot mode (for PS and PDF outputs).
  102. */
  103. void PlotDrillMarks();
  104. /**
  105. * White color is special because it cannot be seen on a white paper in B&W mode. It is
  106. * plotted as white but other colors are plotted in BLACK so the returned color is LIGHTGRAY
  107. * when the layer color is WHITE.
  108. *
  109. * @param aLayer is the layer id.
  110. * @return the layer color.
  111. */
  112. COLOR4D getColor( int aLayer ) const;
  113. private:
  114. /**
  115. * Helper function to plot a single drill mark.
  116. *
  117. * It compensate and clamp the drill mark size depending on the current plot options.
  118. */
  119. void plotOneDrillMark( PAD_DRILL_SHAPE_T aDrillShape, const VECTOR2I& aDrillPos,
  120. const VECTOR2I& aDrillSize, const VECTOR2I& aPadSize,
  121. const EDA_ANGLE& aOrientation, int aSmallDrill );
  122. PLOTTER* m_plotter;
  123. BOARD* m_board;
  124. LSET m_layerMask;
  125. };
  126. PLOTTER* StartPlotBoard( BOARD* aBoard, const PCB_PLOT_PARAMS* aPlotOpts, int aLayer,
  127. const wxString& aFullFileName, const wxString& aSheetName,
  128. const wxString& aSheetPath );
  129. /**
  130. * Plot a sequence of board layer IDs.
  131. *
  132. * @param aBoard is the board to plot.
  133. * @param aPlotter is the plotter to use.
  134. * @param aLayerSequence is the sequence of layer IDs to plot.
  135. * @param aPlotOptions are the plot options (files, sketch). Has meaning for some formats only.
  136. */
  137. void PlotBoardLayers( BOARD* aBoard, PLOTTER* aPlotter, const LSEQ& aLayerSequence,
  138. const PCB_PLOT_PARAMS& aPlotOptions );
  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_