KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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
21#pragma once
22
23#include "plotter.h"
25
26class SHAPE_ARC;
27class GBR_METADATA;
28
29class GERBER_PLOTTER : public PLOTTER
30{
31public:
33
34 virtual PLOT_FORMAT GetPlotterType() const override
35 {
36 return PLOT_FORMAT::GERBER;
37 }
38
39 static wxString GetDefaultFileExtension()
40 {
41 return wxString( wxT( "gbr" ) );
42 }
43
47 virtual bool StartPlot( const wxString& pageNumber ) override;
48 virtual bool EndPlot() override;
49 virtual void SetCurrentLineWidth( int aLineWidth, void* aData = nullptr ) override;
50
51 // RS274X has no dashing, nor colors
52 virtual void SetDash( int aLineWidth, LINE_STYLE aLineStyle ) override
53 {
54 }
55
56 virtual void SetColor( const COLOR4D& aColor ) override {}
57
58 // Currently, aScale and aMirror are not used in gerber plotter
59 virtual void SetViewport( const VECTOR2I& aOffset, double aIusPerDecimil,
60 double aScale, bool aMirror ) override;
61
62 // Basic plot primitives
63 virtual void Rect( const VECTOR2I& p1, const VECTOR2I& p2, FILL_T fill,
64 int width = USE_DEFAULT_LINE_WIDTH ) override;
65 virtual void Circle( const VECTOR2I& pos, int diametre, FILL_T fill,
66 int width = USE_DEFAULT_LINE_WIDTH ) override;
67 virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
68 const EDA_ANGLE& aAngle, double aRadius, FILL_T aFill,
69 int aWidth = USE_DEFAULT_LINE_WIDTH ) override;
70
71 // These functions plot an item and manage X2 gerber attributes
72 virtual void ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
73 OUTLINE_MODE tracemode, void* aData ) override;
74
75 virtual void ThickRect( const VECTOR2I& p1, const VECTOR2I& p2, int width,
76 OUTLINE_MODE tracemode, void* aData ) override;
77
78 virtual void ThickCircle( const VECTOR2I& pos, int diametre, int width,
79 OUTLINE_MODE tracemode, void* aData ) override;
80
81 virtual void FilledCircle( const VECTOR2I& pos, int diametre,
82 OUTLINE_MODE tracemode, void* aData ) override;
83
88 virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill,
89 int aWidth = USE_DEFAULT_LINE_WIDTH, void* aData = nullptr ) override;
90
91 virtual void PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill,
92 int aWidth = USE_DEFAULT_LINE_WIDTH, void* aData = nullptr ) override;
93
98 void PlotPolyAsRegion( const SHAPE_LINE_CHAIN& aPoly, FILL_T aFill,
99 int aWidth, GBR_METADATA* aGbrMetadata );
100
101 virtual void PenTo( const VECTOR2I& pos, char plume ) override;
102
103 virtual void Text( const VECTOR2I& aPos,
104 const COLOR4D& aColor,
105 const wxString& aText,
106 const EDA_ANGLE& aOrient,
107 const VECTOR2I& aSize,
108 enum GR_TEXT_H_ALIGN_T aH_justify,
109 enum GR_TEXT_V_ALIGN_T aV_justify,
110 int aWidth,
111 bool aItalic,
112 bool aBold,
113 bool aMultilineAllowed,
114 KIFONT::FONT* aFont,
115 const KIFONT::METRICS& aFontMetrics,
116 void* aData = nullptr ) override;
117
118
119 virtual void PlotText( const VECTOR2I& aPos,
120 const COLOR4D& aColor,
121 const wxString& aText,
122 const TEXT_ATTRIBUTES& aAttributes,
123 KIFONT::FONT* aFont,
124 const KIFONT::METRICS& aFontMetrics,
125 void* aData = nullptr ) override;
126
130 virtual void FlashPadCircle( const VECTOR2I& pos, int diametre,
131 OUTLINE_MODE trace_mode, void* aData ) override;
132
133 virtual void FlashPadOval( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
134 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
135 void* aData ) override;
136
137 virtual void FlashPadRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
138 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
139 void* aData ) override;
140
141 virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
142 int aCornerRadius, const EDA_ANGLE& aOrient,
143 OUTLINE_MODE aTraceMode, void* aData ) override;
144 virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
145 const EDA_ANGLE& aPadOrient, SHAPE_POLY_SET* aPolygons,
146 OUTLINE_MODE aTraceMode, void* aData ) override;
147
148 virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
149 const EDA_ANGLE& aPadOrient, OUTLINE_MODE aTraceMode,
150 void* aData ) override;
151
152 virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
153 const EDA_ANGLE& aOrient, OUTLINE_MODE aTraceMode,
154 void* aData ) override;
155
173 void FlashPadChamferRoundRect( const VECTOR2I& aShapePos, const VECTOR2I& aPadSize,
174 int aCornerRadius, double aChamferRatio,
175 int aChamferPositions, const EDA_ANGLE& aPadOrient,
176 OUTLINE_MODE aPlotMode, void* aData );
177
183 void PlotGerberRegion( const std::vector<VECTOR2I>& aCornerList, GBR_METADATA* aGbrMetadata );
184
185 void PlotGerberRegion( const SHAPE_LINE_CHAIN& aPoly, GBR_METADATA* aGbrMetadata );
186
192 virtual void SetLayerPolarity( bool aPositive ) override;
193
204 virtual void SetGerberCoordinatesFormat( int aResolution, bool aUseInches = false ) override;
205
206 void UseX2format( bool aEnable ) { m_useX2format = aEnable; }
207 void UseX2NetAttributes( bool aEnable ) { m_useNetAttributes = aEnable; }
208
216 void DisableApertMacros( bool aDisable ) { m_gerberDisableApertMacros = aDisable; }
217
224 virtual void StartBlock( void* aData ) override;
225
233 virtual void EndBlock( void* aData ) override;
234
239 void ClearAllAttributes();
240
251 int GetOrCreateAperture( const VECTOR2I& aSize, int aRadius, const EDA_ANGLE& aRotation,
252 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
253
263 int GetOrCreateAperture( const std::vector<VECTOR2I>& aCorners, const EDA_ANGLE& aRotation,
264 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
265
266protected:
267 virtual void ThickArc( const VECTOR2D& aCentre, const EDA_ANGLE& aStartAngle,
268 const EDA_ANGLE& aAngle, double aRadius, int aWidth,
269 OUTLINE_MODE aTraceMode, void* aData ) override;
270
282 void plotRoundRectAsRegion( const VECTOR2I& aRectCenter, const VECTOR2I& aSize,
283 int aCornerRadius, const EDA_ANGLE& aOrient );
294 void plotArc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle,
295 double aRadius, bool aPlotInRegion );
296 void plotArc( const SHAPE_ARC& aArc, bool aPlotInRegion );
297
303 void selectAperture( const VECTOR2I& aSize, int aRadius, const EDA_ANGLE& aRotation,
304 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
312 void selectAperture( const std::vector<VECTOR2I>& aCorners, const EDA_ANGLE& aPolygonRotation,
313 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
314
323 void selectAperture( int aDiameter, const EDA_ANGLE& aRotation,
324 APERTURE::APERTURE_TYPE aType, int aApertureAttribute );
325
332 void emitDcode( const VECTOR2D& pt, int dcode );
333
344
350 void clearNetAttribute();
351
352 // the attributes dictionary created/modified by %TO, attached to objects, when they are created
353 // by D01, D03, G36/G37 commands
354 // standard attributes are .P, .C and .N
355 // this is used by gerber readers when creating a new object. Cleared by %TD command
356 // Note: m_objectAttributesDictionary can store more than one attribute
357 // the string stores the line(s) actually written to the gerber file
358 // it can store a .P, .C or .N attribute, or 2 or 3 attributes, separated by a \n char (EOL)
360
361 // The last aperture attribute generated (only one aperture attribute can be set)
363
364 FILE* workFile;
367
371 void writeApertureList();
372
373 std::vector<APERTURE> m_apertures; // The list of available apertures
374 int m_currentApertureIdx; // The index of the current aperture in m_apertures
375 bool m_hasApertureRoundRect; // true is at least one round rect aperture is in use
376 bool m_hasApertureRotOval; // true is at least one oval rotated aperture is in use
377 bool m_hasApertureRotRect; // true is at least one rect. rotated aperture is in use
378 bool m_hasApertureOutline4P; // true is at least one 4 corners outline (free polygon
379 // with 4 corners) aperture is in use
380 bool m_hasApertureChamferedRect; // true is at least one chamfered rect is in use
381 // (with no rounded corner)
382
383 bool m_gerberUnitInch; // true if the gerber units are inches, false for mm
384 int m_gerberUnitFmt; // number of digits in mantissa.
385 // usually 6 in Inches and 5 or 6 in mm
386 bool m_gerberDisableApertMacros; // True to disable Aperture Macro (AM) command,
387 // for broken Gerber Readers
388 // Regions will be used instead of AM shapes
389 bool m_useX2format; // Add X2 file header attributes. If false, attributes
390 // will be added as comments.
391 bool m_useNetAttributes; // In recent gerber files, netlist info can be added.
392 // It will be added if this param is true, using X2 or
393 // X1 format
394
395 // A list of aperture macros defined "on the fly" because the number of parameters is not
396 // defined: this is the case of the macro using the primitive 4 to create a polygon.
397 // The number of vertices is not known for free polygonal shapes, and an aperture macro
398 // must be created for each specific polygon
400};
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:205
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 SetGerberCoordinatesFormat(int aResolution, bool aUseInches=false) override
Selection of Gerber units and resolution (number of digits in mantissa).
virtual void ThickArc(const VECTOR2D &aCentre, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, int aWidth, OUTLINE_MODE aTraceMode, void *aData) override
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
int GetOrCreateAperture(const VECTOR2I &aSize, int aRadius, const EDA_ANGLE &aRotation, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
void PlotPolyAsRegion(const SHAPE_LINE_CHAIN &aPoly, FILL_T aFill, int aWidth, GBR_METADATA *aGbrMetadata)
Similar to PlotPoly(), plot a filled polygon using Gerber region, therefore adding X2 attributes to t...
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
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.
virtual void SetDash(int aLineWidth, LINE_STYLE aLineStyle) override
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 PlotText(const VECTOR2I &aPos, const COLOR4D &aColor, const wxString &aText, const TEXT_ATTRIBUTES &aAttributes, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
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 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
void PlotGerberRegion(const std::vector< VECTOR2I > &aCornerList, GBR_METADATA *aGbrMetadata)
Plot a Gerber region: similar to PlotPoly but plot only filled polygon, and add the TA....
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 bool StartPlot(const wxString &pageNumber) override
Write GERBER header to file initialize global variable g_Plot_PlotOutputFile.
virtual void FilledCircle(const VECTOR2I &pos, int diametre, OUTLINE_MODE tracemode, void *aData) override
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
void plotArc(const VECTOR2I &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle, double aRadius, bool aPlotInRegion)
Plot a Gerber arc.
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, KIFONT::FONT *aFont, const KIFONT::METRICS &aFontMetrics, void *aData=nullptr) override
Draw text with the plotter.
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:131
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:104
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:108
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:55
Plotting engine (Gerber)
OUTLINE_MODE
Definition: outline_mode.h:25
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:64
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:48
GR_TEXT_H_ALIGN_T
GR_TEXT_V_ALIGN_T