Skip to content

PCB gerber import: Incorrect handling of D02 operations #750

@neinseg

Description

@neinseg

When importing a PCB gerber file through File -> Import -> Gerber PCB -> New Project, KLayout incorrectly interprets D02 operations inside G36/G37 regions. test1.gbr below (download: testfiles.zip) should render a rectangle. Ucamco's reference gerber viewer agrees.

KLayout v0.26.11 instead renders a triangle. The missing point is the one described by the D02 "move" operation. When duplicating the coordinates of the D02 operation with an additional D01 operation, KLayout again produces correct output. See test2.gbr. A screenshot of KLayout with both files loaded is embedded below. Thanks to @mx-yah for reporting this on the gerbolyze tracker, jaseg/gerbolyze#12

The issue seems to stem from KLayout completely ignoring the coordinate when handling D02 statements:

if (m_current_dcode == 2) {
// move
if (m_polygon_mode) {
// D02 strokes close the polygon (and restart a new one)
if (m_polygon_points.size () >= 3) {
db::DPolygon poly;
poly.assign_hull (m_polygon_points.begin (), m_polygon_points.end ());
produce_polygon (poly, is_clear_polarity ());
}
m_polygon_points.clear ();
}
} else if (m_current_dcode == 3) {

test1.gbr:

%FSLAX46Y46*%
%MOMM*%
%LPD*%
G01*
%ADD10C,0.050000*%
D10*
%LPD*%
G36*
X0070000000Y0050000000D02*
X0020000000Y0050000000D01*
X0020000000Y0080000000D01*
X0070000000Y0080000000D01*
G37*
M02*

test2.gbr:

%FSLAX46Y46*%
%MOMM*%
%LPD*%
G01*
%ADD10C,0.050000*%
D10*
%LPD*%
G36*
X0070000000Y0050000000D02*
X0070000000Y0050000000D01*
X0020000000Y0050000000D01*
X0020000000Y0080000000D01*
X0070000000Y0080000000D01*
G37*
M02*

KLayout with both files loaded:
klayout-d02-fail

Here's test1.gbr in Ucamco's reference gerber viewer for comparison:
klayout-ucamco-ref

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions