KiCad PCB EDA Suite
APERTURE_MACRO Class Reference

Support the "aperture macro" defined within standard RS274X. More...

#include <aperture_macro.h>

Public Member Functions

 APERTURE_MACRO ()
 
double GetLocalParam (const D_CODE *aDcode, unsigned aParamId) const
 Usually, parameters are defined inside the aperture primitive using immediate mode or deferred mode. More...
 
void InitLocalParams (const D_CODE *aDcode)
 Init m_localParamValues to a initial values coming from aDcode and clear m_paramLevelEval must be called once before trying to build the aperture macro shape corresponding to aDcode. More...
 
void EvalLocalParams (const AM_PRIMITIVE &aPrimitive)
 Evaluate m_localParamValues from current m_paramLevelEval to aPrimitive m_LocalParamLevel if m_paramLevelEval >= m_LocalParamLevel, do nothing after call, m_paramLevelEval = m_LocalParamLevel. More...
 
double GetLocalParamValue (int aIndex)
 
SHAPE_POLY_SETGetApertureMacroShape (const GERBER_DRAW_ITEM *aParent, const VECTOR2I &aShapePos)
 Calculate the primitive shape for flashed items. More...
 
void AddPrimitiveToList (AM_PRIMITIVE &aPrimitive)
 Add a new ptimitive ( AMP_CIRCLE, AMP_LINE2 ...) to the list of primitives to define the full shape of the aperture macro. More...
 
void AddLocalParamDefToStack ()
 A deferred parameter can be defined in aperture macro, but outside aperture primitives. More...
 
AM_PARAMGetLastLocalParamDefFromStack ()
 

Public Attributes

wxString m_AmName
 The name of the aperture macro as defined like AMVB_RECTANGLE* (name is VB_RECTANGLE) More...
 

Private Attributes

std::vector< AM_PRIMITIVEm_primitivesList
 A list of AM_PRIMITIVEs to define the shape of the aperture macro. More...
 
AM_PARAMS m_localParamStack
 m_localparamStack handle a list of local deferred parameters More...
 
std::map< int, double > m_localParamValues
 m_localParamValues is the current value of local parameters after evaluation the key is the local param id (from $n) and the value is double More...
 
int m_paramLevelEval
 the current level of local param values evaluation when a primitive is evaluated, if its m_LocalParamLevel is smaller than m_paramLevelEval, all local params must be evaluated from current m_paramLevelEval upto m_LocalParamLevel before use in this primitive More...
 
SHAPE_POLY_SET m_shape
 The shape of the item, calculated by GetApertureMacroShape. More...
 

Detailed Description

Support the "aperture macro" defined within standard RS274X.

Definition at line 68 of file aperture_macro.h.

Constructor & Destructor Documentation

◆ APERTURE_MACRO()

APERTURE_MACRO::APERTURE_MACRO ( )
inline

Definition at line 71 of file aperture_macro.h.

71 :
73 {}
int m_paramLevelEval
the current level of local param values evaluation when a primitive is evaluated, if its m_LocalParam...

Member Function Documentation

◆ AddLocalParamDefToStack()

void APERTURE_MACRO::AddLocalParamDefToStack ( )

A deferred parameter can be defined in aperture macro, but outside aperture primitives.

Example AMRECTHERM* $4=$3/2* parameter $4 is half value of parameter $3

Definition at line 91 of file aperture_macro.cpp.

92{
93 m_localParamStack.push_back( AM_PARAM() );
94}
Hold a parameter value for an "aperture macro" as defined within standard RS274X.
Definition: am_param.h:285
AM_PARAMS m_localParamStack
m_localparamStack handle a list of local deferred parameters

References m_localParamStack.

Referenced by GERBER_FILE_IMAGE::ReadApertureMacro().

◆ AddPrimitiveToList()

void APERTURE_MACRO::AddPrimitiveToList ( AM_PRIMITIVE aPrimitive)

Add a new ptimitive ( AMP_CIRCLE, AMP_LINE2 ...) to the list of primitives to define the full shape of the aperture macro.

Definition at line 85 of file aperture_macro.cpp.

86{
87 m_primitivesList.push_back( aPrimitive );
88 m_primitivesList.back().m_LocalParamLevel = m_localParamStack.size();
89}
std::vector< AM_PRIMITIVE > m_primitivesList
A list of AM_PRIMITIVEs to define the shape of the aperture macro.

References m_localParamStack, and m_primitivesList.

Referenced by GERBER_FILE_IMAGE::ReadApertureMacro().

◆ EvalLocalParams()

void APERTURE_MACRO::EvalLocalParams ( const AM_PRIMITIVE aPrimitive)

Evaluate m_localParamValues from current m_paramLevelEval to aPrimitive m_LocalParamLevel if m_paramLevelEval >= m_LocalParamLevel, do nothing after call, m_paramLevelEval = m_LocalParamLevel.

Definition at line 49 of file aperture_macro.cpp.

