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

Fails to detect units if format spec combined with units spec #234

Open
davidworkman9 opened this issue Apr 17, 2019 · 4 comments
Open

Fails to detect units if format spec combined with units spec #234

davidworkman9 opened this issue Apr 17, 2019 · 4 comments
Labels
gerber-parser Tickets for the gerber-parser package v5-fixed Ticket is resolved in the `v5` branch

Comments

@davidworkman9
Copy link
Contributor

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.

@mcous mcous added the gerber-parser Tickets for the gerber-parser package label Apr 17, 2019
@mcous
Copy link
Member

mcous commented Apr 17, 2019

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?

@davidworkman9
Copy link
Contributor Author

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*

@thetroy
Copy link

thetroy commented Jan 20, 2020

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
Copy link

thetroy commented Jan 20, 2020

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);
    }
...
  }

@mcous mcous changed the title Fails to detect Eagle units Fails to detect units if format spec combined with units spec Jun 27, 2020
@mcous mcous added the v5-fixed Ticket is resolved in the `v5` branch label Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gerber-parser Tickets for the gerber-parser package v5-fixed Ticket is resolved in the `v5` branch
Projects
None yet
Development

No branches or pull requests

3 participants