40 const wxString& aFileName )
74 for(
unsigned layer = 0; layer < images->
ImagesMaxCount(); ++layer )
76 int pcb_layer_number = aLayerLookUpTable[layer];
98 for(
unsigned layer = 0; layer < images->
ImagesMaxCount(); ++layer )
102 if( gerber ==
nullptr )
105 int pcb_layer_number = aLayerLookUpTable[layer];
114 for(
size_t ii = 0; ii < items.size(); ++ii )
119 for(
unsigned layer = 0; layer < images->
ImagesMaxCount(); ++layer )
123 if( gerber ==
nullptr )
126 int pcb_layer_number = aLayerLookUpTable[layer];
135 for(
size_t ii = 0; ii < items.size(); ++ii )
146 fprintf(
m_fp,
")\n" );
160 static D_CODE dummyD_CODE( 0 );
167 if( d_codeDescr ==
nullptr )
168 d_codeDescr = &dummyD_CODE;
205 seg_start.
y = -seg_start.
y;
206 seg_end.
y = -seg_end.
y;
208 fprintf(
m_fp,
"\t(gr_circle (start %s %s) (end %s %s) (layer %s)\n",
215 fprintf(
m_fp,
"\t)\n" );
233 seg_start.
y = -seg_start.
y;
234 seg_end.
y = -seg_end.
y;
236 fprintf(
m_fp,
"\t(gr_line\n\t\t(start %s %s) (end %s %s) (layer %s)\n",
244 fprintf(
m_fp,
"\t)\n" );
266 if( seg_start == seg_end )
269 arc_center.
y = -arc_center.
y;
270 seg_end.
y = -seg_end.
y;
272 fprintf(
m_fp,
"\t(gr_circle\n\t\t(center %s %s) (end %s %s) (layer %s)\n",
279 fprintf(
m_fp,
"\t)\n" );
287 seg_middle.
y = -seg_middle.
y;
288 seg_start.
y = -seg_start.
y;
289 seg_end.
y = -seg_end.
y;
291 fprintf(
m_fp,
"\t(gr_arc\n\t\t(start %s %s) (mid %s %s) (end %s %s) (layer %s)\n",
301 fprintf(
m_fp,
"\t)\n" );
320 via_pos.
y = -via_pos.
y;
323 fprintf(
m_fp,
"\t(via (at %s %s) (size %s) (drill %s)",
329 fprintf(
m_fp,
" (layers %s %s))\n",
349 fprintf(
m_fp,
"\t(footprint \"slot\" (pad 1 thru_hole oval (at %s %s %s) (size %s %s) (drill oval %s %s)))\n",
423 seg_end = aGbrItem->
m_End;
426 seg_start.
y = -seg_start.
y;
427 seg_end.
y = -seg_end.
y;
434 int aWidth,
int aLayer )
436 fprintf(
m_fp,
"\t(segment (start %s %s) (end %s %s) (width %s) (layer %s) (net 0))\n",
448 fprintf(
m_fp,
"\t\t(stroke (width %s) (type solid))\n",
471 seg_end.
y = -seg_end.
y;
472 seg_start.
y = -seg_start.
y;
473 seg_middle.
y = -seg_middle.
y;
475 fprintf(
m_fp,
"\t(arc\n\t\t(start %s %s) (mid %s %s) (end %s %s) (layer %s)\n",
484 fprintf(
m_fp,
"\t\t(width %s) (net 0 )\n",
486 fprintf(
m_fp,
"\t)\n" );
492 static D_CODE flashed_item_D_CODE( 0 );
496 if( d_codeDescr ==
nullptr )
497 d_codeDescr = &flashed_item_D_CODE;
551 fprintf(
m_fp,
"\t(gr_circle\n\t\t(center %s %s) (end %s %s)\n",
558 fprintf(
m_fp,
"\t\t(fill yes) (layer %s)",
560 fprintf(
m_fp,
"\n\t)\n" );
567 fprintf(
m_fp,
"(kicad_pcb (version 20240928)\n" );
568 fprintf(
m_fp,
"\t(generator \"gerbview\")\n\t(generator_version \"%s\")\n\n",
572 fprintf(
m_fp,
"\t(layers \n" );
578 fprintf(
m_fp,
"\t\t(%d %s signal)\n",
579 *cu_it,
LSET::Name( *cu_it ).ToStdString().c_str() );
584 fprintf(
m_fp,
"\t\t(%d %s user)\n",
585 *non_cu_it,
LSET::Name( *non_cu_it ).ToStdString().c_str() );
588 fprintf(
m_fp,
"\t)\n\n" );
600 for(
size_t ii = 0; ii < items.size(); ++ii )
637 double a = atan2( (
double) ( item->
m_Start.
y - centre.
y ), (
double) ( item->
m_Start.
x - centre.
x ) );
638 double b = atan2( (
double) ( item->
m_End.
y - centre.
y ), (
double) ( item->
m_End.
x - centre.
x ) );
682 if(
clear.m_Index > aIndex &&
clear.m_BBox.Intersects( bbox ) )
711 fprintf(
m_fp,
"\t(gr_poly\n\t\t(pts\n\t\t\t" );
713 #define MAX_COORD_CNT 4
721 for(
int ii = 0; ii <= cnt_max; ii++ )
726 fprintf(
m_fp,
"\n\t\t\t" );
729 fprintf(
m_fp,
" (xy %s %s)",
734 fprintf(
m_fp,
")" );
736 fprintf(
m_fp,
"\n" );
738 fprintf(
m_fp,
"\t\t(fill yes) (layer %s)",
740 fprintf(
m_fp,
"\n\t)\n" );
752 fprintf(
m_fp,
"\t(zone (net 0) (net_name \"\") (layer %s) (tstamp 0000000) (hatch edge 0.508)\n",
755 fprintf(
m_fp,
" (connect_pads (clearance 0.0))\n" );
757 fprintf(
m_fp,
" (min_thickness 0.1) (filled_areas_thickness no)\n"
758 " (fill (thermal_gap 0.3) (thermal_bridge_width 0.3))\n" );
766 fprintf(
m_fp,
" (polygon\n (pts" );
770 #define MAX_COORD_CNT 4
778 for(
int ii = 0; ii <= cnt_max; ii++ )
783 fprintf(
m_fp,
"\n " );
790 fprintf(
m_fp,
")\n" );
792 fprintf(
m_fp,
" )\n)\n" );
constexpr EDA_IU_SCALE gerbIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
Support the "aperture macro" defined within standard RS274X.
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, const VECTOR2I &aShapePos)
Calculate the primitive shape for flashed items.
A gerber DCODE (also called Aperture) definition.
APERTURE_MACRO * GetMacro() const
VECTOR2I m_Size
Horizontal and vertical dimensions.
APERTURE_T m_ApertType
Aperture type ( Line, rectangle, circle, oval poly, macro )
void ConvertShapeToPolygon(const GERBER_DRAW_ITEM *aParent)
Convert a shape to an equivalent polygon.
GERBER_FILE_IMAGE_LIST * m_images
void export_stroke_info(double aWidth)
Write the stroke info (thickness, line type) to the board file.
void export_non_copper_arc(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a non copper arc to the board file.
GBR_TO_PCB_EXPORTER(GERBER_FILE_IMAGE_LIST *aImages, wxWindow *aParent, const wxString &aFileName)
void writePcbZoneItem(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a zone item to the board file.
void export_segarc_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a set of tracks (arcs are approximated by track segments) to the board file.
void write_trimmed_polygon(const GERBER_DRAW_ITEM *aGbrItem, size_t aIndex, int aLayer)
Write a dark region to the board file, minus the clear items drawn after it.
void export_copper_item(const GERBER_DRAW_ITEM *aGbrItem, size_t aIndex, int aLayer)
Write a track (or via) to the board file.
int m_pcbCopperLayersCount
void export_flashed_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a synthetic pad to the board file.
double MapToPcbUnits(int aValue) const
Map GerbView internal units to millimeters for Pcbnew board files.
std::vector< EXPORT_VIA > m_vias
void collect_hole(const GERBER_DRAW_ITEM *aGbrItem)
Collect holes from a drill layer.
void writePcbPolygon(const SHAPE_POLY_SET &aPolys, int aLayer, const VECTOR2I &aOffset={ 0, 0 })
Write a non-copper polygon to the board file.
void export_non_copper_item(const GERBER_DRAW_ITEM *aGbrItem, size_t aIndex, int aLayer)
Write a non copper line or arc to the board file.
void writePcbFilledCircle(const VECTOR2I &aCenterPosition, int aRadius, int aLayer)
Write a filled circle to the board file (with line thickness = 0).
std::vector< EXPORT_SLOT > m_slots
void export_segline_copper_item(const GERBER_DRAW_ITEM *aGbrItem, int aLayer)
Write a track (not via) to the board file.
void writePcbHeader(const int *aLayerLookUpTable)
Write a very basic header to the board file.
void export_slot(const EXPORT_SLOT &aSlot)
bool ExportPcb(const int *aLayerLookUpTable, int aCopperLayers)
Save a board from a set of Gerber images.
void writeCopperLineItem(const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aLayer)
Basic write function to write a a PCB_TRACK to the board file from a non flashed item.
std::vector< CLEAR_SHAPE > m_clearShapes
void collect_clear_shapes(const GERBER_FILE_IMAGE *aImage)
Convert every clear polarity item of an image to a polygon, in file order.
void export_via(const EXPORT_VIA &aVia)
Write a via to the board file.
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.
SHAPE_POLY_SET m_ShapeAsPolygon
bool GetLayerPolarity() const
void ConvertSegmentToPolygon()
Convert a lines in m_ShapeAsPolygon to an equivalent polygon.
GBR_BASIC_SHAPE_TYPE m_ShapeType
GERBER_FILE_IMAGE_LIST is a helper class to handle a list of GERBER_FILE_IMAGE files which are loaded...
unsigned ImagesMaxCount()
GERBER_FILE_IMAGE * GetGbrImage(int aIdx)
Hold the image data and parameters for one gerber file and layer parameters.
GERBER_DRAW_ITEMS & GetItems()
LSET is a set of PCB_LAYER_IDs.
copper_layers_iterator copper_layers_end() const
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
static const LSET & UserMask()
copper_layers_iterator copper_layers_begin() const
non_copper_layers_iterator non_copper_layers_begin() const
static const LSET & AllTechMask()
Return a mask holding all technical layers (no CU layer) on both side.
non_copper_layers_iterator non_copper_layers_end() const
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
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.
void Mirror(const VECTOR2I &aRef, FLIP_DIRECTION aFlipDirection)
Mirror the line points about y or x (or both).
Represent a set of closed polygons.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
void Move(const VECTOR2I &aVector) override
void Fracture(bool aSimplify=true)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
SHAPE_POLY_SET CloneDropTriangulation() const
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
This file is part of the common library.
void TransformRingToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aCentre, int aRadius, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arcs to multiple straight segments.
void TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
static std::string ToStdString(const wxString &aStr)
std::vector< GERBER_DRAW_ITEM * > GERBER_DRAW_ITEMS
bool IsPcbLayer(int aLayer)
Test whether a layer is a valid layer for Pcbnew.
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
std::string FormatDouble2Str(double aValue)
Print a float number without using scientific notation and no trailing 0 This function is intended in...
VECTOR2I GetRotated(const VECTOR2I &aVector, const EDA_ANGLE &aAngle)
Return a new VECTOR2I that is the result of rotating aVector by aAngle.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.