ThisIsNotRocketScience / GerberTools

Tools to load/edit/create/panelizer sets of gerber files
MIT License
725 stars 144 forks source link

Add support Excellon cutter compensation (G40/G41/G42) #119

Closed FabianoGK closed 4 years ago

FabianoGK commented 4 years ago

I had a panel created with Fab3000. The slots around the individual boards were created with cutter compensation.

QuickGerberRender was not rendering the slots correctly. After inspection the source code, I noticed the cutter compensation feature was not supported.

The logic I used to handle cutter compensation is relatively straight forward.

Once cutter compensation is engaged (G41 or G42), all the points are collected until cutter compensation is cancelled (G40). Then, all the points are processed by the CutCompensation routine.

The CutCompensation routine is responsible for:

a) removing any contiguous duplicated points. For example, { A, B, B, C, A, D, E, E, F } would become { A, B, C, A, D, E, F }. b) creating offset segments, by creating a line segment from two consecutive points and moving that line segment to the left or right from the direction of the path by the offset amount. c) figuring out how to join two consecutive offset segments.

There are 3 cases to handle: 1) if segments are colinear, the path is a line segment from the beginning of first segment to the end of the second segment; 2) if segments intersect, the path is line segment from the beginning of the first segment to the intersection point and then another line segment from the intersection point to the end of the second segment; 3) if segments do not intersect, cutter compensation dictates an arc is created to join the two consecutive offset segments.

Thank you, Fabiano

PS: I also added file extensions that are used by Altium tools. Please let me know if you would like me to separate the pull request for them.