KiCad PCB EDA Suite
dcode.cpp File Reference

D_CODE class implementation. More...

#include <trigo.h>
#include <gerbview_frame.h>
#include <gerber_file_image.h>
#include <eda_units.h>
#include <convert_basic_shapes_to_polygon.h>

Go to the source code of this file.

Macros

#define DCODE_DEFAULT_SIZE   gerbIUScale.mmToIU( 0.1 )
 
#define SEGS_CNT   64
 

Functions

static void addHoleToPolygon (SHAPE_POLY_SET *aPolygon, APERTURE_DEF_HOLETYPE aHoleShape, const VECTOR2I &aSize, const VECTOR2I &aAnchorPos)
 

Detailed Description

D_CODE class implementation.

Definition in file dcode.cpp.

Macro Definition Documentation

◆ DCODE_DEFAULT_SIZE

#define DCODE_DEFAULT_SIZE   gerbIUScale.mmToIU( 0.1 )

Definition at line 37 of file dcode.cpp.

◆ SEGS_CNT

#define SEGS_CNT   64

Definition at line 289 of file dcode.cpp.

Function Documentation

◆ addHoleToPolygon()

static void addHoleToPolygon ( SHAPE_POLY_SET aPolygon,
APERTURE_DEF_HOLETYPE  aHoleShape,
const VECTOR2I aSize,
const VECTOR2I aAnchorPos 
)
static

Definition at line 422 of file dcode.cpp.

424{
425 VECTOR2I currpos;
426 SHAPE_POLY_SET holeBuffer;
427
428 if( aHoleShape == APT_DEF_ROUND_HOLE )
429 {
430 // Adjust the allowed approx error to convert arcs to segments:
431 int arc_to_seg_error = gerbIUScale.mmToIU( 0.005 ); // Allow 5 microns
432 TransformCircleToPolygon( holeBuffer, VECTOR2I( 0, 0 ), aSize.x / 2, arc_to_seg_error,
433 ERROR_INSIDE );
434 }
435 else if( aHoleShape == APT_DEF_RECT_HOLE )
436 {
437 holeBuffer.NewOutline();
438 currpos.x = aSize.x / 2;
439 currpos.y = aSize.y / 2;
440 holeBuffer.Append( VECTOR2I( currpos ) ); // link to hole and begin hole
441 currpos.x -= aSize.x;
442 holeBuffer.Append( VECTOR2I( currpos ) );
443 currpos.y -= aSize.y;
444 holeBuffer.Append( VECTOR2I( currpos ) );
445 currpos.x += aSize.x;
446 holeBuffer.Append( VECTOR2I( currpos ) );
447 currpos.y += aSize.y;
448 holeBuffer.Append( VECTOR2I( currpos ) ); // close hole
449 }
450
451 aPolygon->BooleanSubtract( holeBuffer, SHAPE_POLY_SET::PM_FAST );
453}
constexpr EDA_IU_SCALE gerbIUScale
Definition: base_units.h:108
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.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Add a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last po...
int NewOutline()
Creates a new hole in a given outline.
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
@ APT_DEF_ROUND_HOLE
Definition: dcode.h:62
@ APT_DEF_RECT_HOLE
Definition: dcode.h:63
@ ERROR_INSIDE
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References SHAPE_POLY_SET::Append(), APT_DEF_RECT_HOLE, APT_DEF_ROUND_HOLE, SHAPE_POLY_SET::BooleanSubtract(), ERROR_INSIDE, SHAPE_POLY_SET::Fracture(), gerbIUScale, EDA_IU_SCALE::mmToIU(), SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::PM_FAST, TransformCircleToPolygon(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by D_CODE::ConvertShapeToPolygon().