Entering expressions in numeric fields

When creating pad designs or placing edge cuts or components, it is often necessary to calculate the absolute X, Y coordinates relative to other components and/or a center coordinate. Rather than requiring the user to perform mental calculations or use an external calculator (app), and enter the result, wouldn’t it be nice, if one could just enter a numeric expression in the numeric input field? In fact, this feature should be available for ANY numeric field in KiCAD, including thickness/width fields.

Example:
kicad-numeric

Once a numeric expression has been entered, and the field is deselected (pressing ENTER, TAB or mouse-clicking outside the input field) the numeric expression is evaluated, rounded (as appropriate), and the resulting value is shown.

The range of supported operators (and possibly -functions) is not critical, but operator precedence should follow generally accepted conventions.

  • Addition, subtraction [10 + 3 - 0.75]
  • Multiplication, division [2 + 5 * 2.54/10]
  • Unary sign [-5 + 2]
  • Parentheses [5 + 3 * (1 + 1/8)]

Implementation

This feature should be relatively trivial to implement, as it will require an identical change to all affected input fields, adding an (open source) expression parser, and handling syntax or arithmetic errors (e.g. division by zero). Errors can be reported visually in many ways (text message, highlighting text), or even left out.

There would be some value in actually storing the original expression along with the evaluated numeric result, as it typically contains more semantic value (10+7*2.54) than the value on its own (27.78). But I suspect that would require a major change to the internal data model, and thus require a lot more development effort.

What do you guys think?

I think you should try it in KiCad 5 :wink:

1 Like

KiCad 5 only has it in the grid settings dialog (if i remember correctly)
Current nightly however has it everywhere. (unless something has been missed)

Pcbnew 5.0.1 also in footprints coordinates. I have not checked elsewhere.

Should be most everywhere in 5.0.x. There were a few spots that were overlooked that are fixed in master. But almost everywhere. @hatte - You can also use units in the expressions

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.