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 The 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, int width ) override;
64 virtual void Circle( const VECTOR2I& pos, int diametre, FILL_T fill, int width ) override;
65 virtual void Arc( const VECTOR2D& aCenter, const EDA_ANGLE& aStartAngle,
66 const EDA_ANGLE& aAngle, double aRadius, FILL_T aFill, int aWidth ) override;
67
68 // These functions plot an item and manage X2 gerber attributes
69 virtual void ThickSegment( const VECTOR2I& start, const VECTOR2I& end, int width,
70 void* aData ) override;
71
72 virtual void ThickRect( const VECTOR2I& p1, const VECTOR2I& p2, int width,
73 void* aData ) override;
74
75 virtual void ThickCircle( const VECTOR2I& pos, int diametre, int width, void* aData ) override;
76
77 virtual void FilledCircle( const VECTOR2I& pos, int diametre, void* aData ) override;
78
79 virtual void ThickPoly( const SHAPE_POLY_SET& aPoly, int aWidth, void* aData ) override;
80
85 virtual void PlotPoly( const std::vector<VECTOR2I>& aCornerList, FILL_T aFill, int aWidth,
86 void* aData ) override;
87
88 virtual void PlotPoly( const SHAPE_LINE_CHAIN& aCornerList, FILL_T aFill, int aWidth,
89 void* aData ) override;
90
95 void PlotPolyAsRegion( const SHAPE_LINE_CHAIN& aPoly, FILL_T aFill,
96 int aWidth, GBR_METADATA* aGbrMetadata );
97
98 virtual void PenTo( const VECTOR2I& pos, char plume ) override;
99
100 virtual void Text( const VECTOR2I& aPos,
101 const COLOR4D& aColor,
102 const wxString& aText,
103 const EDA_ANGLE& aOrient,
104 const VECTOR2I& aSize,
105 enum GR_TEXT_H_ALIGN_T aH_justify,
106 enum GR_TEXT_V_ALIGN_T aV_justify,
107 int aWidth,
108 bool aItalic,
109 bool aBold,
110 bool aMultilineAllowed,
111 KIFONT::FONT* aFont,
112 const KIFONT::METRICS& aFontMetrics,
113 void* aData = nullptr ) override;
114
115
116 virtual void PlotText( const VECTOR2I& aPos,
117 const COLOR4D& aColor,
118 const wxString& aText,
119 const TEXT_ATTRIBUTES& aAttributes,
120 KIFONT::FONT* aFont,
121 const KIFONT::METRICS& aFontMetrics,
122 void* aData = nullptr ) override;
123
127 virtual void FlashPadCircle( const VECTOR2I& pos, int diametre, void* aData ) override;
128
129 virtual void FlashPadOval( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
130 const EDA_ANGLE& aOrient, void* aData ) override;
131
132 virtual void FlashPadRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
133 const EDA_ANGLE& aOrient, void* aData ) override;
134
135 virtual void FlashPadRoundRect( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
136 int aCornerRadius, const EDA_ANGLE& aOrient,
137 void* aData ) override;
138 virtual void FlashPadCustom( const VECTOR2I& aPadPos, const VECTOR2I& aSize,
139 const EDA_ANGLE& aPadOrient, SHAPE_POLY_SET* aPolygons,
140 void* aData ) override;
141
142 virtual void FlashPadTrapez( const VECTOR2I& aPadPos, const VECTOR2I* aCorners,
143 const EDA_ANGLE& aPadOrient, void* aData ) override;
144
145 virtual void FlashRegularPolygon( const VECTOR2I& aShapePos, int aDiameter, int aCornerCount,
146 const EDA_ANGLE& aOrient, void* aData ) override;
147
164 void FlashPadChamferRoundRect( const VECTOR2I& aShapePos, const VECTOR2I& aPadSize,
165 int aCornerRadius, double aChamferRatio, int aChamferPositions,
166 const EDA_ANGLE& aPadOrient, void* aData );
167
173 void PlotGerberRegion( const std::vector<VECTOR2I>& aCornerList, GBR_METADATA* aGbrMetadata );
174
175 void PlotGerberRegion( const SHAPE_LINE_CHAIN& aPoly, GBR_METADATA* aGbrMetadata );
176
182 virtual void SetLayerPolarity( bool aPositive ) override;
183
194 virtual void SetGerberCoordinatesFormat( int aResolution, bool aUseInches = false ) override;
195
196 void UseX2format( bool aEnable ) { m_useX2format = aEnable; }
197 void UseX2NetAttributes( bool aEnable ) { m_useNetAttributes = aEnable; }
198
206 void DisableApertMacros( bool aDisable ) { m_gerberDisableApertMacros = aDisable; }
207
214 virtual void StartBlock( void* aData ) override;
215
223 virtual void EndBlock( void* aData ) override;
224
229 void ClearAllAttributes();
230
242 int GetOrCreateAperture( const VECTOR2I& aSize, int aRadius, const EDA_ANGLE& aRotation,
243 APERTURE::APERTURE_TYPE aType, int aApertureAttribute,
244 const std::string& aCustomAttribute );
245
256 int GetOrCreateAperture( const std::vector<VECTOR2I>& aCorners, const EDA_ANGLE& aRotation,
257 APERTURE::APERTURE_TYPE aType, int aApertureAttribute,
258 const std::string& aCustomAttribute );
259
260protected:
261 virtual void ThickArc( const VECTOR2D& aCentre, const EDA_ANGLE& aStartAngle,
262 const EDA_ANGLE& aAngle, double aRadius, int aWidth, void* aData ) override;
263
275 void plotRoundRectAsRegion( const VECTOR2I& aRectCenter, const VECTOR2I& aSize,
276 int aCornerRadius, const EDA_ANGLE& aOrient );
287 void plotArc( const VECTOR2I& aCenter, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle,
288 double aRadius, bool aPlotInRegion );
289 void plotArc( const SHAPE_ARC& aArc, bool aPlotInRegion );
290
296 void selectAperture( const VECTOR2I& aSize, int aRadius, const EDA_ANGLE& aRotation,
297 APERTURE::APERTURE_TYPE aType, int aApertureAttribute,
298 const std::string& aCustomAttribute );
306 void selectAperture( const std::vector<VECTOR2I>& aCorners, const EDA_ANGLE& aPolygonRotation,
307 APERTURE::APERTURE_TYPE aType, int aApertureAttribute,
308 const std::string& aCustomAttribute );
309
310
315 void selectApertureWithAttributes( const VECTOR2I& aPos, GBR_METADATA* aGbrMetadata,
316 VECTOR2I aSize, int aRadius, const EDA_ANGLE& aAngle,
318
325 void emitDcode( const VECTOR2D& pt, int dcode );
326
337
343 void clearNetAttribute();
344
345 // the attributes dictionary created/modified by %TO, attached to objects, when they are created
346 // by D01, D03, G36/G37 commands
347 // standard attributes are .P, .C and .N
348 // this is used by gerber readers when creating a new object. Cleared by %TD command
349 // Note: m_objectAttributesDictionary can store more than one attribute
350 // the string stores the line(s) actually written to the gerber file
351 // it can store a .P, .C or .N attribute, or 2 or 3 attributes, separated by a \n char (EOL)
353
354 // The last aperture attribute generated (only one aperture attribute can be set)
356
357 FILE* workFile;
360
364 void writeApertureList();
365
366 std::vector<APERTURE> m_apertures; // The list of available apertures
367 int m_currentApertureIdx; // The index of the current aperture in m_apertures
368 bool m_hasApertureRoundRect; // true is at least one round rect aperture is in use
369 bool m_hasApertureRotOval; // true is at least one oval rotated aperture is in use
370 bool m_hasApertureRotRect; // true is at least one rect. rotated aperture is in use
371 bool m_hasApertureOutline4P; // true is at least one 4 corners outline (free polygon
372 // with 4 corners) aperture is in use
373 bool m_hasApertureChamferedRect; // true is at least one chamfered rect is in use
374 // (with no rounded corner)
375
376 bool m_gerberUnitInch; // true if the gerber units are inches, false for mm
377 int m_gerberUnitFmt; // number of digits in mantissa.
378 // usually 6 in Inches and 5 or 6 in mm
379 bool m_gerberDisableApertMacros; // True to disable Aperture Macro (AM) command,
380 // for broken Gerber Readers
381 // Regions will be used instead of AM shapes
382 bool m_useX2format; // Add X2 file header attributes. If false, attributes
383 // will be added as comments.
384 bool m_useNetAttributes; // In recent gerber files, netlist info can be added.
385 // It will be added if this param is true, using X2 or
386 // X1 format
387
388 // A list of aperture macros defined "on the fly" because the number of parameters is not
389 // defined: this is the case of the macro using the primitive 4 to create a polygon.
390 // The number of vertices is not known for free polygonal shapes, and an aperture macro
391 // must be created for each specific polygon
393};
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:211
Information which can be added in a gerber file as attribute of an object.
virtual void SetColor(const COLOR4D &aColor) override
virtual void FlashPadRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, void *aData) override
std::string m_objectAttributesDictionary
virtual void ThickSegment(const VECTOR2I &start, const VECTOR2I &end, int width, void *aData) override
virtual void SetGerberCoordinatesFormat(int aResolution, bool aUseInches=false) override
Selection of Gerber units and resolution (number of digits in mantissa).
void FlashPadChamferRoundRect(const VECTOR2I &aShapePos, const VECTOR2I &aPadSize, int aCornerRadius, double aChamferRatio, int aChamferPositions, const EDA_ANGLE &aPadOrient, void *aData)
Flash a chamfered round rect pad.
void ClearAllAttributes()
Remove (clear) all attributes from object attributes dictionary (TO.
int GetOrCreateAperture(const VECTOR2I &aSize, int aRadius, const EDA_ANGLE &aRotation, APERTURE::APERTURE_TYPE aType, int aApertureAttribute, const std::string &aCustomAttribute)
virtual void ThickPoly(const SHAPE_POLY_SET &aPoly, int aWidth, void *aData) override
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 FlashPadCircle(const VECTOR2I &pos, int diametre, void *aData) override
Filled circular flashes are stored as apertures.
virtual void FlashPadRoundRect(const VECTOR2I &aPadPos, const VECTOR2I &aSize, int aCornerRadius, const EDA_ANGLE &aOrient, void *aData) override
virtual void PenTo(const VECTOR2I &pos, char plume) override
Moveto/lineto primitive, moves the 'pen' to the specified direction.
void selectAperture(const VECTOR2I &aSize, int aRadius, const EDA_ANGLE &aRotation, APERTURE::APERTURE_TYPE aType, int aApertureAttribute, const std::string &aCustomAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
void emitDcode(const VECTOR2D &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
virtual void FlashRegularPolygon(const VECTOR2I &aShapePos, int aDiameter, int aCornerCount, const EDA_ANGLE &aOrient, void *aData) override
Flash a regular polygon.
APER_MACRO_FREEPOLY_LIST m_am_freepoly_list
virtual void PlotPoly(const std::vector< VECTOR2I > &aCornerList, FILL_T aFill, int aWidth, void *aData) override
Gerber polygon: they can (and should) be filled with the appropriate G36/G37 sequence.
virtual void FlashPadOval(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aOrient, void *aData) override
std::vector< APERTURE > m_apertures
bool m_hasApertureChamferedRect
virtual void FlashPadTrapez(const VECTOR2I &aPadPos, const VECTOR2I *aCorners, const EDA_ANGLE &aPadOrient, 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 Circle(const VECTOR2I &pos, int diametre, FILL_T fill, int width) override
virtual void Arc(const VECTOR2D &aCenter, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, FILL_T aFill, int aWidth) override
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
virtual void Rect(const VECTOR2I &p1, const VECTOR2I &p2, FILL_T fill, int width) override
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
void selectApertureWithAttributes(const VECTOR2I &aPos, GBR_METADATA *aGbrMetadata, VECTOR2I aSize, int aRadius, const EDA_ANGLE &aAngle, APERTURE::APERTURE_TYPE aType)
Pick an aperture or create a new one and emits the DCode.
virtual PLOT_FORMAT GetPlotterType() const override
Return the effective plot engine in use.
void UseX2format(bool aEnable)
virtual void ThickRect(const VECTOR2I &p1, const VECTOR2I &p2, int width, void *aData) override
virtual void SetLayerPolarity(bool aPositive) override
Change the plot polarity and begin a new layer.
void UseX2NetAttributes(bool aEnable)
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 FlashPadCustom(const VECTOR2I &aPadPos, const VECTOR2I &aSize, const EDA_ANGLE &aPadOrient, SHAPE_POLY_SET *aPolygons, void *aData) override
virtual void EndBlock(void *aData) override
Define the end of a group of drawing items the group is started by StartBlock().
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 ThickArc(const VECTOR2D &aCentre, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aRadius, int aWidth, void *aData) override
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, void *aData) 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.
virtual void ThickCircle(const VECTOR2I &pos, int diametre, int width, 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:131
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Base plotter engine class.
Definition: plotter.h:121
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:56
Plotting engine (Gerber)
PLOT_FORMAT
The set of supported output plot formats.
Definition: plotter.h:64
LINE_STYLE
Dashed line types.
Definition: stroke_params.h:46
VECTOR2I end
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.