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.

1579 lines
62 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. /**
  25. * Common plot library \n
  26. * Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF)
  27. *
  28. * @file plot_common.h
  29. */
  30. #ifndef PLOT_COMMON_H_
  31. #define PLOT_COMMON_H_
  32. #include <vector>
  33. #include <math/box2.h>
  34. #include <gr_text.h>
  35. #include <page_info.h>
  36. #include <eda_text.h> // FILL_T
  37. class COLOR_SETTINGS;
  38. class SHAPE_POLY_SET;
  39. class SHAPE_LINE_CHAIN;
  40. class GBR_NETLIST_METADATA;
  41. /**
  42. * Enum PlotFormat
  43. * is the set of supported output plot formats. They should be kept in order
  44. * of the radio buttons in the plot panel/windows.
  45. */
  46. enum class PLOT_FORMAT
  47. {
  48. UNDEFINED = -1,
  49. FIRST_FORMAT = 0,
  50. HPGL = FIRST_FORMAT,
  51. GERBER,
  52. POST,
  53. DXF,
  54. PDF,
  55. SVG,
  56. LAST_FORMAT = SVG
  57. };
  58. /**
  59. * Enum for choosing which kind of text to output with the PSLIKE
  60. * plotters. You can:
  61. * 1) only use the internal vector font
  62. * 2) only use native postscript fonts
  63. * 3) use the internal vector font and add 'phantom' text to aid
  64. * searching
  65. * 4) keep the default for the plot driver
  66. *
  67. * This is recognized by the DXF driver too, where NATIVE emits
  68. * TEXT entities instead of stroking the text
  69. */
  70. enum class PLOT_TEXT_MODE
  71. {
  72. STROKE,
  73. NATIVE,
  74. PHANTOM,
  75. DEFAULT
  76. };
  77. /**
  78. * Enum for choosing dashed line type
  79. */
  80. enum class PLOT_DASH_TYPE
  81. {
  82. DEFAULT = -1,
  83. SOLID = 0,
  84. FIRST_TYPE = SOLID,
  85. DASH,
  86. DOT,
  87. DASHDOT,
  88. LAST_TYPE = DASHDOT
  89. };
  90. /**
  91. * Base plotter engine class. General rule: all the interface with the caller
  92. * is done in IU, the IU size is specified with SetViewport. Internal and
  93. * output processing is usually done in decimils (or whatever unit the
  94. * effective engine class need to use)
  95. */
  96. class PLOTTER
  97. {
  98. public:
  99. // These values are used as flag for pen or aperture selection
  100. static const int DO_NOT_SET_LINE_WIDTH = -2; // Skip selection
  101. static const int USE_DEFAULT_LINE_WIDTH = -1; // use the default pen
  102. PLOTTER();
  103. virtual ~PLOTTER();
  104. /**
  105. * Returns the effective plot engine in use. It's not very OO but for
  106. * now is required since some things are only done with some output devices
  107. * (like drill marks, emitted only for postscript
  108. */
  109. virtual PLOT_FORMAT GetPlotterType() const = 0;
  110. virtual bool StartPlot() = 0;
  111. virtual bool EndPlot() = 0;
  112. virtual void SetNegative( bool aNegative )
  113. {
  114. negativeMode = aNegative;
  115. }
  116. /** Plot in B/W or color.
  117. * @param aColorMode = true to plot in color, false to plot in black and white
  118. */
  119. virtual void SetColorMode( bool aColorMode ) { colorMode = aColorMode; }
  120. bool GetColorMode() const { return colorMode; }
  121. void SetRenderSettings( RENDER_SETTINGS* aSettings ) { m_renderSettings = aSettings; }
  122. RENDER_SETTINGS* RenderSettings() { return m_renderSettings; }
  123. virtual void SetPageSettings( const PAGE_INFO& aPageSettings ) { pageInfo = aPageSettings; }
  124. PAGE_INFO& PageSettings() { return pageInfo; }
  125. /**
  126. * Set the line width for the next drawing.
  127. * @param width is specified in IUs
  128. * @param aData is an auxiliary parameter, mainly used in gerber plotter
  129. */
  130. virtual void SetCurrentLineWidth( int width, void* aData = NULL ) = 0;
  131. virtual int GetCurrentLineWidth() const { return currentPenWidth; }
  132. virtual void SetColor( COLOR4D color ) = 0;
  133. virtual void SetDash( PLOT_DASH_TYPE dashed ) = 0;
  134. virtual void SetCreator( const wxString& aCreator )
  135. {
  136. creator = aCreator;
  137. }
  138. virtual void SetTitle( const wxString& aTitle )
  139. {
  140. title = aTitle;
  141. }
  142. /**
  143. * Function AddLineToHeader
  144. * Add a line to the list of free lines to print at the beginning of the file
  145. * @param aExtraString is the string to print
  146. */
  147. void AddLineToHeader( const wxString& aExtraString )
  148. {
  149. m_headerExtraLines.Add( aExtraString );
  150. }
  151. /**
  152. * Function ClearHeaderLinesList
  153. * remove all lines from the list of free lines to print at the beginning of the file
  154. */
  155. void ClearHeaderLinesList()
  156. {
  157. m_headerExtraLines.Clear();
  158. }
  159. /**
  160. * Set the plot offset and scaling for the current plot
  161. * @param aOffset is the plot offset
  162. * @param aIusPerDecimil gives the scaling factor from IUs to device units
  163. * @param aScale is the user set plot scaling factor (either explicitly
  164. * or using 'fit to A4')
  165. * @param aMirror flips the plot in the Y direction (useful for toner
  166. * transfers or some kind of film)
  167. */
  168. virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
  169. double aScale, bool aMirror ) = 0;
  170. /**
  171. * Open or create the plot file aFullFilename
  172. * @param aFullFilename = the full file name of the file to create
  173. * @return true if success, false if the file cannot be created/opened
  174. *
  175. * Virtual because some plotters use ascii files, some others binary files (PDF)
  176. * The base class open the file in text mode
  177. */
  178. virtual bool OpenFile( const wxString& aFullFilename );
  179. /**
  180. * The IUs per decimil are an essential scaling factor when
  181. * plotting; they are set and saved when establishing the viewport.
  182. * Here they can be get back again
  183. */
  184. double GetIUsPerDecimil() const { return m_IUsPerDecimil; }
  185. int GetPlotterArcLowDef() const { return m_IUsPerDecimil * 8; }
  186. int GetPlotterArcHighDef() const { return m_IUsPerDecimil * 2; }
  187. // Low level primitives
  188. virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
  189. int width = USE_DEFAULT_LINE_WIDTH ) = 0;
  190. virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
  191. int width = USE_DEFAULT_LINE_WIDTH ) = 0;
  192. /**
  193. * Generic fallback: arc rendered as a polyline
  194. */
  195. virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
  196. int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH );
  197. /**
  198. * Generic fallback: Cubic Bezier curve rendered as a polyline
  199. * In Kicad the bezier curves have 4 control points:
  200. * start ctrl1 ctrl2 end
  201. */
  202. virtual void BezierCurve( const wxPoint& aStart, const wxPoint& aControl1,
  203. const wxPoint& aControl2, const wxPoint& aEnd,
  204. int aTolerance,
  205. int aLineThickness = USE_DEFAULT_LINE_WIDTH );
  206. /**
  207. * moveto/lineto primitive, moves the 'pen' to the specified direction
  208. * @param pos is the target position
  209. * @param plume specifies the kind of motion: 'U' only moves the pen,
  210. * 'D' draw a line from the current position and 'Z' finish
  211. * the drawing and returns the 'pen' to rest (flushes the trace)
  212. */
  213. virtual void PenTo( const wxPoint& pos, char plume ) = 0;
  214. // Convenience functions for PenTo
  215. void MoveTo( const wxPoint& pos )
  216. {
  217. PenTo( pos, 'U' );
  218. }
  219. void LineTo( const wxPoint& pos )
  220. {
  221. PenTo( pos, 'D' );
  222. }
  223. void FinishTo( const wxPoint& pos )
  224. {
  225. PenTo( pos, 'D' );
  226. PenTo( pos, 'Z' );
  227. }
  228. void PenFinish()
  229. {
  230. // The point is not important with Z motion
  231. PenTo( wxPoint( 0, 0 ), 'Z' );
  232. }
  233. /**
  234. * Function PlotPoly
  235. * @brief Draw a polygon ( filled or not )
  236. * @param aCornerList = corners list (a std::vector< wxPoint >)
  237. * @param aFill = type of fill
  238. * @param aWidth = line width
  239. * @param aData an auxiliary info (mainly for gerber format)
  240. */
  241. virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, FILL_T aFill,
  242. int aWidth = USE_DEFAULT_LINE_WIDTH, void * aData = NULL ) = 0;
  243. /**
  244. * Function PlotPoly
  245. * @brief Draw a polygon ( filled or not )
  246. * @param aCornerList = corners list (a SHAPE_LINE_CHAIN).
  247. * must be closed (IsClosed() == true) for a polygon. Otherwise this is a polyline
  248. * @param aFill = type of fill
  249. * @param aWidth = line width
  250. * @param aData an auxiliary info (mainly for gerber format)
  251. */
  252. virtual void PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill,
  253. int aWidth = USE_DEFAULT_LINE_WIDTH, void * aData = NULL );
  254. /**
  255. * Function PlotImage
  256. * Only Postscript plotters can plot bitmaps
  257. * for plotters that cannot plot a bitmap, a rectangle is plotted
  258. * @brief Draw an image bitmap
  259. * @param aImage = the bitmap
  260. * @param aPos = position of the center of the bitmap
  261. * @param aScaleFactor = the scale factor to apply to the bitmap size
  262. * (this is not the plot scale factor)
  263. */
  264. virtual void PlotImage( const wxImage & aImage, const wxPoint& aPos,
  265. double aScaleFactor );
  266. // Higher level primitives -- can be drawn as line, sketch or 'filled'
  267. virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
  268. EDA_DRAW_MODE_T tracemode, void* aData );
  269. virtual void ThickArc( const wxPoint& centre, double StAngle, double EndAngle,
  270. int rayon, int width, EDA_DRAW_MODE_T tracemode, void* aData );
  271. virtual void ThickRect( const wxPoint& p1, const wxPoint& p2, int width,
  272. EDA_DRAW_MODE_T tracemode, void* aData );
  273. virtual void ThickCircle( const wxPoint& pos, int diametre, int width,
  274. EDA_DRAW_MODE_T tracemode, void* aData );
  275. // Flash primitives
  276. /**
  277. * virtual function FlashPadCircle
  278. * @param aPadPos Position of the shape (center of the rectangle
  279. * @param aDiameter diameter of round pad
  280. * @param aTraceMode FILLED or SKETCH
  281. * @param aData an auxiliary info (mainly for gerber format attributes)
  282. */
  283. virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter,
  284. EDA_DRAW_MODE_T aTraceMode, void* aData ) = 0;
  285. /**
  286. * virtual function FlashPadOval
  287. * @param aPadPos Position of the shape (center of the rectangle
  288. * @param aSize = size of oblong shape
  289. * @param aPadOrient The rotation of the shape
  290. * @param aTraceMode FILLED or SKETCH
  291. * @param aData an auxiliary info (mainly for gerber format attributes)
  292. */
  293. virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient,
  294. EDA_DRAW_MODE_T aTraceMode, void* aData ) = 0;
  295. /**
  296. * virtual function FlashPadRect
  297. * @param aPadPos Position of the shape (center of the rectangle
  298. * @param aSize = size of rounded rect
  299. * @param aPadOrient The rotation of the shape
  300. * @param aTraceMode FILLED or SKETCH
  301. * @param aData an auxuliary info (mainly for gerber format attributes)
  302. */
  303. virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize,
  304. double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) = 0;
  305. /**
  306. * virtual function FlashPadRoundRect
  307. * @param aPadPos Position of the shape (center of the rectangle
  308. * @param aSize = size of rounded rect
  309. * @param aCornerRadius Radius of the rounded corners
  310. * @param aOrient The rotation of the shape
  311. * @param aTraceMode FILLED or SKETCH
  312. * @param aData an auxiliary info (mainly for gerber format attributes)
  313. */
  314. virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
  315. int aCornerRadius, double aOrient,
  316. EDA_DRAW_MODE_T aTraceMode, void* aData ) = 0;
  317. /**
  318. * virtual function FlashPadCustom
  319. * @param aPadPos Position of the shape (center of the rectangle
  320. * @param aSize = size of round reference pad
  321. * @param aPolygons the shape as polygon set
  322. * @param aTraceMode FILLED or SKETCH
  323. * @param aData an auxiliary info (mainly for gerber format attributes)
  324. */
  325. virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
  326. SHAPE_POLY_SET* aPolygons,
  327. EDA_DRAW_MODE_T aTraceMode, void* aData ) = 0;
  328. /** virtual function FlashPadTrapez
  329. * flash a trapezoidal pad
  330. * @param aPadPos = the position of the shape
  331. * @param aCorners = the list of 4 corners positions,
  332. * relative to the shape position, pad orientation 0
  333. * @param aPadOrient = the rotation of the shape
  334. * @param aTraceMode = FILLED or SKETCH
  335. * @param aData an auxiliary info (mainly for gerber format attributes)
  336. */
  337. virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
  338. double aPadOrient, EDA_DRAW_MODE_T aTraceMode,
  339. void* aData ) = 0;
  340. /** Flash a regular polygon. Usefull only in Gerber files to flash a regular polygon
  341. * @param aShapePos is the center of the circle containing the polygon
  342. * @param aRadius is the radius of the circle containing the polygon
  343. * @param aCornerCount is the number of vertices
  344. * @param aOrient is the polygon rotation in degrees
  345. * @param aData is a auxiliary parameter used (if needed) to handle extra info
  346. * specific to the plotter
  347. */
  348. virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
  349. double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) = 0 ;
  350. /**
  351. * Draws text with the plotter. For convenience it accept the color to use
  352. * for specific plotters (GERBER) aData is used to pass extra parameters
  353. */
  354. virtual void Text( const wxPoint& aPos,
  355. const COLOR4D aColor,
  356. const wxString& aText,
  357. double aOrient,
  358. const wxSize& aSize,
  359. enum EDA_TEXT_HJUSTIFY_T aH_justify,
  360. enum EDA_TEXT_VJUSTIFY_T aV_justify,
  361. int aWidth,
  362. bool aItalic,
  363. bool aBold,
  364. bool aMultilineAllowed = false,
  365. void* aData = NULL );
  366. /**
  367. * Draw a marker (used for the drill map)
  368. */
  369. static const unsigned MARKER_COUNT = 58;
  370. /**
  371. * Draw a pattern shape number aShapeId, to coord position.
  372. * Diameter diameter = (coord table) hole
  373. * AShapeId = index (used to generate forms characters)
  374. */
  375. void Marker( const wxPoint& position, int diametre, unsigned aShapeId );
  376. /**
  377. * Function SetLayerPolarity
  378. * sets current Gerber layer polarity to positive or negative
  379. * by writing \%LPD*\% or \%LPC*\% to the Gerber file, respectively.
  380. * (obviously starts a new Gerber layer, too)
  381. * @param aPositive is the layer polarity and true for positive.
  382. * It's not useful with most other plotter since they can't 'scratch'
  383. * the film like photoplotter imagers do
  384. */
  385. virtual void SetLayerPolarity( bool aPositive )
  386. {
  387. // NOP for most plotters
  388. }
  389. /**
  390. * Change the current text mode. See the PlotTextMode
  391. * explanation at the beginning of the file
  392. */
  393. virtual void SetTextMode( PLOT_TEXT_MODE mode )
  394. {
  395. // NOP for most plotters.
  396. }
  397. virtual void SetGerberCoordinatesFormat( int aResolution, bool aUseInches = false )
  398. {
  399. // NOP for most plotters. Only for Gerber plotter
  400. }
  401. virtual void SetSvgCoordinatesFormat( unsigned aResolution, bool aUseInches = false )
  402. {
  403. // NOP for most plotters. Only for SVG plotter
  404. }
  405. /**
  406. * calling this function allows one to define the beginning of a group
  407. * of drawing items, for instance in SVG or Gerber format.
  408. * (example: group all segments of a letter or a text)
  409. * @param aData can define any parameter
  410. * for most of plotters: do nothing
  411. */
  412. virtual void StartBlock( void* aData ) {}
  413. /**
  414. * calling this function allows one to define the end of a group of drawing
  415. * items for instance in SVG or Gerber format.
  416. * the group is started by StartBlock()
  417. * @param aData can define any parameter
  418. * for most of plotters: do nothing
  419. */
  420. virtual void EndBlock( void* aData ) {}
  421. protected:
  422. // These are marker subcomponents
  423. /**
  424. * Plot a circle centered on the position. Building block for markers
  425. */
  426. void markerCircle( const wxPoint& pos, int radius );
  427. /**
  428. * Plot a - bar centered on the position. Building block for markers
  429. */
  430. void markerHBar( const wxPoint& pos, int radius );
  431. /**
  432. * Plot a / bar centered on the position. Building block for markers
  433. */
  434. void markerSlash( const wxPoint& pos, int radius );
  435. /**
  436. * Plot a \ bar centered on the position. Building block for markers
  437. */
  438. void markerBackSlash( const wxPoint& pos, int radius );
  439. /**
  440. * Plot a | bar centered on the position. Building block for markers
  441. */
  442. void markerVBar( const wxPoint& pos, int radius );
  443. /**
  444. * Plot a square centered on the position. Building block for markers
  445. */
  446. void markerSquare( const wxPoint& position, int radius );
  447. /**
  448. * Plot a lozenge centered on the position. Building block for markers
  449. */
  450. void markerLozenge( const wxPoint& position, int radius );
  451. // Helper function for sketched filler segment
  452. /**
  453. * Cdonvert a thick segment and plot it as an oval
  454. */
  455. void segmentAsOval( const wxPoint& start, const wxPoint& end, int width,
  456. EDA_DRAW_MODE_T tracemode );
  457. void sketchOval( const wxPoint& pos, const wxSize& size, double orient, int width );
  458. // Coordinate and scaling conversion functions
  459. /**
  460. * Modifies coordinates according to the orientation,
  461. * scale factor, and offsets trace. Also convert from a wxPoint to DPOINT,
  462. * since some output engines needs floating point coordinates.
  463. */
  464. virtual DPOINT userToDeviceCoordinates( const wxPoint& aCoordinate );
  465. /**
  466. * Modifies size according to the plotter scale factors
  467. * (wxSize version, returns a DPOINT)
  468. */
  469. virtual DPOINT userToDeviceSize( const wxSize& size );
  470. /**
  471. * Modifies size according to the plotter scale factors
  472. * (simple double version)
  473. */
  474. virtual double userToDeviceSize( double size ) const;
  475. double GetDotMarkLenIU() const;
  476. double GetDashMarkLenIU() const;
  477. double GetDashGapLenIU() const;
  478. protected: // variables used in most of plotters:
  479. /// Plot scale - chosen by the user (even implicitly with 'fit in a4')
  480. double plotScale;
  481. /* Caller scale (how many IUs in a decimil - always); it's a double
  482. * because in eeschema there are 0.1 IUs in a decimil (eeschema
  483. * always works in mils internally) while pcbnew can work in decimil
  484. * or nanometers, so this value would be >= 1 */
  485. double m_IUsPerDecimil;
  486. /// Device scale (from IUs to plotter device units - usually decimils)
  487. double iuPerDeviceUnit;
  488. /// Plot offset (in IUs)
  489. wxPoint plotOffset;
  490. /// X axis orientation (SVG)
  491. /// and plot mirrored (only for PS, PDF HPGL and SVG)
  492. bool m_plotMirror;
  493. bool m_mirrorIsHorizontal; /// true to mirror horizontally (else vertically)
  494. bool m_yaxisReversed; /// true if the Y axis is top to bottom (SVG)
  495. /// Output file
  496. FILE* outputFile;
  497. // Pen handling
  498. bool colorMode; // true to plot in color, false to plot in black & white
  499. bool negativeMode; // true to generate a negative image (PS mode mainly)
  500. int currentPenWidth;
  501. char penState; // Current pen state: 'U', 'D' or 'Z' (see PenTo)
  502. wxPoint penLastpos; // Last pen positions; set to -1,-1 when the pen is
  503. // at rest
  504. wxString creator;
  505. wxString filename;
  506. wxString title;
  507. PAGE_INFO pageInfo;
  508. wxSize paperSize; // Paper size in IU - not in mils
  509. wxArrayString m_headerExtraLines; // a set of string to print in header file
  510. RENDER_SETTINGS* m_renderSettings;
  511. };
  512. class HPGL_PLOTTER : public PLOTTER
  513. {
  514. public:
  515. HPGL_PLOTTER();
  516. virtual PLOT_FORMAT GetPlotterType() const override
  517. {
  518. return PLOT_FORMAT::HPGL;
  519. }
  520. static wxString GetDefaultFileExtension()
  521. {
  522. return wxString( wxT( "plt" ) );
  523. }
  524. virtual bool StartPlot() override;
  525. virtual bool EndPlot() override;
  526. /// HPGL doesn't handle line thickness or color
  527. virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override
  528. {
  529. // This is the truth
  530. currentPenWidth = userToDeviceSize( penDiameter );
  531. }
  532. virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
  533. virtual void SetColor( COLOR4D color ) override {}
  534. virtual void SetPenSpeed( int speed )
  535. {
  536. penSpeed = speed;
  537. }
  538. virtual void SetPenNumber( int number )
  539. {
  540. penNumber = number;
  541. }
  542. virtual void SetPenDiameter( double diameter );
  543. virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
  544. double aScale, bool aMirror ) override;
  545. virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
  546. int width = USE_DEFAULT_LINE_WIDTH ) override;
  547. virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
  548. int width = USE_DEFAULT_LINE_WIDTH ) override;
  549. virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
  550. FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH,
  551. void * aData = NULL) override;
  552. virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
  553. EDA_DRAW_MODE_T tracemode, void* aData ) override;
  554. virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
  555. int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
  556. virtual void PenTo( const wxPoint& pos, char plume ) override;
  557. virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter,
  558. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  559. virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient,
  560. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  561. virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize,
  562. double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  563. virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
  564. int aCornerRadius, double aOrient,
  565. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  566. virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
  567. SHAPE_POLY_SET* aPolygons,
  568. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  569. virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
  570. double aPadOrient, EDA_DRAW_MODE_T aTraceMode,
  571. void* aData ) override;
  572. virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
  573. double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  574. protected:
  575. void penControl( char plume );
  576. int penSpeed;
  577. int penNumber;
  578. double penDiameter;
  579. };
  580. /**
  581. * The PSLIKE_PLOTTER class is an intermediate class to handle common
  582. * routines for engines working more or less with the postscript imaging
  583. * model
  584. */
  585. class PSLIKE_PLOTTER : public PLOTTER
  586. {
  587. public:
  588. PSLIKE_PLOTTER() :
  589. plotScaleAdjX( 1 ),
  590. plotScaleAdjY( 1 ),
  591. m_textMode( PLOT_TEXT_MODE::PHANTOM )
  592. {
  593. }
  594. /**
  595. * PS and PDF fully implement native text (for the Latin-1 subset)
  596. */
  597. virtual void SetTextMode( PLOT_TEXT_MODE mode ) override
  598. {
  599. if( mode != PLOT_TEXT_MODE::DEFAULT )
  600. m_textMode = mode;
  601. }
  602. /**
  603. * Set the 'fine' scaling for the postscript engine
  604. */
  605. void SetScaleAdjust( double scaleX, double scaleY )
  606. {
  607. plotScaleAdjX = scaleX;
  608. plotScaleAdjY = scaleY;
  609. }
  610. // Pad routines are handled with lower level primitives
  611. virtual void FlashPadCircle( const wxPoint& aPadPos, int aDiameter,
  612. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  613. virtual void FlashPadOval( const wxPoint& aPadPos, const wxSize& aSize, double aPadOrient,
  614. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  615. virtual void FlashPadRect( const wxPoint& aPadPos, const wxSize& aSize,
  616. double aPadOrient, EDA_DRAW_MODE_T aTraceMode,
  617. void* aData ) override;
  618. virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
  619. int aCornerRadius, double aOrient,
  620. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  621. virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
  622. SHAPE_POLY_SET* aPolygons,
  623. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  624. virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
  625. double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  626. virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
  627. double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  628. /** The SetColor implementation is split with the subclasses:
  629. * The PSLIKE computes the rgb values, the subclass emits the
  630. * operator to actually do it
  631. */
  632. virtual void SetColor( COLOR4D color ) override;
  633. protected:
  634. void computeTextParameters( const wxPoint& aPos,
  635. const wxString& aText,
  636. int aOrient,
  637. const wxSize& aSize,
  638. bool aMirror,
  639. enum EDA_TEXT_HJUSTIFY_T aH_justify,
  640. enum EDA_TEXT_VJUSTIFY_T aV_justify,
  641. int aWidth,
  642. bool aItalic,
  643. bool aBold,
  644. double *wideningFactor,
  645. double *ctm_a,
  646. double *ctm_b,
  647. double *ctm_c,
  648. double *ctm_d,
  649. double *ctm_e,
  650. double *ctm_f,
  651. double *heightFactor );
  652. void postscriptOverlinePositions( const wxString& aText, int aXSize,
  653. bool aItalic, bool aBold,
  654. std::vector<int> *pos_pairs );
  655. void fputsPostscriptString(FILE *fout, const wxString& txt);
  656. /// Virtual primitive for emitting the setrgbcolor operator
  657. virtual void emitSetRGBColor( double r, double g, double b ) = 0;
  658. /// Height of the postscript font (from the AFM)
  659. static const double postscriptTextAscent; // = 0.718;
  660. int returnPostscriptTextWidth( const wxString& aText, int aXSize,
  661. bool aItalic, bool aBold );
  662. /// Fine user scale adjust ( = 1.0 if no correction)
  663. double plotScaleAdjX, plotScaleAdjY;
  664. /// How to draw text
  665. PLOT_TEXT_MODE m_textMode;
  666. };
  667. class PS_PLOTTER : public PSLIKE_PLOTTER
  668. {
  669. public:
  670. PS_PLOTTER()
  671. {
  672. // The phantom plot in postscript is an hack and reportedly
  673. // crashes Adobe's own postscript interpreter!
  674. m_textMode = PLOT_TEXT_MODE::STROKE;
  675. }
  676. static wxString GetDefaultFileExtension()
  677. {
  678. return wxString( wxT( "ps" ) );
  679. }
  680. virtual PLOT_FORMAT GetPlotterType() const override
  681. {
  682. return PLOT_FORMAT::POST;
  683. }
  684. virtual bool StartPlot() override;
  685. virtual bool EndPlot() override;
  686. virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override;
  687. virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
  688. virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
  689. double aScale, bool aMirror ) override;
  690. virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
  691. int width = USE_DEFAULT_LINE_WIDTH ) override;
  692. virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
  693. int width = USE_DEFAULT_LINE_WIDTH ) override;
  694. virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
  695. int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
  696. virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
  697. FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH,
  698. void * aData = NULL ) override;
  699. virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos,
  700. double aScaleFactor ) override;
  701. virtual void PenTo( const wxPoint& pos, char plume ) override;
  702. virtual void Text( const wxPoint& aPos,
  703. const COLOR4D aColor,
  704. const wxString& aText,
  705. double aOrient,
  706. const wxSize& aSize,
  707. enum EDA_TEXT_HJUSTIFY_T aH_justify,
  708. enum EDA_TEXT_VJUSTIFY_T aV_justify,
  709. int aWidth,
  710. bool aItalic,
  711. bool aBold,
  712. bool aMultilineAllowed = false,
  713. void* aData = NULL ) override;
  714. protected:
  715. virtual void emitSetRGBColor( double r, double g, double b ) override;
  716. };
  717. class PDF_PLOTTER : public PSLIKE_PLOTTER
  718. {
  719. public:
  720. PDF_PLOTTER() :
  721. pageTreeHandle( 0 ),
  722. fontResDictHandle( 0 ),
  723. pageStreamHandle( 0 ),
  724. streamLengthHandle( 0 ),
  725. workFile( nullptr )
  726. {
  727. }
  728. virtual PLOT_FORMAT GetPlotterType() const override
  729. {
  730. return PLOT_FORMAT::PDF;
  731. }
  732. static wxString GetDefaultFileExtension()
  733. {
  734. return wxString( wxT( "pdf" ) );
  735. }
  736. /**
  737. * Open or create the plot file aFullFilename
  738. * @param aFullFilename = the full file name of the file to create
  739. * @return true if success, false if the file cannot be created/opened
  740. *
  741. * The base class open the file in text mode, so we should have this
  742. * function overlaid for PDF files, which are binary files
  743. */
  744. virtual bool OpenFile( const wxString& aFullFilename ) override;
  745. virtual bool StartPlot() override;
  746. virtual bool EndPlot() override;
  747. virtual void StartPage();
  748. virtual void ClosePage();
  749. virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override;
  750. virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
  751. /** PDF can have multiple pages, so SetPageSettings can be called
  752. * with the outputFile open (but not inside a page stream!) */
  753. virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
  754. double aScale, bool aMirror ) override;
  755. virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
  756. int width = USE_DEFAULT_LINE_WIDTH ) override;
  757. virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
  758. int width = USE_DEFAULT_LINE_WIDTH ) override;
  759. virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
  760. int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
  761. virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
  762. FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH,
  763. void * aData = NULL ) override;
  764. virtual void PenTo( const wxPoint& pos, char plume ) override;
  765. virtual void Text( const wxPoint& aPos,
  766. const COLOR4D aColor,
  767. const wxString& aText,
  768. double aOrient,
  769. const wxSize& aSize,
  770. enum EDA_TEXT_HJUSTIFY_T aH_justify,
  771. enum EDA_TEXT_VJUSTIFY_T aV_justify,
  772. int aWidth,
  773. bool aItalic,
  774. bool aBold,
  775. bool aMultilineAllowed = false,
  776. void* aData = NULL ) override;
  777. virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos,
  778. double aScaleFactor ) override;
  779. protected:
  780. virtual void emitSetRGBColor( double r, double g, double b ) override;
  781. int allocPdfObject();
  782. int startPdfObject(int handle = -1);
  783. void closePdfObject();
  784. int startPdfStream(int handle = -1);
  785. void closePdfStream();
  786. int pageTreeHandle; /// Handle to the root of the page tree object
  787. int fontResDictHandle; /// Font resource dictionary
  788. std::vector<int> pageHandles;/// Handles to the page objects
  789. int pageStreamHandle; /// Handle of the page content object
  790. int streamLengthHandle; /// Handle to the deferred stream length
  791. wxString workFilename;
  792. FILE* workFile; /// Temporary file to costruct the stream before zipping
  793. std::vector<long> xrefTable; /// The PDF xref offset table
  794. };
  795. class SVG_PLOTTER : public PSLIKE_PLOTTER
  796. {
  797. public:
  798. SVG_PLOTTER();
  799. static wxString GetDefaultFileExtension()
  800. {
  801. return wxString( wxT( "svg" ) );
  802. }
  803. virtual PLOT_FORMAT GetPlotterType() const override
  804. {
  805. return PLOT_FORMAT::SVG;
  806. }
  807. virtual void SetColor( COLOR4D color ) override;
  808. virtual bool StartPlot() override;
  809. virtual bool EndPlot() override;
  810. virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override;
  811. virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
  812. virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
  813. double aScale, bool aMirror ) override;
  814. virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
  815. int width = USE_DEFAULT_LINE_WIDTH ) override;
  816. virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
  817. int width = USE_DEFAULT_LINE_WIDTH ) override;
  818. virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
  819. int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
  820. virtual void BezierCurve( const wxPoint& aStart, const wxPoint& aControl1,
  821. const wxPoint& aControl2, const wxPoint& aEnd,
  822. int aTolerance,
  823. int aLineThickness = USE_DEFAULT_LINE_WIDTH ) override;
  824. virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
  825. FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH,
  826. void * aData = NULL ) override;
  827. virtual void PlotImage( const wxImage& aImage, const wxPoint& aPos,
  828. double aScaleFactor ) override;
  829. virtual void PenTo( const wxPoint& pos, char plume ) override;
  830. /**
  831. * Function SetSvgCoordinatesFormat
  832. * selection of SVG step size (number of digits needed for 1 mm or 1 inch )
  833. * @param aResolution = number of digits in mantissa of coordinate
  834. * use a value from 3-6
  835. * do not use value > 6 to avoid overflow in PCBNEW
  836. * do not use value > 4 to avoid overflow for other parts
  837. * @param aUseInches = true to use inches, false to use mm (default)
  838. *
  839. * Should be called only after SetViewport() is called
  840. */
  841. virtual void SetSvgCoordinatesFormat( unsigned aResolution, bool aUseInches = false ) override;
  842. /**
  843. * calling this function allows one to define the beginning of a group
  844. * of drawing items (used in SVG format to separate components)
  845. * @param aData should be a string for the SVG ID tage
  846. */
  847. virtual void StartBlock( void* aData ) override;
  848. /**
  849. * calling this function allows one to define the end of a group of drawing
  850. * items the group is started by StartBlock()
  851. * @param aData should be null
  852. */
  853. virtual void EndBlock( void* aData ) override;
  854. virtual void Text( const wxPoint& aPos,
  855. const COLOR4D aColor,
  856. const wxString& aText,
  857. double aOrient,
  858. const wxSize& aSize,
  859. enum EDA_TEXT_HJUSTIFY_T aH_justify,
  860. enum EDA_TEXT_VJUSTIFY_T aV_justify,
  861. int aWidth,
  862. bool aItalic,
  863. bool aBold,
  864. bool aMultilineAllowed = false,
  865. void* aData = NULL ) override;
  866. protected:
  867. FILL_T m_fillMode; // true if the current contour
  868. // rect, arc, circle, polygon must be filled
  869. long m_pen_rgb_color; // current rgb color value: each color has
  870. // a value 0 ... 255, and the 3 colors are
  871. // grouped in a 3x8 bits value
  872. // (written in hex to svg files)
  873. long m_brush_rgb_color; // same as m_pen_rgb_color, used to fill
  874. // some contours.
  875. bool m_graphics_changed; // true if a pen/brush parameter is modified
  876. // color, pen size, fil mode ...
  877. // the new SVG stype must be output on file
  878. PLOT_DASH_TYPE m_dashed; // plot line style
  879. bool m_useInch; // is 0 if the step size is 10**-n*mm
  880. // is 1 if the step size is 10**-n*inch
  881. // Where n is given from m_precision
  882. unsigned m_precision; // How fine the step size is
  883. // Use 3-6 (3 means um precision, 6 nm precision) in pcbnew
  884. // 3-4 in other moduls (avoid values >4 to avoid overflow)
  885. // see also comment for m_useInch.
  886. /**
  887. * function emitSetRGBColor()
  888. * initialize m_pen_rgb_color from reduced values r, g ,b
  889. * ( reduced values are 0.0 to 1.0 )
  890. */
  891. virtual void emitSetRGBColor( double r, double g, double b ) override;
  892. /**
  893. * function setSVGPlotStyle()
  894. * output the string which define pen and brush color, shape, transparency
  895. *
  896. * @param aIsGroup If false, do not form a new group for the style.
  897. * @param aExtraStyle If given, the string will be added into the style string before closing
  898. */
  899. void setSVGPlotStyle( bool aIsGroup = true, const std::string& aExtraStyle = {} );
  900. /**
  901. * function setFillMode()
  902. * prepare parameters for setSVGPlotStyle()
  903. */
  904. void setFillMode( FILL_T fill );
  905. };
  906. /* Class to handle a D_CODE when plotting a board using Standard Aperture Templates
  907. * (complex apertures need aperture macros
  908. * 5 types:
  909. * Circle (round)
  910. * Rectangle
  911. * Obround (oval)
  912. * regular polygon
  913. *
  914. * We need round apertures to plot lines, so we also defined a aperture type for plotting
  915. */
  916. #define FIRST_DCODE_VALUE 10 // D_CODE < 10 is a command, D_CODE >= 10 is a tool
  917. class APERTURE
  918. {
  919. public:
  920. enum APERTURE_TYPE {
  921. AT_CIRCLE = 1, // round aperture, to flash pads
  922. AT_RECT = 2, // rect aperture, to flash pads
  923. AT_PLOTTING = 3, // round aperture, to plot lines
  924. AT_OVAL = 4, // oval aperture, to flash pads
  925. AT_REGULAR_POLY = 5,// Regular polygon (n vertices, n = 3 .. 12, with rotation)
  926. AT_REGULAR_POLY3, // Regular polygon 3 vertices, with rotation
  927. AT_REGULAR_POLY4, // Regular polygon 4 vertices, with rotation
  928. AT_REGULAR_POLY5, // Regular polygon 5 vertices, with rotation
  929. AT_REGULAR_POLY6, // Regular polygon 6 vertices, with rotation
  930. AT_REGULAR_POLY7, // Regular polygon 7 vertices, with rotation
  931. AT_REGULAR_POLY8, // Regular polygon 8 vertices, with rotation
  932. AT_REGULAR_POLY9, // Regular polygon 9 vertices, with rotation
  933. AT_REGULAR_POLY10, // Regular polygon 10 vertices, with rotation
  934. AT_REGULAR_POLY11, // Regular polygon 11 vertices, with rotation
  935. AT_REGULAR_POLY12, // Regular polygon 12 vertices, with rotation
  936. };
  937. void SetSize( const wxSize& aSize )
  938. {
  939. m_Size = aSize;
  940. }
  941. const wxSize GetSize()
  942. {
  943. return m_Size;
  944. }
  945. void SetDiameter( int aDiameter )
  946. {
  947. m_Size.x = aDiameter;
  948. }
  949. int GetDiameter()
  950. {
  951. return m_Size.x;
  952. }
  953. void SetVerticeCount( int aCount )
  954. {
  955. if( aCount < 3 )
  956. aCount = 3;
  957. else if( aCount > 12 )
  958. aCount = 12;
  959. m_Type = (APERTURE_TYPE)(AT_REGULAR_POLY3 - 3 + aCount);
  960. }
  961. int GetVerticeCount()
  962. {
  963. return m_Type - AT_REGULAR_POLY3 + 3;
  964. }
  965. void SetRotation( double aRotDegree )
  966. {
  967. // The rotation is stored in 1/1000 degree
  968. m_Size.y = int( aRotDegree * 1000.0 );
  969. }
  970. double GetRotation()
  971. {
  972. // The rotation is stored in 1/1000 degree
  973. return m_Size.y / 1000.0;
  974. }
  975. // Type ( Line, rect , circulaire , ovale poly 3 to 12 vertices )
  976. APERTURE_TYPE m_Type;
  977. // horiz and Vert size, or diameter and rotation for regular polygon
  978. // The diameter (for circle and polygons) is stored in m_Size.x
  979. // the rotation is stored in m_Size.y in 1/1000 degree
  980. wxSize m_Size;
  981. // code number ( >= 10 )
  982. int m_DCode;
  983. // the attribute attached to this aperture
  984. // Only one attribute is allowed by aperture
  985. // 0 = no specific aperture attribute
  986. int m_ApertureAttribute;
  987. };
  988. class GERBER_PLOTTER : public PLOTTER
  989. {
  990. public:
  991. GERBER_PLOTTER();
  992. virtual PLOT_FORMAT GetPlotterType() const override
  993. {
  994. return PLOT_FORMAT::GERBER;
  995. }
  996. static wxString GetDefaultFileExtension()
  997. {
  998. return wxString( wxT( "gbr" ) );
  999. }
  1000. /**
  1001. * Function StartPlot
  1002. * Write GERBER header to file
  1003. * initialize global variable g_Plot_PlotOutputFile
  1004. */
  1005. virtual bool StartPlot() override;
  1006. virtual bool EndPlot() override;
  1007. virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override;
  1008. // RS274X has no dashing, nor colours
  1009. virtual void SetDash( PLOT_DASH_TYPE dashed ) override
  1010. {
  1011. }
  1012. virtual void SetColor( COLOR4D color ) override {}
  1013. // Currently, aScale and aMirror are not used in gerber plotter
  1014. virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
  1015. double aScale, bool aMirror ) override;
  1016. virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
  1017. int width = USE_DEFAULT_LINE_WIDTH ) override;
  1018. virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
  1019. int width = USE_DEFAULT_LINE_WIDTH ) override;
  1020. virtual void Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle,
  1021. int aRadius, FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH ) override;
  1022. virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
  1023. EDA_DRAW_MODE_T tracemode, void* aData ) override;
  1024. virtual void ThickArc( const wxPoint& centre, double StAngle, double EndAngle,
  1025. int rayon, int width, EDA_DRAW_MODE_T tracemode, void* aData ) override;
  1026. virtual void ThickRect( const wxPoint& p1, const wxPoint& p2, int width,
  1027. EDA_DRAW_MODE_T tracemode, void* aData ) override;
  1028. virtual void ThickCircle( const wxPoint& pos, int diametre, int width,
  1029. EDA_DRAW_MODE_T tracemode, void* aData ) override;
  1030. /**
  1031. * Gerber polygon: they can (and *should*) be filled with the
  1032. * appropriate G36/G37 sequence
  1033. */
  1034. virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
  1035. FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH,
  1036. void* aData = nullptr ) override;
  1037. virtual void PenTo( const wxPoint& pos, char plume ) override;
  1038. virtual void Text( const wxPoint& aPos,
  1039. const COLOR4D aColor,
  1040. const wxString& aText,
  1041. double aOrient,
  1042. const wxSize& aSize,
  1043. enum EDA_TEXT_HJUSTIFY_T aH_justify,
  1044. enum EDA_TEXT_VJUSTIFY_T aV_justify,
  1045. int aWidth,
  1046. bool aItalic,
  1047. bool aBold,
  1048. bool aMultilineAllowed = false,
  1049. void* aData = NULL ) override;
  1050. /**
  1051. * Filled circular flashes are stored as apertures
  1052. */
  1053. virtual void FlashPadCircle( const wxPoint& pos, int diametre,
  1054. EDA_DRAW_MODE_T trace_mode, void* aData ) override;
  1055. /**
  1056. * Filled oval flashes are handled as aperture in the 90 degree positions only
  1057. */
  1058. virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient,
  1059. EDA_DRAW_MODE_T trace_mode, void* aData ) override;
  1060. /**
  1061. * Filled rect flashes are handled as aperture in the 0 90 180 or 270 degree orientation only
  1062. * and as polygon for other orientations
  1063. * TODO: always use flashed shapes (aperture macros)
  1064. */
  1065. virtual void FlashPadRect( const wxPoint& pos, const wxSize& size,
  1066. double orient, EDA_DRAW_MODE_T trace_mode, void* aData ) override;
  1067. /**
  1068. * Roundrect pad at the moment are not handled as aperture, since
  1069. * they require aperture macros
  1070. * TODO: always use flashed shapes (aperture macros)
  1071. */
  1072. virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
  1073. int aCornerRadius, double aOrient,
  1074. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1075. virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
  1076. SHAPE_POLY_SET* aPolygons,
  1077. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1078. /**
  1079. * Trapezoidal pad at the moment are *never* handled as aperture, since
  1080. * they require aperture macros
  1081. * TODO: always use flashed shapes (aperture macros)
  1082. */
  1083. virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
  1084. double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1085. virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
  1086. double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1087. /**
  1088. * Plot a Gerber region: similar to PlotPoly but plot only filled polygon,
  1089. * and add the TA.AperFunction if aData contains this attribute, and clear it
  1090. * after plotting
  1091. */
  1092. void PlotGerberRegion( const std::vector< wxPoint >& aCornerList,
  1093. void * aData = NULL );
  1094. /**
  1095. * Change the plot polarity and begin a new layer
  1096. * Used to 'scratch off' silk screen away from solder mask
  1097. */
  1098. virtual void SetLayerPolarity( bool aPositive ) override;
  1099. /**
  1100. * Function SetGerberCoordinatesFormat
  1101. * selection of Gerber units and resolution (number of digits in mantissa)
  1102. * @param aResolution = number of digits in mantissa of coordinate
  1103. * use 5 or 6 for mm and 6 or 7 for inches
  1104. * do not use value > 6 (mm) or > 7 (in) to avoid overflow
  1105. * @param aUseInches = true to use inches, false to use mm (default)
  1106. *
  1107. * Should be called only after SetViewport() is called
  1108. */
  1109. virtual void SetGerberCoordinatesFormat( int aResolution, bool aUseInches = false ) override;
  1110. void UseX2format( bool aEnable ) { m_useX2format = aEnable; }
  1111. void UseX2NetAttributes( bool aEnable ) { m_useNetAttributes = aEnable; }
  1112. /**
  1113. * calling this function allows one to define the beginning of a group
  1114. * of drawing items (used in X2 format with netlist attributes)
  1115. * @param aData can define any parameter
  1116. */
  1117. virtual void StartBlock( void* aData ) override;
  1118. /**
  1119. * calling this function allows one to define the end of a group of drawing
  1120. * items the group is started by StartBlock()
  1121. * (used in X2 format with netlist attributes)
  1122. * @param aData can define any parameter
  1123. */
  1124. virtual void EndBlock( void* aData ) override;
  1125. /** Remove (clear) all attributes from object attributes dictionary (TO. and TA commands)
  1126. * similar to clearNetAttribute(), this is an unconditional reset of TO. and TA. attributes
  1127. */
  1128. void ClearAllAttributes();
  1129. /**
  1130. * @return a index to the aperture in aperture list which meets the size and type of tool
  1131. * if the aperture does not exist, it is created and entered in aperture list
  1132. * @param aSize = the size of tool
  1133. * @param aType = the type ( shape ) of tool
  1134. * @param aApertureAttribute = an aperture attribute of the tool (a tool can have onlu one attribute)
  1135. * 0 = no specific attribute
  1136. */
  1137. int GetOrCreateAperture( const wxSize& aSize,
  1138. APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
  1139. protected:
  1140. /** Plot a round rect (a round rect shape in fact) as a Gerber region
  1141. * using lines and arcs for corners
  1142. * @param aRectCenter is the center of the rectangle
  1143. * @param aSize is the size of the rectangle
  1144. * @param aCornerRadius is the radius of the corners
  1145. * @param aOrient is the rotation of the rectangle
  1146. * Note: only the G36 ... G37 region is created.
  1147. */
  1148. void plotRoundRectAsRegion( const wxPoint& aRectCenter, const wxSize& aSize,
  1149. int aCornerRadius, double aOrient );
  1150. /**
  1151. * Plot a Gerber arc.
  1152. * if aPlotInRegion = true, the current pen position will not be
  1153. * initialized to the arc start position, and therefore the arc can be used
  1154. * to define a region outline item
  1155. * a line will be created from current ^position to arc start point
  1156. * if aPlotInRegion = false, the current pen position will be initialized
  1157. * to the arc start position, to plot an usual arc item
  1158. * The line thickness is not initialized in plotArc, and must be initialized
  1159. * before calling it if needed.
  1160. */
  1161. void plotArc( const wxPoint& aCenter, double aStAngle, double aEndAngle,
  1162. int aRadius, bool aPlotInRegion );
  1163. /**
  1164. * Pick an existing aperture or create a new one, matching the
  1165. * size, type and attributes.
  1166. * write the DCode selection on gerber file
  1167. */
  1168. void selectAperture( const wxSize& aSize, APERTURE::APERTURE_TYPE aType,
  1169. int aApertureAttribute );
  1170. /**
  1171. * Pick an existing aperture or create a new one, matching the
  1172. * aDiameter, aPolygonRotation, type and attributes.
  1173. * It apply only to apertures with type = AT_REGULAR_POLY3 to AT_REGULAR_POLY12
  1174. * write the DCode selection on gerber file
  1175. */
  1176. void selectAperture( int aDiameter, double aPolygonRotation,
  1177. APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
  1178. /**
  1179. * Emit a D-Code record, using proper conversions
  1180. * to format a leading zero omitted gerber coordinate
  1181. * (for n decimal positions, see header generation in start_plot
  1182. */
  1183. void emitDcode( const DPOINT& pt, int dcode );
  1184. /**
  1185. * print a Gerber net attribute object record.
  1186. * In a gerber file, a net attribute is owned by a graphic object
  1187. * formatNetAttribute must be called before creating the object
  1188. * @param aData contains the dato to format.
  1189. * the generated string depends on the type of netlist info
  1190. */
  1191. void formatNetAttribute( GBR_NETLIST_METADATA* aData );
  1192. /**
  1193. * clear a Gerber net attribute record (clear object attribute dictionary)
  1194. * and output the clear object attribute dictionary command to gerber file
  1195. * has effect only if a net attribute is stored in m_objectAttributesDictionnary
  1196. */
  1197. void clearNetAttribute();
  1198. // the attributes dictionary created/modifed by %TO, attached to objects, when they are created
  1199. // by D01, D03, G36/G37 commands
  1200. // standard attributes are .P, .C and .N
  1201. // this is used by gerber readers when creating a new object. Cleared by %TD command
  1202. // Note: m_objectAttributesDictionnary can store more than one attribute
  1203. // the string stores the line(s) actually written to the gerber file
  1204. // it can store a .P, .C or .N attribute, or 2 or 3 attributes, separated by a \n char (EOL)
  1205. std::string m_objectAttributesDictionnary;
  1206. // The last aperture attribute generated (only one aperture attribute can be set)
  1207. int m_apertureAttribute;
  1208. FILE* workFile;
  1209. FILE* finalFile;
  1210. wxString m_workFilename;
  1211. /**
  1212. * Generate the table of D codes
  1213. */
  1214. void writeApertureList();
  1215. std::vector<APERTURE> m_apertures; // The list of available apertures
  1216. int m_currentApertureIdx; // The index of the current aperture in m_apertures
  1217. bool m_gerberUnitInch; // true if the gerber units are inches, false for mm
  1218. int m_gerberUnitFmt; // number of digits in mantissa.
  1219. // usually 6 in Inches and 5 or 6 in mm
  1220. bool m_useX2format; // Add X2 file header attributes. If false, attributes
  1221. // will be added as comments.
  1222. bool m_useNetAttributes; // In recent gerber files, netlist info can be added.
  1223. // It will be added if this param is true, using X2 or
  1224. // X1 format
  1225. };
  1226. class DXF_PLOTTER : public PLOTTER
  1227. {
  1228. public:
  1229. DXF_PLOTTER() : m_textAsLines( false )
  1230. {
  1231. m_textAsLines = true;
  1232. m_currentColor = COLOR4D::BLACK;
  1233. m_currentLineType = PLOT_DASH_TYPE::SOLID;
  1234. SetUnits( DXF_UNITS::INCHES );
  1235. }
  1236. virtual PLOT_FORMAT GetPlotterType() const override
  1237. {
  1238. return PLOT_FORMAT::DXF;
  1239. }
  1240. static wxString GetDefaultFileExtension()
  1241. {
  1242. return wxString( wxT( "dxf" ) );
  1243. }
  1244. /**
  1245. * DXF handles NATIVE text emitting TEXT entities
  1246. */
  1247. virtual void SetTextMode( PLOT_TEXT_MODE mode ) override
  1248. {
  1249. if( mode != PLOT_TEXT_MODE::DEFAULT )
  1250. m_textAsLines = ( mode != PLOT_TEXT_MODE::NATIVE );
  1251. }
  1252. virtual bool StartPlot() override;
  1253. virtual bool EndPlot() override;
  1254. // For now we don't use 'thick' primitives, so no line width
  1255. virtual void SetCurrentLineWidth( int width, void* aData = NULL ) override
  1256. {
  1257. currentPenWidth = 0;
  1258. }
  1259. virtual void SetDash( PLOT_DASH_TYPE dashed ) override;
  1260. virtual void SetColor( COLOR4D color ) override;
  1261. virtual void SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
  1262. double aScale, bool aMirror ) override;
  1263. virtual void Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
  1264. int width = USE_DEFAULT_LINE_WIDTH ) override;
  1265. virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
  1266. int width = USE_DEFAULT_LINE_WIDTH ) override;
  1267. virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
  1268. FILL_T aFill, int aWidth = USE_DEFAULT_LINE_WIDTH, void * aData = NULL ) override;
  1269. virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
  1270. EDA_DRAW_MODE_T tracemode, void* aData ) override;
  1271. virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
  1272. int rayon, FILL_T fill, int width = USE_DEFAULT_LINE_WIDTH ) override;
  1273. virtual void PenTo( const wxPoint& pos, char plume ) override;
  1274. virtual void FlashPadCircle( const wxPoint& pos, int diametre,
  1275. EDA_DRAW_MODE_T trace_mode, void* aData ) override;
  1276. virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient,
  1277. EDA_DRAW_MODE_T trace_mode, void* aData ) override;
  1278. virtual void FlashPadRect( const wxPoint& pos, const wxSize& size,
  1279. double orient, EDA_DRAW_MODE_T trace_mode, void* aData ) override;
  1280. virtual void FlashPadRoundRect( const wxPoint& aPadPos, const wxSize& aSize,
  1281. int aCornerRadius, double aOrient,
  1282. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1283. virtual void FlashPadCustom( const wxPoint& aPadPos, const wxSize& aSize,
  1284. SHAPE_POLY_SET* aPolygons,
  1285. EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1286. virtual void FlashPadTrapez( const wxPoint& aPadPos, const wxPoint *aCorners,
  1287. double aPadOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1288. virtual void FlashRegularPolygon( const wxPoint& aShapePos, int aDiameter, int aCornerCount,
  1289. double aOrient, EDA_DRAW_MODE_T aTraceMode, void* aData ) override;
  1290. virtual void Text( const wxPoint& aPos,
  1291. const COLOR4D aColor,
  1292. const wxString& aText,
  1293. double aOrient,
  1294. const wxSize& aSize,
  1295. enum EDA_TEXT_HJUSTIFY_T aH_justify,
  1296. enum EDA_TEXT_VJUSTIFY_T aV_justify,
  1297. int aWidth,
  1298. bool aItalic,
  1299. bool aBold,
  1300. bool aMultilineAllowed = false,
  1301. void* aData = NULL ) override;
  1302. // Must be in the same order as the drop-down list in the plot dialog inside pcbnew
  1303. enum class DXF_UNITS
  1304. {
  1305. INCHES = 0,
  1306. MILLIMETERS = 1
  1307. };
  1308. /**
  1309. * Set the units to use for plotting the DXF file.
  1310. *
  1311. * @param aUnit - The units to use
  1312. */
  1313. void SetUnits( DXF_UNITS aUnit );
  1314. /**
  1315. * The units currently enabled for plotting
  1316. *
  1317. * @return The currently configured units
  1318. */
  1319. DXF_UNITS GetUnits() const
  1320. {
  1321. return m_plotUnits;
  1322. }
  1323. /**
  1324. * Get the scale factor to apply to convert the device units to be in the
  1325. * currently set units.
  1326. *
  1327. * @return Scaling factor to apply for unit conversion
  1328. */
  1329. double GetUnitScaling() const
  1330. {
  1331. return m_unitScalingFactor;
  1332. }
  1333. /**
  1334. * Get the correct value for the $MEASUREMENT field given the current units
  1335. *
  1336. * @return the $MEASUREMENT directive field value
  1337. */
  1338. unsigned int GetMeasurementDirective() const
  1339. {
  1340. return m_measurementDirective;
  1341. }
  1342. protected:
  1343. bool m_textAsLines;
  1344. COLOR4D m_currentColor;
  1345. PLOT_DASH_TYPE m_currentLineType;
  1346. DXF_UNITS m_plotUnits;
  1347. double m_unitScalingFactor;
  1348. unsigned int m_measurementDirective;
  1349. };
  1350. class TITLE_BLOCK;
  1351. void PlotWorkSheet( PLOTTER* plotter, const PROJECT* aProject, const TITLE_BLOCK& aTitleBlock,
  1352. const PAGE_INFO& aPageInfo, int aSheetNumber, int aNumberOfSheets,
  1353. const wxString &aSheetDesc, const wxString &aFilename,
  1354. COLOR4D aColor = COLOR4D::UNSPECIFIED );
  1355. /** Returns the default plot extension for a format
  1356. */
  1357. wxString GetDefaultPlotExtension( PLOT_FORMAT aFormat );
  1358. #endif // PLOT_COMMON_H_