50{
51 // Evaluate m_localParamValues from current m_paramLevelEval to
52 // aPrimitive.m_LocalParamLevel
53 // if m_paramLevelEval >= m_LocalParamLevel, do nothing: the
54 // m_localParamValues are already up to date
55
56 if( m_paramLevelEval >= aPrimitive.m_LocalParamLevel )
57 return;
58
60 {
62 int prm_index = am_param.GetIndex();
63
64 double value = am_param.GetValueFromMacro( this );
65
66 // if am_param value is not yet stored in m_localParamValues, add it.
67 // if it is already in m_localParamValues, update its value;
68 m_localParamValues[ prm_index ] = value;
69 }
70}
unsigned GetIndex() const
Definition: am_param.h:309
double GetValueFromMacro(APERTURE_MACRO *aApertureMacro) const
Definition: am_param.cpp:73
int m_LocalParamLevel
Definition: am_primitive.h:98
std::map< int, double > m_localParamValues
m_localParamValues is the current value of local parameters after evaluation the key is the local par...

References AM_PARAM::GetIndex(), AM_PARAM::GetValueFromMacro(), AM_PRIMITIVE::m_LocalParamLevel, m_localParamStack, m_localParamValues, and m_paramLevelEval.

Referenced by AM_PRIMITIVE::ConvertBasicShapeToPolygon().

◆ GetApertureMacroShape()

SHAPE_POLY_SET * APERTURE_MACRO::GetApertureMacroShape ( const GERBER_DRAW_ITEM aParent,
const VECTOR2I aShapePos 
)

Calculate the primitive shape for flashed items.

When an item is flashed, this is the shape of the item.

Returns
the shape of the item.
Parameters
aParentis the parent GERBER_DRAW_ITEM which is actually drawn.
aShapePosis the position of the shape to build.

Definition at line 103 of file aperture_macro.cpp.

105{
106 SHAPE_POLY_SET holeBuffer;
107
109 D_CODE* dcode = aParent->GetDcodeDescr();
110 InitLocalParams( dcode );
111
112 for( AM_PRIMITIVE& prim_macro : m_primitivesList )
113 {
114 if( prim_macro.m_Primitive_id == AMP_COMMENT )
115 continue;
116
117 if( prim_macro.IsAMPrimitiveExposureOn( this ) )
118 {
119 prim_macro.ConvertBasicShapeToPolygon( this, m_shape );
120 }
121 else
122 {
123 prim_macro.ConvertBasicShapeToPolygon( this, holeBuffer );
124
125 if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole
126 {
128 holeBuffer.RemoveAllContours();
129 }
130 }
131 }
132
133 // Merge and cleanup basic shape polygons
135
136 // A hole can be is defined inside a polygon, or the polygons themselve can create
137 // a hole when merged, so we must fracture the polygon to be able to drawn it
138 // (i.e link holes by overlapping edges)
140
141 // Move m_shape to the actual draw position:
142 for( int icnt = 0; icnt < m_shape.OutlineCount(); icnt++ )
143 {
144
145 SHAPE_LINE_CHAIN& outline = m_shape.Outline( icnt );
146
147 for( int jj = 0; jj < outline.PointCount(); jj++ )
148 {
149 VECTOR2I point = outline.CPoint( jj );
150 point += aShapePos;
151 point = aParent->GetABPosition( point );
152 outline.SetPoint( jj, point );
153 }
154 }
155
156 return &m_shape;
157}
@ AMP_COMMENT
Definition: am_primitive.h:71
An aperture macro primitive as given in gerber layer format doc.
Definition: am_primitive.h:92
void InitLocalParams(const D_CODE *aDcode)
Init m_localParamValues to a initial values coming from aDcode and clear m_paramLevelEval must be cal...
SHAPE_POLY_SET m_shape
The shape of the item, calculated by GetApertureMacroShape.
A gerber DCODE (also called Aperture) definition.
Definition: dcode.h:80
D_CODE * GetDcodeDescr() const
Return the GetDcodeDescr of this object, or NULL.
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
Return the image position of aPosition for this object.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
void Fracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
void Simplify(POLYGON_MODE aFastMode)
SHAPE_LINE_CHAIN & Outline(int aIndex)
int OutlineCount() const
Return the number of vertices in a given outline/hole.

