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 wxPoint &aShapePos)
 Calculate the primitive shape for flashed items. More...
 
void DrawApertureMacroShape (GERBER_DRAW_ITEM *aParent, EDA_RECT *aClipBox, wxDC *aDC, const COLOR4D &aColor, const wxPoint &aShapePos, bool aFilledShape)
 Draw the primitive shape for flashed items. More...
 
int GetShapeDim (GERBER_DRAW_ITEM *aParent)
 Calculate a value that can be used to evaluate the size of text when displaying the D-Code of an item. More...
 
EDA_RECT 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...
 
EDA_RECT 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 167 of file am_primitive.h.

Member Function Documentation

◆ DrawApertureMacroShape()

void APERTURE_MACRO::DrawApertureMacroShape ( GERBER_DRAW_ITEM aParent,
EDA_RECT aClipBox,
wxDC *  aDC,
const COLOR4D aColor,
const wxPoint &  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.
aClipBoxis DC clip box (NULL is no clip).
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 862 of file am_primitive.cpp.

865 {
866  SHAPE_POLY_SET* shapeBuffer = GetApertureMacroShape( aParent, aShapePos );
867 
868  if( shapeBuffer->OutlineCount() == 0 )
869  return;
870 
871  for( int ii = 0; ii < shapeBuffer->OutlineCount(); ii++ )
872  {
873  SHAPE_LINE_CHAIN& poly = shapeBuffer->Outline( ii );
874 
875  GRClosedPoly( aClipBox, aDC, poly.PointCount(), (wxPoint*) &poly.CPoint( 0 ), aFilledShape,
876  aColor, aColor );
877  }
878 }
int OutlineCount() const
Return the number of vertices in a given outline/hole.
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)
void GRClosedPoly(EDA_RECT *ClipBox, wxDC *DC, int n, const wxPoint *Points, bool Fill, const COLOR4D &Color, const COLOR4D &BgColor)
Draw a closed polyline and fill it if Fill, in object space.
Definition: gr_basic.cpp:507
Represent a polyline (an zero-thickness chain of connected line segments).
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, const wxPoint &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 wxPoint &  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 813 of file am_primitive.cpp.

815 {
816  SHAPE_POLY_SET holeBuffer;
817  bool hasHole = false;
818 
820 
821  for( AM_PRIMITIVES::iterator prim_macro = primitives.begin();
822  prim_macro != primitives.end(); ++prim_macro )
823  {
824  if( prim_macro->primitive_id == AMP_COMMENT )
825  continue;
826 
827  if( prim_macro->IsAMPrimitiveExposureOn( aParent ) )
828  {
829  prim_macro->DrawBasicShape( aParent, m_shape, aShapePos );
830  }
831  else
832  {
833  prim_macro->DrawBasicShape( aParent, holeBuffer, aShapePos );
834 
835  if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole
836  {
838  holeBuffer.RemoveAllContours();
839  hasHole = true;
840  }
841  }
842  }
843 
844  // Merge and cleanup basic shape polygons
846 
847  // If a hole is defined inside a polygon, we must fracture the polygon
848  // to be able to drawn it (i.e link holes by overlapping edges)
849  if( hasHole )
851 
852  m_boundingBox = EDA_RECT( wxPoint( 0, 0 ), wxSize( 1, 1 ) );
853  auto bb = m_shape.BBox();
854  wxPoint center( bb.Centre().x, bb.Centre().y );
855  m_boundingBox.Move( aParent->GetABPosition( center ) );
856  m_boundingBox.Inflate( bb.GetWidth() / 2, bb.GetHeight() / 2 );
857 
858  return &m_shape;
859 }
void Move(const wxPoint &aMoveVector)
Move the rectangle by the aMoveVector.
Definition: eda_rect.cpp:51
int OutlineCount() const
Return the number of vertices in a given outline/hole.
EDA_RECT m_boundingBox
The bounding box of the item, calculated by GetApertureMacroShape.
Definition: am_primitive.h:243
wxPoint GetABPosition(const wxPoint &aXYPosition) const
Return the image position of aPosition for this object.
Represent a set of closed polygons.
void Simplify(POLYGON_MODE aFastMode)
void Fracture(POLYGON_MODE aFastMode)
Convert a single outline slitted ("fractured") polygon into a set ouf outlines with holes.
SHAPE_POLY_SET m_shape
The shape of the item, calculated by GetApertureMacroShape.
Definition: am_primitive.h:242
AM_PRIMITIVES primitives
A sequence of AM_PRIMITIVEs.
Definition: am_primitive.h:232
Handle the component boundary box.
Definition: eda_rect.h:42
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Inflate the rectangle horizontally by dx and vertically by dy.
Definition: eda_rect.cpp:364

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

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

◆ GetBoundingBox()

EDA_RECT 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  }
EDA_RECT m_boundingBox
The bounding box of the item, calculated by GetApertureMacroShape.
Definition: am_primitive.h:243

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 }
double GetValue(const D_CODE *aDcode) const
Definition: am_param.cpp:74
AM_PARAMS m_localparamStack
Definition: am_primitive.h:240
Hold a parameter value for an "aperture macro" as defined within standard RS274X.
Definition: am_param.h:284

References AM_PARAM::GetValue(), and m_localparamStack.

Referenced by AM_PARAM::GetValue().

◆ GetShapeDim()

int APERTURE_MACRO::GetShapeDim ( GERBER_DRAW_ITEM aParent)

Calculate 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 }
AM_PRIMITIVES primitives
A sequence of AM_PRIMITIVEs.
Definition: am_primitive.h:232

References primitives.

Referenced by D_CODE::GetShapeDim().

Member Data Documentation

◆ m_boundingBox

EDA_RECT 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: