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.

277 lines
9.8 KiB

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