References AMP_COMMENT, SHAPE_POLY_SET::BooleanSubtract(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_POLY_SET::Fracture(), GERBER_DRAW_ITEM::GetABPosition(), GERBER_DRAW_ITEM::GetDcodeDescr(), InitLocalParams(), m_primitivesList, m_shape, SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::PM_FAST, SHAPE_LINE_CHAIN::PointCount(), SHAPE_POLY_SET::RemoveAllContours(), SHAPE_LINE_CHAIN::SetPoint(), and SHAPE_POLY_SET::Simplify().

Referenced by D_CODE::ConvertShapeToPolygon(), KIGFX::GERBVIEW_PAINTER::drawApertureMacro(), GBR_TO_PCB_EXPORTER::export_flashed_copper_item(), and fillFlashedGBRITEM().

◆ GetLastLocalParamDefFromStack()

AM_PARAM & APERTURE_MACRO::GetLastLocalParamDefFromStack ( )

Definition at line 97 of file aperture_macro.cpp.

98{
99 return m_localParamStack.back();
100}

References m_localParamStack.

Referenced by GERBER_FILE_IMAGE::ReadApertureMacro().

◆ GetLocalParam()

double APERTURE_MACRO::GetLocalParam ( const D_CODE aDcode,
unsigned  aParamId 
) const

Usually, parameters are defined inside the aperture primitive using immediate mode or deferred mode.

In deferred mode the value is defined in a DCODE that want to use the aperture macro. Some parameters are defined outside the aperture primitive and are local to the aperture macro.

Returns
the value of a deferred parameter defined inside the aperture macro.
Parameters
aDcodeis the D_CODE that uses this aperture macro and define deferred parameters.
aParamIdis the param id (defined by $3 or $5 ..) to evaluate.

◆ GetLocalParamValue()

double APERTURE_MACRO::GetLocalParamValue ( int  aIndex)
Returns
the local param value stored in m_localParamValues
Parameters
aIndexis the param Id (from $n) if not found, returns 0

Definition at line 73 of file aperture_macro.cpp.

74{
75 // return the local param value stored in m_localParamValues
76 // if not existing, returns 0
77
78 if( m_localParamValues.find( aIndex ) != m_localParamValues.end() )
79 return m_localParamValues[ aIndex ];
80
81 return 0.0;
82}

References m_localParamValues.

Referenced by AM_PARAM::GetValueFromMacro().

◆ InitLocalParams()

void APERTURE_MACRO::InitLocalParams ( const D_CODE aDcode)

Init m_localParamValues to a initial values coming from aDcode and clear m_paramLevelEval must be called once before trying to build the aperture macro shape corresponding to aDcode.

Definition at line 35 of file aperture_macro.cpp.

36{
37 // store the initial values coming from aDcode into m_localParamValues
38 // for n parameters, they are local params $1 to $n
39 m_localParamValues.clear();
40
41 // Note: id_param = 1... n, not 0
42 for( unsigned id_param = 1; id_param <= aDcode->GetParamCount(); id_param++ )
43 m_localParamValues[id_param] = aDcode->GetParam( id_param );
44
46}
double GetParam(unsigned aIdx) const
Return a parameter stored in parameter list.
Definition: dcode.h:110
unsigned GetParamCount() const
Return the number of parameters stored in parameter list.
Definition: dcode.h:99

References D_CODE::GetParam(), D_CODE::GetParamCount(), m_localParamValues, and m_paramLevelEval.

Referenced by GetApertureMacroShape().

Member Data Documentation

◆ m_AmName

wxString APERTURE_MACRO::m_AmName

The name of the aperture macro as defined like AMVB_RECTANGLE* (name is VB_RECTANGLE)

Definition at line 126 of file aperture_macro.h.

Referenced by GERBER_FILE_IMAGE::ExecuteRS274XCommand(), APERTURE_MACRO_less_than::operator()(), GERBER_FILE_IMAGE::ReadApertureMacro(), and GERBER_DRAW_ITEM::ShowGBRShape().

◆ m_localParamStack

AM_PARAMS APERTURE_MACRO::m_localParamStack
private

m_localparamStack handle a list of local deferred parameters

Definition at line 152 of file aperture_macro.h.

Referenced by AddLocalParamDefToStack(), AddPrimitiveToList(), EvalLocalParams(), and GetLastLocalParamDefFromStack().

◆ m_localParamValues

std::map<int, double> APERTURE_MACRO::m_localParamValues
private

m_localParamValues is the current value of local parameters after evaluation the key is the local param id (from $n) and the value is double

Definition at line 158 of file aperture_macro.h.

Referenced by EvalLocalParams(), GetLocalParamValue(), and InitLocalParams().

◆ m_paramLevelEval

int APERTURE_MACRO::m_paramLevelEval
private

the current level of local param values evaluation when a primitive is evaluated, if its m_LocalParamLevel is smaller than m_paramLevelEval, all local params must be evaluated from current m_paramLevelEval upto m_LocalParamLevel before use in this primitive

Definition at line 166 of file aperture_macro.h.

Referenced by EvalLocalParams(), and InitLocalParams().

◆ m_primitivesList

std::vector<AM_PRIMITIVE> APERTURE_MACRO::m_primitivesList
private

A list of AM_PRIMITIVEs to define the shape of the aperture macro.

Definition at line 147 of file aperture_macro.h.

Referenced by AddPrimitiveToList(), and GetApertureMacroShape().

◆ m_shape

SHAPE_POLY_SET APERTURE_MACRO::m_shape
private

The shape of the item, calculated by GetApertureMacroShape.

Definition at line 168 of file aperture_macro.h.

Referenced by GetApertureMacroShape().


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