KiCad PCB EDA Suite
APERTURE_MACRO Struct Reference

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

#include <am_primitive.h>

Public Member Functions

double GetLocalParam (const D_CODE *aDcode, unsigned aParamId) const
 Usually, parameters are defined inside the aperture primitive using immediate mode or deferred mode. More...
 
SHAPE_POLY_SETGetApertureMacroShape (const GERBER_DRAW_ITEM *aParent, const VECTOR2I &aShapePos)
 Calculate the primitive shape for flashed items. More...
 
void DrawApertureMacroShape (const GERBER_DRAW_ITEM *aParent, wxDC *aDC, const COLOR4D &aColor, const VECTOR2I &aShapePos, bool aFilledShape)
 Draw the primitive shape for flashed items. More...
 
int GetShapeDim (GERBER_DRAW_ITEM *aParent)
 C. More...
 
BOX2I GetBoundingBox () const
 Return the bounding box of the shape. More...
 

Public Attributes

wxString name
 The name of the aperture macro. More...
 
AM_PRIMITIVES primitives
 A sequence of AM_PRIMITIVEs. More...
 
AM_PARAMS m_localparamStack
 
SHAPE_POLY_SET m_shape
 The shape of the item, calculated by GetApertureMacroShape. More...
 
BOX2I m_boundingBox
 The bounding box of the item, calculated by GetApertureMacroShape. More...
 

Detailed Description

Support the "aperture macro" defined within standard RS274X.

Definition at line 166 of file am_primitive.h.

Member Function Documentation

◆ DrawApertureMacroShape()

void APERTURE_MACRO::DrawApertureMacroShape ( const GERBER_DRAW_ITEM aParent,
wxDC *  aDC,
const COLOR4D aColor,
const VECTOR2I aShapePos,
bool  aFilledShape 
)

Draw the primitive shape for flashed items.

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

Parameters
aParentis the parent GERBER_DRAW_ITEM which is actually drawn.
aDCis the device context.
aColoris the color of shape.
aShapePosis the actual shape position.
aFilledShapeset to true to draw in filled mode, false to draw in sketch mode.

Definition at line 864 of file am_primitive.cpp.

867{
868 SHAPE_POLY_SET* shapeBuffer = GetApertureMacroShape( aParent, aShapePos );
869
870 if( shapeBuffer->OutlineCount() == 0 )
871 return;
872
873 for( int ii = 0; ii < shapeBuffer->OutlineCount(); ii++ )
874 {
875 SHAPE_LINE_CHAIN& poly = shapeBuffer->Outline( ii );
876 GRClosedPoly( aDC, poly.PointCount(), (VECTOR2I*) &poly.CPoint( 0 ), aFilledShape, aColor );
877 }
878}
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
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.
SHAPE_LINE_CHAIN & Outline(int aIndex)
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void GRClosedPoly(wxDC *DC, int n, const VECTOR2I *Points, bool Fill, const COLOR4D &Color)
Draw a closed polyline and fill it if Fill, in object space.
Definition: gr_basic.cpp:342
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, const VECTOR2I &aShapePos)
Calculate the primitive shape for flashed items.

