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.

303 lines
11 KiB

5 years ago
9 months ago
4 years ago
4 years ago
4 years ago
9 months ago
9 months 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( const 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, PCB_PLOT_PARAMS* aPlotOpts,
  142. const wxString& aLayerName, const wxString& aSheetName,
  143. const wxString& aSheetPath, const wxString& aPageNumber,
  144. int aPageCount );
  145. /**
  146. * Plot a sequence of board layer IDs.
  147. *
  148. * @param aBoard is the board to plot.
  149. * @param aPlotter is the plotter to use.
  150. * @param aLayerSequence is the sequence of layer IDs to plot.
  151. * @param aPlotOptions are the plot options (files, sketch). Has meaning for some formats only.
  152. */
  153. void PlotBoardLayers( BOARD* aBoard, PLOTTER* aPlotter, const LSEQ& aLayerSequence,
  154. const PCB_PLOT_PARAMS& aPlotOptions );
  155. /**
  156. * Plot interactive items (hypertext links, properties, etc.).
  157. */
  158. void PlotInteractiveLayer( BOARD* aBoard, PLOTTER* aPlotter, const PCB_PLOT_PARAMS& aPlotOpt );
  159. /**
  160. * Plot one copper or technical layer.
  161. *
  162. * It prepares options and calls the specialized plot function according to the layer type.
  163. *
  164. * @param aBoard is the board to plot.
  165. * @param aPlotter is the plotter to use.
  166. * @param aLayer is the layer id to plot.
  167. * @param aPlotOpt is the plot options (files, sketch). Has meaning for some formats only.
  168. */
  169. void PlotOneBoardLayer( BOARD* aBoard, PLOTTER* aPlotter, PCB_LAYER_ID aLayer,
  170. const PCB_PLOT_PARAMS& aPlotOpt, bool isPrimaryLayer );
  171. /**
  172. * Plot copper or technical layers.
  173. *
  174. * This is not used for silk screen layers because these layers have specific requirements.
  175. * This is mainly for pads.
  176. *
  177. * @param aBoard is the board to plot.
  178. * @param aPlotter is the plotter to use.
  179. * @param aLayerMask is the mask to define the layers to plot.
  180. * @param aPlotOpt is the plot options (files, sketch). Has meaning for some formats only.
  181. *
  182. * aPlotOpt has 3 important options which are set depending on the layer type to plot:
  183. * SetEnablePlotVia( bool aEnable )
  184. * aEnable = true to plot vias, false to skip vias (has meaning only for solder mask layers)
  185. * SetSkipPlotNPTH_Pads( bool aSkip )
  186. * aSkip = true to skip NPTH Pads, when the pad size and the pad hole have the same size.
  187. * Used in GERBER format only.
  188. * SetDrillMarksType( DrillMarksType aVal )
  189. * aVal = no hole, small hole, actual hole size
  190. */
  191. void PlotStandardLayer( BOARD* aBoard, PLOTTER* aPlotter, const LSET& aLayerMask,
  192. const PCB_PLOT_PARAMS& aPlotOpt );
  193. /**
  194. * Plot copper outline of a copper layer.
  195. *
  196. * @param aBoard is the board to plot.
  197. * @param aPlotter is the plotter to use.
  198. * @param aLayerMask is the mask to define the layers to plot.
  199. * @param aPlotOpt is the plot options. Has meaning for some formats only.
  200. */
  201. void PlotLayerOutlines( BOARD* aBoard, PLOTTER* aPlotter, const LSET& aLayerMask,
  202. const PCB_PLOT_PARAMS& aPlotOpt );
  203. /**
  204. * Complete a plot filename.
  205. *
  206. * It forces the output directory, adds a suffix to the name, and sets the specified extension.
  207. * The suffix is usually the layer name and replaces illegal file name character in the suffix
  208. * with an underscore character.
  209. *
  210. * @param aFilename is the file name to initialize that contains the base filename.
  211. * @param aOutputDir is the path.
  212. * @param aSuffix is the suffix to add to the base filename.
  213. * @param aExtension is the file extension.
  214. */
  215. void BuildPlotFileName( wxFileName* aFilename, const wxString& aOutputDir, const wxString& aSuffix,
  216. const wxString& aExtension );
  217. /**
  218. * @return the appropriate Gerber file extension for \a aLayer
  219. */
  220. const wxString GetGerberProtelExtension( int aLayer );
  221. /**
  222. * Return the "file function" attribute for \a aLayer, as defined in the
  223. * Gerber file format specification J1 (chapter 5).
  224. *
  225. * The returned string includes the "%TF.FileFunction" attribute prefix and the "*%" suffix.
  226. *
  227. * @param aBoard is the board, needed to get the total count of copper layers.
  228. * @param aLayer is the layer number to create the attribute for.
  229. * @return The attribute, as a text string
  230. */
  231. const wxString GetGerberFileFunctionAttribute( const BOARD* aBoard, int aLayer );
  232. /**
  233. * Calculate some X2 attributes as defined in the Gerber file format specification J4
  234. * (chapter 5) and add them the to the gerber file header.
  235. *
  236. * TF.GenerationSoftware
  237. * TF.CreationDate
  238. * TF.ProjectId
  239. * file format attribute is not added
  240. *
  241. * @param aPlotter is the current plotter.
  242. * @param aBoard is the board, needed to extract some info.
  243. * @param aUseX1CompatibilityMode set to false to generate X2 attributes, true to
  244. * use X1 compatibility (X2 attributes added as structured comments,
  245. * starting by "G04 #@! " followed by the X2 attribute
  246. */
  247. void AddGerberX2Header( PLOTTER* aPlotter, const BOARD* aBoard,
  248. bool aUseX1CompatibilityMode = false );
  249. /**
  250. * Calculate some X2 attributes as defined in the Gerber file format specification and add them
  251. * to the gerber file header.
  252. *
  253. * TF.GenerationSoftware
  254. * TF.CreationDate
  255. * TF.ProjectId
  256. * TF.FileFunction
  257. * TF.FilePolarity
  258. *
  259. * @param aPlotter is the current plotter.
  260. * @param aBoard is the board, needed to extract some info.
  261. * @param aLayer is the layer number to create the attribute for.
  262. * @param aUseX1CompatibilityMode set to false to generate X2 attributes, true to use X1
  263. * compatibility (X2 attributes added as structured comments, starting by "G04 #@! "
  264. * followed by the X2 attribute.
  265. */
  266. void AddGerberX2Attribute( PLOTTER* aPlotter, const BOARD* aBoard, int aLayer,
  267. bool aUseX1CompatibilityMode );
  268. #endif // PCBPLOT_H_