KiCad PCB EDA Suite
plotter_gerber.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
27#pragma once
28
29#include "plotter.h"
31
32class SHAPE_ARC;
33
34class GERBER_PLOTTER : public PLOTTER
35{
36public:
38
39 virtual PLOT_FORMAT GetPlotterType() const override
40 {
42 }
43
44 static wxString GetDefaultFileExtension()
45 {
46 return wxString( wxT( "gbr" ) );
47 }
48
52 virtual bool StartPlot( const wxString& pageNumber ) override;
53 virtual bool EndPlot() override;
54 virtual void SetCurrentLineWidth( int aLineWidth, void* aData = nullptr ) override;
55
56 // RS274X has no dashing, nor colors
57 virtual void SetDash( int aLineWidth, PLOT_DASH_TYPE aLineStyle ) override
58 {
59 }
60
61 virtual void SetColor( const COLOR4D& aColor ) override {}
62
63 // Currently, aScale and aMirror are not used in gerber plotter
64 virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
65 double aScale, bool aMirror ) override;
66
67 // Basic plot primitives
68 virtual void Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill,
69 int width = USE_DEFAULT_LINE_WIDTH ) override;
70 virtual void Circle( const VECTOR2I& pos, int diametre, FILL_T fill,
71 int width = USE_DEFAULT_LINE_WIDTH ) override;
72
73 // These functions plot an item and manage X2 gerber attributes
74 virtual void ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
75 OUTLINE_MODE tracemode, void* aData ) override;
76
77 virtual void ThickArc( const VECTOR2I& aCentre, const VECTOR2I& aStart,
78 const VECTOR2I& aEnd, int aWidth,
79 OUTLINE_MODE aTraceMode, void* aData ) override;
80
81 virtual void ThickArc( const EDA_SHAPE& aArcShape,
82 OUTLINE_MODE aTraceMode, void* aData ) override;
83
84 virtual void ThickRect( const VECTOR2I& p1, const VECTOR2I& p2, int width,
85 OUTLINE_MODE tracemode, void* aData ) override;
86
87 virtual void ThickCircle( const VECTOR2I& pos, int diametre, int width,
88 OUTLINE_MODE tracemode, void* aData ) override;
89
90 virtual void FilledCircle( const VECTOR2I& pos, int diametre,
91 OUTLINE_MODE tracemode, void* aData ) override;
92
97 virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill,
98 int aWidth = USE_DEFAULT_LINE_WIDTH, void* aData = nullptr ) override;
99
100 virtual void PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill,
101 int aWidth = USE_DEFAULT_LINE_WIDTH, void* aData = nullptr ) override;
102
103 virtual void PenTo( const VECTOR2I& pos, char plume ) override;
104
105 virtual void Text( const VECTOR2I& aPos,
106 const COLOR4D& aColor,
107 const wxString& aText,
108 const EDA_ANGLE& aOrient,
109 const VECTOR2I& aSize,
110 enum GR_TEXT_H_ALIGN_T aH_justify,
111 enum GR_TEXT_V_ALIGN_T aV_justify,
112 int aWidth,
113 bool aItalic,
114 bool aBold,
115 bool aMultilineAllowed = false,
116 KIFONT::FONT* aFont = nullptr,
117 void* aData = nullptr ) override;
118
122 virtual void FlashPadCircle( const VECTOR2I& pos, int diametre,
123 OUTLINE_MODE trace_mode, void* aData ) override;
124
125 virtual void FlashPadOval( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
126 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
127 void* aData ) override;
128
129 virtual void FlashPadRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
130 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
131 void* aData ) override;
132
133 virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
134 int aCornerRadius, const EDA_ANGLE& aOrient,
135 OUTLINE_MODE aTraceMode, void* aData ) override;
136 virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
137 const EDA_ANGLE& aPadOrient, SHAPE_POLY_SET* aPolygons,
138 OUTLINE_MODE aTraceMode, void* aData ) override;
139
140 virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
141 const EDA_ANGLE& aPadOrient, OUTLINE_MODE aTraceMode,
142 void* aData ) override;
143
144 virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
145 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
146 void* aData ) override;
147
165 void FlashPadChamferRoundRect( const VECTOR2I& aShapePos, const VECTOR2I& aPadSize,
166 int aCornerRadius, double aChamferRatio,
167 int aChamferPositions, const EDA_ANGLE& aPadOrient,
168 OUTLINE_MODE aPlotMode, void* aData );
169
175 void PlotGerberRegion( const std::vector<VECTOR2I>& aCornerList, void* aData = nullptr );
176
177 void PlotGerberRegion( const SHAPE_LINE_CHAIN& aPoly, void* aData = nullptr );
178
184 virtual void SetLayerPolarity( bool aPositive ) override;
185
196 virtual void SetGerberCoordinatesFormat( int aResolution, bool aUseInches = false ) override;
197
198 void UseX2format( bool aEnable ) { m_useX2format = aEnable; }
199 void UseX2NetAttributes( bool aEnable ) { m_useNetAttributes = aEnable; }
200
208 void DisableApertMacros( bool aDisable ) { m_gerberDisableApertMacros = aDisable; }
209
216 virtual void StartBlock( void* aData ) override;
217
225 virtual void EndBlock( void* aData ) override;
226
231 void ClearAllAttributes();
232
243 int GetOrCreateAperture( const VECTOR2I& aSize, int aRadius, const EDA_ANGLE& aRotation,
244 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
245
255 int GetOrCreateAperture( const std::vector<VECTOR2I>& aCorners, const EDA_ANGLE& aRotation,
256 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
257
258protected:
259 virtual void Arc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle,
260 const EDA_ANGLE& aEndAngle, int aRadius, FILL_T aFill,
261 int aWidth = USE_DEFAULT_LINE_WIDTH ) override;
262
263 virtual void ThickArc( const VECTOR2I& aCentre, const EDA_ANGLE& aStartAngle,
264 const EDA_ANGLE& aEndAngle, int aRadius, int aWidth,
265 OUTLINE_MODE aTraceMode, void* aData ) override;
266
278 void plotRoundRectAsRegion( const VECTOR2I& aRectCenter, const VECTOR2I& aSize,
279 int aCornerRadius, const EDA_ANGLE& aOrient );
290 void plotArc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle,
291 int aRadius, bool aPlotInRegion );
292 void plotArc( const SHAPE_ARC& aArc, bool aPlotInRegion );
293
299 void selectAperture( const VECTOR2I& aSize, int aRadius, const EDA_ANGLE& aRotation,
300 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
308 void selectAperture( const std::vector<VECTOR2I>& aCorners, const EDA_ANGLE& aPolygonRotation,
309 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
310
319 void selectAperture( int aDiameter, const EDA_ANGLE& aRotation,
320 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
321
328 void emitDcode( const VECTOR2D& pt, int dcode );
329
340
346 void clearNetAttribute();
347
348 // the attributes dictionary created/modified by %TO, attached to objects, when they are created
349 // by D01, D03, G36/G37 commands
350 // standard attributes are .P, .C and .N
351 // this is used by gerber readers when creating a new object. Cleared by %TD command
352 // Note: m_objectAttributesDictionary can store more than one attribute
353 // the string stores the line(s) actually written to the gerber file
354 // it can store a .P, .C or .N attribute, or 2 or 3 attributes, separated by a \n char (EOL)
356
357 // The last aperture attribute generated (only one aperture attribute can be set)
359
360 FILE* workFile;
363
367 void writeApertureList();
368
369 std::vector<APERTURE> m_apertures; // The list of available apertures
370 int m_currentApertureIdx; // The index of the current aperture in m_apertures
371 bool m_hasApertureRoundRect; // true is at least one round rect aperture is in use
372 bool m_hasApertureRotOval; // true is at least one oval rotated aperture is in use
373 bool m_hasApertureRotRect; // true is at least one rect. rotated aperture is in use
374 bool m_hasApertureOutline4P; // true is at least one 4 corners outline (free polygon
375 // with 4 corners) aperture is in use
376 bool m_hasApertureChamferedRect; // true is at least one chamfered rect is in use
377 // (with no rounded corner)
378
379 bool m_gerberUnitInch; // true if the gerber units are inches, false for mm
380 int m_gerberUnitFmt; // number of digits in mantissa.
381 // usually 6 in Inches and 5 or 6 in mm
382 bool m_gerberDisableApertMacros; // True to disable Aperture Macro (AM) command,
383 // for broken Gerber Readers
384 // Regions will be used instead of AM shapes
385 bool m_useX2format; // Add X2 file header attributes. If false, attributes
386 // will be added as comments.
387 bool m_useNetAttributes; // In recent gerber files, netlist info can be added.
388 // It will be added if this param is true, using X2 or
389 // X1 format
390
391 // A list of aperture macros defined "on the fly" because the number of parameters is not
392 // defined: this is the case of the macro using the primitive 4 to create a polygon.
393 // The number of vertices is not known for free polygonal shapes, and an aperture macro
394 // must be created for each specific polygon
396};
Information which can be added in a gerber file as attribute of an object.
virtual void Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
virtual void SetColor(const COLOR4D &aColor) override
std::string m_objectAttributesDictionary
virtual void Arc(const VECTOR2I &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, int aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: arc rendered as a polyline.
virtual void SetGerberCoordinatesFormat(int aResolution, bool aUseInches=false) override
Selection of Gerber units and resolution (number of digits in mantissa).
virtual void ThickCircle(const VECTOR2I &pos, int diametre, int width, OUTLINE_MODE tracemode, void *aData) override
void ClearAllAttributes()
Remove (clear) all attributes from object attributes dictionary (TO.
void selectAperture(const VECTOR2I &aSize, int aRadius, const EDA_ANGLE &aRotation, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual void FlashPadCustom(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, SHAPE_POLY_SET *aPolygons, OUTLINE_MODE aTraceMode, void *aData) override
void PlotGerberRegion(const std::vector< VECTOR2I > &aCornerList, void *aData=nullptr)
Plot a Gerber region: similar to PlotPoly but plot only filled polygon, and add the TA....
int GetOrCreateAperture(const VECTOR2I &aSize, int aRadius, const EDA_ANGLE &aRotation, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
void emitDcode(const VECTOR2D &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
APER_MACRO_FREEPOLY_LIST m_am_freepoly_list
void plotArc(const VECTOR2I &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, int aRadius, bool aPlotInRegion)
Plot a Gerber arc.
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
virtual void FlashPadCircle(const VECTOR2I &pos, int diametre, OUTLINE_MODE trace_mode, void *aData) override
Filled circular flashes are stored as apertures.
std::vector< APERTURE > m_apertures
bool m_hasApertureChamferedRect
virtual void FlashPadTrapez(const VECTOR2I &aPadPos, const VECTOR2I *aCorners, const EDA_ANGLE &aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a trapezoidal pad.
bool m_hasApertureOutline4P
virtual void SetCurrentLineWidth(int aLineWidth, void *aData=nullptr) override
Set the line width for the next drawing.
void writeApertureList()
Generate the table of D codes.
void plotRoundRectAsRegion(const VECTOR2I &aRectCenter, const VECTOR2I &aSize, int aCornerRadius, const EDA_ANGLE &aOrient)
Plot a round rect (a round rect shape in fact) as a Gerber region using lines and arcs for corners.
virtual void FlashPadRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, OUTLINE_MODE aTraceMode, void *aData) override
void FlashPadChamferRoundRect(const VECTOR2I &aShapePos, const VECTOR2I &aPadSize, int aCornerRadius, double aChamferRatio, int aChamferPositions, const EDA_ANGLE &aPadOrient, OUTLINE_MODE aPlotMode, void *aData)
Flash a chamfered round rect pad.
wxString m_workFilename
bool m_hasApertureRoundRect
static wxString GetDefaultFileExtension()
bool m_gerberDisableApertMacros
virtual void Text(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const EDA_ANGLE &aOrient, const VECTOR2I &aSize, enum GR_TEXT_H_ALIGN_T aH_justify, enum GR_TEXT_V_ALIGN_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, KIFONT::FONT *aFont=nullptr, void *aData=nullptr) override
Draw text with the plotter.
virtual void SetViewport(const VECTOR2I &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
Set the plot offset and scaling for the current plot.
virtual bool EndPlot() override
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
virtual PLOT_FORMAT GetPlotterType() const override
Returns the effective plot engine in use.
void UseX2format(bool aEnable)
virtual void SetLayerPolarity(bool aPositive) override
Change the plot polarity and begin a new layer.
virtual void FlashPadOval(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, OUTLINE_MODE aTraceMode, void *aData) override
void UseX2NetAttributes(bool aEnable)
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
Gerber polygon: they can (and should) be filled with the appropriate G36/G37 sequence.
virtual void FlashPadRoundRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, int aCornerRadius, const EDA_ANGLE &aOrient, OUTLINE_MODE aTraceMode, void *aData) override
virtual void EndBlock(void *aData) override
Define the end of a group of drawing items the group is started by StartBlock().
virtual void ThickRect(const VECTOR2I &p1, const VECTOR2I &p2, int width, OUTLINE_MODE tracemode, void *aData) override
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, OUTLINE_MODE tracemode, void *aData) override
void clearNetAttribute()
Clear a Gerber net attribute record (clear object attribute dictionary) and output the clear object a...
virtual void StartBlock(void *aData) override
Calling this function allows one to define the beginning of a group of drawing items (used in X2 form...
virtual void FlashRegularPolygon(const VECTOR2I &aShapePos, int aDiameter, int aCornerCount, const EDA_ANGLE &aOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a regular polygon.
virtual void SetDash(int aLineWidth, PLOT_DASH_TYPE aLineStyle) override
virtual bool StartPlot(const wxString &pageNumber) override
Write GERBER header to file initialize global variable g_Plot_PlotOutputFile.
virtual void ThickArc(const VECTOR2I &aCentre, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, OUTLINE_MODE aTraceMode, void *aData) override
virtual void FilledCircle(const VECTOR2I &pos, int diametre, OUTLINE_MODE tracemode, void *aData) override
void DisableApertMacros(bool aDisable)
Disable Aperture Macro (AM) command, only for broken Gerber Readers.
FONT is an abstract base class for both outline and stroke fonts.
Definition: font.h:105
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:110
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:114
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
FILL_T
Definition: eda_shape.h:54
Plotting engine (Gerber)
OUTLINE_MODE
Definition: outline_mode.h:25
Plot settings, and plotting engines (PostScript, Gerber, HPGL and DXF)
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:70
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T