References SHAPE_LINE_CHAIN::CPoint(), GetApertureMacroShape(), GRClosedPoly(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by D_CODE::DrawFlashedShape().

◆ 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.

Parameters
aParentis the parent GERBER_DRAW_ITEM which is actually drawn.
Returns
the shape of the item.

Definition at line 815 of file am_primitive.cpp.

817{
818 SHAPE_POLY_SET holeBuffer;
819
821
822 for( AM_PRIMITIVES::iterator prim_macro = primitives.begin();
823 prim_macro != primitives.end(); ++prim_macro )
824 {
825 if( prim_macro->primitive_id == AMP_COMMENT )
826 continue;
827
828 if( prim_macro->IsAMPrimitiveExposureOn( aParent ) )
829 {
830 prim_macro->DrawBasicShape( aParent, m_shape, aShapePos );
831 }
832 else
833 {
834 prim_macro->DrawBasicShape( aParent, holeBuffer, aShapePos );
835
836 if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole
837 {
839 holeBuffer.RemoveAllContours();
840 }
841 }
842 }
843
844 // Merge and cleanup basic shape polygons
846
847 // A hole can be is defined inside a polygon, or the polygons themselve can create
848 // a hole when merged, so we must fracture the polygon to be able to drawn it
849 // (i.e link holes by overlapping edges)
851
852 m_boundingBox = BOX2I( VECTOR2I( 0, 0 ), VECTOR2I( 1, 1 ) );
853
854 auto bb = m_shape.BBox();
855 VECTOR2I center( bb.Centre().x, bb.Centre().y );
856
857 m_boundingBox.Move( aParent->GetABPosition( center ) );
858 m_boundingBox.Inflate( bb.GetWidth() / 2, bb.GetHeight() / 2 );
859
860 return &m_shape;
861}
@ AMP_COMMENT
Definition: am_primitive.h:71
BOX2< VECTOR2I > BOX2I
Definition: box2.h:835
void Move(const Vec &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: box2.h:111
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:506
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
Return the image position of aPosition for this object.
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)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
AM_PRIMITIVES primitives
A sequence of AM_PRIMITIVEs.
Definition: am_primitive.h:232
BOX2I m_boundingBox
The bounding box of the item, calculated by GetApertureMacroShape.
Definition: am_primitive.h:243
SHAPE_POLY_SET m_shape
The shape of the item, calculated by GetApertureMacroShape.
Definition: am_primitive.h:242
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References AMP_COMMENT, SHAPE_POLY_SET::BBox(), SHAPE_POLY_SET::BooleanSubtract(), SHAPE_POLY_SET::Fracture(), GERBER_DRAW_ITEM::GetABPosition(), BOX2< Vec >::Inflate(), m_boundingBox, m_shape, BOX2< Vec >::Move(), SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::PM_FAST, primitives, SHAPE_POLY_SET::RemoveAllContours(), and SHAPE_POLY_SET::Simplify().

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

◆ GetBoundingBox()

BOX2I APERTURE_MACRO::GetBoundingBox ( ) const
inline

Return the bounding box of the shape.

Definition at line 226 of file am_primitive.h.

227 {
228 return m_boundingBox;
229 }

References m_boundingBox.

Referenced by GERBER_DRAW_ITEM::GetBoundingBox(), and GERBER_DRAW_ITEM::ViewGetLOD().

◆ 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.

Definition at line 898 of file am_primitive.cpp.

899{
900 // find parameter descr.
901 const AM_PARAM * param = nullptr;
902
903 for( unsigned ii = 0; ii < m_localparamStack.size(); ii ++ )
904 {
905 if( m_localparamStack[ii].GetIndex() == aParamId )
906 {
907 param = &m_localparamStack[ii];
908 break;
909 }
910 }
911
912 if ( param == nullptr ) // not found
913 return 0.0;
914
915 // Evaluate parameter
916 double value = param->GetValue( aDcode );
917
918 return value;
919}
Hold a parameter value for an "aperture macro" as defined within standard RS274X.
Definition: am_param.h:285
double GetValue(const D_CODE *aDcode) const
Definition: am_param.cpp:74
AM_PARAMS m_localparamStack
Definition: am_primitive.h:240

References AM_PARAM::GetValue(), and m_localparamStack.

Referenced by AM_PARAM::GetValue().

◆ GetShapeDim()

int APERTURE_MACRO::GetShapeDim ( GERBER_DRAW_ITEM aParent)

C.

alculate a value that can be used to evaluate the size of text when displaying the D-Code of an item.

Due to the complexity of a shape using many primitives one cannot calculate the "size" of a shape (only abounding box) but most of aperture macro are using one or few primitives and the "dimension" of the shape is the diameter of the primitive (or the max diameter of primitives).

Parameters
aParentis the parent GERBER_DRAW_ITEM which is actually drawn.
Returns
a dimension, or -1 if no dim to calculate.

Definition at line 881 of file am_primitive.cpp.

882{
883 int dim = -1;
884
885 for( AM_PRIMITIVES::iterator prim_macro = primitives.begin();
886 prim_macro != primitives.end(); ++prim_macro )
887 {
888 int pdim = prim_macro->GetShapeDim( aParent );
889
890 if( dim < pdim )
891 dim = pdim;
892 }
893
894 return dim;
895}

References primitives.

Referenced by D_CODE::GetShapeDim().

Member Data Documentation

◆ m_boundingBox

BOX2I APERTURE_MACRO::m_boundingBox

The bounding box of the item, calculated by GetApertureMacroShape.

Definition at line 243 of file am_primitive.h.

Referenced by GetApertureMacroShape(), and GetBoundingBox().

◆ m_localparamStack

AM_PARAMS APERTURE_MACRO::m_localparamStack

Definition at line 240 of file am_primitive.h.

Referenced by GetLocalParam(), and GERBER_FILE_IMAGE::ReadApertureMacro().

◆ m_shape

SHAPE_POLY_SET APERTURE_MACRO::m_shape

The shape of the item, calculated by GetApertureMacroShape.

Definition at line 242 of file am_primitive.h.

Referenced by GetApertureMacroShape().

◆ name

wxString APERTURE_MACRO::name

◆ primitives

AM_PRIMITIVES APERTURE_MACRO::primitives

A sequence of AM_PRIMITIVEs.

Definition at line 232 of file am_primitive.h.

Referenced by GetApertureMacroShape(), GetShapeDim(), and GERBER_FILE_IMAGE::ReadApertureMacro().


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