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.

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