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.

308 lines
11 KiB

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