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.

302 lines
11 KiB

5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The 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. #ifndef PCBPLOT_H_
  24. #define PCBPLOT_H_
  25. #include <lset.h>
  26. #include <padstack.h> // for PAD_DRILL_SHAPE
  27. #include <pcb_plot_params.h>
  28. #include <settings/color_settings.h>
  29. #include <settings/settings_manager.h>
  30. #include <board.h>
  31. #include <board_design_settings.h>
  32. #include <board_item.h>
  33. class EDA_TEXT;
  34. class PLOTTER;
  35. class PCB_TEXT;
  36. class PAD;
  37. class PCB_SHAPE;
  38. class PCB_TABLE;
  39. class PCB_DIMENSION_BASE;
  40. class FOOTPRINT;
  41. class PCB_TARGET;
  42. class ZONE;
  43. class REPORTER;
  44. class wxFileName;
  45. namespace KIFONT
  46. {
  47. class FONT;
  48. class METRICS;
  49. }
  50. // Define min and max reasonable values for plot/print scale
  51. #define PLOT_MIN_SCALE 0.01
  52. #define PLOT_MAX_SCALE 100.0
  53. // A helper class to plot board items
  54. class BRDITEMS_PLOTTER : public PCB_PLOT_PARAMS
  55. {
  56. public:
  57. BRDITEMS_PLOTTER( PLOTTER* aPlotter, BOARD* aBoard, const PCB_PLOT_PARAMS& aPlotOpts ) :
  58. PCB_PLOT_PARAMS( aPlotOpts ),
  59. m_plotter( aPlotter ),
  60. m_board( aBoard )
  61. { }
  62. /**
  63. * @return a 'width adjustment' for the postscript engine
  64. * (useful for controlling toner bleeding during direct transfer)
  65. * added to track width and via/pads size
  66. */
  67. int getFineWidthAdj() const
  68. {
  69. if( GetFormat() == PLOT_FORMAT::POST )
  70. return GetWidthAdjust();
  71. else
  72. return 0;
  73. }
  74. // Basic functions to plot a board item
  75. void SetLayerSet( LSET aLayerMask ) { m_layerMask = aLayerMask; }
  76. void PlotFootprintGraphicItems( const FOOTPRINT* aFootprint );
  77. void PlotFootprintTextItems( const FOOTPRINT* aFootprint );
  78. void PlotDimension( const PCB_DIMENSION_BASE* aDim );
  79. void PlotPcbTarget( const PCB_TARGET* aMire );
  80. void PlotZone( const ZONE* aZone, PCB_LAYER_ID aLayer, const SHAPE_POLY_SET& aPolysList );
  81. void PlotText( const EDA_TEXT* aText, PCB_LAYER_ID aLayer, bool aIsKnockout,
  82. const KIFONT::METRICS& aFontMetrics, bool aStrikeout = false );
  83. void PlotShape( const PCB_SHAPE* aShape );
  84. void PlotTableBorders( const PCB_TABLE* aTable );
  85. /**
  86. * Plot a pad.
  87. *
  88. * Unlike other items, a pad had not a specific color and be drawn as a non filled item
  89. * although the plot mode is filled color and plot mode are needed by this function.
  90. */
  91. void PlotPad( const PAD* aPad, PCB_LAYER_ID aLayer, const COLOR4D& aColor,
  92. OUTLINE_MODE aPlotMode );
  93. void PlotPadNumber( const PAD* aPad, const COLOR4D& aColor );
  94. /**
  95. * Plot items like text and graphics but not tracks and footprints.
  96. */
  97. void PlotBoardGraphicItem( const BOARD_ITEM* item );
  98. /**
  99. * Draw a drill mark for pads and vias.
  100. *
  101. * Must be called after all drawings, because it redraws the drill mark on a pad or via, as
  102. * a negative (i.e. white) shape in FILLED plot mode (for PS and PDF outputs).
  103. */
  104. void PlotDrillMarks();
  105. /**
  106. * White color is special because it cannot be seen on a white paper in B&W mode. It is
  107. * plotted as white but other colors are plotted in BLACK so the returned color is LIGHTGRAY
  108. * when the layer color is WHITE.
  109. *
  110. * @param aLayer is the layer id.
  111. * @return the layer color.
  112. */
  113. COLOR4D getColor( int aLayer ) const;
  114. private:
  115. bool hideDNPItems( PCB_LAYER_ID aLayer )
  116. {
  117. return GetHideDNPFPsOnFabLayers() && ( aLayer == F_Fab || aLayer == B_Fab );
  118. }
  119. bool crossoutDNPItems( PCB_LAYER_ID aLayer )
  120. {
  121. return GetCrossoutDNPFPsOnFabLayers() && ( aLayer == F_Fab || aLayer == B_Fab );
  122. }
  123. /**
  124. * Helper function to plot a single drill mark.
  125. *
  126. * It compensate and clamp the drill mark size depending on the current plot options.
  127. */
  128. void plotOneDrillMark( PAD_DRILL_SHAPE aDrillShape, const VECTOR2I& aDrillPos,
  129. const VECTOR2I& aDrillSize, const VECTOR2I& aPadSize,
  130. const EDA_ANGLE& aOrientation, int aSmallDrill );
  131. PLOTTER* m_plotter;
  132. BOARD* m_board;
  133. LSET m_layerMask;
  134. };
  135. PLOTTER* StartPlotBoard( BOARD* aBoard, const PCB_PLOT_PARAMS* aPlotOpts, int aLayer,
  136. const wxString& aLayerName, const wxString& aFullFileName,
  137. const wxString& aSheetName, const wxString& aSheetPath,
  138. const wxString& aPageName = wxT( "1" ),
  139. const wxString& aPageNumber = wxEmptyString,
  140. const int aPageCount = 1);
  141. void setupPlotterNewPDFPage( PLOTTER* aPlotter, BOARD* aBoard, const PCB_PLOT_PARAMS* aPlotOpts,
  142. const wxString& aSheetName, const wxString& aSheetPath,
  143. const wxString& aPageNumber, int aPageCount );
  144. /**
  145. * Plot a sequence of board layer IDs.
  146. *
  147. * @param aBoard is the board to plot.
  148. * @param aPlotter is the plotter to use.
  149. * @param aLayerSequence is the sequence of layer IDs to plot.
  150. * @param aPlotOptions are the plot options (files, sketch). Has meaning for some formats only.
  151. */
  152. void PlotBoardLayers( BOARD* aBoard, PLOTTER* aPlotter, const LSEQ& aLayerSequence,
  153. const PCB_PLOT_PARAMS& aPlotOptions );
  154. /**
  155. * Plot interactive items (hypertext links, properties, etc.).
  156. */
  157. void PlotInteractiveLayer( BOARD* aBoard, PLOTTER* aPlotter, const PCB_PLOT_PARAMS& aPlotOpt );
  158. /**
  159. * Plot one copper or technical layer.
  160. *
  161. * It prepares options and calls the specialized plot function according to the layer type.
  162. *
  163. * @param aBoard is the board to plot.
  164. * @param aPlotter is the plotter to use.
  165. * @param aLayer is the layer id to plot.
  166. * @param aPlotOpt is the plot options (files, sketch). Has meaning for some formats only.
  167. */
  168. void PlotOneBoardLayer( BOARD* aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
  169. const PCB_PLOT_PARAMS& aPlotOpt, bool isPrimaryLayer );
  170. /**
  171. * Plot copper or technical layers.
  172. *
  173. * This is not used for silk screen layers because these layers have specific requirements.
  174. * This is mainly for pads.
  175. *
  176. * @param aBoard is the board to plot.
  177. * @param aPlotter is the plotter to use.
  178. * @param aLayerMask is the mask to define the layers to plot.
  179. * @param aPlotOpt is the plot options (files, sketch). Has meaning for some formats only.
  180. *
  181. * aPlotOpt has 3 important options which are set depending on the layer type to plot:
  182. * SetEnablePlotVia( bool aEnable )
  183. * aEnable = true to plot vias, false to skip vias (has meaning only for solder mask layers)
  184. * SetSkipPlotNPTH_Pads( bool aSkip )
  185. * aSkip = true to skip NPTH Pads, when the pad size and the pad hole have the same size.
  186. * Used in GERBER format only.
  187. * SetDrillMarksType( DrillMarksType aVal )
  188. * aVal = no hole, small hole, actual hole size
  189. */
  190. void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
  191. const PCB_PLOT_PARAMS& aPlotOpt );
  192. /**
  193. * Plot copper outline of a copper layer.
  194. *
  195. * @param aBoard is the board to plot.
  196. * @param aPlotter is the plotter to use.
  197. * @param aLayerMask is the mask to define the layers to plot.
  198. * @param aPlotOpt is the plot options. Has meaning for some formats only.
  199. */
  200. void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, LSET aLayerMask,
  201. const PCB_PLOT_PARAMS& aPlotOpt );
  202. /**
  203. * Complete a plot filename.
  204. *
  205. * It forces the output directory, adds a suffix to the name, and sets the specified extension.
  206. * The suffix is usually the layer name and replaces illegal file name character in the suffix
  207. * with an underscore character.
  208. *
  209. * @param aFilename is the file name to initialize that contains the base filename.
  210. * @param aOutputDir is the path.
  211. * @param aSuffix is the suffix to add to the base filename.
  212. * @param aExtension is the file extension.
  213. */
  214. void BuildPlotFileName( wxFileName* aFilename, const wxString& aOutputDir, const wxString& aSuffix,
  215. const wxString& aExtension );
  216. /**
  217. * @return the appropriate Gerber file extension for \a aLayer
  218. */
  219. const wxString GetGerberProtelExtension( int aLayer );
  220. /**
  221. * Return the "file function" attribute for \a aLayer, as defined in the
  222. * Gerber file format specification J1 (chapter 5).
  223. *
  224. * The returned string includes the "%TF.FileFunction" attribute prefix and the "*%" suffix.
  225. *
  226. * @param aBoard is the board, needed to get the total count of copper layers.
  227. * @param aLayer is the layer number to create the attribute for.
  228. * @return The attribute, as a text string
  229. */
  230. const wxString GetGerberFileFunctionAttribute( const BOARD* aBoard, int aLayer );
  231. /**
  232. * Calculate some X2 attributes as defined in the Gerber file format specification J4
  233. * (chapter 5) and add them the to the gerber file header.
  234. *
  235. * TF.GenerationSoftware
  236. * TF.CreationDate
  237. * TF.ProjectId
  238. * file format attribute is not added
  239. *
  240. * @param aPlotter is the current plotter.
  241. * @param aBoard is the board, needed to extract some info.
  242. * @param aUseX1CompatibilityMode set to 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 AddGerberX2Header( PLOTTER* aPlotter, const BOARD* aBoard,
  247. bool aUseX1CompatibilityMode = false );
  248. /**
  249. * Calculate some X2 attributes as defined in the Gerber file format specification and add them
  250. * to the gerber file header.
  251. *
  252. * TF.GenerationSoftware
  253. * TF.CreationDate
  254. * TF.ProjectId
  255. * TF.FileFunction
  256. * TF.FilePolarity
  257. *
  258. * @param aPlotter is the current plotter.
  259. * @param aBoard is the board, needed to extract some info.
  260. * @param aLayer is the layer number to create the attribute for.
  261. * @param aUseX1CompatibilityMode set to false to generate X2 attributes, true to use X1
  262. * compatibility (X2 attributes added as structured comments, starting by "G04 #@! "
  263. * followed by the X2 attribute.
  264. */
  265. void AddGerberX2Attribute( PLOTTER* aPlotter, const BOARD* aBoard, int aLayer,
  266. bool aUseX1CompatibilityMode );
  267. #endif // PCBPLOT_H_