Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCB gerber import: Incorrect handling of D02 operations #750

Closed
neinseg opened this issue Mar 19, 2021 · 2 comments
Closed

PCB gerber import: Incorrect handling of D02 operations #750

neinseg opened this issue Mar 19, 2021 · 2 comments
Assignees
Labels
Milestone

Comments

@neinseg
Copy link

neinseg commented Mar 19, 2021

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

@klayoutmatthias
Copy link
Collaborator

@neinseg Thanks a lot for this nice test case. I'll take a look.

Kind regards,

Matthias

@klayoutmatthias klayoutmatthias self-assigned this Mar 21, 2021
@klayoutmatthias klayoutmatthias added this to the 0.26.12 milestone Mar 21, 2021
klayoutmatthias added a commit that referenced this issue Mar 22, 2021
klayoutmatthias added a commit that referenced this issue Mar 30, 2021
klayoutmatthias added a commit that referenced this issue Mar 30, 2021
@klayoutmatthias
Copy link
Collaborator

As 0.27 is ahead I don't think I'll port the fix to 0.26.12. Let me know if you need to and reopen the bug in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants