tracespace icon indicating copy to clipboard operation
tracespace copied to clipboard

Fails to detect units if format spec combined with units spec

Open davidworkman9 opened this issue 5 years ago • 4 comments

By the looks of things Eagle (sometimes?) exports the units on the same line as the coordinate system line. Example:

%FSLAX43Y43*MOMM*%

In this case, the gerber parser does not pick up the units.

davidworkman9 avatar Apr 17 '19 15:04 davidworkman9

That's frustrating. According to the Gerber spec...

There can be only one extended code command between each pair of ‘%’ delimiters

...so this is invalid output from Eagle. Do you have any idea which version(s) of Eagle are doing this and/or how prevalent this is?

mcous avatar Apr 17 '19 20:04 mcous

I saw that too, definitely frustrating.

Looking at the file again I think I was wrong about it being from Eagle:

G04 File Origin:  Cadence Allegro 17.2-S049*

davidworkman9 avatar Apr 18 '19 13:04 davidworkman9

Same issue, slightly different version of Cadence Allegro.

G04 File Origin:  Cadence Allegro 17.2-S032*
...
%FSLAX25Y25*MOMM*%

Spec is clear, this is wrong. I don't have info on which versions of Cadence Allegro do this.

To address, I believe the best fix would be to add code to the RE_FORMAT case in parse() detect the extra command. A design tool detecting test could also be added to the RE_COMMENT case. I can make the change but i'd like to confirm this approach make sense to you wonderful people first.

Thanks for making, and continuing to maintaining this parser!

thetroy avatar Jan 20 '20 17:01 thetroy

Would have had to store the detected design tool in the parser and doing so would expand the scope of my hack/patch. I opted to just detect the suffix. Need some design guidance if I'm going to refine + PR this.

// PATCH START -- PART 1 of 4
//
// Special Case: Cadence Allegro
// The gerber spec says
//   "There can be only one extended code command between each pair of ‘%’ delimiters"
// Cadence Allegro violates this rule by including the units after the format command
//
// Sample:
//   G04 File Origin:  Cadence Allegro 17.2-S032*
//   ...
//   %FSLAX25Y25*MOMM*%
//   ...
//
var RE_CADENCE_ALLEGRO_UNITS_IN_FORMAT = /\*MO(IN|MM)$/
// PATCH END

// PATCH START -- PART 2 of 4
var parseUnits = function(parser, unitsMatch) {
  var units = unitsMatch === 'IN' ? 'in' : 'mm'
  return parser._push(commands.set('units', units))
}
// PATCH END -- PART 2 of 4

...

  if (RE_UNITS.test(block)) {
    var unitsMatch = block.match(RE_UNITS)[1]
    // PATCH START -- PART 3 of 4
    return parseUnits(parser, unitsMatch);
    // PATCH END -- PART 3 of 4
  }
...
  if (RE_FORMAT.test(block)) {
...
    if (RE_CADENCE_ALLEGRO_UNITS_IN_FORMAT.test(block)) {
      var unitsMatch = block.match(RE_CADENCE_ALLEGRO_UNITS_IN_FORMAT)[1]
      console.log('matched hack', unitsMatch);
      return parseUnits(parser, unitsMatch);
    }
...
  }

thetroy avatar Jan 20 '20 17:01 thetroy