KiCad PCB EDA Suite
GERBER_PLOTTER Class Reference

#include <plotter_gerber.h>

Inheritance diagram for GERBER_PLOTTER:
PLOTTER

Public Member Functions

 GERBER_PLOTTER ()
 
virtual PLOT_FORMAT GetPlotterType () const override
 Returns the effective plot engine in use. More...
 
virtual bool StartPlot () override
 Write GERBER header to file initialize global variable g_Plot_PlotOutputFile. More...
 
virtual bool EndPlot () override
 
virtual void SetCurrentLineWidth (int width, void *aData=nullptr) override
 Set the line width for the next drawing. More...
 
virtual void SetDash (PLOT_DASH_TYPE dashed) override
 
virtual void SetColor (const COLOR4D &color) override
 
virtual void SetViewport (const wxPoint &aOffset, double aIusPerDecimil, double aScale, bool aMirror) override
 Set the plot offset and scaling for the current plot. More...
 
virtual void Rect (const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
 
virtual void Circle (const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
 
virtual void Arc (const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
 Generic fallback: arc rendered as a polyline. More...
 
virtual void Arc (const SHAPE_ARC &aArc) override
 
virtual void ThickSegment (const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode, void *aData) override
 
virtual void ThickArc (const wxPoint &centre, double StAngle, double EndAngle, int rayon, int width, OUTLINE_MODE tracemode, void *aData) override
 
virtual void ThickRect (const wxPoint &p1, const wxPoint &p2, int width, OUTLINE_MODE tracemode, void *aData) override
 
virtual void ThickCircle (const wxPoint &pos, int diametre, int width, OUTLINE_MODE tracemode, void *aData) override
 
virtual void FilledCircle (const wxPoint &pos, int diametre, OUTLINE_MODE tracemode, void *aData) override
 
virtual void PlotPoly (const std::vector< wxPoint > &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. More...
 
virtual void PlotPoly (const SHAPE_LINE_CHAIN &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr) override
 Draw a polygon ( filled or not ). More...
 
virtual void PenTo (const wxPoint &pos, char plume) override
 Moveto/lineto primitive, moves the 'pen' to the specified direction. More...
 
virtual void Text (const wxPoint &aPos, const COLOR4D &aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=nullptr) override
 Draw text with the plotter. More...
 
virtual void FlashPadCircle (const wxPoint &pos, int diametre, OUTLINE_MODE trace_mode, void *aData) override
 Filled circular flashes are stored as apertures. More...
 
virtual void FlashPadOval (const wxPoint &aPadPos, const wxSize &size, double orient, OUTLINE_MODE trace_mode, void *aData) override
 
virtual void FlashPadRect (const wxPoint &aPadPos, const wxSize &size, double orient, OUTLINE_MODE trace_mode, void *aData) override
 
virtual void FlashPadRoundRect (const wxPoint &aPadPos, const wxSize &aSize, int aCornerRadius, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
 
virtual void FlashPadCustom (const wxPoint &aPadPos, const wxSize &aSize, double aPadOrient, SHAPE_POLY_SET *aPolygons, OUTLINE_MODE aTraceMode, void *aData) override
 
virtual void FlashPadTrapez (const wxPoint &aPadPos, const wxPoint *aCorners, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
 Flash a trapezoidal pad. More...
 
virtual void FlashRegularPolygon (const wxPoint &aShapePos, int aDiameter, int aCornerCount, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
 Flash a regular polygon. More...
 
void FlashPadChamferRoundRect (const wxPoint &aShapePos, const wxSize &aPadSize, int aCornerRadius, double aChamferRatio, int aChamferPositions, double aPadOrient, OUTLINE_MODE aPlotMode, void *aData)
 Flash a chamfered round rect pad. More...
 
void PlotGerberRegion (const std::vector< wxPoint > &aCornerList, void *aData=nullptr)
 Plot a Gerber region: similar to PlotPoly but plot only filled polygon, and add the TA.AperFunction if aData contains this attribute, and clear it after plotting. More...
 
void PlotGerberRegion (const SHAPE_LINE_CHAIN &aPoly, void *aData=nullptr)
 
virtual void SetLayerPolarity (bool aPositive) override
 Change the plot polarity and begin a new layer. More...
 
virtual void SetGerberCoordinatesFormat (int aResolution, bool aUseInches=false) override
 Selection of Gerber units and resolution (number of digits in mantissa). More...
 
void UseX2format (bool aEnable)
 
void UseX2NetAttributes (bool aEnable)
 
void DisableApertMacros (bool aDisable)
 Disable Aperture Macro (AM) command, only for broken Gerber Readers. More...
 
virtual void StartBlock (void *aData) override
 Calling this function allows one to define the beginning of a group of drawing items (used in X2 format with netlist attributes). More...
 
virtual void EndBlock (void *aData) override
 Define the end of a group of drawing items the group is started by StartBlock(). More...
 
void ClearAllAttributes ()
 Remove (clear) all attributes from object attributes dictionary (TO. More...
 
int GetOrCreateAperture (const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
 
int GetOrCreateAperture (const std::vector< wxPoint > &aCorners, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
 
virtual void SetNegative (bool aNegative)
 
virtual void SetColorMode (bool aColorMode)
 Plot in B/W or color. More...
 
bool GetColorMode () const
 
void SetRenderSettings (RENDER_SETTINGS *aSettings)
 
RENDER_SETTINGSRenderSettings ()
 
virtual void SetPageSettings (const PAGE_INFO &aPageSettings)
 
PAGE_INFOPageSettings ()
 
virtual int GetCurrentLineWidth () const
 
virtual void SetCreator (const wxString &aCreator)
 
virtual void SetTitle (const wxString &aTitle)
 
void AddLineToHeader (const wxString &aExtraString)
 Add a line to the list of free lines to print at the beginning of the file. More...
 
void ClearHeaderLinesList ()
 Remove all lines from the list of free lines to print at the beginning of the file. More...
 
virtual bool OpenFile (const wxString &aFullFilename)
 Open or create the plot file aFullFilename. More...
 
double GetIUsPerDecimil () const
 The IUs per decimil are an essential scaling factor when plotting; they are set and saved when establishing the viewport. More...
 
int GetPlotterArcLowDef () const
 
int GetPlotterArcHighDef () const
 
virtual void BezierCurve (const wxPoint &aStart, const wxPoint &aControl1, const wxPoint &aControl2, const wxPoint &aEnd, int aTolerance, int aLineThickness=USE_DEFAULT_LINE_WIDTH)
 Generic fallback: Cubic Bezier curve rendered as a polyline In KiCad the bezier curves have 4 control points: start ctrl1 ctrl2 end. More...
 
void MoveTo (const wxPoint &pos)
 
void LineTo (const wxPoint &pos)
 
void FinishTo (const wxPoint &pos)
 
void PenFinish ()
 
virtual void PlotImage (const wxImage &aImage, const wxPoint &aPos, double aScaleFactor)
 Only PostScript plotters can plot bitmaps. More...
 
void Marker (const wxPoint &position, int diametre, unsigned aShapeId)
 Draw a pattern shape number aShapeId, to coord position. More...
 
virtual void SetTextMode (PLOT_TEXT_MODE mode)
 Change the current text mode. More...
 
virtual void SetSvgCoordinatesFormat (unsigned aResolution, bool aUseInches=false)
 

Static Public Member Functions

static wxString GetDefaultFileExtension ()
 

Static Public Attributes

static const int DO_NOT_SET_LINE_WIDTH = -2
 
static const int USE_DEFAULT_LINE_WIDTH = -1
 
static const unsigned MARKER_COUNT = 58
 Draw a marker (used for the drill map). More...
 

Protected Member Functions

void plotRoundRectAsRegion (const wxPoint &aRectCenter, const wxSize &aSize, int aCornerRadius, double aOrient)
 Plot a round rect (a round rect shape in fact) as a Gerber region using lines and arcs for corners. More...
 
void plotArc (const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, bool aPlotInRegion)
 Plot a Gerber arc. More...
 
void plotArc (const SHAPE_ARC &aArc, bool aPlotInRegion)
 
void selectAperture (const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
 Pick an existing aperture or create a new one, matching the size, type and attributes. More...
 
void selectAperture (const std::vector< wxPoint > &aCorners, double aPolygonRotation, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
 Pick an existing aperture or create a new one, matching the aDiameter, aPolygonRotation, type and attributes. More...
 
void selectAperture (int aDiameter, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
 Pick an existing aperture or create a new one, matching the corner list, aRotDegree, type and attributes. More...
 
void emitDcode (const DPOINT &pt, int dcode)
 Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate. More...
 
void formatNetAttribute (GBR_NETLIST_METADATA *aData)
 Print a Gerber net attribute object record. More...
 
void clearNetAttribute ()
 Clear a Gerber net attribute record (clear object attribute dictionary) and output the clear object attribute dictionary command to gerber file has effect only if a net attribute is stored in m_objectAttributesDictionary. More...
 
void writeApertureList ()
 Generate the table of D codes. More...
 
void markerCircle (const wxPoint &pos, int radius)
 Plot a circle centered on the position. More...
 
void markerHBar (const wxPoint &pos, int radius)
 Plot a - bar centered on the position. More...
 
void markerSlash (const wxPoint &pos, int radius)
 Plot a / bar centered on the position. More...
 
void markerBackSlash (const wxPoint &pos, int radius)
 Plot a \ bar centered on the position. More...
 
void markerVBar (const wxPoint &pos, int radius)
 Plot a | bar centered on the position. More...
 
void markerSquare (const wxPoint &position, int radius)
 Plot a square centered on the position. More...
 
void markerLozenge (const wxPoint &position, int radius)
 Plot a lozenge centered on the position. More...
 
void segmentAsOval (const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode)
 Convert a thick segment and plot it as an oval. More...
 
void sketchOval (const wxPoint &pos, const wxSize &size, double orient, int width)
 
virtual DPOINT userToDeviceCoordinates (const wxPoint &aCoordinate)
 Modify coordinates according to the orientation, scale factor, and offsets trace. More...
 
virtual DPOINT userToDeviceSize (const wxSize &size)
 Modify size according to the plotter scale factors (wxSize version, returns a DPOINT). More...
 
virtual double userToDeviceSize (double size) const
 Modify size according to the plotter scale factors (simple double version). More...
 
double GetDotMarkLenIU () const
 
double GetDashMarkLenIU () const
 
double GetDashGapLenIU () const
 

Protected Attributes

std::string m_objectAttributesDictionary
 
int m_apertureAttribute
 
FILE * workFile
 
FILE * finalFile
 
wxString m_workFilename
 
std::vector< APERTUREm_apertures
 
int m_currentApertureIdx
 
bool m_hasApertureRoundRect
 
bool m_hasApertureRotOval
 
bool m_hasApertureRotRect
 
bool m_hasApertureOutline4P
 
bool m_hasApertureChamferedRect
 
bool m_gerberUnitInch
 
int m_gerberUnitFmt
 
bool m_gerberDisableApertMacros
 
bool m_useX2format
 
bool m_useNetAttributes
 
APER_MACRO_FREEPOLY_LIST m_am_freepoly_list
 
double m_plotScale
 Plot scale - chosen by the user (even implicitly with 'fit in a4') More...
 
double m_IUsPerDecimil
 
double m_iuPerDeviceUnit
 
wxPoint m_plotOffset
 
bool m_plotMirror
 
bool m_mirrorIsHorizontal
 
bool m_yaxisReversed
 
FILE * m_outputFile
 Output file. More...
 
bool m_colorMode
 
bool m_negativeMode
 
int m_currentPenWidth
 
char m_penState
 
wxPoint m_penLastpos
 
wxString m_creator
 
wxString m_filename
 
wxString m_title
 
PAGE_INFO m_pageInfo
 
wxSize m_paperSize
 
wxArrayString m_headerExtraLines
 
RENDER_SETTINGSm_renderSettings
 

Detailed Description

Definition at line 34 of file plotter_gerber.h.

Constructor & Destructor Documentation

◆ GERBER_PLOTTER()

GERBER_PLOTTER::GERBER_PLOTTER ( )

Definition at line 91 of file GERBER_plotter.cpp.

92 {
93  workFile = nullptr;
94  finalFile = nullptr;
97 
98  // number of digits after the point (number of digits of the mantissa
99  // Be careful: the Gerber coordinates are stored in an integer
100  // so 6 digits (inches) or 5 digits (mm) is a good value
101  // To avoid overflow, 7 digits (inches) or 6 digits is a max.
102  // with lower values than 6 digits (inches) or 5 digits (mm),
103  // Creating self-intersecting polygons from non-intersecting polygons
104  // happen easily.
105  m_gerberUnitInch = false;
106  m_gerberUnitFmt = 6;
107  m_useX2format = true;
108  m_useNetAttributes = true;
110 
111  m_hasApertureRoundRect = false; // true is at least one round rect aperture is in use
112  m_hasApertureRotOval = false; // true is at least one oval rotated aperture is in use
113  m_hasApertureRotRect = false; // true is at least one rect. rotated aperture is in use
114  m_hasApertureOutline4P = false; // true is at least one rotated rect or trapezoid pad
115  // aperture is in use
116  m_hasApertureChamferedRect = false; // true is at least one chamfered rect
117  // (no rounded corner) is in use
118 }
bool m_hasApertureChamferedRect
bool m_hasApertureOutline4P
bool m_hasApertureRoundRect
bool m_gerberDisableApertMacros

References finalFile, m_apertureAttribute, m_currentApertureIdx, m_gerberDisableApertMacros, m_gerberUnitFmt, m_gerberUnitInch, m_hasApertureChamferedRect, m_hasApertureOutline4P, m_hasApertureRotOval, m_hasApertureRotRect, m_hasApertureRoundRect, m_useNetAttributes, m_useX2format, and workFile.

Member Function Documentation

◆ AddLineToHeader()

void PLOTTER::AddLineToHeader ( const wxString &  aExtraString)
inlineinherited

Add a line to the list of free lines to print at the beginning of the file.

Parameters
aExtraStringis the string to print

Definition at line 183 of file plotter.h.

184  {
185  m_headerExtraLines.Add( aExtraString );
186  }
wxArrayString m_headerExtraLines
Definition: plotter.h:605

References PLOTTER::m_headerExtraLines.

Referenced by AddGerberX2Attribute(), AddGerberX2Header(), GERBER_WRITER::createDrillFile(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), and GENDRILL_WRITER_BASE::genDrillMapFile().

◆ Arc() [1/2]

void GERBER_PLOTTER::Arc ( const wxPoint &  centre,
double  StAngle,
double  EndAngle,
int  rayon,
FILL_T  fill,
int  width = USE_DEFAULT_LINE_WIDTH 
)
overridevirtual

Generic fallback: arc rendered as a polyline.

Reimplemented from PLOTTER.

Definition at line 821 of file GERBER_plotter.cpp.

823 {
824  SetCurrentLineWidth( aWidth );
825 
826  // aFill is not used here.
827  plotArc( aCenter, aStAngle, aEndAngle, aRadius, false );
828 }
void plotArc(const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, bool aPlotInRegion)
Plot a Gerber arc.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.

References plotArc(), and SetCurrentLineWidth().

Referenced by Circle(), and ThickArc().

◆ Arc() [2/2]

void GERBER_PLOTTER::Arc ( const SHAPE_ARC aArc)
overridevirtual

Reimplemented from PLOTTER.

Definition at line 831 of file GERBER_plotter.cpp.

832 {
833  SetCurrentLineWidth( aArc.GetWidth() );
834 
835  // aFill is not used here.
836  plotArc( aArc, false );
837 }
void plotArc(const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, bool aPlotInRegion)
Plot a Gerber arc.
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
int GetWidth() const
Definition: shape_arc.h:156

References SHAPE_ARC::GetWidth(), plotArc(), and SetCurrentLineWidth().

◆ BezierCurve()

void PLOTTER::BezierCurve ( const wxPoint &  aStart,
const wxPoint &  aControl1,
const wxPoint &  aControl2,
const wxPoint &  aEnd,
int  aTolerance,
int  aLineThickness = USE_DEFAULT_LINE_WIDTH 
)
virtualinherited

Generic fallback: Cubic Bezier curve rendered as a polyline In KiCad the bezier curves have 4 control points: start ctrl1 ctrl2 end.

Reimplemented in SVG_PLOTTER.

Definition at line 205 of file plotter.cpp.

208 {
209  // Generic fallback: Quadratic Bezier curve plotted as a polyline
210  int minSegLen = aLineThickness; // The segment min length to approximate a bezier curve
211 
212  std::vector<wxPoint> ctrlPoints;
213  ctrlPoints.push_back( aStart );
214  ctrlPoints.push_back( aControl1 );
215  ctrlPoints.push_back( aControl2 );
216  ctrlPoints.push_back( aEnd );
217 
218  BEZIER_POLY bezier_converter( ctrlPoints );
219 
220  std::vector<wxPoint> approxPoints;
221  bezier_converter.GetPoly( approxPoints, minSegLen );
222 
223  SetCurrentLineWidth( aLineThickness );
224  MoveTo( aStart );
225 
226  for( unsigned ii = 1; ii < approxPoints.size()-1; ii++ )
227  LineTo( approxPoints[ii] );
228 
229  FinishTo( aEnd );
230 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void LineTo(const wxPoint &pos)
Definition: plotter.h:268
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
Bezier curves to polygon converter.
Definition: bezier_curves.h:36
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.

References PLOTTER::FinishTo(), BEZIER_POLY::GetPoly(), PLOTTER::LineTo(), PLOTTER::MoveTo(), and PLOTTER::SetCurrentLineWidth().

Referenced by SVG_PLOTTER::BezierCurve(), BRDITEMS_PLOTTER::PlotFootprintGraphicItem(), and BRDITEMS_PLOTTER::PlotPcbShape().

◆ Circle()

void GERBER_PLOTTER::Circle ( const wxPoint &  pos,
int  diametre,
FILL_T  fill,
int  width = USE_DEFAULT_LINE_WIDTH 
)
overridevirtual

Implements PLOTTER.

Definition at line 814 of file GERBER_plotter.cpp.

815 {
816  Arc( aCenter, 0, 3600, aDiameter / 2, aFill, aWidth );
817 }
virtual void Arc(const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: arc rendered as a polyline.

References Arc().

Referenced by FilledCircle(), FlashPadCircle(), and ThickCircle().

◆ ClearAllAttributes()

void GERBER_PLOTTER::ClearAllAttributes ( )

Remove (clear) all attributes from object attributes dictionary (TO.

and TA commands) similar to clearNetAttribute(), this is an unconditional reset of TO. and TA. attributes.

Definition at line 161 of file GERBER_plotter.cpp.

162 {
163  // Remove all attributes from object attributes dictionary (TO. and TA commands)
164  if( m_useX2format )
165  fputs( "%TD*%\n", m_outputFile );
166  else
167  fputs( "G04 #@! TD*\n", m_outputFile );
168 
170 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
std::string m_objectAttributesDictionary

References m_objectAttributesDictionary, PLOTTER::m_outputFile, and m_useX2format.

Referenced by PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ ClearHeaderLinesList()

void PLOTTER::ClearHeaderLinesList ( )
inlineinherited

Remove all lines from the list of free lines to print at the beginning of the file.

Definition at line 191 of file plotter.h.

192  {
193  m_headerExtraLines.Clear();
194  }
wxArrayString m_headerExtraLines
Definition: plotter.h:605

References PLOTTER::m_headerExtraLines.

Referenced by GENDRILL_WRITER_BASE::genDrillMapFile(), and StartPlotBoard().

◆ clearNetAttribute()

void GERBER_PLOTTER::clearNetAttribute ( )
protected

Clear a Gerber net attribute record (clear object attribute dictionary) and output the clear object attribute dictionary command to gerber file has effect only if a net attribute is stored in m_objectAttributesDictionary.

Definition at line 173 of file GERBER_plotter.cpp.

174 {
175  // disable a Gerber net attribute (exists only in X2 with net attributes mode).
176  if( m_objectAttributesDictionary.empty() ) // No net attribute or not X2 mode
177  return;
178 
179  // Remove all net attributes from object attributes dictionary
180  if( m_useX2format )
181  fputs( "%TD*%\n", m_outputFile );
182  else
183  fputs( "G04 #@! TD*\n", m_outputFile );
184 
186 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
std::string m_objectAttributesDictionary

References m_objectAttributesDictionary, PLOTTER::m_outputFile, and m_useX2format.

Referenced by EndBlock(), and formatNetAttribute().

◆ DisableApertMacros()

void GERBER_PLOTTER::DisableApertMacros ( bool  aDisable)
inline

Disable Aperture Macro (AM) command, only for broken Gerber Readers.

Regions will be used instead of AM shapes to draw complex shapes.

Parameters
aDisableuse true to disable Aperture Macro (AM) command.

Definition at line 200 of file plotter_gerber.h.

200 { m_gerberDisableApertMacros = aDisable; }
bool m_gerberDisableApertMacros

References m_gerberDisableApertMacros.

Referenced by GERBER_WRITER::createDrillFile(), GENDRILL_WRITER_BASE::genDrillMapFile(), and StartPlotBoard().

◆ emitDcode()

void GERBER_PLOTTER::emitDcode ( const DPOINT pt,
int  dcode 
)
protected

Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.

For n decimal positions, see header generation in start_plot.

Definition at line 155 of file GERBER_plotter.cpp.

156 {
157 
158  fprintf( m_outputFile, "X%dY%dD%02d*\n", KiROUND( pt.x ), KiROUND( pt.y ), dcode );
159 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

References KiROUND(), PLOTTER::m_outputFile, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by FlashPadChamferRoundRect(), FlashPadCircle(), FlashPadCustom(), FlashPadOval(), FlashPadRect(), FlashPadRoundRect(), FlashPadTrapez(), FlashRegularPolygon(), and PenTo().

◆ EndBlock()

void GERBER_PLOTTER::EndBlock ( void *  aData)
overridevirtual

Define the end of a group of drawing items the group is started by StartBlock().

Used in X2 format with netlist attributes.

Parameters
aDatacan define any parameter

Reimplemented from PLOTTER.

Definition at line 196 of file GERBER_plotter.cpp.

197 {
198  // Remove all net attributes from object attributes dictionary
200 }
void clearNetAttribute()
Clear a Gerber net attribute record (clear object attribute dictionary) and output the clear object a...

References clearNetAttribute().

Referenced by GERBER_WRITER::createDrillFile(), and StartBlock().

◆ EndPlot()

bool GERBER_PLOTTER::EndPlot ( )
overridevirtual

Implements PLOTTER.

Definition at line 317 of file GERBER_plotter.cpp.

318 {
319  char line[1024];
320  wxString msg;
321 
322  wxASSERT( m_outputFile );
323 
324  /* Outfile is actually a temporary file i.e. workFile */
325  fputs( "M02*\n", m_outputFile );
326  fflush( m_outputFile );
327 
328  fclose( workFile );
329  workFile = wxFopen( m_workFilename, wxT( "rt" ));
330  wxASSERT( workFile );
332 
333  // Placement of apertures in RS274X
334  while( fgets( line, 1024, workFile ) )
335  {
336  fputs( line, m_outputFile );
337 
338  char* substr = strtok( line, "\n\r" );
339 
340  if( substr && strcmp( substr, "G04 APERTURE LIST*" ) == 0 )
341  {
342  // Add aperture list macro:
346  {
347  fputs( "G04 Aperture macros list*\n", m_outputFile );
348 
351 
354 
357 
360 
362  {
367  }
368 
370  {
371  // aperture sizes are in inch or mm, regardless the
372  // coordinates format
373  double fscale = 0.0001 * m_plotScale / m_IUsPerDecimil; // inches
374 
375  if(! m_gerberUnitInch )
376  fscale *= 25.4; // size in mm
377 
379  }
380 
381  fputs( "G04 Aperture macros list end*\n", m_outputFile );
382  }
383 
385  fputs( "G04 APERTURE END LIST*\n", m_outputFile );
386  }
387  }
388 
389  fclose( workFile );
390  fclose( finalFile );
391  ::wxRemoveFile( m_workFilename );
392  m_outputFile = nullptr;
393 
394  return true;
395 }
#define APER_MACRO_ROT_RECT_HEADER
void writeApertureList()
Generate the table of D codes.
bool m_hasApertureChamferedRect
FILE * m_outputFile
Output file.
Definition: plotter.h:590
APER_MACRO_FREEPOLY_LIST m_am_freepoly_list
double m_IUsPerDecimil
Definition: plotter.h:579
#define APER_MACRO_OUTLINE6P_HEADER
bool m_hasApertureOutline4P
bool m_hasApertureRoundRect
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:573
#define APER_MACRO_SHAPE_OVAL_HEADER
#define APER_MACRO_OUTLINE5P_HEADER
#define APER_MACRO_ROUNDRECT_HEADER
#define APER_MACRO_OUTLINE7P_HEADER
#define APER_MACRO_OUTLINE4P_HEADER
#define APER_MACRO_OUTLINE8P_HEADER
wxString m_workFilename
void Format(FILE *aOutput, double aIu2GbrMacroUnit)
print the aperture macro list to aOutput

References APER_MACRO_FREEPOLY_LIST::AmCount(), APER_MACRO_OUTLINE4P_HEADER, APER_MACRO_OUTLINE5P_HEADER, APER_MACRO_OUTLINE6P_HEADER, APER_MACRO_OUTLINE7P_HEADER, APER_MACRO_OUTLINE8P_HEADER, APER_MACRO_ROT_RECT_HEADER, APER_MACRO_ROUNDRECT_HEADER, APER_MACRO_SHAPE_OVAL_HEADER, finalFile, APER_MACRO_FREEPOLY_LIST::Format(), m_am_freepoly_list, m_gerberUnitInch, m_hasApertureChamferedRect, m_hasApertureOutline4P, m_hasApertureRotOval, m_hasApertureRotRect, m_hasApertureRoundRect, PLOTTER::m_IUsPerDecimil, PLOTTER::m_outputFile, PLOTTER::m_plotScale, m_workFilename, workFile, and writeApertureList().

Referenced by GERBER_WRITER::createDrillFile(), and PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ FilledCircle()

void GERBER_PLOTTER::FilledCircle ( const wxPoint &  pos,
int  diametre,
OUTLINE_MODE  tracemode,
void *  aData 
)
overridevirtual

Reimplemented from PLOTTER.

Definition at line 1217 of file GERBER_plotter.cpp.

1219 {
1220  // A filled circle is a graphic item, not a pad.
1221  // So it is drawn, not flashed.
1222  GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
1223 
1224  if( gbr_metadata )
1225  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1226 
1227  if( tracemode == FILLED )
1228  {
1229  // Draw a circle of diameter = diameter/2 with a line thickness = radius,
1230  // To create a filled circle
1231  SetCurrentLineWidth( diametre/2, gbr_metadata );
1232  Circle( pos, diametre/2, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
1233  }
1234  else
1235  {
1237  Circle( pos, diametre, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
1238  }
1239 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
static const int DO_NOT_SET_LINE_WIDTH
Definition: plotter.h:125

References Circle(), PLOTTER::DO_NOT_SET_LINE_WIDTH, FILLED, formatNetAttribute(), GBR_METADATA::m_NetlistMetadata, NO_FILL, SetCurrentLineWidth(), and PLOTTER::USE_DEFAULT_LINE_WIDTH.

◆ FinishTo()

◆ FlashPadChamferRoundRect()

void GERBER_PLOTTER::FlashPadChamferRoundRect ( const wxPoint &  aShapePos,
const wxSize &  aPadSize,
int  aCornerRadius,
double  aChamferRatio,
int  aChamferPositions,
double  aPadOrient,
OUTLINE_MODE  aPlotMode,
void *  aData 
)

Flash a chamfered round rect pad.

Parameters
aShapePosis the position of the pad shape.
aPadSizeis the size of the rectangle.
aCornerRadiusis the radius of rounded corners.
aChamferRatiois the chamfer value (ratio < 0.5 between smallest size and chamfer).
aChamferPositionsis the identifier of the corners to chamfer: 0 = no chamfer 1 = TOP_LEFT 2 = TOP_RIGHT 4 = BOTTOM_LEFT 8 = BOTTOM_RIGHT
aPadOrientis the rotation in 0.1 degrees of the shape.
aPlotModeis the drawing mode, FILLED or SKETCH.
aDatais the a reference to Gerber attributes descr.

Definition at line 1708 of file GERBER_plotter.cpp.

1713 {
1714  GBR_METADATA gbr_metadata;
1715 
1716  if( aData )
1717  gbr_metadata = *static_cast<GBR_METADATA*>( aData );
1718 
1719  DPOINT pos_dev = userToDeviceCoordinates( aShapePos );
1720 
1721  SHAPE_POLY_SET outline;
1722  // polygon corners list
1723  std::vector<wxPoint> cornerList;
1724 
1725  bool hasRoundedCorner = aCornerRadius != 0 && aChamferPositions != 15;
1726 
1727 #ifdef GBR_USE_MACROS_FOR_CHAMFERED_RECT
1728  // Sketch mode or round rect shape or Apert Macros disabled
1729  if( aPlotMode != FILLED || hasRoundedCorner || m_gerberDisableApertMacros )
1730 #endif
1731  {
1732  TransformRoundChamferedRectToPolygon( outline, aShapePos, aPadSize, aPadOrient,
1733  aCornerRadius, aChamferRatio, aChamferPositions, 0,
1735 
1736  // Build the corner list
1737  const SHAPE_LINE_CHAIN& corners = outline.Outline(0);
1738 
1739  for( int ii = 0; ii < corners.PointCount(); ii++ )
1740  cornerList.emplace_back( corners.CPoint( ii ).x, corners.CPoint( ii ).y );
1741 
1742  // Close the polygon
1743  cornerList.push_back( cornerList[0] );
1744 
1745  if( aPlotMode == SKETCH )
1746  PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &gbr_metadata );
1747  else
1748  {
1749 #ifdef GBR_USE_MACROS_FOR_CHAMFERED_ROUND_RECT
1751  {
1752  PlotGerberRegion( cornerList, &gbr_metadata );
1753  }
1754  else
1755  {
1756  // An AM will be created. the shape must be in position 0,0 and orientation 0
1757  // to be able to reuse the same AM for pads having the same shape
1758  for( size_t ii = 0; ii < cornerList.size(); ii++ )
1759  {
1760  cornerList[ii] -= aShapePos;
1761  RotatePoint( &cornerList[ii], -aPadOrient );
1762  }
1763 
1764  selectAperture( cornerList, aPadOrient/10.0,
1765  APERTURE::AM_FREE_POLYGON, gbr_metadata.GetApertureAttrib() );
1766  formatNetAttribute( &gbr_metadata.m_NetlistMetadata );
1767 
1768  emitDcode( pos_dev, 3 );
1769  }
1770 #else
1771  PlotGerberRegion( cornerList, &gbr_metadata );
1772 #endif
1773  }
1774 
1775  return;
1776  }
1777 
1778  // Build the chamfered polygon (4 to 8 corners )
1779  TransformRoundChamferedRectToPolygon( outline, wxPoint( 0, 0 ), aPadSize, 0.0, 0,
1780  aChamferRatio, aChamferPositions, 0,
1782 
1783  // Build the corner list
1784  const SHAPE_LINE_CHAIN& corners = outline.Outline(0);
1785 
1786  // Generate the polygon (4 to 8 corners )
1787  for( int ii = 0; ii < corners.PointCount(); ii++ )
1788  cornerList.emplace_back( corners.CPoint( ii ).x, corners.CPoint( ii ).y );
1789 
1790  switch( cornerList.size() )
1791  {
1792  case 4:
1793  m_hasApertureOutline4P = true;
1794  selectAperture( cornerList, aPadOrient/10.0,
1796  break;
1797 
1798  case 5:
1800  selectAperture( cornerList, aPadOrient/10.0,
1802  break;
1803 
1804  case 6:
1806  selectAperture( cornerList, aPadOrient/10.0,
1808  break;
1809 
1810  case 7:
1812  selectAperture( cornerList, aPadOrient/10.0,
1814  break;
1815 
1816  case 8:
1818  selectAperture( cornerList, aPadOrient/10.0,
1820  break;
1821 
1822  default:
1823  wxLogMessage( wxT( "FlashPadChamferRoundRect(): Unexpected number of corners (%d)" ),
1824  (int)cornerList.size() );
1825  break;
1826  }
1827 
1828  formatNetAttribute( &gbr_metadata.m_NetlistMetadata );
1829 
1830  emitDcode( pos_dev, 3 );
1831 }
bool m_hasApertureChamferedRect
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
int PointCount() const
Return the number of points (vertices) in this line chain.
bool m_hasApertureOutline4P
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
virtual void PlotPoly(const std::vector< wxPoint > &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.
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int GetPlotterArcHighDef() const
Definition: plotter.h:228
void PlotGerberRegion(const std::vector< wxPoint > &aCornerList, void *aData=nullptr)
Plot a Gerber region: similar to PlotPoly but plot only filled polygon, and add the TA....
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
bool m_gerberDisableApertMacros

References APERTURE::AM_FREE_POLYGON, APERTURE::APER_MACRO_OUTLINE4P, APERTURE::APER_MACRO_OUTLINE5P, APERTURE::APER_MACRO_OUTLINE6P, APERTURE::APER_MACRO_OUTLINE7P, APERTURE::APER_MACRO_OUTLINE8P, SHAPE_LINE_CHAIN::CPoint(), emitDcode(), ERROR_INSIDE, FILLED, formatNetAttribute(), GBR_METADATA::GetApertureAttrib(), PLOTTER::GetCurrentLineWidth(), PLOTTER::GetPlotterArcHighDef(), m_gerberDisableApertMacros, m_hasApertureChamferedRect, m_hasApertureOutline4P, GBR_METADATA::m_NetlistMetadata, NO_FILL, SHAPE_POLY_SET::Outline(), PlotGerberRegion(), PlotPoly(), SHAPE_LINE_CHAIN::PointCount(), RotatePoint(), selectAperture(), SKETCH, TransformRoundChamferedRectToPolygon(), PLOTTER::userToDeviceCoordinates(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ FlashPadCircle()

void GERBER_PLOTTER::FlashPadCircle ( const wxPoint &  pos,
int  diametre,
OUTLINE_MODE  trace_mode,
void *  aData 
)
overridevirtual

Filled circular flashes are stored as apertures.

Implements PLOTTER.

Definition at line 1242 of file GERBER_plotter.cpp.

1244 {
1245  wxSize size( diametre, diametre );
1246  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1247 
1248  if( trace_mode == SKETCH )
1249  {
1250  if( gbr_metadata )
1251  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1252 
1254 
1255  Circle( pos, diametre, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
1256  }
1257  else
1258  {
1259  DPOINT pos_dev = userToDeviceCoordinates( pos );
1260 
1261  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1262  selectAperture( size, 0, 0.0, APERTURE::AT_CIRCLE, aperture_attrib );
1263 
1264  if( gbr_metadata )
1265  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1266 
1267  emitDcode( pos_dev, 3 );
1268  }
1269 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
static const int DO_NOT_SET_LINE_WIDTH
Definition: plotter.h:125

References APERTURE::AT_CIRCLE, Circle(), PLOTTER::DO_NOT_SET_LINE_WIDTH, emitDcode(), formatNetAttribute(), GBR_METADATA::GetApertureAttrib(), GBR_METADATA::m_NetlistMetadata, NO_FILL, selectAperture(), SetCurrentLineWidth(), SKETCH, PLOTTER::USE_DEFAULT_LINE_WIDTH, and PLOTTER::userToDeviceCoordinates().

Referenced by GERBER_WRITER::createDrillFile(), and PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ FlashPadCustom()

void GERBER_PLOTTER::FlashPadCustom ( const wxPoint &  aPadPos,
const wxSize &  aSize,
double  aPadOrient,
SHAPE_POLY_SET aPolygons,
OUTLINE_MODE  aTraceMode,
void *  aData 
)
overridevirtual
Parameters
aPadPosPosition of the shape.
aSizeis the size of round reference pad.
aPadOrientis the pad rotation, used only with aperture macros (Gerber plotter).
aPolygonsthe shape as polygon set.
aTraceModeis the drawing mode, FILLED or SKETCH.
aDataan auxiliary info (mainly for gerber format attributes).

Implements PLOTTER.

Definition at line 1641 of file GERBER_plotter.cpp.

1645 {
1646  // A Pad custom is plotted as polygon (a region in Gerber language).
1647  GBR_METADATA gbr_metadata;
1648 
1649  if( aData )
1650  gbr_metadata = *static_cast<GBR_METADATA*>( aData );
1651 
1652  SHAPE_POLY_SET polyshape = *aPolygons;
1653 
1654  if( aTraceMode != FILLED )
1655  {
1656  SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, &gbr_metadata );
1657  }
1658 
1659  std::vector< wxPoint > cornerList;
1660 
1661  for( int cnt = 0; cnt < polyshape.OutlineCount(); ++cnt )
1662  {
1663  SHAPE_LINE_CHAIN& poly = polyshape.Outline( cnt );
1664 
1665  cornerList.clear();
1666 
1667  for( int ii = 0; ii < poly.PointCount(); ++ii )
1668  cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
1669 
1670  // Close polygon
1671  cornerList.push_back( cornerList[0] );
1672 
1673  if( aTraceMode == SKETCH )
1674  {
1675  PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &gbr_metadata );
1676  }
1677  else
1678  {
1679 #ifdef GBR_USE_MACROS_FOR_CUSTOM_PAD
1681  || cornerList.size() > GBR_MACRO_FOR_CUSTOM_PAD_MAX_CORNER_COUNT )
1682  PlotGerberRegion( cornerList, &gbr_metadata );
1683  else
1684  {
1685  // An AM will be created. the shape must be in position 0,0 and orientation 0
1686  // to be able to reuse the same AM for pads having the same shape
1687  for( size_t ii = 0; ii < cornerList.size(); ii++ )
1688  {
1689  cornerList[ii] -= aPadPos;
1690  RotatePoint( &cornerList[ii], -aOrient );
1691  }
1692 
1693  DPOINT pos_dev = userToDeviceCoordinates( aPadPos );
1694  selectAperture( cornerList, aOrient/10.0,
1695  APERTURE::AM_FREE_POLYGON, gbr_metadata.GetApertureAttrib() );
1696  formatNetAttribute( &gbr_metadata.m_NetlistMetadata );
1697 
1698  emitDcode( pos_dev, 3 );
1699  }
1700 #else
1701  PlotGerberRegion( cornerList, &gbr_metadata );
1702 #endif
1703  }
1704  }
1705 }
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
virtual void PlotPoly(const std::vector< wxPoint > &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.
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
#define GBR_MACRO_FOR_CUSTOM_PAD_MAX_CORNER_COUNT
void PlotGerberRegion(const std::vector< wxPoint > &aCornerList, void *aData=nullptr)
Plot a Gerber region: similar to PlotPoly but plot only filled polygon, and add the TA....
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
bool m_gerberDisableApertMacros

References APERTURE::AM_FREE_POLYGON, SHAPE_LINE_CHAIN::CPoint(), emitDcode(), FILLED, formatNetAttribute(), GBR_MACRO_FOR_CUSTOM_PAD_MAX_CORNER_COUNT, GBR_METADATA::GetApertureAttrib(), PLOTTER::GetCurrentLineWidth(), m_gerberDisableApertMacros, GBR_METADATA::m_NetlistMetadata, NO_FILL, SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), PlotGerberRegion(), PlotPoly(), SHAPE_LINE_CHAIN::PointCount(), RotatePoint(), selectAperture(), SetCurrentLineWidth(), SKETCH, PLOTTER::USE_DEFAULT_LINE_WIDTH, PLOTTER::userToDeviceCoordinates(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ FlashPadOval()

void GERBER_PLOTTER::FlashPadOval ( const wxPoint &  aPadPos,
const wxSize &  aSize,
double  aPadOrient,
OUTLINE_MODE  aTraceMode,
void *  aData 
)
overridevirtual
Parameters
aPadPosPosition of the shape (center of the rectangle.
aSizeis the size of oblong shape.
aPadOrientThe rotation of the shape.
aTraceModeis the drawing mode, FILLED or SKETCH.
aDataan auxiliary info (mainly for gerber format attributes).

Implements PLOTTER.

Definition at line 1272 of file GERBER_plotter.cpp.

1274 {
1275  wxASSERT( m_outputFile );
1276  wxSize size( aSize );
1277  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1278 
1279  // Flash a vertical or horizontal shape (this is a basic aperture).
1280  if( ( orient == 0 || orient == 900 || orient == 1800 || orient == 2700 )
1281  && trace_mode == FILLED )
1282  {
1283  if( orient == 900 || orient == 2700 ) /* orientation turned 90 deg. */
1284  std::swap( size.x, size.y );
1285 
1286  DPOINT pos_dev = userToDeviceCoordinates( pos );
1287  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1288  selectAperture( size, 0, 0.0, APERTURE::AT_OVAL, aperture_attrib );
1289 
1290  if( gbr_metadata )
1291  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1292 
1293  emitDcode( pos_dev, 3 );
1294  }
1295  else // Plot pad as region.
1296  // Only regions and flashed items accept a object attribute TO.P for the pin name
1297  {
1298  if( trace_mode == FILLED )
1299  {
1300  #ifdef GBR_USE_MACROS_FOR_ROTATED_OVAL
1302  #endif
1303  {
1304  m_hasApertureRotOval = true;
1305  // We are using a aperture macro that expect size.y < size.x
1306  // i.e draw a horizontal line for rotation = 0.0
1307  // size.x = length, size.y = width
1308  if( size.x < size.y )
1309  {
1310  std::swap( size.x, size.y );
1311  orient += 900;
1312 
1313  if( orient > 1800 )
1314  orient -= 1800;
1315  }
1316 
1317  DPOINT pos_dev = userToDeviceCoordinates( pos );
1318  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1319  selectAperture( size, 0, orient/10.0, APERTURE::AM_ROTATED_OVAL, aperture_attrib );
1320 
1321  if( gbr_metadata )
1322  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1323 
1324  emitDcode( pos_dev, 3 );
1325  return;
1326  }
1327  // Draw the oval as round rect pad with a radius = 50% min size)
1328  // In gerber file, it will be drawn as a region with arcs, and can be
1329  // detected as pads (similar to a flashed pad)
1330  FlashPadRoundRect( pos, aSize, std::min( aSize.x, aSize.y ) / 2,
1331  orient, FILLED, aData );
1332  }
1333  else // Non filled shape: plot outlines:
1334  {
1335  if( size.x > size.y )
1336  {
1337  std::swap( size.x, size.y );
1338 
1339  if( orient < 2700 )
1340  orient += 900;
1341  else
1342  orient -= 2700;
1343  }
1344 
1345  sketchOval( pos, size, orient, -1 );
1346  }
1347  }
1348 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
FILE * m_outputFile
Output file.
Definition: plotter.h:590
virtual void FlashPadRoundRect(const wxPoint &aPadPos, const wxSize &aSize, int aCornerRadius, double aOrient, OUTLINE_MODE aTraceMode, void *aData) override
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
bool m_gerberDisableApertMacros
void sketchOval(const wxPoint &pos, const wxSize &size, double orient, int width)
Definition: plotter.cpp:475

References APERTURE::AM_ROTATED_OVAL, APERTURE::AT_OVAL, emitDcode(), FILLED, FlashPadRoundRect(), formatNetAttribute(), GBR_METADATA::GetApertureAttrib(), m_gerberDisableApertMacros, m_hasApertureRotOval, GBR_METADATA::m_NetlistMetadata, PLOTTER::m_outputFile, selectAperture(), PLOTTER::sketchOval(), and PLOTTER::userToDeviceCoordinates().

Referenced by GERBER_WRITER::createDrillFile().

◆ FlashPadRect()

void GERBER_PLOTTER::FlashPadRect ( const wxPoint &  aPadPos,
const wxSize &  aSize,
double  aPadOrient,
OUTLINE_MODE  aTraceMode,
void *  aData 
)
overridevirtual
Parameters
aPadPosPosition of the shape (center of the rectangle).
aSizeis the size of rounded rect.
aPadOrientThe rotation of the shape.
aTraceModeis the drawing mode, FILLED or SKETCH.
aDataan auxiliary info (mainly for gerber format attributes).

Implements PLOTTER.

Definition at line 1351 of file GERBER_plotter.cpp.

1354 {
1355  wxASSERT( m_outputFile );
1356  wxSize size( aSize );
1357  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1358 
1359  // Plot as an aperture flash
1360  switch( int( orient ) )
1361  {
1362  case 900:
1363  case 2700: // rotation of 90 degrees or 270 swaps sizes
1364  std::swap( size.x, size.y );
1366 
1367  case 0:
1368  case 1800:
1369  if( trace_mode == SKETCH )
1370  {
1371  if( gbr_metadata )
1372  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1373 
1375  Rect( wxPoint( pos.x - ( size.x / 2 ), pos.y - ( size.y / 2 ) ),
1376  wxPoint( pos.x + ( size.x / 2 ), pos.y + ( size.y / 2 ) ),
1378  }
1379  else
1380  {
1381  DPOINT pos_dev = userToDeviceCoordinates( pos );
1382  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1383  selectAperture( size, 0, 0.0, APERTURE::AT_RECT, aperture_attrib );
1384 
1385  if( gbr_metadata )
1386  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1387 
1388  emitDcode( pos_dev, 3 );
1389  }
1390  break;
1391 
1392  default:
1393  #ifdef GBR_USE_MACROS_FOR_ROTATED_RECT
1394  if( trace_mode != SKETCH && !m_gerberDisableApertMacros )
1395  {
1396  m_hasApertureRotRect = true;
1397  DPOINT pos_dev = userToDeviceCoordinates( pos );
1398  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1399  selectAperture( size, 0, orient/10.0, APERTURE::AM_ROT_RECT, aperture_attrib );
1400 
1401  if( gbr_metadata )
1402  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1403 
1404  emitDcode( pos_dev, 3 );
1405 
1406  break;
1407  }
1408  #endif
1409  {
1410  // plot pad shape as Gerber region
1411  wxPoint coord[4];
1412  // coord[0] is assumed the lower left
1413  // coord[1] is assumed the upper left
1414  // coord[2] is assumed the upper right
1415  // coord[3] is assumed the lower right
1416 
1417  coord[0].x = -size.x/2; // lower left
1418  coord[0].y = size.y/2;
1419  coord[1].x = -size.x/2; // upper left
1420  coord[1].y = -size.y/2;
1421  coord[2].x = size.x/2; // upper right
1422  coord[2].y = -size.y/2;
1423  coord[3].x = size.x/2; // lower right
1424  coord[3].y = size.y/2;
1425 
1426  FlashPadTrapez( pos, coord, orient, trace_mode, aData );
1427  }
1428  break;
1429  }
1430 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
virtual void FlashPadTrapez(const wxPoint &aPadPos, const wxPoint *aCorners, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData) override
Flash a trapezoidal pad.
FILE * m_outputFile
Output file.
Definition: plotter.h:590
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
bool m_gerberDisableApertMacros

References APERTURE::AM_ROT_RECT, APERTURE::AT_RECT, emitDcode(), FlashPadTrapez(), formatNetAttribute(), GBR_METADATA::GetApertureAttrib(), PLOTTER::GetCurrentLineWidth(), KI_FALLTHROUGH, m_gerberDisableApertMacros, m_hasApertureRotRect, GBR_METADATA::m_NetlistMetadata, PLOTTER::m_outputFile, NO_FILL, Rect(), selectAperture(), SetCurrentLineWidth(), SKETCH, PLOTTER::USE_DEFAULT_LINE_WIDTH, and PLOTTER::userToDeviceCoordinates().

◆ FlashPadRoundRect()

void GERBER_PLOTTER::FlashPadRoundRect ( const wxPoint &  aPadPos,
const wxSize &  aSize,
int  aCornerRadius,
double  aOrient,
OUTLINE_MODE  aTraceMode,
void *  aData 
)
overridevirtual
Parameters
aPadPosPosition of the shape (center of the rectangle.
aSizeis the size of rounded rect.
aCornerRadiusRadius of the rounded corners.
aOrientThe rotation of the shape.
aTraceModeis the drawing mode, FILLED or SKETCH.
aDataan auxiliary info (mainly for gerber format attributes).

Implements PLOTTER.

Definition at line 1432 of file GERBER_plotter.cpp.

1436 {
1437  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1438 
1439  if( aTraceMode != FILLED )
1440  {
1441  SHAPE_POLY_SET outline;
1442  TransformRoundChamferedRectToPolygon( outline, aPadPos, aSize, aOrient, aCornerRadius,
1443  0.0, 0, 0, GetPlotterArcHighDef(), ERROR_INSIDE );
1444 
1445  SetCurrentLineWidth( USE_DEFAULT_LINE_WIDTH, &gbr_metadata );
1446 
1447  std::vector< wxPoint > cornerList;
1448  // TransformRoundRectToPolygon creates only one convex polygon
1449  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
1450  cornerList.reserve( poly.PointCount() + 1 );
1451 
1452  for( int ii = 0; ii < poly.PointCount(); ++ii )
1453  cornerList.emplace_back( poly.CPoint( ii ).x, poly.CPoint( ii ).y );
1454 
1455  // Close polygon
1456  cornerList.push_back( cornerList[0] );
1457 
1458  // plot outlines
1459  PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), gbr_metadata );
1460  }
1461  else
1462  {
1463  #ifdef GBR_USE_MACROS_FOR_ROUNDRECT
1465  #endif
1466  {
1467  m_hasApertureRoundRect = true;
1468 
1469  DPOINT pos_dev = userToDeviceCoordinates( aPadPos );
1470  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1471  selectAperture( aSize, aCornerRadius, aOrient/10.0,
1472  APERTURE::AM_ROUND_RECT, aperture_attrib );
1473 
1474  if( gbr_metadata )
1475  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1476 
1477  emitDcode( pos_dev, 3 );
1478  return;
1479  }
1480 
1481  // A Pad RoundRect is plotted as a Gerber region.
1482  // Initialize region metadata:
1483  bool clearTA_AperFunction = false; // true if a TA.AperFunction is used
1484 
1485  if( gbr_metadata )
1486  {
1487  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1488  std::string attrib = gbr_metadata->m_ApertureMetadata.FormatAttribute( !m_useX2format );
1489 
1490  if( !attrib.empty() )
1491  {
1492  fputs( attrib.c_str(), m_outputFile );
1493  clearTA_AperFunction = true;
1494  }
1495  }
1496 
1497  // Plot the region using arcs in corners.
1498  plotRoundRectAsRegion( aPadPos, aSize, aCornerRadius, aOrient );
1499 
1500  // Clear the TA attribute, to avoid the next item to inherit it:
1501  if( clearTA_AperFunction )
1502  {
1503  if( m_useX2format )
1504  fputs( "%TD.AperFunction*%\n", m_outputFile );
1505  else
1506  fputs( "G04 #@! TD.AperFunction*\n", m_outputFile );
1507  }
1508  }
1509 }
void plotRoundRectAsRegion(const wxPoint &aRectCenter, const wxSize &aSize, int aCornerRadius, double aOrient)
Plot a round rect (a round rect shape in fact) as a Gerber region using lines and arcs for corners.
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
FILE * m_outputFile
Output file.
Definition: plotter.h:590
int PointCount() const
Return the number of points (vertices) in this line chain.
void TransformRoundChamferedRectToPolygon(SHAPE_POLY_SET &aCornerBuffer, const wxPoint &aPosition, const wxSize &aSize, double aRotation, int aCornerRadius, double aChamferRatio, int aChamferCorners, int aInflate, int aError, ERROR_LOC aErrorLoc)
Convert a rectangle with rounded corners and/or chamfered corners to a polygon.
bool m_hasApertureRoundRect
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
virtual void PlotPoly(const std::vector< wxPoint > &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.
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
static std::string FormatAttribute(GBR_APERTURE_ATTRIB aAttribute, bool aUseX1StructuredComment)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
int GetPlotterArcHighDef() const
Definition: plotter.h:228
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
bool m_gerberDisableApertMacros
GBR_APERTURE_METADATA m_ApertureMetadata
An item to handle aperture attribute.
Definition: gbr_metadata.h:257

References APERTURE::AM_ROUND_RECT, SHAPE_LINE_CHAIN::CPoint(), emitDcode(), ERROR_INSIDE, FILLED, GBR_APERTURE_METADATA::FormatAttribute(), formatNetAttribute(), GBR_METADATA::GetApertureAttrib(), PLOTTER::GetCurrentLineWidth(), PLOTTER::GetPlotterArcHighDef(), GBR_METADATA::m_ApertureMetadata, m_gerberDisableApertMacros, m_hasApertureRoundRect, GBR_METADATA::m_NetlistMetadata, PLOTTER::m_outputFile, m_useX2format, NO_FILL, SHAPE_POLY_SET::Outline(), PlotPoly(), plotRoundRectAsRegion(), SHAPE_LINE_CHAIN::PointCount(), selectAperture(), SetCurrentLineWidth(), TransformRoundChamferedRectToPolygon(), PLOTTER::USE_DEFAULT_LINE_WIDTH, PLOTTER::userToDeviceCoordinates(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by FlashPadOval().

◆ FlashPadTrapez()

void GERBER_PLOTTER::FlashPadTrapez ( const wxPoint &  aPadPos,
const wxPoint *  aCorners,
double  aPadOrient,
OUTLINE_MODE  aTraceMode,
void *  aData 
)
overridevirtual

Flash a trapezoidal pad.

Parameters
aPadPosis the the position of the shape.
aCornersis the list of 4 corners positions, relative to the shape position, pad orientation 0.
aPadOrientis the rotation of the shape.
aTraceModeis the drawing mode, FILLED or SKETCH.
aDataan auxiliary info (mainly for gerber format attributes).

Implements PLOTTER.

Definition at line 1834 of file GERBER_plotter.cpp.

1837 {
1838  // polygon corners list
1839  std::vector<wxPoint> cornerList = { aCorners[0], aCorners[1], aCorners[2], aCorners[3] };
1840 
1841  // Draw the polygon and fill the interior as required
1842  for( unsigned ii = 0; ii < 4; ii++ )
1843  {
1844  RotatePoint( &cornerList[ii], aPadOrient );
1845  cornerList[ii] += aPadPos;
1846  }
1847 
1848  // Close the polygon
1849  cornerList.push_back( cornerList[0] );
1850  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1851 
1852  GBR_METADATA metadata;
1853 
1854  if( gbr_metadata )
1855  metadata = *gbr_metadata;
1856 
1857  if( aTrace_Mode == SKETCH )
1858  {
1859  PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &metadata );
1860  return;
1861  }
1862 
1863  // Plot a filled polygon:
1864  #ifdef GBR_USE_MACROS_FOR_TRAPEZOID
1866  #endif
1867  {
1868  m_hasApertureOutline4P = true;
1869  DPOINT pos_dev = userToDeviceCoordinates( aPadPos );
1870  // polygon corners list
1871  std::vector<wxPoint> corners = { aCorners[0], aCorners[1], aCorners[2], aCorners[3] };
1872  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1873  selectAperture( corners, aPadOrient/10.0, APERTURE::APER_MACRO_OUTLINE4P, aperture_attrib );
1874 
1875  if( gbr_metadata )
1876  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1877 
1878  emitDcode( pos_dev, 3 );
1879  return;
1880  }
1881 
1882  PlotGerberRegion( cornerList, &metadata );
1883 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
bool m_hasApertureOutline4P
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
virtual void PlotPoly(const std::vector< wxPoint > &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.
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
void PlotGerberRegion(const std::vector< wxPoint > &aCornerList, void *aData=nullptr)
Plot a Gerber region: similar to PlotPoly but plot only filled polygon, and add the TA....
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
bool m_gerberDisableApertMacros

References APERTURE::APER_MACRO_OUTLINE4P, emitDcode(), formatNetAttribute(), GBR_METADATA::GetApertureAttrib(), PLOTTER::GetCurrentLineWidth(), m_gerberDisableApertMacros, m_hasApertureOutline4P, GBR_METADATA::m_NetlistMetadata, NO_FILL, PlotGerberRegion(), PlotPoly(), RotatePoint(), selectAperture(), SKETCH, and PLOTTER::userToDeviceCoordinates().

Referenced by FlashPadRect().

◆ FlashRegularPolygon()

void GERBER_PLOTTER::FlashRegularPolygon ( const wxPoint &  aShapePos,
int  aDiameter,
int  aCornerCount,
double  aOrient,
OUTLINE_MODE  aTraceMode,
void *  aData 
)
overridevirtual

Flash a regular polygon.

Useful only in Gerber files to flash a regular polygon.

Parameters
aShapePosis the center of the circle containing the polygon.
aRadiusis the radius of the circle containing the polygon.
aCornerCountis the number of vertices.
aOrientis the polygon rotation in degrees.
aDatais a auxiliary parameter used (if needed) to handle extra info specific to the plotter.

Implements PLOTTER.

Definition at line 1886 of file GERBER_plotter.cpp.

1889 {
1890  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1891 
1892  GBR_METADATA metadata;
1893 
1894  if( gbr_metadata )
1895  metadata = *gbr_metadata;
1896 
1897  if( aTraceMode == SKETCH )
1898  {
1899  // Build the polygon:
1900  std::vector< wxPoint > cornerList;
1901 
1902  double angle_delta = 3600.0 / aCornerCount; // in 0.1 degree
1903 
1904  for( int ii = 0; ii < aCornerCount; ii++ )
1905  {
1906  double rot = aOrient + (angle_delta*ii);
1907  wxPoint vertice( aDiameter/2, 0 );
1908  RotatePoint( &vertice, rot );
1909  vertice += aShapePos;
1910  cornerList.push_back( vertice );
1911  }
1912 
1913  cornerList.push_back( cornerList[0] ); // Close the shape
1914 
1915  PlotPoly( cornerList, FILL_T::NO_FILL, GetCurrentLineWidth(), &gbr_metadata );
1916  }
1917  else
1918  {
1919  DPOINT pos_dev = userToDeviceCoordinates( aShapePos );
1920 
1921  int aperture_attrib = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
1922 
1923  APERTURE::APERTURE_TYPE apert_type =
1925  selectAperture( aDiameter, aOrient, apert_type, aperture_attrib );
1926 
1927  if( gbr_metadata )
1928  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1929 
1930  emitDcode( pos_dev, 3 );
1931  }
1932 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
virtual void PlotPoly(const std::vector< wxPoint > &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.
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262

References APERTURE::AT_REGULAR_POLY3, emitDcode(), formatNetAttribute(), GBR_METADATA::GetApertureAttrib(), PLOTTER::GetCurrentLineWidth(), GBR_METADATA::m_NetlistMetadata, NO_FILL, PlotPoly(), RotatePoint(), selectAperture(), SKETCH, and PLOTTER::userToDeviceCoordinates().

Referenced by PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ formatNetAttribute()

void GERBER_PLOTTER::formatNetAttribute ( GBR_NETLIST_METADATA aData)
protected

Print a Gerber net attribute object record.

In a gerber file, a net attribute is owned by a graphic object formatNetAttribute must be called before creating the object. The generated string depends on the type of netlist info.

Parameters
aDatacontains the data to format.

Definition at line 203 of file GERBER_plotter.cpp.

204 {
205  // print a Gerber net attribute record.
206  // it is added to the object attributes dictionary
207  // On file, only modified or new attributes are printed.
208  if( aData == nullptr )
209  return;
210 
211  if( !m_useNetAttributes )
212  return;
213 
214  bool useX1StructuredComment = !m_useX2format;
215 
216  bool clearDict;
217  std::string short_attribute_string;
218 
219  if( !FormatNetAttribute( short_attribute_string, m_objectAttributesDictionary,
220  aData, clearDict, useX1StructuredComment ) )
221  return;
222 
223  if( clearDict )
225 
226  if( !short_attribute_string.empty() )
227  fputs( short_attribute_string.c_str(), m_outputFile );
228 
229  if( m_useX2format && !aData->m_ExtraData.IsEmpty() )
230  {
231  std::string extra_data = TO_UTF8( aData->m_ExtraData );
232  fputs( extra_data.c_str(), m_outputFile );
233  }
234 }
void clearNetAttribute()
Clear a Gerber net attribute record (clear object attribute dictionary) and output the clear object a...
FILE * m_outputFile
Output file.
Definition: plotter.h:590
std::string m_objectAttributesDictionary
bool FormatNetAttribute(std::string &aPrintedText, std::string &aLastNetAttributes, const GBR_NETLIST_METADATA *aData, bool &aClearPreviousAttributes, bool aUseX1StructuredComment)
Generate the string to set a net attribute for a graphic object to print to a gerber file.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
wxString m_ExtraData
a string to print after TO object attributes, if not empty it is printed "as this"

References clearNetAttribute(), FormatNetAttribute(), GBR_NETLIST_METADATA::m_ExtraData, m_objectAttributesDictionary, PLOTTER::m_outputFile, m_useNetAttributes, m_useX2format, and TO_UTF8.

Referenced by FilledCircle(), FlashPadChamferRoundRect(), FlashPadCircle(), FlashPadCustom(), FlashPadOval(), FlashPadRect(), FlashPadRoundRect(), FlashPadTrapez(), FlashRegularPolygon(), PlotPoly(), Text(), ThickArc(), ThickCircle(), ThickRect(), and ThickSegment().

◆ GetColorMode()

◆ GetCurrentLineWidth()

◆ GetDashGapLenIU()

double PLOTTER::GetDashGapLenIU ( ) const
protectedinherited

Definition at line 145 of file plotter.cpp.

146 {
148 }
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
constexpr double dash_gap_len(double aLineWidth)
virtual DPOINT userToDeviceSize(const wxSize &size)
Modify size according to the plotter scale factors (wxSize version, returns a DPOINT).
Definition: plotter.cpp:117

References dash_gap_len(), PLOTTER::GetCurrentLineWidth(), and PLOTTER::userToDeviceSize().

Referenced by PS_PLOTTER::SetDash(), PDF_PLOTTER::SetDash(), and SVG_PLOTTER::setSVGPlotStyle().

◆ GetDashMarkLenIU()

double PLOTTER::GetDashMarkLenIU ( ) const
protectedinherited

Definition at line 139 of file plotter.cpp.

140 {
142 }
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
virtual DPOINT userToDeviceSize(const wxSize &size)
Modify size according to the plotter scale factors (wxSize version, returns a DPOINT).
Definition: plotter.cpp:117
constexpr double dash_mark_len(double aLineWidth)

References dash_mark_len(), PLOTTER::GetCurrentLineWidth(), and PLOTTER::userToDeviceSize().

Referenced by PS_PLOTTER::SetDash(), PDF_PLOTTER::SetDash(), and SVG_PLOTTER::setSVGPlotStyle().

◆ GetDefaultFileExtension()

static wxString GERBER_PLOTTER::GetDefaultFileExtension ( )
inlinestatic

Definition at line 44 of file plotter_gerber.h.

45  {
46  return wxString( wxT( "gbr" ) );
47  }

Referenced by GetDefaultPlotExtension().

◆ GetDotMarkLenIU()

double PLOTTER::GetDotMarkLenIU ( ) const
protectedinherited

Definition at line 133 of file plotter.cpp.

134 {
136 }
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
constexpr double dot_mark_len(double aLineWidth)
Dashed and dotted line patterns.
virtual DPOINT userToDeviceSize(const wxSize &size)
Modify size according to the plotter scale factors (wxSize version, returns a DPOINT).
Definition: plotter.cpp:117

References dot_mark_len(), PLOTTER::GetCurrentLineWidth(), and PLOTTER::userToDeviceSize().

Referenced by PS_PLOTTER::SetDash(), PDF_PLOTTER::SetDash(), and SVG_PLOTTER::setSVGPlotStyle().

◆ GetIUsPerDecimil()

double PLOTTER::GetIUsPerDecimil ( ) const
inlineinherited

The IUs per decimil are an essential scaling factor when plotting; they are set and saved when establishing the viewport.

Here they can be get back again

Definition at line 225 of file plotter.h.

225 { return m_IUsPerDecimil; }
double m_IUsPerDecimil
Definition: plotter.h:579

References PLOTTER::m_IUsPerDecimil.

Referenced by PlotDrawingSheet().

◆ GetOrCreateAperture() [1/2]

int GERBER_PLOTTER::GetOrCreateAperture ( const wxSize &  aSize,
int  aRadius,
double  aRotDegree,
APERTURE::APERTURE_TYPE  aType,
int  aApertureAttribute 
)
Parameters
aSizeis the size of tool.
aRadiusis the radius used for some shapes tool (oval, roundrect macros).
aRotDegreeis the rotation of tool (primitives round, oval rect accept only 0.0).
aTypeis the type ( shape ) of tool.
aApertureAttributeis an aperture attribute of the tool (a tool can have only one attribute) 0 = no specific attribute.
Returns
an index to the aperture in aperture list which meets the size and type of tool if the aperture does not exist, it is created and entered in aperture list.

Definition at line 415 of file GERBER_plotter.cpp.

417 {
418  int last_D_code = 9;
419 
420  // Search an existing aperture
421  for( int idx = 0; idx < (int)m_apertures.size(); ++idx )
422  {
423  APERTURE* tool = &m_apertures[idx];
424  last_D_code = tool->m_DCode;
425 
426  if( (tool->m_Type == aType) && (tool->m_Size == aSize) &&
427  (tool->m_Radius == aRadius) && (tool->m_Rotation == aRotDegree) &&
428  (tool->m_ApertureAttribute == aApertureAttribute) )
429  return idx;
430  }
431 
432  // Allocate a new aperture
433  APERTURE new_tool;
434  new_tool.m_Size = aSize;
435  new_tool.m_Type = aType;
436  new_tool.m_Radius = aRadius;
437  new_tool.m_Rotation = aRotDegree;
438  new_tool.m_DCode = last_D_code + 1;
439  new_tool.m_ApertureAttribute = aApertureAttribute;
440 
441  m_apertures.push_back( new_tool );
442 
443  return m_apertures.size() - 1;
444 }
APERTURE_TYPE m_Type
std::vector< APERTURE > m_apertures

References APERTURE::m_ApertureAttribute, m_apertures, APERTURE::m_DCode, APERTURE::m_Radius, APERTURE::m_Rotation, APERTURE::m_Size, and APERTURE::m_Type.

Referenced by selectAperture().

◆ GetOrCreateAperture() [2/2]

int GERBER_PLOTTER::GetOrCreateAperture ( const std::vector< wxPoint > &  aCorners,
double  aRotDegree,
APERTURE::APERTURE_TYPE  aType,
int  aApertureAttribute 
)
Parameters
aCornersis the corner list.
aRotDegreeis the rotation of tool.
aTypeis the type ( shape ) of tool that can manage a list of corners (polygon).
aApertureAttributeis an aperture attribute of the tool (a tool can have only one attribute) 0 = no specific attribute.
Returns
an index to the aperture in aperture list which meets the data and type of tool if the aperture does not exist, it is created and entered in aperture list.

Definition at line 447 of file GERBER_plotter.cpp.

449 {
450  int last_D_code = 9;
451 
452  // For APERTURE::AM_FREE_POLYGON aperture macros, we need to create the macro
453  // on the fly, because due to the fact the vertex count is not a constant we
454  // cannot create a static definition.
455  if( APERTURE::AM_FREE_POLYGON == aType )
456  {
457  int idx = m_am_freepoly_list.FindAm( aCorners );
458 
459  if( idx < 0 )
460  m_am_freepoly_list.Append( aCorners );
461  }
462 
463  // Search an existing aperture
464  for( int idx = 0; idx < (int)m_apertures.size(); ++idx )
465  {
466  APERTURE* tool = &m_apertures[idx];
467 
468  last_D_code = tool->m_DCode;
469 
470  if( (tool->m_Type == aType) &&
471  (tool->m_Corners.size() == aCorners.size() ) &&
472  (tool->m_Rotation == aRotDegree) &&
473  (tool->m_ApertureAttribute == aApertureAttribute) )
474  {
475  // A candidate is found. the corner lists must be similar
476  bool is_same = polyCompare( tool->m_Corners, aCorners );
477 
478  if( is_same )
479  return idx;
480  }
481  }
482 
483  // Allocate a new aperture
484  APERTURE new_tool;
485 
486  new_tool.m_Corners = aCorners;
487  new_tool.m_Size = wxSize( 0, 0 ); // Not used
488  new_tool.m_Type = aType;
489  new_tool.m_Radius = 0; // Not used
490  new_tool.m_Rotation = aRotDegree;
491  new_tool.m_DCode = last_D_code + 1;
492  new_tool.m_ApertureAttribute = aApertureAttribute;
493 
494  m_apertures.push_back( new_tool );
495 
496  return m_apertures.size() - 1;
497 }
APERTURE_TYPE m_Type
static bool polyCompare(const std::vector< wxPoint > &aPolygon, const std::vector< wxPoint > &aTestPolygon)
APER_MACRO_FREEPOLY_LIST m_am_freepoly_list
void Append(const std::vector< wxPoint > &aPolygon)
append a new APER_MACRO_FREEPOLY containing the polygon aPolygon to the current list
std::vector< APERTURE > m_apertures
std::vector< wxPoint > m_Corners
int FindAm(const std::vector< wxPoint > &aPolygon) const

References APERTURE::AM_FREE_POLYGON, APER_MACRO_FREEPOLY_LIST::Append(), APER_MACRO_FREEPOLY_LIST::FindAm(), m_am_freepoly_list, APERTURE::m_ApertureAttribute, m_apertures, APERTURE::m_Corners, APERTURE::m_DCode, APERTURE::m_Radius, APERTURE::m_Rotation, APERTURE::m_Size, APERTURE::m_Type, and polyCompare().

◆ GetPlotterArcHighDef()

int PLOTTER::GetPlotterArcHighDef ( ) const
inlineinherited

◆ GetPlotterArcLowDef()

int PLOTTER::GetPlotterArcLowDef ( ) const
inlineinherited

Definition at line 227 of file plotter.h.

227 { return m_IUsPerDecimil * 8; }
double m_IUsPerDecimil
Definition: plotter.h:579

References PLOTTER::m_IUsPerDecimil.

◆ GetPlotterType()

virtual PLOT_FORMAT GERBER_PLOTTER::GetPlotterType ( ) const
inlineoverridevirtual

Returns the effective plot engine in use.

It's not very OO but for now is required since some things are only done with some output devices (like drill marks, emitted only for postscript

Implements PLOTTER.

Definition at line 39 of file plotter_gerber.h.

40  {
41  return PLOT_FORMAT::GERBER;
42  }

References GERBER.

◆ LineTo()

void PLOTTER::LineTo ( const wxPoint &  pos)
inlineinherited

Definition at line 268 of file plotter.h.

269  {
270  PenTo( pos, 'D' );
271  }
virtual void PenTo(const wxPoint &pos, char plume)=0
Moveto/lineto primitive, moves the 'pen' to the specified direction.

References PLOTTER::PenTo().

Referenced by PLOTTER::Arc(), PLOTTER::BezierCurve(), DXF_PLOTTER::FlashPadCustom(), DXF_PLOTTER::FlashPadRect(), DXF_PLOTTER::FlashPadRoundRect(), DXF_PLOTTER::FlashPadTrapez(), plotArc(), PlotPoly(), HPGL_PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), plotRoundRectAsRegion(), LIB_PIN::PlotSymbol(), and DXF_PLOTTER::Rect().

◆ Marker()

void PLOTTER::Marker ( const wxPoint &  position,
int  diametre,
unsigned  aShapeId 
)
inherited

Draw a pattern shape number aShapeId, to coord position.

Parameters
aPositionis the position of the marker.
aDiameteris the diameter of the marker.
aShapeIdis the index (used to generate forms characters).

Definition at line 332 of file plotter.cpp.

333 {
334  int radius = diametre / 2;
335 
336  /* Marker are composed by a series of 'parts' superimposed; not every
337  combination make sense, obviously. Since they are used in order I
338  tried to keep the uglier/more complex constructions at the end.
339  Also I avoided the |/ |\ -/ -\ construction because they're *very*
340  ugly... if needed they could be added anyway... I'd like to see
341  a board with more than 58 drilling/slotting tools!
342  If Visual C++ supported the 0b literals they would be optimally
343  and easily encoded as an integer array. We have to do with octal */
344  static const unsigned char marker_patterns[MARKER_COUNT] = {
345 
346  // Bit order: O Square Lozenge - | \ /
347  // First choice: simple shapes
348  0003, // X
349  0100, // O
350  0014, // +
351  0040, // Sq
352  0020, // Lz
353 
354  // Two simple shapes
355  0103, // X O
356  0017, // X +
357  0043, // X Sq
358  0023, // X Lz
359  0114, // O +
360  0140, // O Sq
361  0120, // O Lz
362  0054, // + Sq
363  0034, // + Lz
364  0060, // Sq Lz
365 
366  // Three simple shapes
367  0117, // X O +
368  0143, // X O Sq
369  0123, // X O Lz
370  0057, // X + Sq
371  0037, // X + Lz
372  0063, // X Sq Lz
373  0154, // O + Sq
374  0134, // O + Lz
375  0074, // + Sq Lz
376 
377  // Four simple shapes
378  0174, // O Sq Lz +
379  0163, // X O Sq Lz
380  0157, // X O Sq +
381  0137, // X O Lz +
382  0077, // X Sq Lz +
383 
384  // This draws *everything *
385  0177, // X O Sq Lz +
386 
387  // Here we use the single bars... so the cross is forbidden
388  0110, // O -
389  0104, // O |
390  0101, // O /
391  0050, // Sq -
392  0044, // Sq |
393  0041, // Sq /
394  0030, // Lz -
395  0024, // Lz |
396  0021, // Lz /
397  0150, // O Sq -
398  0144, // O Sq |
399  0141, // O Sq /
400  0130, // O Lz -
401  0124, // O Lz |
402  0121, // O Lz /
403  0070, // Sq Lz -
404  0064, // Sq Lz |
405  0061, // Sq Lz /
406  0170, // O Sq Lz -
407  0164, // O Sq Lz |
408  0161, // O Sq Lz /
409 
410  // Last resort: the backlash component (easy to confound)
411  0102, // \ O
412  0042, // \ Sq
413  0022, // \ Lz
414  0142, // \ O Sq
415  0122, // \ O Lz
416  0062, // \ Sq Lz
417  0162 // \ O Sq Lz
418  };
419 
420  if( aShapeId >= MARKER_COUNT )
421  {
422  // Fallback shape
423  markerCircle( position, radius );
424  }
425  else
426  {
427  // Decode the pattern and draw the corresponding parts
428  unsigned char pat = marker_patterns[aShapeId];
429 
430  if( pat & 0001 )
431  markerSlash( position, radius );
432 
433  if( pat & 0002 )
434  markerBackSlash( position, radius );
435 
436  if( pat & 0004 )
437  markerVBar( position, radius );
438 
439  if( pat & 0010 )
440  markerHBar( position, radius );
441 
442  if( pat & 0020 )
443  markerLozenge( position, radius );
444 
445  if( pat & 0040 )
446  markerSquare( position, radius );
447 
448  if( pat & 0100 )
449  markerCircle( position, radius );
450  }
451 }
void markerHBar(const wxPoint &pos, int radius)
Plot a - bar centered on the position.
Definition: plotter.cpp:304
static const unsigned MARKER_COUNT
Draw a marker (used for the drill map).
Definition: plotter.h:436
void markerSlash(const wxPoint &pos, int radius)
Plot a / bar centered on the position.
Definition: plotter.cpp:311
void markerLozenge(const wxPoint &position, int radius)
Plot a lozenge centered on the position.
Definition: plotter.cpp:280
void markerCircle(const wxPoint &pos, int radius)
Plot a circle centered on the position.
Definition: plotter.cpp:274
void markerVBar(const wxPoint &pos, int radius)
Plot a | bar centered on the position.
Definition: plotter.cpp:325
void markerSquare(const wxPoint &position, int radius)
Plot a square centered on the position.
Definition: plotter.cpp:249
void markerBackSlash(const wxPoint &pos, int radius)
Plot a \ bar centered on the position.
Definition: plotter.cpp:318

References PLOTTER::MARKER_COUNT, PLOTTER::markerBackSlash(), PLOTTER::markerCircle(), PLOTTER::markerHBar(), PLOTTER::markerLozenge(), PLOTTER::markerSlash(), PLOTTER::markerSquare(), and PLOTTER::markerVBar().

Referenced by GENDRILL_WRITER_BASE::genDrillMapFile(), and GENDRILL_WRITER_BASE::plotDrillMarks().

◆ markerBackSlash()

void PLOTTER::markerBackSlash ( const wxPoint &  pos,
int  radius 
)
protectedinherited

Plot a \ bar centered on the position.

Building block for markers

Definition at line 318 of file plotter.cpp.

319 {
320  MoveTo( wxPoint( pos.x + radius, pos.y - radius ) );
321  FinishTo( wxPoint( pos.x - radius, pos.y + radius ) );
322 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263

References PLOTTER::FinishTo(), and PLOTTER::MoveTo().

Referenced by PLOTTER::Marker().

◆ markerCircle()

void PLOTTER::markerCircle ( const wxPoint &  pos,
int  radius 
)
protectedinherited

Plot a circle centered on the position.

Building block for markers

Definition at line 274 of file plotter.cpp.

275 {
276  Circle( position, radius * 2, FILL_T::NO_FILL, GetCurrentLineWidth() );
277 }
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0

References PLOTTER::Circle(), PLOTTER::GetCurrentLineWidth(), and NO_FILL.

Referenced by PLOTTER::Marker().

◆ markerHBar()

void PLOTTER::markerHBar ( const wxPoint &  pos,
int  radius 
)
protectedinherited

Plot a - bar centered on the position.

Building block for markers

Definition at line 304 of file plotter.cpp.

305 {
306  MoveTo( wxPoint( pos.x - radius, pos.y ) );
307  FinishTo( wxPoint( pos.x + radius, pos.y ) );
308 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263

References PLOTTER::FinishTo(), and PLOTTER::MoveTo().

Referenced by PLOTTER::Marker().

◆ markerLozenge()

void PLOTTER::markerLozenge ( const wxPoint &  position,
int  radius 
)
protectedinherited

Plot a lozenge centered on the position.

Building block for markers

Definition at line 280 of file plotter.cpp.

281 {
282  std::vector< wxPoint > corner_list;
283  wxPoint corner;
284  corner.x = position.x;
285  corner.y = position.y + radius;
286  corner_list.push_back( corner );
287  corner.x = position.x + radius;
288  corner.y = position.y,
289  corner_list.push_back( corner );
290  corner.x = position.x;
291  corner.y = position.y - radius;
292  corner_list.push_back( corner );
293  corner.x = position.x - radius;
294  corner.y = position.y;
295  corner_list.push_back( corner );
296  corner.x = position.x;
297  corner.y = position.y + radius;
298  corner_list.push_back( corner );
299 
300  PlotPoly( corner_list, FILL_T::NO_FILL, GetCurrentLineWidth() );
301 }
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168

References PLOTTER::GetCurrentLineWidth(), NO_FILL, and PLOTTER::PlotPoly().

Referenced by PLOTTER::Marker().

◆ markerSlash()

void PLOTTER::markerSlash ( const wxPoint &  pos,
int  radius 
)
protectedinherited

Plot a / bar centered on the position.

Building block for markers

Definition at line 311 of file plotter.cpp.

312 {
313  MoveTo( wxPoint( pos.x - radius, pos.y - radius ) );
314  FinishTo( wxPoint( pos.x + radius, pos.y + radius ) );
315 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263

References PLOTTER::FinishTo(), and PLOTTER::MoveTo().

Referenced by PLOTTER::Marker().

◆ markerSquare()

void PLOTTER::markerSquare ( const wxPoint &  position,
int  radius 
)
protectedinherited

Plot a square centered on the position.

Building block for markers

Definition at line 249 of file plotter.cpp.

250 {
251  double r = KiROUND( radius / 1.4142 );
252  std::vector< wxPoint > corner_list;
253  wxPoint corner;
254  corner.x = position.x + r;
255  corner.y = position.y + r;
256  corner_list.push_back( corner );
257  corner.x = position.x + r;
258  corner.y = position.y - r;
259  corner_list.push_back( corner );
260  corner.x = position.x - r;
261  corner.y = position.y - r;
262  corner_list.push_back( corner );
263  corner.x = position.x - r;
264  corner.y = position.y + r;
265  corner_list.push_back( corner );
266  corner.x = position.x + r;
267  corner.y = position.y + r;
268  corner_list.push_back( corner );
269 
270  PlotPoly( corner_list, FILL_T::NO_FILL, GetCurrentLineWidth() );
271 }
virtual void PlotPoly(const std::vector< wxPoint > &aCornerList, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH, void *aData=nullptr)=0
Draw a polygon ( filled or not ).
virtual int GetCurrentLineWidth() const
Definition: plotter.h:168
E_SERIE r
Definition: eserie.cpp:41
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

References PLOTTER::GetCurrentLineWidth(), KiROUND(), NO_FILL, PLOTTER::PlotPoly(), and r.

Referenced by PLOTTER::Marker().

◆ markerVBar()

void PLOTTER::markerVBar ( const wxPoint &  pos,
int  radius 
)
protectedinherited

Plot a | bar centered on the position.

Building block for markers

Definition at line 325 of file plotter.cpp.

326 {
327  MoveTo( wxPoint( pos.x, pos.y - radius ) );
328  FinishTo( wxPoint( pos.x, pos.y + radius ) );
329 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263

References PLOTTER::FinishTo(), and PLOTTER::MoveTo().

Referenced by PLOTTER::Marker().

◆ MoveTo()

◆ OpenFile()

bool PLOTTER::OpenFile ( const wxString &  aFullFilename)
virtualinherited

Open or create the plot file aFullFilename.

Parameters
aFullFilenameis the full file name of the file to create.
Returns
true if success, false if the file cannot be created/opened.

Virtual because some plotters use ascii files, some others binary files (PDF) The base class open the file in text mode

Reimplemented in PDF_PLOTTER.

Definition at line 76 of file plotter.cpp.

77 {
78  m_filename = aFullFilename;
79 
80  wxASSERT( !m_outputFile );
81 
82  // Open the file in text mode (not suitable for all plotters but only for most of them.
83  m_outputFile = wxFopen( m_filename, wxT( "wt" ) );
84 
85  if( m_outputFile == nullptr )
86  return false ;
87 
88  return true;
89 }
wxString m_filename
Definition: plotter.h:600
FILE * m_outputFile
Output file.
Definition: plotter.h:590

References PLOTTER::m_filename, and PLOTTER::m_outputFile.

Referenced by GERBER_WRITER::createDrillFile(), PLACEFILE_GERBER_WRITER::CreatePlaceFile(), GENDRILL_WRITER_BASE::genDrillMapFile(), DIALOG_PLOT_SCHEMATIC::plotOneSheetDXF(), DIALOG_PLOT_SCHEMATIC::plotOneSheetHpgl(), DIALOG_PLOT_SCHEMATIC::plotOneSheetPS(), DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG(), StartPlotBoard(), and SYMBOL_EDIT_FRAME::SVGPlotSymbol().

◆ PageSettings()

PAGE_INFO& PLOTTER::PageSettings ( )
inlineinherited

◆ PenFinish()

void PLOTTER::PenFinish ( )
inlineinherited

Definition at line 279 of file plotter.h.

280  {
281  // The point is not important with Z motion
282  PenTo( wxPoint( 0, 0 ), 'Z' );
283  }
virtual void PenTo(const wxPoint &pos, char plume)=0
Moveto/lineto primitive, moves the 'pen' to the specified direction.

References PLOTTER::PenTo().

Referenced by HPGL_PLOTTER::Circle(), HPGL_PLOTTER::FlashPadCircle(), PlotPoly(), HPGL_PLOTTER::PlotPoly(), DXF_PLOTTER::PlotPoly(), and HPGL_PLOTTER::Rect().

◆ PenTo()

void GERBER_PLOTTER::PenTo ( const wxPoint &  pos,
char  plume 
)
overridevirtual

Moveto/lineto primitive, moves the 'pen' to the specified direction.

Parameters
posis the target position.
plumespecifies the kind of motion: 'U' only moves the pen, 'D' draw a line from the current position and 'Z' finish the drawing and returns the 'pen' to rest (flushes the trace).

Implements PLOTTER.

Definition at line 774 of file GERBER_plotter.cpp.

775 {
776  wxASSERT( m_outputFile );
777  DPOINT pos_dev = userToDeviceCoordinates( aPos );
778 
779  switch( plume )
780  {
781  case 'Z':
782  break;
783 
784  case 'U':
785  emitDcode( pos_dev, 2 );
786  break;
787 
788  case 'D':
789  emitDcode( pos_dev, 1 );
790  }
791 
792  m_penState = plume;
793 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
void emitDcode(const DPOINT &pt, int dcode)
Emit a D-Code record, using proper conversions to format a leading zero omitted gerber coordinate.
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
char m_penState
Definition: plotter.h:596

References emitDcode(), PLOTTER::m_outputFile, PLOTTER::m_penState, and PLOTTER::userToDeviceCoordinates().

◆ plotArc() [1/2]

void GERBER_PLOTTER::plotArc ( const wxPoint &  aCenter,
double  aStAngle,
double  aEndAngle,
int  aRadius,
bool  aPlotInRegion 
)
protected

Plot a Gerber arc.

If aPlotInRegion = true, the current pen position will not be initialized to the arc start position, and therefore the arc can be used to define a region outline item a line will be created from current position to arc start point. If aPlotInRegion = false, the current pen position will be initialized to the arc start position, to plot an usual arc item. The line thickness is not initialized in plotArc, and must be initialized before calling it if needed.

Definition at line 875 of file GERBER_plotter.cpp.

877 {
878  wxPoint start, end;
879  start.x = aCenter.x + KiROUND( cosdecideg( aRadius, aStAngle ) );
880  start.y = aCenter.y - KiROUND( sindecideg( aRadius, aStAngle ) );
881 
882  if( !aPlotInRegion )
883  MoveTo( start );
884  else
885  LineTo( start );
886 
887  end.x = aCenter.x + KiROUND( cosdecideg( aRadius, aEndAngle ) );
888  end.y = aCenter.y - KiROUND( sindecideg( aRadius, aEndAngle ) );
889  DPOINT devEnd = userToDeviceCoordinates( end );
890  DPOINT devCenter = userToDeviceCoordinates( aCenter ) - userToDeviceCoordinates( start );
891 
892  fprintf( m_outputFile, "G75*\n" ); // Multiquadrant (360 degrees) mode
893 
894  if( aStAngle < aEndAngle )
895  fprintf( m_outputFile, "G03*\n" ); // Active circular interpolation, CCW
896  else
897  fprintf( m_outputFile, "G02*\n" ); // Active circular interpolation, CW
898 
899  fprintf( m_outputFile, "X%dY%dI%dJ%dD01*\n",
900  KiROUND( devEnd.x ), KiROUND( devEnd.y ),
901  KiROUND( devCenter.x ), KiROUND( devCenter.y ) );
902 
903  fprintf( m_outputFile, "G01*\n" ); // Back to linear interpolate (perhaps useless here).
904 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
void LineTo(const wxPoint &pos)
Definition: plotter.h:268
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
double cosdecideg(double r, double a)
Circle generation utility: computes r * cos(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:452
double sindecideg(double r, double a)
Circle generation utility: computes r * sin(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:443
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

References cosdecideg(), KiROUND(), PLOTTER::LineTo(), PLOTTER::m_outputFile, PLOTTER::MoveTo(), sindecideg(), PLOTTER::userToDeviceCoordinates(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Arc(), PlotPoly(), and plotRoundRectAsRegion().

◆ plotArc() [2/2]

void GERBER_PLOTTER::plotArc ( const SHAPE_ARC aArc,
bool  aPlotInRegion 
)
protected

Definition at line 840 of file GERBER_plotter.cpp.

841 {
842  wxPoint start( aArc.GetP0() );
843  wxPoint end( aArc.GetP1() );
844  wxPoint center( aArc.GetCenter() );
845 
846  if( !aPlotInRegion )
847  MoveTo( start);
848  else
849  LineTo( start );
850 
851  DPOINT devEnd = userToDeviceCoordinates( end );
852  DPOINT devCenter = userToDeviceCoordinates( center - start );
853  VECTOR2I arcMidPoint = aArc.GetArcMid();
854 
855  // We need to know if the arc is CW or CCW in device coordinates, so build this arc.
856  SHAPE_ARC deviceArc( userToDeviceCoordinates( start ),
857  userToDeviceCoordinates( wxPoint( arcMidPoint.x, arcMidPoint.y ) ),
858  devEnd, 0 );
859 
860  fprintf( m_outputFile, "G75*\n" ); // Multiquadrant (360 degrees) mode
861 
862  if( deviceArc.IsClockwise() )
863  fprintf( m_outputFile, "G02*\n" ); // Active circular interpolation, CW
864  else
865  fprintf( m_outputFile, "G03*\n" ); // Active circular interpolation, CCW
866 
867  fprintf( m_outputFile, "X%dY%dI%dJ%dD01*\n",
868  KiROUND( devEnd.x ), KiROUND( devEnd.y ),
869  KiROUND( devCenter.x ), KiROUND( devCenter.y ) );
870 
871  fprintf( m_outputFile, "G01*\n" ); // Back to linear interpolate (perhaps useless here).
872 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
void LineTo(const wxPoint &pos)
Definition: plotter.h:268
const VECTOR2I & GetP0() const
Definition: shape_arc.h:111
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:113
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
virtual DPOINT userToDeviceCoordinates(const wxPoint &aCoordinate)
Modify coordinates according to the orientation, scale factor, and offsets trace.
Definition: plotter.cpp:92
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
const VECTOR2I & GetP1() const
Definition: shape_arc.h:112
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:424

References SHAPE_ARC::GetArcMid(), SHAPE_ARC::GetCenter(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), SHAPE_ARC::IsClockwise(), KiROUND(), PLOTTER::LineTo(), PLOTTER::m_outputFile, PLOTTER::MoveTo(), PLOTTER::userToDeviceCoordinates(), VECTOR2< T >::x, and VECTOR2< T >::y.

◆ PlotGerberRegion() [1/2]

void GERBER_PLOTTER::PlotGerberRegion ( const std::vector< wxPoint > &  aCornerList,
void *  aData = nullptr 
)

Plot a Gerber region: similar to PlotPoly but plot only filled polygon, and add the TA.AperFunction if aData contains this attribute, and clear it after plotting.

Definition at line 944 of file GERBER_plotter.cpp.

945 {
946  if( aCornerList.size() <= 2 )
947  return;
948 
949  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
950 
951  bool clearTA_AperFunction = false; // true if a TA.AperFunction is used
952 
953  if( gbr_metadata )
954  {
955  std::string attrib = gbr_metadata->m_ApertureMetadata.FormatAttribute( !m_useX2format );
956 
957  if( !attrib.empty() )
958  {
959  fputs( attrib.c_str(), m_outputFile );
960  clearTA_AperFunction = true;
961  }
962  }
963 
964  PlotPoly( aCornerList, FILL_T::FILLED_SHAPE, 0, gbr_metadata );
965 
966  // Clear the TA attribute, to avoid the next item to inherit it:
967  if( clearTA_AperFunction )
968  {
969  if( m_useX2format )
970  {
971  fputs( "%TD.AperFunction*%\n", m_outputFile );
972  }
973  else
974  {
975  fputs( "G04 #@! TD.AperFunction*\n", m_outputFile );
976  }
977  }
978 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
virtual void PlotPoly(const std::vector< wxPoint > &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.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
static std::string FormatAttribute(GBR_APERTURE_ATTRIB aAttribute, bool aUseX1StructuredComment)
GBR_APERTURE_METADATA m_ApertureMetadata
An item to handle aperture attribute.
Definition: gbr_metadata.h:257

References FILLED_SHAPE, GBR_APERTURE_METADATA::FormatAttribute(), GBR_METADATA::m_ApertureMetadata, PLOTTER::m_outputFile, m_useX2format, and PlotPoly().

Referenced by FlashPadChamferRoundRect(), FlashPadCustom(), and FlashPadTrapez().

◆ PlotGerberRegion() [2/2]

void GERBER_PLOTTER::PlotGerberRegion ( const SHAPE_LINE_CHAIN aPoly,
void *  aData = nullptr 
)

Definition at line 907 of file GERBER_plotter.cpp.

908 {
909  if( aPoly.PointCount() <= 2 )
910  return;
911 
912  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
913 
914  bool clearTA_AperFunction = false; // true if a TA.AperFunction is used
915 
916  if( gbr_metadata )
917  {
918  std::string attrib = gbr_metadata->m_ApertureMetadata.FormatAttribute( !m_useX2format );
919 
920  if( !attrib.empty() )
921  {
922  fputs( attrib.c_str(), m_outputFile );
923  clearTA_AperFunction = true;
924  }
925  }
926 
927  PlotPoly( aPoly, FILL_T::FILLED_SHAPE, 0 , gbr_metadata );
928 
929  // Clear the TA attribute, to avoid the next item to inherit it:
930  if( clearTA_AperFunction )
931  {
932  if( m_useX2format )
933  {
934  fputs( "%TD.AperFunction*%\n", m_outputFile );
935  }
936  else
937  {
938  fputs( "G04 #@! TD.AperFunction*\n", m_outputFile );
939  }
940  }
941 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual void PlotPoly(const std::vector< wxPoint > &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.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
static std::string FormatAttribute(GBR_APERTURE_ATTRIB aAttribute, bool aUseX1StructuredComment)
GBR_APERTURE_METADATA m_ApertureMetadata
An item to handle aperture attribute.
Definition: gbr_metadata.h:257

References FILLED_SHAPE, GBR_APERTURE_METADATA::FormatAttribute(), GBR_METADATA::m_ApertureMetadata, PLOTTER::m_outputFile, m_useX2format, PlotPoly(), and SHAPE_LINE_CHAIN::PointCount().

◆ PlotImage()

void PLOTTER::PlotImage ( const wxImage &  aImage,
const wxPoint &  aPos,
double  aScaleFactor 
)
virtualinherited

Only PostScript plotters can plot bitmaps.

A rectangle is plotted for plotters that cannot plot a bitmap.

Parameters
aImageis the bitmap.
aPosis position of the center of the bitmap.
aScaleFactoris the scale factor to apply to the bitmap size (this is not the plot scale factor).

Reimplemented in SVG_PLOTTER, PDF_PLOTTER, and PS_PLOTTER.

Definition at line 233 of file plotter.cpp.

234 {
235  wxSize size( aImage.GetWidth() * aScaleFactor, aImage.GetHeight() * aScaleFactor );
236 
237  wxPoint start = aPos;
238  start.x -= size.x / 2;
239  start.y -= size.y / 2;
240 
241  wxPoint end = start;
242  end.x += size.x;
243  end.y += size.y;
244 
245  Rect( start, end, FILL_T::NO_FILL );
246 }
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)=0

References NO_FILL, and PLOTTER::Rect().

Referenced by BITMAP_BASE::PlotImage(), and SVG_PLOTTER::PlotImage().

◆ PlotPoly() [1/2]

void GERBER_PLOTTER::PlotPoly ( const std::vector< wxPoint > &  aCornerList,
FILL_T  aFill,
int  aWidth = USE_DEFAULT_LINE_WIDTH,
void *  aData = nullptr 
)
overridevirtual

Gerber polygon: they can (and should) be filled with the appropriate G36/G37 sequence.

Implements PLOTTER.

Definition at line 1068 of file GERBER_plotter.cpp.

1070 {
1071  if( aCornerList.size() <= 1 )
1072  return;
1073 
1074  // Gerber format does not know filled polygons with thick outline
1075  // Therefore, to plot a filled polygon with outline having a thickness,
1076  // one should plot outline as thick segments
1077  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1078 
1079  if( gbr_metadata )
1080  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1081 
1082  if( aFill != FILL_T::NO_FILL )
1083  {
1084  fputs( "G36*\n", m_outputFile );
1085 
1086  MoveTo( aCornerList[0] );
1087  fputs( "G01*\n", m_outputFile ); // Set linear interpolation.
1088 
1089  for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
1090  LineTo( aCornerList[ii] );
1091 
1092  // If the polygon is not closed, close it:
1093  if( aCornerList[0] != aCornerList[aCornerList.size()-1] )
1094  FinishTo( aCornerList[0] );
1095 
1096  fputs( "G37*\n", m_outputFile );
1097  }
1098 
1099  if( aWidth > 0 ) // Draw the polyline/polygon outline
1100  {
1101  SetCurrentLineWidth( aWidth, gbr_metadata );
1102 
1103  MoveTo( aCornerList[0] );
1104 
1105  for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
1106  LineTo( aCornerList[ii] );
1107 
1108  // Ensure the thick outline is closed for filled polygons
1109  // (if not filled, could be only a polyline)
1110  if( aFill != FILL_T::NO_FILL && ( aCornerList[aCornerList.size() - 1] != aCornerList[0] ) )
1111  LineTo( aCornerList[0] );
1112 
1113  PenFinish();
1114  }
1115 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void PenFinish()
Definition: plotter.h:279
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
FILE * m_outputFile
Output file.
Definition: plotter.h:590
void LineTo(const wxPoint &pos)
Definition: plotter.h:268
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262

References PLOTTER::FinishTo(), formatNetAttribute(), PLOTTER::LineTo(), GBR_METADATA::m_NetlistMetadata, PLOTTER::m_outputFile, PLOTTER::MoveTo(), NO_FILL, PLOTTER::PenFinish(), and SetCurrentLineWidth().

Referenced by FlashPadChamferRoundRect(), FlashPadCustom(), FlashPadRoundRect(), FlashPadTrapez(), FlashRegularPolygon(), PlotGerberRegion(), and Rect().

◆ PlotPoly() [2/2]

void GERBER_PLOTTER::PlotPoly ( const SHAPE_LINE_CHAIN aCornerList,
FILL_T  aFill,
int  aWidth = USE_DEFAULT_LINE_WIDTH,
void *  aData = nullptr 
)
overridevirtual

Draw a polygon ( filled or not ).

Parameters
aCornerListis the corners list (a SHAPE_LINE_CHAIN). must be closed (IsClosed() == true) for a polygon. Otherwise this is a polyline.
aFillis the type of fill.
aWidthis the line width.
aDatais an auxiliary info (mainly for gerber format).

Plain point

Plain point

Reimplemented from PLOTTER.

Definition at line 981 of file GERBER_plotter.cpp.

983 {
984  if( aPoly.CPoints().size() <= 1 )
985  return;
986 
987  // Gerber format does not know filled polygons with thick outline
988  // Therefore, to plot a filled polygon with outline having a thickness,
989  // one should plot outline as thick segments
990  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
991 
992  if( gbr_metadata )
993  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
994 
995  if( aFill != FILL_T::NO_FILL )
996  {
997  fputs( "G36*\n", m_outputFile );
998 
999  MoveTo( wxPoint( aPoly.CPoint( 0 ) ) );
1000 
1001  fputs( "G01*\n", m_outputFile ); // Set linear interpolation.
1002 
1003  for( int ii = 1; ii < aPoly.PointCount(); ii++ )
1004  {
1005  int arcindex = aPoly.ArcIndex( ii );
1006 
1007  if( arcindex < 0 )
1008  {
1010  LineTo( wxPoint( aPoly.CPoint( ii ) ) );
1011  }
1012  else
1013  {
1014  const SHAPE_ARC& arc = aPoly.Arc( arcindex );
1015 
1016  plotArc( arc, ii > 0 );
1017 
1018  // skip points on arcs, since we plot the arc itself
1019  while( ii+1 < aPoly.PointCount() && arcindex == aPoly.ArcIndex( ii+1 ) )
1020  ii++;
1021  }
1022  }
1023 
1024  // If the polygon is not closed, close it:
1025  if( aPoly.CPoint( 0 ) != aPoly.CPoint( -1 ) )
1026  FinishTo( wxPoint( aPoly.CPoint( 0 ) ) );
1027 
1028  fputs( "G37*\n", m_outputFile );
1029  }
1030 
1031  if( aWidth > 0 ) // Draw the polyline/polygon outline
1032  {
1033  SetCurrentLineWidth( aWidth, gbr_metadata );
1034 
1035  MoveTo( wxPoint( aPoly.CPoint( 0 ) ) );
1036 
1037  for( int ii = 1; ii < aPoly.PointCount(); ii++ )
1038  {
1039  int arcindex = aPoly.ArcIndex( ii );
1040 
1041  if( arcindex < 0 )
1042  {
1044  LineTo( wxPoint( aPoly.CPoint( ii ) ) );
1045  }
1046  else
1047  {
1048  const SHAPE_ARC& arc = aPoly.Arc( arcindex );
1049 
1050  plotArc( arc, ii > 0 );
1051 
1052  // skip points on arcs, since we plot the arc itself
1053  while( ii+1 < aPoly.PointCount() && arcindex == aPoly.ArcIndex( ii+1 ) )
1054  ii++;
1055  }
1056  }
1057 
1058  // Ensure the thick outline is closed for filled polygons
1059  // (if not filled, could be only a polyline)
1060  if( ( aPoly.CPoint( 0 ) != aPoly.CPoint( -1 ) )
1061  && ( aPoly.IsClosed() || aFill != FILL_T::NO_FILL ) )
1062  LineTo( wxPoint( aPoly.CPoint( 0 ) ) );
1063 
1064  PenFinish();
1065  }
1066 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void PenFinish()
Definition: plotter.h:279
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
FILE * m_outputFile
Output file.
Definition: plotter.h:590
void plotArc(const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, bool aPlotInRegion)
Plot a Gerber arc.
void LineTo(const wxPoint &pos)
Definition: plotter.h:268
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262

References SHAPE_LINE_CHAIN::Arc(), SHAPE_LINE_CHAIN::ArcIndex(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::CPoints(), PLOTTER::FinishTo(), formatNetAttribute(), SHAPE_LINE_CHAIN::IsClosed(), PLOTTER::LineTo(), GBR_METADATA::m_NetlistMetadata, PLOTTER::m_outputFile, PLOTTER::MoveTo(), NO_FILL, PLOTTER::PenFinish(), plotArc(), SHAPE_LINE_CHAIN::PointCount(), and SetCurrentLineWidth().

◆ plotRoundRectAsRegion()

void GERBER_PLOTTER::plotRoundRectAsRegion ( const wxPoint &  aRectCenter,
const wxSize &  aSize,
int  aCornerRadius,
double  aOrient 
)
protected

Plot a round rect (a round rect shape in fact) as a Gerber region using lines and arcs for corners.

Note
Only the G36 ... G37 region is created.
Parameters
aRectCenteris the center of the rectangle.
aSizeis the size of the rectangle.
aCornerRadiusis the radius of the corners.
aOrientis the rotation of the rectangle.

Definition at line 1512 of file GERBER_plotter.cpp.

1514 {
1515  // The region outline is generated by 4 sides and 4 90 deg arcs
1516  // 1 --- 2
1517  // | c |
1518  // 4 --- 3
1519 
1520  // Note also in user coordinates the Y axis is from top to bottom
1521  // for historical reasons.
1522 
1523  // A helper structure to handle outlines coordinates (segments and arcs)
1524  // in user coordinates
1525  struct RR_EDGE
1526  {
1527  wxPoint m_start;
1528  wxPoint m_end;
1529  wxPoint m_center;
1530  // in decidegrees: angle start. angle end = m_arc_angle_start+arc_angle
1531  double m_arc_angle_start;
1532  };
1533 
1534  const double arc_angle = -900.0; // in decidegrees
1535  int hsizeX = aSize.x/2;
1536  int hsizeY = aSize.y/2;
1537 
1538  RR_EDGE curr_edge;
1539  std::vector<RR_EDGE> rr_outline;
1540 
1541  // Build outline coordinates, relative to rectangle center, rotation 0:
1542 
1543  // Top left corner 1 (and 4 to 1 left vertical side @ x=-hsizeX)
1544  curr_edge.m_start.x = -hsizeX;
1545  curr_edge.m_start.y = hsizeY - aCornerRadius;
1546  curr_edge.m_end.x = curr_edge.m_start.x;
1547  curr_edge.m_end.y = -hsizeY + aCornerRadius;
1548  curr_edge.m_center.x = -hsizeX + aCornerRadius;
1549  curr_edge.m_center.y = curr_edge.m_end.y;
1550  curr_edge.m_arc_angle_start = aOrient + 1800.0; // En decidegree
1551 
1552  rr_outline.push_back( curr_edge );
1553 
1554  // Top right corner 2 (and 1 to 2 top horizontal side @ y=-hsizeY)
1555  curr_edge.m_start.x = -hsizeX + aCornerRadius;
1556  curr_edge.m_start.y = -hsizeY;
1557  curr_edge.m_end.x = hsizeX - aCornerRadius;
1558  curr_edge.m_end.y = curr_edge.m_start.y;
1559  curr_edge.m_center.x = curr_edge.m_end.x;
1560  curr_edge.m_center.y = -hsizeY + aCornerRadius;
1561  curr_edge.m_arc_angle_start = aOrient + 900.0; // En decidegree
1562 
1563  rr_outline.push_back( curr_edge );
1564 
1565  // bottom right corner 3 (and 2 to 3 right vertical side @ x=hsizeX)
1566  curr_edge.m_start.x = hsizeX;
1567  curr_edge.m_start.y = -hsizeY + aCornerRadius;
1568  curr_edge.m_end.x = curr_edge.m_start.x;
1569  curr_edge.m_end.y = hsizeY - aCornerRadius;
1570  curr_edge.m_center.x = hsizeX - aCornerRadius;
1571  curr_edge.m_center.y = curr_edge.m_end.y;
1572  curr_edge.m_arc_angle_start = aOrient + 0.0; // En decidegree
1573 
1574  rr_outline.push_back( curr_edge );
1575 
1576  // bottom left corner 4 (and 3 to 4 bottom horizontal side @ y=hsizeY)
1577  curr_edge.m_start.x = hsizeX - aCornerRadius;
1578  curr_edge.m_start.y = hsizeY;
1579  curr_edge.m_end.x = -hsizeX + aCornerRadius;
1580  curr_edge.m_end.y = curr_edge.m_start.y;
1581  curr_edge.m_center.x = curr_edge.m_end.x;
1582  curr_edge.m_center.y = hsizeY - aCornerRadius;
1583  curr_edge.m_arc_angle_start = aOrient - 900.0; // En decidegree
1584 
1585  rr_outline.push_back( curr_edge );
1586 
1587  // Move relative coordinates to the actual location and rotation:
1588  wxPoint arc_last_center;
1589  int arc_last_angle = curr_edge.m_arc_angle_start+arc_angle;
1590 
1591  for( RR_EDGE& rr_edge: rr_outline )
1592  {
1593  RotatePoint( &rr_edge.m_start, aOrient );
1594  RotatePoint( &rr_edge.m_end, aOrient );
1595  RotatePoint( &rr_edge.m_center, aOrient );
1596  rr_edge.m_start += aRectCenter;
1597  rr_edge.m_end += aRectCenter;
1598  rr_edge.m_center += aRectCenter;
1599  arc_last_center = rr_edge.m_center;
1600  }
1601 
1602  // Ensure the region is a closed polygon, i.e. the end point of last segment
1603  // (end of arc) is the same as the first point. Rounding issues can create a
1604  // small difference, mainly for rotated pads.
1605  // calculate last point (end of last arc):
1606  wxPoint last_pt;
1607  last_pt.x = arc_last_center.x + KiROUND( cosdecideg( aCornerRadius, arc_last_angle ) );
1608  last_pt.y = arc_last_center.y - KiROUND( sindecideg( aCornerRadius, arc_last_angle ) );
1609 
1610  wxPoint first_pt = rr_outline[0].m_start;
1611 
1612 #if 0 // For test only:
1613  if( last_pt != first_pt )
1614  wxLogMessage( wxT( "first pt %d %d last pt %d %d" ),
1615  first_pt.x, first_pt.y, last_pt.x, last_pt.y );
1616 #endif
1617 
1618  fputs( "G36*\n", m_outputFile ); // Start region
1619  fputs( "G01*\n", m_outputFile ); // Set linear interpolation.
1620  first_pt = last_pt;
1621  MoveTo( first_pt ); // Start point of region, must be same as end point
1622 
1623  for( RR_EDGE& rr_edge: rr_outline )
1624  {
1625  if( aCornerRadius ) // Guard: ensure we do not create arcs with radius = 0
1626  {
1627  // LineTo( rr_edge.m_end ); // made in plotArc()
1628  plotArc( rr_edge.m_center, rr_edge.m_arc_angle_start,
1629  rr_edge.m_arc_angle_start+arc_angle, aCornerRadius, true );
1630  }
1631  else
1632  {
1633  LineTo( rr_edge.m_end );
1634  }
1635  }
1636 
1637  fputs( "G37*\n", m_outputFile ); // Close region
1638 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
void plotArc(const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, bool aPlotInRegion)
Plot a Gerber arc.
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
void LineTo(const wxPoint &pos)
Definition: plotter.h:268
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
double cosdecideg(double r, double a)
Circle generation utility: computes r * cos(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:452
double sindecideg(double r, double a)
Circle generation utility: computes r * sin(a) Where a is in decidegrees, not in radians.
Definition: trigo.h:443
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73

References cosdecideg(), KiROUND(), PLOTTER::LineTo(), PLOTTER::m_outputFile, PLOTTER::MoveTo(), plotArc(), RotatePoint(), and sindecideg().

Referenced by FlashPadRoundRect().

◆ Rect()

void GERBER_PLOTTER::Rect ( const wxPoint &  p1,
const wxPoint &  p2,
FILL_T  fill,
int  width = USE_DEFAULT_LINE_WIDTH 
)
overridevirtual

Implements PLOTTER.

Definition at line 796 of file GERBER_plotter.cpp.

797 {
798  std::vector< wxPoint > cornerList;
799 
800  // Build corners list
801  cornerList.push_back( p1 );
802  wxPoint corner(p1.x, p2.y);
803  cornerList.push_back( corner );
804  cornerList.push_back( p2 );
805  corner.x = p2.x;
806  corner.y = p1.y;
807  cornerList.push_back( corner );
808  cornerList.push_back( p1 );
809 
810  PlotPoly( cornerList, fill, width );
811 }
virtual void PlotPoly(const std::vector< wxPoint > &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.

References PlotPoly().

Referenced by FlashPadRect(), and ThickRect().

◆ RenderSettings()

◆ segmentAsOval()

void PLOTTER::segmentAsOval ( const wxPoint &  start,
const wxPoint &  end,
int  width,
OUTLINE_MODE  tracemode 
)
protectedinherited

Convert a thick segment and plot it as an oval.

Definition at line 454 of file plotter.cpp.

456 {
457  wxPoint center( (start.x + end.x) / 2, (start.y + end.y) / 2 );
458  wxSize size( end.x - start.x, end.y - start.y );
459  double orient;
460 
461  if( size.y == 0 )
462  orient = 0;
463  else if( size.x == 0 )
464  orient = 900;
465  else
466  orient = -ArcTangente( size.y, size.x );
467 
468  size.x = KiROUND( EuclideanNorm( size ) ) + width;
469  size.y = width;
470 
471  FlashPadOval( center, size, orient, tracemode, nullptr );
472 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
virtual void FlashPadOval(const wxPoint &aPadPos, const wxSize &aSize, double aPadOrient, OUTLINE_MODE aTraceMode, void *aData)=0
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
double ArcTangente(int dy, int dx)
Definition: trigo.cpp:183

References ArcTangente(), EuclideanNorm(), PLOTTER::FlashPadOval(), and KiROUND().

Referenced by ThickSegment(), HPGL_PLOTTER::ThickSegment(), and PLOTTER::ThickSegment().

◆ selectAperture() [1/3]

void GERBER_PLOTTER::selectAperture ( const wxSize &  aSize,
int  aRadius,
double  aRotDegree,
APERTURE::APERTURE_TYPE  aType,
int  aApertureAttribute 
)
protected

Pick an existing aperture or create a new one, matching the size, type and attributes.

Write the DCode selection on gerber file.

Definition at line 500 of file GERBER_plotter.cpp.

502 {
503  bool change = ( m_currentApertureIdx < 0 ) ||
504  ( m_apertures[m_currentApertureIdx].m_Type != aType ) ||
505  ( m_apertures[m_currentApertureIdx].m_Size != aSize ) ||
506  ( m_apertures[m_currentApertureIdx].m_Radius != aRadius ) ||
507  ( m_apertures[m_currentApertureIdx].m_Rotation != aRotDegree );
508 
509  if( !change )
510  change = m_apertures[m_currentApertureIdx].m_ApertureAttribute != aApertureAttribute;
511 
512  if( change )
513  {
514  // Pick an existing aperture or create a new one
515  m_currentApertureIdx = GetOrCreateAperture( aSize, aRadius, aRotDegree,
516  aType, aApertureAttribute );
517  fprintf( m_outputFile, "D%d*\n", m_apertures[m_currentApertureIdx].m_DCode );
518  }
519 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
std::vector< APERTURE > m_apertures
int GetOrCreateAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)

References GetOrCreateAperture(), m_apertures, m_currentApertureIdx, and PLOTTER::m_outputFile.

Referenced by FlashPadChamferRoundRect(), FlashPadCircle(), FlashPadCustom(), FlashPadOval(), FlashPadRect(), FlashPadRoundRect(), FlashPadTrapez(), FlashRegularPolygon(), selectAperture(), and SetCurrentLineWidth().

◆ selectAperture() [2/3]

void GERBER_PLOTTER::selectAperture ( const std::vector< wxPoint > &  aCorners,
double  aPolygonRotation,
APERTURE::APERTURE_TYPE  aType,
int  aApertureAttribute 
)
protected

Pick an existing aperture or create a new one, matching the aDiameter, aPolygonRotation, type and attributes.

It apply only to apertures with type = AT_REGULAR_POLY3 to AT_REGULAR_POLY12 write the DCode selection on gerber file

Definition at line 522 of file GERBER_plotter.cpp.

524 {
525  bool change = ( m_currentApertureIdx < 0 ) ||
526  ( m_apertures[m_currentApertureIdx].m_Type != aType ) ||
527  ( m_apertures[m_currentApertureIdx].m_Corners.size() != aCorners.size() ) ||
528  ( m_apertures[m_currentApertureIdx].m_Rotation != aRotDegree );
529 
530  if( !change ) // Compare corner lists
531  {
532  for( size_t ii = 0; ii < aCorners.size(); ii++ )
533  {
534  if( aCorners[ii] != m_apertures[m_currentApertureIdx].m_Corners[ii] )
535  {
536  change = true;
537  break;
538  }
539  }
540  }
541 
542  if( !change )
543  change = m_apertures[m_currentApertureIdx].m_ApertureAttribute != aApertureAttribute;
544 
545  if( change )
546  {
547  // Pick an existing aperture or create a new one
548  m_currentApertureIdx = GetOrCreateAperture( aCorners, aRotDegree,
549  aType, aApertureAttribute );
550  fprintf( m_outputFile, "D%d*\n", m_apertures[m_currentApertureIdx].m_DCode );
551  }
552 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590
std::vector< APERTURE > m_apertures
int GetOrCreateAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)

References GetOrCreateAperture(), m_apertures, m_currentApertureIdx, and PLOTTER::m_outputFile.

◆ selectAperture() [3/3]

void GERBER_PLOTTER::selectAperture ( int  aDiameter,
double  aRotDegree,
APERTURE::APERTURE_TYPE  aType,
int  aApertureAttribute 
)
protected

Pick an existing aperture or create a new one, matching the corner list, aRotDegree, type and attributes.

It only applies to apertures managing a polygon that differs from AT_REGULAR_POLY3 to AT_REGULAR_POLY12 (for instance APER_MACRO_TRAPEZOID ) write the DCode selection on gerber file.

Definition at line 555 of file GERBER_plotter.cpp.

557 {
558  // Pick an existing aperture or create a new one, matching the
559  // aDiameter, aPolygonRotation, type and attributes for type =
560  // AT_REGULAR_POLY3 to AT_REGULAR_POLY12
561 
562  wxASSERT( aType>= APERTURE::APERTURE_TYPE::AT_REGULAR_POLY3 &&
563  aType <= APERTURE::APERTURE_TYPE::AT_REGULAR_POLY12 );
564 
565  wxSize size( aDiameter, (int)( aPolygonRotation * 1000.0 ) );
566  selectAperture( wxSize( 0, 0), aDiameter/2, aPolygonRotation, aType, aApertureAttribute );
567 }
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.

References selectAperture().

◆ SetColor()

virtual void GERBER_PLOTTER::SetColor ( const COLOR4D color)
inlineoverridevirtual

Implements PLOTTER.

Definition at line 61 of file plotter_gerber.h.

61 {}

◆ SetColorMode()

virtual void PLOTTER::SetColorMode ( bool  aColorMode)
inlinevirtualinherited

◆ SetCreator()

◆ SetCurrentLineWidth()

void GERBER_PLOTTER::SetCurrentLineWidth ( int  width,
void *  aData = nullptr 
)
overridevirtual

Set the line width for the next drawing.

Parameters
widthis specified in IUs.
aDatais an auxiliary parameter, mainly used in gerber plotter.

Implements PLOTTER.

Definition at line 398 of file GERBER_plotter.cpp.

399 {
400  if( aWidth == DO_NOT_SET_LINE_WIDTH )
401  return;
402  else if( aWidth == USE_DEFAULT_LINE_WIDTH )
404 
405  wxASSERT_MSG( aWidth >= 0, wxT( "Plotter called to set negative pen width" ) );
406 
407  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
408  int aperture_attribute = gbr_metadata ? gbr_metadata->GetApertureAttrib() : 0;
409 
410  selectAperture( wxSize( aWidth, aWidth ), 0, 0.0, APERTURE::AT_PLOTTING, aperture_attribute );
411  m_currentPenWidth = aWidth;
412 }
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
int m_currentPenWidth
Definition: plotter.h:595
GBR_APERTURE_METADATA::GBR_APERTURE_ATTRIB GetApertureAttrib()
Definition: gbr_metadata.h:214
RENDER_SETTINGS * m_renderSettings
Definition: plotter.h:607
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void selectAperture(const wxSize &aSize, int aRadius, double aRotDegree, APERTURE::APERTURE_TYPE aType, int aApertureAttribute)
Pick an existing aperture or create a new one, matching the size, type and attributes.
int GetDefaultPenWidth() const
static const int DO_NOT_SET_LINE_WIDTH
Definition: plotter.h:125

References APERTURE::AT_PLOTTING, PLOTTER::DO_NOT_SET_LINE_WIDTH, GBR_METADATA::GetApertureAttrib(), KIGFX::RENDER_SETTINGS::GetDefaultPenWidth(), PLOTTER::m_currentPenWidth, PLOTTER::m_renderSettings, selectAperture(), and PLOTTER::USE_DEFAULT_LINE_WIDTH.

Referenced by Arc(), FilledCircle(), FlashPadCircle(), FlashPadCustom(), FlashPadRect(), FlashPadRoundRect(), PlotPoly(), ThickArc(), ThickCircle(), ThickRect(), and ThickSegment().

◆ SetDash()

virtual void GERBER_PLOTTER::SetDash ( PLOT_DASH_TYPE  dashed)
inlineoverridevirtual

Implements PLOTTER.

Definition at line 57 of file plotter_gerber.h.

58  {
59  }

◆ SetGerberCoordinatesFormat()

void GERBER_PLOTTER::SetGerberCoordinatesFormat ( int  aResolution,
bool  aUseInches = false 
)
overridevirtual

Selection of Gerber units and resolution (number of digits in mantissa).

Should be called only after SetViewport() is called.

Parameters
aResolutionis the number of digits in mantissa of coordinate use 5 or 6 for mm and 6 or 7 for inches do not use value > 6 (mm) or > 7 (in) to avoid overflow.
aUseInchesuse true to use inches, false to use mm (default).

Reimplemented from PLOTTER.

Definition at line 143 of file GERBER_plotter.cpp.

144 {
145  m_gerberUnitInch = aUseInches;
146  m_gerberUnitFmt = aResolution;
147 
148  m_iuPerDeviceUnit = pow( 10.0, m_gerberUnitFmt ) / ( m_IUsPerDecimil * 10000.0 );
149 
150  if( ! m_gerberUnitInch )
151  m_iuPerDeviceUnit *= 25.4; // gerber output in mm
152 }
double m_iuPerDeviceUnit
Definition: plotter.h:581
double m_IUsPerDecimil
Definition: plotter.h:579

References m_gerberUnitFmt, m_gerberUnitInch, PLOTTER::m_iuPerDeviceUnit, and PLOTTER::m_IUsPerDecimil.

Referenced by GERBER_WRITER::createDrillFile(), and PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ SetLayerPolarity()

void GERBER_PLOTTER::SetLayerPolarity ( bool  aPositive)
overridevirtual

Change the plot polarity and begin a new layer.

Used to 'scratch off' silk screen away from solder mask.

Reimplemented from PLOTTER.

Definition at line 1951 of file GERBER_plotter.cpp.

1952 {
1953  if( aPositive )
1954  fprintf( m_outputFile, "%%LPD*%%\n" );
1955  else
1956  fprintf( m_outputFile, "%%LPC*%%\n" );
1957 }
FILE * m_outputFile
Output file.
Definition: plotter.h:590

References PLOTTER::m_outputFile.

◆ SetNegative()

virtual void PLOTTER::SetNegative ( bool  aNegative)
inlinevirtualinherited

Definition at line 142 of file plotter.h.

143  {
144  m_negativeMode = aNegative;
145  }
bool m_negativeMode
Definition: plotter.h:594

References PLOTTER::m_negativeMode.

Referenced by FillNegativeKnockout().

◆ SetPageSettings()

◆ SetRenderSettings()

◆ SetSvgCoordinatesFormat()

virtual void PLOTTER::SetSvgCoordinatesFormat ( unsigned  aResolution,
bool  aUseInches = false 
)
inlinevirtualinherited

Reimplemented in SVG_PLOTTER.

Definition at line 475 of file plotter.h.

476  {
477  // NOP for most plotters. Only for SVG plotter
478  }

Referenced by initializePlotter().

◆ SetTextMode()

virtual void PLOTTER::SetTextMode ( PLOT_TEXT_MODE  mode)
inlinevirtualinherited

Change the current text mode.

See the PlotTextMode explanation at the beginning of the file.

Reimplemented in DXF_PLOTTER, and PSLIKE_PLOTTER.

Definition at line 465 of file plotter.h.

466  {
467  // NOP for most plotters.
468  }

Referenced by initializePlotter(), and PlotOneBoardLayer().

◆ SetTitle()

virtual void PLOTTER::SetTitle ( const wxString &  aTitle)
inlinevirtualinherited

Definition at line 176 of file plotter.h.

176 { m_title = aTitle; }
wxString m_title
Definition: plotter.h:601

References PLOTTER::m_title.

Referenced by DIALOG_PLOT_SCHEMATIC::createPDFFile().

◆ SetViewport()

void GERBER_PLOTTER::SetViewport ( const wxPoint &  aOffset,
double  aIusPerDecimil,
double  aScale,
bool  aMirror 
)
overridevirtual

Set the plot offset and scaling for the current plot.

Parameters
aOffsetis the plot offset.
aIusPerDecimilgives the scaling factor from IUs to device units
aScaleis the user set plot scaling factor (either explicitly or using 'fit to A4').
aMirrorflips the plot in the Y direction (useful for toner transfers or some kind of film).

Implements PLOTTER.

Definition at line 121 of file GERBER_plotter.cpp.

123 {
124  wxASSERT( aMirror == false );
125  m_plotMirror = false;
126  m_plotOffset = aOffset;
127  wxASSERT( aScale == 1 ); // aScale parameter is not used in Gerber
128  m_plotScale = 1; // Plot scale is *always* 1.0
129 
130  m_IUsPerDecimil = aIusPerDecimil;
131 
132  // gives now a default value to iuPerDeviceUnit (because the units of the caller is now known)
133  // which could be modified later by calling SetGerberCoordinatesFormat()
134  m_iuPerDeviceUnit = pow( 10.0, m_gerberUnitFmt ) / ( m_IUsPerDecimil * 10000.0 );
135 
136  // We don't handle the filmbox, and it's more useful to keep the
137  // origin at the origin
138  m_paperSize.x = 0;
139  m_paperSize.y = 0;
140 }
double m_iuPerDeviceUnit
Definition: plotter.h:581
double m_IUsPerDecimil
Definition: plotter.h:579
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:573
bool m_plotMirror
Definition: plotter.h:584
wxPoint m_plotOffset
Definition: plotter.h:583
wxSize m_paperSize
Definition: plotter.h:603

References m_gerberUnitFmt, PLOTTER::m_iuPerDeviceUnit, PLOTTER::m_IUsPerDecimil, PLOTTER::m_paperSize, PLOTTER::m_plotMirror, PLOTTER::m_plotOffset, and PLOTTER::m_plotScale.

Referenced by GERBER_WRITER::createDrillFile(), and PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ sketchOval()

void PLOTTER::sketchOval ( const wxPoint &  pos,
const wxSize &  size,
double  orient,
int  width 
)
protectedinherited

Definition at line 475 of file plotter.cpp.

476 {
477  SetCurrentLineWidth( width );
478  width = m_currentPenWidth;
479  int radius, deltaxy, cx, cy;
480  wxSize size( aSize );
481 
482  if( size.x > size.y )
483  {
484  std::swap( size.x, size.y );
485  orient = AddAngles( orient, 900 );
486  }
487 
488  deltaxy = size.y - size.x; /* distance between centers of the oval */
489  radius = size.x / 2;
490  cx = -radius;
491  cy = -deltaxy / 2;
492  RotatePoint( &cx, &cy, orient );
493  MoveTo( wxPoint( cx + pos.x, cy + pos.y ) );
494  cx = -radius;
495  cy = deltaxy / 2;
496  RotatePoint( &cx, &cy, orient );
497  FinishTo( wxPoint( cx + pos.x, cy + pos.y ) );
498 
499  cx = radius;
500  cy = -deltaxy / 2;
501  RotatePoint( &cx, &cy, orient );
502  MoveTo( wxPoint( cx + pos.x, cy + pos.y ) );
503  cx = radius;
504  cy = deltaxy / 2;
505  RotatePoint( &cx, &cy, orient );
506  FinishTo( wxPoint( cx + pos.x, cy + pos.y ) );
507 
508  cx = 0;
509  cy = deltaxy / 2;
510  RotatePoint( &cx, &cy, orient );
511  Arc( wxPoint( cx + pos.x, cy + pos.y ), orient + 1800, orient + 3600, radius, FILL_T::NO_FILL );
512  cx = 0;
513  cy = -deltaxy / 2;
514  RotatePoint( &cx, &cy, orient );
515  Arc( wxPoint( cx + pos.x, cy + pos.y ), orient, orient + 1800, radius, FILL_T::NO_FILL );
516 }
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
int m_currentPenWidth
Definition: plotter.h:595
T AddAngles(T a1, T2 a2)
Add two angles (keeping the result normalized). T2 is here.
Definition: trigo.h:341
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
virtual void Arc(const wxPoint &centre, double StAngle, double EndAngle, int rayon, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH)
Generic fallback: arc rendered as a polyline.
Definition: plotter.cpp:158
virtual void SetCurrentLineWidth(int width, void *aData=nullptr)=0
Set the line width for the next drawing.

References AddAngles(), PLOTTER::Arc(), PLOTTER::FinishTo(), PLOTTER::m_currentPenWidth, PLOTTER::MoveTo(), NO_FILL, RotatePoint(), and PLOTTER::SetCurrentLineWidth().

Referenced by PSLIKE_PLOTTER::FlashPadOval(), FlashPadOval(), HPGL_PLOTTER::FlashPadOval(), and DXF_PLOTTER::FlashPadOval().

◆ StartBlock()

void GERBER_PLOTTER::StartBlock ( void *  aData)
overridevirtual

Calling this function allows one to define the beginning of a group of drawing items (used in X2 format with netlist attributes).

Parameters
aDatacan define any parameter.

Reimplemented from PLOTTER.

Definition at line 189 of file GERBER_plotter.cpp.

190 {
191  // Currently, it is the same as EndBlock(): clear all aperture net attributes
192  EndBlock( aData );
193 }
virtual void EndBlock(void *aData) override
Define the end of a group of drawing items the group is started by StartBlock().

References EndBlock().

◆ StartPlot()

bool GERBER_PLOTTER::StartPlot ( )
overridevirtual

Write GERBER header to file initialize global variable g_Plot_PlotOutputFile.

Implements PLOTTER.

Definition at line 237 of file GERBER_plotter.cpp.

238 {
239  m_hasApertureRoundRect = false; // true is at least one round rect aperture is in use
240  m_hasApertureRotOval = false; // true is at least one oval rotated aperture is in use
241  m_hasApertureRotRect = false; // true is at least one rect. rotated aperture is in use
242  m_hasApertureOutline4P = false; // true is at least one rotated rect/trapezoid aperture
243  // is in use
244  m_hasApertureChamferedRect = false; // true is at least one chamfered rect is in use
246 
247  wxASSERT( m_outputFile );
248 
249  finalFile = m_outputFile; // the actual gerber file will be created later
250 
251  // Create a temp file in system temp to avoid potential network share buffer issues for
252  // the final read and save.
253  m_workFilename = wxFileName::CreateTempFileName( wxEmptyString );
254  workFile = wxFopen( m_workFilename, wxT( "wt" ));
256  wxASSERT( m_outputFile );
257 
258  if( m_outputFile == nullptr )
259  return false;
260 
261  for( unsigned ii = 0; ii < m_headerExtraLines.GetCount(); ii++ )
262  {
263  if( ! m_headerExtraLines[ii].IsEmpty() )
264  fprintf( m_outputFile, "%s\n", TO_UTF8( m_headerExtraLines[ii] ) );
265  }
266 
267  // Set coordinate format to 3.6 or 4.5 absolute, leading zero omitted
268  // the number of digits for the integer part of coordinates is needed
269  // in gerber format, but is not very important when omitting leading zeros
270  // It is fixed here to 3 (inch) or 4 (mm), but is not actually used
271  int leadingDigitCount = m_gerberUnitInch ? 3 : 4;
272 
273  fprintf( m_outputFile, "%%FSLAX%d%dY%d%d*%%\n",
274  leadingDigitCount, m_gerberUnitFmt,
275  leadingDigitCount, m_gerberUnitFmt );
276  fprintf( m_outputFile,
277  "G04 Gerber Fmt %d.%d, Leading zero omitted, Abs format (unit %s)*\n",
278  leadingDigitCount, m_gerberUnitFmt,
279  m_gerberUnitInch ? "inch" : "mm" );
280 
281  wxString Title = m_creator + wxT( " " ) + GetBuildVersion();
282 
283  // In gerber files, ASCII7 chars only are allowed.
284  // So use a ISO date format (using a space as separator between date and time),
285  // not a localized date format
286  wxDateTime date = wxDateTime::Now();
287  fprintf( m_outputFile, "G04 Created by KiCad (%s) date %s*\n",
288  TO_UTF8( Title ), TO_UTF8( date.FormatISOCombined( ' ') ) );
289 
290  /* Mass parameter: unit = INCHES/MM */
291  if( m_gerberUnitInch )
292  fputs( "%MOIN*%\n", m_outputFile );
293  else
294  fputs( "%MOMM*%\n", m_outputFile );
295 
296  // Be sure the usual dark polarity is selected:
297  fputs( "%LPD*%\n", m_outputFile );
298 
299  // Set initial interpolation mode: always G01 (linear):
300  fputs( "G01*\n", m_outputFile );
301 
302  // Add aperture list start point
303  fputs( "G04 APERTURE LIST*\n", m_outputFile );
304 
305  // Give a minimal value to the default pen size, used to plot items in sketch mode
306  if( m_renderSettings )
307  {
308  const int pen_min = 0.1 * m_IUsPerDecimil * 10000 / 25.4; // for min width = 0.1 mm
310  pen_min ) );
311  }
312 
313  return true;
314 }
bool m_hasApertureChamferedRect
FILE * m_outputFile
Output file.
Definition: plotter.h:590
APER_MACRO_FREEPOLY_LIST m_am_freepoly_list
double m_IUsPerDecimil
Definition: plotter.h:579
wxArrayString m_headerExtraLines
Definition: plotter.h:605
bool m_hasApertureOutline4P
bool m_hasApertureRoundRect
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
wxString GetBuildVersion()
Get the full KiCad version string.
RENDER_SETTINGS * m_renderSettings
Definition: plotter.h:607
int GetDefaultPenWidth() const
wxString m_workFilename
void SetDefaultPenWidth(int aWidth)
wxString m_creator
Definition: plotter.h:599

References APER_MACRO_FREEPOLY_LIST::ClearList(), finalFile, GetBuildVersion(), KIGFX::RENDER_SETTINGS::GetDefaultPenWidth(), m_am_freepoly_list, PLOTTER::m_creator, m_gerberUnitFmt, m_gerberUnitInch, m_hasApertureChamferedRect, m_hasApertureOutline4P, m_hasApertureRotOval, m_hasApertureRotRect, m_hasApertureRoundRect, PLOTTER::m_headerExtraLines, PLOTTER::m_IUsPerDecimil, PLOTTER::m_outputFile, PLOTTER::m_renderSettings, m_workFilename, KIGFX::RENDER_SETTINGS::SetDefaultPenWidth(), TO_UTF8, and workFile.

Referenced by GERBER_WRITER::createDrillFile(), and PLACEFILE_GERBER_WRITER::CreatePlaceFile().

◆ Text()

void GERBER_PLOTTER::Text ( const wxPoint &  aPos,
const COLOR4D aColor,
const wxString &  aText,
double  aOrient,
const wxSize &  aSize,
enum EDA_TEXT_HJUSTIFY_T  aH_justify,
enum EDA_TEXT_VJUSTIFY_T  aV_justify,
int  aPenWidth,
bool  aItalic,
bool  aBold,
bool  aMultilineAllowed = false,
void *  aData = nullptr 
)
overridevirtual

Draw text with the plotter.

Same as GRText, but plot graphic text instead of draw it.

For convenience it accept the color to use for specific plotters (GERBER) aData is used to pass extra parameters.

Parameters
aPosis the text position (according to aH_justify, aV_justify).
aColoris the text color.
aTextis the text to draw.
aOrientis the angle in 0.1 degree.
aSizeis the text size (size.x or size.y can be < 0 for mirrored texts).
aH_justifyis the horizontal justification (Left, center, right).
aV_justifyis the vertical justification (bottom, center, top).
aPenWidthis the line width (if = 0, use plot default line width).
aItalicis the true to simulate an italic font.
aBolduse true to use a bold font Useful only with default width value (aWidth = 0).
aMultilineAlloweduse true to plot text as multiline, otherwise single line.
aDatais a parameter used by some plotters in SetCurrentLineWidth(), not directly used here.

Reimplemented from PLOTTER.

Definition at line 1935 of file GERBER_plotter.cpp.

1940 {
1941  GBR_METADATA* gbr_metadata = static_cast<GBR_METADATA*>( aData );
1942 
1943  if( gbr_metadata )
1944  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1945 
1946  PLOTTER::Text( aPos, aColor, aText, aOrient, aSize, aH_justify, aV_justify, aWidth, aItalic,
1947  aBold, aMultilineAllowed, aData );
1948 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
virtual void Text(const wxPoint &aPos, const COLOR4D &aColor, const wxString &aText, double aOrient, const wxSize &aSize, enum EDA_TEXT_HJUSTIFY_T aH_justify, enum EDA_TEXT_VJUSTIFY_T aV_justify, int aWidth, bool aItalic, bool aBold, bool aMultilineAllowed=false, void *aData=nullptr)
Draw text with the plotter.
Definition: gr_text.cpp:219
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262

References formatNetAttribute(), GBR_METADATA::m_NetlistMetadata, and PLOTTER::Text().

◆ ThickArc()

void GERBER_PLOTTER::ThickArc ( const wxPoint &  centre,
double  StAngle,
double  EndAngle,
int  rayon,
int  width,
OUTLINE_MODE  tracemode,
void *  aData 
)
overridevirtual

Reimplemented from PLOTTER.

Definition at line 1139 of file GERBER_plotter.cpp.

1141 {
1142  GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
1143  SetCurrentLineWidth( width, gbr_metadata );
1144 
1145  if( gbr_metadata )
1146  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1147 
1148  if( tracemode == FILLED )
1149  {
1150  Arc( centre, StAngle, EndAngle, radius, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
1151  }
1152  else
1153  {
1155  Arc( centre, StAngle, EndAngle, radius - ( width - m_currentPenWidth ) / 2, FILL_T::NO_FILL,
1157  Arc( centre, StAngle, EndAngle, radius + ( width - m_currentPenWidth ) / 2, FILL_T::NO_FILL,
1159  }
1160 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
int m_currentPenWidth
Definition: plotter.h:595
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
virtual void Arc(const wxPoint &aCenter, double aStAngle, double aEndAngle, int aRadius, FILL_T aFill, int aWidth=USE_DEFAULT_LINE_WIDTH) override
Generic fallback: arc rendered as a polyline.
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
static const int DO_NOT_SET_LINE_WIDTH
Definition: plotter.h:125

References Arc(), PLOTTER::DO_NOT_SET_LINE_WIDTH, FILLED, formatNetAttribute(), PLOTTER::m_currentPenWidth, GBR_METADATA::m_NetlistMetadata, NO_FILL, SetCurrentLineWidth(), and PLOTTER::USE_DEFAULT_LINE_WIDTH.

◆ ThickCircle()

void GERBER_PLOTTER::ThickCircle ( const wxPoint &  pos,
int  diametre,
int  width,
OUTLINE_MODE  tracemode,
void *  aData 
)
overridevirtual

Reimplemented from PLOTTER.

Definition at line 1193 of file GERBER_plotter.cpp.

1195 {
1196  GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
1197  SetCurrentLineWidth( width, gbr_metadata );
1198 
1199  if( gbr_metadata )
1200  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1201 
1202  if( tracemode == FILLED )
1203  {
1204  Circle( pos, diametre, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
1205  }
1206  else
1207  {
1209  Circle( pos, diametre - (width - m_currentPenWidth), FILL_T::NO_FILL,
1211  Circle( pos, diametre + (width - m_currentPenWidth), FILL_T::NO_FILL,
1213  }
1214 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
int m_currentPenWidth
Definition: plotter.h:595
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
virtual void Circle(const wxPoint &pos, int diametre, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
static const int DO_NOT_SET_LINE_WIDTH
Definition: plotter.h:125

References Circle(), PLOTTER::DO_NOT_SET_LINE_WIDTH, FILLED, formatNetAttribute(), PLOTTER::m_currentPenWidth, GBR_METADATA::m_NetlistMetadata, NO_FILL, SetCurrentLineWidth(), and PLOTTER::USE_DEFAULT_LINE_WIDTH.

◆ ThickRect()

void GERBER_PLOTTER::ThickRect ( const wxPoint &  p1,
const wxPoint &  p2,
int  width,
OUTLINE_MODE  tracemode,
void *  aData 
)
overridevirtual

Reimplemented from PLOTTER.

Definition at line 1163 of file GERBER_plotter.cpp.

1165 {
1166  GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
1167  SetCurrentLineWidth( width, gbr_metadata );
1168 
1169  if( gbr_metadata )
1170  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1171 
1172  if( tracemode == FILLED )
1173  {
1175  }
1176  else
1177  {
1179  wxPoint offsetp1( p1.x - (width - m_currentPenWidth) / 2,
1180  p1.y - (width - m_currentPenWidth) / 2 );
1181  wxPoint offsetp2( p2.x + (width - m_currentPenWidth) / 2,
1182  p2.y + (width - m_currentPenWidth) / 2 );
1183  Rect( offsetp1, offsetp2, FILL_T::NO_FILL, -1 );
1184  offsetp1.x += (width - m_currentPenWidth);
1185  offsetp1.y += (width - m_currentPenWidth);
1186  offsetp2.x -= (width - m_currentPenWidth);
1187  offsetp2.y -= (width - m_currentPenWidth);
1188  Rect( offsetp1, offsetp2, FILL_T::NO_FILL, DO_NOT_SET_LINE_WIDTH );
1189  }
1190 }
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
virtual void Rect(const wxPoint &p1, const wxPoint &p2, FILL_T fill, int width=USE_DEFAULT_LINE_WIDTH) override
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
int m_currentPenWidth
Definition: plotter.h:595
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262
static const int DO_NOT_SET_LINE_WIDTH
Definition: plotter.h:125

References PLOTTER::DO_NOT_SET_LINE_WIDTH, FILLED, formatNetAttribute(), PLOTTER::m_currentPenWidth, GBR_METADATA::m_NetlistMetadata, NO_FILL, Rect(), SetCurrentLineWidth(), and PLOTTER::USE_DEFAULT_LINE_WIDTH.

◆ ThickSegment()

void GERBER_PLOTTER::ThickSegment ( const wxPoint &  start,
const wxPoint &  end,
int  width,
OUTLINE_MODE  tracemode,
void *  aData 
)
overridevirtual

Reimplemented from PLOTTER.

Definition at line 1118 of file GERBER_plotter.cpp.

1120 {
1121  if( tracemode == FILLED )
1122  {
1123  GBR_METADATA *gbr_metadata = static_cast<GBR_METADATA*>( aData );
1124  SetCurrentLineWidth( width, gbr_metadata );
1125 
1126  if( gbr_metadata )
1127  formatNetAttribute( &gbr_metadata->m_NetlistMetadata );
1128 
1129  MoveTo( start );
1130  FinishTo( end );
1131  }
1132  else
1133  {
1135  segmentAsOval( start, end, width, tracemode );
1136  }
1137 }
void segmentAsOval(const wxPoint &start, const wxPoint &end, int width, OUTLINE_MODE tracemode)
Convert a thick segment and plot it as an oval.
Definition: plotter.cpp:454
void FinishTo(const wxPoint &pos)
Definition: plotter.h:273
void formatNetAttribute(GBR_NETLIST_METADATA *aData)
Print a Gerber net attribute object record.
static const int USE_DEFAULT_LINE_WIDTH
Definition: plotter.h:126
virtual void SetCurrentLineWidth(int width, void *aData=nullptr) override
Set the line width for the next drawing.
Metadata which can be added in a gerber file as attribute in X2 format.
Definition: gbr_metadata.h:204
void MoveTo(const wxPoint &pos)
Definition: plotter.h:263
GBR_NETLIST_METADATA m_NetlistMetadata
An item to handle object attribute.
Definition: gbr_metadata.h:262

References FILLED, PLOTTER::FinishTo(), formatNetAttribute(), GBR_METADATA::m_NetlistMetadata, PLOTTER::MoveTo(), PLOTTER::segmentAsOval(), SetCurrentLineWidth(), and PLOTTER::USE_DEFAULT_LINE_WIDTH.

Referenced by GERBER_WRITER::createDrillFile().

◆ userToDeviceCoordinates()

DPOINT PLOTTER::userToDeviceCoordinates ( const wxPoint &  aCoordinate)
protectedvirtualinherited

Modify coordinates according to the orientation, scale factor, and offsets trace.

Also convert from a wxPoint to DPOINT, since some output engines needs floating point coordinates.

Definition at line 92 of file plotter.cpp.

93 {
94  wxPoint pos = aCoordinate - m_plotOffset;
95 
96  double x = pos.x * m_plotScale;
97  double y = ( m_paperSize.y - pos.y * m_plotScale );
98 
99  if( m_plotMirror )
100  {
102  x = ( m_paperSize.x - pos.x * m_plotScale );
103  else
104  y = pos.y * m_plotScale;
105  }
106 
107  if( m_yaxisReversed )
108  y = m_paperSize.y - y;
109 
110  x *= m_iuPerDeviceUnit;
111  y *= m_iuPerDeviceUnit;
112 
113  return DPOINT( x, y );
114 }
double m_iuPerDeviceUnit
Definition: plotter.h:581
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:573
bool m_yaxisReversed
Definition: plotter.h:587
bool m_plotMirror
Definition: plotter.h:584
wxPoint m_plotOffset
Definition: plotter.h:583
VECTOR2< double > DPOINT
Definition: vector2d.h:645
wxSize m_paperSize
Definition: plotter.h:603
bool m_mirrorIsHorizontal
Definition: plotter.h:586

References PLOTTER::m_iuPerDeviceUnit, PLOTTER::m_mirrorIsHorizontal, PLOTTER::m_paperSize, PLOTTER::m_plotMirror, PLOTTER::m_plotOffset, PLOTTER::m_plotScale, and PLOTTER::m_yaxisReversed.

Referenced by DXF_PLOTTER::Arc(), HPGL_PLOTTER::Arc(), PS_PLOTTER::Arc(), PDF_PLOTTER::Arc(), SVG_PLOTTER::Arc(), SVG_PLOTTER::BezierCurve(), DXF_PLOTTER::Circle(), HPGL_PLOTTER::Circle(), PS_PLOTTER::Circle(), PDF_PLOTTER::Circle(), SVG_PLOTTER::Circle(), PSLIKE_PLOTTER::computeTextParameters(), FlashPadChamferRoundRect(), FlashPadCircle(), HPGL_PLOTTER::FlashPadCircle(), FlashPadCustom(), FlashPadOval(), FlashPadRect(), FlashPadRoundRect(), FlashPadTrapez(), FlashRegularPolygon(), PenTo(), DXF_PLOTTER::PenTo(), HPGL_PLOTTER::PenTo(), PS_PLOTTER::PenTo(), PDF_PLOTTER::PenTo(), SVG_PLOTTER::PenTo(), plotArc(), PS_PLOTTER::PlotImage(), PDF_PLOTTER::PlotImage(), HPGL_PLOTTER::PlotPoly(), PS_PLOTTER::PlotPoly(), PDF_PLOTTER::PlotPoly(), SVG_PLOTTER::PlotPoly(), HPGL_PLOTTER::Rect(), PS_PLOTTER::Rect(), PDF_PLOTTER::Rect(), SVG_PLOTTER::Rect(), DXF_PLOTTER::Text(), PS_PLOTTER::Text(), and SVG_PLOTTER::Text().

◆ userToDeviceSize() [1/2]

◆ userToDeviceSize() [2/2]

double PLOTTER::userToDeviceSize ( double  size) const
protectedvirtualinherited

Modify size according to the plotter scale factors (simple double version).

Definition at line 124 of file plotter.cpp.

125 {
126  return size * m_plotScale * m_iuPerDeviceUnit;
127 }
double m_iuPerDeviceUnit
Definition: plotter.h:581
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:573

References PLOTTER::m_iuPerDeviceUnit, and PLOTTER::m_plotScale.

◆ UseX2format()

void GERBER_PLOTTER::UseX2format ( bool  aEnable)
inline

◆ UseX2NetAttributes()

void GERBER_PLOTTER::UseX2NetAttributes ( bool  aEnable)
inline

◆ writeApertureList()

void GERBER_PLOTTER::writeApertureList ( )
protected

Generate the table of D codes.

Definition at line 569 of file GERBER_plotter.cpp.

570 {
571  wxASSERT( m_outputFile );
572  char cbuf[1024];
573  std::string buffer;
574 
575  bool useX1StructuredComment = false;
576 
577  if( !m_useX2format )
578  useX1StructuredComment = true;
579 
580  // Init
581  for( APERTURE& tool : m_apertures )
582  {
583  // aperture sizes are in inch or mm, regardless the
584  // coordinates format
585  double fscale = 0.0001 * m_plotScale / m_IUsPerDecimil; // inches
586 
587  if(! m_gerberUnitInch )
588  fscale *= 25.4; // size in mm
589 
590  int attribute = tool.m_ApertureAttribute;
591 
592  if( attribute != m_apertureAttribute )
593  {
596  useX1StructuredComment ).c_str(), m_outputFile );
597  }
598 
599  sprintf( cbuf, "%%ADD%d", tool.m_DCode );
600  buffer = cbuf;
601 
602  /* Please note: the Gerber specs for mass parameters say that
603  exponential syntax is *not* allowed and the decimal point should
604  also be always inserted. So the %g format is ruled out, but %f is fine
605  (the # modifier forces the decimal point). Sadly the %f formatter
606  can't remove trailing zeros but that's not a problem, since nothing
607  forbid it (the file is only slightly longer) */
608 
609  switch( tool.m_Type )
610  {
611  case APERTURE::AT_CIRCLE:
612  sprintf( cbuf, "C,%#f*%%\n", tool.GetDiameter() * fscale );
613  break;
614 
615  case APERTURE::AT_RECT:
616  sprintf( cbuf, "R,%#fX%#f*%%\n", tool.m_Size.x * fscale,
617  tool.m_Size.y * fscale );
618  break;
619 
621  sprintf( cbuf, "C,%#f*%%\n", tool.m_Size.x * fscale );
622  break;
623 
624  case APERTURE::AT_OVAL:
625  sprintf( cbuf, "O,%#fX%#f*%%\n", tool.m_Size.x * fscale,
626  tool.m_Size.y * fscale );
627  break;
628 
640  sprintf( cbuf, "P,%#fX%dX%#f*%%\n", tool.GetDiameter() * fscale,
641  tool.GetRegPolyVerticeCount(), tool.GetRotation() );
642  break;
643 
644  case APERTURE::AM_ROUND_RECT: // Aperture macro for round rect pads
645  {
646  // The aperture macro needs coordinates of the centers of the 4 corners
647  std::vector<VECTOR2I> corners;
648  wxSize half_size( tool.m_Size.x/2-tool.m_Radius, tool.m_Size.y/2-tool.m_Radius );
649 
650  corners.emplace_back( -half_size.x, -half_size.y );
651  corners.emplace_back( half_size.x, -half_size.y );
652  corners.emplace_back( half_size.x, half_size.y );
653  corners.emplace_back( -half_size.x, half_size.y );
654 
655  // Rotate the corner coordinates:
656  for( int ii = 0; ii < 4; ii++ )
657  RotatePoint( corners[ii], -tool.m_Rotation*10.0 );
658 
659  sprintf( cbuf, "%s,%#fX", APER_MACRO_ROUNDRECT_NAME,
660  tool.m_Radius * fscale );
661  buffer += cbuf;
662 
663  // Add each corner
664  for( int ii = 0; ii < 4; ii++ )
665  {
666  sprintf( cbuf, "%#fX%#fX",
667  corners[ii].x * fscale, corners[ii].y * fscale );
668  buffer += cbuf;
669  }
670 
671  sprintf( cbuf, "0*%%\n" );
672  }
673  break;
674 
675  case APERTURE::AM_ROT_RECT: // Aperture macro for rotated rect pads
676  sprintf( cbuf, "%s,%#fX%#fX%#f*%%\n", APER_MACRO_ROT_RECT_NAME,
677  tool.m_Size.x * fscale, tool.m_Size.y * fscale,
678  tool.m_Rotation );
679  break;
680 
681  case APERTURE::APER_MACRO_OUTLINE4P: // Aperture macro for trapezoid pads
682  case APERTURE::APER_MACRO_OUTLINE5P: // Aperture macro for chamfered rect pads
683  case APERTURE::APER_MACRO_OUTLINE6P: // Aperture macro for chamfered rect pads
684  case APERTURE::APER_MACRO_OUTLINE7P: // Aperture macro for chamfered rect pads
685  case APERTURE::APER_MACRO_OUTLINE8P: // Aperture macro for chamfered rect pads
686  switch( tool.m_Type )
687  {
689  sprintf( cbuf, "%s,", APER_MACRO_OUTLINE4P_NAME ); break;
691  sprintf( cbuf, "%s,", APER_MACRO_OUTLINE5P_NAME ); break;
693  sprintf( cbuf, "%s,", APER_MACRO_OUTLINE6P_NAME ); break;
695  sprintf( cbuf, "%s,", APER_MACRO_OUTLINE7P_NAME ); break;
697  sprintf( cbuf, "%s,", APER_MACRO_OUTLINE8P_NAME ); break;
698  default:
699  break;
700  }
701 
702  buffer += cbuf;
703 
704  // Output all corners (should be 4 to 8 corners)
705  // Remember: the Y coordinate must be negated, due to the fact in Pcbnew
706  // the Y axis is from top to bottom
707  for( size_t ii = 0; ii < tool.m_Corners.size(); ii++ )
708  {
709  sprintf( cbuf, "%#fX%#fX",
710  tool.m_Corners[ii].x * fscale, -tool.m_Corners[ii].y * fscale );
711  buffer += cbuf;
712  }
713 
714  // close outline and output rotation
715  sprintf( cbuf, "%#f*%%\n", tool.m_Rotation );
716  break;
717 
718  case APERTURE::AM_ROTATED_OVAL: // Aperture macro for rotated oval pads
719  // (not rotated is a primitive)
720  // m_Size.x = full length; m_Size.y = width, and the macro aperture expects
721  // the position of ends
722  {
723  // the seg_len is the distance between the 2 circle centers
724  int seg_len = tool.m_Size.x - tool.m_Size.y;
725  // Center of the circle on the segment start point:
726  VECTOR2I start( seg_len/2, 0 );
727  // Center of the circle on the segment end point:
728  VECTOR2I end( - seg_len/2, 0 );
729 
730  RotatePoint( start, tool.m_Rotation*10.0 );
731  RotatePoint( end, tool.m_Rotation*10.0 );
732 
733  sprintf( cbuf, "%s,%#fX%#fX%#fX%#fX%#fX0*%%\n", APER_MACRO_SHAPE_OVAL_NAME,
734  tool.m_Size.y * fscale, // width
735  start.x * fscale, -start.y * fscale, // X,Y corner start pos
736  end.x * fscale, -end.y * fscale ); // X,Y cornerend pos
737  }
738  break;
739 
741  {
742  // Find the aperture macro name in the list of aperture macro
743  // created on the fly for this polygon:
744  int idx = m_am_freepoly_list.FindAm( tool.m_Corners );
745 
746  // Write DCODE id ( "%ADDxx" is already in buffer) and rotation
747  // the full line is something like :%ADD12FreePoly1,45.000000*%
748  sprintf( cbuf, "%s%d,%#f*%%\n", AM_FREEPOLY_BASENAME, idx, tool.m_Rotation );
749  break;
750  }
751  }
752 
753  buffer += cbuf;
754  fputs( buffer.c_str(), m_outputFile );
755 
756  m_apertureAttribute = attribute;
757 
758  // Currently reset the aperture attribute. Perhaps a better optimization
759  // is to store the last attribute
760  if( attribute )
761  {
762  if( m_useX2format )
763  fputs( "%TD*%\n", m_outputFile );
764  else
765  fputs( "G04 #@! TD*\n", m_outputFile );
766 
768  }
769 
770  }
771 }
#define APER_MACRO_ROUNDRECT_NAME
#define APER_MACRO_SHAPE_OVAL_NAME
FILE * m_outputFile
Output file.
Definition: plotter.h:590
#define APER_MACRO_OUTLINE7P_NAME
APER_MACRO_FREEPOLY_LIST m_am_freepoly_list
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:229
double m_IUsPerDecimil
Definition: plotter.h:579
double m_plotScale
Plot scale - chosen by the user (even implicitly with 'fit in a4')
Definition: plotter.h:573
std::vector< APERTURE > m_apertures
#define APER_MACRO_OUTLINE5P_NAME
#define APER_MACRO_OUTLINE8P_NAME
#define APER_MACRO_ROT_RECT_NAME
#define AM_FREEPOLY_BASENAME
static std::string FormatAttribute(GBR_APERTURE_ATTRIB aAttribute, bool aUseX1StructuredComment)
#define APER_MACRO_OUTLINE4P_NAME
int FindAm(const std::vector< wxPoint > &aPolygon) const
#define APER_MACRO_OUTLINE6P_NAME

References APERTURE::AM_FREE_POLYGON, AM_FREEPOLY_BASENAME, APERTURE::AM_ROT_RECT, APERTURE::AM_ROTATED_OVAL, APERTURE::AM_ROUND_RECT, APERTURE::APER_MACRO_OUTLINE4P, APER_MACRO_OUTLINE4P_NAME, APERTURE::APER_MACRO_OUTLINE5P, APER_MACRO_OUTLINE5P_NAME, APERTURE::APER_MACRO_OUTLINE6P, APER_MACRO_OUTLINE6P_NAME, APERTURE::APER_MACRO_OUTLINE7P, APER_MACRO_OUTLINE7P_NAME, APERTURE::APER_MACRO_OUTLINE8P, APER_MACRO_OUTLINE8P_NAME, APER_MACRO_ROT_RECT_NAME, APER_MACRO_ROUNDRECT_NAME, APER_MACRO_SHAPE_OVAL_NAME, APERTURE::AT_CIRCLE, APERTURE::AT_OVAL, APERTURE::AT_PLOTTING, APERTURE::AT_RECT, APERTURE::AT_REGULAR_POLY, APERTURE::AT_REGULAR_POLY10, APERTURE::AT_REGULAR_POLY11, APERTURE::AT_REGULAR_POLY12, APERTURE::AT_REGULAR_POLY3, APERTURE::AT_REGULAR_POLY4, APERTURE::AT_REGULAR_POLY5, APERTURE::AT_REGULAR_POLY6, APERTURE::AT_REGULAR_POLY7, APERTURE::AT_REGULAR_POLY8, APERTURE::AT_REGULAR_POLY9, APER_MACRO_FREEPOLY_LIST::FindAm(), GBR_APERTURE_METADATA::FormatAttribute(), m_am_freepoly_list, m_apertureAttribute, m_apertures, m_gerberUnitInch, PLOTTER::m_IUsPerDecimil, PLOTTER::m_outputFile, PLOTTER::m_plotScale, m_useX2format, RotatePoint(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EndPlot().

Member Data Documentation

◆ DO_NOT_SET_LINE_WIDTH

◆ finalFile

FILE* GERBER_PLOTTER::finalFile
protected

Definition at line 345 of file plotter_gerber.h.

Referenced by EndPlot(), GERBER_PLOTTER(), and StartPlot().

◆ m_am_freepoly_list

APER_MACRO_FREEPOLY_LIST GERBER_PLOTTER::m_am_freepoly_list
protected

Definition at line 379 of file plotter_gerber.h.

Referenced by EndPlot(), GetOrCreateAperture(), StartPlot(), and writeApertureList().

◆ m_apertureAttribute

int GERBER_PLOTTER::m_apertureAttribute
protected

Definition at line 342 of file plotter_gerber.h.

Referenced by GERBER_PLOTTER(), and writeApertureList().

◆ m_apertures

std::vector<APERTURE> GERBER_PLOTTER::m_apertures
protected

Definition at line 353 of file plotter_gerber.h.

Referenced by GetOrCreateAperture(), selectAperture(), and writeApertureList().

◆ m_colorMode

◆ m_creator

wxString PLOTTER::m_creator
protectedinherited

◆ m_currentApertureIdx

int GERBER_PLOTTER::m_currentApertureIdx
protected

Definition at line 354 of file plotter_gerber.h.

Referenced by GERBER_PLOTTER(), and selectAperture().

◆ m_currentPenWidth

◆ m_filename

wxString PLOTTER::m_filename
protectedinherited

◆ m_gerberDisableApertMacros

bool GERBER_PLOTTER::m_gerberDisableApertMacros
protected

◆ m_gerberUnitFmt

int GERBER_PLOTTER::m_gerberUnitFmt
protected

◆ m_gerberUnitInch

bool GERBER_PLOTTER::m_gerberUnitInch
protected

◆ m_hasApertureChamferedRect

bool GERBER_PLOTTER::m_hasApertureChamferedRect
protected

Definition at line 360 of file plotter_gerber.h.

Referenced by EndPlot(), FlashPadChamferRoundRect(), GERBER_PLOTTER(), and StartPlot().

◆ m_hasApertureOutline4P

bool GERBER_PLOTTER::m_hasApertureOutline4P
protected

◆ m_hasApertureRotOval

bool GERBER_PLOTTER::m_hasApertureRotOval
protected

Definition at line 356 of file plotter_gerber.h.

Referenced by EndPlot(), FlashPadOval(), GERBER_PLOTTER(), and StartPlot().

◆ m_hasApertureRotRect

bool GERBER_PLOTTER::m_hasApertureRotRect
protected

Definition at line 357 of file plotter_gerber.h.

Referenced by EndPlot(), FlashPadRect(), GERBER_PLOTTER(), and StartPlot().

◆ m_hasApertureRoundRect

bool GERBER_PLOTTER::m_hasApertureRoundRect
protected

Definition at line 355 of file plotter_gerber.h.

Referenced by EndPlot(), FlashPadRoundRect(), GERBER_PLOTTER(), and StartPlot().

◆ m_headerExtraLines

wxArrayString PLOTTER::m_headerExtraLines
protectedinherited

Definition at line 605 of file plotter.h.

Referenced by PLOTTER::AddLineToHeader(), PLOTTER::ClearHeaderLinesList(), and StartPlot().

◆ m_iuPerDeviceUnit

◆ m_IUsPerDecimil

◆ m_mirrorIsHorizontal

bool PLOTTER::m_mirrorIsHorizontal
protectedinherited

◆ m_negativeMode

bool PLOTTER::m_negativeMode
protectedinherited

Definition at line 594 of file plotter.h.

Referenced by PLOTTER::PLOTTER(), PSLIKE_PLOTTER::SetColor(), and PLOTTER::SetNegative().

◆ m_objectAttributesDictionary

std::string GERBER_PLOTTER::m_objectAttributesDictionary
protected

Definition at line 339 of file plotter_gerber.h.

Referenced by ClearAllAttributes(), clearNetAttribute(), and formatNetAttribute().

◆ m_outputFile

FILE* PLOTTER::m_outputFile
protectedinherited

Output file.

Definition at line 590 of file plotter.h.

Referenced by DXF_PLOTTER::Arc(), HPGL_PLOTTER::Arc(), PS_PLOTTER::Arc(), SVG_PLOTTER::Arc(), SVG_PLOTTER::BezierCurve(), HPGL_PLOTTER::Circle(), DXF_PLOTTER::Circle(), PS_PLOTTER::Circle(), SVG_PLOTTER::Circle(), ClearAllAttributes(), clearNetAttribute(), PDF_PLOTTER::ClosePage(), PDF_PLOTTER::closePdfObject(), PDF_PLOTTER::closePdfStream(), emitDcode(), PS_PLOTTER::emitSetRGBColor(), SVG_PLOTTER::EndBlock(), EndPlot(), DXF_PLOTTER::EndPlot(), HPGL_PLOTTER::EndPlot(), PS_PLOTTER::EndPlot(), PDF_PLOTTER::EndPlot(), SVG_PLOTTER::EndPlot(), DXF_PLOTTER::FlashPadCircle(), HPGL_PLOTTER::FlashPadCircle(), PSLIKE_PLOTTER::FlashPadOval(), FlashPadOval(), HPGL_PLOTTER::FlashPadOval(), DXF_PLOTTER::FlashPadOval(), FlashPadRect(), DXF_PLOTTER::FlashPadRect(), FlashPadRoundRect(), DXF_PLOTTER::FlashPadTrapez(), formatNetAttribute(), PLOTTER::OpenFile(), PDF_PLOTTER::OpenFile(), PenTo(), DXF_PLOTTER::PenTo(), HPGL_PLOTTER::PenTo(), PS_PLOTTER::PenTo(), SVG_PLOTTER::PenTo(), plotArc(), PlotGerberRegion(), PS_PLOTTER::PlotImage(), SVG_PLOTTER::PlotImage(), PlotPoly(), PS_PLOTTER::PlotPoly(), SVG_PLOTTER::PlotPoly(), plotRoundRectAsRegion(), PLOTTER::PLOTTER(), DXF_PLOTTER::Rect(), HPGL_PLOTTER::Rect(), PS_PLOTTER::Rect(), SVG_PLOTTER::Rect(), selectAperture(), PS_PLOTTER::SetCurrentLineWidth(), PS_PLOTTER::SetDash(), SetLayerPolarity(), SVG_PLOTTER::setSVGPlotStyle(), PS_PLOTTER::SetViewport(), SVG_PLOTTER::StartBlock(), PDF_PLOTTER::StartPage(), PDF_PLOTTER::startPdfObject(), PDF_PLOTTER::startPdfStream(), StartPlot(), DXF_PLOTTER::StartPlot(), HPGL_PLOTTER::StartPlot(), PS_PLOTTER::StartPlot(), PDF_PLOTTER::StartPlot(), SVG_PLOTTER::StartPlot(), DXF_PLOTTER::Text(), PS_PLOTTER::Text(), SVG_PLOTTER::Text(), HPGL_PLOTTER::ThickSegment(), writeApertureList(), and PLOTTER::~PLOTTER().

◆ m_pageInfo

◆ m_paperSize

◆ m_penLastpos

wxPoint PLOTTER::m_penLastpos
protectedinherited

◆ m_penState

char PLOTTER::m_penState
protectedinherited

◆ m_plotMirror

◆ m_plotOffset

◆ m_plotScale

double PLOTTER::m_plotScale
protectedinherited

◆ m_renderSettings

◆ m_title

wxString PLOTTER::m_title
protectedinherited

Definition at line 601 of file plotter.h.

Referenced by PDF_PLOTTER::EndPlot(), PLOTTER::SetTitle(), and PS_PLOTTER::StartPlot().

◆ m_useNetAttributes

bool GERBER_PLOTTER::m_useNetAttributes
protected

Definition at line 371 of file plotter_gerber.h.

Referenced by formatNetAttribute(), GERBER_PLOTTER(), and UseX2NetAttributes().

◆ m_useX2format

bool GERBER_PLOTTER::m_useX2format
protected

◆ m_workFilename

wxString GERBER_PLOTTER::m_workFilename
protected

Definition at line 346 of file plotter_gerber.h.

Referenced by EndPlot(), and StartPlot().

◆ m_yaxisReversed

bool PLOTTER::m_yaxisReversed
protectedinherited

◆ MARKER_COUNT

const unsigned PLOTTER::MARKER_COUNT = 58
staticinherited

Draw a marker (used for the drill map).

Definition at line 436 of file plotter.h.

Referenced by PLOTTER::Marker().

◆ USE_DEFAULT_LINE_WIDTH

◆ workFile

FILE* GERBER_PLOTTER::workFile
protected

Definition at line 344 of file plotter_gerber.h.

Referenced by EndPlot(), GERBER_PLOTTER(), and StartPlot().


The documentation for this class was generated from the following files: