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.

281 lines
10 KiB

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