LibrePCB Developers Documentation
GerberApertureList Class Referencefinal

A helper class to generate the aperture definitions for a Gerber file. More...

#include <gerberaperturelist.h>

+ Collaboration diagram for GerberApertureList:

Public Types

using Function = tl::optional< GerberAttribute::ApertureFunction >
 

Public Member Functions

 GerberApertureList () noexcept
 
 GerberApertureList (const GerberApertureList &other)=delete
 
 ~GerberApertureList () noexcept
 
QString generateString () const noexcept
 Generate the aperture definitions string. More...
 
int addCircle (const UnsignedLength &dia, Function function)
 Add a circle aperture. More...
 
int addObround (const PositiveLength &w, const PositiveLength &h, const Angle &rot, Function function) noexcept
 Add an obround aperture. More...
 
int addRect (const PositiveLength &w, const PositiveLength &h, const UnsignedLength &r, const Angle &rot, Function function) noexcept
 Add a rectangular aperture. More...
 
int addOctagon (const PositiveLength &w, const PositiveLength &h, const UnsignedLength &r, const Angle &rot, Function function) noexcept
 Add an octagon aperture. More...
 
int addOutline (const StraightAreaPath &path, const Angle &rot, Function function) noexcept
 Add a custom outline aperture. More...
 
int addComponentMain () noexcept
 Add a component main aperture (for component layers only) More...
 
int addComponentPin (bool isPin1) noexcept
 Add a component pin aperture (for component layers only) More...
 
GerberApertureListoperator= (const GerberApertureList &rhs)=delete
 

Private Member Functions

int addOutline (const QString &name, const Path &path, const Angle &rot, Function function) noexcept
 Add a custom outline aperture. More...
 
QString buildOutlineMacro (Path path, const Angle &rot) const noexcept
 Internal helper for addOutline() More...
 
int addAperture (QString aperture, Function function) noexcept
 Helper method to actually add a new or get an existing aperture. More...
 

Private Attributes

QMap< int, std::pair< Function, QString > > mApertures
 

Detailed Description

A helper class to generate the aperture definitions for a Gerber file.

The class provides methods to add certain apertures. Identical Apertures are added only once, i.e. if you call addCircle() multiple times with a diameter of 1mm, only one circle aperture of 1mm is created.

In addition, methods will always create the most simple aperture which represents the desired image. For example, if you call addObround() with both width and height set to the same value, a circle aperture is added instead of an obround (and the rotation parameter is ignored).

Warning
The implementation of this class is very critical for generating correct Gerber files widely compatible with CAM software used by PCB fabricators. A lot of know how is contained in the implementtion to avoid issues with PCB fabricators. When changing anything here, read the Gerber specs very carefully, follow their recommendations and try to determine the compatibility with CAM software like CAM350 or Generis2000. In addition, add unit tests for each new requirement.

Member Typedef Documentation

◆ Function

Constructor & Destructor Documentation

◆ GerberApertureList() [1/2]

GerberApertureList ( )
noexcept

◆ GerberApertureList() [2/2]

GerberApertureList ( const GerberApertureList other)
delete

◆ ~GerberApertureList()

~GerberApertureList ( )
noexcept

Member Function Documentation

◆ generateString()

QString generateString ( ) const
noexcept

Generate the aperture definitions string.

Returns
String containing 0..n lines
+ Here is the call graph for this function:

◆ addCircle()

int addCircle ( const UnsignedLength dia,
Function  function 
)

Add a circle aperture.

Parameters
diaCircle diameter. According Gerber specs, it's allowed to create a circle with a diameter of zero.
functionFunction attribute.
Returns
Aperture number.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addObround()

int addObround ( const PositiveLength w,
const PositiveLength h,
const Angle rot,
Function  function 
)
noexcept

Add an obround aperture.

Note
If w==h, a circle aperture will be created.
Parameters
wTotal width.
hTotal height.
rotRotation.
functionFunction attribute.
Returns
Aperture number.
+ Here is the call graph for this function:

◆ addRect()

int addRect ( const PositiveLength w,
const PositiveLength h,
const UnsignedLength r,
const Angle rot,
Function  function 
)
noexcept

Add a rectangular aperture.

Parameters
wWidth.
hHeight.
rCorner radius.
rotRotation.
functionFunction attribute.
Returns
Aperture number.
+ Here is the call graph for this function:

◆ addOctagon()

int addOctagon ( const PositiveLength w,
const PositiveLength h,
const UnsignedLength r,
const Angle rot,
Function  function 
)
noexcept

Add an octagon aperture.

Parameters
wWidth.
hHeight.
rCorner radius.
rotRotation.
functionFunction attribute.
Returns
Aperture number.
+ Here is the call graph for this function:

◆ addOutline() [1/2]

int addOutline ( const StraightAreaPath path,
const Angle rot,
Function  function 
)
noexcept

Add a custom outline aperture.

Parameters
pathThe vertices.
rotRotation.
functionFunction attribute.
Returns
Aperture number.

◆ addComponentMain()

int addComponentMain ( )
noexcept

Add a component main aperture (for component layers only)

Returns
Aperture number.
+ Here is the call graph for this function:

◆ addComponentPin()

int addComponentPin ( bool  isPin1)
noexcept

Add a component pin aperture (for component layers only)

Parameters
isPin1Whether the aperture is for pin 1 or another pin.
Returns
Aperture number.

◆ operator=()

GerberApertureList & operator= ( const GerberApertureList rhs)
delete

◆ addOutline() [2/2]

int addOutline ( const QString &  name,
const Path path,
const Angle rot,
Function  function 
)
privatenoexcept

Add a custom outline aperture.

Parameters
nameMacro name (use only characters A..Z!).
pathThe vertices. ATTENTION: After closing the path, it must contain at least 4 vertices and it must not contain any arc segment (i.e. all angles must be zero)!!!
rotRotation.
functionFunction attribute.
Returns
Aperture number.

◆ buildOutlineMacro()

QString buildOutlineMacro ( Path  path,
const Angle rot 
) const
privatenoexcept

Internal helper for addOutline()

Parameters
pathThe vertices. ATTENTION: After closing the path, it must contain at least 4 vertices and it must not contain any arc segment (i.e. all angles must be zero)!!!
rotRotation.
Returns
Aperture macro content.
+ Here is the call graph for this function:

◆ addAperture()

int addAperture ( QString  aperture,
Function  function 
)
privatenoexcept

Helper method to actually add a new or get an existing aperture.

Note
If the same aperture already exists, nothing is added and the number of the existing aperture is returned.
Parameters
apertureThe full content of the aperture to add (except the X2 attributes).
functionFunction attribute.
Returns
Aperture number.
+ Here is the caller graph for this function:

Member Data Documentation

◆ mApertures

QMap<int, std::pair<Function, QString> > mApertures
private

Added apertures

  • key: Aperture number (>= 10).
  • value: Aperture function and definition, with the placeholder "{}" instead of the aperture number. Needs to be substituted by the aperture number when serializing.

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