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

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