abetusk/gbr2ngc

Implement Aperture Macros (AM)

Closed this issue · 3 comments

Aperture macros aren't implemented, implement them. There's a complication in that the aperture macro can reference aperture definitions and also have "arithmetic expressions with other variables", so we're starting to need to implement a real language.

The first step is to make sure the aperture macros can parse lines that are simple, without references to other aperture definitions or contain arithmetic operations. The next step is to add aperture definitions. Finally, the last step is to add arithmetic operations.

Aperture Definitions (AD) can reference Aperture Macros. Instantiating an AD from an AM only needs to evaluate the AM once at load and the geometry can be referenced.

I'm thinking of using a stripped down version of tinyexpr for the calculator functions.

The AD function can mostly be kept except for an alternate code path to reference an AM if used.

tinyexpr has been added to gbl2ngc along with code to evaluate aperture macros in the branch gerber-extensions.

Briefly, aperture macros are handled by extending the gerber_state_t structure in gerber_interpreter.h. A linked list of newly defined am_ll_node_t structure is used to create a linked list of aperture macros, where each node holds a string array for each aperture macro command.

The parameters to each aperture macro are shoved into a tinyexpr context as global variables whose names are the $<param_position>. In each line of the evaluated aperture macro, lines are parsed either creating aperture definitions and evaluating each AD parameter with a call to the tinyexpr engine or are used to create a new variable. In a "new variable" definition, the right hand side of the equal is evaluated with a tinyexpr context that has all previous variable names for this aperture macro set up in it's environment.

gerber-extensions need to implement the rest of the Gerber spec as well as provide some tests before it's merged into release.

resolved by 2e149e4