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 Angle &rot, Function function) noexcept
 Add a rectangular aperture. More...
 
int addOctagon (const PositiveLength &w, const PositiveLength &h, const Angle &rot, Function function) noexcept
 Add an octagon aperture. More...
 
GerberApertureListoperator= (const GerberApertureList &rhs)=delete
 

Private Member Functions

int addOutline (const QString &name, Path path, const Angle &rot, Function function) noexcept
 Add a custom outline aperture. 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 Angle rot,
Function  function 
)
noexcept

Add a rectangular aperture.

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

◆ addOctagon()

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

Add an octagon aperture.

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

◆ operator=()

GerberApertureList& operator= ( const GerberApertureList rhs)
delete

◆ addOutline()

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

Add a custom outline aperture.

Note
This is private because it does not implement proper error handling yet, so you could create invalid Gerber files when passing invalid parameters! Let's implement proper error handling once we need to make it public.
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.
+ Here is the call graph for this function:
+ Here is the caller 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: